Browse Source

Refactor and improve StatusBar

adaptive-webui-19844
Vladimir Golovnev (Glassez) 8 years ago
parent
commit
c456b9a42c
  1. 40
      src/gui/mainwindow.cpp
  2. 4
      src/gui/mainwindow.h
  3. 152
      src/gui/statusbar.cpp
  4. 28
      src/gui/statusbar.h

40
src/gui/mainwindow.cpp

@ -264,6 +264,7 @@ MainWindow::MainWindow(QWidget *parent) @@ -264,6 +264,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_ui->actionBottomPriority, SIGNAL(triggered()), m_transferListWidget, SLOT(bottomPrioSelectedTorrents()));
connect(m_ui->actionToggleVisibility, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
connect(m_ui->actionMinimize, SIGNAL(triggered()), SLOT(minimizeWindow()));
connect(m_ui->actionUseAlternativeSpeedLimits, &QAction::triggered, this, &MainWindow::toggleAlternativeSpeeds);
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
m_programUpdateTimer = new QTimer(this);
@ -289,10 +290,6 @@ MainWindow::MainWindow(QWidget *parent) @@ -289,10 +290,6 @@ MainWindow::MainWindow(QWidget *parent)
// Accept drag 'n drops
setAcceptDrops(true);
createKeyboardShortcuts();
// Create status bar
m_statusBar = new StatusBar(QMainWindow::statusBar());
connect(m_statusBar->connectionStatusButton(), SIGNAL(clicked()), SLOT(showConnectionSettings()));
connect(m_ui->actionUseAlternativeSpeedLimits, SIGNAL(triggered()), m_statusBar, SLOT(toggleAlternativeSpeeds()));
#ifdef Q_OS_MAC
setUnifiedTitleAndToolBarOnMac(true);
@ -951,6 +948,8 @@ void MainWindow::notifyOfUpdate(QString) @@ -951,6 +948,8 @@ void MainWindow::notifyOfUpdate(QString)
{
// Show restart message
m_statusBar->showRestartRequired();
Logger::instance()->addMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective.")
, Log::CRITICAL);
// Delete the executable watcher
delete m_executableWatcher;
m_executableWatcher = 0;
@ -1240,7 +1239,21 @@ void MainWindow::optionsSaved() @@ -1240,7 +1239,21 @@ void MainWindow::optionsSaved()
loadPreferences();
}
// Load program preferences
void MainWindow::showStatusBar(bool show)
{
if (show && !m_statusBar) {
// Create status bar
m_statusBar = new StatusBar;
connect(m_statusBar.data(), &StatusBar::connectionButtonClicked, this, &MainWindow::showConnectionSettings);
connect(m_statusBar.data(), &StatusBar::alternativeSpeedsButtonClicked, this, &MainWindow::toggleAlternativeSpeeds);
setStatusBar(m_statusBar);
}
else if (!show && m_statusBar) {
// Remove status bar
setStatusBar(nullptr);
}
}
void MainWindow::loadPreferences(bool configureSession)
{
Logger::instance()->addMessage(tr("Options were saved successfully."));
@ -1285,7 +1298,7 @@ void MainWindow::loadPreferences(bool configureSession) @@ -1285,7 +1298,7 @@ void MainWindow::loadPreferences(bool configureSession)
m_ui->toolBar->setVisible(false);
}
m_statusBar->setVisible(pref->isStatusbarDisplayed());
showStatusBar(pref->isStatusbarDisplayed());
if (pref->preventFromSuspend() && !m_preventTimer->isActive()) {
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
@ -1541,16 +1554,16 @@ void MainWindow::on_actionOptions_triggered() @@ -1541,16 +1554,16 @@ void MainWindow::on_actionOptions_triggered()
void MainWindow::on_actionTopToolBar_triggered()
{
bool isVisible = static_cast<QAction * >(sender())->isChecked();
const bool isVisible = static_cast<QAction*>(sender())->isChecked();
m_ui->toolBar->setVisible(isVisible);
Preferences::instance()->setToolbarDisplayed(isVisible);
}
void MainWindow::on_actionShowStatusbar_triggered()
{
bool isVisible = static_cast<QAction*>(sender())->isChecked();
m_statusBar->setVisible(isVisible);
const bool isVisible = static_cast<QAction*>(sender())->isChecked();
Preferences::instance()->setStatusbarDisplayed(isVisible);
showStatusBar(isVisible);
}
void MainWindow::on_actionSpeedInTitleBar_triggered()
@ -1681,9 +1694,16 @@ void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVers @@ -1681,9 +1694,16 @@ void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVers
if (Preferences::instance()->isUpdateCheckEnabled() && (answer == QMessageBox::Yes))
m_programUpdateTimer->start();
}
#endif
void MainWindow::toggleAlternativeSpeeds()
{
BitTorrent::Session *const session = BitTorrent::Session::instance();
if (session->isBandwidthSchedulerEnabled())
m_statusBar->showMessage(tr("Manual change of rate limits mode. The scheduler is disabled."), 5000);
session->setAltGlobalSpeedLimitEnabled(!session->isAltGlobalSpeedLimitEnabled());
}
void MainWindow::on_actionDonateMoney_triggered()
{
QDesktopServices::openUrl(QUrl("http://www.qbittorrent.org/donate"));

4
src/gui/mainwindow.h

@ -137,6 +137,7 @@ private slots: @@ -137,6 +137,7 @@ private slots:
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
void handleUpdateCheckFinished(bool updateAvailable, QString newVersion, bool invokedByUser);
#endif
void toggleAlternativeSpeeds();
#ifdef Q_OS_WIN
void pythonDownloadSuccess(const QString &url, const QString &filePath);
@ -204,6 +205,7 @@ private: @@ -204,6 +205,7 @@ private:
void displayRSSTab(bool enable);
void displaySearchTab(bool enable);
void createTorrentTriggered(const QString &path = QString());
void showStatusBar(bool show);
Ui::MainWindow *m_ui;
@ -213,7 +215,7 @@ private: @@ -213,7 +215,7 @@ private:
// GUI related
bool m_posInitialized;
QPointer<QTabWidget> m_tabs;
StatusBar *m_statusBar;
QPointer<StatusBar> m_statusBar;
QPointer<OptionsDialog> m_options;
QPointer<about> m_aboutDlg;
QPointer<StatsDialog> m_statsDlg;

152
src/gui/statusbar.cpp

@ -1,6 +1,6 @@ @@ -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,74 +24,74 @@ @@ -24,74 +24,74 @@
* 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
*/
#include "statusbar.h"
#include <QApplication>
#include <QStatusBar>
#include <QDebug>
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFontMetrics>
#include <QDebug>
#include <QStyle>
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "speedlimitdlg.h"
#include "guiiconprovider.h"
#include "base/utils/misc.h"
#include "base/logger.h"
#include "guiiconprovider.h"
#include "speedlimitdlg.h"
StatusBar::StatusBar(QStatusBar *bar)
: m_bar(bar)
StatusBar::StatusBar(QWidget *parent)
: QStatusBar(parent)
{
qApp->setStyleSheet("QStatusBar::item { border-width: 0; }");
BitTorrent::Session *const session = BitTorrent::Session::instance();
connect(session, SIGNAL(speedLimitModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
m_container = new QWidget(bar);
m_layout = new QHBoxLayout(m_container);
m_layout->setContentsMargins(0,0,0,0);
connect(session, &BitTorrent::Session::speedLimitModeChanged, this, &StatusBar::updateAltSpeedsBtn);
QWidget *container = new QWidget(this);
QHBoxLayout *layout = new QHBoxLayout(container);
layout->setContentsMargins(0,0,0,0);
m_container->setLayout(m_layout);
m_connecStatusLblIcon = new QPushButton(bar);
container->setLayout(layout);
m_connecStatusLblIcon = new QPushButton(this);
m_connecStatusLblIcon->setFlat(true);
m_connecStatusLblIcon->setFocusPolicy(Qt::NoFocus);
m_connecStatusLblIcon->setCursor(Qt::PointingHandCursor);
m_connecStatusLblIcon->setIcon(QIcon(":/icons/skin/firewalled.png"));
m_connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>") + tr("Connection status:") + QString::fromUtf8("</b><br>") + QString::fromUtf8("<i>") + tr("No direct connections. This may indicate network configuration problems.") + QString::fromUtf8("</i>"));
m_connecStatusLblIcon->setToolTip(
QString(QLatin1String("<b>%1</b><br><i>%2</i>"))
.arg(tr("Connection status:"))
.arg(tr("No direct connections. This may indicate network configuration problems.")));
connect(m_connecStatusLblIcon, &QAbstractButton::clicked, this, &StatusBar::connectionButtonClicked);
m_dlSpeedLbl = new QPushButton(bar);
m_dlSpeedLbl = new QPushButton(this);
m_dlSpeedLbl->setIcon(QIcon(":/icons/skin/download.png"));
connect(m_dlSpeedLbl, SIGNAL(clicked()), this, SLOT(capDownloadSpeed()));
connect(m_dlSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capDownloadSpeed);
m_dlSpeedLbl->setFlat(true);
m_dlSpeedLbl->setFocusPolicy(Qt::NoFocus);
m_dlSpeedLbl->setCursor(Qt::PointingHandCursor);
m_dlSpeedLbl->setStyleSheet("text-align:left;");
m_dlSpeedLbl->setMinimumWidth(200);
m_upSpeedLbl = new QPushButton(bar);
m_upSpeedLbl = new QPushButton(this);
m_upSpeedLbl->setIcon(QIcon(":/icons/skin/seeding.png"));
connect(m_upSpeedLbl, SIGNAL(clicked()), this, SLOT(capUploadSpeed()));
connect(m_upSpeedLbl, &QAbstractButton::clicked, this, &StatusBar::capUploadSpeed);
m_upSpeedLbl->setFlat(true);
m_upSpeedLbl->setFocusPolicy(Qt::NoFocus);
m_upSpeedLbl->setCursor(Qt::PointingHandCursor);
m_upSpeedLbl->setStyleSheet("text-align:left;");
m_upSpeedLbl->setMinimumWidth(200);
m_DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), bar);
m_DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), this);
m_DHTLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
m_altSpeedsBtn = new QPushButton(bar);
m_altSpeedsBtn = new QPushButton(this);
m_altSpeedsBtn->setFlat(true);
m_altSpeedsBtn->setFocusPolicy(Qt::NoFocus);
m_altSpeedsBtn->setCursor(Qt::PointingHandCursor);
updateAltSpeedsBtn(session->isAltGlobalSpeedLimitEnabled());
connect(m_altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds()));
connect(m_altSpeedsBtn, &QAbstractButton::clicked, this, &StatusBar::alternativeSpeedsButtonClicked);
// Because on some platforms the default icon size is bigger
// and it will result in taller/fatter statusbar, even if the
@ -106,37 +106,36 @@ StatusBar::StatusBar(QStatusBar *bar) @@ -106,37 +106,36 @@ StatusBar::StatusBar(QStatusBar *bar)
m_connecStatusLblIcon->setMaximumWidth(16 + 6);
m_altSpeedsBtn->setMaximumWidth(28 + 6);
m_statusSep1 = new QFrame(bar);
m_statusSep1->setFrameStyle(QFrame::VLine);
m_statusSep1->setFrameShadow(QFrame::Raised);
m_statusSep2 = new QFrame(bar);
m_statusSep2->setFrameStyle(QFrame::VLine);
m_statusSep2->setFrameShadow(QFrame::Raised);
m_statusSep3 = new QFrame(bar);
m_statusSep3->setFrameStyle(QFrame::VLine);
m_statusSep3->setFrameShadow(QFrame::Raised);
m_statusSep4 = new QFrame(bar);
m_statusSep4->setFrameStyle(QFrame::VLine);
m_statusSep4->setFrameShadow(QFrame::Raised);
m_layout->addWidget(m_DHTLbl);
m_layout->addWidget(m_statusSep1);
m_layout->addWidget(m_connecStatusLblIcon);
m_layout->addWidget(m_statusSep2);
m_layout->addWidget(m_altSpeedsBtn);
m_layout->addWidget(m_statusSep4);
m_layout->addWidget(m_dlSpeedLbl);
m_layout->addWidget(m_statusSep3);
m_layout->addWidget(m_upSpeedLbl);
QFrame *statusSep1 = new QFrame(this);
statusSep1->setFrameStyle(QFrame::VLine);
statusSep1->setFrameShadow(QFrame::Raised);
QFrame *statusSep2 = new QFrame(this);
statusSep2->setFrameStyle(QFrame::VLine);
statusSep2->setFrameShadow(QFrame::Raised);
QFrame *statusSep3 = new QFrame(this);
statusSep3->setFrameStyle(QFrame::VLine);
statusSep3->setFrameShadow(QFrame::Raised);
QFrame *statusSep4 = new QFrame(this);
statusSep4->setFrameStyle(QFrame::VLine);
statusSep4->setFrameShadow(QFrame::Raised);
layout->addWidget(m_DHTLbl);
layout->addWidget(statusSep1);
layout->addWidget(m_connecStatusLblIcon);
layout->addWidget(statusSep2);
layout->addWidget(m_altSpeedsBtn);
layout->addWidget(statusSep4);
layout->addWidget(m_dlSpeedLbl);
layout->addWidget(statusSep3);
layout->addWidget(m_upSpeedLbl);
bar->addPermanentWidget(m_container);
bar->setStyleSheet("QWidget {margin: 0;}");
m_container->adjustSize();
bar->adjustSize();
addPermanentWidget(container);
setStyleSheet("QWidget {margin: 0;}");
container->adjustSize();
adjustSize();
// Is DHT enabled
m_DHTLbl->setVisible(session->isDHTEnabled());
refreshStatusBar();
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatusBar::refreshStatusBar);
refresh();
connect(session, &BitTorrent::Session::statsUpdated, this, &StatusBar::refresh);
}
StatusBar::~StatusBar()
@ -144,25 +143,18 @@ StatusBar::~StatusBar() @@ -144,25 +143,18 @@ StatusBar::~StatusBar()
qDebug() << Q_FUNC_INFO;
}
QPushButton* StatusBar::connectionStatusButton() const
{
return m_connecStatusLblIcon;
}
void StatusBar::showRestartRequired()
{
// Restart required notification
const QString restartText = tr("qBittorrent needs to be restarted");
QLabel *restartIconLbl = new QLabel(m_bar);
restartIconLbl->setPixmap(QPixmap(":/icons/qbt-theme/dialog-warning.png").scaled(QSize(24,24)));
const QString restartText = tr("qBittorrent needs to be restarted!");
QLabel *restartIconLbl = new QLabel(this);
restartIconLbl->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning));
restartIconLbl->setToolTip(restartText);
m_bar->insertWidget(0, restartIconLbl);
QLabel *restartLbl = new QLabel(m_bar);
restartLbl->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_bar->insertWidget(1, restartLbl);
QFontMetrics fm(restartLbl->font());
restartLbl->setText(fm.elidedText(restartText, Qt::ElideRight, restartLbl->width()));
Logger::instance()->addMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective."), Log::CRITICAL);
insertWidget(0, restartIconLbl);
QLabel *restartLbl = new QLabel(this);
restartLbl->setText(restartText);
insertWidget(1, restartLbl);
}
void StatusBar::updateConnectionStatus()
@ -216,7 +208,7 @@ void StatusBar::updateSpeedLabels() @@ -216,7 +208,7 @@ void StatusBar::updateSpeedLabels()
m_upSpeedLbl->setText(speedLbl);
}
void StatusBar::refreshStatusBar()
void StatusBar::refresh()
{
updateConnectionStatus();
updateDHTNodesNumber();
@ -235,15 +227,7 @@ void StatusBar::updateAltSpeedsBtn(bool alternative) @@ -235,15 +227,7 @@ void StatusBar::updateAltSpeedsBtn(bool alternative)
m_altSpeedsBtn->setToolTip(tr("Click to switch to alternative speed limits"));
m_altSpeedsBtn->setDown(false);
}
refreshStatusBar();
}
void StatusBar::toggleAlternativeSpeeds()
{
BitTorrent::Session *const session = BitTorrent::Session::instance();
if (session->isBandwidthSchedulerEnabled())
m_bar->showMessage(tr("Manual change of rate limits mode. The scheduler is disabled."), 5000);
session->setAltGlobalSpeedLimitEnabled(!session->isAltGlobalSpeedLimitEnabled());
refresh();
}
void StatusBar::capDownloadSpeed()
@ -252,11 +236,11 @@ void StatusBar::capDownloadSpeed() @@ -252,11 +236,11 @@ void StatusBar::capDownloadSpeed()
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
m_bar->parentWidget(), &ok, tr("Global Download Speed Limit"), session->downloadSpeedLimit());
parentWidget(), &ok, tr("Global Download Speed Limit"), session->downloadSpeedLimit());
if (ok) {
qDebug("Setting global download rate limit to %.1fKb/s", newLimit / 1024.);
session->setDownloadSpeedLimit(newLimit);
refreshStatusBar();
refresh();
}
}
@ -266,10 +250,10 @@ void StatusBar::capUploadSpeed() @@ -266,10 +250,10 @@ void StatusBar::capUploadSpeed()
bool ok = false;
const long newLimit = SpeedLimitDialog::askSpeedLimit(
m_bar->parentWidget(), &ok, tr("Global Upload Speed Limit"), session->uploadSpeedLimit());
parentWidget(), &ok, tr("Global Upload Speed Limit"), session->uploadSpeedLimit());
if (ok) {
qDebug("Setting global upload rate limit to %.1fKb/s", newLimit / 1024.);
session->setUploadSpeedLimit(newLimit);
refreshStatusBar();
refresh();
}
}

28
src/gui/statusbar.h

@ -29,34 +29,35 @@ @@ -29,34 +29,35 @@
#ifndef STATUSBAR_H
#define STATUSBAR_H
#include <QObject>
#include <QStatusBar>
class QStatusBar;
class QFrame;
class QLabel;
class QPushButton;
class QHBoxLayout;
namespace BitTorrent
{
struct SessionStatus;
}
class StatusBar: public QObject
class StatusBar: public QStatusBar
{
Q_OBJECT
Q_DISABLE_COPY(StatusBar)
public:
StatusBar(QStatusBar *bar);
~StatusBar();
StatusBar(QWidget *parent = nullptr);
~StatusBar() override;
QPushButton* connectionStatusButton() const;
signals:
void alternativeSpeedsButtonClicked();
void connectionButtonClicked();
public slots:
void showRestartRequired();
void refreshStatusBar();
private slots:
void refresh();
void updateAltSpeedsBtn(bool alternative);
void toggleAlternativeSpeeds();
void capDownloadSpeed();
void capUploadSpeed();
@ -65,18 +66,11 @@ private: @@ -65,18 +66,11 @@ private:
void updateDHTNodesNumber();
void updateSpeedLabels();
QStatusBar *m_bar;
QPushButton *m_dlSpeedLbl;
QPushButton *m_upSpeedLbl;
QLabel *m_DHTLbl;
QFrame *m_statusSep1;
QFrame *m_statusSep2;
QFrame *m_statusSep3;
QFrame *m_statusSep4;
QPushButton *m_connecStatusLblIcon;
QPushButton *m_altSpeedsBtn;
QWidget *m_container;
QHBoxLayout *m_layout;
};
#endif // STATUSBAR_H

Loading…
Cancel
Save