Port away from deprecated QtNetwork classes
This commit is contained in:
parent
b3163d8725
commit
5b5265f7a8
2 changed files with 26 additions and 17 deletions
|
@ -20,9 +20,7 @@
|
|||
|
||||
#include <QHostInfo>
|
||||
#include <QMetaEnum>
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkSession>
|
||||
#include <QSslCipher>
|
||||
#include <QSslConfiguration>
|
||||
#include <QSslKey>
|
||||
|
@ -60,21 +58,26 @@ LanLinkProvider::LanLinkProvider(bool testMode, quint16 udpBroadcastPort, quint1
|
|||
|
||||
m_udpSocket.setProxy(QNetworkProxy::NoProxy);
|
||||
|
||||
// Detect when a network interface changes status, so we announce ourselves in the new network
|
||||
QNetworkConfigurationManager *networkManager = new QNetworkConfigurationManager(this);
|
||||
connect(networkManager, &QNetworkConfigurationManager::configurationChanged, this, &LanLinkProvider::onNetworkConfigurationChanged);
|
||||
|
||||
connect(&m_udpSocket, &QAbstractSocket::errorOccurred, [](QAbstractSocket::SocketError socketError) {
|
||||
qWarning() << "Error sending UDP packet:" << socketError;
|
||||
});
|
||||
}
|
||||
|
||||
void LanLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration &config)
|
||||
{
|
||||
if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) {
|
||||
m_lastConfig = config;
|
||||
onNetworkChange();
|
||||
}
|
||||
#if QT_VERSION_MAJOR < 6
|
||||
QNetworkConfigurationManager *networkManager = new QNetworkConfigurationManager(this);
|
||||
connect(networkManager, &QNetworkConfigurationManager::configurationChanged, this, [this](QNetworkConfiguration config) {
|
||||
if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) {
|
||||
m_lastConfig = config;
|
||||
onNetworkChange();
|
||||
}
|
||||
});
|
||||
#else
|
||||
// Detect when a network interface changes status, so we announce ourselves in the new network
|
||||
connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, [this]() {
|
||||
if (QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online) {
|
||||
onNetworkChange();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
LanLinkProvider::~LanLinkProvider()
|
||||
|
@ -566,7 +569,7 @@ void LanLinkProvider::configureSocket(QSslSocket *socket)
|
|||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
int maxIdle = 5 * 60 * 1000; // 5 minutes of idle before sending keep-alives
|
||||
int maxIdle = 5 * 60 * 1000; // 5 minutes of idle before sending keep-alive
|
||||
int interval = 5 * 1000; // 5 seconds interval between probes after 5 minute delay
|
||||
DWORD nop;
|
||||
|
||||
|
|
|
@ -7,12 +7,17 @@
|
|||
#ifndef LANLINKPROVIDER_H
|
||||
#define LANLINKPROVIDER_H
|
||||
|
||||
#include <QNetworkSession>
|
||||
#include <QObject>
|
||||
#include <QSslSocket>
|
||||
#include <QTcpServer>
|
||||
#include <QTimer>
|
||||
#include <QUdpSocket>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include <QNetworkSession>
|
||||
#else
|
||||
#include <QNetworkInformation>
|
||||
#endif
|
||||
|
||||
#include "backends/linkprovider.h"
|
||||
#include "kdeconnectcore_export.h"
|
||||
|
@ -69,7 +74,6 @@ private Q_SLOTS:
|
|||
void broadcastToNetwork();
|
||||
|
||||
private:
|
||||
void onNetworkConfigurationChanged(const QNetworkConfiguration &config);
|
||||
void addLink(QSslSocket *socket, const DeviceInfo &deviceInfo);
|
||||
QList<QHostAddress> getBroadcastAddresses();
|
||||
void sendUdpIdentityPacket(QUdpSocket &socket, const QList<QHostAddress> &addresses);
|
||||
|
@ -89,13 +93,15 @@ private:
|
|||
QHostAddress sender;
|
||||
};
|
||||
QMap<QSslSocket *, PendingConnect> m_receivedIdentityPackets;
|
||||
QNetworkConfiguration m_lastConfig;
|
||||
const bool m_testMode;
|
||||
QTimer m_combineBroadcastsTimer;
|
||||
|
||||
#ifdef KDECONNECT_MDNS
|
||||
MdnsDiscovery m_mdnsDiscovery;
|
||||
#endif
|
||||
#if QT_VERSION_MAJOR < 6
|
||||
QNetworkConfiguration m_lastConfig;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue