refactor: Unify ENetworkProtocol and ServerProtocol into new enum Class NetworkProtocol in new file base/NetworkProtocol.h
This commit is contained in:
@ -25,6 +25,7 @@ add_library(base STATIC
|
||||
Log.cpp
|
||||
Log.h
|
||||
LogLevel.h
|
||||
NetworkProtocol.h
|
||||
Path.cpp
|
||||
Path.h
|
||||
PriorityQueue.h
|
||||
|
||||
13
src/lib/base/NetworkProtocol.h
Normal file
13
src/lib/base/NetworkProtocol.h
Normal 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
|
||||
};
|
||||
@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/EventTypes.h"
|
||||
#include "base/NetworkProtocol.h"
|
||||
|
||||
#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;
|
||||
//@}
|
||||
|
||||
//! @name Network protocol
|
||||
//@{
|
||||
enum class ENetworkProtocol
|
||||
{
|
||||
kSynergy,
|
||||
kBarrier
|
||||
};
|
||||
//@}
|
||||
|
||||
#undef OPTION_CODE
|
||||
|
||||
@ -165,7 +165,7 @@ void ServerConfig::recall()
|
||||
|
||||
haveHeartbeat(settings().value("hasHeartbeat", false).toBool());
|
||||
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());
|
||||
setWin32KeepForeground(settings().value("win32KeepForeground", 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)
|
||||
{
|
||||
using enum deskflow::gui::ServerProtocol;
|
||||
using enum NetworkProtocol;
|
||||
|
||||
outStream << "section: screens" << Qt::endl;
|
||||
|
||||
@ -264,9 +264,9 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config)
|
||||
if (config.hasHeartbeat())
|
||||
outStream << "\t" << "heartbeat = " << config.heartbeat() << Qt::endl;
|
||||
|
||||
if (config.protocol() == kSynergy) {
|
||||
if (config.protocol() == Synergy) {
|
||||
outStream << "\t" << "protocol = synergy" << Qt::endl;
|
||||
} else if (config.protocol() == kBarrier) {
|
||||
} else if (config.protocol() == Barrier) {
|
||||
outStream << "\t" << "protocol = barrier" << Qt::endl;
|
||||
} else {
|
||||
qFatal("unrecognized protocol when writing config");
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Hotkey.h"
|
||||
#include "base/NetworkProtocol.h"
|
||||
#include "gui/config/IServerConfig.h"
|
||||
#include "gui/config/ScreenConfig.h"
|
||||
#include "gui/config/ScreenList.h"
|
||||
@ -26,14 +27,8 @@ class MainWindow;
|
||||
|
||||
namespace deskflow::gui {
|
||||
|
||||
enum class ServerProtocol
|
||||
{
|
||||
kSynergy,
|
||||
kBarrier
|
||||
};
|
||||
|
||||
// The default protocol was decided by a community vote.
|
||||
const auto kDefaultProtocol = ServerProtocol::kBarrier;
|
||||
const auto kDefaultProtocol = NetworkProtocol::Barrier;
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
||||
@ -47,8 +42,6 @@ enum class ScreenAddResults
|
||||
|
||||
class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig
|
||||
{
|
||||
using ServerProtocol = deskflow::gui::ServerProtocol;
|
||||
|
||||
friend class ServerConfigDialog;
|
||||
friend QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
|
||||
|
||||
@ -85,7 +78,7 @@ public:
|
||||
{
|
||||
return m_Heartbeat;
|
||||
}
|
||||
ServerProtocol protocol() const
|
||||
NetworkProtocol protocol() const
|
||||
{
|
||||
return m_Protocol;
|
||||
}
|
||||
@ -197,7 +190,7 @@ private:
|
||||
{
|
||||
m_Heartbeat = val;
|
||||
}
|
||||
void setProtocol(ServerProtocol val)
|
||||
void setProtocol(NetworkProtocol val)
|
||||
{
|
||||
m_Protocol = val;
|
||||
}
|
||||
@ -261,7 +254,7 @@ private:
|
||||
private:
|
||||
bool m_HasHeartbeat = false;
|
||||
int m_Heartbeat = 0;
|
||||
ServerProtocol m_Protocol = deskflow::gui::kDefaultProtocol;
|
||||
NetworkProtocol m_Protocol = deskflow::gui::kDefaultProtocol;
|
||||
bool m_RelativeMouseMoves = false;
|
||||
bool m_Win32KeepForeground = false;
|
||||
bool m_HasSwitchDelay = false;
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "ServerConfigDialog.h"
|
||||
#include "ui_ServerConfigDialog.h"
|
||||
|
||||
#include "base/NetworkProtocol.h"
|
||||
#include "common/Constants.h"
|
||||
#include "dialogs/ActionDialog.h"
|
||||
#include "dialogs/HotkeyDialog.h"
|
||||
@ -20,7 +21,7 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
using enum ScreenConfig::SwitchCorner;
|
||||
using ServerProtocol = deskflow::gui::ServerProtocol;
|
||||
using enum NetworkProtocol;
|
||||
|
||||
ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config)
|
||||
: 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->lineConfigFile->setText(serverConfig().configFile());
|
||||
|
||||
ui->rbProtocolSynergy->setChecked(serverConfig().protocol() == ServerProtocol::kSynergy);
|
||||
ui->rbProtocolBarrier->setChecked(serverConfig().protocol() == ServerProtocol::kBarrier);
|
||||
ui->rbProtocolSynergy->setChecked(serverConfig().protocol() == NetworkProtocol::Synergy);
|
||||
ui->rbProtocolBarrier->setChecked(serverConfig().protocol() == NetworkProtocol::Barrier);
|
||||
connect(ui->rbProtocolBarrier, &QRadioButton::toggled, this, &ServerConfigDialog::toggleProtocol);
|
||||
|
||||
ui->cbHeartbeat->setChecked(serverConfig().hasHeartbeat());
|
||||
@ -359,7 +360,7 @@ void ServerConfigDialog::toggleRelativeMouseMoves(bool enabled)
|
||||
|
||||
void ServerConfigDialog::toggleProtocol()
|
||||
{
|
||||
ServerProtocol proto = ui->rbProtocolBarrier->isChecked() ? ServerProtocol::kBarrier : ServerProtocol::kSynergy;
|
||||
auto proto = ui->rbProtocolBarrier->isChecked() ? NetworkProtocol::Barrier : NetworkProtocol::Synergy;
|
||||
serverConfig().setProtocol(proto);
|
||||
onChange();
|
||||
}
|
||||
|
||||
@ -1311,11 +1311,11 @@ std::string Config::getOptionValue(OptionID id, OptionValue value)
|
||||
return result;
|
||||
}
|
||||
if (id == kOptionProtocol) {
|
||||
using enum ENetworkProtocol;
|
||||
const auto enumValue = static_cast<ENetworkProtocol>(value);
|
||||
if (enumValue == kSynergy) {
|
||||
using enum NetworkProtocol;
|
||||
const auto enumValue = static_cast<NetworkProtocol>(value);
|
||||
if (enumValue == Synergy) {
|
||||
return kSynergyProtocolOption;
|
||||
} else if (enumValue == kBarrier) {
|
||||
} else if (enumValue == Barrier) {
|
||||
return kBarrierProtocolOption;
|
||||
} else {
|
||||
throw XInvalidProtocol();
|
||||
@ -1809,9 +1809,9 @@ OptionValue ConfigReadContext::parseCorner(const std::string &arg) const
|
||||
OptionValue ConfigReadContext::parseProtocol(const std::string &args) const
|
||||
{
|
||||
if (CaselessCmp::equal(args, kSynergyProtocolOption)) {
|
||||
return static_cast<OptionValue>(ENetworkProtocol::kSynergy);
|
||||
return static_cast<OptionValue>(NetworkProtocol::Synergy);
|
||||
} 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);
|
||||
}
|
||||
|
||||
@ -275,10 +275,10 @@ void Server::disconnect()
|
||||
|
||||
std::string Server::protocolString() const
|
||||
{
|
||||
using enum ENetworkProtocol;
|
||||
if (m_protocol == kSynergy) {
|
||||
using enum NetworkProtocol;
|
||||
if (m_protocol == Synergy) {
|
||||
return kSynergyProtocolName;
|
||||
} else if (m_protocol == kBarrier) {
|
||||
} else if (m_protocol == Barrier) {
|
||||
return kBarrierProtocolName;
|
||||
}
|
||||
throw XInvalidProtocol();
|
||||
@ -1074,12 +1074,12 @@ void Server::processOptions()
|
||||
const OptionID id = optionId;
|
||||
const OptionValue value = optionValue;
|
||||
if (id == kOptionProtocol) {
|
||||
using enum ENetworkProtocol;
|
||||
const auto enumValue = static_cast<ENetworkProtocol>(value);
|
||||
if (enumValue == kSynergy) {
|
||||
m_protocol = kSynergy;
|
||||
} else if (enumValue == kBarrier) {
|
||||
m_protocol = kBarrier;
|
||||
using enum NetworkProtocol;
|
||||
const auto enumValue = static_cast<NetworkProtocol>(value);
|
||||
if (enumValue == Synergy) {
|
||||
m_protocol = Synergy;
|
||||
} else if (enumValue == Barrier) {
|
||||
m_protocol = Barrier;
|
||||
} else {
|
||||
throw XInvalidProtocol();
|
||||
}
|
||||
|
||||
@ -358,7 +358,7 @@ private:
|
||||
};
|
||||
|
||||
// used in hello message sent to the client
|
||||
ENetworkProtocol m_protocol;
|
||||
NetworkProtocol m_protocol;
|
||||
|
||||
// the primary screen client
|
||||
PrimaryClient *m_primaryClient;
|
||||
|
||||
Reference in New Issue
Block a user