Use cached SessionStatus and CacheStatus

This commit is contained in:
Vladimir Golovnev (Glassez)
2017-04-29 14:45:30 +03:00
parent cb678a254d
commit 8a6d8f3953
15 changed files with 171 additions and 360 deletions

View File

@@ -1319,7 +1319,7 @@ void MainWindow::trackerAuthenticationRequired(BitTorrent::TorrentHandle *const
// Check connection status and display right icon
void MainWindow::updateGUI()
{
BitTorrent::SessionStatus status = BitTorrent::Session::instance()->status();
const BitTorrent::SessionStatus &status = BitTorrent::Session::instance()->status();
// update global informations
if (m_systrayIcon) {
@@ -1328,24 +1328,24 @@ void MainWindow::updateGUI()
html += "qBittorrent";
html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/icons/skin/download.png' height='14'/>&nbsp;" + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate(), true));
html += "<img src=':/icons/skin/download.png' height='14'/>&nbsp;" + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true));
html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/icons/skin/seeding.png' height='14'/>&nbsp;" + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate(), true));
html += "<img src=':/icons/skin/seeding.png' height='14'/>&nbsp;" + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true));
html += "</div>";
#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));
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));
html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true));
#endif
m_systrayIcon->setToolTip(html); // tray icon
}
if (m_displaySpeedInTitle) {
setWindowTitle(tr("[D: %1, U: %2] qBittorrent %3", "D = Download; U = Upload; %3 is qBittorrent version")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate(), true))
.arg(Utils::Misc::friendlyUnit(status.payloadUploadRate(), true))
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
.arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true))
.arg(QBT_VERSION));
}
}

View File

@@ -45,7 +45,8 @@
ComboBoxMenuButton::ComboBoxMenuButton(QWidget *parent, QMenu *menu)
: QComboBox(parent)
, m_menu(menu)
{}
{
}
void ComboBoxMenuButton::showPopup()
{
@@ -134,20 +135,20 @@ void SpeedWidget::update()
{
while (m_isUpdating) {
BitTorrent::SessionStatus btStatus = BitTorrent::Session::instance()->status();
const BitTorrent::SessionStatus &btStatus = BitTorrent::Session::instance()->status();
SpeedPlotView::PointData point;
point.x = QDateTime::currentDateTime().toTime_t();
point.y[SpeedPlotView::UP] = btStatus.uploadRate();
point.y[SpeedPlotView::DOWN] = btStatus.downloadRate();
point.y[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate();
point.y[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate();
point.y[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate();
point.y[SpeedPlotView::OVERHEAD_DOWN] = btStatus.ipOverheadDownloadRate();
point.y[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate();
point.y[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate();
point.y[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate();
point.y[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate();
point.y[SpeedPlotView::UP] = btStatus.uploadRate;
point.y[SpeedPlotView::DOWN] = btStatus.downloadRate;
point.y[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate;
point.y[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate;
point.y[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate;
point.y[SpeedPlotView::OVERHEAD_DOWN] = btStatus.ipOverheadDownloadRate;
point.y[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate;
point.y[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate;
point.y[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate;
point.y[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate;
m_plot->pushPoint(point);

View File

@@ -45,25 +45,21 @@ StatsDialog::StatsDialog(QWidget *parent)
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &StatsDialog::close);
update();
m_timer = new QTimer(this);
m_timer->setInterval(1500);
connect(m_timer, &QTimer::timeout, this, &StatsDialog::update);
m_timer->start();
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatsDialog::update);
show();
}
StatsDialog::~StatsDialog()
{
m_timer->stop();
delete m_timer;
delete m_ui;
}
void StatsDialog::update()
{
BitTorrent::SessionStatus ss = BitTorrent::Session::instance()->status();
BitTorrent::CacheStatus cs = BitTorrent::Session::instance()->cacheStatus();
const BitTorrent::SessionStatus &ss = BitTorrent::Session::instance()->status();
const BitTorrent::CacheStatus &cs = BitTorrent::Session::instance()->cacheStatus();
// Alltime DL/UL
quint64 atd = BitTorrent::Session::instance()->getAlltimeDL();
@@ -71,17 +67,17 @@ void StatsDialog::update()
m_ui->labelAlltimeDL->setText(Utils::Misc::friendlyUnit(atd));
m_ui->labelAlltimeUL->setText(Utils::Misc::friendlyUnit(atu));
// Total waste (this session)
m_ui->labelWaste->setText(Utils::Misc::friendlyUnit(ss.totalWasted()));
m_ui->labelWaste->setText(Utils::Misc::friendlyUnit(ss.totalWasted));
// Global ratio
m_ui->labelGlobalRatio->setText(
((atd > 0) && (atu > 0))
? Utils::String::fromDouble((qreal)atu / (qreal)atd, 2)
: "-");
// Cache hits
qreal readRatio = cs.readRatio();
qreal readRatio = cs.readRatio;
m_ui->labelCacheHits->setText((readRatio >= 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "-");
// Buffers size
m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers() * 16 * 1024));
m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers * 16 * 1024));
// Disk overload (100%) equivalent
// From lt manual: disk_write_queue and disk_read_queue are the number of peers currently waiting on a disk write or disk read
// to complete before it receives or sends any more data on the socket. It's a metric of how disk bound you are.
@@ -92,18 +88,18 @@ void StatsDialog::update()
peers += torrent->peersCount();
m_ui->labelWriteStarve->setText(QString("%1%")
.arg(((ss.diskWriteQueue() > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskWriteQueue()) / peers, 2)
.arg(((ss.diskWriteQueue > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskWriteQueue) / peers, 2)
: "0"));
m_ui->labelReadStarve->setText(QString("%1%")
.arg(((ss.diskReadQueue() > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskReadQueue()) / peers, 2)
.arg(((ss.diskReadQueue > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskReadQueue) / peers, 2)
: "0"));
// Disk queues
m_ui->labelQueuedJobs->setText(QString::number(cs.jobQueueLength()));
m_ui->labelJobsTime->setText(tr("%1 ms", "18 milliseconds").arg(cs.averageJobTime()));
m_ui->labelQueuedBytes->setText(Utils::Misc::friendlyUnit(cs.queuedBytes()));
m_ui->labelQueuedJobs->setText(QString::number(cs.jobQueueLength));
m_ui->labelJobsTime->setText(tr("%1 ms", "18 milliseconds").arg(cs.averageJobTime));
m_ui->labelQueuedBytes->setText(Utils::Misc::friendlyUnit(cs.queuedBytes));
// Total connected peers
m_ui->labelPeers->setText(QString::number(ss.peersCount()));
m_ui->labelPeers->setText(QString::number(ss.peersCount));
}

View File

@@ -30,7 +30,6 @@
#define STATSDIALOG_H
#include <QDialog>
#include <QTimer>
namespace Ui
{
@@ -50,7 +49,6 @@ private slots:
private:
Ui::StatsDialog *m_ui;
QTimer *m_timer;
};
#endif // STATSDIALOG_H

View File

@@ -34,7 +34,6 @@
#include <QStatusBar>
#include <QFrame>
#include <QLabel>
#include <QTimer>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFontMetrics>
@@ -135,10 +134,9 @@ StatusBar::StatusBar(QStatusBar *bar)
bar->adjustSize();
// Is DHT enabled
m_DHTLbl->setVisible(session->isDHTEnabled());
m_refreshTimer = new QTimer(bar);
refreshStatusBar();
connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refreshStatusBar()));
m_refreshTimer->start(1500);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatusBar::refreshStatusBar);
}
StatusBar::~StatusBar()
@@ -167,19 +165,16 @@ void StatusBar::showRestartRequired()
Logger::instance()->addMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective."), Log::CRITICAL);
}
void StatusBar::stopTimer()
void StatusBar::updateConnectionStatus()
{
m_refreshTimer->stop();
}
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
void StatusBar::updateConnectionStatus(const BitTorrent::SessionStatus &sessionStatus)
{
if (!BitTorrent::Session::instance()->isListening()) {
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/skin/disconnected.png")));
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection Status:") + QLatin1String("</b><br>") + tr("Offline. This usually means that qBittorrent failed to listen on the selected port for incoming connections."));
}
else {
if (sessionStatus.hasIncomingConnections()) {
if (sessionStatus.hasIncomingConnections) {
// Connection OK
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/skin/connected.png")));
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection Status:") + QLatin1String("</b><br>") + tr("Online"));
@@ -191,39 +186,41 @@ void StatusBar::updateConnectionStatus(const BitTorrent::SessionStatus &sessionS
}
}
void StatusBar::updateDHTNodesNumber(const BitTorrent::SessionStatus &sessionStatus)
void StatusBar::updateDHTNodesNumber()
{
if (BitTorrent::Session::instance()->isDHTEnabled()) {
m_DHTLbl->setVisible(true);
m_DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dhtNodes())));
m_DHTLbl->setText(tr("DHT: %1 nodes")
.arg(QString::number(BitTorrent::Session::instance()->status().dhtNodes)));
}
else {
m_DHTLbl->setVisible(false);
}
}
void StatusBar::updateSpeedLabels(const BitTorrent::SessionStatus &sessionStatus)
void StatusBar::updateSpeedLabels()
{
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate(), true);
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true);
int speedLimit = BitTorrent::Session::instance()->downloadSpeedLimit();
if (speedLimit)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + "]";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload()) + ")";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ")";
m_dlSpeedLbl->setText(speedLbl);
speedLimit = BitTorrent::Session::instance()->uploadSpeedLimit();
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate(), true);
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true);
if (speedLimit)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + "]";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload()) + ")";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ")";
m_upSpeedLbl->setText(speedLbl);
}
void StatusBar::refreshStatusBar()
{
const BitTorrent::SessionStatus sessionStatus = BitTorrent::Session::instance()->status();
updateConnectionStatus(sessionStatus);
updateDHTNodesNumber(sessionStatus);
updateSpeedLabels(sessionStatus);
updateConnectionStatus();
updateDHTNodesNumber();
updateSpeedLabels();
}
void StatusBar::updateAltSpeedsBtn(bool alternative)

View File

@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef STATUSBAR_H
@@ -36,13 +34,12 @@
class QStatusBar;
class QFrame;
class QLabel;
class QTimer;
class QPushButton;
class QHBoxLayout;
namespace BitTorrent
{
class SessionStatus;
struct SessionStatus;
}
class StatusBar: public QObject
@@ -57,7 +54,6 @@ public:
public slots:
void showRestartRequired();
void stopTimer();
void refreshStatusBar();
void updateAltSpeedsBtn(bool alternative);
void toggleAlternativeSpeeds();
@@ -65,6 +61,10 @@ public slots:
void capUploadSpeed();
private:
void updateConnectionStatus();
void updateDHTNodesNumber();
void updateSpeedLabels();
QStatusBar *m_bar;
QPushButton *m_dlSpeedLbl;
QPushButton *m_upSpeedLbl;
@@ -75,13 +75,8 @@ private:
QFrame *m_statusSep4;
QPushButton *m_connecStatusLblIcon;
QPushButton *m_altSpeedsBtn;
QTimer *m_refreshTimer;
QWidget *m_container;
QHBoxLayout *m_layout;
void updateConnectionStatus(const BitTorrent::SessionStatus &sessionStatus);
void updateDHTNodesNumber(const BitTorrent::SessionStatus &sessionStatus);
void updateSpeedLabels(const BitTorrent::SessionStatus &sessionStatus);
};
#endif // STATUSBAR_H