refactor: move logExpanded to Settings

newkey: gui/logExpanded <= General/logExpanded
remove logExpanded AppConfig
This commit is contained in:
sithlord48 2025-03-08 10:10:42 -05:00 committed by Nick Bolton
parent 2a53d4f187
commit 698fd3f83c
6 changed files with 24 additions and 29 deletions

View file

@ -15,7 +15,7 @@
#include "dialogs/SettingsDialog.h" #include "dialogs/SettingsDialog.h"
#include "base/String.h" #include "base/String.h"
#include "common/constants.h" #include "common/Settings.h"
#include "gui/Logger.h" #include "gui/Logger.h"
#include "gui/config/ConfigScopes.h" #include "gui/config/ConfigScopes.h"
#include "gui/constants.h" #include "gui/constants.h"
@ -226,7 +226,7 @@ void MainWindow::setupControls()
// Setup the log toggle, set its initial state to closed // Setup the log toggle, set its initial state to closed
ui->btnToggleLog->setStyleSheet(kStyleFlatButton); ui->btnToggleLog->setStyleSheet(kStyleFlatButton);
if (m_appConfig.logExpanded()) { if (Settings::value(Settings::Gui::LogExpanded).toBool()) {
ui->btnToggleLog->setArrowType(Qt::DownArrow); ui->btnToggleLog->setArrowType(Qt::DownArrow);
ui->textLog->setVisible(true); ui->textLog->setVisible(true);
ui->btnToggleLog->click(); ui->btnToggleLog->click();
@ -361,14 +361,12 @@ void MainWindow::toggleLogVisible(bool visible)
{ {
if (visible) { if (visible) {
ui->btnToggleLog->setArrowType(Qt::DownArrow); ui->btnToggleLog->setArrowType(Qt::DownArrow);
ui->textLog->setVisible(true);
m_appConfig.setLogExpanded(true);
} else { } else {
ui->btnToggleLog->setArrowType(Qt::RightArrow); ui->btnToggleLog->setArrowType(Qt::RightArrow);
m_expandedSize = size(); m_expandedSize = size();
ui->textLog->setVisible(false);
m_appConfig.setLogExpanded(false);
} }
ui->textLog->setVisible(visible);
Settings::setValue(Settings::Gui::LogExpanded, visible);
// 1 ms delay is to make sure we have left the function before calling updateSize // 1 ms delay is to make sure we have left the function before calling updateSize
QTimer::singleShot(1, this, &MainWindow::updateSize); QTimer::singleShot(1, this, &MainWindow::updateSize);
} }
@ -516,7 +514,7 @@ void MainWindow::resetCore()
void MainWindow::updateSize() void MainWindow::updateSize()
{ {
if (m_appConfig.logExpanded()) { if (Settings::value(Settings::Gui::LogExpanded).toBool()) {
setMaximumHeight(16777215); setMaximumHeight(16777215);
setMaximumWidth(16777215); setMaximumWidth(16777215);
resize(m_expandedSize); resize(m_expandedSize);

View file

@ -73,6 +73,10 @@ QVariant Settings::defaultValue(const QString &key)
return false; return false;
} }
if (key == Gui::LogExpanded) {
return true;
}
return QVariant(); return QVariant();
} }
@ -101,11 +105,11 @@ void Settings::setScope(bool systemScope)
const bool wasWritable = instance()->m_settings->isWritable(); const bool wasWritable = instance()->m_settings->isWritable();
QSettings userSettings(Settings::UserSettingFile, QSettings::IniFormat); QSettings userSettings(Settings::UserSettingFile, QSettings::IniFormat);
userSettings.setValue(Settings::Core::Scope, systemScope); userSettings.setValue(Core::Scope, systemScope);
userSettings.sync(); userSettings.sync();
QSettings systemSettings(Settings::SystemSettingFile, QSettings::IniFormat); QSettings systemSettings(Settings::SystemSettingFile, QSettings::IniFormat);
systemSettings.setValue(Settings::Core::Scope, systemScope); systemSettings.setValue(Core::Scope, systemScope);
systemSettings.sync(); systemSettings.sync();
instance()->initSettings(); instance()->initSettings();

View file

@ -34,6 +34,10 @@ public:
{ {
inline static const auto Scope = QStringLiteral("core/loadFromSystemScope"); inline static const auto Scope = QStringLiteral("core/loadFromSystemScope");
}; };
struct Gui
{
inline static const auto LogExpanded = QStringLiteral("gui/logExpanded");
};
static Settings *instance(); static Settings *instance();
static void setSettingFile(const QString &settingsFile = QString()); static void setSettingFile(const QString &settingsFile = QString());
@ -63,5 +67,10 @@ private:
QSettings *m_settings = nullptr; QSettings *m_settings = nullptr;
QString m_portableSettingsFile = QStringLiteral("%1.conf").arg(kAppName); QString m_portableSettingsFile = QStringLiteral("%1.conf").arg(kAppName);
inline static const QStringList m_validKeys = {Settings::Core::Scope}; // clang-format off
inline static const QStringList m_validKeys = {
Core::Scope
, Gui::LogExpanded
};
// clang-format on
}; };

View file

@ -95,6 +95,7 @@ add_library(${target} STATIC
target_link_libraries( target_link_libraries(
${target} ${target}
common
platform platform
Qt6::Core Qt6::Core
Qt6::Widgets Qt6::Widgets

View file

@ -77,7 +77,7 @@ const char *const AppConfig::m_SettingsName[] = {
"", // 41 = Show dev thanks, obsolete "", // 41 = Show dev thanks, obsolete
"showCloseReminder", "showCloseReminder",
"enableUpdateCheck", "enableUpdateCheck",
"logExpanded", "", // 44, Moved to deskflow settings.
"colorfulIcon", "colorfulIcon",
"requireClientCerts", "requireClientCerts",
}; };
@ -143,7 +143,6 @@ void AppConfig::recallFromCurrentScope()
m_MainWindowSize = getFromCurrentScope<QSize>(kMainWindowSize, [](const QVariant &v) { return v.toSize(); }); m_MainWindowSize = getFromCurrentScope<QSize>(kMainWindowSize, [](const QVariant &v) { return v.toSize(); });
m_ShowCloseReminder = getFromCurrentScope(kShowCloseReminder, m_ShowCloseReminder).toBool(); m_ShowCloseReminder = getFromCurrentScope(kShowCloseReminder, m_ShowCloseReminder).toBool();
m_EnableUpdateCheck = getFromCurrentScope<bool>(kEnableUpdateCheck, [](const QVariant &v) { return v.toBool(); }); m_EnableUpdateCheck = getFromCurrentScope<bool>(kEnableUpdateCheck, [](const QVariant &v) { return v.toBool(); });
m_logExpanded = getFromCurrentScope(kLogExpanded, m_logExpanded).toBool();
m_colorfulTrayIcon = getFromCurrentScope(kColorfulIcon, m_colorfulTrayIcon).toBool(); m_colorfulTrayIcon = getFromCurrentScope(kColorfulIcon, m_colorfulTrayIcon).toBool();
} }
@ -200,7 +199,6 @@ void AppConfig::commit()
setInCurrentScope(kMainWindowPosition, m_MainWindowPosition); setInCurrentScope(kMainWindowPosition, m_MainWindowPosition);
setInCurrentScope(kShowCloseReminder, m_ShowCloseReminder); setInCurrentScope(kShowCloseReminder, m_ShowCloseReminder);
setInCurrentScope(kEnableUpdateCheck, m_EnableUpdateCheck); setInCurrentScope(kEnableUpdateCheck, m_EnableUpdateCheck);
setInCurrentScope(kLogExpanded, m_logExpanded);
setInCurrentScope(kColorfulIcon, m_colorfulTrayIcon); setInCurrentScope(kColorfulIcon, m_colorfulTrayIcon);
setInCurrentScope(kRequireClientCert, m_RequireClientCert); setInCurrentScope(kRequireClientCert, m_RequireClientCert);
} }
@ -574,11 +572,6 @@ std::optional<bool> AppConfig::enableUpdateCheck() const
return m_EnableUpdateCheck; return m_EnableUpdateCheck;
} }
bool AppConfig::logExpanded() const
{
return m_logExpanded;
}
bool AppConfig::colorfulTrayIcon() const bool AppConfig::colorfulTrayIcon() const
{ {
return m_colorfulTrayIcon; return m_colorfulTrayIcon;
@ -756,13 +749,6 @@ void AppConfig::setEnableUpdateCheck(bool value)
m_EnableUpdateCheck = value; m_EnableUpdateCheck = value;
} }
void AppConfig::setLogExpanded(bool expanded)
{
if (expanded == m_logExpanded)
return;
m_logExpanded = expanded;
}
void AppConfig::setColorfulTrayIcon(bool colorful) void AppConfig::setColorfulTrayIcon(bool colorful)
{ {
if (colorful == m_colorfulTrayIcon) if (colorful == m_colorfulTrayIcon)

View file

@ -99,7 +99,7 @@ private:
// 41 = show dev thanks, obsolete // 41 = show dev thanks, obsolete
kShowCloseReminder = 42, kShowCloseReminder = 42,
kEnableUpdateCheck = 43, kEnableUpdateCheck = 43,
kLogExpanded = 44, // 44 = LogExpanded, Moved to deskflow settings
kColorfulIcon = 45, kColorfulIcon = 45,
kRequireClientCert = 46 kRequireClientCert = 46
}; };
@ -175,7 +175,6 @@ public:
std::optional<QPoint> mainWindowPosition() const; std::optional<QPoint> mainWindowPosition() const;
bool showCloseReminder() const; bool showCloseReminder() const;
std::optional<bool> enableUpdateCheck() const; std::optional<bool> enableUpdateCheck() const;
bool logExpanded() const;
bool colorfulTrayIcon() const; bool colorfulTrayIcon() const;
// //
@ -216,7 +215,6 @@ public:
void setMainWindowPosition(const QPoint &position); void setMainWindowPosition(const QPoint &position);
void setShowCloseReminder(bool show); void setShowCloseReminder(bool show);
void setEnableUpdateCheck(bool value); void setEnableUpdateCheck(bool value);
void setLogExpanded(bool expanded);
void setColorfulTrayIcon(bool color); void setColorfulTrayIcon(bool color);
/// @brief Sets the user preference to load from SystemScope. /// @brief Sets the user preference to load from SystemScope.
@ -321,7 +319,6 @@ private:
bool m_LoadFromSystemScope = false; bool m_LoadFromSystemScope = false;
bool m_ShowCloseReminder = true; bool m_ShowCloseReminder = true;
std::optional<bool> m_EnableUpdateCheck; std::optional<bool> m_EnableUpdateCheck;
bool m_logExpanded = true;
bool m_colorfulTrayIcon = false; bool m_colorfulTrayIcon = false;
bool m_RequireClientCert = true; bool m_RequireClientCert = true;