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>
# include <QInputDialog>
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>
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
# include <time.h>
# include <stdlib.h>
2006-09-30 20:02:39 +04:00
# include "options_imp.h"
2009-11-14 22:08:28 +03:00
# include "preferences.h"
2006-09-30 20:02:39 +04:00
# include "misc.h"
2010-01-31 18:11:15 +03:00
# include "advancedsettings.h"
2010-02-28 18:15:00 +03:00
# include "scannedfoldersmodel.h"
2010-07-16 19:03:18 +04:00
# include "qinisettings.h"
2010-12-25 17:47:52 +03:00
# include "qbtsession.h"
2011-01-01 16:05:28 +03:00
# include "iconprovider.h"
2006-09-30 20:02:39 +04:00
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 ( ) ;
2009-01-24 23:07:05 +03:00
foreach ( QAbstractButton * button , buttons ) {
2007-04-11 22:19:20 +04:00
if ( buttonBox - > buttonRole ( button ) = = QDialogButtonBox : : ApplyRole ) {
applyButton = button ;
break ;
}
}
2010-02-28 18:15:00 +03:00
scanFoldersView - > horizontalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
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)
for ( uint i = 1 ; i < = 7 ; + + i ) {
2010-07-24 21:35:29 +04:00
# if QT_VERSION >= 0x040500
2010-01-23 23:44:09 +03:00
schedule_days - > addItem ( QDate : : longDayName ( i , QDate : : StandaloneFormat ) ) ;
2010-02-28 19:07:09 +03:00
# else
schedule_days - > addItem ( QDate : : longDayName ( i ) ) ;
# endif
2010-01-23 23:44:09 +03:00
}
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
2010-10-09 19:36:39 +04:00
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
checkShowSystray - > setChecked ( false ) ;
checkShowSystray - > setEnabled ( false ) ;
}
// Connect signals / slots
// General tab
connect ( checkShowSystray , SIGNAL ( toggled ( bool ) ) , this , SLOT ( setSystrayOptionsState ( bool ) ) ) ;
// Connection tab
connect ( checkUploadLimit , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableUploadLimit ( bool ) ) ) ;
connect ( checkDownloadLimit , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableDownloadLimit ( bool ) ) ) ;
// Bittorrent tab
connect ( checkMaxConnecs , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableMaxConnecsLimit ( bool ) ) ) ;
connect ( checkMaxConnecsPerTorrent , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableMaxConnecsLimitPerTorrent ( bool ) ) ) ;
connect ( checkMaxUploadsPerTorrent , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableMaxUploadsLimitPerTorrent ( bool ) ) ) ;
connect ( checkMaxRatio , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableMaxRatio ( bool ) ) ) ;
// Proxy tab
2010-11-18 23:05:56 +03:00
connect ( comboProxyType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( enableProxy ( int ) ) ) ;
connect ( checkProxyAuth , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableProxyAuth ( 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 ( ) ) ) ;
connect ( checkShowSplash , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
2011-02-06 17:27:34 +03:00
connect ( checkPreventFromSuspend , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
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 ( ) ) ) ;
connect ( checkStartPaused , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkExportDir , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textExportDir , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
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 ( ) ) ) ;
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 ( ) ) ) ;
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 ( ) ) ) ;
// Bittorrent tab
connect ( checkMaxConnecs , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkMaxConnecsPerTorrent , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkMaxUploadsPerTorrent , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxConnec , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxConnecPerTorrent , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinMaxUploadsPerTorrent , SIGNAL ( valueChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkDHT , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkPeX , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( checkDifferentDHTPort , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinDHTPort , SIGNAL ( valueChanged ( QString ) ) , 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 ( ) ) ) ;
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 ( ) ) ) ;
// Web UI tab
connect ( checkWebUi , SIGNAL ( toggled ( bool ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( spinWebUiPort , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textWebUiUsername , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
connect ( textWebUiPassword , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( enableApplyButton ( ) ) ) ;
// Disable apply Button
applyButton - > setEnabled ( false ) ;
// Tab selection mecanism
connect ( tabSelection , SIGNAL ( currentItemChanged ( QListWidgetItem * , QListWidgetItem * ) ) , this , SLOT ( changePage ( QListWidgetItem * , QListWidgetItem * ) ) ) ;
2010-06-07 12:32:41 +04:00
# if LIBTORRENT_VERSION_MINOR < 15
2010-10-09 19:36:39 +04:00
checkAppendqB - > setVisible ( false ) ;
2009-12-18 16:36:47 +03:00
# endif
2010-10-09 19:36:39 +04:00
// 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 ( ) ) ) ;
// Adapt size
show ( ) ;
loadWindowState ( ) ;
}
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 ) ;
foreach ( QString lang_file , lang_files ) {
QString localeStr = lang_file . mid ( 12 ) ; // remove "qbittorrent_"
localeStr . chop ( 3 ) ; // Remove ".qm"
QLocale locale ( localeStr ) ;
2011-01-12 20:42:55 +03:00
const QString country = locale . name ( ) . split ( " _ " ) . last ( ) . toLower ( ) ;
QString language_name = languageToLocalizedString ( locale . language ( ) , country ) ;
comboI18n - > addItem ( /*QIcon(":/Icons/flags/"+country+".png"), */ language_name , locale . name ( ) ) ;
2010-11-20 18:59:17 +03:00
qDebug ( ) < < " Supported locale: " < < locale . name ( ) ;
}
}
2010-10-09 19:36:39 +04:00
// Main destructor
options_imp : : ~ options_imp ( ) {
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 ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
resize ( settings . value ( QString : : fromUtf8 ( " Preferences/State/size " ) , sizeFittingScreen ( ) ) . toSize ( ) ) ;
QPoint p = settings . value ( QString : : fromUtf8 ( " Preferences/State/pos " ) , QPoint ( ) ) . toPoint ( ) ;
if ( ! p . isNull ( ) )
move ( p ) ;
// Load slider size
const QStringList sizes_str = settings . value ( " Preferences/State/hSplitterSizes " , QStringList ( ) ) . toStringList ( ) ;
// Splitter size
QList < int > sizes ;
if ( sizes_str . size ( ) = = 2 ) {
sizes < < sizes_str . first ( ) . toInt ( ) ;
sizes < < sizes_str . last ( ) . toInt ( ) ;
} else {
sizes < < 130 ;
sizes < < hsplitter - > width ( ) - 130 ;
}
hsplitter - > setSizes ( sizes ) ;
}
void options_imp : : saveWindowState ( ) const {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
settings . setValue ( QString : : fromUtf8 ( " Preferences/State/size " ) , size ( ) ) ;
settings . setValue ( QString : : fromUtf8 ( " Preferences/State/pos " ) , pos ( ) ) ;
// Splitter size
QStringList sizes_str ;
sizes_str < < QString : : number ( hsplitter - > sizes ( ) . first ( ) ) ;
sizes_str < < QString : : number ( hsplitter - > sizes ( ) . last ( ) ) ;
settings . setValue ( QString : : fromUtf8 ( " Preferences/State/hSplitterSizes " ) , sizes_str ) ;
}
QSize options_imp : : sizeFittingScreen ( ) {
int scrn = 0 ;
QWidget * w = this - > topLevelWidget ( ) ;
if ( w )
scrn = QApplication : : desktop ( ) - > screenNumber ( w ) ;
else if ( QApplication : : desktop ( ) - > isVirtualDesktop ( ) )
scrn = QApplication : : desktop ( ) - > screenNumber ( QCursor : : pos ( ) ) ;
else
scrn = QApplication : : desktop ( ) - > screenNumber ( this ) ;
QRect desk ( QApplication : : desktop ( ) - > availableGeometry ( scrn ) ) ;
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 ( ) {
applyButton - > setEnabled ( false ) ;
2010-11-16 23:34:31 +03:00
Preferences pref ;
2010-10-09 19:36:39 +04:00
// Load the translation
QString locale = getLocale ( ) ;
2010-11-16 23:34:31 +03:00
if ( pref . getLocale ( ) ! = locale ) {
2010-10-09 19:36:39 +04:00
QTranslator * translator = new QTranslator ;
if ( translator - > load ( QString : : fromUtf8 ( " :/lang/qbittorrent_ " ) + locale ) ) {
qDebug ( " %s locale recognized, using translation. " , qPrintable ( locale ) ) ;
} else {
qDebug ( " %s locale unrecognized, using default (en_GB). " , qPrintable ( locale ) ) ;
2010-09-25 16:42:19 +04:00
}
2010-10-09 19:36:39 +04:00
qApp - > installTranslator ( translator ) ;
}
// General preferences
2010-11-16 23:34:31 +03:00
pref . setLocale ( locale ) ;
pref . setAlternatingRowColors ( checkAltRowColors - > isChecked ( ) ) ;
pref . setSystrayIntegration ( systrayIntegration ( ) ) ;
pref . setCloseToTray ( closeToTray ( ) ) ;
pref . setMinimizeToTray ( minimizeToTray ( ) ) ;
pref . setStartMinimized ( startMinimized ( ) ) ;
pref . setSplashScreenDisabled ( isSlashScreenDisabled ( ) ) ;
2011-02-06 17:27:34 +03:00
pref . setPreventFromSuspend ( preventFromSuspend ( ) ) ;
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
QString save_path = getSavePath ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
save_path = save_path . replace ( " \\ " , " / " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-11-16 23:34:31 +03:00
pref . setSavePath ( save_path ) ;
pref . setTempPathEnabled ( isTempPathEnabled ( ) ) ;
2010-10-09 19:36:39 +04:00
QString temp_path = getTempPath ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
temp_path = temp_path . replace ( " \\ " , " / " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-11-16 23:34:31 +03:00
pref . setTempPath ( temp_path ) ;
pref . setAppendTorrentLabel ( checkAppendLabel - > isChecked ( ) ) ;
2010-06-07 12:32:41 +04:00
# if LIBTORRENT_VERSION_MINOR > 14
2010-11-16 23:34:31 +03:00
pref . useIncompleteFilesExtension ( checkAppendqB - > isChecked ( ) ) ;
2009-12-18 16:36:47 +03:00
# endif
2010-11-16 23:34:31 +03:00
pref . preAllocateAllFiles ( preAllocateAllFiles ( ) ) ;
pref . useAdditionDialog ( useAdditionDialog ( ) ) ;
pref . addTorrentsInPause ( addTorrentsInPause ( ) ) ;
2010-12-27 22:26:21 +03:00
ScanFoldersModel : : instance ( ) - > makePersistent ( ) ;
2010-10-09 19:36:39 +04:00
addedScanDirs . clear ( ) ;
QString export_dir = getExportDir ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
export_dir = export_dir . replace ( " \\ " , " / " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-11-16 23:34:31 +03:00
pref . setExportDir ( export_dir ) ;
pref . setMailNotificationEnabled ( groupMailNotification - > isChecked ( ) ) ;
pref . setMailNotificationEmail ( dest_email_txt - > text ( ) ) ;
pref . setMailNotificationSMTP ( smtp_server_txt - > 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
2010-11-16 23:34:31 +03:00
pref . setSessionPort ( getPort ( ) ) ;
pref . setUPnPEnabled ( isUPnPEnabled ( ) ) ;
2010-12-02 20:17:50 +03:00
const QPair < int , int > down_up_limit = getGlobalBandwidthLimits ( ) ;
pref . setGlobalDownloadLimit ( down_up_limit . first ) ;
pref . setGlobalUploadLimit ( down_up_limit . second ) ;
2010-11-16 23:34:31 +03:00
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 ( ) ) ;
2010-11-18 23:05:56 +03:00
pref . setProxyType ( getProxyType ( ) ) ;
pref . setProxyIp ( getProxyIp ( ) ) ;
pref . setProxyPort ( getProxyPort ( ) ) ;
pref . setProxyAuthEnabled ( isProxyAuthEnabled ( ) ) ;
pref . setProxyUsername ( getProxyUsername ( ) ) ;
pref . setProxyPassword ( getProxyPassword ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Connection preferences
// Bittorrent preferences
2010-11-16 23:34:31 +03:00
pref . setMaxConnecs ( getMaxConnecs ( ) ) ;
pref . setMaxConnecsPerTorrent ( getMaxConnecsPerTorrent ( ) ) ;
pref . setMaxUploadsPerTorrent ( getMaxUploadsPerTorrent ( ) ) ;
pref . setDHTEnabled ( isDHTEnabled ( ) ) ;
pref . setPeXEnabled ( checkPeX - > isChecked ( ) ) ;
pref . setDHTPortSameAsBT ( isDHTPortSameAsBT ( ) ) ;
pref . setDHTPort ( getDHTPort ( ) ) ;
pref . setLSDEnabled ( isLSDEnabled ( ) ) ;
pref . setEncryptionSetting ( getEncryptionSetting ( ) ) ;
pref . setMaxRatio ( getMaxRatio ( ) ) ;
pref . setMaxRatioAction ( comboRatioLimitAct - > currentIndex ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Bittorrent preferences
// Misc preferences
// * IPFilter
2010-11-16 23:34:31 +03:00
pref . setFilteringEnabled ( isFilteringEnabled ( ) ) ;
2010-10-09 19:36:39 +04:00
if ( isFilteringEnabled ( ) ) {
QString filter_path = textFilterPath - > text ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
filter_path = filter_path . replace ( " \\ " , " / " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-11-16 23:34:31 +03:00
pref . setFilter ( filter_path ) ;
2010-10-09 19:36:39 +04:00
}
// End IPFilter preferences
// Queueing system
2010-11-16 23:34:31 +03:00
pref . setQueueingSystemEnabled ( isQueueingSystemEnabled ( ) ) ;
pref . setMaxActiveDownloads ( spinMaxActiveDownloads - > value ( ) ) ;
pref . setMaxActiveUploads ( spinMaxActiveUploads - > value ( ) ) ;
pref . setMaxActiveTorrents ( spinMaxActiveTorrents - > value ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Queueing system preferences
// Web UI
2010-11-16 23:34:31 +03:00
pref . setWebUiEnabled ( isWebUiEnabled ( ) ) ;
2010-10-09 19:36:39 +04:00
if ( isWebUiEnabled ( ) )
{
2010-11-16 23:34:31 +03:00
pref . setWebUiPort ( webUiPort ( ) ) ;
pref . setWebUiUsername ( webUiUsername ( ) ) ;
2010-10-09 19:36:39 +04:00
// FIXME: Check that the password is valid (not empty at least)
2010-11-16 23:34:31 +03:00
pref . setWebUiPassword ( webUiPassword ( ) ) ;
2010-10-09 19:36:39 +04:00
}
// End Web UI
// End preferences
// Save advanced settings
advancedSettings - > saveAdvancedSettings ( ) ;
}
bool options_imp : : isFilteringEnabled ( ) const {
return checkIPFilter - > isChecked ( ) ;
}
2010-11-18 23:05:56 +03: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 :
2010-11-18 23:05:56 +03: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 :
2010-11-18 23:05:56 +03: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
2010-10-09 19:36:39 +04:00
void options_imp : : loadOptions ( ) {
int intValue ;
2011-01-25 20:01:09 +03:00
qreal floatValue ;
2010-10-09 19:36:39 +04:00
QString strValue ;
// General preferences
2010-11-16 23:34:31 +03:00
const Preferences pref ;
setLocale ( pref . getLocale ( ) ) ;
checkAltRowColors - > setChecked ( pref . useAlternatingRowColors ( ) ) ;
checkShowSystray - > setChecked ( pref . systrayIntegration ( ) ) ;
checkShowSplash - > setChecked ( ! pref . isSlashScreenDisabled ( ) ) ;
2010-10-09 19:36:39 +04:00
if ( ! checkShowSystray - > isChecked ( ) ) {
disableSystrayOptions ( ) ;
} else {
enableSystrayOptions ( ) ;
2010-11-16 23:34:31 +03:00
checkCloseToSystray - > setChecked ( pref . closeToTray ( ) ) ;
checkMinimizeToSysTray - > setChecked ( pref . minimizeToTray ( ) ) ;
checkStartMinimized - > setChecked ( pref . startMinimized ( ) ) ;
2010-10-09 19:36:39 +04:00
}
2011-02-06 17:27:34 +03:00
checkPreventFromSuspend - > setChecked ( pref . preventFromSuspend ( ) ) ;
2010-10-09 19:36:39 +04:00
// End General preferences
// Downloads preferences
2010-11-16 23:34:31 +03:00
QString save_path = pref . getSavePath ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
save_path = save_path . replace ( " / " , " \\ " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-10-09 19:36:39 +04:00
textSavePath - > setText ( save_path ) ;
2010-11-16 23:34:31 +03:00
if ( pref . isTempPathEnabled ( ) ) {
2010-10-09 19:36:39 +04:00
// enable
checkTempFolder - > setChecked ( true ) ;
} else {
checkTempFolder - > setChecked ( false ) ;
}
2010-11-16 23:34:31 +03:00
QString temp_path = pref . getTempPath ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
temp_path = temp_path . replace ( " / " , " \\ " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-10-09 19:36:39 +04:00
textTempPath - > setText ( temp_path ) ;
2010-11-16 23:34:31 +03:00
checkAppendLabel - > setChecked ( pref . appendTorrentLabel ( ) ) ;
2010-06-07 12:32:41 +04:00
# if LIBTORRENT_VERSION_MINOR > 14
2010-11-16 23:34:31 +03:00
checkAppendqB - > setChecked ( pref . useIncompleteFilesExtension ( ) ) ;
2009-12-18 16:36:47 +03:00
# endif
2010-11-16 23:34:31 +03:00
checkPreallocateAll - > setChecked ( pref . preAllocateAllFiles ( ) ) ;
checkAdditionDialog - > setChecked ( pref . useAdditionDialog ( ) ) ;
checkStartPaused - > setChecked ( pref . addTorrentsInPause ( ) ) ;
2010-10-09 19:36:39 +04:00
2010-11-16 23:34:31 +03:00
strValue = pref . getExportDir ( ) ;
2010-10-09 19:36:39 +04:00
if ( strValue . isEmpty ( ) ) {
// Disable
checkExportDir - > setChecked ( false ) ;
} else {
// enable
checkExportDir - > setChecked ( true ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
strValue = strValue . replace ( " / " , " \\ " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-10-09 19:36:39 +04:00
textExportDir - > setText ( strValue ) ;
}
2010-11-16 23:34:31 +03:00
groupMailNotification - > setChecked ( pref . isMailNotificationEnabled ( ) ) ;
dest_email_txt - > setText ( pref . getMailNotificationEmail ( ) ) ;
smtp_server_txt - > setText ( pref . getMailNotificationSMTP ( ) ) ;
autoRunBox - > setChecked ( pref . isAutoRunEnabled ( ) ) ;
autoRun_txt - > setText ( pref . getAutoRunProgram ( ) ) ;
intValue = pref . getActionOnDblClOnTorrentDl ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue > = actionTorrentDlOnDblClBox - > count ( ) )
intValue = 0 ;
actionTorrentDlOnDblClBox - > setCurrentIndex ( intValue ) ;
2010-11-16 23:34:31 +03:00
intValue = pref . getActionOnDblClOnTorrentFn ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue > = actionTorrentFnOnDblClBox - > count ( ) )
intValue = 1 ;
actionTorrentFnOnDblClBox - > setCurrentIndex ( intValue ) ;
// End Downloads preferences
// Connection preferences
2010-11-16 23:34:31 +03:00
spinPort - > setValue ( pref . getSessionPort ( ) ) ;
checkUPnP - > setChecked ( pref . isUPnPEnabled ( ) ) ;
intValue = pref . getGlobalDownloadLimit ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue > 0 ) {
// Enabled
checkDownloadLimit - > setChecked ( true ) ;
spinDownloadLimit - > setEnabled ( true ) ;
spinDownloadLimit - > setValue ( intValue ) ;
} else {
// Disabled
checkDownloadLimit - > setChecked ( false ) ;
spinDownloadLimit - > setEnabled ( false ) ;
}
2010-11-16 23:34:31 +03:00
intValue = pref . getGlobalUploadLimit ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue ! = - 1 ) {
// Enabled
checkUploadLimit - > setChecked ( true ) ;
spinUploadLimit - > setEnabled ( true ) ;
spinUploadLimit - > setValue ( intValue ) ;
} else {
// Disabled
checkUploadLimit - > setChecked ( false ) ;
spinUploadLimit - > setEnabled ( false ) ;
}
2010-11-16 23:34:31 +03:00
spinUploadLimitAlt - > setValue ( pref . getAltGlobalUploadLimit ( ) ) ;
spinDownloadLimitAlt - > setValue ( pref . getAltGlobalDownloadLimit ( ) ) ;
2010-10-09 19:36:39 +04:00
// Scheduler
2010-11-16 23:34:31 +03: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
2010-11-18 23:05:56 +03: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 ( ) ) ;
2010-10-09 19:36:39 +04:00
//if(isProxyEnabled()) {
// Proxy is enabled, save settings
2010-11-18 23:05:56 +03:00
textProxyIP - > setText ( pref . getProxyIp ( ) ) ;
spinProxyPort - > setValue ( pref . getProxyPort ( ) ) ;
checkProxyAuth - > setChecked ( pref . isProxyAuthEnabled ( ) ) ;
textProxyUsername - > setText ( pref . getProxyUsername ( ) ) ;
textProxyPassword - > setText ( pref . getProxyPassword ( ) ) ;
enableProxyAuth ( checkProxyAuth - > isChecked ( ) ) ;
2010-10-09 19:36:39 +04:00
//}
// End Connection preferences
// Bittorrent preferences
2010-11-16 23:34:31 +03:00
intValue = pref . getMaxConnecs ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue > 0 ) {
// enable
checkMaxConnecs - > setChecked ( true ) ;
spinMaxConnec - > setEnabled ( true ) ;
spinMaxConnec - > setValue ( intValue ) ;
} else {
// disable
checkMaxConnecs - > setChecked ( false ) ;
spinMaxConnec - > setEnabled ( false ) ;
}
2010-11-16 23:34:31 +03:00
intValue = pref . getMaxConnecsPerTorrent ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue > 0 ) {
// enable
checkMaxConnecsPerTorrent - > setChecked ( true ) ;
spinMaxConnecPerTorrent - > setEnabled ( true ) ;
spinMaxConnecPerTorrent - > setValue ( intValue ) ;
} else {
// disable
checkMaxConnecsPerTorrent - > setChecked ( false ) ;
spinMaxConnecPerTorrent - > setEnabled ( false ) ;
}
2010-11-16 23:34:31 +03:00
intValue = pref . getMaxUploadsPerTorrent ( ) ;
2010-10-09 19:36:39 +04:00
if ( intValue > 0 ) {
// enable
checkMaxUploadsPerTorrent - > setChecked ( true ) ;
spinMaxUploadsPerTorrent - > setEnabled ( true ) ;
spinMaxUploadsPerTorrent - > setValue ( intValue ) ;
} else {
// disable
checkMaxUploadsPerTorrent - > setChecked ( false ) ;
spinMaxUploadsPerTorrent - > setEnabled ( false ) ;
}
2010-11-16 23:34:31 +03:00
checkDHT - > setChecked ( pref . isDHTEnabled ( ) ) ;
checkDifferentDHTPort - > setChecked ( ! pref . isDHTPortSameAsBT ( ) ) ;
spinDHTPort - > setValue ( pref . getDHTPort ( ) ) ;
checkPeX - > setChecked ( pref . isPeXEnabled ( ) ) ;
checkLSD - > setChecked ( pref . isLSDEnabled ( ) ) ;
comboEncryption - > setCurrentIndex ( pref . getEncryptionSetting ( ) ) ;
2010-10-09 19:36:39 +04:00
// Ratio limit
2010-11-16 23:34:31 +03:00
floatValue = pref . getMaxRatio ( ) ;
2010-10-09 19:36:39 +04:00
if ( floatValue > = 0. ) {
// Enable
checkMaxRatio - > setChecked ( true ) ;
spinMaxRatio - > setEnabled ( true ) ;
comboRatioLimitAct - > setEnabled ( true ) ;
spinMaxRatio - > setValue ( floatValue ) ;
} else {
// Disable
checkMaxRatio - > setChecked ( false ) ;
spinMaxRatio - > setEnabled ( false ) ;
comboRatioLimitAct - > setEnabled ( false ) ;
}
2010-11-16 23:34:31 +03:00
comboRatioLimitAct - > setCurrentIndex ( pref . getMaxRatioAction ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Bittorrent preferences
// Misc preferences
// * IP Filter
2010-11-16 23:34:31 +03:00
checkIPFilter - > setChecked ( pref . isFilteringEnabled ( ) ) ;
textFilterPath - > setText ( pref . getFilter ( ) ) ;
2010-10-09 19:36:39 +04:00
// End IP Filter
// Queueing system preferences
2010-11-16 23:34:31 +03:00
checkEnableQueueing - > setChecked ( pref . isQueueingSystemEnabled ( ) ) ;
spinMaxActiveDownloads - > setValue ( pref . getMaxActiveDownloads ( ) ) ;
spinMaxActiveUploads - > setValue ( pref . getMaxActiveUploads ( ) ) ;
spinMaxActiveTorrents - > setValue ( pref . getMaxActiveTorrents ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Queueing system preferences
// Web UI
2010-11-16 23:34:31 +03:00
checkWebUi - > setChecked ( pref . isWebUiEnabled ( ) ) ;
spinWebUiPort - > setValue ( pref . getWebUiPort ( ) ) ;
textWebUiUsername - > setText ( pref . getWebUiUsername ( ) ) ;
textWebUiPassword - > setText ( pref . getWebUiPassword ( ) ) ;
2010-10-09 19:36:39 +04:00
// End Web UI
// Random stuff
srand ( time ( 0 ) ) ;
}
// return min & max ports
// [min, max]
int options_imp : : getPort ( ) const {
return spinPort - > value ( ) ;
}
void options_imp : : on_randomButton_clicked ( ) {
// Range [1024: 65535]
spinPort - > setValue ( rand ( ) % 64512 + 1024 ) ;
}
int options_imp : : getEncryptionSetting ( ) const {
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 ( ) ;
}
bool options_imp : : minimizeToTray ( ) const {
if ( ! checkShowSystray - > isChecked ( ) ) return false ;
return checkMinimizeToSysTray - > isChecked ( ) ;
}
bool options_imp : : closeToTray ( ) const {
if ( ! checkShowSystray - > isChecked ( ) ) return false ;
return checkCloseToSystray - > isChecked ( ) ;
}
bool options_imp : : isQueueingSystemEnabled ( ) const {
return checkEnableQueueing - > isChecked ( ) ;
}
bool options_imp : : isDHTEnabled ( ) const {
return checkDHT - > isChecked ( ) ;
}
bool options_imp : : isLSDEnabled ( ) const {
return checkLSD - > isChecked ( ) ;
}
bool options_imp : : isUPnPEnabled ( ) const {
return checkUPnP - > isChecked ( ) ;
}
// Return Download & Upload limits in kbps
// [download,upload]
QPair < int , int > options_imp : : getGlobalBandwidthLimits ( ) const {
int DL = - 1 , UP = - 1 ;
if ( checkDownloadLimit - > isChecked ( ) ) {
DL = spinDownloadLimit - > value ( ) ;
}
if ( checkUploadLimit - > isChecked ( ) ) {
UP = spinUploadLimit - > value ( ) ;
}
return qMakePair ( DL , UP ) ;
}
bool options_imp : : startMinimized ( ) const {
if ( checkStartMinimized - > isChecked ( ) ) return true ;
return checkStartMinimized - > isChecked ( ) ;
}
bool options_imp : : systrayIntegration ( ) const {
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) return false ;
return checkShowSystray - > isChecked ( ) ;
}
int options_imp : : getDHTPort ( ) const {
return spinDHTPort - > value ( ) ;
}
// Return Share ratio
2011-01-25 20:01:09 +03:00
qreal options_imp : : getMaxRatio ( ) const {
2010-10-09 19:36:39 +04:00
if ( checkMaxRatio - > isChecked ( ) ) {
return spinMaxRatio - > value ( ) ;
}
return - 1 ;
}
// Return Save Path
QString options_imp : : getSavePath ( ) const {
if ( textSavePath - > text ( ) . trimmed ( ) . isEmpty ( ) ) {
2010-11-16 23:34:31 +03:00
QString save_path = Preferences ( ) . getSavePath ( ) ;
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
save_path = save_path . replace ( " / " , " \\ " ) ;
2009-01-04 22:37:55 +03:00
# endif
2010-10-09 19:36:39 +04:00
textSavePath - > setText ( save_path ) ;
2006-09-30 20:02:39 +04:00
}
2010-10-09 19:36:39 +04:00
return misc : : expandPath ( textSavePath - > text ( ) ) ;
}
2006-09-30 20:02:39 +04:00
2010-10-09 19:36:39 +04:00
QString options_imp : : getTempPath ( ) const {
return misc : : expandPath ( textTempPath - > text ( ) ) ;
}
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
int options_imp : : getMaxConnecs ( ) const {
if ( ! checkMaxConnecs - > isChecked ( ) ) {
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
2010-10-09 19:36:39 +04:00
int options_imp : : getMaxConnecsPerTorrent ( ) const {
if ( ! checkMaxConnecsPerTorrent - > isChecked ( ) ) {
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
2010-10-09 19:36:39 +04:00
int options_imp : : getMaxUploadsPerTorrent ( ) const {
if ( ! checkMaxUploadsPerTorrent - > isChecked ( ) ) {
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
2010-10-09 19:36:39 +04:00
void options_imp : : on_buttonBox_accepted ( ) {
if ( applyButton - > isEnabled ( ) ) {
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 ) {
if ( button = = applyButton ) {
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
2010-10-09 19:36:39 +04:00
void options_imp : : closeEvent ( QCloseEvent * e ) {
setAttribute ( Qt : : WA_DeleteOnClose ) ;
e - > accept ( ) ;
}
2010-06-21 23:20:58 +04:00
2010-10-09 19:36:39 +04:00
void options_imp : : on_buttonBox_rejected ( ) {
setAttribute ( Qt : : WA_DeleteOnClose ) ;
reject ( ) ;
}
void options_imp : : enableDownloadLimit ( bool checked ) {
if ( checked ) {
spinDownloadLimit - > setEnabled ( true ) ;
} else {
spinDownloadLimit - > setEnabled ( false ) ;
}
}
bool options_imp : : useAdditionDialog ( ) const {
return checkAdditionDialog - > isChecked ( ) ;
}
void options_imp : : enableMaxConnecsLimit ( bool checked ) {
spinMaxConnec - > setEnabled ( checked ) ;
}
void options_imp : : enableMaxConnecsLimitPerTorrent ( bool checked ) {
spinMaxConnecPerTorrent - > setEnabled ( checked ) ;
}
void options_imp : : enableSystrayOptions ( ) {
checkCloseToSystray - > setEnabled ( true ) ;
checkMinimizeToSysTray - > setEnabled ( true ) ;
}
void options_imp : : disableSystrayOptions ( ) {
checkCloseToSystray - > setEnabled ( false ) ;
checkMinimizeToSysTray - > setEnabled ( false ) ;
}
void options_imp : : setSystrayOptionsState ( bool checked ) {
if ( checked ) {
enableSystrayOptions ( ) ;
} else {
disableSystrayOptions ( ) ;
}
}
void options_imp : : enableMaxUploadsLimitPerTorrent ( bool checked ) {
if ( checked ) {
spinMaxUploadsPerTorrent - > setEnabled ( true ) ;
} else {
spinMaxUploadsPerTorrent - > setEnabled ( false ) ;
}
}
void options_imp : : enableUploadLimit ( bool checked ) {
spinUploadLimit - > setEnabled ( checked ) ;
}
void options_imp : : enableApplyButton ( ) {
applyButton - > setEnabled ( true ) ;
}
void options_imp : : enableMaxRatio ( bool checked ) {
spinMaxRatio - > setEnabled ( checked ) ;
comboRatioLimitAct - > setEnabled ( checked ) ;
}
2010-11-18 23:05:56 +03:00
void options_imp : : enableProxy ( int index ) {
2010-10-09 19:36:39 +04:00
if ( index ) {
//enable
lblProxyIP - > setEnabled ( true ) ;
textProxyIP - > setEnabled ( true ) ;
lblProxyPort - > setEnabled ( true ) ;
spinProxyPort - > setEnabled ( true ) ;
if ( index > 1 ) {
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 ) ;
checkProxyAuth - > setEnabled ( false ) ;
checkProxyAuth - > setChecked ( false ) ;
}
}
2010-11-18 23:05:56 +03:00
void options_imp : : enableProxyAuth ( bool checked ) {
2010-10-09 19:36:39 +04:00
lblProxyUsername - > setEnabled ( checked ) ;
lblProxyPassword - > setEnabled ( checked ) ;
textProxyUsername - > setEnabled ( checked ) ;
textProxyPassword - > setEnabled ( checked ) ;
}
bool options_imp : : isSlashScreenDisabled ( ) const {
return ! checkShowSplash - > isChecked ( ) ;
}
2011-02-06 17:27:34 +03:00
bool options_imp : : preventFromSuspend ( ) const {
return checkPreventFromSuspend - > isChecked ( ) ;
}
2010-10-09 19:36:39 +04:00
bool options_imp : : preAllocateAllFiles ( ) const {
return checkPreallocateAll - > isChecked ( ) ;
}
bool options_imp : : addTorrentsInPause ( ) const {
return checkStartPaused - > isChecked ( ) ;
}
bool options_imp : : isDHTPortSameAsBT ( ) const {
return ! checkDifferentDHTPort - > isChecked ( ) ;
}
// Proxy settings
2010-11-18 23:05:56 +03:00
bool options_imp : : isProxyEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return comboProxyType - > currentIndex ( ) ;
}
2010-11-18 23:05:56 +03:00
bool options_imp : : isProxyAuthEnabled ( ) const {
2010-10-09 19:36:39 +04:00
return checkProxyAuth - > isChecked ( ) ;
}
2010-11-18 23:05:56 +03:00
QString options_imp : : getProxyIp ( ) const {
2010-10-09 19:36:39 +04:00
QString ip = textProxyIP - > text ( ) ;
ip = ip . trimmed ( ) ;
return ip ;
}
2010-11-18 23:05:56 +03:00
unsigned short options_imp : : getProxyPort ( ) const {
2010-10-09 19:36:39 +04:00
return spinProxyPort - > value ( ) ;
}
2010-11-18 23:05:56 +03:00
QString options_imp : : getProxyUsername ( ) const {
2010-10-09 19:36:39 +04:00
QString username = textProxyUsername - > text ( ) ;
username = username . trimmed ( ) ;
return username ;
}
2010-11-18 23:05:56 +03: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
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
}
2010-11-20 18:59:17 +03:00
void options_imp : : setLocale ( QString localeStr ) {
QLocale locale ( localeStr ) ;
// Attempt to find exact match
int index = comboI18n - > findData ( locale . name ( ) , Qt : : UserRole ) ;
if ( index < 0 ) {
// Unreconized, use US English
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
}
QString options_imp : : getExportDir ( ) const {
if ( checkExportDir - > isChecked ( ) ) {
return misc : : expandPath ( textExportDir - > text ( ) ) ;
} else {
return QString : : null ;
}
}
// Return action on double-click on a downloading torrent set in options
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 {
if ( actionTorrentFnOnDblClBox - > currentIndex ( ) < 1 )
return 0 ;
return actionTorrentFnOnDblClBox - > currentIndex ( ) ;
}
void options_imp : : on_addScanFolderButton_clicked ( ) {
const QString dir = QFileDialog : : getExistingDirectory ( this , tr ( " Add directory to scan " ) ) ;
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 :
addedScanDirs < < dir ;
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 ( ) ) ;
}
void options_imp : : on_browseExportDirButton_clicked ( ) {
QString export_path = misc : : expandPath ( textExportDir - > text ( ) ) ;
QDir exportDir ( export_path ) ;
QString dir ;
if ( ! export_path . isEmpty ( ) & & exportDir . exists ( ) ) {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose export directory " ) , exportDir . absolutePath ( ) ) ;
} else {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose export directory " ) , QDir : : homePath ( ) ) ;
}
if ( ! dir . isNull ( ) ) {
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
dir = dir . replace ( " / " , " \\ " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-10-09 19:36:39 +04:00
textExportDir - > setText ( dir ) ;
2006-09-30 20:02:39 +04:00
}
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 ( ) {
QString filter_path = misc : : expandPath ( textFilterPath - > text ( ) ) ;
QDir filterDir ( filter_path ) ;
QString ipfilter ;
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 {
ipfilter = QFileDialog : : getOpenFileName ( this , tr ( " Choose an ip filter file " ) , QDir : : homePath ( ) , tr ( " Filters " ) + QString ( " (*.dat *.p2p *.p2b) " ) ) ;
}
if ( ! ipfilter . isNull ( ) ) {
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
ipfilter = ipfilter . replace ( " / " , " \\ " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-10-09 19:36:39 +04:00
textFilterPath - > setText ( ipfilter ) ;
2006-09-30 20:02:39 +04:00
}
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
void options_imp : : on_browseSaveDirButton_clicked ( ) {
QString save_path = misc : : expandPath ( textSavePath - > text ( ) ) ;
QDir saveDir ( save_path ) ;
QString dir ;
if ( ! save_path . isEmpty ( ) & & saveDir . exists ( ) ) {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , saveDir . absolutePath ( ) ) ;
} else {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , QDir : : homePath ( ) ) ;
}
if ( ! dir . isNull ( ) ) {
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
dir = dir . replace ( " / " , " \\ " ) ;
2010-06-21 23:20:58 +04:00
# endif
2010-10-09 19:36:39 +04:00
textSavePath - > setText ( dir ) ;
2009-12-22 13:29:39 +03:00
}
2010-10-09 19:36:39 +04:00
}
2010-06-21 23:20:58 +04:00
2010-10-09 19:36:39 +04:00
void options_imp : : on_browseTempDirButton_clicked ( ) {
QString temp_path = misc : : expandPath ( textTempPath - > text ( ) ) ;
QDir tempDir ( temp_path ) ;
QString dir ;
if ( ! temp_path . isEmpty ( ) & & tempDir . exists ( ) ) {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , tempDir . absolutePath ( ) ) ;
} else {
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose a save directory " ) , QDir : : homePath ( ) ) ;
}
if ( ! dir . isNull ( ) ) {
2010-06-22 23:17:47 +04:00
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
2010-10-09 19:36:39 +04:00
dir = dir . replace ( " / " , " \\ " ) ;
2010-06-04 01:08:28 +04:00
# endif
2010-10-09 19:36:39 +04:00
textTempPath - > setText ( dir ) ;
2009-12-19 23:39:38 +03:00
}
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
QString options_imp : : getFilter ( ) const {
return textFilterPath - > text ( ) ;
}
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 ( )
{
tabSelection - > setCurrentRow ( 2 ) ;
}
2010-11-20 18:59:17 +03:00
2010-12-25 17:47:52 +03:00
void options_imp : : on_IpFilterRefreshBtn_clicked ( ) {
if ( m_refreshingIpFilter ) return ;
m_refreshingIpFilter = true ;
// Updating program preferences
Preferences pref ;
pref . setFilteringEnabled ( true ) ;
pref . setFilter ( getFilter ( ) ) ;
// 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 ) ) ;
if ( error ) {
QMessageBox : : warning ( this , tr ( " Parsing error " ) , tr ( " Failed to parse the provided IP filter " ) ) ;
} else {
2011-01-12 23:10:10 +03:00
QMessageBox : : information ( this , tr ( " Successfully refreshed " ) , tr ( " Successfuly 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
QString options_imp : : languageToLocalizedString ( QLocale : : Language language , const QString & country )
{
switch ( language ) {
case QLocale : : English : return " English " ;
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 : {
if ( country = = " br " )
return QString : : fromUtf8 ( " Português brasileiro " ) ;
return QString : : fromUtf8 ( " Português " ) ;
}
case QLocale : : Polish : return QString : : fromUtf8 ( " Polski " ) ;
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 ( " 日本語 " ) ;
case QLocale : : Arabic : return QString : : fromUtf8 ( " عربي " ) ;
case QLocale : : Chinese : {
if ( country = = " cn " )
return QString : : fromUtf8 ( " 中文 (简体) " ) ;
return QString : : fromUtf8 ( " 中文 (繁體) " ) ;
}
case QLocale : : Korean : return QString : : fromUtf8 ( " 한글 " ) ;
default : {
// Fallback to English
const QString eng_lang = QLocale : : languageToString ( language ) ;
qWarning ( ) < < " Unrecognized language name: " < < eng_lang ;
return eng_lang ;
}
}
}