Merge pull request #10732 from Chocobo1/refactor

Avoid using deprecated stats_alert
This commit is contained in:
Mike Tzou 2019-06-01 10:07:52 +08:00 committed by GitHub
commit 84e683cc99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 38 deletions

View file

@ -386,7 +386,6 @@ Session::Session(QObject *parent)
| lt::alert::status_notification | lt::alert::status_notification
| lt::alert::ip_block_notification | lt::alert::ip_block_notification
| lt::alert::performance_warning | lt::alert::performance_warning
| lt::alert::stats_notification
| lt::alert::file_progress_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); 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) { for (const lt::torrent_status &status : p->status) {
TorrentHandle *const torrent = m_torrents.value(status.info_hash); TorrentHandle *const torrent = m_torrents.value(status.info_hash);
if (torrent)
if (!torrent)
continue;
torrent->handleStateUpdate(status); torrent->handleStateUpdate(status);
} }
m_torrentStatusReport = TorrentStatusReport(); m_torrentStatusReport = TorrentStatusReport();
for (TorrentHandle *const torrent : asConst(m_torrents)) { for (const TorrentHandle *torrent : asConst(m_torrents)) {
if (torrent->isDownloading()) if (torrent->isDownloading())
++m_torrentStatusReport.nbDownloading; ++m_torrentStatusReport.nbDownloading;
if (torrent->isUploading()) if (torrent->isUploading())

View file

@ -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) void TorrentHandle::handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
{ {
Q_UNUSED(p); Q_UNUSED(p);
@ -1862,9 +1854,6 @@ void TorrentHandle::handleAppendExtensionToggled()
void TorrentHandle::handleAlert(const lt::alert *a) void TorrentHandle::handleAlert(const lt::alert *a)
{ {
switch (a->type()) { switch (a->type()) {
case lt::stats_alert::alert_type:
handleStatsAlert(static_cast<const lt::stats_alert*>(a));
break;
case lt::file_renamed_alert::alert_type: case lt::file_renamed_alert::alert_type:
handleFileRenamedAlert(static_cast<const lt::file_renamed_alert*>(a)); handleFileRenamedAlert(static_cast<const lt::file_renamed_alert*>(a));
break; break;
@ -2013,6 +2002,9 @@ void TorrentHandle::updateStatus(const lt::torrent_status &nativeStatus)
m_unchecked = false; m_unchecked = false;
else if (isDownloading()) else if (isDownloading())
m_unchecked = true; m_unchecked = true;
m_speedMonitor.addSample({nativeStatus.download_payload_rate
, nativeStatus.upload_payload_rate});
} }
void TorrentHandle::setRatioLimit(qreal limit) void TorrentHandle::setRatioLimit(qreal limit)

View file

@ -368,7 +368,6 @@ namespace BitTorrent
void handlePerformanceAlert(const lt::performance_alert *p) const; void handlePerformanceAlert(const lt::performance_alert *p) const;
void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p); void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p);
void handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_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 handleStorageMovedAlert(const lt::storage_moved_alert *p);
void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p); void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p); void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p);

View file

@ -402,11 +402,9 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
} }
} }
QString sizeString = torrentSize ? Utils::Misc::friendlyUnit(torrentSize) : QString(tr("Not Available", "This size is unavailable.")); const QString sizeString = tr("%1 (Free space on disk: %2)").arg(
sizeString += " ("; ((torrentSize > 0) ? Utils::Misc::friendlyUnit(torrentSize) : tr("Not available", "This size is unavailable."))
sizeString += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath( , Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(m_ui->savePath->selectedPath())));
m_ui->savePath->selectedPath())));
sizeString += ')';
m_ui->labelSizeData->setText(sizeString); m_ui->labelSizeData->setText(sizeString);
} }

View file

@ -1529,20 +1529,23 @@ void MainWindow::updateGUI()
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
if (m_systrayIcon) { if (m_systrayIcon) {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
QString html = "<div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'>"; const QString html = QString(QLatin1String(
html += "qBittorrent"; "<div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'>"
html += "</div>"; "qBittorrent"
html += "<div style='vertical-align: baseline; height: 18px;'>"; "</div>"
html += "<img src=':/icons/skin/download.svg' height='14'/>&nbsp;" + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)); "<div style='vertical-align: baseline; height: 18px;'>"
html += "</div>"; "<img src=':/icons/skin/download.svg' height='14'/>&nbsp;%1"
html += "<div style='vertical-align: baseline; height: 18px;'>"; "</div>"
html += "<img src=':/icons/skin/seeding.svg' height='14'/>&nbsp;" + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); "<div style='vertical-align: baseline; height: 18px;'>"
html += "</div>"; "<img src=':/icons/skin/seeding.svg' height='14'/>&nbsp;%2"
"</div>"))
.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 #else
// OSes such as Windows do not support html here // 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)); const QString html = QString("%1\n%2").arg(
html += '\n'; tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); , tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
#endif // Q_OS_UNIX #endif // Q_OS_UNIX
m_systrayIcon->setToolTip(html); // tray icon m_systrayIcon->setToolTip(html); // tray icon
} }

View file

@ -448,15 +448,15 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL
auto article = m_articleListWidget->getRSSArticle(currentItem); auto article = m_articleListWidget->getRSSArticle(currentItem);
Q_ASSERT(article); Q_ASSERT(article);
QString html; QString html =
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>"; "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>"
html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>" + article->title() + "</div>"; "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>" + article->title() + "</div>";
if (article->date().isValid()) if (article->date().isValid())
html += "<div style='background-color: #efefef;'><b>" + tr("Date: ") + "</b>" + article->date().toLocalTime().toString(Qt::SystemLocaleLongDate) + "</div>"; html += "<div style='background-color: #efefef;'><b>" + tr("Date: ") + "</b>" + article->date().toLocalTime().toString(Qt::SystemLocaleLongDate) + "</div>";
if (!article->author().isEmpty()) if (!article->author().isEmpty())
html += "<div style='background-color: #efefef;'><b>" + tr("Author: ") + "</b>" + article->author() + "</div>"; html += "<div style='background-color: #efefef;'><b>" + tr("Author: ") + "</b>" + article->author() + "</div>";
html += "</div>"; html += "</div>"
html += "<div style='margin-left: 5px; margin-right: 5px;'>"; "<div style='margin-left: 5px; margin-right: 5px;'>";
if (Qt::mightBeRichText(article->description())) { if (Qt::mightBeRichText(article->description())) {
html += article->description(); html += article->description();
} }