refactor: Move messages client connection error to common, new common/Enums
This commit is contained in:
parent
2485916ad1
commit
1ebcab60e2
7 changed files with 38 additions and 18 deletions
|
|
@ -12,6 +12,7 @@ unset(CLIENT_BINARY)
|
||||||
unset(SERVER_BINARY)
|
unset(SERVER_BINARY)
|
||||||
|
|
||||||
add_library(common STATIC
|
add_library(common STATIC
|
||||||
|
Enums.h
|
||||||
ExitCodes.h
|
ExitCodes.h
|
||||||
I18N.h
|
I18N.h
|
||||||
I18N.cpp
|
I18N.cpp
|
||||||
|
|
|
||||||
23
src/lib/common/Enums.h
Normal file
23
src/lib/common/Enums.h
Normal 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
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "Styles.h"
|
#include "Styles.h"
|
||||||
#include "VersionInfo.h"
|
#include "VersionInfo.h"
|
||||||
|
|
||||||
|
#include "common/Enums.h"
|
||||||
#include "common/Settings.h"
|
#include "common/Settings.h"
|
||||||
#include "common/UrlConstants.h"
|
#include "common/UrlConstants.h"
|
||||||
|
|
||||||
|
|
@ -183,9 +184,9 @@ void showFirstConnectedMessage(QWidget *parent, bool closeToTray, bool enableSer
|
||||||
QMessageBox::information(parent, title, message);
|
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)
|
if (error == NoError)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -216,7 +217,7 @@ void showClientConnectError(QWidget *parent, ClientError error, const QString &a
|
||||||
|
|
||||||
auto title = QObject::tr("%1 Connection Error").arg(kAppName);
|
auto title = QObject::tr("%1 Connection Error").arg(kAppName);
|
||||||
|
|
||||||
if (error != ClientError::HostnameError) {
|
if (error != HostnameError) {
|
||||||
QMessageBox::warning(parent, title, message);
|
QMessageBox::warning(parent, title, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,12 @@
|
||||||
#include <QMessageLogContext>
|
#include <QMessageLogContext>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <common/Enums.h>
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
namespace deskflow::gui::messages {
|
namespace deskflow::gui::messages {
|
||||||
|
|
||||||
enum class ClientError
|
|
||||||
{
|
|
||||||
NoError,
|
|
||||||
AlreadyConnected,
|
|
||||||
HostnameError,
|
|
||||||
GenericError
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class NewClientPromptResult
|
enum class NewClientPromptResult
|
||||||
{
|
{
|
||||||
Add,
|
Add,
|
||||||
|
|
@ -37,7 +31,7 @@ void showFirstConnectedMessage(QWidget *parent, bool closeToTray, bool enableSer
|
||||||
|
|
||||||
void showCloseReminder(QWidget *parent);
|
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
|
NewClientPromptResult
|
||||||
showNewClientPrompt(QWidget *parent, const QString &clientName, bool serverRequiresPeerAuth = false);
|
showNewClientPrompt(QWidget *parent, const QString &clientName, bool serverRequiresPeerAuth = false);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace deskflow::gui {
|
||||||
// ClientConnection::Deps
|
// 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);
|
messages::showClientConnectError(parent, error, address);
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ void ClientConnection::handleLogLine(const QString &logLine)
|
||||||
|
|
||||||
void ClientConnection::showMessage(const QString &logLine)
|
void ClientConnection::showMessage(const QString &logLine)
|
||||||
{
|
{
|
||||||
using enum messages::ClientError;
|
using enum deskflow::client::ErrorType;
|
||||||
|
|
||||||
if (logLine.isEmpty())
|
if (logLine.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Enums.h"
|
||||||
#include "gui/Messages.h"
|
#include "gui/Messages.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
@ -25,7 +26,7 @@ public:
|
||||||
struct Deps
|
struct Deps
|
||||||
{
|
{
|
||||||
virtual ~Deps() = default;
|
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>())
|
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 error the type of error being reported
|
||||||
* @param address of the host
|
* @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();
|
void messageShowing();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ class QWidget;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
using testing::NiceMock;
|
using testing::NiceMock;
|
||||||
using namespace deskflow::gui;
|
using namespace deskflow::gui;
|
||||||
using enum messages::ClientError;
|
using enum deskflow::client::ErrorType;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct DepsMock : public ClientConnection::Deps
|
struct DepsMock : public ClientConnection::Deps
|
||||||
{
|
{
|
||||||
MOCK_METHOD(
|
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)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue