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
*/
# include <QTextStream>
# include <QFileDialog>
# include <QMessageBox>
2006-10-19 00:48:41 +04:00
# include <QSystemTrayIcon>
2007-03-29 22:43:04 +04:00
# include <QApplication>
2007-04-11 22:19:20 +04:00
# include <QDialogButtonBox>
2007-07-23 16:56:57 +04:00
# include <QCloseEvent>
2009-03-15 20:48:20 +03:00
# include <QDesktopWidget>
2010-09-25 16:42:19 +04:00
# include <QTranslator>
2011-04-15 17:02:39 +04:00
# include <QDesktopServices>
2014-07-05 16:44:13 +04:00
# include <QDebug>
2006-09-30 20:02:39 +04:00
2010-06-07 12:32:41 +04:00
# include <libtorrent/version.hpp>
2009-08-25 13:19:02 +04:00
2006-09-30 20:02:39 +04:00
# include "options_imp.h"
2009-11-14 22:08:28 +03:00
# include "preferences.h"
2012-05-16 22:19:05 +04:00
# include "fs_utils.h"
2010-01-31 18:11:15 +03:00
# include "advancedsettings.h"
2010-02-28 18:15:00 +03:00
# include "scannedfoldersmodel.h"
2010-12-25 17:47:52 +03:00
# include "qbtsession.h"
2011-01-01 16:05:28 +03:00
# include "iconprovider.h"
2011-04-15 17:02:39 +04:00
# include "dnsupdater.h"
2006-09-30 20:02:39 +04:00
2011-06-05 20:08:30 +04:00
# ifndef QT_NO_OPENSSL
# include <QSslKey>
# include <QSslCertificate>
# endif
2010-11-23 00:55:32 +03:00
using namespace libtorrent ;
2006-09-30 20:02:39 +04:00
// Constructor
2010-12-25 17:47:52 +03:00
options_imp : : options_imp ( QWidget * parent ) :
QDialog ( parent ) , m_refreshingIpFilter ( false ) {
2007-03-10 21:14:53 +03:00
qDebug ( " -> Constructing Options " ) ;
2010-12-12 22:37:59 +03:00
setupUi ( this ) ;
2009-11-14 22:08:28 +03:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
2010-03-10 23:21:56 +03:00
setModal ( true ) ;
2010-12-12 22:37:59 +03:00
// Icons
2011-01-01 16:05:28 +03:00
tabSelection - > item ( TAB_UI ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " preferences-desktop " ) ) ;
tabSelection - > item ( TAB_BITTORRENT ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " preferences-system-network " ) ) ;
tabSelection - > item ( TAB_CONNECTION ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " network-wired " ) ) ;
tabSelection - > item ( TAB_DOWNLOADS ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " download " ) ) ;
tabSelection - > item ( TAB_SPEED ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " chronometer " ) ) ;
tabSelection - > item ( TAB_WEBUI ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " network-server " ) ) ;
tabSelection - > item ( TAB_ADVANCED ) - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " preferences-other " ) ) ;
IpFilterRefreshBtn - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " view-refresh " ) ) ;
2010-03-10 23:21:56 +03:00
2010-03-13 17:10:26 +03:00
hsplitter - > setCollapsible ( 0 , false ) ;
hsplitter - > setCollapsible ( 1 , false ) ;
2007-04-11 22:19:20 +04:00
// Get apply button in button box
QList < QAbstractButton * > buttons = buttonBox - > buttons ( ) ;
2012-02-20 21:56:07 +04:00
foreach ( QAbstractButton * button , buttons ) {
if ( buttonBox - > buttonRole ( button ) = = QDialogButtonBox : : ApplyRole ) {
2007-04-11 22:19:20 +04:00
applyButton = button ;
break ;
}
}
2010-02-28 18:15:00 +03:00
2013-09-21 11:59:58 +04:00
# if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
2010-02-28 18:15:00 +03:00
scanFoldersView - > horizontalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
2013-09-21 11:59:58 +04:00
# else
scanFoldersView - > horizontalHeader ( ) - > setSectionResizeMode ( QHeaderView : : ResizeToContents ) ;
# endif
2010-02-28 18:15:00 +03:00
scanFoldersView - > setModel ( ScanFoldersModel : : instance ( ) ) ;
connect ( ScanFoldersModel : : instance ( ) , SIGNAL ( dataChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( scanFoldersView - > selectionModel ( ) , SIGNAL ( selectionChanged ( QItemSelection , QItemSelection ) ) , this , SLOT ( handleScanFolderViewSelectionChanged ( ) ) ) ;
2007-04-11 22:19:20 +04:00
connect ( buttonBox , SIGNAL ( clicked ( QAbstractButton * ) ) , this , SLOT ( applySettings ( QAbstractButton * ) ) ) ;
2006-09-30 20:02:39 +04:00
// Languages supported
2010-11-20 18:59:17 +03:00
initializeLanguageCombo ( ) ;
2006-09-30 20:02:39 +04:00
2010-01-23 23:44:09 +03:00
// Load week days (scheduler)
2012-02-20 21:30:53 +04:00
for ( uint i = 1 ; i < = 7 ; + + i ) {
2010-01-23 23:44:09 +03:00
schedule_days - > addItem ( QDate : : longDayName ( i , QDate : : StandaloneFormat ) ) ;
}
2006-11-14 23:26:32 +03:00
// Load options
loadOptions ( ) ;
2007-03-29 23:54:45 +04:00
// Disable systray integration if it is not supported by the system
2012-02-20 21:56:07 +04:00
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
2010-10-09 19:36:39 +04:00
checkShowSystray - > setChecked ( false ) ;
checkShowSystray - > setEnabled ( false ) ;
}
2013-09-21 11:59:58 +04:00
# if (!defined(Q_OS_UNIX) || defined(Q_OS_MAC))
2011-03-27 12:34:51 +04:00
label_trayIconStyle - > setVisible ( false ) ;
comboTrayIcon - > setVisible ( false ) ;
2011-06-05 20:08:30 +04:00
# endif
# if defined(QT_NO_OPENSSL)
checkWebUiHttps - > setVisible ( false ) ;
2011-03-12 23:59:44 +03:00
# endif
2011-09-18 17:42:50 +04:00
2013-09-21 11:59:58 +04:00
# ifndef Q_OS_WIN
2012-10-08 00:05:33 +04:00
checkStartup - > setVisible ( false ) ;
2011-09-18 17:42:50 +04:00
groupFileAssociation - > setVisible ( false ) ;
# endif
2010-10-09 19:36:39 +04:00
// Connect signals / slots
2010-11-18 23:05:56 +03:00
connect ( comboProxyType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableProxy ( int ) ) ) ;
2012-09-16 02:28:58 +04:00
connect ( checkRandomPort , SIGNAL ( toggled ( bool ) ) , spinPort , SLOT ( setDisabled ( bool ) ) ) ;
2010-10-09 19:36:39 +04:00
// Apply button is activated when a value is changed
// General tab
connect ( comboI18n , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkAltRowColors , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkShowSystray , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkCloseToSystray , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkMinimizeToSysTray , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkStartMinimized , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_WIN
2012-10-08 00:05:33 +04:00
connect ( checkStartup , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
# endif
2010-10-09 19:36:39 +04:00
connect ( checkShowSplash , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-02-27 12:43:58 +03:00
connect ( checkProgramExitConfirm , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-02-06 17:27:34 +03:00
connect ( checkPreventFromSuspend , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-03-27 12:34:51 +04:00
connect ( comboTrayIcon , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2013-09-21 11:59:58 +04:00
# if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && !defined(QT_DBUS_LIB)
2011-03-07 23:22:35 +03:00
checkPreventFromSuspend - > setDisabled ( true ) ;
2011-09-18 20:45:46 +04:00
# endif
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_WIN
2011-09-18 20:45:46 +04:00
connect ( checkAssociateTorrents , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkAssociateMagnetLinks , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-03-07 23:22:35 +03:00
# endif
2010-10-09 19:36:39 +04:00
// Downloads tab
connect ( textSavePath , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textTempPath , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkAppendLabel , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkAppendqB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkPreallocateAll , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkAdditionDialog , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2013-10-06 19:42:56 +04:00
connect ( checkAdditionDialogFront , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( checkStartPaused , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkExportDir , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2012-08-21 11:16:49 +04:00
connect ( checkExportDirFin , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( textExportDir , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2012-08-21 11:16:49 +04:00
connect ( textExportDirFin , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( actionTorrentDlOnDblClBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( actionTorrentFnOnDblClBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkTempFolder , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( addScanFolderButton , SIGNAL ( clicked ( ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( removeScanFolderButton , SIGNAL ( clicked ( ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( groupMailNotification , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( dest_email_txt , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( smtp_server_txt , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-04-09 21:39:51 +04:00
connect ( checkSmtpSSL , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( groupMailNotifAuth , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( mailNotifUsername , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( mailNotifPassword , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( autoRunBox , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( autoRun_txt , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
// Connection tab
connect ( spinPort , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2012-09-16 02:28:58 +04:00
connect ( checkRandomPort , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( checkUPnP , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkUploadLimit , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkDownloadLimit , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinUploadLimit , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinDownloadLimit , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinUploadLimitAlt , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinDownloadLimitAlt , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( check_schedule , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( schedule_from , SIGNAL ( timeChanged ( QTime ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( schedule_to , SIGNAL ( timeChanged ( QTime ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( schedule_days , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-04-17 22:11:03 +04:00
connect ( checkuTP , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
2011-04-17 18:42:38 +04:00
connect ( checkLimituTPConnections , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkLimitTransportOverhead , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
// Bittorrent tab
connect ( checkMaxConnecs , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkMaxConnecsPerTorrent , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2013-07-22 02:20:48 +04:00
connect ( checkMaxUploads , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( checkMaxUploadsPerTorrent , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxConnec , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxConnecPerTorrent , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2013-07-22 02:20:48 +04:00
connect ( spinMaxUploads , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( spinMaxUploadsPerTorrent , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkDHT , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-09-20 21:15:47 +04:00
connect ( checkAnonymousMode , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( checkPeX , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkLSD , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( comboEncryption , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkMaxRatio , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxRatio , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( comboRatioLimitAct , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
// Proxy tab
connect ( comboProxyType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textProxyIP , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinProxyPort , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-05-01 15:22:17 +04:00
connect ( checkProxyPeerConnecs , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
2014-08-26 01:32:10 +04:00
# if LIBTORRENT_VERSION_NUM >= 10000
connect ( checkForceProxy , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
# endif
2010-10-09 19:36:39 +04:00
connect ( checkProxyAuth , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textProxyUsername , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textProxyPassword , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
// Misc tab
connect ( checkIPFilter , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textFilterPath , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkEnableQueueing , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxActiveDownloads , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxActiveUploads , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxActiveTorrents , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-09-18 20:34:29 +04:00
connect ( checkIgnoreSlowTorrentsForQueueing , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
// Web UI tab
connect ( checkWebUi , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinWebUiPort , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-04-12 23:50:05 +04:00
connect ( checkWebUIUPnP , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
2011-06-05 20:08:30 +04:00
connect ( checkWebUiHttps , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( btnWebUiKey , SIGNAL ( clicked ( ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( btnWebUiCrt , SIGNAL ( clicked ( ) ) , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
connect ( textWebUiUsername , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textWebUiPassword , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-02-27 12:34:42 +03:00
connect ( checkBypassLocalAuth , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-04-15 17:02:39 +04:00
connect ( checkDynDNS , SIGNAL ( toggled ( bool ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( comboDNSService , SIGNAL ( currentIndexChanged ( int ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( domainNameTxt , SIGNAL ( textChanged ( QString ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( DNSUsernameTxt , SIGNAL ( textChanged ( QString ) ) , SLOT ( enableApplyButton ( ) ) ) ;
connect ( DNSPasswordTxt , SIGNAL ( textChanged ( QString ) ) , SLOT ( enableApplyButton ( ) ) ) ;
2010-10-09 19:36:39 +04:00
// Disable apply Button
applyButton - > setEnabled ( false ) ;
// Tab selection mecanism
connect ( tabSelection , SIGNAL ( currentItemChanged ( QListWidgetItem * , QListWidgetItem * ) ) , this , SLOT ( changePage ( QListWidgetItem * , QListWidgetItem * ) ) ) ;
// Load Advanced settings
QVBoxLayout * adv_layout = new QVBoxLayout ( ) ;
advancedSettings = new AdvancedSettings ( ) ;
adv_layout - > addWidget ( advancedSettings ) ;
scrollArea_advanced - > setLayout ( adv_layout ) ;
connect ( advancedSettings , SIGNAL ( settingsChanged ( ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2014-08-26 01:32:10 +04:00
//Hide incompatible options
# if LIBTORRENT_VERSION_NUM < 10000
checkForceProxy - > setVisible ( false ) ;
# endif
2010-10-09 19:36:39 +04:00
// Adapt size
2014-01-02 23:09:45 +04:00
show ( ) ;
2014-01-26 15:29:29 +04:00
loadWindowState ( ) ;
2010-10-09 19:36:39 +04:00
}
2010-11-20 18:59:17 +03:00
void options_imp : : initializeLanguageCombo ( )
{
// List language files
const QDir lang_dir ( " :/lang " ) ;
const QStringList lang_files = lang_dir . entryList ( QStringList ( ) < < " qbittorrent_*.qm " , QDir : : Files ) ;
2012-02-20 21:30:53 +04:00
foreach ( QString lang_file , lang_files ) {
2010-11-20 18:59:17 +03:00
QString localeStr = lang_file . mid ( 12 ) ; // remove "qbittorrent_"
localeStr . chop ( 3 ) ; // Remove ".qm"
2013-10-20 20:31:01 +04:00
QLocale locale ( localeStr ) ;
QString language_name = languageToLocalizedString ( locale ) ;
2014-11-30 02:58:07 +03:00
comboI18n - > addItem ( /*QIcon(":/Icons/flags/"+country+".png"), */ language_name , localeStr ) ;
qDebug ( ) < < " Supported locale: " < < localeStr ;
2010-11-20 18:59:17 +03:00
}
}
2010-10-09 19:36:39 +04:00
// Main destructor
2012-02-20 21:56:07 +04:00
options_imp : : ~ options_imp ( ) {
2010-10-09 19:36:39 +04:00
qDebug ( " -> destructing Options " ) ;
foreach ( const QString & path , addedScanDirs )
ScanFoldersModel : : instance ( ) - > removePath ( path ) ;
delete scrollArea_advanced - > layout ( ) ;
delete advancedSettings ;
}
void options_imp : : changePage ( QListWidgetItem * current , QListWidgetItem * previous ) {
if ( ! current )
current = previous ;
tabOption - > setCurrentIndex ( tabSelection - > row ( current ) ) ;
}
void options_imp : : loadWindowState ( ) {
2014-07-05 16:44:13 +04:00
const Preferences * const pref = Preferences : : instance ( ) ;
resize ( pref - > getPrefSize ( sizeFittingScreen ( ) ) ) ;
QPoint p = pref - > getPrefPos ( ) ;
2014-01-02 23:09:45 +04:00
QRect scr_rect = qApp - > desktop ( ) - > screenGeometry ( ) ;
if ( ! p . isNull ( ) & & scr_rect . contains ( p ) )
2010-10-09 19:36:39 +04:00
move ( p ) ;
// Load slider size
2014-07-05 16:44:13 +04:00
const QStringList sizes_str = pref - > getPrefHSplitterSizes ( ) ;
2010-10-09 19:36:39 +04:00
// Splitter size
QList < int > sizes ;
2012-02-20 21:30:53 +04:00
if ( sizes_str . size ( ) = = 2 ) {
2010-10-09 19:36:39 +04:00
sizes < < sizes_str . first ( ) . toInt ( ) ;
sizes < < sizes_str . last ( ) . toInt ( ) ;
} else {
2014-10-14 20:21:38 +04:00
sizes < < 116 ;
sizes < < hsplitter - > width ( ) - 116 ;
2010-10-09 19:36:39 +04:00
}
hsplitter - > setSizes ( sizes ) ;
}
void options_imp : : saveWindowState ( ) const {
2014-07-05 16:44:13 +04:00
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setPrefSize ( size ( ) ) ;
pref - > setPrefPos ( pos ( ) ) ;
2010-10-09 19:36:39 +04:00
// Splitter size
QStringList sizes_str ;
sizes_str < < QString : : number ( hsplitter - > sizes ( ) . first ( ) ) ;
sizes_str < < QString : : number ( hsplitter - > sizes ( ) . last ( ) ) ;
2014-07-05 16:44:13 +04:00
pref - > setPrefHSplitterSizes ( sizes_str ) ;
2010-10-09 19:36:39 +04:00
}
2011-04-11 21:21:16 +04:00
QSize options_imp : : sizeFittingScreen ( ) const {
2010-10-09 19:36:39 +04:00
int scrn = 0 ;
QWidget * w = this - > topLevelWidget ( ) ;
2012-02-20 21:30:53 +04:00
if ( w )
2010-10-09 19:36:39 +04:00
scrn = QApplication : : desktop ( ) - > screenNumber ( w ) ;
2012-02-20 21:30:53 +04:00
else if ( QApplication : : desktop ( ) - > isVirtualDesktop ( ) )
2010-10-09 19:36:39 +04:00
scrn = QApplication : : desktop ( ) - > screenNumber ( QCursor : : pos ( ) ) ;
else
scrn = QApplication : : desktop ( ) - > screenNumber ( this ) ;
QRect desk ( QApplication : : desktop ( ) - > availableGeometry ( scrn ) ) ;
2012-02-20 21:30:53 +04:00
if ( width ( ) > desk . width ( ) | | height ( ) > desk . height ( ) ) {
if ( desk . width ( ) > 0 & & desk . height ( ) > 0 )
2010-10-09 19:36:39 +04:00
return QSize ( desk . width ( ) , desk . height ( ) ) ;
}
return size ( ) ;
}
2012-02-20 21:56:07 +04:00
void options_imp : : saveOptions ( ) {
2010-10-09 19:36:39 +04:00
applyButton - > setEnabled ( false ) ;
2014-07-05 16:44:13 +04:00
Preferences * const pref = Preferences : : instance ( ) ;
2010-10-09 19:36:39 +04:00
// Load the translation
QString locale = getLocale ( ) ;
2014-07-05 16:44:13 +04:00
if ( pref - > getLocale ( ) ! = locale ) {
2010-10-09 19:36:39 +04:00
QTranslator * translator = new QTranslator ;
2012-02-20 21:56:07 +04:00
if ( translator - > load ( QString : : fromUtf8 ( " :/lang/qbittorrent_ " ) + locale ) ) {
2010-10-09 19:36:39 +04:00
qDebug ( " %s locale recognized, using translation. " , qPrintable ( locale ) ) ;
} else {
2013-10-20 20:31:01 +04:00
qDebug ( " %s locale unrecognized, using default (en). " , qPrintable ( locale ) ) ;
2010-09-25 16:42:19 +04:00
}
2010-10-09 19:36:39 +04:00
qApp - > installTranslator ( translator ) ;
}
// General preferences
2014-07-05 16:44:13 +04:00
pref - > setLocale ( locale ) ;
pref - > setAlternatingRowColors ( checkAltRowColors - > isChecked ( ) ) ;
pref - > setSystrayIntegration ( systrayIntegration ( ) ) ;
pref - > setTrayIconStyle ( TrayIcon : : Style ( comboTrayIcon - > currentIndex ( ) ) ) ;
pref - > setCloseToTray ( closeToTray ( ) ) ;
pref - > setMinimizeToTray ( minimizeToTray ( ) ) ;
pref - > setStartMinimized ( startMinimized ( ) ) ;
pref - > setSplashScreenDisabled ( isSlashScreenDisabled ( ) ) ;
pref - > setConfirmOnExit ( checkProgramExitConfirm - > isChecked ( ) ) ;
pref - > setPreventFromSuspend ( preventFromSuspend ( ) ) ;
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_WIN
2014-07-05 16:44:13 +04:00
pref - > setWinStartup ( WinStartup ( ) ) ;
2011-09-18 17:42:50 +04:00
// Windows: file association settings
Preferences : : setTorrentFileAssoc ( checkAssociateTorrents - > isChecked ( ) ) ;
Preferences : : setMagnetLinkAssoc ( checkAssociateMagnetLinks - > isChecked ( ) ) ;
# endif
2010-10-09 19:36:39 +04:00
// End General preferences
2010-11-16 23:34:31 +03:00
2010-10-09 19:36:39 +04:00
// Downloads preferences
2014-07-05 16:44:13 +04:00
pref - > setSavePath ( getSavePath ( ) ) ;
pref - > setTempPathEnabled ( isTempPathEnabled ( ) ) ;
pref - > setTempPath ( getTempPath ( ) ) ;
pref - > setAppendTorrentLabel ( checkAppendLabel - > isChecked ( ) ) ;
pref - > useIncompleteFilesExtension ( checkAppendqB - > isChecked ( ) ) ;
pref - > preAllocateAllFiles ( preAllocateAllFiles ( ) ) ;
pref - > useAdditionDialog ( useAdditionDialog ( ) ) ;
pref - > additionDialogFront ( checkAdditionDialogFront - > isChecked ( ) ) ;
pref - > addTorrentsInPause ( addTorrentsInPause ( ) ) ;
2010-12-27 22:26:21 +03:00
ScanFoldersModel : : instance ( ) - > makePersistent ( ) ;
2010-10-09 19:36:39 +04:00
addedScanDirs . clear ( ) ;
2014-07-05 16:44:13 +04:00
pref - > setTorrentExportDir ( getTorrentExportDir ( ) ) ;
pref - > setFinishedTorrentExportDir ( getFinishedTorrentExportDir ( ) ) ;
pref - > setMailNotificationEnabled ( groupMailNotification - > isChecked ( ) ) ;
pref - > setMailNotificationEmail ( dest_email_txt - > text ( ) ) ;
pref - > setMailNotificationSMTP ( smtp_server_txt - > text ( ) ) ;
pref - > setMailNotificationSMTPSSL ( checkSmtpSSL - > isChecked ( ) ) ;
pref - > setMailNotificationSMTPAuth ( groupMailNotifAuth - > isChecked ( ) ) ;
pref - > setMailNotificationSMTPUsername ( mailNotifUsername - > text ( ) ) ;
pref - > setMailNotificationSMTPPassword ( mailNotifPassword - > text ( ) ) ;
pref - > setAutoRunEnabled ( autoRunBox - > isChecked ( ) ) ;
pref - > setAutoRunProgram ( autoRun_txt - > text ( ) ) ;
pref - > setActionOnDblClOnTorrentDl ( getActionOnDblClOnTorrentDl ( ) ) ;
pref - > setActionOnDblClOnTorrentFn ( getActionOnDblClOnTorrentFn ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Downloads preferences
// Connection preferences
2014-07-05 16:44:13 +04:00
pref - > setSessionPort ( getPort ( ) ) ;
pref - > setRandomPort ( checkRandomPort - > isChecked ( ) ) ;
pref - > setUPnPEnabled ( isUPnPEnabled ( ) ) ;
2010-12-02 20:17:50 +03:00
const QPair < int , int > down_up_limit = getGlobalBandwidthLimits ( ) ;
2014-07-05 16:44:13 +04:00
pref - > setGlobalDownloadLimit ( down_up_limit . first ) ;
pref - > setGlobalUploadLimit ( down_up_limit . second ) ;
pref - > setuTPEnabled ( checkuTP - > isChecked ( ) ) ;
pref - > setuTPRateLimited ( checkLimituTPConnections - > isChecked ( ) ) ;
pref - > includeOverheadInLimits ( checkLimitTransportOverhead - > isChecked ( ) ) ;
pref - > setAltGlobalDownloadLimit ( spinDownloadLimitAlt - > value ( ) ) ;
pref - > setAltGlobalUploadLimit ( spinUploadLimitAlt - > value ( ) ) ;
pref - > setSchedulerEnabled ( check_schedule - > isChecked ( ) ) ;
pref - > setSchedulerStartTime ( schedule_from - > time ( ) ) ;
pref - > setSchedulerEndTime ( schedule_to - > time ( ) ) ;
pref - > setSchedulerDays ( ( scheduler_days ) schedule_days - > currentIndex ( ) ) ;
pref - > setProxyType ( getProxyType ( ) ) ;
pref - > setProxyIp ( getProxyIp ( ) ) ;
pref - > setProxyPort ( getProxyPort ( ) ) ;
pref - > setProxyPeerConnections ( checkProxyPeerConnecs - > isChecked ( ) ) ;
2014-08-26 01:32:10 +04:00
# if LIBTORRENT_VERSION_NUM >= 10000
pref - > setForceProxy ( checkForceProxy - > isChecked ( ) ) ;
# endif
2014-07-05 16:44:13 +04:00
pref - > setProxyAuthEnabled ( isProxyAuthEnabled ( ) ) ;
pref - > setProxyUsername ( getProxyUsername ( ) ) ;
pref - > setProxyPassword ( getProxyPassword ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Connection preferences
// Bittorrent preferences
2014-07-05 16:44:13 +04:00
pref - > setMaxConnecs ( getMaxConnecs ( ) ) ;
pref - > setMaxConnecsPerTorrent ( getMaxConnecsPerTorrent ( ) ) ;
pref - > setMaxUploads ( getMaxUploads ( ) ) ;
pref - > setMaxUploadsPerTorrent ( getMaxUploadsPerTorrent ( ) ) ;
pref - > setDHTEnabled ( isDHTEnabled ( ) ) ;
pref - > setPeXEnabled ( checkPeX - > isChecked ( ) ) ;
pref - > setLSDEnabled ( isLSDEnabled ( ) ) ;
pref - > setEncryptionSetting ( getEncryptionSetting ( ) ) ;
pref - > enableAnonymousMode ( checkAnonymousMode - > isChecked ( ) ) ;
pref - > setGlobalMaxRatio ( getMaxRatio ( ) ) ;
pref - > setMaxRatioAction ( comboRatioLimitAct - > currentIndex ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Bittorrent preferences
// Misc preferences
// * IPFilter
2014-07-05 16:44:13 +04:00
pref - > setFilteringEnabled ( isFilteringEnabled ( ) ) ;
2013-11-09 22:20:00 +04:00
if ( isFilteringEnabled ( ) )
2014-07-05 16:44:13 +04:00
pref - > setFilter ( textFilterPath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
// End IPFilter preferences
// Queueing system
2014-07-05 16:44:13 +04:00
pref - > setQueueingSystemEnabled ( isQueueingSystemEnabled ( ) ) ;
pref - > setMaxActiveDownloads ( spinMaxActiveDownloads - > value ( ) ) ;
pref - > setMaxActiveUploads ( spinMaxActiveUploads - > value ( ) ) ;
pref - > setMaxActiveTorrents ( spinMaxActiveTorrents - > value ( ) ) ;
pref - > setIgnoreSlowTorrentsForQueueing ( checkIgnoreSlowTorrentsForQueueing - > isChecked ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Queueing system preferences
// Web UI
2014-07-05 16:44:13 +04:00
pref - > setWebUiEnabled ( isWebUiEnabled ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( isWebUiEnabled ( ) )
2010-10-09 19:36:39 +04:00
{
2014-07-05 16:44:13 +04:00
pref - > setWebUiPort ( webUiPort ( ) ) ;
pref - > setUPnPForWebUIPort ( checkWebUIUPnP - > isChecked ( ) ) ;
pref - > setWebUiHttpsEnabled ( checkWebUiHttps - > isChecked ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( checkWebUiHttps - > isChecked ( ) )
2011-06-05 20:08:30 +04:00
{
2014-07-05 16:44:13 +04:00
pref - > setWebUiHttpsCertificate ( m_sslCert ) ;
pref - > setWebUiHttpsKey ( m_sslKey ) ;
2011-06-05 20:08:30 +04:00
}
2014-07-05 16:44:13 +04:00
pref - > setWebUiUsername ( webUiUsername ( ) ) ;
2010-10-09 19:36:39 +04:00
// FIXME: Check that the password is valid (not empty at least)
2014-07-05 16:44:13 +04:00
pref - > setWebUiPassword ( webUiPassword ( ) ) ;
pref - > setWebUiLocalAuthEnabled ( ! checkBypassLocalAuth - > isChecked ( ) ) ;
2011-04-15 17:02:39 +04:00
// DynDNS
2014-07-05 16:44:13 +04:00
pref - > setDynDNSEnabled ( checkDynDNS - > isChecked ( ) ) ;
pref - > setDynDNSService ( comboDNSService - > currentIndex ( ) ) ;
pref - > setDynDomainName ( domainNameTxt - > text ( ) ) ;
pref - > setDynDNSUsername ( DNSUsernameTxt - > text ( ) ) ;
pref - > setDynDNSPassword ( DNSPasswordTxt - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
}
// End Web UI
// End preferences
// Save advanced settings
advancedSettings - > saveAdvancedSettings ( ) ;
2014-07-05 16:44:13 +04:00
// Assume that user changed multiple settings
// so it's best to save immediately
pref - > save ( ) ;
2010-10-09 19:36:39 +04:00
}
2012-02-20 23:32:58 +04:00
bool options_imp : : isFilteringEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return checkIPFilter - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
int options_imp : : getProxyType ( ) const {
2010-10-09 19:36:39 +04:00
switch ( comboProxyType - > currentIndex ( ) ) {
case 1 :
2010-10-24 01:46:05 +04:00
return Proxy : : SOCKS4 ;
2010-10-09 19:36:39 +04:00
break ;
case 2 :
2012-02-20 21:56:07 +04:00
if ( isProxyAuthEnabled ( ) ) {
2010-10-24 01:46:05 +04:00
return Proxy : : SOCKS5_PW ;
2007-05-14 00:02:30 +04:00
}
2010-10-24 01:46:05 +04:00
return Proxy : : SOCKS5 ;
2010-10-09 19:36:39 +04:00
case 3 :
2012-02-20 21:56:07 +04:00
if ( isProxyAuthEnabled ( ) ) {
2010-10-24 01:46:05 +04:00
return Proxy : : HTTP_PW ;
2010-01-15 19:41:39 +03:00
}
2010-10-24 01:46:05 +04:00
return Proxy : : HTTP ;
2010-10-09 19:36:39 +04:00
default :
return - 1 ;
2007-05-14 00:02:30 +04:00
}
2010-10-09 19:36:39 +04:00
}
2007-05-14 00:02:30 +04:00
2012-02-20 21:56:07 +04:00
void options_imp : : loadOptions ( ) {
2010-10-09 19:36:39 +04:00
int intValue ;
2011-01-25 20:01:09 +03:00
qreal floatValue ;
2010-10-09 19:36:39 +04:00
QString strValue ;
// General preferences
2014-07-05 16:44:13 +04:00
const Preferences * const pref = Preferences : : instance ( ) ;
setLocale ( pref - > getLocale ( ) ) ;
checkAltRowColors - > setChecked ( pref - > useAlternatingRowColors ( ) ) ;
checkShowSystray - > setChecked ( pref - > systrayIntegration ( ) ) ;
checkShowSplash - > setChecked ( ! pref - > isSlashScreenDisabled ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( checkShowSystray - > isChecked ( ) ) {
2014-07-05 16:44:13 +04:00
checkCloseToSystray - > setChecked ( pref - > closeToTray ( ) ) ;
checkMinimizeToSysTray - > setChecked ( pref - > minimizeToTray ( ) ) ;
checkStartMinimized - > setChecked ( pref - > startMinimized ( ) ) ;
2010-10-09 19:36:39 +04:00
}
2014-07-05 16:44:13 +04:00
comboTrayIcon - > setCurrentIndex ( pref - > trayIconStyle ( ) ) ;
checkProgramExitConfirm - > setChecked ( pref - > confirmOnExit ( ) ) ;
checkPreventFromSuspend - > setChecked ( pref - > preventFromSuspend ( ) ) ;
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_WIN
2014-07-05 16:44:13 +04:00
checkStartup - > setChecked ( pref - > WinStartup ( ) ) ;
2011-09-18 17:42:50 +04:00
// Windows: file association settings
checkAssociateTorrents - > setChecked ( Preferences : : isTorrentFileAssocSet ( ) ) ;
checkAssociateMagnetLinks - > setChecked ( Preferences : : isMagnetLinkAssocSet ( ) ) ;
# endif
2010-10-09 19:36:39 +04:00
// End General preferences
// Downloads preferences
2014-07-05 16:44:13 +04:00
textSavePath - > setText ( fsutils : : toNativePath ( pref - > getSavePath ( ) ) ) ;
if ( pref - > isTempPathEnabled ( ) ) {
2010-10-09 19:36:39 +04:00
// enable
checkTempFolder - > setChecked ( true ) ;
} else {
checkTempFolder - > setChecked ( false ) ;
}
2014-07-05 16:44:13 +04:00
textTempPath - > setText ( fsutils : : toNativePath ( pref - > getTempPath ( ) ) ) ;
checkAppendLabel - > setChecked ( pref - > appendTorrentLabel ( ) ) ;
checkAppendqB - > setChecked ( pref - > useIncompleteFilesExtension ( ) ) ;
checkPreallocateAll - > setChecked ( pref - > preAllocateAllFiles ( ) ) ;
checkAdditionDialog - > setChecked ( pref - > useAdditionDialog ( ) ) ;
checkAdditionDialogFront - > setChecked ( pref - > additionDialogFront ( ) ) ;
checkStartPaused - > setChecked ( pref - > addTorrentsInPause ( ) ) ;
strValue = fsutils : : toNativePath ( pref - > getTorrentExportDir ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( strValue . isEmpty ( ) ) {
2010-10-09 19:36:39 +04:00
// Disable
checkExportDir - > setChecked ( false ) ;
} else {
// enable
2014-08-06 01:44:35 +04:00
checkExportDir - > setChecked ( true ) ;
2010-10-09 19:36:39 +04:00
textExportDir - > setText ( strValue ) ;
}
2012-08-21 11:16:49 +04:00
2014-07-05 16:44:13 +04:00
strValue = fsutils : : toNativePath ( pref - > getFinishedTorrentExportDir ( ) ) ;
2012-08-21 11:16:49 +04:00
if ( strValue . isEmpty ( ) ) {
// Disable
checkExportDirFin - > setChecked ( false ) ;
} else {
// enable
checkExportDirFin - > setChecked ( true ) ;
textExportDirFin - > setText ( strValue ) ;
}
2014-07-05 16:44:13 +04:00
groupMailNotification - > setChecked ( pref - > isMailNotificationEnabled ( ) ) ;
dest_email_txt - > setText ( pref - > getMailNotificationEmail ( ) ) ;
smtp_server_txt - > setText ( pref - > getMailNotificationSMTP ( ) ) ;
checkSmtpSSL - > setChecked ( pref - > getMailNotificationSMTPSSL ( ) ) ;
groupMailNotifAuth - > setChecked ( pref - > getMailNotificationSMTPAuth ( ) ) ;
mailNotifUsername - > setText ( pref - > getMailNotificationSMTPUsername ( ) ) ;
mailNotifPassword - > setText ( pref - > getMailNotificationSMTPPassword ( ) ) ;
autoRunBox - > setChecked ( pref - > isAutoRunEnabled ( ) ) ;
autoRun_txt - > setText ( pref - > getAutoRunProgram ( ) ) ;
intValue = pref - > getActionOnDblClOnTorrentDl ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue > = actionTorrentDlOnDblClBox - > count ( ) )
2010-10-09 19:36:39 +04:00
intValue = 0 ;
actionTorrentDlOnDblClBox - > setCurrentIndex ( intValue ) ;
2014-07-05 16:44:13 +04:00
intValue = pref - > getActionOnDblClOnTorrentFn ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue > = actionTorrentFnOnDblClBox - > count ( ) )
2010-10-09 19:36:39 +04:00
intValue = 1 ;
actionTorrentFnOnDblClBox - > setCurrentIndex ( intValue ) ;
// End Downloads preferences
// Connection preferences
2014-07-05 16:44:13 +04:00
spinPort - > setValue ( pref - > getSessionPort ( ) ) ;
checkUPnP - > setChecked ( pref - > isUPnPEnabled ( ) ) ;
checkRandomPort - > setChecked ( pref - > useRandomPort ( ) ) ;
2013-06-30 16:51:15 +04:00
spinPort - > setDisabled ( checkRandomPort - > isChecked ( ) ) ;
2014-07-05 16:44:13 +04:00
intValue = pref - > getGlobalDownloadLimit ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue > 0 ) {
2010-10-09 19:36:39 +04:00
// Enabled
checkDownloadLimit - > setChecked ( true ) ;
spinDownloadLimit - > setEnabled ( true ) ;
spinDownloadLimit - > setValue ( intValue ) ;
} else {
// Disabled
checkDownloadLimit - > setChecked ( false ) ;
spinDownloadLimit - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
intValue = pref - > getGlobalUploadLimit ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue ! = - 1 ) {
2010-10-09 19:36:39 +04:00
// Enabled
checkUploadLimit - > setChecked ( true ) ;
spinUploadLimit - > setEnabled ( true ) ;
spinUploadLimit - > setValue ( intValue ) ;
} else {
// Disabled
checkUploadLimit - > setChecked ( false ) ;
spinUploadLimit - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
spinUploadLimitAlt - > setValue ( pref - > getAltGlobalUploadLimit ( ) ) ;
spinDownloadLimitAlt - > setValue ( pref - > getAltGlobalDownloadLimit ( ) ) ;
2011-04-17 18:42:38 +04:00
// Options
2014-07-05 16:44:13 +04:00
checkuTP - > setChecked ( pref - > isuTPEnabled ( ) ) ;
checkLimituTPConnections - > setChecked ( pref - > isuTPRateLimited ( ) ) ;
checkLimitTransportOverhead - > setChecked ( pref - > includeOverheadInLimits ( ) ) ;
2010-10-09 19:36:39 +04:00
// Scheduler
2014-07-05 16:44:13 +04:00
check_schedule - > setChecked ( pref - > isSchedulerEnabled ( ) ) ;
schedule_from - > setTime ( pref - > getSchedulerStartTime ( ) ) ;
schedule_to - > setTime ( pref - > getSchedulerEndTime ( ) ) ;
schedule_days - > setCurrentIndex ( ( int ) pref - > getSchedulerDays ( ) ) ;
2010-10-09 19:36:39 +04:00
2014-07-05 16:44:13 +04:00
intValue = pref - > getProxyType ( ) ;
2010-10-09 19:36:39 +04:00
switch ( intValue ) {
2010-10-24 01:46:05 +04:00
case Proxy : : SOCKS4 :
2010-10-09 19:36:39 +04:00
comboProxyType - > setCurrentIndex ( 1 ) ;
break ;
2010-10-24 01:46:05 +04:00
case Proxy : : SOCKS5 :
case Proxy : : SOCKS5_PW :
2010-10-09 19:36:39 +04:00
comboProxyType - > setCurrentIndex ( 2 ) ;
break ;
2010-10-24 01:46:05 +04:00
case Proxy : : HTTP :
case Proxy : : HTTP_PW :
2010-10-09 19:36:39 +04:00
comboProxyType - > setCurrentIndex ( 3 ) ;
break ;
default :
comboProxyType - > setCurrentIndex ( 0 ) ;
}
2010-11-18 23:05:56 +03:00
enableProxy ( comboProxyType - > currentIndex ( ) ) ;
2012-02-20 21:30:53 +04:00
//if (isProxyEnabled()) {
2010-10-09 19:36:39 +04:00
// Proxy is enabled, save settings
2014-07-05 16:44:13 +04:00
textProxyIP - > setText ( pref - > getProxyIp ( ) ) ;
spinProxyPort - > setValue ( pref - > getProxyPort ( ) ) ;
checkProxyPeerConnecs - > setChecked ( pref - > proxyPeerConnections ( ) ) ;
2014-08-26 01:32:10 +04:00
# if LIBTORRENT_VERSION_NUM >= 10000
checkForceProxy - > setChecked ( pref - > getForceProxy ( ) ) ;
# endif
2014-07-05 16:44:13 +04:00
checkProxyAuth - > setChecked ( pref - > isProxyAuthEnabled ( ) ) ;
textProxyUsername - > setText ( pref - > getProxyUsername ( ) ) ;
textProxyPassword - > setText ( pref - > getProxyPassword ( ) ) ;
2010-10-09 19:36:39 +04:00
//}
// End Connection preferences
// Bittorrent preferences
2014-07-05 16:44:13 +04:00
intValue = pref - > getMaxConnecs ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue > 0 ) {
2010-10-09 19:36:39 +04:00
// enable
checkMaxConnecs - > setChecked ( true ) ;
spinMaxConnec - > setEnabled ( true ) ;
spinMaxConnec - > setValue ( intValue ) ;
} else {
// disable
checkMaxConnecs - > setChecked ( false ) ;
spinMaxConnec - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
intValue = pref - > getMaxConnecsPerTorrent ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue > 0 ) {
2010-10-09 19:36:39 +04:00
// enable
checkMaxConnecsPerTorrent - > setChecked ( true ) ;
spinMaxConnecPerTorrent - > setEnabled ( true ) ;
spinMaxConnecPerTorrent - > setValue ( intValue ) ;
} else {
// disable
checkMaxConnecsPerTorrent - > setChecked ( false ) ;
spinMaxConnecPerTorrent - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
intValue = pref - > getMaxUploads ( ) ;
2013-07-22 02:20:48 +04:00
if ( intValue > 0 ) {
// enable
checkMaxUploads - > setChecked ( true ) ;
spinMaxUploads - > setEnabled ( true ) ;
spinMaxUploads - > setValue ( intValue ) ;
} else {
// disable
checkMaxUploads - > setChecked ( false ) ;
spinMaxUploads - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
intValue = pref - > getMaxUploadsPerTorrent ( ) ;
2012-02-20 21:30:53 +04:00
if ( intValue > 0 ) {
2010-10-09 19:36:39 +04:00
// enable
checkMaxUploadsPerTorrent - > setChecked ( true ) ;
spinMaxUploadsPerTorrent - > setEnabled ( true ) ;
spinMaxUploadsPerTorrent - > setValue ( intValue ) ;
} else {
// disable
checkMaxUploadsPerTorrent - > setChecked ( false ) ;
spinMaxUploadsPerTorrent - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
checkDHT - > setChecked ( pref - > isDHTEnabled ( ) ) ;
checkPeX - > setChecked ( pref - > isPeXEnabled ( ) ) ;
checkLSD - > setChecked ( pref - > isLSDEnabled ( ) ) ;
comboEncryption - > setCurrentIndex ( pref - > getEncryptionSetting ( ) ) ;
checkAnonymousMode - > setChecked ( pref - > isAnonymousModeEnabled ( ) ) ;
2010-10-09 19:36:39 +04:00
// Ratio limit
2014-07-05 16:44:13 +04:00
floatValue = pref - > getGlobalMaxRatio ( ) ;
2012-02-20 21:30:53 +04:00
if ( floatValue > = 0. ) {
2010-10-09 19:36:39 +04:00
// Enable
checkMaxRatio - > setChecked ( true ) ;
spinMaxRatio - > setEnabled ( true ) ;
comboRatioLimitAct - > setEnabled ( true ) ;
spinMaxRatio - > setValue ( floatValue ) ;
} else {
// Disable
checkMaxRatio - > setChecked ( false ) ;
spinMaxRatio - > setEnabled ( false ) ;
comboRatioLimitAct - > setEnabled ( false ) ;
}
2014-07-05 16:44:13 +04:00
comboRatioLimitAct - > setCurrentIndex ( pref - > getMaxRatioAction ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Bittorrent preferences
// Misc preferences
// * IP Filter
2014-07-05 16:44:13 +04:00
checkIPFilter - > setChecked ( pref - > isFilteringEnabled ( ) ) ;
textFilterPath - > setText ( fsutils : : toNativePath ( pref - > getFilter ( ) ) ) ;
2010-10-09 19:36:39 +04:00
// End IP Filter
// Queueing system preferences
2014-07-05 16:44:13 +04:00
checkEnableQueueing - > setChecked ( pref - > isQueueingSystemEnabled ( ) ) ;
spinMaxActiveDownloads - > setValue ( pref - > getMaxActiveDownloads ( ) ) ;
spinMaxActiveUploads - > setValue ( pref - > getMaxActiveUploads ( ) ) ;
spinMaxActiveTorrents - > setValue ( pref - > getMaxActiveTorrents ( ) ) ;
checkIgnoreSlowTorrentsForQueueing - > setChecked ( pref - > ignoreSlowTorrentsForQueueing ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Queueing system preferences
// Web UI
2014-07-05 16:44:13 +04:00
checkWebUi - > setChecked ( pref - > isWebUiEnabled ( ) ) ;
spinWebUiPort - > setValue ( pref - > getWebUiPort ( ) ) ;
checkWebUIUPnP - > setChecked ( pref - > useUPnPForWebUIPort ( ) ) ;
checkWebUiHttps - > setChecked ( pref - > isWebUiHttpsEnabled ( ) ) ;
setSslCertificate ( pref - > getWebUiHttpsCertificate ( ) , false ) ;
setSslKey ( pref - > getWebUiHttpsKey ( ) , false ) ;
textWebUiUsername - > setText ( pref - > getWebUiUsername ( ) ) ;
textWebUiPassword - > setText ( pref - > getWebUiPassword ( ) ) ;
checkBypassLocalAuth - > setChecked ( ! pref - > isWebUiLocalAuthEnabled ( ) ) ;
2011-04-15 17:02:39 +04:00
// Dynamic DNS
2014-07-05 16:44:13 +04:00
checkDynDNS - > setChecked ( pref - > isDynDNSEnabled ( ) ) ;
comboDNSService - > setCurrentIndex ( ( int ) pref - > getDynDNSService ( ) ) ;
domainNameTxt - > setText ( pref - > getDynDomainName ( ) ) ;
DNSUsernameTxt - > setText ( pref - > getDynDNSUsername ( ) ) ;
DNSPasswordTxt - > setText ( pref - > getDynDNSPassword ( ) ) ;
2013-06-30 16:32:45 +04:00
// End Web UI
2010-10-09 19:36:39 +04:00
}
// return min & max ports
// [min, max]
2012-02-20 23:32:58 +04:00
int options_imp : : getPort ( ) const {
2010-10-09 19:36:39 +04:00
return spinPort - > value ( ) ;
}
void options_imp : : on_randomButton_clicked ( ) {
// Range [1024: 65535]
spinPort - > setValue ( rand ( ) % 64512 + 1024 ) ;
}
2012-02-20 23:32:58 +04:00
int options_imp : : getEncryptionSetting ( ) const {
2010-10-09 19:36:39 +04:00
return comboEncryption - > currentIndex ( ) ;
}
int options_imp : : getMaxActiveDownloads ( ) const {
return spinMaxActiveDownloads - > value ( ) ;
}
int options_imp : : getMaxActiveUploads ( ) const {
return spinMaxActiveUploads - > value ( ) ;
}
int options_imp : : getMaxActiveTorrents ( ) const {
return spinMaxActiveTorrents - > value ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : minimizeToTray ( ) const {
2012-02-20 21:30:53 +04:00
if ( ! checkShowSystray - > isChecked ( ) ) return false ;
2010-10-09 19:36:39 +04:00
return checkMinimizeToSysTray - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : closeToTray ( ) const {
2012-02-20 21:30:53 +04:00
if ( ! checkShowSystray - > isChecked ( ) ) return false ;
2010-10-09 19:36:39 +04:00
return checkCloseToSystray - > isChecked ( ) ;
}
bool options_imp : : isQueueingSystemEnabled ( ) const {
return checkEnableQueueing - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : isDHTEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return checkDHT - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : isLSDEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return checkLSD - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : isUPnPEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return checkUPnP - > isChecked ( ) ;
}
// Return Download & Upload limits in kbps
// [download,upload]
2012-02-20 23:32:58 +04:00
QPair < int , int > options_imp : : getGlobalBandwidthLimits ( ) const {
2010-10-09 19:36:39 +04:00
int DL = - 1 , UP = - 1 ;
2012-02-20 21:56:07 +04:00
if ( checkDownloadLimit - > isChecked ( ) ) {
2010-10-09 19:36:39 +04:00
DL = spinDownloadLimit - > value ( ) ;
}
2012-02-20 21:56:07 +04:00
if ( checkUploadLimit - > isChecked ( ) ) {
2010-10-09 19:36:39 +04:00
UP = spinUploadLimit - > value ( ) ;
}
return qMakePair ( DL , UP ) ;
}
bool options_imp : : startMinimized ( ) const {
return checkStartMinimized - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : systrayIntegration ( ) const {
2010-10-09 19:36:39 +04:00
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) return false ;
return checkShowSystray - > isChecked ( ) ;
}
// Return Share ratio
2012-02-20 23:32:58 +04:00
qreal options_imp : : getMaxRatio ( ) const {
2012-02-20 21:56:07 +04:00
if ( checkMaxRatio - > isChecked ( ) ) {
2010-10-09 19:36:39 +04:00
return spinMaxRatio - > value ( ) ;
}
return - 1 ;
}
// Return Save Path
2012-02-20 23:32:58 +04:00
QString options_imp : : getSavePath ( ) const {
2012-02-20 21:56:07 +04:00
if ( textSavePath - > text ( ) . trimmed ( ) . isEmpty ( ) ) {
2014-07-05 16:44:13 +04:00
QString save_path = Preferences : : instance ( ) - > getSavePath ( ) ;
2013-11-09 22:20:00 +04:00
textSavePath - > setText ( fsutils : : toNativePath ( save_path ) ) ;
2006-09-30 20:02:39 +04:00
}
2013-11-09 22:20:00 +04:00
return fsutils : : expandPathAbs ( textSavePath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
QString options_imp : : getTempPath ( ) const {
2013-11-09 22:20:00 +04:00
return fsutils : : expandPathAbs ( textTempPath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
bool options_imp : : isTempPathEnabled ( ) const {
return checkTempFolder - > isChecked ( ) ;
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
// Return max connections number
2012-02-20 23:32:58 +04:00
int options_imp : : getMaxConnecs ( ) const {
2012-02-20 21:56:07 +04:00
if ( ! checkMaxConnecs - > isChecked ( ) ) {
2010-10-09 19:36:39 +04:00
return - 1 ;
} else {
return spinMaxConnec - > value ( ) ;
2010-06-21 23:20:58 +04:00
}
2010-10-09 19:36:39 +04:00
}
2010-06-21 23:20:58 +04:00
2012-02-20 23:32:58 +04:00
int options_imp : : getMaxConnecsPerTorrent ( ) const {
2012-02-20 21:56:07 +04:00
if ( ! checkMaxConnecsPerTorrent - > isChecked ( ) ) {
2010-10-09 19:36:39 +04:00
return - 1 ;
} else {
return spinMaxConnecPerTorrent - > value ( ) ;
2010-06-21 23:20:58 +04:00
}
2010-10-09 19:36:39 +04:00
}
2010-06-21 23:20:58 +04:00
2013-07-22 02:20:48 +04:00
int options_imp : : getMaxUploads ( ) const {
if ( ! checkMaxUploads - > isChecked ( ) ) {
return - 1 ;
} else {
return spinMaxUploads - > value ( ) ;
}
}
2012-02-20 23:32:58 +04:00
int options_imp : : getMaxUploadsPerTorrent ( ) const {
2012-02-20 21:56:07 +04:00
if ( ! checkMaxUploadsPerTorrent - > isChecked ( ) ) {
2010-10-09 19:36:39 +04:00
return - 1 ;
} else {
return spinMaxUploadsPerTorrent - > value ( ) ;
2010-06-21 23:20:58 +04:00
}
2010-10-09 19:36:39 +04:00
}
2010-06-21 23:20:58 +04:00
2012-02-20 21:56:07 +04:00
void options_imp : : on_buttonBox_accepted ( ) {
if ( applyButton - > isEnabled ( ) ) {
2013-09-14 13:54:22 +04:00
if ( ! schedTimesOk ( ) ) {
tabSelection - > setCurrentRow ( TAB_SPEED ) ;
return ;
}
2010-10-09 19:36:39 +04:00
saveOptions ( ) ;
applyButton - > setEnabled ( false ) ;
this - > hide ( ) ;
emit status_changed ( ) ;
2010-06-21 23:20:58 +04:00
}
2010-10-09 19:36:39 +04:00
saveWindowState ( ) ;
accept ( ) ;
}
2010-06-21 23:20:58 +04:00
2010-10-09 19:36:39 +04:00
void options_imp : : applySettings ( QAbstractButton * button ) {
2012-02-20 21:56:07 +04:00
if ( button = = applyButton ) {
2013-09-14 13:54:22 +04:00
if ( ! schedTimesOk ( ) ) {
tabSelection - > setCurrentRow ( TAB_SPEED ) ;
return ;
}
2010-10-09 19:36:39 +04:00
saveOptions ( ) ;
emit status_changed ( ) ;
2010-06-21 23:20:58 +04:00
}
2010-10-09 19:36:39 +04:00
}
2010-06-21 23:20:58 +04:00
2012-02-20 21:56:07 +04:00
void options_imp : : closeEvent ( QCloseEvent * e ) {
2010-10-09 19:36:39 +04:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
e - > accept ( ) ;
}
2010-06-21 23:20:58 +04:00
2012-02-20 21:56:07 +04:00
void options_imp : : on_buttonBox_rejected ( ) {
2010-10-09 19:36:39 +04:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
reject ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : useAdditionDialog ( ) const {
2010-10-09 19:36:39 +04:00
return checkAdditionDialog - > isChecked ( ) ;
}
2012-02-20 21:56:07 +04:00
void options_imp : : enableApplyButton ( ) {
2010-10-09 19:36:39 +04:00
applyButton - > setEnabled ( true ) ;
}
2012-02-20 21:56:07 +04:00
void options_imp : : enableProxy ( int index ) {
if ( index ) {
2010-10-09 19:36:39 +04:00
//enable
lblProxyIP - > setEnabled ( true ) ;
textProxyIP - > setEnabled ( true ) ;
lblProxyPort - > setEnabled ( true ) ;
spinProxyPort - > setEnabled ( true ) ;
2011-05-01 15:22:17 +04:00
checkProxyPeerConnecs - > setEnabled ( true ) ;
2014-08-26 01:32:10 +04:00
# if LIBTORRENT_VERSION_NUM >= 10000
checkForceProxy - > setEnabled ( true ) ;
# endif
2012-02-20 21:30:53 +04:00
if ( index > 1 ) {
2010-10-09 19:36:39 +04:00
checkProxyAuth - > setEnabled ( true ) ;
2009-12-30 13:53:58 +03:00
} else {
checkProxyAuth - > setEnabled ( false ) ;
checkProxyAuth - > setChecked ( false ) ;
}
2010-10-09 19:36:39 +04:00
} else {
//disable
lblProxyIP - > setEnabled ( false ) ;
textProxyIP - > setEnabled ( false ) ;
lblProxyPort - > setEnabled ( false ) ;
spinProxyPort - > setEnabled ( false ) ;
2011-05-01 15:22:17 +04:00
checkProxyPeerConnecs - > setEnabled ( false ) ;
2014-08-26 01:32:10 +04:00
# if LIBTORRENT_VERSION_NUM >= 10000
checkForceProxy - > setEnabled ( false ) ;
# endif
2010-10-09 19:36:39 +04:00
checkProxyAuth - > setEnabled ( false ) ;
checkProxyAuth - > setChecked ( false ) ;
}
}
bool options_imp : : isSlashScreenDisabled ( ) const {
return ! checkShowSplash - > isChecked ( ) ;
}
2013-09-21 11:59:58 +04:00
# ifdef Q_OS_WIN
2014-07-05 16:44:13 +04:00
bool options_imp : : WinStartup ( ) const {
2012-10-08 00:05:33 +04:00
return checkStartup - > isChecked ( ) ;
}
# endif
2011-02-06 17:27:34 +03:00
bool options_imp : : preventFromSuspend ( ) const {
2011-03-07 23:22:35 +03:00
return checkPreventFromSuspend - > isChecked ( ) ;
2011-02-06 17:27:34 +03:00
}
2010-10-09 19:36:39 +04:00
bool options_imp : : preAllocateAllFiles ( ) const {
return checkPreallocateAll - > isChecked ( ) ;
}
bool options_imp : : addTorrentsInPause ( ) const {
return checkStartPaused - > isChecked ( ) ;
}
// Proxy settings
2012-02-20 23:32:58 +04:00
bool options_imp : : isProxyEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return comboProxyType - > currentIndex ( ) ;
}
2012-02-20 23:32:58 +04:00
bool options_imp : : isProxyAuthEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return checkProxyAuth - > isChecked ( ) ;
}
2012-02-20 23:32:58 +04:00
QString options_imp : : getProxyIp ( ) const {
2011-04-11 21:21:16 +04:00
return textProxyIP - > text ( ) . trimmed ( ) ;
2010-10-09 19:36:39 +04:00
}
2012-02-20 23:32:58 +04:00
unsigned short options_imp : : getProxyPort ( ) const {
2010-10-09 19:36:39 +04:00
return spinProxyPort - > value ( ) ;
}
2012-02-20 23:32:58 +04:00
QString options_imp : : getProxyUsername ( ) const {
2010-10-09 19:36:39 +04:00
QString username = textProxyUsername - > text ( ) ;
username = username . trimmed ( ) ;
return username ;
}
2012-02-20 23:32:58 +04:00
QString options_imp : : getProxyPassword ( ) const {
2010-10-09 19:36:39 +04:00
QString password = textProxyPassword - > text ( ) ;
password = password . trimmed ( ) ;
return password ;
}
// Locale Settings
2012-02-20 23:32:58 +04:00
QString options_imp : : getLocale ( ) const {
2010-11-20 18:59:17 +03:00
return comboI18n - > itemData ( comboI18n - > currentIndex ( ) , Qt : : UserRole ) . toString ( ) ;
2010-10-09 19:36:39 +04:00
}
2011-04-11 21:21:16 +04:00
void options_imp : : setLocale ( const QString & localeStr ) {
2010-11-20 18:59:17 +03:00
QLocale locale ( localeStr ) ;
2014-11-30 02:58:07 +03:00
QString name = locale . name ( ) ;
2010-11-20 18:59:17 +03:00
// Attempt to find exact match
2014-11-30 02:58:07 +03:00
int index = comboI18n - > findData ( name , Qt : : UserRole ) ;
if ( index < 0 ) {
//Attempt to find a language match without a country
int pos = name . indexOf ( ' _ ' ) ;
if ( pos > - 1 ) {
QString lang = name . left ( pos ) ;
index = comboI18n - > findData ( lang , Qt : : UserRole ) ;
}
}
2012-02-20 21:30:53 +04:00
if ( index < 0 ) {
2014-11-30 02:58:07 +03:00
// Unrecognized, use US English
2010-11-20 18:59:17 +03:00
index = comboI18n - > findData ( QLocale ( " en " ) . name ( ) , Qt : : UserRole ) ;
Q_ASSERT ( index > = 0 ) ;
2010-10-09 19:36:39 +04:00
}
2010-11-20 18:59:17 +03:00
comboI18n - > setCurrentIndex ( index ) ;
2010-10-09 19:36:39 +04:00
}
2012-08-21 11:16:49 +04:00
QString options_imp : : getTorrentExportDir ( ) const {
2012-02-20 21:30:53 +04:00
if ( checkExportDir - > isChecked ( ) )
2013-11-09 22:20:00 +04:00
return fsutils : : expandPathAbs ( textExportDir - > text ( ) ) ;
2011-04-11 21:21:16 +04:00
return QString ( ) ;
2010-10-09 19:36:39 +04:00
}
2012-08-21 11:16:49 +04:00
QString options_imp : : getFinishedTorrentExportDir ( ) const {
if ( checkExportDirFin - > isChecked ( ) )
2013-11-09 22:20:00 +04:00
return fsutils : : expandPathAbs ( textExportDirFin - > text ( ) ) ;
2012-08-21 11:16:49 +04:00
return QString ( ) ;
}
2010-10-09 19:36:39 +04:00
// Return action on double-click on a downloading torrent set in options
int options_imp : : getActionOnDblClOnTorrentDl ( ) const {
2012-02-20 21:30:53 +04:00
if ( actionTorrentDlOnDblClBox - > currentIndex ( ) < 1 )
2010-10-09 19:36:39 +04:00
return 0 ;
return actionTorrentDlOnDblClBox - > currentIndex ( ) ;
}
// Return action on double-click on a finished torrent set in options
int options_imp : : getActionOnDblClOnTorrentFn ( ) const {
2012-02-20 21:30:53 +04:00
if ( actionTorrentFnOnDblClBox - > currentIndex ( ) < 1 )
2010-10-09 19:36:39 +04:00
return 0 ;
return actionTorrentFnOnDblClBox - > currentIndex ( ) ;
}
void options_imp : : on_addScanFolderButton_clicked ( ) {
2014-07-05 16:44:13 +04:00
Preferences * const pref = Preferences : : instance ( ) ;
2014-07-13 20:56:27 +04:00
const QString dir = QFileDialog : : getExistingDirectory ( this , tr ( " Add directory to scan " ) ,
2014-07-05 16:44:13 +04:00
fsutils : : toNativePath ( fsutils : : folderName ( pref - > getScanDirsLastPath ( ) ) ) ) ;
2010-10-09 19:36:39 +04:00
if ( ! dir . isEmpty ( ) ) {
const ScanFoldersModel : : PathStatus status = ScanFoldersModel : : instance ( ) - > addPath ( dir , false ) ;
QString error ;
switch ( status ) {
case ScanFoldersModel : : AlreadyInList :
error = tr ( " Folder is already being watched. " ) . arg ( dir ) ;
break ;
case ScanFoldersModel : : DoesNotExist :
error = tr ( " Folder does not exist. " ) ;
break ;
case ScanFoldersModel : : CannotRead :
error = tr ( " Folder is not readable. " ) ;
break ;
default :
2014-07-05 16:44:13 +04:00
pref - > setScanDirsLastPath ( dir ) ;
2010-10-09 19:36:39 +04:00
addedScanDirs < < dir ;
2014-07-13 22:09:21 +04:00
scanFoldersView - > resizeColumnsToContents ( ) ;
2010-10-09 19:36:39 +04:00
enableApplyButton ( ) ;
2010-02-28 18:15:00 +03:00
}
2010-06-21 23:20:58 +04:00
2010-10-09 19:36:39 +04:00
if ( ! error . isEmpty ( ) ) {
QMessageBox : : warning ( this , tr ( " Failure " ) , tr ( " Failed to add Scan Folder '%1': %2 " ) . arg ( dir ) . arg ( error ) ) ;
2010-06-21 23:20:58 +04:00
}
}
2010-10-09 19:36:39 +04:00
}
void options_imp : : on_removeScanFolderButton_clicked ( ) {
const QModelIndexList selected
= scanFoldersView - > selectionModel ( ) - > selectedIndexes ( ) ;
if ( selected . isEmpty ( ) )
return ;
Q_ASSERT ( selected . count ( ) = = ScanFoldersModel : : instance ( ) - > columnCount ( ) ) ;
ScanFoldersModel : : instance ( ) - > removePath ( selected . first ( ) . row ( ) ) ;
}
void options_imp : : handleScanFolderViewSelectionChanged ( ) {
removeScanFolderButton - > setEnabled ( ! scanFoldersView - > selectionModel ( ) - > selectedIndexes ( ) . isEmpty ( ) ) ;
}
2012-08-21 11:16:49 +04:00
QString options_imp : : askForExportDir ( const QString & currentExportPath )
{
2013-11-09 22:20:00 +04:00
QDir currentExportDir ( fsutils : : expandPathAbs ( currentExportPath ) ) ;
2010-10-09 19:36:39 +04:00
QString dir ;
2012-08-21 11:16:49 +04:00
if ( ! currentExportPath . isEmpty ( ) & & currentExportDir . exists ( ) ) {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose export directory " ) , currentExportDir . absolutePath ( ) ) ;
2010-10-09 19:36:39 +04:00
} else {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose export directory " ) , QDir : : homePath ( ) ) ;
}
2012-08-21 11:16:49 +04:00
return dir ;
}
void options_imp : : on_browseExportDirButton_clicked ( ) {
const QString newExportDir = askForExportDir ( textExportDir - > text ( ) ) ;
if ( ! newExportDir . isNull ( ) )
2013-11-05 22:33:04 +04:00
textExportDir - > setText ( fsutils : : toNativePath ( newExportDir ) ) ;
2012-08-21 11:16:49 +04:00
}
void options_imp : : on_browseExportDirFinButton_clicked ( ) {
const QString newExportDir = askForExportDir ( textExportDirFin - > text ( ) ) ;
if ( ! newExportDir . isNull ( ) )
2013-11-05 22:33:04 +04:00
textExportDirFin - > setText ( fsutils : : toNativePath ( newExportDir ) ) ;
2010-10-09 19:36:39 +04:00
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
void options_imp : : on_browseFilterButton_clicked ( ) {
2013-11-09 22:20:00 +04:00
const QString filter_path = fsutils : : expandPathAbs ( textFilterPath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
QDir filterDir ( filter_path ) ;
QString ipfilter ;
2012-02-20 21:30:53 +04:00
if ( ! filter_path . isEmpty ( ) & & filterDir . exists ( ) ) {
2010-10-09 19:36:39 +04:00
ipfilter = QFileDialog : : getOpenFileName ( this , tr ( " Choose an ip filter file " ) , filterDir . absolutePath ( ) , tr ( " Filters " ) + QString ( " (*.dat *.p2p *.p2b) " ) ) ;
} else {
ipfilter = QFileDialog : : getOpenFileName ( this , tr ( " Choose an ip filter file " ) , QDir : : homePath ( ) , tr ( " Filters " ) + QString ( " (*.dat *.p2p *.p2b) " ) ) ;
}
2013-11-09 22:20:00 +04:00
if ( ! ipfilter . isNull ( ) )
textFilterPath - > setText ( fsutils : : toNativePath ( ipfilter ) ) ;
2010-10-09 19:36:39 +04:00
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
// Display dialog to choose save dir
2012-02-20 21:56:07 +04:00
void options_imp : : on_browseSaveDirButton_clicked ( ) {
2013-11-09 22:20:00 +04:00
const QString save_path = fsutils : : expandPathAbs ( textSavePath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
QDir saveDir ( save_path ) ;
QString dir ;
2012-02-20 21:30:53 +04:00
if ( ! save_path . isEmpty ( ) & & saveDir . exists ( ) ) {
2010-10-09 19:36:39 +04:00
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , saveDir . absolutePath ( ) ) ;
} else {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , QDir : : homePath ( ) ) ;
}
2013-11-09 22:20:00 +04:00
if ( ! dir . isNull ( ) )
textSavePath - > setText ( fsutils : : toNativePath ( dir ) ) ;
2010-10-09 19:36:39 +04:00
}
2010-06-21 23:20:58 +04:00
2012-02-20 21:56:07 +04:00
void options_imp : : on_browseTempDirButton_clicked ( ) {
2013-11-09 22:20:00 +04:00
const QString temp_path = fsutils : : expandPathAbs ( textTempPath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
QDir tempDir ( temp_path ) ;
QString dir ;
2012-02-20 21:30:53 +04:00
if ( ! temp_path . isEmpty ( ) & & tempDir . exists ( ) ) {
2010-10-09 19:36:39 +04:00
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , tempDir . absolutePath ( ) ) ;
} else {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , QDir : : homePath ( ) ) ;
}
2013-11-09 22:20:00 +04:00
if ( ! dir . isNull ( ) )
textTempPath - > setText ( fsutils : : toNativePath ( dir ) ) ;
2010-10-09 19:36:39 +04:00
}
2009-12-19 23:39:38 +03:00
2010-10-09 19:36:39 +04:00
// Return Filter object to apply to BT session
2012-02-20 23:32:58 +04:00
QString options_imp : : getFilter ( ) const {
2013-11-09 22:20:00 +04:00
return fsutils : : fromNativePath ( textFilterPath - > text ( ) ) ;
2010-10-09 19:36:39 +04:00
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
// Web UI
2008-05-16 11:10:50 +04:00
2010-10-09 19:36:39 +04:00
bool options_imp : : isWebUiEnabled ( ) const
{
return checkWebUi - > isChecked ( ) ;
}
2008-05-16 11:10:50 +04:00
2010-10-09 19:36:39 +04:00
quint16 options_imp : : webUiPort ( ) const
{
return spinWebUiPort - > value ( ) ;
}
2008-05-16 11:10:50 +04:00
2010-10-09 19:36:39 +04:00
QString options_imp : : webUiUsername ( ) const
{
return textWebUiUsername - > text ( ) ;
}
2008-05-16 11:10:50 +04:00
2010-10-09 19:36:39 +04:00
QString options_imp : : webUiPassword ( ) const
{
return textWebUiPassword - > text ( ) ;
}
2010-11-08 21:17:54 +03:00
void options_imp : : showConnectionTab ( )
{
2013-09-14 13:54:22 +04:00
tabSelection - > setCurrentRow ( TAB_CONNECTION ) ;
2010-11-08 21:17:54 +03:00
}
2010-11-20 18:59:17 +03:00
2011-06-05 20:08:30 +04:00
void options_imp : : on_btnWebUiCrt_clicked ( ) {
2014-08-30 22:54:57 +04:00
QString filename = QFileDialog : : getOpenFileName ( this , QString ( ) , QString ( ) , tr ( " SSL Certificate " ) + QString ( " (*.crt *.pem) " ) ) ;
2012-02-20 21:30:53 +04:00
if ( filename . isNull ( ) )
2011-06-05 20:08:30 +04:00
return ;
QFile file ( filename ) ;
if ( file . open ( QIODevice : : ReadOnly ) ) {
setSslCertificate ( file . readAll ( ) ) ;
file . close ( ) ;
}
}
void options_imp : : on_btnWebUiKey_clicked ( ) {
2014-08-30 22:54:57 +04:00
QString filename = QFileDialog : : getOpenFileName ( this , QString ( ) , QString ( ) , tr ( " SSL Key " ) + QString ( " (*.key *.pem) " ) ) ;
2012-02-20 21:30:53 +04:00
if ( filename . isNull ( ) )
2011-06-05 20:08:30 +04:00
return ;
QFile file ( filename ) ;
if ( file . open ( QIODevice : : ReadOnly ) ) {
setSslKey ( file . readAll ( ) ) ;
file . close ( ) ;
}
}
2011-04-15 17:02:39 +04:00
void options_imp : : on_registerDNSBtn_clicked ( ) {
QDesktopServices : : openUrl ( DNSUpdater : : getRegistrationUrl ( comboDNSService - > currentIndex ( ) ) ) ;
}
2010-12-25 17:47:52 +03:00
void options_imp : : on_IpFilterRefreshBtn_clicked ( ) {
2012-02-20 21:30:53 +04:00
if ( m_refreshingIpFilter ) return ;
2010-12-25 17:47:52 +03:00
m_refreshingIpFilter = true ;
// Updating program preferences
2014-07-05 16:44:13 +04:00
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setFilteringEnabled ( true ) ;
pref - > setFilter ( getFilter ( ) ) ;
2010-12-25 17:47:52 +03:00
// Force refresh
connect ( QBtSession : : instance ( ) , SIGNAL ( ipFilterParsed ( bool , int ) ) , SLOT ( handleIPFilterParsed ( bool , int ) ) ) ;
setCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QBtSession : : instance ( ) - > enableIPFilter ( getFilter ( ) , true ) ;
}
void options_imp : : handleIPFilterParsed ( bool error , int ruleCount )
{
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
2012-02-20 21:30:53 +04:00
if ( error ) {
2010-12-25 17:47:52 +03:00
QMessageBox : : warning ( this , tr ( " Parsing error " ) , tr ( " Failed to parse the provided IP filter " ) ) ;
} else {
2012-02-20 23:46:02 +04:00
QMessageBox : : information ( this , tr ( " Successfully refreshed " ) , tr ( " Successfully parsed the provided IP filter: %1 rules were applied. " , " %1 is a number " ) . arg ( ruleCount ) ) ;
2010-12-25 17:47:52 +03:00
}
m_refreshingIpFilter = false ;
disconnect ( QBtSession : : instance ( ) , SIGNAL ( ipFilterParsed ( bool , int ) ) , this , SLOT ( handleIPFilterParsed ( bool , int ) ) ) ;
}
2011-01-12 20:42:55 +03:00
2013-10-20 20:31:01 +04:00
QString options_imp : : languageToLocalizedString ( const QLocale & locale )
2011-01-12 20:42:55 +03:00
{
2013-10-20 20:31:01 +04:00
switch ( locale . language ( ) ) {
case QLocale : : English : {
if ( locale . country ( ) = = QLocale : : Australia )
return " English(Australia) " ;
else if ( locale . country ( ) = = QLocale : : UnitedKingdom )
return " English(United Kingdom) " ;
return " English " ;
}
2011-01-12 20:42:55 +03:00
case QLocale : : French : return QString : : fromUtf8 ( " Français " ) ;
case QLocale : : German : return QString : : fromUtf8 ( " Deutsch " ) ;
case QLocale : : Hungarian : return QString : : fromUtf8 ( " Magyar " ) ;
case QLocale : : Italian : return QString : : fromUtf8 ( " Italiano " ) ;
case QLocale : : Dutch : return QString : : fromUtf8 ( " Nederlands " ) ;
case QLocale : : Spanish : return QString : : fromUtf8 ( " Español " ) ;
case QLocale : : Catalan : return QString : : fromUtf8 ( " Català " ) ;
case QLocale : : Galician : return QString : : fromUtf8 ( " Galego " ) ;
case QLocale : : Portuguese : {
2013-10-20 20:31:01 +04:00
if ( locale . country ( ) = = QLocale : : Brazil )
2011-01-12 20:42:55 +03:00
return QString : : fromUtf8 ( " Português brasileiro " ) ;
return QString : : fromUtf8 ( " Português " ) ;
}
case QLocale : : Polish : return QString : : fromUtf8 ( " Polski " ) ;
2011-02-07 21:56:17 +03:00
case QLocale : : Lithuanian : return QString : : fromUtf8 ( " Lietuvių " ) ;
2011-01-12 20:42:55 +03:00
case QLocale : : Czech : return QString : : fromUtf8 ( " Čeština " ) ;
case QLocale : : Slovak : return QString : : fromUtf8 ( " Slovenčina " ) ;
case QLocale : : Serbian : return QString : : fromUtf8 ( " Српски " ) ;
case QLocale : : Croatian : return QString : : fromUtf8 ( " Hrvatski " ) ;
case QLocale : : Armenian : return QString : : fromUtf8 ( " Հայերեն " ) ;
case QLocale : : Romanian : return QString : : fromUtf8 ( " Română " ) ;
case QLocale : : Turkish : return QString : : fromUtf8 ( " Türkçe " ) ;
case QLocale : : Greek : return QString : : fromUtf8 ( " Ελληνικά " ) ;
case QLocale : : Swedish : return QString : : fromUtf8 ( " Svenska " ) ;
case QLocale : : Finnish : return QString : : fromUtf8 ( " Suomi " ) ;
case QLocale : : Norwegian : return QString : : fromUtf8 ( " Norsk " ) ;
case QLocale : : Danish : return QString : : fromUtf8 ( " Dansk " ) ;
case QLocale : : Bulgarian : return QString : : fromUtf8 ( " Български " ) ;
case QLocale : : Ukrainian : return QString : : fromUtf8 ( " Українська " ) ;
case QLocale : : Russian : return QString : : fromUtf8 ( " Русский " ) ;
case QLocale : : Japanese : return QString : : fromUtf8 ( " 日本語 " ) ;
2012-09-15 11:05:50 +04:00
case QLocale : : Hebrew : return QString : : fromUtf8 ( " עברית " ) ;
2011-01-12 20:42:55 +03:00
case QLocale : : Arabic : return QString : : fromUtf8 ( " عربي " ) ;
2011-12-27 15:29:35 +04:00
case QLocale : : Georgian : return QString : : fromUtf8 ( " ქართული " ) ;
2012-01-31 21:25:57 +04:00
case QLocale : : Byelorussian : return QString : : fromUtf8 ( " Беларуская " ) ;
2012-03-07 20:12:14 +04:00
case QLocale : : Basque : return QString : : fromUtf8 ( " Euskara " ) ;
2013-10-12 17:13:27 +04:00
case QLocale : : Vietnamese : return QString : : fromUtf8 ( " tiếng Việt " ) ;
2011-01-12 20:42:55 +03:00
case QLocale : : Chinese : {
2013-10-20 20:31:01 +04:00
if ( locale . country ( ) = = QLocale : : China )
2011-01-12 20:42:55 +03:00
return QString : : fromUtf8 ( " 中文 (简体) " ) ;
return QString : : fromUtf8 ( " 中文 (繁體) " ) ;
}
case QLocale : : Korean : return QString : : fromUtf8 ( " 한글 " ) ;
default : {
// Fallback to English
2013-10-20 20:31:01 +04:00
const QString eng_lang = QLocale : : languageToString ( locale . language ( ) ) ;
2011-01-12 20:42:55 +03:00
qWarning ( ) < < " Unrecognized language name: " < < eng_lang ;
return eng_lang ;
}
}
}
2011-06-05 20:08:30 +04:00
void options_imp : : setSslKey ( const QByteArray & key , bool interactive )
{
# ifndef QT_NO_OPENSSL
if ( ! key . isEmpty ( ) & & ! QSslKey ( key , QSsl : : Rsa ) . isNull ( ) ) {
lblSslKeyStatus - > setPixmap ( QPixmap ( " :/Icons/oxygen/security-high.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslKey = key ;
} else {
lblSslKeyStatus - > setPixmap ( QPixmap ( " :/Icons/oxygen/security-low.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslKey . clear ( ) ;
if ( interactive )
QMessageBox : : warning ( this , tr ( " Invalid key " ) , tr ( " This is not a valid SSL key. " ) ) ;
}
# endif
}
void options_imp : : setSslCertificate ( const QByteArray & cert , bool interactive )
{
# ifndef QT_NO_OPENSSL
if ( ! cert . isEmpty ( ) & & ! QSslCertificate ( cert ) . isNull ( ) ) {
lblSslCertStatus - > setPixmap ( QPixmap ( " :/Icons/oxygen/security-high.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslCert = cert ;
} else {
lblSslCertStatus - > setPixmap ( QPixmap ( " :/Icons/oxygen/security-low.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslCert . clear ( ) ;
if ( interactive )
QMessageBox : : warning ( this , tr ( " Invalid certificate " ) , tr ( " This is not a valid SSL certificate. " ) ) ;
}
# endif
}
2011-09-20 21:15:47 +04:00
2013-09-14 13:54:22 +04:00
bool options_imp : : schedTimesOk ( ) {
QString msg ;
if ( schedule_from - > time ( ) = = schedule_to - > time ( ) )
msg = tr ( " The start time and the end time can't be the same. " ) ;
if ( ! msg . isEmpty ( ) ) {
QMessageBox : : critical ( this , tr ( " Time Error " ) , msg ) ;
return false ;
}
return true ;
}