mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-29 19:18:42 -07:00
Refactor and improve StatusBar
This commit is contained in:
parent
0940a8a764
commit
c456b9a42c
4 changed files with 112 additions and 112 deletions
|
@ -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 @@
|
|||
* 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)
|
|||
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()
|
|||
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()
|
|||
m_upSpeedLbl->setText(speedLbl);
|
||||
}
|
||||
|
||||
void StatusBar::refreshStatusBar()
|
||||
void StatusBar::refresh()
|
||||
{
|
||||
updateConnectionStatus();
|
||||
updateDHTNodesNumber();
|
||||
|
@ -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()
|
|||
|
||||
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()
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue