refactor: move logLevel and loglevelText to Settings
newKey: log/level <= General/logLevel2 remove logLevel from AppConfig
This commit is contained in:
@ -294,7 +294,6 @@ void MainWindow::connectSlots()
|
||||
connect(Settings::instance(), &Settings::settingsChanged, this, &MainWindow::settingsChanged);
|
||||
|
||||
connect(&m_appConfig, &AppConfig::screenNameChanged, this, &MainWindow::updateScreenName);
|
||||
connect(&m_appConfig, &AppConfig::logLevelChanged, &m_coreProcess, &CoreProcess::applyLogLevel);
|
||||
|
||||
connect(&m_coreProcess, &CoreProcess::starting, this, &MainWindow::coreProcessStarting, Qt::DirectConnection);
|
||||
connect(&m_coreProcess, &CoreProcess::error, this, &MainWindow::coreProcessError);
|
||||
@ -384,6 +383,11 @@ void MainWindow::firstShown()
|
||||
|
||||
void MainWindow::settingsChanged(const QString &key)
|
||||
{
|
||||
if (key == Settings::Log::Level) {
|
||||
m_coreProcess.applyLogLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
|
||||
(key == Settings::Security::TlsEnabled) || (key == Settings::Security::CheckPeers)) {
|
||||
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
||||
@ -391,6 +395,7 @@ void MainWindow::settingsChanged(const QString &key)
|
||||
m_tlsUtility.generateCertificate();
|
||||
}
|
||||
updateSecurityIcon(m_lblSecurityStatus->isVisible());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -145,7 +145,7 @@ void SettingsDialog::accept()
|
||||
m_appConfig.setLoadFromSystemScope(ui->rbScopeSystem->isChecked());
|
||||
Settings::setValue(Settings::Core::Port, ui->sbPort->value());
|
||||
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
|
||||
m_appConfig.setLogLevel(ui->comboLogLevel->currentIndex());
|
||||
Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex());
|
||||
Settings::setValue(Settings::Log::ToFile, ui->cbLogToFile->isChecked());
|
||||
m_appConfig.setLogFilename(ui->lineLogFilename->text());
|
||||
m_appConfig.setElevateMode(static_cast<ElevateMode>(ui->comboElevate->currentIndex()));
|
||||
@ -180,7 +180,7 @@ void SettingsDialog::loadFromConfig()
|
||||
|
||||
ui->sbPort->setValue(Settings::value(Settings::Core::Port).toInt());
|
||||
ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString());
|
||||
ui->comboLogLevel->setCurrentIndex(m_appConfig.logLevel());
|
||||
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->cbAutoHide->setChecked(Settings::value(Settings::Gui::Autohide).toBool());
|
||||
|
||||
@ -92,6 +92,9 @@ QVariant Settings::defaultValue(const QString &key)
|
||||
if (key == Security::KeySize)
|
||||
return 2048;
|
||||
|
||||
if (key == Log::Level)
|
||||
return 0;
|
||||
|
||||
if (key == Client::Binary)
|
||||
return kClientBinName;
|
||||
|
||||
@ -101,15 +104,17 @@ QVariant Settings::defaultValue(const QString &key)
|
||||
if (key == Server::ExternalConfigFile)
|
||||
return QStringLiteral("%1/%2.conf").arg(instance()->settingsPath(), kAppId);
|
||||
|
||||
if (key == Security::KeySize)
|
||||
return 2048;
|
||||
|
||||
if (key == Core::Port)
|
||||
return 24800;
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const QString Settings::logLevelText()
|
||||
{
|
||||
return instance()->m_logLevels.at(instance()->value(Log::Level).toInt());
|
||||
}
|
||||
|
||||
bool Settings::isWritable()
|
||||
{
|
||||
return instance()->m_settings->isWritable();
|
||||
|
||||
@ -57,6 +57,7 @@ public:
|
||||
};
|
||||
struct Log
|
||||
{
|
||||
inline static const auto Level = QStringLiteral("log/level");
|
||||
inline static const auto ToFile = QStringLiteral("log/toFile");
|
||||
};
|
||||
struct Security
|
||||
@ -84,6 +85,7 @@ public:
|
||||
static void setScope(bool systemScope);
|
||||
static const QString settingsFile();
|
||||
static const QString settingsPath();
|
||||
static const QString logLevelText();
|
||||
|
||||
signals:
|
||||
void scopeChanged(bool isSystemScope);
|
||||
@ -102,6 +104,13 @@ private:
|
||||
QSettings *m_settings = nullptr;
|
||||
QString m_portableSettingsFile = QStringLiteral("%1.conf").arg(kAppName);
|
||||
// clang-format off
|
||||
inline static const QStringList m_logLevels = {
|
||||
QStringLiteral("INFO")
|
||||
, QStringLiteral("DEBUG")
|
||||
, QStringLiteral("DEBUG1")
|
||||
, QStringLiteral("DEBUG2")
|
||||
};
|
||||
|
||||
inline static const QStringList m_validKeys = {
|
||||
Client::Binary
|
||||
, Client::InvertScrollDirection
|
||||
@ -113,6 +122,7 @@ private:
|
||||
, Core::PreventSleep
|
||||
, Core::Scope
|
||||
, Core::StartedBefore
|
||||
, Log::Level
|
||||
, Log::ToFile
|
||||
, Gui::Autohide
|
||||
, Gui::AutoUpdateCheck
|
||||
|
||||
@ -23,8 +23,6 @@ using namespace deskflow::gui;
|
||||
// which will force it to re-run for existing installations.
|
||||
const int kWizardVersion = 8;
|
||||
|
||||
static const char *const kLogLevelNames[] = {"INFO", "DEBUG", "DEBUG1", "DEBUG2"};
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
const char AppConfig::m_LogDir[] = "log/";
|
||||
#else
|
||||
@ -36,7 +34,7 @@ const char *const AppConfig::m_SettingsName[] = {
|
||||
"screenName",
|
||||
"", // port moved to deskflow settings
|
||||
"", // interface moved to deskflow settings
|
||||
"logLevel2",
|
||||
"", // log level moved to deskflow settings
|
||||
"", // Log to file Moved to Deskflow settings
|
||||
"logFilename",
|
||||
"", // 6 wizardLastRun, obsolete
|
||||
@ -114,7 +112,6 @@ void AppConfig::recallFromCurrentScope()
|
||||
recallScreenName();
|
||||
recallElevateMode();
|
||||
|
||||
m_LogLevel = getFromCurrentScope(kLogLevel, m_LogLevel).toInt();
|
||||
m_LogFilename = getFromCurrentScope(kLogFilename, m_LogFilename).toString();
|
||||
m_ServerGroupChecked = getFromCurrentScope(kServerGroupChecked, m_ServerGroupChecked).toBool();
|
||||
m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool();
|
||||
@ -151,7 +148,6 @@ void AppConfig::commit()
|
||||
|
||||
if (isActiveScopeWritable()) {
|
||||
setInCurrentScope(kScreenName, m_ScreenName);
|
||||
setInCurrentScope(kLogLevel, m_LogLevel);
|
||||
setInCurrentScope(kLogFilename, m_LogFilename);
|
||||
setInCurrentScope(kElevateMode, static_cast<int>(m_ElevateMode));
|
||||
setInCurrentScope(kElevateModeLegacy, m_ElevateMode == ElevateMode::kAlways);
|
||||
@ -355,21 +351,11 @@ const QString &AppConfig::screenName() const
|
||||
return m_ScreenName;
|
||||
}
|
||||
|
||||
int AppConfig::logLevel() const
|
||||
{
|
||||
return m_LogLevel;
|
||||
}
|
||||
|
||||
const QString &AppConfig::logFilename() const
|
||||
{
|
||||
return m_LogFilename;
|
||||
}
|
||||
|
||||
QString AppConfig::logLevelText() const
|
||||
{
|
||||
return kLogLevelNames[logLevel()];
|
||||
}
|
||||
|
||||
ProcessMode AppConfig::processMode() const
|
||||
{
|
||||
return m_EnableService ? ProcessMode::kService : ProcessMode::kDesktop;
|
||||
@ -429,14 +415,6 @@ void AppConfig::setScreenName(const QString &s)
|
||||
Q_EMIT screenNameChanged();
|
||||
}
|
||||
|
||||
void AppConfig::setLogLevel(int i)
|
||||
{
|
||||
const auto changed = (m_LogLevel != i);
|
||||
m_LogLevel = i;
|
||||
if (changed)
|
||||
Q_EMIT logLevelChanged();
|
||||
}
|
||||
|
||||
void AppConfig::setLogFilename(const QString &s)
|
||||
{
|
||||
m_LogFilename = s;
|
||||
|
||||
@ -57,7 +57,7 @@ private:
|
||||
kScreenName = 0,
|
||||
// kPort = 1, moved to deskflow settings
|
||||
// kInterface = 2, moved to deskflow settings
|
||||
kLogLevel = 3,
|
||||
// kLogLevel = 3, moved to deskflow settings
|
||||
// 4 = LogToFile moved to deskflow settings
|
||||
kLogFilename = 5,
|
||||
// 6 = show first run wizard, obsolete
|
||||
@ -130,13 +130,11 @@ public:
|
||||
IConfigScopes &scopes() const override;
|
||||
ProcessMode processMode() const override;
|
||||
ElevateMode elevateMode() const override;
|
||||
QString logLevelText() const override;
|
||||
const QString &screenName() const override;
|
||||
const QString &logFilename() const override;
|
||||
void persistLogDir() const override;
|
||||
bool isActiveScopeWritable() const override;
|
||||
bool isActiveScopeSystem() const override;
|
||||
int logLevel() const override;
|
||||
bool enableService() const override;
|
||||
bool clientGroupChecked() const override;
|
||||
|
||||
@ -153,7 +151,6 @@ public:
|
||||
//
|
||||
|
||||
void setScreenName(const QString &s) override;
|
||||
void setLogLevel(int i) override;
|
||||
void setLogFilename(const QString &s) override;
|
||||
void setElevateMode(ElevateMode em) override;
|
||||
void setEnableService(bool enabled) override;
|
||||
@ -223,7 +220,6 @@ private:
|
||||
/// @brief Contains the string values of the settings names that will be saved
|
||||
static const char *const m_SettingsName[];
|
||||
|
||||
int m_LogLevel = 0;
|
||||
QString m_LogFilename = logDir() + deskflow::gui::kDefaultLogFile;
|
||||
ElevateMode m_ElevateMode = deskflow::gui::kDefaultElevateMode;
|
||||
bool m_ServerGroupChecked = false;
|
||||
@ -238,5 +234,4 @@ private:
|
||||
|
||||
signals:
|
||||
void screenNameChanged();
|
||||
void logLevelChanged();
|
||||
};
|
||||
|
||||
@ -34,11 +34,9 @@ public:
|
||||
virtual IConfigScopes &scopes() const = 0;
|
||||
virtual ProcessMode processMode() const = 0;
|
||||
virtual ElevateMode elevateMode() const = 0;
|
||||
virtual QString logLevelText() const = 0;
|
||||
virtual const QString &screenName() const = 0;
|
||||
virtual const QString &logFilename() const = 0;
|
||||
virtual void persistLogDir() const = 0;
|
||||
virtual int logLevel() const = 0;
|
||||
virtual bool enableService() const = 0;
|
||||
virtual bool isActiveScopeSystem() const = 0;
|
||||
virtual bool isActiveScopeWritable() const = 0;
|
||||
@ -50,7 +48,6 @@ public:
|
||||
|
||||
virtual void setLoadFromSystemScope(bool loadFromSystemScope) = 0;
|
||||
virtual void setScreenName(const QString &screenName) = 0;
|
||||
virtual void setLogLevel(int logLevel) = 0;
|
||||
virtual void setLogFilename(const QString &logFilename) = 0;
|
||||
virtual void setElevateMode(ElevateMode elevateMode) = 0;
|
||||
virtual void setEnableService(bool enableService) = 0;
|
||||
|
||||
@ -240,8 +240,8 @@ void CoreProcess::onProcessFinished(int exitCode, QProcess::ExitStatus)
|
||||
void CoreProcess::applyLogLevel()
|
||||
{
|
||||
if (m_appConfig.processMode() == ProcessMode::kService) {
|
||||
qDebug() << "setting daemon log level:" << m_appConfig.logLevelText();
|
||||
if (!m_daemonIpcClient->sendLogLevel(m_appConfig.logLevelText())) {
|
||||
qDebug() << "setting daemon log level:" << Settings::logLevelText();
|
||||
if (!m_daemonIpcClient->sendLogLevel(Settings::logLevelText())) {
|
||||
qCritical() << "failed to set daemon ipc log level";
|
||||
}
|
||||
}
|
||||
@ -388,7 +388,7 @@ void CoreProcess::start(std::optional<ProcessMode> processModeOption)
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug("log level: %s", qPrintable(m_appConfig.logLevelText()));
|
||||
qDebug().noquote() << "log level:" << Settings::logLevelText();
|
||||
|
||||
if (Settings::value(Settings::Log::ToFile).toBool())
|
||||
qInfo("log file: %s", qPrintable(m_appConfig.logFilename()));
|
||||
@ -471,7 +471,7 @@ void CoreProcess::cleanup()
|
||||
bool CoreProcess::addGenericArgs(QStringList &args, const ProcessMode processMode) const
|
||||
{
|
||||
args << "-f"
|
||||
<< "--debug" << m_appConfig.logLevelText();
|
||||
<< "--debug" << Settings::logLevelText();
|
||||
|
||||
args << "--name" << m_appConfig.screenName();
|
||||
|
||||
|
||||
@ -21,8 +21,6 @@ public:
|
||||
{
|
||||
ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stub));
|
||||
|
||||
ON_CALL(*this, logLevelText()).WillByDefault(testing::Return(m_stub));
|
||||
|
||||
ON_CALL(*this, logFilename()).WillByDefault(testing::ReturnRef(m_stub));
|
||||
}
|
||||
|
||||
@ -33,11 +31,9 @@ public:
|
||||
MOCK_METHOD(deskflow::gui::IConfigScopes &, scopes, (), (const, override));
|
||||
MOCK_METHOD(ProcessMode, processMode, (), (const, override));
|
||||
MOCK_METHOD(ElevateMode, elevateMode, (), (const, override));
|
||||
MOCK_METHOD(QString, logLevelText, (), (const, override));
|
||||
MOCK_METHOD(const QString &, screenName, (), (const, override));
|
||||
MOCK_METHOD(const QString &, logFilename, (), (const, override));
|
||||
MOCK_METHOD(void, persistLogDir, (), (const, override));
|
||||
MOCK_METHOD(int, logLevel, (), (const, override));
|
||||
MOCK_METHOD(bool, enableService, (), (const, override));
|
||||
MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override));
|
||||
MOCK_METHOD(bool, isActiveScopeWritable, (), (const, override));
|
||||
@ -49,7 +45,6 @@ public:
|
||||
|
||||
MOCK_METHOD(void, setLoadFromSystemScope, (bool loadFromSystemScope), (override));
|
||||
MOCK_METHOD(void, setScreenName, (const QString &screenName), (override));
|
||||
MOCK_METHOD(void, setLogLevel, (int logLevel), (override));
|
||||
MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override));
|
||||
MOCK_METHOD(void, setElevateMode, (ElevateMode elevateMode), (override));
|
||||
MOCK_METHOD(void, setEnableService, (bool enableService), (override));
|
||||
|
||||
Reference in New Issue
Block a user