From 0fe9cd05c4aca8be9820cd489c8fa57173df6ed3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 May 2019 15:15:59 +0800 Subject: [PATCH 1/2] Avoid using deprecated stats_alert From libtorrent doc: This alert has been superseded by calling post_torrent_updates() regularly on the session object. --- src/base/bittorrent/session.cpp | 10 ++++++---- src/base/bittorrent/torrenthandle.cpp | 14 +++----------- src/base/bittorrent/torrenthandle.h | 1 - 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 879187c7a..4ed8cf4ed 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -386,7 +386,6 @@ Session::Session(QObject *parent) | lt::alert::status_notification | lt::alert::ip_block_notification | lt::alert::performance_warning - | lt::alert::stats_notification | lt::alert::file_progress_notification; const std::string peerId = lt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); @@ -4280,12 +4279,15 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p) { for (const lt::torrent_status &status : p->status) { TorrentHandle *const torrent = m_torrents.value(status.info_hash); - if (torrent) - torrent->handleStateUpdate(status); + + if (!torrent) + continue; + + torrent->handleStateUpdate(status); } m_torrentStatusReport = TorrentStatusReport(); - for (TorrentHandle *const torrent : asConst(m_torrents)) { + for (const TorrentHandle *torrent : asConst(m_torrents)) { if (torrent->isDownloading()) ++m_torrentStatusReport.nbDownloading; if (torrent->isUploading()) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index e9b57070c..f11e5e15c 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1799,14 +1799,6 @@ void TorrentHandle::handleFileCompletedAlert(const lt::file_completed_alert *p) } } -void TorrentHandle::handleStatsAlert(const lt::stats_alert *p) -{ - Q_ASSERT(p->interval >= 1000); - const SpeedSample transferred(p->transferred[lt::stats_alert::download_payload] * 1000LL / p->interval, - p->transferred[lt::stats_alert::upload_payload] * 1000LL / p->interval); - m_speedMonitor.addSample(transferred); -} - void TorrentHandle::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) { Q_UNUSED(p); @@ -1862,9 +1854,6 @@ void TorrentHandle::handleAppendExtensionToggled() void TorrentHandle::handleAlert(const lt::alert *a) { switch (a->type()) { - case lt::stats_alert::alert_type: - handleStatsAlert(static_cast(a)); - break; case lt::file_renamed_alert::alert_type: handleFileRenamedAlert(static_cast(a)); break; @@ -2013,6 +2002,9 @@ void TorrentHandle::updateStatus(const lt::torrent_status &nativeStatus) m_unchecked = false; else if (isDownloading()) m_unchecked = true; + + m_speedMonitor.addSample({nativeStatus.download_payload_rate + , nativeStatus.upload_payload_rate}); } void TorrentHandle::setRatioLimit(qreal limit) diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 2b2538095..4eaf94482 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -368,7 +368,6 @@ namespace BitTorrent void handlePerformanceAlert(const lt::performance_alert *p) const; void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p); void handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p); - void handleStatsAlert(const lt::stats_alert *p); void handleStorageMovedAlert(const lt::storage_moved_alert *p); void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p); void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p); From 49df1cd3c7e7f471c9cb9d8dd32f1391da683f2e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 May 2019 16:19:24 +0800 Subject: [PATCH 2/2] Use less operations when building strings --- src/gui/addnewtorrentdialog.cpp | 8 +++----- src/gui/mainwindow.cpp | 27 +++++++++++++++------------ src/gui/rss/rsswidget.cpp | 10 +++++----- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index b516f8468..7b90af8c8 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -402,11 +402,9 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() } } - QString sizeString = torrentSize ? Utils::Misc::friendlyUnit(torrentSize) : QString(tr("Not Available", "This size is unavailable.")); - sizeString += " ("; - sizeString += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath( - m_ui->savePath->selectedPath()))); - sizeString += ')'; + const QString sizeString = tr("%1 (Free space on disk: %2)").arg( + ((torrentSize > 0) ? Utils::Misc::friendlyUnit(torrentSize) : tr("Not available", "This size is unavailable.")) + , Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(m_ui->savePath->selectedPath()))); m_ui->labelSizeData->setText(sizeString); } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 2504a06b5..d27366f44 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1529,20 +1529,23 @@ void MainWindow::updateGUI() #ifndef Q_OS_MAC if (m_systrayIcon) { #ifdef Q_OS_UNIX - QString html = "
"; - html += "qBittorrent"; - html += "
"; - html += "
"; - html += " " + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)); - html += "
"; - html += "
"; - html += " " + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); - html += "
"; + const QString html = QString(QLatin1String( + "
" + "qBittorrent" + "
" + "
" + " %1" + "
" + "
" + " %2" + "
")) + .arg(tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)) + , tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true))); #else // OSes such as Windows do not support html here - QString html = tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)); - html += '\n'; - html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); + const QString html = QString("%1\n%2").arg( + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)) + , tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true))); #endif // Q_OS_UNIX m_systrayIcon->setToolTip(html); // tray icon } diff --git a/src/gui/rss/rsswidget.cpp b/src/gui/rss/rsswidget.cpp index 6525cc7e6..7f2e33f26 100644 --- a/src/gui/rss/rsswidget.cpp +++ b/src/gui/rss/rsswidget.cpp @@ -448,15 +448,15 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL auto article = m_articleListWidget->getRSSArticle(currentItem); Q_ASSERT(article); - QString html; - html += "
"; - html += "
" + article->title() + "
"; + QString html = + "
" + "
" + article->title() + "
"; if (article->date().isValid()) html += "
" + tr("Date: ") + "" + article->date().toLocalTime().toString(Qt::SystemLocaleLongDate) + "
"; if (!article->author().isEmpty()) html += "
" + tr("Author: ") + "" + article->author() + "
"; - html += "
"; - html += "
"; + html += "
" + "
"; if (Qt::mightBeRichText(article->description())) { html += article->description(); }