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