From e85de7d787498624020884ef2e269c15faf76b50 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 1 Nov 2019 13:21:32 +0100 Subject: Cleanup network examples Cleanup network examples: - use nullptr - use member-init - adjust includes - use new-style connects Change-Id: I80aa230168e5aec88a1bc93bbf49a471bfc30e7b Reviewed-by: Timur Pocheptsov --- examples/network/torrent/addtorrentdialog.cpp | 12 ++-- examples/network/torrent/addtorrentdialog.h | 2 +- examples/network/torrent/filemanager.h | 2 +- examples/network/torrent/mainwindow.cpp | 92 +++++++++++++++------------ examples/network/torrent/mainwindow.h | 2 +- examples/network/torrent/peerwireclient.cpp | 34 +++++----- examples/network/torrent/peerwireclient.h | 2 +- examples/network/torrent/ratecontroller.cpp | 6 +- examples/network/torrent/ratecontroller.h | 9 ++- examples/network/torrent/torrentclient.cpp | 88 ++++++++++++------------- examples/network/torrent/torrentclient.h | 5 +- examples/network/torrent/torrentserver.cpp | 10 +-- examples/network/torrent/trackerclient.cpp | 14 ++-- examples/network/torrent/trackerclient.h | 16 ++--- 14 files changed, 148 insertions(+), 146 deletions(-) (limited to 'examples/network/torrent') diff --git a/examples/network/torrent/addtorrentdialog.cpp b/examples/network/torrent/addtorrentdialog.cpp index c87110ac4a..129ad8c968 100644 --- a/examples/network/torrent/addtorrentdialog.cpp +++ b/examples/network/torrent/addtorrentdialog.cpp @@ -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(); diff --git a/examples/network/torrent/addtorrentdialog.h b/examples/network/torrent/addtorrentdialog.h index b5bd1df84f..00546c624c 100644 --- a/examples/network/torrent/addtorrentdialog.h +++ b/examples/network/torrent/addtorrentdialog.h @@ -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; diff --git a/examples/network/torrent/filemanager.h b/examples/network/torrent/filemanager.h index 82f9983ea6..1438ed5404 100644 --- a/examples/network/torrent/filemanager.h +++ b/examples/network/torrent/filemanager.h @@ -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; } diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp index 704012ef6d..331fa12944 100644 --- a/examples/network/torrent/mainwindow.cpp +++ b/examples/network/torrent/mainwindow.cpp @@ -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::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) diff --git a/examples/network/torrent/mainwindow.h b/examples/network/torrent/mainwindow.h index 9c55b72256..78542b535b 100644 --- a/examples/network/torrent/mainwindow.h +++ b/examples/network/torrent/mainwindow.h @@ -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; diff --git a/examples/network/torrent/peerwireclient.cpp b/examples/network/torrent/peerwireclient.cpp index 7a53c85f0c..cea4ef53fa 100644 --- a/examples/network/torrent/peerwireclient.cpp +++ b/examples/network/torrent/peerwireclient.cpp @@ -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(&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(this, &PeerWireClient::readyRead, + this, &PeerWireClient::readyToTransfer); + connect(this, &PeerWireClient::connected, + this, &PeerWireClient::readyToTransfer); + + connect(&socket, &QTcpSocket::connected, + this, &PeerWireClient::connected); + connect(&socket, &QTcpSocket::readyRead, + this, &PeerWireClient::readyRead); + connect(&socket, &QTcpSocket::disconnected, + this, &PeerWireClient::disconnected); + connect(&socket, QOverload::of(&QTcpSocket::error), + this, QOverload::of(&PeerWireClient::error)); + connect(&socket, &QTcpSocket::bytesWritten, + this, &PeerWireClient::bytesWritten); + connect(&socket, &QTcpSocket::stateChanged, + this, &PeerWireClient::socketStateChanged); } diff --git a/examples/network/torrent/peerwireclient.h b/examples/network/torrent/peerwireclient.h index e03b538f63..75edf8ee77 100644 --- a/examples/network/torrent/peerwireclient.h +++ b/examples/network/torrent/peerwireclient.h @@ -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); diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp index 96474806f5..756947b65c 100644 --- a/examples/network/torrent/ratecontroller.cpp +++ b/examples/network/torrent/ratecontroller.cpp @@ -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); } diff --git a/examples/network/torrent/ratecontroller.h b/examples/network/torrent/ratecontroller.h index f8bff0cc36..593a76f592 100644 --- a/examples/network/torrent/ratecontroller.h +++ b/examples/network/torrent/ratecontroller.h @@ -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 sockets; - int upLimit; - int downLimit; - bool transferScheduled; + int upLimit = 0; + int downLimit = 0; + bool transferScheduled = false; }; #endif diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index bddf3caa1a..6b11338f42 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -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)), - this, SLOT(addToPeerList(QList))); - 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::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::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 currentPieces; bool somePiecesAreNotInProgress = false; - TorrentPiece *lastPendingPiece = 0; + TorrentPiece *lastPendingPiece = nullptr; QMultiMap::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. diff --git a/examples/network/torrent/torrentclient.h b/examples/network/torrent/torrentclient.h index b9b88b3a07..ad77caa66c 100644 --- a/examples/network/torrent/torrentclient.h +++ b/examples/network/torrent/torrentclient.h @@ -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); diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp index c68f33249c..215498194b 100644 --- a/examples/network/torrent/torrentserver.cpp +++ b/examples/network/torrent/torrentserver.cpp @@ -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::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(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; } diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index e883317b12..00810a98af 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -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); } diff --git a/examples/network/torrent/trackerclient.h b/examples/network/torrent/trackerclient.h index 323fc67eba..b8c169ff22 100644 --- a/examples/network/torrent/trackerclient.h +++ b/examples/network/torrent/trackerclient.h @@ -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 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 -- cgit v1.2.3 From 94b3dd77f29a00ebbd1efdc66d75f57e1c75b152 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 9 Jan 2020 11:58:34 +0100 Subject: QAbstractSocket: deprecate 'error' member-function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The one that is a getter for the last error found. This is to disambiguate the expression '&QAbstractSocket::error'. Introduce a new member-function socketError as a replacement. [ChangeLog][Deprecation Notice] QAbstractSocket::error() (the getter) is deprecated; superseded by socketError(). Task-number: QTBUG-80369 Change-Id: Ia2e3d108657aaa7929ab0810babe2ede309740ba Reviewed-by: Mårten Nordheim --- examples/network/torrent/torrentclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/network/torrent') diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index 6b11338f42..00f46df892 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -867,7 +867,7 @@ void TorrentClient::removeClient() // Remove the host from our list of known peers if the connection // failed. - if (client->peer() && client->error() == QAbstractSocket::ConnectionRefusedError) + if (client->peer() && client->socketError() == QAbstractSocket::ConnectionRefusedError) d->peers.removeAll(client->peer()); // Remove the client from RateController and all structures. -- cgit v1.2.3 From ccb2cb84f535b0bfce19a95d7f3a36803480cae8 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 10 Jan 2020 14:15:35 +0100 Subject: QNetworkReply: deprecate the 'error' getter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To disambiguate &QNetworkReply::error expression. [ChangeLog][Deprecation Notice] QNetworkReply::error() (the getter) was deprecated; superseded by networkError(). Task-number: QTBUG-80369 Change-Id: I545f963788bce0800c9e0f0c94d5f1029946effe Reviewed-by: Mårten Nordheim --- examples/network/torrent/trackerclient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/network/torrent') diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index 00810a98af..540ab31557 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -165,8 +165,8 @@ void TrackerClient::httpRequestDone(QNetworkReply *reply) return; } - if (reply->error() != QNetworkReply::NoError) { - emit connectionError(reply->error()); + if (reply->networkError() != QNetworkReply::NoError) { + emit connectionError(reply->networkError()); return; } -- cgit v1.2.3