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:
parent
8f5a4106d3
commit
be4e861604
9 changed files with 67 additions and 36 deletions
|
|
@ -72,7 +72,7 @@ This section contains general options it will begin with `[core]`
|
||||||
| port | port # | Port to use when connecting [default: 24800 |
|
| port | port # | Port to use when connecting [default: 24800 |
|
||||||
| preventSleep | `true` or `false` | Prevent sleep when Deskflow is active [default: false] |
|
| 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 |
|
| 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] |
|
| useHooks | `true` or `false` | If Windows uses hooks or not [default: true] |
|
||||||
| language | 639 language | The language to display the GUI in [default: en] |
|
| 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] |
|
| wlClipboard | `true` or `false` | When true the wl-clipboard backend will be enabled [default: false] |
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* 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
|
* 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);
|
instance()->m_settingsProxy->load(settingsFile);
|
||||||
qInfo().noquote() << "settings file changed:" << instance()->m_settings->fileName();
|
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)
|
void Settings::setStateFile(const QString &stateFile)
|
||||||
|
|
@ -83,9 +86,19 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
m_stateSettings = new QSettings(stateFile, QSettings::IniFormat, this);
|
m_stateSettings = new QSettings(stateFile, QSettings::IniFormat, this);
|
||||||
|
|
||||||
|
upgradeSettings();
|
||||||
cleanSettings();
|
cleanSettings();
|
||||||
cleanStateSettings();
|
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()
|
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())
|
if (m_settings->value(Settings::Core::ComputerName).toString().isEmpty())
|
||||||
m_settings->setValue(Settings::Core::ScreenName, cleanScreenName(QSysInfo::machineHostName()));
|
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 hyphen = QStringLiteral("-");
|
||||||
static const auto space = QStringLiteral(" ");
|
static const auto space = QStringLiteral(" ");
|
||||||
|
|
@ -136,7 +149,7 @@ QString Settings::cleanScreenName(const QString &name)
|
||||||
cleanName.removeLast();
|
cleanName.removeLast();
|
||||||
if (cleanName.length() > 255) {
|
if (cleanName.length() > 255) {
|
||||||
cleanName.truncate(255);
|
cleanName.truncate(255);
|
||||||
cleanName = cleanScreenName(cleanName);
|
cleanName = cleanComputerName(cleanName);
|
||||||
}
|
}
|
||||||
return cleanName;
|
return cleanName;
|
||||||
}
|
}
|
||||||
|
|
@ -272,8 +285,8 @@ void Settings::setValue(const QString &key, const QVariant &value)
|
||||||
if (!value.isValid())
|
if (!value.isValid())
|
||||||
settings->remove(key);
|
settings->remove(key);
|
||||||
else {
|
else {
|
||||||
if (key == Settings::Core::ScreenName)
|
if (key == Settings::Core::ComputerName)
|
||||||
settings->setValue(key, cleanScreenName(value.toString()));
|
settings->setValue(key, cleanComputerName(value.toString()));
|
||||||
else
|
else
|
||||||
settings->setValue(key, value);
|
settings->setValue(key, value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* 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-FileCopyrightText: (C) 2016 - 2025 Symless Ltd.
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* 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 Port = QStringLiteral("core/port");
|
||||||
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
||||||
inline static const auto ProcessMode = QStringLiteral("core/processMode");
|
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 Display = QStringLiteral("core/display");
|
||||||
inline static const auto UseHooks = QStringLiteral("core/useHooks");
|
inline static const auto UseHooks = QStringLiteral("core/useHooks");
|
||||||
inline static const auto Language = QStringLiteral("core/language");
|
inline static const auto Language = QStringLiteral("core/language");
|
||||||
inline static const auto UseWlClipboard = QStringLiteral("core/wlClipboard");
|
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
|
struct Daemon
|
||||||
{
|
{
|
||||||
|
|
@ -149,20 +152,27 @@ private:
|
||||||
Settings *operator=(Settings &other) = delete;
|
Settings *operator=(Settings &other) = delete;
|
||||||
Settings(const Settings &other) = delete;
|
Settings(const Settings &other) = delete;
|
||||||
~Settings() override = default;
|
~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 cleanSettings();
|
||||||
void cleanStateSettings();
|
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
|
* @brief cleanComputerName ensure a valid computerName from the provided one
|
||||||
* @param name any string to be used as the screenName
|
* @param name any string to be used as the computerName
|
||||||
* @return a valid screeName
|
* @return a valid computerName
|
||||||
*/
|
*/
|
||||||
static QString cleanScreenName(const QString &name);
|
static QString cleanComputerName(const QString &name);
|
||||||
|
|
||||||
QSettings *m_settings = nullptr;
|
QSettings *m_settings = nullptr;
|
||||||
QSettings *m_stateSettings = nullptr;
|
QSettings *m_stateSettings = nullptr;
|
||||||
|
|
@ -193,6 +203,7 @@ private:
|
||||||
, Settings::Core::PreventSleep
|
, Settings::Core::PreventSleep
|
||||||
, Settings::Core::ProcessMode
|
, Settings::Core::ProcessMode
|
||||||
, Settings::Core::ScreenName
|
, Settings::Core::ScreenName
|
||||||
|
, Settings::Core::ComputerName
|
||||||
, Settings::Core::Display
|
, Settings::Core::Display
|
||||||
, Settings::Core::UseHooks
|
, Settings::Core::UseHooks
|
||||||
, Settings::Core::UseWlClipboard
|
, Settings::Core::UseWlClipboard
|
||||||
|
|
@ -255,5 +266,11 @@ private:
|
||||||
|
|
||||||
// Settings saved in our State file
|
// Settings saved in our State file
|
||||||
inline static const QStringList m_stateKeys = { Settings::Gui::WindowGeometry };
|
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
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,8 @@ bool ClientApp::startClient()
|
||||||
if (m_clientScreen == nullptr) {
|
if (m_clientScreen == nullptr) {
|
||||||
clientScreen = openClientScreen();
|
clientScreen = openClientScreen();
|
||||||
m_client = openClient(
|
m_client = openClient(
|
||||||
Settings::value(Settings::Core::ScreenName).toString().toStdString(), getCurrentServerAddress(), clientScreen
|
Settings::value(Settings::Core::ComputerName).toString().toStdString(), getCurrentServerAddress(),
|
||||||
|
clientScreen
|
||||||
);
|
);
|
||||||
m_clientScreen = clientScreen;
|
m_clientScreen = clientScreen;
|
||||||
LOG_NOTE("started client");
|
LOG_NOTE("started client");
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ using namespace deskflow::server;
|
||||||
|
|
||||||
ServerApp::ServerApp(IEventQueue *events, const QString &processName) : App(events, processName)
|
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
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ void MainWindow::settingsChanged(const QString &key)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == Settings::Core::ScreenName)
|
if (key == Settings::Core::ComputerName)
|
||||||
updateScreenName();
|
updateScreenName();
|
||||||
|
|
||||||
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
|
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
|
||||||
|
|
@ -1104,7 +1104,7 @@ void MainWindow::secureSocket(bool secureSocket)
|
||||||
|
|
||||||
void MainWindow::updateScreenName()
|
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->lblComputerName->setText(screenName);
|
||||||
ui->lineEditName->setText(screenName);
|
ui->lineEditName->setText(screenName);
|
||||||
m_serverConfig.updateServerName();
|
m_serverConfig.updateServerName();
|
||||||
|
|
@ -1140,7 +1140,7 @@ void MainWindow::setHostName()
|
||||||
ui->btnEditName->show();
|
ui->btnEditName->show();
|
||||||
|
|
||||||
QString text = ui->lineEditName->text();
|
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)
|
if (text == screenName)
|
||||||
return;
|
return;
|
||||||
|
|
@ -1172,7 +1172,7 @@ void MainWindow::setHostName()
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->lblComputerName->setText(ui->lineEditName->text());
|
ui->lblComputerName->setText(ui->lineEditName->text());
|
||||||
Settings::setValue(Settings::Core::ScreenName, ui->lineEditName->text());
|
Settings::setValue(Settings::Core::ComputerName, ui->lineEditName->text());
|
||||||
if (isServer)
|
if (isServer)
|
||||||
serverConfig().updateServerName();
|
serverConfig().updateServerName();
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,9 @@ void ServerConfig::commit()
|
||||||
settings().setArrayIndex(i);
|
settings().setArrayIndex(i);
|
||||||
const auto &screen = screens()[i];
|
const auto &screen = screens()[i];
|
||||||
screen.saveSettings(settings());
|
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()) {
|
if (screen.isServer() && screenName != screen.name()) {
|
||||||
Settings::setValue(Settings::Core::ScreenName, screen.name());
|
Settings::setValue(Settings::Core::ComputerName, screen.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings().endArray();
|
settings().endArray();
|
||||||
|
|
@ -316,14 +316,14 @@ int ServerConfig::numScreens() const
|
||||||
|
|
||||||
QString ServerConfig::getServerName() const
|
QString ServerConfig::getServerName() const
|
||||||
{
|
{
|
||||||
return Settings::value(Settings::Core::ScreenName).toString();
|
return Settings::value(Settings::Core::ComputerName).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::updateServerName()
|
void ServerConfig::updateServerName()
|
||||||
{
|
{
|
||||||
for (auto &screen : screens()) {
|
for (auto &screen : screens()) {
|
||||||
if (screen.isServer()) {
|
if (screen.isServer()) {
|
||||||
screen.setName(Settings::value(Settings::Core::ScreenName).toString());
|
screen.setName(Settings::value(Settings::Core::ComputerName).toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -370,7 +370,7 @@ bool ServerConfig::screenExists(const QString &screenName) const
|
||||||
void ServerConfig::addClient(const QString &clientName)
|
void ServerConfig::addClient(const QString &clientName)
|
||||||
{
|
{
|
||||||
int serverIndex = -1;
|
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)) {
|
if (findScreenName(screenName, serverIndex)) {
|
||||||
m_Screens[serverIndex].markAsServer();
|
m_Screens[serverIndex].markAsServer();
|
||||||
|
|
|
||||||
|
|
@ -469,7 +469,7 @@ int SecureSocket::secureConnect(int socket)
|
||||||
LOG_DEBUG2("connecting secure socket");
|
LOG_DEBUG2("connecting secure socket");
|
||||||
|
|
||||||
// enable hostname verification.
|
// 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());
|
SSL_set1_host(m_ssl->m_ssl, name.c_str());
|
||||||
int r = SSL_connect(m_ssl->m_ssl);
|
int r = SSL_connect(m_ssl->m_ssl);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ void SettingsTests::checkValidSettings()
|
||||||
QSignalSpy spy(Settings::instance(), &Settings::settingsChanged);
|
QSignalSpy spy(Settings::instance(), &Settings::settingsChanged);
|
||||||
QVERIFY(spy.isValid());
|
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);
|
const auto validKeys = Settings::validKeys().filter(keysToCheck);
|
||||||
for (const auto &setting : validKeys) {
|
for (const auto &setting : validKeys) {
|
||||||
const auto value = Settings::value(setting).toString();
|
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 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");
|
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()
|
void SettingsTests::checkCleanScreenName_LongName()
|
||||||
|
|
@ -96,9 +96,9 @@ void SettingsTests::checkCleanScreenName_LongName()
|
||||||
QString expected;
|
QString expected;
|
||||||
expected.fill('f', 255);
|
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()
|
void SettingsTests::checkLogLevels_Valid()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue