refactor: move logFile to Settings
newKey log/file <= General/logFilename remove logfilename from appConfig
This commit is contained in:
parent
4273fe2318
commit
6834862413
10 changed files with 22 additions and 51 deletions
|
|
@ -147,7 +147,7 @@ void SettingsDialog::accept()
|
|||
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
|
||||
Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex());
|
||||
Settings::setValue(Settings::Log::ToFile, ui->cbLogToFile->isChecked());
|
||||
m_appConfig.setLogFilename(ui->lineLogFilename->text());
|
||||
Settings::setValue(Settings::Log::File, ui->lineLogFilename->text());
|
||||
m_appConfig.setElevateMode(static_cast<ElevateMode>(ui->comboElevate->currentIndex()));
|
||||
Settings::setValue(Settings::Gui::Autohide, ui->cbAutoHide->isChecked());
|
||||
Settings::setValue(Settings::Gui::AutoUpdateCheck, ui->cbAutoUpdate->isChecked());
|
||||
|
|
@ -182,7 +182,7 @@ void SettingsDialog::loadFromConfig()
|
|||
ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString());
|
||||
ui->comboLogLevel->setCurrentIndex(Settings::value(Settings::Log::Level).toInt());
|
||||
ui->cbLogToFile->setChecked(Settings::value(Settings::Log::ToFile).toBool());
|
||||
ui->lineLogFilename->setText(m_appConfig.logFilename());
|
||||
ui->lineLogFilename->setText(Settings::value(Settings::Log::File).toString());
|
||||
ui->cbAutoHide->setChecked(Settings::value(Settings::Gui::Autohide).toBool());
|
||||
ui->cbPreventSleep->setChecked(Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
ui->cbLanguageSync->setChecked(Settings::value(Settings::Client::LanguageSync).toBool());
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ QVariant Settings::defaultValue(const QString &key)
|
|||
if (key == Security::KeySize)
|
||||
return 2048;
|
||||
|
||||
if (key == Log::File)
|
||||
return QStringLiteral("%1/%2").arg(QDir::homePath(), kDefaultLogFile);
|
||||
|
||||
if (key == Log::Level)
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public:
|
|||
};
|
||||
struct Log
|
||||
{
|
||||
inline static const auto File = QStringLiteral("log/file");
|
||||
inline static const auto Level = QStringLiteral("log/level");
|
||||
inline static const auto ToFile = QStringLiteral("log/toFile");
|
||||
};
|
||||
|
|
@ -122,6 +123,7 @@ private:
|
|||
, Core::PreventSleep
|
||||
, Core::Scope
|
||||
, Core::StartedBefore
|
||||
, Log::File
|
||||
, Log::Level
|
||||
, Log::ToFile
|
||||
, Gui::Autohide
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ const auto kVersionGitSha = "@GIT_SHA_SHORT@";
|
|||
const auto kDaemonBinName = "@CMAKE_PROJECT_NAME@-daemon";
|
||||
const auto kDaemonIpcName = "@CMAKE_PROJECT_NAME@-daemon";
|
||||
const auto kDaemonLogFilename = "@CMAKE_PROJECT_NAME@-daemon.log";
|
||||
const auto kDefaultLogFile = "@CMAKE_PROJECT_NAME@.log";
|
||||
|
||||
// clang-format off
|
||||
const auto kDisplayVersion = @CMAKE_PROJECT_VERSION_TWEAK@ ? "@CMAKE_PROJECT_VERSION@ (@GIT_SHA_SHORT@)" : "@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@.@CMAKE_PROJECT_VERSION_PATCH@";
|
||||
|
|
@ -59,3 +60,4 @@ const auto kClientBinName = "@CMAKE_PROJECT_NAME@-client";
|
|||
const auto kServerBinName = "@CMAKE_PROJECT_NAME@-server";
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ const char *const AppConfig::m_SettingsName[] = {
|
|||
"", // interface moved to deskflow settings
|
||||
"", // log level moved to deskflow settings
|
||||
"", // Log to file Moved to Deskflow settings
|
||||
"logFilename",
|
||||
"", // 5 logFilename, moved to deskflow settings
|
||||
"", // 6 wizardLastRun, obsolete
|
||||
"", // 7 statedBefore moved to deskflow settings
|
||||
"elevateMode",
|
||||
|
|
@ -112,7 +112,6 @@ void AppConfig::recallFromCurrentScope()
|
|||
recallScreenName();
|
||||
recallElevateMode();
|
||||
|
||||
m_LogFilename = getFromCurrentScope(kLogFilename, m_LogFilename).toString();
|
||||
m_ServerGroupChecked = getFromCurrentScope(kServerGroupChecked, m_ServerGroupChecked).toBool();
|
||||
m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool();
|
||||
m_ClientGroupChecked = getFromCurrentScope(kClientGroupChecked, m_ClientGroupChecked).toBool();
|
||||
|
|
@ -148,7 +147,6 @@ void AppConfig::commit()
|
|||
|
||||
if (isActiveScopeWritable()) {
|
||||
setInCurrentScope(kScreenName, m_ScreenName);
|
||||
setInCurrentScope(kLogFilename, m_LogFilename);
|
||||
setInCurrentScope(kElevateMode, static_cast<int>(m_ElevateMode));
|
||||
setInCurrentScope(kElevateModeLegacy, m_ElevateMode == ElevateMode::kAlways);
|
||||
setInCurrentScope(kUseInternalConfig, m_UseInternalConfig);
|
||||
|
|
@ -321,22 +319,6 @@ bool AppConfig::isActiveScopeSystem() const
|
|||
return m_Scopes.activeScope() == ConfigScopes::Scope::System;
|
||||
}
|
||||
|
||||
QString AppConfig::logDir() const
|
||||
{
|
||||
// by default log to home dir
|
||||
return QDir::home().absolutePath() + "/";
|
||||
}
|
||||
|
||||
void AppConfig::persistLogDir() const
|
||||
{
|
||||
QDir dir = logDir();
|
||||
|
||||
// persist the log directory
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(dir.path());
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Begin getters
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -351,11 +333,6 @@ const QString &AppConfig::screenName() const
|
|||
return m_ScreenName;
|
||||
}
|
||||
|
||||
const QString &AppConfig::logFilename() const
|
||||
{
|
||||
return m_LogFilename;
|
||||
}
|
||||
|
||||
ProcessMode AppConfig::processMode() const
|
||||
{
|
||||
return m_EnableService ? ProcessMode::kService : ProcessMode::kDesktop;
|
||||
|
|
@ -415,11 +392,6 @@ void AppConfig::setScreenName(const QString &s)
|
|||
Q_EMIT screenNameChanged();
|
||||
}
|
||||
|
||||
void AppConfig::setLogFilename(const QString &s)
|
||||
{
|
||||
m_LogFilename = s;
|
||||
}
|
||||
|
||||
void AppConfig::setElevateMode(ElevateMode em)
|
||||
{
|
||||
m_ElevateMode = em;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
namespace deskflow::gui {
|
||||
|
||||
const ElevateMode kDefaultElevateMode = ElevateMode::kAutomatic;
|
||||
const QString kDefaultLogFile = QStringLiteral("%1.log").arg(kAppId);
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
const ProcessMode kDefaultProcessMode = ProcessMode::kService;
|
||||
|
|
@ -59,7 +58,7 @@ private:
|
|||
// kInterface = 2, moved to deskflow settings
|
||||
// kLogLevel = 3, moved to deskflow settings
|
||||
// 4 = LogToFile moved to deskflow settings
|
||||
kLogFilename = 5,
|
||||
// 5 = logfilename moved to deskflow settings
|
||||
// 6 = show first run wizard, obsolete
|
||||
// 7 Started before moved to deskflow settings
|
||||
kElevateModeLegacy = 8,
|
||||
|
|
@ -131,8 +130,6 @@ public:
|
|||
ProcessMode processMode() const override;
|
||||
ElevateMode elevateMode() const override;
|
||||
const QString &screenName() const override;
|
||||
const QString &logFilename() const override;
|
||||
void persistLogDir() const override;
|
||||
bool isActiveScopeWritable() const override;
|
||||
bool isActiveScopeSystem() const override;
|
||||
bool enableService() const override;
|
||||
|
|
@ -142,7 +139,6 @@ public:
|
|||
// Getters (new methods)
|
||||
//
|
||||
|
||||
QString logDir() const;
|
||||
bool serverGroupChecked() const;
|
||||
bool useInternalConfig() const;
|
||||
|
||||
|
|
@ -151,7 +147,6 @@ public:
|
|||
//
|
||||
|
||||
void setScreenName(const QString &s) override;
|
||||
void setLogFilename(const QString &s) override;
|
||||
void setElevateMode(ElevateMode em) override;
|
||||
void setEnableService(bool enabled) override;
|
||||
|
||||
|
|
@ -220,7 +215,6 @@ private:
|
|||
/// @brief Contains the string values of the settings names that will be saved
|
||||
static const char *const m_SettingsName[];
|
||||
|
||||
QString m_LogFilename = logDir() + deskflow::gui::kDefaultLogFile;
|
||||
ElevateMode m_ElevateMode = deskflow::gui::kDefaultElevateMode;
|
||||
bool m_ServerGroupChecked = false;
|
||||
bool m_UseInternalConfig = false;
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ public:
|
|||
virtual ProcessMode processMode() const = 0;
|
||||
virtual ElevateMode elevateMode() const = 0;
|
||||
virtual const QString &screenName() const = 0;
|
||||
virtual const QString &logFilename() const = 0;
|
||||
virtual void persistLogDir() const = 0;
|
||||
virtual bool enableService() const = 0;
|
||||
virtual bool isActiveScopeSystem() const = 0;
|
||||
virtual bool isActiveScopeWritable() const = 0;
|
||||
|
|
@ -48,7 +46,6 @@ public:
|
|||
|
||||
virtual void setLoadFromSystemScope(bool loadFromSystemScope) = 0;
|
||||
virtual void setScreenName(const QString &screenName) = 0;
|
||||
virtual void setLogFilename(const QString &logFilename) = 0;
|
||||
virtual void setElevateMode(ElevateMode elevateMode) = 0;
|
||||
virtual void setEnableService(bool enableService) = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ void CoreProcess::start(std::optional<ProcessMode> processModeOption)
|
|||
qDebug().noquote() << "log level:" << Settings::logLevelText();
|
||||
|
||||
if (Settings::value(Settings::Log::ToFile).toBool())
|
||||
qInfo("log file: %s", qPrintable(m_appConfig.logFilename()));
|
||||
qInfo().noquote() << "log file:" << Settings::value(Settings::Log::File).toString();
|
||||
|
||||
if (processMode == ProcessMode::kDesktop) {
|
||||
startForegroundProcess(app, args);
|
||||
|
|
@ -529,8 +529,8 @@ bool CoreProcess::addServerArgs(QStringList &args, QString &app)
|
|||
}
|
||||
|
||||
if (Settings::value(Settings::Log::ToFile).toBool()) {
|
||||
m_appConfig.persistLogDir();
|
||||
args << "--log" << m_appConfig.logFilename();
|
||||
persistLogDir();
|
||||
args << "--log" << Settings::value(Settings::Log::File).toString();
|
||||
}
|
||||
|
||||
if (!Settings::value(Settings::Security::CheckPeers).toBool()) {
|
||||
|
|
@ -576,8 +576,8 @@ bool CoreProcess::addClientArgs(QStringList &args, QString &app)
|
|||
}
|
||||
|
||||
if (Settings::value(Settings::Log::ToFile).toBool()) {
|
||||
m_appConfig.persistLogDir();
|
||||
args << "--log" << m_appConfig.logFilename();
|
||||
persistLogDir();
|
||||
args << "--log" << Settings::value(Settings::Log::File).toString();
|
||||
}
|
||||
|
||||
if (Settings::value(Settings::Client::LanguageSync).toBool()) {
|
||||
|
|
@ -746,6 +746,11 @@ QString CoreProcess::requestDaemonLogPath()
|
|||
return logPath;
|
||||
}
|
||||
|
||||
void CoreProcess::persistLogDir()
|
||||
{
|
||||
QDir(QFileInfo(Settings::value(Settings::Log::File).toString()).absolutePath()).mkpath(".");
|
||||
}
|
||||
|
||||
void CoreProcess::clearSettings()
|
||||
{
|
||||
if (m_appConfig.processMode() == ProcessMode::kDesktop) {
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ private:
|
|||
QString correctedInterface() const;
|
||||
QString correctedAddress() const;
|
||||
QString requestDaemonLogPath();
|
||||
void persistLogDir();
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
void checkOSXNotification(const QString &line);
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ public:
|
|||
AppConfigMock()
|
||||
{
|
||||
ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stub));
|
||||
|
||||
ON_CALL(*this, logFilename()).WillByDefault(testing::ReturnRef(m_stub));
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -32,8 +30,6 @@ public:
|
|||
MOCK_METHOD(ProcessMode, processMode, (), (const, override));
|
||||
MOCK_METHOD(ElevateMode, elevateMode, (), (const, override));
|
||||
MOCK_METHOD(const QString &, screenName, (), (const, override));
|
||||
MOCK_METHOD(const QString &, logFilename, (), (const, override));
|
||||
MOCK_METHOD(void, persistLogDir, (), (const, override));
|
||||
MOCK_METHOD(bool, enableService, (), (const, override));
|
||||
MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override));
|
||||
MOCK_METHOD(bool, isActiveScopeWritable, (), (const, override));
|
||||
|
|
@ -45,7 +41,6 @@ public:
|
|||
|
||||
MOCK_METHOD(void, setLoadFromSystemScope, (bool loadFromSystemScope), (override));
|
||||
MOCK_METHOD(void, setScreenName, (const QString &screenName), (override));
|
||||
MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override));
|
||||
MOCK_METHOD(void, setElevateMode, (ElevateMode elevateMode), (override));
|
||||
MOCK_METHOD(void, setEnableService, (bool enableService), (override));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue