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 .
*
2009-04-05 21:00:55 +04:00
* In addition , as a special exception , the copyright holders give permission to
* link this program with the OpenSSL project ' s " OpenSSL " library ( or with
* modified versions of it that use the same license as the " OpenSSL " library ) ,
* and distribute the linked executables . You must obey the GNU General Public
* License in all respects for all of the code used other than " OpenSSL " . If you
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
*
2007-07-14 18:31:59 +04:00
* Contact : chris @ qbittorrent . org
2006-09-30 20:02:39 +04:00
*/
2009-11-25 23:32:18 +03:00
# ifdef WITH_LIBNOTIFY
# include <glib.h>
# include <unistd.h>
# include <libnotify/notify.h>
# endif
2006-09-30 20:02:39 +04:00
# include <QFileDialog>
2010-08-23 23:42:15 +04:00
# include <QFileSystemWatcher>
2006-09-30 20:02:39 +04:00
# include <QMessageBox>
# include <QTimer>
2006-12-27 06:19:38 +03:00
# include <QDesktopServices>
2008-07-11 00:19:28 +04:00
# include <QStatusBar>
2009-08-17 14:22:41 +04:00
# include <QClipboard>
2007-03-27 22:49:29 +04:00
# include <QCloseEvent>
2007-07-19 16:58:45 +04:00
# include <QShortcut>
2010-10-08 21:47:34 +04:00
# include <QScrollBar>
2006-12-28 02:56:30 +03:00
2010-11-14 00:15:52 +03:00
# include "mainwindow.h"
2009-11-20 10:48:44 +03:00
# include "transferlistwidget.h"
2006-09-30 20:02:39 +04:00
# include "misc.h"
2010-10-23 00:13:22 +04:00
# include "torrentcreatordlg.h"
2009-11-20 10:48:44 +03:00
# include "downloadfromurldlg.h"
# include "torrentadditiondlg.h"
# include "searchengine.h"
2007-03-29 19:43:08 +04:00
# include "rss_imp.h"
2010-10-09 18:06:35 +04:00
# include "qbtsession.h"
2007-07-23 16:46:36 +04:00
# include "about_imp.h"
2009-11-20 10:48:44 +03:00
# include "trackerlogin.h"
2007-07-23 16:46:36 +04:00
# include "options_imp.h"
2009-11-17 16:11:32 +03:00
# include "speedlimitdlg.h"
2009-11-14 22:08:28 +03:00
# include "preferences.h"
2008-09-07 16:09:41 +04:00
# include "console_imp.h"
2010-01-13 02:16:18 +03:00
# include "trackerlist.h"
# include "peerlistwidget.h"
2009-11-20 10:48:44 +03:00
# include "torrentpersistentdata.h"
# include "transferlistfilterswidget.h"
2009-11-08 17:20:58 +03:00
# include "propertieswidget.h"
2009-11-18 16:18:55 +03:00
# include "statusbar.h"
2010-06-22 18:20:21 +04:00
# include "hidabletabwidget.h"
2010-07-16 19:03:18 +04:00
# include "qinisettings.h"
2010-10-23 20:21:56 +04:00
# include "torrentimportdlg.h"
2010-10-31 15:03:24 +03:00
# include "rsssettings.h"
2010-11-14 18:28:22 +03:00
# include "torrentmodel.h"
2010-06-08 19:17:15 +04:00
# ifdef Q_WS_MAC
# include "qmacapplication.h"
2010-06-09 19:43:29 +04:00
void qt_mac_set_dock_menu ( QMenu * menu ) ;
2010-06-08 19:17:15 +04:00
# endif
2010-08-20 16:27:20 +04:00
# include "lineedit.h"
2010-10-02 00:03:27 +04:00
# include "sessionapplication.h"
2010-10-24 01:46:05 +04:00
# if defined(Q_WS_WIN) || defined(Q_WS_MAC)
# include "programupdater.h"
# endif
2007-03-04 20:13:29 +03:00
2007-08-20 10:29:18 +04:00
using namespace libtorrent ;
2009-11-26 01:36:42 +03:00
# define TIME_TRAY_BALLOON 5000
2006-09-30 20:02:39 +04:00
/*****************************************************
* *
* GUI *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Constructor
2010-11-14 00:15:52 +03:00
MainWindow : : MainWindow ( QWidget * parent , QStringList torrentCmdLine ) : QMainWindow ( parent ) , force_exit ( false ) {
2006-09-30 20:02:39 +04:00
setupUi ( this ) ;
2010-11-16 23:34:31 +03:00
Preferences pref ;
ui_locked = pref . isUILocked ( ) ;
2010-06-21 22:32:01 +04:00
setWindowTitle ( tr ( " qBittorrent %1 " , " e.g: qBittorrent v0.x " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
2010-11-16 23:34:31 +03:00
displaySpeedInTitle = pref . speedInTitleBar ( ) ;
2010-10-02 00:03:27 +04:00
// Clean exit on log out
connect ( static_cast < SessionApplication * > ( qApp ) , SIGNAL ( sessionIsShuttingDown ( ) ) , this , SLOT ( deleteBTSession ( ) ) ) ;
2006-09-30 20:02:39 +04:00
// Setting icons
2009-03-08 13:28:58 +03:00
this - > setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/qbittorrent32.png " ) ) ) ;
2006-09-30 20:02:39 +04:00
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 " ) ) ) ;
2009-07-15 15:13:52 +04:00
actionWebsite - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/qbittorrent32.png " ) ) ) ;
2009-03-08 13:28:58 +03:00
actionBugReport - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/oxygen/bug.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 " ) ) ) ;
2009-11-24 21:15:08 +03:00
actionSet_download_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/download.png " ) ) ) ;
2007-07-14 14:50:38 +04:00
actionSet_global_upload_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/seeding.png " ) ) ) ;
2009-11-25 20:54:12 +03:00
actionSet_global_download_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/download.png " ) ) ) ;
2007-06-19 19:11:02 +04:00
actionDocumentation - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/qb_question.png " ) ) ) ;
2010-08-19 20:30:13 +04:00
actionLock_qBittorrent - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/oxygen/encrypted32.png " ) ) ) ;
2010-09-28 00:42:00 +04:00
lockMenu = new QMenu ( ) ;
2010-08-19 20:30:13 +04:00
QAction * defineUiLockPasswdAct = lockMenu - > addAction ( tr ( " Set the password... " ) ) ;
connect ( defineUiLockPasswdAct , SIGNAL ( triggered ( ) ) , this , SLOT ( defineUILockPassword ( ) ) ) ;
actionLock_qBittorrent - > setMenu ( lockMenu ) ;
2008-12-29 23:01:03 +03:00
prioSeparator = toolBar - > insertSeparator ( actionDecreasePriority ) ;
prioSeparator2 = menu_Edit - > insertSeparator ( actionDecreasePriority ) ;
prioSeparator - > setVisible ( false ) ;
prioSeparator2 - > setVisible ( false ) ;
2006-09-30 20:02:39 +04:00
actionCreate_torrent - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/new.png " ) ) ) ;
// Fix Tool bar layout
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
2009-11-14 22:08:28 +03:00
// Creating Bittorrent session
2010-11-13 22:36:46 +03:00
BTSession = QBtSession : : instance ( ) ;
2009-04-18 00:04:09 +04:00
connect ( BTSession , SIGNAL ( fullDiskError ( QTorrentHandle & , QString ) ) , this , SLOT ( fullDiskError ( QTorrentHandle & , QString ) ) ) ;
2007-08-26 20:25:22 +04:00
connect ( BTSession , SIGNAL ( finishedTorrent ( QTorrentHandle & ) ) , this , SLOT ( finishedTorrent ( 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 ) ) ) ;
2010-01-24 14:57:15 +03:00
connect ( BTSession , SIGNAL ( alternativeSpeedsModeChanged ( bool ) ) , this , SLOT ( updateAltSpeedsBtn ( bool ) ) ) ;
2010-03-20 14:30:11 +03:00
connect ( BTSession , SIGNAL ( recursiveTorrentDownloadPossible ( QTorrentHandle & ) ) , this , SLOT ( askRecursiveTorrentDownloadConfirmation ( QTorrentHandle & ) ) ) ;
2010-06-08 19:17:15 +04:00
# ifdef Q_WS_MAC
2010-06-09 13:48:14 +04:00
connect ( static_cast < QMacApplication * > ( qApp ) , SIGNAL ( newFileOpenMacEvent ( QString ) ) , this , SLOT ( processParams ( QString ) ) ) ;
2010-06-08 19:17:15 +04:00
# endif
2009-11-07 22:55:33 +03:00
2007-08-26 20:25:22 +04:00
qDebug ( " create tabWidget " ) ;
2010-06-22 18:18:43 +04:00
tabs = new HidableTabWidget ( ) ;
2009-11-21 17:16:54 +03:00
connect ( tabs , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( tab_changed ( int ) ) ) ;
2009-11-08 15:05:35 +03:00
vSplitter = new QSplitter ( Qt : : Horizontal ) ;
2009-11-25 21:13:20 +03:00
//vSplitter->setChildrenCollapsible(false);
2009-11-11 19:22:57 +03:00
hSplitter = new QSplitter ( Qt : : Vertical ) ;
2009-11-11 19:30:05 +03:00
hSplitter - > setChildrenCollapsible ( false ) ;
2009-11-08 15:05:35 +03:00
2009-11-07 22:55:33 +03:00
// Transfer List tab
2009-11-21 17:16:54 +03:00
transferList = new TransferListWidget ( hSplitter , this , BTSession ) ;
2010-11-14 00:15:52 +03:00
properties = new PropertiesWidget ( hSplitter , this , transferList ) ;
2009-11-08 15:35:12 +03:00
transferListFilters = new TransferListFiltersWidget ( vSplitter , transferList ) ;
2009-11-08 17:20:58 +03:00
hSplitter - > addWidget ( transferList ) ;
hSplitter - > addWidget ( properties ) ;
2009-11-08 15:35:12 +03:00
vSplitter - > addWidget ( transferListFilters ) ;
2009-11-11 19:22:57 +03:00
vSplitter - > addWidget ( hSplitter ) ;
2009-11-25 21:13:20 +03:00
vSplitter - > setCollapsible ( 0 , true ) ;
vSplitter - > setCollapsible ( 1 , false ) ;
2009-11-08 15:05:35 +03:00
tabs - > addTab ( vSplitter , QIcon ( QString : : fromUtf8 ( " :/Icons/oxygen/folder-remote.png " ) ) , tr ( " Transfers " ) ) ;
2010-11-14 18:28:22 +03:00
connect ( transferList - > getSourceModel ( ) , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( updateNbTorrents ( ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( rowsRemoved ( QModelIndex , int , int ) ) , this , SLOT ( updateNbTorrents ( ) ) ) ;
2009-03-28 01:25:34 +03:00
vboxLayout - > addWidget ( tabs ) ;
2009-11-07 22:55:33 +03:00
2010-08-20 16:27:20 +04:00
// Name filter
search_filter = new LineEdit ( ) ;
2010-08-23 20:12:17 +04:00
QAction * separatorBFSearch = toolBar - > insertSeparator ( actionLock_qBittorrent ) ;
toolBar - > insertWidget ( separatorBFSearch , search_filter ) ;
2010-08-20 16:27:20 +04:00
search_filter - > setFixedWidth ( 200 ) ;
connect ( search_filter , SIGNAL ( textChanged ( QString ) ) , transferList , SLOT ( applyNameFilter ( QString ) ) ) ;
2009-11-07 22:55:33 +03:00
// Transfer list slots
connect ( actionStart , SIGNAL ( triggered ( ) ) , transferList , SLOT ( startSelectedTorrents ( ) ) ) ;
connect ( actionStart_All , SIGNAL ( triggered ( ) ) , transferList , SLOT ( startAllTorrents ( ) ) ) ;
connect ( actionPause , SIGNAL ( triggered ( ) ) , transferList , SLOT ( pauseSelectedTorrents ( ) ) ) ;
connect ( actionPause_All , SIGNAL ( triggered ( ) ) , transferList , SLOT ( pauseAllTorrents ( ) ) ) ;
connect ( actionDelete , SIGNAL ( triggered ( ) ) , transferList , SLOT ( deleteSelectedTorrents ( ) ) ) ;
connect ( actionIncreasePriority , SIGNAL ( triggered ( ) ) , transferList , SLOT ( increasePrioSelectedTorrents ( ) ) ) ;
connect ( actionDecreasePriority , SIGNAL ( triggered ( ) ) , transferList , SLOT ( decreasePrioSelectedTorrents ( ) ) ) ;
2008-09-28 21:58:12 +04:00
// Configure BT session according to options
2009-11-14 22:08:28 +03:00
loadPreferences ( false ) ;
2010-06-09 13:48:14 +04:00
2009-11-06 17:30:14 +03:00
// Start connection checking timer
2009-11-18 16:18:55 +03:00
guiUpdater = new QTimer ( this ) ;
connect ( guiUpdater , SIGNAL ( timeout ( ) ) , this , SLOT ( updateGUI ( ) ) ) ;
guiUpdater - > start ( 2000 ) ;
2009-11-06 17:30:14 +03:00
// Accept drag 'n drops
setAcceptDrops ( true ) ;
createKeyboardShortcuts ( ) ;
2009-11-18 20:32:54 +03:00
// Create status bar
2010-11-14 00:15:52 +03:00
status_bar = new StatusBar ( QMainWindow : : statusBar ( ) ) ;
2010-11-08 21:17:54 +03:00
connect ( status_bar - > connectionStatusButton ( ) , SIGNAL ( clicked ( ) ) , SLOT ( showConnectionSettings ( ) ) ) ;
2010-01-23 23:44:09 +03:00
connect ( actionUse_alternative_speed_limits , SIGNAL ( triggered ( ) ) , status_bar , SLOT ( toggleAlternativeSpeeds ( ) ) ) ;
2009-11-08 15:23:04 +03:00
2010-06-09 11:37:05 +04:00
# ifdef Q_WS_MAC
setUnifiedTitleAndToolBarOnMac ( true ) ;
# endif
2010-06-21 22:32:01 +04:00
// View settings
2010-11-16 23:34:31 +03:00
actionTop_tool_bar - > setChecked ( pref . isToolbarDisplayed ( ) ) ;
actionSpeed_in_title_bar - > setChecked ( pref . speedInTitleBar ( ) ) ;
2010-10-31 15:03:24 +03:00
actionRSS_Reader - > setChecked ( RssSettings : : isRSSEnabled ( ) ) ;
2010-11-16 23:34:31 +03:00
actionSearch_engine - > setChecked ( pref . isSearchEnabled ( ) ) ;
2010-06-22 18:18:43 +04:00
displaySearchTab ( actionSearch_engine - > isChecked ( ) ) ;
displayRSSTab ( actionRSS_Reader - > isChecked ( ) ) ;
2010-11-16 23:34:31 +03:00
actionShutdown_when_downloads_complete - > setChecked ( pref . shutdownWhenDownloadsComplete ( ) ) ;
actionShutdown_qBittorrent_when_downloads_complete - > setChecked ( pref . shutdownqBTWhenDownloadsComplete ( ) ) ;
2010-06-21 22:32:01 +04:00
2009-11-06 17:30:14 +03:00
show ( ) ;
2009-11-08 15:23:04 +03:00
// Load Window state and sizes
readSettings ( ) ;
2009-11-09 22:30:13 +03:00
properties - > readSettings ( ) ;
2009-11-08 15:23:04 +03:00
2010-01-18 00:27:08 +03:00
// Limit status filters list height
2010-10-23 20:58:06 +04:00
transferListFilters - > getStatusFilters ( ) - > updateHeight ( ) ;
2010-01-18 00:27:08 +03:00
2010-08-19 20:30:13 +04:00
if ( ui_locked ) {
hide ( ) ;
} else {
2010-11-16 23:34:31 +03:00
if ( pref . startMinimized ( ) )
2010-08-19 20:30:13 +04:00
showMinimized ( ) ;
2009-11-06 17:30:14 +03:00
}
2009-11-08 15:23:04 +03:00
2010-08-23 23:42:15 +04:00
// Start watching the executable for updates
executable_watcher = new QFileSystemWatcher ( ) ;
connect ( executable_watcher , SIGNAL ( fileChanged ( QString ) ) , this , SLOT ( notifyOfUpdate ( QString ) ) ) ;
executable_watcher - > addPath ( qApp - > applicationFilePath ( ) ) ;
2010-08-19 20:30:13 +04:00
// Resume unfinished torrents
BTSession - > startUpTorrents ( ) ;
// Add torrent given on command line
processParams ( torrentCmdLine ) ;
2010-11-14 18:28:22 +03:00
// Populate the transfer list
transferList - > getSourceModel ( ) - > populate ( ) ;
2009-11-06 17:30:14 +03:00
qDebug ( " GUI Built " ) ;
2010-05-31 01:45:55 +04:00
# ifdef Q_WS_WIN
2010-11-16 23:34:31 +03:00
if ( ! pref . neverCheckFileAssoc ( ) & & ! Preferences : : isFileAssocOk ( ) ) {
2010-06-02 17:08:26 +04:00
if ( QMessageBox : : question ( 0 , tr ( " Torrent file association " ) ,
tr ( " qBittorrent is not the default application to open torrent files or Magnet links. \n Do you want to associate qBittorrent to torrent files and Magnet links? " ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
Preferences : : setFileAssoc ( ) ;
} else {
2010-11-16 23:34:31 +03:00
pref . setNeverCheckFileAssoc ( ) ;
2010-06-02 17:08:26 +04:00
}
2010-05-31 01:45:55 +04:00
}
# endif
2010-06-09 19:40:55 +04:00
# ifdef Q_WS_MAC
qt_mac_set_dock_menu ( getTrayIconMenu ( ) ) ;
# endif
2010-10-24 01:46:05 +04:00
# if defined(Q_WS_WIN) || defined(Q_WS_MAC)
// Check for update
ProgramUpdater * updater = new ProgramUpdater ( this ) ;
connect ( updater , SIGNAL ( updateCheckFinished ( bool , QString ) ) , SLOT ( handleUpdateCheckFinished ( bool , QString ) ) ) ;
updater - > checkForUpdates ( ) ;
# endif
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : deleteBTSession ( ) {
2010-10-02 00:03:27 +04:00
guiUpdater - > stop ( ) ;
status_bar - > stopTimer ( ) ;
if ( BTSession ) {
delete BTSession ;
BTSession = 0 ;
}
QTimer : : singleShot ( 0 , this , SLOT ( close ( ) ) ) ;
}
2009-11-06 17:30:14 +03:00
// Destructor
2010-11-14 00:15:52 +03:00
MainWindow : : ~ MainWindow ( ) {
2009-11-06 17:30:14 +03:00
qDebug ( " GUI destruction " ) ;
hide ( ) ;
2010-06-09 19:13:52 +04:00
# ifdef Q_WS_MAC
// Workaround to avoid bug http://bugreports.qt.nokia.com/browse/QTBUG-7305
2010-06-09 19:19:43 +04:00
setUnifiedTitleAndToolBarOnMac ( false ) ;
2010-06-09 19:13:52 +04:00
# endif
2009-12-01 14:56:51 +03:00
// Some saving
properties - > saveSettings ( ) ;
disconnect ( tabs , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( tab_changed ( int ) ) ) ;
2009-12-01 00:30:14 +03:00
// Delete other GUI objects
2010-08-23 23:42:15 +04:00
if ( executable_watcher )
delete executable_watcher ;
2009-11-18 16:18:55 +03:00
delete status_bar ;
2010-08-20 16:27:20 +04:00
delete search_filter ;
2009-12-01 00:30:14 +03:00
delete transferList ;
delete guiUpdater ;
2010-09-28 00:42:00 +04:00
delete lockMenu ;
2010-03-03 17:42:57 +03:00
if ( createTorrentDlg )
delete createTorrentDlg ;
if ( console )
2010-03-03 16:15:13 +03:00
delete console ;
2010-03-03 17:42:57 +03:00
if ( aboutDlg )
delete aboutDlg ;
2010-03-03 16:15:13 +03:00
if ( options )
delete options ;
2010-03-10 23:21:56 +03:00
if ( downloadFromURLDialog )
delete downloadFromURLDialog ;
2009-11-14 23:39:37 +03:00
if ( rssWidget )
2009-11-06 17:30:14 +03:00
delete rssWidget ;
2010-06-22 17:58:22 +04:00
if ( searchEngine )
delete searchEngine ;
2009-11-08 15:05:35 +03:00
delete transferListFilters ;
2009-11-08 17:20:58 +03:00
delete properties ;
delete hSplitter ;
2009-11-08 15:05:35 +03:00
delete vSplitter ;
2009-11-06 17:30:14 +03:00
if ( systrayCreator ) {
delete systrayCreator ;
}
2009-11-18 21:45:06 +03:00
if ( systrayIcon ) {
delete systrayIcon ;
2010-06-09 19:45:59 +04:00
}
if ( myTrayIconMenu ) {
2009-11-06 17:30:14 +03:00
delete myTrayIconMenu ;
}
delete tabs ;
// Keyboard shortcuts
delete switchSearchShortcut ;
delete switchSearchShortcut2 ;
2009-11-18 20:51:50 +03:00
delete switchTransferShortcut ;
2009-11-06 17:30:14 +03:00
delete switchRSSShortcut ;
2009-12-01 00:30:14 +03:00
// Delete BTSession objects
2010-08-20 13:31:00 +04:00
qDebug ( " Deleting BTSession " ) ;
2010-11-13 22:36:46 +03:00
QBtSession : : drop ( ) ;
2009-12-01 00:30:14 +03:00
// May freeze for a few seconds after the next line
// because the Bittorrent session proxy will
// actually be deleted now and destruction
// becomes synchronous
qDebug ( " Exiting GUI destructor... " ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : defineUILockPassword ( ) {
2010-11-16 23:34:31 +03:00
QString old_pass_md5 = Preferences ( ) . getUILockPasswordMD5 ( ) ;
2010-08-19 20:30:13 +04:00
if ( old_pass_md5 . isNull ( ) ) old_pass_md5 = " " ;
bool ok = false ;
2010-08-19 23:37:29 +04:00
QString new_clear_password = QInputDialog : : getText ( this , tr ( " UI lock password " ) , tr ( " Please type the UI lock password: " ) , QLineEdit : : Password , old_pass_md5 , & ok ) ;
2010-08-19 20:30:13 +04:00
if ( ok ) {
if ( new_clear_password ! = old_pass_md5 ) {
2010-11-16 23:34:31 +03:00
Preferences ( ) . setUILockPassword ( new_clear_password ) ;
2010-08-19 20:30:13 +04:00
}
QMessageBox : : information ( this , tr ( " Password update " ) , tr ( " The UI lock password has been successfully updated " ) ) ;
}
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionLock_qBittorrent_triggered ( ) {
2010-11-16 23:34:31 +03:00
Preferences pref ;
2010-08-19 20:30:13 +04:00
// Check if there is a password
2010-11-16 23:34:31 +03:00
if ( pref . getUILockPasswordMD5 ( ) . isEmpty ( ) ) {
2010-08-19 20:30:13 +04:00
// Ask for a password
bool ok = false ;
2010-08-19 23:37:29 +04:00
QString clear_password = QInputDialog : : getText ( this , tr ( " UI lock password " ) , tr ( " Please type the UI lock password: " ) , QLineEdit : : Password , " " , & ok ) ;
2010-08-19 20:30:13 +04:00
if ( ! ok ) return ;
2010-11-16 23:34:31 +03:00
pref . setUILockPassword ( clear_password ) ;
2010-08-19 20:30:13 +04:00
}
// Lock the interface
ui_locked = true ;
2010-11-16 23:34:31 +03:00
pref . setUILocked ( true ) ;
2010-08-22 23:08:15 +04:00
myTrayIconMenu - > setEnabled ( false ) ;
2010-08-19 20:30:13 +04:00
hide ( ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : displayRSSTab ( bool enable ) {
2009-11-06 17:30:14 +03:00
if ( enable ) {
// RSS tab
2009-11-14 23:39:37 +03:00
if ( ! rssWidget ) {
2010-11-13 23:14:59 +03:00
rssWidget = new RSSImp ( tabs ) ;
2009-11-07 22:55:33 +03:00
int index_tab = tabs - > addTab ( rssWidget , tr ( " RSS " ) ) ;
tabs - > setTabIcon ( index_tab , QIcon ( QString : : fromUtf8 ( " :/Icons/rss32.png " ) ) ) ;
2009-11-06 17:30:14 +03:00
}
2010-06-22 18:18:43 +04:00
tabs - > showTabBar ( true ) ;
2009-11-06 17:30:14 +03:00
} else {
2009-11-14 23:39:37 +03:00
if ( rssWidget ) {
2008-07-11 21:43:57 +04:00
delete rssWidget ;
2009-08-16 07:09:20 +04:00
}
2010-06-22 18:18:43 +04:00
if ( ! searchEngine )
tabs - > showTabBar ( false ) ;
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : displaySearchTab ( bool enable ) {
2010-06-22 17:58:22 +04:00
if ( enable ) {
// RSS tab
if ( ! searchEngine ) {
2010-11-14 00:15:52 +03:00
searchEngine = new SearchEngine ( this ) ;
2010-06-22 17:58:22 +04:00
tabs - > insertTab ( 1 , searchEngine , QIcon ( QString : : fromUtf8 ( " :/Icons/oxygen/edit-find.png " ) ) , tr ( " Search " ) ) ;
}
2010-06-22 18:18:43 +04:00
tabs - > showTabBar ( true ) ;
2010-06-22 17:58:22 +04:00
} else {
if ( searchEngine ) {
delete searchEngine ;
}
2010-06-22 18:18:43 +04:00
if ( ! rssWidget )
tabs - > showTabBar ( false ) ;
2010-06-22 17:58:22 +04:00
}
}
2010-11-14 18:28:22 +03:00
void MainWindow : : updateNbTorrents ( ) {
tabs - > setTabText ( 0 , tr ( " Transfers (%1) " ) . arg ( transferList - > getSourceModel ( ) - > rowCount ( ) ) ) ;
2010-05-21 18:56:56 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionWebsite_triggered ( ) const {
2009-11-06 17:30:14 +03:00
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://www.qbittorrent.org " ) ) ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionDocumentation_triggered ( ) const {
2009-11-27 00:27:06 +03:00
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://doc.qbittorrent.org " ) ) ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionBugReport_triggered ( ) const {
2009-11-06 17:30:14 +03:00
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://bugs.qbittorrent.org " ) ) ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : tab_changed ( int new_tab ) {
2010-07-19 22:49:53 +04:00
Q_UNUSED ( new_tab ) ;
// We cannot rely on the index new_tab
// because the tab order is undetermined now
if ( tabs - > currentWidget ( ) = = vSplitter ) {
2009-11-21 17:16:54 +03:00
qDebug ( " Changed tab to transfer list, refreshing the list " ) ;
properties - > loadDynamicData ( ) ;
2010-07-19 22:49:53 +04:00
return ;
}
if ( tabs - > currentWidget ( ) = = searchEngine ) {
qDebug ( " Changed tab to search engine, giving focus to search input " ) ;
searchEngine - > giveFocusToSearchInput ( ) ;
2009-11-21 17:16:54 +03:00
}
}
2010-11-14 00:15:52 +03:00
void MainWindow : : writeSettings ( ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2009-11-06 17:30:14 +03:00
settings . beginGroup ( QString : : fromUtf8 ( " MainWindow " ) ) ;
2010-06-23 19:47:03 +04:00
settings . setValue ( " geometry " , saveGeometry ( ) ) ;
2009-11-08 15:23:04 +03:00
// Splitter size
QStringList sizes_str ;
sizes_str < < QString : : number ( vSplitter - > sizes ( ) . first ( ) ) ;
sizes_str < < QString : : number ( vSplitter - > sizes ( ) . last ( ) ) ;
settings . setValue ( QString : : fromUtf8 ( " vSplitterSizes " ) , sizes_str ) ;
2009-11-06 17:30:14 +03:00
settings . endGroup ( ) ;
}
// called when a torrent has finished
2010-11-14 00:15:52 +03:00
void MainWindow : : finishedTorrent ( QTorrentHandle & h ) const {
2009-11-07 22:55:33 +03:00
if ( ! TorrentPersistentData : : isSeed ( h . hash ( ) ) )
showNotificationBaloon ( tr ( " Download completion " ) , tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( h . name ( ) ) ) ;
2009-11-06 17:30:14 +03:00
}
// Notification when disk is full
2010-11-14 00:15:52 +03:00
void MainWindow : : fullDiskError ( QTorrentHandle & h , QString msg ) const {
2010-03-03 17:42:57 +03:00
if ( ! h . is_valid ( ) ) return ;
showNotificationBaloon ( tr ( " I/O Error " , " i.e: Input/Output Error " ) , tr ( " An I/O error occured for torrent %1. \n Reason: %2 " , " e.g: An error occured for torrent xxx.avi. \n Reason: disk is full. " ) . arg ( h . name ( ) ) . arg ( msg ) ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : createKeyboardShortcuts ( ) {
2009-11-06 17:30:14 +03:00
actionCreate_torrent - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+N " ) ) ) ;
actionOpen - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+O " ) ) ) ;
actionExit - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Q " ) ) ) ;
2009-11-18 20:51:50 +03:00
switchTransferShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+1 " , " shortcut to switch to first tab " ) ) , this ) ;
connect ( switchTransferShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayTransferTab ( ) ) ) ;
2009-11-18 15:40:13 +03:00
switchSearchShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+2 " , " shortcut to switch to third tab " ) ) , this ) ;
2009-11-06 17:30:14 +03:00
connect ( switchSearchShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displaySearchTab ( ) ) ) ;
switchSearchShortcut2 = new QShortcut ( QKeySequence ( tr ( " Ctrl+F " , " shortcut to switch to search tab " ) ) , this ) ;
connect ( switchSearchShortcut2 , SIGNAL ( activated ( ) ) , this , SLOT ( displaySearchTab ( ) ) ) ;
2009-11-18 15:40:13 +03:00
switchRSSShortcut = new QShortcut ( QKeySequence ( tr ( " Alt+3 " , " shortcut to switch to fourth tab " ) ) , this ) ;
2009-11-06 17:30:14 +03:00
connect ( switchRSSShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayRSSTab ( ) ) ) ;
2009-11-22 13:08:03 +03:00
actionDocumentation - > setShortcut ( QKeySequence ( " F1 " ) ) ;
2009-11-06 17:30:14 +03:00
actionOptions - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Alt+O " ) ) ) ;
actionDelete - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " 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 " ) ) ) ;
actionDecreasePriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+- " ) ) ) ;
actionIncreasePriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl++ " ) ) ) ;
}
// Keyboard shortcuts slots
2010-11-14 00:15:52 +03:00
void MainWindow : : displayTransferTab ( ) const {
2010-07-19 22:49:53 +04:00
tabs - > setCurrentWidget ( transferList ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : displaySearchTab ( ) const {
2010-07-19 22:49:53 +04:00
if ( searchEngine )
tabs - > setCurrentWidget ( searchEngine ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : displayRSSTab ( ) const {
2010-07-19 22:49:53 +04:00
if ( rssWidget )
tabs - > setCurrentWidget ( rssWidget ) ;
2009-11-06 17:30:14 +03:00
}
// End of keyboard shortcuts slots
2010-11-14 00:15:52 +03:00
void MainWindow : : readSettings ( ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2009-11-06 17:30:14 +03:00
settings . beginGroup ( QString : : fromUtf8 ( " MainWindow " ) ) ;
2010-06-23 19:47:03 +04:00
restoreGeometry ( settings . value ( " geometry " ) . toByteArray ( ) ) ;
2010-07-23 18:05:53 +04:00
const QStringList sizes_str = settings . value ( " vSplitterSizes " , QStringList ( ) ) . toStringList ( ) ;
2009-11-08 15:23:04 +03:00
// Splitter size
QList < int > sizes ;
if ( sizes_str . size ( ) = = 2 ) {
sizes < < sizes_str . first ( ) . toInt ( ) ;
sizes < < sizes_str . last ( ) . toInt ( ) ;
} else {
qDebug ( " Default splitter size " ) ;
sizes < < 120 ;
sizes < < vSplitter - > width ( ) - 120 ;
}
vSplitter - > setSizes ( sizes ) ;
2009-11-06 17:30:14 +03:00
settings . endGroup ( ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : balloonClicked ( ) {
2009-11-06 17:30:14 +03:00
if ( isHidden ( ) ) {
show ( ) ;
if ( isMinimized ( ) ) {
showNormal ( ) ;
2008-12-29 21:36:54 +03:00
}
2009-11-06 17:30:14 +03:00
raise ( ) ;
activateWindow ( ) ;
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : askRecursiveTorrentDownloadConfirmation ( QTorrentHandle & h ) {
2010-11-16 23:34:31 +03:00
Preferences pref ;
if ( pref . recursiveDownloadDisabled ( ) ) return ;
2010-06-14 21:46:33 +04:00
QMessageBox confirmBox ( QMessageBox : : Question , tr ( " Recursive download confirmation " ) , tr ( " The torrent %1 contains torrent files, do you want to proceed with their download? " ) . arg ( h . name ( ) ) ) ;
QPushButton * yes = confirmBox . addButton ( tr ( " Yes " ) , QMessageBox : : YesRole ) ;
/*QPushButton *no = */ confirmBox . addButton ( tr ( " No " ) , QMessageBox : : NoRole ) ;
2010-10-24 01:46:05 +04:00
QPushButton * never = confirmBox . addButton ( tr ( " Never " ) , QMessageBox : : NoRole ) ;
confirmBox . exec ( ) ;
if ( confirmBox . clickedButton ( ) = = 0 ) return ;
if ( confirmBox . clickedButton ( ) = = yes ) {
BTSession - > recursiveTorrentDownload ( h ) ;
return ;
}
if ( confirmBox . clickedButton ( ) = = never ) {
2010-11-16 23:34:31 +03:00
pref . disableRecursiveDownload ( ) ;
2010-10-24 01:46:05 +04:00
}
}
2010-03-20 14:30:11 +03:00
2010-11-14 00:15:52 +03:00
void MainWindow : : handleDownloadFromUrlFailure ( QString url , QString reason ) const {
2009-11-06 17:30:14 +03:00
// Display a message box
2010-10-09 19:40:24 +04:00
showNotificationBaloon ( tr ( " Url download error " ) , tr ( " Couldn't download file at url: %1, reason: %2. " ) . arg ( url ) . arg ( reason ) ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionSet_global_upload_limit_triggered ( ) {
2009-11-06 17:30:14 +03:00
qDebug ( " actionSet_global_upload_limit_triggered " ) ;
2009-11-17 16:11:32 +03:00
bool ok ;
2010-03-03 17:42:57 +03:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Upload Speed Limit " ) , BTSession - > getSession ( ) - > upload_rate_limit ( ) ) ;
2009-11-17 16:11:32 +03:00
if ( ok ) {
qDebug ( " Setting global upload rate limit to %.1fKb/s " , new_limit / 1024. ) ;
BTSession - > getSession ( ) - > set_upload_rate_limit ( new_limit ) ;
if ( new_limit < = 0 )
2010-11-16 23:34:31 +03:00
Preferences ( ) . setGlobalUploadLimit ( - 1 ) ;
2009-11-17 16:11:32 +03:00
else
2010-11-16 23:34:31 +03:00
Preferences ( ) . setGlobalUploadLimit ( new_limit / 1024. ) ;
2009-11-17 16:11:32 +03:00
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionShow_console_triggered ( ) {
2010-03-03 16:07:27 +03:00
if ( ! console ) {
2010-11-14 00:15:52 +03:00
console = new consoleDlg ( this ) ;
2010-03-03 16:07:27 +03:00
} else {
console - > setFocus ( ) ;
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionSet_global_download_limit_triggered ( ) {
2009-11-06 17:30:14 +03:00
qDebug ( " actionSet_global_download_limit_triggered " ) ;
2009-11-17 16:11:32 +03:00
bool ok ;
2010-03-03 17:42:57 +03:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Download Speed Limit " ) , BTSession - > getSession ( ) - > download_rate_limit ( ) ) ;
2009-11-17 16:11:32 +03:00
if ( ok ) {
qDebug ( " Setting global download rate limit to %.1fKb/s " , new_limit / 1024. ) ;
BTSession - > getSession ( ) - > set_download_rate_limit ( new_limit ) ;
if ( new_limit < = 0 )
2010-11-16 23:34:31 +03:00
Preferences ( ) . setGlobalDownloadLimit ( - 1 ) ;
2009-11-17 16:11:32 +03:00
else
2010-11-16 23:34:31 +03:00
Preferences ( ) . setGlobalDownloadLimit ( new_limit / 1024. ) ;
2009-11-17 16:11:32 +03:00
}
2009-11-06 17:30:14 +03:00
}
// Necessary if we want to close the window
// in one time if "close to systray" is enabled
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionExit_triggered ( ) {
2009-11-06 17:30:14 +03:00
force_exit = true ;
close ( ) ;
}
2010-11-14 00:15:52 +03:00
QWidget * MainWindow : : getCurrentTabWidget ( ) const {
2009-11-21 17:16:54 +03:00
if ( isMinimized ( ) | | ! isVisible ( ) )
2010-07-19 22:49:53 +04:00
return 0 ;
if ( tabs - > currentIndex ( ) = = 0 )
return transferList ;
return tabs - > currentWidget ( ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : setTabText ( int index , QString text ) const {
2009-11-06 17:30:14 +03:00
tabs - > setTabText ( index , text ) ;
}
2010-11-14 00:15:52 +03:00
bool MainWindow : : unlockUI ( ) {
2010-08-19 20:30:13 +04:00
bool ok = false ;
QString clear_password = QInputDialog : : getText ( this , tr ( " UI lock password " ) , tr ( " Please type the UI lock password: " ) , QLineEdit : : Password , " " , & ok ) ;
if ( ! ok ) return false ;
2010-11-16 23:34:31 +03:00
Preferences pref ;
QString real_pass_md5 = pref . getUILockPasswordMD5 ( ) ;
2010-08-19 20:30:13 +04:00
QCryptographicHash md5 ( QCryptographicHash : : Md5 ) ;
md5 . addData ( clear_password . toLocal8Bit ( ) ) ;
QString password_md5 = md5 . result ( ) . toHex ( ) ;
if ( real_pass_md5 = = password_md5 ) {
ui_locked = false ;
2010-11-16 23:34:31 +03:00
pref . setUILocked ( false ) ;
2010-08-22 23:08:15 +04:00
myTrayIconMenu - > setEnabled ( true ) ;
2010-08-19 20:30:13 +04:00
return true ;
}
QMessageBox : : warning ( this , tr ( " Invalid password " ) , tr ( " The password is invalid " ) ) ;
return false ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : notifyOfUpdate ( QString ) {
2010-08-23 23:42:15 +04:00
// Show restart message
status_bar - > showRestartRequired ( ) ;
// Delete the executable watcher
delete executable_watcher ;
executable_watcher = 0 ;
}
2009-11-06 17:30:14 +03:00
// Toggle Main window visibility
2010-11-14 00:15:52 +03:00
void MainWindow : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e ) {
2009-11-06 17:30:14 +03:00
if ( e = = QSystemTrayIcon : : Trigger | | e = = QSystemTrayIcon : : DoubleClick ) {
2009-08-16 07:09:20 +04:00
if ( isHidden ( ) ) {
2010-08-19 20:30:13 +04:00
if ( ui_locked ) {
// Ask for UI lock password
if ( ! unlockUI ( ) )
return ;
}
2006-10-19 00:40:40 +04:00
show ( ) ;
2007-08-20 10:29:18 +04:00
if ( isMinimized ( ) ) {
2009-11-06 17:30:14 +03:00
if ( isMaximized ( ) ) {
showMaximized ( ) ;
} else {
showNormal ( ) ;
}
2006-10-19 00:40:40 +04:00
}
raise ( ) ;
activateWindow ( ) ;
2009-11-06 17:30:14 +03:00
} else {
hide ( ) ;
2009-08-16 07:09:20 +04:00
}
2006-10-19 00:40:40 +04:00
}
2009-11-06 17:30:14 +03:00
}
// Display About Dialog
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionAbout_triggered ( ) {
2009-11-06 17:30:14 +03:00
//About dialog
2010-03-03 17:42:57 +03:00
if ( aboutDlg ) {
aboutDlg - > setFocus ( ) ;
} else {
aboutDlg = new about ( this ) ;
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : showEvent ( QShowEvent * e ) {
2009-11-06 17:30:14 +03:00
qDebug ( " ** Show Event ** " ) ;
2010-07-19 22:49:53 +04:00
if ( getCurrentTabWidget ( ) = = transferList ) {
2009-11-21 17:16:54 +03:00
properties - > loadDynamicData ( ) ;
}
2009-11-06 17:30:14 +03:00
e - > accept ( ) ;
}
// Called when we close the program
2010-11-14 00:15:52 +03:00
void MainWindow : : closeEvent ( QCloseEvent * e ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2010-03-03 17:42:57 +03:00
const bool goToSystrayOnExit = settings . value ( QString : : fromUtf8 ( " Preferences/General/CloseToTray " ) , false ) . toBool ( ) ;
2009-11-18 21:45:06 +03:00
if ( ! force_exit & & systrayIcon & & goToSystrayOnExit & & ! this - > isHidden ( ) ) {
2009-11-06 17:30:14 +03:00
hide ( ) ;
e - > accept ( ) ;
return ;
2006-09-30 20:02:39 +04:00
}
2010-10-02 00:03:27 +04:00
if ( settings . value ( QString : : fromUtf8 ( " Preferences/General/ExitConfirm " ) , true ) . toBool ( ) & & BTSession & & BTSession - > hasActiveTorrents ( ) ) {
2010-03-03 17:42:57 +03:00
if ( e - > spontaneous ( ) | | force_exit ) {
2010-06-21 19:53:42 +04:00
if ( ! isVisible ( ) )
show ( ) ;
2010-06-22 21:51:59 +04:00
QMessageBox confirmBox ( QMessageBox : : Question , tr ( " Exiting qBittorrent " ) ,
2010-06-21 20:10:09 +04:00
tr ( " Some files are currently transferring. \n Are you sure you want to quit qBittorrent? " ) ,
QMessageBox : : NoButton , this ) ;
2010-06-21 19:53:42 +04:00
QPushButton * noBtn = confirmBox . addButton ( tr ( " No " ) , QMessageBox : : NoRole ) ;
QPushButton * yesBtn = confirmBox . addButton ( tr ( " Yes " ) , QMessageBox : : YesRole ) ;
QPushButton * alwaysBtn = confirmBox . addButton ( tr ( " Always " ) , QMessageBox : : YesRole ) ;
confirmBox . setDefaultButton ( yesBtn ) ;
confirmBox . exec ( ) ;
if ( ! confirmBox . clickedButton ( ) | | confirmBox . clickedButton ( ) = = noBtn ) {
// Cancel exit
2009-11-06 17:30:14 +03:00
e - > ignore ( ) ;
force_exit = false ;
return ;
2009-08-16 07:09:20 +04:00
}
2010-06-21 19:53:42 +04:00
if ( confirmBox . clickedButton ( ) = = alwaysBtn ) {
// Remember choice
2010-11-16 23:34:31 +03:00
Preferences ( ) . setConfirmOnExit ( false ) ;
2010-06-21 19:53:42 +04:00
}
2007-11-16 21:53:21 +03:00
}
}
2009-11-06 17:30:14 +03:00
hide ( ) ;
2009-11-18 21:45:06 +03:00
if ( systrayIcon ) {
2009-11-06 17:30:14 +03:00
// Hide tray icon
2009-11-18 21:45:06 +03:00
systrayIcon - > hide ( ) ;
2007-12-08 01:33:19 +03:00
}
2009-11-06 17:30:14 +03:00
// Save window size, columns size
writeSettings ( ) ;
// Accept exit
e - > accept ( ) ;
qApp - > exit ( ) ;
}
// Display window to create a torrent
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionCreate_torrent_triggered ( ) {
2010-03-03 17:42:57 +03:00
if ( createTorrentDlg ) {
createTorrentDlg - > setFocus ( ) ;
} else {
2010-10-23 00:13:22 +04:00
createTorrentDlg = new TorrentCreatorDlg ( this ) ;
2010-03-03 17:42:57 +03:00
connect ( createTorrentDlg , SIGNAL ( torrent_to_seed ( QString ) ) , this , SLOT ( addTorrent ( QString ) ) ) ;
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
bool MainWindow : : event ( QEvent * e ) {
2010-07-21 22:02:29 +04:00
switch ( e - > type ( ) ) {
case QEvent : : WindowStateChange : {
2010-10-24 01:46:05 +04:00
qDebug ( " Window change event " ) ;
//Now check to see if the window is minimised
if ( isMinimized ( ) ) {
qDebug ( " minimisation " ) ;
2010-11-16 23:34:31 +03:00
if ( systrayIcon & & Preferences ( ) . minimizeToTray ( ) ) {
2010-10-24 01:46:05 +04:00
qDebug ( " Has active window: %d " , ( int ) ( qApp - > activeWindow ( ) ! = 0 ) ) ;
// Check if there is a modal window
bool has_modal_window = false ;
foreach ( QWidget * widget , QApplication : : allWidgets ( ) ) {
if ( widget - > isModal ( ) ) {
has_modal_window = true ;
break ;
2010-07-21 22:02:29 +04:00
}
2010-06-10 22:54:23 +04:00
}
2010-10-24 01:46:05 +04:00
// Iconify if there is no modal window
if ( ! has_modal_window ) {
qDebug ( " Minimize to Tray enabled, hiding! " ) ;
e - > accept ( ) ;
QTimer : : singleShot ( 0 , this , SLOT ( hide ( ) ) ) ;
return true ;
}
2006-09-30 20:02:39 +04:00
}
}
2010-10-24 01:46:05 +04:00
break ;
}
2010-07-21 22:02:29 +04:00
# ifdef Q_WS_MAC
case QEvent : : ToolBarChange : {
2010-10-24 01:46:05 +04:00
qDebug ( " MAC: Received a toolbar change event! " ) ;
bool ret = QMainWindow : : event ( e ) ;
2010-07-22 12:36:40 +04:00
2010-10-24 01:46:05 +04:00
qDebug ( " MAC: new toolbar visibility is %d " , ! actionTop_tool_bar - > isChecked ( ) ) ;
actionTop_tool_bar - > toggle ( ) ;
2010-11-16 23:34:31 +03:00
Preferences ( ) . setToolbarDisplayed ( actionTop_tool_bar - > isChecked ( ) ) ;
2010-10-24 01:46:05 +04:00
return ret ;
}
2010-07-21 22:02:29 +04:00
# endif
default :
break ;
2006-09-30 20:02:39 +04:00
}
2009-11-06 17:30:14 +03:00
return QMainWindow : : event ( e ) ;
}
// Action executed when a file is dropped
2010-11-14 00:15:52 +03:00
void MainWindow : : dropEvent ( QDropEvent * event ) {
2009-11-06 17:30:14 +03:00
event - > acceptProposedAction ( ) ;
QStringList files ;
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
2010-07-23 18:05:53 +04:00
const QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
2009-11-06 17:30:14 +03:00
foreach ( const QUrl & url , urls ) {
2010-03-03 17:42:57 +03:00
const QString tmp = url . toString ( ) . trimmed ( ) ;
2009-11-06 17:30:14 +03:00
if ( ! tmp . isEmpty ( ) )
files < < url . toString ( ) ;
}
} else {
files = event - > mimeData ( ) - > text ( ) . split ( QString : : fromUtf8 ( " \n " ) ) ;
}
// Add file to download list
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2010-03-03 17:42:57 +03:00
const bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2009-11-06 17:30:14 +03:00
foreach ( QString file , files ) {
2010-07-25 19:20:37 +04:00
# ifdef Q_WS_WIN
file = file . trimmed ( ) . replace ( QString : : fromUtf8 ( " file:/// " ) , QString : : fromUtf8 ( " " ) , Qt : : CaseInsensitive ) ;
# else
2009-11-06 17:30:14 +03:00
file = file . trimmed ( ) . replace ( QString : : fromUtf8 ( " file:// " ) , QString : : fromUtf8 ( " " ) , Qt : : CaseInsensitive ) ;
2010-07-25 19:20:37 +04:00
# endif
2009-11-06 17:30:14 +03:00
qDebug ( " Dropped file %s on download list " , file . toLocal8Bit ( ) . data ( ) ) ;
if ( file . startsWith ( QString : : fromUtf8 ( " http:// " ) , Qt : : CaseInsensitive ) | | file . startsWith ( QString : : fromUtf8 ( " ftp:// " ) , Qt : : CaseInsensitive ) | | file . startsWith ( QString : : fromUtf8 ( " https:// " ) , Qt : : CaseInsensitive ) ) {
BTSession - > downloadFromUrl ( file ) ;
continue ;
}
2010-07-23 02:19:42 +04:00
if ( file . startsWith ( " bc://bt/ " , Qt : : CaseInsensitive ) ) {
qDebug ( " Converting bc link to magnet link " ) ;
file = misc : : bcLinkToMagnet ( file ) ;
}
2009-11-06 17:30:14 +03:00
if ( file . startsWith ( " magnet: " , Qt : : CaseInsensitive ) ) {
// FIXME: Possibly skipped torrent addition dialog
BTSession - > addMagnetUri ( file ) ;
continue ;
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
if ( useTorrentAdditionDialog ) {
2010-11-14 00:15:52 +03:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this ) ;
2009-11-06 17:30:14 +03:00
dialog - > showLoad ( file ) ;
} else {
BTSession - > addTorrent ( file ) ;
2008-08-02 00:03:16 +04:00
}
2006-09-30 20:02:39 +04:00
}
2009-11-06 17:30:14 +03:00
}
// Decode if we accept drag 'n drop or not
2010-11-14 00:15:52 +03:00
void MainWindow : : dragEnterEvent ( QDragEnterEvent * event ) {
2009-11-06 17:30:14 +03:00
foreach ( const QString & mime , event - > mimeData ( ) - > formats ( ) ) {
qDebug ( " mimeData: %s " , mime . toLocal8Bit ( ) . data ( ) ) ;
}
2009-12-16 18:06:02 +03:00
if ( event - > mimeData ( ) - > hasFormat ( QString : : fromUtf8 ( " text/plain " ) ) | | event - > mimeData ( ) - > hasFormat ( QString : : fromUtf8 ( " text/uri-list " ) ) ) {
event - > acceptProposedAction ( ) ;
2009-11-06 17:30:14 +03:00
}
}
/*****************************************************
* *
* Torrent *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Display a dialog to allow user to add
// torrents to download list
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionOpen_triggered ( ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2009-11-06 17:30:14 +03:00
// Open File Open Dialog
// Note: it is possible to select more than one file
2010-07-23 18:05:53 +04:00
const QStringList pathsList = QFileDialog : : getOpenFileNames ( 0 ,
2010-08-19 20:30:13 +04:00
tr ( " Open Torrent Files " ) , settings . value ( QString : : fromUtf8 ( " MainWindowLastDir " ) , QDir : : homePath ( ) ) . toString ( ) ,
tr ( " Torrent Files " ) + QString : : fromUtf8 ( " (*.torrent) " ) ) ;
2009-11-06 17:30:14 +03:00
if ( ! pathsList . empty ( ) ) {
2010-03-03 17:42:57 +03:00
const bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
const uint listSize = pathsList . size ( ) ;
for ( uint i = 0 ; i < listSize ; + + i ) {
2009-08-16 07:09:20 +04:00
if ( useTorrentAdditionDialog ) {
2010-11-14 00:15:52 +03:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this ) ;
2009-11-06 17:30:14 +03:00
dialog - > showLoad ( pathsList . at ( i ) ) ;
2009-08-16 07:09:20 +04:00
} else {
2009-11-06 17:30:14 +03:00
BTSession - > addTorrent ( pathsList . at ( i ) ) ;
2009-08-16 07:09:20 +04:00
}
2006-10-24 15:41:28 +04:00
}
2009-11-06 17:30:14 +03:00
// Save last dir to remember it
QStringList top_dir = pathsList . at ( 0 ) . split ( QDir : : separator ( ) ) ;
top_dir . removeLast ( ) ;
settings . setValue ( QString : : fromUtf8 ( " MainWindowLastDir " ) , top_dir . join ( QDir : : separator ( ) ) ) ;
2006-10-24 01:42:37 +04:00
}
2009-11-06 17:30:14 +03: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.
2010-11-14 00:15:52 +03:00
void MainWindow : : processParams ( const QString & params_str ) {
2010-06-23 23:07:54 +04:00
processParams ( params_str . split ( " | " , QString : : SkipEmptyParts ) ) ;
2010-06-09 13:48:14 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : processParams ( const QStringList & params ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2010-03-03 17:42:57 +03:00
const bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2009-11-06 17:30:14 +03:00
foreach ( QString param , params ) {
param = param . trimmed ( ) ;
if ( param . startsWith ( QString : : fromUtf8 ( " http:// " ) , Qt : : CaseInsensitive ) | | param . startsWith ( QString : : fromUtf8 ( " ftp:// " ) , Qt : : CaseInsensitive ) | | param . startsWith ( QString : : fromUtf8 ( " https:// " ) , Qt : : CaseInsensitive ) ) {
BTSession - > downloadFromUrl ( param ) ;
} else {
2010-07-23 02:19:42 +04:00
if ( param . startsWith ( " bc://bt/ " , Qt : : CaseInsensitive ) ) {
qDebug ( " Converting bc link to magnet link " ) ;
param = misc : : bcLinkToMagnet ( param ) ;
}
2009-11-06 17:30:14 +03:00
if ( param . startsWith ( " magnet: " , Qt : : CaseInsensitive ) ) {
2010-01-03 17:20:31 +03:00
if ( useTorrentAdditionDialog ) {
2010-11-14 00:15:52 +03:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this ) ;
2010-01-03 17:20:31 +03:00
dialog - > showLoadMagnetURI ( param ) ;
} else {
BTSession - > addMagnetUri ( param ) ;
}
2009-11-06 17:30:14 +03:00
} else {
2009-08-16 07:09:20 +04:00
if ( useTorrentAdditionDialog ) {
2010-11-14 00:15:52 +03:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this ) ;
2009-11-06 17:30:14 +03:00
dialog - > showLoad ( param ) ;
2009-08-16 07:09:20 +04:00
} else {
2009-11-06 17:30:14 +03:00
BTSession - > addTorrent ( param ) ;
2009-08-16 07:09:20 +04:00
}
2006-10-24 15:41:28 +04:00
}
2006-09-30 20:02:39 +04:00
}
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : addTorrent ( QString path ) {
2009-11-06 17:30:14 +03:00
BTSession - > addTorrent ( path ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : processDownloadedFiles ( QString path , QString url ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2010-03-03 17:42:57 +03:00
const bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2009-11-06 17:30:14 +03:00
if ( useTorrentAdditionDialog ) {
2010-11-14 00:15:52 +03:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this ) ;
2009-11-06 17:30:14 +03:00
dialog - > showLoad ( path , url ) ;
} else {
BTSession - > addTorrent ( path , false , url ) ;
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : optionsSaved ( ) {
2009-11-15 13:00:07 +03:00
loadPreferences ( ) ;
}
2009-11-14 22:08:28 +03:00
// Load program preferences
2010-11-14 00:15:52 +03:00
void MainWindow : : loadPreferences ( bool configure_session ) {
2009-11-14 22:08:28 +03:00
BTSession - > addConsoleMessage ( tr ( " Options were saved successfully. " ) ) ;
2010-11-16 23:34:31 +03:00
const Preferences pref ;
const bool newSystrayIntegration = pref . systrayIntegration ( ) ;
2010-08-19 20:30:13 +04:00
actionLock_qBittorrent - > setEnabled ( newSystrayIntegration ) ;
2009-11-18 21:45:06 +03:00
if ( newSystrayIntegration ! = ( systrayIcon ! = 0 ) ) {
2009-11-14 22:08:28 +03:00
if ( newSystrayIntegration ) {
// create the trayicon
2009-11-18 21:45:06 +03:00
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
if ( ! configure_session ) { // Program startup
systrayCreator = new QTimer ( this ) ;
connect ( systrayCreator , SIGNAL ( timeout ( ) ) , this , SLOT ( createSystrayDelayed ( ) ) ) ;
systrayCreator - > setSingleShot ( true ) ;
systrayCreator - > start ( 2000 ) ;
qDebug ( " Info: System tray is unavailable, trying again later. " ) ;
} else {
qDebug ( " Warning: System tray is unavailable. " ) ;
}
} else {
createTrayIcon ( ) ;
}
2009-11-14 22:08:28 +03:00
} else {
// Destroy trayicon
2009-11-18 21:45:06 +03:00
delete systrayIcon ;
2009-11-14 22:08:28 +03:00
delete myTrayIconMenu ;
}
}
2009-11-06 17:30:14 +03:00
// General
2010-11-16 23:34:31 +03:00
if ( pref . isToolbarDisplayed ( ) ) {
2009-11-06 17:30:14 +03:00
toolBar - > setVisible ( true ) ;
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
} else {
2010-08-22 12:54:33 +04:00
// Clear search filter before hiding the top toolbar
search_filter - > clear ( ) ;
2009-11-06 17:30:14 +03:00
toolBar - > setVisible ( false ) ;
}
2010-11-16 23:34:31 +03:00
const uint new_refreshInterval = pref . getRefreshInterval ( ) ;
2009-11-07 22:55:33 +03:00
transferList - > setRefreshInterval ( new_refreshInterval ) ;
2010-11-16 23:34:31 +03:00
transferList - > setAlternatingRowColors ( pref . useAlternatingRowColors ( ) ) ;
properties - > getFilesList ( ) - > setAlternatingRowColors ( pref . useAlternatingRowColors ( ) ) ;
properties - > getTrackerList ( ) - > setAlternatingRowColors ( pref . useAlternatingRowColors ( ) ) ;
properties - > getPeerList ( ) - > setAlternatingRowColors ( pref . useAlternatingRowColors ( ) ) ;
2009-11-06 17:30:14 +03:00
// Queueing System
2010-11-16 23:34:31 +03:00
if ( pref . isQueueingSystemEnabled ( ) ) {
2010-10-18 21:06:11 +04:00
if ( ! actionDecreasePriority - > isVisible ( ) ) {
2009-11-07 22:55:33 +03:00
transferList - > hidePriorityColumn ( false ) ;
2009-11-06 17:30:14 +03:00
actionDecreasePriority - > setVisible ( true ) ;
actionIncreasePriority - > setVisible ( true ) ;
prioSeparator - > setVisible ( true ) ;
prioSeparator2 - > setVisible ( true ) ;
2009-08-16 07:09:20 +04:00
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
}
2009-11-06 17:30:14 +03:00
} else {
2010-10-18 21:06:11 +04:00
if ( actionDecreasePriority - > isVisible ( ) ) {
2009-11-07 22:55:33 +03:00
transferList - > hidePriorityColumn ( true ) ;
2009-11-06 17:30:14 +03:00
actionDecreasePriority - > setVisible ( false ) ;
actionIncreasePriority - > setVisible ( false ) ;
prioSeparator - > setVisible ( false ) ;
prioSeparator2 - > setVisible ( false ) ;
toolBar - > layout ( ) - > setSpacing ( 7 ) ;
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
}
2009-11-14 22:08:28 +03:00
2009-11-15 13:00:07 +03:00
// Torrent properties
properties - > reloadPreferences ( ) ;
2009-11-14 22:08:28 +03:00
if ( configure_session )
BTSession - > configureSession ( ) ;
qDebug ( " GUI settings loaded " ) ;
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : addUnauthenticatedTracker ( const QPair < QTorrentHandle , QString > & tracker ) {
2009-11-06 17:30:14 +03:00
// Trackers whose authentication was cancelled
if ( unauthenticated_trackers . indexOf ( tracker ) < 0 ) {
unauthenticated_trackers < < tracker ;
}
}
// Called when a tracker requires authentication
2010-11-14 00:15:52 +03:00
void MainWindow : : trackerAuthenticationRequired ( QTorrentHandle & h ) {
2009-11-06 17:30:14 +03:00
if ( unauthenticated_trackers . indexOf ( QPair < QTorrentHandle , QString > ( h , h . current_tracker ( ) ) ) < 0 ) {
// Tracker login
new trackerLogin ( this , h ) ;
}
}
// Check connection status and display right icon
2010-11-14 00:15:52 +03:00
void MainWindow : : updateGUI ( ) {
2009-11-06 17:30:14 +03:00
// update global informations
2009-11-18 21:45:06 +03:00
if ( systrayIcon ) {
2010-10-09 19:36:39 +04:00
# if defined(Q_WS_X11) || defined(Q_WS_MAC)
2009-11-06 17:30:14 +03:00
QString html = " <div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'> " ;
html + = tr ( " qBittorrent " ) ;
html + = " </div> " ;
html + = " <div style='vertical-align: baseline; height: 18px;'> " ;
2010-03-03 17:42:57 +03:00
html + = " <img src=':/Icons/skin/download.png'/> " + tr ( " DL speed: %1 KiB/s " , " e.g: Download speed: 10 KiB/s " ) . arg ( QString : : number ( BTSession - > getPayloadDownloadRate ( ) / 1024. , ' f ' , 1 ) ) ;
2009-11-06 17:30:14 +03:00
html + = " </div> " ;
html + = " <div style='vertical-align: baseline; height: 18px;'> " ;
2010-03-03 17:42:57 +03:00
html + = " <img src=':/Icons/skin/seeding.png'/> " + tr ( " UP speed: %1 KiB/s " , " e.g: Upload speed: 10 KiB/s " ) . arg ( QString : : number ( BTSession - > getPayloadUploadRate ( ) / 1024. , ' f ' , 1 ) ) ;
2009-11-06 17:30:14 +03:00
html + = " </div> " ;
2010-03-30 15:35:20 +04:00
# else
// OSes such as Windows do not support html here
QString html = tr ( " DL speed: %1 KiB/s " , " e.g: Download speed: 10 KiB/s " ) . arg ( QString : : number ( BTSession - > getPayloadDownloadRate ( ) / 1024. , ' f ' , 1 ) ) ;
html + = " \n " ;
html + = tr ( " UP speed: %1 KiB/s " , " e.g: Upload speed: 10 KiB/s " ) . arg ( QString : : number ( BTSession - > getPayloadUploadRate ( ) / 1024. , ' f ' , 1 ) ) ;
2009-01-04 20:08:52 +03:00
# endif
2009-11-18 21:45:06 +03:00
systrayIcon - > setToolTip ( html ) ; // tray icon
2006-09-30 20:02:39 +04:00
}
2009-11-18 16:18:55 +03:00
if ( displaySpeedInTitle ) {
2009-11-23 15:57:16 +03:00
setWindowTitle ( tr ( " qBittorrent %1 (Down: %2/s, Up: %3/s) " , " %1 is qBittorrent version " ) . arg ( QString : : fromUtf8 ( VERSION ) ) . arg ( misc : : friendlyUnit ( BTSession - > getSessionStatus ( ) . payload_download_rate ) ) . arg ( misc : : friendlyUnit ( BTSession - > getSessionStatus ( ) . payload_upload_rate ) ) ) ;
2009-11-06 17:30:14 +03:00
}
}
2010-11-14 00:15:52 +03:00
void MainWindow : : showNotificationBaloon ( QString title , QString msg ) const {
2010-11-16 23:34:31 +03:00
if ( ! Preferences ( ) . useProgramNotification ( ) ) return ;
2009-11-25 23:32:18 +03:00
# ifdef WITH_LIBNOTIFY
2010-06-22 18:18:43 +04:00
if ( notify_init ( " summary-body " ) ) {
NotifyNotification * notification ;
2010-11-06 12:24:09 +03:00
notification = notify_notification_new ( qPrintable ( title ) , qPrintable ( msg ) , " qbittorrent "
# if !defined(NOTIFY_VERSION_MINOR) || (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
, 0
# endif
) ;
2010-06-22 18:18:43 +04:00
gboolean success = notify_notification_show ( notification , NULL ) ;
g_object_unref ( G_OBJECT ( notification ) ) ;
notify_uninit ( ) ;
if ( success ) {
return ;
2009-11-25 23:32:18 +03:00
}
2010-06-22 18:18:43 +04:00
}
2009-11-26 01:36:42 +03:00
# endif
2010-06-22 18:18:43 +04:00
if ( systrayIcon & & QSystemTrayIcon : : supportsMessages ( ) )
systrayIcon - > showMessage ( title , msg , QSystemTrayIcon : : Information , TIME_TRAY_BALLOON ) ;
2009-11-07 22:55:33 +03:00
}
2009-11-06 17:30:14 +03:00
/*****************************************************
2006-09-30 20:02:39 +04:00
* *
* Utils *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-11-06 17:30:14 +03:00
2010-11-14 00:15:52 +03:00
void MainWindow : : downloadFromURLList ( const QStringList & url_list ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
2010-03-03 17:42:57 +03:00
const bool useTorrentAdditionDialog = settings . value ( QString : : fromUtf8 ( " Preferences/Downloads/AdditionDialog " ) , true ) . toBool ( ) ;
2010-07-23 02:19:42 +04:00
foreach ( QString url , url_list ) {
if ( url . startsWith ( " bc://bt/ " , Qt : : CaseInsensitive ) ) {
qDebug ( " Converting bc link to magnet link " ) ;
url = misc : : bcLinkToMagnet ( url ) ;
}
2009-11-06 17:30:14 +03:00
if ( url . startsWith ( " magnet: " , Qt : : CaseInsensitive ) ) {
2010-01-03 17:20:31 +03:00
if ( useTorrentAdditionDialog ) {
2010-11-14 00:15:52 +03:00
torrentAdditionDialog * dialog = new torrentAdditionDialog ( this ) ;
2010-01-03 17:20:31 +03:00
dialog - > showLoadMagnetURI ( url ) ;
} else {
BTSession - > addMagnetUri ( url ) ;
}
2009-11-06 17:30:14 +03:00
} else {
BTSession - > downloadFromUrl ( url ) ;
2009-08-17 09:14:03 +04:00
}
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
}
/*****************************************************
2006-09-30 20:02:39 +04:00
* *
* Options *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-11-06 17:30:14 +03:00
2010-11-14 00:15:52 +03:00
void MainWindow : : createSystrayDelayed ( ) {
2009-11-18 21:45:06 +03:00
static int timeout = 20 ;
2009-11-06 17:30:14 +03:00
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
// Ok, systray integration is now supported
// Create systray icon
createTrayIcon ( ) ;
delete systrayCreator ;
} else {
if ( timeout ) {
// Retry a bit later
2009-11-18 21:45:06 +03:00
systrayCreator - > start ( 2000 ) ;
2009-11-06 17:30:14 +03:00
- - timeout ;
2008-01-04 23:09:37 +03:00
} else {
2009-11-06 17:30:14 +03:00
// Timed out, apparently system really does not
// support systray icon
delete systrayCreator ;
2009-11-18 21:45:06 +03:00
// Disable it in program preferences to
// avoid trying at earch startup
2010-11-16 23:34:31 +03:00
Preferences ( ) . setSystrayIntegration ( false ) ;
2008-01-04 23:09:37 +03:00
}
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : updateAltSpeedsBtn ( bool alternative ) {
2010-06-22 18:18:43 +04:00
actionUse_alternative_speed_limits - > setChecked ( alternative ) ;
2010-01-23 23:44:09 +03:00
}
2010-11-14 00:15:52 +03:00
QMenu * MainWindow : : getTrayIconMenu ( ) {
2010-06-09 19:40:55 +04:00
if ( myTrayIconMenu )
return myTrayIconMenu ;
2009-11-06 17:30:14 +03:00
// Tray icon Menu
myTrayIconMenu = new QMenu ( this ) ;
myTrayIconMenu - > addAction ( actionOpen ) ;
myTrayIconMenu - > addAction ( actionDownload_from_URL ) ;
myTrayIconMenu - > addSeparator ( ) ;
2010-11-16 23:34:31 +03:00
const bool isAltBWEnabled = Preferences ( ) . isAltBandwidthEnabled ( ) ;
updateAltSpeedsBtn ( isAltBWEnabled ) ;
actionUse_alternative_speed_limits - > setChecked ( isAltBWEnabled ) ;
2010-01-23 23:44:09 +03:00
myTrayIconMenu - > addAction ( actionUse_alternative_speed_limits ) ;
2009-11-06 17:30:14 +03:00
myTrayIconMenu - > addAction ( actionSet_global_download_limit ) ;
myTrayIconMenu - > addAction ( actionSet_global_upload_limit ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionStart_All ) ;
myTrayIconMenu - > addAction ( actionPause_All ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionExit ) ;
2010-08-22 23:08:15 +04:00
if ( ui_locked )
myTrayIconMenu - > setEnabled ( false ) ;
2010-06-09 19:40:55 +04:00
return myTrayIconMenu ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : createTrayIcon ( ) {
2010-06-09 19:40:55 +04:00
// Tray icon
# ifdef Q_WS_WIN
systrayIcon = new QSystemTrayIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/qbittorrent16.png " ) ) , this ) ;
# else
systrayIcon = new QSystemTrayIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/qbittorrent22.png " ) ) , this ) ;
# endif
systrayIcon - > setContextMenu ( getTrayIconMenu ( ) ) ;
2009-11-18 21:45:06 +03:00
connect ( systrayIcon , SIGNAL ( messageClicked ( ) ) , this , SLOT ( balloonClicked ( ) ) ) ;
2009-11-06 17:30:14 +03:00
// End of Icon Menu
2009-11-18 21:45:06 +03:00
connect ( systrayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( toggleVisibility ( QSystemTrayIcon : : ActivationReason ) ) ) ;
systrayIcon - > show ( ) ;
2009-11-06 17:30:14 +03:00
}
// Display Program Options
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionOptions_triggered ( ) {
2010-03-03 17:42:57 +03:00
if ( options ) {
2010-03-03 16:07:27 +03:00
// Get focus
options - > setFocus ( ) ;
2010-03-03 17:42:57 +03:00
} else {
options = new options_imp ( this ) ;
connect ( options , SIGNAL ( status_changed ( ) ) , this , SLOT ( optionsSaved ( ) ) ) ;
2010-02-10 02:32:54 +03:00
}
2009-11-06 17:30:14 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionTop_tool_bar_triggered ( ) {
2010-06-22 18:18:43 +04:00
bool is_visible = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
toolBar - > setVisible ( is_visible ) ;
2010-11-16 23:34:31 +03:00
Preferences ( ) . setToolbarDisplayed ( is_visible ) ;
2010-06-21 22:32:01 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionShutdown_when_downloads_complete_triggered ( ) {
2010-08-16 21:35:32 +04:00
bool is_checked = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
2010-11-16 23:34:31 +03:00
Preferences ( ) . setShutdownWhenDownloadsComplete ( is_checked ) ;
2010-08-16 21:35:32 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionShutdown_qBittorrent_when_downloads_complete_triggered ( ) {
2010-10-09 18:57:41 +04:00
bool is_checked = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
2010-11-16 23:34:31 +03:00
Preferences ( ) . setShutdownqBTWhenDownloadsComplete ( is_checked ) ;
2010-10-09 18:57:41 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionSpeed_in_title_bar_triggered ( ) {
2010-06-22 18:18:43 +04:00
displaySpeedInTitle = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
2010-11-16 23:34:31 +03:00
Preferences ( ) . showSpeedInTitleBar ( displaySpeedInTitle ) ;
2010-06-22 18:18:43 +04:00
if ( displaySpeedInTitle )
updateGUI ( ) ;
else
setWindowTitle ( tr ( " qBittorrent %1 " , " e.g: qBittorrent v0.x " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
2010-06-21 22:32:01 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionRSS_Reader_triggered ( ) {
2010-10-31 15:03:24 +03:00
RssSettings : : setRSSEnabled ( actionRSS_Reader - > isChecked ( ) ) ;
2010-06-22 17:39:49 +04:00
displayRSSTab ( actionRSS_Reader - > isChecked ( ) ) ;
}
2010-06-21 22:32:01 +04:00
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionSearch_engine_triggered ( ) {
2010-11-16 23:34:31 +03:00
Preferences ( ) . setSearchEnabled ( actionSearch_engine - > isChecked ( ) ) ;
2010-06-22 17:58:22 +04:00
displaySearchTab ( actionSearch_engine - > isChecked ( ) ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_action_Import_Torrent_triggered ( )
2010-10-23 20:21:56 +04:00
{
2010-11-14 00:15:52 +03:00
TorrentImportDlg : : importTorrent ( ) ;
2010-10-23 20:21:56 +04:00
}
2009-11-06 17:30:14 +03:00
/*****************************************************
2006-09-30 20:02:39 +04:00
* *
* HTTP Downloader *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-11-06 17:30:14 +03:00
// Display an input dialog to prompt user for
// an url
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionDownload_from_URL_triggered ( ) {
2010-03-10 23:21:56 +03:00
if ( ! downloadFromURLDialog ) {
downloadFromURLDialog = new downloadFromURL ( this ) ;
connect ( downloadFromURLDialog , SIGNAL ( urlsReadyToBeDownloaded ( const QStringList & ) ) , this , SLOT ( downloadFromURLList ( const QStringList & ) ) ) ;
}
2009-11-06 17:30:14 +03:00
}
2010-06-22 17:58:22 +04:00
2010-10-24 01:46:05 +04:00
# if defined(Q_WS_WIN) || defined(Q_WS_MAC)
void GUI : : handleUpdateCheckFinished ( bool update_available , QString new_version )
{
if ( update_available ) {
if ( QMessageBox : : question ( this , tr ( " A newer version is available " ) ,
tr ( " A newer version of qBittorrent is available on Sourceforge. \n Would you like to update qBittorrent to version %1? " ) . arg ( new_version ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
// The user want to update, let's download the update
ProgramUpdater * updater = dynamic_cast < ProgramUpdater * > ( sender ( ) ) ;
connect ( updater , SIGNAL ( updateInstallFinished ( QString ) ) , SLOT ( handleUpdateInstalled ( QString ) ) ) ;
updater - > updateProgram ( ) ;
return ;
}
}
sender ( ) - > deleteLater ( ) ;
}
void GUI : : handleUpdateInstalled ( QString error_msg )
{
if ( ! error_msg . isEmpty ( ) ) {
QMessageBox : : critical ( this , tr ( " Impossible to update qBittorrent " ) , tr ( " qBittorrent failed to update, reason: %1 " ) . arg ( error_msg ) ) ;
}
}
# endif
2010-10-31 15:03:24 +03:00
2010-11-14 00:15:52 +03:00
void MainWindow : : on_actionDonate_money_triggered ( )
2010-10-31 15:03:24 +03:00
{
2010-11-08 21:17:54 +03:00
QDesktopServices : : openUrl ( QUrl ( " http://sourceforge.net/donate/index.php?group_id=163414 " ) ) ;
}
2010-11-14 00:15:52 +03:00
void MainWindow : : showConnectionSettings ( )
2010-11-08 21:17:54 +03:00
{
on_actionOptions_triggered ( ) ;
options - > showConnectionTab ( ) ;
2010-10-31 15:03:24 +03:00
}