From e5032a52c41cd1635ea44a8cda36a2b091a4fd1a Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 16 Nov 2010 20:34:31 +0000 Subject: [PATCH] Importance code refactoring related to the "preferences" code - Greatly improves performance --- src/advancedsettings.h | 64 +- src/deletionconfirmationdlg.h | 6 +- src/downloadthread.cpp | 3 +- src/headlessloader.h | 9 +- src/main.cpp | 6 +- src/mainwindow.cpp | 93 ++- src/options_imp.cpp | 315 ++++--- src/preferences.h | 1084 ++++++++++--------------- src/programupdater.cpp | 15 +- src/properties/peerlistwidget.cpp | 8 +- src/qtlibtorrent/bandwidthscheduler.h | 16 +- src/qtlibtorrent/qbtsession.cpp | 195 ++--- src/qtlibtorrent/qtorrenthandle.cpp | 12 +- src/rss/automatedrssdownloader.cpp | 4 +- src/rss/rss_imp.cpp | 7 +- src/rss/rssdownloadrule.cpp | 2 +- src/rss/rsssettings.h | 21 + src/smtp.cpp | 2 +- src/statusbar.h | 18 +- src/torrentadditiondlg.cpp | 7 +- src/tracker/qtracker.cpp | 4 +- src/transferlistfilterswidget.h | 6 +- src/transferlistwidget.cpp | 8 +- src/webui/eventmanager.cpp | 204 ++--- src/webui/httpconnection.cpp | 4 +- src/webui/httpserver.cpp | 5 +- 26 files changed, 976 insertions(+), 1142 deletions(-) diff --git a/src/advancedsettings.h b/src/advancedsettings.h index 5f97e2a4e..6a203359e 100644 --- a/src/advancedsettings.h +++ b/src/advancedsettings.h @@ -58,51 +58,53 @@ public: public slots: void saveAdvancedSettings() { + Preferences pref; // Disk write cache - Preferences::setDiskCacheSize(spin_cache->value()); + pref.setDiskCacheSize(spin_cache->value()); // Outgoing ports - Preferences::setOutgoingPortsMin(outgoing_ports_min->value()); - Preferences::setOutgoingPortsMax(outgoing_ports_max->value()); + pref.setOutgoingPortsMin(outgoing_ports_min->value()); + pref.setOutgoingPortsMax(outgoing_ports_max->value()); // Ignore limits on LAN - Preferences::ignoreLimitsOnLAN(cb_ignore_limits_lan->isChecked()); + pref.ignoreLimitsOnLAN(cb_ignore_limits_lan->isChecked()); // Include protocol overhead in transfer limits - Preferences::includeOverheadInLimits(cb_count_overhead->isChecked()); + pref.includeOverheadInLimits(cb_count_overhead->isChecked()); // Recheck torrents on completion - Preferences::recheckTorrentsOnCompletion(cb_recheck_completed->isChecked()); + pref.recheckTorrentsOnCompletion(cb_recheck_completed->isChecked()); // Transfer list refresh interval - Preferences::setRefreshInterval(spin_list_refresh->value()); + pref.setRefreshInterval(spin_list_refresh->value()); // Peer resolution - Preferences::resolvePeerCountries(cb_resolve_countries->isChecked()); - Preferences::resolvePeerHostNames(cb_resolve_hosts->isChecked()); + pref.resolvePeerCountries(cb_resolve_countries->isChecked()); + pref.resolvePeerHostNames(cb_resolve_hosts->isChecked()); // Max Half-Open connections - Preferences::setMaxHalfOpenConnections(spin_maxhalfopen->value()); + pref.setMaxHalfOpenConnections(spin_maxhalfopen->value()); #if LIBTORRENT_VERSION_MINOR > 14 // Super seeding - Preferences::enableSuperSeeding(cb_super_seeding->isChecked()); + pref.enableSuperSeeding(cb_super_seeding->isChecked()); #endif // Network interface if(combo_iface->currentIndex() == 0) { // All interfaces (default) - Preferences::setNetworkInterface(QString::null); + pref.setNetworkInterface(QString::null); } else { - Preferences::setNetworkInterface(combo_iface->currentText()); + pref.setNetworkInterface(combo_iface->currentText()); } // Program notification - Preferences::useProgramNotification(cb_program_notifications->isChecked()); + pref.useProgramNotification(cb_program_notifications->isChecked()); // Tracker - Preferences::setTrackerEnabled(cb_tracker_status->isChecked()); - Preferences::setTrackerPort(spin_tracker_port->value()); + pref.setTrackerEnabled(cb_tracker_status->isChecked()); + pref.setTrackerPort(spin_tracker_port->value()); } protected slots: void loadAdvancedSettings() { + const Preferences pref; // Disk write cache setItem(DISK_CACHE, PROPERTY, new QTableWidgetItem(tr("Disk write cache size"))); spin_cache = new QSpinBox(); connect(spin_cache, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged())); spin_cache->setMinimum(1); spin_cache->setMaximum(200); - spin_cache->setValue(Preferences::diskCacheSize()); + spin_cache->setValue(pref.diskCacheSize()); spin_cache->setSuffix(tr(" MiB")); setCellWidget(DISK_CACHE, VALUE, spin_cache); // Outgoing port Min @@ -111,7 +113,7 @@ protected slots: connect(outgoing_ports_min, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged())); outgoing_ports_min->setMinimum(0); outgoing_ports_min->setMaximum(65535); - outgoing_ports_min->setValue(Preferences::outgoingPortsMin()); + outgoing_ports_min->setValue(pref.outgoingPortsMin()); setCellWidget(OUTGOING_PORT_MIN, VALUE, outgoing_ports_min); // Outgoing port Min setItem(OUTGOING_PORT_MAX, PROPERTY, new QTableWidgetItem(tr("Outgoing ports (Max) [0: Disabled]"))); @@ -119,25 +121,25 @@ protected slots: connect(outgoing_ports_max, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged())); outgoing_ports_max->setMinimum(0); outgoing_ports_max->setMaximum(65535); - outgoing_ports_max->setValue(Preferences::outgoingPortsMax()); + outgoing_ports_max->setValue(pref.outgoingPortsMax()); setCellWidget(OUTGOING_PORT_MAX, VALUE, outgoing_ports_max); // Ignore transfer limits on local network setItem(IGNORE_LIMIT_LAN, PROPERTY, new QTableWidgetItem(tr("Ignore transfer limits on local network"))); cb_ignore_limits_lan = new QCheckBox(); connect(cb_ignore_limits_lan, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_ignore_limits_lan->setChecked(Preferences::ignoreLimitsOnLAN()); + cb_ignore_limits_lan->setChecked(pref.ignoreLimitsOnLAN()); setCellWidget(IGNORE_LIMIT_LAN, VALUE, cb_ignore_limits_lan); // Consider protocol overhead in transfer limits setItem(COUNT_OVERHEAD, PROPERTY, new QTableWidgetItem(tr("Include TCP/IP overhead in transfer limits"))); cb_count_overhead = new QCheckBox(); connect(cb_count_overhead, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_count_overhead->setChecked(Preferences::includeOverheadInLimits()); + cb_count_overhead->setChecked(pref.includeOverheadInLimits()); setCellWidget(COUNT_OVERHEAD, VALUE, cb_count_overhead); // Recheck completed torrents setItem(RECHECK_COMPLETED, PROPERTY, new QTableWidgetItem(tr("Recheck torrents on completion"))); cb_recheck_completed = new QCheckBox(); connect(cb_recheck_completed, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_recheck_completed->setChecked(Preferences::recheckTorrentsOnCompletion()); + cb_recheck_completed->setChecked(pref.recheckTorrentsOnCompletion()); setCellWidget(RECHECK_COMPLETED, VALUE, cb_recheck_completed); // Transfer list refresh interval setItem(LIST_REFRESH, PROPERTY, new QTableWidgetItem(tr("Transfer list refresh interval"))); @@ -145,20 +147,20 @@ protected slots: connect(spin_list_refresh, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged())); spin_list_refresh->setMinimum(30); spin_list_refresh->setMaximum(99999); - spin_list_refresh->setValue(Preferences::getRefreshInterval()); + spin_list_refresh->setValue(pref.getRefreshInterval()); spin_list_refresh->setSuffix(tr(" ms", " milliseconds")); setCellWidget(LIST_REFRESH, VALUE, spin_list_refresh); // Resolve Peer countries setItem(RESOLVE_COUNTRIES, PROPERTY, new QTableWidgetItem(tr("Resolve peer countries (GeoIP)"))); cb_resolve_countries = new QCheckBox(); connect(cb_resolve_countries, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_resolve_countries->setChecked(Preferences::resolvePeerCountries()); + cb_resolve_countries->setChecked(pref.resolvePeerCountries()); setCellWidget(RESOLVE_COUNTRIES, VALUE, cb_resolve_countries); // Resolve peer hosts setItem(RESOLVE_HOSTS, PROPERTY, new QTableWidgetItem(tr("Resolve peer host names"))); cb_resolve_hosts = new QCheckBox(); connect(cb_resolve_hosts, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_resolve_hosts->setChecked(Preferences::resolvePeerHostNames()); + cb_resolve_hosts->setChecked(pref.resolvePeerHostNames()); setCellWidget(RESOLVE_HOSTS, VALUE, cb_resolve_hosts); // Max Half Open connections setItem(MAX_HALF_OPEN, PROPERTY, new QTableWidgetItem(tr("Maximum number of half-open connections [0: Disabled]"))); @@ -166,14 +168,14 @@ protected slots: connect(spin_maxhalfopen, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged())); spin_maxhalfopen->setMinimum(0); spin_maxhalfopen->setMaximum(99999); - spin_maxhalfopen->setValue(Preferences::getMaxHalfOpenConnections()); + spin_maxhalfopen->setValue(pref.getMaxHalfOpenConnections()); setCellWidget(MAX_HALF_OPEN, VALUE, spin_maxhalfopen); // Super seeding setItem(SUPER_SEEDING, PROPERTY, new QTableWidgetItem(tr("Strict super seeding"))); cb_super_seeding = new QCheckBox(); connect(cb_super_seeding, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); #if LIBTORRENT_VERSION_MINOR > 14 - cb_super_seeding->setChecked(Preferences::isSuperSeedingEnabled()); + cb_super_seeding->setChecked(pref.isSuperSeedingEnabled()); #else cb_super_seeding->setEnabled(false); #endif @@ -182,7 +184,7 @@ protected slots: setItem(NETWORK_IFACE, PROPERTY, new QTableWidgetItem(tr("Network Interface (requires restart)"))); combo_iface = new QComboBox; combo_iface->addItem(tr("Any interface", "i.e. Any network interface")); - const QString current_iface = Preferences::getNetworkInterface(); + const QString current_iface = pref.getNetworkInterface(); int i = 1; foreach(const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) { if(iface.name() == "lo") continue; @@ -197,13 +199,13 @@ protected slots: setItem(PROGRAM_NOTIFICATIONS, PROPERTY, new QTableWidgetItem(tr("Display program notification balloons"))); cb_program_notifications = new QCheckBox(); connect(cb_program_notifications, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_program_notifications->setChecked(Preferences::useProgramNotification()); + cb_program_notifications->setChecked(pref.useProgramNotification()); setCellWidget(PROGRAM_NOTIFICATIONS, VALUE, cb_program_notifications); // Tracker State setItem(TRACKER_STATUS, PROPERTY, new QTableWidgetItem(tr("Enable embedded tracker"))); cb_tracker_status = new QCheckBox(); connect(cb_tracker_status, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged())); - cb_tracker_status->setChecked(Preferences::isTrackerEnabled()); + cb_tracker_status->setChecked(pref.isTrackerEnabled()); setCellWidget(TRACKER_STATUS, VALUE, cb_tracker_status); // Tracker port setItem(TRACKER_PORT, PROPERTY, new QTableWidgetItem(tr("Embedded tracker port"))); @@ -211,7 +213,7 @@ protected slots: connect(spin_tracker_port, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged())); spin_tracker_port->setMinimum(1); spin_tracker_port->setMaximum(65535); - spin_tracker_port->setValue(Preferences::getTrackerPort()); + spin_tracker_port->setValue(pref.getTrackerPort()); setCellWidget(TRACKER_PORT, VALUE, spin_tracker_port); } diff --git a/src/deletionconfirmationdlg.h b/src/deletionconfirmationdlg.h index 4490c8302..c0fa2df25 100644 --- a/src/deletionconfirmationdlg.h +++ b/src/deletionconfirmationdlg.h @@ -43,7 +43,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { DeletionConfirmationDlg(QWidget *parent=0): QDialog(parent) { setupUi(this); move(misc::screenCenter(this)); - checkPermDelete->setChecked(Preferences::deleteTorrentFilesAsDefault()); + checkPermDelete->setChecked(Preferences().deleteTorrentFilesAsDefault()); connect(checkPermDelete, SIGNAL(clicked()), this, SLOT(updateRememberButtonState())); buttonBox->setFocus(); } @@ -63,11 +63,11 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { private slots: void updateRememberButtonState() { - rememberBtn->setEnabled(checkPermDelete->isChecked() != Preferences::deleteTorrentFilesAsDefault()); + rememberBtn->setEnabled(checkPermDelete->isChecked() != Preferences().deleteTorrentFilesAsDefault()); } void on_rememberBtn_clicked() { - Preferences::setDeleteTorrentFilesAsDefault(checkPermDelete->isChecked()); + Preferences().setDeleteTorrentFilesAsDefault(checkPermDelete->isChecked()); rememberBtn->setEnabled(false); } }; diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index 9b6a0518c..b36fea8e5 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -37,6 +37,7 @@ #include "downloadthread.h" #include "preferences.h" +#include "rsssettings.h" #include "qinisettings.h" /** Download Thread **/ @@ -99,7 +100,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) { } void downloadThread::loadCookies(const QString &host_name, QString url) { - const QList raw_cookies = Preferences::getHostNameCookies(host_name); + const QList raw_cookies = RssSettings::getHostNameCookies(host_name); QNetworkCookieJar *cookie_jar = networkManager.cookieJar(); QList cookies; qDebug("Loading cookies for host name: %s", qPrintable(host_name)); diff --git a/src/headlessloader.h b/src/headlessloader.h index ccd6b215d..ee74d20aa 100644 --- a/src/headlessloader.h +++ b/src/headlessloader.h @@ -41,8 +41,9 @@ class HeadlessLoader: public QObject { public: HeadlessLoader(QStringList torrentCmdLine) { + Preferences pref; // Enable Web UI - Preferences::setWebUiEnabled(true); + pref.setWebUiEnabled(true); // Instanciate Bittorrent Object BTSession = QBtSession::instance(); connect(BTSession, SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString))); @@ -52,9 +53,9 @@ public: processParams(torrentCmdLine); // Display some information to the user std::cout << std::endl << "******** " << qPrintable(tr("Information")) << " ********" << std::endl; - std::cout << qPrintable(tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(Preferences::getWebUiPort()))) << std::endl; - std::cout << qPrintable(tr("The Web UI administrator user name is: %1").arg(Preferences::getWebUiUsername())) << std::endl; - if(Preferences::getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { + std::cout << qPrintable(tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(pref.getWebUiPort()))) << std::endl; + std::cout << qPrintable(tr("The Web UI administrator user name is: %1").arg(pref.getWebUiUsername())) << std::endl; + if(pref.getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { std::cout << qPrintable(tr("The Web UI administrator password is still the default one: %1").arg("adminadmin")) << std::endl; std::cout << qPrintable(tr("This is a security risk, please consider changing your password from program preferences.")) << std::endl; } diff --git a/src/main.cpp b/src/main.cpp index a33bc610a..a9a31ad48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,7 +74,7 @@ public: std::cout << '\t' << prg_name << " --no-splash: " << qPrintable(tr("disable splash screen")) << std::endl; #endif std::cout << '\t' << prg_name << " --help: " << qPrintable(tr("displays this help message")) << std::endl; - std::cout << '\t' << prg_name << " --webui-port=x: " << qPrintable(tr("changes the webui port (current: %1)").arg(QString::number(Preferences::getWebUiPort()))) << std::endl; + std::cout << '\t' << prg_name << " --webui-port=x: " << qPrintable(tr("changes the webui port (current: %1)").arg(QString::number(Preferences().getWebUiPort()))) << std::endl; std::cout << '\t' << prg_name << " " << qPrintable(tr("[files or urls]: downloads the torrents passed by the user (optional)")) << std::endl; } }; @@ -154,7 +154,7 @@ void useStyle(QString style){ if(!style.isEmpty()) { QApplication::setStyle(QStyleFactory::create(style)); } - Preferences::setStyle(QApplication::style()->objectName()); + Preferences().setStyle(QApplication::style()->objectName()); } #endif @@ -240,7 +240,7 @@ int main(int argc, char *argv[]){ bool ok = false; int new_port = parts.last().toInt(&ok); if(ok && new_port > 0 && new_port <= 65535) { - Preferences::setWebUiPort(new_port); + Preferences().setWebUiPort(new_port); } } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 644fbfab1..8b8f4508c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -93,9 +93,10 @@ using namespace libtorrent; // Constructor MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), force_exit(false) { setupUi(this); - ui_locked = Preferences::isUILocked(); + Preferences pref; + ui_locked = pref.isUILocked(); setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION))); - displaySpeedInTitle = Preferences::speedInTitleBar(); + displaySpeedInTitle = pref.speedInTitleBar(); // Clean exit on log out connect(static_cast(qApp), SIGNAL(sessionIsShuttingDown()), this, SLOT(deleteBTSession())); // Setting icons @@ -204,14 +205,14 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo #endif // View settings - actionTop_tool_bar->setChecked(Preferences::isToolbarDisplayed()); - actionSpeed_in_title_bar->setChecked(Preferences::speedInTitleBar()); + actionTop_tool_bar->setChecked(pref.isToolbarDisplayed()); + actionSpeed_in_title_bar->setChecked(pref.speedInTitleBar()); actionRSS_Reader->setChecked(RssSettings::isRSSEnabled()); - actionSearch_engine->setChecked(Preferences::isSearchEnabled()); + actionSearch_engine->setChecked(pref.isSearchEnabled()); displaySearchTab(actionSearch_engine->isChecked()); displayRSSTab(actionRSS_Reader->isChecked()); - actionShutdown_when_downloads_complete->setChecked(Preferences::shutdownWhenDownloadsComplete()); - actionShutdown_qBittorrent_when_downloads_complete->setChecked(Preferences::shutdownqBTWhenDownloadsComplete()); + actionShutdown_when_downloads_complete->setChecked(pref.shutdownWhenDownloadsComplete()); + actionShutdown_qBittorrent_when_downloads_complete->setChecked(pref.shutdownqBTWhenDownloadsComplete()); show(); @@ -225,7 +226,7 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo if(ui_locked) { hide(); } else { - if(Preferences::startMinimized()) + if(pref.startMinimized()) showMinimized(); } @@ -244,13 +245,13 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo qDebug("GUI Built"); #ifdef Q_WS_WIN - if(!Preferences::neverCheckFileAssoc() && !Preferences::isFileAssocOk()) { + if(!pref.neverCheckFileAssoc() && !Preferences::isFileAssocOk()) { if(QMessageBox::question(0, tr("Torrent file association"), tr("qBittorrent is not the default application to open torrent files or Magnet links.\nDo you want to associate qBittorrent to torrent files and Magnet links?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { Preferences::setFileAssoc(); } else { - Preferences::setNeverCheckFileAssoc(); + pref.setNeverCheckFileAssoc(); } } #endif @@ -338,30 +339,31 @@ MainWindow::~MainWindow() { } void MainWindow::defineUILockPassword() { - QString old_pass_md5 = Preferences::getUILockPasswordMD5(); + QString old_pass_md5 = Preferences().getUILockPasswordMD5(); if(old_pass_md5.isNull()) old_pass_md5 = ""; bool ok = false; QString new_clear_password = QInputDialog::getText(this, tr("UI lock password"), tr("Please type the UI lock password:"), QLineEdit::Password, old_pass_md5, &ok); if(ok) { if(new_clear_password != old_pass_md5) { - Preferences::setUILockPassword(new_clear_password); + Preferences().setUILockPassword(new_clear_password); } QMessageBox::information(this, tr("Password update"), tr("The UI lock password has been successfully updated")); } } void MainWindow::on_actionLock_qBittorrent_triggered() { + Preferences pref; // Check if there is a password - if(Preferences::getUILockPasswordMD5().isEmpty()) { + if(pref.getUILockPasswordMD5().isEmpty()) { // Ask for a password bool ok = false; QString clear_password = QInputDialog::getText(this, tr("UI lock password"), tr("Please type the UI lock password:"), QLineEdit::Password, "", &ok); if(!ok) return; - Preferences::setUILockPassword(clear_password); + pref.setUILockPassword(clear_password); } // Lock the interface ui_locked = true; - Preferences::setUILocked(true); + pref.setUILocked(true); myTrayIconMenu->setEnabled(false); hide(); } @@ -527,7 +529,8 @@ void MainWindow::balloonClicked() { } void MainWindow::askRecursiveTorrentDownloadConfirmation(QTorrentHandle &h) { - if(Preferences::recursiveDownloadDisabled()) return; + Preferences pref; + if(pref.recursiveDownloadDisabled()) return; QMessageBox confirmBox(QMessageBox::Question, tr("Recursive download confirmation"), tr("The torrent %1 contains torrent files, do you want to proceed with their download?").arg(h.name())); QPushButton *yes = confirmBox.addButton(tr("Yes"), QMessageBox::YesRole); /*QPushButton *no = */confirmBox.addButton(tr("No"), QMessageBox::NoRole); @@ -539,7 +542,7 @@ void MainWindow::askRecursiveTorrentDownloadConfirmation(QTorrentHandle &h) { return; } if(confirmBox.clickedButton() == never) { - Preferences::disableRecursiveDownload(); + pref.disableRecursiveDownload(); } } @@ -556,9 +559,9 @@ void MainWindow::on_actionSet_global_upload_limit_triggered() { qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); BTSession->getSession()->set_upload_rate_limit(new_limit); if(new_limit <= 0) - Preferences::setGlobalUploadLimit(-1); + Preferences().setGlobalUploadLimit(-1); else - Preferences::setGlobalUploadLimit(new_limit/1024.); + Preferences().setGlobalUploadLimit(new_limit/1024.); } } @@ -578,9 +581,9 @@ void MainWindow::on_actionSet_global_download_limit_triggered() { qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); BTSession->getSession()->set_download_rate_limit(new_limit); if(new_limit <= 0) - Preferences::setGlobalDownloadLimit(-1); + Preferences().setGlobalDownloadLimit(-1); else - Preferences::setGlobalDownloadLimit(new_limit/1024.); + Preferences().setGlobalDownloadLimit(new_limit/1024.); } } @@ -607,13 +610,14 @@ bool MainWindow::unlockUI() { bool ok = false; QString clear_password = QInputDialog::getText(this, tr("UI lock password"), tr("Please type the UI lock password:"), QLineEdit::Password, "", &ok); if(!ok) return false; - QString real_pass_md5 = Preferences::getUILockPasswordMD5(); + Preferences pref; + QString real_pass_md5 = pref.getUILockPasswordMD5(); QCryptographicHash md5(QCryptographicHash::Md5); md5.addData(clear_password.toLocal8Bit()); QString password_md5 = md5.result().toHex(); if(real_pass_md5 == password_md5) { ui_locked = false; - Preferences::setUILocked(false); + pref.setUILocked(false); myTrayIconMenu->setEnabled(true); return true; } @@ -701,7 +705,7 @@ void MainWindow::closeEvent(QCloseEvent *e) { } if(confirmBox.clickedButton() == alwaysBtn) { // Remember choice - Preferences::setConfirmOnExit(false); + Preferences().setConfirmOnExit(false); } } } @@ -734,8 +738,7 @@ bool MainWindow::event(QEvent * e) { //Now check to see if the window is minimised if(isMinimized()) { qDebug("minimisation"); - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - if(systrayIcon && settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool()) { + if(systrayIcon && Preferences().minimizeToTray()) { qDebug("Has active window: %d", (int)(qApp->activeWindow() != 0)); // Check if there is a modal window bool has_modal_window = false; @@ -763,7 +766,7 @@ bool MainWindow::event(QEvent * e) { qDebug("MAC: new toolbar visibility is %d", !actionTop_tool_bar->isChecked()); actionTop_tool_bar->toggle(); - Preferences::setToolbarDisplayed(actionTop_tool_bar->isChecked()); + Preferences().setToolbarDisplayed(actionTop_tool_bar->isChecked()); return ret; } #endif @@ -923,7 +926,8 @@ void MainWindow::optionsSaved() { // Load program preferences void MainWindow::loadPreferences(bool configure_session) { BTSession->addConsoleMessage(tr("Options were saved successfully.")); - const bool newSystrayIntegration = Preferences::systrayIntegration(); + const Preferences pref; + const bool newSystrayIntegration = pref.systrayIntegration(); actionLock_qBittorrent->setEnabled(newSystrayIntegration); if(newSystrayIntegration != (systrayIcon!=0)) { if(newSystrayIntegration) { @@ -948,7 +952,7 @@ void MainWindow::loadPreferences(bool configure_session) { } } // General - if(Preferences::isToolbarDisplayed()) { + if(pref.isToolbarDisplayed()) { toolBar->setVisible(true); toolBar->layout()->setSpacing(7); } else { @@ -956,14 +960,14 @@ void MainWindow::loadPreferences(bool configure_session) { search_filter->clear(); toolBar->setVisible(false); } - const uint new_refreshInterval = Preferences::getRefreshInterval(); + const uint new_refreshInterval = pref.getRefreshInterval(); transferList->setRefreshInterval(new_refreshInterval); - transferList->setAlternatingRowColors(Preferences::useAlternatingRowColors()); - properties->getFilesList()->setAlternatingRowColors(Preferences::useAlternatingRowColors()); - properties->getTrackerList()->setAlternatingRowColors(Preferences::useAlternatingRowColors()); - properties->getPeerList()->setAlternatingRowColors(Preferences::useAlternatingRowColors()); + transferList->setAlternatingRowColors(pref.useAlternatingRowColors()); + properties->getFilesList()->setAlternatingRowColors(pref.useAlternatingRowColors()); + properties->getTrackerList()->setAlternatingRowColors(pref.useAlternatingRowColors()); + properties->getPeerList()->setAlternatingRowColors(pref.useAlternatingRowColors()); // Queueing System - if(Preferences::isQueueingSystemEnabled()) { + if(pref.isQueueingSystemEnabled()) { if(!actionDecreasePriority->isVisible()) { transferList->hidePriorityColumn(false); actionDecreasePriority->setVisible(true); @@ -1035,7 +1039,7 @@ void MainWindow::updateGUI() { } void MainWindow::showNotificationBaloon(QString title, QString msg) const { - if(!Preferences::useProgramNotification()) return; + if(!Preferences().useProgramNotification()) return; #ifdef WITH_LIBNOTIFY if (notify_init ("summary-body")) { NotifyNotification* notification; @@ -1108,7 +1112,7 @@ void MainWindow::createSystrayDelayed() { delete systrayCreator; // Disable it in program preferences to // avoid trying at earch startup - Preferences::setSystrayIntegration(false); + Preferences().setSystrayIntegration(false); } } } @@ -1125,8 +1129,9 @@ QMenu* MainWindow::getTrayIconMenu() { myTrayIconMenu->addAction(actionOpen); myTrayIconMenu->addAction(actionDownload_from_URL); myTrayIconMenu->addSeparator(); - updateAltSpeedsBtn(Preferences::isAltBandwidthEnabled()); - actionUse_alternative_speed_limits->setChecked(Preferences::isAltBandwidthEnabled()); + const bool isAltBWEnabled = Preferences().isAltBandwidthEnabled(); + updateAltSpeedsBtn(isAltBWEnabled); + actionUse_alternative_speed_limits->setChecked(isAltBWEnabled); myTrayIconMenu->addAction(actionUse_alternative_speed_limits); myTrayIconMenu->addAction(actionSet_global_download_limit); myTrayIconMenu->addAction(actionSet_global_upload_limit); @@ -1169,22 +1174,22 @@ void MainWindow::on_actionOptions_triggered() { void MainWindow::on_actionTop_tool_bar_triggered() { bool is_visible = static_cast(sender())->isChecked(); toolBar->setVisible(is_visible); - Preferences::setToolbarDisplayed(is_visible); + Preferences().setToolbarDisplayed(is_visible); } void MainWindow::on_actionShutdown_when_downloads_complete_triggered() { bool is_checked = static_cast(sender())->isChecked(); - Preferences::setShutdownWhenDownloadsComplete(is_checked); + Preferences().setShutdownWhenDownloadsComplete(is_checked); } void MainWindow::on_actionShutdown_qBittorrent_when_downloads_complete_triggered() { bool is_checked = static_cast(sender())->isChecked(); - Preferences::setShutdownqBTWhenDownloadsComplete(is_checked); + Preferences().setShutdownqBTWhenDownloadsComplete(is_checked); } void MainWindow::on_actionSpeed_in_title_bar_triggered() { displaySpeedInTitle = static_cast(sender())->isChecked(); - Preferences::showSpeedInTitleBar(displaySpeedInTitle); + Preferences().showSpeedInTitleBar(displaySpeedInTitle); if(displaySpeedInTitle) updateGUI(); else @@ -1197,7 +1202,7 @@ void MainWindow::on_actionRSS_Reader_triggered() { } void MainWindow::on_actionSearch_engine_triggered() { - Preferences::setSearchEnabled(actionSearch_engine->isChecked()); + Preferences().setSearchEnabled(actionSearch_engine->isChecked()); displaySearchTab(actionSearch_engine->isChecked()); } diff --git a/src/options_imp.cpp b/src/options_imp.cpp index f8d69a49d..81324d017 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -346,12 +346,12 @@ QSize options_imp::sizeFittingScreen() { void options_imp::saveOptions(){ applyButton->setEnabled(false); - QIniSettings settings("qBittorrent", "qBittorrent"); + Preferences pref; // Apply style useStyle(); // Load the translation QString locale = getLocale(); - if(Preferences::getLocale() != locale) { + if(pref.getLocale() != locale) { QTranslator *translator = new QTranslator; if(translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){ qDebug("%s locale recognized, using translation.", qPrintable(locale)); @@ -361,149 +361,117 @@ void options_imp::saveOptions(){ qApp->installTranslator(translator); } - settings.beginGroup("Preferences"); // General preferences - settings.beginGroup("General"); - settings.setValue(QString::fromUtf8("Locale"), locale); - settings.setValue(QString::fromUtf8("Style"), getStyle()); - settings.setValue(QString::fromUtf8("AlternatingRowColors"), checkAltRowColors->isChecked()); - settings.setValue(QString::fromUtf8("SystrayEnabled"), systrayIntegration()); - settings.setValue(QString::fromUtf8("CloseToTray"), closeToTray()); - settings.setValue(QString::fromUtf8("MinimizeToTray"), minimizeToTray()); - settings.setValue(QString::fromUtf8("StartMinimized"), startMinimized()); - settings.setValue(QString::fromUtf8("NoSplashScreen"), isSlashScreenDisabled()); + pref.setLocale(locale); + pref.setStyle(getStyle()); + pref.setAlternatingRowColors(checkAltRowColors->isChecked()); + pref.setSystrayIntegration(systrayIntegration()); + pref.setCloseToTray(closeToTray()); + pref.setMinimizeToTray(minimizeToTray()); + pref.setStartMinimized(startMinimized()); + pref.setSplashScreenDisabled(isSlashScreenDisabled()); // End General preferences - settings.endGroup(); + // Downloads preferences - settings.beginGroup("Downloads"); QString save_path = getSavePath(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) save_path = save_path.replace("\\", "/"); #endif - settings.setValue(QString::fromUtf8("SavePath"), save_path); - settings.setValue(QString::fromUtf8("TempPathEnabled"), isTempPathEnabled()); + pref.setSavePath(save_path); + pref.setTempPathEnabled(isTempPathEnabled()); QString temp_path = getTempPath(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) temp_path = temp_path.replace("\\", "/"); #endif - settings.setValue(QString::fromUtf8("TempPath"), temp_path); - settings.setValue(QString::fromUtf8("AppendLabel"), checkAppendLabel->isChecked()); + pref.setTempPath(temp_path); + pref.setAppendTorrentLabel(checkAppendLabel->isChecked()); #if LIBTORRENT_VERSION_MINOR > 14 - settings.setValue(QString::fromUtf8("UseIncompleteExtension"), checkAppendqB->isChecked()); + pref.useIncompleteFilesExtension(checkAppendqB->isChecked()); #endif - settings.setValue(QString::fromUtf8("PreAllocation"), preAllocateAllFiles()); - settings.setValue(QString::fromUtf8("AdditionDialog"), useAdditionDialog()); - settings.setValue(QString::fromUtf8("StartInPause"), addTorrentsInPause()); - ScanFoldersModel::instance()->makePersistent(settings); + pref.preAllocateAllFiles(preAllocateAllFiles()); + pref.useAdditionDialog(useAdditionDialog()); + pref.addTorrentsInPause(addTorrentsInPause()); + ScanFoldersModel::instance()->makePersistent(pref); addedScanDirs.clear(); QString export_dir = getExportDir(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) export_dir = export_dir.replace("\\", "/"); #endif - Preferences::setExportDir(export_dir); - Preferences::setMailNotificationEnabled(groupMailNotification->isChecked()); - Preferences::setMailNotificationEmail(dest_email_txt->text()); - Preferences::setMailNotificationSMTP(smtp_server_txt->text()); - Preferences::setAutoRunEnabled(autoRunBox->isChecked()); - Preferences::setAutoRunProgram(autoRun_txt->text()); - settings.setValue(QString::fromUtf8("DblClOnTorDl"), getActionOnDblClOnTorrentDl()); - settings.setValue(QString::fromUtf8("DblClOnTorFn"), getActionOnDblClOnTorrentFn()); + pref.setExportDir(export_dir); + pref.setMailNotificationEnabled(groupMailNotification->isChecked()); + pref.setMailNotificationEmail(dest_email_txt->text()); + pref.setMailNotificationSMTP(smtp_server_txt->text()); + pref.setAutoRunEnabled(autoRunBox->isChecked()); + pref.setAutoRunProgram(autoRun_txt->text()); + pref.setActionOnDblClOnTorrentDl(getActionOnDblClOnTorrentDl()); + pref.setActionOnDblClOnTorrentFn(getActionOnDblClOnTorrentFn()); // End Downloads preferences - settings.endGroup(); // Connection preferences - settings.beginGroup("Connection"); - settings.setValue(QString::fromUtf8("PortRangeMin"), getPort()); - settings.setValue(QString::fromUtf8("UPnP"), isUPnPEnabled()); - settings.setValue(QString::fromUtf8("NAT-PMP"), isNATPMPEnabled()); - settings.setValue(QString::fromUtf8("GlobalDLLimit"), getGlobalBandwidthLimits().first); - settings.setValue(QString::fromUtf8("GlobalUPLimit"), getGlobalBandwidthLimits().second); - Preferences::setAltGlobalDownloadLimit(spinDownloadLimitAlt->value()); - Preferences::setAltGlobalUploadLimit(spinUploadLimitAlt->value()); - Preferences::setSchedulerEnabled(check_schedule->isChecked()); - Preferences::setSchedulerStartTime(schedule_from->time()); - Preferences::setSchedulerEndTime(schedule_to->time()); - Preferences::setSchedulerDays((scheduler_days)schedule_days->currentIndex()); - settings.setValue(QString::fromUtf8("ProxyType"), getPeerProxyType()); - //if(isProxyEnabled()) { - settings.beginGroup("Proxy"); - // Proxy is enabled, save settings - settings.setValue(QString::fromUtf8("IP"), getPeerProxyIp()); - settings.setValue(QString::fromUtf8("Port"), getPeerProxyPort()); - settings.setValue(QString::fromUtf8("Authentication"), isPeerProxyAuthEnabled()); - //if(isProxyAuthEnabled()) { - // Credentials - settings.setValue(QString::fromUtf8("Username"), getPeerProxyUsername()); - settings.setValue(QString::fromUtf8("Password"), getPeerProxyPassword()); - //} - settings.endGroup(); // End Proxy - //} - settings.setValue(QString::fromUtf8("HTTPProxyType"), getHTTPProxyType()); - //if(isHTTPProxyEnabled()) { - settings.beginGroup("HTTPProxy"); - // Proxy is enabled, save settings - settings.setValue(QString::fromUtf8("IP"), getHTTPProxyIp()); - settings.setValue(QString::fromUtf8("Port"), getHTTPProxyPort()); - settings.setValue(QString::fromUtf8("Authentication"), isHTTPProxyAuthEnabled()); - //if(isHTTPProxyAuthEnabled()) { - // Credentials - settings.setValue(QString::fromUtf8("Username"), getHTTPProxyUsername()); - settings.setValue(QString::fromUtf8("Password"), getHTTPProxyPassword()); - //} - settings.endGroup(); // End HTTPProxy - //} + pref.setSessionPort(getPort()); + pref.setUPnPEnabled(isUPnPEnabled()); + pref.setNATPMPEnabled(isNATPMPEnabled()); + pref.setGlobalDownloadLimit(getGlobalBandwidthLimits().first); + pref.setGlobalUploadLimit(getGlobalBandwidthLimits().second); + pref.setAltGlobalDownloadLimit(spinDownloadLimitAlt->value()); + pref.setAltGlobalUploadLimit(spinUploadLimitAlt->value()); + pref.setSchedulerEnabled(check_schedule->isChecked()); + pref.setSchedulerStartTime(schedule_from->time()); + pref.setSchedulerEndTime(schedule_to->time()); + pref.setSchedulerDays((scheduler_days)schedule_days->currentIndex()); + pref.setPeerProxyType(getPeerProxyType()); + pref.setPeerProxyIp(getPeerProxyIp()); + pref.setPeerProxyPort(getPeerProxyPort()); + pref.setPeerProxyAuthEnabled(isPeerProxyAuthEnabled()); + pref.setPeerProxyUsername(getPeerProxyUsername()); + pref.setPeerProxyPassword(getPeerProxyPassword()); + pref.setHTTPProxyType(getHTTPProxyType()); + pref.setHTTPProxyIp(getHTTPProxyIp()); + pref.setHTTPProxyPort(getHTTPProxyPort()); + pref.setHTTPProxyAuthEnabled(isHTTPProxyAuthEnabled()); + pref.setHTTPProxyUsername(getHTTPProxyUsername()); + pref.setHTTPProxyPassword(getHTTPProxyPassword()); // End Connection preferences - settings.endGroup(); // Bittorrent preferences - settings.beginGroup("Bittorrent"); - settings.setValue(QString::fromUtf8("MaxConnecs"), getMaxConnecs()); - settings.setValue(QString::fromUtf8("MaxConnecsPerTorrent"), getMaxConnecsPerTorrent()); - settings.setValue(QString::fromUtf8("MaxUploadsPerTorrent"), getMaxUploadsPerTorrent()); - settings.setValue(QString::fromUtf8("DHT"), isDHTEnabled()); - settings.setValue(QString::fromUtf8("PeX"), checkPeX->isChecked()); - settings.setValue(QString::fromUtf8("sameDHTPortAsBT"), isDHTPortSameAsBT()); - settings.setValue(QString::fromUtf8("DHTPort"), getDHTPort()); - settings.setValue(QString::fromUtf8("LSD"), isLSDEnabled()); - settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting()); - Preferences::setMaxRatio(getMaxRatio()); - Preferences::setMaxRatioAction(comboRatioLimitAct->currentIndex()); + pref.setMaxConnecs(getMaxConnecs()); + pref.setMaxConnecsPerTorrent(getMaxConnecsPerTorrent()); + pref.setMaxUploadsPerTorrent(getMaxUploadsPerTorrent()); + pref.setDHTEnabled(isDHTEnabled()); + pref.setPeXEnabled(checkPeX->isChecked()); + pref.setDHTPortSameAsBT(isDHTPortSameAsBT()); + pref.setDHTPort(getDHTPort()); + pref.setLSDEnabled(isLSDEnabled()); + pref.setEncryptionSetting(getEncryptionSetting()); + pref.setMaxRatio(getMaxRatio()); + pref.setMaxRatioAction(comboRatioLimitAct->currentIndex()); // End Bittorrent preferences - settings.endGroup(); // Misc preferences // * IPFilter - settings.beginGroup("IPFilter"); - settings.setValue(QString::fromUtf8("Enabled"), isFilteringEnabled()); + pref.setFilteringEnabled(isFilteringEnabled()); if(isFilteringEnabled()){ QString filter_path = textFilterPath->text(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) filter_path = filter_path.replace("\\", "/"); #endif - settings.setValue(QString::fromUtf8("File"), filter_path); + pref.setFilter(filter_path); } // End IPFilter preferences - settings.endGroup(); // Queueing system - settings.beginGroup("Queueing"); - settings.setValue(QString::fromUtf8("QueueingEnabled"), isQueueingSystemEnabled()); - settings.setValue(QString::fromUtf8("MaxActiveDownloads"), spinMaxActiveDownloads->value()); - settings.setValue(QString::fromUtf8("MaxActiveUploads"), spinMaxActiveUploads->value()); - settings.setValue(QString::fromUtf8("MaxActiveTorrents"), spinMaxActiveTorrents->value()); + pref.setQueueingSystemEnabled(isQueueingSystemEnabled()); + pref.setMaxActiveDownloads(spinMaxActiveDownloads->value()); + pref.setMaxActiveUploads(spinMaxActiveUploads->value()); + pref.setMaxActiveTorrents(spinMaxActiveTorrents->value()); // End Queueing system preferences - settings.endGroup(); // Web UI - settings.beginGroup("WebUI"); - settings.setValue("Enabled", isWebUiEnabled()); + pref.setWebUiEnabled(isWebUiEnabled()); if(isWebUiEnabled()) { - settings.setValue("Port", webUiPort()); - settings.setValue("Username", webUiUsername()); + pref.setWebUiPort(webUiPort()); + pref.setWebUiUsername(webUiUsername()); // FIXME: Check that the password is valid (not empty at least) - Preferences::setWebUiPassword(webUiPassword()); + pref.setWebUiPassword(webUiPassword()); } // End Web UI - settings.endGroup(); // End preferences - settings.endGroup(); - // Save advanced settings advancedSettings->saveAdvancedSettings(); } @@ -570,46 +538,47 @@ void options_imp::loadOptions(){ float floatValue; QString strValue; // General preferences - setLocale(Preferences::getLocale()); - setStyle(Preferences::getStyle()); - checkAltRowColors->setChecked(Preferences::useAlternatingRowColors()); - checkShowSystray->setChecked(Preferences::systrayIntegration()); - checkShowSplash->setChecked(!Preferences::isSlashScreenDisabled()); + const Preferences pref; + setLocale(pref.getLocale()); + setStyle(pref.getStyle()); + checkAltRowColors->setChecked(pref.useAlternatingRowColors()); + checkShowSystray->setChecked(pref.systrayIntegration()); + checkShowSplash->setChecked(!pref.isSlashScreenDisabled()); if(!checkShowSystray->isChecked()) { disableSystrayOptions(); } else { enableSystrayOptions(); - checkCloseToSystray->setChecked(Preferences::closeToTray()); - checkMinimizeToSysTray->setChecked(Preferences::minimizeToTray()); - checkStartMinimized->setChecked(Preferences::startMinimized()); + checkCloseToSystray->setChecked(pref.closeToTray()); + checkMinimizeToSysTray->setChecked(pref.minimizeToTray()); + checkStartMinimized->setChecked(pref.startMinimized()); } // End General preferences // Downloads preferences - QString save_path = Preferences::getSavePath(); + QString save_path = pref.getSavePath(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) save_path = save_path.replace("/", "\\"); #endif textSavePath->setText(save_path); - if(Preferences::isTempPathEnabled()) { + if(pref.isTempPathEnabled()) { // enable checkTempFolder->setChecked(true); } else { checkTempFolder->setChecked(false); } - QString temp_path = Preferences::getTempPath(); + QString temp_path = pref.getTempPath(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) temp_path = temp_path.replace("/", "\\"); #endif textTempPath->setText(temp_path); - checkAppendLabel->setChecked(Preferences::appendTorrentLabel()); + checkAppendLabel->setChecked(pref.appendTorrentLabel()); #if LIBTORRENT_VERSION_MINOR > 14 - checkAppendqB->setChecked(Preferences::useIncompleteFilesExtension()); + checkAppendqB->setChecked(pref.useIncompleteFilesExtension()); #endif - checkPreallocateAll->setChecked(Preferences::preAllocateAllFiles()); - checkAdditionDialog->setChecked(Preferences::useAdditionDialog()); - checkStartPaused->setChecked(Preferences::addTorrentsInPause()); + checkPreallocateAll->setChecked(pref.preAllocateAllFiles()); + checkAdditionDialog->setChecked(pref.useAdditionDialog()); + checkStartPaused->setChecked(pref.addTorrentsInPause()); - strValue = Preferences::getExportDir(); + strValue = pref.getExportDir(); if(strValue.isEmpty()) { // Disable checkExportDir->setChecked(false); @@ -621,25 +590,25 @@ void options_imp::loadOptions(){ #endif textExportDir->setText(strValue); } - groupMailNotification->setChecked(Preferences::isMailNotificationEnabled()); - dest_email_txt->setText(Preferences::getMailNotificationEmail()); - smtp_server_txt->setText(Preferences::getMailNotificationSMTP()); - autoRunBox->setChecked(Preferences::isAutoRunEnabled()); - autoRun_txt->setText(Preferences::getAutoRunProgram()); - intValue = Preferences::getActionOnDblClOnTorrentDl(); + groupMailNotification->setChecked(pref.isMailNotificationEnabled()); + dest_email_txt->setText(pref.getMailNotificationEmail()); + smtp_server_txt->setText(pref.getMailNotificationSMTP()); + autoRunBox->setChecked(pref.isAutoRunEnabled()); + autoRun_txt->setText(pref.getAutoRunProgram()); + intValue = pref.getActionOnDblClOnTorrentDl(); if(intValue >= actionTorrentDlOnDblClBox->count()) intValue = 0; actionTorrentDlOnDblClBox->setCurrentIndex(intValue); - intValue = Preferences::getActionOnDblClOnTorrentFn(); + intValue = pref.getActionOnDblClOnTorrentFn(); if(intValue >= actionTorrentFnOnDblClBox->count()) intValue = 1; actionTorrentFnOnDblClBox->setCurrentIndex(intValue); // End Downloads preferences // Connection preferences - spinPort->setValue(Preferences::getSessionPort()); - checkUPnP->setChecked(Preferences::isUPnPEnabled()); - checkNATPMP->setChecked(Preferences::isNATPMPEnabled()); - intValue = Preferences::getGlobalDownloadLimit(); + spinPort->setValue(pref.getSessionPort()); + checkUPnP->setChecked(pref.isUPnPEnabled()); + checkNATPMP->setChecked(pref.isNATPMPEnabled()); + intValue = pref.getGlobalDownloadLimit(); if(intValue > 0) { // Enabled checkDownloadLimit->setChecked(true); @@ -650,7 +619,7 @@ void options_imp::loadOptions(){ checkDownloadLimit->setChecked(false); spinDownloadLimit->setEnabled(false); } - intValue = Preferences::getGlobalUploadLimit(); + intValue = pref.getGlobalUploadLimit(); if(intValue != -1) { // Enabled checkUploadLimit->setChecked(true); @@ -661,15 +630,15 @@ void options_imp::loadOptions(){ checkUploadLimit->setChecked(false); spinUploadLimit->setEnabled(false); } - spinUploadLimitAlt->setValue(Preferences::getAltGlobalUploadLimit()); - spinDownloadLimitAlt->setValue(Preferences::getAltGlobalDownloadLimit()); + spinUploadLimitAlt->setValue(pref.getAltGlobalUploadLimit()); + spinDownloadLimitAlt->setValue(pref.getAltGlobalDownloadLimit()); // Scheduler - check_schedule->setChecked(Preferences::isSchedulerEnabled()); - schedule_from->setTime(Preferences::getSchedulerStartTime()); - schedule_to->setTime(Preferences::getSchedulerEndTime()); - schedule_days->setCurrentIndex((int)Preferences::getSchedulerDays()); + check_schedule->setChecked(pref.isSchedulerEnabled()); + schedule_from->setTime(pref.getSchedulerStartTime()); + schedule_to->setTime(pref.getSchedulerEndTime()); + schedule_days->setCurrentIndex((int)pref.getSchedulerDays()); - intValue = Preferences::getPeerProxyType(); + intValue = pref.getPeerProxyType(); switch(intValue) { case Proxy::SOCKS4: comboProxyType->setCurrentIndex(1); @@ -688,14 +657,14 @@ void options_imp::loadOptions(){ enablePeerProxy(comboProxyType->currentIndex()); //if(isProxyEnabled()) { // Proxy is enabled, save settings - textProxyIP->setText(Preferences::getPeerProxyIp()); - spinProxyPort->setValue(Preferences::getPeerProxyPort()); - checkProxyAuth->setChecked(Preferences::isPeerProxyAuthEnabled()); - textProxyUsername->setText(Preferences::getPeerProxyUsername()); - textProxyPassword->setText(Preferences::getPeerProxyPassword()); + textProxyIP->setText(pref.getPeerProxyIp()); + spinProxyPort->setValue(pref.getPeerProxyPort()); + checkProxyAuth->setChecked(pref.isPeerProxyAuthEnabled()); + textProxyUsername->setText(pref.getPeerProxyUsername()); + textProxyPassword->setText(pref.getPeerProxyPassword()); enablePeerProxyAuth(checkProxyAuth->isChecked()); //} - intValue = Preferences::getHTTPProxyType(); + intValue = pref.getHTTPProxyType(); switch(intValue) { case Proxy::HTTP: case Proxy::HTTP_PW: @@ -709,16 +678,16 @@ void options_imp::loadOptions(){ comboProxyType_http->setCurrentIndex(0); } enableHTTPProxy(comboProxyType_http->currentIndex()); - textProxyUsername_http->setText(Preferences::getHTTPProxyUsername()); - textProxyPassword_http->setText(Preferences::getHTTPProxyPassword()); - textProxyIP_http->setText(Preferences::getHTTPProxyIp()); - spinProxyPort_http->setValue(Preferences::getHTTPProxyPort()); - checkProxyAuth_http->setChecked(Preferences::isHTTPProxyAuthEnabled()); + textProxyUsername_http->setText(pref.getHTTPProxyUsername()); + textProxyPassword_http->setText(pref.getHTTPProxyPassword()); + textProxyIP_http->setText(pref.getHTTPProxyIp()); + spinProxyPort_http->setValue(pref.getHTTPProxyPort()); + checkProxyAuth_http->setChecked(pref.isHTTPProxyAuthEnabled()); enableHTTPProxyAuth(checkProxyAuth_http->isChecked()); // End HTTPProxy // End Connection preferences // Bittorrent preferences - intValue = Preferences::getMaxConnecs(); + intValue = pref.getMaxConnecs(); if(intValue > 0) { // enable checkMaxConnecs->setChecked(true); @@ -729,7 +698,7 @@ void options_imp::loadOptions(){ checkMaxConnecs->setChecked(false); spinMaxConnec->setEnabled(false); } - intValue = Preferences::getMaxConnecsPerTorrent(); + intValue = pref.getMaxConnecsPerTorrent(); if(intValue > 0) { // enable checkMaxConnecsPerTorrent->setChecked(true); @@ -740,7 +709,7 @@ void options_imp::loadOptions(){ checkMaxConnecsPerTorrent->setChecked(false); spinMaxConnecPerTorrent->setEnabled(false); } - intValue = Preferences::getMaxUploadsPerTorrent(); + intValue = pref.getMaxUploadsPerTorrent(); if(intValue > 0) { // enable checkMaxUploadsPerTorrent->setChecked(true); @@ -751,14 +720,14 @@ void options_imp::loadOptions(){ checkMaxUploadsPerTorrent->setChecked(false); spinMaxUploadsPerTorrent->setEnabled(false); } - checkDHT->setChecked(Preferences::isDHTEnabled()); - checkDifferentDHTPort->setChecked(!Preferences::isDHTPortSameAsBT()); - spinDHTPort->setValue(Preferences::getDHTPort()); - checkPeX->setChecked(Preferences::isPeXEnabled()); - checkLSD->setChecked(Preferences::isLSDEnabled()); - comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting()); + checkDHT->setChecked(pref.isDHTEnabled()); + checkDifferentDHTPort->setChecked(!pref.isDHTPortSameAsBT()); + spinDHTPort->setValue(pref.getDHTPort()); + checkPeX->setChecked(pref.isPeXEnabled()); + checkLSD->setChecked(pref.isLSDEnabled()); + comboEncryption->setCurrentIndex(pref.getEncryptionSetting()); // Ratio limit - floatValue = Preferences::getMaxRatio(); + floatValue = pref.getMaxRatio(); if(floatValue >= 0.) { // Enable checkMaxRatio->setChecked(true); @@ -771,24 +740,24 @@ void options_imp::loadOptions(){ spinMaxRatio->setEnabled(false); comboRatioLimitAct->setEnabled(false); } - comboRatioLimitAct->setCurrentIndex(Preferences::getMaxRatioAction()); + comboRatioLimitAct->setCurrentIndex(pref.getMaxRatioAction()); // End Bittorrent preferences // Misc preferences // * IP Filter - checkIPFilter->setChecked(Preferences::isFilteringEnabled()); - textFilterPath->setText(Preferences::getFilter()); + checkIPFilter->setChecked(pref.isFilteringEnabled()); + textFilterPath->setText(pref.getFilter()); // End IP Filter // Queueing system preferences - checkEnableQueueing->setChecked(Preferences::isQueueingSystemEnabled()); - spinMaxActiveDownloads->setValue(Preferences::getMaxActiveDownloads()); - spinMaxActiveUploads->setValue(Preferences::getMaxActiveUploads()); - spinMaxActiveTorrents->setValue(Preferences::getMaxActiveTorrents()); + checkEnableQueueing->setChecked(pref.isQueueingSystemEnabled()); + spinMaxActiveDownloads->setValue(pref.getMaxActiveDownloads()); + spinMaxActiveUploads->setValue(pref.getMaxActiveUploads()); + spinMaxActiveTorrents->setValue(pref.getMaxActiveTorrents()); // End Queueing system preferences // Web UI - checkWebUi->setChecked(Preferences::isWebUiEnabled()); - spinWebUiPort->setValue(Preferences::getWebUiPort()); - textWebUiUsername->setText(Preferences::getWebUiUsername()); - textWebUiPassword->setText(Preferences::getWebUiPassword()); + checkWebUi->setChecked(pref.isWebUiEnabled()); + spinWebUiPort->setValue(pref.getWebUiPort()); + textWebUiUsername->setText(pref.getWebUiUsername()); + textWebUiPassword->setText(pref.getWebUiPassword()); // End Web UI // Random stuff srand(time(0)); @@ -889,7 +858,7 @@ float options_imp::getMaxRatio() const{ // Return Save Path QString options_imp::getSavePath() const{ if(textSavePath->text().trimmed().isEmpty()){ - QString save_path = Preferences::getSavePath(); + QString save_path = Preferences().getSavePath(); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) save_path = save_path.replace("/", "\\"); #endif diff --git a/src/preferences.h b/src/preferences.h index 21760d459..925f23a93 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -58,767 +58,666 @@ namespace Proxy { enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5}; } -class Preferences { -private: - Preferences(); // Present instanciation +class Preferences : public QIniSettings { + Q_DISABLE_COPY(Preferences); + +public: + Preferences() : QIniSettings("qBittorrent", "qBittorrent") {} public: // General options - static QString getLocale() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString(); + QString getLocale() const { + return value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString(); } - static void setLocale(QString locale) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/Locale"), locale); + void setLocale(const QString &locale) { + setValue(QString::fromUtf8("Preferences/General/Locale"), locale); } - static QString getStyle() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/Style"), "").toString(); + QString getStyle() const { + return value(QString::fromUtf8("Preferences/General/Style"), "").toString(); } - static void setStyle(QString style) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/Style"), style); + void setStyle(const QString &style) { + setValue(QString::fromUtf8("Preferences/General/Style"), style); } - static bool useProgramNotification() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/ProgramNotification"), true).toBool(); + bool useProgramNotification() const { + return value(QString::fromUtf8("Preferences/General/ProgramNotification"), true).toBool(); } - static void useProgramNotification(bool use) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/ProgramNotification"), use); + void useProgramNotification(bool use) { + setValue(QString::fromUtf8("Preferences/General/ProgramNotification"), use); } - static bool deleteTorrentFilesAsDefault() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/DeleteTorrentsFilesAsDefault"), false).toBool(); + bool deleteTorrentFilesAsDefault() const { + return value(QString::fromUtf8("Preferences/General/DeleteTorrentsFilesAsDefault"), false).toBool(); } - static void setDeleteTorrentFilesAsDefault(bool del) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/DeleteTorrentsFilesAsDefault"), del); + void setDeleteTorrentFilesAsDefault(bool del) { + setValue(QString::fromUtf8("Preferences/General/DeleteTorrentsFilesAsDefault"), del); } - static void setConfirmOnExit(bool confirm) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/ExitConfirm"), confirm); + void setConfirmOnExit(bool confirm) { + setValue(QString::fromUtf8("Preferences/General/ExitConfirm"), confirm); } - static bool confirmOnExit() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/ExitConfirm"), true).toBool(); + bool confirmOnExit() const { + return value(QString::fromUtf8("Preferences/General/ExitConfirm"), true).toBool(); } - static void showSpeedInTitleBar(bool show) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), show); + void showSpeedInTitleBar(bool show) { + setValue(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), show); } - static bool speedInTitleBar() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), false).toBool(); + bool speedInTitleBar() const { + return value(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), false).toBool(); } - static bool useAlternatingRowColors() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/AlternatingRowColors"), true).toBool(); + bool useAlternatingRowColors() const { + return value(QString::fromUtf8("Preferences/General/AlternatingRowColors"), true).toBool(); } - static bool systrayIntegration() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool(); + void setAlternatingRowColors(bool b) { + setValue("Preferences/General/AlternatingRowColors", b); } - static void setSystrayIntegration(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/SystrayEnabled"), enabled); + bool systrayIntegration() const { + return value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool(); } - static void setToolbarDisplayed(bool displayed) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), displayed); + void setSystrayIntegration(bool enabled) { + setValue(QString::fromUtf8("Preferences/General/SystrayEnabled"), enabled); } - static bool isToolbarDisplayed() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool(); + void setToolbarDisplayed(bool displayed) { + setValue(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), displayed); } - static bool minimizeToTray() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool(); + bool isToolbarDisplayed() const { + return value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool(); } - static bool closeToTray() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool(); + bool minimizeToTray() const { + return value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool(); } - static bool startMinimized() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/StartMinimized"), false).toBool(); + void setMinimizeToTray(bool b) { + setValue("Preferences/General/MinimizeToTray", b); } - static bool isSlashScreenDisabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/NoSplashScreen"), false).toBool(); + bool closeToTray() const { + return value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool(); + } + + void setCloseToTray(bool b) { + setValue("Preferences/General/CloseToTray", b); + } + + bool startMinimized() const { + return value(QString::fromUtf8("Preferences/General/StartMinimized"), false).toBool(); + } + + void setStartMinimized(bool b) { + setValue("Preferences/General/StartMinimized", b); + } + + bool isSlashScreenDisabled() const { + return value(QString::fromUtf8("Preferences/General/NoSplashScreen"), false).toBool(); + } + + void setSplashScreenDisabled(bool b) { + setValue("Preferences/General/NoSplashScreen", b); } // Downloads - static QString getSavePath() { - QIniSettings settings("qBittorrent", "qBittorrent"); + QString getSavePath() const { #ifdef Q_WS_WIN - return settings.value(QString::fromUtf8("Preferences/Downloads/SavePath"), + return value(QString::fromUtf8("Preferences/Downloads/SavePath"), QDir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).absoluteFilePath("Downloads")).toString(); #else - return settings.value(QString::fromUtf8("Preferences/Downloads/SavePath"), QDir::home().absoluteFilePath("qBT_dir")).toString(); + return value(QString::fromUtf8("Preferences/Downloads/SavePath"), QDir::home().absoluteFilePath("qBT_dir")).toString(); #endif } - static void setSavePath(QString save_path) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), save_path); + void setSavePath(const QString &save_path) { + setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), save_path); } - static bool isTempPathEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), false).toBool(); + bool isTempPathEnabled() const { + return value(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), false).toBool(); } - static void setTempPathEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), enabled); + void setTempPathEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), enabled); } - static QString getTempPath() { - QIniSettings settings("qBittorrent", "qBittorrent"); - QString temp = QDir(getSavePath()).absoluteFilePath("temp"); - return settings.value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString(); + QString getTempPath() const { + const QString temp = QDir(getSavePath()).absoluteFilePath("temp"); + return value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString(); } - static void setTempPath(QString path) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), path); + void setTempPath(const QString &path) { + setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), path); } #if LIBTORRENT_VERSION_MINOR > 14 - static bool useIncompleteFilesExtension() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), false).toBool(); + bool useIncompleteFilesExtension() const { + return value(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), false).toBool(); } - static void useIncompleteFilesExtension(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), enabled); + void useIncompleteFilesExtension(bool enabled) { + setValue(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), enabled); } #endif - static bool appendTorrentLabel() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/AppendLabel"), false).toBool(); + bool appendTorrentLabel() const { + return value(QString::fromUtf8("Preferences/Downloads/AppendLabel"), false).toBool(); } - static bool preAllocateAllFiles() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool(); + void setAppendTorrentLabel(bool b) { + setValue("Preferences/Downloads/AppendLabel", b); } - static void preAllocateAllFiles(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.setValue(QString::fromUtf8("Preferences/Downloads/PreAllocation"), enabled); + bool preAllocateAllFiles() const { + return value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool(); } - static bool useAdditionDialog() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), false).toBool(); + void preAllocateAllFiles(bool enabled) { + return setValue(QString::fromUtf8("Preferences/Downloads/PreAllocation"), enabled); } - static bool addTorrentsInPause() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/StartInPause"), false).toBool(); + bool useAdditionDialog() const { + return value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), false).toBool(); } - static QStringList getScanDirs() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/ScanDirs"), QStringList()).toStringList(); + void useAdditionDialog(bool b) { + setValue("Preferences/Downloads/AdditionDialog", b); + } + + bool addTorrentsInPause() const { + return value(QString::fromUtf8("Preferences/Downloads/StartInPause"), false).toBool(); + } + + void addTorrentsInPause(bool b) { + setValue("Preferences/Downloads/StartInPause", b); + } + + QStringList getScanDirs() const { + return value(QString::fromUtf8("Preferences/Downloads/ScanDirs"), QStringList()).toStringList(); } // This must be called somewhere with data from the model - static void setScanDirs(const QStringList &dirs) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), dirs); + void setScanDirs(const QStringList &dirs) { + setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), dirs); } - static QList getDownloadInScanDirs() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return misc::boolListfromStringList(settings.value(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs")).toStringList()); + QList getDownloadInScanDirs() const { + return misc::boolListfromStringList(value(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs")).toStringList()); } - static void setDownloadInScanDirs(const QList &list) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs"), misc::toStringList(list)); + void setDownloadInScanDirs(const QList &list) { + setValue(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs"), misc::toStringList(list)); } - static bool isTorrentExportEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return !settings.value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString().isEmpty(); + bool isTorrentExportEnabled() const { + return !value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString().isEmpty(); } - static QString getExportDir() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString(); + QString getExportDir() const { + return value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString(); } - static void setExportDir(QString path) { + void setExportDir(QString path) { path = path.trimmed(); if(path.isEmpty()) path = QString(); - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/TorrentExport"), path); + setValue(QString::fromUtf8("Preferences/Downloads/TorrentExport"), path); } - static bool isMailNotificationEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/MailNotification/enabled"), false).toBool(); + bool isMailNotificationEnabled() const { + return value(QString::fromUtf8("Preferences/MailNotification/enabled"), false).toBool(); } - static void setMailNotificationEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/MailNotification/enabled"), enabled); + void setMailNotificationEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/MailNotification/enabled"), enabled); } - static QString getMailNotificationEmail() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/MailNotification/email"), "").toString(); + QString getMailNotificationEmail() const { + return value(QString::fromUtf8("Preferences/MailNotification/email"), "").toString(); } - static void setMailNotificationEmail(QString mail) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/MailNotification/email"), mail); + void setMailNotificationEmail(const QString &mail) { + setValue(QString::fromUtf8("Preferences/MailNotification/email"), mail); } - static QString getMailNotificationSMTP() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/MailNotification/smtp_server"), "smtp.changeme.com").toString(); + QString getMailNotificationSMTP() const { + return value(QString::fromUtf8("Preferences/MailNotification/smtp_server"), "smtp.changeme.com").toString(); } - static void setMailNotificationSMTP(QString smtp_server) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/MailNotification/smtp_server"), smtp_server); + void setMailNotificationSMTP(const QString &smtp_server) { + setValue(QString::fromUtf8("Preferences/MailNotification/smtp_server"), smtp_server); } - static int getActionOnDblClOnTorrentDl() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).toInt(); + int getActionOnDblClOnTorrentDl() const { + return value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).toInt(); } - static int getActionOnDblClOnTorrentFn() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorFn"), 1).toInt(); + void setActionOnDblClOnTorrentDl(int act) { + setValue("Preferences/Downloads/DblClOnTorDl", act); + } + + int getActionOnDblClOnTorrentFn() const { + return value(QString::fromUtf8("Preferences/Downloads/DblClOnTorFn"), 1).toInt(); + } + + void setActionOnDblClOnTorrentFn(int act) { + setValue("Preferences/Downloads/DblClOnTorFn", act); } // Connection options - static int getSessionPort() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/PortRangeMin"), 6881).toInt(); + int getSessionPort() const { + return value(QString::fromUtf8("Preferences/Connection/PortRangeMin"), 6881).toInt(); } - static void setSessionPort(int port) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/PortRangeMin"), port); + void setSessionPort(int port) { + setValue(QString::fromUtf8("Preferences/Connection/PortRangeMin"), port); } - static bool isUPnPEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/UPnP"), true).toBool(); + bool isUPnPEnabled() const { + return value(QString::fromUtf8("Preferences/Connection/UPnP"), true).toBool(); } - static void setUPnPEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/UPnP"), enabled); + void setUPnPEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Connection/UPnP"), enabled); } - static bool isNATPMPEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/NAT-PMP"), true).toBool(); + bool isNATPMPEnabled() const { + return value(QString::fromUtf8("Preferences/Connection/NAT-PMP"), true).toBool(); } - static void setNATPMPEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/NAT-PMP"), enabled); + void setNATPMPEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Connection/NAT-PMP"), enabled); } - static int getGlobalDownloadLimit() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt(); + int getGlobalDownloadLimit() const { + return value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt(); } - static void setGlobalDownloadLimit(int limit) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setGlobalDownloadLimit(int limit) { if(limit <= 0) limit = -1; - settings.setValue("Preferences/Connection/GlobalDLLimit", limit); + setValue("Preferences/Connection/GlobalDLLimit", limit); } - static int getGlobalUploadLimit() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), 50).toInt(); + int getGlobalUploadLimit() const { + return value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), 50).toInt(); } - static void setGlobalUploadLimit(int limit) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setGlobalUploadLimit(int limit) { if(limit <= 0) limit = -1; - settings.setValue("Preferences/Connection/GlobalUPLimit", limit); + setValue("Preferences/Connection/GlobalUPLimit", limit); } - static int getAltGlobalDownloadLimit() { - QIniSettings settings("qBittorrent", "qBittorrent"); - int ret = settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimitAlt"), 10).toInt(); + int getAltGlobalDownloadLimit() const { + int ret = value(QString::fromUtf8("Preferences/Connection/GlobalDLLimitAlt"), 10).toInt(); if(ret <= 0) ret = 10; return ret; } - static void setAltGlobalDownloadLimit(int limit) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setAltGlobalDownloadLimit(int limit) { if(limit <= 0) limit = -1; - settings.setValue("Preferences/Connection/GlobalDLLimitAlt", limit); + setValue("Preferences/Connection/GlobalDLLimitAlt", limit); } - static int getAltGlobalUploadLimit() { - QIniSettings settings("qBittorrent", "qBittorrent"); - int ret = settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimitAlt"), 10).toInt(); + int getAltGlobalUploadLimit() const { + int ret = value(QString::fromUtf8("Preferences/Connection/GlobalUPLimitAlt"), 10).toInt(); if(ret <= 0) ret = 10; return ret; } - static void setAltGlobalUploadLimit(int limit) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setAltGlobalUploadLimit(int limit) { if(limit <= 0) limit = -1; - settings.setValue("Preferences/Connection/GlobalUPLimitAlt", limit); + setValue("Preferences/Connection/GlobalUPLimitAlt", limit); } - static bool isAltBandwidthEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Preferences/Connection/alt_speeds_on", false).toBool(); + bool isAltBandwidthEnabled() const { + return value("Preferences/Connection/alt_speeds_on", false).toBool(); } - static void setAltBandwidthEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/Connection/alt_speeds_on", enabled); + void setAltBandwidthEnabled(bool enabled) { + setValue("Preferences/Connection/alt_speeds_on", enabled); } - static void setSchedulerEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Scheduler/Enabled"), enabled); + void setSchedulerEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Scheduler/Enabled"), enabled); } - static bool isSchedulerEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Scheduler/Enabled"), false).toBool(); + bool isSchedulerEnabled() const { + return value(QString::fromUtf8("Preferences/Scheduler/Enabled"), false).toBool(); } - static QTime getSchedulerStartTime() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Scheduler/start_time"), QTime(8,0)).toTime(); + QTime getSchedulerStartTime() const { + return value(QString::fromUtf8("Preferences/Scheduler/start_time"), QTime(8,0)).toTime(); } - static void setSchedulerStartTime(QTime time) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Scheduler/start_time"), time); + void setSchedulerStartTime(const QTime &time) { + setValue(QString::fromUtf8("Preferences/Scheduler/start_time"), time); } - static QTime getSchedulerEndTime() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Scheduler/end_time"), QTime(20,0)).toTime(); + QTime getSchedulerEndTime() const { + return value(QString::fromUtf8("Preferences/Scheduler/end_time"), QTime(20,0)).toTime(); } - static void setSchedulerEndTime(QTime time) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Scheduler/end_time"), time); + void setSchedulerEndTime(const QTime &time) { + setValue(QString::fromUtf8("Preferences/Scheduler/end_time"), time); } - static scheduler_days getSchedulerDays() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return (scheduler_days)settings.value(QString::fromUtf8("Preferences/Scheduler/days"), EVERY_DAY).toInt(); + scheduler_days getSchedulerDays() const { + return (scheduler_days)value(QString::fromUtf8("Preferences/Scheduler/days"), EVERY_DAY).toInt(); } - static void setSchedulerDays(scheduler_days days) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Scheduler/days"), (int)days); + void setSchedulerDays(scheduler_days days) { + setValue(QString::fromUtf8("Preferences/Scheduler/days"), (int)days); } // Proxy options - static bool isHTTPProxyEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt() > 0; + bool isHTTPProxyEnabled() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt() > 0; } - static bool isHTTPProxyAuthEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Authentication"), false).toBool(); + bool isHTTPProxyAuthEnabled() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Authentication"), false).toBool(); } - static void setHTTPProxyAuthEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Authentication"), enabled); + void setHTTPProxyAuthEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Authentication"), enabled); } - static QString getHTTPProxyIp() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), "0.0.0.0").toString(); + QString getHTTPProxyIp() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), "0.0.0.0").toString(); } - static void setHTTPProxyIp(QString ip) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), ip); + void setHTTPProxyIp(const QString &ip) { + setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), ip); } - static unsigned short getHTTPProxyPort() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), 8080).toInt(); + unsigned short getHTTPProxyPort() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), 8080).toInt(); } - static void setHTTPProxyPort(unsigned short port) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), port); + void setHTTPProxyPort(unsigned short port) { + setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), port); } - static QString getHTTPProxyUsername() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Username"), QString()).toString(); + QString getHTTPProxyUsername() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Username"), QString()).toString(); } - static void setHTTPProxyUsername(QString username) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Username"), username); + void setHTTPProxyUsername(const QString &username) { + setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Username"), username); } - static QString getHTTPProxyPassword() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Password"), QString()).toString(); + QString getHTTPProxyPassword() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Password"), QString()).toString(); } - static void setHTTPProxyPassword(QString password) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Password"), password); + void setHTTPProxyPassword(const QString &password) { + setValue(QString::fromUtf8("Preferences/Connection/HTTPProxy/Password"), password); } - static int getHTTPProxyType() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt(); + int getHTTPProxyType() const { + return value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt(); } - static void setHTTPProxyType(int type) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), type); + void setHTTPProxyType(int type) { + setValue(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), type); } - static bool isPeerProxyEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt() > 0; + bool isPeerProxyEnabled() const { + return value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt() > 0; } - static bool isPeerProxyAuthEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), false).toBool(); + bool isPeerProxyAuthEnabled() const { + return value(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), false).toBool(); } - static void setPeerProxyAuthEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), enabled); + void setPeerProxyAuthEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), enabled); } - static QString getPeerProxyIp() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/IP"), "0.0.0.0").toString(); + QString getPeerProxyIp() const { + return value(QString::fromUtf8("Preferences/Connection/Proxy/IP"), "0.0.0.0").toString(); } - static void setPeerProxyIp(QString ip) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/Proxy/IP"), ip); + void setPeerProxyIp(const QString &ip) { + setValue(QString::fromUtf8("Preferences/Connection/Proxy/IP"), ip); } - static unsigned short getPeerProxyPort() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Port"), 8080).toInt(); + unsigned short getPeerProxyPort() const { + return value(QString::fromUtf8("Preferences/Connection/Proxy/Port"), 8080).toInt(); } - static void setPeerProxyPort(unsigned short port) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/Proxy/Port"), port); + void setPeerProxyPort(unsigned short port) { + setValue(QString::fromUtf8("Preferences/Connection/Proxy/Port"), port); } - static QString getPeerProxyUsername() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Username"), QString()).toString(); + QString getPeerProxyUsername() const { + return value(QString::fromUtf8("Preferences/Connection/Proxy/Username"), QString()).toString(); } - static void setPeerProxyUsername(QString username) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/Proxy/Username"), username); + void setPeerProxyUsername(const QString &username) { + setValue(QString::fromUtf8("Preferences/Connection/Proxy/Username"), username); } - static QString getPeerProxyPassword() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/Proxy/Password"), QString()).toString(); + QString getPeerProxyPassword() const { + return value(QString::fromUtf8("Preferences/Connection/Proxy/Password"), QString()).toString(); } - static void setPeerProxyPassword(QString password) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/Proxy/Password"), password); + void setPeerProxyPassword(const QString &password) { + setValue(QString::fromUtf8("Preferences/Connection/Proxy/Password"), password); } - static int getPeerProxyType() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt(); + int getPeerProxyType() const { + return value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt(); } - static void setPeerProxyType(int type) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/ProxyType"), type); + void setPeerProxyType(int type) { + setValue(QString::fromUtf8("Preferences/Connection/ProxyType"), type); } // Bittorrent options - static int getMaxConnecs() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt(); + int getMaxConnecs() const { + return value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt(); } - static void setMaxConnecs(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxConnecs(int val) { if(val <= 0) val = -1; - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), val); + setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), val); } - static int getMaxConnecsPerTorrent() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt(); + int getMaxConnecsPerTorrent() const { + return value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt(); } - static void setMaxConnecsPerTorrent(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxConnecsPerTorrent(int val) { if(val <= 0) val = -1; - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), val); + setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), val); } - static int getMaxUploadsPerTorrent() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt(); + int getMaxUploadsPerTorrent() const { + return value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt(); } - static void setMaxUploadsPerTorrent(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxUploadsPerTorrent(int val) { if(val <= 0) val = -1; - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), val); + setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), val); } - static bool isDHTEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool(); + bool isDHTEnabled() const { + return value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool(); } - static void setDHTEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/DHT"), enabled); + void setDHTEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Bittorrent/DHT"), enabled); } - static bool isPeXEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/PeX"), true).toBool(); + bool isPeXEnabled() const { + return value(QString::fromUtf8("Preferences/Bittorrent/PeX"), true).toBool(); } - static void setPeXEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/PeX"), enabled); + void setPeXEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Bittorrent/PeX"), enabled); } - static bool isDHTPortSameAsBT() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool(); + bool isDHTPortSameAsBT() const { + return value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool(); } - static void setDHTPortSameAsBT(bool same) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), same); + void setDHTPortSameAsBT(bool same) { + setValue(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), same); } - static int getDHTPort() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), 6881).toInt(); + int getDHTPort() const { + return value(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), 6881).toInt(); } - static void setDHTPort(int port) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), port); + void setDHTPort(int port) { + setValue(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), port); } - static bool isLSDEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/LSD"), true).toBool(); + bool isLSDEnabled() const { + return value(QString::fromUtf8("Preferences/Bittorrent/LSD"), true).toBool(); } - static void setLSDEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/LSD"), enabled); + void setLSDEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Bittorrent/LSD"), enabled); } - static int getEncryptionSetting() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/Encryption"), 0).toInt(); + int getEncryptionSetting() const { + return value(QString::fromUtf8("Preferences/Bittorrent/Encryption"), 0).toInt(); } - static void setEncryptionSetting(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val); + void setEncryptionSetting(int val) { + setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val); } - static float getMaxRatio() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble(); + float getMaxRatio() const { + return value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble(); } - static void setMaxRatio(float ratio) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), ratio); + void setMaxRatio(float ratio) { + setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), ratio); } - static void setMaxRatioAction(int act) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), act); + void setMaxRatioAction(int act) { + setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), act); } - static int getMaxRatioAction() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), PAUSE_ACTION).toInt(); + int getMaxRatioAction() const { + return value(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), PAUSE_ACTION).toInt(); } // IP Filter - static bool isFilteringEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/IPFilter/Enabled"), false).toBool(); + bool isFilteringEnabled() const { + return value(QString::fromUtf8("Preferences/IPFilter/Enabled"), false).toBool(); } - static void setFilteringEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/IPFilter/Enabled"), enabled); + void setFilteringEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/IPFilter/Enabled"), enabled); } - static QString getFilter() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString(); + QString getFilter() const { + return value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString(); } - static void setFilter(QString path) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/IPFilter/File"), path); + void setFilter(const QString &path) { + setValue(QString::fromUtf8("Preferences/IPFilter/File"), path); } - static void banIP(QString ip) { - QIniSettings settings("qBittorrent", "qBittorrent"); - QStringList banned_ips = settings.value(QString::fromUtf8("Preferences/IPFilter/BannedIPs"), QStringList()).toStringList(); + void banIP(const QString &ip) { + QStringList banned_ips = value(QString::fromUtf8("Preferences/IPFilter/BannedIPs"), QStringList()).toStringList(); if(!banned_ips.contains(ip)) { banned_ips << ip; - settings.setValue("Preferences/IPFilter/BannedIPs", banned_ips); + setValue("Preferences/IPFilter/BannedIPs", banned_ips); } } - static QStringList bannedIPs() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/IPFilter/BannedIPs"), QStringList()).toStringList(); + QStringList bannedIPs() const { + return value(QString::fromUtf8("Preferences/IPFilter/BannedIPs"), QStringList()).toStringList(); } // Search - static bool isSearchEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Search/SearchEnabled"), true).toBool(); + bool isSearchEnabled() const { + return value(QString::fromUtf8("Preferences/Search/SearchEnabled"), true).toBool(); } - static void setSearchEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Search/SearchEnabled"), enabled); + void setSearchEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Search/SearchEnabled"), enabled); } // Queueing system - static bool isQueueingSystemEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Preferences/Queueing/QueueingEnabled", false).toBool(); + bool isQueueingSystemEnabled() const { + return value("Preferences/Queueing/QueueingEnabled", false).toBool(); } - static void setQueueingSystemEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/Queueing/QueueingEnabled", enabled); + void setQueueingSystemEnabled(bool enabled) { + setValue("Preferences/Queueing/QueueingEnabled", enabled); } - static int getMaxActiveDownloads() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), 3).toInt(); + int getMaxActiveDownloads() const { + return value(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), 3).toInt(); } - static void setMaxActiveDownloads(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxActiveDownloads(int val) { if(val < 0) val = -1; - settings.setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), val); + setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), val); } - static int getMaxActiveUploads() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), 3).toInt(); + int getMaxActiveUploads() const { + return value(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), 3).toInt(); } - static void setMaxActiveUploads(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxActiveUploads(int val) { if(val < 0) val = -1; - settings.setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), val); + setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), val); } - static int getMaxActiveTorrents() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), 5).toInt(); + int getMaxActiveTorrents() const { + return value(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), 5).toInt(); } - static void setMaxActiveTorrents(int val) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxActiveTorrents(int val) { if(val < 0) val = -1; - settings.setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), val); + setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), val); } - static bool isWebUiEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Preferences/WebUI/Enabled", false).toBool(); + bool isWebUiEnabled() const { + return value("Preferences/WebUI/Enabled", false).toBool(); } - static void setWebUiEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/WebUI/Enabled", enabled); + void setWebUiEnabled(bool enabled) { + setValue("Preferences/WebUI/Enabled", enabled); } - static quint16 getWebUiPort() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Preferences/WebUI/Port", 8080).toInt(); + quint16 getWebUiPort() const { + return value("Preferences/WebUI/Port", 8080).toInt(); } - static void setWebUiPort(quint16 port) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/WebUI/Port", port); + void setWebUiPort(quint16 port) { + setValue("Preferences/WebUI/Port", port); } - static QString getWebUiUsername() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Preferences/WebUI/Username", "admin").toString(); + QString getWebUiUsername() const { + return value("Preferences/WebUI/Username", "admin").toString(); } - static void setWebUiUsername(QString username) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/WebUI/Username", username); + void setWebUiUsername(const QString &username) { + setValue("Preferences/WebUI/Username", username); } - static void setWebUiPassword(QString new_password) { + void setWebUiPassword(const QString &new_password) { // Get current password md5 QString current_pass_md5 = getWebUiPassword(); // Check if password did not change @@ -827,24 +726,12 @@ public: QCryptographicHash md5(QCryptographicHash::Md5); md5.addData(getWebUiUsername().toLocal8Bit()+":"+QBT_REALM+":"); md5.addData(new_password.toLocal8Bit()); - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/WebUI/Password_ha1", md5.result().toHex()); + + setValue("Preferences/WebUI/Password_ha1", md5.result().toHex()); } - static QString getWebUiPassword() { - QIniSettings settings("qBittorrent", "qBittorrent"); - // Here for backward compatiblity - if(settings.contains("Preferences/WebUI/Password")) { - QString clear_pass = settings.value("Preferences/WebUI/Password", "adminadmin").toString(); - settings.remove("Preferences/WebUI/Password"); - QCryptographicHash md5(QCryptographicHash::Md5); - md5.addData(getWebUiUsername().toLocal8Bit()+":"+QBT_REALM+":"); - md5.addData(clear_pass.toLocal8Bit()); - QString pass_md5(md5.result().toHex()); - settings.setValue("Preferences/WebUI/Password_ha1", pass_md5); - return pass_md5; - } - QString pass_ha1 = settings.value("Preferences/WebUI/Password_ha1", "").toString(); + QString getWebUiPassword() const { + QString pass_ha1 = value("Preferences/WebUI/Password_ha1", "").toString(); if(pass_ha1.isEmpty()) { QCryptographicHash md5(QCryptographicHash::Md5); md5.addData(getWebUiUsername().toLocal8Bit()+":"+QBT_REALM+":"); @@ -856,245 +743,182 @@ public: // Advanced settings - static void setUILockPassword(QString clear_password) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setUILockPassword(const QString &clear_password) { QCryptographicHash md5(QCryptographicHash::Md5); md5.addData(clear_password.toLocal8Bit()); QString md5_password = md5.result().toHex(); - settings.setValue("Locking/password", md5_password); + setValue("Locking/password", md5_password); } - static QString getUILockPasswordMD5() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Locking/password", QString()).toString(); + QString getUILockPasswordMD5() const { + return value("Locking/password", QString()).toString(); } - static bool isUILocked() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Locking/locked", false).toBool(); + bool isUILocked() const { + return value("Locking/locked", false).toBool(); } - static void setUILocked(bool locked) { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.setValue("Locking/locked", locked); + void setUILocked(bool locked) { + return setValue("Locking/locked", locked); } - static bool isAutoRunEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("AutoRun/enabled", false).toBool(); + bool isAutoRunEnabled() const { + return value("AutoRun/enabled", false).toBool(); } - static void setAutoRunEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.setValue("AutoRun/enabled", enabled); + void setAutoRunEnabled(bool enabled) { + return setValue("AutoRun/enabled", enabled); } - static void setAutoRunProgram(QString program) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("AutoRun/program", program); + void setAutoRunProgram(const QString &program) { + setValue("AutoRun/program", program); } - static QString getAutoRunProgram() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("AutoRun/program", QString()).toString(); + QString getAutoRunProgram() const { + return value("AutoRun/program", QString()).toString(); } - static bool shutdownWhenDownloadsComplete() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), false).toBool(); + bool shutdownWhenDownloadsComplete() const { + return value(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), false).toBool(); } - static void setShutdownWhenDownloadsComplete(bool shutdown) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), shutdown); + void setShutdownWhenDownloadsComplete(bool shutdown) { + setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), shutdown); } - static bool shutdownqBTWhenDownloadsComplete() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), false).toBool(); + bool shutdownqBTWhenDownloadsComplete() const { + return value(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), false).toBool(); } - static void setShutdownqBTWhenDownloadsComplete(bool shutdown) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), shutdown); + void setShutdownqBTWhenDownloadsComplete(bool shutdown) { + setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), shutdown); } - static uint diskCacheSize() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/DiskCache"), 16).toUInt(); + uint diskCacheSize() const { + return value(QString::fromUtf8("Preferences/Downloads/DiskCache"), 16).toUInt(); } - static void setDiskCacheSize(uint size) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/DiskCache"), size); + void setDiskCacheSize(uint size) { + setValue(QString::fromUtf8("Preferences/Downloads/DiskCache"), size); } - static uint outgoingPortsMin() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), 0).toUInt(); + uint outgoingPortsMin() const { + return value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), 0).toUInt(); } - static void setOutgoingPortsMin(uint val) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), val); + void setOutgoingPortsMin(uint val) { + setValue(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), val); } - static uint outgoingPortsMax() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMax"), 0).toUInt(); + uint outgoingPortsMax() const { + return value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMax"), 0).toUInt(); } - static void setOutgoingPortsMax(uint val) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMax"), val); + void setOutgoingPortsMax(uint val) { + setValue(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMax"), val); } - static bool ignoreLimitsOnLAN() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/IgnoreLimitsLAN"), true).toBool(); + bool ignoreLimitsOnLAN() const { + return value(QString::fromUtf8("Preferences/Advanced/IgnoreLimitsLAN"), true).toBool(); } - static void ignoreLimitsOnLAN(bool ignore) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/IgnoreLimitsLAN"), ignore); + void ignoreLimitsOnLAN(bool ignore) { + setValue(QString::fromUtf8("Preferences/Advanced/IgnoreLimitsLAN"), ignore); } - static bool includeOverheadInLimits() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/IncludeOverhead"), false).toBool(); + bool includeOverheadInLimits() const { + return value(QString::fromUtf8("Preferences/Advanced/IncludeOverhead"), false).toBool(); } - static void includeOverheadInLimits(bool include) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/IncludeOverhead"), include); + void includeOverheadInLimits(bool include) { + setValue(QString::fromUtf8("Preferences/Advanced/IncludeOverhead"), include); } - static bool recheckTorrentsOnCompletion() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/RecheckOnCompletion"), false).toBool(); + bool recheckTorrentsOnCompletion() const { + return value(QString::fromUtf8("Preferences/Advanced/RecheckOnCompletion"), false).toBool(); } - static void recheckTorrentsOnCompletion(bool recheck) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/RecheckOnCompletion"), recheck); + void recheckTorrentsOnCompletion(bool recheck) { + setValue(QString::fromUtf8("Preferences/Advanced/RecheckOnCompletion"), recheck); } - static unsigned int getRefreshInterval() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/General/RefreshInterval"), 1500).toUInt(); + unsigned int getRefreshInterval() const { + return value(QString::fromUtf8("Preferences/General/RefreshInterval"), 1500).toUInt(); } - static void setRefreshInterval(uint interval) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/General/RefreshInterval"), interval); + void setRefreshInterval(uint interval) { + setValue(QString::fromUtf8("Preferences/General/RefreshInterval"), interval); } - static bool resolvePeerCountries() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), true).toBool(); + bool resolvePeerCountries() const { + return value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), true).toBool(); } - static void resolvePeerCountries(bool resolve) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), resolve); + void resolvePeerCountries(bool resolve) { + setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), resolve); } - static bool resolvePeerHostNames() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), false).toBool(); + bool resolvePeerHostNames() const { + return value(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), false).toBool(); } - static void resolvePeerHostNames(bool resolve) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), resolve); + void resolvePeerHostNames(bool resolve) { + setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), resolve); } - static int getMaxHalfOpenConnections() { - QIniSettings settings("qBittorrent", "qBittorrent"); - const int val = settings.value(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), 50).toInt(); + int getMaxHalfOpenConnections() const { + const int val = value(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), 50).toInt(); if(val <= 0) return -1; return val; } - static void setMaxHalfOpenConnections(int value) { - QIniSettings settings("qBittorrent", "qBittorrent"); + void setMaxHalfOpenConnections(int value) { if(value <= 0) value = -1; - settings.setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value); + setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value); } - static void setNetworkInterface(QString iface) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Connection/Interface"), iface); + void setNetworkInterface(const QString& iface) { + setValue(QString::fromUtf8("Preferences/Connection/Interface"), iface); } - static QString getNetworkInterface() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/Interface"), QString()).toString(); + QString getNetworkInterface() const { + return value(QString::fromUtf8("Preferences/Connection/Interface"), QString()).toString(); } #if LIBTORRENT_VERSION_MINOR > 14 - static bool isSuperSeedingEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), false).toBool(); + bool isSuperSeedingEnabled() const { + return value(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), false).toBool(); } - static void enableSuperSeeding(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), enabled); + void enableSuperSeeding(bool enabled) { + setValue(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), enabled); } #endif - static QList getHostNameCookies(QString host_name) { - QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - QList ret; - QMap hosts_table = qBTRSS.value("hosts_cookies", QMap()).toMap(); - if(!hosts_table.contains(host_name)) return ret; - QByteArray raw_cookies = hosts_table.value(host_name).toByteArray(); - return raw_cookies.split(':'); + QStringList getTorrentLabels() const { + return value("TransferListFilters/customLabels").toStringList(); } - static QStringList getTorrentLabels() { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - return settings.value("TransferListFilters/customLabels").toStringList(); - } - - static void addTorrentLabel(const QString& label) { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QStringList labels = settings.value("TransferListFilters/customLabels").toStringList(); + void addTorrentLabel(const QString& label) { + QStringList labels = value("TransferListFilters/customLabels").toStringList(); if(!labels.contains(label)) labels << label; - settings.setValue("TransferListFilters/customLabels", labels); + setValue("TransferListFilters/customLabels", labels); } - static void removeTorrentLabel(const QString& label) { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QStringList labels = settings.value("TransferListFilters/customLabels").toStringList(); + void removeTorrentLabel(const QString& label) { + QStringList labels = value("TransferListFilters/customLabels").toStringList(); if(labels.contains(label)) labels.removeOne(label); - settings.setValue("TransferListFilters/customLabels", labels); + setValue("TransferListFilters/customLabels", labels); } - static void setHostNameCookies(QString host_name, const QList &cookies) { - QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - QMap hosts_table = qBTRSS.value("hosts_cookies", QMap()).toMap(); - QByteArray raw_cookies = ""; - foreach(const QByteArray& cookie, cookies) { - raw_cookies += cookie + ":"; - } - if(raw_cookies.endsWith(":")) - raw_cookies.chop(1); - hosts_table.insert(host_name, raw_cookies); - qBTRSS.setValue("hosts_cookies", hosts_table); + bool recursiveDownloadDisabled() const { + return value(QString::fromUtf8("Preferences/Advanced/DisableRecursiveDownload"), false).toBool(); } - static bool recursiveDownloadDisabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/DisableRecursiveDownload"), false).toBool(); - } - - static void disableRecursiveDownload(bool disable=true) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/DisableRecursiveDownload"), disable); + void disableRecursiveDownload(bool disable=true) { + setValue(QString::fromUtf8("Preferences/Advanced/DisableRecursiveDownload"), disable); } #ifdef Q_WS_WIN @@ -1124,24 +948,22 @@ public: return QString::null; } - static bool neverCheckFileAssoc() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), false).toBool(); + bool neverCheckFileAssoc() const { + return value(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), false).toBool(); } - static void setNeverCheckFileAssoc(bool check=true) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check); + void setNeverCheckFileAssoc(bool check=true) { + setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check); } static bool isFileAssocOk() { QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat); - if(settings.value(".torrent/Default").toString() != "qBittorrent") { + if(value(".torrent/Default").toString() != "qBittorrent") { qDebug(".torrent != qBittorrent"); return false; } qDebug("Checking shell command"); - QString shell_command = settings.value("qBittorrent/shell/open/command/Default", "").toString(); + QString shell_command = value("qBittorrent/shell/open/command/Default", "").toString(); qDebug("Shell command is: %s", qPrintable(shell_command)); QRegExp exe_reg("\"([^\"]+)\".*"); if(exe_reg.indexIn(shell_command) < 0) @@ -1152,10 +974,10 @@ public: return false; // Icon const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1"; - if(settings.value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0) + if(value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0) return false; // Check magnet link assoc - shell_command = settings.value("Magnet/shell/open/command/Default", "").toString(); + shell_command = value("Magnet/shell/open/command/Default", "").toString(); if(exe_reg.indexIn(shell_command) < 0) return false; assoc_exe = exe_reg.cap(1); @@ -1168,43 +990,39 @@ public: static void setFileAssoc() { QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat); // .Torrent association - settings.setValue(".torrent/Default", "qBittorrent"); - settings.setValue(".torrent/Content Type", "application/x-bittorrent"); - settings.setValue("qBittorrent/shell/Default", "open"); + setValue(".torrent/Default", "qBittorrent"); + setValue(".torrent/Content Type", "application/x-bittorrent"); + setValue("qBittorrent/shell/Default", "open"); const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\""; - settings.setValue("qBittorrent/shell/open/command/Default", command_str); - settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent"); + setValue("qBittorrent/shell/open/command/Default", command_str); + setValue("qBittorrent/Content Type/Default", "application/x-bittorrent"); const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1"; - settings.setValue("qBittorrent/DefaultIcon/Default", icon_str); + setValue("qBittorrent/DefaultIcon/Default", icon_str); // Magnet association - settings.setValue("Magnet/Default", "Magnet URI"); - settings.setValue("Magnet/Content Type", "application/x-magnet"); - settings.setValue("Magnet/URL Protocol", ""); - settings.setValue("Magnet/DefaultIcon\\Default", icon_str); - settings.setValue("Magnet/shell/Default", "open"); - settings.setValue("Magnet/shell/open/command/Default", command_str); + setValue("Magnet/Default", "Magnet URI"); + setValue("Magnet/Content Type", "application/x-magnet"); + setValue("Magnet/URL Protocol", ""); + setValue("Magnet/DefaultIcon\\Default", icon_str); + setValue("Magnet/shell/Default", "open"); + setValue("Magnet/shell/open/command/Default", command_str); } #endif - static bool isTrackerEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/trackerEnabled"), false).toBool(); + bool isTrackerEnabled() const { + return value(QString::fromUtf8("Preferences/Advanced/trackerEnabled"), false).toBool(); } - static void setTrackerEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/trackerEnabled"), enabled); + void setTrackerEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/Advanced/trackerEnabled"), enabled); } - static int getTrackerPort() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Advanced/trackerPort"), 9000).toInt(); + int getTrackerPort() const { + return value(QString::fromUtf8("Preferences/Advanced/trackerPort"), 9000).toInt(); } - static void setTrackerPort(int port) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Advanced/trackerPort"), port); + void setTrackerPort(int port) { + setValue(QString::fromUtf8("Preferences/Advanced/trackerPort"), port); } }; diff --git a/src/programupdater.cpp b/src/programupdater.cpp index c0161d33e..a37854a9c 100644 --- a/src/programupdater.cpp +++ b/src/programupdater.cpp @@ -51,10 +51,11 @@ ProgramUpdater::ProgramUpdater(QObject *parent) : QObject(parent) { mp_manager = new QNetworkAccessManager(this); + Preferences pref; // Proxy support - if(Preferences::isHTTPProxyEnabled()) { + if(pref.isHTTPProxyEnabled()) { QNetworkProxy proxy; - switch(Preferences::getHTTPProxyType()) { + switch(pref.getHTTPProxyType()) { case Proxy::SOCKS4: case Proxy::SOCKS5: case Proxy::SOCKS5_PW: @@ -63,12 +64,12 @@ ProgramUpdater::ProgramUpdater(QObject *parent) : proxy.setType(QNetworkProxy::HttpProxy); break; } - proxy.setHostName(Preferences::getHTTPProxyIp()); - proxy.setPort(Preferences::getHTTPProxyPort()); + proxy.setHostName(pref.getHTTPProxyIp()); + proxy.setPort(pref.getHTTPProxyPort()); // Proxy authentication - if(Preferences::isHTTPProxyAuthEnabled()) { - proxy.setUser(Preferences::getHTTPProxyUsername()); - proxy.setPassword(Preferences::getHTTPProxyPassword()); + if(pref.isHTTPProxyAuthEnabled()) { + proxy.setUser(pref.getHTTPProxyUsername()); + proxy.setPassword(pref.getHTTPProxyPassword()); } mp_manager->setProxy(proxy); } diff --git a/src/properties/peerlistwidget.cpp b/src/properties/peerlistwidget.cpp index 4d7a01ad0..9583d41e6 100644 --- a/src/properties/peerlistwidget.cpp +++ b/src/properties/peerlistwidget.cpp @@ -93,7 +93,7 @@ PeerListWidget::~PeerListWidget() { } void PeerListWidget::updatePeerHostNameResolutionState() { - if(Preferences::resolvePeerHostNames()) { + if(Preferences().resolvePeerHostNames()) { if(!resolver) { resolver = new ReverseResolution(this); connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString))); @@ -107,7 +107,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() { } void PeerListWidget::updatePeerCountryResolutionState() { - if(Preferences::resolvePeerCountries() != display_flags) { + if(Preferences().resolvePeerCountries() != display_flags) { display_flags = !display_flags; if(display_flags) { const QTorrentHandle h = properties->getCurrentTorrent(); @@ -206,7 +206,7 @@ void PeerListWidget::limitUpRateSelectedPeers(QStringList peer_ips) { QTorrentHandle h = properties->getCurrentTorrent(); if(!h.is_valid()) return; bool ok=false; - long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Upload rate limiting"), -1, Preferences::getGlobalUploadLimit()*1024.); + long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Upload rate limiting"), -1, Preferences().getGlobalUploadLimit()*1024.); if(!ok) return; foreach(const QString &ip, peer_ips) { libtorrent::asio::ip::tcp::endpoint ep = peerEndpoints.value(ip, libtorrent::asio::ip::tcp::endpoint()); @@ -227,7 +227,7 @@ void PeerListWidget::limitDlRateSelectedPeers(QStringList peer_ips) { QTorrentHandle h = properties->getCurrentTorrent(); if(!h.is_valid()) return; bool ok=false; - long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Download rate limiting"), -1, Preferences::getGlobalDownloadLimit()*1024.); + long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Download rate limiting"), -1, Preferences().getGlobalDownloadLimit()*1024.); if(!ok) return; foreach(const QString &ip, peer_ips) { libtorrent::asio::ip::tcp::endpoint ep = peerEndpoints.value(ip, libtorrent::asio::ip::tcp::endpoint()); diff --git a/src/qtlibtorrent/bandwidthscheduler.h b/src/qtlibtorrent/bandwidthscheduler.h index d9ed84cf2..a7baabfab 100644 --- a/src/qtlibtorrent/bandwidthscheduler.h +++ b/src/qtlibtorrent/bandwidthscheduler.h @@ -15,7 +15,7 @@ private: public: BandwidthScheduler(QObject *parent): QTimer(parent), in_alternative_mode(false) { - Q_ASSERT(Preferences::isSchedulerEnabled()); + Q_ASSERT(Preferences().isSchedulerEnabled()); // Signal shot, we call start() again manually setSingleShot(true); // Connect Signals/Slots @@ -24,10 +24,11 @@ public: public slots: void start() { - Q_ASSERT(Preferences::isSchedulerEnabled()); + const Preferences pref; + Q_ASSERT(pref.isSchedulerEnabled()); - QTime startAltSpeeds = Preferences::getSchedulerStartTime(); - QTime endAltSpeeds = Preferences::getSchedulerEndTime(); + QTime startAltSpeeds = pref.getSchedulerStartTime(); + QTime endAltSpeeds = pref.getSchedulerEndTime(); if(startAltSpeeds == endAltSpeeds) { std::cerr << "Error: bandwidth scheduler have the same start time and end time." << std::endl; std::cerr << "The bandwidth scheduler will be disabled" << std::endl; @@ -56,19 +57,20 @@ public slots: } void switchMode() { + const Preferences pref; // Get the day this mode was started (either today or yesterday) QDate current_date = QDateTime::currentDateTime().toLocalTime().date(); int day = current_date.dayOfWeek(); if(in_alternative_mode) { // It is possible that starttime was yesterday - if(QTime::currentTime().secsTo(Preferences::getSchedulerStartTime()) > 0) { + if(QTime::currentTime().secsTo(pref.getSchedulerStartTime()) > 0) { current_date.addDays(-1); // Go to yesterday day = current_date.day(); } } // Check if the day is in scheduler days // Notify BTSession only if necessary - switch(Preferences::getSchedulerDays()) { + switch(pref.getSchedulerDays()) { case EVERY_DAY: emit switchToAlternativeMode(!in_alternative_mode); break; @@ -82,7 +84,7 @@ public slots: break; default: // Convert our enum index to Qt enum index - int scheduler_day = ((int)Preferences::getSchedulerDays()) - 2; + int scheduler_day = ((int)pref.getSchedulerDays()) - 2; if(day == scheduler_day) emit switchToAlternativeMode(!in_alternative_mode); break; diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index c21f4ca03..cd66f270e 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -85,6 +85,7 @@ QBtSession::QBtSession() , geoipDBLoaded(false), resolve_countries(false) #endif { + Preferences pref; m_tracker = 0; // To avoid some exceptions fs::path::default_name_check(fs::no_check); @@ -115,7 +116,7 @@ QBtSession::QBtSession() #if LIBTORRENT_VERSION_MINOR > 14 s->add_extension(create_lt_trackers_plugin); #endif - if(Preferences::isPeXEnabled()) { + if(pref.isPeXEnabled()) { PeXEnabled = true; s->add_extension(&create_ut_pex_plugin); } else { @@ -131,9 +132,9 @@ QBtSession::QBtSession() downloader = new downloadThread(this); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); - appendLabelToSavePath = Preferences::appendTorrentLabel(); + appendLabelToSavePath = pref.appendTorrentLabel(); #if LIBTORRENT_VERSION_MINOR > 14 - appendqBExtension = Preferences::useIncompleteFilesExtension(); + appendqBExtension = pref.useIncompleteFilesExtension(); #endif connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), this, SLOT(addTorrentsFromScanFolder(QStringList&))); // Apply user settings to Bittorrent session @@ -267,23 +268,24 @@ void QBtSession::setQueueingEnabled(bool enable) { // Set BT session configuration void QBtSession::configureSession() { qDebug("Configuring session"); + const Preferences pref; // Downloads // * Save path - defaultSavePath = Preferences::getSavePath(); - if(Preferences::isTempPathEnabled()) { - setDefaultTempPath(Preferences::getTempPath()); + defaultSavePath = pref.getSavePath(); + if(pref.isTempPathEnabled()) { + setDefaultTempPath(pref.getTempPath()); } else { setDefaultTempPath(QString::null); } - setAppendLabelToSavePath(Preferences::appendTorrentLabel()); + setAppendLabelToSavePath(pref.appendTorrentLabel()); #if LIBTORRENT_VERSION_MINOR > 14 - setAppendqBExtension(Preferences::useIncompleteFilesExtension()); + setAppendqBExtension(pref.useIncompleteFilesExtension()); #endif - preAllocateAllFiles(Preferences::preAllocateAllFiles()); - startTorrentsInPause(Preferences::addTorrentsInPause()); + preAllocateAllFiles(pref.preAllocateAllFiles()); + startTorrentsInPause(pref.addTorrentsInPause()); // * Scan dirs - const QStringList scan_dirs = Preferences::getScanDirs(); - QList downloadInDirList = Preferences::getDownloadInScanDirs(); + const QStringList scan_dirs = pref.getScanDirs(); + QList downloadInDirList = pref.getDownloadInScanDirs(); while(scan_dirs.size() > downloadInDirList.size()) { downloadInDirList << false; } @@ -293,29 +295,29 @@ void QBtSession::configureSession() { ++i; } // * Export Dir - const bool newTorrentExport = Preferences::isTorrentExportEnabled(); + const bool newTorrentExport = pref.isTorrentExportEnabled(); if(torrentExport != newTorrentExport) { torrentExport = newTorrentExport; if(torrentExport) { qDebug("Torrent export is enabled, exporting the current torrents"); - exportTorrentFiles(Preferences::getExportDir()); + exportTorrentFiles(pref.getExportDir()); } } // Connection // * Ports binding const unsigned short old_listenPort = getListenPort(); - const unsigned short new_listenPort = Preferences::getSessionPort(); + const unsigned short new_listenPort = pref.getSessionPort(); if(old_listenPort != new_listenPort) { setListeningPort(new_listenPort); addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(new_listenPort))); } // * Global download limit - const bool alternative_speeds = Preferences::isAltBandwidthEnabled(); + const bool alternative_speeds = pref.isAltBandwidthEnabled(); int down_limit; if(alternative_speeds) - down_limit = Preferences::getAltGlobalDownloadLimit(); + down_limit = pref.getAltGlobalDownloadLimit(); else - down_limit = Preferences::getGlobalDownloadLimit(); + down_limit = pref.getGlobalDownloadLimit(); if(down_limit <= 0) { // Download limit disabled setDownloadRateLimit(-1); @@ -325,9 +327,9 @@ void QBtSession::configureSession() { } int up_limit; if(alternative_speeds) - up_limit = Preferences::getAltGlobalUploadLimit(); + up_limit = pref.getAltGlobalUploadLimit(); else - up_limit = Preferences::getGlobalUploadLimit(); + up_limit = pref.getGlobalUploadLimit(); // * Global Upload limit if(up_limit <= 0) { // Upload limit disabled @@ -336,7 +338,7 @@ void QBtSession::configureSession() { // Enabled setUploadRateLimit(up_limit*1024); } - if(Preferences::isSchedulerEnabled()) { + if(pref.isSchedulerEnabled()) { if(!bd_scheduler) { bd_scheduler = new BandwidthScheduler(this); connect(bd_scheduler, SIGNAL(switchToAlternativeMode(bool)), this, SLOT(useAlternativeSpeedsLimit(bool))); @@ -348,7 +350,7 @@ void QBtSession::configureSession() { #ifndef DISABLE_GUI // Resolve countries qDebug("Loading country resolution settings"); - const bool new_resolv_countries = Preferences::resolvePeerCountries(); + const bool new_resolv_countries = pref.resolvePeerCountries(); if(resolve_countries != new_resolv_countries) { qDebug("in country reoslution settings"); resolve_countries = new_resolv_countries; @@ -368,7 +370,7 @@ void QBtSession::configureSession() { } #endif // * UPnP - if(Preferences::isUPnPEnabled()) { + if(pref.isUPnPEnabled()) { enableUPnP(true); addConsoleMessage(tr("UPnP support [ON]"), QString::fromUtf8("blue")); } else { @@ -376,7 +378,7 @@ void QBtSession::configureSession() { addConsoleMessage(tr("UPnP support [OFF]"), QString::fromUtf8("blue")); } // * NAT-PMP - if(Preferences::isNATPMPEnabled()) { + if(pref.isNATPMPEnabled()) { enableNATPMP(true); addConsoleMessage(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue")); } else { @@ -404,13 +406,13 @@ void QBtSession::configureSession() { #endif // To keep same behavior as in qBittorrent v1.2.0 sessionSettings.rate_limit_ip_overhead = false; - sessionSettings.cache_size = Preferences::diskCacheSize()*64; - addConsoleMessage(tr("Using a disk cache size of %1 MiB").arg(Preferences::diskCacheSize())); + sessionSettings.cache_size = pref.diskCacheSize()*64; + addConsoleMessage(tr("Using a disk cache size of %1 MiB").arg(pref.diskCacheSize())); // Queueing System - if(Preferences::isQueueingSystemEnabled()) { - sessionSettings.active_downloads = Preferences::getMaxActiveDownloads(); - sessionSettings.active_seeds = Preferences::getMaxActiveUploads(); - sessionSettings.active_limit = Preferences::getMaxActiveTorrents(); + if(pref.isQueueingSystemEnabled()) { + sessionSettings.active_downloads = pref.getMaxActiveDownloads(); + sessionSettings.active_seeds = pref.getMaxActiveUploads(); + sessionSettings.active_limit = pref.getMaxActiveTorrents(); sessionSettings.dont_count_slow_torrents = false; setQueueingEnabled(true); } else { @@ -420,30 +422,30 @@ void QBtSession::configureSession() { setQueueingEnabled(false); } // Outgoing ports - sessionSettings.outgoing_ports = std::make_pair(Preferences::outgoingPortsMin(), Preferences::outgoingPortsMax()); + sessionSettings.outgoing_ports = std::make_pair(pref.outgoingPortsMin(), pref.outgoingPortsMax()); setSessionSettings(sessionSettings); // Ignore limits on LAN - sessionSettings.ignore_limits_on_local_network = Preferences::ignoreLimitsOnLAN(); + sessionSettings.ignore_limits_on_local_network = pref.ignoreLimitsOnLAN(); // Include overhead in transfer limits - sessionSettings.rate_limit_ip_overhead = Preferences::includeOverheadInLimits(); + sessionSettings.rate_limit_ip_overhead = pref.includeOverheadInLimits(); // Bittorrent // * Max Half-open connections - s->set_max_half_open_connections(Preferences::getMaxHalfOpenConnections()); + s->set_max_half_open_connections(pref.getMaxHalfOpenConnections()); // * Max connections limit - setMaxConnections(Preferences::getMaxConnecs()); + setMaxConnections(pref.getMaxConnecs()); // * Max connections per torrent limit - setMaxConnectionsPerTorrent(Preferences::getMaxConnecsPerTorrent()); + setMaxConnectionsPerTorrent(pref.getMaxConnecsPerTorrent()); // * Max uploads per torrent limit - setMaxUploadsPerTorrent(Preferences::getMaxUploadsPerTorrent()); + setMaxUploadsPerTorrent(pref.getMaxUploadsPerTorrent()); // * DHT - if(Preferences::isDHTEnabled()) { + if(pref.isDHTEnabled()) { // Set DHT Port if(enableDHT(true)) { int dht_port; - if(Preferences::isDHTPortSameAsBT()) + if(pref.isDHTPortSameAsBT()) dht_port = 0; else - dht_port = Preferences::getDHTPort(); + dht_port = pref.getDHTPort(); setDHTPort(dht_port); if(dht_port == 0) dht_port = new_listenPort; addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue")); @@ -460,11 +462,11 @@ void QBtSession::configureSession() { } else { addConsoleMessage(tr("PeX support [OFF]"), QString::fromUtf8("red")); } - if(PeXEnabled != Preferences::isPeXEnabled()) { + if(PeXEnabled != pref.isPeXEnabled()) { addConsoleMessage(tr("Restart is required to toggle PeX support"), QString::fromUtf8("red")); } // * LSD - if(Preferences::isLSDEnabled()) { + if(pref.isLSDEnabled()) { enableLSD(true); addConsoleMessage(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue")); } else { @@ -472,7 +474,7 @@ void QBtSession::configureSession() { addConsoleMessage(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue")); } // * Encryption - const int encryptionState = Preferences::getEncryptionSetting(); + const int encryptionState = pref.getEncryptionSetting(); // The most secure, rc4 only so that all streams and encrypted pe_settings encryptionSettings; encryptionSettings.allowed_enc_level = pe_settings::rc4; @@ -495,40 +497,40 @@ void QBtSession::configureSession() { } applyEncryptionSettings(encryptionSettings); // * Maximum ratio - high_ratio_action = Preferences::getMaxRatioAction(); - setMaxRatio(Preferences::getMaxRatio()); + high_ratio_action = pref.getMaxRatioAction(); + setMaxRatio(pref.getMaxRatio()); // Ip Filter - FilterParserThread::processFilterList(s, Preferences::bannedIPs()); - if(Preferences::isFilteringEnabled()) { - enableIPFilter(Preferences::getFilter()); + FilterParserThread::processFilterList(s, pref.bannedIPs()); + if(pref.isFilteringEnabled()) { + enableIPFilter(pref.getFilter()); }else{ disableIPFilter(); } // Update Web UI - if (Preferences::isWebUiEnabled()) { - const quint16 port = Preferences::getWebUiPort(); - const QString username = Preferences::getWebUiUsername(); - const QString password = Preferences::getWebUiPassword(); + if (pref.isWebUiEnabled()) { + const quint16 port = pref.getWebUiPort(); + const QString username = pref.getWebUiUsername(); + const QString password = pref.getWebUiPassword(); initWebUi(username, password, port); } else if(httpServer) { delete httpServer; } // * Proxy settings proxy_settings proxySettings; - if(Preferences::isPeerProxyEnabled()) { + if(pref.isPeerProxyEnabled()) { qDebug("Enabling P2P proxy"); - proxySettings.hostname = Preferences::getPeerProxyIp().toStdString(); + proxySettings.hostname = pref.getPeerProxyIp().toStdString(); qDebug("hostname is %s", proxySettings.hostname.c_str()); - proxySettings.port = Preferences::getPeerProxyPort(); + proxySettings.port = pref.getPeerProxyPort(); qDebug("port is %d", proxySettings.port); - if(Preferences::isPeerProxyAuthEnabled()) { - proxySettings.username = Preferences::getPeerProxyUsername().toStdString(); - proxySettings.password = Preferences::getPeerProxyPassword().toStdString(); + if(pref.isPeerProxyAuthEnabled()) { + proxySettings.username = pref.getPeerProxyUsername().toStdString(); + proxySettings.password = pref.getPeerProxyPassword().toStdString(); qDebug("username is %s", proxySettings.username.c_str()); qDebug("password is %s", proxySettings.password.c_str()); } } - switch(Preferences::getPeerProxyType()) { + switch(pref.getPeerProxyType()) { case Proxy::HTTP: qDebug("type: http"); proxySettings.type = proxy_settings::http; @@ -553,38 +555,38 @@ void QBtSession::configureSession() { setPeerProxySettings(proxySettings); // HTTP Proxy proxy_settings http_proxySettings; - qDebug("HTTP Communications proxy type: %d", Preferences::getHTTPProxyType()); - switch(Preferences::getHTTPProxyType()) { + qDebug("HTTP Communications proxy type: %d", pref.getHTTPProxyType()); + switch(pref.getHTTPProxyType()) { case Proxy::HTTP_PW: http_proxySettings.type = proxy_settings::http_pw; - http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString(); - http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString(); - http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); - http_proxySettings.port = Preferences::getHTTPProxyPort(); + http_proxySettings.username = pref.getHTTPProxyUsername().toStdString(); + http_proxySettings.password = pref.getHTTPProxyPassword().toStdString(); + http_proxySettings.hostname = pref.getHTTPProxyIp().toStdString(); + http_proxySettings.port = pref.getHTTPProxyPort(); break; case Proxy::HTTP: http_proxySettings.type = proxy_settings::http; - http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); - http_proxySettings.port = Preferences::getHTTPProxyPort(); + http_proxySettings.hostname = pref.getHTTPProxyIp().toStdString(); + http_proxySettings.port = pref.getHTTPProxyPort(); break; case Proxy::SOCKS5: http_proxySettings.type = proxy_settings::socks5; - http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); - http_proxySettings.port = Preferences::getHTTPProxyPort(); + http_proxySettings.hostname = pref.getHTTPProxyIp().toStdString(); + http_proxySettings.port = pref.getHTTPProxyPort(); break; case Proxy::SOCKS5_PW: http_proxySettings.type = proxy_settings::socks5_pw; - http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString(); - http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString(); - http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); - http_proxySettings.port = Preferences::getHTTPProxyPort(); + http_proxySettings.username = pref.getHTTPProxyUsername().toStdString(); + http_proxySettings.password = pref.getHTTPProxyPassword().toStdString(); + http_proxySettings.hostname = pref.getHTTPProxyIp().toStdString(); + http_proxySettings.port = pref.getHTTPProxyPort(); break; default: http_proxySettings.type = proxy_settings::none; } setHTTPProxySettings(http_proxySettings); // Tracker - if(Preferences::isTrackerEnabled()) { + if(pref.isTrackerEnabled()) { if(!m_tracker) { m_tracker = new QTracker(this); } @@ -623,20 +625,21 @@ bool QBtSession::initWebUi(QString username, QString password, int port) { void QBtSession::useAlternativeSpeedsLimit(bool alternative) { // Save new state to remember it on startup - Preferences::setAltBandwidthEnabled(alternative); + Preferences pref; + pref.setAltBandwidthEnabled(alternative); // Apply settings to the bittorrent session if(alternative) { - s->set_download_rate_limit(Preferences::getAltGlobalDownloadLimit()*1024); - s->set_upload_rate_limit(Preferences::getAltGlobalUploadLimit()*1024); + s->set_download_rate_limit(pref.getAltGlobalDownloadLimit()*1024); + s->set_upload_rate_limit(pref.getAltGlobalUploadLimit()*1024); } else { - int down_limit = Preferences::getGlobalDownloadLimit(); + int down_limit = pref.getGlobalDownloadLimit(); if(down_limit <= 0) { down_limit = -1; } else { down_limit *= 1024; } s->set_download_rate_limit(down_limit); - int up_limit = Preferences::getGlobalUploadLimit(); + int up_limit = pref.getGlobalUploadLimit(); if(up_limit <= 0) { up_limit = -1; } else { @@ -740,7 +743,7 @@ bool QBtSession::hasDownloadingTorrents() const { void QBtSession::banIP(QString ip) { FilterParserThread::processFilterList(s, QStringList(ip)); - Preferences::banIP(ip); + Preferences().banIP(ip); } // Delete a torrent from the session, given its hash @@ -853,10 +856,11 @@ bool QBtSession::loadFastResumeData(QString hash, std::vector &buf) { } void QBtSession::loadTorrentSettings(QTorrentHandle h) { + Preferences pref; // Connections limit per torrent - h.set_max_connections(Preferences::getMaxConnecsPerTorrent()); + h.set_max_connections(pref.getMaxConnecsPerTorrent()); // Uploads limit per torrent - h.set_max_uploads(Preferences::getMaxUploadsPerTorrent()); + h.set_max_uploads(pref.getMaxUploadsPerTorrent()); #ifndef DISABLE_GUI // Resolve countries h.resolve_countries(resolve_countries); @@ -944,7 +948,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed) { if(!resumed) { loadTorrentTempData(h, savePath, true); } - if(!fastResume && (!addInPause || (Preferences::useAdditionDialog()))) { + if(!fastResume && (!addInPause || (Preferences().useAdditionDialog()))) { // Start torrent because it was added in paused state h.resume(); } @@ -1130,7 +1134,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr exportTorrentFile(h); } - if(!fastResume && (!addInPause || (Preferences::useAdditionDialog() && !fromScanDir))) { + if(!fastResume && (!addInPause || (Preferences().useAdditionDialog() && !fromScanDir))) { // Start torrent because it was added in paused state h.resume(); } @@ -1159,7 +1163,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr void QBtSession::exportTorrentFile(QTorrentHandle h) { Q_ASSERT(torrentExport); QString torrent_path = QDir(misc::BTBackupLocation()).absoluteFilePath(h.hash()+".torrent"); - QDir exportPath(Preferences::getExportDir()); + QDir exportPath(Preferences().getExportDir()); if(exportPath.exists() || exportPath.mkpath(exportPath.absolutePath())) { QString new_torrent_path = exportPath.absoluteFilePath(h.name()+".torrent"); if(QFile::exists(new_torrent_path) && misc::sameFiles(torrent_path, new_torrent_path)) { @@ -1777,12 +1781,12 @@ void QBtSession::setAppendqBExtension(bool append) { // session will listen to void QBtSession::setListeningPort(int port) { std::pair ports(port, port); - const QString& iface_name = Preferences::getNetworkInterface(); + const QString& iface_name = Preferences().getNetworkInterface(); if(iface_name.isEmpty()) { s->listen_on(ports); return; } - QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name); + const QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name); if(!network_iface.isValid()) { qDebug("Invalid network interface: %s", qPrintable(iface_name)); addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red"); @@ -1963,7 +1967,7 @@ void QBtSession::cleanUpAutoRunProcess(int) { void QBtSession::autoRunExternalProgram(QTorrentHandle h, bool async) { if(!h.is_valid()) return; - QString program = Preferences::getAutoRunProgram().trimmed(); + QString program = Preferences().getAutoRunProgram().trimmed(); if(program.isEmpty()) return; // Replace %f by torrent path QString torrent_path; @@ -1990,7 +1994,7 @@ void QBtSession::sendNotificationEmail(QTorrentHandle h) { content += tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds").arg(misc::userFriendlyDuration(h.active_time())) + "\n\n\n"; content += tr("Thank you for using qBittorrent.") + "\n"; // Send the notification email - new Smtp("notification@qbittorrent.org", Preferences::getMailNotificationEmail(), tr("[qBittorrent] %1 has finished downloading").arg(h.name()), content); + new Smtp("notification@qbittorrent.org", Preferences().getMailNotificationEmail(), tr("[qBittorrent] %1 has finished downloading").arg(h.name()), content); } // Read alerts sent by the Bittorrent session @@ -2048,26 +2052,27 @@ void QBtSession::readAlerts() { qDebug("Saving seed status"); TorrentPersistentData::saveSeedStatus(h); // Recheck if the user asked to - if(Preferences::recheckTorrentsOnCompletion()) { + Preferences pref; + if(pref.recheckTorrentsOnCompletion()) { h.force_recheck(); } qDebug("Emitting finishedTorrent() signal"); emit finishedTorrent(h); qDebug("Received finished alert for %s", qPrintable(h.name())); - bool will_shutdown = (Preferences::shutdownWhenDownloadsComplete() || Preferences::shutdownqBTWhenDownloadsComplete()) + bool will_shutdown = (pref.shutdownWhenDownloadsComplete() || pref.shutdownqBTWhenDownloadsComplete()) && !hasDownloadingTorrents(); // AutoRun program - if(Preferences::isAutoRunEnabled()) + if(pref.isAutoRunEnabled()) autoRunExternalProgram(h, will_shutdown); // Mail notification - if(Preferences::isMailNotificationEnabled()) + if(pref.isMailNotificationEnabled()) sendNotificationEmail(h); // Auto-Shutdown if(will_shutdown) { - if(Preferences::shutdownWhenDownloadsComplete()) { + if(pref.shutdownWhenDownloadsComplete()) { qDebug("Preparing for auto-shutdown because all downloads are complete!"); // Disabling it for next time - Preferences::setShutdownWhenDownloadsComplete(false); + pref.setShutdownWhenDownloadsComplete(false); #if LIBTORRENT_VERSION_MINOR < 15 saveDHTEntry(); #endif diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index e212ec2f9..ceb3ce036 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -390,7 +390,7 @@ void QTorrentHandle::resume() { const QString torrent_hash = hash(); bool has_persistant_error = TorrentPersistentData::hasError(torrent_hash); TorrentPersistentData::setErrorState(torrent_hash, false); - bool temp_path_enabled = Preferences::isTempPathEnabled(); + bool temp_path_enabled = Preferences().isTempPathEnabled(); if(has_persistant_error && temp_path_enabled) { // Torrent was supposed to be seeding, checking again in final destination qDebug("Resuming a torrent with error..."); @@ -427,8 +427,9 @@ void QTorrentHandle::prioritize_files(const std::vector &v) { // Reset seed status TorrentPersistentData::saveSeedStatus(*this); // Move to temp folder if necessary - if(Preferences::isTempPathEnabled()) { - QString tmp_path = Preferences::getTempPath(); + const Preferences pref; + if(pref.isTempPathEnabled()) { + QString tmp_path = pref.getTempPath(); QString root_folder = TorrentPersistentData::getRootFolder(hash()); if(!root_folder.isEmpty()) tmp_path = QDir(tmp_path).absoluteFilePath(root_folder); @@ -444,8 +445,9 @@ void QTorrentHandle::file_priority(int index, int priority) const { // Save seed status TorrentPersistentData::saveSeedStatus(*this); // Move to temp folder if necessary - if(Preferences::isTempPathEnabled()) { - QString tmp_path = Preferences::getTempPath(); + const Preferences pref; + if(pref.isTempPathEnabled()) { + QString tmp_path = pref.getTempPath(); QString root_folder = TorrentPersistentData::getRootFolder(hash()); if(!root_folder.isEmpty()) tmp_path = QDir(tmp_path).absoluteFilePath(root_folder); diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index fc78a3373..27f40b87a 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -220,7 +220,7 @@ RssDownloadRule AutomatedRssDownloader::getCurrentRule() const void AutomatedRssDownloader::initLabelCombobox() { // Load custom labels - const QStringList customLabels = Preferences::getTorrentLabels(); + const QStringList customLabels = Preferences().getTorrentLabels(); foreach(const QString& label, customLabels) { ui->comboLabel->addItem(label); } @@ -252,7 +252,7 @@ void AutomatedRssDownloader::saveEditedRule() rule.setLabel(ui->comboLabel->currentText()); // Save new label if(!rule.label().isEmpty()) - Preferences::addTorrentLabel(rule.label()); + Preferences().addTorrentLabel(rule.label()); //rule.setRssFeeds(getSelectedFeeds()); // Save it m_ruleList->saveRule(rule); diff --git a/src/rss/rss_imp.cpp b/src/rss/rss_imp.cpp index 970e02237..77c2f7135 100644 --- a/src/rss/rss_imp.cpp +++ b/src/rss/rss_imp.cpp @@ -47,6 +47,7 @@ #include "rssfolder.h" #include "rssarticle.h" #include "rssfeed.h" +#include "rsssettings.h" #include "automatedrssdownloader.h" enum NewsCols { NEWS_ICON, NEWS_TITLE_COL, NEWS_URL_COL, NEWS_ID }; @@ -117,9 +118,9 @@ void RSSImp::on_actionManage_cookies_triggered() { qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname)); Q_ASSERT(!feed_hostname.isEmpty()); bool ok = false; - QList raw_cookies = CookiesDlg::askForCookies(this, Preferences::getHostNameCookies(feed_hostname), &ok); + QList raw_cookies = CookiesDlg::askForCookies(this, RssSettings::getHostNameCookies(feed_hostname), &ok); if(ok) { - Preferences::setHostNameCookies(feed_hostname, raw_cookies); + RssSettings::setHostNameCookies(feed_hostname, raw_cookies); } } @@ -642,7 +643,7 @@ RSSImp::~RSSImp(){ void RSSImp::on_settingsButton_clicked() { RssSettingsDlg dlg(this); if(dlg.exec()) - updateRefreshInterval(Preferences::getRefreshInterval()); + updateRefreshInterval(RssSettings::getRSSRefreshInterval()); } void RSSImp::on_rssDownloaderBtn_clicked() diff --git a/src/rss/rssdownloadrule.cpp b/src/rss/rssdownloadrule.cpp index 39748cf05..69c9418d2 100644 --- a/src/rss/rssdownloadrule.cpp +++ b/src/rss/rssdownloadrule.cpp @@ -120,7 +120,7 @@ bool RssDownloadRule::operator==(const RssDownloadRule &other) { void RssDownloadRule::setSavePath(const QString &save_path) { - if(!save_path.isEmpty() && QDir(save_path) != QDir(Preferences::getSavePath())) + if(!save_path.isEmpty() && QDir(save_path) != QDir(Preferences().getSavePath())) m_savePath = save_path; else m_savePath = QString(); diff --git a/src/rss/rsssettings.h b/src/rss/rsssettings.h index 02ddbf9d0..4800d6654 100644 --- a/src/rss/rsssettings.h +++ b/src/rss/rsssettings.h @@ -95,6 +95,27 @@ public: QIniSettings settings("qBittorrent", "qBittorrent"); settings.setValue("Rss/streamAlias", rssAliases); } + + static QList getHostNameCookies(const QString &host_name) { + QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); + QMap hosts_table = qBTRSS.value("hosts_cookies", QMap()).toMap(); + if(!hosts_table.contains(host_name)) return QList(); + QByteArray raw_cookies = hosts_table.value(host_name).toByteArray(); + return raw_cookies.split(':'); + } + + static void setHostNameCookies(QString host_name, const QList &cookies) { + QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); + QMap hosts_table = qBTRSS.value("hosts_cookies", QMap()).toMap(); + QByteArray raw_cookies = ""; + foreach(const QByteArray& cookie, cookies) { + raw_cookies += cookie + ":"; + } + if(raw_cookies.endsWith(":")) + raw_cookies.chop(1); + hosts_table.insert(host_name, raw_cookies); + qBTRSS.setValue("hosts_cookies", hosts_table); + } }; #endif // RSSSETTINGS_H diff --git a/src/smtp.cpp b/src/smtp.cpp index 51dc07a19..4e0df7930 100644 --- a/src/smtp.cpp +++ b/src/smtp.cpp @@ -28,7 +28,7 @@ Smtp::Smtp(const QString &from, const QString &to, const QString &subject, const this->from = from; rcpt = to; state = Init; - socket->connectToHost(Preferences::getMailNotificationSMTP(), 25); + socket->connectToHost(Preferences().getMailNotificationSMTP(), 25); if(socket->waitForConnected ( 30000 )) { qDebug("connected"); } else { diff --git a/src/statusbar.h b/src/statusbar.h index 15886c618..522d8b326 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -49,6 +49,7 @@ class StatusBar: public QObject { public: StatusBar(QStatusBar *bar): bar(bar) { + Preferences pref; connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool))); container = new QWidget(); layout = new QGridLayout(container); @@ -75,7 +76,7 @@ public: altSpeedsBtn->setFlat(true); altSpeedsBtn->setFocusPolicy(Qt::NoFocus); altSpeedsBtn->setCursor(Qt::PointingHandCursor); - updateAltSpeedsBtn(Preferences::isAltBandwidthEnabled()); + updateAltSpeedsBtn(pref.isAltBandwidthEnabled()); connect(altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds())); @@ -129,7 +130,7 @@ public: bar->setContentsMargins(12, 0, 12, 0); bar->setFixedHeight(dlSpeedLbl->fontMetrics().height()+9); // Is DHT enabled - DHTLbl->setVisible(Preferences::isDHTEnabled()); + DHTLbl->setVisible(pref.isDHTEnabled()); refreshTimer = new QTimer(bar); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshStatusBar())); refreshTimer->start(1500); @@ -216,24 +217,25 @@ public slots: } void toggleAlternativeSpeeds() { - QBtSession::instance()->useAlternativeSpeedsLimit(!Preferences::isAltBandwidthEnabled()); + QBtSession::instance()->useAlternativeSpeedsLimit(!Preferences().isAltBandwidthEnabled()); } void capDownloadSpeed() { bool ok = false; long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), QBtSession::instance()->getSession()->download_rate_limit()); if(ok) { - bool alt = Preferences::isAltBandwidthEnabled(); + Preferences pref; + bool alt = pref.isAltBandwidthEnabled(); if(new_limit <= 0) { qDebug("Setting global download rate limit to Unlimited"); if(!alt) QBtSession::instance()->getSession()->set_download_rate_limit(-1); - Preferences::setGlobalDownloadLimit(-1); + pref.setGlobalDownloadLimit(-1); } else { qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); if(!alt) QBtSession::instance()->getSession()->set_download_rate_limit(new_limit); - Preferences::setGlobalDownloadLimit(new_limit/1024.); + pref.setGlobalDownloadLimit(new_limit/1024.); } } } @@ -245,10 +247,10 @@ public slots: if(new_limit <= 0) { qDebug("Setting global upload rate limit to Unlimited"); QBtSession::instance()->getSession()->set_upload_rate_limit(-1); - Preferences::setGlobalUploadLimit(-1); + Preferences().setGlobalUploadLimit(-1); } else { qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); - Preferences::setGlobalUploadLimit(new_limit/1024.); + Preferences().setGlobalUploadLimit(new_limit/1024.); QBtSession::instance()->getSession()->set_upload_rate_limit(new_limit); } } diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index ee3aab8bf..fbf97083a 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -56,6 +56,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : QDialog(parent), old_label(""), hidden_height(0) { + const Preferences pref; setupUi(this); setAttribute(Qt::WA_DeleteOnClose); // Set Properties list model @@ -77,8 +78,8 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : // Remember columns width readSettings(); //torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch); - defaultSavePath = Preferences::getSavePath(); - appendLabelToSavePath = Preferences::appendTorrentLabel(); + defaultSavePath = pref.getSavePath(); + appendLabelToSavePath = pref.appendTorrentLabel(); QString display_path = defaultSavePath.replace("\\", "/"); if(!display_path.endsWith("/")) display_path += "/"; @@ -88,7 +89,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : #endif savePathTxt->addItem(display_path); - if(Preferences::addTorrentsInPause()) { + if(pref.addTorrentsInPause()) { addInPause->setChecked(true); //addInPause->setEnabled(false); } diff --git a/src/tracker/qtracker.cpp b/src/tracker/qtracker.cpp index 83539fb6a..6ce509bde 100644 --- a/src/tracker/qtracker.cpp +++ b/src/tracker/qtracker.cpp @@ -42,7 +42,7 @@ using namespace libtorrent; QTracker::QTracker(QObject *parent) : QTcpServer(parent) { - Q_ASSERT(Preferences::isTrackerEnabled()); + Q_ASSERT(Preferences().isTrackerEnabled()); connect(this, SIGNAL(newConnection()), this, SLOT(handlePeerConnection())); } @@ -66,7 +66,7 @@ void QTracker::handlePeerConnection() bool QTracker::start() { - const int listen_port = Preferences::getTrackerPort(); + const int listen_port = Preferences().getTrackerPort(); // if(isListening()) { if(serverPort() == listen_port) { diff --git a/src/transferlistfilterswidget.h b/src/transferlistfilterswidget.h index de2db1d8e..df7d82942 100644 --- a/src/transferlistfilterswidget.h +++ b/src/transferlistfilterswidget.h @@ -285,7 +285,7 @@ public: void loadSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); statusFilters->setCurrentRow(settings.value("TransferListFilters/selectedFilterIndex", 0).toInt()); - const QStringList label_list = Preferences::getTorrentLabels(); + const QStringList label_list = Preferences().getTorrentLabels(); foreach(const QString &label, label_list) { customLabels.insert(label, 0); qDebug("Creating label QListWidgetItem: %s", qPrintable(label)); @@ -324,7 +324,7 @@ protected slots: newLabel->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/folder.png")); labelFilters->addItem(newLabel); customLabels.insert(label, 0); - Preferences::addTorrentLabel(label); + Preferences().addTorrentLabel(label); } void showLabelMenu(QPoint) { @@ -391,7 +391,7 @@ protected slots: // Un display filter delete labelFilters->takeItem(row); // Save custom labels to remember it was deleted - Preferences::removeTorrentLabel(label); + Preferences().removeTorrentLabel(label); } void applyLabelFilter(int row) { diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index c08f46fd4..7b62d4cbc 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -180,9 +180,9 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) { if(!h.is_valid()) return; int action; if(h.is_seed()) { - action = Preferences::getActionOnDblClOnTorrentFn(); + action = Preferences().getActionOnDblClOnTorrentFn(); } else { - action = Preferences::getActionOnDblClOnTorrentDl(); + action = Preferences().getActionOnDblClOnTorrentDl(); } switch(action) { @@ -424,7 +424,7 @@ void TransferListWidget::setDlLimitSelectedTorrents() { int default_limit = -1; if(all_same_limit) default_limit = selected_torrents.first().download_limit(); - const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences::getGlobalDownloadLimit()*1024.); + const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences().getGlobalDownloadLimit()*1024.); if(ok) { foreach(const QTorrentHandle &h, selected_torrents) { qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash())); @@ -457,7 +457,7 @@ void TransferListWidget::setUpLimitSelectedTorrents() { int default_limit = -1; if(all_same_limit) default_limit = selected_torrents.first().upload_limit(); - const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences::getGlobalUploadLimit()*1024.); + const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences().getGlobalUploadLimit()*1024.); if(ok) { foreach(const QTorrentHandle &h, selected_torrents) { qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash())); diff --git a/src/webui/eventmanager.cpp b/src/webui/eventmanager.cpp index 0daa8f356..1f6c01608 100644 --- a/src/webui/eventmanager.cpp +++ b/src/webui/eventmanager.cpp @@ -125,9 +125,10 @@ QList EventManager::getPropFilesInfo(QString hash) const { void EventManager::setGlobalPreferences(QVariantMap m) const { // UI + Preferences pref; if(m.contains("locale")) { QString locale = m["locale"].toString(); - if(Preferences::getLocale() != locale) { + if(pref.getLocale() != locale) { QTranslator *translator = new QTranslator; if(translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){ qDebug("%s locale recognized, using translation.", qPrintable(locale)); @@ -137,26 +138,26 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { qApp->installTranslator(translator); } - Preferences::setLocale(locale); + pref.setLocale(locale); } // Downloads if(m.contains("save_path")) - Preferences::setSavePath(m["save_path"].toString()); + pref.setSavePath(m["save_path"].toString()); if(m.contains("temp_path_enabled")) - Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool()); + pref.setTempPathEnabled(m["temp_path_enabled"].toBool()); if(m.contains("temp_path")) - Preferences::setTempPath(m["temp_path"].toString()); + pref.setTempPath(m["temp_path"].toString()); if(m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) { QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList(); QList download_at_path; foreach(QVariant var, download_at_path_tmp) { download_at_path << var.toBool(); } - QStringList old_folders = Preferences::getScanDirs(); + QStringList old_folders = pref.getScanDirs(); QStringList new_folders = m["scan_dirs"].toStringList(); if(download_at_path.size() == new_folders.size()) { - Preferences::setScanDirs(new_folders); - Preferences::setDownloadInScanDirs(download_at_path); + pref.setScanDirs(new_folders); + pref.setDownloadInScanDirs(download_at_path); foreach(const QString &old_folder, old_folders) { // Update deleted folders if(!new_folders.contains(old_folder)) { @@ -175,168 +176,169 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { } } if(m.contains("export_dir")) - Preferences::setExportDir(m["export_dir"].toString()); + pref.setExportDir(m["export_dir"].toString()); if(m.contains("mail_notification_enabled")) - Preferences::setMailNotificationEnabled(m["mail_notification_enabled"].toBool()); + pref.setMailNotificationEnabled(m["mail_notification_enabled"].toBool()); if(m.contains("mail_notification_email")) - Preferences::setMailNotificationEmail(m["mail_notification_email"].toString()); + pref.setMailNotificationEmail(m["mail_notification_email"].toString()); if(m.contains("mail_notification_smtp")) - Preferences::setMailNotificationSMTP(m["mail_notification_smtp"].toString()); + pref.setMailNotificationSMTP(m["mail_notification_smtp"].toString()); if(m.contains("autorun_enabled")) - Preferences::setAutoRunEnabled(m["autorun_enabled"].toBool()); + pref.setAutoRunEnabled(m["autorun_enabled"].toBool()); if(m.contains("autorun_program")) - Preferences::setAutoRunProgram(m["autorun_program"].toString()); + pref.setAutoRunProgram(m["autorun_program"].toString()); if(m.contains("preallocate_all")) - Preferences::preAllocateAllFiles(m["preallocate_all"].toBool()); + pref.preAllocateAllFiles(m["preallocate_all"].toBool()); if(m.contains("queueing_enabled")) - Preferences::setQueueingSystemEnabled(m["queueing_enabled"].toBool()); + pref.setQueueingSystemEnabled(m["queueing_enabled"].toBool()); if(m.contains("max_active_downloads")) - Preferences::setMaxActiveDownloads(m["max_active_downloads"].toInt()); + pref.setMaxActiveDownloads(m["max_active_downloads"].toInt()); if(m.contains("max_active_torrents")) - Preferences::setMaxActiveTorrents(m["max_active_torrents"].toInt()); + pref.setMaxActiveTorrents(m["max_active_torrents"].toInt()); if(m.contains("max_active_uploads")) - Preferences::setMaxActiveUploads(m["max_active_uploads"].toInt()); + pref.setMaxActiveUploads(m["max_active_uploads"].toInt()); #if LIBTORRENT_VERSION_MINOR > 14 if(m.contains("incomplete_files_ext")) - Preferences::useIncompleteFilesExtension(m["incomplete_files_ext"].toBool()); + pref.useIncompleteFilesExtension(m["incomplete_files_ext"].toBool()); #endif // Connection if(m.contains("listen_port")) - Preferences::setSessionPort(m["listen_port"].toInt()); + pref.setSessionPort(m["listen_port"].toInt()); if(m.contains("upnp")) - Preferences::setUPnPEnabled(m["upnp"].toBool()); + pref.setUPnPEnabled(m["upnp"].toBool()); if(m.contains("natpmp")) - Preferences::setNATPMPEnabled(m["natpmp"].toBool()); + pref.setNATPMPEnabled(m["natpmp"].toBool()); if(m.contains("dl_limit")) - Preferences::setGlobalDownloadLimit(m["dl_limit"].toInt()); + pref.setGlobalDownloadLimit(m["dl_limit"].toInt()); if(m.contains("up_limit")) - Preferences::setGlobalUploadLimit(m["up_limit"].toInt()); + pref.setGlobalUploadLimit(m["up_limit"].toInt()); if(m.contains("max_connec")) - Preferences::setMaxConnecs(m["max_connec"].toInt()); + pref.setMaxConnecs(m["max_connec"].toInt()); if(m.contains("max_connec_per_torrent")) - Preferences::setMaxConnecsPerTorrent(m["max_connec_per_torrent"].toInt()); + pref.setMaxConnecsPerTorrent(m["max_connec_per_torrent"].toInt()); if(m.contains("max_uploads_per_torrent")) - Preferences::setMaxUploadsPerTorrent(m["max_uploads_per_torrent"].toInt()); + pref.setMaxUploadsPerTorrent(m["max_uploads_per_torrent"].toInt()); // Bittorrent if(m.contains("dht")) - Preferences::setDHTEnabled(m["dht"].toBool()); + pref.setDHTEnabled(m["dht"].toBool()); if(m.contains("dhtSameAsBT")) - Preferences::setDHTPortSameAsBT(m["dhtSameAsBT"].toBool()); + pref.setDHTPortSameAsBT(m["dhtSameAsBT"].toBool()); if(m.contains("dht_port")) - Preferences::setDHTPort(m["dht_port"].toInt()); + pref.setDHTPort(m["dht_port"].toInt()); if(m.contains("pex")) - Preferences::setPeXEnabled(m["pex"].toBool()); + pref.setPeXEnabled(m["pex"].toBool()); qDebug("Pex support: %d", (int)m["pex"].toBool()); if(m.contains("lsd")) - Preferences::setLSDEnabled(m["lsd"].toBool()); + pref.setLSDEnabled(m["lsd"].toBool()); if(m.contains("encryption")) - Preferences::setEncryptionSetting(m["encryption"].toInt()); + pref.setEncryptionSetting(m["encryption"].toInt()); // Proxy if(m.contains("proxy_type")) - Preferences::setPeerProxyType(m["proxy_type"].toInt()); + pref.setPeerProxyType(m["proxy_type"].toInt()); if(m.contains("proxy_ip")) - Preferences::setPeerProxyIp(m["proxy_ip"].toString()); + pref.setPeerProxyIp(m["proxy_ip"].toString()); if(m.contains("proxy_port")) - Preferences::setPeerProxyPort(m["proxy_port"].toUInt()); + pref.setPeerProxyPort(m["proxy_port"].toUInt()); if(m.contains("proxy_auth_enabled")) - Preferences::setPeerProxyAuthEnabled(m["proxy_auth_enabled"].toBool()); + pref.setPeerProxyAuthEnabled(m["proxy_auth_enabled"].toBool()); if(m.contains("proxy_username")) - Preferences::setPeerProxyUsername(m["proxy_username"].toString()); + pref.setPeerProxyUsername(m["proxy_username"].toString()); if(m.contains("proxy_password")) - Preferences::setPeerProxyPassword(m["proxy_password"].toString()); + pref.setPeerProxyPassword(m["proxy_password"].toString()); if(m.contains("http_proxy_type")) - Preferences::setHTTPProxyType(m["http_proxy_type"].toInt()); + pref.setHTTPProxyType(m["http_proxy_type"].toInt()); if(m.contains("http_proxy_ip")) - Preferences::setHTTPProxyIp(m["http_proxy_ip"].toString()); + pref.setHTTPProxyIp(m["http_proxy_ip"].toString()); if(m.contains("http_proxy_port")) - Preferences::setHTTPProxyPort(m["http_proxy_port"].toUInt()); + pref.setHTTPProxyPort(m["http_proxy_port"].toUInt()); if(m.contains("http_proxy_auth_enabled")) - Preferences::setHTTPProxyAuthEnabled(m["http_proxy_auth_enabled"].toBool()); + pref.setHTTPProxyAuthEnabled(m["http_proxy_auth_enabled"].toBool()); if(m.contains("http_proxy_username")) - Preferences::setHTTPProxyUsername(m["http_proxy_username"].toString()); + pref.setHTTPProxyUsername(m["http_proxy_username"].toString()); if(m.contains("http_proxy_password")) - Preferences::setHTTPProxyPassword(m["http_proxy_password"].toString()); + pref.setHTTPProxyPassword(m["http_proxy_password"].toString()); // IP Filter if(m.contains("ip_filter_enabled")) - Preferences::setFilteringEnabled(m["ip_filter_enabled"].toBool()); + pref.setFilteringEnabled(m["ip_filter_enabled"].toBool()); if(m.contains("ip_filter_path")) - Preferences::setFilter(m["ip_filter_path"].toString()); + pref.setFilter(m["ip_filter_path"].toString()); // Web UI if(m.contains("web_ui_port")) - Preferences::setWebUiPort(m["web_ui_port"].toUInt()); + pref.setWebUiPort(m["web_ui_port"].toUInt()); if(m.contains("web_ui_username")) - Preferences::setWebUiUsername(m["web_ui_username"].toString()); + pref.setWebUiUsername(m["web_ui_username"].toString()); if(m.contains("web_ui_password")) - Preferences::setWebUiPassword(m["web_ui_password"].toString()); + pref.setWebUiPassword(m["web_ui_password"].toString()); // Reload preferences QBtSession::instance()->configureSession(); } QVariantMap EventManager::getGlobalPreferences() const { + const Preferences pref; QVariantMap data; // UI - data["locale"] = Preferences::getLocale(); + data["locale"] = pref.getLocale(); // Downloads - data["save_path"] = Preferences::getSavePath(); - data["temp_path_enabled"] = Preferences::isTempPathEnabled(); - data["temp_path"] = Preferences::getTempPath(); - data["scan_dirs"] = Preferences::getScanDirs(); + data["save_path"] = pref.getSavePath(); + data["temp_path_enabled"] = pref.isTempPathEnabled(); + data["temp_path"] = pref.getTempPath(); + data["scan_dirs"] = pref.getScanDirs(); QVariantList var_list; - foreach(bool b, Preferences::getDownloadInScanDirs()) { + foreach(bool b, pref.getDownloadInScanDirs()) { var_list << b; } data["download_in_scan_dirs"] = var_list; - data["export_dir_enabled"] = Preferences::isTorrentExportEnabled(); - data["export_dir"] = Preferences::getExportDir(); - data["mail_notification_enabled"] = Preferences::isMailNotificationEnabled(); - data["mail_notification_email"] = Preferences::getMailNotificationEmail(); - data["mail_notification_smtp"] = Preferences::getMailNotificationSMTP(); - data["autorun_enabled"] = Preferences::isAutoRunEnabled(); - data["autorun_program"] = Preferences::getAutoRunProgram(); - data["preallocate_all"] = Preferences::preAllocateAllFiles(); - data["queueing_enabled"] = Preferences::isQueueingSystemEnabled(); - data["max_active_downloads"] = Preferences::getMaxActiveDownloads(); - data["max_active_torrents"] = Preferences::getMaxActiveTorrents(); - data["max_active_uploads"] = Preferences::getMaxActiveUploads(); + data["export_dir_enabled"] = pref.isTorrentExportEnabled(); + data["export_dir"] = pref.getExportDir(); + data["mail_notification_enabled"] = pref.isMailNotificationEnabled(); + data["mail_notification_email"] = pref.getMailNotificationEmail(); + data["mail_notification_smtp"] = pref.getMailNotificationSMTP(); + data["autorun_enabled"] = pref.isAutoRunEnabled(); + data["autorun_program"] = pref.getAutoRunProgram(); + data["preallocate_all"] = pref.preAllocateAllFiles(); + data["queueing_enabled"] = pref.isQueueingSystemEnabled(); + data["max_active_downloads"] = pref.getMaxActiveDownloads(); + data["max_active_torrents"] = pref.getMaxActiveTorrents(); + data["max_active_uploads"] = pref.getMaxActiveUploads(); #if LIBTORRENT_VERSION_MINOR > 14 - data["incomplete_files_ext"] = Preferences::useIncompleteFilesExtension(); + data["incomplete_files_ext"] = pref.useIncompleteFilesExtension(); #endif // Connection - data["listen_port"] = Preferences::getSessionPort(); - data["upnp"] = Preferences::isUPnPEnabled(); - data["natpmp"] = Preferences::isNATPMPEnabled(); - data["dl_limit"] = Preferences::getGlobalDownloadLimit(); - data["up_limit"] = Preferences::getGlobalUploadLimit(); - data["max_connec"] = Preferences::getMaxConnecs(); - data["max_connec_per_torrent"] = Preferences::getMaxConnecsPerTorrent(); - data["max_uploads_per_torrent"] = Preferences::getMaxUploadsPerTorrent(); + data["listen_port"] = pref.getSessionPort(); + data["upnp"] = pref.isUPnPEnabled(); + data["natpmp"] = pref.isNATPMPEnabled(); + data["dl_limit"] = pref.getGlobalDownloadLimit(); + data["up_limit"] = pref.getGlobalUploadLimit(); + data["max_connec"] = pref.getMaxConnecs(); + data["max_connec_per_torrent"] = pref.getMaxConnecsPerTorrent(); + data["max_uploads_per_torrent"] = pref.getMaxUploadsPerTorrent(); // Bittorrent - data["dht"] = Preferences::isDHTEnabled(); - data["dhtSameAsBT"] = Preferences::isDHTPortSameAsBT(); - data["dht_port"] = Preferences::getDHTPort(); - data["pex"] = Preferences::isPeXEnabled(); - data["lsd"] = Preferences::isLSDEnabled(); - data["encryption"] = Preferences::getEncryptionSetting(); + data["dht"] = pref.isDHTEnabled(); + data["dhtSameAsBT"] = pref.isDHTPortSameAsBT(); + data["dht_port"] = pref.getDHTPort(); + data["pex"] = pref.isPeXEnabled(); + data["lsd"] = pref.isLSDEnabled(); + data["encryption"] = pref.getEncryptionSetting(); // Proxy - data["proxy_type"] = Preferences::getPeerProxyType(); - data["proxy_ip"] = Preferences::getPeerProxyIp(); - data["proxy_port"] = Preferences::getPeerProxyPort(); - data["proxy_auth_enabled"] = Preferences::isPeerProxyAuthEnabled(); - data["proxy_username"] = Preferences::getPeerProxyUsername(); - data["proxy_password"] = Preferences::getPeerProxyPassword(); - data["http_proxy_type"] = Preferences::getHTTPProxyType(); - data["http_proxy_ip"] = Preferences::getHTTPProxyIp(); - data["http_proxy_port"] = Preferences::getHTTPProxyPort(); - data["http_proxy_auth_enabled"] = Preferences::isHTTPProxyAuthEnabled(); - data["http_proxy_username"] = Preferences::getHTTPProxyUsername(); - data["http_proxy_password"] = Preferences::getHTTPProxyPassword(); + data["proxy_type"] = pref.getPeerProxyType(); + data["proxy_ip"] = pref.getPeerProxyIp(); + data["proxy_port"] = pref.getPeerProxyPort(); + data["proxy_auth_enabled"] = pref.isPeerProxyAuthEnabled(); + data["proxy_username"] = pref.getPeerProxyUsername(); + data["proxy_password"] = pref.getPeerProxyPassword(); + data["http_proxy_type"] = pref.getHTTPProxyType(); + data["http_proxy_ip"] = pref.getHTTPProxyIp(); + data["http_proxy_port"] = pref.getHTTPProxyPort(); + data["http_proxy_auth_enabled"] = pref.isHTTPProxyAuthEnabled(); + data["http_proxy_username"] = pref.getHTTPProxyUsername(); + data["http_proxy_password"] = pref.getHTTPProxyPassword(); // IP Filter - data["ip_filter_enabled"] = Preferences::isFilteringEnabled(); - data["ip_filter_path"] = Preferences::getFilter(); + data["ip_filter_enabled"] = pref.isFilteringEnabled(); + data["ip_filter_path"] = pref.getFilter(); // Web UI - data["web_ui_port"] = Preferences::getWebUiPort(); - data["web_ui_username"] = Preferences::getWebUiUsername(); - data["web_ui_password"] = Preferences::getWebUiPassword(); + data["web_ui_port"] = pref.getWebUiPort(); + data["web_ui_username"] = pref.getWebUiUsername(); + data["web_ui_password"] = pref.getWebUiPassword(); return data; } diff --git a/src/webui/httpconnection.cpp b/src/webui/httpconnection.cpp index d4da2a403..6d68e5c46 100644 --- a/src/webui/httpconnection.cpp +++ b/src/webui/httpconnection.cpp @@ -473,13 +473,13 @@ void HttpConnection::respondCommand(QString command) qlonglong limit = parser.post("limit").toLongLong(); if(limit == 0) limit = -1; QBtSession::instance()->getSession()->set_upload_rate_limit(limit); - Preferences::setGlobalUploadLimit(limit/1024.); + Preferences().setGlobalUploadLimit(limit/1024.); } if(command == "setGlobalDlLimit") { qlonglong limit = parser.post("limit").toLongLong(); if(limit == 0) limit = -1; QBtSession::instance()->getSession()->set_download_rate_limit(limit); - Preferences::setGlobalDownloadLimit(limit/1024.); + Preferences().setGlobalDownloadLimit(limit/1024.); } if(command == "pause") { emit pauseTorrent(parser.post("hash")); diff --git a/src/webui/httpserver.cpp b/src/webui/httpserver.cpp index 99860a491..4aa9494b6 100644 --- a/src/webui/httpserver.cpp +++ b/src/webui/httpserver.cpp @@ -81,8 +81,9 @@ void HttpServer::resetNbFailedAttemptsForIp(QString ip) { } HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent) { - username = Preferences::getWebUiUsername().toLocal8Bit(); - password_ha1 = Preferences::getWebUiPassword().toLocal8Bit(); + const Preferences pref; + username = pref.getWebUiUsername().toLocal8Bit(); + password_ha1 = pref.getWebUiPassword().toLocal8Bit(); connect(this, SIGNAL(newConnection()), this, SLOT(newHttpConnection())); manager = new EventManager(this); //add torrents