@ -1,6 +1,6 @@
/*
/*
* Bittorrent Client using Qt4 and libtorrent .
* Bittorrent Client using Qt and libtorrent .
* Copyright ( C ) 2006 Christophe Dumez
* Copyright ( C ) 2006 Christophe Dumez < chris @ qbittorrent . org >
*
*
* This program is free software ; you can redistribute it and / or
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* 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 ) ,
* 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
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
* exception statement from your version .
*
* Contact : chris @ qbittorrent . org
*/
*/
# include "statusbar.h"
# include "statusbar.h"
# include <QApplication>
# include <QApplication>
# include <QStatusBar >
# include <QDebug >
# include <QFrame>
# include <QFrame>
# include <QHBoxLayout>
# include <QLabel>
# include <QLabel>
# include <QPushButton>
# include <QPushButton>
# include <QHBoxLayout>
# include <QStyle>
# include <QFontMetrics>
# include <QDebug>
# include "base/bittorrent/session.h"
# include "base/bittorrent/session.h"
# include "base/bittorrent/sessionstatus.h"
# include "base/bittorrent/sessionstatus.h"
# include "speedlimitdlg.h"
# include "guiiconprovider.h"
# include "base/utils/misc.h"
# include "base/utils/misc.h"
# include "base/logger.h"
# include "guiiconprovider.h"
# include "speedlimitdlg.h"
StatusBar : : StatusBar ( QStatusBar * bar )
StatusBar : : StatusBar ( QWidget * parent )
: m_bar ( bar )
: QStatusBar ( parent )
{
{
qApp - > setStyleSheet ( " QStatusBar::item { border-width: 0; } " ) ;
qApp - > setStyleSheet ( " QStatusBar::item { border-width: 0; } " ) ;
BitTorrent : : Session * const session = BitTorrent : : Session : : instance ( ) ;
BitTorrent : : Session * const session = BitTorrent : : Session : : instance ( ) ;
connect ( session , SIGNAL ( speedLimitModeChanged ( bool ) ) , this , SLOT ( updateAltSpeedsBtn ( bool ) ) ) ;
connect ( session , & BitTorrent : : Session : : speedLimitModeChanged , this , & StatusBar : : updateAltSpeedsBtn ) ;
m_ container = new QWidget ( bar ) ;
QWidget * container = new QWidget ( this ) ;
m_ layout = new QHBoxLayout ( m_ container) ;
QHBoxLayout * layout = new QHBoxLayout ( container ) ;
m_ layout- > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
m_ container- > setLayout ( m_ layout) ;
container - > setLayout ( layout ) ;
m_connecStatusLblIcon = new QPushButton ( bar ) ;
m_connecStatusLblIcon = new QPushButton ( this ) ;
m_connecStatusLblIcon - > setFlat ( true ) ;
m_connecStatusLblIcon - > setFlat ( true ) ;
m_connecStatusLblIcon - > setFocusPolicy ( Qt : : NoFocus ) ;
m_connecStatusLblIcon - > setFocusPolicy ( Qt : : NoFocus ) ;
m_connecStatusLblIcon - > setCursor ( Qt : : PointingHandCursor ) ;
m_connecStatusLblIcon - > setCursor ( Qt : : PointingHandCursor ) ;
m_connecStatusLblIcon - > setIcon ( QIcon ( " :/icons/skin/firewalled.png " ) ) ;
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 " ) ) ;
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 - > setFlat ( true ) ;
m_dlSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
m_dlSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
m_dlSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
m_dlSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
m_dlSpeedLbl - > setStyleSheet ( " text-align:left; " ) ;
m_dlSpeedLbl - > setStyleSheet ( " text-align:left; " ) ;
m_dlSpeedLbl - > setMinimumWidth ( 200 ) ;
m_dlSpeedLbl - > setMinimumWidth ( 200 ) ;
m_upSpeedLbl = new QPushButton ( bar ) ;
m_upSpeedLbl = new QPushButton ( this ) ;
m_upSpeedLbl - > setIcon ( QIcon ( " :/icons/skin/seeding.png " ) ) ;
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 - > setFlat ( true ) ;
m_upSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
m_upSpeedLbl - > setFocusPolicy ( Qt : : NoFocus ) ;
m_upSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
m_upSpeedLbl - > setCursor ( Qt : : PointingHandCursor ) ;
m_upSpeedLbl - > setStyleSheet ( " text-align:left; " ) ;
m_upSpeedLbl - > setStyleSheet ( " text-align:left; " ) ;
m_upSpeedLbl - > setMinimumWidth ( 200 ) ;
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_DHTLbl - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Preferred ) ;
m_altSpeedsBtn = new QPushButton ( bar ) ;
m_altSpeedsBtn = new QPushButton ( this ) ;
m_altSpeedsBtn - > setFlat ( true ) ;
m_altSpeedsBtn - > setFlat ( true ) ;
m_altSpeedsBtn - > setFocusPolicy ( Qt : : NoFocus ) ;
m_altSpeedsBtn - > setFocusPolicy ( Qt : : NoFocus ) ;
m_altSpeedsBtn - > setCursor ( Qt : : PointingHandCursor ) ;
m_altSpeedsBtn - > setCursor ( Qt : : PointingHandCursor ) ;
updateAltSpeedsBtn ( session - > isAltGlobalSpeedLimitEnabled ( ) ) ;
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
// 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
@ -106,37 +106,36 @@ StatusBar::StatusBar(QStatusBar *bar)
m_connecStatusLblIcon - > setMaximumWidth ( 16 + 6 ) ;
m_connecStatusLblIcon - > setMaximumWidth ( 16 + 6 ) ;
m_altSpeedsBtn - > setMaximumWidth ( 28 + 6 ) ;
m_altSpeedsBtn - > setMaximumWidth ( 28 + 6 ) ;
m_ statusSep1 = new QFrame ( bar ) ;
QFrame * statusSep1 = new QFrame ( this ) ;
m_ statusSep1- > setFrameStyle ( QFrame : : VLine ) ;
statusSep1 - > setFrameStyle ( QFrame : : VLine ) ;
m_ statusSep1- > setFrameShadow ( QFrame : : Raised ) ;
statusSep1 - > setFrameShadow ( QFrame : : Raised ) ;
m_ statusSep2 = new QFrame ( bar ) ;
QFrame * statusSep2 = new QFrame ( this ) ;
m_ statusSep2- > setFrameStyle ( QFrame : : VLine ) ;
statusSep2 - > setFrameStyle ( QFrame : : VLine ) ;
m_ statusSep2- > setFrameShadow ( QFrame : : Raised ) ;
statusSep2 - > setFrameShadow ( QFrame : : Raised ) ;
m_ statusSep3 = new QFrame ( bar ) ;
QFrame * statusSep3 = new QFrame ( this ) ;
m_ statusSep3- > setFrameStyle ( QFrame : : VLine ) ;
statusSep3 - > setFrameStyle ( QFrame : : VLine ) ;
m_ statusSep3- > setFrameShadow ( QFrame : : Raised ) ;
statusSep3 - > setFrameShadow ( QFrame : : Raised ) ;
m_ statusSep4 = new QFrame ( bar ) ;
QFrame * statusSep4 = new QFrame ( this ) ;
m_ statusSep4- > setFrameStyle ( QFrame : : VLine ) ;
statusSep4 - > setFrameStyle ( QFrame : : VLine ) ;
m_ statusSep4- > setFrameShadow ( QFrame : : Raised ) ;
statusSep4 - > setFrameShadow ( QFrame : : Raised ) ;
m_ layout- > addWidget ( m_DHTLbl ) ;
layout - > addWidget ( m_DHTLbl ) ;
m_ layout- > addWidget ( m_ statusSep1) ;
layout - > addWidget ( statusSep1 ) ;
m_ layout- > addWidget ( m_connecStatusLblIcon ) ;
layout - > addWidget ( m_connecStatusLblIcon ) ;
m_ layout- > addWidget ( m_ statusSep2) ;
layout - > addWidget ( statusSep2 ) ;
m_ layout- > addWidget ( m_altSpeedsBtn ) ;
layout - > addWidget ( m_altSpeedsBtn ) ;
m_ layout- > addWidget ( m_ statusSep4) ;
layout - > addWidget ( statusSep4 ) ;
m_ layout- > addWidget ( m_dlSpeedLbl ) ;
layout - > addWidget ( m_dlSpeedLbl ) ;
m_ layout- > addWidget ( m_ statusSep3) ;
layout - > addWidget ( statusSep3 ) ;
m_ layout- > addWidget ( m_upSpeedLbl ) ;
layout - > addWidget ( m_upSpeedLbl ) ;
bar - > addPermanentWidget ( m_ container) ;
addPermanentWidget ( container ) ;
bar - > setStyleSheet ( " QWidget {margin: 0;} " ) ;
setStyleSheet ( " QWidget {margin: 0;} " ) ;
m_ container- > adjustSize ( ) ;
container - > adjustSize ( ) ;
bar - > adjustSize ( ) ;
adjustSize ( ) ;
// Is DHT enabled
// Is DHT enabled
m_DHTLbl - > setVisible ( session - > isDHTEnabled ( ) ) ;
m_DHTLbl - > setVisible ( session - > isDHTEnabled ( ) ) ;
refreshStatusBar ( ) ;
refresh ( ) ;
connect ( BitTorrent : : Session : : instance ( ) , & BitTorrent : : Session : : statsUpdated
connect ( session , & BitTorrent : : Session : : statsUpdated , this , & StatusBar : : refresh ) ;
, this , & StatusBar : : refreshStatusBar ) ;
}
}
StatusBar : : ~ StatusBar ( )
StatusBar : : ~ StatusBar ( )
@ -144,25 +143,18 @@ StatusBar::~StatusBar()
qDebug ( ) < < Q_FUNC_INFO ;
qDebug ( ) < < Q_FUNC_INFO ;
}
}
QPushButton * StatusBar : : connectionStatusButton ( ) const
{
return m_connecStatusLblIcon ;
}
void StatusBar : : showRestartRequired ( )
void StatusBar : : showRestartRequired ( )
{
{
// Restart required notification
// Restart required notification
const QString restartText = tr ( " qBittorrent needs to be restarted " ) ;
const QString restartText = tr ( " qBittorrent needs to be restarted! " ) ;
QLabel * restartIconLbl = new QLabel ( m_bar ) ;
QLabel * restartIconLbl = new QLabel ( this ) ;
restartIconLbl - > setPixmap ( QPixmap ( " :/icons/qbt-theme/dialog-warning.png " ) . scaled ( QSize ( 24 , 24 ) ) ) ;
restartIconLbl - > setPixmap ( style ( ) - > standardPixmap ( QStyle : : SP_MessageBoxWarning ) ) ;
restartIconLbl - > setToolTip ( restartText ) ;
restartIconLbl - > setToolTip ( restartText ) ;
m_bar - > insertWidget ( 0 , restartIconLbl ) ;
insertWidget ( 0 , restartIconLbl ) ;
QLabel * restartLbl = new QLabel ( m_bar ) ;
restartLbl - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Preferred ) ;
QLabel * restartLbl = new QLabel ( this ) ;
m_bar - > insertWidget ( 1 , restartLbl ) ;
restartLbl - > setText ( restartText ) ;
QFontMetrics fm ( restartLbl - > font ( ) ) ;
insertWidget ( 1 , restartLbl ) ;
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 ) ;
}
}
void StatusBar : : updateConnectionStatus ( )
void StatusBar : : updateConnectionStatus ( )
@ -216,7 +208,7 @@ void StatusBar::updateSpeedLabels()
m_upSpeedLbl - > setText ( speedLbl ) ;
m_upSpeedLbl - > setText ( speedLbl ) ;
}
}
void StatusBar : : refreshStatusBar ( )
void StatusBar : : refresh ( )
{
{
updateConnectionStatus ( ) ;
updateConnectionStatus ( ) ;
updateDHTNodesNumber ( ) ;
updateDHTNodesNumber ( ) ;
@ -235,15 +227,7 @@ void StatusBar::updateAltSpeedsBtn(bool alternative)
m_altSpeedsBtn - > setToolTip ( tr ( " Click to switch to alternative speed limits " ) ) ;
m_altSpeedsBtn - > setToolTip ( tr ( " Click to switch to alternative speed limits " ) ) ;
m_altSpeedsBtn - > setDown ( false ) ;
m_altSpeedsBtn - > setDown ( false ) ;
}
}
refreshStatusBar ( ) ;
refresh ( ) ;
}
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 ( ) ) ;
}
}
void StatusBar : : capDownloadSpeed ( )
void StatusBar : : capDownloadSpeed ( )
@ -252,11 +236,11 @@ void StatusBar::capDownloadSpeed()
bool ok = false ;
bool ok = false ;
const long newLimit = SpeedLimitDialog : : askSpeedLimit (
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 ) {
if ( ok ) {
qDebug ( " Setting global download rate limit to %.1fKb/s " , newLimit / 1024. ) ;
qDebug ( " Setting global download rate limit to %.1fKb/s " , newLimit / 1024. ) ;
session - > setDownloadSpeedLimit ( newLimit ) ;
session - > setDownloadSpeedLimit ( newLimit ) ;
refreshStatusBar ( ) ;
refresh ( ) ;
}
}
}
}
@ -266,10 +250,10 @@ void StatusBar::capUploadSpeed()
bool ok = false ;
bool ok = false ;
const long newLimit = SpeedLimitDialog : : askSpeedLimit (
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 ) {
if ( ok ) {
qDebug ( " Setting global upload rate limit to %.1fKb/s " , newLimit / 1024. ) ;
qDebug ( " Setting global upload rate limit to %.1fKb/s " , newLimit / 1024. ) ;
session - > setUploadSpeedLimit ( newLimit ) ;
session - > setUploadSpeedLimit ( newLimit ) ;
refreshStatusBar ( ) ;
refresh ( ) ;
}
}
}
}