Cleanup network examples
Cleanup network examples: - use nullptr - use member-init - adjust includes - use new-style connects Change-Id: I80aa230168e5aec88a1bc93bbf49a471bfc30e7b Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>bb10
parent
66b6e28c01
commit
e85de7d787
|
|
@ -80,34 +80,37 @@ BearerMonitor::BearerMonitor(QWidget *parent)
|
|||
break;
|
||||
}
|
||||
}
|
||||
connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool)));
|
||||
connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
|
||||
this, SLOT(configurationAdded(const QNetworkConfiguration&)));
|
||||
connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)),
|
||||
this, SLOT(configurationRemoved(const QNetworkConfiguration&)));
|
||||
connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)),
|
||||
this, SLOT(configurationChanged(const QNetworkConfiguration)));
|
||||
connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations()));
|
||||
connect(&manager, &QNetworkConfigurationManager::onlineStateChanged,
|
||||
this, &BearerMonitor::onlineStateChanged);
|
||||
connect(&manager, &QNetworkConfigurationManager::configurationAdded,
|
||||
this, [this](const QNetworkConfiguration &config) { configurationAdded(config); });
|
||||
connect(&manager, &QNetworkConfigurationManager::configurationRemoved,
|
||||
this, &BearerMonitor::configurationRemoved);
|
||||
connect(&manager, &QNetworkConfigurationManager::configurationChanged,
|
||||
this, &BearerMonitor::configurationChanged);
|
||||
connect(&manager, &QNetworkConfigurationManager::updateCompleted,
|
||||
this, &BearerMonitor::updateConfigurations);
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
|
||||
connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork()));
|
||||
connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork()));
|
||||
connect(registerButton, &QPushButton::clicked,
|
||||
this, &BearerMonitor::registerNetwork);
|
||||
connect(unregisterButton, &QPushButton::clicked,
|
||||
this, &BearerMonitor::unregisterNetwork);
|
||||
#else // Q_OS_WIN && !Q_OS_WINRT
|
||||
nlaGroup->hide();
|
||||
#endif
|
||||
|
||||
connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
|
||||
this, SLOT(createSessionFor(QTreeWidgetItem*)));
|
||||
connect(treeWidget, &QTreeWidget::itemActivated,
|
||||
this, &BearerMonitor::createSessionFor);
|
||||
connect(treeWidget, &QTreeWidget::currentItemChanged,
|
||||
this, &BearerMonitor::showConfigurationFor);
|
||||
|
||||
connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
||||
this, SLOT(showConfigurationFor(QTreeWidgetItem*)));
|
||||
|
||||
connect(newSessionButton, SIGNAL(clicked()),
|
||||
this, SLOT(createNewSession()));
|
||||
connect(deleteSessionButton, SIGNAL(clicked()),
|
||||
this, SLOT(deleteSession()));
|
||||
connect(scanButton, SIGNAL(clicked()),
|
||||
this, SLOT(performScan()));
|
||||
connect(newSessionButton, &QPushButton::clicked,
|
||||
this, &BearerMonitor::createNewSession);
|
||||
connect(deleteSessionButton, &QPushButton::clicked,
|
||||
this, &BearerMonitor::deleteSession);
|
||||
connect(scanButton, &QPushButton::clicked,
|
||||
this, &BearerMonitor::performScan);
|
||||
|
||||
// Just in case update all configurations so that all
|
||||
// configurations are up to date.
|
||||
|
|
@ -124,7 +127,7 @@ static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &confi
|
|||
item->setData(0, Qt::UserRole, config.identifier());
|
||||
|
||||
QFont font = item->font(1);
|
||||
font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active);
|
||||
font.setBold(config.state().testFlag(QNetworkConfiguration::Active));
|
||||
item->setFont(0, font);
|
||||
}
|
||||
|
||||
|
|
@ -333,8 +336,6 @@ void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
|
|||
case QNetworkConfiguration::Undefined:
|
||||
configurationState->setText(tr("Undefined"));
|
||||
break;
|
||||
default:
|
||||
configurationState->setText(QString());
|
||||
}
|
||||
|
||||
switch (conf.type()) {
|
||||
|
|
@ -350,8 +351,6 @@ void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
|
|||
case QNetworkConfiguration::Invalid:
|
||||
configurationType->setText(tr("Invalid"));
|
||||
break;
|
||||
default:
|
||||
configurationType->setText(QString());
|
||||
}
|
||||
|
||||
switch (conf.purpose()) {
|
||||
|
|
@ -367,8 +366,6 @@ void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
|
|||
case QNetworkConfiguration::ServiceSpecificPurpose:
|
||||
configurationPurpose->setText(tr("Service Specific"));
|
||||
break;
|
||||
default:
|
||||
configurationPurpose->setText(QString());
|
||||
}
|
||||
|
||||
configurationIdentifier->setText(conf.identifier());
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@
|
|||
#ifndef BEARERMONITOR_H
|
||||
#define BEARERMONITOR_H
|
||||
|
||||
#include <qnetworkconfigmanager.h>
|
||||
#include <qnetworksession.h>
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include "ui_bearermonitor_640_480.h"
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
|
@ -64,11 +63,11 @@ class BearerMonitor : public QWidget, public Ui_BearerMonitor
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BearerMonitor(QWidget *parent = 0);
|
||||
BearerMonitor(QWidget *parent = nullptr);
|
||||
~BearerMonitor();
|
||||
|
||||
private slots:
|
||||
void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = 0);
|
||||
void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = nullptr);
|
||||
void configurationRemoved(const QNetworkConfiguration &config);
|
||||
void configurationChanged(const QNetworkConfiguration &config);
|
||||
void updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap);
|
||||
|
|
@ -90,7 +89,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QNetworkConfigurationManager manager;
|
||||
QList<SessionWidget *> sessionWidgets;
|
||||
QVector<SessionWidget *> sessionWidgets;
|
||||
};
|
||||
|
||||
#endif //BEARERMONITOR_H
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "bearermonitor.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "sessionwidget.h"
|
||||
#include "qnetworkconfigmanager.h"
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent)
|
||||
: QWidget(parent), statsTimer(-1)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
|
|
@ -65,10 +65,10 @@ SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *paren
|
|||
|
||||
session = new QNetworkSession(config, this);
|
||||
|
||||
connect(session, SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
this, SLOT(updateSession()));
|
||||
connect(session, SIGNAL(error(QNetworkSession::SessionError)),
|
||||
this, SLOT(updateSessionError(QNetworkSession::SessionError)));
|
||||
connect(session, &QNetworkSession::stateChanged,
|
||||
this, &SessionWidget::updateSession);
|
||||
connect(session, QOverload<QNetworkSession::SessionError>::of(&QNetworkSession::error),
|
||||
this, &SessionWidget::updateSessionError);
|
||||
|
||||
updateSession();
|
||||
|
||||
|
|
@ -76,14 +76,14 @@ SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *paren
|
|||
|
||||
configuration->setText(session->configuration().name());
|
||||
|
||||
connect(openSessionButton, SIGNAL(clicked()),
|
||||
this, SLOT(openSession()));
|
||||
connect(openSyncSessionButton, SIGNAL(clicked()),
|
||||
this, SLOT(openSyncSession()));
|
||||
connect(closeSessionButton, SIGNAL(clicked()),
|
||||
this, SLOT(closeSession()));
|
||||
connect(stopSessionButton, SIGNAL(clicked()),
|
||||
this, SLOT(stopSession()));
|
||||
connect(openSessionButton, &QPushButton::clicked,
|
||||
this, &SessionWidget::openSession);
|
||||
connect(openSyncSessionButton, &QPushButton::clicked,
|
||||
this, &SessionWidget::openSyncSession);
|
||||
connect(closeSessionButton, &QPushButton::clicked,
|
||||
this, &SessionWidget::closeSession);
|
||||
connect(stopSessionButton, &QPushButton::clicked,
|
||||
this, &SessionWidget::stopSession);
|
||||
}
|
||||
|
||||
SessionWidget::~SessionWidget()
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#ifndef SESSIONWIDGET_H
|
||||
#define SESSIONWIDGET_H
|
||||
|
||||
#include <qnetworksession.h>
|
||||
#include <QNetworkSession>
|
||||
|
||||
#include "ui_sessionwidget.h"
|
||||
|
||||
|
|
@ -62,10 +62,10 @@ class SessionWidget : public QWidget, public Ui_SessionWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0);
|
||||
explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = nullptr);
|
||||
~SessionWidget();
|
||||
|
||||
void timerEvent(QTimerEvent *) override;
|
||||
void timerEvent(QTimerEvent *e) override;
|
||||
|
||||
private:
|
||||
void updateSessionState(QNetworkSession::State state);
|
||||
|
|
@ -80,8 +80,8 @@ private Q_SLOTS:
|
|||
void updateSessionError(QNetworkSession::SessionError error);
|
||||
|
||||
private:
|
||||
QNetworkSession *session;
|
||||
int statsTimer;
|
||||
QNetworkSession *session = nullptr;
|
||||
int statsTimer = -1;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -96,20 +96,21 @@ BlockingClient::BlockingClient(QWidget *parent)
|
|||
buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
|
||||
|
||||
connect(getFortuneButton, SIGNAL(clicked()), this, SLOT(requestNewFortune()));
|
||||
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(getFortuneButton, &QPushButton::clicked,
|
||||
this, &BlockingClient::requestNewFortune);
|
||||
connect(quitButton, &QPushButton::clicked,
|
||||
this, &BlockingClient::close);
|
||||
|
||||
connect(hostLineEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(enableGetFortuneButton()));
|
||||
connect(portLineEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(enableGetFortuneButton()));
|
||||
connect(hostLineEdit, &QLineEdit::textChanged,
|
||||
this, &BlockingClient::enableGetFortuneButton);
|
||||
connect(portLineEdit, &QLineEdit::textChanged,
|
||||
this, &BlockingClient::enableGetFortuneButton);
|
||||
//! [0]
|
||||
connect(&thread, &FortuneThread::newFortune,
|
||||
this, &BlockingClient::showFortune);
|
||||
connect(&thread, &FortuneThread::error,
|
||||
this, &BlockingClient::displayError);
|
||||
//! [0]
|
||||
connect(&thread, SIGNAL(newFortune(QString)),
|
||||
this, SLOT(showFortune(QString)));
|
||||
//! [0] //! [1]
|
||||
connect(&thread, SIGNAL(error(int,QString)),
|
||||
this, SLOT(displayError(int,QString)));
|
||||
//! [1]
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
mainLayout->addWidget(hostLabel, 0, 0);
|
||||
|
|
@ -124,30 +125,30 @@ BlockingClient::BlockingClient(QWidget *parent)
|
|||
portLineEdit->setFocus();
|
||||
}
|
||||
|
||||
//! [2]
|
||||
//! [1]
|
||||
void BlockingClient::requestNewFortune()
|
||||
{
|
||||
getFortuneButton->setEnabled(false);
|
||||
thread.requestNewFortune(hostLineEdit->text(),
|
||||
portLineEdit->text().toInt());
|
||||
}
|
||||
//! [2]
|
||||
//! [1]
|
||||
|
||||
//! [3]
|
||||
//! [2]
|
||||
void BlockingClient::showFortune(const QString &nextFortune)
|
||||
{
|
||||
if (nextFortune == currentFortune) {
|
||||
requestNewFortune();
|
||||
return;
|
||||
}
|
||||
//! [3]
|
||||
//! [2]
|
||||
|
||||
//! [4]
|
||||
//! [3]
|
||||
currentFortune = nextFortune;
|
||||
statusLabel->setText(currentFortune);
|
||||
getFortuneButton->setEnabled(true);
|
||||
}
|
||||
//! [4]
|
||||
//! [3]
|
||||
|
||||
void BlockingClient::displayError(int socketError, const QString &message)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class BlockingClient : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BlockingClient(QWidget *parent = 0);
|
||||
BlockingClient(QWidget *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void requestNewFortune();
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class FortuneThread : public QThread
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FortuneThread(QObject *parent = 0);
|
||||
FortuneThread(QObject *parent = nullptr);
|
||||
~FortuneThread();
|
||||
|
||||
void requestNewFortune(const QString &hostName, quint16 port);
|
||||
|
|
|
|||
|
|
@ -48,8 +48,10 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QtNetwork>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QUdpSocket>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "receiver.h"
|
||||
|
||||
|
|
@ -67,10 +69,11 @@ Receiver::Receiver(QWidget *parent)
|
|||
//! [0]
|
||||
|
||||
//! [1]
|
||||
connect(udpSocket, SIGNAL(readyRead()),
|
||||
this, SLOT(processPendingDatagrams()));
|
||||
connect(udpSocket, &QUdpSocket::readyRead,
|
||||
this, &Receiver::processPendingDatagrams);
|
||||
//! [1]
|
||||
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(quitButton, &QPushButton::clicked,
|
||||
this, &Receiver::close);
|
||||
|
||||
auto buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch(1);
|
||||
|
|
|
|||
|
|
@ -151,9 +151,9 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu
|
|||
//! [0]
|
||||
|
||||
DnsManager::DnsManager()
|
||||
: dns(new QDnsLookup(this))
|
||||
{
|
||||
dns = new QDnsLookup(this);
|
||||
connect(dns, SIGNAL(finished()), this, SLOT(showResults()));
|
||||
connect(dns, &QDnsLookup::finished, this, &DnsManager::showResults);
|
||||
}
|
||||
|
||||
void DnsManager::execute()
|
||||
|
|
|
|||
|
|
@ -176,21 +176,20 @@
|
|||
but its implementation is slightly different:
|
||||
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 0
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 1
|
||||
|
||||
We connect our FortuneThread's two signals newFortune() and error() (which
|
||||
are somewhat similar to QTcpSocket::readyRead() and QTcpSocket::error() in
|
||||
the previous example) to requestNewFortune() and displayError().
|
||||
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 2
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 1
|
||||
|
||||
The requestNewFortune() slot calls FortuneThread::requestNewFortune(),
|
||||
which \e shedules the request. When the thread has received a new fortune
|
||||
and emits newFortune(), our showFortune() slot is called:
|
||||
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 3
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 2
|
||||
\codeline
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 4
|
||||
\snippet blockingfortuneclient/blockingclient.cpp 3
|
||||
|
||||
Here, we simply display the fortune we received as the argument.
|
||||
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ public slots:
|
|||
|
||||
DownloadManager::DownloadManager()
|
||||
{
|
||||
connect(&manager, SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(downloadFinished(QNetworkReply*)));
|
||||
connect(&manager, &QNetworkAccessManager::finished,
|
||||
this, &DownloadManager::downloadFinished);
|
||||
}
|
||||
|
||||
void DownloadManager::doDownload(const QUrl &url)
|
||||
|
|
@ -90,8 +90,8 @@ void DownloadManager::doDownload(const QUrl &url)
|
|||
QNetworkReply *reply = manager.get(request);
|
||||
|
||||
#if QT_CONFIG(ssl)
|
||||
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
|
||||
SLOT(sslErrors(QList<QSslError>)));
|
||||
connect(reply, &QNetworkReply::sslErrors,
|
||||
this, &DownloadManager::sslErrors);
|
||||
#endif
|
||||
|
||||
currentDownloads.append(reply);
|
||||
|
|
|
|||
|
|
@ -67,13 +67,13 @@ void DownloadManager::append(const QStringList &urls)
|
|||
append(QUrl::fromEncoded(urlAsString.toLocal8Bit()));
|
||||
|
||||
if (downloadQueue.isEmpty())
|
||||
QTimer::singleShot(0, this, SIGNAL(finished()));
|
||||
QTimer::singleShot(0, this, &DownloadManager::finished);
|
||||
}
|
||||
|
||||
void DownloadManager::append(const QUrl &url)
|
||||
{
|
||||
if (downloadQueue.isEmpty())
|
||||
QTimer::singleShot(0, this, SLOT(startNextDownload()));
|
||||
QTimer::singleShot(0, this, &DownloadManager::startNextDownload);
|
||||
|
||||
downloadQueue.enqueue(url);
|
||||
++totalCount;
|
||||
|
|
@ -123,12 +123,12 @@ void DownloadManager::startNextDownload()
|
|||
|
||||
QNetworkRequest request(url);
|
||||
currentDownload = manager.get(request);
|
||||
connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
|
||||
SLOT(downloadProgress(qint64,qint64)));
|
||||
connect(currentDownload, SIGNAL(finished()),
|
||||
SLOT(downloadFinished()));
|
||||
connect(currentDownload, SIGNAL(readyRead()),
|
||||
SLOT(downloadReadyRead()));
|
||||
connect(currentDownload, &QNetworkReply::downloadProgress,
|
||||
this, &DownloadManager::downloadProgress);
|
||||
connect(currentDownload, &QNetworkReply::finished,
|
||||
this, &DownloadManager::downloadFinished);
|
||||
connect(currentDownload, &QNetworkReply::readyRead,
|
||||
this, &DownloadManager::downloadReadyRead);
|
||||
|
||||
// prepare the output
|
||||
printf("Downloading %s...\n", url.toEncoded().constData());
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ int main(int argc, char **argv)
|
|||
DownloadManager manager;
|
||||
manager.append(arguments);
|
||||
|
||||
QObject::connect(&manager, SIGNAL(finished()), &app, SLOT(quit()));
|
||||
QObject::connect(&manager, &DownloadManager::finished,
|
||||
&app, &QCoreApplication::quit);
|
||||
app.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
//! [1]
|
||||
#include "googlesuggest.h"
|
||||
|
||||
//! [1]
|
||||
const QString gsuggestUrl(QStringLiteral("http://google.com/complete/search?output=toolbar&q=%1"));
|
||||
//! [1]
|
||||
|
||||
|
|
@ -74,16 +74,18 @@ GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), edit
|
|||
|
||||
popup->installEventFilter(this);
|
||||
|
||||
connect(popup, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
|
||||
SLOT(doneCompletion()));
|
||||
connect(popup, &QTreeWidget::itemClicked,
|
||||
this, &GSuggestCompletion::doneCompletion);
|
||||
|
||||
timer.setSingleShot(true);
|
||||
timer.setInterval(500);
|
||||
connect(&timer, SIGNAL(timeout()), SLOT(autoSuggest()));
|
||||
connect(editor, SIGNAL(textEdited(QString)), &timer, SLOT(start()));
|
||||
connect(&timer, &QTimer::timeout,
|
||||
this, &GSuggestCompletion::autoSuggest);
|
||||
connect(editor, &QLineEdit::textEdited,
|
||||
&timer, QOverload<>::of(&QTimer::start));
|
||||
|
||||
connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
|
||||
this, SLOT(handleNetworkData(QNetworkReply*)));
|
||||
connect(&networkManager, &QNetworkAccessManager::finished,
|
||||
this, &GSuggestCompletion::handleNetworkData);
|
||||
|
||||
}
|
||||
//! [2]
|
||||
|
|
|
|||
|
|
@ -57,11 +57,11 @@
|
|||
const QString gsearchUrl = QStringLiteral("http://www.google.com/search?q=%1");
|
||||
|
||||
//! [1]
|
||||
SearchBox::SearchBox(QWidget *parent): QLineEdit(parent)
|
||||
SearchBox::SearchBox(QWidget *parent)
|
||||
: QLineEdit(parent)
|
||||
, completer(new GSuggestCompletion(this))
|
||||
{
|
||||
completer = new GSuggestCompletion(this);
|
||||
|
||||
connect(this, SIGNAL(returnPressed()),this, SLOT(doSearch()));
|
||||
connect(this, &SearchBox::returnPressed, this, &SearchBox::doSearch);
|
||||
|
||||
setWindowTitle("Search with Google");
|
||||
|
||||
|
|
|
|||
|
|
@ -80,10 +80,12 @@ Receiver::Receiver(QWidget *parent)
|
|||
!udpSocket6.joinMulticastGroup(groupAddress6))
|
||||
statusLabel->setText(tr("Listening for multicast messages on IPv4 only"));
|
||||
|
||||
connect(&udpSocket4, SIGNAL(readyRead()),
|
||||
this, SLOT(processPendingDatagrams()));
|
||||
connect(&udpSocket6, &QUdpSocket::readyRead, this, &Receiver::processPendingDatagrams);
|
||||
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(&udpSocket4, &QUdpSocket::readyRead,
|
||||
this, &Receiver::processPendingDatagrams);
|
||||
connect(&udpSocket6, &QUdpSocket::readyRead,
|
||||
this, &Receiver::processPendingDatagrams);
|
||||
connect(quitButton, &QPushButton::clicked,
|
||||
this, &Receiver::close);
|
||||
}
|
||||
|
||||
void Receiver::processPendingDatagrams()
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ Client::Client(QWidget *parent)
|
|||
connect(sctpSocket, &QSctpSocket::connected, this, &Client::connected);
|
||||
connect(sctpSocket, &QSctpSocket::disconnected, this, &Client::disconnected);
|
||||
connect(sctpSocket, &QSctpSocket::channelReadyRead, this, &Client::readDatagram);
|
||||
connect(sctpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SLOT(displayError(QAbstractSocket::SocketError)));
|
||||
connect(sctpSocket, QOverload<QAbstractSocket::SocketError>::of(&QSctpSocket::error),
|
||||
this, &Client::displayError);
|
||||
connect(consumers[SctpChannels::Time], &Consumer::writeDatagram, this, &Client::writeDatagram);
|
||||
connect(consumers[SctpChannels::Chat], &Consumer::writeDatagram, this, &Client::writeDatagram);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,14 +62,14 @@ ChatDialog::ChatDialog(QWidget *parent)
|
|||
textEdit->setReadOnly(true);
|
||||
listWidget->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
|
||||
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
|
||||
connect(&client, SIGNAL(newMessage(QString,QString)),
|
||||
this, SLOT(appendMessage(QString,QString)));
|
||||
connect(&client, SIGNAL(newParticipant(QString)),
|
||||
this, SLOT(newParticipant(QString)));
|
||||
connect(&client, SIGNAL(participantLeft(QString)),
|
||||
this, SLOT(participantLeft(QString)));
|
||||
connect(lineEdit, &QLineEdit::returnPressed,
|
||||
this, &ChatDialog::returnPressed);
|
||||
connect(&client, &Client::newMessage,
|
||||
this, &ChatDialog::appendMessage);
|
||||
connect(&client, &Client::newParticipant,
|
||||
this, &ChatDialog::newParticipant);
|
||||
connect(&client, &Client::participantLeft,
|
||||
this, &ChatDialog::participantLeft);
|
||||
|
||||
myNickName = client.nickName();
|
||||
newParticipant(myNickName);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class ChatDialog : public QDialog, private Ui::ChatDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatDialog(QWidget *parent = 0);
|
||||
ChatDialog(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void appendMessage(const QString &from, const QString &message);
|
||||
|
|
|
|||
|
|
@ -60,10 +60,10 @@ Client::Client()
|
|||
peerManager->setServerPort(server.serverPort());
|
||||
peerManager->startBroadcasting();
|
||||
|
||||
QObject::connect(peerManager, SIGNAL(newConnection(Connection*)),
|
||||
this, SLOT(newConnection(Connection*)));
|
||||
QObject::connect(&server, SIGNAL(newConnection(Connection*)),
|
||||
this, SLOT(newConnection(Connection*)));
|
||||
connect(peerManager, &PeerManager::newConnection,
|
||||
this, &Client::newConnection);
|
||||
connect(&server, &Server::newConnection,
|
||||
this, &Client::newConnection);
|
||||
}
|
||||
|
||||
void Client::sendMessage(const QString &message)
|
||||
|
|
@ -102,10 +102,10 @@ void Client::newConnection(Connection *connection)
|
|||
{
|
||||
connection->setGreetingMessage(peerManager->userName());
|
||||
|
||||
connect(connection, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SLOT(connectionError(QAbstractSocket::SocketError)));
|
||||
connect(connection, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
||||
connect(connection, SIGNAL(readyForUse()), this, SLOT(readyForUse()));
|
||||
connect(connection, QOverload<QAbstractSocket::SocketError>::of(&Connection::error),
|
||||
this, &Client::connectionError);
|
||||
connect(connection, &Connection::disconnected, this, &Client::disconnected);
|
||||
connect(connection, &Connection::readyForUse, this, &Client::readyForUse);
|
||||
}
|
||||
|
||||
void Client::readyForUse()
|
||||
|
|
@ -115,8 +115,8 @@ void Client::readyForUse()
|
|||
connection->peerPort()))
|
||||
return;
|
||||
|
||||
connect(connection, SIGNAL(newMessage(QString,QString)),
|
||||
this, SIGNAL(newMessage(QString,QString)));
|
||||
connect(connection, &Connection::newMessage,
|
||||
this, &Client::newMessage);
|
||||
|
||||
peers.insert(connection->peerAddress(), connection);
|
||||
QString nick = connection->name();
|
||||
|
|
|
|||
|
|
@ -82,11 +82,14 @@ Connection::Connection(QObject *parent)
|
|||
isGreetingMessageSent = false;
|
||||
pingTimer.setInterval(PingInterval);
|
||||
|
||||
QObject::connect(this, SIGNAL(readyRead()), this, SLOT(processReadyRead()));
|
||||
QObject::connect(this, SIGNAL(disconnected()), &pingTimer, SLOT(stop()));
|
||||
QObject::connect(&pingTimer, SIGNAL(timeout()), this, SLOT(sendPing()));
|
||||
QObject::connect(this, SIGNAL(connected()),
|
||||
this, SLOT(sendGreetingMessage()));
|
||||
connect(this, &QTcpSocket::readyRead, this,
|
||||
&Connection::processReadyRead);
|
||||
connect(this, &QTcpSocket::disconnected,
|
||||
&pingTimer, &QTimer::stop);
|
||||
connect(&pingTimer, &QTimer::timeout,
|
||||
this, &Connection::sendPing);
|
||||
connect(this, &QTcpSocket::connected,
|
||||
this, &Connection::sendGreetingMessage);
|
||||
}
|
||||
|
||||
Connection::Connection(qintptr socketDescriptor, QObject *parent)
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ public:
|
|||
Undefined
|
||||
};
|
||||
|
||||
Connection(QObject *parent = 0);
|
||||
Connection(qintptr socketDescriptor, QObject *parent = 0);
|
||||
Connection(QObject *parent = nullptr);
|
||||
Connection(qintptr socketDescriptor, QObject *parent = nullptr);
|
||||
~Connection();
|
||||
|
||||
QString name() const;
|
||||
|
|
|
|||
|
|
@ -81,12 +81,12 @@ PeerManager::PeerManager(Client *client)
|
|||
|
||||
broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress
|
||||
| QUdpSocket::ReuseAddressHint);
|
||||
connect(&broadcastSocket, SIGNAL(readyRead()),
|
||||
this, SLOT(readBroadcastDatagram()));
|
||||
connect(&broadcastSocket, &QUdpSocket::readyRead,
|
||||
this, &PeerManager::readBroadcastDatagram);
|
||||
|
||||
broadcastTimer.setInterval(BroadcastInterval);
|
||||
connect(&broadcastTimer, SIGNAL(timeout()),
|
||||
this, SLOT(sendBroadcastDatagram()));
|
||||
connect(&broadcastTimer, &QTimer::timeout,
|
||||
this, &PeerManager::sendBroadcastDatagram);
|
||||
}
|
||||
|
||||
void PeerManager::setServerPort(int port)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class Server : public QTcpServer
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Server(QObject *parent = 0);
|
||||
Server(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void newConnection(Connection *connection);
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ int main(int argc, char **argv)
|
|||
QApplication app(argc, argv);
|
||||
|
||||
if (!QSslSocket::supportsSsl()) {
|
||||
QMessageBox::information(0, "Secure Socket Client",
|
||||
"This system does not support SSL/TLS.");
|
||||
QMessageBox::information(nullptr, "Secure Socket Client",
|
||||
"This system does not support TLS.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@
|
|||
#include "ui_sslclient.h"
|
||||
#include "ui_sslerrors.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
SslClient::SslClient(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
|
|
@ -185,16 +183,17 @@ void SslClient::setupUi()
|
|||
form->hostNameEdit->setSelection(0, form->hostNameEdit->text().size());
|
||||
form->sessionOutput->setHtml(tr("<not connected>"));
|
||||
|
||||
connect(form->hostNameEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(updateEnabledState()));
|
||||
connect(form->connectButton, SIGNAL(clicked()),
|
||||
this, SLOT(secureConnect()));
|
||||
connect(form->sendButton, SIGNAL(clicked()),
|
||||
this, SLOT(sendData()));
|
||||
connect(form->hostNameEdit, &QLineEdit::textChanged,
|
||||
this, &SslClient::updateEnabledState);
|
||||
connect(form->connectButton, &QPushButton::clicked,
|
||||
this, &SslClient::secureConnect);
|
||||
connect(form->sendButton, &QPushButton::clicked,
|
||||
this, &SslClient::sendData);
|
||||
|
||||
padLock = new QToolButton;
|
||||
padLock->setIcon(QIcon(":/encrypted.png"));
|
||||
connect(padLock, SIGNAL(clicked()), this, SLOT(displayCertificateInfo()));
|
||||
connect(padLock, &QToolButton::clicked,
|
||||
this, &SslClient::displayCertificateInfo);
|
||||
|
||||
#if QT_CONFIG(cursor)
|
||||
padLock->setCursor(Qt::ArrowCursor);
|
||||
|
|
@ -223,16 +222,16 @@ void SslClient::setupSecureSocket()
|
|||
|
||||
socket = new QSslSocket(this);
|
||||
|
||||
connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
|
||||
this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
|
||||
connect(socket, SIGNAL(encrypted()),
|
||||
this, SLOT(socketEncrypted()));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
|
||||
this, SLOT(sslErrors(QList<QSslError>)));
|
||||
connect(socket, SIGNAL(readyRead()),
|
||||
this, SLOT(socketReadyRead()));
|
||||
connect(socket, &QSslSocket::stateChanged,
|
||||
this, &SslClient::socketStateChanged);
|
||||
connect(socket, &QSslSocket::encrypted,
|
||||
this, &SslClient::socketEncrypted);
|
||||
connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QSslSocket::error),
|
||||
this, &SslClient::socketError);
|
||||
connect(socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors),
|
||||
this, &SslClient::sslErrors);
|
||||
connect(socket, &QSslSocket::readyRead,
|
||||
this, &SslClient::socketReadyRead);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ Dialog::Dialog(QWidget *parent)
|
|||
"Run the Fortune Client example now.")
|
||||
.arg(ipAddress).arg(server.serverPort()));
|
||||
|
||||
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(quitButton, &QPushButton::clicked, this, &Dialog::close);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch(1);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class Dialog : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Dialog(QWidget *parent = 0);
|
||||
Dialog(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel *statusLabel;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ void FortuneServer::incomingConnection(qintptr socketDescriptor)
|
|||
{
|
||||
QString fortune = fortunes.at(QRandomGenerator::global()->bounded(fortunes.size()));
|
||||
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
connect(thread, &FortuneThread::finished, thread, &FortuneThread::deleteLater);
|
||||
thread->start();
|
||||
}
|
||||
//! [1]
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class FortuneServer : public QTcpServer
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FortuneServer(QObject *parent = 0);
|
||||
FortuneServer(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void incomingConnection(qintptr socketDescriptor) override;
|
||||
|
|
|
|||
|
|
@ -73,12 +73,12 @@ AddTorrentDialog::AddTorrentDialog(QWidget *parent)
|
|||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
connect(ui.browseTorrents, SIGNAL(clicked()),
|
||||
this, SLOT(selectTorrent()));
|
||||
connect(ui.browseDestination, SIGNAL(clicked()),
|
||||
this, SLOT(selectDestination()));
|
||||
connect(ui.torrentFile, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(setTorrent(QString)));
|
||||
connect(ui.browseTorrents, &QPushButton::clicked,
|
||||
this, &AddTorrentDialog::selectTorrent);
|
||||
connect(ui.browseDestination, &QPushButton::clicked,
|
||||
this, &AddTorrentDialog::selectDestination);
|
||||
connect(ui.torrentFile, &QLineEdit::textChanged,
|
||||
this, &AddTorrentDialog::setTorrent);
|
||||
|
||||
ui.destinationFolder->setText(destinationDirectory = QDir::current().path());
|
||||
ui.torrentFile->setFocus();
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class AddTorrentDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AddTorrentDialog(QWidget *parent = 0);
|
||||
AddTorrentDialog(QWidget *parent = nullptr);
|
||||
|
||||
QString torrentFileName() const;
|
||||
QString destinationFolder() const;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class FileManager : public QThread
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FileManager(QObject *parent = 0);
|
||||
FileManager(QObject *parent = nullptr);
|
||||
virtual ~FileManager();
|
||||
|
||||
inline void setMetaInfo(const MetaInfo &info) { metaInfo = info; }
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class TorrentView : public QTreeWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TorrentView(QWidget *parent = 0);
|
||||
TorrentView(QWidget *parent = nullptr);
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
signals:
|
||||
|
|
@ -110,7 +110,7 @@ public:
|
|||
};
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), quitDialog(0), saveChanges(false)
|
||||
: QMainWindow(parent), quitDialog(nullptr), saveChanges(false)
|
||||
{
|
||||
// Initialize some static strings
|
||||
QStringList headers;
|
||||
|
|
@ -147,12 +147,12 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
fileMenu->addAction(pauseTorrentAction);
|
||||
fileMenu->addAction(removeTorrentAction);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, SLOT(close()));
|
||||
fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, &MainWindow::close);
|
||||
|
||||
// Help menu
|
||||
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
helpMenu->addAction(tr("&About"), this, SLOT(about()));
|
||||
helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
|
||||
helpMenu->addAction(tr("&About"), this, &MainWindow::about);
|
||||
helpMenu->addAction(tr("About &Qt"), qApp, QApplication::aboutQt);
|
||||
|
||||
// Top toolbar
|
||||
QToolBar *topBar = new QToolBar(tr("Tools"));
|
||||
|
|
@ -188,24 +188,24 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
#endif
|
||||
|
||||
// Set up connections
|
||||
connect(torrentView, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(setActionsEnabled()));
|
||||
connect(torrentView, SIGNAL(fileDropped(QString)),
|
||||
this, SLOT(acceptFileDrop(QString)));
|
||||
connect(uploadLimitSlider, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(setUploadLimit(int)));
|
||||
connect(downloadLimitSlider, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(setDownloadLimit(int)));
|
||||
connect(newTorrentAction, SIGNAL(triggered()),
|
||||
this, SLOT(addTorrent()));
|
||||
connect(pauseTorrentAction, SIGNAL(triggered()),
|
||||
this, SLOT(pauseTorrent()));
|
||||
connect(removeTorrentAction, SIGNAL(triggered()),
|
||||
this, SLOT(removeTorrent()));
|
||||
connect(upActionTool, SIGNAL(triggered(bool)),
|
||||
this, SLOT(moveTorrentUp()));
|
||||
connect(downActionTool, SIGNAL(triggered(bool)),
|
||||
this, SLOT(moveTorrentDown()));
|
||||
connect(torrentView, &TorrentView::itemSelectionChanged,
|
||||
this, &MainWindow::setActionsEnabled);
|
||||
connect(torrentView, &TorrentView::fileDropped,
|
||||
this, &MainWindow::acceptFileDrop);
|
||||
connect(uploadLimitSlider, &QSlider::valueChanged,
|
||||
this, &MainWindow::setUploadLimit);
|
||||
connect(downloadLimitSlider, &QSlider::valueChanged,
|
||||
this, &MainWindow::setDownloadLimit);
|
||||
connect(newTorrentAction, &QAction::triggered,
|
||||
this, QOverload<>::of(&MainWindow::addTorrent));
|
||||
connect(pauseTorrentAction, &QAction::triggered,
|
||||
this, &MainWindow::pauseTorrent);
|
||||
connect(removeTorrentAction, &QAction::triggered,
|
||||
this, &MainWindow::removeTorrent);
|
||||
connect(upActionTool, &QAction::triggered,
|
||||
this, &MainWindow::moveTorrentUp);
|
||||
connect(downActionTool, &QAction::triggered,
|
||||
this, &MainWindow::moveTorrentDown);
|
||||
|
||||
// Load settings and start
|
||||
setWindowTitle(tr("Torrent Client"));
|
||||
|
|
@ -297,7 +297,7 @@ bool MainWindow::addTorrent()
|
|||
addTorrent(fileName, addTorrentDialog->destinationFolder());
|
||||
if (!saveChanges) {
|
||||
saveChanges = true;
|
||||
QTimer::singleShot(1000, this, SLOT(saveSettings()));
|
||||
QTimer::singleShot(1000, this, &MainWindow::saveSettings);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -311,7 +311,8 @@ void MainWindow::removeTorrent()
|
|||
|
||||
// Stop the client.
|
||||
client->disconnect();
|
||||
connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
|
||||
connect(client, &TorrentClient::stopped,
|
||||
this, &MainWindow::torrentStopped);
|
||||
client->stop();
|
||||
|
||||
// Remove the row from the view.
|
||||
|
|
@ -379,13 +380,20 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
|
|||
client->setDumpedState(resumeState);
|
||||
|
||||
// Setup the client connections.
|
||||
connect(client, SIGNAL(stateChanged(TorrentClient::State)), this, SLOT(updateState(TorrentClient::State)));
|
||||
connect(client, SIGNAL(peerInfoUpdated()), this, SLOT(updatePeerInfo()));
|
||||
connect(client, SIGNAL(progressUpdated(int)), this, SLOT(updateProgress(int)));
|
||||
connect(client, SIGNAL(downloadRateUpdated(int)), this, SLOT(updateDownloadRate(int)));
|
||||
connect(client, SIGNAL(uploadRateUpdated(int)), this, SLOT(updateUploadRate(int)));
|
||||
connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
|
||||
connect(client, SIGNAL(error(TorrentClient::Error)), this, SLOT(torrentError(TorrentClient::Error)));
|
||||
connect(client, &TorrentClient::stateChanged,
|
||||
this, &MainWindow::updateState);
|
||||
connect(client, &TorrentClient::peerInfoUpdated,
|
||||
this, &MainWindow::updatePeerInfo);
|
||||
connect(client, &TorrentClient::progressUpdated,
|
||||
this, &MainWindow::updateProgress);
|
||||
connect(client, &TorrentClient::downloadRateUpdated,
|
||||
this, &MainWindow::updateDownloadRate);
|
||||
connect(client, &TorrentClient::uploadRateUpdated,
|
||||
this, &MainWindow::updateUploadRate);
|
||||
connect(client, &TorrentClient::stopped,
|
||||
this, &MainWindow::torrentStopped);
|
||||
connect(client, QOverload<TorrentClient::Error>::of(&TorrentClient::error),
|
||||
this, &MainWindow::torrentError);
|
||||
|
||||
// Add the client to the list of downloading jobs.
|
||||
Job job;
|
||||
|
|
@ -414,7 +422,7 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
|
|||
|
||||
if (!saveChanges) {
|
||||
saveChanges = true;
|
||||
QTimer::singleShot(5000, this, SLOT(saveSettings()));
|
||||
QTimer::singleShot(5000, this, &MainWindow::saveSettings);
|
||||
}
|
||||
client->start();
|
||||
return true;
|
||||
|
|
@ -491,15 +499,15 @@ void MainWindow::setActionsEnabled()
|
|||
{
|
||||
// Find the view item and client for the current row, and update
|
||||
// the states of the actions.
|
||||
QTreeWidgetItem *item = 0;
|
||||
QTreeWidgetItem *item = nullptr;
|
||||
if (!torrentView->selectedItems().isEmpty())
|
||||
item = torrentView->selectedItems().first();
|
||||
TorrentClient *client = item ? jobs.at(torrentView->indexOfTopLevelItem(item)).client : 0;
|
||||
TorrentClient *client = item ? jobs.at(torrentView->indexOfTopLevelItem(item)).client : nullptr;
|
||||
bool pauseEnabled = client && ((client->state() == TorrentClient::Paused)
|
||||
|| (client->state() > TorrentClient::Preparing));
|
||||
|
||||
removeTorrentAction->setEnabled(item != 0);
|
||||
pauseTorrentAction->setEnabled(item != 0 && pauseEnabled);
|
||||
removeTorrentAction->setEnabled(item != nullptr);
|
||||
pauseTorrentAction->setEnabled(item && pauseEnabled);
|
||||
|
||||
if (client && client->state() == TorrentClient::Paused) {
|
||||
pauseTorrentAction->setIcon(QIcon(":/icons/player_play.png"));
|
||||
|
|
@ -524,7 +532,7 @@ void MainWindow::updateDownloadRate(int bytesPerSecond)
|
|||
|
||||
if (!saveChanges) {
|
||||
saveChanges = true;
|
||||
QTimer::singleShot(5000, this, SLOT(saveSettings()));
|
||||
QTimer::singleShot(5000, this, &MainWindow::saveSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +546,7 @@ void MainWindow::updateUploadRate(int bytesPerSecond)
|
|||
|
||||
if (!saveChanges) {
|
||||
saveChanges = true;
|
||||
QTimer::singleShot(5000, this, SLOT(saveSettings()));
|
||||
QTimer::singleShot(5000, this, &MainWindow::saveSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -649,7 +657,7 @@ void MainWindow::about()
|
|||
about.setWindowTitle(tr("About Torrent Client"));
|
||||
about.setLayout(mainLayout);
|
||||
|
||||
connect(quitButton, SIGNAL(clicked()), &about, SLOT(close()));
|
||||
connect(quitButton, &QPushButton::clicked, &about, &QDialog::close);
|
||||
|
||||
about.exec();
|
||||
}
|
||||
|
|
@ -688,7 +696,7 @@ void MainWindow::closeEvent(QCloseEvent *)
|
|||
++jobsToStop;
|
||||
TorrentClient *client = job.client;
|
||||
client->disconnect();
|
||||
connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
|
||||
connect(client, &TorrentClient::stopped, this, &MainWindow::torrentStopped);
|
||||
client->stop();
|
||||
delete torrentView->takeTopLevelItem(0);
|
||||
}
|
||||
|
|
@ -696,7 +704,7 @@ void MainWindow::closeEvent(QCloseEvent *)
|
|||
if (jobsToStop > jobsStopped)
|
||||
quitDialog->exec();
|
||||
quitDialog->deleteLater();
|
||||
quitDialog = 0;
|
||||
quitDialog = nullptr;
|
||||
}
|
||||
|
||||
TorrentView::TorrentView(QWidget *parent)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class MainWindow : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
QSize sizeHint() const override;
|
||||
const TorrentClient *clientForRow(int row) const;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent)
|
|||
: QTcpSocket(parent), pendingBlockSizes(0),
|
||||
pwState(ChokingPeer | ChokedByPeer), receivedHandShake(false), gotPeerId(false),
|
||||
sentHandShake(false), nextPacketLength(-1), pendingRequestTimer(0), invalidateTimeout(false),
|
||||
keepAliveTimer(0), torrentPeer(0)
|
||||
keepAliveTimer(0), torrentPeer(nullptr)
|
||||
{
|
||||
memset(uploadSpeedData, 0, sizeof(uploadSpeedData));
|
||||
memset(downloadSpeedData, 0, sizeof(downloadSpeedData));
|
||||
|
|
@ -96,21 +96,23 @@ PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent)
|
|||
timeoutTimer = startTimer(ConnectTimeout);
|
||||
peerIdString = peerId;
|
||||
|
||||
connect(this, SIGNAL(readyRead()), this, SIGNAL(readyToTransfer()));
|
||||
connect(this, SIGNAL(connected()), this, SIGNAL(readyToTransfer()));
|
||||
connect(this, &PeerWireClient::readyRead,
|
||||
this, &PeerWireClient::readyToTransfer);
|
||||
connect(this, &PeerWireClient::connected,
|
||||
this, &PeerWireClient::readyToTransfer);
|
||||
|
||||
connect(&socket, SIGNAL(connected()),
|
||||
this, SIGNAL(connected()));
|
||||
connect(&socket, SIGNAL(readyRead()),
|
||||
this, SIGNAL(readyRead()));
|
||||
connect(&socket, SIGNAL(disconnected()),
|
||||
this, SIGNAL(disconnected()));
|
||||
connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SIGNAL(error(QAbstractSocket::SocketError)));
|
||||
connect(&socket, SIGNAL(bytesWritten(qint64)),
|
||||
this, SIGNAL(bytesWritten(qint64)));
|
||||
connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
|
||||
this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
|
||||
connect(&socket, &QTcpSocket::connected,
|
||||
this, &PeerWireClient::connected);
|
||||
connect(&socket, &QTcpSocket::readyRead,
|
||||
this, &PeerWireClient::readyRead);
|
||||
connect(&socket, &QTcpSocket::disconnected,
|
||||
this, &PeerWireClient::disconnected);
|
||||
connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error),
|
||||
this, QOverload<QAbstractSocket::SocketError>::of(&PeerWireClient::error));
|
||||
connect(&socket, &QTcpSocket::bytesWritten,
|
||||
this, &PeerWireClient::bytesWritten);
|
||||
connect(&socket, &QTcpSocket::stateChanged,
|
||||
this, &PeerWireClient::socketStateChanged);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public:
|
|||
};
|
||||
Q_DECLARE_FLAGS(PeerWireState, PeerWireStateFlag)
|
||||
|
||||
explicit PeerWireClient(const QByteArray &peerId, QObject *parent = 0);
|
||||
explicit PeerWireClient(const QByteArray &peerId, QObject *parent = nullptr);
|
||||
void initialize(const QByteArray &infoHash, int pieceCount);
|
||||
|
||||
void setPeer(TorrentPeer *peer);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ RateController *RateController::instance()
|
|||
|
||||
void RateController::addSocket(PeerWireClient *socket)
|
||||
{
|
||||
connect(socket, SIGNAL(readyToTransfer()), this, SLOT(scheduleTransfer()));
|
||||
connect(socket, &PeerWireClient::readyToTransfer,
|
||||
this, &RateController::scheduleTransfer);
|
||||
socket->setReadBufferSize(downLimit * 4);
|
||||
sockets << socket;
|
||||
scheduleTransfer();
|
||||
|
|
@ -70,7 +71,8 @@ void RateController::addSocket(PeerWireClient *socket)
|
|||
|
||||
void RateController::removeSocket(PeerWireClient *socket)
|
||||
{
|
||||
disconnect(socket, SIGNAL(readyToTransfer()), this, SLOT(scheduleTransfer()));
|
||||
disconnect(socket, &PeerWireClient::readyToTransfer,
|
||||
this, &RateController::scheduleTransfer);
|
||||
socket->setReadBufferSize(0);
|
||||
sockets.remove(socket);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,7 @@ class RateController : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
inline RateController(QObject *parent = 0)
|
||||
: QObject(parent), transferScheduled(false) { }
|
||||
using QObject::QObject;
|
||||
static RateController *instance();
|
||||
|
||||
void addSocket(PeerWireClient *socket);
|
||||
|
|
@ -81,9 +80,9 @@ public slots:
|
|||
private:
|
||||
QElapsedTimer stopWatch;
|
||||
QSet<PeerWireClient *> sockets;
|
||||
int upLimit;
|
||||
int downLimit;
|
||||
bool transferScheduled;
|
||||
int upLimit = 0;
|
||||
int downLimit = 0;
|
||||
bool transferScheduled = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -75,13 +75,12 @@ static const int MinimumTimeBeforeRevisit = 30;
|
|||
static const int MaxUploads = 4;
|
||||
static const int UploadScheduleInterval = 10000;
|
||||
|
||||
class TorrentPiece {
|
||||
public:
|
||||
int index;
|
||||
int length;
|
||||
struct TorrentPiece {
|
||||
QBitArray completedBlocks;
|
||||
QBitArray requestedBlocks;
|
||||
bool inProgress;
|
||||
int index = 0;
|
||||
int length = 0;
|
||||
bool inProgress = false;
|
||||
};
|
||||
|
||||
class TorrentClientPrivate
|
||||
|
|
@ -227,7 +226,7 @@ void TorrentClientPrivate::callPeerConnector()
|
|||
{
|
||||
if (!connectingToClients) {
|
||||
connectingToClients = true;
|
||||
QTimer::singleShot(10000, q, SLOT(connectToPeers()));
|
||||
QTimer::singleShot(10000, q, &TorrentClient::connectToPeers);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,22 +234,22 @@ TorrentClient::TorrentClient(QObject *parent)
|
|||
: QObject(parent), d(new TorrentClientPrivate(this))
|
||||
{
|
||||
// Connect the file manager
|
||||
connect(&d->fileManager, SIGNAL(dataRead(int,int,int,QByteArray)),
|
||||
this, SLOT(sendToPeer(int,int,int,QByteArray)));
|
||||
connect(&d->fileManager, SIGNAL(verificationProgress(int)),
|
||||
this, SLOT(updateProgress(int)));
|
||||
connect(&d->fileManager, SIGNAL(verificationDone()),
|
||||
this, SLOT(fullVerificationDone()));
|
||||
connect(&d->fileManager, SIGNAL(pieceVerified(int,bool)),
|
||||
this, SLOT(pieceVerified(int,bool)));
|
||||
connect(&d->fileManager, SIGNAL(error()),
|
||||
this, SLOT(handleFileError()));
|
||||
connect(&d->fileManager, &FileManager::dataRead,
|
||||
this, &TorrentClient::sendToPeer);
|
||||
connect(&d->fileManager, &FileManager::verificationProgress,
|
||||
this, &TorrentClient::updateProgress);
|
||||
connect(&d->fileManager, &FileManager::verificationDone,
|
||||
this, &TorrentClient::fullVerificationDone);
|
||||
connect(&d->fileManager, &FileManager::pieceVerified,
|
||||
this, &TorrentClient::pieceVerified);
|
||||
connect(&d->fileManager, &FileManager::error,
|
||||
this, &TorrentClient::handleFileError);
|
||||
|
||||
// Connect the tracker client
|
||||
connect(&d->trackerClient, SIGNAL(peerListUpdated(QList<TorrentPeer>)),
|
||||
this, SLOT(addToPeerList(QList<TorrentPeer>)));
|
||||
connect(&d->trackerClient, SIGNAL(stopped()),
|
||||
this, SIGNAL(stopped()));
|
||||
connect(&d->trackerClient, &TrackerClient::peerListUpdated,
|
||||
this, &TorrentClient::addToPeerList);
|
||||
connect(&d->trackerClient, &TrackerClient::stopped,
|
||||
this, &TorrentClient::stopped);
|
||||
}
|
||||
|
||||
TorrentClient::~TorrentClient()
|
||||
|
|
@ -840,26 +839,26 @@ void TorrentClient::setupOutgoingConnection()
|
|||
|
||||
void TorrentClient::initializeConnection(PeerWireClient *client)
|
||||
{
|
||||
connect(client, SIGNAL(connected()),
|
||||
this, SLOT(setupOutgoingConnection()));
|
||||
connect(client, SIGNAL(disconnected()),
|
||||
this, SLOT(removeClient()));
|
||||
connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SLOT(removeClient()));
|
||||
connect(client, SIGNAL(piecesAvailable(QBitArray)),
|
||||
this, SLOT(peerPiecesAvailable(QBitArray)));
|
||||
connect(client, SIGNAL(blockRequested(int,int,int)),
|
||||
this, SLOT(peerRequestsBlock(int,int,int)));
|
||||
connect(client, SIGNAL(blockReceived(int,int,QByteArray)),
|
||||
this, SLOT(blockReceived(int,int,QByteArray)));
|
||||
connect(client, SIGNAL(choked()),
|
||||
this, SLOT(peerChoked()));
|
||||
connect(client, SIGNAL(unchoked()),
|
||||
this, SLOT(peerUnchoked()));
|
||||
connect(client, SIGNAL(bytesWritten(qint64)),
|
||||
this, SLOT(peerWireBytesWritten(qint64)));
|
||||
connect(client, SIGNAL(bytesReceived(qint64)),
|
||||
this, SLOT(peerWireBytesReceived(qint64)));
|
||||
connect(client, &PeerWireClient::connected,
|
||||
this, &TorrentClient::setupOutgoingConnection);
|
||||
connect(client, &PeerWireClient::disconnected,
|
||||
this, &TorrentClient::removeClient);
|
||||
connect(client, QOverload<QAbstractSocket::SocketError>::of(&PeerWireClient::error),
|
||||
this, &TorrentClient::removeClient);
|
||||
connect(client, &PeerWireClient::piecesAvailable,
|
||||
this, &TorrentClient::peerPiecesAvailable);
|
||||
connect(client, &PeerWireClient::blockRequested,
|
||||
this, &TorrentClient::peerRequestsBlock);
|
||||
connect(client, &PeerWireClient::blockReceived,
|
||||
this, &TorrentClient::blockReceived);
|
||||
connect(client, &PeerWireClient::choked,
|
||||
this, &TorrentClient::peerChoked);
|
||||
connect(client, &PeerWireClient::unchoked,
|
||||
this, &TorrentClient::peerUnchoked);
|
||||
connect(client, &PeerWireClient::bytesWritten,
|
||||
this, &TorrentClient::peerWireBytesWritten);
|
||||
connect(client, &PeerWireClient::bytesReceived,
|
||||
this, &TorrentClient::peerWireBytesReceived);
|
||||
}
|
||||
|
||||
void TorrentClient::removeClient()
|
||||
|
|
@ -890,7 +889,8 @@ void TorrentClient::removeClient()
|
|||
}
|
||||
|
||||
// Delete the client later.
|
||||
disconnect(client, SIGNAL(disconnected()), this, SLOT(removeClient()));
|
||||
disconnect(client, &PeerWireClient::disconnected,
|
||||
this, &TorrentClient::removeClient);
|
||||
client->deleteLater();
|
||||
ConnectionManager::instance()->removeConnection(client);
|
||||
|
||||
|
|
@ -905,7 +905,7 @@ void TorrentClient::peerPiecesAvailable(const QBitArray &pieces)
|
|||
// Find the peer in our list of announced peers. If it's there,
|
||||
// then we can use the piece list into to gather statistics that
|
||||
// help us decide what peers to connect to.
|
||||
TorrentPeer *peer = 0;
|
||||
TorrentPeer *peer = nullptr;
|
||||
QList<TorrentPeer *>::Iterator it = d->peers.begin();
|
||||
while (it != d->peers.end()) {
|
||||
if ((*it)->address == client->peerAddress() && (*it)->port == client->peerPort()) {
|
||||
|
|
@ -1163,7 +1163,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
|
|||
// many blocks have been requested.
|
||||
QList<int> currentPieces;
|
||||
bool somePiecesAreNotInProgress = false;
|
||||
TorrentPiece *lastPendingPiece = 0;
|
||||
TorrentPiece *lastPendingPiece = nullptr;
|
||||
QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
|
||||
while (it != d->payloads.end() && it.key() == client) {
|
||||
lastPendingPiece = it.value();
|
||||
|
|
@ -1183,7 +1183,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
|
|||
// If all pieces are in progress, but we haven't filled up our
|
||||
// block requesting quota, then we need to schedule another piece.
|
||||
if (!somePiecesAreNotInProgress || client->incomingBlocks().size() > 0)
|
||||
lastPendingPiece = 0;
|
||||
lastPendingPiece = nullptr;
|
||||
TorrentPiece *piece = lastPendingPiece;
|
||||
|
||||
// In warmup state, all clients request blocks from the same pieces.
|
||||
|
|
|
|||
|
|
@ -58,8 +58,7 @@
|
|||
class MetaInfo;
|
||||
class PeerWireClient;
|
||||
class TorrentClientPrivate;
|
||||
class TorrentPeer;
|
||||
class TorrentPiece;
|
||||
struct TorrentPiece;
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTimerEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -110,7 +109,7 @@ public:
|
|||
ServerError
|
||||
};
|
||||
|
||||
TorrentClient(QObject *parent = 0);
|
||||
TorrentClient(QObject *parent = nullptr);
|
||||
~TorrentClient();
|
||||
|
||||
bool setTorrent(const QString &fileName);
|
||||
|
|
|
|||
|
|
@ -78,10 +78,10 @@ void TorrentServer::incomingConnection(qintptr socketDescriptor)
|
|||
|
||||
if (client->setSocketDescriptor(socketDescriptor)) {
|
||||
if (ConnectionManager::instance()->canAddConnection() && !clients.isEmpty()) {
|
||||
connect(client, SIGNAL(infoHashReceived(QByteArray)),
|
||||
this, SLOT(processInfoHash(QByteArray)));
|
||||
connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SLOT(removeClient()));
|
||||
connect(client, &PeerWireClient::infoHashReceived,
|
||||
this, &TorrentServer::processInfoHash);
|
||||
connect(client, QOverload<QAbstractSocket::SocketError>::of(&PeerWireClient::error),
|
||||
this, QOverload<>::of(&TorrentServer::removeClient));
|
||||
RateController::instance()->addSocket(client);
|
||||
ConnectionManager::instance()->addConnection(client);
|
||||
return;
|
||||
|
|
@ -104,7 +104,7 @@ void TorrentServer::processInfoHash(const QByteArray &infoHash)
|
|||
PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
|
||||
for (TorrentClient *client : qAsConst(clients)) {
|
||||
if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) {
|
||||
peer->disconnect(peer, 0, this, 0);
|
||||
peer->disconnect(peer, nullptr, this, nullptr);
|
||||
client->setupIncomingConnection(peer);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,14 +60,8 @@
|
|||
TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
|
||||
: QObject(parent), torrentDownloader(downloader)
|
||||
{
|
||||
length = 0;
|
||||
requestInterval = 5 * 60;
|
||||
requestIntervalTimer = -1;
|
||||
firstTrackerRequest = true;
|
||||
lastTrackerRequest = false;
|
||||
firstSeeding = true;
|
||||
|
||||
connect(&http, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpRequestDone(QNetworkReply*)));
|
||||
connect(&http, &QNetworkAccessManager::finished,
|
||||
this, &TrackerClient::httpRequestDone);
|
||||
}
|
||||
|
||||
void TrackerClient::start(const MetaInfo &info)
|
||||
|
|
@ -157,8 +151,8 @@ void TrackerClient::fetchPeerList()
|
|||
if (!url.userName().isEmpty()) {
|
||||
uname = url.userName();
|
||||
pwd = url.password();
|
||||
connect(&http, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
|
||||
this, SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
|
||||
connect(&http, &QNetworkAccessManager::authenticationRequired,
|
||||
this, &TrackerClient::provideAuthentication);
|
||||
}
|
||||
http.get(req);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class TrackerClient : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TrackerClient(TorrentClient *downloader, QObject *parent = 0);
|
||||
explicit TrackerClient(TorrentClient *downloader, QObject *parent = nullptr);
|
||||
|
||||
void start(const MetaInfo &info);
|
||||
void stop();
|
||||
|
|
@ -98,21 +98,19 @@ private slots:
|
|||
private:
|
||||
TorrentClient *torrentDownloader;
|
||||
|
||||
int requestInterval;
|
||||
int requestIntervalTimer;
|
||||
int requestInterval = 5 * 60;
|
||||
int requestIntervalTimer = -1;
|
||||
QNetworkAccessManager http;
|
||||
MetaInfo metaInfo;
|
||||
QByteArray trackerId;
|
||||
QList<TorrentPeer> peers;
|
||||
qint64 uploadedBytes;
|
||||
qint64 downloadedBytes;
|
||||
qint64 length;
|
||||
qint64 length = 0;
|
||||
QString uname;
|
||||
QString pwd;
|
||||
|
||||
bool firstTrackerRequest;
|
||||
bool lastTrackerRequest;
|
||||
bool firstSeeding;
|
||||
bool firstTrackerRequest = true;
|
||||
bool lastTrackerRequest = false;
|
||||
bool firstSeeding = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue