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