1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Follow project coding style. Issue #2192.

This commit is contained in:
Chocobo1 2015-12-02 00:25:25 +08:00
parent e35a7ef9d3
commit f410b29c99
2 changed files with 270 additions and 248 deletions

View File

@ -30,6 +30,12 @@
#include "statusbar.h"
#include <QStatusBar>
#include <QFrame>
#include <QLabel>
#include <QTimer>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFontMetrics>
#include <QDebug>
@ -50,7 +56,7 @@ StatusBar::StatusBar(QStatusBar *bar)
connect(BitTorrent::Session::instance(), SIGNAL(speedLimitModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
container = new QWidget(bar);
layout = new QHBoxLayout(container);
layout->setContentsMargins(0,0,0,0);
layout->setContentsMargins(0, 0, 0, 0);
container->setLayout(layout);
connecStatusLblIcon = new QPushButton(bar);
@ -58,7 +64,7 @@ StatusBar::StatusBar(QStatusBar *bar)
connecStatusLblIcon->setFocusPolicy(Qt::NoFocus);
connecStatusLblIcon->setCursor(Qt::PointingHandCursor);
connecStatusLblIcon->setIcon(QIcon(":/icons/skin/firewalled.png"));
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>"));
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>"));
dlSpeedLbl = new QPushButton(bar);
dlSpeedLbl->setIcon(QIcon(":/icons/skin/download.png"));
connect(dlSpeedLbl, SIGNAL(clicked()), this, SLOT(capDownloadSpeed()));
@ -130,21 +136,24 @@ StatusBar::StatusBar(QStatusBar *bar)
refreshTimer->start(1500);
}
StatusBar::~StatusBar() {
StatusBar::~StatusBar()
{
qDebug() << Q_FUNC_INFO;
}
QPushButton* StatusBar::connectionStatusButton() const {
QPushButton* StatusBar::connectionStatusButton() const
{
return connecStatusLblIcon;
}
void StatusBar::showRestartRequired() {
void StatusBar::showRestartRequired()
{
// Restart required notification
const QString restart_text = tr("qBittorrent needs to be restarted");
QLabel *restartIconLbl = new QLabel(m_bar);
restartIconLbl->setPixmap(QPixmap(":/icons/oxygen/dialog-warning.png").scaled(QSize(24,24)));
restartIconLbl->setPixmap(QPixmap(":/icons/oxygen/dialog-warning.png").scaled(QSize(24, 24)));
restartIconLbl->setToolTip(restart_text);
m_bar->insertWidget(0,restartIconLbl);
m_bar->insertWidget(0, restartIconLbl);
QLabel *restartLbl = new QLabel(m_bar);
restartLbl->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_bar->insertWidget(1, restartLbl);
@ -153,24 +162,28 @@ 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::stopTimer()
{
refreshTimer->stop();
}
void StatusBar::refreshStatusBar() {
void StatusBar::refreshStatusBar()
{
// Update connection status
const BitTorrent::SessionStatus sessionStatus = BitTorrent::Session::instance()->status();
if (!BitTorrent::Session::instance()->isListening()) {
connecStatusLblIcon->setIcon(QIcon(QString::fromUtf8(":/icons/skin/disconnected.png")));
connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection Status:")+QString::fromUtf8("</b><br>")+tr("Offline. This usually means that qBittorrent failed to listen on the selected port for incoming connections."));
} else {
connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>") + tr("Connection Status:") + QString::fromUtf8("</b><br>") + tr("Offline. This usually means that qBittorrent failed to listen on the selected port for incoming connections."));
}
else {
if (sessionStatus.hasIncomingConnections()) {
// Connection OK
connecStatusLblIcon->setIcon(QIcon(QString::fromUtf8(":/icons/skin/connected.png")));
connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection Status:")+QString::fromUtf8("</b><br>")+tr("Online"));
}else{
connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>") + tr("Connection Status:") + QString::fromUtf8("</b><br>") + tr("Online"));
}
else {
connecStatusLblIcon->setIcon(QIcon(QString::fromUtf8(":/icons/skin/firewalled.png")));
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>"));
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>"));
}
}
// Update Number of DHT nodes
@ -178,29 +191,32 @@ void StatusBar::refreshStatusBar() {
DHTLbl->setVisible(true);
//statusSep1->setVisible(true);
DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dhtNodes())));
} else {
}
else {
DHTLbl->setVisible(false);
//statusSep1->setVisible(false);
}
// Update speed labels
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate(), true)+" ("+Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload())+")";
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate(), true) + " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload()) + ")";
int speedLimit = BitTorrent::Session::instance()->downloadRateLimit();
if (speedLimit)
speedLbl = "["+Utils::Misc::friendlyUnit(speedLimit, true)+"] " + speedLbl;
speedLbl = "[" + Utils::Misc::friendlyUnit(speedLimit, true) + "] " + speedLbl;
dlSpeedLbl->setText(speedLbl);
speedLimit = BitTorrent::Session::instance()->uploadRateLimit();
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate(), true)+" ("+Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload())+")";
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate(), true) + " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload()) + ")";
if (speedLimit)
speedLbl = "["+Utils::Misc::friendlyUnit(speedLimit, true)+"] " + speedLbl;
speedLbl = "[" + Utils::Misc::friendlyUnit(speedLimit, true) + "] " + speedLbl;
upSpeedLbl->setText(speedLbl);
}
void StatusBar::updateAltSpeedsBtn(bool alternative) {
void StatusBar::updateAltSpeedsBtn(bool alternative)
{
if (alternative) {
altSpeedsBtn->setIcon(QIcon(":/icons/slow.png"));
altSpeedsBtn->setToolTip(tr("Click to switch to regular speed limits"));
altSpeedsBtn->setDown(true);
} else {
}
else {
altSpeedsBtn->setIcon(QIcon(":/icons/slow_off.png"));
altSpeedsBtn->setToolTip(tr("Click to switch to alternative speed limits"));
altSpeedsBtn->setDown(false);
@ -208,14 +224,16 @@ void StatusBar::updateAltSpeedsBtn(bool alternative) {
refreshStatusBar();
}
void StatusBar::toggleAlternativeSpeeds() {
void StatusBar::toggleAlternativeSpeeds()
{
Preferences* const pref = Preferences::instance();
if (pref->isSchedulerEnabled())
m_bar->showMessage(tr("Manual change of rate limits mode. The scheduler is disabled."), 5000);
BitTorrent::Session::instance()->changeSpeedLimitMode(!pref->isAltBandwidthEnabled());
}
void StatusBar::capDownloadSpeed() {
void StatusBar::capDownloadSpeed()
{
bool ok = false;
int cur_limit = BitTorrent::Session::instance()->downloadRateLimit();
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), cur_limit);
@ -229,19 +247,21 @@ void StatusBar::capDownloadSpeed() {
pref->setGlobalDownloadLimit(-1);
else
pref->setAltGlobalDownloadLimit(-1);
} else {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
}
else {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit / 1024.);
BitTorrent::Session::instance()->setDownloadRateLimit(new_limit);
if (!alt)
pref->setGlobalDownloadLimit(new_limit/1024.);
pref->setGlobalDownloadLimit(new_limit / 1024.);
else
pref->setAltGlobalDownloadLimit(new_limit/1024.);
pref->setAltGlobalDownloadLimit(new_limit / 1024.);
}
refreshStatusBar();
}
}
void StatusBar::capUploadSpeed() {
void StatusBar::capUploadSpeed()
{
bool ok = false;
int cur_limit = BitTorrent::Session::instance()->uploadRateLimit();
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), cur_limit);
@ -255,13 +275,14 @@ void StatusBar::capUploadSpeed() {
Preferences::instance()->setGlobalUploadLimit(-1);
else
Preferences::instance()->setAltGlobalUploadLimit(-1);
} else {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
}
else {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit / 1024.);
BitTorrent::Session::instance()->setUploadRateLimit(new_limit);
if (!alt)
Preferences::instance()->setGlobalUploadLimit(new_limit/1024.);
Preferences::instance()->setGlobalUploadLimit(new_limit / 1024.);
else
Preferences::instance()->setAltGlobalUploadLimit(new_limit/1024.);
Preferences::instance()->setAltGlobalUploadLimit(new_limit / 1024.);
}
refreshStatusBar();
}

View File

@ -31,15 +31,17 @@
#ifndef STATUSBAR_H
#define STATUSBAR_H
#include <QStatusBar>
#include <QFrame>
#include <QLabel>
#include <QTimer>
#include <QGridLayout>
#include <QPushButton>
#include <QHBoxLayout>
#include <QObject>
class StatusBar: public QObject {
class QStatusBar;
class QFrame;
class QLabel;
class QTimer;
class QPushButton;
class QHBoxLayout;
class StatusBar: public QObject
{
Q_OBJECT
public:
@ -71,7 +73,6 @@ private:
QTimer *refreshTimer;
QWidget *container;
QHBoxLayout *layout;
};
#endif // STATUSBAR_H