@ -30,6 +30,12 @@
# include "statusbar.h"
# include "statusbar.h"
# include <QStatusBar>
# include <QFrame>
# include <QLabel>
# include <QTimer>
# include <QPushButton>
# include <QHBoxLayout>
# include <QFontMetrics>
# include <QFontMetrics>
# include <QDebug>
# include <QDebug>
@ -42,225 +48,242 @@
# include "base/logger.h"
# include "base/logger.h"
StatusBar : : StatusBar ( QStatusBar * bar )
StatusBar : : StatusBar ( QStatusBar * bar )
: m_bar ( bar )
: m_bar ( bar )
{
{
Preferences * const pref = Preferences : : instance ( ) ;
qApp - > setStyleSheet ( " QStatusBar::item { border-width: 0; } " ) ;
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 ) ;
container - > setLayout ( layout ) ;
Preferences * const pref = Preferences : : instance ( ) ;
connecStatusLblIcon = new QPushButton ( bar ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( speedLimitModeChanged ( bool ) ) , this , SLOT ( updateAltSpeedsBtn ( bool ) ) ) ;
connecStatusLblIcon - > setFlat ( true ) ;
container = new QWidget ( bar ) ;
connecStatusLblIcon - > setFocusPolicy ( Qt : : NoFocus ) ;
layout = new QHBoxLayout ( container ) ;
connecStatusLblIcon - > setCursor ( Qt : : PointingHandCursor ) ;
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
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> " ) ) ;
container - > setLayout ( layout ) ;
dlSpeedLbl = new QPushButton ( bar ) ;
connecStatusLblIcon = new QPushButton ( bar ) ;
dlSpeedLbl - > setIcon ( QIcon ( " :/icons/skin/download.png " ) ) ;
connecStatusLblIcon - > setFlat ( true ) ;
connect ( dlSpeedLbl , SIGNAL ( clicked ( ) ) , this , SLOT ( capDownloadSpeed ( ) ) ) ;
connecStatusLblIcon - > setFocusPolicy ( Qt : : NoFocus ) ;
dlSpeedLbl - > setFlat ( true ) ;
connecStatusLblIcon - > setCursor ( Qt : : PointingHandCursor ) ;
dlSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
connecStatusLblIcon - > setIcon ( QIcon ( " :/icons/skin/firewalled.png " ) ) ;
dlSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
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 ( ) ) ) ;
dlSpeedLbl - > setFlat ( true ) ;
dlSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
dlSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
upSpeedLbl = new QPushButton ( bar ) ;
upSpeedLbl = new QPushButton ( bar ) ;
upSpeedLbl - > setIcon ( QIcon ( " :/icons/skin/seeding.png " ) ) ;
upSpeedLbl - > setIcon ( QIcon ( " :/icons/skin/seeding.png " ) ) ;
connect ( upSpeedLbl , SIGNAL ( clicked ( ) ) , this , SLOT ( capUploadSpeed ( ) ) ) ;
connect ( upSpeedLbl , SIGNAL ( clicked ( ) ) , this , SLOT ( capUploadSpeed ( ) ) ) ;
upSpeedLbl - > setFlat ( true ) ;
upSpeedLbl - > setFlat ( true ) ;
upSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
upSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
upSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
upSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
DHTLbl = new QLabel ( tr ( " DHT: %1 nodes " ) . arg ( 0 ) , bar ) ;
DHTLbl = new QLabel ( tr ( " DHT: %1 nodes " ) . arg ( 0 ) , bar ) ;
DHTLbl - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Preferred ) ;
DHTLbl - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Preferred ) ;
altSpeedsBtn = new QPushButton ( bar ) ;
altSpeedsBtn = new QPushButton ( bar ) ;
altSpeedsBtn - > setFlat ( true ) ;
altSpeedsBtn - > setFlat ( true ) ;
altSpeedsBtn - > setFocusPolicy ( Qt : : NoFocus ) ;
altSpeedsBtn - > setFocusPolicy ( Qt : : NoFocus ) ;
altSpeedsBtn - > setCursor ( Qt : : PointingHandCursor ) ;
altSpeedsBtn - > setCursor ( Qt : : PointingHandCursor ) ;
updateAltSpeedsBtn ( pref - > isAltBandwidthEnabled ( ) ) ;
updateAltSpeedsBtn ( pref - > isAltBandwidthEnabled ( ) ) ;
connect ( altSpeedsBtn , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAlternativeSpeeds ( ) ) ) ;
connect ( altSpeedsBtn , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAlternativeSpeeds ( ) ) ) ;
// Because on some platforms the default icon size is bigger
// Because on some platforms the default icon size is bigger
// and it will result in taller/fatter statusbar, even if the
// and it will result in taller/fatter statusbar, even if the
// icons are actually 16x16
// icons are actually 16x16
connecStatusLblIcon - > setIconSize ( QSize ( 16 , 16 ) ) ;
connecStatusLblIcon - > setIconSize ( QSize ( 16 , 16 ) ) ;
dlSpeedLbl - > setIconSize ( QSize ( 16 , 16 ) ) ;
dlSpeedLbl - > setIconSize ( QSize ( 16 , 16 ) ) ;
upSpeedLbl - > setIconSize ( QSize ( 16 , 16 ) ) ;
upSpeedLbl - > setIconSize ( QSize ( 16 , 16 ) ) ;
altSpeedsBtn - > setIconSize ( QSize ( 28 , 16 ) ) ;
altSpeedsBtn - > setIconSize ( QSize ( 28 , 16 ) ) ;
// Set to the known maximum width(plus some padding)
// Set to the known maximum width(plus some padding)
// so the speed widgets will take the rest of the space
// so the speed widgets will take the rest of the space
connecStatusLblIcon - > setMaximumWidth ( 16 + 6 ) ;
connecStatusLblIcon - > setMaximumWidth ( 16 + 6 ) ;
altSpeedsBtn - > setMaximumWidth ( 28 + 6 ) ;
altSpeedsBtn - > setMaximumWidth ( 28 + 6 ) ;
statusSep1 = new QFrame ( bar ) ;
statusSep1 = new QFrame ( bar ) ;
statusSep1 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep1 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep1 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep1 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep2 = new QFrame ( bar ) ;
statusSep2 = new QFrame ( bar ) ;
statusSep2 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep2 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep2 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep2 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep3 = new QFrame ( bar ) ;
statusSep3 = new QFrame ( bar ) ;
statusSep3 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep3 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep3 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep3 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep4 = new QFrame ( bar ) ;
statusSep4 = new QFrame ( bar ) ;
statusSep4 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep4 - > setFrameStyle ( QFrame : : VLine ) ;
statusSep4 - > setFrameShadow ( QFrame : : Raised ) ;
statusSep4 - > setFrameShadow ( QFrame : : Raised ) ;
layout - > addWidget ( DHTLbl ) ;
layout - > addWidget ( DHTLbl ) ;
layout - > addWidget ( statusSep1 ) ;
layout - > addWidget ( statusSep1 ) ;
layout - > addWidget ( connecStatusLblIcon ) ;
layout - > addWidget ( connecStatusLblIcon ) ;
layout - > addWidget ( statusSep2 ) ;
layout - > addWidget ( statusSep2 ) ;
layout - > addWidget ( altSpeedsBtn ) ;
layout - > addWidget ( altSpeedsBtn ) ;
layout - > addWidget ( statusSep4 ) ;
layout - > addWidget ( statusSep4 ) ;
layout - > addWidget ( dlSpeedLbl ) ;
layout - > addWidget ( dlSpeedLbl ) ;
layout - > addWidget ( statusSep3 ) ;
layout - > addWidget ( statusSep3 ) ;
layout - > addWidget ( upSpeedLbl ) ;
layout - > addWidget ( upSpeedLbl ) ;
bar - > addPermanentWidget ( container ) ;
bar - > addPermanentWidget ( container ) ;
container - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ;
container - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ;
bar - > setStyleSheet ( " QWidget {margin: 0;} " ) ;
bar - > setStyleSheet ( " QWidget {margin: 0;} " ) ;
container - > adjustSize ( ) ;
container - > adjustSize ( ) ;
bar - > adjustSize ( ) ;
bar - > adjustSize ( ) ;
// Is DHT enabled
// Is DHT enabled
DHTLbl - > setVisible ( pref - > isDHTEnabled ( ) ) ;
DHTLbl - > setVisible ( pref - > isDHTEnabled ( ) ) ;
refreshTimer = new QTimer ( bar ) ;
refreshTimer = new QTimer ( bar ) ;
refreshStatusBar ( ) ;
refreshStatusBar ( ) ;
connect ( refreshTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( refreshStatusBar ( ) ) ) ;
connect ( refreshTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( refreshStatusBar ( ) ) ) ;
refreshTimer - > start ( 1500 ) ;
refreshTimer - > start ( 1500 ) ;
}
}
StatusBar : : ~ StatusBar ( ) {
StatusBar : : ~ StatusBar ( )
qDebug ( ) < < Q_FUNC_INFO ;
{
qDebug ( ) < < Q_FUNC_INFO ;
}
}
QPushButton * StatusBar : : connectionStatusButton ( ) const {
QPushButton * StatusBar : : connectionStatusButton ( ) const
return connecStatusLblIcon ;
{
return connecStatusLblIcon ;
}
}
void StatusBar : : showRestartRequired ( ) {
void StatusBar : : showRestartRequired ( )
// Restart required notification
{
const QString restart_text = tr ( " qBittorrent needs to be restarted " ) ;
// Restart required notification
QLabel * restartIconLbl = new QLabel ( m_bar ) ;
const QString restart_text = tr ( " qBittorrent needs to be restarted " ) ;
restartIconLbl - > setPixmap ( QPixmap ( " :/icons/oxygen/dialog-warning.png " ) . scaled ( QSize ( 24 , 24 ) ) ) ;
QLabel * restartIconLbl = new QLabel ( m_bar ) ;
restartIconLbl - > setToolTip ( restart_text ) ;
restartIconLbl - > setPixmap ( QPixmap ( " :/icons/oxygen/dialog-warning.png " ) . scaled ( QSize ( 24 , 24 ) ) ) ;
m_bar - > insertWidget ( 0 , restartIconLbl ) ;
restartIconLbl - > setToolTip ( restart_text ) ;
QLabel * restartLbl = new QLabel ( m_bar ) ;
m_bar - > insertWidget ( 0 , restartIconLbl ) ;
restartLbl - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Preferred ) ;
QLabel * restartLbl = new QLabel ( m_bar ) ;
m_bar - > insertWidget ( 1 , restartLbl ) ;
restartLbl - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Preferred ) ;
QFontMetrics fm ( restartLbl - > font ( ) ) ;
m_bar - > insertWidget ( 1 , restartLbl ) ;
restartLbl - > setText ( fm . elidedText ( restart_text , Qt : : ElideRight , restartLbl - > width ( ) ) ) ;
QFontMetrics fm ( restartLbl - > font ( ) ) ;
Logger : : instance ( ) - > addMessage ( tr ( " qBittorrent was just updated and needs to be restarted for the changes to be effective. " ) , Log : : CRITICAL ) ;
restartLbl - > setText ( fm . elidedText ( restart_text , 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 ) ;
}
}
void StatusBar : : stopTimer ( ) {
void StatusBar : : stopTimer ( )
refreshTimer - > stop ( ) ;
{
refreshTimer - > stop ( ) ;
}
}
void StatusBar : : refreshStatusBar ( ) {
void StatusBar : : refreshStatusBar ( )
// Update connection status
{
const BitTorrent : : SessionStatus sessionStatus = BitTorrent : : Session : : instance ( ) - > status ( ) ;
// Update connection status
if ( ! BitTorrent : : Session : : instance ( ) - > isListening ( ) ) {
const BitTorrent : : SessionStatus sessionStatus = BitTorrent : : Session : : instance ( ) - > status ( ) ;
connecStatusLblIcon - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/disconnected.png " ) ) ) ;
if ( ! BitTorrent : : Session : : instance ( ) - > isListening ( ) ) {
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. " ) ) ;
connecStatusLblIcon - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/disconnected.png " ) ) ) ;
} 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. " ) ) ;
if ( sessionStatus . hasIncomingConnections ( ) ) {
}
// Connection OK
else {
connecStatusLblIcon - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/connected.png " ) ) ) ;
if ( sessionStatus . hasIncomingConnections ( ) ) {
connecStatusLblIcon - > setToolTip ( QString : : fromUtf8 ( " <b> " ) + tr ( " Connection Status: " ) + QString : : fromUtf8 ( " </b><br> " ) + tr ( " Online " ) ) ;
// Connection OK
} else {
connecStatusLblIcon - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/connected.png " ) ) ) ;
connecStatusLblIcon - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/firewalled.png " ) ) ) ;
connecStatusLblIcon - > setToolTip ( QString : : fromUtf8 ( " <b> " ) + tr ( " Connection Status: " ) + QString : : fromUtf8 ( " </b><br> " ) + tr ( " Online " ) ) ;
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> " ) ) ;
}
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> " ) ) ;
}
}
}
}
// Update Number of DHT nodes
// Update Number of DHT nodes
if ( BitTorrent : : Session : : instance ( ) - > isDHTEnabled ( ) ) {
if ( BitTorrent : : Session : : instance ( ) - > isDHTEnabled ( ) ) {
DHTLbl - > setVisible ( true ) ;
DHTLbl - > setVisible ( true ) ;
//statusSep1->setVisible(true);
//statusSep1->setVisible(true);
DHTLbl - > setText ( tr ( " DHT: %1 nodes " ) . arg ( QString : : number ( sessionStatus . dhtNodes ( ) ) ) ) ;
DHTLbl - > setText ( tr ( " DHT: %1 nodes " ) . arg ( QString : : number ( sessionStatus . dhtNodes ( ) ) ) ) ;
}
} else {
else {
DHTLbl - > setVisible ( false ) ;
DHTLbl - > setVisible ( false ) ;
//statusSep1->setVisible(false);
//statusSep1->setVisible(false);
}
}
// Update speed labels
// 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 ( ) ;
int speedLimit = BitTorrent : : Session : : instance ( ) - > downloadRateLimit ( ) ;
if ( speedLimit )
if ( speedLimit )
speedLbl = " [ " + Utils : : Misc : : friendlyUnit ( speedLimit , true ) + " ] " + speedLbl ;
speedLbl = " [ " + Utils : : Misc : : friendlyUnit ( speedLimit , true ) + " ] " + speedLbl ;
dlSpeedLbl - > setText ( speedLbl ) ;
dlSpeedLbl - > setText ( speedLbl ) ;
speedLimit = BitTorrent : : Session : : instance ( ) - > uploadRateLimit ( ) ;
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 )
if ( speedLimit )
speedLbl = " [ " + Utils : : Misc : : friendlyUnit ( speedLimit , true ) + " ] " + speedLbl ;
speedLbl = " [ " + Utils : : Misc : : friendlyUnit ( speedLimit , true ) + " ] " + speedLbl ;
upSpeedLbl - > setText ( speedLbl ) ;
upSpeedLbl - > setText ( speedLbl ) ;
}
}
void StatusBar : : updateAltSpeedsBtn ( bool alternative ) {
void StatusBar : : updateAltSpeedsBtn ( bool alternative )
if ( alternative ) {
{
altSpeedsBtn - > setIcon ( QIcon ( " :/icons/slow.png " ) ) ;
if ( alternative ) {
altSpeedsBtn - > setToolTip ( tr ( " Click to switch to regular speed limits " ) ) ;
altSpeedsBtn - > setIcon ( QIcon ( " :/icons/slow.png " ) ) ;
altSpeedsBtn - > setDown ( true ) ;
altSpeedsBtn - > setToolTip ( tr ( " Click to switch to regular speed limits " ) ) ;
} else {
altSpeedsBtn - > setDown ( true ) ;
altSpeedsBtn - > setIcon ( QIcon ( " :/icons/slow_off.png " ) ) ;
}
altSpeedsBtn - > setToolTip ( tr ( " Click to switch to alternative speed limits " ) ) ;
else {
altSpeedsBtn - > setDown ( false ) ;
altSpeedsBtn - > setIcon ( QIcon ( " :/icons/slow_off.png " ) ) ;
}
altSpeedsBtn - > setToolTip ( tr ( " Click to switch to alternative speed limits " ) ) ;
refreshStatusBar ( ) ;
altSpeedsBtn - > setDown ( false ) ;
}
refreshStatusBar ( ) ;
}
}
void StatusBar : : toggleAlternativeSpeeds ( ) {
void StatusBar : : toggleAlternativeSpeeds ( )
Preferences * const pref = Preferences : : instance ( ) ;
{
if ( pref - > isSchedulerEnabled ( ) )
Preferences * const pref = Preferences : : instance ( ) ;
m_bar - > showMessage ( tr ( " Manual change of rate limits mode. The scheduler is disabled. " ) , 5000 ) ;
if ( pref - > isSchedulerEnabled ( ) )
BitTorrent : : Session : : instance ( ) - > changeSpeedLimitMode ( ! pref - > isAltBandwidthEnabled ( ) ) ;
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 ( ) ;
bool ok = false ;
long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Download Speed Limit " ) , cur_limit ) ;
int cur_limit = BitTorrent : : Session : : instance ( ) - > downloadRateLimit ( ) ;
if ( ok ) {
long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Download Speed Limit " ) , cur_limit ) ;
Preferences * const pref = Preferences : : instance ( ) ;
if ( ok ) {
bool alt = pref - > isAltBandwidthEnabled ( ) ;
Preferences * const pref = Preferences : : instance ( ) ;
if ( new_limit < = 0 ) {
bool alt = pref - > isAltBandwidthEnabled ( ) ;
qDebug ( " Setting global download rate limit to Unlimited " ) ;
if ( new_limit < = 0 ) {
BitTorrent : : Session : : instance ( ) - > setDownloadRateLimit ( - 1 ) ;
qDebug ( " Setting global download rate limit to Unlimited " ) ;
if ( ! alt )
BitTorrent : : Session : : instance ( ) - > setDownloadRateLimit ( - 1 ) ;
pref - > setGlobalDownloadLimit ( - 1 ) ;
if ( ! alt )
else
pref - > setGlobalDownloadLimit ( - 1 ) ;
pref - > setAltGlobalDownloadLimit ( - 1 ) ;
else
} else {
pref - > setAltGlobalDownloadLimit ( - 1 ) ;
qDebug ( " Setting global download rate limit to %.1fKb/s " , new_limit / 1024. ) ;
}
BitTorrent : : Session : : instance ( ) - > setDownloadRateLimit ( new_limit ) ;
else {
if ( ! alt )
qDebug ( " Setting global download rate limit to %.1fKb/s " , new_limit / 1024. ) ;
pref - > setGlobalDownloadLimit ( new_limit / 1024. ) ;
BitTorrent : : Session : : instance ( ) - > setDownloadRateLimit ( new_limit ) ;
else
if ( ! alt )
pref - > setAltGlobalDownloadLimit ( new_limit / 1024. ) ;
pref - > setGlobalDownloadLimit ( new_limit / 1024. ) ;
else
pref - > setAltGlobalDownloadLimit ( new_limit / 1024. ) ;
}
refreshStatusBar ( ) ;
}
}
refreshStatusBar ( ) ;
}
}
}
void StatusBar : : capUploadSpeed ( ) {
void StatusBar : : capUploadSpeed ( )
bool ok = false ;
{
int cur_limit = BitTorrent : : Session : : instance ( ) - > uploadRateLimit ( ) ;
bool ok = false ;
long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Upload Speed Limit " ) , cur_limit ) ;
int cur_limit = BitTorrent : : Session : : instance ( ) - > uploadRateLimit ( ) ;
if ( ok ) {
long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Upload Speed Limit " ) , cur_limit ) ;
Preferences * const pref = Preferences : : instance ( ) ;
if ( ok ) {
bool alt = pref - > isAltBandwidthEnabled ( ) ;
Preferences * const pref = Preferences : : instance ( ) ;
if ( new_limit < = 0 ) {
bool alt = pref - > isAltBandwidthEnabled ( ) ;
qDebug ( " Setting global upload rate limit to Unlimited " ) ;
if ( new_limit < = 0 ) {
BitTorrent : : Session : : instance ( ) - > setUploadRateLimit ( - 1 ) ;
qDebug ( " Setting global upload rate limit to Unlimited " ) ;
if ( ! alt )
BitTorrent : : Session : : instance ( ) - > setUploadRateLimit ( - 1 ) ;
Preferences : : instance ( ) - > setGlobalUploadLimit ( - 1 ) ;
if ( ! alt )
else
Preferences : : instance ( ) - > setGlobalUploadLimit ( - 1 ) ;
Preferences : : instance ( ) - > setAltGlobalUploadLimit ( - 1 ) ;
else
} else {
Preferences : : instance ( ) - > setAltGlobalUploadLimit ( - 1 ) ;
qDebug ( " Setting global upload rate limit to %.1fKb/s " , new_limit / 1024. ) ;
}
BitTorrent : : Session : : instance ( ) - > setUploadRateLimit ( new_limit ) ;
else {
if ( ! alt )
qDebug ( " Setting global upload rate limit to %.1fKb/s " , new_limit / 1024. ) ;
Preferences : : instance ( ) - > setGlobalUploadLimit ( new_limit / 1024. ) ;
BitTorrent : : Session : : instance ( ) - > setUploadRateLimit ( new_limit ) ;
else
if ( ! alt )
Preferences : : instance ( ) - > setAltGlobalUploadLimit ( new_limit / 1024. ) ;
Preferences : : instance ( ) - > setGlobalUploadLimit ( new_limit / 1024. ) ;
else
Preferences : : instance ( ) - > setAltGlobalUploadLimit ( new_limit / 1024. ) ;
}
refreshStatusBar ( ) ;
}
}
refreshStatusBar ( ) ;
}
}
}