mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-04 14:42:29 -06:00
Restructured the project file
Move OS specific configuration to separate project files
This commit is contained in:
228
src/preferences/advancedsettings.h
Normal file
228
src/preferences/advancedsettings.h
Normal file
@@ -0,0 +1,228 @@
|
||||
#ifndef ADVANCEDSETTINGS_H
|
||||
#define ADVANCEDSETTINGS_H
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QNetworkInterface>
|
||||
#include <libtorrent/version.hpp>
|
||||
#include "preferences.h"
|
||||
|
||||
enum AdvSettingsCols {PROPERTY, VALUE};
|
||||
enum AdvSettingsRows {DISK_CACHE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_LIMIT_LAN, COUNT_OVERHEAD, RECHECK_COMPLETED, LIST_REFRESH, RESOLVE_COUNTRIES, RESOLVE_HOSTS, MAX_HALF_OPEN, SUPER_SEEDING, NETWORK_IFACE, PROGRAM_NOTIFICATIONS, TRACKER_STATUS, TRACKER_PORT, ROW_COUNT };
|
||||
|
||||
class AdvancedSettings: public QTableWidget {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QSpinBox *spin_cache, *outgoing_ports_min, *outgoing_ports_max, *spin_list_refresh, *spin_maxhalfopen, *spin_tracker_port;
|
||||
QCheckBox *cb_ignore_limits_lan, *cb_count_overhead, *cb_recheck_completed, *cb_resolve_countries, *cb_resolve_hosts, *cb_super_seeding, *cb_program_notifications, *cb_tracker_status;
|
||||
QComboBox *combo_iface;
|
||||
|
||||
public:
|
||||
AdvancedSettings(QWidget *parent=0): QTableWidget(parent) {
|
||||
// Set visual appearance
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
setAlternatingRowColors(true);
|
||||
setColumnCount(2);
|
||||
QStringList header;
|
||||
header << tr("Property") << tr("Value");
|
||||
setHorizontalHeaderLabels(header);
|
||||
setColumnWidth(0, width()/2);
|
||||
horizontalHeader()->setStretchLastSection(true);
|
||||
verticalHeader()->setVisible(false);
|
||||
setRowCount(ROW_COUNT);
|
||||
// Load settings
|
||||
loadAdvancedSettings();
|
||||
}
|
||||
|
||||
~AdvancedSettings() {
|
||||
delete spin_cache;
|
||||
delete outgoing_ports_min;
|
||||
delete outgoing_ports_max;
|
||||
delete cb_ignore_limits_lan;
|
||||
delete cb_count_overhead;
|
||||
delete cb_recheck_completed;
|
||||
delete spin_list_refresh;
|
||||
delete cb_resolve_countries;
|
||||
delete cb_resolve_hosts;
|
||||
delete spin_maxhalfopen;
|
||||
delete cb_super_seeding;
|
||||
delete combo_iface;
|
||||
delete cb_program_notifications;
|
||||
delete spin_tracker_port;
|
||||
delete cb_tracker_status;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void saveAdvancedSettings() {
|
||||
Preferences pref;
|
||||
// Disk write cache
|
||||
pref.setDiskCacheSize(spin_cache->value());
|
||||
// Outgoing ports
|
||||
pref.setOutgoingPortsMin(outgoing_ports_min->value());
|
||||
pref.setOutgoingPortsMax(outgoing_ports_max->value());
|
||||
// Ignore limits on LAN
|
||||
pref.ignoreLimitsOnLAN(cb_ignore_limits_lan->isChecked());
|
||||
// Include protocol overhead in transfer limits
|
||||
pref.includeOverheadInLimits(cb_count_overhead->isChecked());
|
||||
// Recheck torrents on completion
|
||||
pref.recheckTorrentsOnCompletion(cb_recheck_completed->isChecked());
|
||||
// Transfer list refresh interval
|
||||
pref.setRefreshInterval(spin_list_refresh->value());
|
||||
// Peer resolution
|
||||
pref.resolvePeerCountries(cb_resolve_countries->isChecked());
|
||||
pref.resolvePeerHostNames(cb_resolve_hosts->isChecked());
|
||||
// Max Half-Open connections
|
||||
pref.setMaxHalfOpenConnections(spin_maxhalfopen->value());
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Super seeding
|
||||
pref.enableSuperSeeding(cb_super_seeding->isChecked());
|
||||
#endif
|
||||
// Network interface
|
||||
if(combo_iface->currentIndex() == 0) {
|
||||
// All interfaces (default)
|
||||
pref.setNetworkInterface(QString::null);
|
||||
} else {
|
||||
pref.setNetworkInterface(combo_iface->currentText());
|
||||
}
|
||||
// Program notification
|
||||
pref.useProgramNotification(cb_program_notifications->isChecked());
|
||||
// Tracker
|
||||
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(pref.diskCacheSize());
|
||||
spin_cache->setSuffix(tr(" MiB"));
|
||||
setCellWidget(DISK_CACHE, VALUE, spin_cache);
|
||||
// Outgoing port Min
|
||||
setItem(OUTGOING_PORT_MIN, PROPERTY, new QTableWidgetItem(tr("Outgoing ports (Min) [0: Disabled]")));
|
||||
outgoing_ports_min = new QSpinBox();
|
||||
connect(outgoing_ports_min, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged()));
|
||||
outgoing_ports_min->setMinimum(0);
|
||||
outgoing_ports_min->setMaximum(65535);
|
||||
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]")));
|
||||
outgoing_ports_max = new QSpinBox();
|
||||
connect(outgoing_ports_max, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged()));
|
||||
outgoing_ports_max->setMinimum(0);
|
||||
outgoing_ports_max->setMaximum(65535);
|
||||
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(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(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(pref.recheckTorrentsOnCompletion());
|
||||
setCellWidget(RECHECK_COMPLETED, VALUE, cb_recheck_completed);
|
||||
// Transfer list refresh interval
|
||||
setItem(LIST_REFRESH, PROPERTY, new QTableWidgetItem(tr("Transfer list refresh interval")));
|
||||
spin_list_refresh = new QSpinBox();
|
||||
connect(spin_list_refresh, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged()));
|
||||
spin_list_refresh->setMinimum(30);
|
||||
spin_list_refresh->setMaximum(99999);
|
||||
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(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(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]")));
|
||||
spin_maxhalfopen = new QSpinBox();
|
||||
connect(spin_maxhalfopen, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged()));
|
||||
spin_maxhalfopen->setMinimum(0);
|
||||
spin_maxhalfopen->setMaximum(99999);
|
||||
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(pref.isSuperSeedingEnabled());
|
||||
#else
|
||||
cb_super_seeding->setEnabled(false);
|
||||
#endif
|
||||
setCellWidget(SUPER_SEEDING, VALUE, cb_super_seeding);
|
||||
// Network interface
|
||||
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 = pref.getNetworkInterface();
|
||||
int i = 1;
|
||||
foreach(const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
|
||||
if(iface.name() == "lo") continue;
|
||||
combo_iface->addItem(iface.name());
|
||||
if(!current_iface.isEmpty() && iface.name() == current_iface)
|
||||
combo_iface->setCurrentIndex(i);
|
||||
++i;
|
||||
}
|
||||
connect(combo_iface, SIGNAL(currentIndexChanged(int)), this, SLOT(emitSettingsChanged()));
|
||||
setCellWidget(NETWORK_IFACE, VALUE, combo_iface);
|
||||
// Program notifications
|
||||
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(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(pref.isTrackerEnabled());
|
||||
setCellWidget(TRACKER_STATUS, VALUE, cb_tracker_status);
|
||||
// Tracker port
|
||||
setItem(TRACKER_PORT, PROPERTY, new QTableWidgetItem(tr("Embedded tracker port")));
|
||||
spin_tracker_port = new QSpinBox();
|
||||
connect(spin_tracker_port, SIGNAL(valueChanged(int)), this, SLOT(emitSettingsChanged()));
|
||||
spin_tracker_port->setMinimum(1);
|
||||
spin_tracker_port->setMaximum(65535);
|
||||
spin_tracker_port->setValue(pref.getTrackerPort());
|
||||
setCellWidget(TRACKER_PORT, VALUE, spin_tracker_port);
|
||||
}
|
||||
|
||||
void emitSettingsChanged() {
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
};
|
||||
|
||||
#endif // ADVANCEDSETTINGS_H
|
||||
2417
src/preferences/options.ui
Normal file
2417
src/preferences/options.ui
Normal file
File diff suppressed because it is too large
Load Diff
1144
src/preferences/options_imp.cpp
Normal file
1144
src/preferences/options_imp.cpp
Normal file
File diff suppressed because it is too large
Load Diff
160
src/preferences/options_imp.h
Normal file
160
src/preferences/options_imp.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2006 Christophe Dumez
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#ifndef OPTIONS_IMP_H
|
||||
#define OPTIONS_IMP_H
|
||||
|
||||
#include "ui_options.h"
|
||||
#include <libtorrent/ip_filter.hpp>
|
||||
|
||||
// actions on double-click on torrents
|
||||
enum DoubleClickAction {TOGGLE_PAUSE, OPEN_DEST, NO_ACTION};
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
class QCloseEvent;
|
||||
class AdvancedSettings;
|
||||
|
||||
class options_imp : public QDialog, private Ui_Preferences {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Contructor / Destructor
|
||||
options_imp(QWidget *parent=0);
|
||||
~options_imp();
|
||||
QSize sizeFittingScreen();
|
||||
|
||||
protected slots:
|
||||
void enableUploadLimit(bool checked);
|
||||
void enableDownloadLimit(bool checked);
|
||||
void enableProxy(int comboIndex);
|
||||
void enableProxyAuth(bool checked);
|
||||
void enableMaxConnecsLimit(bool checked);
|
||||
void enableMaxConnecsLimitPerTorrent(bool checked);
|
||||
void enableMaxUploadsLimitPerTorrent(bool checked);
|
||||
void enableMaxRatio(bool checked);
|
||||
void setStyle(QString style);
|
||||
void on_buttonBox_accepted();
|
||||
void closeEvent(QCloseEvent *e);
|
||||
void on_buttonBox_rejected();
|
||||
void applySettings(QAbstractButton* button);
|
||||
void on_browseExportDirButton_clicked();
|
||||
void on_browseFilterButton_clicked();
|
||||
void on_browseSaveDirButton_clicked();
|
||||
void on_browseTempDirButton_clicked();
|
||||
void enableApplyButton();
|
||||
void enableSystrayOptions();
|
||||
void disableSystrayOptions();
|
||||
void setSystrayOptionsState(bool checked);
|
||||
void changePage(QListWidgetItem*, QListWidgetItem*);
|
||||
void loadWindowState();
|
||||
void saveWindowState() const;
|
||||
void on_randomButton_clicked();
|
||||
void on_addScanFolderButton_clicked();
|
||||
void on_removeScanFolderButton_clicked();
|
||||
void handleScanFolderViewSelectionChanged();
|
||||
|
||||
public slots:
|
||||
void setLocale(QString locale);
|
||||
void useStyle();
|
||||
void showConnectionTab();
|
||||
|
||||
signals:
|
||||
void status_changed() const;
|
||||
void exitWithCancel();
|
||||
|
||||
private:
|
||||
// Methods
|
||||
void saveOptions();
|
||||
void loadOptions();
|
||||
void initializeLanguageCombo();
|
||||
// General options
|
||||
QString getLocale() const;
|
||||
QString getStyle() const;
|
||||
bool systrayIntegration() const;
|
||||
bool minimizeToTray() const;
|
||||
bool closeToTray() const;
|
||||
bool startMinimized() const;
|
||||
bool isSlashScreenDisabled() const;
|
||||
// Downloads
|
||||
QString getSavePath() const;
|
||||
bool isTempPathEnabled() const;
|
||||
QString getTempPath() const;
|
||||
bool preAllocateAllFiles() const;
|
||||
bool useAdditionDialog() const;
|
||||
bool addTorrentsInPause() const;
|
||||
QString getExportDir() const;
|
||||
int getActionOnDblClOnTorrentDl() const;
|
||||
int getActionOnDblClOnTorrentFn() const;
|
||||
// Connection options
|
||||
int getPort() const;
|
||||
bool isUPnPEnabled() const;
|
||||
bool isNATPMPEnabled() const;
|
||||
QPair<int,int> getGlobalBandwidthLimits() const;
|
||||
// Bittorrent options
|
||||
int getMaxConnecs() const;
|
||||
int getMaxConnecsPerTorrent() const;
|
||||
int getMaxUploadsPerTorrent() const;
|
||||
bool isDHTEnabled() const;
|
||||
bool isDHTPortSameAsBT() const;
|
||||
int getDHTPort() const;
|
||||
bool isLSDEnabled() const;
|
||||
int getEncryptionSetting() const;
|
||||
float getMaxRatio() const;
|
||||
// Proxy options
|
||||
bool isProxyEnabled() const;
|
||||
bool isProxyAuthEnabled() const;
|
||||
QString getProxyIp() const;
|
||||
unsigned short getProxyPort() const;
|
||||
QString getProxyUsername() const;
|
||||
QString getProxyPassword() const;
|
||||
int getProxyType() const;
|
||||
// IP Filter
|
||||
bool isFilteringEnabled() const;
|
||||
QString getFilter() const;
|
||||
// Queueing system
|
||||
bool isQueueingSystemEnabled() const;
|
||||
int getMaxActiveDownloads() const;
|
||||
int getMaxActiveUploads() const;
|
||||
int getMaxActiveTorrents() const;
|
||||
bool isWebUiEnabled() const;
|
||||
quint16 webUiPort() const;
|
||||
QString webUiUsername() const;
|
||||
QString webUiPassword() const;
|
||||
|
||||
private:
|
||||
QButtonGroup choiceLanguage;
|
||||
QAbstractButton *applyButton;
|
||||
AdvancedSettings *advancedSettings;
|
||||
QList<QString> addedScanDirs;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
981
src/preferences/preferences.h
Normal file
981
src/preferences/preferences.h
Normal file
@@ -0,0 +1,981 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2006 Christophe Dumez
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#ifndef PREFERENCES_H
|
||||
#define PREFERENCES_H
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QPair>
|
||||
#include <QDir>
|
||||
#include <QTime>
|
||||
#include <QList>
|
||||
#include <QDebug>
|
||||
#include <libtorrent/version.hpp>
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
#include <QApplication>
|
||||
#else
|
||||
#include <QCoreApplication>
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
#include <QDesktopServices>
|
||||
#endif
|
||||
|
||||
#include "misc.h"
|
||||
#include "qinisettings.h"
|
||||
|
||||
#define QBT_REALM "Web UI Access"
|
||||
enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN };
|
||||
enum maxRatioAction {PAUSE_ACTION, REMOVE_ACTION};
|
||||
namespace Proxy {
|
||||
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5};
|
||||
}
|
||||
|
||||
class Preferences : public QIniSettings {
|
||||
Q_DISABLE_COPY(Preferences);
|
||||
|
||||
public:
|
||||
Preferences() : QIniSettings("qBittorrent", "qBittorrent") {
|
||||
qDebug() << "Preferences constructor";
|
||||
}
|
||||
|
||||
public:
|
||||
// General options
|
||||
QString getLocale() const {
|
||||
return value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString();
|
||||
}
|
||||
|
||||
void setLocale(const QString &locale) {
|
||||
setValue(QString::fromUtf8("Preferences/General/Locale"), locale);
|
||||
}
|
||||
|
||||
QString getStyle() const {
|
||||
return value(QString::fromUtf8("Preferences/General/Style"), "").toString();
|
||||
}
|
||||
|
||||
void setStyle(const QString &style) {
|
||||
setValue(QString::fromUtf8("Preferences/General/Style"), style);
|
||||
}
|
||||
|
||||
bool useProgramNotification() const {
|
||||
return value(QString::fromUtf8("Preferences/General/ProgramNotification"), true).toBool();
|
||||
}
|
||||
|
||||
void useProgramNotification(bool use) {
|
||||
setValue(QString::fromUtf8("Preferences/General/ProgramNotification"), use);
|
||||
}
|
||||
|
||||
bool deleteTorrentFilesAsDefault() const {
|
||||
return value(QString::fromUtf8("Preferences/General/DeleteTorrentsFilesAsDefault"), false).toBool();
|
||||
}
|
||||
|
||||
void setDeleteTorrentFilesAsDefault(bool del) {
|
||||
setValue(QString::fromUtf8("Preferences/General/DeleteTorrentsFilesAsDefault"), del);
|
||||
}
|
||||
|
||||
void setConfirmOnExit(bool confirm) {
|
||||
setValue(QString::fromUtf8("Preferences/General/ExitConfirm"), confirm);
|
||||
}
|
||||
|
||||
bool confirmOnExit() const {
|
||||
return value(QString::fromUtf8("Preferences/General/ExitConfirm"), true).toBool();
|
||||
}
|
||||
|
||||
void showSpeedInTitleBar(bool show) {
|
||||
setValue(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), show);
|
||||
}
|
||||
|
||||
bool speedInTitleBar() const {
|
||||
return value(QString::fromUtf8("Preferences/General/SpeedInTitleBar"), false).toBool();
|
||||
}
|
||||
|
||||
bool useAlternatingRowColors() const {
|
||||
return value(QString::fromUtf8("Preferences/General/AlternatingRowColors"), true).toBool();
|
||||
}
|
||||
|
||||
void setAlternatingRowColors(bool b) {
|
||||
setValue("Preferences/General/AlternatingRowColors", b);
|
||||
}
|
||||
|
||||
bool systrayIntegration() const {
|
||||
return value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool();
|
||||
}
|
||||
|
||||
void setSystrayIntegration(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/General/SystrayEnabled"), enabled);
|
||||
}
|
||||
|
||||
void setToolbarDisplayed(bool displayed) {
|
||||
setValue(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), displayed);
|
||||
}
|
||||
|
||||
bool isToolbarDisplayed() const {
|
||||
return value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool();
|
||||
}
|
||||
|
||||
bool minimizeToTray() const {
|
||||
return value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool();
|
||||
}
|
||||
|
||||
void setMinimizeToTray(bool b) {
|
||||
setValue("Preferences/General/MinimizeToTray", b);
|
||||
}
|
||||
|
||||
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
|
||||
QString getSavePath() const {
|
||||
#ifdef Q_WS_WIN
|
||||
return value(QString::fromUtf8("Preferences/Downloads/SavePath"),
|
||||
QDir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).absoluteFilePath("Downloads")).toString();
|
||||
#else
|
||||
return value(QString::fromUtf8("Preferences/Downloads/SavePath"), QDir::home().absoluteFilePath("qBT_dir")).toString();
|
||||
#endif
|
||||
}
|
||||
|
||||
void setSavePath(const QString &save_path) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), save_path);
|
||||
}
|
||||
|
||||
bool isTempPathEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), false).toBool();
|
||||
}
|
||||
|
||||
void setTempPathEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/TempPathEnabled"), enabled);
|
||||
}
|
||||
|
||||
QString getTempPath() const {
|
||||
const QString temp = QDir(getSavePath()).absoluteFilePath("temp");
|
||||
return value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString();
|
||||
}
|
||||
|
||||
void setTempPath(const QString &path) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), path);
|
||||
}
|
||||
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
bool useIncompleteFilesExtension() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), false).toBool();
|
||||
}
|
||||
|
||||
void useIncompleteFilesExtension(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), enabled);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool appendTorrentLabel() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/AppendLabel"), false).toBool();
|
||||
}
|
||||
|
||||
void setAppendTorrentLabel(bool b) {
|
||||
setValue("Preferences/Downloads/AppendLabel", b);
|
||||
}
|
||||
|
||||
bool preAllocateAllFiles() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool();
|
||||
}
|
||||
|
||||
void preAllocateAllFiles(bool enabled) {
|
||||
return setValue(QString::fromUtf8("Preferences/Downloads/PreAllocation"), enabled);
|
||||
}
|
||||
|
||||
bool useAdditionDialog() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), false).toBool();
|
||||
}
|
||||
|
||||
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
|
||||
void setScanDirs(const QStringList &dirs) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), dirs);
|
||||
}
|
||||
|
||||
QList<bool> getDownloadInScanDirs() const {
|
||||
return misc::boolListfromStringList(value(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs")).toStringList());
|
||||
}
|
||||
|
||||
void setDownloadInScanDirs(const QList<bool> &list) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs"), misc::toStringList(list));
|
||||
}
|
||||
|
||||
bool isTorrentExportEnabled() const {
|
||||
return !value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString().isEmpty();
|
||||
}
|
||||
|
||||
QString getExportDir() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString();
|
||||
}
|
||||
|
||||
void setExportDir(QString path) {
|
||||
path = path.trimmed();
|
||||
if(path.isEmpty())
|
||||
path = QString();
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/TorrentExport"), path);
|
||||
}
|
||||
|
||||
bool isMailNotificationEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/MailNotification/enabled"), false).toBool();
|
||||
}
|
||||
|
||||
void setMailNotificationEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/MailNotification/enabled"), enabled);
|
||||
}
|
||||
|
||||
QString getMailNotificationEmail() const {
|
||||
return value(QString::fromUtf8("Preferences/MailNotification/email"), "").toString();
|
||||
}
|
||||
|
||||
void setMailNotificationEmail(const QString &mail) {
|
||||
setValue(QString::fromUtf8("Preferences/MailNotification/email"), mail);
|
||||
}
|
||||
|
||||
QString getMailNotificationSMTP() const {
|
||||
return value(QString::fromUtf8("Preferences/MailNotification/smtp_server"), "smtp.changeme.com").toString();
|
||||
}
|
||||
|
||||
void setMailNotificationSMTP(const QString &smtp_server) {
|
||||
setValue(QString::fromUtf8("Preferences/MailNotification/smtp_server"), smtp_server);
|
||||
}
|
||||
|
||||
int getActionOnDblClOnTorrentDl() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).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
|
||||
int getSessionPort() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/PortRangeMin"), 6881).toInt();
|
||||
}
|
||||
|
||||
void setSessionPort(int port) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/PortRangeMin"), port);
|
||||
}
|
||||
|
||||
bool isUPnPEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/UPnP"), true).toBool();
|
||||
}
|
||||
|
||||
void setUPnPEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/UPnP"), enabled);
|
||||
}
|
||||
|
||||
bool isNATPMPEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/NAT-PMP"), true).toBool();
|
||||
}
|
||||
|
||||
void setNATPMPEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/NAT-PMP"), enabled);
|
||||
}
|
||||
|
||||
int getGlobalDownloadLimit() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/GlobalDLLimit"), -1).toInt();
|
||||
}
|
||||
|
||||
void setGlobalDownloadLimit(int limit) {
|
||||
if(limit <= 0) limit = -1;
|
||||
setValue("Preferences/Connection/GlobalDLLimit", limit);
|
||||
}
|
||||
|
||||
int getGlobalUploadLimit() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), 50).toInt();
|
||||
}
|
||||
|
||||
void setGlobalUploadLimit(int limit) {
|
||||
if(limit <= 0) limit = -1;
|
||||
setValue("Preferences/Connection/GlobalUPLimit", limit);
|
||||
}
|
||||
|
||||
int getAltGlobalDownloadLimit() const {
|
||||
int ret = value(QString::fromUtf8("Preferences/Connection/GlobalDLLimitAlt"), 10).toInt();
|
||||
if(ret <= 0)
|
||||
ret = 10;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void setAltGlobalDownloadLimit(int limit) {
|
||||
if(limit <= 0) limit = -1;
|
||||
setValue("Preferences/Connection/GlobalDLLimitAlt", limit);
|
||||
}
|
||||
|
||||
int getAltGlobalUploadLimit() const {
|
||||
int ret = value(QString::fromUtf8("Preferences/Connection/GlobalUPLimitAlt"), 10).toInt();
|
||||
if(ret <= 0)
|
||||
ret = 10;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void setAltGlobalUploadLimit(int limit) {
|
||||
if(limit <= 0) limit = -1;
|
||||
setValue("Preferences/Connection/GlobalUPLimitAlt", limit);
|
||||
}
|
||||
|
||||
bool isAltBandwidthEnabled() const {
|
||||
return value("Preferences/Connection/alt_speeds_on", false).toBool();
|
||||
}
|
||||
|
||||
void setAltBandwidthEnabled(bool enabled) {
|
||||
setValue("Preferences/Connection/alt_speeds_on", enabled);
|
||||
}
|
||||
|
||||
void setSchedulerEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Scheduler/Enabled"), enabled);
|
||||
}
|
||||
|
||||
bool isSchedulerEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Scheduler/Enabled"), false).toBool();
|
||||
}
|
||||
|
||||
QTime getSchedulerStartTime() const {
|
||||
return value(QString::fromUtf8("Preferences/Scheduler/start_time"), QTime(8,0)).toTime();
|
||||
}
|
||||
|
||||
void setSchedulerStartTime(const QTime &time) {
|
||||
setValue(QString::fromUtf8("Preferences/Scheduler/start_time"), time);
|
||||
}
|
||||
|
||||
QTime getSchedulerEndTime() const {
|
||||
return value(QString::fromUtf8("Preferences/Scheduler/end_time"), QTime(20,0)).toTime();
|
||||
}
|
||||
|
||||
void setSchedulerEndTime(const QTime &time) {
|
||||
setValue(QString::fromUtf8("Preferences/Scheduler/end_time"), time);
|
||||
}
|
||||
|
||||
scheduler_days getSchedulerDays() const {
|
||||
return (scheduler_days)value(QString::fromUtf8("Preferences/Scheduler/days"), EVERY_DAY).toInt();
|
||||
}
|
||||
|
||||
void setSchedulerDays(scheduler_days days) {
|
||||
setValue(QString::fromUtf8("Preferences/Scheduler/days"), (int)days);
|
||||
}
|
||||
|
||||
// Proxy options
|
||||
bool isProxyEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt() > 0;
|
||||
}
|
||||
|
||||
bool isProxyAuthEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), false).toBool();
|
||||
}
|
||||
|
||||
void setProxyAuthEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/Proxy/Authentication"), enabled);
|
||||
}
|
||||
|
||||
QString getProxyIp() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/Proxy/IP"), "0.0.0.0").toString();
|
||||
}
|
||||
|
||||
void setProxyIp(const QString &ip) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/Proxy/IP"), ip);
|
||||
}
|
||||
|
||||
unsigned short getProxyPort() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/Proxy/Port"), 8080).toInt();
|
||||
}
|
||||
|
||||
void setProxyPort(unsigned short port) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/Proxy/Port"), port);
|
||||
}
|
||||
|
||||
QString getProxyUsername() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/Proxy/Username"), QString()).toString();
|
||||
}
|
||||
|
||||
void setProxyUsername(const QString &username) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/Proxy/Username"), username);
|
||||
}
|
||||
|
||||
QString getProxyPassword() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/Proxy/Password"), QString()).toString();
|
||||
}
|
||||
|
||||
void setProxyPassword(const QString &password) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/Proxy/Password"), password);
|
||||
}
|
||||
|
||||
int getProxyType() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/ProxyType"), 0).toInt();
|
||||
}
|
||||
|
||||
void setProxyType(int type) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/ProxyType"), type);
|
||||
}
|
||||
|
||||
// Bittorrent options
|
||||
int getMaxConnecs() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt();
|
||||
}
|
||||
|
||||
void setMaxConnecs(int val) {
|
||||
if(val <= 0) val = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), val);
|
||||
}
|
||||
|
||||
int getMaxConnecsPerTorrent() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt();
|
||||
}
|
||||
|
||||
void setMaxConnecsPerTorrent(int val) {
|
||||
if(val <= 0) val = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), val);
|
||||
}
|
||||
|
||||
int getMaxUploadsPerTorrent() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt();
|
||||
}
|
||||
|
||||
void setMaxUploadsPerTorrent(int val) {
|
||||
if(val <= 0) val = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), val);
|
||||
}
|
||||
|
||||
bool isDHTEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool();
|
||||
}
|
||||
|
||||
void setDHTEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/DHT"), enabled);
|
||||
}
|
||||
|
||||
bool isPeXEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/PeX"), true).toBool();
|
||||
}
|
||||
|
||||
void setPeXEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/PeX"), enabled);
|
||||
}
|
||||
|
||||
bool isDHTPortSameAsBT() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool();
|
||||
}
|
||||
|
||||
void setDHTPortSameAsBT(bool same) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), same);
|
||||
}
|
||||
|
||||
int getDHTPort() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), 6881).toInt();
|
||||
}
|
||||
|
||||
void setDHTPort(int port) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/DHTPort"), port);
|
||||
}
|
||||
|
||||
bool isLSDEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/LSD"), true).toBool();
|
||||
}
|
||||
|
||||
void setLSDEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/LSD"), enabled);
|
||||
}
|
||||
|
||||
int getEncryptionSetting() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/Encryption"), 0).toInt();
|
||||
}
|
||||
|
||||
void setEncryptionSetting(int val) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val);
|
||||
}
|
||||
|
||||
float getMaxRatio() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble();
|
||||
}
|
||||
|
||||
void setMaxRatio(float ratio) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), ratio);
|
||||
}
|
||||
|
||||
void setMaxRatioAction(int act) {
|
||||
setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), act);
|
||||
}
|
||||
|
||||
int getMaxRatioAction() const {
|
||||
return value(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), PAUSE_ACTION).toInt();
|
||||
}
|
||||
|
||||
// IP Filter
|
||||
bool isFilteringEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/IPFilter/Enabled"), false).toBool();
|
||||
}
|
||||
|
||||
void setFilteringEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/IPFilter/Enabled"), enabled);
|
||||
}
|
||||
|
||||
QString getFilter() const {
|
||||
return value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString();
|
||||
}
|
||||
|
||||
void setFilter(const QString &path) {
|
||||
setValue(QString::fromUtf8("Preferences/IPFilter/File"), path);
|
||||
}
|
||||
|
||||
void banIP(const QString &ip) {
|
||||
QStringList banned_ips = value(QString::fromUtf8("Preferences/IPFilter/BannedIPs"), QStringList()).toStringList();
|
||||
if(!banned_ips.contains(ip)) {
|
||||
banned_ips << ip;
|
||||
setValue("Preferences/IPFilter/BannedIPs", banned_ips);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList bannedIPs() const {
|
||||
return value(QString::fromUtf8("Preferences/IPFilter/BannedIPs"), QStringList()).toStringList();
|
||||
}
|
||||
|
||||
// Search
|
||||
bool isSearchEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Search/SearchEnabled"), true).toBool();
|
||||
}
|
||||
|
||||
void setSearchEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Search/SearchEnabled"), enabled);
|
||||
}
|
||||
|
||||
// Queueing system
|
||||
bool isQueueingSystemEnabled() const {
|
||||
return value("Preferences/Queueing/QueueingEnabled", false).toBool();
|
||||
}
|
||||
|
||||
void setQueueingSystemEnabled(bool enabled) {
|
||||
setValue("Preferences/Queueing/QueueingEnabled", enabled);
|
||||
}
|
||||
|
||||
int getMaxActiveDownloads() const {
|
||||
return value(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), 3).toInt();
|
||||
}
|
||||
|
||||
void setMaxActiveDownloads(int val) {
|
||||
if(val < 0) val = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveDownloads"), val);
|
||||
}
|
||||
|
||||
int getMaxActiveUploads() const {
|
||||
return value(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), 3).toInt();
|
||||
}
|
||||
|
||||
void setMaxActiveUploads(int val) {
|
||||
if(val < 0) val = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveUploads"), val);
|
||||
}
|
||||
|
||||
int getMaxActiveTorrents() const {
|
||||
return value(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), 5).toInt();
|
||||
}
|
||||
|
||||
void setMaxActiveTorrents(int val) {
|
||||
if(val < 0) val = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Queueing/MaxActiveTorrents"), val);
|
||||
}
|
||||
|
||||
bool isWebUiEnabled() const {
|
||||
return value("Preferences/WebUI/Enabled", false).toBool();
|
||||
}
|
||||
|
||||
void setWebUiEnabled(bool enabled) {
|
||||
setValue("Preferences/WebUI/Enabled", enabled);
|
||||
}
|
||||
|
||||
quint16 getWebUiPort() const {
|
||||
return value("Preferences/WebUI/Port", 8080).toInt();
|
||||
}
|
||||
|
||||
void setWebUiPort(quint16 port) {
|
||||
setValue("Preferences/WebUI/Port", port);
|
||||
}
|
||||
|
||||
QString getWebUiUsername() const {
|
||||
return value("Preferences/WebUI/Username", "admin").toString();
|
||||
}
|
||||
|
||||
void setWebUiUsername(const QString &username) {
|
||||
setValue("Preferences/WebUI/Username", username);
|
||||
}
|
||||
|
||||
void setWebUiPassword(const QString &new_password) {
|
||||
// Get current password md5
|
||||
QString current_pass_md5 = getWebUiPassword();
|
||||
// Check if password did not change
|
||||
if(current_pass_md5 == new_password) return;
|
||||
// Encode to md5 and save
|
||||
QCryptographicHash md5(QCryptographicHash::Md5);
|
||||
md5.addData(getWebUiUsername().toLocal8Bit()+":"+QBT_REALM+":");
|
||||
md5.addData(new_password.toLocal8Bit());
|
||||
|
||||
setValue("Preferences/WebUI/Password_ha1", md5.result().toHex());
|
||||
}
|
||||
|
||||
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+":");
|
||||
md5.addData("adminadmin");
|
||||
pass_ha1 = md5.result().toHex();
|
||||
}
|
||||
return pass_ha1;
|
||||
}
|
||||
|
||||
// Advanced settings
|
||||
|
||||
void setUILockPassword(const QString &clear_password) {
|
||||
QCryptographicHash md5(QCryptographicHash::Md5);
|
||||
md5.addData(clear_password.toLocal8Bit());
|
||||
QString md5_password = md5.result().toHex();
|
||||
setValue("Locking/password", md5_password);
|
||||
}
|
||||
|
||||
QString getUILockPasswordMD5() const {
|
||||
return value("Locking/password", QString()).toString();
|
||||
}
|
||||
|
||||
bool isUILocked() const {
|
||||
return value("Locking/locked", false).toBool();
|
||||
}
|
||||
|
||||
void setUILocked(bool locked) {
|
||||
return setValue("Locking/locked", locked);
|
||||
}
|
||||
|
||||
bool isAutoRunEnabled() const {
|
||||
return value("AutoRun/enabled", false).toBool();
|
||||
}
|
||||
|
||||
void setAutoRunEnabled(bool enabled) {
|
||||
return setValue("AutoRun/enabled", enabled);
|
||||
}
|
||||
|
||||
void setAutoRunProgram(const QString &program) {
|
||||
setValue("AutoRun/program", program);
|
||||
}
|
||||
|
||||
QString getAutoRunProgram() const {
|
||||
return value("AutoRun/program", QString()).toString();
|
||||
}
|
||||
|
||||
bool shutdownWhenDownloadsComplete() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), false).toBool();
|
||||
}
|
||||
|
||||
void setShutdownWhenDownloadsComplete(bool shutdown) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), shutdown);
|
||||
}
|
||||
|
||||
bool shutdownqBTWhenDownloadsComplete() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), false).toBool();
|
||||
}
|
||||
|
||||
void setShutdownqBTWhenDownloadsComplete(bool shutdown) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), shutdown);
|
||||
}
|
||||
|
||||
uint diskCacheSize() const {
|
||||
return value(QString::fromUtf8("Preferences/Downloads/DiskCache"), 16).toUInt();
|
||||
}
|
||||
|
||||
void setDiskCacheSize(uint size) {
|
||||
setValue(QString::fromUtf8("Preferences/Downloads/DiskCache"), size);
|
||||
}
|
||||
|
||||
uint outgoingPortsMin() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), 0).toUInt();
|
||||
}
|
||||
|
||||
void setOutgoingPortsMin(uint val) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), val);
|
||||
}
|
||||
|
||||
uint outgoingPortsMax() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMax"), 0).toUInt();
|
||||
}
|
||||
|
||||
void setOutgoingPortsMax(uint val) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMax"), val);
|
||||
}
|
||||
|
||||
bool ignoreLimitsOnLAN() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/IgnoreLimitsLAN"), true).toBool();
|
||||
}
|
||||
|
||||
void ignoreLimitsOnLAN(bool ignore) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/IgnoreLimitsLAN"), ignore);
|
||||
}
|
||||
|
||||
bool includeOverheadInLimits() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/IncludeOverhead"), false).toBool();
|
||||
}
|
||||
|
||||
void includeOverheadInLimits(bool include) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/IncludeOverhead"), include);
|
||||
}
|
||||
|
||||
bool recheckTorrentsOnCompletion() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/RecheckOnCompletion"), false).toBool();
|
||||
}
|
||||
|
||||
void recheckTorrentsOnCompletion(bool recheck) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/RecheckOnCompletion"), recheck);
|
||||
}
|
||||
|
||||
unsigned int getRefreshInterval() const {
|
||||
return value(QString::fromUtf8("Preferences/General/RefreshInterval"), 1500).toUInt();
|
||||
}
|
||||
|
||||
void setRefreshInterval(uint interval) {
|
||||
setValue(QString::fromUtf8("Preferences/General/RefreshInterval"), interval);
|
||||
}
|
||||
|
||||
bool resolvePeerCountries() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), true).toBool();
|
||||
}
|
||||
|
||||
void resolvePeerCountries(bool resolve) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), resolve);
|
||||
}
|
||||
|
||||
bool resolvePeerHostNames() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), false).toBool();
|
||||
}
|
||||
|
||||
void resolvePeerHostNames(bool resolve) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), resolve);
|
||||
}
|
||||
|
||||
int getMaxHalfOpenConnections() const {
|
||||
const int val = value(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), 50).toInt();
|
||||
if(val <= 0) return -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
void setMaxHalfOpenConnections(int value) {
|
||||
if(value <= 0) value = -1;
|
||||
setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value);
|
||||
}
|
||||
|
||||
void setNetworkInterface(const QString& iface) {
|
||||
setValue(QString::fromUtf8("Preferences/Connection/Interface"), iface);
|
||||
}
|
||||
|
||||
QString getNetworkInterface() const {
|
||||
return value(QString::fromUtf8("Preferences/Connection/Interface"), QString()).toString();
|
||||
}
|
||||
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
bool isSuperSeedingEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), false).toBool();
|
||||
}
|
||||
|
||||
void enableSuperSeeding(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), enabled);
|
||||
}
|
||||
#endif
|
||||
|
||||
QStringList getTorrentLabels() const {
|
||||
return value("TransferListFilters/customLabels").toStringList();
|
||||
}
|
||||
|
||||
void addTorrentLabel(const QString& label) {
|
||||
QStringList labels = value("TransferListFilters/customLabels").toStringList();
|
||||
if(!labels.contains(label))
|
||||
labels << label;
|
||||
setValue("TransferListFilters/customLabels", labels);
|
||||
}
|
||||
|
||||
void removeTorrentLabel(const QString& label) {
|
||||
QStringList labels = value("TransferListFilters/customLabels").toStringList();
|
||||
if(labels.contains(label))
|
||||
labels.removeOne(label);
|
||||
setValue("TransferListFilters/customLabels", labels);
|
||||
}
|
||||
|
||||
bool recursiveDownloadDisabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/DisableRecursiveDownload"), false).toBool();
|
||||
}
|
||||
|
||||
void disableRecursiveDownload(bool disable=true) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/DisableRecursiveDownload"), disable);
|
||||
}
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
static QString getPythonPath() {
|
||||
QSettings reg_python("HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore", QIniSettings::NativeFormat);
|
||||
QStringList versions = reg_python.childGroups();
|
||||
qDebug("Python versions nb: %d", versions.size());
|
||||
versions = versions.filter(QRegExp("2\\..*"));
|
||||
versions.sort();
|
||||
while(!versions.empty()) {
|
||||
const QString version = versions.takeLast();
|
||||
qDebug("Detected possible Python v%s location", qPrintable(version));
|
||||
QString path = reg_python.value(version+"/InstallPath/Default", "").toString().replace("/", "\\");
|
||||
if(!path.isEmpty() && QDir(path).exists("python.exe")) {
|
||||
qDebug("Found python.exe at %s", qPrintable(path));
|
||||
return path;
|
||||
}
|
||||
}
|
||||
if(QFile::exists("C:/Python26/python.exe")) {
|
||||
reg_python.setValue("2.6/InstallPath/Default", "C:\\Python26");
|
||||
return "C:\\Python26";
|
||||
}
|
||||
if(QFile::exists("C:/Python25/python.exe")) {
|
||||
reg_python.setValue("2.5/InstallPath/Default", "C:\\Python26");
|
||||
return "C:\\Python25";
|
||||
}
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
bool neverCheckFileAssoc() const {
|
||||
return value(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), false).toBool();
|
||||
}
|
||||
|
||||
void setNeverCheckFileAssoc(bool check=true) {
|
||||
setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check);
|
||||
}
|
||||
|
||||
static bool isFileAssocOk() {
|
||||
QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat);
|
||||
if(value(".torrent/Default").toString() != "qBittorrent") {
|
||||
qDebug(".torrent != qBittorrent");
|
||||
return false;
|
||||
}
|
||||
qDebug("Checking shell command");
|
||||
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)
|
||||
return false;
|
||||
QString assoc_exe = exe_reg.cap(1);
|
||||
qDebug("exe: %s", qPrintable(assoc_exe));
|
||||
if(assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
|
||||
return false;
|
||||
// Icon
|
||||
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
|
||||
if(value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0)
|
||||
return false;
|
||||
// Check magnet link assoc
|
||||
shell_command = value("Magnet/shell/open/command/Default", "").toString();
|
||||
if(exe_reg.indexIn(shell_command) < 0)
|
||||
return false;
|
||||
assoc_exe = exe_reg.cap(1);
|
||||
qDebug("exe: %s", qPrintable(assoc_exe));
|
||||
if(assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void setFileAssoc() {
|
||||
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
|
||||
// .Torrent association
|
||||
setValue(".torrent/Default", "qBittorrent");
|
||||
setValue(".torrent/Content Type", "application/x-bittorrent");
|
||||
setValue("qBittorrent/shell/Default", "open");
|
||||
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
|
||||
setValue("qBittorrent/shell/open/command/Default", command_str);
|
||||
setValue("qBittorrent/Content Type/Default", "application/x-bittorrent");
|
||||
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
|
||||
setValue("qBittorrent/DefaultIcon/Default", icon_str);
|
||||
// Magnet association
|
||||
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
|
||||
|
||||
bool isTrackerEnabled() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/trackerEnabled"), false).toBool();
|
||||
}
|
||||
|
||||
void setTrackerEnabled(bool enabled) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/trackerEnabled"), enabled);
|
||||
}
|
||||
|
||||
int getTrackerPort() const {
|
||||
return value(QString::fromUtf8("Preferences/Advanced/trackerPort"), 9000).toInt();
|
||||
}
|
||||
|
||||
void setTrackerPort(int port) {
|
||||
setValue(QString::fromUtf8("Preferences/Advanced/trackerPort"), port);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // PREFERENCES_H
|
||||
13
src/preferences/preferences.pri
Normal file
13
src/preferences/preferences.pri
Normal file
@@ -0,0 +1,13 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
!contains(DEFINES, DISABLE_GUI) {
|
||||
|
||||
HEADERS += $$PWD/options_imp.h \
|
||||
$$PWD/advancedsettings.h
|
||||
|
||||
SOURCES += $$PWD/options_imp.cpp
|
||||
|
||||
FORMS += $$PWD/options.ui
|
||||
}
|
||||
|
||||
HEADERS += $$PWD/preferences.h
|
||||
Reference in New Issue
Block a user