From af17b14224b3d161cb650325eaebe0b4116d6b41 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Mon, 10 Mar 2025 00:26:41 -0400 Subject: [PATCH] refactor: move serverconfigdialog visible to Settings --- src/apps/deskflow-gui/MainWindow.cpp | 6 +- src/apps/deskflow-gui/MainWindow.h | 2 - src/lib/common/Settings.h | 64 ++++++++++--------- src/lib/gui/CMakeLists.txt | 1 - src/lib/gui/config/ServerConfigDialogState.h | 34 ---------- src/lib/gui/core/ServerConnection.cpp | 11 ++-- src/lib/gui/core/ServerConnection.h | 5 +- .../gui/core/ServerConnectionTests.cpp | 10 ++- 8 files changed, 45 insertions(+), 88 deletions(-) delete mode 100644 src/lib/gui/config/ServerConfigDialogState.h diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index 895a37c33..85574b7e1 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -65,7 +65,7 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) m_appConfig(appConfig), m_serverConfig(appConfig, *this), m_coreProcess(m_serverConfig), - m_serverConnection(this, m_serverConfig, m_serverConfigDialogState), + m_serverConnection(this, m_serverConfig), m_clientConnection(this), m_tlsUtility(this), m_trayIcon{new QSystemTrayIcon(this)}, @@ -615,12 +615,12 @@ void MainWindow::updateSecurityIcon(bool visible) void MainWindow::serverConnectionConfigureClient(const QString &clientName) { - m_serverConfigDialogState.setVisible(true); + Settings::setValue(Settings::Server::ConfigVisible, true); ServerConfigDialog dialog(this, m_serverConfig); if (dialog.addClient(clientName) && dialog.exec() == QDialog::Accepted) { m_coreProcess.restart(); } - m_serverConfigDialogState.setVisible(false); + Settings::setValue(Settings::Server::ConfigVisible, false); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/apps/deskflow-gui/MainWindow.h b/src/apps/deskflow-gui/MainWindow.h index 4718ae22e..46bc6e733 100644 --- a/src/apps/deskflow-gui/MainWindow.h +++ b/src/apps/deskflow-gui/MainWindow.h @@ -20,7 +20,6 @@ #include "VersionChecker.h" #include "gui/config/AppConfig.h" #include "gui/config/ConfigScopes.h" -#include "gui/config/ServerConfigDialogState.h" #include "gui/core/ClientConnection.h" #include "gui/core/CoreProcess.h" #include "gui/core/ServerConnection.h" @@ -195,7 +194,6 @@ private: VersionChecker m_versionChecker; bool m_secureSocket = false; - deskflow::gui::config::ServerConfigDialogState m_serverConfigDialogState; bool m_saveOnExit = true; deskflow::gui::core::WaylandWarnings m_waylandWarnings; deskflow::gui::ConfigScopes &m_configScopes; diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index 9d14225d4..3f9513c03 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -76,6 +76,7 @@ public: struct Server { inline static const auto Binary = QStringLiteral("server/binary"); + inline static const auto ConfigVisible = QStringLiteral("server/configVisible"); inline static const auto ExternalConfig = QStringLiteral("server/externalConfig"); inline static const auto ExternalConfigFile = QStringLiteral("server/externalConfigFile"); }; @@ -163,37 +164,38 @@ private: }; inline static const QStringList m_validKeys = { - Client::Binary - , Client::InvertScrollDirection - , Client::LanguageSync - , Client::RemoteHost - , Core::CoreMode - , Core::ElevateMode - , Core::Interface - , Core::LastVersion - , Core::Port - , Core::PreventSleep - , Core::ProcessMode - , Core::Scope - , Core::ScreenName - , Core::StartedBefore - , Log::File - , Log::Level - , Log::ToFile - , Gui::Autohide - , Gui::AutoUpdateCheck - , Gui::CloseReminder - , Gui::CloseToTray - , Gui::LogExpanded - , Gui::SymbolicTrayIcon - , Gui::WindowGeometry - , Security::Certificate - , Security::CheckPeers - , Security::KeySize - , Security::TlsEnabled - , Server::Binary - , Server::ExternalConfig - , Server::ExternalConfigFile + Settings::Client::Binary + , Settings::Client::InvertScrollDirection + , Settings::Client::LanguageSync + , Settings::Client::RemoteHost + , Settings::Core::CoreMode + , Settings::Core::ElevateMode + , Settings::Core::Interface + , Settings::Core::LastVersion + , Settings::Core::Port + , Settings::Core::PreventSleep + , Settings::Core::ProcessMode + , Settings::Core::Scope + , Settings::Core::ScreenName + , Settings::Core::StartedBefore + , Settings::Log::File + , Settings::Log::Level + , Settings::Log::ToFile + , Settings::Gui::Autohide + , Settings::Gui::AutoUpdateCheck + , Settings::Gui::CloseReminder + , Settings::Gui::CloseToTray + , Settings::Gui::LogExpanded + , Settings::Gui::SymbolicTrayIcon + , Settings::Gui::WindowGeometry + , Settings::Security::Certificate + , Settings::Security::CheckPeers + , Settings::Security::KeySize + , Settings::Security::TlsEnabled + , Settings::Server::Binary + , Settings::Server::ConfigVisible + , Settings::Server::ExternalConfig + , Settings::Server::ExternalConfigFile }; // clang-format on diff --git a/src/lib/gui/CMakeLists.txt b/src/lib/gui/CMakeLists.txt index 03548d89b..3b6a841cf 100644 --- a/src/lib/gui/CMakeLists.txt +++ b/src/lib/gui/CMakeLists.txt @@ -45,7 +45,6 @@ add_library(${target} STATIC config/ScreenConfig.h config/ScreenList.cpp config/ScreenList.h - config/ServerConfigDialogState.h core/ClientConnection.cpp core/ClientConnection.h core/CommandProcess.cpp diff --git a/src/lib/gui/config/ServerConfigDialogState.h b/src/lib/gui/config/ServerConfigDialogState.h deleted file mode 100644 index 51e063482..000000000 --- a/src/lib/gui/config/ServerConfigDialogState.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2021 Symless Ltd. - * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception - */ - -#pragma once - -namespace deskflow::gui::config { - -/** - * @brief Represents the state of the server config dialog. - * - * Future design consideration: Once moving the server config dialog to the GUI - * lib, we can probably just pass a reference to that rather than needing an - * object to track it's state. - */ -class ServerConfigDialogState -{ -public: - bool isVisible() const - { - return m_isVisible; - } - void setVisible(bool isVisible) - { - m_isVisible = isVisible; - } - -private: - bool m_isVisible = false; -}; - -} // namespace deskflow::gui::config diff --git a/src/lib/gui/core/ServerConnection.cpp b/src/lib/gui/core/ServerConnection.cpp index a76f701bd..06b627cd5 100644 --- a/src/lib/gui/core/ServerConnection.cpp +++ b/src/lib/gui/core/ServerConnection.cpp @@ -7,8 +7,9 @@ #include "ServerConnection.h" #include "ServerMessage.h" + #include "common/Settings.h" -#include "gui/config/ServerConfigDialogState.h" + #include "messages.h" #include @@ -31,13 +32,9 @@ messages::NewClientPromptResult ServerConnection::Deps::showNewClientPrompt( // ServerConnection // -ServerConnection::ServerConnection( - QWidget *parent, IServerConfig &serverConfig, const config::ServerConfigDialogState &serverConfigDialogState, - std::shared_ptr deps -) +ServerConnection::ServerConnection(QWidget *parent, IServerConfig &serverConfig, std::shared_ptr deps) : m_pParent(parent), m_serverConfig(serverConfig), - m_serverConfigDialogState(serverConfigDialogState), m_pDeps(deps) { } @@ -55,7 +52,7 @@ void ServerConnection::handleLogLine(const QString &logLine) return; } - if (m_serverConfigDialogState.isVisible()) { + if (Settings::value(Settings::Server::ConfigVisible).toBool()) { qDebug("server config dialog visible, skipping new client prompt"); return; } diff --git a/src/lib/gui/core/ServerConnection.h b/src/lib/gui/core/ServerConnection.h index 36c89bb4b..9d6c9257d 100644 --- a/src/lib/gui/core/ServerConnection.h +++ b/src/lib/gui/core/ServerConnection.h @@ -10,7 +10,6 @@ #include #include "gui/config/IServerConfig.h" -#include "gui/config/ServerConfigDialogState.h" #include "gui/messages.h" namespace deskflow::gui { @@ -29,8 +28,7 @@ public: }; explicit ServerConnection( - QWidget *parent, IServerConfig &serverConfig, const config::ServerConfigDialogState &serverConfigDialogState, - std::shared_ptr deps = std::make_shared() + QWidget *parent, IServerConfig &serverConfig, std::shared_ptr deps = std::make_shared() ); void handleLogLine(const QString &logLine); @@ -43,7 +41,6 @@ private: QWidget *m_pParent; IServerConfig &m_serverConfig; - const config::ServerConfigDialogState &m_serverConfigDialogState; std::shared_ptr m_pDeps; QStringList m_receivedClients; bool m_messageShowing = false; diff --git a/src/test/unittests/gui/core/ServerConnectionTests.cpp b/src/test/unittests/gui/core/ServerConnectionTests.cpp index c75a9b05f..9d30279de 100644 --- a/src/test/unittests/gui/core/ServerConnectionTests.cpp +++ b/src/test/unittests/gui/core/ServerConnectionTests.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception */ -#include "gui/config/ServerConfigDialogState.h" #include "gui/core/ServerConnection.h" #include "shared/gui/mocks/ServerConfigMock.h" @@ -36,12 +35,11 @@ class ServerConnectionTests : public testing::Test public: std::shared_ptr m_pDeps = std::make_shared>(); NiceMock m_serverConfig; - config::ServerConfigDialogState m_serverConfigDialogState; }; TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt) { - ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps); + ServerConnection serverConnection(nullptr, m_serverConfig, m_pDeps); QString clientName = "test client"; EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, clientName, true)).Times(0); @@ -51,7 +49,7 @@ TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt) TEST_F(ServerConnectionTests, handleLogLine_ignoredClient_shouldNotShowPrompt) { - ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps); + ServerConnection serverConnection(nullptr, m_serverConfig, m_pDeps); ON_CALL(*m_pDeps, showNewClientPrompt(_, _, false)) .WillByDefault(testing::Return(messages::NewClientPromptResult::Ignore)); serverConnection.handleLogLine(R"(unrecognised client name "stub")"); @@ -63,7 +61,7 @@ TEST_F(ServerConnectionTests, handleLogLine_ignoredClient_shouldNotShowPrompt) TEST_F(ServerConnectionTests, handleLogLine_serverConfigFull_shouldNotShowPrompt) { - ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps); + ServerConnection serverConnection(nullptr, m_serverConfig, m_pDeps); ON_CALL(m_serverConfig, isFull()).WillByDefault(testing::Return(true)); EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0); @@ -73,7 +71,7 @@ TEST_F(ServerConnectionTests, handleLogLine_serverConfigFull_shouldNotShowPrompt TEST_F(ServerConnectionTests, handleLogLine_screenExists_shouldNotShowPrompt) { - ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps); + ServerConnection serverConnection(nullptr, m_serverConfig, m_pDeps); ON_CALL(m_serverConfig, screenExists(_)).WillByDefault(testing::Return(true)); EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0);