refactor: move serverconfigdialog visible to Settings

This commit is contained in:
sithlord48
2025-03-10 00:26:41 -04:00
committed by Nick Bolton
parent 1e9f92c93f
commit af17b14224
8 changed files with 45 additions and 88 deletions

View File

@ -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);
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -7,8 +7,9 @@
#include "ServerConnection.h"
#include "ServerMessage.h"
#include "common/Settings.h"
#include "gui/config/ServerConfigDialogState.h"
#include "messages.h"
#include <QMessageBox>
@ -31,13 +32,9 @@ messages::NewClientPromptResult ServerConnection::Deps::showNewClientPrompt(
// ServerConnection
//
ServerConnection::ServerConnection(
QWidget *parent, IServerConfig &serverConfig, const config::ServerConfigDialogState &serverConfigDialogState,
std::shared_ptr<Deps> deps
)
ServerConnection::ServerConnection(QWidget *parent, IServerConfig &serverConfig, std::shared_ptr<Deps> 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;
}

View File

@ -10,7 +10,6 @@
#include <QStringList>
#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> deps = std::make_shared<Deps>()
QWidget *parent, IServerConfig &serverConfig, std::shared_ptr<Deps> deps = std::make_shared<Deps>()
);
void handleLogLine(const QString &logLine);
@ -43,7 +41,6 @@ private:
QWidget *m_pParent;
IServerConfig &m_serverConfig;
const config::ServerConfigDialogState &m_serverConfigDialogState;
std::shared_ptr<Deps> m_pDeps;
QStringList m_receivedClients;
bool m_messageShowing = false;

View File

@ -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<DepsMock> m_pDeps = std::make_shared<NiceMock<DepsMock>>();
NiceMock<ServerConfigMock> 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);