@ -333,7 +333,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
@@ -333,7 +333,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
Preferences : : setTorrentFileAssoc ( true ) ;
Preferences : : setMagnetLinkAssoc ( true ) ;
} else {
}
else {
pref - > setNeverCheckFileAssoc ( ) ;
}
}
@ -346,7 +347,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
@@ -346,7 +347,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
if ( ! systrayIcon ) {
if ( pref - > startMinimized ( ) ) {
showMinimized ( ) ;
} else {
}
else {
show ( ) ;
activateWindow ( ) ;
raise ( ) ;
@ -354,7 +356,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
@@ -354,7 +356,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
}
}
void MainWindow : : shutdownCleanUp ( ) {
void MainWindow : : shutdownCleanUp ( )
{
qDebug ( " GUI destruction " ) ;
hide ( ) ;
guiUpdater - > stop ( ) ;
@ -412,7 +415,8 @@ void MainWindow::shutdownCleanUp() {
@@ -412,7 +415,8 @@ void MainWindow::shutdownCleanUp() {
qDebug ( " Finished GUI destruction " ) ;
}
void MainWindow : : defineUILockPassword ( ) {
void MainWindow : : defineUILockPassword ( )
{
QString old_pass_md5 = Preferences : : instance ( ) - > getUILockPasswordMD5 ( ) ;
if ( old_pass_md5 . isNull ( ) ) old_pass_md5 = " " ;
bool ok = false ;
@ -423,20 +427,21 @@ void MainWindow::defineUILockPassword() {
@@ -423,20 +427,21 @@ void MainWindow::defineUILockPassword() {
QMessageBox : : warning ( this , tr ( " Invalid password " ) , tr ( " The password should contain at least 3 characters " ) ) ;
return ;
}
if ( new_clear_password ! = old_pass_md5 ) {
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 " ) ) ;
}
}
void MainWindow : : clearUILockPassword ( ) {
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 ( ) ;
}
void MainWindow : : on_actionLock_qBittorrent_triggered ( ) {
void MainWindow : : on_actionLock_qBittorrent_triggered ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
// Check if there is a password
if ( pref - > getUILockPasswordMD5 ( ) . isEmpty ( ) ) {
@ -453,7 +458,8 @@ void MainWindow::on_actionLock_qBittorrent_triggered() {
@@ -453,7 +458,8 @@ void MainWindow::on_actionLock_qBittorrent_triggered() {
hide ( ) ;
}
void MainWindow : : displayRSSTab ( bool enable ) {
void MainWindow : : displayRSSTab ( bool enable )
{
if ( enable ) {
// RSS tab
if ( ! rssWidget ) {
@ -461,14 +467,14 @@ void MainWindow::displayRSSTab(bool enable) {
@@ -461,14 +467,14 @@ void MainWindow::displayRSSTab(bool enable) {
int index_tab = tabs - > addTab ( rssWidget , tr ( " RSS " ) ) ;
tabs - > setTabIcon ( index_tab , IconProvider : : instance ( ) - > getIcon ( " application-rss+xml " ) ) ;
}
} else {
if ( rssWidget ) {
delete rssWidget ;
}
}
else if ( rssWidget )
delete rssWidget ;
}
void MainWindow : : displaySearchTab ( bool enable ) {
void MainWindow : : displaySearchTab ( bool enable )
{
Preferences : : instance ( ) - > setSearchEnabled ( enable ) ;
if ( enable ) {
// RSS tab
@ -476,30 +482,34 @@ void MainWindow::displaySearchTab(bool enable) {
@@ -476,30 +482,34 @@ void MainWindow::displaySearchTab(bool enable) {
searchEngine = new SearchEngine ( this ) ;
tabs - > insertTab ( 1 , searchEngine , IconProvider : : instance ( ) - > getIcon ( " edit-find " ) , tr ( " Search " ) ) ;
}
} else {
if ( searchEngine ) {
delete searchEngine ;
}
}
else if ( searchEngine )
delete searchEngine ;
}
void MainWindow : : updateNbTorrents ( ) {
void MainWindow : : updateNbTorrents ( )
{
tabs - > setTabText ( 0 , tr ( " Transfers (%1) " ) . arg ( transferList - > getSourceModel ( ) - > rowCount ( ) ) ) ;
}
void MainWindow : : on_actionWebsite_triggered ( ) const {
void MainWindow : : on_actionWebsite_triggered ( ) const
{
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://www.qbittorrent.org " ) ) ) ;
}
void MainWindow : : on_actionDocumentation_triggered ( ) const {
void MainWindow : : on_actionDocumentation_triggered ( ) const
{
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://doc.qbittorrent.org " ) ) ) ;
}
void MainWindow : : on_actionBugReport_triggered ( ) const {
void MainWindow : : on_actionBugReport_triggered ( ) const
{
QDesktopServices : : openUrl ( QUrl ( QString : : fromUtf8 ( " http://bugs.qbittorrent.org " ) ) ) ;
}
void MainWindow : : tab_changed ( int new_tab ) {
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
@ -509,15 +519,17 @@ void MainWindow::tab_changed(int new_tab) {
@@ -509,15 +519,17 @@ void MainWindow::tab_changed(int new_tab) {
searchFilterAct - > setVisible ( true ) ;
return ;
}
else
else {
searchFilterAct - > setVisible ( false ) ;
}
if ( tabs - > currentWidget ( ) = = searchEngine ) {
qDebug ( " Changed tab to search engine, giving focus to search input " ) ;
searchEngine - > giveFocusToSearchInput ( ) ;
}
}
void MainWindow : : writeSettings ( ) {
void MainWindow : : writeSettings ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setMainGeometry ( saveGeometry ( ) ) ;
// Splitter size
@ -525,23 +537,23 @@ void MainWindow::writeSettings() {
@@ -525,23 +537,23 @@ void MainWindow::writeSettings() {
properties - > saveSettings ( ) ;
}
void MainWindow : : readSettings ( ) {
void MainWindow : : readSettings ( )
{
const Preferences * const pref = Preferences : : instance ( ) ;
const QByteArray mainGeo = pref - > getMainGeometry ( ) ;
if ( ! mainGeo . isEmpty ( ) ) {
if ( ! mainGeo . isEmpty ( ) )
if ( restoreGeometry ( mainGeo ) )
m_posInitialized = true ;
}
const QByteArray splitterState = pref - > getMainVSplitterState ( ) ;
if ( splitterState . isEmpty ( ) ) {
if ( splitterState . isEmpty ( ) )
// Default sizes
vSplitter - > setSizes ( QList < int > ( ) < < 120 < < vSplitter - > width ( ) - 120 ) ;
} else {
else
vSplitter - > restoreState ( splitterState ) ;
}
}
void MainWindow : : balloonClicked ( ) {
void MainWindow : : balloonClicked ( )
{
if ( isHidden ( ) ) {
if ( ui_locked ) {
// Ask for UI lock password
@ -558,18 +570,21 @@ void MainWindow::balloonClicked() {
@@ -558,18 +570,21 @@ void MainWindow::balloonClicked() {
}
// called when a torrent has finished
void MainWindow : : finishedTorrent ( const QTorrentHandle & h ) const {
void MainWindow : : finishedTorrent ( const QTorrentHandle & h ) const
{
if ( TorrentPersistentData : : isSeed ( h . hash ( ) ) )
showNotificationBaloon ( tr ( " Download completion " ) , tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( h . name ( ) ) ) ;
}
// Notification when disk is full
void MainWindow : : fullDiskError ( const QTorrentHandle & h , QString msg ) const {
void MainWindow : : fullDiskError ( const QTorrentHandle & h , QString msg ) const
{
if ( ! h . is_valid ( ) ) return ;
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 ( h . name ( ) ) . arg ( msg ) ) ;
}
void MainWindow : : createKeyboardShortcuts ( ) {
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 " ) ) ) ;
@ -599,23 +614,27 @@ void MainWindow::createKeyboardShortcuts() {
@@ -599,23 +614,27 @@ void MainWindow::createKeyboardShortcuts() {
}
// Keyboard shortcuts slots
void MainWindow : : displayTransferTab ( ) const {
void MainWindow : : displayTransferTab ( ) const
{
tabs - > setCurrentWidget ( transferList ) ;
}
void MainWindow : : displaySearchTab ( ) const {
void MainWindow : : displaySearchTab ( ) const
{
if ( searchEngine )
tabs - > setCurrentWidget ( searchEngine ) ;
}
void MainWindow : : displayRSSTab ( ) const {
void MainWindow : : displayRSSTab ( ) const
{
if ( rssWidget )
tabs - > setCurrentWidget ( rssWidget ) ;
}
// End of keyboard shortcuts slots
void MainWindow : : askRecursiveTorrentDownloadConfirmation ( const QTorrentHandle & h ) {
void MainWindow : : askRecursiveTorrentDownloadConfirmation ( const QTorrentHandle & h )
{
Preferences * const pref = Preferences : : instance ( ) ;
if ( pref - > recursiveDownloadDisabled ( ) ) return ;
// Get Torrent name
@ -635,17 +654,18 @@ void MainWindow::askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h
@@ -635,17 +654,18 @@ void MainWindow::askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h
QBtSession : : instance ( ) - > recursiveTorrentDownload ( h ) ;
return ;
}
if ( confirmBox . clickedButton ( ) = = never ) {
if ( confirmBox . clickedButton ( ) = = never )
pref - > disableRecursiveDownload ( ) ;
}
}
void MainWindow : : handleDownloadFromUrlFailure ( QString url , QString reason ) const {
void MainWindow : : handleDownloadFromUrlFailure ( QString url , QString reason ) const
{
// Display a message box
showNotificationBaloon ( tr ( " Url download error " ) , tr ( " Couldn't download file at url: %1, reason: %2. " ) . arg ( url ) . arg ( reason ) ) ;
}
void MainWindow : : on_actionSet_global_upload_limit_triggered ( ) {
void MainWindow : : on_actionSet_global_upload_limit_triggered ( )
{
qDebug ( " actionSet_global_upload_limit_triggered " ) ;
bool ok ;
int cur_limit = QBtSession : : instance ( ) - > getSession ( ) - > settings ( ) . upload_rate_limit ;
@ -660,7 +680,8 @@ void MainWindow::on_actionSet_global_upload_limit_triggered() {
@@ -660,7 +680,8 @@ void MainWindow::on_actionSet_global_upload_limit_triggered() {
}
}
void MainWindow : : on_actionSet_global_download_limit_triggered ( ) {
void MainWindow : : on_actionSet_global_download_limit_triggered ( )
{
qDebug ( " actionSet_global_download_limit_triggered " ) ;
bool ok ;
int cur_limit = QBtSession : : instance ( ) - > getSession ( ) - > settings ( ) . download_rate_limit ;
@ -677,7 +698,8 @@ void MainWindow::on_actionSet_global_download_limit_triggered() {
@@ -677,7 +698,8 @@ void MainWindow::on_actionSet_global_download_limit_triggered() {
// Necessary if we want to close the window
// in one time if "close to systray" is enabled
void MainWindow : : on_actionExit_triggered ( ) {
void MainWindow : : on_actionExit_triggered ( )
{
// UI locking enforcement.
if ( isHidden ( ) & & ui_locked ) {
// Ask for UI lock password
@ -689,7 +711,8 @@ void MainWindow::on_actionExit_triggered() {
@@ -689,7 +711,8 @@ void MainWindow::on_actionExit_triggered() {
close ( ) ;
}
QWidget * MainWindow : : getCurrentTabWidget ( ) const {
QWidget * MainWindow : : getCurrentTabWidget ( ) const
{
if ( isMinimized ( ) | | ! isVisible ( ) )
return 0 ;
if ( tabs - > currentIndex ( ) = = 0 )
@ -697,11 +720,13 @@ QWidget* MainWindow::getCurrentTabWidget() const {
@@ -697,11 +720,13 @@ QWidget* MainWindow::getCurrentTabWidget() const {
return tabs - > currentWidget ( ) ;
}
void MainWindow : : setTabText ( int index , QString text ) const {
void MainWindow : : setTabText ( int index , QString text ) const
{
tabs - > setTabText ( index , text ) ;
}
bool MainWindow : : unlockUI ( ) {
bool MainWindow : : unlockUI ( )
{
if ( unlockDlgShowing )
return false ;
else
@ -726,7 +751,8 @@ bool MainWindow::unlockUI() {
@@ -726,7 +751,8 @@ bool MainWindow::unlockUI() {
return false ;
}
void MainWindow : : notifyOfUpdate ( QString ) {
void MainWindow : : notifyOfUpdate ( QString )
{
// Show restart message
status_bar - > showRestartRequired ( ) ;
// Delete the executable watcher
@ -735,7 +761,8 @@ void MainWindow::notifyOfUpdate(QString) {
@@ -735,7 +761,8 @@ void MainWindow::notifyOfUpdate(QString) {
}
// Toggle Main window visibility
void MainWindow : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e ) {
void MainWindow : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e )
{
if ( e = = QSystemTrayIcon : : Trigger | | e = = QSystemTrayIcon : : DoubleClick ) {
if ( isHidden ( ) ) {
if ( ui_locked ) {
@ -749,35 +776,37 @@ void MainWindow::toggleVisibility(QSystemTrayIcon::ActivationReason e) {
@@ -749,35 +776,37 @@ void MainWindow::toggleVisibility(QSystemTrayIcon::ActivationReason e) {
show ( ) ;
raise ( ) ;
activateWindow ( ) ;
} else {
}
else {
hide ( ) ;
}
}
}
// Display About Dialog
void MainWindow : : on_actionAbout_triggered ( ) {
void MainWindow : : on_actionAbout_triggered ( )
{
//About dialog
if ( aboutDlg ) {
if ( aboutDlg )
aboutDlg - > setFocus ( ) ;
} else {
else
aboutDlg = new about ( this ) ;
}
}
void MainWindow : : on_actionStatistics_triggered ( ) {
void MainWindow : : on_actionStatistics_triggered ( )
{
if ( statsDlg )
statsDlg - > setFocus ( ) ;
else
statsDlg = new StatsDialog ( this ) ;
}
void MainWindow : : showEvent ( QShowEvent * e ) {
void MainWindow : : showEvent ( QShowEvent * e )
{
qDebug ( " ** Show Event ** " ) ;
if ( getCurrentTabWidget ( ) = = transferList ) {
if ( getCurrentTabWidget ( ) = = transferList )
properties - > loadDynamicData ( ) ;
}
e - > accept ( ) ;
@ -789,7 +818,8 @@ void MainWindow::showEvent(QShowEvent *e) {
@@ -789,7 +818,8 @@ void MainWindow::showEvent(QShowEvent *e) {
}
// Called when we close the program
void MainWindow : : closeEvent ( QCloseEvent * e ) {
void MainWindow : : closeEvent ( QCloseEvent * e )
{
Preferences * const pref = Preferences : : instance ( ) ;
const bool goToSystrayOnExit = pref - > closeToTray ( ) ;
if ( ! force_exit & & systrayIcon & & goToSystrayOnExit & & ! this - > isHidden ( ) ) {
@ -815,17 +845,15 @@ void MainWindow::closeEvent(QCloseEvent *e) {
@@ -815,17 +845,15 @@ void MainWindow::closeEvent(QCloseEvent *e) {
force_exit = false ;
return ;
}
if ( confirmBox . clickedButton ( ) = = alwaysBtn ) {
if ( confirmBox . clickedButton ( ) = = alwaysBtn )
// Remember choice
Preferences : : instance ( ) - > setConfirmOnExit ( false ) ;
}
}
}
hide ( ) ;
if ( systrayIcon ) {
if ( systrayIcon )
// Hide tray icon
systrayIcon - > hide ( ) ;
}
// Save window size, columns size
writeSettings ( ) ;
// Accept exit
@ -834,16 +862,19 @@ void MainWindow::closeEvent(QCloseEvent *e) {
@@ -834,16 +862,19 @@ void MainWindow::closeEvent(QCloseEvent *e) {
}
// Display window to create a torrent
void MainWindow : : on_actionCreate_torrent_triggered ( ) {
void MainWindow : : on_actionCreate_torrent_triggered ( )
{
if ( createTorrentDlg ) {
createTorrentDlg - > setFocus ( ) ;
} else {
}
else {
createTorrentDlg = new TorrentCreatorDlg ( this ) ;
connect ( createTorrentDlg , SIGNAL ( torrent_to_seed ( QString ) ) , this , SLOT ( addTorrent ( QString ) ) ) ;
}
}
bool MainWindow : : event ( QEvent * e ) {
bool MainWindow : : event ( QEvent * e )
{
switch ( e - > type ( ) ) {
case QEvent : : WindowStateChange : {
qDebug ( " Window change event " ) ;
@ -889,7 +920,8 @@ bool MainWindow::event(QEvent * e) {
@@ -889,7 +920,8 @@ bool MainWindow::event(QEvent * e) {
}
// Action executed when a file is dropped
void MainWindow : : dropEvent ( QDropEvent * event ) {
void MainWindow : : dropEvent ( QDropEvent * event )
{
event - > acceptProposedAction ( ) ;
QStringList files ;
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
@ -902,7 +934,8 @@ void MainWindow::dropEvent(QDropEvent *event) {
@@ -902,7 +934,8 @@ void MainWindow::dropEvent(QDropEvent *event) {
files < < url . toString ( ) ;
}
}
} else {
}
else {
files = event - > mimeData ( ) - > text ( ) . split ( QString : : fromUtf8 ( " \n " ) ) ;
}
// Add file to download list
@ -924,7 +957,8 @@ void MainWindow::dropEvent(QDropEvent *event) {
@@ -924,7 +957,8 @@ void MainWindow::dropEvent(QDropEvent *event) {
AddNewTorrentDialog : : showMagnet ( file , this ) ;
else
QBtSession : : instance ( ) - > addMagnetUri ( file ) ;
} else {
}
else {
// Local file
if ( useTorrentAdditionDialog )
AddNewTorrentDialog : : showTorrent ( file , QString ( ) , this ) ;
@ -935,14 +969,13 @@ void MainWindow::dropEvent(QDropEvent *event) {
@@ -935,14 +969,13 @@ void MainWindow::dropEvent(QDropEvent *event) {
}
// Decode if we accept drag 'n drop or not
void MainWindow : : dragEnterEvent ( QDragEnterEvent * event ) {
foreach ( const QString & mime , event - > mimeData ( ) - > formats ( ) ) {
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 " ) ) ) {
if ( event - > mimeData ( ) - > hasFormat ( QString : : fromUtf8 ( " text/plain " ) ) | | event - > mimeData ( ) - > hasFormat ( QString : : fromUtf8 ( " text/uri-list " ) ) )
event - > acceptProposedAction ( ) ;
}
}
/*****************************************************
* *
@ -952,7 +985,8 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
@@ -952,7 +985,8 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
// Display a dialog to allow user to add
// torrents to download list
void MainWindow : : on_actionOpen_triggered ( ) {
void MainWindow : : on_actionOpen_triggered ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
// Open File Open Dialog
// Note: it is possible to select more than one file
@ -978,23 +1012,25 @@ void MainWindow::on_actionOpen_triggered() {
@@ -978,23 +1012,25 @@ void MainWindow::on_actionOpen_triggered() {
// This function parse the parameters and call
// the right addTorrent function, considering
// the parameter type.
void MainWindow : : processParams ( const QString & params_str ) {
void MainWindow : : processParams ( const QString & params_str )
{
processParams ( params_str . split ( " | " , QString : : SkipEmptyParts ) ) ;
}
void MainWindow : : processParams ( const QStringList & params ) {
void MainWindow : : processParams ( const QStringList & params )
{
Preferences * const pref = Preferences : : instance ( ) ;
const bool useTorrentAdditionDialog = pref - > useAdditionDialog ( ) ;
foreach ( QString param , params ) {
param = param . trimmed ( ) ;
if ( misc : : isUrl ( param ) ) {
QBtSession : : instance ( ) - > downloadFromUrl ( param ) ;
} else {
}
else {
if ( param . startsWith ( " qbt://show " ) ) {
if ( ui_locked ) {
if ( ui_locked )
if ( ! unlockUI ( ) )
return ;
}
show ( ) ;
activateWindow ( ) ;
raise ( ) ;
@ -1009,7 +1045,8 @@ void MainWindow::processParams(const QStringList& params) {
@@ -1009,7 +1045,8 @@ void MainWindow::processParams(const QStringList& params) {
AddNewTorrentDialog : : showMagnet ( param , this ) ;
else
QBtSession : : instance ( ) - > addMagnetUri ( param ) ;
} else {
}
else {
if ( useTorrentAdditionDialog )
AddNewTorrentDialog : : showTorrent ( param , QString ( ) , this ) ;
else
@ -1019,11 +1056,13 @@ void MainWindow::processParams(const QStringList& params) {
@@ -1019,11 +1056,13 @@ void MainWindow::processParams(const QStringList& params) {
}
}
void MainWindow : : addTorrent ( QString path ) {
void MainWindow : : addTorrent ( QString path )
{
QBtSession : : instance ( ) - > addTorrent ( path ) ;
}
void MainWindow : : processDownloadedFiles ( QString path , QString url ) {
void MainWindow : : processDownloadedFiles ( QString path , QString url )
{
Preferences * const pref = Preferences : : instance ( ) ;
if ( pref - > useAdditionDialog ( ) )
AddNewTorrentDialog : : showTorrent ( path , url , this ) ;
@ -1031,7 +1070,8 @@ void MainWindow::processDownloadedFiles(QString path, QString url) {
@@ -1031,7 +1070,8 @@ void MainWindow::processDownloadedFiles(QString path, QString url) {
QBtSession : : instance ( ) - > addTorrent ( path , false , url ) ;
}
void MainWindow : : processNewMagnetLink ( const QString & link ) {
void MainWindow : : processNewMagnetLink ( const QString & link )
{
Preferences * const pref = Preferences : : instance ( ) ;
if ( pref - > useAdditionDialog ( ) )
AddNewTorrentDialog : : showMagnet ( link , this ) ;
@ -1039,12 +1079,14 @@ void MainWindow::processNewMagnetLink(const QString& link) {
@@ -1039,12 +1079,14 @@ void MainWindow::processNewMagnetLink(const QString& link) {
QBtSession : : instance ( ) - > addMagnetUri ( link ) ;
}
void MainWindow : : optionsSaved ( ) {
void MainWindow : : optionsSaved ( )
{
loadPreferences ( ) ;
}
// Load program preferences
void MainWindow : : loadPreferences ( bool configure_session ) {
void MainWindow : : loadPreferences ( bool configure_session )
{
QBtSession : : instance ( ) - > addConsoleMessage ( tr ( " Options were saved successfully. " ) ) ;
const Preferences * const pref = Preferences : : instance ( ) ;
const bool newSystrayIntegration = pref - > systrayIntegration ( ) ;
@ -1059,37 +1101,38 @@ void MainWindow::loadPreferences(bool configure_session) {
@@ -1059,37 +1101,38 @@ void MainWindow::loadPreferences(bool configure_session) {
systrayCreator - > setSingleShot ( true ) ;
systrayCreator - > start ( 2000 ) ;
qDebug ( " Info: System tray is unavailable, trying again later. " ) ;
} else {
}
else {
qDebug ( " Warning: System tray is unavailable. " ) ;
}
} else {
}
else {
createTrayIcon ( ) ;
}
} else {
}
else {
// Destroy trayicon
delete systrayIcon ;
delete myTrayIconMenu ;
}
}
// Reload systray icon
if ( newSystrayIntegration & & systrayIcon ) {
if ( newSystrayIntegration & & systrayIcon )
systrayIcon - > setIcon ( getSystrayIcon ( ) ) ;
}
// General
if ( pref - > isToolbarDisplayed ( ) ) {
toolBar - > setVisible ( true ) ;
} else {
}
else {
// Clear search filter before hiding the top toolbar
search_filter - > clear ( ) ;
toolBar - > setVisible ( false ) ;
}
if ( pref - > preventFromSuspend ( ) )
{
if ( pref - > preventFromSuspend ( ) ) {
preventTimer - > start ( PREVENT_SUSPEND_INTERVAL ) ;
}
else
{
else {
preventTimer - > stop ( ) ;
m_pwr - > setActivityState ( false ) ;
}
@ -1112,7 +1155,8 @@ void MainWindow::loadPreferences(bool configure_session) {
@@ -1112,7 +1155,8 @@ void MainWindow::loadPreferences(bool configure_session) {
prioSeparator - > setVisible ( true ) ;
prioSeparatorMenu - > setVisible ( true ) ;
}
} else {
}
else {
if ( actionDecreasePriority - > isVisible ( ) ) {
transferList - > hidePriorityColumn ( true ) ;
actionDecreasePriority - > setVisible ( false ) ;
@ -1145,23 +1189,24 @@ void MainWindow::loadPreferences(bool configure_session) {
@@ -1145,23 +1189,24 @@ void MainWindow::loadPreferences(bool configure_session) {
qDebug ( " GUI settings loaded " ) ;
}
void MainWindow : : addUnauthenticatedTracker ( const QPair < QTorrentHandle , QString > & tracker ) {
void MainWindow : : addUnauthenticatedTracker ( const QPair < QTorrentHandle , QString > & tracker )
{
// Trackers whose authentication was cancelled
if ( unauthenticated_trackers . indexOf ( tracker ) < 0 ) {
if ( unauthenticated_trackers . indexOf ( tracker ) < 0 )
unauthenticated_trackers < < tracker ;
}
}
// Called when a tracker requires authentication
void MainWindow : : trackerAuthenticationRequired ( const QTorrentHandle & h ) {
if ( unauthenticated_trackers . indexOf ( QPair < QTorrentHandle , QString > ( h , h . current_tracker ( ) ) ) < 0 ) {
void MainWindow : : trackerAuthenticationRequired ( const QTorrentHandle & h )
{
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
void MainWindow : : updateGUI ( ) {
void MainWindow : : updateGUI ( )
{
// update global informations
if ( systrayIcon ) {
# if defined(Q_OS_UNIX)
@ -1182,12 +1227,12 @@ void MainWindow::updateGUI() {
@@ -1182,12 +1227,12 @@ void MainWindow::updateGUI() {
# endif
systrayIcon - > setToolTip ( html ) ; // tray icon
}
if ( displaySpeedInTitle ) {
if ( displaySpeedInTitle )
setWindowTitle ( tr ( " [D: %1/s, U: %2/s] qBittorrent %3 " , " D = Download; U = Upload; %3 is qBittorrent version " ) . arg ( misc : : friendlyUnit ( QBtSession : : instance ( ) - > getSessionStatus ( ) . payload_download_rate ) ) . arg ( misc : : friendlyUnit ( QBtSession : : instance ( ) - > getSessionStatus ( ) . payload_upload_rate ) ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
}
}
void MainWindow : : showNotificationBaloon ( QString title , QString msg ) const {
void MainWindow : : showNotificationBaloon ( QString title , QString msg ) const
{
if ( ! Preferences : : instance ( ) - > useProgramNotification ( ) ) return ;
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
org : : freedesktop : : Notifications notifications ( " org.freedesktop.Notifications " ,
@ -1220,7 +1265,8 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const {
@@ -1220,7 +1265,8 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const {
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void MainWindow : : downloadFromURLList ( const QStringList & url_list ) {
void MainWindow : : downloadFromURLList ( const QStringList & url_list )
{
Preferences * const pref = Preferences : : instance ( ) ;
const bool useTorrentAdditionDialog = pref - > useAdditionDialog ( ) ;
foreach ( QString url , url_list ) {
@ -1229,9 +1275,8 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) {
@@ -1229,9 +1275,8 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) {
url = misc : : bcLinkToMagnet ( url ) ;
}
if ( ( url . size ( ) = = 40 & & ! url . contains ( QRegExp ( " [^0-9A-Fa-f] " ) ) )
| | ( url . size ( ) = = 32 & & ! url . contains ( QRegExp ( " [^2-7A-Za-z] " ) ) ) ) {
| | ( url . size ( ) = = 32 & & ! url . contains ( QRegExp ( " [^2-7A-Za-z] " ) ) ) )
url = " magnet:?xt=urn:btih: " + url ;
}
if ( url . startsWith ( " magnet: " , Qt : : CaseInsensitive ) ) {
if ( useTorrentAdditionDialog )
AddNewTorrentDialog : : showMagnet ( url , this ) ;
@ -1251,19 +1296,22 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) {
@@ -1251,19 +1296,22 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) {
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void MainWindow : : createSystrayDelayed ( ) {
void MainWindow : : createSystrayDelayed ( )
{
static int timeout = 20 ;
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
// Ok, systray integration is now supported
// Create systray icon
createTrayIcon ( ) ;
delete systrayCreator ;
} else {
}
else {
if ( timeout ) {
// Retry a bit later
systrayCreator - > start ( 2000 ) ;
- - timeout ;
} else {
}
else {
// Timed out, apparently system really does not
// support systray icon
delete systrayCreator ;
@ -1274,7 +1322,8 @@ void MainWindow::createSystrayDelayed() {
@@ -1274,7 +1322,8 @@ void MainWindow::createSystrayDelayed() {
}
}
void MainWindow : : updateAltSpeedsBtn ( bool alternative ) {
void MainWindow : : updateAltSpeedsBtn ( bool alternative )
{
actionUse_alternative_speed_limits - > setChecked ( alternative ) ;
}
@ -1283,7 +1332,8 @@ void MainWindow::updateTrayIconMenu()
@@ -1283,7 +1332,8 @@ void MainWindow::updateTrayIconMenu()
actionToggleVisibility - > setText ( isVisible ( ) ? tr ( " Hide " ) : tr ( " Show " ) ) ;
}
QMenu * MainWindow : : getTrayIconMenu ( ) {
QMenu * MainWindow : : getTrayIconMenu ( )
{
if ( myTrayIconMenu )
return myTrayIconMenu ;
// Tray icon Menu
@ -1310,7 +1360,8 @@ QMenu* MainWindow::getTrayIconMenu() {
@@ -1310,7 +1360,8 @@ QMenu* MainWindow::getTrayIconMenu() {
return myTrayIconMenu ;
}
void MainWindow : : createTrayIcon ( ) {
void MainWindow : : createTrayIcon ( )
{
// Tray icon
systrayIcon = new QSystemTrayIcon ( getSystrayIcon ( ) , this ) ;
@ -1322,23 +1373,27 @@ void MainWindow::createTrayIcon() {
@@ -1322,23 +1373,27 @@ void MainWindow::createTrayIcon() {
}
// Display Program Options
void MainWindow : : on_actionOptions_triggered ( ) {
void MainWindow : : on_actionOptions_triggered ( )
{
if ( options ) {
// Get focus
options - > setFocus ( ) ;
} else {
}
else {
options = new options_imp ( this ) ;
connect ( options , SIGNAL ( status_changed ( ) ) , this , SLOT ( optionsSaved ( ) ) ) ;
}
}
void MainWindow : : on_actionTop_tool_bar_triggered ( ) {
void MainWindow : : on_actionTop_tool_bar_triggered ( )
{
bool is_visible = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
toolBar - > setVisible ( is_visible ) ;
Preferences : : instance ( ) - > setToolbarDisplayed ( is_visible ) ;
}
void MainWindow : : on_actionSpeed_in_title_bar_triggered ( ) {
void MainWindow : : on_actionSpeed_in_title_bar_triggered ( )
{
displaySpeedInTitle = static_cast < QAction * > ( sender ( ) ) - > isChecked ( ) ;
Preferences : : instance ( ) - > showSpeedInTitleBar ( displaySpeedInTitle ) ;
if ( displaySpeedInTitle )
@ -1347,12 +1402,14 @@ void MainWindow::on_actionSpeed_in_title_bar_triggered() {
@@ -1347,12 +1402,14 @@ void MainWindow::on_actionSpeed_in_title_bar_triggered() {
setWindowTitle ( QString ( " qBittorrent %1 " ) . arg ( QString : : fromUtf8 ( VERSION ) ) ) ;
}
void MainWindow : : on_actionRSS_Reader_triggered ( ) {
void MainWindow : : on_actionRSS_Reader_triggered ( )
{
Preferences : : instance ( ) - > setRSSEnabled ( actionRSS_Reader - > isChecked ( ) ) ;
displayRSSTab ( actionRSS_Reader - > isChecked ( ) ) ;
}
void MainWindow : : on_actionSearch_engine_triggered ( ) {
void MainWindow : : on_actionSearch_engine_triggered ( )
{
# ifdef Q_OS_WIN
if ( ! has_python & & actionSearch_engine - > isChecked ( ) ) {
bool res = false ;
@ -1363,8 +1420,9 @@ void MainWindow::on_actionSearch_engine_triggered() {
@@ -1363,8 +1420,9 @@ void MainWindow::on_actionSearch_engine_triggered() {
else
res = addPythonPathToEnv ( ) ;
if ( res )
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 ) {
@ -1397,7 +1455,8 @@ void MainWindow::on_action_Import_Torrent_triggered()
@@ -1397,7 +1455,8 @@ void MainWindow::on_action_Import_Torrent_triggered()
// Display an input dialog to prompt user for
// an url
void MainWindow : : on_actionDownload_from_URL_triggered ( ) {
void MainWindow : : on_actionDownload_from_URL_triggered ( )
{
if ( ! downloadFromURLDialog ) {
downloadFromURLDialog = new downloadFromURL ( this ) ;
connect ( downloadFromURLDialog , SIGNAL ( urlsReadyToBeDownloaded ( QStringList ) ) , this , SLOT ( downloadFromURLList ( QStringList ) ) ) ;
@ -1456,10 +1515,9 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked)
@@ -1456,10 +1515,9 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked)
m_executionLog = new ExecutionLog ( tabs ) ;
int index_tab = tabs - > addTab ( m_executionLog , tr ( " Execution Log " ) ) ;
tabs - > setTabIcon ( index_tab , IconProvider : : instance ( ) - > getIcon ( " view-calendar-journal " ) ) ;
} else {
if ( m_executionLog )
delete m_executionLog ;
}
else if ( m_executionLog )
delete m_executionLog ;
Preferences : : instance ( ) - > setExecutionLogEnabled ( checked ) ;
}
@ -1475,7 +1533,8 @@ void MainWindow::on_actionAutoSuspend_system_toggled(bool enabled)
@@ -1475,7 +1533,8 @@ void MainWindow::on_actionAutoSuspend_system_toggled(bool enabled)
Preferences : : instance ( ) - > setSuspendWhenDownloadsComplete ( enabled ) ;
}
void MainWindow : : on_actionAutoHibernate_system_toggled ( bool enabled ) {
void MainWindow : : on_actionAutoHibernate_system_toggled ( bool enabled )
{
qDebug ( ) < < Q_FUNC_INFO < < enabled ;
Preferences : : instance ( ) - > setHibernateWhenDownloadsComplete ( enabled ) ;
}
@ -1506,9 +1565,9 @@ QIcon MainWindow::getSystrayIcon() const
@@ -1506,9 +1565,9 @@ QIcon MainWindow::getSystrayIcon() const
# endif
QIcon icon ;
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
if ( Preferences : : instance ( ) - > useSystemIconTheme ( ) ) {
if ( Preferences : : instance ( ) - > useSystemIconTheme ( ) )
icon = QIcon : : fromTheme ( " qbittorrent " ) ;
}
# endif
if ( icon . isNull ( ) ) {
icon . addFile ( " :/Icons/skin/qbittorrent22.png " , QSize ( 22 , 22 ) ) ;
@ -1519,7 +1578,8 @@ QIcon MainWindow::getSystrayIcon() const
@@ -1519,7 +1578,8 @@ QIcon MainWindow::getSystrayIcon() const
}
# if defined(Q_OS_WIN) || defined(Q_OS_MAC)
void MainWindow : : checkProgramUpdate ( ) {
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... " ) ) ;
@ -1532,16 +1592,16 @@ void MainWindow::checkProgramUpdate() {
@@ -1532,16 +1592,16 @@ void MainWindow::checkProgramUpdate() {
# endif
# ifdef Q_OS_WIN
bool MainWindow : : addPythonPathToEnv ( ) {
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 ( ) ) {
if ( path_envar . isNull ( ) )
path_envar = " " ;
}
path_envar = python_path + " ; " + path_envar ;
qDebug ( " New PATH envvar is: %s " , qPrintable ( path_envar ) ) ;
qputenv ( " PATH " , fsutils : : toNativePath ( path_envar ) . toLocal8Bit ( ) ) ;
@ -1550,7 +1610,8 @@ bool MainWindow::addPythonPathToEnv() {
@@ -1550,7 +1610,8 @@ bool MainWindow::addPythonPathToEnv() {
return false ;
}
void MainWindow : : installPython ( ) {
void MainWindow : : installPython ( )
{
setCursor ( QCursor ( Qt : : WaitCursor ) ) ;
// Download python
DownloadThread * pydownloader = new DownloadThread ( this ) ;
@ -1559,7 +1620,8 @@ void MainWindow::installPython() {
@@ -1559,7 +1620,8 @@ void MainWindow::installPython() {
pydownloader - > downloadUrl ( " http://python.org/ftp/python/2.7.3/python-2.7.3.msi " ) ;
}
void MainWindow : : pythonDownloadSuccess ( QString url , QString file_path ) {
void MainWindow : : pythonDownloadSuccess ( QString url , QString file_path )
{
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
Q_UNUSED ( url ) ;
QFile : : rename ( file_path , file_path + " .msi " ) ;
@ -1584,7 +1646,8 @@ void MainWindow::pythonDownloadSuccess(QString url, QString file_path) {
@@ -1584,7 +1646,8 @@ void MainWindow::pythonDownloadSuccess(QString url, QString file_path) {
sender ( ) - > deleteLater ( ) ;
}
void MainWindow : : pythonDownloadFailure ( QString url , QString error ) {
void MainWindow : : pythonDownloadFailure ( QString url , QString error )
{
Q_UNUSED ( url ) ;
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 ) ) ;