Browse Source

- Split Preferences from the GUI so that Options dialog does not need to be created on startup to retrieve the preferences:

* This speeds up startup
  * Bittorrent session settings are now applied at bittorrent class level (Required for headless running)
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
51ebfadd85
  1. 1
      Changelog
  2. 305
      src/GUI.cpp
  3. 3
      src/GUI.h
  4. 229
      src/bittorrent.cpp
  5. 1
      src/bittorrent.h
  6. 33
      src/options.ui
  7. 620
      src/options_imp.cpp
  8. 50
      src/options_imp.h
  9. 406
      src/preferences.h
  10. 3
      src/src.pro

1
Changelog

@ -17,6 +17,7 @@
- FEATURE: Display more information regarding the torrent in its properties - FEATURE: Display more information regarding the torrent in its properties
- FEATURE: Various optimizations to save CPU and memory - FEATURE: Various optimizations to save CPU and memory
- FEATURE: Folder scanning now works with CIFS and NFS mounted folders - FEATURE: Folder scanning now works with CIFS and NFS mounted folders
- FEATURE: Speed up qBittorrent startup
- COSMETIC: Merged download / upload lists - COSMETIC: Merged download / upload lists
- COSMETIC: Torrents can be filtered based on their status - COSMETIC: Torrents can be filtered based on their status
- COSMETIC: Torrent properties are now displayed in main window - COSMETIC: Torrent properties are now displayed in main window

305
src/GUI.cpp

@ -59,6 +59,7 @@
#include "trackerLogin.h" #include "trackerLogin.h"
#include "options_imp.h" #include "options_imp.h"
#include "allocationDlg.h" #include "allocationDlg.h"
#include "preferences.h"
#include <stdlib.h> #include <stdlib.h>
#include "console_imp.h" #include "console_imp.h"
#include "httpserver.h" #include "httpserver.h"
@ -126,9 +127,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
actionCreate_torrent->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/new.png"))); actionCreate_torrent->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/new.png")));
// Fix Tool bar layout // Fix Tool bar layout
toolBar->layout()->setSpacing(7); toolBar->layout()->setSpacing(7);
// creating options // Creating Bittorrent session
options = new options_imp(this);
connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool)));
BTSession = new bittorrent(); BTSession = new bittorrent();
connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&, QString)), this, SLOT(fullDiskError(QTorrentHandle&, QString))); connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&, QString)), this, SLOT(fullDiskError(QTorrentHandle&, QString)));
connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&))); connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&)));
@ -174,7 +173,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
rssWidget = 0; rssWidget = 0;
// Configure BT session according to options // Configure BT session according to options
configureSession(true); loadPreferences(false);
// Resume unfinished torrents // Resume unfinished torrents
BTSession->startUpTorrents(); BTSession->startUpTorrents();
// FIXME: Sorting // FIXME: Sorting
@ -765,95 +764,49 @@ void GUI::processDownloadedFiles(QString path, QString url) {
} }
} }
// Set BT session configuration // Load program preferences
void GUI::configureSession(bool deleteOptions) { void GUI::loadPreferences(bool configure_session) {
qDebug("Configuring session"); BTSession->addConsoleMessage(tr("Options were saved successfully."));
bool newSystrayIntegration = Preferences::systrayIntegration();
if(newSystrayIntegration != systrayIntegration) {
if(newSystrayIntegration) {
// create the trayicon
createTrayIcon();
} else {
// Destroy trayicon
delete myTrayIcon;
delete myTrayIconMenu;
}
systrayIntegration = newSystrayIntegration;
}
// XXX: Should probably be done in bittorrent, not here
// Update Web UI
if (Preferences::isWebUiEnabled()) {
quint16 port = Preferences::getWebUiPort();
QString username = Preferences::getWebUiUsername();
QString password = Preferences::getWebUiPassword();
initWebUi(username, password, port);
} else if(httpServer) {
delete httpServer;
}
// General // General
bool new_displaySpeedInTitle = options->speedInTitleBar(); bool new_displaySpeedInTitle = Preferences::speedInTitleBar();
if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) { if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) {
// Reset title // Reset title
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION))); setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
} }
displaySpeedInTitle = new_displaySpeedInTitle; displaySpeedInTitle = new_displaySpeedInTitle;
if(options->isToolbarDisplayed()) { if(Preferences::isToolbarDisplayed()) {
toolBar->setVisible(true); toolBar->setVisible(true);
toolBar->layout()->setSpacing(7); toolBar->layout()->setSpacing(7);
} else { } else {
toolBar->setVisible(false); toolBar->setVisible(false);
} }
unsigned int new_refreshInterval = options->getRefreshInterval(); unsigned int new_refreshInterval = Preferences::getRefreshInterval();
transferList->setRefreshInterval(new_refreshInterval); transferList->setRefreshInterval(new_refreshInterval);
// Downloads
// * Save path
BTSession->setDefaultSavePath(options->getSavePath());
if(options->isTempPathEnabled()) {
BTSession->setDefaultTempPath(options->getTempPath());
} else {
BTSession->setDefaultTempPath(QString::null);
}
BTSession->preAllocateAllFiles(options->preAllocateAllFiles());
BTSession->startTorrentsInPause(options->addTorrentsInPause());
// * Scan dir
if(options->getScanDir().isNull()) {
BTSession->disableDirectoryScanning();
}else{
//Interval first
BTSession->enableDirectoryScanning(options->getScanDir());
}
// Connection
// * Ports binding
unsigned short old_listenPort = BTSession->getListenPort();
BTSession->setListeningPort(options->getPort());
unsigned short new_listenPort = BTSession->getListenPort();
if(new_listenPort != old_listenPort) {
BTSession->addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg( misc::toQString(new_listenPort)));
}
// * Global download limit
QPair<int, int> limits = options->getGlobalBandwidthLimits();
if(limits.first <= 0) {
// Download limit disabled
BTSession->setDownloadRateLimit(-1);
} else {
// Enabled
BTSession->setDownloadRateLimit(limits.first*1024);
}
// * Global Upload limit
if(limits.second <= 0) {
// Upload limit disabled
BTSession->setUploadRateLimit(-1);
} else {
// Enabled
BTSession->setUploadRateLimit(limits.second*1024);
}
// * UPnP
if(options->isUPnPEnabled()) {
BTSession->enableUPnP(true);
BTSession->addConsoleMessage(tr("UPnP support [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableUPnP(false);
BTSession->addConsoleMessage(tr("UPnP support [OFF]"), QString::fromUtf8("blue"));
}
// * NAT-PMP
if(options->isNATPMPEnabled()) {
BTSession->enableNATPMP(true);
BTSession->addConsoleMessage(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableNATPMP(false);
BTSession->addConsoleMessage(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
}
// * Session settings
session_settings sessionSettings;
if(options->shouldSpoofAzureus()) {
sessionSettings.user_agent = "Azureus 3.0.5.2";
} else {
sessionSettings.user_agent = "qBittorrent "VERSION;
}
sessionSettings.upnp_ignore_nonrouters = true;
sessionSettings.use_dht_as_fallback = false;
// To keep same behavior as in qbittorrent v1.2.0
sessionSettings.rate_limit_ip_overhead = false;
// Queueing System // Queueing System
if(options->isQueueingSystemEnabled()) { if(Preferences::isQueueingSystemEnabled()) {
if(!BTSession->isQueueingEnabled()) { if(!BTSession->isQueueingEnabled()) {
transferList->hidePriorityColumn(false); transferList->hidePriorityColumn(false);
actionDecreasePriority->setVisible(true); actionDecreasePriority->setVisible(true);
@ -862,20 +815,8 @@ void GUI::configureSession(bool deleteOptions) {
prioSeparator2->setVisible(true); prioSeparator2->setVisible(true);
toolBar->layout()->setSpacing(7); toolBar->layout()->setSpacing(7);
} }
int max_torrents = options->getMaxActiveTorrents();
int max_uploads = options->getMaxActiveUploads();
int max_downloads = options->getMaxActiveDownloads();
sessionSettings.active_downloads = max_downloads;
sessionSettings.active_seeds = max_uploads;
sessionSettings.active_limit = max_torrents;
sessionSettings.dont_count_slow_torrents = false;
BTSession->setQueueingEnabled(true);
} else { } else {
if(BTSession->isQueueingEnabled()) { if(BTSession->isQueueingEnabled()) {
sessionSettings.active_downloads = -1;
sessionSettings.active_seeds = -1;
sessionSettings.active_limit = -1;
BTSession->setQueueingEnabled(false);
transferList->hidePriorityColumn(true); transferList->hidePriorityColumn(true);
actionDecreasePriority->setVisible(false); actionDecreasePriority->setVisible(false);
actionIncreasePriority->setVisible(false); actionIncreasePriority->setVisible(false);
@ -884,153 +825,18 @@ void GUI::configureSession(bool deleteOptions) {
toolBar->layout()->setSpacing(7); toolBar->layout()->setSpacing(7);
} }
} }
BTSession->setSessionSettings(sessionSettings);
// Bittorrent
// * Max connections limit
BTSession->setMaxConnections(options->getMaxConnecs());
// * Max connections per torrent limit
BTSession->setMaxConnectionsPerTorrent(options->getMaxConnecsPerTorrent());
// * Max uploads per torrent limit
BTSession->setMaxUploadsPerTorrent(options->getMaxUploadsPerTorrent());
// * DHT
if(options->isDHTEnabled()) {
// Set DHT Port
BTSession->setDHTPort(options->getDHTPort());
if(BTSession->enableDHT(true)) {
int dht_port = new_listenPort;
if(options->getDHTPort())
dht_port = options->getDHTPort();
BTSession->addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue"));
} else {
BTSession->addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("red"));
}
} else {
BTSession->enableDHT(false);
BTSession->addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
}
// * PeX
BTSession->addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue"));
// * LSD
if(options->isLSDEnabled()) {
BTSession->enableLSD(true);
BTSession->addConsoleMessage(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableLSD(false);
BTSession->addConsoleMessage(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
}
// * Encryption
int encryptionState = options->getEncryptionSetting();
// The most secure, rc4 only so that all streams and encrypted
pe_settings encryptionSettings;
encryptionSettings.allowed_enc_level = pe_settings::rc4;
encryptionSettings.prefer_rc4 = true;
switch(encryptionState) {
case 0: //Enabled
encryptionSettings.out_enc_policy = pe_settings::enabled;
encryptionSettings.in_enc_policy = pe_settings::enabled;
BTSession->addConsoleMessage(tr("Encryption support [ON]"), QString::fromUtf8("blue"));
break;
case 1: // Forced
encryptionSettings.out_enc_policy = pe_settings::forced;
encryptionSettings.in_enc_policy = pe_settings::forced;
BTSession->addConsoleMessage(tr("Encryption support [FORCED]"), QString::fromUtf8("blue"));
break;
default: // Disabled
encryptionSettings.out_enc_policy = pe_settings::disabled;
encryptionSettings.in_enc_policy = pe_settings::disabled;
BTSession->addConsoleMessage(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
}
BTSession->applyEncryptionSettings(encryptionSettings);
// * Desired ratio
BTSession->setGlobalRatio(options->getDesiredRatio());
// * Maximum ratio
BTSession->setDeleteRatio(options->getDeleteRatio());
// Ip Filter
if(options->isFilteringEnabled()) {
BTSession->enableIPFilter(options->getFilter());
}else{
BTSession->disableIPFilter();
}
// RSS // RSS
if(options->isRSSEnabled()) { if(Preferences::isRSSEnabled()) {
displayRSSTab(true); displayRSSTab(true);
} else { } else {
displayRSSTab(false); displayRSSTab(false);
} }
// * Proxy settings
proxy_settings proxySettings; if(configure_session)
if(options->isProxyEnabled()) { BTSession->configureSession();
qDebug("Enabling P2P proxy");
proxySettings.hostname = options->getProxyIp().toStdString(); qDebug("GUI settings loaded");
qDebug("hostname is %s", proxySettings.hostname.c_str());
proxySettings.port = options->getProxyPort();
qDebug("port is %d", proxySettings.port);
if(options->isProxyAuthEnabled()) {
proxySettings.username = options->getProxyUsername().toStdString();
proxySettings.password = options->getProxyPassword().toStdString();
qDebug("username is %s", proxySettings.username.c_str());
qDebug("password is %s", proxySettings.password.c_str());
}
switch(options->getProxyType()) {
case HTTP:
qDebug("type: http");
proxySettings.type = proxy_settings::http;
break;
case HTTP_PW:
qDebug("type: http_pw");
proxySettings.type = proxy_settings::http_pw;
break;
case SOCKS5:
qDebug("type: socks5");
proxySettings.type = proxy_settings::socks5;
break;
default:
qDebug("type: socks5_pw");
proxySettings.type = proxy_settings::socks5_pw;
break;
}
qDebug("booleans: %d %d %d %d", options->useProxyForTrackers(), options->useProxyForPeers(), options->useProxyForWebseeds(), options->useProxyForDHT());
BTSession->setProxySettings(proxySettings, options->useProxyForTrackers(), options->useProxyForPeers(), options->useProxyForWebseeds(), options->useProxyForDHT());
} else {
qDebug("Disabling P2P proxy");
BTSession->setProxySettings(proxySettings, false, false, false, false);
}
if(options->isHTTPProxyEnabled()) {
qDebug("Enabling Search HTTP proxy");
// HTTP Proxy
QString proxy_str;
switch(options->getHTTPProxyType()) {
case HTTP_PW:
proxy_str = misc::toQString("http://")+options->getHTTPProxyUsername()+":"+options->getHTTPProxyPassword()+"@"+options->getHTTPProxyIp()+":"+misc::toQString(options->getHTTPProxyPort());
break;
default:
proxy_str = misc::toQString("http://")+options->getHTTPProxyIp()+":"+misc::toQString(options->getHTTPProxyPort());
}
// We need this for urllib in search engine plugins
#ifdef Q_WS_WIN
char proxystr[512];
snprintf(proxystr, 512, "http_proxy=%s", proxy_str.toLocal8Bit().data());
putenv(proxystr);
#else
qDebug("HTTP: proxy string: %s", proxy_str.toLocal8Bit().data());
setenv("http_proxy", proxy_str.toLocal8Bit().data(), 1);
#endif
} else {
qDebug("Disabling search proxy");
#ifdef Q_WS_WIN
putenv("http_proxy=");
#else
unsetenv("http_proxy");
#endif
}
// Clean up
if(deleteOptions && options) {
qDebug("Deleting options");
//delete options;
options->deleteLater();
}
qDebug("Session configured");
} }
void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) { void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) {
@ -1198,36 +1004,7 @@ void GUI::createTrayIcon() {
// Display Program Options // Display Program Options
void GUI::on_actionOptions_triggered() { void GUI::on_actionOptions_triggered() {
options = new options_imp(this); options = new options_imp(this);
connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool))); connect(options, SIGNAL(status_changed()), this, SLOT(loadPreferences(bool)));
options->show();
}
// Is executed each time options are saved
void GUI::OptionsSaved(bool deleteOptions) {
BTSession->addConsoleMessage(tr("Options were saved successfully."));
bool newSystrayIntegration = options->systrayIntegration();
if(newSystrayIntegration != systrayIntegration) {
if(newSystrayIntegration) {
// create the trayicon
createTrayIcon();
} else {
// Destroy trayicon
delete myTrayIcon;
delete myTrayIconMenu;
}
systrayIntegration = newSystrayIntegration;
}
// Update Web UI
if (options->isWebUiEnabled()) {
quint16 port = options->webUiPort();
QString username = options->webUiUsername();
QString password = options->webUiPassword();
initWebUi(username, password, port);
} else if(httpServer) {
delete httpServer;
}
// Update session
configureSession(deleteOptions);
} }
bool GUI::initWebUi(QString username, QString password, int port) { bool GUI::initWebUi(QString username, QString password, int port) {

3
src/GUI.h

@ -144,7 +144,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void on_actionDocumentation_triggered() const; void on_actionDocumentation_triggered() const;
void on_actionOpen_triggered(); void on_actionOpen_triggered();
void checkConnectionStatus(); void checkConnectionStatus();
void configureSession(bool deleteOptions); void loadPreferences(bool configure_session=true);
void processParams(const QStringList& params); void processParams(const QStringList& params);
void addTorrent(QString path); void addTorrent(QString path);
void addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker); void addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker);
@ -156,7 +156,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void scrapeTrackers(); void scrapeTrackers();
// Options slots // Options slots
void on_actionOptions_triggered(); void on_actionOptions_triggered();
void OptionsSaved(bool deleteOptions);
// HTTP slots // HTTP slots
void on_actionDownload_from_URL_triggered(); void on_actionDownload_from_URL_triggered();

229
src/bittorrent.cpp

@ -39,6 +39,7 @@
#include "misc.h" #include "misc.h"
#include "downloadThread.h" #include "downloadThread.h"
#include "filterParserThread.h" #include "filterParserThread.h"
#include "preferences.h"
#include "torrentPersistentData.h" #include "torrentPersistentData.h"
#include <libtorrent/extensions/ut_metadata.hpp> #include <libtorrent/extensions/ut_metadata.hpp>
#include <libtorrent/extensions/lt_trackers.hpp> #include <libtorrent/extensions/lt_trackers.hpp>
@ -54,6 +55,7 @@
#define MAX_TRACKER_ERRORS 2 #define MAX_TRACKER_ERRORS 2
#define MAX_RATIO 100. #define MAX_RATIO 100.
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4};
// Main constructor // Main constructor
bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false) { bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false) {
@ -61,8 +63,7 @@ bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(
fs::path::default_name_check(fs::no_check); fs::path::default_name_check(fs::no_check);
// Creating bittorrent session // Creating bittorrent session
// Check if we should spoof utorrent // Check if we should spoof utorrent
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); if(Preferences::isUtorrentSpoofingEnabled()) {
if(settings.value(QString::fromUtf8("Preferences/Bittorrent/AzureusSpoof"), false).toBool()) {
s = new session(fingerprint("UT", 1, 8, 5, 0), 0); s = new session(fingerprint("UT", 1, 8, 5, 0), 0);
qDebug("Peer ID: %s", fingerprint("UT", 1, 8, 5, 0).to_string().c_str()); qDebug("Peer ID: %s", fingerprint("UT", 1, 8, 5, 0).to_string().c_str());
} else { } else {
@ -88,6 +89,8 @@ bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(
downloader = new downloadThread(this); downloader = new downloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
// Apply user settings to Bittorrent session
configureSession();
qDebug("* BTSession constructed"); qDebug("* BTSession constructed");
} }
@ -212,6 +215,228 @@ int bittorrent::getUpTorrentPriority(QString hash) const {
return h.queue_position(); return h.queue_position();
} }
// Set BT session configuration
void bittorrent::configureSession() {
qDebug("Configuring session");
// Downloads
// * Save path
setDefaultSavePath(Preferences::getSavePath());
if(Preferences::isTempPathEnabled()) {
setDefaultTempPath(Preferences::getTempPath());
} else {
setDefaultTempPath(QString::null);
}
preAllocateAllFiles(Preferences::preAllocateAllFiles());
startTorrentsInPause(Preferences::addTorrentsInPause());
// * Scan dir
QString scan_dir = Preferences::getScanDir();
if(scan_dir.isEmpty()) {
disableDirectoryScanning();
}else{
//Interval first
enableDirectoryScanning(scan_dir);
}
// Connection
// * Ports binding
unsigned short old_listenPort = getListenPort();
setListeningPort(Preferences::getSessionPort());
unsigned short new_listenPort = getListenPort();
if(new_listenPort != old_listenPort) {
addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg( misc::toQString(new_listenPort)));
}
// * Global download limit
int down_limit = Preferences::getGlobalDownloadLimit();
if(down_limit <= 0) {
// Download limit disabled
setDownloadRateLimit(-1);
} else {
// Enabled
setDownloadRateLimit(down_limit*1024);
}
int up_limit = Preferences::getGlobalUploadLimit();
// * Global Upload limit
if(up_limit <= 0) {
// Upload limit disabled
setUploadRateLimit(-1);
} else {
// Enabled
setUploadRateLimit(up_limit*1024);
}
// * UPnP
if(Preferences::isUPnPEnabled()) {
enableUPnP(true);
addConsoleMessage(tr("UPnP support [ON]"), QString::fromUtf8("blue"));
} else {
enableUPnP(false);
addConsoleMessage(tr("UPnP support [OFF]"), QString::fromUtf8("blue"));
}
// * NAT-PMP
if(Preferences::isNATPMPEnabled()) {
enableNATPMP(true);
addConsoleMessage(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue"));
} else {
enableNATPMP(false);
addConsoleMessage(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
}
// * Session settings
session_settings sessionSettings;
if(Preferences::isUtorrentSpoofingEnabled()) {
sessionSettings.user_agent = "uTorrent/1850";
} else {
sessionSettings.user_agent = "qBittorrent "VERSION;
}
sessionSettings.upnp_ignore_nonrouters = true;
sessionSettings.use_dht_as_fallback = false;
// To keep same behavior as in qbittorrent v1.2.0
sessionSettings.rate_limit_ip_overhead = false;
// Queueing System
if(Preferences::isQueueingSystemEnabled()) {
sessionSettings.active_downloads = Preferences::getMaxActiveDownloads();
sessionSettings.active_seeds = Preferences::getMaxActiveUploads();
sessionSettings.active_limit = Preferences::getMaxActiveTorrents();
sessionSettings.dont_count_slow_torrents = false;
setQueueingEnabled(true);
} else {
sessionSettings.active_downloads = -1;
sessionSettings.active_seeds = -1;
sessionSettings.active_limit = -1;
setQueueingEnabled(false);
}
setSessionSettings(sessionSettings);
// Bittorrent
// * Max connections limit
setMaxConnections(Preferences::getMaxConnecs());
// * Max connections per torrent limit
setMaxConnectionsPerTorrent(Preferences::getMaxConnecsPerTorrent());
// * Max uploads per torrent limit
setMaxUploadsPerTorrent(Preferences::getMaxUploadsPerTorrent());
// * DHT
if(Preferences::isDHTEnabled()) {
// Set DHT Port
if(enableDHT(true)) {
int dht_port = new_listenPort;
if(!Preferences::isDHTPortSameAsBT())
dht_port = Preferences::getDHTPort();
setDHTPort(dht_port);
addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue"));
} else {
addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("red"));
}
} else {
enableDHT(false);
addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
}
// * PeX
addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue"));
// * LSD
if(Preferences::isLSDEnabled()) {
enableLSD(true);
addConsoleMessage(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
} else {
enableLSD(false);
addConsoleMessage(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
}
// * Encryption
int encryptionState = Preferences::getEncryptionSetting();
// The most secure, rc4 only so that all streams and encrypted
pe_settings encryptionSettings;
encryptionSettings.allowed_enc_level = pe_settings::rc4;
encryptionSettings.prefer_rc4 = true;
switch(encryptionState) {
case 0: //Enabled
encryptionSettings.out_enc_policy = pe_settings::enabled;
encryptionSettings.in_enc_policy = pe_settings::enabled;
addConsoleMessage(tr("Encryption support [ON]"), QString::fromUtf8("blue"));
break;
case 1: // Forced
encryptionSettings.out_enc_policy = pe_settings::forced;
encryptionSettings.in_enc_policy = pe_settings::forced;
addConsoleMessage(tr("Encryption support [FORCED]"), QString::fromUtf8("blue"));
break;
default: // Disabled
encryptionSettings.out_enc_policy = pe_settings::disabled;
encryptionSettings.in_enc_policy = pe_settings::disabled;
addConsoleMessage(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
}
applyEncryptionSettings(encryptionSettings);
// * Desired ratio
setGlobalRatio(Preferences::getDesiredRatio());
// * Maximum ratio
setDeleteRatio(Preferences::getDeleteRatio());
// Ip Filter
if(Preferences::isFilteringEnabled()) {
enableIPFilter(Preferences::getFilter());
}else{
disableIPFilter();
}
// * Proxy settings
proxy_settings proxySettings;
if(Preferences::isProxyEnabled()) {
qDebug("Enabling P2P proxy");
proxySettings.hostname = Preferences::getProxyIp().toStdString();
qDebug("hostname is %s", proxySettings.hostname.c_str());
proxySettings.port = Preferences::getProxyPort();
qDebug("port is %d", proxySettings.port);
if(Preferences::isProxyAuthEnabled()) {
proxySettings.username = Preferences::getProxyUsername().toStdString();
proxySettings.password = Preferences::getProxyPassword().toStdString();
qDebug("username is %s", proxySettings.username.c_str());
qDebug("password is %s", proxySettings.password.c_str());
}
switch(Preferences::getProxyType()) {
case HTTP:
qDebug("type: http");
proxySettings.type = proxy_settings::http;
break;
case HTTP_PW:
qDebug("type: http_pw");
proxySettings.type = proxy_settings::http_pw;
break;
case SOCKS5:
qDebug("type: socks5");
proxySettings.type = proxy_settings::socks5;
break;
default:
qDebug("type: socks5_pw");
proxySettings.type = proxy_settings::socks5_pw;
break;
}
setProxySettings(proxySettings, Preferences::useProxyForTrackers(), Preferences::useProxyForPeers(), Preferences::useProxyForWebseeds(), Preferences::useProxyForDHT());
} else {
qDebug("Disabling P2P proxy");
setProxySettings(proxySettings, false, false, false, false);
}
if(Preferences::isHTTPProxyEnabled()) {
qDebug("Enabling Search HTTP proxy");
// HTTP Proxy
QString proxy_str;
switch(Preferences::getHTTPProxyType()) {
case HTTP_PW:
proxy_str = "http://"+Preferences::getHTTPProxyUsername()+":"+Preferences::getHTTPProxyPassword()+"@"+Preferences::getHTTPProxyIp()+":"+QString::number(Preferences::getHTTPProxyPort());
break;
default:
proxy_str = "http://"+Preferences::getHTTPProxyIp()+":"+QString::number(Preferences::getHTTPProxyPort());
}
// We need this for urllib in search engine plugins
#ifdef Q_WS_WIN
char proxystr[512];
snprintf(proxystr, 512, "http_proxy=%s", proxy_str.toLocal8Bit().data());
putenv(proxystr);
#else
qDebug("HTTP: proxy string: %s", proxy_str.toLocal8Bit().data());
setenv("http_proxy", proxy_str.toLocal8Bit().data(), 1);
#endif
} else {
qDebug("Disabling search proxy");
#ifdef Q_WS_WIN
putenv("http_proxy=");
#else
unsetenv("http_proxy");
#endif
}
qDebug("Session configured");
}
// Calculate the ETA using GASA // Calculate the ETA using GASA
// GASA: global Average Speed Algorithm // GASA: global Average Speed Algorithm
qlonglong bittorrent::getETA(QString hash) const { qlonglong bittorrent::getETA(QString hash) const {

1
src/bittorrent.h

@ -168,6 +168,7 @@ class bittorrent : public QObject {
void saveTrackerFile(QString hash); void saveTrackerFile(QString hash);
void addMagnetSkipAddDlg(QString uri); void addMagnetSkipAddDlg(QString uri);
void downloadFromURLList(const QStringList& urls); void downloadFromURLList(const QStringList& urls);
void configureSession();
protected slots: protected slots:
void addTorrentsFromScanFolder(QStringList&); void addTorrentsFromScanFolder(QStringList&);

33
src/options.ui

@ -209,7 +209,7 @@
<item> <item>
<widget class="QStackedWidget" name="tabOption"> <widget class="QStackedWidget" name="tabOption">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="tabOptionPage1"> <widget class="QWidget" name="tabOptionPage1">
<layout class="QVBoxLayout" name="verticalLayout_10"> <layout class="QVBoxLayout" name="verticalLayout_10">
@ -382,7 +382,7 @@
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>transfer lists refresh interval:</string> <string>Transfer list refresh interval:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -1081,9 +1081,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-4</y>
<width>620</width> <width>602</width>
<height>480</height> <height>513</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_18"> <layout class="QVBoxLayout" name="verticalLayout_18">
@ -1443,6 +1443,29 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Peer connections</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
<item>
<widget class="QCheckBox" name="checkResolveCountries">
<property name="text">
<string>Resolve peer countries</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkResolveHosts">
<property name="text">
<string>Resolve peer host names</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer_7"> <spacer name="verticalSpacer_7">
<property name="orientation"> <property name="orientation">

620
src/options_imp.cpp

@ -42,22 +42,24 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QDesktopWidget> #include <QDesktopWidget>
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#include <QWindowsXPStyle> #include <QWindowsXPStyle>
#endif #endif
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
#include <QMacStyle> #include <QMacStyle>
#endif #endif
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include "options_imp.h" #include "options_imp.h"
#include "preferences.h"
#include "misc.h" #include "misc.h"
// Constructor // Constructor
options_imp::options_imp(QWidget *parent):QDialog(parent){ options_imp::options_imp(QWidget *parent):QDialog(parent){
qDebug("-> Constructing Options"); qDebug("-> Constructing Options");
setAttribute(Qt::WA_DeleteOnClose);
QString savePath; QString savePath;
setupUi(this); setupUi(this);
// Get apply button in button box // Get apply button in button box
@ -140,32 +142,32 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
} }
// Connect signals / slots // Connect signals / slots
// General tab // General tab
connect(checkNoSystray, SIGNAL(stateChanged(int)), this, SLOT(setSystrayOptionsState(int))); connect(checkNoSystray, SIGNAL(toggled(bool)), this, SLOT(setSystrayOptionsState(bool)));
// Downloads tab // Downloads tab
connect(checkTempFolder, SIGNAL(stateChanged(int)), this, SLOT(enableTempPathInput(int))); connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableTempPathInput(bool)));
connect(checkScanDir, SIGNAL(stateChanged(int)), this, SLOT(enableDirScan(int))); connect(checkScanDir, SIGNAL(toggled(bool)), this, SLOT(enableDirScan(bool)));
connect(actionTorrentDlOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(actionTorrentDlOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkTempFolder, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
// Connection tab // Connection tab
connect(checkUploadLimit, SIGNAL(stateChanged(int)), this, SLOT(enableUploadLimit(int))); connect(checkUploadLimit, SIGNAL(toggled(bool)), this, SLOT(enableUploadLimit(bool)));
connect(checkDownloadLimit, SIGNAL(stateChanged(int)), this, SLOT(enableDownloadLimit(int))); connect(checkDownloadLimit, SIGNAL(toggled(bool)), this, SLOT(enableDownloadLimit(bool)));
// Bittorrent tab // Bittorrent tab
connect(checkMaxConnecs, SIGNAL(stateChanged(int)), this, SLOT(enableMaxConnecsLimit(int))); connect(checkMaxConnecs, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimit(bool)));
connect(checkMaxConnecsPerTorrent, SIGNAL(stateChanged(int)), this, SLOT(enableMaxConnecsLimitPerTorrent(int))); connect(checkMaxConnecsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimitPerTorrent(bool)));
connect(checkMaxUploadsPerTorrent, SIGNAL(stateChanged(int)), this, SLOT(enableMaxUploadsLimitPerTorrent(int))); connect(checkMaxUploadsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxUploadsLimitPerTorrent(bool)));
connect(checkRatioLimit, SIGNAL(stateChanged(int)), this, SLOT(enableShareRatio(int))); connect(checkRatioLimit, SIGNAL(toggled(bool)), this, SLOT(enableShareRatio(bool)));
connect(checkRatioRemove, SIGNAL(stateChanged(int)), this, SLOT(enableDeleteRatio(int))); connect(checkRatioRemove, SIGNAL(toggled(bool)), this, SLOT(enableDeleteRatio(bool)));
connect(checkSameDHTPort, SIGNAL(stateChanged(int)), this, SLOT(enableDHTPortSettings(int))); connect(checkSameDHTPort, SIGNAL(toggled(bool)), this, SLOT(enableDHTPortSettings(bool)));
// Proxy tab // Proxy tab
connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxyHTTP(int))); connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxyHTTP(int)));
connect(checkProxyAuth_http, SIGNAL(stateChanged(int)), this, SLOT(enableProxyAuthHTTP(int))); connect(checkProxyAuth_http, SIGNAL(toggled(bool)), this, SLOT(enableProxyAuthHTTP(bool)));
connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxy(int))); connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxy(int)));
connect(checkProxyAuth, SIGNAL(stateChanged(int)), this, SLOT(enableProxyAuth(int))); connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enableProxyAuth(bool)));
// Misc tab // Misc tab
connect(checkIPFilter, SIGNAL(stateChanged(int)), this, SLOT(enableFilter(int))); connect(checkIPFilter, SIGNAL(toggled(bool)), this, SLOT(enableFilter(bool)));
connect(checkEnableRSS, SIGNAL(stateChanged(int)), this, SLOT(enableRSS(int))); connect(checkEnableRSS, SIGNAL(toggled(bool)), this, SLOT(enableRSS(bool)));
connect(checkEnableQueueing, SIGNAL(stateChanged(int)), this, SLOT(enableQueueingSystem(int))); connect(checkEnableQueueing, SIGNAL(toggled(bool)), this, SLOT(enableQueueingSystem(bool)));
// Web UI tab // Web UI tab
connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableWebUi(bool))); connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableWebUi(bool)));
@ -173,72 +175,74 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
// General tab // General tab
connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(comboStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkConfirmExit, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkConfirmExit, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkSpeedInTitle, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkSpeedInTitle, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinRefreshInterval, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinRefreshInterval, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkNoSystray, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkNoSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkCloseToSystray, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkMinimizeToSysTray, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkMinimizeToSysTray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkStartMinimized, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkStartMinimized, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkSystrayBalloons, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkSystrayBalloons, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkDisplayToolbar, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkDisplayToolbar, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkNoSplash, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkNoSplash, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
// Downloads tab // Downloads tab
connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkPreallocateAll, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkPreallocateAll, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkAdditionDialog, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkAdditionDialog, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkStartPaused, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkStartPaused, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkScanDir, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkScanDir, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textScanDir, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textScanDir, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
// Connection tab // Connection tab
connect(spinPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkUPnP, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkUPnP, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkNATPMP, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkNATPMP, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkUploadLimit, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkUploadLimit, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkDownloadLimit, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkDownloadLimit, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinUploadLimit, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinUploadLimit, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinDownloadLimit, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinDownloadLimit, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkResolveCountries, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkResolveHosts, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
// Bittorrent tab // Bittorrent tab
connect(checkMaxConnecs, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkMaxConnecs, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkMaxConnecsPerTorrent, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkMaxConnecsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkMaxUploadsPerTorrent, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkMaxUploadsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinMaxConnec, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxConnec, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinMaxConnecPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxConnecPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinMaxUploadsPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxUploadsPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkDHT, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkDHT, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkSameDHTPort, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkSameDHTPort, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinDHTPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinDHTPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkLSD, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkLSD, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkAzureusSpoof, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkAzureusSpoof, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(comboEncryption, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboEncryption, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkRatioLimit, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkRatioLimit, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkRatioRemove, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkRatioRemove, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
// Proxy tab // Proxy tab
connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(textProxyIP_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyIP_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinProxyPort_http, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinProxyPort_http, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkProxyAuth_http, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkProxyAuth_http, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textProxyUsername_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyUsername_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(textProxyPassword_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyPassword_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(comboProxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboProxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(textProxyIP, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyIP, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinProxyPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinProxyPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkProxyAuth, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textProxyUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(textProxyPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkProxyTrackers, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkProxyTrackers, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkProxyPeers, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkProxyPeers, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkProxyWebseeds, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkProxyWebseeds, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkProxyDHT, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkProxyDHT, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
// Misc tab // Misc tab
connect(checkIPFilter, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkIPFilter, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textFilterPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textFilterPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinRSSRefresh, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinRSSRefresh, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinRSSMaxArticlesPerFeed, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinRSSMaxArticlesPerFeed, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkEnableRSS, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkEnableRSS, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkEnableQueueing, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkEnableQueueing, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinMaxActiveDownloads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxActiveDownloads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinMaxActiveUploads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxActiveUploads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinMaxActiveTorrents, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxActiveTorrents, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
@ -258,6 +262,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(tabSelection, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem*))); connect(tabSelection, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem*)));
// Adapt size // Adapt size
adaptToScreenSize(); adaptToScreenSize();
show();
} }
// Main destructor // Main destructor
@ -266,33 +271,33 @@ options_imp::~options_imp(){
} }
void options_imp::changePage(QListWidgetItem *current, QListWidgetItem *previous) { void options_imp::changePage(QListWidgetItem *current, QListWidgetItem *previous) {
if (!current) if (!current)
current = previous; current = previous;
tabOption->setCurrentIndex(tabSelection->row(current)); tabOption->setCurrentIndex(tabSelection->row(current));
} }
void options_imp::useStyle(){ void options_imp::useStyle(){
int style = getStyle(); int style = getStyle();
switch(style) { switch(style) {
case 1: case 1:
QApplication::setStyle(new QPlastiqueStyle()); QApplication::setStyle(new QPlastiqueStyle());
break; break;
case 2: case 2:
QApplication::setStyle(new QGnomeLookStyle()); QApplication::setStyle(new QGnomeLookStyle());
break; break;
case 3: case 3:
QApplication::setStyle(new QMotifStyle()); QApplication::setStyle(new QMotifStyle());
break; break;
case 4: case 4:
QApplication::setStyle(new QCDEStyle()); QApplication::setStyle(new QCDEStyle());
break; break;
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
case 5: case 5:
QApplication::setStyle(new QMacStyle()); QApplication::setStyle(new QMacStyle());
break; break;
#endif #endif
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
case 6: case 6:
QApplication::setStyle(new QWindowsXPStyle()); QApplication::setStyle(new QWindowsXPStyle());
break; break;
#endif #endif
@ -361,36 +366,36 @@ void options_imp::saveOptions(){
settings.setValue(QString::fromUtf8("GlobalUPLimit"), getGlobalBandwidthLimits().second); settings.setValue(QString::fromUtf8("GlobalUPLimit"), getGlobalBandwidthLimits().second);
settings.setValue(QString::fromUtf8("ProxyType"), getProxyType()); settings.setValue(QString::fromUtf8("ProxyType"), getProxyType());
//if(isProxyEnabled()) { //if(isProxyEnabled()) {
settings.beginGroup("Proxy"); settings.beginGroup("Proxy");
// Proxy is enabled, save settings // Proxy is enabled, save settings
settings.setValue(QString::fromUtf8("IP"), getProxyIp()); settings.setValue(QString::fromUtf8("IP"), getProxyIp());
settings.setValue(QString::fromUtf8("Port"), getProxyPort()); settings.setValue(QString::fromUtf8("Port"), getProxyPort());
settings.setValue(QString::fromUtf8("Authentication"), isProxyAuthEnabled()); settings.setValue(QString::fromUtf8("Authentication"), isProxyAuthEnabled());
//if(isProxyAuthEnabled()) { //if(isProxyAuthEnabled()) {
// Credentials // Credentials
settings.setValue(QString::fromUtf8("Username"), getProxyUsername()); settings.setValue(QString::fromUtf8("Username"), getProxyUsername());
settings.setValue(QString::fromUtf8("Password"), getProxyPassword()); settings.setValue(QString::fromUtf8("Password"), getProxyPassword());
//} //}
// Affected connections // Affected connections
settings.setValue(QString::fromUtf8("AffectTrackers"), useProxyForTrackers()); settings.setValue(QString::fromUtf8("AffectTrackers"), useProxyForTrackers());
settings.setValue(QString::fromUtf8("AffectPeers"), useProxyForPeers()); settings.setValue(QString::fromUtf8("AffectPeers"), useProxyForPeers());
settings.setValue(QString::fromUtf8("AffectWebSeeds"), useProxyForWebseeds()); settings.setValue(QString::fromUtf8("AffectWebSeeds"), useProxyForWebseeds());
settings.setValue(QString::fromUtf8("AffectDHT"), useProxyForDHT()); settings.setValue(QString::fromUtf8("AffectDHT"), useProxyForDHT());
settings.endGroup(); // End Proxy settings.endGroup(); // End Proxy
//} //}
settings.setValue(QString::fromUtf8("HTTPProxyType"), getHTTPProxyType()); settings.setValue(QString::fromUtf8("HTTPProxyType"), getHTTPProxyType());
//if(isHTTPProxyEnabled()) { //if(isHTTPProxyEnabled()) {
settings.beginGroup("HTTPProxy"); settings.beginGroup("HTTPProxy");
// Proxy is enabled, save settings // Proxy is enabled, save settings
settings.setValue(QString::fromUtf8("IP"), getHTTPProxyIp()); settings.setValue(QString::fromUtf8("IP"), getHTTPProxyIp());
settings.setValue(QString::fromUtf8("Port"), getHTTPProxyPort()); settings.setValue(QString::fromUtf8("Port"), getHTTPProxyPort());
settings.setValue(QString::fromUtf8("Authentication"), isHTTPProxyAuthEnabled()); settings.setValue(QString::fromUtf8("Authentication"), isHTTPProxyAuthEnabled());
//if(isHTTPProxyAuthEnabled()) { //if(isHTTPProxyAuthEnabled()) {
// Credentials // Credentials
settings.setValue(QString::fromUtf8("Username"), getHTTPProxyUsername()); settings.setValue(QString::fromUtf8("Username"), getHTTPProxyUsername());
settings.setValue(QString::fromUtf8("Password"), getHTTPProxyPassword()); settings.setValue(QString::fromUtf8("Password"), getHTTPProxyPassword());
//} //}
settings.endGroup(); // End HTTPProxy settings.endGroup(); // End HTTPProxy
//} //}
// End Connection preferences // End Connection preferences
settings.endGroup(); settings.endGroup();
@ -403,7 +408,7 @@ void options_imp::saveOptions(){
settings.setValue(QString::fromUtf8("sameDHTPortAsBT"), isDHTPortSameAsBT()); settings.setValue(QString::fromUtf8("sameDHTPortAsBT"), isDHTPortSameAsBT());
settings.setValue(QString::fromUtf8("DHTPort"), getDHTPort()); settings.setValue(QString::fromUtf8("DHTPort"), getDHTPort());
settings.setValue(QString::fromUtf8("LSD"), isLSDEnabled()); settings.setValue(QString::fromUtf8("LSD"), isLSDEnabled());
settings.setValue(QString::fromUtf8("AzureusSpoof"), shouldSpoofAzureus()); settings.setValue(QString::fromUtf8("utorrentSpoof"), isUtorrentSpoofingEnabled());
settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting()); settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting());
settings.setValue(QString::fromUtf8("DesiredRatio"), getDesiredRatio()); settings.setValue(QString::fromUtf8("DesiredRatio"), getDesiredRatio());
settings.setValue(QString::fromUtf8("MaxRatio"), getDeleteRatio()); settings.setValue(QString::fromUtf8("MaxRatio"), getDeleteRatio());
@ -448,7 +453,7 @@ void options_imp::saveOptions(){
settings.endGroup(); settings.endGroup();
} }
bool options_imp::shouldSpoofAzureus() const { bool options_imp::isUtorrentSpoofingEnabled() const {
return checkAzureusSpoof->isChecked(); return checkAzureusSpoof->isChecked();
} }
@ -512,83 +517,72 @@ void options_imp::setStyle(int style){
comboStyle->setCurrentIndex(style); comboStyle->setCurrentIndex(style);
} }
bool options_imp::isHTTPProxyAuthEnabled() const{
return checkProxyAuth_http->isChecked();
}
void options_imp::loadOptions(){ void options_imp::loadOptions(){
int intValue; int intValue;
float floatValue; float floatValue;
QString strValue; QString strValue;
QSettings settings("qBittorrent", "qBittorrent");
settings.beginGroup("Preferences");
// General preferences // General preferences
settings.beginGroup("General"); setLocale(Preferences::getLocale());
setLocale(settings.value(QString::fromUtf8("Locale"), "en_GB").toString()); setStyle(Preferences::getStyle());
setStyle(settings.value(QString::fromUtf8("Style"), 0).toInt()); checkConfirmExit->setChecked(Preferences::confirmOnExit());
checkConfirmExit->setChecked(settings.value(QString::fromUtf8("ExitConfirm"), true).toBool()); checkSpeedInTitle->setChecked(Preferences::speedInTitleBar());
checkSpeedInTitle->setChecked(settings.value(QString::fromUtf8("SpeedInTitleBar"), false).toBool()); spinRefreshInterval->setValue(Preferences::getRefreshInterval());
spinRefreshInterval->setValue(settings.value(QString::fromUtf8("RefreshInterval"), 1500).toInt()); checkNoSystray->setChecked(!Preferences::systrayIntegration());
checkNoSystray->setChecked(!settings.value(QString::fromUtf8("SystrayEnabled"), true).toBool()); checkDisplayToolbar->setChecked(Preferences::isToolbarDisplayed());
checkDisplayToolbar->setChecked(settings.value(QString::fromUtf8("ToolbarDisplayed"), true).toBool()); checkNoSplash->setChecked(Preferences::isSlashScreenDisabled());
checkNoSplash->setChecked(settings.value(QString::fromUtf8("NoSplashScreen"), false).toBool()); if(checkNoSystray->isChecked()) {
if(!systrayIntegration()) {
disableSystrayOptions(); disableSystrayOptions();
} else { } else {
enableSystrayOptions(); enableSystrayOptions();
checkCloseToSystray->setChecked(settings.value(QString::fromUtf8("CloseToTray"), false).toBool()); checkCloseToSystray->setChecked(Preferences::closeToTray());
checkMinimizeToSysTray->setChecked(settings.value(QString::fromUtf8("MinimizeToTray"), false).toBool()); checkMinimizeToSysTray->setChecked(Preferences::minimizeToTray());
checkStartMinimized->setChecked(settings.value(QString::fromUtf8("StartMinimized"), false).toBool()); checkStartMinimized->setChecked(Preferences::startMinimized());
checkSystrayBalloons->setChecked(settings.value(QString::fromUtf8("NotificationBaloons"), true).toBool()); checkSystrayBalloons->setChecked(Preferences::OSDEnabled());
} }
// End General preferences // End General preferences
settings.endGroup();
// Downloads preferences // Downloads preferences
settings.beginGroup("Downloads"); textSavePath->setText(Preferences::getSavePath());
#ifdef Q_WS_WIN if(Preferences::isTempPathEnabled()) {
QString home = QDir::rootPath();
#else
QString home = QDir::homePath();
#endif
if(home[home.length()-1] != QDir::separator()){
home += QDir::separator();
}
textSavePath->setText(settings.value(QString::fromUtf8("SavePath"), home+"qBT_dir").toString());
if(settings.value(QString::fromUtf8("TempPathEnabled"), false).toBool()) {
// enable // enable
checkTempFolder->setChecked(true); checkTempFolder->setChecked(true);
enableTempPathInput(2); enableTempPathInput(checkTempFolder->isChecked());
} else { } else {
checkTempFolder->setChecked(false); checkTempFolder->setChecked(false);
enableTempPathInput(0); enableTempPathInput(checkTempFolder->isChecked());
} }
textTempPath->setText(settings.value(QString::fromUtf8("TempPath"), home+"qBT_dir"+QDir::separator()+"temp").toString()); textTempPath->setText(Preferences::getTempPath());
checkPreallocateAll->setChecked(settings.value(QString::fromUtf8("PreAllocation"), false).toBool()); checkPreallocateAll->setChecked(Preferences::preAllocateAllFiles());
checkAdditionDialog->setChecked(settings.value(QString::fromUtf8("AdditionDialog"), true).toBool()); checkAdditionDialog->setChecked(Preferences::useAdditionDialog());
checkStartPaused->setChecked(settings.value(QString::fromUtf8("StartInPause"), false).toBool()); checkStartPaused->setChecked(Preferences::addTorrentsInPause());
strValue = settings.value(QString::fromUtf8("ScanDir"), QString()).toString(); strValue = Preferences::getSavePath();
if(strValue.isEmpty()) { if(strValue.isEmpty()) {
// Disable // Disable
checkScanDir->setChecked(false); checkScanDir->setChecked(false);
enableDirScan(0); enableDirScan(checkScanDir->isChecked());
} else { } else {
// enable // enable
checkScanDir->setChecked(true); checkScanDir->setChecked(true);
textScanDir->setText(strValue); textScanDir->setText(strValue);
enableDirScan(2); enableDirScan(checkScanDir->isChecked());
} }
intValue = settings.value(QString::fromUtf8("DblClOnTorDl"), 0).toInt(); intValue = Preferences::getActionOnDblClOnTorrentDl();
if(intValue >= actionTorrentDlOnDblClBox->count()) if(intValue >= actionTorrentDlOnDblClBox->count())
intValue = 0; intValue = 0;
actionTorrentDlOnDblClBox->setCurrentIndex(intValue); actionTorrentDlOnDblClBox->setCurrentIndex(intValue);
intValue = settings.value(QString::fromUtf8("DblClOnTorFn"), 1).toInt(); intValue = Preferences::getActionOnDblClOnTorrentFn();
if(intValue >= actionTorrentFnOnDblClBox->count()) if(intValue >= actionTorrentFnOnDblClBox->count())
intValue = 1; intValue = 1;
actionTorrentFnOnDblClBox->setCurrentIndex(intValue); actionTorrentFnOnDblClBox->setCurrentIndex(intValue);
// End Downloads preferences // End Downloads preferences
settings.endGroup();
// Connection preferences // Connection preferences
settings.beginGroup("Connection"); spinPort->setValue(Preferences::getSessionPort());
spinPort->setValue(settings.value(QString::fromUtf8("PortRangeMin"), 6881).toInt()); checkUPnP->setChecked(Preferences::isUPnPEnabled());
checkUPnP->setChecked(settings.value(QString::fromUtf8("UPnP"), true).toBool()); checkNATPMP->setChecked(Preferences::isNATPMPEnabled());
checkNATPMP->setChecked(settings.value(QString::fromUtf8("NAT-PMP"), true).toBool()); intValue = Preferences::getGlobalDownloadLimit();
intValue = settings.value(QString::fromUtf8("GlobalDLLimit"), -1).toInt();
if(intValue > 0) { if(intValue > 0) {
// Enabled // Enabled
checkDownloadLimit->setChecked(true); checkDownloadLimit->setChecked(true);
@ -599,7 +593,7 @@ void options_imp::loadOptions(){
checkDownloadLimit->setChecked(false); checkDownloadLimit->setChecked(false);
spinDownloadLimit->setEnabled(false); spinDownloadLimit->setEnabled(false);
} }
intValue = settings.value(QString::fromUtf8("GlobalUPLimit"), 50).toInt(); intValue = Preferences::getGlobalUploadLimit();
if(intValue != -1) { if(intValue != -1) {
// Enabled // Enabled
checkUploadLimit->setChecked(true); checkUploadLimit->setChecked(true);
@ -610,7 +604,7 @@ void options_imp::loadOptions(){
checkUploadLimit->setChecked(false); checkUploadLimit->setChecked(false);
spinUploadLimit->setEnabled(false); spinUploadLimit->setEnabled(false);
} }
intValue = settings.value(QString::fromUtf8("ProxyType"), 0).toInt(); intValue = Preferences::getProxyType();
if(intValue <= 0) { if(intValue <= 0) {
intValue = 0; intValue = 0;
} else { } else {
@ -623,56 +617,38 @@ void options_imp::loadOptions(){
comboProxyType->setCurrentIndex(intValue); comboProxyType->setCurrentIndex(intValue);
enableProxy(intValue); enableProxy(intValue);
//if(isProxyEnabled()) { //if(isProxyEnabled()) {
settings.beginGroup("Proxy"); // Proxy is enabled, save settings
// Proxy is enabled, save settings textProxyIP->setText(Preferences::getProxyIp());
textProxyIP->setText(settings.value(QString::fromUtf8("IP"), "0.0.0.0").toString()); spinProxyPort->setValue(Preferences::getProxyPort());
spinProxyPort->setValue(settings.value(QString::fromUtf8("Port"), 8080).toInt()); checkProxyAuth->setChecked(Preferences::isProxyAuthEnabled());
checkProxyAuth->setChecked(settings.value(QString::fromUtf8("Authentication"), false).toBool()); textProxyUsername->setText(Preferences::getProxyUsername());
textProxyUsername->setText(settings.value(QString::fromUtf8("Username"), QString()).toString()); textProxyPassword->setText(Preferences::getProxyPassword());
textProxyPassword->setText(settings.value(QString::fromUtf8("Password"), QString()).toString()); enableProxyAuth(checkProxyAuth->isChecked());
if(isProxyAuthEnabled()) { // Affected connections
enableProxyAuth(2); // Enable checkProxyTrackers->setChecked(Preferences::useProxyForTrackers());
// Credentials checkProxyPeers->setChecked(Preferences::useProxyForPeers());
} else { checkProxyWebseeds->setChecked(Preferences::useProxyForWebseeds());
enableProxyAuth(0); // Disable checkProxyDHT->setChecked(Preferences::useProxyForDHT());
}
// Affected connections
checkProxyTrackers->setChecked(settings.value(QString::fromUtf8("AffectTrackers"), true).toBool());
checkProxyPeers->setChecked(settings.value(QString::fromUtf8("AffectPeers"), true).toBool());
checkProxyWebseeds->setChecked(settings.value(QString::fromUtf8("AffectWebSeeds"), true).toBool());
checkProxyDHT->setChecked(settings.value(QString::fromUtf8("AffectDHT"), true).toBool());
settings.endGroup(); // End Proxy
//} //}
intValue = settings.value(QString::fromUtf8("HTTPProxyType"), 0).toInt(); intValue = Preferences::getHTTPProxyType();
if(intValue <= 0) { if(intValue <= 0) {
intValue = 0; intValue = 0;
} else { } else {
intValue = 1; intValue = 1;
} }
comboProxyType_http->setCurrentIndex(intValue); comboProxyType_http->setCurrentIndex(intValue);
enableProxyHTTP(intValue); enableProxyHTTP(intValue);
settings.beginGroup("HTTPProxy"); textProxyUsername_http->setText(Preferences::getHTTPProxyUsername());
textProxyUsername_http->setText(settings.value(QString::fromUtf8("Username"), QString()).toString()); textProxyPassword_http->setText(Preferences::getHTTPProxyPassword());
textProxyPassword_http->setText(settings.value(QString::fromUtf8("Password"), QString()).toString()); textProxyIP_http->setText(Preferences::getHTTPProxyIp());
textProxyIP_http->setText(settings.value(QString::fromUtf8("IP"), "0.0.0.0").toString()); spinProxyPort_http->setValue(Preferences::getHTTPProxyPort());
spinProxyPort_http->setValue(settings.value(QString::fromUtf8("Port"), 8080).toInt()); checkProxyAuth_http->setChecked(Preferences::isHTTPProxyAuthEnabled());
checkProxyAuth_http->setChecked(settings.value(QString::fromUtf8("Authentication"), false).toBool()); enableProxyAuthHTTP(checkProxyAuth_http->isChecked());
if(isHTTPProxyEnabled()) { // End HTTPProxy
if(isHTTPProxyAuthEnabled()) {
enableProxyAuthHTTP(2); // Enable
} else {
enableProxyAuthHTTP(0); // Disable
}
} else {
enableProxyAuthHTTP(0); // Disable
}
settings.endGroup(); // End HTTPProxy
// End Connection preferences // End Connection preferences
settings.endGroup();
// Bittorrent preferences // Bittorrent preferences
settings.beginGroup("Bittorrent"); intValue = Preferences::getMaxConnecs();
intValue = settings.value(QString::fromUtf8("MaxConnecs"), 500).toInt(); if(intValue > 0) {
if(intValue != -1) {
// enable // enable
checkMaxConnecs->setChecked(true); checkMaxConnecs->setChecked(true);
spinMaxConnec->setEnabled(true); spinMaxConnec->setEnabled(true);
@ -682,8 +658,8 @@ void options_imp::loadOptions(){
checkMaxConnecs->setChecked(false); checkMaxConnecs->setChecked(false);
spinMaxConnec->setEnabled(false); spinMaxConnec->setEnabled(false);
} }
intValue = settings.value(QString::fromUtf8("MaxConnecsPerTorrent"), 100).toInt(); intValue = Preferences::getMaxConnecsPerTorrent();
if(intValue != -1) { if(intValue > 0) {
// enable // enable
checkMaxConnecsPerTorrent->setChecked(true); checkMaxConnecsPerTorrent->setChecked(true);
spinMaxConnecPerTorrent->setEnabled(true); spinMaxConnecPerTorrent->setEnabled(true);
@ -693,8 +669,8 @@ void options_imp::loadOptions(){
checkMaxConnecsPerTorrent->setChecked(false); checkMaxConnecsPerTorrent->setChecked(false);
spinMaxConnecPerTorrent->setEnabled(false); spinMaxConnecPerTorrent->setEnabled(false);
} }
intValue = settings.value(QString::fromUtf8("MaxUploadsPerTorrent"), 4).toInt(); intValue = Preferences::getMaxUploadsPerTorrent();
if(intValue != -1) { if(intValue > 0) {
// enable // enable
checkMaxUploadsPerTorrent->setChecked(true); checkMaxUploadsPerTorrent->setChecked(true);
spinMaxUploadsPerTorrent->setEnabled(true); spinMaxUploadsPerTorrent->setEnabled(true);
@ -704,14 +680,14 @@ void options_imp::loadOptions(){
checkMaxUploadsPerTorrent->setChecked(false); checkMaxUploadsPerTorrent->setChecked(false);
spinMaxUploadsPerTorrent->setEnabled(false); spinMaxUploadsPerTorrent->setEnabled(false);
} }
checkDHT->setChecked(settings.value(QString::fromUtf8("DHT"), true).toBool()); checkDHT->setChecked(Preferences::isDHTEnabled());
checkSameDHTPort->setChecked(settings.value(QString::fromUtf8("sameDHTPortAsBT"), true).toBool()); checkSameDHTPort->setChecked(Preferences::isDHTPortSameAsBT());
enableDHTPortSettings(checkSameDHTPort->checkState()); enableDHTPortSettings(checkSameDHTPort->isChecked());
spinDHTPort->setValue(settings.value(QString::fromUtf8("DHTPort"), 6882).toInt()); spinDHTPort->setValue(Preferences::getDHTPort());
checkLSD->setChecked(settings.value(QString::fromUtf8("LSD"), true).toBool()); checkLSD->setChecked(Preferences::isLSDEnabled());
checkAzureusSpoof->setChecked(settings.value(QString::fromUtf8("AzureusSpoof"), false).toBool()); checkAzureusSpoof->setChecked(Preferences::isUtorrentSpoofingEnabled());
comboEncryption->setCurrentIndex(settings.value(QString::fromUtf8("Encryption"), 0).toInt()); comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting());
floatValue = settings.value(QString::fromUtf8("DesiredRatio"), -1).toDouble(); floatValue = Preferences::getDesiredRatio();
if(floatValue >= 1.) { if(floatValue >= 1.) {
// Enable // Enable
checkRatioLimit->setChecked(true); checkRatioLimit->setChecked(true);
@ -722,7 +698,7 @@ void options_imp::loadOptions(){
checkRatioLimit->setChecked(false); checkRatioLimit->setChecked(false);
spinRatio->setEnabled(false); spinRatio->setEnabled(false);
} }
floatValue = settings.value(QString::fromUtf8("MaxRatio"), -1).toDouble(); floatValue = Preferences::getDeleteRatio();
if(floatValue >= 1.) { if(floatValue >= 1.) {
// Enable // Enable
checkRatioRemove->setChecked(true); checkRatioRemove->setChecked(true);
@ -734,53 +710,32 @@ void options_imp::loadOptions(){
spinMaxRatio->setEnabled(false); spinMaxRatio->setEnabled(false);
} }
// End Bittorrent preferences // End Bittorrent preferences
settings.endGroup();
// Misc preferences // Misc preferences
// * IP Filter // * IP Filter
settings.beginGroup("IPFilter"); checkIPFilter->setChecked(Preferences::isFilteringEnabled());
checkIPFilter->setChecked(settings.value(QString::fromUtf8("Enabled"), false).toBool()); enableFilter(checkIPFilter->isChecked());
if(isFilteringEnabled()) { textFilterPath->setText(Preferences::getFilter());
enableFilter(2); // Enable
textFilterPath->setText(settings.value(QString::fromUtf8("File"), QString()).toString());
} else {
enableFilter(0); // Disable
}
// End IP Filter // End IP Filter
settings.endGroup();
// * RSS // * RSS
settings.beginGroup("RSS"); checkEnableRSS->setChecked(Preferences::isRSSEnabled());
checkEnableRSS->setChecked(settings.value(QString::fromUtf8("RSSEnabled"), false).toBool()); enableRSS(checkEnableRSS->isChecked());
if(isRSSEnabled()) { spinRSSRefresh->setValue(Preferences::getRSSRefreshInterval());
enableRSS(2); // Enable spinRSSMaxArticlesPerFeed->setValue(Preferences::getRSSMaxArticlesPerFeed());
} else {
enableRSS(0); // Disable
}
spinRSSRefresh->setValue(settings.value(QString::fromUtf8("RSSRefresh"), 5).toInt());
spinRSSMaxArticlesPerFeed->setValue(settings.value(QString::fromUtf8("RSSMaxArticlesPerFeed"), 50).toInt());
// End RSS preferences // End RSS preferences
settings.endGroup();
// Queueing system preferences // Queueing system preferences
settings.beginGroup("Queueing"); checkEnableQueueing->setChecked(Preferences::isQueueingSystemEnabled());
checkEnableQueueing->setChecked(settings.value("QueueingEnabled", false).toBool()); enableQueueingSystem(checkEnableQueueing->isChecked());
if(isQueueingSystemEnabled()) { spinMaxActiveDownloads->setValue(Preferences::getMaxActiveDownloads());
enableQueueingSystem(2); // Enable spinMaxActiveUploads->setValue(Preferences::getMaxActiveUploads());
spinMaxActiveDownloads->setValue(settings.value(QString::fromUtf8("MaxActiveDownloads"), 3).toInt()); spinMaxActiveTorrents->setValue(Preferences::getMaxActiveTorrents());
spinMaxActiveUploads->setValue(settings.value(QString::fromUtf8("MaxActiveUploads"), 3).toInt());
spinMaxActiveTorrents->setValue(settings.value(QString::fromUtf8("MaxActiveTorrents"), 5).toInt());
} else {
enableQueueingSystem(0); // Disable
}
// End Queueing system preferences // End Queueing system preferences
settings.endGroup();
// Web UI // Web UI
settings.beginGroup("WebUI"); checkWebUi->setChecked(Preferences::isWebUiEnabled());
checkWebUi->setChecked(settings.value("Enabled", false).toBool()); enableWebUi(checkWebUi->isChecked());
enableWebUi(isWebUiEnabled()); spinWebUiPort->setValue(Preferences::getWebUiPort());
spinWebUiPort->setValue(settings.value("Port", 8080).toInt()); textWebUiUsername->setText(Preferences::getWebUiUsername());
textWebUiUsername->setText(settings.value("Username", "user").toString()); textWebUiPassword->setText(Preferences::getWebUiPassword());
textWebUiPassword->setText(settings.value("Password", "").toString());
// End Web UI // End Web UI
settings.endGroup();
// Random stuff // Random stuff
srand(time(0)); srand(time(0));
} }
@ -887,9 +842,9 @@ bool options_imp::systrayIntegration() const{
} }
int options_imp::getDHTPort() const { int options_imp::getDHTPort() const {
if(isDHTPortSameAsBT()) if(isDHTPortSameAsBT())
return 0; return 0;
return spinDHTPort->value(); return spinDHTPort->value();
} }
// Return Share ratio // Return Share ratio
@ -925,11 +880,11 @@ QString options_imp::getSavePath() const{
} }
QString options_imp::getTempPath() const { QString options_imp::getTempPath() const {
return textTempPath->text(); return textTempPath->text();
} }
bool options_imp::isTempPathEnabled() const { bool options_imp::isTempPathEnabled() const {
return checkTempFolder->isChecked(); return checkTempFolder->isChecked();
} }
// Return max connections number // Return max connections number
@ -961,19 +916,16 @@ void options_imp::on_buttonBox_accepted(){
if(applyButton->isEnabled()){ if(applyButton->isEnabled()){
saveOptions(); saveOptions();
applyButton->setEnabled(false); applyButton->setEnabled(false);
// set infobar text
this->hide(); this->hide();
emit status_changed(true); emit status_changed();
}else{
setAttribute(Qt::WA_DeleteOnClose);
accept();
} }
accept();
} }
void options_imp::applySettings(QAbstractButton* button) { void options_imp::applySettings(QAbstractButton* button) {
if(button == applyButton){ if(button == applyButton){
saveOptions(); saveOptions();
emit status_changed(false); emit status_changed();
} }
} }
@ -987,25 +939,21 @@ void options_imp::on_buttonBox_rejected(){
reject(); reject();
} }
void options_imp::enableDownloadLimit(int checkBoxValue){ void options_imp::enableDownloadLimit(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
spinDownloadLimit->setEnabled(false);
}else{
//enable
spinDownloadLimit->setEnabled(true); spinDownloadLimit->setEnabled(true);
}else{
spinDownloadLimit->setEnabled(false);
} }
} }
void options_imp::enableTempPathInput(int checkBoxValue){ void options_imp::enableTempPathInput(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
textTempPath->setEnabled(false);
browseTempDirButton->setEnabled(false);
}else{
//enable
textTempPath->setEnabled(true); textTempPath->setEnabled(true);
browseTempDirButton->setEnabled(true); browseTempDirButton->setEnabled(true);
}else{
textTempPath->setEnabled(false);
browseTempDirButton->setEnabled(false);
} }
} }
@ -1013,43 +961,37 @@ bool options_imp::useAdditionDialog() const{
return checkAdditionDialog->isChecked(); return checkAdditionDialog->isChecked();
} }
void options_imp::enableMaxConnecsLimit(int checkBoxValue){ void options_imp::enableMaxConnecsLimit(bool checked){
if(checkBoxValue != 2){ if(checked) {
//Disable
spinMaxConnec->setEnabled(false);
}else{
//enable
spinMaxConnec->setEnabled(true); spinMaxConnec->setEnabled(true);
}else{
spinMaxConnec->setEnabled(false);
} }
} }
void options_imp::enableQueueingSystem(int checkBoxValue) { void options_imp::enableQueueingSystem(bool checked) {
if(checkBoxValue != 2) { if(checked) {
//Disable
spinMaxActiveDownloads->setEnabled(false);
spinMaxActiveUploads->setEnabled(false);
label_max_active_dl->setEnabled(false);
label_max_active_up->setEnabled(false);
maxActiveTorrents_lbl->setEnabled(false);
spinMaxActiveTorrents->setEnabled(false);
}else{
//enable
spinMaxActiveDownloads->setEnabled(true); spinMaxActiveDownloads->setEnabled(true);
spinMaxActiveUploads->setEnabled(true); spinMaxActiveUploads->setEnabled(true);
label_max_active_dl->setEnabled(true); label_max_active_dl->setEnabled(true);
label_max_active_up->setEnabled(true); label_max_active_up->setEnabled(true);
maxActiveTorrents_lbl->setEnabled(true); maxActiveTorrents_lbl->setEnabled(true);
spinMaxActiveTorrents->setEnabled(true); spinMaxActiveTorrents->setEnabled(true);
}else{
spinMaxActiveDownloads->setEnabled(false);
spinMaxActiveUploads->setEnabled(false);
label_max_active_dl->setEnabled(false);
label_max_active_up->setEnabled(false);
maxActiveTorrents_lbl->setEnabled(false);
spinMaxActiveTorrents->setEnabled(false);
} }
} }
void options_imp::enableMaxConnecsLimitPerTorrent(int checkBoxValue){ void options_imp::enableMaxConnecsLimitPerTorrent(bool checked){
if(checkBoxValue != 2){ if(checked) {
//Disable
spinMaxConnecPerTorrent->setEnabled(false);
}else{
//enable
spinMaxConnecPerTorrent->setEnabled(true); spinMaxConnecPerTorrent->setEnabled(true);
}else{
spinMaxConnecPerTorrent->setEnabled(false);
} }
} }
@ -1065,55 +1007,47 @@ void options_imp::disableSystrayOptions() {
checkSystrayBalloons->setEnabled(false); checkSystrayBalloons->setEnabled(false);
} }
void options_imp::setSystrayOptionsState(int checkBoxValue) { void options_imp::setSystrayOptionsState(bool checked) {
if(checkBoxValue == 2) { if(checked) {
disableSystrayOptions(); disableSystrayOptions();
} else { } else {
enableSystrayOptions(); enableSystrayOptions();
} }
} }
void options_imp::enableMaxUploadsLimitPerTorrent(int checkBoxValue){ void options_imp::enableMaxUploadsLimitPerTorrent(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
spinMaxUploadsPerTorrent->setEnabled(false);
}else{
//enable
spinMaxUploadsPerTorrent->setEnabled(true); spinMaxUploadsPerTorrent->setEnabled(true);
}else{
spinMaxUploadsPerTorrent->setEnabled(false);
} }
} }
void options_imp::enableFilter(int checkBoxValue){ void options_imp::enableFilter(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
lblFilterPath->setEnabled(false);
textFilterPath->setEnabled(false);
browseFilterButton->setEnabled(false);
}else{
//enable
lblFilterPath->setEnabled(true); lblFilterPath->setEnabled(true);
textFilterPath->setEnabled(true); textFilterPath->setEnabled(true);
browseFilterButton->setEnabled(true); browseFilterButton->setEnabled(true);
}else{
lblFilterPath->setEnabled(false);
textFilterPath->setEnabled(false);
browseFilterButton->setEnabled(false);
} }
} }
void options_imp::enableRSS(int checkBoxValue) { void options_imp::enableRSS(bool checked) {
if(checkBoxValue != 2){ if(checked){
//Disable
groupRSSSettings->setEnabled(false);
}else{
//enable
groupRSSSettings->setEnabled(true); groupRSSSettings->setEnabled(true);
}else{
groupRSSSettings->setEnabled(false);
} }
} }
void options_imp::enableUploadLimit(int checkBoxValue){ void options_imp::enableUploadLimit(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
spinUploadLimit->setEnabled(false);
}else{
//enable
spinUploadLimit->setEnabled(true); spinUploadLimit->setEnabled(true);
}else{
spinUploadLimit->setEnabled(false);
} }
} }
@ -1123,35 +1057,29 @@ void options_imp::enableApplyButton(){
} }
} }
void options_imp::enableShareRatio(int checkBoxValue){ void options_imp::enableShareRatio(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
spinRatio->setEnabled(false);
}else{
//enable
spinRatio->setEnabled(true); spinRatio->setEnabled(true);
}else{
spinRatio->setEnabled(false);
} }
} }
void options_imp::enableDHTPortSettings(int checkBoxValue) { void options_imp::enableDHTPortSettings(bool checked) {
if(checkBoxValue == 2){ if(checked){
//Disable
spinDHTPort->setEnabled(false);
dh_port_lbl->setEnabled(false);
}else{
//enable
spinDHTPort->setEnabled(true); spinDHTPort->setEnabled(true);
dh_port_lbl->setEnabled(true); dh_port_lbl->setEnabled(true);
}else{
spinDHTPort->setEnabled(false);
dh_port_lbl->setEnabled(false);
} }
} }
void options_imp::enableDeleteRatio(int checkBoxValue){ void options_imp::enableDeleteRatio(bool checked){
if(checkBoxValue != 2){ if(checked){
//Disable
spinMaxRatio->setEnabled(false);
}else{
//enable
spinMaxRatio->setEnabled(true); spinMaxRatio->setEnabled(true);
}else{
spinMaxRatio->setEnabled(false);
} }
} }
@ -1195,15 +1123,13 @@ void options_imp::enableProxyHTTP(int index){
} }
} }
void options_imp::enableProxyAuth(int checkBoxValue){ void options_imp::enableProxyAuth(bool checked){
if(checkBoxValue==2){ if(checked){
//enable
lblProxyUsername->setEnabled(true); lblProxyUsername->setEnabled(true);
lblProxyPassword->setEnabled(true); lblProxyPassword->setEnabled(true);
textProxyUsername->setEnabled(true); textProxyUsername->setEnabled(true);
textProxyPassword->setEnabled(true); textProxyPassword->setEnabled(true);
}else{ }else{
//disable
lblProxyUsername->setEnabled(false); lblProxyUsername->setEnabled(false);
lblProxyPassword->setEnabled(false); lblProxyPassword->setEnabled(false);
textProxyUsername->setEnabled(false); textProxyUsername->setEnabled(false);
@ -1211,15 +1137,13 @@ void options_imp::enableProxyAuth(int checkBoxValue){
} }
} }
void options_imp::enableProxyAuthHTTP(int checkBoxValue){ void options_imp::enableProxyAuthHTTP(bool checked){
if(checkBoxValue==2){ if(checked){
//enable
lblProxyUsername_http->setEnabled(true); lblProxyUsername_http->setEnabled(true);
lblProxyPassword_http->setEnabled(true); lblProxyPassword_http->setEnabled(true);
textProxyUsername_http->setEnabled(true); textProxyUsername_http->setEnabled(true);
textProxyPassword_http->setEnabled(true); textProxyPassword_http->setEnabled(true);
}else{ }else{
//disable
lblProxyUsername_http->setEnabled(false); lblProxyUsername_http->setEnabled(false);
lblProxyPassword_http->setEnabled(false); lblProxyPassword_http->setEnabled(false);
textProxyUsername_http->setEnabled(false); textProxyUsername_http->setEnabled(false);
@ -1227,13 +1151,11 @@ void options_imp::enableProxyAuthHTTP(int checkBoxValue){
} }
} }
void options_imp::enableDirScan(int checkBoxValue){ void options_imp::enableDirScan(bool checked){
if(checkBoxValue==2){ if(checked){
//enable
textScanDir->setEnabled(true); textScanDir->setEnabled(true);
browseScanDirButton->setEnabled(true); browseScanDirButton->setEnabled(true);
}else{ }else{
//disable
textScanDir->setEnabled(false); textScanDir->setEnabled(false);
browseScanDirButton->setEnabled(false); browseScanDirButton->setEnabled(false);
} }
@ -1269,11 +1191,7 @@ bool options_imp::isHTTPProxyEnabled() const {
} }
bool options_imp::isProxyAuthEnabled() const{ bool options_imp::isProxyAuthEnabled() const{
return checkProxyAuth->isEnabled() && checkProxyAuth->isChecked(); return checkProxyAuth->isChecked();
}
bool options_imp::isHTTPProxyAuthEnabled() const{
return checkProxyAuth_http->isEnabled() && checkProxyAuth_http->isChecked();
} }
QString options_imp::getProxyIp() const{ QString options_imp::getProxyIp() const{

50
src/options_imp.h

@ -34,15 +34,10 @@
#include "ui_options.h" #include "ui_options.h"
#include <libtorrent/ip_filter.hpp> #include <libtorrent/ip_filter.hpp>
#define HTTP 1 enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4};
#define SOCKS5 2
#define HTTP_PW 3
#define SOCKS5_PW 4
// actions on double-click on torrents // actions on double-click on torrents
#define TOGGLE_PAUSE 0 enum DoubleClickAction {TOGGLE_PAUSE, OPEN_DEST};
#define OPEN_DEST 1
#define SHOW_PROPERTIES 2
using namespace libtorrent; using namespace libtorrent;
@ -100,23 +95,22 @@ class options_imp : public QDialog, private Ui::Dialog {
bool isDHTEnabled() const; bool isDHTEnabled() const;
bool isDHTPortSameAsBT() const; bool isDHTPortSameAsBT() const;
int getDHTPort() const; int getDHTPort() const;
bool isPeXEnabled() const;
bool isLSDEnabled() const; bool isLSDEnabled() const;
bool isRSSEnabled() const; bool isRSSEnabled() const;
bool shouldSpoofAzureus() const; bool isUtorrentSpoofingEnabled() const;
int getEncryptionSetting() const; int getEncryptionSetting() const;
float getDesiredRatio() const; float getDesiredRatio() const;
float getDeleteRatio() const; float getDeleteRatio() const;
// Proxy options // Proxy options
bool isHTTPProxyEnabled() const;
bool isHTTPProxyAuthEnabled() const;
QString getHTTPProxyIp() const; QString getHTTPProxyIp() const;
unsigned short getHTTPProxyPort() const; unsigned short getHTTPProxyPort() const;
QString getHTTPProxyUsername() const; QString getHTTPProxyUsername() const;
QString getHTTPProxyPassword() const; QString getHTTPProxyPassword() const;
int getHTTPProxyType() const; int getHTTPProxyType() const;
bool isProxyEnabled() const; bool isProxyEnabled() const;
bool isHTTPProxyEnabled() const;
bool isProxyAuthEnabled() const; bool isProxyAuthEnabled() const;
bool isHTTPProxyAuthEnabled() const;
QString getProxyIp() const; QString getProxyIp() const;
unsigned short getProxyPort() const; unsigned short getProxyPort() const;
QString getProxyUsername() const; QString getProxyUsername() const;
@ -140,23 +134,23 @@ class options_imp : public QDialog, private Ui::Dialog {
QString webUiPassword() const; QString webUiPassword() const;
protected slots: protected slots:
void enableUploadLimit(int checkBoxValue); void enableUploadLimit(bool checked);
void enableDownloadLimit(int checkBoxValue); void enableDownloadLimit(bool checked);
void enableTempPathInput(int checkBoxValue); void enableTempPathInput(bool checked);
void enableDirScan(int checkBoxValue); void enableDirScan(bool checked);
void enableProxy(int comboIndex); void enableProxy(int comboIndex);
void enableProxyAuth(int checkBoxValue); void enableProxyAuth(bool checked);
void enableProxyHTTP(int comboIndex); void enableProxyHTTP(int comboIndex);
void enableProxyAuthHTTP(int checkBoxValue); void enableProxyAuthHTTP(bool checked);
void enableMaxConnecsLimit(int); void enableMaxConnecsLimit(bool checked);
void enableMaxConnecsLimitPerTorrent(int checkBoxValue); void enableMaxConnecsLimitPerTorrent(bool checked);
void enableMaxUploadsLimitPerTorrent(int checkBoxValue); void enableMaxUploadsLimitPerTorrent(bool checked);
void enableShareRatio(int checkBoxValue); void enableShareRatio(bool checked);
void enableDeleteRatio(int checkBoxValue); void enableDeleteRatio(bool checked);
void enableFilter(int checkBoxValue); void enableFilter(bool checked);
void enableRSS(int checkBoxValue); void enableRSS(bool checked);
void enableDHTPortSettings(int checkBoxValue); void enableDHTPortSettings(bool checked);
void enableQueueingSystem(int checkBoxValue); void enableQueueingSystem(bool checked);
void setStyle(int style); void setStyle(int style);
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void closeEvent(QCloseEvent *e); void closeEvent(QCloseEvent *e);
@ -168,7 +162,7 @@ class options_imp : public QDialog, private Ui::Dialog {
void enableApplyButton(); void enableApplyButton();
void enableSystrayOptions(); void enableSystrayOptions();
void disableSystrayOptions(); void disableSystrayOptions();
void setSystrayOptionsState(int checkBoxValue); void setSystrayOptionsState(bool checked);
void enableWebUi(bool checkBoxValue); void enableWebUi(bool checkBoxValue);
void changePage(QListWidgetItem*, QListWidgetItem*); void changePage(QListWidgetItem*, QListWidgetItem*);
void adaptToScreenSize(); void adaptToScreenSize();
@ -179,7 +173,7 @@ class options_imp : public QDialog, private Ui::Dialog {
void useStyle(); void useStyle();
signals: signals:
void status_changed(bool) const; void status_changed() const;
void exitWithCancel(); void exitWithCancel();
}; };

406
src/preferences.h

@ -0,0 +1,406 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* 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.
*
* 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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PREFERENCES_H
#define PREFERENCES_H
#include <QSettings>
#include <QPair>
class Preferences {
public:
// General options
static QString getLocale() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString();
}
static int getStyle() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/Style"), 0).toInt();
}
static bool confirmOnExit() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/ExitConfirm"), true).toBool();
}
static bool speedInTitleBar() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), false).toBool();
}
static unsigned int getRefreshInterval() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/RefreshInterval"), 1500).toUInt();
}
static bool systrayIntegration() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool();
}
static bool isToolbarDisplayed() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool();
}
static bool minimizeToTray() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool();
}
static bool closeToTray() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool();
}
static bool startMinimized() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/StartMinimized"), false).toBool();
}
static bool isSlashScreenDisabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/NoSplashScreen"), false).toBool();
}
static bool OSDEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool();
}
// Downloads
static QString getSavePath() {
QSettings settings("qBittorrent", "qBittorrent");
#ifdef Q_WS_WIN
QString home = QDir::rootPath();
#else
QString home = QDir::homePath();
#endif
if(home[home.length()-1] != QDir::separator()){
home += QDir::separator();
}
return settings.value(QString::fromUtf8("Preferences/Downloads/SavePath"), home+"qBT_dir").toString();
}
static bool isTempPathEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), false).toBool();
}
static QString getTempPath() {
QSettings settings("qBittorrent", "qBittorrent");
#ifdef Q_WS_WIN
QString home = QDir::rootPath();
#else
QString home = QDir::homePath();
#endif
return settings.value(QString::fromUtf8("Preferences/Downloads/TempPath"), home+"qBT_dir"+QDir::separator()+"temp").toString();
}
static bool preAllocateAllFiles() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool();
}
static bool useAdditionDialog() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
}
static bool addTorrentsInPause() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/StartInPause"), false).toBool();
}
static bool isDirScanEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/ScanDir"), QString()).toString().isEmpty();
}
static QString getScanDir() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/ScanDir"), QString()).toString();
}
static int getActionOnDblClOnTorrentDl() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).toInt();
}
static int getActionOnDblClOnTorrentFn() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorFn"), 1).toInt();
}
// Connection options
static int getSessionPort() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/PortRangeMin"), 6881).toInt();
}
static bool isUPnPEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/UPnP"), true).toBool();
}
static bool isNATPMPEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/NAT-PMP"), true).toBool();
}
static int getGlobalDownloadLimit() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt();
}
static int getGlobalUploadLimit() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), -1).toInt();
}
// Proxy options
static bool isHTTPProxyEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt() > 0;
}
static bool isHTTPProxyAuthEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Authentication"), false).toBool();
}
static QString getHTTPProxyIp() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), "0.0.0.0").toString();
}
static unsigned short getHTTPProxyPort() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), 8080).toInt();
}
static QString getHTTPProxyUsername() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Username"), QString()).toString();
}
static QString getHTTPProxyPassword() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Password"), QString()).toString();
}
static int getHTTPProxyType() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt();
}
static bool isProxyEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt() > 0;
}
static bool isProxyAuthEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), false).toBool();
}
static QString getProxyIp() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/IP"), "0.0.0.0").toString();
}
static unsigned short getProxyPort() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Port"), 8080).toInt();
}
static QString getProxyUsername() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Username"), QString()).toString();
}
static QString getProxyPassword() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Password"), QString()).toString();
}
static int getProxyType() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt();
}
static bool useProxyForTrackers() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/AffectTrackers"), true).toBool();
}
static bool useProxyForPeers() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/AffectPeers"), true).toBool();
}
static bool useProxyForWebseeds() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/AffectWebSeeds"), true).toBool();
}
static bool useProxyForDHT() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/AffectDHT"), true).toBool();
}
// Bittorrent options
static int getMaxConnecs() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt();
}
static int getMaxConnecsPerTorrent() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt();
}
static int getMaxUploadsPerTorrent() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt();
}
static bool isDHTEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool();
}
static bool isDHTPortSameAsBT() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool();
}
static int getDHTPort() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), 6882).toInt();
}
static bool isLSDEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/LSD"), true).toBool();
}
static bool isUtorrentSpoofingEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/utorrentSpoof"), false).toBool();
}
static int getEncryptionSetting() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/Encryption"), 0).toInt();
}
static float getDesiredRatio() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/DesiredRatio"), -1).toDouble();
}
static float getDeleteRatio() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble();
}
// IP Filter
static bool isFilteringEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/IPFilter/Enabled"), false).toBool();
}
static QString getFilter() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString();
}
// RSS
static bool isRSSEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/RSS/RSSEnabled"), false).toBool();
}
static int getRSSRefreshInterval() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/RSS/RSSRefresh"), 5).toInt();
}
static int getRSSMaxArticlesPerFeed() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt();
}
// Queueing system
static bool isQueueingSystemEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value("Preferences/Queueing/QueueingEnabled", false).toBool();
}
static int getMaxActiveDownloads() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), 3).toInt();
}
static int getMaxActiveUploads() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), 3).toInt();
}
static int getMaxActiveTorrents() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), 5).toInt();
}
static bool isWebUiEnabled() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value("Preferences/WebUI/Enabled", false).toBool();
}
static quint16 getWebUiPort() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value("Preferences/WebUI/Port", 8080).toInt();
}
static QString getWebUiUsername() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value("Preferences/WebUI/Username", "user").toString();
}
static QString getWebUiPassword() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value("Preferences/WebUI/Password", "").toString();
}
};
#endif // PREFERENCES_H

3
src/src.pro

@ -188,7 +188,8 @@ HEADERS += GUI.h \
filesystemwatcher.h \ filesystemwatcher.h \
peerlistwidget.h \ peerlistwidget.h \
peerlistdelegate.h \ peerlistdelegate.h \
reverseresolution.h reverseresolution.h \
preferences.h
FORMS += MainWindow.ui \ FORMS += MainWindow.ui \
options.ui \ options.ui \
about.ui \ about.ui \

Loading…
Cancel
Save