refactor: Move messages client connection error to common, new common/Enums

This commit is contained in:
sithlord48
2025-11-28 12:55:57 -05:00
committed by Nick Bolton
parent 2485916ad1
commit 1ebcab60e2
7 changed files with 38 additions and 18 deletions

View File

@ -12,6 +12,7 @@ unset(CLIENT_BINARY)
unset(SERVER_BINARY)
add_library(common STATIC
Enums.h
ExitCodes.h
I18N.h
I18N.cpp

23
src/lib/common/Enums.h Normal file
View File

@ -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 <QObject>
namespace deskflow::client {
Q_NAMESPACE
enum class ErrorType : uint8_t
{
NoError,
AlreadyConnected,
HostnameError,
GenericError
};
Q_ENUM_NS(ErrorType)
} // namespace deskflow::client

View File

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

View File

@ -9,18 +9,12 @@
#include <QMessageLogContext>
#include <QString>
#include <common/Enums.h>
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);

View File

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

View File

@ -6,6 +6,7 @@
#pragma once
#include "common/Enums.h"
#include "gui/Messages.h"
#include <QObject>
@ -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> deps = std::make_shared<Deps>())
@ -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:

View File

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