refactor: NetworkMonitor: use QStrings
allows us to simplify alot of the code around the lists and lets us also fliter lists easily update copyright for 2026, add missing deskflow devlopers for mainwindow for 2025 work
This commit is contained in:
parent
dac9539ad9
commit
ae9ca35448
6 changed files with 45 additions and 50 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
# SPDX-FileCopyrightText: 2024 - 2025 Deskflow Developers
|
# SPDX-FileCopyrightText: 2024 - 2026 Deskflow Developers
|
||||||
# SPDX-FileCopyrightText: 2012 - 2024 Symless Ltd
|
# SPDX-FileCopyrightText: 2012 - 2024 Symless Ltd
|
||||||
# SPDX-FileCopyrightText: 2009 - 2012 Nick Bolton
|
# SPDX-FileCopyrightText: 2009 - 2012 Nick Bolton
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
@ -79,7 +79,7 @@ project(
|
||||||
# Define Additional "PROJECT" vars for packaging and metadata
|
# Define Additional "PROJECT" vars for packaging and metadata
|
||||||
set(CMAKE_PROJECT_PROPER_NAME "Deskflow")
|
set(CMAKE_PROJECT_PROPER_NAME "Deskflow")
|
||||||
set(CMAKE_PROJECT_VENDOR "${CMAKE_PROJECT_PROPER_NAME} Devs")
|
set(CMAKE_PROJECT_VENDOR "${CMAKE_PROJECT_PROPER_NAME} Devs")
|
||||||
set(CMAKE_PROJECT_COPYRIGHT "(C) 2024-2025 ${CMAKE_PROJECT_VENDOR}")
|
set(CMAKE_PROJECT_COPYRIGHT "(C) 2024-2026 ${CMAKE_PROJECT_VENDOR}")
|
||||||
set(CMAKE_PROJECT_CONTACT "${CMAKE_PROJECT_PROPER_NAME} <maintainers@deskflow.org>")
|
set(CMAKE_PROJECT_CONTACT "${CMAKE_PROJECT_PROPER_NAME} <maintainers@deskflow.org>")
|
||||||
set(CMAKE_PROJECT_REV_FQDN "org.deskflow.deskflow")
|
set(CMAKE_PROJECT_REV_FQDN "org.deskflow.deskflow")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
* SPDX-FileCopyrightText: (C) 2024 - 2025 Chris Rizzitello <sithord48@gmail.com>
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||||
|
* SPDX-FileCopyrightText: (C) 2024 - 2026 Chris Rizzitello <sithord48@gmail.com>
|
||||||
* SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd.
|
* SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd.
|
||||||
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
|
@ -1241,7 +1242,7 @@ void MainWindow::handleNewClientPromptRequest(const QString &clientName, bool us
|
||||||
m_serverConnection.handleNewClientResult(clientName, result);
|
m_serverConnection.handleNewClientResult(clientName, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
void MainWindow::updateIpLabel(const QStringList &addresses)
|
||||||
{
|
{
|
||||||
if (m_coreProcess.mode() != CoreMode::Server) {
|
if (m_coreProcess.mode() != CoreMode::Server) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1255,12 +1256,6 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all available IPs for tooltip
|
|
||||||
QStringList ipList;
|
|
||||||
for (const auto &address : addresses) {
|
|
||||||
ipList.append(address.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString labelText;
|
QString labelText;
|
||||||
QString toolTipText;
|
QString toolTipText;
|
||||||
|
|
||||||
|
|
@ -1268,7 +1263,7 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||||
if (const auto ip = Settings::value(Settings::Core::Interface).toString(); !ip.isEmpty()) {
|
if (const auto ip = Settings::value(Settings::Core::Interface).toString(); !ip.isEmpty()) {
|
||||||
labelText = tr("Using IP: ");
|
labelText = tr("Using IP: ");
|
||||||
toolTipText = tr("Selected as the interface in settings.");
|
toolTipText = tr("Selected as the interface in settings.");
|
||||||
if (ipList.contains(ip, Qt::CaseInsensitive)) {
|
if (addresses.contains(ip, Qt::CaseInsensitive)) {
|
||||||
labelText.append(ip);
|
labelText.append(ip);
|
||||||
} else {
|
} else {
|
||||||
labelText.append(colorText.arg(palette().linkVisited().color().name(), ip));
|
labelText.append(colorText.arg(palette().linkVisited().color().name(), ip));
|
||||||
|
|
@ -1282,26 +1277,22 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||||
labelText = tr("Suggested IP: ");
|
labelText = tr("Suggested IP: ");
|
||||||
toolTipText = tr("<p>If connecting via the hostname fails, try %1</p>");
|
toolTipText = tr("<p>If connecting via the hostname fails, try %1</p>");
|
||||||
|
|
||||||
|
// Get all available IPs for tooltip
|
||||||
|
QStringList ipList = addresses;
|
||||||
|
|
||||||
// Determine which IP to show and tooltip based on server state
|
// Determine which IP to show and tooltip based on server state
|
||||||
if (m_coreProcess.isStarted()) {
|
if (m_coreProcess.isStarted()) {
|
||||||
// ipList should only include valid ip from servers start
|
// ipList should only include valid ip from servers start
|
||||||
ipList.clear();
|
const QRegularExpression ipListFilter(QStringLiteral("(%1)").arg(m_serverStartIPs.join("|")));
|
||||||
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
ipList = addresses.filter(ipListFilter);
|
||||||
if (addresses.contains(address))
|
|
||||||
ipList.append(address.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IPValid = true;
|
bool IPValid = true;
|
||||||
QString suggestedIP = m_serverStartSuggestedIP.toString();
|
QString suggestedIP = m_serverStartSuggestedIP;
|
||||||
if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) {
|
if ((suggestedIP != m_currentIpAddress) || !ipList.contains(m_serverStartSuggestedIP)) {
|
||||||
IPValid = false;
|
IPValid = false;
|
||||||
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
if (!ipList.isEmpty()) {
|
||||||
if (addresses.contains(address)) {
|
suggestedIP = ipList.first();
|
||||||
suggestedIP = address.toString();
|
m_currentIpAddress = suggestedIP;
|
||||||
m_currentIpAddress = address;
|
|
||||||
IPValid = true;
|
IPValid = true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1314,7 +1305,7 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||||
} else {
|
} else {
|
||||||
// Server is not running - update normally
|
// Server is not running - update normally
|
||||||
m_currentIpAddress = m_networkMonitor->getSuggestedIPv4Address();
|
m_currentIpAddress = m_networkMonitor->getSuggestedIPv4Address();
|
||||||
labelText.append(m_currentIpAddress.isNull() ? m_currentIpAddress.toString() : ipList.first());
|
labelText.append(m_currentIpAddress.isEmpty() ? m_currentIpAddress : ipList.first());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipList.count() < 2) {
|
if (ipList.count() < 2) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
* SPDX-FileCopyrightText: (C) 2024 Chris Rizzitello <sithord48@gmail.com>
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||||
|
* SPDX-FileCopyrightText: (C) 2024 - 2026 Chris Rizzitello <sithord48@gmail.com>
|
||||||
* SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd.
|
* SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd.
|
||||||
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
|
@ -155,7 +156,7 @@ private:
|
||||||
void toggleCanRunCore(bool enableButtons);
|
void toggleCanRunCore(bool enableButtons);
|
||||||
void remoteHostChanged(const QString &newRemoteHost);
|
void remoteHostChanged(const QString &newRemoteHost);
|
||||||
void handleNewClientPromptRequest(const QString &clientName, bool usePeerAuth);
|
void handleNewClientPromptRequest(const QString &clientName, bool usePeerAuth);
|
||||||
void updateIpLabel(const QList<QHostAddress> &addresses);
|
void updateIpLabel(const QStringList &addresses);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief showClientError
|
* @brief showClientError
|
||||||
|
|
@ -226,9 +227,9 @@ private:
|
||||||
|
|
||||||
// Network monitoring
|
// Network monitoring
|
||||||
NetworkMonitor *m_networkMonitor = nullptr;
|
NetworkMonitor *m_networkMonitor = nullptr;
|
||||||
QHostAddress m_currentIpAddress;
|
QString m_currentIpAddress;
|
||||||
|
|
||||||
// Server IP strategy optimization
|
// Server IP strategy optimization
|
||||||
QList<QHostAddress> m_serverStartIPs;
|
QStringList m_serverStartIPs;
|
||||||
QHostAddress m_serverStartSuggestedIP;
|
QString m_serverStartSuggestedIP;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
* SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ void NetworkMonitor::stopMonitoring()
|
||||||
m_isMonitoring = false;
|
m_isMonitoring = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QHostAddress> NetworkMonitor::getAvailableIPv4Addresses() const
|
QStringList NetworkMonitor::getAvailableIPv4Addresses() const
|
||||||
{
|
{
|
||||||
QList<QHostAddress> physicalIPs;
|
QList<QHostAddress> physicalIPs;
|
||||||
QList<QHostAddress> virtualIPs;
|
QList<QHostAddress> virtualIPs;
|
||||||
|
|
@ -110,18 +110,22 @@ QList<QHostAddress> NetworkMonitor::getAvailableIPv4Addresses() const
|
||||||
auto result = physicalIPs;
|
auto result = physicalIPs;
|
||||||
result.append(virtualIPs);
|
result.append(virtualIPs);
|
||||||
|
|
||||||
return result;
|
QStringList ipList;
|
||||||
|
for (const auto &host : result) {
|
||||||
|
ipList.append(host.toString());
|
||||||
|
}
|
||||||
|
return ipList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress NetworkMonitor::getSuggestedIPv4Address() const
|
QString NetworkMonitor::getSuggestedIPv4Address() const
|
||||||
{
|
{
|
||||||
const auto addresses = getAvailableIPv4Addresses();
|
const auto addresses = getAvailableIPv4Addresses();
|
||||||
if (addresses.isEmpty())
|
if (addresses.isEmpty())
|
||||||
return QHostAddress();
|
return {};
|
||||||
return addresses.first();
|
return addresses.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkMonitor::setIpAddresses(const QList<QHostAddress> &newAddresses)
|
void NetworkMonitor::setIpAddresses(const QStringList &newAddresses)
|
||||||
{
|
{
|
||||||
if (newAddresses == m_lastAddresses)
|
if (newAddresses == m_lastAddresses)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
* SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -50,23 +50,23 @@ public:
|
||||||
* @brief Get list of all available IPv4 addresses (excluding local and link-local addresses)
|
* @brief Get list of all available IPv4 addresses (excluding local and link-local addresses)
|
||||||
* @return IPv4 address list
|
* @return IPv4 address list
|
||||||
*/
|
*/
|
||||||
QList<QHostAddress> getAvailableIPv4Addresses() const;
|
QStringList getAvailableIPv4Addresses() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get recommended IP address (RFC-1918 addresses preferred)
|
* @brief Get recommended IP address (RFC-1918 addresses preferred)
|
||||||
* @return Recommended IP address, returns null if none available
|
* @return Recommended IP address, returns null if none available
|
||||||
*/
|
*/
|
||||||
QHostAddress getSuggestedIPv4Address() const;
|
QString getSuggestedIPv4Address() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* @brief Emitted when IP addresses change
|
* @brief Emitted when IP addresses change
|
||||||
* @param addresses New IP address list
|
* @param addresses New IP address list
|
||||||
*/
|
*/
|
||||||
void ipAddressesChanged(const QList<QHostAddress> &addresses);
|
void ipAddressesChanged(const QStringList &addresses);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setIpAddresses(const QList<QHostAddress> &newAddresses);
|
void setIpAddresses(const QStringList &newAddresses);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if a network interface is virtual
|
* @brief Check if a network interface is virtual
|
||||||
|
|
@ -81,7 +81,7 @@ private:
|
||||||
void updateNetworkState();
|
void updateNetworkState();
|
||||||
|
|
||||||
QTimer *m_checkTimer; ///< Timer for periodic network checks
|
QTimer *m_checkTimer; ///< Timer for periodic network checks
|
||||||
QList<QHostAddress> m_lastAddresses; ///< Last known IP addresses
|
QStringList m_lastAddresses; ///< Last known IP addresses
|
||||||
bool m_isMonitoring = false; ///< Flag indicating if monitoring is active
|
bool m_isMonitoring = false; ///< Flag indicating if monitoring is active
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
* SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers
|
||||||
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
|
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
|
||||||
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
|
@ -52,9 +52,8 @@ SettingsDialog::SettingsDialog(QWidget *parent, const IServerConfig &serverConfi
|
||||||
|
|
||||||
// Populate the list of IP addresses
|
// Populate the list of IP addresses
|
||||||
NetworkMonitor networkMonitor(this);
|
NetworkMonitor networkMonitor(this);
|
||||||
const auto addresses = networkMonitor.getAvailableIPv4Addresses();
|
for (const auto &address : networkMonitor.getAvailableIPv4Addresses()) {
|
||||||
for (const auto &address : addresses) {
|
QString ipString = address;
|
||||||
QString ipString = address.toString();
|
|
||||||
if (ui->comboInterface->findText(ipString) == -1) {
|
if (ui->comboInterface->findText(ipString) == -1) {
|
||||||
ui->comboInterface->addItem(ipString, ipString);
|
ui->comboInterface->addItem(ipString, ipString);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue