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
*/
2011-04-02 12:54:28 +04:00
# include <QtGlobal>
2013-09-21 11:59:58 +04:00
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
2011-04-02 12:54:28 +04:00
# include <QDBusConnection>
# include "notifications.h"
2009-11-25 23:32:18 +03:00
# 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>
2013-09-21 11:59:58 +04:00
# include <QMimeData>
2014-07-05 16:44:13 +04:00
# include <QCryptographicHash>
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"
2015-05-06 14:53:27 +03:00
# include "core/utils/misc.h"
2010-10-23 00:13:22 +04:00
# include "torrentcreatordlg.h"
2009-11-20 10:48:44 +03:00
# include "downloadfromurldlg.h"
2012-05-15 20:57:31 +04:00
# include "addnewtorrentdialog.h"
2009-11-20 10:48:44 +03:00
# include "searchengine.h"
2007-03-29 19:43:08 +04:00
# include "rss_imp.h"
2015-04-19 18:17:47 +03:00
# include "core/bittorrent/session.h"
# include "core/bittorrent/sessionstatus.h"
# include "core/bittorrent/torrenthandle.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"
2015-04-13 19:19:53 +03:00
# include "core/preferences.h"
2010-01-13 02:16:18 +03:00
# include "trackerlist.h"
# include "peerlistwidget.h"
2009-11-20 10:48:44 +03:00
# 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-10-23 20:21:56 +04:00
# include "torrentimportdlg.h"
2010-11-14 18:28:22 +03:00
# include "torrentmodel.h"
2010-12-20 21:07:36 +03:00
# include "executionlog.h"
2015-04-19 18:17:47 +03:00
# include "guiiconprovider.h"
2015-04-13 19:19:53 +03:00
# include "core/logger.h"
2013-07-22 15:46:10 +04:00
# include "autoexpandabledialog.h"
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_MAC
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"
2015-01-22 15:56:16 +03:00
# include "application.h"
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_WIN) || defined(Q_OS_MAC)
2010-10-24 01:46:05 +04:00
# include "programupdater.h"
# endif
2011-02-06 17:27:34 +03:00
# include "powermanagement.h"
2014-09-14 15:30:22 +04:00
# ifdef Q_OS_WIN
2015-04-19 18:17:47 +03:00
# include "core/net/downloadmanager.h"
# include "core/net/downloadhandler.h"
2014-09-14 15:30:22 +04:00
# endif
2007-03-04 20:13:29 +03:00
2009-11-26 01:36:42 +03:00
# define TIME_TRAY_BALLOON 5000
2011-02-06 17:27:34 +03:00
# define PREVENT_SUSPEND_INTERVAL 60000
2009-11-26 01:36:42 +03:00
2006-09-30 20:02:39 +04:00
/*****************************************************
2014-12-20 20:53:58 +03:00
* *
* GUI *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-30 20:02:39 +04:00
// Constructor
2015-01-22 15:56:16 +03:00
MainWindow : : MainWindow ( QWidget * parent )
: QMainWindow ( parent )
, m_posInitialized ( false )
, force_exit ( false )
, unlockDlgShowing ( false )
2014-09-14 15:30:22 +04:00
# ifdef Q_OS_WIN
2014-12-20 20:53:58 +03:00
, has_python ( false )
2014-09-14 15:30:22 +04:00
# endif
{
2014-12-20 20:53:58 +03:00
setupUi ( this ) ;
2011-04-09 21:39:51 +04:00
2014-12-20 20:53:58 +03:00
Preferences * const pref = Preferences : : instance ( ) ;
ui_locked = pref - > isUILocked ( ) ;
setWindowTitle ( QString ( " qBittorrent %1 " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
displaySpeedInTitle = pref - > speedInTitleBar ( ) ;
// Setting icons
2013-09-21 11:59:58 +04:00
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
2014-12-20 20:53:58 +03:00
if ( Preferences : : instance ( ) - > useSystemIconTheme ( ) )
2015-01-18 15:13:06 +03:00
setWindowIcon ( QIcon : : fromTheme ( " qbittorrent " , QIcon ( QString : : fromUtf8 ( " :/icons/skin/qbittorrent32.png " ) ) ) ) ;
2014-12-20 20:53:58 +03:00
else
2012-08-23 22:19:50 +04:00
# endif
2015-01-18 15:13:06 +03:00
setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/qbittorrent32.png " ) ) ) ;
2013-03-11 22:50:32 +04:00
2014-10-18 18:18:58 +04:00
addToolbarContextMenu ( ) ;
2015-04-19 18:17:47 +03:00
actionOpen - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " list-add " ) ) ;
actionDownload_from_URL - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " insert-link " ) ) ;
2015-01-18 15:13:06 +03:00
actionSet_upload_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/seeding.png " ) ) ) ;
actionSet_download_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/download.png " ) ) ) ;
actionSet_global_upload_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/seeding.png " ) ) ) ;
actionSet_global_download_limit - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/download.png " ) ) ) ;
2015-04-19 18:17:47 +03:00
actionCreate_torrent - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " document-edit " ) ) ;
actionAbout - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " help-about " ) ) ;
actionStatistics - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " view-statistics " ) ) ;
actionDecreasePriority - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " go-down " ) ) ;
actionBottomPriority - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " go-bottom " ) ) ;
actionDelete - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " list-remove " ) ) ;
actionDocumentation - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " help-contents " ) ) ;
actionDonate_money - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " wallet-open " ) ) ;
actionExit - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " application-exit " ) ) ;
actionIncreasePriority - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " go-up " ) ) ;
actionTopPriority - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " go-top " ) ) ;
actionLock_qBittorrent - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " object-locked " ) ) ;
actionOptions - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " preferences-system " ) ) ;
actionPause - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " media-playback-pause " ) ) ;
actionPause_All - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " media-playback-pause " ) ) ;
actionStart - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " media-playback-start " ) ) ;
actionStart_All - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " media-playback-start " ) ) ;
action_Import_Torrent - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " document-import " ) ) ;
menuAuto_Shutdown_on_downloads_completion - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " application-exit " ) ) ;
2014-12-20 20:53:58 +03:00
QMenu * startAllMenu = new QMenu ( this ) ;
startAllMenu - > addAction ( actionStart_All ) ;
actionStart - > setMenu ( startAllMenu ) ;
QMenu * pauseAllMenu = new QMenu ( this ) ;
pauseAllMenu - > addAction ( actionPause_All ) ;
actionPause - > setMenu ( pauseAllMenu ) ;
QMenu * lockMenu = new QMenu ( this ) ;
2015-04-08 08:27:46 +03:00
QAction * defineUiLockPasswdAct = lockMenu - > addAction ( tr ( " &Set Password " ) ) ;
2014-12-20 20:53:58 +03:00
connect ( defineUiLockPasswdAct , SIGNAL ( triggered ( ) ) , this , SLOT ( defineUILockPassword ( ) ) ) ;
2015-04-08 08:27:46 +03:00
QAction * clearUiLockPasswdAct = lockMenu - > addAction ( tr ( " &Clear Password " ) ) ;
2014-12-20 20:53:58 +03:00
connect ( clearUiLockPasswdAct , SIGNAL ( triggered ( ) ) , this , SLOT ( clearUILockPassword ( ) ) ) ;
actionLock_qBittorrent - > setMenu ( lockMenu ) ;
2015-01-26 17:00:23 +03:00
2014-12-20 20:53:58 +03:00
// Creating Bittorrent session
2015-04-19 18:17:47 +03:00
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( fullDiskError ( BitTorrent : : TorrentHandle * const , QString ) ) , this , SLOT ( fullDiskError ( BitTorrent : : TorrentHandle * const , QString ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( addTorrentFailed ( const QString & ) ) , this , SLOT ( addTorrentFailed ( const QString & ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( torrentFinished ( BitTorrent : : TorrentHandle * const ) ) , this , SLOT ( finishedTorrent ( BitTorrent : : TorrentHandle * const ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackerAuthenticationRequired ( BitTorrent : : TorrentHandle * const ) ) , this , SLOT ( trackerAuthenticationRequired ( BitTorrent : : TorrentHandle * const ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( downloadFromUrlFailed ( QString , QString ) ) , this , SLOT ( handleDownloadFromUrlFailure ( QString , QString ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( speedLimitModeChanged ( bool ) ) , this , SLOT ( updateAltSpeedsBtn ( bool ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( recursiveTorrentDownloadPossible ( BitTorrent : : TorrentHandle * const ) ) , this , SLOT ( askRecursiveTorrentDownloadConfirmation ( BitTorrent : : TorrentHandle * const ) ) ) ;
2009-11-07 22:55:33 +03:00
2014-12-20 20:53:58 +03:00
qDebug ( " create tabWidget " ) ;
2015-01-26 17:00:23 +03:00
tabs = new HidableTabWidget ( this ) ;
2014-12-20 20:53:58 +03:00
connect ( tabs , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( tab_changed ( int ) ) ) ;
2015-01-26 17:00:23 +03:00
vSplitter = new QSplitter ( Qt : : Horizontal , this ) ;
2014-12-20 20:53:58 +03:00
//vSplitter->setChildrenCollapsible(false);
2015-01-26 17:00:23 +03:00
hSplitter = new QSplitter ( Qt : : Vertical , this ) ;
2014-12-20 20:53:58 +03:00
hSplitter - > setChildrenCollapsible ( false ) ;
hSplitter - > setContentsMargins ( 0 , 4 , 0 , 0 ) ;
// Name filter
2015-01-26 17:00:23 +03:00
search_filter = new LineEdit ( this ) ;
2014-12-20 20:53:58 +03:00
searchFilterAct = toolBar - > insertWidget ( actionLock_qBittorrent , search_filter ) ;
search_filter - > setPlaceholderText ( tr ( " Filter torrent list... " ) ) ;
search_filter - > setFixedWidth ( 200 ) ;
2015-01-26 17:00:23 +03:00
2014-12-20 20:53:58 +03:00
QWidget * spacer = new QWidget ( this ) ;
spacer - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
toolBar - > insertWidget ( searchFilterAct , spacer ) ;
// Transfer List tab
2015-04-19 18:17:47 +03:00
transferList = new TransferListWidget ( hSplitter , this ) ;
2014-12-20 20:53:58 +03:00
properties = new PropertiesWidget ( hSplitter , this , transferList ) ;
transferListFilters = new TransferListFiltersWidget ( vSplitter , transferList ) ;
hSplitter - > addWidget ( transferList ) ;
hSplitter - > addWidget ( properties ) ;
vSplitter - > addWidget ( transferListFilters ) ;
vSplitter - > addWidget ( hSplitter ) ;
vSplitter - > setCollapsible ( 0 , true ) ;
vSplitter - > setCollapsible ( 1 , false ) ;
2015-04-19 18:17:47 +03:00
tabs - > addTab ( vSplitter , GuiIconProvider : : instance ( ) - > getIcon ( " folder-remote " ) , tr ( " Transfers " ) ) ;
2014-12-20 20:53:58 +03:00
connect ( search_filter , SIGNAL ( textChanged ( QString ) ) , transferList , SLOT ( applyNameFilter ( QString ) ) ) ;
connect ( hSplitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( writeSettings ( ) ) ) ;
connect ( vSplitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( writeSettings ( ) ) ) ;
2015-04-19 18:17:47 +03:00
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackersChanged ( BitTorrent : : TorrentHandle * const ) ) , properties , SLOT ( loadTrackers ( BitTorrent : : TorrentHandle * const ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackersAdded ( BitTorrent : : TorrentHandle * const , const QList < BitTorrent : : TrackerEntry > & ) ) , transferListFilters , SLOT ( addTrackers ( BitTorrent : : TorrentHandle * const , const QList < BitTorrent : : TrackerEntry > & ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackersRemoved ( BitTorrent : : TorrentHandle * const , const QList < BitTorrent : : TrackerEntry > & ) ) , transferListFilters , SLOT ( removeTrackers ( BitTorrent : : TorrentHandle * const , const QList < BitTorrent : : TrackerEntry > & ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackerlessStateChanged ( BitTorrent : : TorrentHandle * const , bool ) ) , transferListFilters , SLOT ( changeTrackerless ( BitTorrent : : TorrentHandle * const , bool ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackerSuccess ( BitTorrent : : TorrentHandle * const , const QString & ) ) , transferListFilters , SLOT ( trackerSuccess ( BitTorrent : : TorrentHandle * const , const QString & ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackerError ( BitTorrent : : TorrentHandle * const , const QString & ) ) , transferListFilters , SLOT ( trackerError ( BitTorrent : : TorrentHandle * const , const QString & ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( trackerWarning ( BitTorrent : : TorrentHandle * const , const QString & ) ) , transferListFilters , SLOT ( trackerWarning ( BitTorrent : : TorrentHandle * const , const QString & ) ) ) ;
2014-12-20 20:53:58 +03:00
vboxLayout - > addWidget ( tabs ) ;
prioSeparator = toolBar - > insertSeparator ( actionBottomPriority ) ;
prioSeparatorMenu = menu_Edit - > insertSeparator ( actionTopPriority ) ;
// Transfer list slots
connect ( actionStart , SIGNAL ( triggered ( ) ) , transferList , SLOT ( startSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
connect ( actionStart_All , SIGNAL ( triggered ( ) ) , transferList , SLOT ( resumeAllTorrents ( ) ) ) ;
2014-12-20 20:53:58 +03:00
connect ( actionPause , SIGNAL ( triggered ( ) ) , transferList , SLOT ( pauseSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
connect ( actionPause_All , SIGNAL ( triggered ( ) ) , transferList , SLOT ( pauseAllTorrents ( ) ) ) ;
2014-12-20 20:53:58 +03:00
connect ( actionDelete , SIGNAL ( triggered ( ) ) , transferList , SLOT ( deleteSelectedTorrents ( ) ) ) ;
connect ( actionTopPriority , SIGNAL ( triggered ( ) ) , transferList , SLOT ( topPrioSelectedTorrents ( ) ) ) ;
connect ( actionIncreasePriority , SIGNAL ( triggered ( ) ) , transferList , SLOT ( increasePrioSelectedTorrents ( ) ) ) ;
connect ( actionDecreasePriority , SIGNAL ( triggered ( ) ) , transferList , SLOT ( decreasePrioSelectedTorrents ( ) ) ) ;
connect ( actionBottomPriority , SIGNAL ( triggered ( ) ) , transferList , SLOT ( bottomPrioSelectedTorrents ( ) ) ) ;
connect ( actionToggleVisibility , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleVisibility ( ) ) ) ;
connect ( actionMinimize , SIGNAL ( triggered ( ) ) , SLOT ( minimizeWindow ( ) ) ) ;
2009-11-07 22:55:33 +03:00
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_WIN) || defined(Q_OS_MAC)
2014-12-20 20:53:58 +03:00
programUpdateTimer . setInterval ( 60 * 60 * 1000 ) ;
programUpdateTimer . setSingleShot ( true ) ;
connect ( & programUpdateTimer , SIGNAL ( timeout ( ) ) , SLOT ( checkProgramUpdate ( ) ) ) ;
connect ( actionCheck_for_updates , SIGNAL ( triggered ( ) ) , SLOT ( checkProgramUpdate ( ) ) ) ;
2013-11-23 16:58:03 +04:00
# else
2014-12-20 20:53:58 +03:00
actionCheck_for_updates - > setVisible ( false ) ;
2013-11-23 16:58:03 +04:00
# endif
2014-12-20 20:53:58 +03:00
m_pwr = new PowerManagement ( this ) ;
preventTimer = new QTimer ( this ) ;
connect ( preventTimer , SIGNAL ( timeout ( ) ) , SLOT ( checkForActiveTorrents ( ) ) ) ;
// Configure BT session according to options
loadPreferences ( false ) ;
2015-04-19 18:17:47 +03:00
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( torrentsUpdated ( ) ) , this , SLOT ( updateGUI ( ) ) ) ;
2014-12-20 20:53:58 +03:00
// Accept drag 'n drops
setAcceptDrops ( true ) ;
createKeyboardShortcuts ( ) ;
// Create status bar
status_bar = new StatusBar ( QMainWindow : : statusBar ( ) ) ;
connect ( status_bar - > connectionStatusButton ( ) , SIGNAL ( clicked ( ) ) , SLOT ( showConnectionSettings ( ) ) ) ;
connect ( actionUse_alternative_speed_limits , SIGNAL ( triggered ( ) ) , status_bar , SLOT ( toggleAlternativeSpeeds ( ) ) ) ;
2009-11-08 15:23:04 +03:00
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_MAC
2014-12-20 20:53:58 +03:00
setUnifiedTitleAndToolBarOnMac ( true ) ;
2010-06-09 11:37:05 +04:00
# endif
2014-12-20 20:53:58 +03:00
// View settings
actionTop_tool_bar - > setChecked ( pref - > isToolbarDisplayed ( ) ) ;
actionSpeed_in_title_bar - > setChecked ( pref - > speedInTitleBar ( ) ) ;
actionRSS_Reader - > setChecked ( pref - > isRSSEnabled ( ) ) ;
actionSearch_engine - > setChecked ( pref - > isSearchEnabled ( ) ) ;
actionExecution_Logs - > setChecked ( pref - > isExecutionLogEnabled ( ) ) ;
displayRSSTab ( actionRSS_Reader - > isChecked ( ) ) ;
on_actionExecution_Logs_triggered ( actionExecution_Logs - > isChecked ( ) ) ;
if ( actionSearch_engine - > isChecked ( ) )
QTimer : : singleShot ( 0 , this , SLOT ( on_actionSearch_engine_triggered ( ) ) ) ;
// Auto shutdown actions
2015-01-26 17:00:23 +03:00
QActionGroup * autoShutdownGroup = new QActionGroup ( this ) ;
2014-12-20 20:53:58 +03:00
autoShutdownGroup - > setExclusive ( true ) ;
autoShutdownGroup - > addAction ( actionAutoShutdown_Disabled ) ;
autoShutdownGroup - > addAction ( actionAutoExit_qBittorrent ) ;
autoShutdownGroup - > addAction ( actionAutoShutdown_system ) ;
autoShutdownGroup - > addAction ( actionAutoSuspend_system ) ;
autoShutdownGroup - > addAction ( actionAutoHibernate_system ) ;
2013-09-21 11:59:58 +04:00
# if (!defined(Q_OS_UNIX) || defined(Q_OS_MAC)) || defined(QT_DBUS_LIB)
2014-12-20 20:53:58 +03:00
actionAutoShutdown_system - > setChecked ( pref - > shutdownWhenDownloadsComplete ( ) ) ;
actionAutoSuspend_system - > setChecked ( pref - > suspendWhenDownloadsComplete ( ) ) ;
actionAutoHibernate_system - > setChecked ( pref - > hibernateWhenDownloadsComplete ( ) ) ;
2011-03-07 23:25:20 +03:00
# else
2014-12-20 20:53:58 +03:00
actionAutoShutdown_system - > setDisabled ( true ) ;
actionAutoSuspend_system - > setDisabled ( true ) ;
actionAutoHibernate_system - > setDisabled ( true ) ;
2011-03-07 23:22:35 +03:00
# endif
2014-12-20 20:53:58 +03:00
actionAutoExit_qBittorrent - > setChecked ( pref - > shutdownqBTWhenDownloadsComplete ( ) ) ;
2011-03-07 23:22:35 +03:00
2014-12-20 20:53:58 +03:00
if ( ! autoShutdownGroup - > checkedAction ( ) )
actionAutoShutdown_Disabled - > setChecked ( true ) ;
2010-06-21 22:32:01 +04:00
2014-12-20 20:53:58 +03:00
// Load Window state and sizes
readSettings ( ) ;
2009-11-08 15:23:04 +03:00
2014-12-20 20:53:58 +03:00
if ( systrayIcon ) {
if ( ! ( pref - > startMinimized ( ) | | ui_locked ) ) {
show ( ) ;
activateWindow ( ) ;
raise ( ) ;
}
2015-06-20 23:28:40 +03:00
else if ( pref - > startMinimized ( ) ) {
if ( pref - > minimizeToTray ( ) )
create ( ) ;
else
showMinimized ( ) ;
2015-04-21 12:58:21 +03:00
}
}
else {
// Make sure the Window is visible if we don't have a tray icon
if ( pref - > startMinimized ( ) ) {
showMinimized ( ) ;
}
else {
show ( ) ;
activateWindow ( ) ;
raise ( ) ;
}
2011-01-17 20:29:25 +03:00
}
2009-11-08 15:23:04 +03:00
2014-12-20 20:53:58 +03:00
properties - > readSettings ( ) ;
2011-02-06 00:27:13 +03:00
2014-12-20 20:53:58 +03:00
// Start watching the executable for updates
2015-01-26 17:00:23 +03:00
executable_watcher = new QFileSystemWatcher ( this ) ;
2014-12-20 20:53:58 +03:00
connect ( executable_watcher , SIGNAL ( fileChanged ( QString ) ) , this , SLOT ( notifyOfUpdate ( QString ) ) ) ;
executable_watcher - > addPath ( qApp - > applicationFilePath ( ) ) ;
2010-08-23 23:42:15 +04:00
2014-12-20 20:53:58 +03:00
transferList - > setFocus ( ) ;
2010-11-14 18:28:22 +03:00
2014-12-20 20:53:58 +03:00
// Update the number of torrents (tab)
updateNbTorrents ( ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( updateNbTorrents ( ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( rowsRemoved ( QModelIndex , int , int ) ) , this , SLOT ( updateNbTorrents ( ) ) ) ;
2010-12-25 12:23:04 +03:00
2014-12-20 20:53:58 +03:00
qDebug ( " GUI Built " ) ;
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_WIN
2014-12-20 20:53:58 +03:00
if ( ! pref - > neverCheckFileAssoc ( ) & & ( ! Preferences : : isTorrentFileAssocSet ( ) | | ! Preferences : : isMagnetLinkAssocSet ( ) ) ) {
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 : : setTorrentFileAssoc ( true ) ;
Preferences : : setMagnetLinkAssoc ( true ) ;
}
else {
pref - > setNeverCheckFileAssoc ( ) ;
}
2010-06-02 17:08:26 +04:00
}
2010-05-31 01:45:55 +04:00
# endif
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_MAC
2014-12-20 20:53:58 +03:00
qt_mac_set_dock_menu ( getTrayIconMenu ( ) ) ;
2010-06-09 19:40:55 +04:00
# endif
2014-12-20 20:53:58 +03:00
}
2015-01-26 17:00:23 +03:00
MainWindow : : ~ MainWindow ( )
{
# ifdef Q_OS_MAC
// Workaround to avoid bug http://bugreports.qt.nokia.com/browse/QTBUG-7305
setUnifiedTitleAndToolBarOnMac ( false ) ;
# endif
}
2014-10-18 18:18:58 +04:00
void MainWindow : : addToolbarContextMenu ( )
{
const Preferences * const pref = Preferences : : instance ( ) ;
toolbarMenu = new QMenu ( this ) ;
toolBar - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( toolBar , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( toolbarMenuRequested ( QPoint ) ) ) ;
QAction * iconsOnly = new QAction ( tr ( " Icons Only " ) , toolbarMenu ) ;
connect ( iconsOnly , SIGNAL ( triggered ( ) ) , this , SLOT ( toolbarIconsOnly ( ) ) ) ;
QAction * textOnly = new QAction ( tr ( " Text Only " ) , toolbarMenu ) ;
connect ( textOnly , SIGNAL ( triggered ( ) ) , this , SLOT ( toolbarTextOnly ( ) ) ) ;
QAction * textBesideIcons = new QAction ( tr ( " Text Alongside Icons " ) , toolbarMenu ) ;
connect ( textBesideIcons , SIGNAL ( triggered ( ) ) , this , SLOT ( toolbarTextBeside ( ) ) ) ;
QAction * textUnderIcons = new QAction ( tr ( " Text Under Icons " ) , toolbarMenu ) ;
connect ( textUnderIcons , SIGNAL ( triggered ( ) ) , this , SLOT ( toolbarTextUnder ( ) ) ) ;
QAction * followSystemStyle = new QAction ( tr ( " Follow System Style " ) , toolbarMenu ) ;
connect ( followSystemStyle , SIGNAL ( triggered ( ) ) , this , SLOT ( toolbarFollowSystem ( ) ) ) ;
toolbarMenu - > addAction ( iconsOnly ) ;
toolbarMenu - > addAction ( textOnly ) ;
toolbarMenu - > addAction ( textBesideIcons ) ;
toolbarMenu - > addAction ( textUnderIcons ) ;
toolbarMenu - > addAction ( followSystemStyle ) ;
QActionGroup * textPositionGroup = new QActionGroup ( toolbarMenu ) ;
textPositionGroup - > addAction ( iconsOnly ) ;
iconsOnly - > setCheckable ( true ) ;
textPositionGroup - > addAction ( textOnly ) ;
textOnly - > setCheckable ( true ) ;
textPositionGroup - > addAction ( textBesideIcons ) ;
textBesideIcons - > setCheckable ( true ) ;
textPositionGroup - > addAction ( textUnderIcons ) ;
textUnderIcons - > setCheckable ( true ) ;
textPositionGroup - > addAction ( followSystemStyle ) ;
followSystemStyle - > setCheckable ( true ) ;
const Qt : : ToolButtonStyle buttonStyle = static_cast < Qt : : ToolButtonStyle > ( pref - > getToolbarTextPosition ( ) ) ;
if ( buttonStyle > = Qt : : ToolButtonIconOnly & & buttonStyle < = Qt : : ToolButtonFollowStyle )
toolBar - > setToolButtonStyle ( buttonStyle ) ;
switch ( buttonStyle ) {
case Qt : : ToolButtonIconOnly :
iconsOnly - > setChecked ( true ) ;
break ;
case Qt : : ToolButtonTextOnly :
textOnly - > setChecked ( true ) ;
break ;
case Qt : : ToolButtonTextBesideIcon :
textBesideIcons - > setChecked ( true ) ;
break ;
case Qt : : ToolButtonTextUnderIcon :
textUnderIcons - > setChecked ( true ) ;
break ;
default :
followSystemStyle - > setChecked ( true ) ;
}
}
void MainWindow : : toolbarMenuRequested ( QPoint point )
{
toolbarMenu - > exec ( toolBar - > mapToGlobal ( point ) ) ;
}
void MainWindow : : toolbarIconsOnly ( )
{
toolBar - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
Preferences : : instance ( ) - > setToolbarTextPosition ( Qt : : ToolButtonIconOnly ) ;
}
void MainWindow : : toolbarTextOnly ( )
{
toolBar - > setToolButtonStyle ( Qt : : ToolButtonTextOnly ) ;
Preferences : : instance ( ) - > setToolbarTextPosition ( Qt : : ToolButtonTextOnly ) ;
}
void MainWindow : : toolbarTextBeside ( )
{
toolBar - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
Preferences : : instance ( ) - > setToolbarTextPosition ( Qt : : ToolButtonTextBesideIcon ) ;
}
void MainWindow : : toolbarTextUnder ( )
{
toolBar - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
Preferences : : instance ( ) - > setToolbarTextPosition ( Qt : : ToolButtonTextUnderIcon ) ;
}
void MainWindow : : toolbarFollowSystem ( )
{
toolBar - > setToolButtonStyle ( Qt : : ToolButtonFollowStyle ) ;
Preferences : : instance ( ) - > setToolbarTextPosition ( Qt : : ToolButtonFollowStyle ) ;
}
2014-12-20 20:53:58 +03:00
void MainWindow : : defineUILockPassword ( )
{
QString old_pass_md5 = Preferences : : instance ( ) - > getUILockPasswordMD5 ( ) ;
if ( old_pass_md5 . isNull ( ) ) old_pass_md5 = " " ;
bool ok = false ;
QString new_clear_password = AutoExpandableDialog : : getText ( this , tr ( " UI lock password " ) , tr ( " Please type the UI lock password: " ) , QLineEdit : : Password , old_pass_md5 , & ok ) ;
if ( ok ) {
new_clear_password = new_clear_password . trimmed ( ) ;
if ( new_clear_password . size ( ) < 3 ) {
QMessageBox : : warning ( this , tr ( " Invalid password " ) , tr ( " The password should contain at least 3 characters " ) ) ;
return ;
}
if ( new_clear_password ! = old_pass_md5 )
Preferences : : instance ( ) - > setUILockPassword ( new_clear_password ) ;
QMessageBox : : information ( this , tr ( " Password update " ) , tr ( " The UI lock password has been successfully updated " ) ) ;
2010-08-19 20:30:13 +04:00
}
}
2014-12-20 20:53:58 +03:00
void MainWindow : : clearUILockPassword ( )
{
QMessageBox : : StandardButton answer = QMessageBox : : question ( this , tr ( " Clear the password " ) , tr ( " Are you sure you want to clear the password? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ;
if ( answer = = QMessageBox : : Yes )
Preferences : : instance ( ) - > clearUILockPassword ( ) ;
2013-10-25 00:23:56 +04:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionLock_qBittorrent_triggered ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
// Check if there is a password
if ( pref - > getUILockPasswordMD5 ( ) . isEmpty ( ) ) {
// Ask for a password
bool ok = false ;
QString clear_password = AutoExpandableDialog : : getText ( this , tr ( " UI lock password " ) , tr ( " Please type the UI lock password: " ) , QLineEdit : : Password , " " , & ok ) ;
if ( ! ok ) return ;
pref - > setUILockPassword ( clear_password ) ;
2009-08-16 07:09:20 +04:00
}
2014-12-20 20:53:58 +03:00
// Lock the interface
ui_locked = true ;
pref - > setUILocked ( true ) ;
myTrayIconMenu - > setEnabled ( false ) ;
hide ( ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : displayRSSTab ( bool enable )
{
if ( enable ) {
// RSS tab
if ( ! rssWidget ) {
rssWidget = new RSSImp ( tabs ) ;
int index_tab = tabs - > addTab ( rssWidget , tr ( " RSS " ) ) ;
2015-04-19 18:17:47 +03:00
tabs - > setTabIcon ( index_tab , GuiIconProvider : : instance ( ) - > getIcon ( " application-rss+xml " ) ) ;
2014-12-20 20:53:58 +03:00
}
2010-06-22 17:58:22 +04:00
}
2015-01-26 17:00:23 +03:00
else if ( rssWidget ) {
2014-12-20 20:53:58 +03:00
delete rssWidget ;
2015-01-26 17:00:23 +03:00
}
2014-12-20 20:53:58 +03:00
}
void MainWindow : : displaySearchTab ( bool enable )
{
Preferences : : instance ( ) - > setSearchEnabled ( enable ) ;
if ( enable ) {
// RSS tab
if ( ! searchEngine ) {
searchEngine = new SearchEngine ( this ) ;
2015-04-19 18:17:47 +03:00
tabs - > insertTab ( 1 , searchEngine , GuiIconProvider : : instance ( ) - > getIcon ( " edit-find " ) , tr ( " Search " ) ) ;
2014-12-20 20:53:58 +03:00
}
2010-06-22 17:58:22 +04:00
}
2015-01-26 17:00:23 +03:00
else if ( searchEngine ) {
2014-12-20 20:53:58 +03:00
delete searchEngine ;
2015-01-26 17:00:23 +03:00
}
2014-12-20 20:53:58 +03:00
2010-06-22 17:58:22 +04:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : updateNbTorrents ( )
{
tabs - > setTabText ( 0 , tr ( " Transfers (%1) " ) . arg ( transferList - > getSourceModel ( ) - > rowCount ( ) ) ) ;
2010-05-21 18:56:56 +04:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionDocumentation_triggered ( ) const
{
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://doc.qbittorrent.org " ) ) ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : tab_changed ( int new_tab )
{
Q_UNUSED ( new_tab ) ;
// We cannot rely on the index new_tab
// because the tab order is undetermined now
if ( tabs - > currentWidget ( ) = = vSplitter ) {
qDebug ( " Changed tab to transfer list, refreshing the list " ) ;
properties - > loadDynamicData ( ) ;
searchFilterAct - > setVisible ( true ) ;
return ;
}
else {
searchFilterAct - > setVisible ( false ) ;
}
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
}
2014-12-20 20:53:58 +03:00
void MainWindow : : writeSettings ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setMainGeometry ( saveGeometry ( ) ) ;
// Splitter size
pref - > setMainVSplitterState ( vSplitter - > saveState ( ) ) ;
properties - > saveSettings ( ) ;
2009-11-06 17:30:14 +03:00
}
2015-04-16 00:47:59 +03:00
void MainWindow : : cleanup ( )
{
writeSettings ( ) ;
delete executable_watcher ;
if ( systrayCreator )
systrayCreator - > stop ( ) ;
if ( preventTimer )
preventTimer - > stop ( ) ;
2015-05-03 01:21:06 +03:00
# if (defined(Q_OS_WIN) || defined(Q_OS_MAC))
2015-04-16 00:47:59 +03:00
programUpdateTimer . stop ( ) ;
2015-05-03 01:21:06 +03:00
# endif
2015-04-16 00:47:59 +03:00
delete search_filter ;
delete searchFilterAct ;
delete tabs ; // this seems enough to also delete all contained widgets
delete status_bar ;
delete m_pwr ;
delete toolbarMenu ;
}
2014-12-20 20:53:58 +03:00
void MainWindow : : readSettings ( )
{
const Preferences * const pref = Preferences : : instance ( ) ;
const QByteArray mainGeo = pref - > getMainGeometry ( ) ;
if ( ! mainGeo . isEmpty ( ) )
if ( restoreGeometry ( mainGeo ) )
m_posInitialized = true ;
const QByteArray splitterState = pref - > getMainVSplitterState ( ) ;
if ( splitterState . isEmpty ( ) )
// Default sizes
vSplitter - > setSizes ( QList < int > ( ) < < 120 < < vSplitter - > width ( ) - 120 ) ;
else
vSplitter - > restoreState ( splitterState ) ;
2010-12-04 12:37:13 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : balloonClicked ( )
{
if ( isHidden ( ) ) {
if ( ui_locked ) {
// Ask for UI lock password
if ( ! unlockUI ( ) )
return ;
}
show ( ) ;
if ( isMinimized ( ) )
showNormal ( ) ;
2013-07-22 02:46:10 +04:00
}
2014-06-19 00:22:25 +04:00
2014-12-20 20:53:58 +03:00
raise ( ) ;
activateWindow ( ) ;
2010-12-04 12:37:13 +03:00
}
2015-04-19 18:17:47 +03:00
void MainWindow : : addTorrentFailed ( const QString & error ) const
{
showNotificationBaloon ( tr ( " Error " ) , tr ( " Failed to add torrent: %1 " ) . arg ( error ) ) ;
}
2009-11-06 17:30:14 +03:00
// called when a torrent has finished
2015-04-19 18:17:47 +03:00
void MainWindow : : finishedTorrent ( BitTorrent : : TorrentHandle * const torrent ) const
2014-12-20 20:53:58 +03:00
{
2015-04-19 18:17:47 +03:00
showNotificationBaloon ( tr ( " Download completion " ) , tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( torrent - > name ( ) ) ) ;
2009-11-06 17:30:14 +03:00
}
// Notification when disk is full
2015-04-19 18:17:47 +03:00
void MainWindow : : fullDiskError ( BitTorrent : : TorrentHandle * const torrent , QString msg ) const
2014-12-20 20:53:58 +03:00
{
2015-04-19 18:17:47 +03:00
showNotificationBaloon ( tr ( " I/O Error " , " i.e: Input/Output Error " ) , tr ( " An I/O error occurred for torrent %1. \n Reason: %2 " , " e.g: An error occurred for torrent xxx.avi. \n Reason: disk is full. " ) . arg ( torrent - > name ( ) ) . arg ( msg ) ) ;
2014-12-20 20:53:58 +03:00
}
void MainWindow : : createKeyboardShortcuts ( )
{
actionCreate_torrent - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+N " ) ) ) ;
actionOpen - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+O " ) ) ) ;
actionDownload_from_URL - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Shift+O " ) ) ) ;
actionExit - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Q " ) ) ) ;
2015-01-26 17:00:23 +03:00
QShortcut * switchTransferShortcut = new QShortcut ( QKeySequence ( " Alt+1 " ) , this ) ;
2014-12-20 20:53:58 +03:00
connect ( switchTransferShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayTransferTab ( ) ) ) ;
2015-01-26 17:00:23 +03:00
QShortcut * switchSearchShortcut = new QShortcut ( QKeySequence ( " Alt+2 " ) , this ) ;
2014-12-20 20:53:58 +03:00
connect ( switchSearchShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displaySearchTab ( ) ) ) ;
2015-01-26 17:00:23 +03:00
QShortcut * switchSearchShortcut2 = new QShortcut ( QKeySequence ( " Ctrl+F " ) , this ) ;
2014-12-20 20:53:58 +03:00
connect ( switchSearchShortcut2 , SIGNAL ( activated ( ) ) , this , SLOT ( displaySearchTab ( ) ) ) ;
2015-01-26 17:00:23 +03:00
QShortcut * switchRSSShortcut = new QShortcut ( QKeySequence ( " Alt+3 " ) , this ) ;
2014-12-20 20:53:58 +03:00
connect ( switchRSSShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( displayRSSTab ( ) ) ) ;
2015-01-26 17:00:23 +03:00
2014-12-20 20:53:58 +03:00
actionDocumentation - > setShortcut ( QKeySequence ( " F1 " ) ) ;
actionOptions - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Alt+O " ) ) ) ;
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 " ) ) ) ;
actionBottomPriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Shift+- " ) ) ) ;
actionDecreasePriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+- " ) ) ) ;
actionIncreasePriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl++ " ) ) ) ;
actionTopPriority - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+Shift++ " ) ) ) ;
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_MAC
2014-12-20 20:53:58 +03:00
actionMinimize - > setShortcut ( QKeySequence ( QString : : fromUtf8 ( " Ctrl+M " ) ) ) ;
addAction ( actionMinimize ) ;
2012-02-07 21:48:25 +04:00
# endif
2009-11-06 17:30:14 +03:00
}
// Keyboard shortcuts slots
2014-12-20 20:53:58 +03:00
void MainWindow : : displayTransferTab ( ) const
{
tabs - > setCurrentWidget ( transferList ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : displaySearchTab ( ) const
{
if ( searchEngine )
tabs - > setCurrentWidget ( searchEngine ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : displayRSSTab ( ) const
{
if ( rssWidget )
tabs - > setCurrentWidget ( rssWidget ) ;
2009-11-06 17:30:14 +03:00
}
// End of keyboard shortcuts slots
2015-04-19 18:17:47 +03:00
void MainWindow : : askRecursiveTorrentDownloadConfirmation ( BitTorrent : : TorrentHandle * const torrent )
2014-12-20 20:53:58 +03:00
{
Preferences * const pref = Preferences : : instance ( ) ;
if ( pref - > recursiveDownloadDisabled ( ) ) return ;
// Get Torrent name
2015-04-19 18:17:47 +03:00
QString torrent_name = torrent - > name ( ) ;
2014-12-20 20:53:58 +03: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 ( torrent_name ) ) ;
QPushButton * yes = confirmBox . addButton ( tr ( " Yes " ) , QMessageBox : : YesRole ) ;
/*QPushButton *no = */ confirmBox . addButton ( tr ( " No " ) , QMessageBox : : NoRole ) ;
QPushButton * never = confirmBox . addButton ( tr ( " Never " ) , QMessageBox : : NoRole ) ;
confirmBox . exec ( ) ;
2015-04-19 18:17:47 +03:00
if ( confirmBox . clickedButton ( ) = = yes )
BitTorrent : : Session : : instance ( ) - > recursiveTorrentDownload ( torrent - > hash ( ) ) ;
else if ( confirmBox . clickedButton ( ) = = never )
2014-12-20 20:53:58 +03:00
pref - > disableRecursiveDownload ( ) ;
}
void MainWindow : : handleDownloadFromUrlFailure ( QString url , QString reason ) const
{
// Display a message box
2015-03-30 14:15:48 +03:00
showNotificationBaloon ( tr ( " URL download error " ) , tr ( " Couldn't download file at URL: %1, reason: %2. " ) . arg ( url ) . arg ( reason ) ) ;
2014-12-20 20:53:58 +03:00
}
void MainWindow : : on_actionSet_global_upload_limit_triggered ( )
{
qDebug ( " actionSet_global_upload_limit_triggered " ) ;
bool ok ;
2015-04-19 18:17:47 +03:00
int cur_limit = BitTorrent : : Session : : instance ( ) - > uploadRateLimit ( ) ;
2014-12-20 20:53:58 +03:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Upload Speed Limit " ) , cur_limit ) ;
if ( ok ) {
qDebug ( " Setting global upload rate limit to %.1fKb/s " , new_limit / 1024. ) ;
2015-04-19 18:17:47 +03:00
BitTorrent : : Session : : instance ( ) - > setUploadRateLimit ( new_limit ) ;
2014-12-20 20:53:58 +03:00
if ( new_limit < = 0 )
Preferences : : instance ( ) - > setGlobalUploadLimit ( - 1 ) ;
else
Preferences : : instance ( ) - > setGlobalUploadLimit ( new_limit / 1024. ) ;
}
}
void MainWindow : : on_actionSet_global_download_limit_triggered ( )
{
qDebug ( " actionSet_global_download_limit_triggered " ) ;
bool ok ;
2015-04-19 18:17:47 +03:00
int cur_limit = BitTorrent : : Session : : instance ( ) - > downloadRateLimit ( ) ;
2014-12-20 20:53:58 +03:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Global Download Speed Limit " ) , cur_limit ) ;
if ( ok ) {
qDebug ( " Setting global download rate limit to %.1fKb/s " , new_limit / 1024. ) ;
2015-04-19 18:17:47 +03:00
BitTorrent : : Session : : instance ( ) - > setDownloadRateLimit ( new_limit ) ;
2014-12-20 20:53:58 +03:00
if ( new_limit < = 0 )
Preferences : : instance ( ) - > setGlobalDownloadLimit ( - 1 ) ;
else
Preferences : : instance ( ) - > setGlobalDownloadLimit ( new_limit / 1024. ) ;
}
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
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionExit_triggered ( )
{
// UI locking enforcement.
if ( isHidden ( ) & & ui_locked ) {
// Ask for UI lock password
if ( ! unlockUI ( ) )
return ;
}
2013-01-12 21:18:39 +04:00
2014-12-20 20:53:58 +03:00
force_exit = true ;
close ( ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
QWidget * MainWindow : : getCurrentTabWidget ( ) const
{
if ( isMinimized ( ) | | ! isVisible ( ) )
return 0 ;
if ( tabs - > currentIndex ( ) = = 0 )
return transferList ;
return tabs - > currentWidget ( ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : setTabText ( int index , QString text ) const
{
tabs - > setTabText ( index , text ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
bool MainWindow : : unlockUI ( )
{
if ( unlockDlgShowing )
return false ;
else
unlockDlgShowing = true ;
bool ok = false ;
QString clear_password = AutoExpandableDialog : : getText ( this , tr ( " UI lock password " ) , tr ( " Please type the UI lock password: " ) , QLineEdit : : Password , " " , & ok ) ;
unlockDlgShowing = false ;
if ( ! ok ) return false ;
Preferences * const pref = Preferences : : instance ( ) ;
QString real_pass_md5 = pref - > getUILockPasswordMD5 ( ) ;
QCryptographicHash md5 ( QCryptographicHash : : Md5 ) ;
md5 . addData ( clear_password . toLocal8Bit ( ) ) ;
QString password_md5 = md5 . result ( ) . toHex ( ) ;
if ( real_pass_md5 = = password_md5 ) {
ui_locked = false ;
pref - > setUILocked ( false ) ;
myTrayIconMenu - > setEnabled ( true ) ;
return true ;
}
QMessageBox : : warning ( this , tr ( " Invalid password " ) , tr ( " The password is invalid " ) ) ;
2014-10-20 21:34:46 +04:00
return false ;
2014-12-20 20:53:58 +03:00
}
void MainWindow : : notifyOfUpdate ( QString )
{
// Show restart message
status_bar - > showRestartRequired ( ) ;
// Delete the executable watcher
delete executable_watcher ;
executable_watcher = 0 ;
2010-08-23 23:42:15 +04:00
}
2009-11-06 17:30:14 +03:00
// Toggle Main window visibility
2014-12-20 20:53:58 +03:00
void MainWindow : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e )
{
if ( e = = QSystemTrayIcon : : Trigger | | e = = QSystemTrayIcon : : DoubleClick ) {
if ( isHidden ( ) ) {
if ( ui_locked ) {
// Ask for UI lock password
if ( ! unlockUI ( ) )
return ;
}
// Make sure the window is not minimized
setWindowState ( windowState ( ) & ( ~ Qt : : WindowMinimized | Qt : : WindowActive ) ) ;
// Then show it
show ( ) ;
raise ( ) ;
activateWindow ( ) ;
}
else {
hide ( ) ;
}
2009-08-16 07:09:20 +04:00
}
2009-11-06 17:30:14 +03:00
}
// Display About Dialog
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionAbout_triggered ( )
{
//About dialog
if ( aboutDlg )
aboutDlg - > setFocus ( ) ;
else
aboutDlg = new about ( this ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionStatistics_triggered ( )
{
if ( statsDlg )
statsDlg - > setFocus ( ) ;
else
statsDlg = new StatsDialog ( this ) ;
2013-11-17 01:16:24 +04:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : showEvent ( QShowEvent * e )
{
qDebug ( " ** Show Event ** " ) ;
2011-01-21 21:38:58 +03:00
2014-12-20 20:53:58 +03:00
if ( getCurrentTabWidget ( ) = = transferList )
properties - > loadDynamicData ( ) ;
2011-01-22 22:51:06 +03:00
2014-12-20 20:53:58 +03:00
e - > accept ( ) ;
2011-01-22 22:51:06 +03:00
2014-12-20 20:53:58 +03:00
// Make sure the window is initially centered
if ( ! m_posInitialized ) {
2015-05-06 14:53:27 +03:00
move ( Utils : : Misc : : screenCenter ( this ) ) ;
2014-12-20 20:53:58 +03:00
m_posInitialized = true ;
}
2009-11-06 17:30:14 +03:00
}
// Called when we close the program
2014-12-20 20:53:58 +03:00
void MainWindow : : closeEvent ( QCloseEvent * e )
{
Preferences * const pref = Preferences : : instance ( ) ;
const bool goToSystrayOnExit = pref - > closeToTray ( ) ;
if ( ! force_exit & & systrayIcon & & goToSystrayOnExit & & ! this - > isHidden ( ) ) {
hide ( ) ;
e - > accept ( ) ;
2009-11-06 17:30:14 +03:00
return ;
2007-11-16 21:53:21 +03:00
}
2015-04-21 12:58:21 +03:00
2015-04-19 18:17:47 +03:00
if ( pref - > confirmOnExit ( ) & & BitTorrent : : Session : : instance ( ) - > hasActiveTorrents ( ) ) {
2014-12-20 20:53:58 +03:00
if ( e - > spontaneous ( ) | | force_exit ) {
if ( ! isVisible ( ) )
show ( ) ;
QMessageBox confirmBox ( QMessageBox : : Question , tr ( " Exiting qBittorrent " ) ,
tr ( " Some files are currently transferring. \n Are you sure you want to quit qBittorrent? " ) ,
QMessageBox : : NoButton , this ) ;
2015-05-26 08:25:12 +03:00
QPushButton * noBtn = confirmBox . addButton ( tr ( " &No " ) , QMessageBox : : NoRole ) ;
QPushButton * yesBtn = confirmBox . addButton ( tr ( " &Yes " ) , QMessageBox : : YesRole ) ;
QPushButton * alwaysBtn = confirmBox . addButton ( tr ( " &Always Yes " ) , QMessageBox : : YesRole ) ;
confirmBox . setDefaultButton ( noBtn ) ;
2014-12-20 20:53:58 +03:00
confirmBox . exec ( ) ;
if ( ! confirmBox . clickedButton ( ) | | confirmBox . clickedButton ( ) = = noBtn ) {
// Cancel exit
e - > ignore ( ) ;
force_exit = false ;
return ;
}
2015-05-26 08:25:12 +03:00
if ( confirmBox . clickedButton ( ) = = alwaysBtn ) {
2014-12-20 20:53:58 +03:00
// Remember choice
Preferences : : instance ( ) - > setConfirmOnExit ( false ) ;
2015-05-26 08:25:12 +03:00
}
2014-12-20 20:53:58 +03:00
}
}
2015-04-21 12:58:21 +03:00
2015-03-07 23:54:31 +03:00
//abort search if any
if ( searchEngine ) delete searchEngine ;
2014-12-20 20:53:58 +03:00
hide ( ) ;
2015-04-21 12:58:21 +03:00
// Hide tray icon
2014-12-20 20:53:58 +03:00
if ( systrayIcon )
systrayIcon - > hide ( ) ;
// Accept exit
e - > accept ( ) ;
qApp - > exit ( ) ;
2009-11-06 17:30:14 +03:00
}
// Display window to create a torrent
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionCreate_torrent_triggered ( )
{
2015-04-19 18:17:47 +03:00
if ( createTorrentDlg )
2014-12-20 20:53:58 +03:00
createTorrentDlg - > setFocus ( ) ;
2015-04-19 18:17:47 +03:00
else
2014-12-20 20:53:58 +03:00
createTorrentDlg = new TorrentCreatorDlg ( this ) ;
}
bool MainWindow : : event ( QEvent * e )
{
switch ( e - > type ( ) ) {
case QEvent : : WindowStateChange : {
qDebug ( " Window change event " ) ;
//Now check to see if the window is minimised
if ( isMinimized ( ) ) {
qDebug ( " minimisation " ) ;
if ( systrayIcon & & Preferences : : instance ( ) - > minimizeToTray ( ) ) {
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 ;
}
}
// Iconify if there is no modal window
if ( ! has_modal_window ) {
qDebug ( " Minimize to Tray enabled, hiding! " ) ;
e - > ignore ( ) ;
QTimer : : singleShot ( 0 , this , SLOT ( hide ( ) ) ) ;
return true ;
}
}
2010-10-24 01:46:05 +04:00
}
2014-12-20 20:53:58 +03:00
break ;
2006-09-30 20:02:39 +04:00
}
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_MAC
2014-12-20 20:53:58 +03:00
case QEvent : : ToolBarChange : {
qDebug ( " MAC: Received a toolbar change event! " ) ;
bool ret = QMainWindow : : event ( e ) ;
qDebug ( " MAC: new toolbar visibility is %d " , ! actionTop_tool_bar - > isChecked ( ) ) ;
actionTop_tool_bar - > toggle ( ) ;
Preferences : : instance ( ) - > setToolbarDisplayed ( actionTop_tool_bar - > isChecked ( ) ) ;
return ret ;
}
2010-07-21 22:02:29 +04:00
# endif
2014-12-20 20:53:58 +03:00
default :
break ;
}
return QMainWindow : : event ( e ) ;
2009-11-06 17:30:14 +03:00
}
// Action executed when a file is dropped
2014-12-20 20:53:58 +03:00
void MainWindow : : dropEvent ( QDropEvent * event )
{
event - > acceptProposedAction ( ) ;
QStringList files ;
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
const QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
foreach ( const QUrl & url , urls ) {
if ( ! url . isEmpty ( ) ) {
if ( url . scheme ( ) . compare ( " file " , Qt : : CaseInsensitive ) = = 0 )
files < < url . toLocalFile ( ) ;
else
files < < url . toString ( ) ;
}
}
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
else {
files = event - > mimeData ( ) - > text ( ) . split ( QString : : fromUtf8 ( " \n " ) ) ;
2010-07-23 02:19:42 +04:00
}
2015-04-19 18:17:47 +03:00
2014-12-20 20:53:58 +03:00
// Add file to download list
2015-04-19 18:17:47 +03:00
const bool useTorrentAdditionDialog = Preferences : : instance ( ) - > useAdditionDialog ( ) ;
2014-12-20 20:53:58 +03:00
foreach ( QString file , files ) {
qDebug ( " Dropped file %s on download list " , qPrintable ( file ) ) ;
2015-04-19 18:17:47 +03:00
if ( useTorrentAdditionDialog )
AddNewTorrentDialog : : show ( file , this ) ;
else
BitTorrent : : Session : : instance ( ) - > addTorrent ( file ) ;
2008-08-02 00:03:16 +04:00
}
2009-11-06 17:30:14 +03:00
}
// Decode if we accept drag 'n drop or not
2014-12-20 20:53:58 +03:00
void MainWindow : : dragEnterEvent ( QDragEnterEvent * event )
{
foreach ( const QString & mime , event - > mimeData ( ) - > formats ( ) )
qDebug ( " mimeData: %s " , mime . toLocal8Bit ( ) . data ( ) ) ;
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
}
/*****************************************************
2014-12-20 20:53:58 +03:00
* *
* Torrent *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-11-06 17:30:14 +03:00
// Display a dialog to allow user to add
// torrents to download list
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionOpen_triggered ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
// Open File Open Dialog
// Note: it is possible to select more than one file
2015-04-19 18:17:47 +03:00
const QStringList pathsList =
QFileDialog : : getOpenFileNames ( 0 , tr ( " Open Torrent Files " ) , pref - > getMainLastDir ( ) ,
tr ( " Torrent Files " ) + QString : : fromUtf8 ( " (*.torrent) " ) ) ;
const bool useTorrentAdditionDialog = Preferences : : instance ( ) - > useAdditionDialog ( ) ;
2015-06-16 09:08:25 +03:00
if ( ! pathsList . isEmpty ( ) ) {
foreach ( QString file , pathsList ) {
qDebug ( " Dropped file %s on download list " , qPrintable ( file ) ) ;
if ( useTorrentAdditionDialog )
AddNewTorrentDialog : : show ( file , this ) ;
else
BitTorrent : : Session : : instance ( ) - > addTorrent ( file ) ;
}
2015-04-19 18:17:47 +03:00
2015-06-16 09:08:25 +03:00
// Save last dir to remember it
QStringList top_dir = Utils : : Fs : : fromNativePath ( pathsList . at ( 0 ) ) . split ( " / " ) ;
top_dir . removeLast ( ) ;
pref - > setMainLastDir ( Utils : : Fs : : fromNativePath ( top_dir . join ( " / " ) ) ) ;
}
2009-11-06 17:30:14 +03:00
}
2015-01-22 15:56:16 +03:00
void MainWindow : : activate ( )
2014-12-20 20:53:58 +03:00
{
2015-01-22 15:56:16 +03:00
if ( ! ui_locked | | unlockUI ( ) ) {
show ( ) ;
activateWindow ( ) ;
raise ( ) ;
2006-09-30 20:02:39 +04:00
}
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : optionsSaved ( )
{
loadPreferences ( ) ;
2009-11-15 13:00:07 +03:00
}
2009-11-14 22:08:28 +03:00
// Load program preferences
2014-12-20 20:53:58 +03:00
void MainWindow : : loadPreferences ( bool configure_session )
{
2015-01-06 04:34:10 +03:00
Logger : : instance ( ) - > addMessage ( tr ( " Options were saved successfully. " ) ) ;
2014-12-20 20:53:58 +03:00
const Preferences * const pref = Preferences : : instance ( ) ;
const bool newSystrayIntegration = pref - > systrayIntegration ( ) ;
actionLock_qBittorrent - > setVisible ( newSystrayIntegration ) ;
2015-01-26 17:00:23 +03:00
if ( newSystrayIntegration ! = ( systrayIcon ! = 0 ) ) {
2014-12-20 20:53:58 +03:00
if ( newSystrayIntegration ) {
// create the trayicon
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 ( ) ;
}
}
else {
// Destroy trayicon
delete systrayIcon ;
delete myTrayIconMenu ;
2009-11-18 21:45:06 +03:00
}
2009-11-14 22:08:28 +03:00
}
2014-12-20 20:53:58 +03:00
// Reload systray icon
if ( newSystrayIntegration & & systrayIcon )
systrayIcon - > setIcon ( getSystrayIcon ( ) ) ;
// General
if ( pref - > isToolbarDisplayed ( ) ) {
toolBar - > setVisible ( true ) ;
}
else {
// Clear search filter before hiding the top toolbar
search_filter - > clear ( ) ;
toolBar - > setVisible ( false ) ;
}
if ( pref - > preventFromSuspend ( ) ) {
preventTimer - > start ( PREVENT_SUSPEND_INTERVAL ) ;
}
else {
preventTimer - > stop ( ) ;
m_pwr - > setActivityState ( false ) ;
}
transferList - > setAlternatingRowColors ( pref - > useAlternatingRowColors ( ) ) ;
properties - > getFilesList ( ) - > setAlternatingRowColors ( pref - > useAlternatingRowColors ( ) ) ;
properties - > getTrackerList ( ) - > setAlternatingRowColors ( pref - > useAlternatingRowColors ( ) ) ;
properties - > getPeerList ( ) - > setAlternatingRowColors ( pref - > useAlternatingRowColors ( ) ) ;
// Queueing System
if ( pref - > isQueueingSystemEnabled ( ) ) {
if ( ! actionDecreasePriority - > isVisible ( ) ) {
transferList - > hidePriorityColumn ( false ) ;
actionDecreasePriority - > setVisible ( true ) ;
actionIncreasePriority - > setVisible ( true ) ;
actionTopPriority - > setVisible ( true ) ;
actionBottomPriority - > setVisible ( true ) ;
prioSeparator - > setVisible ( true ) ;
prioSeparatorMenu - > setVisible ( true ) ;
}
2009-08-16 07:09:20 +04:00
}
2014-12-20 20:53:58 +03:00
else {
if ( actionDecreasePriority - > isVisible ( ) ) {
transferList - > hidePriorityColumn ( true ) ;
actionDecreasePriority - > setVisible ( false ) ;
actionIncreasePriority - > setVisible ( false ) ;
actionTopPriority - > setVisible ( false ) ;
actionBottomPriority - > setVisible ( false ) ;
prioSeparator - > setVisible ( false ) ;
prioSeparatorMenu - > setVisible ( false ) ;
}
2009-08-16 07:09:20 +04:00
}
2009-11-14 22:08:28 +03:00
2014-12-20 20:53:58 +03:00
// Torrent properties
properties - > reloadPreferences ( ) ;
2009-11-15 13:00:07 +03:00
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_WIN) || defined(Q_OS_MAC)
2014-12-20 20:53:58 +03:00
if ( pref - > isUpdateCheckEnabled ( ) )
checkProgramUpdate ( ) ;
else
programUpdateTimer . stop ( ) ;
2013-11-23 16:58:03 +04:00
# endif
2014-12-20 20:53:58 +03:00
qDebug ( " GUI settings loaded " ) ;
2009-11-06 17:30:14 +03:00
}
2015-04-19 18:17:47 +03:00
void MainWindow : : addUnauthenticatedTracker ( const QPair < BitTorrent : : TorrentHandle * const , QString > & tracker )
2014-12-20 20:53:58 +03:00
{
// Trackers whose authentication was cancelled
if ( unauthenticated_trackers . indexOf ( tracker ) < 0 )
unauthenticated_trackers < < tracker ;
2009-11-06 17:30:14 +03:00
}
// Called when a tracker requires authentication
2015-04-19 18:17:47 +03:00
void MainWindow : : trackerAuthenticationRequired ( BitTorrent : : TorrentHandle * const torrent )
2014-12-20 20:53:58 +03:00
{
2015-04-19 18:17:47 +03:00
if ( unauthenticated_trackers . indexOf ( QPair < BitTorrent : : TorrentHandle * const , QString > ( torrent , torrent - > currentTracker ( ) ) ) < 0 )
2014-12-20 20:53:58 +03:00
// Tracker login
2015-04-19 18:17:47 +03:00
new trackerLogin ( this , torrent ) ;
2009-11-06 17:30:14 +03:00
}
// Check connection status and display right icon
2014-12-20 20:53:58 +03:00
void MainWindow : : updateGUI ( )
{
2015-04-19 18:17:47 +03:00
BitTorrent : : SessionStatus status = BitTorrent : : Session : : instance ( ) - > status ( ) ;
2014-12-20 20:53:58 +03:00
// update global informations
if ( systrayIcon ) {
2015-04-04 20:14:38 +03:00
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
2014-12-20 20:53:58 +03:00
QString html = " <div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'> " ;
html + = " qBittorrent " ;
html + = " </div> " ;
html + = " <div style='vertical-align: baseline; height: 18px;'> " ;
2015-05-06 14:53:27 +03:00
html + = " <img src=':/icons/skin/download.png'/> " + tr ( " DL speed: %1 " , " e.g: Download speed: 10 KiB/s " ) . arg ( Utils : : Misc : : friendlyUnit ( status . payloadDownloadRate ( ) , true ) ) ;
2014-12-20 20:53:58 +03:00
html + = " </div> " ;
html + = " <div style='vertical-align: baseline; height: 18px;'> " ;
2015-05-06 14:53:27 +03:00
html + = " <img src=':/icons/skin/seeding.png'/> " + tr ( " UP speed: %1 " , " e.g: Upload speed: 10 KiB/s " ) . arg ( Utils : : Misc : : friendlyUnit ( status . payloadUploadRate ( ) , true ) ) ;
2014-12-20 20:53:58 +03:00
html + = " </div> " ;
2010-03-30 15:35:20 +04:00
# else
2014-12-20 20:53:58 +03:00
// OSes such as Windows do not support html here
2015-05-06 14:53:27 +03:00
QString html = tr ( " DL speed: %1 " , " e.g: Download speed: 10 KiB/s " ) . arg ( Utils : : Misc : : friendlyUnit ( status . payloadDownloadRate ( ) , true ) ) ;
2014-12-20 20:53:58 +03:00
html + = " \n " ;
2015-05-06 14:53:27 +03:00
html + = tr ( " UP speed: %1 " , " e.g: Upload speed: 10 KiB/s " ) . arg ( Utils : : Misc : : friendlyUnit ( status . payloadUploadRate ( ) , true ) ) ;
2009-01-04 20:08:52 +03:00
# endif
2014-12-20 20:53:58 +03:00
systrayIcon - > setToolTip ( html ) ; // tray icon
}
if ( displaySpeedInTitle )
2015-05-06 14:53:27 +03:00
setWindowTitle ( tr ( " [D: %1, U: %2] qBittorrent %3 " , " D = Download; U = Upload; %3 is qBittorrent version " ) . arg ( Utils : : Misc : : friendlyUnit ( status . payloadDownloadRate ( ) , true ) ) . arg ( Utils : : Misc : : friendlyUnit ( status . payloadUploadRate ( ) , true ) ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : showNotificationBaloon ( QString title , QString msg ) const
{
if ( ! Preferences : : instance ( ) - > useProgramNotification ( ) ) return ;
2013-09-21 11:59:58 +04:00
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
2014-12-20 20:53:58 +03:00
org : : freedesktop : : Notifications notifications ( " org.freedesktop.Notifications " ,
" /org/freedesktop/Notifications " ,
QDBusConnection : : sessionBus ( ) ) ;
// Testing for 'notifications.isValid()' isn't helpful here.
// If the notification daemon is configured to run 'as needed'
// the above check can be false if the daemon wasn't started
// by another application. In this case DBus will be able to
// start the notification daemon and complete our request. Such
// a daemon is xfce4-notifyd, DBus autostarts it and after
// some inactivity shuts it down. Other DEs, like GNOME, choose
// to start their daemons at the session startup and have it sit
// idling for the whole session.
QVariantMap hints ;
hints [ " desktop-entry " ] = " qBittorrent " ;
QDBusPendingReply < uint > reply = notifications . Notify ( " qBittorrent " , 0 , " qbittorrent " , title ,
msg , QStringList ( ) , hints , - 1 ) ;
reply . waitForFinished ( ) ;
if ( ! reply . isError ( ) )
return ;
2009-11-26 01:36:42 +03:00
# endif
2014-12-20 20:53:58 +03: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
/*****************************************************
2014-12-20 20:53:58 +03:00
* *
* Utils *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void MainWindow : : downloadFromURLList ( const QStringList & url_list )
{
2015-04-19 18:17:47 +03:00
const bool useTorrentAdditionDialog = Preferences : : instance ( ) - > useAdditionDialog ( ) ;
2014-12-20 20:53:58 +03:00
foreach ( QString url , url_list ) {
if ( ( url . size ( ) = = 40 & & ! url . contains ( QRegExp ( " [^0-9A-Fa-f] " ) ) )
| | ( url . size ( ) = = 32 & & ! url . contains ( QRegExp ( " [^2-7A-Za-z] " ) ) ) )
url = " magnet:?xt=urn:btih: " + url ;
2015-04-19 18:17:47 +03:00
if ( useTorrentAdditionDialog )
AddNewTorrentDialog : : show ( url , this ) ;
else
BitTorrent : : Session : : instance ( ) - > addTorrent ( url ) ;
2013-09-11 01:28:19 +04:00
}
2009-11-06 17:30:14 +03:00
}
/*****************************************************
2014-12-20 20:53:58 +03:00
* *
* Options *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void MainWindow : : createSystrayDelayed ( )
{
static int timeout = 20 ;
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
// Ok, systray integration is now supported
// Create systray icon
createTrayIcon ( ) ;
delete systrayCreator ;
}
else {
if ( timeout ) {
// Retry a bit later
systrayCreator - > start ( 2000 ) ;
- - timeout ;
}
else {
// Timed out, apparently system really does not
// support systray icon
delete systrayCreator ;
// Disable it in program preferences to
2015-05-04 02:09:30 +03:00
// avoid trying at each startup
2014-12-20 20:53:58 +03:00
Preferences : : instance ( ) - > setSystrayIntegration ( false ) ;
}
2008-01-04 23:09:37 +03:00
}
2009-11-06 17:30:14 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : updateAltSpeedsBtn ( bool alternative )
{
actionUse_alternative_speed_limits - > setChecked ( alternative ) ;
2010-01-23 23:44:09 +03:00
}
2012-05-20 17:51:32 +04:00
void MainWindow : : updateTrayIconMenu ( )
{
2014-12-20 20:53:58 +03:00
actionToggleVisibility - > setText ( isVisible ( ) ? tr ( " Hide " ) : tr ( " Show " ) ) ;
2012-05-20 17:51:32 +04:00
}
2014-12-20 20:53:58 +03:00
QMenu * MainWindow : : getTrayIconMenu ( )
{
if ( myTrayIconMenu )
return myTrayIconMenu ;
// Tray icon Menu
myTrayIconMenu = new QMenu ( this ) ;
connect ( myTrayIconMenu , SIGNAL ( aboutToShow ( ) ) , SLOT ( updateTrayIconMenu ( ) ) ) ;
myTrayIconMenu - > addAction ( actionToggleVisibility ) ;
myTrayIconMenu - > addSeparator ( ) ;
myTrayIconMenu - > addAction ( actionOpen ) ;
2015-05-03 19:59:00 +03:00
myTrayIconMenu - > addAction ( actionDownload_from_URL ) ;
2014-12-20 20:53:58 +03:00
myTrayIconMenu - > addSeparator ( ) ;
const bool isAltBWEnabled = Preferences : : instance ( ) - > isAltBandwidthEnabled ( ) ;
updateAltSpeedsBtn ( isAltBWEnabled ) ;
actionUse_alternative_speed_limits - > setChecked ( isAltBWEnabled ) ;
myTrayIconMenu - > addAction ( actionUse_alternative_speed_limits ) ;
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 ) ;
if ( ui_locked )
myTrayIconMenu - > setEnabled ( false ) ;
2010-06-09 19:40:55 +04:00
return myTrayIconMenu ;
}
2014-12-20 20:53:58 +03:00
void MainWindow : : createTrayIcon ( )
{
// Tray icon
systrayIcon = new QSystemTrayIcon ( getSystrayIcon ( ) , this ) ;
2010-06-09 19:40:55 +04:00
2014-12-20 20:53:58 +03:00
systrayIcon - > setContextMenu ( getTrayIconMenu ( ) ) ;
connect ( systrayIcon , SIGNAL ( messageClicked ( ) ) , this , SLOT ( balloonClicked ( ) ) ) ;
// End of Icon Menu
connect ( systrayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( toggleVisibility ( QSystemTrayIcon : : ActivationReason ) ) ) ;
systrayIcon - > show ( ) ;
2009-11-06 17:30:14 +03:00
}
// Display Program Options
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionOptions_triggered ( )
{
if ( options ) {
// Get focus
options - > setFocus ( ) ;
}
else {
options = new options_imp ( this ) ;
connect ( options , SIGNAL ( status_changed ( ) ) , this , SLOT ( optionsSaved ( ) ) ) ;
}
}
void MainWindow : : on_actionTop_tool_bar_triggered ( )
{
bool is_visible = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
toolBar - > setVisible ( is_visible ) ;
Preferences : : instance ( ) - > setToolbarDisplayed ( is_visible ) ;
2010-06-21 22:32:01 +04:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionSpeed_in_title_bar_triggered ( )
{
displaySpeedInTitle = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
Preferences : : instance ( ) - > showSpeedInTitleBar ( displaySpeedInTitle ) ;
if ( displaySpeedInTitle )
updateGUI ( ) ;
else
setWindowTitle ( QString ( " qBittorrent %1 " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
2010-06-22 17:39:49 +04:00
}
2010-06-21 22:32:01 +04:00
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionRSS_Reader_triggered ( )
{
Preferences : : instance ( ) - > setRSSEnabled ( actionRSS_Reader - > isChecked ( ) ) ;
displayRSSTab ( actionRSS_Reader - > isChecked ( ) ) ;
}
void MainWindow : : on_actionSearch_engine_triggered ( )
{
2014-09-14 15:30:22 +04:00
# ifdef Q_OS_WIN
2014-12-20 20:53:58 +03:00
if ( ! has_python & & actionSearch_engine - > isChecked ( ) ) {
bool res = false ;
2014-09-14 22:58:20 +04:00
2014-12-20 20:53:58 +03:00
// Check if python is already in PATH
2015-05-06 14:53:27 +03:00
if ( Utils : : Misc : : pythonVersion ( ) > 0 )
2014-12-20 20:53:58 +03:00
res = true ;
else
res = addPythonPathToEnv ( ) ;
if ( res ) {
has_python = true ;
}
else if ( QMessageBox : : question ( this , tr ( " Missing Python Interpreter " ) ,
tr ( " Python 2.x is required to use the search engine but it does not seem to be installed. \n Do you want to install it now? " ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
// Download and Install Python
installPython ( ) ;
actionSearch_engine - > setChecked ( false ) ;
Preferences : : instance ( ) - > setSearchEnabled ( false ) ;
return ;
}
else {
actionSearch_engine - > setChecked ( false ) ;
Preferences : : instance ( ) - > setSearchEnabled ( false ) ;
return ;
}
2014-09-14 15:30:22 +04:00
}
# endif
2014-12-20 20:53:58 +03:00
displaySearchTab ( actionSearch_engine - > isChecked ( ) ) ;
2010-06-22 17:58:22 +04:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : on_action_Import_Torrent_triggered ( )
2010-10-23 20:21:56 +04:00
{
2014-12-20 20:53:58 +03:00
TorrentImportDlg : : importTorrent ( ) ;
2010-10-23 20:21:56 +04:00
}
2009-11-06 17:30:14 +03:00
/*****************************************************
2014-12-20 20:53:58 +03:00
* *
* HTTP Downloader *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-11-06 17:30:14 +03:00
// Display an input dialog to prompt user for
// an url
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionDownload_from_URL_triggered ( )
{
if ( ! downloadFromURLDialog ) {
downloadFromURLDialog = new downloadFromURL ( this ) ;
connect ( downloadFromURLDialog , SIGNAL ( urlsReadyToBeDownloaded ( QStringList ) ) , this , SLOT ( downloadFromURLList ( QStringList ) ) ) ;
}
2009-11-06 17:30:14 +03:00
}
2010-06-22 17:58:22 +04:00
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_WIN) || defined(Q_OS_MAC)
2010-10-24 01:46:05 +04:00
2014-01-25 22:39:42 +04:00
void MainWindow : : handleUpdateCheckFinished ( bool update_available , QString new_version , bool invokedByUser )
2010-10-24 01:46:05 +04:00
{
2014-12-20 20:53:58 +03:00
QMessageBox : : StandardButton answer = QMessageBox : : Yes ;
if ( update_available ) {
answer = QMessageBox : : question ( this , tr ( " A new version is available " ) ,
tr ( " A new 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 ) ;
if ( answer = = QMessageBox : : Yes ) {
// The user want to update, let's download the update
ProgramUpdater * updater = dynamic_cast < ProgramUpdater * > ( sender ( ) ) ;
updater - > updateProgram ( ) ;
}
2010-10-24 01:46:05 +04:00
}
2014-12-20 20:53:58 +03:00
else if ( invokedByUser ) {
QMessageBox : : information ( this , tr ( " There isn't a new version available " ) ,
tr ( " There isn't a new version of qBittorrent available on Sourceforge " ) ) ;
}
sender ( ) - > deleteLater ( ) ;
actionCheck_for_updates - > setEnabled ( true ) ;
actionCheck_for_updates - > setText ( tr ( " Check for updates " ) ) ;
actionCheck_for_updates - > setToolTip ( tr ( " Check for program updates " ) ) ;
// Don't bother the user again in this session if he chose to ignore the update
if ( Preferences : : instance ( ) - > isUpdateCheckEnabled ( ) & & answer = = QMessageBox : : Yes )
programUpdateTimer . start ( ) ;
2010-10-24 01:46:05 +04:00
}
# 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
{
2014-12-20 20:53:58 +03:00
QDesktopServices : : openUrl ( QUrl ( " http://sourceforge.net/donate/index.php?group_id=163414 " ) ) ;
2010-11-08 21:17:54 +03:00
}
2010-11-14 00:15:52 +03:00
void MainWindow : : showConnectionSettings ( )
2010-11-08 21:17:54 +03:00
{
2014-12-20 20:53:58 +03:00
on_actionOptions_triggered ( ) ;
options - > showConnectionTab ( ) ;
2010-10-31 15:03:24 +03:00
}
2010-12-20 21:07:36 +03:00
2012-02-07 21:48:25 +04:00
void MainWindow : : minimizeWindow ( )
{
setWindowState ( windowState ( ) ^ Qt : : WindowMinimized ) ;
}
2010-12-20 21:07:36 +03:00
void MainWindow : : on_actionExecution_Logs_triggered ( bool checked )
{
2014-12-20 20:53:58 +03:00
if ( checked ) {
Q_ASSERT ( ! m_executionLog ) ;
m_executionLog = new ExecutionLog ( tabs ) ;
int index_tab = tabs - > addTab ( m_executionLog , tr ( " Execution Log " ) ) ;
2015-04-19 18:17:47 +03:00
tabs - > setTabIcon ( index_tab , GuiIconProvider : : instance ( ) - > getIcon ( " view-calendar-journal " ) ) ;
2014-12-20 20:53:58 +03:00
}
2015-01-26 17:00:23 +03:00
else if ( m_executionLog ) {
2014-12-20 20:53:58 +03:00
delete m_executionLog ;
2015-01-26 17:00:23 +03:00
}
2014-12-20 20:53:58 +03:00
Preferences : : instance ( ) - > setExecutionLogEnabled ( checked ) ;
2010-12-20 21:07:36 +03:00
}
2010-12-31 16:36:32 +03:00
void MainWindow : : on_actionAutoExit_qBittorrent_toggled ( bool enabled )
{
2014-12-20 20:53:58 +03:00
qDebug ( ) < < Q_FUNC_INFO < < enabled ;
Preferences : : instance ( ) - > setShutdownqBTWhenDownloadsComplete ( enabled ) ;
2010-12-31 16:36:32 +03:00
}
void MainWindow : : on_actionAutoSuspend_system_toggled ( bool enabled )
{
2014-12-20 20:53:58 +03:00
qDebug ( ) < < Q_FUNC_INFO < < enabled ;
Preferences : : instance ( ) - > setSuspendWhenDownloadsComplete ( enabled ) ;
2010-12-31 16:36:32 +03:00
}
2014-12-20 20:53:58 +03:00
void MainWindow : : on_actionAutoHibernate_system_toggled ( bool enabled )
{
qDebug ( ) < < Q_FUNC_INFO < < enabled ;
Preferences : : instance ( ) - > setHibernateWhenDownloadsComplete ( enabled ) ;
2014-07-06 13:13:36 +04:00
}
2010-12-31 16:36:32 +03:00
void MainWindow : : on_actionAutoShutdown_system_toggled ( bool enabled )
{
2014-12-20 20:53:58 +03:00
qDebug ( ) < < Q_FUNC_INFO < < enabled ;
Preferences : : instance ( ) - > setShutdownWhenDownloadsComplete ( enabled ) ;
2010-12-31 16:36:32 +03:00
}
2011-02-06 17:27:34 +03:00
void MainWindow : : checkForActiveTorrents ( )
{
2015-04-19 18:17:47 +03:00
m_pwr - > setActivityState ( BitTorrent : : Session : : instance ( ) - > hasActiveTorrents ( ) ) ;
2011-02-06 17:27:34 +03:00
}
2011-03-12 23:59:44 +03:00
QIcon MainWindow : : getSystrayIcon ( ) const
{
2014-12-20 20:53:58 +03:00
TrayIcon : : Style style = Preferences : : instance ( ) - > trayIconStyle ( ) ;
switch ( style ) {
case TrayIcon : : MONO_DARK :
2015-01-18 15:13:06 +03:00
return QIcon ( " :/icons/skin/qbittorrent_mono_dark.png " ) ;
2014-12-20 20:53:58 +03:00
case TrayIcon : : MONO_LIGHT :
2015-01-18 15:13:06 +03:00
return QIcon ( " :/icons/skin/qbittorrent_mono_light.png " ) ;
2014-12-20 20:53:58 +03:00
default :
break ;
}
2015-05-13 16:50:15 +03:00
QIcon icon ;
2015-06-21 00:56:18 +03:00
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
if ( Preferences : : instance ( ) - > useSystemIconTheme ( ) )
icon = QIcon : : fromTheme ( " qbittorrent " ) ;
# endif
if ( icon . isNull ( ) ) {
icon . addFile ( " :/icons/skin/qbittorrent22.png " , QSize ( 22 , 22 ) ) ;
icon . addFile ( " :/icons/skin/qbittorrent16.png " , QSize ( 16 , 16 ) ) ;
icon . addFile ( " :/icons/skin/qbittorrent32.png " , QSize ( 32 , 32 ) ) ;
}
2014-12-20 20:53:58 +03:00
return icon ;
2011-03-12 23:59:44 +03:00
}
2013-11-23 16:58:03 +04:00
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_WIN) || defined(Q_OS_MAC)
2014-12-20 20:53:58 +03:00
void MainWindow : : checkProgramUpdate ( )
{
programUpdateTimer . stop ( ) ; // If the user had clicked the menu item
actionCheck_for_updates - > setEnabled ( false ) ;
actionCheck_for_updates - > setText ( tr ( " Checking for updates... " ) ) ;
actionCheck_for_updates - > setToolTip ( tr ( " Already checking for program updates in the background " ) ) ;
bool invokedByUser = actionCheck_for_updates = = qobject_cast < QAction * > ( sender ( ) ) ;
ProgramUpdater * updater = new ProgramUpdater ( this , invokedByUser ) ;
connect ( updater , SIGNAL ( updateCheckFinished ( bool , QString , bool ) ) , SLOT ( handleUpdateCheckFinished ( bool , QString , bool ) ) ) ;
updater - > checkForUpdates ( ) ;
2013-11-23 16:58:03 +04:00
}
# endif
2014-09-14 15:30:22 +04:00
# ifdef Q_OS_WIN
2014-12-20 20:53:58 +03:00
bool MainWindow : : addPythonPathToEnv ( )
{
if ( has_python )
return true ;
QString python_path = Preferences : : getPythonPath ( ) ;
if ( ! python_path . isEmpty ( ) ) {
// Add it to PATH envvar
QString path_envar = QString : : fromLocal8Bit ( qgetenv ( " PATH " ) . constData ( ) ) ;
if ( path_envar . isNull ( ) )
path_envar = " " ;
path_envar = python_path + " ; " + path_envar ;
qDebug ( " New PATH envvar is: %s " , qPrintable ( path_envar ) ) ;
2015-05-06 14:53:27 +03:00
qputenv ( " PATH " , Utils : : Fs : : toNativePath ( path_envar ) . toLocal8Bit ( ) ) ;
2014-12-20 20:53:58 +03:00
return true ;
2014-09-14 15:30:22 +04:00
}
2014-12-20 20:53:58 +03:00
return false ;
}
void MainWindow : : installPython ( )
{
setCursor ( QCursor ( Qt : : WaitCursor ) ) ;
// Download python
2015-04-19 18:17:47 +03:00
Net : : DownloadHandler * handler = Net : : DownloadManager : : instance ( ) - > downloadUrl ( " http://python.org/ftp/python/2.7.3/python-2.7.3.msi " ) ;
connect ( handler , SIGNAL ( downloadFinished ( QString , QString ) ) , this , SLOT ( pythonDownloadSuccess ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFailed ( QString , QString ) ) , this , SLOT ( pythonDownloadFailure ( QString , QString ) ) ) ;
2014-12-20 20:53:58 +03:00
}
2015-04-19 18:17:47 +03:00
void MainWindow : : pythonDownloadSuccess ( const QString & url , const QString & filePath )
2014-12-20 20:53:58 +03:00
{
2015-04-19 18:17:47 +03:00
Q_UNUSED ( url )
2014-12-20 20:53:58 +03:00
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
2015-04-19 18:17:47 +03:00
QFile : : rename ( filePath , filePath + " .msi " ) ;
2014-12-20 20:53:58 +03:00
QProcess installer ;
qDebug ( " Launching Python installer in passive mode... " ) ;
2015-05-06 14:53:27 +03:00
installer . start ( " msiexec.exe /passive /i " + Utils : : Fs : : toNativePath ( filePath ) + " .msi " ) ;
2014-12-20 20:53:58 +03:00
// Wait for setup to complete
installer . waitForFinished ( ) ;
qDebug ( " Installer stdout: %s " , installer . readAllStandardOutput ( ) . data ( ) ) ;
qDebug ( " Installer stderr: %s " , installer . readAllStandardError ( ) . data ( ) ) ;
qDebug ( " Setup should be complete! " ) ;
// Delete temp file
2015-05-06 14:53:27 +03:00
Utils : : Fs : : forceRemove ( filePath ) ;
2014-12-20 20:53:58 +03:00
// Reload search engine
has_python = addPythonPathToEnv ( ) ;
if ( has_python ) {
actionSearch_engine - > setChecked ( true ) ;
displaySearchTab ( true ) ;
}
}
2015-04-19 18:17:47 +03:00
void MainWindow : : pythonDownloadFailure ( const QString & url , const QString & error )
2014-12-20 20:53:58 +03:00
{
2015-04-19 18:17:47 +03:00
Q_UNUSED ( url )
2014-12-20 20:53:58 +03:00
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
QMessageBox : : warning ( this , tr ( " Download error " ) , tr ( " Python setup could not be downloaded, reason: %1. \n Please install it manually. " ) . arg ( error ) ) ;
2014-09-14 15:30:22 +04:00
}
# endif