Browse Source

Merge pull request #11269 from Chocobo1/signals

Improve "stats updated" signal handling in MainWindow class
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
7a3607c729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/base/bittorrent/session.cpp
  2. 43
      src/gui/mainwindow.cpp
  3. 3
      src/gui/mainwindow.h

3
src/base/bittorrent/session.cpp

@ -4399,7 +4399,8 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p) @@ -4399,7 +4399,8 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
updatedTorrents.push_back(torrent);
}
emit torrentsUpdated(updatedTorrents);
if (!updatedTorrents.isEmpty())
emit torrentsUpdated(updatedTorrents);
}
namespace

43
src/gui/mainwindow.cpp

@ -335,7 +335,8 @@ MainWindow::MainWindow(QWidget *parent) @@ -335,7 +335,8 @@ MainWindow::MainWindow(QWidget *parent)
// Configure BT session according to options
loadPreferences(false);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated, this, &MainWindow::updateGUI);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated, this, &MainWindow::reloadSessionStats);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated, this, &MainWindow::reloadTorrentStats);
// Accept drag 'n drops
setAcceptDrops(true);
@ -1509,19 +1510,23 @@ void MainWindow::loadPreferences(bool configureSession) @@ -1509,19 +1510,23 @@ void MainWindow::loadPreferences(bool configureSession)
qDebug("GUI settings loaded");
}
// Check connection status and display right icon
void MainWindow::updateGUI()
void MainWindow::reloadSessionStats()
{
if (currentTabWidget() == m_transferListWidget)
m_propertiesWidget->loadDynamicData();
const BitTorrent::SessionStatus &status = BitTorrent::Session::instance()->status();
// update global information
#ifndef Q_OS_MACOS
#ifdef Q_OS_MACOS
if (status.payloadDownloadRate > 0) {
QtMac::setBadgeLabelText(tr("%1/s", "s is a shorthand for seconds")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate)));
}
else if (!QtMac::badgeLabelText().isEmpty()) {
QtMac::setBadgeLabelText("");
}
#else
if (m_systrayIcon) {
#ifdef Q_OS_UNIX
const QString html = QString(QLatin1String(
const QString toolTip = QString(QLatin1String(
"<div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'>"
"qBittorrent"
"</div>"
@ -1535,19 +1540,13 @@ void MainWindow::updateGUI() @@ -1535,19 +1540,13 @@ void MainWindow::updateGUI()
, 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
const QString html = QString("%1\n%2").arg(
const QString toolTip = 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
m_systrayIcon->setToolTip(toolTip); // tray icon
}
#else
if (status.payloadDownloadRate > 0)
QtMac::setBadgeLabelText(tr("%1/s", "s is a shorthand for seconds")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate)));
else if (!QtMac::badgeLabelText().isEmpty())
QtMac::setBadgeLabelText("");
#endif // Q_OS_MACOS
#endif // Q_OS_MACOS
if (m_displaySpeedInTitle) {
setWindowTitle(tr("[D: %1, U: %2] qBittorrent %3", "D = Download; U = Upload; %3 is qBittorrent version")
@ -1557,6 +1556,14 @@ void MainWindow::updateGUI() @@ -1557,6 +1556,14 @@ void MainWindow::updateGUI()
}
}
void MainWindow::reloadTorrentStats(const QVector<BitTorrent::TorrentHandle *> &torrents)
{
if (currentTabWidget() == m_transferListWidget) {
if (torrents.contains(m_propertiesWidget->getCurrentTorrent()))
m_propertiesWidget->loadDynamicData();
}
}
void MainWindow::showNotificationBaloon(const QString &title, const QString &msg) const
{
if (!isNotificationsEnabled()) return;
@ -1726,7 +1733,7 @@ void MainWindow::on_actionSpeedInTitleBar_triggered() @@ -1726,7 +1733,7 @@ void MainWindow::on_actionSpeedInTitleBar_triggered()
m_displaySpeedInTitle = static_cast<QAction * >(sender())->isChecked();
Preferences::instance()->showSpeedInTitleBar(m_displaySpeedInTitle);
if (m_displaySpeedInTitle)
updateGUI();
reloadSessionStats();
else
setWindowTitle("qBittorrent " QBT_VERSION);
}

3
src/gui/mainwindow.h

@ -127,7 +127,8 @@ private slots: @@ -127,7 +127,8 @@ private slots:
void displayRSSTab();
void displayExecutionLogTab();
void focusSearchFilter();
void updateGUI();
void reloadSessionStats();
void reloadTorrentStats(const QVector<BitTorrent::TorrentHandle *> &torrents);
void loadPreferences(bool configureSession = true);
void addTorrentFailed(const QString &error) const;
void torrentNew(BitTorrent::TorrentHandle *const torrent) const;

Loading…
Cancel
Save