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:
committed by
Chris Rizzitello
parent
dac9539ad9
commit
ae9ca35448
@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2024 - 2025 Deskflow Developers
|
||||
# SPDX-FileCopyrightText: 2024 - 2026 Deskflow Developers
|
||||
# SPDX-FileCopyrightText: 2012 - 2024 Symless Ltd
|
||||
# SPDX-FileCopyrightText: 2009 - 2012 Nick Bolton
|
||||
# SPDX-License-Identifier: MIT
|
||||
@ -79,7 +79,7 @@ project(
|
||||
# Define Additional "PROJECT" vars for packaging and metadata
|
||||
set(CMAKE_PROJECT_PROPER_NAME "Deskflow")
|
||||
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_REV_FQDN "org.deskflow.deskflow")
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* 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) 2008 Volker Lanz <vl@fidra.de>
|
||||
* 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);
|
||||
}
|
||||
|
||||
void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||
void MainWindow::updateIpLabel(const QStringList &addresses)
|
||||
{
|
||||
if (m_coreProcess.mode() != CoreMode::Server) {
|
||||
return;
|
||||
@ -1255,12 +1256,6 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all available IPs for tooltip
|
||||
QStringList ipList;
|
||||
for (const auto &address : addresses) {
|
||||
ipList.append(address.toString());
|
||||
}
|
||||
|
||||
QString labelText;
|
||||
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()) {
|
||||
labelText = tr("Using IP: ");
|
||||
toolTipText = tr("Selected as the interface in settings.");
|
||||
if (ipList.contains(ip, Qt::CaseInsensitive)) {
|
||||
if (addresses.contains(ip, Qt::CaseInsensitive)) {
|
||||
labelText.append(ip);
|
||||
} else {
|
||||
labelText.append(colorText.arg(palette().linkVisited().color().name(), ip));
|
||||
@ -1282,26 +1277,22 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||
labelText = tr("Suggested IP: ");
|
||||
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
|
||||
if (m_coreProcess.isStarted()) {
|
||||
// ipList should only include valid ip from servers start
|
||||
ipList.clear();
|
||||
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
||||
if (addresses.contains(address))
|
||||
ipList.append(address.toString());
|
||||
}
|
||||
|
||||
const QRegularExpression ipListFilter(QStringLiteral("(%1)").arg(m_serverStartIPs.join("|")));
|
||||
ipList = addresses.filter(ipListFilter);
|
||||
bool IPValid = true;
|
||||
QString suggestedIP = m_serverStartSuggestedIP.toString();
|
||||
if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) {
|
||||
QString suggestedIP = m_serverStartSuggestedIP;
|
||||
if ((suggestedIP != m_currentIpAddress) || !ipList.contains(m_serverStartSuggestedIP)) {
|
||||
IPValid = false;
|
||||
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
||||
if (addresses.contains(address)) {
|
||||
suggestedIP = address.toString();
|
||||
m_currentIpAddress = address;
|
||||
IPValid = true;
|
||||
break;
|
||||
}
|
||||
if (!ipList.isEmpty()) {
|
||||
suggestedIP = ipList.first();
|
||||
m_currentIpAddress = suggestedIP;
|
||||
IPValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1314,7 +1305,7 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||
} else {
|
||||
// Server is not running - update normally
|
||||
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) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* 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) 2008 Volker Lanz <vl@fidra.de>
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
@ -155,7 +156,7 @@ private:
|
||||
void toggleCanRunCore(bool enableButtons);
|
||||
void remoteHostChanged(const QString &newRemoteHost);
|
||||
void handleNewClientPromptRequest(const QString &clientName, bool usePeerAuth);
|
||||
void updateIpLabel(const QList<QHostAddress> &addresses);
|
||||
void updateIpLabel(const QStringList &addresses);
|
||||
|
||||
/**
|
||||
* @brief showClientError
|
||||
@ -226,9 +227,9 @@ private:
|
||||
|
||||
// Network monitoring
|
||||
NetworkMonitor *m_networkMonitor = nullptr;
|
||||
QHostAddress m_currentIpAddress;
|
||||
QString m_currentIpAddress;
|
||||
|
||||
// Server IP strategy optimization
|
||||
QList<QHostAddress> m_serverStartIPs;
|
||||
QHostAddress m_serverStartSuggestedIP;
|
||||
QStringList m_serverStartIPs;
|
||||
QString m_serverStartSuggestedIP;
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@ -63,7 +63,7 @@ void NetworkMonitor::stopMonitoring()
|
||||
m_isMonitoring = false;
|
||||
}
|
||||
|
||||
QList<QHostAddress> NetworkMonitor::getAvailableIPv4Addresses() const
|
||||
QStringList NetworkMonitor::getAvailableIPv4Addresses() const
|
||||
{
|
||||
QList<QHostAddress> physicalIPs;
|
||||
QList<QHostAddress> virtualIPs;
|
||||
@ -110,18 +110,22 @@ QList<QHostAddress> NetworkMonitor::getAvailableIPv4Addresses() const
|
||||
auto result = physicalIPs;
|
||||
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();
|
||||
if (addresses.isEmpty())
|
||||
return QHostAddress();
|
||||
return {};
|
||||
return addresses.first();
|
||||
}
|
||||
|
||||
void NetworkMonitor::setIpAddresses(const QList<QHostAddress> &newAddresses)
|
||||
void NetworkMonitor::setIpAddresses(const QStringList &newAddresses)
|
||||
{
|
||||
if (newAddresses == m_lastAddresses)
|
||||
return;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@ -50,23 +50,23 @@ public:
|
||||
* @brief Get list of all available IPv4 addresses (excluding local and link-local addresses)
|
||||
* @return IPv4 address list
|
||||
*/
|
||||
QList<QHostAddress> getAvailableIPv4Addresses() const;
|
||||
QStringList getAvailableIPv4Addresses() const;
|
||||
|
||||
/**
|
||||
* @brief Get recommended IP address (RFC-1918 addresses preferred)
|
||||
* @return Recommended IP address, returns null if none available
|
||||
*/
|
||||
QHostAddress getSuggestedIPv4Address() const;
|
||||
QString getSuggestedIPv4Address() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* @brief Emitted when IP addresses change
|
||||
* @param addresses New IP address list
|
||||
*/
|
||||
void ipAddressesChanged(const QList<QHostAddress> &addresses);
|
||||
void ipAddressesChanged(const QStringList &addresses);
|
||||
|
||||
private:
|
||||
void setIpAddresses(const QList<QHostAddress> &newAddresses);
|
||||
void setIpAddresses(const QStringList &newAddresses);
|
||||
|
||||
/**
|
||||
* @brief Check if a network interface is virtual
|
||||
@ -80,9 +80,9 @@ private:
|
||||
*/
|
||||
void updateNetworkState();
|
||||
|
||||
QTimer *m_checkTimer; ///< Timer for periodic network checks
|
||||
QList<QHostAddress> m_lastAddresses; ///< Last known IP addresses
|
||||
bool m_isMonitoring = false; ///< Flag indicating if monitoring is active
|
||||
QTimer *m_checkTimer; ///< Timer for periodic network checks
|
||||
QStringList m_lastAddresses; ///< Last known IP addresses
|
||||
bool m_isMonitoring = false; ///< Flag indicating if monitoring is active
|
||||
};
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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) 2008 Volker Lanz <vl@fidra.de>
|
||||
* 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
|
||||
NetworkMonitor networkMonitor(this);
|
||||
const auto addresses = networkMonitor.getAvailableIPv4Addresses();
|
||||
for (const auto &address : addresses) {
|
||||
QString ipString = address.toString();
|
||||
for (const auto &address : networkMonitor.getAvailableIPv4Addresses()) {
|
||||
QString ipString = address;
|
||||
if (ui->comboInterface->findText(ipString) == -1) {
|
||||
ui->comboInterface->addItem(ipString, ipString);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user