feat: use Computer in settings to replace name

provide Settings::upgradeSettings to upgrade the screenName -> computerName
Make a note to remove "ScreenName" for 2.0
This commit is contained in:
sithlord48
2026-02-01 10:44:38 -05:00
committed by Nick Bolton
parent 8f5a4106d3
commit be4e861604
9 changed files with 67 additions and 36 deletions

View File

@ -72,7 +72,7 @@ This section contains general options it will begin with `[core]`
| port | port # | Port to use when connecting [default: 24800 |
| preventSleep | `true` or `false` | Prevent sleep when Deskflow is active [default: false] |
| processMode | `1` or `0` | The mode we use to start the process Service or Desktop |
| screenName | string | Name used to identify the computer [default: machine's hostname] |
| computerName | string | Name used to identify the computer [default: machine's hostname] |
| useHooks | `true` or `false` | If Windows uses hooks or not [default: true] |
| language | 639 language | The language to display the GUI in [default: en] |
| wlClipboard | `true` or `false` | When true the wl-clipboard backend will be enabled [default: false] |

View File

@ -1,6 +1,6 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-FileCopyrightText: (C) 2025 - 2026 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
@ -34,7 +34,10 @@ void Settings::setSettingsFile(const QString &settingsFile)
instance()->m_settingsProxy->load(settingsFile);
qInfo().noquote() << "settings file changed:" << instance()->m_settings->fileName();
instance()->setupScreenName();
instance()->upgradeSettings();
instance()->cleanSettings();
instance()->cleanStateSettings();
instance()->setupComputerName();
}
void Settings::setStateFile(const QString &stateFile)
@ -83,9 +86,19 @@ Settings::Settings(QObject *parent) : QObject(parent)
m_stateSettings = new QSettings(stateFile, QSettings::IniFormat, this);
upgradeSettings();
cleanSettings();
cleanStateSettings();
setupScreenName();
setupComputerName();
}
void Settings::upgradeSettings()
{
for (const auto [oldKey, newKey] : m_upgradedMap.asKeyValueRange()) {
if (m_settings->contains(oldKey) && !m_settings->contains(newKey)) {
m_settings->setValue(newKey, m_settings->value(oldKey));
}
}
}
void Settings::cleanSettings()
@ -112,13 +125,13 @@ void Settings::cleanStateSettings()
}
}
void Settings::setupScreenName()
void Settings::setupComputerName()
{
if (m_settings->value(Settings::Core::ScreenName).toString().isEmpty())
m_settings->setValue(Settings::Core::ScreenName, cleanScreenName(QSysInfo::machineHostName()));
if (m_settings->value(Settings::Core::ComputerName).toString().isEmpty())
m_settings->setValue(Settings::Core::ComputerName, cleanComputerName(QSysInfo::machineHostName()));
}
QString Settings::cleanScreenName(const QString &name)
QString Settings::cleanComputerName(const QString &name)
{
static const auto hyphen = QStringLiteral("-");
static const auto space = QStringLiteral(" ");
@ -136,7 +149,7 @@ QString Settings::cleanScreenName(const QString &name)
cleanName.removeLast();
if (cleanName.length() > 255) {
cleanName.truncate(255);
cleanName = cleanScreenName(cleanName);
cleanName = cleanComputerName(cleanName);
}
return cleanName;
}
@ -272,8 +285,8 @@ void Settings::setValue(const QString &key, const QVariant &value)
if (!value.isValid())
settings->remove(key);
else {
if (key == Settings::Core::ScreenName)
settings->setValue(key, cleanScreenName(value.toString()));
if (key == Settings::Core::ComputerName)
settings->setValue(key, cleanComputerName(value.toString()));
else
settings->setValue(key, value);
}

View File

@ -1,6 +1,6 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-FileCopyrightText: (C) 2025 - 2026 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-FileCopyrightText: (C) 2016 - 2025 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
@ -48,11 +48,14 @@ public:
inline static const auto Port = QStringLiteral("core/port");
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
inline static const auto ProcessMode = QStringLiteral("core/processMode");
inline static const auto ScreenName = QStringLiteral("core/screenName");
inline static const auto ComputerName = QStringLiteral("core/computerName");
inline static const auto Display = QStringLiteral("core/display");
inline static const auto UseHooks = QStringLiteral("core/useHooks");
inline static const auto Language = QStringLiteral("core/language");
inline static const auto UseWlClipboard = QStringLiteral("core/wlClipboard");
// TODO: REMOVE In 2.0
inline static const auto ScreenName = QStringLiteral("core/screenName"); // Replaced By ComputerName
};
struct Daemon
{
@ -149,20 +152,27 @@ private:
Settings *operator=(Settings &other) = delete;
Settings(const Settings &other) = delete;
~Settings() override = default;
/**
* @brief This method uses the Settings::m_upgradeMap, keys are upgraded if the oldkey is found and the newKey is not
* This method is run when settings is created before cleaning the settings and when you change settings files
* It does not remove any keys, only copies the old value to the new setings key
*/
void upgradeSettings();
void cleanSettings();
void cleanStateSettings();
/**
* @brief write an initial screen name
* @brief write an initial computer name
*/
void setupScreenName();
void setupComputerName();
/**
* @brief cleanScreenName ensure a valid screenName from the provided one
* @param name any string to be used as the screenName
* @return a valid screeName
* @brief cleanComputerName ensure a valid computerName from the provided one
* @param name any string to be used as the computerName
* @return a valid computerName
*/
static QString cleanScreenName(const QString &name);
static QString cleanComputerName(const QString &name);
QSettings *m_settings = nullptr;
QSettings *m_stateSettings = nullptr;
@ -193,6 +203,7 @@ private:
, Settings::Core::PreventSleep
, Settings::Core::ProcessMode
, Settings::Core::ScreenName
, Settings::Core::ComputerName
, Settings::Core::Display
, Settings::Core::UseHooks
, Settings::Core::UseWlClipboard
@ -255,5 +266,11 @@ private:
// Settings saved in our State file
inline static const QStringList m_stateKeys = { Settings::Gui::WindowGeometry };
// Contains settings keys to be upgraded.
inline static const QMap<QString, QString> m_upgradedMap = {
/* OLD KEY NEW KEY */
{QStringLiteral("core/screenName"), Settings::Core::ComputerName}
};
// clang-format on
};

View File

@ -287,7 +287,8 @@ bool ClientApp::startClient()
if (m_clientScreen == nullptr) {
clientScreen = openClientScreen();
m_client = openClient(
Settings::value(Settings::Core::ScreenName).toString().toStdString(), getCurrentServerAddress(), clientScreen
Settings::value(Settings::Core::ComputerName).toString().toStdString(), getCurrentServerAddress(),
clientScreen
);
m_clientScreen = clientScreen;
LOG_NOTE("started client");

View File

@ -59,7 +59,7 @@ using namespace deskflow::server;
ServerApp::ServerApp(IEventQueue *events, const QString &processName) : App(events, processName)
{
m_name = Settings::value(Settings::Core::ScreenName).toString().toStdString();
m_name = Settings::value(Settings::Core::ComputerName).toString().toStdString();
// do nothing
}

View File

@ -375,7 +375,7 @@ void MainWindow::settingsChanged(const QString &key)
return;
}
if (key == Settings::Core::ScreenName)
if (key == Settings::Core::ComputerName)
updateScreenName();
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
@ -1104,7 +1104,7 @@ void MainWindow::secureSocket(bool secureSocket)
void MainWindow::updateScreenName()
{
const auto screenName = Settings::value(Settings::Core::ScreenName).toString();
const auto screenName = Settings::value(Settings::Core::ComputerName).toString();
ui->lblComputerName->setText(screenName);
ui->lineEditName->setText(screenName);
m_serverConfig.updateServerName();
@ -1140,7 +1140,7 @@ void MainWindow::setHostName()
ui->btnEditName->show();
QString text = ui->lineEditName->text();
const auto screenName = Settings::value(Settings::Core::ScreenName).toString();
const auto screenName = Settings::value(Settings::Core::ComputerName).toString();
if (text == screenName)
return;
@ -1172,7 +1172,7 @@ void MainWindow::setHostName()
}
ui->lblComputerName->setText(ui->lineEditName->text());
Settings::setValue(Settings::Core::ScreenName, ui->lineEditName->text());
Settings::setValue(Settings::Core::ComputerName, ui->lineEditName->text());
if (isServer)
serverConfig().updateServerName();
applyConfig();

View File

@ -128,9 +128,9 @@ void ServerConfig::commit()
settings().setArrayIndex(i);
const auto &screen = screens()[i];
screen.saveSettings(settings());
auto screenName = Settings::value(Settings::Core::ScreenName).toString();
auto screenName = Settings::value(Settings::Core::ComputerName).toString();
if (screen.isServer() && screenName != screen.name()) {
Settings::setValue(Settings::Core::ScreenName, screen.name());
Settings::setValue(Settings::Core::ComputerName, screen.name());
}
}
settings().endArray();
@ -316,14 +316,14 @@ int ServerConfig::numScreens() const
QString ServerConfig::getServerName() const
{
return Settings::value(Settings::Core::ScreenName).toString();
return Settings::value(Settings::Core::ComputerName).toString();
}
void ServerConfig::updateServerName()
{
for (auto &screen : screens()) {
if (screen.isServer()) {
screen.setName(Settings::value(Settings::Core::ScreenName).toString());
screen.setName(Settings::value(Settings::Core::ComputerName).toString());
break;
}
}
@ -370,7 +370,7 @@ bool ServerConfig::screenExists(const QString &screenName) const
void ServerConfig::addClient(const QString &clientName)
{
int serverIndex = -1;
const auto screenName = Settings::value(Settings::Core::ScreenName).toString();
const auto screenName = Settings::value(Settings::Core::ComputerName).toString();
if (findScreenName(screenName, serverIndex)) {
m_Screens[serverIndex].markAsServer();

View File

@ -469,7 +469,7 @@ int SecureSocket::secureConnect(int socket)
LOG_DEBUG2("connecting secure socket");
// enable hostname verification.
const auto name = Settings::value(Settings::Core::ScreenName).toString().toStdString();
const auto name = Settings::value(Settings::Core::ComputerName).toString().toStdString();
SSL_set1_host(m_ssl->m_ssl, name.c_str());
int r = SSL_connect(m_ssl->m_ssl);

View File

@ -56,7 +56,7 @@ void SettingsTests::checkValidSettings()
QSignalSpy spy(Settings::instance(), &Settings::settingsChanged);
QVERIFY(spy.isValid());
const auto keysToCheck = QRegularExpression(QLatin1String("[^%1]").arg(Settings::Core::ScreenName));
const auto keysToCheck = QRegularExpression(QLatin1String("[^%1]").arg(Settings::Core::ComputerName));
const auto validKeys = Settings::validKeys().filter(keysToCheck);
for (const auto &setting : validKeys) {
const auto value = Settings::value(setting).toString();
@ -82,9 +82,9 @@ void SettingsTests::checkCleanScreenName()
const auto input = QStringLiteral("--!_ _-S@c#r$e%e^&*(n)= +Name\n[1]2|3?4--5>6<,7`~/8*90\\.lan--.. ..");
const auto expected = QStringLiteral("Screen_Name_1234--567890.lan");
Settings::setValue(Settings::Core::ScreenName, input);
Settings::setValue(Settings::Core::ComputerName, input);
QCOMPARE(Settings::value(Settings::Core::ScreenName).toString(), expected);
QCOMPARE(Settings::value(Settings::Core::ComputerName).toString(), expected);
}
void SettingsTests::checkCleanScreenName_LongName()
@ -96,9 +96,9 @@ void SettingsTests::checkCleanScreenName_LongName()
QString expected;
expected.fill('f', 255);
Settings::setValue(Settings::Core::ScreenName, input);
Settings::setValue(Settings::Core::ComputerName, input);
QCOMPARE(Settings::value(Settings::Core::ScreenName).toString(), expected);
QCOMPARE(Settings::value(Settings::Core::ComputerName).toString(), expected);
}
void SettingsTests::checkLogLevels_Valid()