From edb818aa42c9bb2e9c5ae437a16aa5f168c0c1a7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 1 Dec 2017 17:12:52 +0100 Subject: Fix connection problems qith Qt5 (again) --- src/client/net/serverconnection.cpp | 24 +++++++++--------------- src/client/net/serverdiscovery.cpp | 4 ++-- src/server/net/discoverylistener.cpp | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index d79c7c3..b2a6b0d 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -1,8 +1,7 @@ #include "serverconnection.h" #include #include -#include -#include +#include #include #include #include @@ -190,9 +189,8 @@ void ServerConnection::handleMsg() int x = _fromServer.getFieldString(_X).toInt(); int y = _fromServer.getFieldString(_Y).toInt(); - // Get rect of primary screen - const QDesktopWidget primary; - const QRect primaryRect = primary.screenGeometry(); + QRect primaryRect = QGuiApplication::primaryScreen()->geometry(); + qDebug() << primaryRect; // Limit requested size so it won't easily leak sensitive information if (x < 32) { x = 32; @@ -206,16 +204,10 @@ void ServerConnection::handleMsg() } QPixmap desktop( - QPixmap::grabWindow( - QApplication::desktop()->winId(), - primaryRect.x(), - primaryRect.y(), - primaryRect.width(), - primaryRect.height() - ).scaled( - x, y, - Qt::KeepAspectRatio, - Qt::SmoothTransformation)); + QGuiApplication::primaryScreen()->grabWindow(0, + primaryRect.x(), primaryRect.y(), primaryRect.width(), primaryRect.height() + ).scaled(x, y, Qt::KeepAspectRatio, Qt::SmoothTransformation + )); QByteArray bytes; QBuffer jpgBuffer(&bytes); jpgBuffer.open(QIODevice::WriteOnly); @@ -365,6 +357,7 @@ void ServerConnection::onVncViewerStartStop(const bool started, const int client */ void ServerConnection::sslErrors(const QList & errors) { + _socket->ignoreSslErrors(); for (QList::const_iterator it = errors.begin(); it != errors.end(); it++) { const QSslError &err = *it; qDebug("Connect SSL: %s", qPrintable(err.errorString())); @@ -375,6 +368,7 @@ void ServerConnection::sslErrors(const QList & errors) if (err.error() == QSslError::CertificateNotYetValid || err.error() == QSslError::CertificateExpired) continue; // Some other SSL error - do not ignore + qDebug() << "FATAL!"; _socket->ignoreSslErrors(QList()); return; } diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index 5ca0eba..33ddbf5 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -21,8 +21,8 @@ ServerDiscovery::ServerDiscovery(QObject *parent) /* Try to get a UDP port for server discovery */ int tries = 10; while (tries-- != 0) { - const quint16 port = (quint16)(qrand() % 10000 + 10000); - if (_discoverySocket.bind(QHostAddress::Any, port)) + quint16 port = (quint16)(16384 + qrand() % 32768); + if (_discoverySocket.bind(QHostAddress::AnyIPv4, port)) break; if (tries == 0) qFatal("Could not bind to any UDP port for server discovery."); diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp index 95ad5e4..a13800b 100644 --- a/src/server/net/discoverylistener.cpp +++ b/src/server/net/discoverylistener.cpp @@ -32,7 +32,7 @@ DiscoveryListener::DiscoveryListener() : _socket(this), _counterResetPos(0) { - if (!_socket.bind(SERVICE_DISCOVERY_PORT)) + if (!_socket.bind(QHostAddress::AnyIPv4, SERVICE_DISCOVERY_PORT)) qFatal("Could not bind to service discovery port %d", (int)SERVICE_DISCOVERY_PORT); connect(&_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); for (int i = 0; i < SD_PACKET_TABLE_SIZE; ++i) -- cgit v1.2.3-55-g7522