2006-09-30 20:02:39 +04:00
/*
* Bittorrent Client using Qt4 and libtorrent .
2007-07-14 18:31:59 +04:00
* Copyright ( C ) 2006 Christophe Dumez
2006-09-30 20:02:39 +04:00
*
2007-07-14 18:31:59 +04:00
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
2006-09-30 20:02:39 +04:00
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2007-07-14 18:31:59 +04:00
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* Contact : chris @ qbittorrent . org
2006-09-30 20:02:39 +04:00
*/
# include <QFileDialog>
# include <QMessageBox>
# include <QDesktopWidget>
# include <QTimer>
2006-12-27 06:19:38 +03:00
# include <QDesktopServices>
2008-07-11 00:19:28 +04:00
# include <QStatusBar>
# include <QFrame>
2008-07-06 22:39:07 +04:00
# ifdef QT_4_4
# include <QLocalServer>
# include <QLocalSocket>
# include <unistd.h>
# include <sys/types.h>
# else
# include <QTcpServer>
# include <QTcpSocket>
# endif
2008-09-13 11:33:41 +04:00
# include <stdlib.h>
2007-03-27 22:49:29 +04:00
# include <QCloseEvent>
2007-07-19 16:58:45 +04:00
# include <QShortcut>
2007-08-26 20:25:22 +04:00
# include <QLabel>
# include <QModelIndex>
2006-12-28 02:56:30 +03:00
2006-09-30 20:02:39 +04:00
# include "GUI.h"
2007-08-26 20:25:22 +04:00
# include "downloadingTorrents.h"
2006-09-30 20:02:39 +04:00
# include "misc.h"
# include "createtorrent_imp.h"
# include "downloadFromURLImp.h"
2006-10-24 01:42:37 +04:00
# include "torrentAddition.h"
2007-03-27 22:49:29 +04:00
# include "searchEngine.h"
2007-03-29 19:43:08 +04:00
# include "rss_imp.h"
2007-04-04 05:36:55 +04:00
# include "FinishedTorrents.h"
2007-07-23 16:12:55 +04:00
# include "bittorrent.h"
2007-07-23 16:46:36 +04:00
# include "about_imp.h"
# include "trackerLogin.h"
# include "options_imp.h"
2007-08-26 20:25:22 +04:00
# include "previewSelect.h"
2007-08-27 17:34:41 +04:00
# include "allocationDlg.h"
2008-09-13 11:33:41 +04:00
# include <stdlib.h>
2008-09-07 16:09:41 +04:00
# include "console_imp.h"
2008-09-13 11:33:41 +04:00
# include "httpserver.h"
2007-03-04 20:13:29 +03:00
2007-08-20 10:29:18 +04:00
using namespace libtorrent ;
2006-09-30 20:02:39 +04:00
/*****************************************************
* *
* GUI *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Constructor
2007-09-09 19:46:23 +04:00
GUI : : GUI ( QWidget * parent , QStringList torrentCmdLine ) : QMainWindow ( parent ) , displaySpeedInTitle ( false ) , force_exit ( false ) , refreshInterval ( 1500 ) {
2006-09-30 20:02:39 +04:00
setupUi ( this ) ;
2007-08-20 10:29:18 +04:00
setWindowTitle ( tr ( " qBittorrent %1 " , " e.g: qBittorrent v0.x " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2007-09-08 21:07:29 +04:00
systrayIntegration = settings . value ( QString : : fromUtf8 ( " Preferences/General/SystrayEnabled " ) , true ) . toBool ( ) ;
2008-01-04 23:09:37 +03:00
systrayCreator = 0 ;
2007-04-10 13:35:34 +04:00
// Create tray icon
2007-08-20 10:29:18 +04:00
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
if ( systrayIntegration ) {
2007-04-10 13:35:34 +04:00
createTrayIcon ( ) ;
}
} else {
2008-01-04 23:09:37 +03:00
if ( systrayIntegration ) {
// May be system startup, check again later
systrayCreator = new QTimer ( this ) ;
connect ( systrayCreator , SIGNAL ( timeout ( ) ) , this , SLOT ( createSystrayDelayed ( ) ) ) ;
systrayCreator - > start ( 1000 ) ;
}
2007-04-10 13:35:34 +04:00
systrayIntegration = false ;
2008-01-04 23:09:37 +03:00
qDebug ( " Info: System tray unavailable " ) ;
2007-04-10 13:35:34 +04:00
}
2006-09-30 20:02:39 +04:00
// Setting icons
this - > setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/qbittorrent32.png " ) ) ) ;
actionOpen - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/open.png " ) ) ) ;
actionExit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/exit.png " ) ) ) ;
actionDownload_from_URL - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/url.png " ) ) ) ;
actionOptions - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/settings.png " ) ) ) ;
actionAbout - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/info.png " ) ) ) ;
2006-12-27 06:19:38 +03:00
actionWebsite - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/qbittorrent32.png " ) ) ) ;
actionBugReport - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/newmsg.png " ) ) ) ;
2006-09-30 20:02:39 +04:00
actionStart - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/play.png " ) ) ) ;
actionPause - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/pause.png " ) ) ) ;
actionDelete - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/delete.png " ) ) ) ;
actionPause_All - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/pause_all.png " ) ) ) ;
actionStart_All - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/play_all.png " ) ) ) ;
actionClearLog - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/delete.png " ) ) ) ;
actionPreview_file - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/preview.png " ) ) ) ;
2007-04-10 14:50:34 +04:00
actionSet_upload_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/seeding.png " ) ) ) ;
actionSet_download_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/downloading.png " ) ) ) ;
2007-07-14 14:50:38 +04:00
actionSet_global_upload_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/seeding.png " ) ) ) ;
actionSet_global_download_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/downloading.png " ) ) ) ;
2007-06-19 19:11:02 +04:00
actionDocumentation - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/qb_question.png " ) ) ) ;
2008-12-29 23:01:03 +03:00
prioSeparator = toolBar - > insertSeparator ( actionDecreasePriority ) ;
prioSeparator2 = menu_Edit - > insertSeparator ( actionDecreasePriority ) ;
prioSeparator - > setVisible ( false ) ;
prioSeparator2 - > setVisible ( false ) ;
2006-10-29 13:17:53 +03:00
actionDelete_Permanently - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/delete_perm.png " ) ) ) ;
2006-09-30 20:02:39 +04:00
actionTorrent_Properties - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/properties.png " ) ) ) ;
actionCreate_torrent - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/new.png " ) ) ) ;
// Fix Tool bar layout
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
2007-08-26 20:25:22 +04:00
// creating options
options = new options_imp ( this ) ;
2008-09-07 15:31:29 +04:00
connect ( options , SIGNAL ( status_changed ( bool ) ) , this , SLOT ( OptionsSaved ( bool ) ) ) ;
2007-08-26 20:25:22 +04:00
BTSession = new bittorrent ( ) ;
2007-08-20 10:29:18 +04:00
connect ( BTSession , SIGNAL ( fullDiskError ( QTorrentHandle & ) ) , this , SLOT ( fullDiskError ( QTorrentHandle & ) ) ) ;
2007-08-26 20:25:22 +04:00
connect ( BTSession , SIGNAL ( finishedTorrent ( QTorrentHandle & ) ) , this , SLOT ( finishedTorrent ( QTorrentHandle & ) ) ) ;
2008-12-27 00:18:33 +03:00
connect ( BTSession , SIGNAL ( addedTorrent ( QTorrentHandle & ) ) , this , SLOT ( addedTorrent ( QTorrentHandle & ) ) ) ;
2008-12-29 21:36:54 +03:00
connect ( BTSession , SIGNAL ( pausedTorrent ( QTorrentHandle & ) ) , this , SLOT ( pausedTorrent ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( resumedTorrent ( QTorrentHandle & ) ) , this , SLOT ( resumedTorrent ( QTorrentHandle & ) ) ) ;
2008-12-27 00:18:33 +03:00
connect ( BTSession , SIGNAL ( torrentFinishedChecking ( QTorrentHandle & ) ) , this , SLOT ( checkedTorrent ( QTorrentHandle & ) ) ) ;
2007-08-20 10:29:18 +04:00
connect ( BTSession , SIGNAL ( trackerAuthenticationRequired ( QTorrentHandle & ) ) , this , SLOT ( trackerAuthenticationRequired ( QTorrentHandle & ) ) ) ;
2007-07-22 13:47:27 +04:00
connect ( BTSession , SIGNAL ( newDownloadedTorrent ( QString , QString ) ) , this , SLOT ( processDownloadedFiles ( QString , QString ) ) ) ;
connect ( BTSession , SIGNAL ( downloadFromUrlFailure ( QString , QString ) ) , this , SLOT ( handleDownloadFromUrlFailure ( QString , QString ) ) ) ;
2008-05-16 11:10:50 +04:00
connect ( BTSession , SIGNAL ( deletedTorrent ( QString ) ) , this , SLOT ( deleteTorrent ( QString ) ) ) ;
2007-08-26 20:25:22 +04:00
qDebug ( " create tabWidget " ) ;
tabs = new QTabWidget ( ) ;
// Download torrents tab
downloadingTorrentTab = new DownloadingTorrents ( this , BTSession ) ;
2008-05-18 13:26:02 +04:00
tabs - > addTab ( downloadingTorrentTab , tr ( " Downloads " ) + QString : : fromUtf8 ( " (0/0) " ) ) ;
2007-08-26 20:25:22 +04:00
tabs - > setTabIcon ( 0 , QIcon ( QString : : fromUtf8 ( " :/Icons/skin/downloading.png " ) ) ) ;
2008-06-23 22:58:24 +04:00
vboxLayout - > addWidget ( tabs ) ;
2007-08-26 20:25:22 +04:00
connect ( downloadingTorrentTab , SIGNAL ( unfinishedTorrentsNumberChanged ( unsigned int ) ) , this , SLOT ( updateUnfinishedTorrentNumber ( unsigned int ) ) ) ;
2007-11-07 00:11:09 +03:00
connect ( downloadingTorrentTab , SIGNAL ( torrentDoubleClicked ( QString , bool ) ) , this , SLOT ( torrentDoubleClicked ( QString , bool ) ) ) ;
2007-08-26 20:25:22 +04:00
// Finished torrents tab
finishedTorrentTab = new FinishedTorrents ( this , BTSession ) ;
2008-09-07 16:12:16 +04:00
tabs - > addTab ( finishedTorrentTab , tr ( " Uploads " ) + QString : : fromUtf8 ( " (0/0) " ) ) ;
2007-08-26 20:25:22 +04:00
tabs - > setTabIcon ( 1 , QIcon ( QString : : fromUtf8 ( " :/Icons/skin/seeding.png " ) ) ) ;
2007-11-07 00:11:09 +03:00
connect ( finishedTorrentTab , SIGNAL ( torrentDoubleClicked ( QString , bool ) ) , this , SLOT ( torrentDoubleClicked ( QString , bool ) ) ) ;
2007-08-26 20:25:22 +04:00
connect ( finishedTorrentTab , SIGNAL ( finishedTorrentsNumberChanged ( unsigned int ) ) , this , SLOT ( updateFinishedTorrentNumber ( unsigned int ) ) ) ;
2008-07-11 21:43:57 +04:00
// Search engine tab
searchEngine = new SearchEngine ( BTSession , myTrayIcon , systrayIntegration ) ;
tabs - > addTab ( searchEngine , tr ( " Search " ) ) ;
tabs - > setTabIcon ( 2 , QIcon ( QString : : fromUtf8 ( " :/Icons/skin/search.png " ) ) ) ;
readSettings ( ) ;
// RSS Tab
rssWidget = 0 ;
2007-09-16 18:25:24 +04:00
// Start download list refresher
refresher = new QTimer ( this ) ;
connect ( refresher , SIGNAL ( timeout ( ) ) , this , SLOT ( updateLists ( ) ) ) ;
refresher - > start ( 1500 ) ;
2008-09-28 21:58:12 +04:00
// Configure BT session according to options
configureSession ( true ) ;
2008-10-04 18:14:07 +04:00
// Resume unfinished torrents
BTSession - > resumeUnfinishedTorrents ( ) ;
2008-11-02 21:19:14 +03:00
downloadingTorrentTab - > loadLastSortedColumn ( ) ;
finishedTorrentTab - > loadLastSortedColumn ( ) ;
2006-09-30 20:02:39 +04:00
// Add torrent given on command line
2006-10-24 01:42:37 +04:00
processParams ( torrentCmdLine ) ;
2008-05-16 11:10:50 +04:00
// Initialize Web UI
httpServer = 0 ;
if ( settings . value ( " Preferences/WebUI/Enabled " , false ) . toBool ( ) )
{
quint16 port = settings . value ( " Preferences/WebUI/Port " , 8080 ) . toUInt ( ) ;
QString username = settings . value ( " Preferences/WebUI/Username " , " " ) . toString ( ) ;
QString password = settings . value ( " Preferences/WebUI/Password " , " " ) . toString ( ) ;
initWebUi ( username , password , port ) ;
}
2006-09-30 20:02:39 +04:00
// Use a tcp server to allow only one instance of qBittorrent
2008-07-06 22:39:07 +04:00
# ifdef QT_4_4
localServer = new QLocalServer ( ) ;
QString uid = QString : : number ( getuid ( ) ) ;
2008-10-29 22:58:44 +03:00
# ifdef Q_WS_X11
if ( QFile : : exists ( QDir : : tempPath ( ) + QDir : : separator ( ) + QString ( " qBittorrent- " ) + uid ) ) {
// Socket was not closed cleanly
std : : cerr < < " Warning: Local domain socket was not closed cleanly, deleting file... \n " ;
QFile : : remove ( QDir : : tempPath ( ) + QDir : : separator ( ) + QString ( " qBittorrent- " ) + uid ) ;
}
# endif
2008-07-06 22:39:07 +04:00
if ( ! localServer - > listen ( " qBittorrent- " + uid ) ) {
# else
localServer = new QTcpServer ( ) ;
if ( ! localServer - > listen ( QHostAddress : : LocalHost ) ) {
# endif
2006-10-16 13:02:53 +04:00
std : : cerr < < " Couldn't create socket, single instance mode won't work... \n " ;
2006-09-30 20:02:39 +04:00
}
2008-10-29 22:58:44 +03:00
# ifndef QT_4_4
2008-07-06 22:39:07 +04:00
else {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
settings . setValue ( QString : : fromUtf8 ( " uniqueInstancePort " ) , localServer - > serverPort ( ) ) ;
}
# endif
connect ( localServer , SIGNAL ( newConnection ( ) ) , this , SLOT ( acceptConnection ( ) ) ) ;
2006-09-30 20:02:39 +04:00
// Start connection checking timer
checkConnect = new QTimer ( this ) ;
connect ( checkConnect , SIGNAL ( timeout ( ) ) , this , SLOT ( checkConnectionStatus ( ) ) ) ;
checkConnect - > start ( 5000 ) ;
// Accept drag 'n drops
setAcceptDrops ( true ) ;
2007-07-19 16:58:45 +04:00
createKeyboardShortcuts ( ) ;
2008-08-08 17:17:26 +04:00
connecStatusLblIcon = new QLabel ( ) ;
connecStatusLblIcon - > setFrameShape ( QFrame : : NoFrame ) ;
connecStatusLblIcon - > setPixmap ( QPixmap ( 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> " ) ) ;
2008-07-11 00:19:28 +04:00
dlSpeedLbl = new QLabel ( tr ( " DL: %1 KiB/s " ) . arg ( " 0.0 " ) ) ;
upSpeedLbl = new QLabel ( tr ( " UP: %1 KiB/s " ) . arg ( " 0.0 " ) ) ;
ratioLbl = new QLabel ( tr ( " Ratio: %1 " ) . arg ( " 1.0 " ) ) ;
2008-07-11 00:21:07 +04:00
DHTLbl = new QLabel ( tr ( " DHT: %1 nodes " ) . arg ( 0 ) ) ;
2008-07-11 00:19:28 +04:00
statusSep1 = new QFrame ( ) ;
statusSep1 - > setFixedWidth ( 1 ) ;
statusSep1 - > setFrameStyle ( QFrame : : Box ) ;
statusSep2 = new QFrame ( ) ;
statusSep2 - > setFixedWidth ( 1 ) ;
statusSep2 - > setFrameStyle ( QFrame : : Box ) ;
statusSep3 = new QFrame ( ) ;
statusSep3 - > setFixedWidth ( 1 ) ;
statusSep3 - > setFrameStyle ( QFrame : : Box ) ;
2008-08-08 17:17:26 +04:00
statusSep4 = new QFrame ( ) ;
statusSep4 - > setFixedWidth ( 1 ) ;
statusSep4 - > setFrameStyle ( QFrame : : Box ) ;
2008-07-11 00:19:28 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( DHTLbl ) ;
QMainWindow : : statusBar ( ) - > addPermanentWidget ( statusSep1 ) ;
2008-08-08 17:17:26 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( connecStatusLblIcon ) ;
2008-07-11 00:19:28 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( statusSep2 ) ;
2008-08-08 17:17:26 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( dlSpeedLbl ) ;
2008-07-11 00:19:28 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( statusSep3 ) ;
2008-08-08 17:17:26 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( upSpeedLbl ) ;
QMainWindow : : statusBar ( ) - > addPermanentWidget ( statusSep4 ) ;
2008-07-11 00:19:28 +04:00
QMainWindow : : statusBar ( ) - > addPermanentWidget ( ratioLbl ) ;
2008-12-27 00:41:09 +03:00
if ( ! settings . value ( QString : : fromUtf8 ( " Preferences/General/StartMinimized " ) , false ) . toBool ( ) ) {
show ( ) ;
}
2006-09-30 20:02:39 +04:00
qDebug ( " GUI Built " ) ;
}
// Destructor
2007-08-20 10:29:18 +04:00
GUI : : ~ GUI ( ) {
2007-07-14 16:35:04 +04:00
qDebug ( " GUI destruction " ) ;
2008-12-26 19:23:53 +03:00
hide ( ) ;
2008-12-27 13:02:42 +03:00
// Do this as soon as possible
BTSession - > saveDHTEntry ( ) ;
BTSession - > saveSessionState ( ) ;
BTSession - > saveFastResumeData ( ) ;
2008-07-11 00:19:28 +04:00
delete dlSpeedLbl ;
delete upSpeedLbl ;
delete ratioLbl ;
delete DHTLbl ;
delete statusSep1 ;
delete statusSep2 ;
delete statusSep3 ;
2008-08-08 17:17:26 +04:00
delete statusSep4 ;
2008-07-11 21:43:57 +04:00
if ( rssWidget ! = 0 )
delete rssWidget ;
2007-03-27 22:49:29 +04:00
delete searchEngine ;
2007-08-26 20:25:22 +04:00
delete refresher ;
delete downloadingTorrentTab ;
2007-04-04 05:36:55 +04:00
delete finishedTorrentTab ;
2006-09-30 20:02:39 +04:00
delete checkConnect ;
2008-05-18 16:01:42 +04:00
qDebug ( " 1 " ) ;
2008-01-04 23:09:37 +03:00
if ( systrayCreator ) {
delete systrayCreator ;
}
2007-08-20 10:29:18 +04:00
if ( systrayIntegration ) {
2007-07-19 16:58:45 +04:00
delete myTrayIcon ;
delete myTrayIconMenu ;
}
2008-05-18 16:01:42 +04:00
qDebug ( " 2 " ) ;
2008-10-04 23:36:27 +04:00
localServer - > close ( ) ;
2008-07-06 22:39:07 +04:00
delete localServer ;
2007-07-19 16:58:45 +04:00
delete connecStatusLblIcon ;
2007-08-26 20:25:22 +04:00
delete tabs ;
2008-05-16 11:10:50 +04:00
// HTTP Server
if ( httpServer )
delete httpServer ;
2008-05-18 16:01:42 +04:00
qDebug ( " 3 " ) ;
2007-07-19 16:58:45 +04:00
// Keyboard shortcuts
delete switchSearchShortcut ;
2007-08-18 16:43:21 +04:00
delete switchSearchShortcut2 ;
2007-07-19 16:58:45 +04:00
delete switchDownShortcut ;
delete switchUpShortcut ;
delete switchRSSShortcut ;
2008-05-18 16:01:42 +04:00
qDebug ( " 4 " ) ;
2007-08-08 03:00:51 +04:00
delete BTSession ;
2008-05-18 16:01:42 +04:00
qDebug ( " 5 " ) ;
2006-09-30 20:02:39 +04:00
}
2008-07-11 21:43:57 +04:00
void GUI : : displayRSSTab ( bool enable ) {
if ( enable ) {
// RSS tab
2008-08-20 16:15:50 +04:00
if ( rssWidget = = 0 ) {
rssWidget = new RSSImp ( ) ;
tabs - > addTab ( rssWidget , tr ( " RSS " ) ) ;
tabs - > setTabIcon ( 3 , QIcon ( QString : : fromUtf8 ( " :/Icons/rss32.png " ) ) ) ;
}
2008-07-11 21:43:57 +04:00
} else {
if ( rssWidget ! = 0 ) {
delete rssWidget ;
rssWidget = 0 ;
}
}
}
2008-06-09 23:59:51 +04:00
void GUI : : updateRatio ( ) {
// Update ratio info
float ratio = 1. ;
session_status sessionStatus = BTSession - > getSessionStatus ( ) ;
if ( sessionStatus . total_payload_download = = 0 ) {
if ( sessionStatus . total_payload_upload = = 0 )
ratio = 1. ;
else
ratio = 10. ;
} else {
ratio = ( double ) sessionStatus . total_payload_upload / ( double ) sessionStatus . total_payload_download ;
if ( ratio > 10. )
ratio = 10. ;
}
2008-07-11 00:19:28 +04:00
ratioLbl - > setText ( tr ( " Ratio: %1 " ) . arg ( QString ( QByteArray : : number ( ratio , ' f ' , 1 ) ) ) ) ;
// Update DHT nodes
2008-07-11 00:21:07 +04:00
DHTLbl - > setText ( tr ( " DHT: %1 nodes " ) . arg ( QString : : number ( sessionStatus . dht_nodes ) ) ) ;
2008-06-09 23:59:51 +04:00
}
2007-08-28 21:03:55 +04:00
void GUI : : on_actionWebsite_triggered ( ) const {
2007-08-20 10:29:18 +04:00
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://www.qbittorrent.org " ) ) ) ;
2006-12-27 06:19:38 +03:00
}
2007-08-28 21:03:55 +04:00
void GUI : : on_actionDocumentation_triggered ( ) const {
2007-08-20 10:29:18 +04:00
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://wiki.qbittorrent.org " ) ) ) ;
2007-06-17 19:09:00 +04:00
}
2007-08-28 21:03:55 +04:00
void GUI : : on_actionBugReport_triggered ( ) const {
2007-08-20 10:29:18 +04:00
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://bugs.qbittorrent.org " ) ) ) ;
2006-12-27 06:19:38 +03:00
}
2006-11-14 19:46:05 +03:00
void GUI : : writeSettings ( ) {
2007-08-20 10:29:18 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
settings . beginGroup ( QString : : fromUtf8 ( " MainWindow " ) ) ;
settings . setValue ( QString : : fromUtf8 ( " size " ) , size ( ) ) ;
settings . setValue ( QString : : fromUtf8 ( " pos " ) , pos ( ) ) ;
2006-11-14 19:46:05 +03:00
settings . endGroup ( ) ;
}
2007-08-26 20:25:22 +04:00
// called when a torrent has finished
2007-08-28 21:33:00 +04:00
void GUI : : finishedTorrent ( QTorrentHandle & h ) const {
2007-08-26 20:25:22 +04:00
qDebug ( " In GUI, a torrent has finished " ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
bool show_msg = true ;
2008-12-27 00:18:33 +03:00
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) )
show_msg = false ;
2007-08-26 20:25:22 +04:00
QString fileName = h . name ( ) ;
2007-09-08 21:07:29 +04:00
bool useNotificationBalloons = settings . value ( QString : : fromUtf8 ( " Preferences/General/NotificationBaloons " ) , true ) . toBool ( ) ;
2007-08-26 20:25:22 +04:00
// Add it to finished tab
QString hash = h . hash ( ) ;
if ( show_msg )
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) ) ;
2007-08-26 21:25:37 +04:00
downloadingTorrentTab - > deleteTorrent ( hash ) ;
2007-08-26 20:25:22 +04:00
finishedTorrentTab - > addTorrent ( hash ) ;
2007-09-08 21:07:29 +04:00
if ( show_msg & & systrayIntegration & & useNotificationBalloons ) {
2007-08-26 20:25:22 +04:00
myTrayIcon - > showMessage ( tr ( " Download finished " ) , tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) , QSystemTrayIcon : : Information , TIME_TRAY_BALLOON ) ;
}
}
2008-12-27 00:18:33 +03:00
void GUI : : addedTorrent ( QTorrentHandle & h ) const {
if ( h . is_seed ( ) ) {
finishedTorrentTab - > addTorrent ( h . hash ( ) ) ;
} else {
downloadingTorrentTab - > addTorrent ( h . hash ( ) ) ;
}
}
2008-12-29 21:36:54 +03:00
void GUI : : pausedTorrent ( QTorrentHandle & h ) const {
if ( h . is_seed ( ) ) {
finishedTorrentTab - > pauseTorrent ( h . hash ( ) ) ;
} else {
downloadingTorrentTab - > pauseTorrent ( h . hash ( ) ) ;
}
}
void GUI : : resumedTorrent ( QTorrentHandle & h ) const {
if ( h . is_seed ( ) ) {
finishedTorrentTab - > updateTorrent ( h ) ;
} else {
downloadingTorrentTab - > updateTorrent ( h ) ;
}
}
2008-12-27 00:18:33 +03:00
void GUI : : checkedTorrent ( QTorrentHandle & h ) const {
if ( h . is_seed ( ) ) {
// Move torrent to finished tab
downloadingTorrentTab - > deleteTorrent ( h . hash ( ) ) ;
finishedTorrentTab - > addTorrent ( h . hash ( ) ) ;
2008-12-27 00:49:13 +03:00
} else {
// Move torrent back to download list (if necessary)
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) ) {
QFile : : remove ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) ;
finishedTorrentTab - > deleteTorrent ( h . hash ( ) ) ;
downloadingTorrentTab - > addTorrent ( h . hash ( ) ) ;
}
2008-12-27 00:18:33 +03:00
}
}
2007-08-26 20:25:22 +04:00
// Notification when disk is full
2007-08-28 21:33:00 +04:00
void GUI : : fullDiskError ( QTorrentHandle & h ) const {
2007-08-26 20:25:22 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2007-09-08 21:07:29 +04:00
bool useNotificationBalloons = settings . value ( QString : : fromUtf8 ( " Preferences/General/NotificationBaloons " ) , true ) . toBool ( ) ;
if ( systrayIntegration & & useNotificationBalloons ) {
2007-08-26 20:25:22 +04:00
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 ( h . name ( ) ) , QSystemTrayIcon : : Critical , TIME_TRAY_BALLOON ) ;
}
// Download will be paused by libtorrent. Updating GUI information accordingly
QString hash = h . hash ( ) ;
qDebug ( " Full disk error, pausing torrent %s " , hash . toUtf8 ( ) . data ( ) ) ;
2008-12-27 12:21:09 +03:00
if ( h . is_seed ( ) ) {
2007-08-26 20:25:22 +04:00
// In finished list
qDebug ( " Automatically paused torrent was in finished list " ) ;
finishedTorrentTab - > pauseTorrent ( hash ) ;
} else {
downloadingTorrentTab - > pauseTorrent ( hash ) ;
}
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " An error occured (full disk?), '%1' paused. " , " e.g: An error occured (full disk?), 'xxx.avi' paused. " ) . arg ( h . name ( ) ) ) ;
2007-08-26 20:25:22 +04:00
}
2007-08-20 10:29:18 +04:00
void GUI : : createKeyboardShortcuts ( ) {
actionCreate_torrent - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+N " ) ) ) ;
actionOpen - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+O " ) ) ) ;
actionExit - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Q " ) ) ) ;
2007-07-19 16:58:45 +04:00
switchDownShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+1 " , " shortcut to switch to first tab " ) ) , this ) ;
connect ( switchDownShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayDownTab ( ) ) ) ;
switchUpShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+2 " , " shortcut to switch to second tab " ) ) , this ) ;
connect ( switchUpShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayUpTab ( ) ) ) ;
2007-08-18 16:43:21 +04:00
switchSearchShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+3 " , " shortcut to switch to third tab " ) ) , this ) ;
2007-07-19 16:58:45 +04:00
connect ( switchSearchShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displaySearchTab ( ) ) ) ;
2007-08-18 16:43:21 +04:00
switchSearchShortcut2 = new QShortcut ( QKeySequence ( tr ( " Ctrl+F " , " shortcut to switch to search tab " ) ) , this ) ;
connect ( switchSearchShortcut2 , SIGNAL ( activated ( ) ) , this , SLOT ( displaySearchTab ( ) ) ) ;
2007-07-19 16:58:45 +04:00
switchRSSShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+4 " , " shortcut to switch to fourth tab " ) ) , this ) ;
connect ( switchRSSShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayRSSTab ( ) ) ) ;
2007-08-20 10:29:18 +04:00
actionTorrent_Properties - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Alt+P " ) ) ) ;
actionOptions - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Alt+O " ) ) ) ;
actionDelete - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Del " ) ) ) ;
actionDelete_Permanently - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Shift+Del " ) ) ) ;
actionStart - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+S " ) ) ) ;
actionStart_All - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Shift+S " ) ) ) ;
actionPause - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+P " ) ) ) ;
actionPause_All - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Shift+P " ) ) ) ;
2008-08-08 17:17:26 +04:00
actionDecreasePriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+- " ) ) ) ;
actionIncreasePriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl++ " ) ) ) ;
2007-07-19 16:58:45 +04:00
}
// Keyboard shortcuts slots
2007-08-28 21:33:00 +04:00
void GUI : : displayDownTab ( ) const {
2007-07-19 16:58:45 +04:00
tabs - > setCurrentIndex ( 0 ) ;
}
2007-08-28 21:33:00 +04:00
void GUI : : displayUpTab ( ) const {
2007-07-19 16:58:45 +04:00
tabs - > setCurrentIndex ( 1 ) ;
}
2007-08-28 21:33:00 +04:00
void GUI : : displaySearchTab ( ) const {
2007-07-19 16:58:45 +04:00
tabs - > setCurrentIndex ( 2 ) ;
}
2007-08-28 21:33:00 +04:00
void GUI : : displayRSSTab ( ) const {
2007-07-19 16:58:45 +04:00
tabs - > setCurrentIndex ( 3 ) ;
}
// End of keyboard shortcuts slots
2006-11-14 19:46:05 +03:00
void GUI : : readSettings ( ) {
2007-08-20 10:29:18 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
settings . beginGroup ( QString : : fromUtf8 ( " MainWindow " ) ) ;
resize ( settings . value ( QString : : fromUtf8 ( " size " ) , size ( ) ) . toSize ( ) ) ;
move ( settings . value ( QString : : fromUtf8 ( " pos " ) , screenCenter ( ) ) . toPoint ( ) ) ;
2006-11-14 19:46:05 +03:00
settings . endGroup ( ) ;
}
2007-08-20 10:29:18 +04:00
void GUI : : balloonClicked ( ) {
if ( isHidden ( ) ) {
2006-10-19 00:40:40 +04:00
show ( ) ;
2007-08-20 10:29:18 +04:00
if ( isMinimized ( ) ) {
2006-10-19 00:40:40 +04:00
showNormal ( ) ;
}
raise ( ) ;
activateWindow ( ) ;
}
}
2006-09-30 20:02:39 +04:00
2007-08-20 10:29:18 +04:00
void GUI : : acceptConnection ( ) {
2008-07-06 22:39:07 +04:00
clientConnection = localServer - > nextPendingConnection ( ) ;
2006-12-05 03:27:00 +03:00
connect ( clientConnection , SIGNAL ( disconnected ( ) ) , this , SLOT ( readParamsOnSocket ( ) ) ) ;
qDebug ( " accepted connection from another instance " ) ;
}
2007-08-20 10:29:18 +04:00
void GUI : : readParamsOnSocket ( ) {
2008-09-13 11:33:41 +04:00
if ( clientConnection ) {
2006-12-05 03:27:00 +03:00
QByteArray params = clientConnection - > readAll ( ) ;
2007-08-20 10:29:18 +04:00
if ( ! params . isEmpty ( ) ) {
processParams ( QString : : fromUtf8 ( params . data ( ) ) . split ( QString : : fromUtf8 ( " \n " ) ) ) ;
2006-12-05 03:27:00 +03:00
qDebug ( " Received parameters from another instance " ) ;
}
2006-09-30 20:02:39 +04:00
}
}
2007-07-30 14:27:56 +04:00
void GUI : : handleDownloadFromUrlFailure ( QString url , QString reason ) const {
2007-07-21 00:18:18 +04:00
// Display a message box
2007-07-21 00:30:33 +04:00
QMessageBox : : critical ( 0 , tr ( " Url download error " ) , tr ( " Couldn't download file at url: %1, reason: %2. " ) . arg ( url ) . arg ( reason ) ) ;
2007-07-21 00:18:18 +04:00
}
2007-08-20 10:29:18 +04:00
void GUI : : on_actionSet_global_upload_limit_triggered ( ) {
2007-07-14 14:50:38 +04:00
qDebug ( " actionSet_global_upload_limit_triggered " ) ;
2007-07-14 16:35:04 +04:00
new BandwidthAllocationDialog ( this , true , BTSession , QStringList ( ) ) ;
2007-07-14 14:50:38 +04:00
}
2008-09-07 16:09:41 +04:00
void GUI : : on_actionShow_console_triggered ( ) {
new consoleDlg ( this , BTSession ) ;
}
2007-08-20 10:29:18 +04:00
void GUI : : on_actionSet_global_download_limit_triggered ( ) {
2007-07-14 14:50:38 +04:00
qDebug ( " actionSet_global_download_limit_triggered " ) ;
2007-07-14 16:35:04 +04:00
new BandwidthAllocationDialog ( this , false , BTSession , QStringList ( ) ) ;
2007-07-14 14:50:38 +04:00
}
2007-08-20 10:29:18 +04:00
void GUI : : on_actionPreview_file_triggered ( ) {
2007-08-26 20:25:22 +04:00
QString hash ;
switch ( tabs - > currentIndex ( ) ) {
case 0 :
hash = downloadingTorrentTab - > getSelectedTorrents ( true ) . first ( ) ;
2006-09-30 20:02:39 +04:00
break ;
2007-08-26 20:25:22 +04:00
case 1 :
hash = finishedTorrentTab - > getSelectedTorrents ( true ) . first ( ) ;
break ;
default :
return ;
2006-09-30 20:02:39 +04:00
}
2007-08-26 20:25:22 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
new previewSelect ( this , h ) ;
2006-09-30 20:02:39 +04:00
}
2007-11-16 21:53:21 +03:00
void GUI : : openDestinationFolder ( ) const {
QStringList hashes ;
switch ( tabs - > currentIndex ( ) ) {
case 0 :
hashes = downloadingTorrentTab - > getSelectedTorrents ( true ) ;
break ;
case 1 :
hashes = finishedTorrentTab - > getSelectedTorrents ( true ) ;
break ;
default :
return ;
}
QString hash ;
QStringList pathsList ;
foreach ( hash , hashes ) {
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
QString savePath = h . save_path ( ) ;
if ( ! pathsList . contains ( savePath ) ) {
pathsList . append ( savePath ) ;
2007-12-09 12:28:11 +03:00
QDesktopServices : : openUrl ( QString ( " file:// " ) + savePath ) ;
2007-11-16 21:53:21 +03:00
}
}
}
2007-12-08 01:33:19 +03:00
void GUI : : goBuyPage ( ) const {
QStringList hashes ;
switch ( tabs - > currentIndex ( ) ) {
case 0 :
hashes = downloadingTorrentTab - > getSelectedTorrents ( true ) ;
break ;
case 1 :
hashes = finishedTorrentTab - > getSelectedTorrents ( true ) ;
break ;
default :
return ;
}
QString hash ;
QStringList pathsList ;
foreach ( hash , hashes ) {
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2007-12-31 00:03:05 +03:00
QDesktopServices : : openUrl ( " http://match.sharemonkey.com/?info_hash= " + hash + " &n= " + h . name ( ) + " &cid=33 " ) ;
2007-12-08 01:33:19 +03:00
}
}
2007-03-05 00:12:37 +03:00
// Necessary if we want to close the window
// in one time if "close to systray" is enabled
2007-08-20 10:29:18 +04:00
void GUI : : on_actionExit_triggered ( ) {
2007-03-30 00:21:17 +04:00
force_exit = true ;
2007-03-05 00:12:37 +03:00
close ( ) ;
}
2007-08-20 10:29:18 +04:00
void GUI : : previewFile ( QString filePath ) {
2007-12-09 12:30:06 +03:00
QDesktopServices : : openUrl ( QString ( " file:// " ) + filePath ) ;
2006-09-30 20:02:39 +04:00
}
2007-12-09 18:51:09 +03:00
int GUI : : getCurrentTabIndex ( ) const {
2007-07-30 14:37:13 +04:00
if ( isMinimized ( ) | | isHidden ( ) )
return - 1 ;
2007-07-29 19:17:50 +04:00
return tabs - > currentIndex ( ) ;
2006-09-30 20:02:39 +04:00
}
2007-08-28 21:33:00 +04:00
void GUI : : setTabText ( int index , QString text ) const {
2007-04-04 16:01:32 +04:00
tabs - > setTabText ( index , text ) ;
}
2006-09-30 20:02:39 +04:00
// Toggle Main window visibility
2007-08-20 10:29:18 +04:00
void GUI : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e ) {
if ( e = = QSystemTrayIcon : : Trigger | | e = = QSystemTrayIcon : : DoubleClick ) {
if ( isHidden ( ) ) {
2006-10-18 23:53:54 +04:00
show ( ) ;
2007-08-20 10:29:18 +04:00
if ( isMinimized ( ) ) {
if ( isMaximized ( ) ) {
2006-10-18 23:53:54 +04:00
showMaximized ( ) ;
} else {
showNormal ( ) ;
}
2006-09-30 20:02:39 +04:00
}
2006-10-18 23:53:54 +04:00
raise ( ) ;
activateWindow ( ) ;
} else {
hide ( ) ;
2006-09-30 20:02:39 +04:00
}
}
}
// Center window
2007-07-30 14:27:56 +04:00
QPoint GUI : : screenCenter ( ) const {
2006-09-30 20:02:39 +04:00
int scrn = 0 ;
QWidget * w = this - > topLevelWidget ( ) ;
if ( w )
scrn = QApplication : : desktop ( ) - > screenNumber ( w ) ;
else if ( QApplication : : desktop ( ) - > isVirtualDesktop ( ) )
scrn = QApplication : : desktop ( ) - > screenNumber ( QCursor : : pos ( ) ) ;
else
scrn = QApplication : : desktop ( ) - > screenNumber ( this ) ;
QRect desk ( QApplication : : desktop ( ) - > availableGeometry ( scrn ) ) ;
2006-11-14 19:46:05 +03:00
return QPoint ( ( desk . width ( ) - this - > frameGeometry ( ) . width ( ) ) / 2 , ( desk . height ( ) - this - > frameGeometry ( ) . height ( ) ) / 2 ) ;
2006-09-30 20:02:39 +04:00
}
// Display About Dialog
2007-08-20 10:29:18 +04:00
void GUI : : on_actionAbout_triggered ( ) {
2006-09-30 20:02:39 +04:00
//About dialog
2007-08-26 20:25:22 +04:00
new about ( this ) ;
2006-09-30 20:02:39 +04:00
}
2008-12-27 00:41:09 +03:00
void GUI : : showEvent ( QShowEvent * e ) {
qDebug ( " ** Show Event ** " ) ;
updateLists ( true ) ;
e - > accept ( ) ;
}
2006-09-30 20:02:39 +04:00
// Called when we close the program
2007-08-20 10:29:18 +04:00
void GUI : : closeEvent ( QCloseEvent * e ) {
2007-12-09 19:35:51 +03:00
2007-08-20 10:29:18 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2007-09-08 21:07:29 +04:00
bool goToSystrayOnExit = settings . value ( QString : : fromUtf8 ( " Preferences/General/CloseToTray " ) , false ) . toBool ( ) ;
2007-08-20 10:29:18 +04:00
if ( ! force_exit & & systrayIntegration & & goToSystrayOnExit & & ! this - > isHidden ( ) ) {
2007-02-24 22:23:10 +03:00
hide ( ) ;
e - > ignore ( ) ;
return ;
}
2007-09-08 21:07:29 +04:00
if ( settings . value ( QString : : fromUtf8 ( " Preferences/General/ExitConfirm " ) , true ) . toBool ( ) & & downloadingTorrentTab - > getNbTorrentsInList ( ) ) {
2007-03-29 22:46:50 +04:00
show ( ) ;
2007-04-04 18:53:00 +04:00
if ( ! isMaximized ( ) )
showNormal ( ) ;
2007-12-09 19:35:51 +03:00
if ( e - > spontaneous ( ) = = true | | force_exit = = true ) {
if ( QMessageBox : : question ( this ,
tr ( " Are you sure you want to quit? " ) + QString : : fromUtf8 ( " -- " ) + tr ( " qBittorrent " ) ,
tr ( " The download list is not empty. \n Are you sure you want to quit qBittorrent? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ) {
e - > ignore ( ) ;
force_exit = false ;
return ;
}
2006-09-30 20:02:39 +04:00
}
}
2007-07-14 14:50:38 +04:00
hide ( ) ;
2007-08-20 10:29:18 +04:00
if ( systrayIntegration ) {
2007-07-14 16:35:04 +04:00
// Hide tray icon
myTrayIcon - > hide ( ) ;
}
2006-09-30 20:02:39 +04:00
// Save window size, columns size
2006-11-14 19:46:05 +03:00
writeSettings ( ) ;
2006-09-30 20:02:39 +04:00
// Accept exit
e - > accept ( ) ;
2007-07-14 16:35:04 +04:00
qApp - > exit ( ) ;
2006-09-30 20:02:39 +04:00
}
2007-12-09 19:35:51 +03:00
2006-09-30 20:02:39 +04:00
// Display window to create a torrent
2007-08-20 10:29:18 +04:00
void GUI : : on_actionCreate_torrent_triggered ( ) {
2007-09-04 08:18:51 +04:00
createtorrent * ct = new createtorrent ( this ) ;
2007-10-12 15:50:02 +04:00
connect ( ct , SIGNAL ( torrent_to_seed ( QString ) ) , this , SLOT ( addTorrent ( QString ) ) ) ;
2006-09-30 20:02:39 +04:00
}
2008-08-02 00:03:16 +04:00
bool GUI : : event ( QEvent * e ) {
if ( e - > type ( ) = = QEvent : : WindowStateChange ) {
//Now check to see if the window is minimised
if ( isMinimized ( ) ) {
qDebug ( " minimisation " ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
if ( systrayIntegration & & settings . value ( QString : : fromUtf8 ( " Preferences/General/MinimizeToTray " ) , false ) . toBool ( ) ) {
hide ( ) ;
}
}
2006-09-30 20:02:39 +04:00
}
2008-08-02 00:03:16 +04:00
return QMainWindow : : event ( e ) ;
2006-12-27 06:19:38 +03:00
}
2006-09-30 20:02:39 +04:00
// Action executed when a file is dropped
2007-08-20 10:29:18 +04:00
void GUI : : dropEvent ( QDropEvent * event ) {
2006-09-30 20:02:39 +04:00
event - > acceptProposedAction ( ) ;
2007-09-02 17:19:30 +04:00
QStringList files ;
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
QUrl url ;
foreach ( url , urls ) {
2007-09-02 17:23:02 +04:00
QString tmp = url . toString ( ) ;
tmp . trimmed ( ) ;
if ( ! tmp . isEmpty ( ) )
files < < url . toString ( ) ;
2007-09-02 17:19:30 +04:00
}
} else {
files = event - > mimeData ( ) - > text ( ) . split ( QString : : fromUtf8 ( " \n " ) ) ;
}
2006-09-30 20:02:39 +04:00
// Add file to download list
2006-10-24 01:42:37 +04:00
QString file ;
2007-08-20 10:29:18 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2007-09-08 21:07:29 +04:00
bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2007-08-20 10:29:18 +04:00
foreach ( file , files ) {
2007-09-08 21:07:29 +04:00
file = file . trimmed ( ) . replace ( QString : : fromUtf8 ( " file:// " ) , QString : : fromUtf8 ( " " ) , Qt : : CaseInsensitive ) ;
2007-08-28 21:33:00 +04:00
qDebug ( " Dropped file %s on download list " , file . toUtf8 ( ) . data ( ) ) ;
2007-08-20 10:29:18 +04:00
if ( file . startsWith ( QString : : fromUtf8 ( " http:// " ) , Qt : : CaseInsensitive ) | | file . startsWith ( QString : : fromUtf8 ( " ftp:// " ) , Qt : : CaseInsensitive ) | | file . startsWith ( QString : : fromUtf8 ( " https:// " ) , Qt : : CaseInsensitive ) ) {
2007-07-30 13:30:07 +04:00
BTSession - > downloadFromUrl ( file ) ;
continue ;
}
2007-08-20 10:29:18 +04:00
if ( useTorrentAdditionDialog ) {
2008-09-07 15:31:29 +04:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this , BTSession ) ;
2007-07-30 13:30:07 +04:00
dialog - > showLoad ( file ) ;
2006-10-24 15:41:28 +04:00
} else {
2007-07-30 13:30:07 +04:00
BTSession - > addTorrent ( file ) ;
2006-10-24 15:41:28 +04:00
}
2006-10-24 01:42:37 +04:00
}
2006-09-30 20:02:39 +04:00
}
// Decode if we accept drag 'n drop or not
2007-08-20 10:29:18 +04:00
void GUI : : dragEnterEvent ( QDragEnterEvent * event ) {
2007-09-02 13:01:22 +04:00
QString mime ;
foreach ( mime , event - > mimeData ( ) - > formats ( ) ) {
qDebug ( " mimeData: %s " , mime . toUtf8 ( ) . data ( ) ) ;
}
2007-09-02 17:06:42 +04:00
if ( event - > mimeData ( ) - > hasFormat ( QString : : fromUtf8 ( " text/plain " ) ) | | event - > mimeData ( ) - > hasFormat ( QString : : fromUtf8 ( " text/uri-list " ) ) ) {
2006-09-30 20:02:39 +04:00
event - > acceptProposedAction ( ) ;
}
}
/*****************************************************
* *
* Torrent *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Display a dialog to allow user to add
// torrents to download list
2007-08-20 10:29:18 +04:00
void GUI : : on_actionOpen_triggered ( ) {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2006-09-30 20:02:39 +04:00
// Open File Open Dialog
// Note: it is possible to select more than one file
2007-09-08 21:07:29 +04:00
QStringList pathsList = QFileDialog : : getOpenFileNames ( 0 ,
2007-08-20 10:29:18 +04:00
tr ( " Open Torrent Files " ) , settings . value ( QString : : fromUtf8 ( " MainWindowLastDir " ) , QDir : : homePath ( ) ) . toString ( ) ,
tr ( " Torrent Files " ) + QString : : fromUtf8 ( " (*.torrent) " ) ) ;
if ( ! pathsList . empty ( ) ) {
2007-09-08 21:07:29 +04:00
bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2007-04-10 12:05:27 +04:00
unsigned int listSize = pathsList . size ( ) ;
2007-08-20 10:29:18 +04:00
for ( unsigned int i = 0 ; i < listSize ; + + i ) {
if ( useTorrentAdditionDialog ) {
2008-09-07 15:31:29 +04:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this , BTSession ) ;
2006-10-29 12:32:28 +03:00
dialog - > showLoad ( pathsList . at ( i ) ) ;
2006-10-24 15:41:28 +04:00
} else {
2007-07-14 16:35:04 +04:00
BTSession - > addTorrent ( pathsList . at ( i ) ) ;
2006-10-24 15:41:28 +04:00
}
2006-10-24 01:42:37 +04:00
}
2006-09-30 20:02:39 +04:00
// Save last dir to remember it
2006-11-15 00:17:51 +03:00
QStringList top_dir = pathsList . at ( 0 ) . split ( QDir : : separator ( ) ) ;
top_dir . removeLast ( ) ;
2007-08-20 10:29:18 +04:00
settings . setValue ( QString : : fromUtf8 ( " MainWindowLastDir " ) , top_dir . join ( QDir : : separator ( ) ) ) ;
2006-09-30 20:02:39 +04:00
}
}
2006-10-29 13:17:53 +03:00
// delete from download list AND from hard drive
2007-08-20 10:29:18 +04:00
void GUI : : on_actionDelete_Permanently_triggered ( ) {
2007-08-26 20:25:22 +04:00
QStringList hashes ;
bool inDownloadList = true ;
switch ( tabs - > currentIndex ( ) ) {
case 0 :
hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
break ;
case 1 :
hashes = finishedTorrentTab - > getSelectedTorrents ( ) ;
inDownloadList = false ;
break ;
default :
return ;
}
int ret ;
if ( inDownloadList ) {
ret = QMessageBox : : question (
this ,
tr ( " Are you sure? -- qBittorrent " ) ,
tr ( " Are you sure you want to delete the selected item(s) from download list and from hard drive? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ;
} else {
ret = QMessageBox : : question (
this ,
tr ( " Are you sure? -- qBittorrent " ) ,
tr ( " Are you sure you want to delete the selected item(s) from finished list and from hard drive? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ;
}
if ( ret ) return ;
//User clicked YES
QString hash ;
foreach ( hash , hashes ) {
// Get the file name
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
QString fileName = h . name ( ) ;
// Remove the torrent
BTSession - > deleteTorrent ( hash , true ) ;
2006-10-29 13:17:53 +03:00
}
2006-09-30 20:02:39 +04:00
}
2008-05-16 11:10:50 +04:00
void GUI : : deleteTorrent ( QString hash ) {
// Delete item from list
downloadingTorrentTab - > deleteTorrent ( hash ) ;
finishedTorrentTab - > deleteTorrent ( hash ) ;
}
2006-09-30 20:02:39 +04:00
// delete selected items in the list
2007-08-20 10:29:18 +04:00
void GUI : : on_actionDelete_triggered ( ) {
2007-08-26 20:25:22 +04:00
QStringList hashes ;
bool inDownloadList = true ;
switch ( tabs - > currentIndex ( ) ) {
case 0 : // DL
hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
break ;
case 1 : // SEED
hashes = finishedTorrentTab - > getSelectedTorrents ( ) ;
inDownloadList = false ;
break ;
2007-08-28 21:33:00 +04:00
case 3 : //RSSImp
rssWidget - > on_delStream_button_clicked ( ) ;
return ;
2007-08-26 20:25:22 +04:00
default :
return ;
}
if ( ! hashes . size ( ) ) return ;
int ret ;
if ( inDownloadList ) {
ret = QMessageBox : : question (
this ,
tr ( " Are you sure? -- qBittorrent " ) ,
tr ( " Are you sure you want to delete the selected item(s) in download list? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ;
2007-04-04 16:41:47 +04:00
} else {
2007-08-26 20:25:22 +04:00
ret = QMessageBox : : question (
this ,
tr ( " Are you sure? -- qBittorrent " ) ,
tr ( " Are you sure you want to delete the selected item(s) in finished list? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ;
}
if ( ret ) return ;
//User clicked YES
QString hash ;
foreach ( hash , hashes ) {
// Get the file name
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
QString fileName = h . name ( ) ;
// Remove the torrent
BTSession - > deleteTorrent ( hash , false ) ;
2006-10-24 01:42:37 +04:00
}
2006-09-30 20:02:39 +04:00
}
// As program parameters, we can get paths or urls.
// This function parse the parameters and call
// the right addTorrent function, considering
// the parameter type.
2007-08-20 10:29:18 +04:00
void GUI : : processParams ( const QStringList & params ) {
2006-09-30 20:02:39 +04:00
QString param ;
2007-08-20 10:29:18 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2007-09-08 21:07:29 +04:00
bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2007-08-20 10:29:18 +04:00
foreach ( param , params ) {
2006-09-30 20:02:39 +04:00
param = param . trimmed ( ) ;
2007-08-20 10:29:18 +04:00
if ( param . startsWith ( QString : : fromUtf8 ( " http:// " ) , Qt : : CaseInsensitive ) | | param . startsWith ( QString : : fromUtf8 ( " ftp:// " ) , Qt : : CaseInsensitive ) | | param . startsWith ( QString : : fromUtf8 ( " https:// " ) , Qt : : CaseInsensitive ) ) {
2007-07-14 16:35:04 +04:00
BTSession - > downloadFromUrl ( param ) ;
2006-09-30 20:02:39 +04:00
} else {
2007-08-20 10:29:18 +04:00
if ( useTorrentAdditionDialog ) {
2008-09-07 15:31:29 +04:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this , BTSession ) ;
2006-10-29 12:32:28 +03:00
dialog - > showLoad ( param ) ;
2006-10-24 15:41:28 +04:00
} else {
2007-07-14 16:35:04 +04:00
BTSession - > addTorrent ( param ) ;
2006-10-24 15:41:28 +04:00
}
2006-09-30 20:02:39 +04:00
}
}
}
2007-09-04 08:18:51 +04:00
void GUI : : addTorrent ( QString path ) {
BTSession - > addTorrent ( path ) ;
}
2007-08-20 10:29:18 +04:00
void GUI : : processDownloadedFiles ( QString path , QString url ) {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2007-09-08 21:07:29 +04:00
bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2007-08-20 10:29:18 +04:00
if ( useTorrentAdditionDialog ) {
2008-09-07 15:31:29 +04:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this , BTSession ) ;
2008-12-27 23:35:25 +03:00
dialog - > showLoad ( path , url ) ;
2007-03-08 01:36:01 +03:00
} else {
2007-08-17 06:03:13 +04:00
BTSession - > addTorrent ( path , false , url ) ;
2006-09-30 20:02:39 +04:00
}
}
// Set BT session configuration
2007-08-20 10:29:18 +04:00
void GUI : : configureSession ( bool deleteOptions ) {
2006-09-30 20:02:39 +04:00
qDebug ( " Configuring session " ) ;
2007-09-09 13:35:30 +04:00
// General
2007-11-21 23:17:01 +03:00
bool new_displaySpeedInTitle = options - > speedInTitleBar ( ) ;
if ( ! new_displaySpeedInTitle & & new_displaySpeedInTitle ! = displaySpeedInTitle ) {
// Reset title
setWindowTitle ( tr ( " qBittorrent %1 " , " e.g: qBittorrent v0.x " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
}
displaySpeedInTitle = new_displaySpeedInTitle ;
2008-12-24 17:41:16 +03:00
if ( options - > isToolbarDisplayed ( ) ! = toolBar - > isVisible ( ) ) {
if ( options - > isToolbarDisplayed ( ) ) {
toolBar - > setVisible ( true ) ;
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
} else {
toolBar - > setVisible ( false ) ;
}
2008-08-08 17:17:26 +04:00
}
2007-09-09 19:46:23 +04:00
unsigned int new_refreshInterval = options - > getRefreshInterval ( ) ;
if ( refreshInterval ! = new_refreshInterval ) {
refreshInterval = new_refreshInterval ;
refresher - > start ( refreshInterval ) ;
}
2007-09-08 21:07:29 +04:00
// Downloads
2007-09-09 13:35:30 +04:00
// * Save path
2007-09-09 13:09:24 +04:00
BTSession - > setDefaultSavePath ( options - > getSavePath ( ) ) ;
2007-09-08 21:07:29 +04:00
BTSession - > preAllocateAllFiles ( options - > preAllocateAllFiles ( ) ) ;
BTSession - > startTorrentsInPause ( options - > addTorrentsInPause ( ) ) ;
2007-09-09 13:09:24 +04:00
// * Scan dir
if ( options - > getScanDir ( ) . isNull ( ) ) {
BTSession - > disableDirectoryScanning ( ) ;
} else {
2008-05-18 12:40:39 +04:00
//Interval first
2007-09-09 13:09:24 +04:00
BTSession - > enableDirectoryScanning ( options - > getScanDir ( ) ) ;
}
2007-09-08 21:07:29 +04:00
// Connection
2007-09-09 11:44:22 +04:00
// * Ports binding
unsigned short old_listenPort = BTSession - > getListenPort ( ) ;
2007-07-14 16:35:04 +04:00
BTSession - > setListeningPortsRange ( options - > getPorts ( ) ) ;
2007-09-09 11:44:22 +04:00
unsigned short new_listenPort = BTSession - > getListenPort ( ) ;
2007-08-20 10:29:18 +04:00
if ( new_listenPort ! = old_listenPort ) {
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " qBittorrent is bind to port: %1 " , " e.g: qBittorrent is bind to port: 1666 " ) . arg ( misc : : toQString ( new_listenPort ) ) ) ;
2007-03-08 01:36:01 +03:00
}
2007-09-09 11:44:22 +04:00
// * Global download limit
QPair < int , int > limits = options - > getGlobalBandwidthLimits ( ) ;
if ( limits . first < = 0 ) {
// Download limit disabled
BTSession - > setDownloadRateLimit ( - 1 ) ;
} else {
// Enabled
BTSession - > setDownloadRateLimit ( limits . first * 1024 ) ;
}
// * Global Upload limit
if ( limits . second < = 0 ) {
// Upload limit disabled
BTSession - > setUploadRateLimit ( - 1 ) ;
} else {
// Enabled
BTSession - > setUploadRateLimit ( limits . second * 1024 ) ;
}
// * UPnP
2007-09-08 21:07:29 +04:00
if ( options - > isUPnPEnabled ( ) ) {
BTSession - > enableUPnP ( true ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " UPnP support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-08 21:07:29 +04:00
} else {
BTSession - > enableUPnP ( false ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " UPnP support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-08 21:07:29 +04:00
}
2007-09-09 11:44:22 +04:00
// * NAT-PMP
2007-09-08 21:07:29 +04:00
if ( options - > isNATPMPEnabled ( ) ) {
BTSession - > enableNATPMP ( true ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " NAT-PMP support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-08 21:07:29 +04:00
} else {
BTSession - > enableNATPMP ( false ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " NAT-PMP support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-08 21:07:29 +04:00
}
2007-09-09 11:44:22 +04:00
// * Proxy settings
proxy_settings proxySettings ;
if ( options - > isProxyEnabled ( ) ) {
2007-11-16 22:59:36 +03:00
proxySettings . hostname = options - > getProxyIp ( ) . toStdString ( ) ;
proxySettings . port = options - > getProxyPort ( ) ;
if ( options - > isProxyAuthEnabled ( ) ) {
proxySettings . username = options - > getProxyUsername ( ) . toStdString ( ) ;
proxySettings . password = options - > getProxyPassword ( ) . toStdString ( ) ;
}
2007-09-09 11:44:22 +04:00
switch ( options - > getProxyType ( ) ) {
case HTTP :
proxySettings . type = proxy_settings : : http ;
break ;
case HTTP_PW :
proxySettings . type = proxy_settings : : http_pw ;
break ;
case SOCKS5 :
proxySettings . type = proxy_settings : : socks5 ;
break ;
default :
proxySettings . type = proxy_settings : : socks5_pw ;
break ;
}
2009-01-04 01:24:56 +03:00
BTSession - > setProxySettings ( proxySettings , options - > useProxyForTrackers ( ) , options - > useProxyForPeers ( ) , options - > useProxyForWebseeds ( ) , options - > useProxyForDHT ( ) ) ;
}
if ( options - > isHTTPProxyEnabled ( ) ) {
// HTTP Proxy
2008-09-27 13:12:41 +04:00
QString proxy_str ;
switch ( options - > getHTTPProxyType ( ) ) {
case HTTP_PW :
proxy_str = misc : : toQString ( " http:// " ) + options - > getProxyUsername ( ) + " : " + options - > getProxyPassword ( ) + " @ " + options - > getProxyIp ( ) + " : " + misc : : toQString ( proxySettings . port ) ;
break ;
default :
proxy_str = misc : : toQString ( " http:// " ) + options - > getProxyIp ( ) + " : " + misc : : toQString ( proxySettings . port ) ;
}
2009-01-04 01:26:45 +03:00
// We need this for urllib in search engine plugins
2007-11-27 22:37:45 +03:00
# ifdef Q_WS_WIN
2009-01-04 01:26:45 +03:00
char proxystr [ 512 ] ;
snprintf ( proxystr , 512 , " http_proxy=%s " , proxy_str . toUtf8 ( ) . data ( ) ) ;
putenv ( proxystr ) ;
2007-11-27 22:37:45 +03:00
# else
2009-01-04 01:26:45 +03:00
setenv ( " http_proxy " , proxy_str . toUtf8 ( ) . data ( ) , 1 ) ;
2007-11-27 22:37:45 +03:00
# endif
2007-11-16 22:59:36 +03:00
} else {
2007-11-27 22:37:45 +03:00
# ifdef Q_WS_WIN
putenv ( " http_proxy= " ) ;
# else
2007-11-16 22:59:36 +03:00
unsetenv ( " http_proxy " ) ;
2007-11-27 22:37:45 +03:00
# endif
2007-09-08 21:07:29 +04:00
}
2009-01-04 01:24:56 +03:00
2007-09-09 11:44:22 +04:00
// * Session settings
session_settings sessionSettings ;
2008-05-18 13:50:35 +04:00
if ( options - > shouldSpoofAzureus ( ) ) {
sessionSettings . user_agent = " Azureus 3.0.5.2 " ;
} else {
sessionSettings . user_agent = " qBittorrent " VERSION ;
}
2008-07-02 18:36:52 +04:00
sessionSettings . upnp_ignore_nonrouters = true ;
2008-07-11 00:19:28 +04:00
sessionSettings . use_dht_as_fallback = false ;
2008-11-02 13:47:59 +03:00
// Queueing System
if ( options - > isQueueingSystemEnabled ( ) ) {
if ( ! BTSession - > isQueueingEnabled ( ) ) {
downloadingTorrentTab - > hidePriorityColumn ( false ) ;
2008-12-29 23:01:03 +03:00
actionDecreasePriority - > setVisible ( true ) ;
actionIncreasePriority - > setVisible ( true ) ;
prioSeparator - > setVisible ( true ) ;
prioSeparator2 - > setVisible ( true ) ;
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
2008-11-02 13:47:59 +03:00
}
int max_torrents = options - > getMaxActiveTorrents ( ) ;
2008-12-27 20:44:33 +03:00
int max_uploads = options - > getMaxActiveUploads ( ) ;
2008-11-02 13:47:59 +03:00
int max_downloads = options - > getMaxActiveDownloads ( ) ;
sessionSettings . active_downloads = max_downloads ;
2008-12-27 20:44:33 +03:00
sessionSettings . active_seeds = max_uploads ;
2008-12-27 20:23:49 +03:00
sessionSettings . active_limit = max_torrents ;
2008-12-23 19:27:47 +03:00
sessionSettings . dont_count_slow_torrents = false ;
2008-11-02 13:47:59 +03:00
BTSession - > setQueueingEnabled ( true ) ;
} else {
if ( BTSession - > isQueueingEnabled ( ) ) {
sessionSettings . active_downloads = - 1 ;
sessionSettings . active_seeds = - 1 ;
2008-12-27 20:23:49 +03:00
sessionSettings . active_limit = - 1 ;
2008-11-02 13:47:59 +03:00
BTSession - > setQueueingEnabled ( false ) ;
downloadingTorrentTab - > hidePriorityColumn ( true ) ;
2008-12-30 02:00:13 +03:00
actionDecreasePriority - > setVisible ( false ) ;
2008-12-29 23:01:03 +03:00
actionIncreasePriority - > setVisible ( false ) ;
prioSeparator - > setVisible ( false ) ;
prioSeparator2 - > setVisible ( false ) ;
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
2008-11-02 13:47:59 +03:00
}
}
2007-09-09 11:44:22 +04:00
BTSession - > setSessionSettings ( sessionSettings ) ;
// Bittorrent
// * Max connections limit
BTSession - > setMaxConnections ( options - > getMaxConnecs ( ) ) ;
// * Max connections per torrent limit
BTSession - > setMaxConnectionsPerTorrent ( options - > getMaxConnecsPerTorrent ( ) ) ;
// * Max uploads per torrent limit
BTSession - > setMaxUploadsPerTorrent ( options - > getMaxUploadsPerTorrent ( ) ) ;
// * DHT
2007-09-08 21:07:29 +04:00
if ( options - > isDHTEnabled ( ) ) {
// Set DHT Port
BTSession - > setDHTPort ( new_listenPort ) ;
2007-10-28 00:53:09 +04:00
if ( BTSession - > enableDHT ( true ) ) {
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " DHT support [ON], port: %1 " ) . arg ( new_listenPort ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-10-28 00:53:09 +04:00
} else {
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " DHT support [OFF] " ) , QString : : fromUtf8 ( " red " ) ) ;
2007-10-28 00:53:09 +04:00
}
} else {
2007-09-08 21:07:29 +04:00
BTSession - > enableDHT ( false ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " DHT support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-08 21:07:29 +04:00
}
2007-09-09 11:44:22 +04:00
// * PeX
2008-11-02 22:22:10 +03:00
BTSession - > addConsoleMessage ( tr ( " PeX support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-09 11:44:22 +04:00
// * LSD
if ( options - > isLSDEnabled ( ) ) {
BTSession - > enableLSD ( true ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " Local Peer Discovery [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-09-09 11:44:22 +04:00
} else {
BTSession - > enableLSD ( false ) ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " Local Peer Discovery support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-03-08 01:36:01 +03:00
}
2007-09-09 11:44:22 +04:00
// * Encryption
2007-06-16 00:35:07 +04:00
int encryptionState = options - > getEncryptionSetting ( ) ;
2007-06-16 00:43:31 +04:00
// The most secure, rc4 only so that all streams and encrypted
2007-09-09 11:44:22 +04:00
pe_settings encryptionSettings ;
2007-06-16 00:43:31 +04:00
encryptionSettings . allowed_enc_level = pe_settings : : rc4 ;
2007-06-16 00:35:07 +04:00
encryptionSettings . prefer_rc4 = true ;
2007-08-20 10:29:18 +04:00
switch ( encryptionState ) {
2007-06-16 00:35:07 +04:00
case 0 : //Enabled
encryptionSettings . out_enc_policy = pe_settings : : enabled ;
encryptionSettings . in_enc_policy = pe_settings : : enabled ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " Encryption support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-06-16 00:35:07 +04:00
break ;
case 1 : // Forced
encryptionSettings . out_enc_policy = pe_settings : : forced ;
encryptionSettings . in_enc_policy = pe_settings : : forced ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " Encryption support [FORCED] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-06-16 00:35:07 +04:00
break ;
default : // Disabled
encryptionSettings . out_enc_policy = pe_settings : : disabled ;
encryptionSettings . in_enc_policy = pe_settings : : disabled ;
2008-09-07 15:31:29 +04:00
BTSession - > addConsoleMessage ( tr ( " Encryption support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
2007-06-16 00:35:07 +04:00
}
2007-07-14 16:35:04 +04:00
BTSession - > applyEncryptionSettings ( encryptionSettings ) ;
2007-09-09 13:09:24 +04:00
// * Desired ratio
2007-09-09 11:44:22 +04:00
BTSession - > setGlobalRatio ( options - > getDesiredRatio ( ) ) ;
2007-09-09 13:09:24 +04:00
// * Maximum ratio
BTSession - > setDeleteRatio ( options - > getDeleteRatio ( ) ) ;
// Ip Filter
2007-08-20 10:29:18 +04:00
if ( options - > isFilteringEnabled ( ) ) {
2007-07-14 16:35:04 +04:00
BTSession - > enableIPFilter ( options - > getFilter ( ) ) ;
2007-03-08 01:36:01 +03:00
} else {
2007-07-14 16:35:04 +04:00
BTSession - > disableIPFilter ( ) ;
2007-03-08 01:36:01 +03:00
}
2008-07-11 21:43:57 +04:00
// RSS
if ( options - > isRSSEnabled ( ) ) {
displayRSSTab ( true ) ;
} else {
displayRSSTab ( false ) ;
}
2007-09-09 13:09:24 +04:00
// Clean up
2008-12-24 17:53:40 +03:00
if ( deleteOptions & & options ) {
qDebug ( " Deleting options " ) ;
//delete options;
options - > deleteLater ( ) ;
2007-03-10 21:14:53 +03:00
}
2006-09-30 20:02:39 +04:00
qDebug ( " Session configured " ) ;
}
2007-08-26 20:25:22 +04:00
void GUI : : updateUnfinishedTorrentNumber ( unsigned int nb ) {
2008-05-18 13:26:02 +04:00
unsigned int paused = BTSession - > getUnfinishedPausedTorrentsNb ( ) ;
tabs - > setTabText ( 0 , tr ( " Downloads " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
2007-08-26 20:25:22 +04:00
}
void GUI : : updateFinishedTorrentNumber ( unsigned int nb ) {
2008-05-18 13:26:02 +04:00
unsigned int paused = BTSession - > getFinishedPausedTorrentsNb ( ) ;
tabs - > setTabText ( 1 , tr ( " Finished " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
2007-08-26 20:25:22 +04:00
}
2007-11-07 00:11:09 +03:00
// Allow to change action on double-click
void GUI : : torrentDoubleClicked ( QString hash , bool finished ) {
int action ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
if ( finished ) {
2007-11-08 21:31:41 +03:00
action = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/DblClOnTorFN " ) , 0 ) . toInt ( ) ;
2007-11-07 00:11:09 +03:00
} else {
2007-11-08 21:31:41 +03:00
action = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/DblClOnTorDl " ) , 0 ) . toInt ( ) ;
2007-11-07 00:11:09 +03:00
}
switch ( action ) {
2007-11-08 21:31:41 +03:00
case TOGGLE_PAUSE :
2007-11-07 00:11:09 +03:00
this - > togglePausedState ( hash ) ;
break ;
2007-11-16 21:26:00 +03:00
case OPEN_DEST : {
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
QString savePath = h . save_path ( ) ;
QDesktopServices : : openUrl ( QUrl ( savePath ) ) ;
2007-11-08 21:31:41 +03:00
break ;
}
2007-11-07 00:11:09 +03:00
case SHOW_PROPERTIES :
if ( finished ) {
finishedTorrentTab - > showPropertiesFromHash ( hash ) ;
} else {
downloadingTorrentTab - > showPropertiesFromHash ( hash ) ;
}
break ;
}
}
2007-08-01 12:43:00 +04:00
// Toggle paused state of selected torrent
2007-08-26 20:25:22 +04:00
void GUI : : togglePausedState ( QString hash ) {
2007-08-01 12:43:00 +04:00
if ( tabs - > currentIndex ( ) > 1 ) return ;
2007-08-26 20:25:22 +04:00
bool inDownloadList = true ;
2007-08-01 12:43:00 +04:00
if ( tabs - > currentIndex ( ) = = 1 )
inDownloadList = false ;
2007-08-26 20:25:22 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2008-12-27 12:40:21 +03:00
if ( h . is_paused ( ) ) {
h . resume ( ) ;
2008-12-29 21:36:54 +03:00
resumedTorrent ( h ) ;
2007-08-20 10:29:18 +04:00
if ( inDownloadList ) {
2008-05-18 13:26:02 +04:00
updateUnfinishedTorrentNumber ( downloadingTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-08-01 12:43:00 +04:00
} else {
2008-05-18 13:26:02 +04:00
updateFinishedTorrentNumber ( finishedTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-08-01 12:43:00 +04:00
}
} else {
2008-12-27 12:40:21 +03:00
h . pause ( ) ;
2008-12-29 21:36:54 +03:00
pausedTorrent ( h ) ;
2007-08-20 10:29:18 +04:00
if ( inDownloadList ) {
2008-05-18 13:26:02 +04:00
updateUnfinishedTorrentNumber ( downloadingTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-08-01 12:43:00 +04:00
} else {
2008-05-18 13:26:02 +04:00
updateFinishedTorrentNumber ( finishedTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-08-01 12:43:00 +04:00
}
}
}
2007-03-08 19:40:02 +03:00
// Pause All Downloads in DL list
2007-08-20 10:29:18 +04:00
void GUI : : on_actionPause_All_triggered ( ) {
2008-12-27 00:18:33 +03:00
bool change = false ;
std : : vector < torrent_handle > torrents = BTSession - > getTorrents ( ) ;
std : : vector < torrent_handle > : : iterator torrentIT ;
for ( torrentIT = torrents . begin ( ) ; torrentIT ! = torrents . end ( ) ; torrentIT + + ) {
QTorrentHandle h = QTorrentHandle ( * torrentIT ) ;
if ( ! h . is_valid ( ) | | h . is_paused ( ) ) continue ;
change = true ;
2008-12-27 01:02:01 +03:00
h . pause ( ) ;
2008-12-29 21:36:54 +03:00
pausedTorrent ( h ) ;
2007-09-02 18:57:07 +04:00
}
2008-12-27 00:18:33 +03:00
if ( change ) {
updateUnfinishedTorrentNumber ( downloadingTorrentTab - > getNbTorrentsInList ( ) ) ;
updateFinishedTorrentNumber ( finishedTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-06-30 22:56:49 +04:00
}
2007-03-08 19:40:02 +03:00
}
2008-07-15 00:01:21 +04:00
void GUI : : on_actionIncreasePriority_triggered ( ) {
2008-12-29 23:01:03 +03:00
if ( tabs - > currentIndex ( ) ! = 0 )
return ;
2008-12-27 00:18:33 +03:00
QStringList hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
2008-07-15 00:01:21 +04:00
foreach ( QString hash , hashes ) {
2008-07-15 02:05:13 +04:00
BTSession - > increaseDlTorrentPriority ( hash ) ;
2008-07-15 00:01:21 +04:00
}
2008-12-27 00:18:33 +03:00
updateLists ( ) ;
2008-07-15 00:01:21 +04:00
}
void GUI : : on_actionDecreasePriority_triggered ( ) {
2008-12-27 00:18:33 +03:00
Q_ASSERT ( tabs - > currentIndex ( ) = = 0 ) ;
QStringList hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
2008-07-15 00:01:21 +04:00
foreach ( QString hash , hashes ) {
2008-07-15 02:05:13 +04:00
BTSession - > decreaseDlTorrentPriority ( hash ) ;
2008-07-15 00:01:21 +04:00
}
2008-12-27 00:18:33 +03:00
updateLists ( ) ;
2008-07-15 00:01:21 +04:00
}
2006-09-30 20:02:39 +04:00
// pause selected items in the list
2007-08-20 10:29:18 +04:00
void GUI : : on_actionPause_triggered ( ) {
2007-08-01 12:43:00 +04:00
bool inDownloadList = true ;
if ( tabs - > currentIndex ( ) > 1 ) return ;
if ( tabs - > currentIndex ( ) = = 1 )
inDownloadList = false ;
2007-08-26 20:25:22 +04:00
QStringList hashes ;
if ( inDownloadList ) {
hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
} else {
hashes = finishedTorrentTab - > getSelectedTorrents ( ) ;
}
QString hash ;
foreach ( hash , hashes ) {
2008-12-27 12:40:21 +03:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
if ( ! h . is_paused ( ) ) {
h . pause ( ) ;
2008-12-29 21:36:54 +03:00
pausedTorrent ( h ) ;
2007-08-26 20:25:22 +04:00
if ( inDownloadList ) {
2008-05-18 13:26:02 +04:00
updateUnfinishedTorrentNumber ( downloadingTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-08-26 20:25:22 +04:00
} else {
2008-05-18 13:26:02 +04:00
updateFinishedTorrentNumber ( finishedTorrentTab - > getNbTorrentsInList ( ) ) ;
2006-09-30 20:02:39 +04:00
}
}
}
}
2007-03-08 19:40:02 +03:00
// Resume All Downloads in DL list
2007-08-20 10:29:18 +04:00
void GUI : : on_actionStart_All_triggered ( ) {
2007-07-29 18:14:57 +04:00
bool change = false ;
2008-12-27 00:18:33 +03:00
std : : vector < torrent_handle > torrents = BTSession - > getTorrents ( ) ;
std : : vector < torrent_handle > : : iterator torrentIT ;
for ( torrentIT = torrents . begin ( ) ; torrentIT ! = torrents . end ( ) ; torrentIT + + ) {
QTorrentHandle h = QTorrentHandle ( * torrentIT ) ;
if ( ! h . is_valid ( ) | | ! h . is_paused ( ) ) continue ;
change = true ;
2008-12-27 01:02:01 +03:00
h . resume ( ) ;
2008-12-29 21:36:54 +03:00
resumedTorrent ( h ) ;
2007-06-30 22:56:49 +04:00
}
2008-05-18 13:26:02 +04:00
if ( change ) {
updateUnfinishedTorrentNumber ( downloadingTorrentTab - > getNbTorrentsInList ( ) ) ;
updateFinishedTorrentNumber ( finishedTorrentTab - > getNbTorrentsInList ( ) ) ;
}
2007-03-08 19:40:02 +03:00
}
2006-09-30 20:02:39 +04:00
// start selected items in the list
2007-08-20 10:29:18 +04:00
void GUI : : on_actionStart_triggered ( ) {
2007-08-01 12:43:00 +04:00
bool inDownloadList = true ;
if ( tabs - > currentIndex ( ) > 1 ) return ;
if ( tabs - > currentIndex ( ) = = 1 )
inDownloadList = false ;
2007-08-26 20:25:22 +04:00
QStringList hashes ;
if ( inDownloadList ) {
hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
} else {
hashes = finishedTorrentTab - > getSelectedTorrents ( ) ;
}
QString hash ;
foreach ( hash , hashes ) {
2008-12-27 12:40:21 +03:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2008-12-27 13:07:03 +03:00
if ( h . is_paused ( ) ) {
2008-12-27 12:40:21 +03:00
h . resume ( ) ;
2008-12-29 21:36:54 +03:00
resumedTorrent ( h ) ;
2007-08-26 20:25:22 +04:00
if ( inDownloadList ) {
2008-05-18 13:26:02 +04:00
updateUnfinishedTorrentNumber ( downloadingTorrentTab - > getNbTorrentsInList ( ) ) ;
2007-08-26 20:25:22 +04:00
} else {
2008-05-18 13:26:02 +04:00
updateFinishedTorrentNumber ( finishedTorrentTab - > getNbTorrentsInList ( ) ) ;
2006-09-30 20:02:39 +04:00
}
}
}
}
2007-08-20 10:29:18 +04:00
void GUI : : addUnauthenticatedTracker ( QPair < QTorrentHandle , QString > tracker ) {
2006-09-30 20:02:39 +04:00
// Trackers whose authentication was cancelled
2007-08-20 10:29:18 +04:00
if ( unauthenticated_trackers . indexOf ( tracker ) < 0 ) {
2006-09-30 20:02:39 +04:00
unauthenticated_trackers < < tracker ;
}
}
// display properties of selected items
2007-08-20 10:29:18 +04:00
void GUI : : on_actionTorrent_Properties_triggered ( ) {
2007-04-04 16:52:50 +04:00
if ( tabs - > currentIndex ( ) > 1 ) return ;
2007-08-26 20:25:22 +04:00
switch ( tabs - > currentIndex ( ) ) {
case 1 : // DL List
finishedTorrentTab - > propertiesSelection ( ) ;
break ;
default :
downloadingTorrentTab - > propertiesSelection ( ) ;
2007-08-17 06:03:13 +04:00
}
}
2008-12-27 00:41:09 +03:00
void GUI : : updateLists ( bool force ) {
if ( isVisible ( ) | | force ) {
// update global informations
dlSpeedLbl - > setText ( tr ( " DL: %1 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadDownloadRate ( ) / 1024. , ' f ' , 1 ) ) ) ) ;
upSpeedLbl - > setText ( tr ( " UP: %1 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadUploadRate ( ) / 1024. , ' f ' , 1 ) ) ) ) ;
std : : vector < torrent_handle > torrents = BTSession - > getTorrents ( ) ;
std : : vector < torrent_handle > : : iterator torrentIT ;
for ( torrentIT = torrents . begin ( ) ; torrentIT ! = torrents . end ( ) ; torrentIT + + ) {
QTorrentHandle h = QTorrentHandle ( * torrentIT ) ;
if ( ! h . is_valid ( ) ) continue ;
if ( h . is_seed ( ) ) {
// Update in finished list
finishedTorrentTab - > updateTorrent ( h ) ;
} else {
// Update in download list
2008-12-27 01:30:23 +03:00
if ( downloadingTorrentTab - > updateTorrent ( h ) ) {
// Torrent was added, we may need to remove it from finished tab
finishedTorrentTab - > deleteTorrent ( h . hash ( ) ) ;
QFile : : remove ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) ;
}
2008-12-27 00:18:33 +03:00
}
}
}
if ( displaySpeedInTitle ) {
QString dl_rate = QByteArray : : number ( BTSession - > getSessionStatus ( ) . payload_download_rate / 1024 , ' f ' , 1 ) ;
QString up_rate = QByteArray : : number ( BTSession - > getSessionStatus ( ) . payload_upload_rate / 1024 , ' f ' , 1 ) ;
setWindowTitle ( tr ( " qBittorrent %1 (DL: %2KiB/s, UP: %3KiB/s) " , " %1 is qBittorrent version " ) . arg ( QString : : fromUtf8 ( VERSION ) ) . arg ( dl_rate ) . arg ( up_rate ) ) ;
}
2007-03-08 01:36:01 +03:00
}
// Called when a tracker requires authentication
2007-08-20 10:29:18 +04:00
void GUI : : trackerAuthenticationRequired ( QTorrentHandle & h ) {
if ( unauthenticated_trackers . indexOf ( QPair < QTorrentHandle , QString > ( h , h . current_tracker ( ) ) ) < 0 ) {
2007-03-08 01:36:01 +03:00
// Tracker login
new trackerLogin ( this , h ) ;
}
}
2006-09-30 20:02:39 +04:00
// Check connection status and display right icon
2007-08-20 10:29:18 +04:00
void GUI : : checkConnectionStatus ( ) {
2007-03-29 01:59:21 +04:00
// qDebug("Checking connection status");
2007-08-26 20:25:22 +04:00
// Update Ratio
2008-06-09 23:59:51 +04:00
updateRatio ( ) ;
2007-08-26 20:25:22 +04:00
// update global informations
if ( systrayIntegration ) {
2007-09-11 22:49:24 +04:00
QString html = " <div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'> " ;
2007-09-11 00:25:31 +04:00
html + = tr ( " qBittorrent " ) ;
html + = " </div> " ;
html + = " <div style='vertical-align: baseline; height: 18px;'> " ;
2007-09-11 15:55:58 +04:00
html + = " <img src=':/Icons/skin/downloading.png'/> " + tr ( " DL speed: %1 KiB/s " , " e.g: Download speed: 10 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadDownloadRate ( ) / 1024. , ' f ' , 1 ) ) ) ;
2007-09-11 00:25:31 +04:00
html + = " </div> " ;
html + = " <div style='vertical-align: baseline; height: 18px;'> " ;
2007-09-11 15:55:58 +04:00
html + = " <img src=':/Icons/skin/seeding.png'/> " + tr ( " UP speed: %1 KiB/s " , " e.g: Upload speed: 10 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadUploadRate ( ) / 1024. , ' f ' , 1 ) ) ) ;
2007-09-11 00:25:31 +04:00
html + = " </div> " ;
myTrayIcon - > setToolTip ( html ) ; // tray icon
2006-09-30 20:02:39 +04:00
}
2007-08-26 20:25:22 +04:00
session_status sessionStatus = BTSession - > getSessionStatus ( ) ;
2007-08-20 10:29:18 +04:00
if ( sessionStatus . has_incoming_connections ) {
2006-09-30 20:02:39 +04:00
// Connection OK
2006-10-23 00:13:35 +04:00
connecStatusLblIcon - > setPixmap ( QPixmap ( QString : : fromUtf8 ( " :/Icons/skin/connected.png " ) ) ) ;
2007-08-20 10:29:18 +04:00
connecStatusLblIcon - > setToolTip ( QString : : fromUtf8 ( " <b> " ) + tr ( " Connection Status: " ) + QString : : fromUtf8 ( " </b><br> " ) + tr ( " Online " ) ) ;
2006-09-30 20:02:39 +04:00
} else {
2008-08-08 17:17:26 +04:00
connecStatusLblIcon - > setPixmap ( QPixmap ( 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> " ) ) ;
2006-09-30 20:02:39 +04:00
}
}
/*****************************************************
* *
* Utils *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-08-20 10:29:18 +04:00
void GUI : : downloadFromURLList ( const QStringList & urls ) {
2007-07-14 16:35:04 +04:00
BTSession - > downloadFromURLList ( urls ) ;
2007-03-08 20:00:12 +03:00
}
2006-09-30 20:02:39 +04:00
/*****************************************************
* *
* Options *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-01-04 23:09:37 +03:00
void GUI : : createSystrayDelayed ( ) {
static int timeout = 10 ;
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
// Ok, systray integration is now supported
// Create systray icon
createTrayIcon ( ) ;
systrayIntegration = true ;
delete systrayCreator ;
} else {
if ( timeout ) {
// Retry a bit later
systrayCreator - > start ( 1000 ) ;
- - timeout ;
} else {
// Timed out, apparently system really does not
// support systray icon
delete systrayCreator ;
}
}
}
2007-08-20 10:29:18 +04:00
void GUI : : createTrayIcon ( ) {
2007-03-29 23:54:45 +04:00
// Tray icon
2008-01-04 22:48:26 +03:00
# ifdef Q_WS_WIN
myTrayIcon = new QSystemTrayIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/qbittorrent16.png " ) ) , this ) ;
# endif
# ifndef Q_WS_WIN
2007-08-20 10:29:18 +04:00
myTrayIcon = new QSystemTrayIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/qbittorrent22.png " ) ) , this ) ;
2008-01-04 22:48:26 +03:00
# endif
2007-03-29 23:54:45 +04:00
// Tray icon Menu
myTrayIconMenu = new QMenu ( this ) ;
myTrayIconMenu - > addAction ( actionOpen ) ;
myTrayIconMenu - > addAction ( actionDownload_from_URL ) ;
myTrayIconMenu - > addSeparator ( ) ;
2007-07-14 14:50:38 +04:00
myTrayIconMenu - > addAction ( actionSet_global_download_limit ) ;
myTrayIconMenu - > addAction ( actionSet_global_upload_limit ) ;
myTrayIconMenu - > addSeparator ( ) ;
2007-03-29 23:54:45 +04:00
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 ( ) ;
}
2006-09-30 20:02:39 +04:00
// Display Program Options
2007-08-20 10:29:18 +04:00
void GUI : : on_actionOptions_triggered ( ) {
2007-03-10 21:14:53 +03:00
options = new options_imp ( this ) ;
2008-09-21 12:17:29 +04:00
connect ( options , SIGNAL ( status_changed ( bool ) ) , this , SLOT ( OptionsSaved ( bool ) ) ) ;
2006-10-12 20:02:56 +04:00
options - > show ( ) ;
2006-09-30 20:02:39 +04:00
}
// Is executed each time options are saved
2008-09-07 15:31:29 +04:00
void GUI : : OptionsSaved ( bool deleteOptions ) {
BTSession - > addConsoleMessage ( tr ( " Options were saved successfully. " ) ) ;
2007-09-08 21:07:29 +04:00
bool newSystrayIntegration = options - > systrayIntegration ( ) ;
2008-12-24 17:41:16 +03:00
if ( newSystrayIntegration ! = systrayIntegration ) {
if ( newSystrayIntegration ) {
// create the trayicon
createTrayIcon ( ) ;
} else {
// Destroy trayicon
delete myTrayIcon ;
delete myTrayIconMenu ;
}
systrayIntegration = newSystrayIntegration ;
2007-03-29 23:54:45 +04:00
}
2008-05-16 11:10:50 +04:00
// Update Web UI
2008-12-24 17:41:16 +03:00
if ( options - > isWebUiEnabled ( ) ) {
2008-05-16 11:10:50 +04:00
quint16 port = options - > webUiPort ( ) ;
QString username = options - > webUiUsername ( ) ;
QString password = options - > webUiPassword ( ) ;
initWebUi ( username , password , port ) ;
2008-12-24 17:41:16 +03:00
} else if ( httpServer ) {
2008-05-16 11:10:50 +04:00
delete httpServer ;
}
2006-09-30 20:02:39 +04:00
// Update session
2007-03-10 21:14:53 +03:00
configureSession ( deleteOptions ) ;
2006-09-30 20:02:39 +04:00
}
2008-12-24 17:41:16 +03:00
bool GUI : : initWebUi ( QString username , QString password , int port ) {
2008-05-16 11:10:50 +04:00
if ( httpServer )
httpServer - > close ( ) ;
else
2008-12-23 19:50:46 +03:00
httpServer = new HttpServer ( BTSession , 3000 , this ) ;
2008-05-16 11:10:50 +04:00
httpServer - > setAuthorization ( username , password ) ;
bool success = httpServer - > listen ( QHostAddress : : Any , port ) ;
if ( success )
2008-07-08 14:56:35 +04:00
qDebug ( " Web UI listening on port %d " , port ) ;
2008-05-16 11:10:50 +04:00
else
2008-07-08 14:56:35 +04:00
QMessageBox : : critical ( this , " Web User Interface Error " , " Unable to initialize HTTP Server on port " + misc : : toQString ( port ) ) ;
2008-05-16 11:10:50 +04:00
return success ;
}
2006-09-30 20:02:39 +04:00
/*****************************************************
* *
* HTTP Downloader *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Display an input dialog to prompt user for
// an url
2007-08-20 10:29:18 +04:00
void GUI : : on_actionDownload_from_URL_triggered ( ) {
2007-08-26 20:25:22 +04:00
downloadFromURL * downloadFromURLDialog = new downloadFromURL ( this ) ;
2007-07-14 16:35:04 +04:00
connect ( downloadFromURLDialog , SIGNAL ( urlsReadyToBeDownloaded ( const QStringList & ) ) , BTSession , SLOT ( downloadFromURLList ( const QStringList & ) ) ) ;
2006-09-30 20:02:39 +04:00
}