@ -156,10 +156,16 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
connect ( actionPreview_file , SIGNAL ( triggered ( ) ) , this , SLOT ( previewFileSelection ( ) ) ) ;
connect ( actionPreview_file , SIGNAL ( triggered ( ) ) , this , SLOT ( previewFileSelection ( ) ) ) ;
connect ( infoBar , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayInfoBarMenu ( const QPoint & ) ) ) ;
connect ( infoBar , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayInfoBarMenu ( const QPoint & ) ) ) ;
// Create tray icon
// Create tray icon
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
std : : cerr < < " Error: System tray unavailable \n " ;
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
systrayIntegration = settings . value ( " Options/Misc/Behaviour/SystrayIntegration " , true ) . toBool ( ) ;
if ( systrayIntegration ) {
createTrayIcon ( ) ;
}
} else {
systrayIntegration = false ;
qDebug ( " Info: System tray unavailable \n " ) ;
}
}
myTrayIcon = new QSystemTrayIcon ( QIcon ( " :/Icons/qbittorrent22.png " ) , this ) ;
// Search engine tab
// Search engine tab
searchEngine = new SearchEngine ( & BTSession , myTrayIcon ) ;
searchEngine = new SearchEngine ( & BTSession , myTrayIcon ) ;
tabs - > addTab ( searchEngine , tr ( " Search " ) ) ;
tabs - > addTab ( searchEngine , tr ( " Search " ) ) ;
@ -172,20 +178,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
refresher = new QTimer ( this ) ;
refresher = new QTimer ( this ) ;
connect ( refresher , SIGNAL ( timeout ( ) ) , this , SLOT ( updateDlList ( ) ) ) ;
connect ( refresher , SIGNAL ( timeout ( ) ) , this , SLOT ( updateDlList ( ) ) ) ;
refresher - > start ( 2000 ) ;
refresher - > start ( 2000 ) ;
// Tray icon Menu
myTrayIconMenu = new QMenu ( this ) ;
myTrayIconMenu - > addAction ( actionOpen ) ;
myTrayIconMenu - > addAction ( actionDownload_from_URL ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionStart_All ) ;
myTrayIconMenu - > addAction ( actionPause_All ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionExit ) ;
myTrayIcon - > setContextMenu ( myTrayIconMenu ) ;
connect ( myTrayIcon , SIGNAL ( messageClicked ( ) ) , this , SLOT ( balloonClicked ( ) ) ) ;
// End of Icon Menu
connect ( myTrayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( toggleVisibility ( QSystemTrayIcon : : ActivationReason ) ) ) ;
myTrayIcon - > show ( ) ;
// Use a tcp server to allow only one instance of qBittorrent
// Use a tcp server to allow only one instance of qBittorrent
tcpServer = new QTcpServer ( ) ;
tcpServer = new QTcpServer ( ) ;
if ( ! tcpServer - > listen ( QHostAddress : : LocalHost , 1666 ) ) {
if ( ! tcpServer - > listen ( QHostAddress : : LocalHost , 1666 ) ) {
@ -211,8 +203,10 @@ GUI::~GUI(){
delete searchEngine ;
delete searchEngine ;
delete checkConnect ;
delete checkConnect ;
delete refresher ;
delete refresher ;
delete myTrayIcon ;
if ( systrayIntegration ) {
delete myTrayIconMenu ;
delete myTrayIcon ;
delete myTrayIconMenu ;
}
delete DLDelegate ;
delete DLDelegate ;
delete DLListModel ;
delete DLListModel ;
delete tcpServer ;
delete tcpServer ;
@ -420,7 +414,9 @@ void GUI::updateDlList(bool force){
// update global informations
// update global informations
snprintf ( tmp , MAX_CHAR_TMP , " %.1f " , BTSession . getPayloadUploadRate ( ) / 1024. ) ;
snprintf ( tmp , MAX_CHAR_TMP , " %.1f " , BTSession . getPayloadUploadRate ( ) / 1024. ) ;
snprintf ( tmp2 , MAX_CHAR_TMP , " %.1f " , BTSession . getPayloadDownloadRate ( ) / 1024. ) ;
snprintf ( tmp2 , MAX_CHAR_TMP , " %.1f " , BTSession . getPayloadDownloadRate ( ) / 1024. ) ;
myTrayIcon - > setToolTip ( " <b> " + tr ( " qBittorrent " ) + " </b><br> " + tr ( " DL speed: %1 KiB/s " , " e.g: Download speed: 10 KiB/s " ) . arg ( QString ( tmp2 ) ) + " <br> " + tr ( " UP speed: %1 KiB/s " , " e.g: Upload speed: 10 KiB/s " ) . arg ( QString ( tmp ) ) ) ; // tray icon
if ( systrayIntegration ) {
myTrayIcon - > setToolTip ( " <b> " + tr ( " qBittorrent " ) + " </b><br> " + tr ( " DL speed: %1 KiB/s " , " e.g: Download speed: 10 KiB/s " ) . arg ( QString ( tmp2 ) ) + " <br> " + tr ( " UP speed: %1 KiB/s " , " e.g: Upload speed: 10 KiB/s " ) . arg ( QString ( tmp ) ) ) ; // tray icon
}
if ( ! force & & ( isMinimized ( ) | | isHidden ( ) | | tabs - > currentIndex ( ) ) ) {
if ( ! force & & ( isMinimized ( ) | | isHidden ( ) | | tabs - > currentIndex ( ) ) ) {
// No need to update if qBittorrent DL list is hidden
// No need to update if qBittorrent DL list is hidden
return ;
return ;
@ -650,7 +646,7 @@ void GUI::showAbout(){
void GUI : : closeEvent ( QCloseEvent * e ) {
void GUI : : closeEvent ( QCloseEvent * e ) {
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
bool goToSystrayOnExit = settings . value ( " Options/Misc/Behaviour/GoToSystrayOnExit " , false ) . toBool ( ) ;
bool goToSystrayOnExit = settings . value ( " Options/Misc/Behaviour/GoToSystrayOnExit " , false ) . toBool ( ) ;
if ( goToSystrayOnExit & & ! this - > isHidden ( ) ) {
if ( systrayIntegration & & goToSystrayOnExit & & ! this - > isHidden ( ) ) {
hide ( ) ;
hide ( ) ;
e - > ignore ( ) ;
e - > ignore ( ) ;
return ;
return ;
@ -688,8 +684,10 @@ void GUI::closeEvent(QCloseEvent *e){
saveColWidthDLList ( ) ;
saveColWidthDLList ( ) ;
// Create fast resume data
// Create fast resume data
BTSession . saveFastResumeData ( ) ;
BTSession . saveFastResumeData ( ) ;
// Hide tray icon
if ( systrayIntegration ) {
myTrayIcon - > hide ( ) ;
// Hide tray icon
myTrayIcon - > hide ( ) ;
}
// Accept exit
// Accept exit
e - > accept ( ) ;
e - > accept ( ) ;
}
}
@ -702,7 +700,7 @@ void GUI::showCreateWindow(){
// Called when we minimize the program
// Called when we minimize the program
void GUI : : hideEvent ( QHideEvent * e ) {
void GUI : : hideEvent ( QHideEvent * e ) {
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
if ( settings . value ( " Options/Misc/Behaviour/GoToSystray " , true ) . toBool ( ) ) {
if ( systrayIntegration & & s ettings . value ( " Options/Misc/Behaviour/GoToSystray " , true ) . toBool ( ) ) {
// Hide window
// Hide window
hide ( ) ;
hide ( ) ;
}
}
@ -1021,7 +1019,7 @@ void GUI::configureSession(bool deleteOptions){
// PeX
// PeX
if ( ! options - > isPeXDisabled ( ) ) {
if ( ! options - > isPeXDisabled ( ) ) {
qDebug ( " Enabling Peer eXchange (PeX) " ) ;
qDebug ( " Enabling Peer eXchange (PeX) " ) ;
setInfoBar ( tr ( " PeX support [OFF ] " ) , " blue " ) ;
setInfoBar ( tr ( " PeX support [ON ] " ) , " blue " ) ;
BTSession . enablePeerExchange ( ) ;
BTSession . enablePeerExchange ( ) ;
} else {
} else {
setInfoBar ( tr ( " PeX support [OFF] " ) , " blue " ) ;
setInfoBar ( tr ( " PeX support [OFF] " ) , " blue " ) ;
@ -1172,7 +1170,7 @@ void GUI::finishedTorrent(torrent_handle& h){
QString fileName = QString ( h . name ( ) . c_str ( ) ) ;
QString fileName = QString ( h . name ( ) . c_str ( ) ) ;
setInfoBar ( tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) ) ;
setInfoBar ( tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) ) ;
int useOSD = settings . value ( " Options/OSDEnabled " , 1 ) . toInt ( ) ;
int useOSD = settings . value ( " Options/OSDEnabled " , 1 ) . toInt ( ) ;
if ( useOSD = = 1 | | ( useOSD = = 2 & & ( isMinimized ( ) | | isHidden ( ) ) ) ) {
if ( systrayIntegration & & ( useOSD = = 1 | | ( useOSD = = 2 & & ( isMinimized ( ) | | isHidden ( ) ) ) ) ) {
myTrayIcon - > showMessage ( tr ( " Download finished " ) , tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) , QSystemTrayIcon : : Information , TIME_TRAY_BALLOON ) ;
myTrayIcon - > showMessage ( tr ( " Download finished " ) , tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) , QSystemTrayIcon : : Information , TIME_TRAY_BALLOON ) ;
}
}
}
}
@ -1181,7 +1179,7 @@ void GUI::finishedTorrent(torrent_handle& h){
void GUI : : fullDiskError ( torrent_handle & h ) {
void GUI : : fullDiskError ( torrent_handle & h ) {
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
int useOSD = settings . value ( " Options/OSDEnabled " , 1 ) . toInt ( ) ;
int useOSD = settings . value ( " Options/OSDEnabled " , 1 ) . toInt ( ) ;
if ( useOSD = = 1 | | ( useOSD = = 2 & & ( isMinimized ( ) | | isHidden ( ) ) ) ) {
if ( systrayIntegration & & ( useOSD = = 1 | | ( useOSD = = 2 & & ( isMinimized ( ) | | isHidden ( ) ) ) ) ) {
myTrayIcon - > showMessage ( tr ( " I/O Error " , " i.e: Input/Output Error " ) , tr ( " An error occured when trying to read or write %1. The disk is probably full, download has been paused " , " e.g: An error occured when trying to read or write xxx.avi. The disk is probably full, download has been paused " ) . arg ( QString ( h . name ( ) . c_str ( ) ) ) , QSystemTrayIcon : : Critical , TIME_TRAY_BALLOON ) ;
myTrayIcon - > showMessage ( tr ( " I/O Error " , " i.e: Input/Output Error " ) , tr ( " An error occured when trying to read or write %1. The disk is probably full, download has been paused " , " e.g: An error occured when trying to read or write xxx.avi. The disk is probably full, download has been paused " ) . arg ( QString ( h . name ( ) . c_str ( ) ) ) , QSystemTrayIcon : : Critical , TIME_TRAY_BALLOON ) ;
}
}
// Download will be paused by libtorrent. Updating GUI information accordingly
// Download will be paused by libtorrent. Updating GUI information accordingly
@ -1300,6 +1298,25 @@ void GUI::displayDownloadingUrlInfos(const QString& url){
* *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void GUI : : createTrayIcon ( ) {
// Tray icon
myTrayIcon = new QSystemTrayIcon ( QIcon ( " :/Icons/qbittorrent22.png " ) , this ) ;
// Tray icon Menu
myTrayIconMenu = new QMenu ( this ) ;
myTrayIconMenu - > addAction ( actionOpen ) ;
myTrayIconMenu - > addAction ( actionDownload_from_URL ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionStart_All ) ;
myTrayIconMenu - > addAction ( actionPause_All ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionExit ) ;
myTrayIcon - > setContextMenu ( myTrayIconMenu ) ;
connect ( myTrayIcon , SIGNAL ( messageClicked ( ) ) , this , SLOT ( balloonClicked ( ) ) ) ;
// End of Icon Menu
connect ( myTrayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( toggleVisibility ( QSystemTrayIcon : : ActivationReason ) ) ) ;
myTrayIcon - > show ( ) ;
}
// Display Program Options
// Display Program Options
void GUI : : showOptions ( ) {
void GUI : : showOptions ( ) {
options = new options_imp ( this ) ;
options = new options_imp ( this ) ;
@ -1309,6 +1326,17 @@ void GUI::showOptions(){
// Is executed each time options are saved
// Is executed each time options are saved
void GUI : : OptionsSaved ( const QString & info , bool deleteOptions ) {
void GUI : : OptionsSaved ( const QString & info , bool deleteOptions ) {
bool newSystrayIntegration = options - > useSystrayIntegration ( ) ;
if ( newSystrayIntegration & & ! systrayIntegration ) {
// create the trayicon
createTrayIcon ( ) ;
}
if ( ! newSystrayIntegration & & systrayIntegration ) {
// Destroy trayicon
delete myTrayIcon ;
delete myTrayIconMenu ;
}
systrayIntegration = newSystrayIntegration ;
// Update info bar
// Update info bar
setInfoBar ( info ) ;
setInfoBar ( info ) ;
// Update session
// Update session