refactor: Unify ENetworkProtocol and ServerProtocol into new enum Class NetworkProtocol in new file base/NetworkProtocol.h

This commit is contained in:
sithlord48 2025-07-30 20:20:59 -04:00 committed by Nick Bolton
parent 9673943556
commit f73d098b1f
9 changed files with 45 additions and 45 deletions

View file

@ -25,6 +25,7 @@ add_library(base STATIC
Log.cpp Log.cpp
Log.h Log.h
LogLevel.h LogLevel.h
NetworkProtocol.h
Path.cpp Path.cpp
Path.h Path.h
PriorityQueue.h PriorityQueue.h

View file

@ -0,0 +1,13 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
enum class NetworkProtocol
{
Synergy,
Barrier
};

View file

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "base/EventTypes.h" #include "base/EventTypes.h"
#include "base/NetworkProtocol.h"
#include <vector> #include <vector>
@ -72,13 +73,4 @@ inline static const auto s_bottomRightCornerMask = 1 << 3;
inline static const auto s_allCornersMask = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3; inline static const auto s_allCornersMask = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3;
//@} //@}
//! @name Network protocol
//@{
enum class ENetworkProtocol
{
kSynergy,
kBarrier
};
//@}
#undef OPTION_CODE #undef OPTION_CODE

View file

@ -165,7 +165,7 @@ void ServerConfig::recall()
haveHeartbeat(settings().value("hasHeartbeat", false).toBool()); haveHeartbeat(settings().value("hasHeartbeat", false).toBool());
setHeartbeat(settings().value("heartbeat", 5000).toInt()); setHeartbeat(settings().value("heartbeat", 5000).toInt());
setProtocol(static_cast<ServerProtocol>(settings().value("protocol", static_cast<int>(protocol())).toInt())); setProtocol(static_cast<NetworkProtocol>(settings().value("protocol", static_cast<int>(protocol())).toInt()));
setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool()); setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool());
setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool()); setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool());
haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool()); haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool());
@ -224,7 +224,7 @@ int ServerConfig::adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) co
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config)
{ {
using enum deskflow::gui::ServerProtocol; using enum NetworkProtocol;
outStream << "section: screens" << Qt::endl; outStream << "section: screens" << Qt::endl;
@ -264,9 +264,9 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config)
if (config.hasHeartbeat()) if (config.hasHeartbeat())
outStream << "\t" << "heartbeat = " << config.heartbeat() << Qt::endl; outStream << "\t" << "heartbeat = " << config.heartbeat() << Qt::endl;
if (config.protocol() == kSynergy) { if (config.protocol() == Synergy) {
outStream << "\t" << "protocol = synergy" << Qt::endl; outStream << "\t" << "protocol = synergy" << Qt::endl;
} else if (config.protocol() == kBarrier) { } else if (config.protocol() == Barrier) {
outStream << "\t" << "protocol = barrier" << Qt::endl; outStream << "\t" << "protocol = barrier" << Qt::endl;
} else { } else {
qFatal("unrecognized protocol when writing config"); qFatal("unrecognized protocol when writing config");

View file

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "Hotkey.h" #include "Hotkey.h"
#include "base/NetworkProtocol.h"
#include "gui/config/IServerConfig.h" #include "gui/config/IServerConfig.h"
#include "gui/config/ScreenConfig.h" #include "gui/config/ScreenConfig.h"
#include "gui/config/ScreenList.h" #include "gui/config/ScreenList.h"
@ -26,14 +27,8 @@ class MainWindow;
namespace deskflow::gui { namespace deskflow::gui {
enum class ServerProtocol
{
kSynergy,
kBarrier
};
// The default protocol was decided by a community vote. // The default protocol was decided by a community vote.
const auto kDefaultProtocol = ServerProtocol::kBarrier; const auto kDefaultProtocol = NetworkProtocol::Barrier;
} // namespace deskflow::gui } // namespace deskflow::gui
@ -47,8 +42,6 @@ enum class ScreenAddResults
class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig
{ {
using ServerProtocol = deskflow::gui::ServerProtocol;
friend class ServerConfigDialog; friend class ServerConfigDialog;
friend QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config); friend QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
@ -85,7 +78,7 @@ public:
{ {
return m_Heartbeat; return m_Heartbeat;
} }
ServerProtocol protocol() const NetworkProtocol protocol() const
{ {
return m_Protocol; return m_Protocol;
} }
@ -197,7 +190,7 @@ private:
{ {
m_Heartbeat = val; m_Heartbeat = val;
} }
void setProtocol(ServerProtocol val) void setProtocol(NetworkProtocol val)
{ {
m_Protocol = val; m_Protocol = val;
} }
@ -261,7 +254,7 @@ private:
private: private:
bool m_HasHeartbeat = false; bool m_HasHeartbeat = false;
int m_Heartbeat = 0; int m_Heartbeat = 0;
ServerProtocol m_Protocol = deskflow::gui::kDefaultProtocol; NetworkProtocol m_Protocol = deskflow::gui::kDefaultProtocol;
bool m_RelativeMouseMoves = false; bool m_RelativeMouseMoves = false;
bool m_Win32KeepForeground = false; bool m_Win32KeepForeground = false;
bool m_HasSwitchDelay = false; bool m_HasSwitchDelay = false;

View file

@ -9,6 +9,7 @@
#include "ServerConfigDialog.h" #include "ServerConfigDialog.h"
#include "ui_ServerConfigDialog.h" #include "ui_ServerConfigDialog.h"
#include "base/NetworkProtocol.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "dialogs/ActionDialog.h" #include "dialogs/ActionDialog.h"
#include "dialogs/HotkeyDialog.h" #include "dialogs/HotkeyDialog.h"
@ -20,7 +21,7 @@
#include <QMessageBox> #include <QMessageBox>
using enum ScreenConfig::SwitchCorner; using enum ScreenConfig::SwitchCorner;
using ServerProtocol = deskflow::gui::ServerProtocol; using enum NetworkProtocol;
ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config) ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
@ -67,8 +68,8 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config)
ui->btnBrowseConfigFile->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen)); ui->btnBrowseConfigFile->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen));
ui->lineConfigFile->setText(serverConfig().configFile()); ui->lineConfigFile->setText(serverConfig().configFile());
ui->rbProtocolSynergy->setChecked(serverConfig().protocol() == ServerProtocol::kSynergy); ui->rbProtocolSynergy->setChecked(serverConfig().protocol() == NetworkProtocol::Synergy);
ui->rbProtocolBarrier->setChecked(serverConfig().protocol() == ServerProtocol::kBarrier); ui->rbProtocolBarrier->setChecked(serverConfig().protocol() == NetworkProtocol::Barrier);
connect(ui->rbProtocolBarrier, &QRadioButton::toggled, this, &ServerConfigDialog::toggleProtocol); connect(ui->rbProtocolBarrier, &QRadioButton::toggled, this, &ServerConfigDialog::toggleProtocol);
ui->cbHeartbeat->setChecked(serverConfig().hasHeartbeat()); ui->cbHeartbeat->setChecked(serverConfig().hasHeartbeat());
@ -359,7 +360,7 @@ void ServerConfigDialog::toggleRelativeMouseMoves(bool enabled)
void ServerConfigDialog::toggleProtocol() void ServerConfigDialog::toggleProtocol()
{ {
ServerProtocol proto = ui->rbProtocolBarrier->isChecked() ? ServerProtocol::kBarrier : ServerProtocol::kSynergy; auto proto = ui->rbProtocolBarrier->isChecked() ? NetworkProtocol::Barrier : NetworkProtocol::Synergy;
serverConfig().setProtocol(proto); serverConfig().setProtocol(proto);
onChange(); onChange();
} }

View file

@ -1311,11 +1311,11 @@ std::string Config::getOptionValue(OptionID id, OptionValue value)
return result; return result;
} }
if (id == kOptionProtocol) { if (id == kOptionProtocol) {
using enum ENetworkProtocol; using enum NetworkProtocol;
const auto enumValue = static_cast<ENetworkProtocol>(value); const auto enumValue = static_cast<NetworkProtocol>(value);
if (enumValue == kSynergy) { if (enumValue == Synergy) {
return kSynergyProtocolOption; return kSynergyProtocolOption;
} else if (enumValue == kBarrier) { } else if (enumValue == Barrier) {
return kBarrierProtocolOption; return kBarrierProtocolOption;
} else { } else {
throw XInvalidProtocol(); throw XInvalidProtocol();
@ -1809,9 +1809,9 @@ OptionValue ConfigReadContext::parseCorner(const std::string &arg) const
OptionValue ConfigReadContext::parseProtocol(const std::string &args) const OptionValue ConfigReadContext::parseProtocol(const std::string &args) const
{ {
if (CaselessCmp::equal(args, kSynergyProtocolOption)) { if (CaselessCmp::equal(args, kSynergyProtocolOption)) {
return static_cast<OptionValue>(ENetworkProtocol::kSynergy); return static_cast<OptionValue>(NetworkProtocol::Synergy);
} else if (CaselessCmp::equal(args, kBarrierProtocolOption)) { } else if (CaselessCmp::equal(args, kBarrierProtocolOption)) {
return static_cast<OptionValue>(ENetworkProtocol::kBarrier); return static_cast<OptionValue>(NetworkProtocol::Barrier);
} }
throw XConfigRead(*this, "invalid protocol argument \"%{1}\"", args); throw XConfigRead(*this, "invalid protocol argument \"%{1}\"", args);
} }

View file

@ -275,10 +275,10 @@ void Server::disconnect()
std::string Server::protocolString() const std::string Server::protocolString() const
{ {
using enum ENetworkProtocol; using enum NetworkProtocol;
if (m_protocol == kSynergy) { if (m_protocol == Synergy) {
return kSynergyProtocolName; return kSynergyProtocolName;
} else if (m_protocol == kBarrier) { } else if (m_protocol == Barrier) {
return kBarrierProtocolName; return kBarrierProtocolName;
} }
throw XInvalidProtocol(); throw XInvalidProtocol();
@ -1074,12 +1074,12 @@ void Server::processOptions()
const OptionID id = optionId; const OptionID id = optionId;
const OptionValue value = optionValue; const OptionValue value = optionValue;
if (id == kOptionProtocol) { if (id == kOptionProtocol) {
using enum ENetworkProtocol; using enum NetworkProtocol;
const auto enumValue = static_cast<ENetworkProtocol>(value); const auto enumValue = static_cast<NetworkProtocol>(value);
if (enumValue == kSynergy) { if (enumValue == Synergy) {
m_protocol = kSynergy; m_protocol = Synergy;
} else if (enumValue == kBarrier) { } else if (enumValue == Barrier) {
m_protocol = kBarrier; m_protocol = Barrier;
} else { } else {
throw XInvalidProtocol(); throw XInvalidProtocol();
} }

View file

@ -358,7 +358,7 @@ private:
}; };
// used in hello message sent to the client // used in hello message sent to the client
ENetworkProtocol m_protocol; NetworkProtocol m_protocol;
// the primary screen client // the primary screen client
PrimaryClient *m_primaryClient; PrimaryClient *m_primaryClient;