mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 05:08:05 -06:00
Merge pull request #5342 from glassez/session
Optimize BitTorrent::Session settings applying
This commit is contained in:
@@ -5,6 +5,7 @@ HEADERS += \
|
||||
$$PWD/qinisettings.h \
|
||||
$$PWD/logger.h \
|
||||
$$PWD/settingsstorage.h \
|
||||
$$PWD/settingvalue.h \
|
||||
$$PWD/preferences.h \
|
||||
$$PWD/indexrange.h \
|
||||
$$PWD/iconprovider.h \
|
||||
@@ -20,6 +21,7 @@ HEADERS += \
|
||||
$$PWD/net/downloadhandler.h \
|
||||
$$PWD/net/geoipmanager.h \
|
||||
$$PWD/net/portforwarder.h \
|
||||
$$PWD/net/proxyconfigurationmanager.h \
|
||||
$$PWD/net/reverseresolution.h \
|
||||
$$PWD/net/smtp.h \
|
||||
$$PWD/net/private/geoipdatabase.h \
|
||||
@@ -74,6 +76,7 @@ SOURCES += \
|
||||
$$PWD/net/downloadhandler.cpp \
|
||||
$$PWD/net/geoipmanager.cpp \
|
||||
$$PWD/net/portforwarder.cpp \
|
||||
$$PWD/net/proxyconfigurationmanager.cpp \
|
||||
$$PWD/net/reverseresolution.cpp \
|
||||
$$PWD/net/smtp.cpp \
|
||||
$$PWD/net/private/geoipdatabase.cpp \
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
#include <QTime>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/preferences.h"
|
||||
#include "bandwidthscheduler.h"
|
||||
|
||||
BandwidthScheduler::BandwidthScheduler(QObject *parent)
|
||||
: QTimer(parent)
|
||||
{
|
||||
Q_ASSERT(Preferences::instance()->isSchedulerEnabled());
|
||||
// Single shot, we call start() again manually
|
||||
setSingleShot(true);
|
||||
// Connect Signals/Slots
|
||||
@@ -47,8 +47,7 @@ BandwidthScheduler::BandwidthScheduler(QObject *parent)
|
||||
void BandwidthScheduler::start()
|
||||
{
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
Q_ASSERT(pref->isSchedulerEnabled());
|
||||
bool alt_bw_enabled = pref->isAltBandwidthEnabled();
|
||||
bool alt_bw_enabled = BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled();
|
||||
|
||||
QTime start = pref->getSchedulerStartTime();
|
||||
QTime end = pref->getSchedulerEndTime();
|
||||
|
||||
@@ -383,22 +383,6 @@ void FilterParserThread::processFilterFile(QString _filePath)
|
||||
start();
|
||||
}
|
||||
|
||||
void FilterParserThread::processFilterList(libt::session *s, const QStringList &IPs)
|
||||
{
|
||||
// First, import current filter
|
||||
libt::ip_filter filter = s->get_ip_filter();
|
||||
foreach (const QString &ip, IPs) {
|
||||
qDebug("Manual ban of peer %s", ip.toLocal8Bit().constData());
|
||||
boost::system::error_code ec;
|
||||
libt::address addr = libt::address::from_string(ip.toLocal8Bit().constData(), ec);
|
||||
Q_ASSERT(!ec);
|
||||
if (!ec)
|
||||
filter.add_rule(addr, addr, libt::ip_filter::blocked);
|
||||
}
|
||||
|
||||
s->set_ip_filter(filter);
|
||||
}
|
||||
|
||||
QString FilterParserThread::cleanupIPAddress(QString _ip)
|
||||
{
|
||||
_ip = _ip.trimmed();
|
||||
|
||||
@@ -55,7 +55,6 @@ public:
|
||||
int getlineInStream(QDataStream &stream, std::string &name, char delim);
|
||||
int parseP2BFilterFile(QString filePath, libtorrent::ip_filter &filter);
|
||||
void processFilterFile(QString _filePath);
|
||||
static void processFilterList(libtorrent::session *s, const QStringList &IPs);
|
||||
|
||||
signals:
|
||||
void IPFilterParsed(int ruleCount);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,17 +30,22 @@
|
||||
#ifndef BITTORRENT_SESSION_H
|
||||
#define BITTORRENT_SESSION_H
|
||||
|
||||
#include <vector>
|
||||
#include <libtorrent/version.hpp>
|
||||
|
||||
#include <QFile>
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QPointer>
|
||||
#include <QVector>
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#endif
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include <QPointer>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <QWaitCondition>
|
||||
|
||||
#include <libtorrent/version.hpp>
|
||||
|
||||
#include "base/settingvalue.h"
|
||||
#include "base/tristatebool.h"
|
||||
#include "base/types.h"
|
||||
#include "torrentinfo.h"
|
||||
@@ -52,19 +57,12 @@ namespace libtorrent
|
||||
class entry;
|
||||
struct add_torrent_params;
|
||||
struct pe_settings;
|
||||
struct session_settings;
|
||||
struct session_status;
|
||||
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
struct proxy_settings;
|
||||
struct session_settings;
|
||||
#else
|
||||
namespace aux
|
||||
{
|
||||
struct proxy_settings;
|
||||
}
|
||||
|
||||
typedef aux::proxy_settings proxy_settings;
|
||||
struct settings_pack;
|
||||
#endif
|
||||
struct session_status;
|
||||
|
||||
class alert;
|
||||
struct torrent_alert;
|
||||
@@ -111,7 +109,6 @@ class FilterParserThread;
|
||||
class BandwidthScheduler;
|
||||
class Statistics;
|
||||
class ResumeDataSavingManager;
|
||||
class SettingsStorage;
|
||||
|
||||
enum MaxRatioAction
|
||||
{
|
||||
@@ -172,13 +169,6 @@ namespace BitTorrent
|
||||
static void freeInstance();
|
||||
static Session *instance();
|
||||
|
||||
bool isDHTEnabled() const;
|
||||
bool isLSDEnabled() const;
|
||||
bool isPexEnabled() const;
|
||||
bool isQueueingEnabled() const;
|
||||
qreal globalMaxRatio() const;
|
||||
bool isAppendExtensionEnabled() const;
|
||||
|
||||
QString defaultSavePath() const;
|
||||
void setDefaultSavePath(QString path);
|
||||
QString tempPath() const;
|
||||
@@ -219,8 +209,122 @@ namespace BitTorrent
|
||||
bool isDisableAutoTMMWhenCategorySavePathChanged() const;
|
||||
void setDisableAutoTMMWhenCategorySavePathChanged(bool value);
|
||||
|
||||
qreal globalMaxRatio() const;
|
||||
void setGlobalMaxRatio(qreal ratio);
|
||||
bool isDHTEnabled() const;
|
||||
void setDHTEnabled(bool enabled);
|
||||
bool isLSDEnabled() const;
|
||||
void setLSDEnabled(bool enabled);
|
||||
bool isPeXEnabled() const;
|
||||
void setPeXEnabled(bool enabled);
|
||||
bool isTrackerExchangeEnabled() const;
|
||||
void setTrackerExchangeEnabled(bool enabled);
|
||||
bool isAddTorrentPaused() const;
|
||||
void setAddTorrentPaused(bool value);
|
||||
bool isTrackerEnabled() const;
|
||||
void setTrackerEnabled(bool enabled);
|
||||
bool isAppendExtensionEnabled() const;
|
||||
void setAppendExtensionEnabled(bool enabled);
|
||||
uint refreshInterval() const;
|
||||
void setRefreshInterval(uint value);
|
||||
bool isPreallocationEnabled() const;
|
||||
void setPreallocationEnabled(bool enabled);
|
||||
QString torrentExportDirectory() const;
|
||||
void setTorrentExportDirectory(const QString &path);
|
||||
QString finishedTorrentExportDirectory() const;
|
||||
void setFinishedTorrentExportDirectory(const QString &path);
|
||||
|
||||
int globalDownloadSpeedLimit() const;
|
||||
void setGlobalDownloadSpeedLimit(int limit);
|
||||
int globalUploadSpeedLimit() const;
|
||||
void setGlobalUploadSpeedLimit(int limit);
|
||||
int altGlobalDownloadSpeedLimit() const;
|
||||
void setAltGlobalDownloadSpeedLimit(int limit);
|
||||
int altGlobalUploadSpeedLimit() const;
|
||||
void setAltGlobalUploadSpeedLimit(int limit);
|
||||
int downloadSpeedLimit() const;
|
||||
void setDownloadSpeedLimit(int limit);
|
||||
int uploadSpeedLimit() const;
|
||||
void setUploadSpeedLimit(int limit);
|
||||
bool isAltGlobalSpeedLimitEnabled() const;
|
||||
void setAltGlobalSpeedLimitEnabled(bool enabled);
|
||||
bool isBandwidthSchedulerEnabled() const;
|
||||
void setBandwidthSchedulerEnabled(bool enabled);
|
||||
|
||||
uint saveResumeDataInterval() const;
|
||||
void setSaveResumeDataInterval(uint value);
|
||||
int port() const;
|
||||
void setPort(int port);
|
||||
bool useRandomPort() const;
|
||||
void setUseRandomPort(bool value);
|
||||
QString networkInterface() const;
|
||||
void setNetworkInterface(const QString &interface);
|
||||
QString networkInterfaceAddress() const;
|
||||
void setNetworkInterfaceAddress(const QString &address);
|
||||
bool isIPv6Enabled() const;
|
||||
void setIPv6Enabled(bool enabled);
|
||||
int encryption() const;
|
||||
void setEncryption(int state);
|
||||
bool isForceProxyEnabled() const;
|
||||
void setForceProxyEnabled(bool enabled);
|
||||
bool isProxyPeerConnectionsEnabled() const;
|
||||
void setProxyPeerConnectionsEnabled(bool enabled);
|
||||
bool isAddTrackersEnabled() const;
|
||||
void setAddTrackersEnabled(bool enabled);
|
||||
QString additionalTrackers() const;
|
||||
void setAdditionalTrackers(const QString &trackers);
|
||||
bool isFilteringEnabled() const;
|
||||
void setFilteringEnabled(bool enabled);
|
||||
QString IPFilterFile() const;
|
||||
void setIPFilterFile(QString path);
|
||||
bool announceToAllTrackers() const;
|
||||
void setAnnounceToAllTrackers(bool val);
|
||||
uint diskCacheSize() const;
|
||||
void setDiskCacheSize(uint size);
|
||||
uint diskCacheTTL() const;
|
||||
void setDiskCacheTTL(uint ttl);
|
||||
bool useOSCache() const;
|
||||
void setUseOSCache(bool use);
|
||||
bool isAnonymousModeEnabled() const;
|
||||
void setAnonymousModeEnabled(bool enabled);
|
||||
bool isQueueingSystemEnabled() const;
|
||||
void setQueueingSystemEnabled(bool enabled);
|
||||
bool ignoreSlowTorrentsForQueueing() const;
|
||||
void setIgnoreSlowTorrentsForQueueing(bool ignore);
|
||||
uint outgoingPortsMin() const;
|
||||
void setOutgoingPortsMin(uint min);
|
||||
uint outgoingPortsMax() const;
|
||||
void setOutgoingPortsMax(uint max);
|
||||
bool ignoreLimitsOnLAN() const;
|
||||
void setIgnoreLimitsOnLAN(bool ignore);
|
||||
bool includeOverheadInLimits() const;
|
||||
void setIncludeOverheadInLimits(bool include);
|
||||
QString networkAddress() const;
|
||||
void setNetworkAddress(const QString &addr);
|
||||
bool isSuperSeedingEnabled() const;
|
||||
void setSuperSeedingEnabled(bool enabled);
|
||||
int maxConnections() const;
|
||||
void setMaxConnections(int max);
|
||||
int maxHalfOpenConnections() const;
|
||||
void setMaxHalfOpenConnections(int max);
|
||||
int maxConnectionsPerTorrent() const;
|
||||
void setMaxConnectionsPerTorrent(int max);
|
||||
int maxUploads() const;
|
||||
void setMaxUploads(int max);
|
||||
int maxUploadsPerTorrent() const;
|
||||
void setMaxUploadsPerTorrent(int max);
|
||||
int maxActiveDownloads() const;
|
||||
void setMaxActiveDownloads(int max);
|
||||
int maxActiveUploads() const;
|
||||
void setMaxActiveUploads(int max);
|
||||
int maxActiveTorrents() const;
|
||||
void setMaxActiveTorrents(int max);
|
||||
bool isUTPEnabled() const;
|
||||
void setUTPEnabled(bool enabled);
|
||||
bool isUTPRateLimited() const;
|
||||
void setUTPRateLimited(bool limited);
|
||||
bool isTrackerFilteringEnabled() const;
|
||||
void setTrackerFilteringEnabled(bool enabled);
|
||||
|
||||
TorrentHandle *findTorrent(const InfoHash &hash) const;
|
||||
QHash<InfoHash, TorrentHandle *> torrents() const;
|
||||
@@ -231,19 +335,11 @@ namespace BitTorrent
|
||||
CacheStatus cacheStatus() const;
|
||||
quint64 getAlltimeDL() const;
|
||||
quint64 getAlltimeUL() const;
|
||||
int downloadRateLimit() const;
|
||||
int uploadRateLimit() const;
|
||||
bool isListening() const;
|
||||
|
||||
MaxRatioAction maxRatioAction() const;
|
||||
void setMaxRatioAction(MaxRatioAction act);
|
||||
|
||||
void changeSpeedLimitMode(bool alternative);
|
||||
void setDownloadRateLimit(int rate);
|
||||
void setUploadRateLimit(int rate);
|
||||
void setGlobalMaxRatio(qreal ratio);
|
||||
void enableIPFilter(const QString &filterPath, bool force = false);
|
||||
void disableIPFilter();
|
||||
void banIP(const QString &ip);
|
||||
|
||||
bool isKnownTorrent(const InfoHash &hash) const;
|
||||
@@ -304,7 +400,7 @@ namespace BitTorrent
|
||||
void trackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent);
|
||||
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
|
||||
void speedLimitModeChanged(bool alternative);
|
||||
void ipFilterParsed(bool error, int ruleCount);
|
||||
void IPFilterParsed(bool error, int ruleCount);
|
||||
void trackersAdded(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
||||
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
||||
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
|
||||
@@ -316,7 +412,7 @@ namespace BitTorrent
|
||||
void subcategoriesSupportChanged();
|
||||
|
||||
private slots:
|
||||
void configure();
|
||||
void configureDeferred();
|
||||
void readAlerts();
|
||||
void refresh();
|
||||
void processBigRatios();
|
||||
@@ -341,20 +437,24 @@ namespace BitTorrent
|
||||
void initResumeFolder();
|
||||
|
||||
// Session configuration
|
||||
void setSessionSettings();
|
||||
void setProxySettings(libtorrent::proxy_settings proxySettings);
|
||||
void adjustLimits();
|
||||
Q_INVOKABLE void configure();
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
void configure(libtorrent::session_settings &sessionSettings);
|
||||
void adjustLimits(libtorrent::session_settings &sessionSettings);
|
||||
#else
|
||||
void configure(libtorrent::settings_pack &settingsPack);
|
||||
void adjustLimits(libtorrent::settings_pack &settingsPack);
|
||||
#endif
|
||||
void adjustLimits();
|
||||
void processBannedIPs();
|
||||
const QStringList getListeningIPs();
|
||||
void setListeningPort();
|
||||
void preAllocateAllFiles(bool b);
|
||||
void setMaxConnectionsPerTorrent(int max);
|
||||
void setMaxUploadsPerTorrent(int max);
|
||||
void enableLSD(bool enable);
|
||||
void enableDHT(bool enable);
|
||||
void configureListeningInterface();
|
||||
void changeSpeedLimitMode_impl(bool alternative);
|
||||
|
||||
void setAppendExtension(bool append);
|
||||
void enableTracker(bool enable);
|
||||
void enableBandwidthScheduler();
|
||||
void populateAdditionalTrackers();
|
||||
void enableIPFilter();
|
||||
void disableIPFilter();
|
||||
|
||||
void startUpTorrents();
|
||||
bool addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri,
|
||||
@@ -393,31 +493,88 @@ namespace BitTorrent
|
||||
#endif
|
||||
void getPendingAlerts(std::vector<libtorrent::alert *> &out, ulong time = 0);
|
||||
|
||||
SettingsStorage *m_settings;
|
||||
|
||||
// BitTorrent
|
||||
libtorrent::session *m_nativeSession;
|
||||
|
||||
bool m_LSDEnabled;
|
||||
bool m_DHTEnabled;
|
||||
bool m_PeXEnabled;
|
||||
bool m_queueingEnabled;
|
||||
bool m_torrentExportEnabled;
|
||||
bool m_finishedTorrentExportEnabled;
|
||||
bool m_preAllocateAll;
|
||||
qreal m_globalMaxRatio;
|
||||
bool m_deferredConfigureScheduled;
|
||||
bool m_IPFilteringChanged;
|
||||
#if LIBTORRENT_VERSION_NUM >= 10100
|
||||
bool m_listenInterfaceChanged; // optimization
|
||||
#endif
|
||||
CachedSettingValue<bool> m_isDHTEnabled;
|
||||
CachedSettingValue<bool> m_isLSDEnabled;
|
||||
CachedSettingValue<bool> m_isPeXEnabled;
|
||||
CachedSettingValue<bool> m_isTrackerExchangeEnabled;
|
||||
CachedSettingValue<bool> m_isFilteringEnabled;
|
||||
CachedSettingValue<bool> m_isTrackerFilteringEnabled;
|
||||
CachedSettingValue<QString> m_IPFilterFile;
|
||||
CachedSettingValue<bool> m_announceToAllTrackers;
|
||||
CachedSettingValue<uint> m_diskCacheSize;
|
||||
CachedSettingValue<uint> m_diskCacheTTL;
|
||||
CachedSettingValue<bool> m_useOSCache;
|
||||
CachedSettingValue<bool> m_isAnonymousModeEnabled;
|
||||
CachedSettingValue<bool> m_isQueueingEnabled;
|
||||
CachedSettingValue<int> m_maxActiveDownloads;
|
||||
CachedSettingValue<int> m_maxActiveUploads;
|
||||
CachedSettingValue<int> m_maxActiveTorrents;
|
||||
CachedSettingValue<bool> m_ignoreSlowTorrentsForQueueing;
|
||||
CachedSettingValue<uint> m_outgoingPortsMin;
|
||||
CachedSettingValue<uint> m_outgoingPortsMax;
|
||||
CachedSettingValue<bool> m_ignoreLimitsOnLAN;
|
||||
CachedSettingValue<bool> m_includeOverheadInLimits;
|
||||
CachedSettingValue<QString> m_networkAddress;
|
||||
CachedSettingValue<bool> m_isSuperSeedingEnabled;
|
||||
CachedSettingValue<int> m_maxConnections;
|
||||
CachedSettingValue<int> m_maxHalfOpenConnections;
|
||||
CachedSettingValue<int> m_maxUploads;
|
||||
CachedSettingValue<int> m_maxConnectionsPerTorrent;
|
||||
CachedSettingValue<int> m_maxUploadsPerTorrent;
|
||||
CachedSettingValue<bool> m_isUTPEnabled;
|
||||
CachedSettingValue<bool> m_isUTPRateLimited;
|
||||
CachedSettingValue<bool> m_isAddTrackersEnabled;
|
||||
CachedSettingValue<QString> m_additionalTrackers;
|
||||
CachedSettingValue<qreal> m_globalMaxRatio;
|
||||
CachedSettingValue<bool> m_isAddTorrentPaused;
|
||||
CachedSettingValue<bool> m_isAppendExtensionEnabled;
|
||||
CachedSettingValue<uint> m_refreshInterval;
|
||||
CachedSettingValue<bool> m_isPreallocationEnabled;
|
||||
CachedSettingValue<QString> m_torrentExportDirectory;
|
||||
CachedSettingValue<QString> m_finishedTorrentExportDirectory;
|
||||
CachedSettingValue<int> m_globalDownloadSpeedLimit;
|
||||
CachedSettingValue<int> m_globalUploadSpeedLimit;
|
||||
CachedSettingValue<int> m_altGlobalDownloadSpeedLimit;
|
||||
CachedSettingValue<int> m_altGlobalUploadSpeedLimit;
|
||||
CachedSettingValue<bool> m_isAltGlobalSpeedLimitEnabled;
|
||||
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
|
||||
CachedSettingValue<uint> m_saveResumeDataInterval;
|
||||
CachedSettingValue<int> m_port;
|
||||
CachedSettingValue<bool> m_useRandomPort;
|
||||
CachedSettingValue<QString> m_networkInterface;
|
||||
CachedSettingValue<QString> m_networkInterfaceAddress;
|
||||
CachedSettingValue<bool> m_isIPv6Enabled;
|
||||
CachedSettingValue<int> m_encryption;
|
||||
CachedSettingValue<bool> m_isForceProxyEnabled;
|
||||
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
|
||||
CachedSettingValue<QVariantMap> m_storedCategories;
|
||||
CachedSettingValue<int> m_maxRatioAction;
|
||||
CachedSettingValue<QString> m_defaultSavePath;
|
||||
CachedSettingValue<QString> m_tempPath;
|
||||
CachedSettingValue<bool> m_isSubcategoriesEnabled;
|
||||
CachedSettingValue<bool> m_isTempPathEnabled;
|
||||
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
|
||||
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
|
||||
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;
|
||||
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategorySavePathChanged;
|
||||
CachedSettingValue<bool> m_isTrackerEnabled;
|
||||
CachedSettingValue<QStringList> m_bannedIPs;
|
||||
|
||||
int m_numResumeData;
|
||||
int m_extraLimit;
|
||||
bool m_appendExtension;
|
||||
uint m_refreshInterval;
|
||||
MaxRatioAction m_maxRatioAction;
|
||||
QList<BitTorrent::TrackerEntry> m_additionalTrackers;
|
||||
QString m_defaultSavePath;
|
||||
QString m_tempPath;
|
||||
QString m_filterPath;
|
||||
QList<BitTorrent::TrackerEntry> m_additionalTrackerList;
|
||||
QString m_resumeFolderPath;
|
||||
QFile m_resumeFolderLock;
|
||||
QHash<InfoHash, QString> m_savePathsToRemove;
|
||||
bool m_useProxy;
|
||||
|
||||
QTimer *m_refreshTimer;
|
||||
QTimer *m_bigRatioTimer;
|
||||
|
||||
@@ -752,7 +752,7 @@ void TorrentHandle::updateState()
|
||||
m_state = isSeed() ? TorrentState::PausedUploading : TorrentState::PausedDownloading;
|
||||
}
|
||||
else {
|
||||
if (m_session->isQueueingEnabled() && isQueued() && !isChecking()) {
|
||||
if (m_session->isQueueingSystemEnabled() && isQueued() && !isChecking()) {
|
||||
m_state = isSeed() ? TorrentState::QueuedUploading : TorrentState::QueuedDownloading;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -27,20 +27,21 @@
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include "downloadmanager.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkCookieJar>
|
||||
#include <QNetworkReply>
|
||||
#include <QDebug>
|
||||
#include <QNetworkCookie>
|
||||
#include <QNetworkCookieJar>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSslError>
|
||||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
|
||||
#include "base/preferences.h"
|
||||
#include "downloadhandler.h"
|
||||
#include "downloadmanager.h"
|
||||
#include "proxyconfigurationmanager.h"
|
||||
|
||||
// Spoof Firefox 38 user agent to avoid web server banning
|
||||
const char DEFAULT_USER_AGENT[] = "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0";
|
||||
@@ -208,16 +209,16 @@ bool DownloadManager::deleteCookie(const QNetworkCookie &cookie)
|
||||
|
||||
void DownloadManager::applyProxySettings()
|
||||
{
|
||||
auto proxyManager = ProxyConfigurationManager::instance();
|
||||
ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
|
||||
QNetworkProxy proxy;
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
|
||||
if (pref->isProxyEnabled() && !pref->isProxyOnlyForTorrents()) {
|
||||
if (!proxyManager->isProxyDisabled() && (proxyConfig.type != ProxyType::None)) {
|
||||
// Proxy enabled
|
||||
proxy.setHostName(pref->getProxyIp());
|
||||
proxy.setPort(pref->getProxyPort());
|
||||
proxy.setHostName(proxyConfig.ip);
|
||||
proxy.setPort(proxyConfig.port);
|
||||
// Default proxy type is HTTP, we must change if it is SOCKS5
|
||||
const int proxyType = pref->getProxyType();
|
||||
if ((proxyType == Proxy::SOCKS5) || (proxyType == Proxy::SOCKS5_PW)) {
|
||||
if ((proxyConfig.type == ProxyType::SOCKS5) || (proxyConfig.type == ProxyType::SOCKS5_PW)) {
|
||||
qDebug() << Q_FUNC_INFO << "using SOCKS proxy";
|
||||
proxy.setType(QNetworkProxy::Socks5Proxy);
|
||||
}
|
||||
@@ -226,10 +227,10 @@ void DownloadManager::applyProxySettings()
|
||||
proxy.setType(QNetworkProxy::HttpProxy);
|
||||
}
|
||||
// Authentication?
|
||||
if (pref->isProxyAuthEnabled()) {
|
||||
if (proxyManager->isAuthenticationRequired()) {
|
||||
qDebug("Proxy requires authentication, authenticating");
|
||||
proxy.setUser(pref->getProxyUsername());
|
||||
proxy.setPassword(pref->getProxyPassword());
|
||||
proxy.setUser(proxyConfig.username);
|
||||
proxy.setPassword(proxyConfig.password);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -26,13 +26,17 @@
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include "portforwarder.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <libtorrent/session.hpp>
|
||||
#include <libtorrent/version.hpp>
|
||||
|
||||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "portforwarder.h"
|
||||
#include "base/settingsstorage.h"
|
||||
|
||||
const QString KEY_ENABLED = QLatin1String("Network/PortForwardingEnabled");
|
||||
|
||||
namespace libt = libtorrent;
|
||||
using namespace Net;
|
||||
@@ -42,8 +46,8 @@ PortForwarder::PortForwarder(libtorrent::session *provider, QObject *parent)
|
||||
, m_active(false)
|
||||
, m_provider(provider)
|
||||
{
|
||||
configure();
|
||||
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
|
||||
if (SettingsStorage::instance()->loadValue(KEY_ENABLED, true).toBool())
|
||||
start();
|
||||
}
|
||||
|
||||
PortForwarder::~PortForwarder()
|
||||
@@ -70,6 +74,21 @@ PortForwarder *PortForwarder::instance()
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
bool PortForwarder::isEnabled() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
void PortForwarder::setEnabled(bool enabled)
|
||||
{
|
||||
if (m_active != enabled) {
|
||||
if (enabled)
|
||||
start();
|
||||
else
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
void PortForwarder::addPort(quint16 port)
|
||||
{
|
||||
if (!m_mappedPorts.contains(port)) {
|
||||
@@ -88,22 +107,18 @@ void PortForwarder::deletePort(quint16 port)
|
||||
}
|
||||
}
|
||||
|
||||
void PortForwarder::configure()
|
||||
{
|
||||
bool enable = Preferences::instance()->isUPnPEnabled();
|
||||
if (m_active != enable) {
|
||||
if (enable)
|
||||
start();
|
||||
else
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
void PortForwarder::start()
|
||||
{
|
||||
qDebug("Enabling UPnP / NAT-PMP");
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
m_provider->start_upnp();
|
||||
m_provider->start_natpmp();
|
||||
#else
|
||||
libt::settings_pack settingsPack = m_provider->get_settings();
|
||||
settingsPack.set_bool(libt::settings_pack::enable_upnp, true);
|
||||
settingsPack.set_bool(libt::settings_pack::enable_natpmp, true);
|
||||
m_provider->apply_settings(settingsPack);
|
||||
#endif
|
||||
foreach (quint16 port, m_mappedPorts.keys())
|
||||
m_mappedPorts[port] = m_provider->add_port_mapping(libt::session::tcp, port, port);
|
||||
m_active = true;
|
||||
@@ -113,8 +128,15 @@ void PortForwarder::start()
|
||||
void PortForwarder::stop()
|
||||
{
|
||||
qDebug("Disabling UPnP / NAT-PMP");
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
m_provider->stop_upnp();
|
||||
m_provider->stop_natpmp();
|
||||
#else
|
||||
libt::settings_pack settingsPack = m_provider->get_settings();
|
||||
settingsPack.set_bool(libt::settings_pack::enable_upnp, false);
|
||||
settingsPack.set_bool(libt::settings_pack::enable_natpmp, false);
|
||||
m_provider->apply_settings(settingsPack);
|
||||
#endif
|
||||
m_active = false;
|
||||
Logger::instance()->addMessage(tr("UPnP / NAT-PMP support [OFF]"), Log::INFO);
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ namespace Net
|
||||
static void freeInstance();
|
||||
static PortForwarder *instance();
|
||||
|
||||
bool isEnabled() const;
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
void addPort(quint16 port);
|
||||
void deletePort(quint16 port);
|
||||
|
||||
private slots:
|
||||
void configure();
|
||||
|
||||
private:
|
||||
explicit PortForwarder(libtorrent::session *const provider, QObject *parent = 0);
|
||||
~PortForwarder();
|
||||
|
||||
160
src/base/net/proxyconfigurationmanager.cpp
Normal file
160
src/base/net/proxyconfigurationmanager.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "proxyconfigurationmanager.h"
|
||||
#include "base/settingsstorage.h"
|
||||
|
||||
#define SETTINGS_KEY(name) "Network/Proxy/" name
|
||||
const QString KEY_DISABLED = SETTINGS_KEY("Disabled");
|
||||
const QString KEY_TYPE = SETTINGS_KEY("Type");
|
||||
const QString KEY_IP = SETTINGS_KEY("IP");
|
||||
const QString KEY_PORT = SETTINGS_KEY("Port");
|
||||
const QString KEY_AUTHENTICATION = SETTINGS_KEY("Authentication");
|
||||
const QString KEY_USERNAME = SETTINGS_KEY("Username");
|
||||
const QString KEY_PASSWORD = SETTINGS_KEY("Password");
|
||||
|
||||
namespace
|
||||
{
|
||||
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
|
||||
|
||||
inline bool isSameConfig(const Net::ProxyConfiguration &conf1, const Net::ProxyConfiguration &conf2)
|
||||
{
|
||||
return conf1.type == conf2.type
|
||||
&& conf1.ip == conf2.ip
|
||||
&& conf1.port == conf2.port
|
||||
&& conf1.username == conf2.username
|
||||
&& conf1.password == conf2.password;
|
||||
}
|
||||
}
|
||||
|
||||
using namespace Net;
|
||||
|
||||
ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
|
||||
|
||||
ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_proxyDisabled = settings()->loadValue(KEY_DISABLED, false).toBool();
|
||||
m_config.type = static_cast<ProxyType>(
|
||||
settings()->loadValue(KEY_TYPE, static_cast<int>(ProxyType::None)).toInt());
|
||||
if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
|
||||
m_config.type = ProxyType::None;
|
||||
m_config.ip = settings()->loadValue(KEY_IP, "0.0.0.0").toString();
|
||||
m_config.port = static_cast<ushort>(settings()->loadValue(KEY_PORT, 8080).toUInt());
|
||||
m_config.username = settings()->loadValue(KEY_USERNAME).toString();
|
||||
m_config.password = settings()->loadValue(KEY_PASSWORD).toString();
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::initInstance()
|
||||
{
|
||||
if (!m_instance)
|
||||
m_instance = new ProxyConfigurationManager;
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::freeInstance()
|
||||
{
|
||||
delete m_instance;
|
||||
}
|
||||
|
||||
ProxyConfigurationManager *ProxyConfigurationManager::instance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
|
||||
{
|
||||
if (!isSameConfig(config, m_config)) {
|
||||
m_config = config;
|
||||
settings()->storeValue(KEY_TYPE, static_cast<int>(config.type));
|
||||
settings()->storeValue(KEY_IP, config.ip);
|
||||
settings()->storeValue(KEY_PORT, config.port);
|
||||
settings()->storeValue(KEY_USERNAME, config.username);
|
||||
settings()->storeValue(KEY_PASSWORD, config.password);
|
||||
configureProxy();
|
||||
|
||||
emit proxyConfigurationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool ProxyConfigurationManager::isProxyDisabled() const
|
||||
{
|
||||
return m_proxyDisabled;
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::setProxyDisabled(bool disabled)
|
||||
{
|
||||
if (m_proxyDisabled != disabled) {
|
||||
settings()->storeValue(KEY_DISABLED, disabled);
|
||||
m_proxyDisabled = disabled;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProxyConfigurationManager::isAuthenticationRequired() const
|
||||
{
|
||||
return m_config.type == ProxyType::SOCKS5_PW
|
||||
|| m_config.type == ProxyType::HTTP_PW;
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::configureProxy()
|
||||
{
|
||||
// Define environment variables for urllib in search engine plugins
|
||||
QString proxyStrHTTP, proxyStrSOCK;
|
||||
if (!m_proxyDisabled) {
|
||||
switch (m_config.type) {
|
||||
case ProxyType::HTTP_PW:
|
||||
proxyStrHTTP = QString("http://%1:%2@%3:%4").arg(m_config.username)
|
||||
.arg(m_config.password).arg(m_config.ip).arg(m_config.port);
|
||||
break;
|
||||
case ProxyType::HTTP:
|
||||
proxyStrHTTP = QString("http://%1:%2").arg(m_config.ip).arg(m_config.port);
|
||||
break;
|
||||
case ProxyType::SOCKS5:
|
||||
proxyStrSOCK = QString("%1:%2").arg(m_config.ip).arg(m_config.port);
|
||||
break;
|
||||
case ProxyType::SOCKS5_PW:
|
||||
proxyStrSOCK = QString("%1:%2@%3:%4").arg(m_config.username)
|
||||
.arg(m_config.password).arg(m_config.ip).arg(m_config.port);
|
||||
break;
|
||||
default:
|
||||
qDebug("Disabling HTTP communications proxy");
|
||||
}
|
||||
|
||||
qDebug("HTTP communications proxy string: %s"
|
||||
, qPrintable((m_config.type == ProxyType::SOCKS5) || (m_config.type == ProxyType::SOCKS5_PW)
|
||||
? proxyStrSOCK : proxyStrHTTP));
|
||||
}
|
||||
|
||||
qputenv("http_proxy", proxyStrHTTP.toLocal8Bit());
|
||||
qputenv("https_proxy", proxyStrHTTP.toLocal8Bit());
|
||||
qputenv("sock_proxy", proxyStrSOCK.toLocal8Bit());
|
||||
}
|
||||
87
src/base/net/proxyconfigurationmanager.h
Normal file
87
src/base/net/proxyconfigurationmanager.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef NET_PROXYCONFIGURATIONMANAGER_H
|
||||
#define NET_PROXYCONFIGURATIONMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Net
|
||||
{
|
||||
enum class ProxyType
|
||||
{
|
||||
None = 0,
|
||||
HTTP = 1,
|
||||
SOCKS5 = 2,
|
||||
HTTP_PW = 3,
|
||||
SOCKS5_PW = 4,
|
||||
SOCKS4 = 5
|
||||
};
|
||||
|
||||
struct ProxyConfiguration
|
||||
{
|
||||
ProxyType type = ProxyType::None;
|
||||
QString ip = "0.0.0.0";
|
||||
ushort port = 8080;
|
||||
QString username;
|
||||
QString password;
|
||||
};
|
||||
|
||||
class ProxyConfigurationManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ProxyConfigurationManager)
|
||||
|
||||
explicit ProxyConfigurationManager(QObject *parent = nullptr);
|
||||
~ProxyConfigurationManager() = default;
|
||||
|
||||
public:
|
||||
static void initInstance();
|
||||
static void freeInstance();
|
||||
static ProxyConfigurationManager *instance();
|
||||
|
||||
ProxyConfiguration proxyConfiguration() const;
|
||||
void setProxyConfiguration(const ProxyConfiguration &config);
|
||||
bool isProxyDisabled() const;
|
||||
void setProxyDisabled(bool disabled);
|
||||
|
||||
bool isAuthenticationRequired() const;
|
||||
|
||||
signals:
|
||||
void proxyConfigurationChanged();
|
||||
|
||||
private:
|
||||
void configureProxy();
|
||||
|
||||
static ProxyConfigurationManager *m_instance;
|
||||
ProxyConfiguration m_config;
|
||||
bool m_proxyDisabled;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NET_PROXYCONFIGURATIONMANAGER_H
|
||||
@@ -50,8 +50,6 @@
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "utils/fs.h"
|
||||
#include "utils/misc.h"
|
||||
#include "settingsstorage.h"
|
||||
@@ -60,10 +58,7 @@
|
||||
|
||||
Preferences* Preferences::m_instance = 0;
|
||||
|
||||
Preferences::Preferences()
|
||||
: m_randomPort(rand() % 64512 + 1024)
|
||||
{
|
||||
}
|
||||
Preferences::Preferences() {}
|
||||
|
||||
Preferences *Preferences::instance()
|
||||
{
|
||||
@@ -165,16 +160,6 @@ void Preferences::setHideZeroComboValues(int n)
|
||||
setValue("Preferences/General/HideZeroComboValues", n);
|
||||
}
|
||||
|
||||
bool Preferences::useRandomPort() const
|
||||
{
|
||||
return value("Preferences/General/UseRandomPort", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setRandomPort(bool b)
|
||||
{
|
||||
setValue("Preferences/General/UseRandomPort", b);
|
||||
}
|
||||
|
||||
bool Preferences::systrayIntegration() const
|
||||
{
|
||||
return value("Preferences/General/SystrayEnabled", true).toBool();
|
||||
@@ -267,16 +252,6 @@ void Preferences::setWinStartup(bool b)
|
||||
#endif
|
||||
|
||||
// Downloads
|
||||
bool Preferences::useIncompleteFilesExtension() const
|
||||
{
|
||||
return value("Preferences/Downloads/UseIncompleteExtension", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::useIncompleteFilesExtension(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Downloads/UseIncompleteExtension", enabled);
|
||||
}
|
||||
|
||||
QString Preferences::lastLocationPath() const
|
||||
{
|
||||
return Utils::Fs::fromNativePath(value("Preferences/Downloads/LastLocationPath").toString());
|
||||
@@ -287,16 +262,6 @@ void Preferences::setLastLocationPath(const QString &path)
|
||||
setValue("Preferences/Downloads/LastLocationPath", Utils::Fs::fromNativePath(path));
|
||||
}
|
||||
|
||||
bool Preferences::preAllocateAllFiles() const
|
||||
{
|
||||
return value("Preferences/Downloads/PreAllocation", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::preAllocateAllFiles(bool enabled)
|
||||
{
|
||||
return setValue("Preferences/Downloads/PreAllocation", enabled);
|
||||
}
|
||||
|
||||
QVariantHash Preferences::getScanDirs() const
|
||||
{
|
||||
return value("Preferences/Downloads/ScanDirsV2").toHash();
|
||||
@@ -318,36 +283,6 @@ void Preferences::setScanDirsLastPath(const QString &path)
|
||||
setValue("Preferences/Downloads/ScanDirsLastPath", Utils::Fs::fromNativePath(path));
|
||||
}
|
||||
|
||||
bool Preferences::isTorrentExportEnabled() const
|
||||
{
|
||||
return !value("Preferences/Downloads/TorrentExportDir").toString().isEmpty();
|
||||
}
|
||||
|
||||
QString Preferences::getTorrentExportDir() const
|
||||
{
|
||||
return Utils::Fs::fromNativePath(value("Preferences/Downloads/TorrentExportDir").toString());
|
||||
}
|
||||
|
||||
void Preferences::setTorrentExportDir(QString path)
|
||||
{
|
||||
setValue("Preferences/Downloads/TorrentExportDir", Utils::Fs::fromNativePath(path.trimmed()));
|
||||
}
|
||||
|
||||
bool Preferences::isFinishedTorrentExportEnabled() const
|
||||
{
|
||||
return !value("Preferences/Downloads/FinishedTorrentExportDir").toString().isEmpty();
|
||||
}
|
||||
|
||||
QString Preferences::getFinishedTorrentExportDir() const
|
||||
{
|
||||
return Utils::Fs::fromNativePath(value("Preferences/Downloads/FinishedTorrentExportDir").toString());
|
||||
}
|
||||
|
||||
void Preferences::setFinishedTorrentExportDir(QString path)
|
||||
{
|
||||
setValue("Preferences/Downloads/FinishedTorrentExportDir", Utils::Fs::fromNativePath(path.trimmed()));
|
||||
}
|
||||
|
||||
bool Preferences::isMailNotificationEnabled() const
|
||||
{
|
||||
return value("Preferences/MailNotification/enabled", false).toBool();
|
||||
@@ -438,97 +373,6 @@ void Preferences::setActionOnDblClOnTorrentFn(int act)
|
||||
setValue("Preferences/Downloads/DblClOnTorFn", act);
|
||||
}
|
||||
|
||||
// Connection options
|
||||
int Preferences::getSessionPort() const
|
||||
{
|
||||
if (useRandomPort())
|
||||
return m_randomPort;
|
||||
return value("Preferences/Connection/PortRangeMin", 8999).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setSessionPort(int port)
|
||||
{
|
||||
setValue("Preferences/Connection/PortRangeMin", port);
|
||||
}
|
||||
|
||||
bool Preferences::isUPnPEnabled() const
|
||||
{
|
||||
return value("Preferences/Connection/UPnP", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setUPnPEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Connection/UPnP", enabled);
|
||||
}
|
||||
|
||||
int Preferences::getGlobalDownloadLimit() const
|
||||
{
|
||||
return value("Preferences/Connection/GlobalDLLimit", -1).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setGlobalDownloadLimit(int limit)
|
||||
{
|
||||
if (limit <= 0)
|
||||
limit = -1;
|
||||
setValue("Preferences/Connection/GlobalDLLimit", limit);
|
||||
}
|
||||
|
||||
int Preferences::getGlobalUploadLimit() const
|
||||
{
|
||||
return value("Preferences/Connection/GlobalUPLimit", -1).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setGlobalUploadLimit(int limit)
|
||||
{
|
||||
if (limit <= 0)
|
||||
limit = -1;
|
||||
setValue("Preferences/Connection/GlobalUPLimit", limit);
|
||||
}
|
||||
|
||||
int Preferences::getAltGlobalDownloadLimit() const
|
||||
{
|
||||
return value("Preferences/Connection/GlobalDLLimitAlt", 10).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setAltGlobalDownloadLimit(int limit)
|
||||
{
|
||||
if (limit <= 0)
|
||||
limit = -1;
|
||||
setValue("Preferences/Connection/GlobalDLLimitAlt", limit);
|
||||
}
|
||||
|
||||
int Preferences::getAltGlobalUploadLimit() const
|
||||
{
|
||||
return value("Preferences/Connection/GlobalUPLimitAlt", 10).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setAltGlobalUploadLimit(int limit)
|
||||
{
|
||||
if (limit <= 0)
|
||||
limit = -1;
|
||||
setValue("Preferences/Connection/GlobalUPLimitAlt", limit);
|
||||
}
|
||||
|
||||
bool Preferences::isAltBandwidthEnabled() const
|
||||
{
|
||||
return value("Preferences/Connection/alt_speeds_on", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setAltBandwidthEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Connection/alt_speeds_on", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isSchedulerEnabled() const
|
||||
{
|
||||
return value("Preferences/Scheduler/Enabled", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setSchedulerEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Scheduler/Enabled", enabled);
|
||||
}
|
||||
|
||||
QTime Preferences::getSchedulerStartTime() const
|
||||
{
|
||||
return value("Preferences/Scheduler/start_time", QTime(8,0)).toTime();
|
||||
@@ -559,286 +403,6 @@ void Preferences::setSchedulerDays(scheduler_days days)
|
||||
setValue("Preferences/Scheduler/days", (int)days);
|
||||
}
|
||||
|
||||
// Proxy options
|
||||
bool Preferences::isProxyEnabled() const
|
||||
{
|
||||
return getProxyType() > 0;
|
||||
}
|
||||
|
||||
bool Preferences::isProxyAuthEnabled() const
|
||||
{
|
||||
return value("Preferences/Connection/Proxy/Authentication", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setProxyAuthEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Connection/Proxy/Authentication", enabled);
|
||||
}
|
||||
|
||||
QString Preferences::getProxyIp() const
|
||||
{
|
||||
return value("Preferences/Connection/Proxy/IP", "0.0.0.0").toString();
|
||||
}
|
||||
|
||||
void Preferences::setProxyIp(const QString &ip)
|
||||
{
|
||||
setValue("Preferences/Connection/Proxy/IP", ip);
|
||||
}
|
||||
|
||||
unsigned short Preferences::getProxyPort() const
|
||||
{
|
||||
return value("Preferences/Connection/Proxy/Port", 8080).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setProxyPort(unsigned short port)
|
||||
{
|
||||
setValue("Preferences/Connection/Proxy/Port", port);
|
||||
}
|
||||
|
||||
QString Preferences::getProxyUsername() const
|
||||
{
|
||||
return value("Preferences/Connection/Proxy/Username").toString();
|
||||
}
|
||||
|
||||
void Preferences::setProxyUsername(const QString &username)
|
||||
{
|
||||
setValue("Preferences/Connection/Proxy/Username", username);
|
||||
}
|
||||
|
||||
QString Preferences::getProxyPassword() const
|
||||
{
|
||||
return value("Preferences/Connection/Proxy/Password").toString();
|
||||
}
|
||||
|
||||
void Preferences::setProxyPassword(const QString &password)
|
||||
{
|
||||
setValue("Preferences/Connection/Proxy/Password", password);
|
||||
}
|
||||
|
||||
int Preferences::getProxyType() const
|
||||
{
|
||||
return value("Preferences/Connection/ProxyType", 0).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setProxyType(int type)
|
||||
{
|
||||
setValue("Preferences/Connection/ProxyType", type);
|
||||
}
|
||||
|
||||
bool Preferences::proxyPeerConnections() const
|
||||
{
|
||||
return value("Preferences/Connection/ProxyPeerConnections", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setProxyPeerConnections(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Connection/ProxyPeerConnections", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::getForceProxy() const
|
||||
{
|
||||
return value("Preferences/Connection/ProxyForce", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setForceProxy(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Connection/ProxyForce", enabled);
|
||||
}
|
||||
|
||||
void Preferences::setProxyOnlyForTorrents(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Connection/ProxyOnlyForTorrents", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isProxyOnlyForTorrents() const
|
||||
{
|
||||
return value("Preferences/Connection/ProxyOnlyForTorrents", false).toBool();
|
||||
}
|
||||
|
||||
// Bittorrent options
|
||||
int Preferences::getMaxConnecs() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/MaxConnecs", 500).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxConnecs(int val)
|
||||
{
|
||||
if (val <= 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Bittorrent/MaxConnecs", val);
|
||||
}
|
||||
|
||||
int Preferences::getMaxConnecsPerTorrent() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/MaxConnecsPerTorrent", 100).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxConnecsPerTorrent(int val)
|
||||
{
|
||||
if (val <= 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Bittorrent/MaxConnecsPerTorrent", val);
|
||||
}
|
||||
|
||||
int Preferences::getMaxUploads() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/MaxUploads", -1).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxUploads(int val)
|
||||
{
|
||||
if (val <= 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Bittorrent/MaxUploads", val);
|
||||
}
|
||||
|
||||
int Preferences::getMaxUploadsPerTorrent() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/MaxUploadsPerTorrent", -1).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxUploadsPerTorrent(int val)
|
||||
{
|
||||
if (val <= 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Bittorrent/MaxUploadsPerTorrent", val);
|
||||
}
|
||||
|
||||
bool Preferences::isuTPEnabled() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/uTP", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setuTPEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/uTP", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isuTPRateLimited() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/uTP_rate_limited", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setuTPRateLimited(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/uTP_rate_limited", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isDHTEnabled() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/DHT", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setDHTEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/DHT", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isPeXEnabled() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/PeX", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setPeXEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/PeX", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isLSDEnabled() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/LSD", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setLSDEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/LSD", enabled);
|
||||
}
|
||||
|
||||
int Preferences::getEncryptionSetting() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/Encryption", 0).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setEncryptionSetting(int val)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/Encryption", val);
|
||||
}
|
||||
|
||||
bool Preferences::isAddTrackersEnabled() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/AddTrackers", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setAddTrackersEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/AddTrackers", enabled);
|
||||
}
|
||||
|
||||
QString Preferences::getTrackersList() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/TrackersList").toString();
|
||||
}
|
||||
|
||||
void Preferences::setTrackersList(const QString &val)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/TrackersList", val);
|
||||
}
|
||||
|
||||
qreal Preferences::getGlobalMaxRatio() const
|
||||
{
|
||||
return value("Preferences/Bittorrent/MaxRatio", -1).toReal();
|
||||
}
|
||||
|
||||
void Preferences::setGlobalMaxRatio(qreal ratio)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/MaxRatio", ratio);
|
||||
}
|
||||
|
||||
// IP Filter
|
||||
bool Preferences::isFilteringEnabled() const
|
||||
{
|
||||
return value("Preferences/IPFilter/Enabled", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setFilteringEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/IPFilter/Enabled", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isFilteringTrackerEnabled() const
|
||||
{
|
||||
return value("Preferences/IPFilter/FilterTracker", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setFilteringTrackerEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/IPFilter/FilterTracker", enabled);
|
||||
}
|
||||
|
||||
QString Preferences::getFilter() const
|
||||
{
|
||||
return Utils::Fs::fromNativePath(value("Preferences/IPFilter/File").toString());
|
||||
}
|
||||
|
||||
void Preferences::setFilter(const QString &path)
|
||||
{
|
||||
setValue("Preferences/IPFilter/File", Utils::Fs::fromNativePath(path));
|
||||
}
|
||||
|
||||
QStringList Preferences::bannedIPs() const
|
||||
{
|
||||
return value("Preferences/IPFilter/BannedIPs").toStringList();
|
||||
}
|
||||
|
||||
void Preferences::banIP(const QString &ip)
|
||||
{
|
||||
QStringList banned_ips = value("Preferences/IPFilter/BannedIPs").toStringList();
|
||||
if (!banned_ips.contains(ip)) {
|
||||
banned_ips << ip;
|
||||
setValue("Preferences/IPFilter/BannedIPs", banned_ips);
|
||||
}
|
||||
}
|
||||
|
||||
// Search
|
||||
bool Preferences::isSearchEnabled() const
|
||||
{
|
||||
@@ -850,63 +414,6 @@ void Preferences::setSearchEnabled(bool enabled)
|
||||
setValue("Preferences/Search/SearchEnabled", enabled);
|
||||
}
|
||||
|
||||
// Queueing system
|
||||
bool Preferences::isQueueingSystemEnabled() const
|
||||
{
|
||||
return value("Preferences/Queueing/QueueingEnabled", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setQueueingSystemEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Queueing/QueueingEnabled", enabled);
|
||||
}
|
||||
|
||||
int Preferences::getMaxActiveDownloads() const
|
||||
{
|
||||
return value("Preferences/Queueing/MaxActiveDownloads", 3).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxActiveDownloads(int val)
|
||||
{
|
||||
if (val < 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Queueing/MaxActiveDownloads", val);
|
||||
}
|
||||
|
||||
int Preferences::getMaxActiveUploads() const
|
||||
{
|
||||
return value("Preferences/Queueing/MaxActiveUploads", 3).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxActiveUploads(int val)
|
||||
{
|
||||
if (val < 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Queueing/MaxActiveUploads", val);
|
||||
}
|
||||
|
||||
int Preferences::getMaxActiveTorrents() const
|
||||
{
|
||||
return value("Preferences/Queueing/MaxActiveTorrents", 5).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setMaxActiveTorrents(int val)
|
||||
{
|
||||
if (val < 0)
|
||||
val = -1;
|
||||
setValue("Preferences/Queueing/MaxActiveTorrents", val);
|
||||
}
|
||||
|
||||
bool Preferences::ignoreSlowTorrentsForQueueing() const
|
||||
{
|
||||
return value("Preferences/Queueing/IgnoreSlowTorrents", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setIgnoreSlowTorrentsForQueueing(bool ignore)
|
||||
{
|
||||
setValue("Preferences/Queueing/IgnoreSlowTorrents", ignore);
|
||||
}
|
||||
|
||||
bool Preferences::isWebUiEnabled() const
|
||||
{
|
||||
#ifdef DISABLE_GUI
|
||||
@@ -1164,111 +671,6 @@ void Preferences::setDontConfirmAutoExit(bool dontConfirmAutoExit)
|
||||
setValue("ShutdownConfirmDlg/DontConfirmAutoExit", dontConfirmAutoExit);
|
||||
}
|
||||
|
||||
uint Preferences::diskCacheSize() const
|
||||
{
|
||||
uint size = value("Preferences/Downloads/DiskWriteCacheSize", 0).toUInt();
|
||||
// These macros may not be available on compilers other than MSVC and GCC
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
size = qMin(size, (uint) 4096); // 4GiB
|
||||
#else
|
||||
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes
|
||||
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM
|
||||
size = qMin(size, (uint) 1536);
|
||||
#endif
|
||||
return size;
|
||||
}
|
||||
|
||||
void Preferences::setDiskCacheSize(uint size)
|
||||
{
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
size = qMin(size, (uint) 4096); // 4GiB
|
||||
#else
|
||||
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM
|
||||
size = qMin(size, (uint) 1536);
|
||||
#endif
|
||||
setValue("Preferences/Downloads/DiskWriteCacheSize", size);
|
||||
}
|
||||
|
||||
uint Preferences::diskCacheTTL() const
|
||||
{
|
||||
return value("Preferences/Downloads/DiskWriteCacheTTL", 60).toUInt();
|
||||
}
|
||||
|
||||
void Preferences::setDiskCacheTTL(uint ttl)
|
||||
{
|
||||
setValue("Preferences/Downloads/DiskWriteCacheTTL", ttl);
|
||||
}
|
||||
|
||||
bool Preferences::osCache() const
|
||||
{
|
||||
return value("Preferences/Advanced/osCache", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setOsCache(bool enable)
|
||||
{
|
||||
setValue("Preferences/Advanced/osCache", enable);
|
||||
}
|
||||
|
||||
uint Preferences::saveResumeDataInterval() const
|
||||
{
|
||||
return value("Preferences/Downloads/SaveResumeDataInterval", 3).toUInt();
|
||||
}
|
||||
|
||||
void Preferences::setSaveResumeDataInterval(uint m)
|
||||
{
|
||||
setValue("Preferences/Downloads/SaveResumeDataInterval", m);
|
||||
}
|
||||
|
||||
uint Preferences::outgoingPortsMin() const
|
||||
{
|
||||
return value("Preferences/Advanced/OutgoingPortsMin", 0).toUInt();
|
||||
}
|
||||
|
||||
void Preferences::setOutgoingPortsMin(uint val)
|
||||
{
|
||||
setValue("Preferences/Advanced/OutgoingPortsMin", val);
|
||||
}
|
||||
|
||||
uint Preferences::outgoingPortsMax() const
|
||||
{
|
||||
return value("Preferences/Advanced/OutgoingPortsMax", 0).toUInt();
|
||||
}
|
||||
|
||||
void Preferences::setOutgoingPortsMax(uint val)
|
||||
{
|
||||
setValue("Preferences/Advanced/OutgoingPortsMax", val);
|
||||
}
|
||||
|
||||
bool Preferences::getIgnoreLimitsOnLAN() const
|
||||
{
|
||||
return value("Preferences/Advanced/IgnoreLimitsLAN", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setIgnoreLimitsOnLAN(bool ignore)
|
||||
{
|
||||
setValue("Preferences/Advanced/IgnoreLimitsLAN", ignore);
|
||||
}
|
||||
|
||||
bool Preferences::includeOverheadInLimits() const
|
||||
{
|
||||
return value("Preferences/Advanced/IncludeOverhead", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::includeOverheadInLimits(bool include)
|
||||
{
|
||||
setValue("Preferences/Advanced/IncludeOverhead", include);
|
||||
}
|
||||
|
||||
bool Preferences::trackerExchangeEnabled() const
|
||||
{
|
||||
return value("Preferences/Advanced/LtTrackerExchange", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setTrackerExchangeEnabled(bool enable)
|
||||
{
|
||||
setValue("Preferences/Advanced/LtTrackerExchange", enable);
|
||||
}
|
||||
|
||||
bool Preferences::recheckTorrentsOnCompletion() const
|
||||
{
|
||||
return value("Preferences/Advanced/RecheckOnCompletion", false).toBool();
|
||||
@@ -1279,16 +681,6 @@ void Preferences::recheckTorrentsOnCompletion(bool recheck)
|
||||
setValue("Preferences/Advanced/RecheckOnCompletion", recheck);
|
||||
}
|
||||
|
||||
unsigned int Preferences::getRefreshInterval() const
|
||||
{
|
||||
return value("Preferences/General/RefreshInterval", 1500).toUInt();
|
||||
}
|
||||
|
||||
void Preferences::setRefreshInterval(uint interval)
|
||||
{
|
||||
setValue("Preferences/General/RefreshInterval", interval);
|
||||
}
|
||||
|
||||
bool Preferences::resolvePeerCountries() const
|
||||
{
|
||||
return value("Preferences/Connection/ResolvePeerCountries", true).toBool();
|
||||
@@ -1309,31 +701,6 @@ void Preferences::resolvePeerHostNames(bool resolve)
|
||||
setValue("Preferences/Connection/ResolvePeerHostNames", resolve);
|
||||
}
|
||||
|
||||
int Preferences::getMaxHalfOpenConnections() const
|
||||
{
|
||||
const int val = value("Preferences/Connection/MaxHalfOpenConnec", 20).toInt();
|
||||
if (val <= 0)
|
||||
return -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Preferences::setMaxHalfOpenConnections(int value)
|
||||
{
|
||||
if (value <= 0)
|
||||
value = -1;
|
||||
setValue("Preferences/Connection/MaxHalfOpenConnec", value);
|
||||
}
|
||||
|
||||
QString Preferences::getNetworkInterface() const
|
||||
{
|
||||
return value("Preferences/Connection/Interface").toString();
|
||||
}
|
||||
|
||||
void Preferences::setNetworkInterface(const QString& iface)
|
||||
{
|
||||
setValue("Preferences/Connection/Interface", iface);
|
||||
}
|
||||
|
||||
QString Preferences::getNetworkInterfaceName() const
|
||||
{
|
||||
return value("Preferences/Connection/InterfaceName").toString();
|
||||
@@ -1354,56 +721,6 @@ QString Preferences::getNetworkInterfaceAddress() const
|
||||
return value("Preferences/Connection/InterfaceAddress").toString();
|
||||
}
|
||||
|
||||
bool Preferences::getListenIPv6() const
|
||||
{
|
||||
return value("Preferences/Connection/InterfaceListenIPv6", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setListenIPv6(bool enable)
|
||||
{
|
||||
setValue("Preferences/Connection/InterfaceListenIPv6", enable);
|
||||
}
|
||||
|
||||
QString Preferences::getNetworkAddress() const
|
||||
{
|
||||
return value("Preferences/Connection/InetAddress").toString();
|
||||
}
|
||||
|
||||
void Preferences::setNetworkAddress(const QString& addr)
|
||||
{
|
||||
setValue("Preferences/Connection/InetAddress", addr);
|
||||
}
|
||||
|
||||
bool Preferences::isAnonymousModeEnabled() const
|
||||
{
|
||||
return value("Preferences/Advanced/AnonymousMode", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::enableAnonymousMode(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Advanced/AnonymousMode", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::isSuperSeedingEnabled() const
|
||||
{
|
||||
return value("Preferences/Advanced/SuperSeeding", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::enableSuperSeeding(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Advanced/SuperSeeding", enabled);
|
||||
}
|
||||
|
||||
bool Preferences::announceToAllTrackers() const
|
||||
{
|
||||
return value("Preferences/Advanced/AnnounceToAllTrackers", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setAnnounceToAllTrackers(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Advanced/AnnounceToAllTrackers", enabled);
|
||||
}
|
||||
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||||
bool Preferences::useSystemIconTheme() const
|
||||
{
|
||||
@@ -1710,16 +1027,6 @@ void Preferences::setMagnetLinkAssoc()
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Preferences::isTrackerEnabled() const
|
||||
{
|
||||
return value("Preferences/Advanced/trackerEnabled", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setTrackerEnabled(bool enabled)
|
||||
{
|
||||
setValue("Preferences/Advanced/trackerEnabled", enabled);
|
||||
}
|
||||
|
||||
int Preferences::getTrackerPort() const
|
||||
{
|
||||
return value("Preferences/Advanced/trackerPort", 9000).toInt();
|
||||
|
||||
@@ -57,18 +57,6 @@ enum scheduler_days
|
||||
SUN
|
||||
};
|
||||
|
||||
namespace Proxy
|
||||
{
|
||||
enum ProxyType
|
||||
{
|
||||
HTTP = 1,
|
||||
SOCKS5 = 2,
|
||||
HTTP_PW = 3,
|
||||
SOCKS5_PW = 4,
|
||||
SOCKS4 = 5
|
||||
};
|
||||
}
|
||||
|
||||
namespace TrayIcon
|
||||
{
|
||||
enum Style
|
||||
@@ -102,7 +90,6 @@ class Preferences: public QObject
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
|
||||
static Preferences* m_instance;
|
||||
int m_randomPort;
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
@@ -127,8 +114,6 @@ public:
|
||||
void setHideZeroValues(bool b);
|
||||
int getHideZeroComboValues() const;
|
||||
void setHideZeroComboValues(int n);
|
||||
bool useRandomPort() const;
|
||||
void setRandomPort(bool b);
|
||||
bool systrayIntegration() const;
|
||||
void setSystrayIntegration(bool enabled);
|
||||
bool isToolbarDisplayed() const;
|
||||
@@ -149,22 +134,12 @@ public:
|
||||
#endif
|
||||
|
||||
// Downloads
|
||||
bool useIncompleteFilesExtension() const;
|
||||
void useIncompleteFilesExtension(bool enabled);
|
||||
QString lastLocationPath() const;
|
||||
void setLastLocationPath(const QString &path);
|
||||
bool preAllocateAllFiles() const;
|
||||
void preAllocateAllFiles(bool enabled);
|
||||
QVariantHash getScanDirs() const;
|
||||
void setScanDirs(const QVariantHash &dirs);
|
||||
QString getScanDirsLastPath() const;
|
||||
void setScanDirsLastPath(const QString &path);
|
||||
bool isTorrentExportEnabled() const;
|
||||
QString getTorrentExportDir() const;
|
||||
void setTorrentExportDir(QString path);
|
||||
bool isFinishedTorrentExportEnabled() const;
|
||||
QString getFinishedTorrentExportDir() const;
|
||||
void setFinishedTorrentExportDir(QString path);
|
||||
bool isMailNotificationEnabled() const;
|
||||
void setMailNotificationEnabled(bool enabled);
|
||||
QString getMailNotificationEmail() const;
|
||||
@@ -185,22 +160,6 @@ public:
|
||||
void setActionOnDblClOnTorrentFn(int act);
|
||||
|
||||
// Connection options
|
||||
int getSessionPort() const;
|
||||
void setSessionPort(int port);
|
||||
bool isUPnPEnabled() const;
|
||||
void setUPnPEnabled(bool enabled);
|
||||
int getGlobalDownloadLimit() const;
|
||||
void setGlobalDownloadLimit(int limit);
|
||||
int getGlobalUploadLimit() const;
|
||||
void setGlobalUploadLimit(int limit);
|
||||
int getAltGlobalDownloadLimit() const;
|
||||
void setAltGlobalDownloadLimit(int limit);
|
||||
int getAltGlobalUploadLimit() const;
|
||||
void setAltGlobalUploadLimit(int limit);
|
||||
bool isAltBandwidthEnabled() const;
|
||||
void setAltBandwidthEnabled(bool enabled);
|
||||
bool isSchedulerEnabled() const;
|
||||
void setSchedulerEnabled(bool enabled);
|
||||
QTime getSchedulerStartTime() const;
|
||||
void setSchedulerStartTime(const QTime &time);
|
||||
QTime getSchedulerEndTime() const;
|
||||
@@ -208,80 +167,10 @@ public:
|
||||
scheduler_days getSchedulerDays() const;
|
||||
void setSchedulerDays(scheduler_days days);
|
||||
|
||||
// Proxy options
|
||||
bool isProxyEnabled() const;
|
||||
bool isProxyAuthEnabled() const;
|
||||
void setProxyAuthEnabled(bool enabled);
|
||||
QString getProxyIp() const;
|
||||
void setProxyIp(const QString &ip);
|
||||
unsigned short getProxyPort() const;
|
||||
void setProxyPort(unsigned short port);
|
||||
QString getProxyUsername() const;
|
||||
void setProxyUsername(const QString &username);
|
||||
QString getProxyPassword() const;
|
||||
void setProxyPassword(const QString &password);
|
||||
int getProxyType() const;
|
||||
void setProxyType(int type);
|
||||
bool proxyPeerConnections() const;
|
||||
void setProxyPeerConnections(bool enabled);
|
||||
bool getForceProxy() const;
|
||||
void setForceProxy(bool enabled);
|
||||
void setProxyOnlyForTorrents(bool enabled);
|
||||
bool isProxyOnlyForTorrents() const;
|
||||
|
||||
// Bittorrent options
|
||||
int getMaxConnecs() const;
|
||||
void setMaxConnecs(int val);
|
||||
int getMaxConnecsPerTorrent() const;
|
||||
void setMaxConnecsPerTorrent(int val);
|
||||
int getMaxUploads() const;
|
||||
void setMaxUploads(int val);
|
||||
int getMaxUploadsPerTorrent() const;
|
||||
void setMaxUploadsPerTorrent(int val);
|
||||
bool isuTPEnabled() const;
|
||||
void setuTPEnabled(bool enabled);
|
||||
bool isuTPRateLimited() const;
|
||||
void setuTPRateLimited(bool enabled);
|
||||
bool isDHTEnabled() const;
|
||||
void setDHTEnabled(bool enabled);
|
||||
bool isPeXEnabled() const;
|
||||
void setPeXEnabled(bool enabled);
|
||||
bool isLSDEnabled() const;
|
||||
void setLSDEnabled(bool enabled);
|
||||
int getEncryptionSetting() const;
|
||||
void setEncryptionSetting(int val);
|
||||
bool isAddTrackersEnabled() const;
|
||||
void setAddTrackersEnabled(bool enabled);
|
||||
QString getTrackersList() const;
|
||||
void setTrackersList(const QString &val);
|
||||
qreal getGlobalMaxRatio() const;
|
||||
void setGlobalMaxRatio(qreal ratio);
|
||||
|
||||
// IP Filter
|
||||
bool isFilteringEnabled() const;
|
||||
void setFilteringEnabled(bool enabled);
|
||||
bool isFilteringTrackerEnabled() const;
|
||||
void setFilteringTrackerEnabled(bool enabled);
|
||||
QString getFilter() const;
|
||||
void setFilter(const QString &path);
|
||||
QStringList bannedIPs() const;
|
||||
void banIP(const QString &ip);
|
||||
|
||||
// Search
|
||||
bool isSearchEnabled() const;
|
||||
void setSearchEnabled(bool enabled);
|
||||
|
||||
// Queueing system
|
||||
bool isQueueingSystemEnabled() const;
|
||||
void setQueueingSystemEnabled(bool enabled);
|
||||
int getMaxActiveDownloads() const;
|
||||
void setMaxActiveDownloads(int val);
|
||||
int getMaxActiveUploads() const;
|
||||
void setMaxActiveUploads(int val);
|
||||
int getMaxActiveTorrents() const;
|
||||
void setMaxActiveTorrents(int val);
|
||||
bool ignoreSlowTorrentsForQueueing() const;
|
||||
void setIgnoreSlowTorrentsForQueueing(bool ignore);
|
||||
bool isWebUiEnabled() const;
|
||||
void setWebUiEnabled(bool enabled);
|
||||
bool isWebUiLocalAuthEnabled() const;
|
||||
@@ -331,50 +220,16 @@ public:
|
||||
void setShutdownqBTWhenDownloadsComplete(bool shutdown);
|
||||
bool dontConfirmAutoExit() const;
|
||||
void setDontConfirmAutoExit(bool dontConfirmAutoExit);
|
||||
uint diskCacheSize() const;
|
||||
void setDiskCacheSize(uint size);
|
||||
uint diskCacheTTL() const;
|
||||
void setDiskCacheTTL(uint ttl);
|
||||
bool osCache() const;
|
||||
void setOsCache(bool enable);
|
||||
uint saveResumeDataInterval() const;
|
||||
void setSaveResumeDataInterval(uint m);
|
||||
uint outgoingPortsMin() const;
|
||||
void setOutgoingPortsMin(uint val);
|
||||
uint outgoingPortsMax() const;
|
||||
void setOutgoingPortsMax(uint val);
|
||||
bool getIgnoreLimitsOnLAN() const;
|
||||
void setIgnoreLimitsOnLAN(bool ignore);
|
||||
bool includeOverheadInLimits() const;
|
||||
void includeOverheadInLimits(bool include);
|
||||
bool trackerExchangeEnabled() const;
|
||||
void setTrackerExchangeEnabled(bool enable);
|
||||
bool recheckTorrentsOnCompletion() const;
|
||||
void recheckTorrentsOnCompletion(bool recheck);
|
||||
unsigned int getRefreshInterval() const;
|
||||
void setRefreshInterval(uint interval);
|
||||
bool resolvePeerCountries() const;
|
||||
void resolvePeerCountries(bool resolve);
|
||||
bool resolvePeerHostNames() const;
|
||||
void resolvePeerHostNames(bool resolve);
|
||||
int getMaxHalfOpenConnections() const;
|
||||
void setMaxHalfOpenConnections(int value);
|
||||
QString getNetworkInterface() const;
|
||||
void setNetworkInterface(const QString& iface);
|
||||
QString getNetworkInterfaceName() const;
|
||||
void setNetworkInterfaceName(const QString& iface);
|
||||
QString getNetworkInterfaceAddress() const;
|
||||
void setNetworkInterfaceAddress(const QString& addr);
|
||||
bool getListenIPv6() const;
|
||||
void setListenIPv6(bool enable);
|
||||
QString getNetworkAddress() const;
|
||||
void setNetworkAddress(const QString& addr);
|
||||
bool isAnonymousModeEnabled() const;
|
||||
void enableAnonymousMode(bool enabled);
|
||||
bool isSuperSeedingEnabled() const;
|
||||
void enableSuperSeeding(bool enabled);
|
||||
bool announceToAllTrackers() const;
|
||||
void setAnnounceToAllTrackers(bool enabled);
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||||
bool useSystemIconTheme() const;
|
||||
void useSystemIconTheme(bool enabled);
|
||||
@@ -396,8 +251,6 @@ public:
|
||||
static void setTorrentFileAssoc();
|
||||
static void setMagnetLinkAssoc();
|
||||
#endif
|
||||
bool isTrackerEnabled() const;
|
||||
void setTrackerEnabled(bool enabled);
|
||||
int getTrackerPort() const;
|
||||
void setTrackerPort(int port);
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||
|
||||
@@ -98,22 +98,85 @@ namespace
|
||||
{
|
||||
static const MappingTable keyMapping = {
|
||||
|
||||
{ "BitTorrent/Session/MaxRatioAction", "Preferences/Bittorrent/MaxRatioAction" },
|
||||
{ "BitTorrent/Session/DefaultSavePath", "Preferences/Downloads/SavePath" },
|
||||
{ "BitTorrent/Session/TempPath", "Preferences/Downloads/TempPath" },
|
||||
{ "BitTorrent/Session/TempPathEnabled", "Preferences/Downloads/TempPathEnabled" },
|
||||
{ "BitTorrent/Session/AddTorrentPaused", "Preferences/Downloads/StartInPause" },
|
||||
{"BitTorrent/Session/MaxRatioAction", "Preferences/Bittorrent/MaxRatioAction"},
|
||||
{"BitTorrent/Session/DefaultSavePath", "Preferences/Downloads/SavePath"},
|
||||
{"BitTorrent/Session/TempPath", "Preferences/Downloads/TempPath"},
|
||||
{"BitTorrent/Session/TempPathEnabled", "Preferences/Downloads/TempPathEnabled"},
|
||||
{"BitTorrent/Session/AddTorrentPaused", "Preferences/Downloads/StartInPause"},
|
||||
{"BitTorrent/Session/RefreshInterval", "Preferences/General/RefreshInterval"},
|
||||
{"BitTorrent/Session/Preallocation", "Preferences/Downloads/PreAllocation"},
|
||||
{"BitTorrent/Session/AddExtensionToIncompleteFiles", "Preferences/Downloads/UseIncompleteExtension"},
|
||||
{"BitTorrent/Session/TorrentExportDirectory", "Preferences/Downloads/TorrentExportDir"},
|
||||
{"BitTorrent/Session/FinishedTorrentExportDirectory", "Preferences/Downloads/FinishedTorrentExportDir"},
|
||||
{"BitTorrent/Session/GlobalUPSpeedLimit", "Preferences/Connection/GlobalUPLimit"},
|
||||
{"BitTorrent/Session/GlobalDLSpeedLimit", "Preferences/Connection/GlobalDLLimit"},
|
||||
{"BitTorrent/Session/AlternativeGlobalUPSpeedLimit", "Preferences/Connection/GlobalUPLimitAlt"},
|
||||
{"BitTorrent/Session/AlternativeGlobalDLSpeedLimit", "Preferences/Connection/GlobalDLLimitAlt"},
|
||||
{"BitTorrent/Session/UseAlternativeGlobalSpeedLimit", "Preferences/Connection/alt_speeds_on"},
|
||||
{"BitTorrent/Session/BandwidthSchedulerEnabled", "Preferences/Scheduler/Enabled"},
|
||||
{"BitTorrent/Session/Port", "Preferences/Connection/PortRangeMin"},
|
||||
{"BitTorrent/Session/UseRandomPort", "Preferences/General/UseRandomPort"},
|
||||
{"BitTorrent/Session/IPv6Enabled", "Preferences/Connection/InterfaceListenIPv6"},
|
||||
{"BitTorrent/Session/Interface", "Preferences/Connection/Interface"},
|
||||
{"BitTorrent/Session/SaveResumeDataInterval", "Preferences/Downloads/SaveResumeDataInterval"},
|
||||
{"BitTorrent/Session/Encryption", "Preferences/Bittorrent/Encryption"},
|
||||
{"BitTorrent/Session/ForceProxy", "Preferences/Connection/ProxyForce"},
|
||||
{"BitTorrent/Session/ProxyPeerConnections", "Preferences/Connection/ProxyPeerConnections"},
|
||||
{"BitTorrent/Session/MaxConnections", "Preferences/Bittorrent/MaxConnecs"},
|
||||
{"BitTorrent/Session/MaxUploads", "Preferences/Bittorrent/MaxUploads"},
|
||||
{"BitTorrent/Session/MaxConnectionsPerTorrent", "Preferences/Bittorrent/MaxConnecsPerTorrent"},
|
||||
{"BitTorrent/Session/MaxUploadsPerTorrent", "Preferences/Bittorrent/MaxUploadsPerTorrent"},
|
||||
{"BitTorrent/Session/DHTEnabled", "Preferences/Bittorrent/DHT"},
|
||||
{"BitTorrent/Session/LSDEnabled", "Preferences/Bittorrent/LSD"},
|
||||
{"BitTorrent/Session/PeXEnabled", "Preferences/Bittorrent/PeX"},
|
||||
{"BitTorrent/Session/TrackerExchangeEnabled", "Preferences/Advanced/LtTrackerExchange"},
|
||||
{"BitTorrent/Session/AddTrackersEnabled", "Preferences/Bittorrent/AddTrackers"},
|
||||
{"BitTorrent/Session/AdditionalTrackers", "Preferences/Bittorrent/TrackersList"},
|
||||
{"BitTorrent/Session/FilteringEnabled", "Preferences/IPFilter/Enabled"},
|
||||
{"BitTorrent/Session/TrackerFilteringEnabled", "Preferences/IPFilter/FilterTracker"},
|
||||
{"BitTorrent/Session/IPFilter", "Preferences/IPFilter/File"},
|
||||
{"BitTorrent/Session/GlobalMaxRatio", "Preferences/Bittorrent/MaxRatio"},
|
||||
{"BitTorrent/Session/AnnounceToAllTrackers", "Preferences/Advanced/AnnounceToAllTrackers"},
|
||||
{"BitTorrent/Session/DiskCacheSize", "Preferences/Downloads/DiskWriteCacheSize"},
|
||||
{"BitTorrent/Session/DiskCacheTTL", "Preferences/Downloads/DiskWriteCacheTTL"},
|
||||
{"BitTorrent/Session/UseOSCache", "Preferences/Advanced/osCache"},
|
||||
{"BitTorrent/Session/AnonymousModeEnabled", "Preferences/Advanced/AnonymousMode"},
|
||||
{"BitTorrent/Session/QueueingSystemEnabled", "Preferences/Queueing/QueueingEnabled"},
|
||||
{"BitTorrent/Session/MaxActiveDownloads", "Preferences/Queueing/MaxActiveDownloads"},
|
||||
{"BitTorrent/Session/MaxActiveUploads", "Preferences/Queueing/MaxActiveUploads"},
|
||||
{"BitTorrent/Session/MaxActiveTorrents", "Preferences/Queueing/MaxActiveTorrents"},
|
||||
{"BitTorrent/Session/IgnoreSlowTorrentsForQueueing", "Preferences/Queueing/IgnoreSlowTorrents"},
|
||||
{"BitTorrent/Session/OutgoingPortsMin", "Preferences/Advanced/OutgoingPortsMin"},
|
||||
{"BitTorrent/Session/OutgoingPortsMax", "Preferences/Advanced/OutgoingPortsMax"},
|
||||
{"BitTorrent/Session/IgnoreLimitsOnLAN", "Preferences/Advanced/IgnoreLimitsLAN"},
|
||||
{"BitTorrent/Session/IncludeOverheadInLimits", "Preferences/Advanced/IncludeOverhead"},
|
||||
{"BitTorrent/Session/NetworkAddress", "Preferences/Connection/InetAddress"},
|
||||
{"BitTorrent/Session/SuperSeedingEnabled", "Preferences/Advanced/SuperSeeding"},
|
||||
{"BitTorrent/Session/MaxHalfOpenConnections", "Preferences/Connection/MaxHalfOpenConnec"},
|
||||
{"BitTorrent/Session/uTPEnabled", "Preferences/Bittorrent/uTP"},
|
||||
{"BitTorrent/Session/uTPRateLimited", "Preferences/Bittorrent/uTP_rate_limited"},
|
||||
{"BitTorrent/TrackerEnabled", "Preferences/TrackerEnabled"},
|
||||
{"Network/Proxy/Disabled", "Preferences/Connection/ProxyOnlyForTorrents"},
|
||||
{"Network/Proxy/Type", "Preferences/Connection/ProxyType"},
|
||||
{"Network/Proxy/Authentication", "Preferences/Connection/Proxy/Authentication"},
|
||||
{"Network/Proxy/Username", "Preferences/Connection/Proxy/Username"},
|
||||
{"Network/Proxy/Password", "Preferences/Connection/Proxy/Password"},
|
||||
{"Network/Proxy/IP", "Preferences/Connection/Proxy/IP"},
|
||||
{"Network/Proxy/Port", "Preferences/Connection/Proxy/Port"},
|
||||
{"Network/PortForwardingEnabled", "Preferences/Connection/UPnP"},
|
||||
#ifdef QBT_USES_QT5
|
||||
{ "AddNewTorrentDialog/TreeHeaderState", "AddNewTorrentDialog/qt5/treeHeaderState" },
|
||||
{"AddNewTorrentDialog/TreeHeaderState", "AddNewTorrentDialog/qt5/treeHeaderState"},
|
||||
#else
|
||||
{ "AddNewTorrentDialog/TreeHeaderState", "AddNewTorrentDialog/treeHeaderState" },
|
||||
{"AddNewTorrentDialog/TreeHeaderState", "AddNewTorrentDialog/treeHeaderState"},
|
||||
#endif
|
||||
{ "AddNewTorrentDialog/Width", "AddNewTorrentDialog/width" },
|
||||
{ "AddNewTorrentDialog/Position", "AddNewTorrentDialog/y" },
|
||||
{ "AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded" },
|
||||
{ "AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history" },
|
||||
{ "AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog" },
|
||||
{ "AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront" }
|
||||
{"AddNewTorrentDialog/Width", "AddNewTorrentDialog/width"},
|
||||
{"AddNewTorrentDialog/Position", "AddNewTorrentDialog/y"},
|
||||
{"AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded"},
|
||||
{"AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history"},
|
||||
{"AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog"},
|
||||
{"AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront"},
|
||||
|
||||
{"State/BannedIPs", "Preferences/IPFilter/BannedIPs"}
|
||||
|
||||
};
|
||||
|
||||
|
||||
73
src/base/settingvalue.h
Normal file
73
src/base/settingvalue.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef SETTINGVALUE_H
|
||||
#define SETTINGVALUE_H
|
||||
|
||||
#include <functional>
|
||||
#include <QString>
|
||||
|
||||
#include "settingsstorage.h"
|
||||
|
||||
template <typename T>
|
||||
class CachedSettingValue
|
||||
{
|
||||
using ProxyFunc = std::function<T (const T&)>;
|
||||
|
||||
public:
|
||||
explicit CachedSettingValue(const char *keyName, const T &defaultValue = T()
|
||||
, ProxyFunc proxyFunc = [](const T &value) { return value; })
|
||||
: m_keyName(QLatin1String(keyName))
|
||||
, m_value(proxyFunc(SettingsStorage::instance()->loadValue(
|
||||
m_keyName, defaultValue).template value<T>()))
|
||||
{
|
||||
}
|
||||
|
||||
T value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
CachedSettingValue<T> &operator=(const T &newValue)
|
||||
{
|
||||
m_value = newValue;
|
||||
SettingsStorage::instance()->storeValue(m_keyName, m_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T() const
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
||||
private:
|
||||
const QString m_keyName;
|
||||
T m_value;
|
||||
};
|
||||
|
||||
#endif // SETTINGVALUE_H
|
||||
Reference in New Issue
Block a user