From 1ebcab60e269973b774cf27d2e1939b309d7d455 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Fri, 28 Nov 2025 12:55:57 -0500 Subject: [PATCH] refactor: Move messages client connection error to common, new common/Enums --- src/lib/common/CMakeLists.txt | 1 + src/lib/common/Enums.h | 23 +++++++++++++++++++ src/lib/gui/Messages.cpp | 7 +++--- src/lib/gui/Messages.h | 12 +++------- src/lib/gui/core/ClientConnection.cpp | 4 ++-- src/lib/gui/core/ClientConnection.h | 5 ++-- .../gui/core/ClientConnectionTests.cpp | 4 ++-- 7 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 src/lib/common/Enums.h diff --git a/src/lib/common/CMakeLists.txt b/src/lib/common/CMakeLists.txt index 5716a0551..c458d162c 100644 --- a/src/lib/common/CMakeLists.txt +++ b/src/lib/common/CMakeLists.txt @@ -12,6 +12,7 @@ unset(CLIENT_BINARY) unset(SERVER_BINARY) add_library(common STATIC + Enums.h ExitCodes.h I18N.h I18N.cpp diff --git a/src/lib/common/Enums.h b/src/lib/common/Enums.h new file mode 100644 index 000000000..362ecb614 --- /dev/null +++ b/src/lib/common/Enums.h @@ -0,0 +1,23 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers + * SPDX-FileCopyrightText: (C) 2010 - 2018, 2024 - 2025 Symless Ltd. + * SPDX-FileCopyrightText: (C) 2002 - 2007 Chris Schoeneman + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#pragma once + +#include + +namespace deskflow::client { +Q_NAMESPACE +enum class ErrorType : uint8_t +{ + NoError, + AlreadyConnected, + HostnameError, + GenericError +}; +Q_ENUM_NS(ErrorType) +} // namespace deskflow::client diff --git a/src/lib/gui/Messages.cpp b/src/lib/gui/Messages.cpp index 416f4d53b..bb5878b06 100644 --- a/src/lib/gui/Messages.cpp +++ b/src/lib/gui/Messages.cpp @@ -10,6 +10,7 @@ #include "Styles.h" #include "VersionInfo.h" +#include "common/Enums.h" #include "common/Settings.h" #include "common/UrlConstants.h" @@ -183,9 +184,9 @@ void showFirstConnectedMessage(QWidget *parent, bool closeToTray, bool enableSer QMessageBox::information(parent, title, message); } -void showClientConnectError(QWidget *parent, ClientError error, const QString &address) +void showClientConnectError(QWidget *parent, deskflow::client::ErrorType error, const QString &address) { - using enum ClientError; + using enum deskflow::client::ErrorType; if (error == NoError) return; @@ -216,7 +217,7 @@ void showClientConnectError(QWidget *parent, ClientError error, const QString &a auto title = QObject::tr("%1 Connection Error").arg(kAppName); - if (error != ClientError::HostnameError) { + if (error != HostnameError) { QMessageBox::warning(parent, title, message); return; } diff --git a/src/lib/gui/Messages.h b/src/lib/gui/Messages.h index 27c23182b..2b0431e2e 100644 --- a/src/lib/gui/Messages.h +++ b/src/lib/gui/Messages.h @@ -9,18 +9,12 @@ #include #include +#include + class QWidget; namespace deskflow::gui::messages { -enum class ClientError -{ - NoError, - AlreadyConnected, - HostnameError, - GenericError -}; - enum class NewClientPromptResult { Add, @@ -37,7 +31,7 @@ void showFirstConnectedMessage(QWidget *parent, bool closeToTray, bool enableSer void showCloseReminder(QWidget *parent); -void showClientConnectError(QWidget *parent, ClientError error, const QString &address); +void showClientConnectError(QWidget *parent, deskflow::client::ErrorType error, const QString &address); NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName, bool serverRequiresPeerAuth = false); diff --git a/src/lib/gui/core/ClientConnection.cpp b/src/lib/gui/core/ClientConnection.cpp index 8b83c890c..4721ce953 100644 --- a/src/lib/gui/core/ClientConnection.cpp +++ b/src/lib/gui/core/ClientConnection.cpp @@ -18,7 +18,7 @@ namespace deskflow::gui { // ClientConnection::Deps // -void ClientConnection::Deps::showError(QWidget *parent, messages::ClientError error, const QString &address) const +void ClientConnection::Deps::showError(QWidget *parent, deskflow::client::ErrorType error, const QString &address) const { messages::showClientConnectError(parent, error, address); } @@ -54,7 +54,7 @@ void ClientConnection::handleLogLine(const QString &logLine) void ClientConnection::showMessage(const QString &logLine) { - using enum messages::ClientError; + using enum deskflow::client::ErrorType; if (logLine.isEmpty()) return; diff --git a/src/lib/gui/core/ClientConnection.h b/src/lib/gui/core/ClientConnection.h index 6afa3d7c7..205ebe7ed 100644 --- a/src/lib/gui/core/ClientConnection.h +++ b/src/lib/gui/core/ClientConnection.h @@ -6,6 +6,7 @@ #pragma once +#include "common/Enums.h" #include "gui/Messages.h" #include @@ -25,7 +26,7 @@ public: struct Deps { virtual ~Deps() = default; - virtual void showError(QWidget *parent, messages::ClientError error, const QString &address) const; + virtual void showError(QWidget *parent, deskflow::client::ErrorType error, const QString &address) const; }; explicit ClientConnection(QWidget *parent, std::shared_ptr deps = std::make_shared()) @@ -48,7 +49,7 @@ Q_SIGNALS: * @param error the type of error being reported * @param address of the host */ - void requestShowError(deskflow::gui::messages::ClientError error, const QString &address); + void requestShowError(deskflow::client::ErrorType error, const QString &address); void messageShowing(); private: diff --git a/src/unittests/legacytests/legacytests/gui/core/ClientConnectionTests.cpp b/src/unittests/legacytests/legacytests/gui/core/ClientConnectionTests.cpp index 263941451..ab25e02fc 100644 --- a/src/unittests/legacytests/legacytests/gui/core/ClientConnectionTests.cpp +++ b/src/unittests/legacytests/legacytests/gui/core/ClientConnectionTests.cpp @@ -15,14 +15,14 @@ class QWidget; using testing::_; using testing::NiceMock; using namespace deskflow::gui; -using enum messages::ClientError; +using enum deskflow::client::ErrorType; namespace { struct DepsMock : public ClientConnection::Deps { MOCK_METHOD( - void, showError, (QWidget * parent, messages::ClientError error, const QString &address), (const, override) + void, showError, (QWidget * parent, deskflow::client::ErrorType error, const QString &address), (const, override) ); };