@ -57,8 +57,10 @@
@@ -57,8 +57,10 @@
# endif
// Constructor
options_imp : : options_imp ( QWidget * parent ) :
QDialog ( parent ) , m_refreshingIpFilter ( false ) {
options_imp : : options_imp ( QWidget * parent )
: QDialog ( parent ) ,
m_refreshingIpFilter ( false )
{
qDebug ( " -> Constructing Options " ) ;
setupUi ( this ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
@ -102,9 +104,8 @@ options_imp::options_imp(QWidget *parent):
@@ -102,9 +104,8 @@ options_imp::options_imp(QWidget *parent):
initializeLanguageCombo ( ) ;
// Load week days (scheduler)
for ( uint i = 1 ; i < = 7 ; + + i ) {
for ( uint i = 1 ; i < = 7 ; + + i )
schedule_days - > addItem ( QDate : : longDayName ( i , QDate : : StandaloneFormat ) ) ;
}
// Load options
loadOptions ( ) ;
@ -297,7 +298,8 @@ void options_imp::initializeLanguageCombo()
@@ -297,7 +298,8 @@ void options_imp::initializeLanguageCombo()
}
// Main destructor
options_imp : : ~ options_imp ( ) {
options_imp : : ~ options_imp ( )
{
qDebug ( " -> destructing Options " ) ;
foreach ( const QString & path , addedScanDirs )
ScanFoldersModel : : instance ( ) - > removePath ( path ) ;
@ -305,13 +307,15 @@ options_imp::~options_imp() {
@@ -305,13 +307,15 @@ options_imp::~options_imp() {
delete advancedSettings ;
}
void options_imp : : changePage ( QListWidgetItem * current , QListWidgetItem * previous ) {
void options_imp : : changePage ( QListWidgetItem * current , QListWidgetItem * previous )
{
if ( ! current )
current = previous ;
tabOption - > setCurrentIndex ( tabSelection - > row ( current ) ) ;
}
void options_imp : : loadWindowState ( ) {
void options_imp : : loadWindowState ( )
{
const Preferences * const pref = Preferences : : instance ( ) ;
resize ( pref - > getPrefSize ( sizeFittingScreen ( ) ) ) ;
QPoint p = pref - > getPrefPos ( ) ;
@ -325,14 +329,16 @@ void options_imp::loadWindowState() {
@@ -325,14 +329,16 @@ void options_imp::loadWindowState() {
if ( sizes_str . size ( ) = = 2 ) {
sizes < < sizes_str . first ( ) . toInt ( ) ;
sizes < < sizes_str . last ( ) . toInt ( ) ;
} else {
}
else {
sizes < < 116 ;
sizes < < hsplitter - > width ( ) - 116 ;
}
hsplitter - > setSizes ( sizes ) ;
}
void options_imp : : saveWindowState ( ) const {
void options_imp : : saveWindowState ( ) const
{
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setPrefSize ( size ( ) ) ;
pref - > setPrefPos ( pos ( ) ) ;
@ -343,7 +349,8 @@ void options_imp::saveWindowState() const {
@@ -343,7 +349,8 @@ void options_imp::saveWindowState() const {
pref - > setPrefHSplitterSizes ( sizes_str ) ;
}
QSize options_imp : : sizeFittingScreen ( ) const {
QSize options_imp : : sizeFittingScreen ( ) const
{
int scrn = 0 ;
QWidget * w = this - > topLevelWidget ( ) ;
@ -355,25 +362,24 @@ QSize options_imp::sizeFittingScreen() const {
@@ -355,25 +362,24 @@ QSize options_imp::sizeFittingScreen() const {
scrn = QApplication : : desktop ( ) - > screenNumber ( this ) ;
QRect desk ( QApplication : : desktop ( ) - > availableGeometry ( scrn ) ) ;
if ( width ( ) > desk . width ( ) | | height ( ) > desk . height ( ) ) {
if ( width ( ) > desk . width ( ) | | height ( ) > desk . height ( ) )
if ( desk . width ( ) > 0 & & desk . height ( ) > 0 )
return QSize ( desk . width ( ) , desk . height ( ) ) ;
}
return size ( ) ;
}
void options_imp : : saveOptions ( ) {
void options_imp : : saveOptions ( )
{
applyButton - > setEnabled ( false ) ;
Preferences * const pref = Preferences : : instance ( ) ;
// Load the translation
QString locale = getLocale ( ) ;
if ( pref - > getLocale ( ) ! = locale ) {
QTranslator * translator = new QTranslator ;
if ( translator - > load ( QString : : fromUtf8 ( " :/lang/qbittorrent_ " ) + locale ) ) {
if ( translator - > load ( QString : : fromUtf8 ( " :/lang/qbittorrent_ " ) + locale ) )
qDebug ( " %s locale recognized, using translation. " , qPrintable ( locale ) ) ;
} else {
else
qDebug ( " %s locale unrecognized, using default (en). " , qPrintable ( locale ) ) ;
}
qApp - > installTranslator ( translator ) ;
}
@ -482,13 +488,11 @@ void options_imp::saveOptions() {
@@ -482,13 +488,11 @@ void options_imp::saveOptions() {
// End Queueing system preferences
// Web UI
pref - > setWebUiEnabled ( isWebUiEnabled ( ) ) ;
if ( isWebUiEnabled ( ) )
{
if ( isWebUiEnabled ( ) ) {
pref - > setWebUiPort ( webUiPort ( ) ) ;
pref - > setUPnPForWebUIPort ( checkWebUIUPnP - > isChecked ( ) ) ;
pref - > setWebUiHttpsEnabled ( checkWebUiHttps - > isChecked ( ) ) ;
if ( checkWebUiHttps - > isChecked ( ) )
{
if ( checkWebUiHttps - > isChecked ( ) ) {
pref - > setWebUiHttpsCertificate ( m_sslCert ) ;
pref - > setWebUiHttpsKey ( m_sslKey ) ;
}
@ -512,31 +516,32 @@ void options_imp::saveOptions() {
@@ -512,31 +516,32 @@ void options_imp::saveOptions() {
pref - > apply ( ) ;
}
bool options_imp : : isFilteringEnabled ( ) const {
bool options_imp : : isFilteringEnabled ( ) const
{
return checkIPFilter - > isChecked ( ) ;
}
int options_imp : : getProxyType ( ) const {
int options_imp : : getProxyType ( ) const
{
switch ( comboProxyType - > currentIndex ( ) ) {
case 1 :
return Proxy : : SOCKS4 ;
break ;
case 2 :
if ( isProxyAuthEnabled ( ) ) {
if ( isProxyAuthEnabled ( ) )
return Proxy : : SOCKS5_PW ;
}
return Proxy : : SOCKS5 ;
case 3 :
if ( isProxyAuthEnabled ( ) ) {
if ( isProxyAuthEnabled ( ) )
return Proxy : : HTTP_PW ;
}
return Proxy : : HTTP ;
default :
return - 1 ;
}
}
void options_imp : : loadOptions ( ) {
void options_imp : : loadOptions ( )
{
int intValue ;
qreal floatValue ;
QString strValue ;
@ -573,11 +578,10 @@ void options_imp::loadOptions() {
@@ -573,11 +578,10 @@ void options_imp::loadOptions() {
checkStartPaused - > setChecked ( pref - > addTorrentsInPause ( ) ) ;
textSavePath - > setText ( Utils : : Fs : : toNativePath ( pref - > getSavePath ( ) ) ) ;
if ( pref - > isTempPathEnabled ( ) ) {
if ( pref - > isTempPathEnabled ( ) )
checkTempFolder - > setChecked ( true ) ;
} else {
else
checkTempFolder - > setChecked ( false ) ;
}
textTempPath - > setText ( Utils : : Fs : : toNativePath ( pref - > getTempPath ( ) ) ) ;
checkAppendLabel - > setChecked ( pref - > appendTorrentLabel ( ) ) ;
checkAppendqB - > setChecked ( pref - > useIncompleteFilesExtension ( ) ) ;
@ -587,7 +591,8 @@ void options_imp::loadOptions() {
@@ -587,7 +591,8 @@ void options_imp::loadOptions() {
if ( strValue . isEmpty ( ) ) {
// Disable
checkExportDir - > setChecked ( false ) ;
} else {
}
else {
// Enable
checkExportDir - > setChecked ( true ) ;
textExportDir - > setText ( strValue ) ;
@ -597,7 +602,8 @@ void options_imp::loadOptions() {
@@ -597,7 +602,8 @@ void options_imp::loadOptions() {
if ( strValue . isEmpty ( ) ) {
// Disable
checkExportDirFin - > setChecked ( false ) ;
} else {
}
else {
// Enable
checkExportDirFin - > setChecked ( true ) ;
textExportDirFin - > setText ( strValue ) ;
@ -635,7 +641,8 @@ void options_imp::loadOptions() {
@@ -635,7 +641,8 @@ void options_imp::loadOptions() {
checkMaxConnecs - > setChecked ( true ) ;
spinMaxConnec - > setEnabled ( true ) ;
spinMaxConnec - > setValue ( intValue ) ;
} else {
}
else {
// disable
checkMaxConnecs - > setChecked ( false ) ;
spinMaxConnec - > setEnabled ( false ) ;
@ -646,7 +653,8 @@ void options_imp::loadOptions() {
@@ -646,7 +653,8 @@ void options_imp::loadOptions() {
checkMaxConnecsPerTorrent - > setChecked ( true ) ;
spinMaxConnecPerTorrent - > setEnabled ( true ) ;
spinMaxConnecPerTorrent - > setValue ( intValue ) ;
} else {
}
else {
// disable
checkMaxConnecsPerTorrent - > setChecked ( false ) ;
spinMaxConnecPerTorrent - > setEnabled ( false ) ;
@ -657,7 +665,8 @@ void options_imp::loadOptions() {
@@ -657,7 +665,8 @@ void options_imp::loadOptions() {
checkMaxUploads - > setChecked ( true ) ;
spinMaxUploads - > setEnabled ( true ) ;
spinMaxUploads - > setValue ( intValue ) ;
} else {
}
else {
// disable
checkMaxUploads - > setChecked ( false ) ;
spinMaxUploads - > setEnabled ( false ) ;
@ -668,7 +677,8 @@ void options_imp::loadOptions() {
@@ -668,7 +677,8 @@ void options_imp::loadOptions() {
checkMaxUploadsPerTorrent - > setChecked ( true ) ;
spinMaxUploadsPerTorrent - > setEnabled ( true ) ;
spinMaxUploadsPerTorrent - > setValue ( intValue ) ;
} else {
}
else {
// disable
checkMaxUploadsPerTorrent - > setChecked ( false ) ;
spinMaxUploadsPerTorrent - > setEnabled ( false ) ;
@ -712,7 +722,8 @@ void options_imp::loadOptions() {
@@ -712,7 +722,8 @@ void options_imp::loadOptions() {
checkDownloadLimit - > setChecked ( true ) ;
spinDownloadLimit - > setEnabled ( true ) ;
spinDownloadLimit - > setValue ( intValue ) ;
} else {
}
else {
// Disabled
checkDownloadLimit - > setChecked ( false ) ;
spinDownloadLimit - > setEnabled ( false ) ;
@ -723,7 +734,8 @@ void options_imp::loadOptions() {
@@ -723,7 +734,8 @@ void options_imp::loadOptions() {
checkUploadLimit - > setChecked ( true ) ;
spinUploadLimit - > setEnabled ( true ) ;
spinUploadLimit - > setValue ( intValue ) ;
} else {
}
else {
// Disabled
checkUploadLimit - > setChecked ( false ) ;
spinUploadLimit - > setEnabled ( false ) ;
@ -735,7 +747,8 @@ void options_imp::loadOptions() {
@@ -735,7 +747,8 @@ void options_imp::loadOptions() {
checkDownloadLimitAlt - > setChecked ( true ) ;
spinDownloadLimitAlt - > setEnabled ( true ) ;
spinDownloadLimitAlt - > setValue ( intValue ) ;
} else {
}
else {
// Disabled
checkDownloadLimitAlt - > setChecked ( false ) ;
spinDownloadLimitAlt - > setEnabled ( false ) ;
@ -746,7 +759,8 @@ void options_imp::loadOptions() {
@@ -746,7 +759,8 @@ void options_imp::loadOptions() {
checkUploadLimitAlt - > setChecked ( true ) ;
spinUploadLimitAlt - > setEnabled ( true ) ;
spinUploadLimitAlt - > setValue ( intValue ) ;
} else {
}
else {
// Disabled
checkUploadLimitAlt - > setChecked ( false ) ;
spinUploadLimitAlt - > setEnabled ( false ) ;
@ -783,7 +797,8 @@ void options_imp::loadOptions() {
@@ -783,7 +797,8 @@ void options_imp::loadOptions() {
spinMaxRatio - > setEnabled ( true ) ;
comboRatioLimitAct - > setEnabled ( true ) ;
spinMaxRatio - > setValue ( floatValue ) ;
} else {
}
else {
// Disable
checkMaxRatio - > setChecked ( false ) ;
spinMaxRatio - > setEnabled ( false ) ;
@ -813,102 +828,115 @@ void options_imp::loadOptions() {
@@ -813,102 +828,115 @@ void options_imp::loadOptions() {
// return min & max ports
// [min, max]
int options_imp : : getPort ( ) const {
int options_imp : : getPort ( ) const
{
return spinPort - > value ( ) ;
}
void options_imp : : on_randomButton_clicked ( ) {
void options_imp : : on_randomButton_clicked ( )
{
// Range [1024: 65535]
spinPort - > setValue ( rand ( ) % 64512 + 1024 ) ;
}
int options_imp : : getEncryptionSetting ( ) const {
int options_imp : : getEncryptionSetting ( ) const
{
return comboEncryption - > currentIndex ( ) ;
}
int options_imp : : getMaxActiveDownloads ( ) const {
int options_imp : : getMaxActiveDownloads ( ) const
{
return spinMaxActiveDownloads - > value ( ) ;
}
int options_imp : : getMaxActiveUploads ( ) const {
int options_imp : : getMaxActiveUploads ( ) const
{
return spinMaxActiveUploads - > value ( ) ;
}
int options_imp : : getMaxActiveTorrents ( ) const {
int options_imp : : getMaxActiveTorrents ( ) const
{
return spinMaxActiveTorrents - > value ( ) ;
}
bool options_imp : : minimizeToTray ( ) const {
bool options_imp : : minimizeToTray ( ) const
{
if ( ! checkShowSystray - > isChecked ( ) ) return false ;
return checkMinimizeToSysTray - > isChecked ( ) ;
}
bool options_imp : : closeToTray ( ) const {
bool options_imp : : closeToTray ( ) const
{
if ( ! checkShowSystray - > isChecked ( ) ) return false ;
return checkCloseToSystray - > isChecked ( ) ;
}
bool options_imp : : isQueueingSystemEnabled ( ) const {
bool options_imp : : isQueueingSystemEnabled ( ) const
{
return checkEnableQueueing - > isChecked ( ) ;
}
bool options_imp : : isDHTEnabled ( ) const {
bool options_imp : : isDHTEnabled ( ) const
{
return checkDHT - > isChecked ( ) ;
}
bool options_imp : : isLSDEnabled ( ) const {
bool options_imp : : isLSDEnabled ( ) const
{
return checkLSD - > isChecked ( ) ;
}
bool options_imp : : isUPnPEnabled ( ) const {
bool options_imp : : isUPnPEnabled ( ) const
{
return checkUPnP - > isChecked ( ) ;
}
// Return Download & Upload limits in kbps
// [download,upload]
QPair < int , int > options_imp : : getGlobalBandwidthLimits ( ) const {
QPair < int , int > options_imp : : getGlobalBandwidthLimits ( ) const
{
int DL = - 1 , UP = - 1 ;
if ( checkDownloadLimit - > isChecked ( ) ) {
if ( checkDownloadLimit - > isChecked ( ) )
DL = spinDownloadLimit - > value ( ) ;
}
if ( checkUploadLimit - > isChecked ( ) ) {
if ( checkUploadLimit - > isChecked ( ) )
UP = spinUploadLimit - > value ( ) ;
}
return qMakePair ( DL , UP ) ;
}
// Return alternate Download & Upload limits in kbps
// [download,upload]
QPair < int , int > options_imp : : getAltGlobalBandwidthLimits ( ) const {
QPair < int , int > options_imp : : getAltGlobalBandwidthLimits ( ) const
{
int DL = - 1 , UP = - 1 ;
if ( checkDownloadLimitAlt - > isChecked ( ) ) {
if ( checkDownloadLimitAlt - > isChecked ( ) )
DL = spinDownloadLimitAlt - > value ( ) ;
}
if ( checkUploadLimitAlt - > isChecked ( ) ) {
if ( checkUploadLimitAlt - > isChecked ( ) )
UP = spinUploadLimitAlt - > value ( ) ;
}
return qMakePair ( DL , UP ) ;
}
bool options_imp : : startMinimized ( ) const {
bool options_imp : : startMinimized ( ) const
{
return checkStartMinimized - > isChecked ( ) ;
}
bool options_imp : : systrayIntegration ( ) const {
bool options_imp : : systrayIntegration ( ) const
{
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) return false ;
return checkShowSystray - > isChecked ( ) ;
}
// Return Share ratio
qreal options_imp : : getMaxRatio ( ) const {
if ( checkMaxRatio - > isChecked ( ) ) {
qreal options_imp : : getMaxRatio ( ) const
{
if ( checkMaxRatio - > isChecked ( ) )
return spinMaxRatio - > value ( ) ;
}
return - 1 ;
}
// Return Save Path
QString options_imp : : getSavePath ( ) const {
QString options_imp : : getSavePath ( ) const
{
if ( textSavePath - > text ( ) . trimmed ( ) . isEmpty ( ) ) {
QString save_path = Preferences : : instance ( ) - > getSavePath ( ) ;
textSavePath - > setText ( Utils : : Fs : : toNativePath ( save_path ) ) ;
@ -916,48 +944,51 @@ QString options_imp::getSavePath() const {
@@ -916,48 +944,51 @@ QString options_imp::getSavePath() const {
return Utils : : Fs : : expandPathAbs ( textSavePath - > text ( ) ) ;
}
QString options_imp : : getTempPath ( ) const {
QString options_imp : : getTempPath ( ) const
{
return Utils : : Fs : : expandPathAbs ( textTempPath - > text ( ) ) ;
}
bool options_imp : : isTempPathEnabled ( ) const {
bool options_imp : : isTempPathEnabled ( ) const
{
return checkTempFolder - > isChecked ( ) ;
}
// Return max connections number
int options_imp : : getMaxConnecs ( ) const {
if ( ! checkMaxConnecs - > isChecked ( ) ) {
int options_imp : : getMaxConnecs ( ) const
{
if ( ! checkMaxConnecs - > isChecked ( ) )
return - 1 ;
} else {
else
return spinMaxConnec - > value ( ) ;
}
}
int options_imp : : getMaxConnecsPerTorrent ( ) const {
if ( ! checkMaxConnecsPerTorrent - > isChecked ( ) ) {
int options_imp : : getMaxConnecsPerTorrent ( ) const
{
if ( ! checkMaxConnecsPerTorrent - > isChecked ( ) )
return - 1 ;
} else {
else
return spinMaxConnecPerTorrent - > value ( ) ;
}
}
int options_imp : : getMaxUploads ( ) const {
if ( ! checkMaxUploads - > isChecked ( ) ) {
int options_imp : : getMaxUploads ( ) const
{
if ( ! checkMaxUploads - > isChecked ( ) )
return - 1 ;
} else {
else
return spinMaxUploads - > value ( ) ;
}
}
int options_imp : : getMaxUploadsPerTorrent ( ) const {
if ( ! checkMaxUploadsPerTorrent - > isChecked ( ) ) {
int options_imp : : getMaxUploadsPerTorrent ( ) const
{
if ( ! checkMaxUploadsPerTorrent - > isChecked ( ) )
return - 1 ;
} else {
else
return spinMaxUploadsPerTorrent - > value ( ) ;
}
}
void options_imp : : on_buttonBox_accepted ( ) {
void options_imp : : on_buttonBox_accepted ( )
{
if ( applyButton - > isEnabled ( ) ) {
if ( ! schedTimesOk ( ) ) {
tabSelection - > setCurrentRow ( TAB_SPEED ) ;
@ -972,7 +1003,8 @@ void options_imp::on_buttonBox_accepted() {
@@ -972,7 +1003,8 @@ void options_imp::on_buttonBox_accepted() {
accept ( ) ;
}
void options_imp : : applySettings ( QAbstractButton * button ) {
void options_imp : : applySettings ( QAbstractButton * button )
{
if ( button = = applyButton ) {
if ( ! schedTimesOk ( ) ) {
tabSelection - > setCurrentRow ( TAB_SPEED ) ;
@ -983,25 +1015,30 @@ void options_imp::applySettings(QAbstractButton* button) {
@@ -983,25 +1015,30 @@ void options_imp::applySettings(QAbstractButton* button) {
}
}
void options_imp : : closeEvent ( QCloseEvent * e ) {
void options_imp : : closeEvent ( QCloseEvent * e )
{
setAttribute ( Qt : : WA_DeleteOnClose ) ;
e - > accept ( ) ;
}
void options_imp : : on_buttonBox_rejected ( ) {
void options_imp : : on_buttonBox_rejected ( )
{
setAttribute ( Qt : : WA_DeleteOnClose ) ;
reject ( ) ;
}
bool options_imp : : useAdditionDialog ( ) const {
bool options_imp : : useAdditionDialog ( ) const
{
return checkAdditionDialog - > isChecked ( ) ;
}
void options_imp : : enableApplyButton ( ) {
void options_imp : : enableApplyButton ( )
{
applyButton - > setEnabled ( true ) ;
}
void options_imp : : enableProxy ( int index ) {
void options_imp : : enableProxy ( int index )
{
if ( index ) {
//enable
lblProxyIP - > setEnabled ( true ) ;
@ -1013,11 +1050,13 @@ void options_imp::enableProxy(int index) {
@@ -1013,11 +1050,13 @@ void options_imp::enableProxy(int index) {
isProxyOnlyForTorrents - > setEnabled ( true ) ;
if ( index > 1 ) {
checkProxyAuth - > setEnabled ( true ) ;
} else {
}
else {
checkProxyAuth - > setEnabled ( false ) ;
checkProxyAuth - > setChecked ( false ) ;
}
} else {
}
else {
//disable
lblProxyIP - > setEnabled ( false ) ;
textProxyIP - > setEnabled ( false ) ;
@ -1031,63 +1070,76 @@ void options_imp::enableProxy(int index) {
@@ -1031,63 +1070,76 @@ void options_imp::enableProxy(int index) {
}
}
bool options_imp : : isSlashScreenDisabled ( ) const {
bool options_imp : : isSlashScreenDisabled ( ) const
{
return ! checkShowSplash - > isChecked ( ) ;
}
# ifdef Q_OS_WIN
bool options_imp : : WinStartup ( ) const {
bool options_imp : : WinStartup ( ) const
{
return checkStartup - > isChecked ( ) ;
}
# endif
bool options_imp : : preventFromSuspend ( ) const {
bool options_imp : : preventFromSuspend ( ) const
{
return checkPreventFromSuspend - > isChecked ( ) ;
}
bool options_imp : : preAllocateAllFiles ( ) const {
bool options_imp : : preAllocateAllFiles ( ) const
{
return checkPreallocateAll - > isChecked ( ) ;
}
bool options_imp : : addTorrentsInPause ( ) const {
bool options_imp : : addTorrentsInPause ( ) const
{
return checkStartPaused - > isChecked ( ) ;
}
// Proxy settings
bool options_imp : : isProxyEnabled ( ) const {
bool options_imp : : isProxyEnabled ( ) const
{
return comboProxyType - > currentIndex ( ) ;
}
bool options_imp : : isProxyAuthEnabled ( ) const {
bool options_imp : : isProxyAuthEnabled ( ) const
{
return checkProxyAuth - > isChecked ( ) ;
}
QString options_imp : : getProxyIp ( ) const {
QString options_imp : : getProxyIp ( ) const
{
return textProxyIP - > text ( ) . trimmed ( ) ;
}
unsigned short options_imp : : getProxyPort ( ) const {
unsigned short options_imp : : getProxyPort ( ) const
{
return spinProxyPort - > value ( ) ;
}
QString options_imp : : getProxyUsername ( ) const {
QString options_imp : : getProxyUsername ( ) const
{
QString username = textProxyUsername - > text ( ) ;
username = username . trimmed ( ) ;
return username ;
}
QString options_imp : : getProxyPassword ( ) const {
QString options_imp : : getProxyPassword ( ) const
{
QString password = textProxyPassword - > text ( ) ;
password = password . trimmed ( ) ;
return password ;
}
// Locale Settings
QString options_imp : : getLocale ( ) const {
QString options_imp : : getLocale ( ) const
{
return comboI18n - > itemData ( comboI18n - > currentIndex ( ) , Qt : : UserRole ) . toString ( ) ;
}
void options_imp : : setLocale ( const QString & localeStr ) {
void options_imp : : setLocale ( const QString & localeStr )
{
QLocale locale ( localeStr ) ;
QString name = locale . name ( ) ;
// Attempt to find exact match
@ -1108,33 +1160,38 @@ void options_imp::setLocale(const QString &localeStr) {
@@ -1108,33 +1160,38 @@ void options_imp::setLocale(const QString &localeStr) {
comboI18n - > setCurrentIndex ( index ) ;
}
QString options_imp : : getTorrentExportDir ( ) const {
QString options_imp : : getTorrentExportDir ( ) const
{
if ( checkExportDir - > isChecked ( ) )
return Utils : : Fs : : expandPathAbs ( textExportDir - > text ( ) ) ;
return QString ( ) ;
}
QString options_imp : : getFinishedTorrentExportDir ( ) const {
QString options_imp : : getFinishedTorrentExportDir ( ) const
{
if ( checkExportDirFin - > isChecked ( ) )
return Utils : : Fs : : expandPathAbs ( textExportDirFin - > text ( ) ) ;
return QString ( ) ;
}
// Return action on double-click on a downloading torrent set in options
int options_imp : : getActionOnDblClOnTorrentDl ( ) const {
int options_imp : : getActionOnDblClOnTorrentDl ( ) const
{
if ( actionTorrentDlOnDblClBox - > currentIndex ( ) < 1 )
return 0 ;
return actionTorrentDlOnDblClBox - > currentIndex ( ) ;
}
// Return action on double-click on a finished torrent set in options
int options_imp : : getActionOnDblClOnTorrentFn ( ) const {
int options_imp : : getActionOnDblClOnTorrentFn ( ) const
{
if ( actionTorrentFnOnDblClBox - > currentIndex ( ) < 1 )
return 0 ;
return actionTorrentFnOnDblClBox - > currentIndex ( ) ;
}
void options_imp : : on_addScanFolderButton_clicked ( ) {
void options_imp : : on_addScanFolderButton_clicked ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
const QString dir = QFileDialog : : getExistingDirectory ( this , tr ( " Add directory to scan " ) ,
Utils : : Fs : : toNativePath ( Utils : : Fs : : folderName ( pref - > getScanDirsLastPath ( ) ) ) ) ;
@ -1158,13 +1215,13 @@ void options_imp::on_addScanFolderButton_clicked() {
@@ -1158,13 +1215,13 @@ void options_imp::on_addScanFolderButton_clicked() {
enableApplyButton ( ) ;
}
if ( ! error . isEmpty ( ) ) {
if ( ! error . isEmpty ( ) )
QMessageBox : : warning ( this , tr ( " Failure " ) , tr ( " Failed to add Scan Folder '%1': %2 " ) . arg ( dir ) . arg ( error ) ) ;
}
}
}
void options_imp : : on_removeScanFolderButton_clicked ( ) {
void options_imp : : on_removeScanFolderButton_clicked ( )
{
const QModelIndexList selected
= scanFoldersView - > selectionModel ( ) - > selectedIndexes ( ) ;
if ( selected . isEmpty ( ) )
@ -1173,7 +1230,8 @@ void options_imp::on_removeScanFolderButton_clicked() {
@@ -1173,7 +1230,8 @@ void options_imp::on_removeScanFolderButton_clicked() {
ScanFoldersModel : : instance ( ) - > removePath ( selected . first ( ) . row ( ) ) ;
}
void options_imp : : handleScanFolderViewSelectionChanged ( ) {
void options_imp : : handleScanFolderViewSelectionChanged ( )
{
removeScanFolderButton - > setEnabled ( ! scanFoldersView - > selectionModel ( ) - > selectedIndexes ( ) . isEmpty ( ) ) ;
}
@ -1181,68 +1239,70 @@ QString options_imp::askForExportDir(const QString& currentExportPath)
@@ -1181,68 +1239,70 @@ QString options_imp::askForExportDir(const QString& currentExportPath)
{
QDir currentExportDir ( Utils : : Fs : : expandPathAbs ( currentExportPath ) ) ;
QString dir ;
if ( ! currentExportPath . isEmpty ( ) & & currentExportDir . exists ( ) ) {
if ( ! currentExportPath . isEmpty ( ) & & currentExportDir . exists ( ) )
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose export directory " ) , currentExportDir . absolutePath ( ) ) ;
} else {
else
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose export directory " ) , QDir : : homePath ( ) ) ;
}
return dir ;
}
void options_imp : : on_browseExportDirButton_clicked ( ) {
void options_imp : : on_browseExportDirButton_clicked ( )
{
const QString newExportDir = askForExportDir ( textExportDir - > text ( ) ) ;
if ( ! newExportDir . isNull ( ) )
textExportDir - > setText ( Utils : : Fs : : toNativePath ( newExportDir ) ) ;
}
void options_imp : : on_browseExportDirFinButton_clicked ( ) {
void options_imp : : on_browseExportDirFinButton_clicked ( )
{
const QString newExportDir = askForExportDir ( textExportDirFin - > text ( ) ) ;
if ( ! newExportDir . isNull ( ) )
textExportDirFin - > setText ( Utils : : Fs : : toNativePath ( newExportDir ) ) ;
}
void options_imp : : on_browseFilterButton_clicked ( ) {
void options_imp : : on_browseFilterButton_clicked ( )
{
const QString filter_path = Utils : : Fs : : expandPathAbs ( textFilterPath - > text ( ) ) ;
QDir filterDir ( filter_path ) ;
QString ipfilter ;
if ( ! filter_path . isEmpty ( ) & & filterDir . exists ( ) ) {
if ( ! filter_path . isEmpty ( ) & & filterDir . exists ( ) )
ipfilter = QFileDialog : : getOpenFileName ( this , tr ( " Choose an IP filter file " ) , filterDir . absolutePath ( ) , tr ( " Filters " ) + QString ( " (*.dat *.p2p *.p2b) " ) ) ;
} else {
else
ipfilter = QFileDialog : : getOpenFileName ( this , tr ( " Choose an IP filter file " ) , QDir : : homePath ( ) , tr ( " Filters " ) + QString ( " (*.dat *.p2p *.p2b) " ) ) ;
}
if ( ! ipfilter . isNull ( ) )
textFilterPath - > setText ( Utils : : Fs : : toNativePath ( ipfilter ) ) ;
}
// Display dialog to choose save dir
void options_imp : : on_browseSaveDirButton_clicked ( ) {
void options_imp : : on_browseSaveDirButton_clicked ( )
{
const QString save_path = Utils : : Fs : : expandPathAbs ( textSavePath - > text ( ) ) ;
QDir saveDir ( save_path ) ;
QString dir ;
if ( ! save_path . isEmpty ( ) & & saveDir . exists ( ) ) {
if ( ! save_path . isEmpty ( ) & & saveDir . exists ( ) )
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , saveDir . absolutePath ( ) ) ;
} else {
else
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , QDir : : homePath ( ) ) ;
}
if ( ! dir . isNull ( ) )
textSavePath - > setText ( Utils : : Fs : : toNativePath ( dir ) ) ;
}
void options_imp : : on_browseTempDirButton_clicked ( ) {
void options_imp : : on_browseTempDirButton_clicked ( )
{
const QString temp_path = Utils : : Fs : : expandPathAbs ( textTempPath - > text ( ) ) ;
QDir tempDir ( temp_path ) ;
QString dir ;
if ( ! temp_path . isEmpty ( ) & & tempDir . exists ( ) ) {
if ( ! temp_path . isEmpty ( ) & & tempDir . exists ( ) )
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , tempDir . absolutePath ( ) ) ;
} else {
else
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , QDir : : homePath ( ) ) ;
}
if ( ! dir . isNull ( ) )
textTempPath - > setText ( Utils : : Fs : : toNativePath ( dir ) ) ;
}
// Return Filter object to apply to BT session
QString options_imp : : getFilter ( ) const {
QString options_imp : : getFilter ( ) const
{
return Utils : : Fs : : fromNativePath ( textFilterPath - > text ( ) ) ;
}
@ -1273,7 +1333,8 @@ void options_imp::showConnectionTab()
@@ -1273,7 +1333,8 @@ void options_imp::showConnectionTab()
tabSelection - > setCurrentRow ( TAB_CONNECTION ) ;
}
void options_imp : : on_btnWebUiCrt_clicked ( ) {
void options_imp : : on_btnWebUiCrt_clicked ( )
{
QString filename = QFileDialog : : getOpenFileName ( this , QString ( ) , QString ( ) , tr ( " SSL Certificate " ) + QString ( " (*.crt *.pem) " ) ) ;
if ( filename . isNull ( ) )
return ;
@ -1284,7 +1345,8 @@ void options_imp::on_btnWebUiCrt_clicked() {
@@ -1284,7 +1345,8 @@ void options_imp::on_btnWebUiCrt_clicked() {
}
}
void options_imp : : on_btnWebUiKey_clicked ( ) {
void options_imp : : on_btnWebUiKey_clicked ( )
{
QString filename = QFileDialog : : getOpenFileName ( this , QString ( ) , QString ( ) , tr ( " SSL Key " ) + QString ( " (*.key *.pem) " ) ) ;
if ( filename . isNull ( ) )
return ;
@ -1295,11 +1357,13 @@ void options_imp::on_btnWebUiKey_clicked() {
@@ -1295,11 +1357,13 @@ void options_imp::on_btnWebUiKey_clicked() {
}
}
void options_imp : : on_registerDNSBtn_clicked ( ) {
void options_imp : : on_registerDNSBtn_clicked ( )
{
QDesktopServices : : openUrl ( Net : : DNSUpdater : : getRegistrationUrl ( comboDNSService - > currentIndex ( ) ) ) ;
}
void options_imp : : on_IpFilterRefreshBtn_clicked ( ) {
void options_imp : : on_IpFilterRefreshBtn_clicked ( )
{
if ( m_refreshingIpFilter ) return ;
m_refreshingIpFilter = true ;
// Updating program preferences
@ -1315,11 +1379,10 @@ void options_imp::on_IpFilterRefreshBtn_clicked() {
@@ -1315,11 +1379,10 @@ void options_imp::on_IpFilterRefreshBtn_clicked() {
void options_imp : : handleIPFilterParsed ( bool error , int ruleCount )
{
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
if ( error ) {
if ( error )
QMessageBox : : warning ( this , tr ( " Parsing error " ) , tr ( " Failed to parse the provided IP filter " ) ) ;
} else {
else
QMessageBox : : information ( this , tr ( " Successfully refreshed " ) , tr ( " Successfully parsed the provided IP filter: %1 rules were applied. " , " %1 is a number " ) . arg ( ruleCount ) ) ;
}
m_refreshingIpFilter = false ;
disconnect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( ipFilterParsed ( bool , int ) ) , this , SLOT ( handleIPFilterParsed ( bool , int ) ) ) ;
}
@ -1401,7 +1464,8 @@ void options_imp::setSslKey(const QByteArray &key, bool interactive)
@@ -1401,7 +1464,8 @@ void options_imp::setSslKey(const QByteArray &key, bool interactive)
if ( ! key . isEmpty ( ) & & ! QSslKey ( key , QSsl : : Rsa ) . isNull ( ) ) {
lblSslKeyStatus - > setPixmap ( QPixmap ( " :/icons/oxygen/security-high.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslKey = key ;
} else {
}
else {
lblSslKeyStatus - > setPixmap ( QPixmap ( " :/icons/oxygen/security-low.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslKey . clear ( ) ;
if ( interactive )
@ -1416,7 +1480,8 @@ void options_imp::setSslCertificate(const QByteArray &cert, bool interactive)
@@ -1416,7 +1480,8 @@ void options_imp::setSslCertificate(const QByteArray &cert, bool interactive)
if ( ! cert . isEmpty ( ) & & ! QSslCertificate ( cert ) . isNull ( ) ) {
lblSslCertStatus - > setPixmap ( QPixmap ( " :/icons/oxygen/security-high.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslCert = cert ;
} else {
}
else {
lblSslCertStatus - > setPixmap ( QPixmap ( " :/icons/oxygen/security-low.png " ) . scaledToHeight ( 20 , Qt : : SmoothTransformation ) ) ;
m_sslCert . clear ( ) ;
if ( interactive )
@ -1425,7 +1490,8 @@ void options_imp::setSslCertificate(const QByteArray &cert, bool interactive)
@@ -1425,7 +1490,8 @@ void options_imp::setSslCertificate(const QByteArray &cert, bool interactive)
# endif
}
bool options_imp : : schedTimesOk ( ) {
bool options_imp : : schedTimesOk ( )
{
QString msg ;
if ( schedule_from - > time ( ) = = schedule_to - > time ( ) )