2008-05-17 17:23:37 +04:00
|
|
|
/*
|
2009-04-05 22:48:45 +04:00
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2012-05-26 23:58:53 +04:00
|
|
|
* Copyright (C) 2006-2012 Ishan Arora and Christophe Dumez
|
2008-05-17 17:23:37 +04:00
|
|
|
*
|
2009-04-05 22:48:45 +04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-05-17 17:23:37 +04:00
|
|
|
*
|
2009-04-05 22:48:45 +04:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2008-05-17 17:23:37 +04:00
|
|
|
*
|
2009-04-05 22:48:45 +04:00
|
|
|
* 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
|
2008-05-17 17:23:37 +04:00
|
|
|
*/
|
|
|
|
|
2016-05-01 11:05:52 +03:00
|
|
|
#include "prefjson.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2011-06-05 20:08:30 +04:00
|
|
|
#ifndef QT_NO_OPENSSL
|
|
|
|
#include <QSslCertificate>
|
|
|
|
#include <QSslKey>
|
|
|
|
#endif
|
2015-04-19 18:17:47 +03:00
|
|
|
#include <QStringList>
|
2012-05-26 23:58:53 +04:00
|
|
|
#include <QTranslator>
|
2016-02-09 11:56:48 +03:00
|
|
|
|
2016-05-01 11:05:52 +03:00
|
|
|
#include "base/bittorrent/session.h"
|
2016-06-03 17:03:17 +03:00
|
|
|
#include "base/net/portforwarder.h"
|
2016-05-01 11:05:52 +03:00
|
|
|
#include "base/net/proxyconfigurationmanager.h"
|
2016-02-09 11:56:48 +03:00
|
|
|
#include "base/preferences.h"
|
|
|
|
#include "base/scanfoldersmodel.h"
|
|
|
|
#include "base/utils/fs.h"
|
2014-06-04 10:11:38 +04:00
|
|
|
#include "jsonutils.h"
|
2008-05-17 17:23:37 +04:00
|
|
|
|
2012-05-26 23:58:53 +04:00
|
|
|
prefjson::prefjson()
|
|
|
|
{
|
|
|
|
}
|
2010-11-23 00:55:32 +03:00
|
|
|
|
2014-06-04 10:11:38 +04:00
|
|
|
QByteArray prefjson::getPreferences()
|
2008-05-17 17:23:37 +04:00
|
|
|
{
|
2015-06-22 15:02:09 +03:00
|
|
|
const Preferences* const pref = Preferences::instance();
|
2016-02-09 11:56:48 +03:00
|
|
|
auto session = BitTorrent::Session::instance();
|
2015-06-22 15:02:09 +03:00
|
|
|
QVariantMap data;
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Downloads
|
2015-07-08 10:06:41 +03:00
|
|
|
// Hard Disk
|
2016-02-09 11:56:48 +03:00
|
|
|
data["save_path"] = Utils::Fs::toNativePath(session->defaultSavePath());
|
|
|
|
data["temp_path_enabled"] = session->isTempPathEnabled();
|
|
|
|
data["temp_path"] = Utils::Fs::toNativePath(session->tempPath());
|
2016-05-01 11:05:52 +03:00
|
|
|
data["preallocate_all"] = session->isPreallocationEnabled();
|
|
|
|
data["incomplete_files_ext"] = session->isAppendExtensionEnabled();
|
2016-01-01 22:08:32 +03:00
|
|
|
QVariantHash dirs = pref->getScanDirs();
|
|
|
|
QVariantMap nativeDirs;
|
|
|
|
for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) {
|
|
|
|
if (i.value().type() == QVariant::Int)
|
|
|
|
nativeDirs.insert(Utils::Fs::toNativePath(i.key()), i.value().toInt());
|
|
|
|
else
|
|
|
|
nativeDirs.insert(Utils::Fs::toNativePath(i.key()), Utils::Fs::toNativePath(i.value().toString()));
|
2015-06-22 15:02:09 +03:00
|
|
|
}
|
2016-01-01 22:08:32 +03:00
|
|
|
data["scan_dirs"] = nativeDirs;
|
2016-05-01 11:05:52 +03:00
|
|
|
data["export_dir"] = Utils::Fs::toNativePath(session->torrentExportDirectory());
|
|
|
|
data["export_dir_fin"] = Utils::Fs::toNativePath(session->finishedTorrentExportDirectory());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Email notification upon download completion
|
2015-06-22 15:02:09 +03:00
|
|
|
data["mail_notification_enabled"] = pref->isMailNotificationEnabled();
|
|
|
|
data["mail_notification_email"] = pref->getMailNotificationEmail();
|
|
|
|
data["mail_notification_smtp"] = pref->getMailNotificationSMTP();
|
|
|
|
data["mail_notification_ssl_enabled"] = pref->getMailNotificationSMTPSSL();
|
|
|
|
data["mail_notification_auth_enabled"] = pref->getMailNotificationSMTPAuth();
|
|
|
|
data["mail_notification_username"] = pref->getMailNotificationSMTPUsername();
|
|
|
|
data["mail_notification_password"] = pref->getMailNotificationSMTPPassword();
|
2015-07-08 10:06:41 +03:00
|
|
|
// Run an external program on torrent completion
|
2015-06-22 15:02:09 +03:00
|
|
|
data["autorun_enabled"] = pref->isAutoRunEnabled();
|
|
|
|
data["autorun_program"] = Utils::Fs::toNativePath(pref->getAutoRunProgram());
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Connection
|
2015-07-08 10:06:41 +03:00
|
|
|
// Listening Port
|
2016-05-01 11:05:52 +03:00
|
|
|
data["listen_port"] = session->port();
|
2016-06-03 17:03:17 +03:00
|
|
|
data["upnp"] = Net::PortForwarder::instance()->isEnabled();
|
2016-05-01 11:05:52 +03:00
|
|
|
data["random_port"] = session->useRandomPort();
|
2015-07-08 10:06:41 +03:00
|
|
|
// Connections Limits
|
2016-05-01 11:05:52 +03:00
|
|
|
data["max_connec"] = session->maxConnections();
|
|
|
|
data["max_connec_per_torrent"] = session->maxConnectionsPerTorrent();
|
|
|
|
data["max_uploads"] = session->maxUploads();
|
|
|
|
data["max_uploads_per_torrent"] = session->maxUploadsPerTorrent();
|
|
|
|
|
2015-07-08 10:06:41 +03:00
|
|
|
// Proxy Server
|
2016-05-01 11:05:52 +03:00
|
|
|
auto proxyManager = Net::ProxyConfigurationManager::instance();
|
|
|
|
Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration();
|
|
|
|
data["proxy_type"] = static_cast<int>(proxyConf.type);
|
|
|
|
data["proxy_ip"] = proxyConf.ip;
|
|
|
|
data["proxy_port"] = proxyConf.port;
|
|
|
|
data["proxy_auth_enabled"] = proxyManager->isAuthenticationRequired(); // deprecated
|
|
|
|
data["proxy_username"] = proxyConf.username;
|
|
|
|
data["proxy_password"] = proxyConf.password;
|
|
|
|
|
|
|
|
data["proxy_peer_connections"] = session->isProxyPeerConnectionsEnabled();
|
|
|
|
data["force_proxy"] = session->isForceProxyEnabled();
|
|
|
|
|
2015-07-08 10:06:41 +03:00
|
|
|
// IP Filtering
|
2016-10-29 19:14:27 +03:00
|
|
|
data["ip_filter_enabled"] = session->isIPFilteringEnabled();
|
2016-05-01 11:05:52 +03:00
|
|
|
data["ip_filter_path"] = Utils::Fs::toNativePath(session->IPFilterFile());
|
|
|
|
data["ip_filter_trackers"] = session->isTrackerFilteringEnabled();
|
2015-07-08 10:06:41 +03:00
|
|
|
|
|
|
|
// Speed
|
|
|
|
// Global Rate Limits
|
2016-05-01 11:05:52 +03:00
|
|
|
data["dl_limit"] = session->globalDownloadSpeedLimit();
|
|
|
|
data["up_limit"] = session->globalUploadSpeedLimit();
|
|
|
|
data["enable_utp"] = session->isUTPEnabled();
|
|
|
|
data["limit_utp_rate"] = session->isUTPRateLimited();
|
|
|
|
data["limit_tcp_overhead"] = session->includeOverheadInLimits();
|
|
|
|
data["alt_dl_limit"] = session->altGlobalDownloadSpeedLimit();
|
|
|
|
data["alt_up_limit"] = session->altGlobalUploadSpeedLimit();
|
2015-07-08 10:06:41 +03:00
|
|
|
// Scheduling
|
2016-05-01 11:05:52 +03:00
|
|
|
data["scheduler_enabled"] = session->isBandwidthSchedulerEnabled();
|
2015-06-22 15:02:09 +03:00
|
|
|
const QTime start_time = pref->getSchedulerStartTime();
|
|
|
|
data["schedule_from_hour"] = start_time.hour();
|
|
|
|
data["schedule_from_min"] = start_time.minute();
|
|
|
|
const QTime end_time = pref->getSchedulerEndTime();
|
|
|
|
data["schedule_to_hour"] = end_time.hour();
|
|
|
|
data["schedule_to_min"] = end_time.minute();
|
|
|
|
data["scheduler_days"] = pref->getSchedulerDays();
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Bittorrent
|
2015-07-08 10:06:41 +03:00
|
|
|
// Privacy
|
2016-05-01 11:05:52 +03:00
|
|
|
data["dht"] = session->isDHTEnabled();
|
|
|
|
data["pex"] = session->isPeXEnabled();
|
|
|
|
data["lsd"] = session->isLSDEnabled();
|
|
|
|
data["encryption"] = session->encryption();
|
|
|
|
data["anonymous_mode"] = session->isAnonymousModeEnabled();
|
2015-07-08 10:06:41 +03:00
|
|
|
// Torrent Queueing
|
2016-05-01 11:05:52 +03:00
|
|
|
data["queueing_enabled"] = session->isQueueingSystemEnabled();
|
|
|
|
data["max_active_downloads"] = session->maxActiveDownloads();
|
|
|
|
data["max_active_torrents"] = session->maxActiveTorrents();
|
|
|
|
data["max_active_uploads"] = session->maxActiveUploads();
|
|
|
|
data["dont_count_slow_torrents"] = session->ignoreSlowTorrentsForQueueing();
|
2015-07-08 10:06:41 +03:00
|
|
|
// Share Ratio Limiting
|
2016-05-01 11:05:52 +03:00
|
|
|
data["max_ratio_enabled"] = (session->globalMaxRatio() >= 0.);
|
|
|
|
data["max_ratio"] = session->globalMaxRatio();
|
|
|
|
data["max_ratio_act"] = session->maxRatioAction();
|
2016-05-07 16:17:01 +03:00
|
|
|
// Add trackers
|
2016-05-01 11:05:52 +03:00
|
|
|
data["add_trackers_enabled"] = session->isAddTrackersEnabled();
|
|
|
|
data["add_trackers"] = session->additionalTrackers();
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Web UI
|
2015-07-08 10:06:41 +03:00
|
|
|
// Language
|
|
|
|
data["locale"] = pref->getLocale();
|
|
|
|
// HTTP Server
|
2015-06-22 15:02:09 +03:00
|
|
|
data["web_ui_port"] = pref->getWebUiPort();
|
2015-07-09 11:42:45 +03:00
|
|
|
data["web_ui_upnp"] = pref->useUPnPForWebUIPort();
|
2015-06-22 15:02:09 +03:00
|
|
|
data["use_https"] = pref->isWebUiHttpsEnabled();
|
|
|
|
data["ssl_key"] = QString::fromLatin1(pref->getWebUiHttpsKey());
|
|
|
|
data["ssl_cert"] = QString::fromLatin1(pref->getWebUiHttpsCertificate());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Authentication
|
|
|
|
data["web_ui_username"] = pref->getWebUiUsername();
|
|
|
|
data["web_ui_password"] = pref->getWebUiPassword();
|
|
|
|
data["bypass_local_auth"] = !pref->isWebUiLocalAuthEnabled();
|
|
|
|
// Update my dynamic domain name
|
2015-06-22 15:02:09 +03:00
|
|
|
data["dyndns_enabled"] = pref->isDynDNSEnabled();
|
|
|
|
data["dyndns_service"] = pref->getDynDNSService();
|
|
|
|
data["dyndns_username"] = pref->getDynDNSUsername();
|
|
|
|
data["dyndns_password"] = pref->getDynDNSPassword();
|
|
|
|
data["dyndns_domain"] = pref->getDynDomainName();
|
2012-05-26 23:58:53 +04:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
return json::toJson(data);
|
2008-05-17 17:23:37 +04:00
|
|
|
}
|
|
|
|
|
2012-05-26 23:58:53 +04:00
|
|
|
void prefjson::setPreferences(const QString& json)
|
|
|
|
{
|
2015-06-22 15:02:09 +03:00
|
|
|
Preferences* const pref = Preferences::instance();
|
2016-02-09 11:56:48 +03:00
|
|
|
auto session = BitTorrent::Session::instance();
|
2015-07-08 10:06:41 +03:00
|
|
|
const QVariantMap m = json::fromJson(json).toMap();
|
2010-09-25 16:42:19 +04:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Downloads
|
2015-07-08 10:06:41 +03:00
|
|
|
// Hard Disk
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("save_path"))
|
2016-02-09 11:56:48 +03:00
|
|
|
session->setDefaultSavePath(m["save_path"].toString());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("temp_path_enabled"))
|
2016-02-09 11:56:48 +03:00
|
|
|
session->setTempPathEnabled(m["temp_path_enabled"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("temp_path"))
|
2016-02-09 11:56:48 +03:00
|
|
|
session->setTempPath(m["temp_path"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("preallocate_all"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setPreallocationEnabled(m["preallocate_all"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("incomplete_files_ext"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setAppendExtensionEnabled(m["incomplete_files_ext"].toBool());
|
2016-01-01 22:08:32 +03:00
|
|
|
if (m.contains("scan_dirs")) {
|
|
|
|
QVariantMap nativeDirs = m["scan_dirs"].toMap();
|
|
|
|
QVariantHash oldScanDirs = pref->getScanDirs();
|
|
|
|
QVariantHash scanDirs;
|
|
|
|
ScanFoldersModel *model = ScanFoldersModel::instance();
|
|
|
|
for (QVariantMap::const_iterator i = nativeDirs.begin(), e = nativeDirs.end(); i != e; ++i) {
|
|
|
|
QString folder = Utils::Fs::fromNativePath(i.key());
|
|
|
|
int downloadType;
|
|
|
|
QString downloadPath;
|
|
|
|
ScanFoldersModel::PathStatus ec;
|
|
|
|
if (i.value().type() == QVariant::String) {
|
|
|
|
downloadType = ScanFoldersModel::CUSTOM_LOCATION;
|
|
|
|
downloadPath = Utils::Fs::fromNativePath(i.value().toString());
|
2015-06-22 15:02:09 +03:00
|
|
|
}
|
2016-01-01 22:08:32 +03:00
|
|
|
else {
|
|
|
|
downloadType = i.value().toInt();
|
|
|
|
downloadPath = (downloadType == ScanFoldersModel::DEFAULT_LOCATION) ? "Default folder" : "Watch folder";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!oldScanDirs.contains(folder))
|
|
|
|
ec = model->addPath(folder, static_cast<ScanFoldersModel::PathType>(downloadType), downloadPath);
|
|
|
|
else
|
|
|
|
ec = model->updatePath(folder, static_cast<ScanFoldersModel::PathType>(downloadType), downloadPath);
|
|
|
|
|
|
|
|
if (ec == ScanFoldersModel::Ok) {
|
|
|
|
scanDirs.insert(folder, (downloadType == ScanFoldersModel::CUSTOM_LOCATION) ? QVariant(downloadPath) : QVariant(downloadType));
|
|
|
|
qDebug("New watched folder: %s to %s", qPrintable(folder), qPrintable(downloadPath));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug("Watched folder %s failed with error %d", qPrintable(folder), ec);
|
2015-06-22 15:02:09 +03:00
|
|
|
}
|
2010-03-22 21:50:04 +03:00
|
|
|
}
|
2016-01-01 22:08:32 +03:00
|
|
|
|
|
|
|
// Update deleted folders
|
|
|
|
foreach (QVariant folderVariant, oldScanDirs.keys()) {
|
|
|
|
QString folder = folderVariant.toString();
|
|
|
|
if (!scanDirs.contains(folder)) {
|
|
|
|
model->removePath(folder);
|
|
|
|
qDebug("Removed watched folder %s", qPrintable(folder));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pref->setScanDirs(scanDirs);
|
|
|
|
}
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("export_dir"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setTorrentExportDirectory(m["export_dir"].toString());
|
2015-06-28 14:28:03 +03:00
|
|
|
if (m.contains("export_dir_fin"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setFinishedTorrentExportDirectory(m["export_dir_fin"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Email notification upon download completion
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("mail_notification_enabled"))
|
|
|
|
pref->setMailNotificationEnabled(m["mail_notification_enabled"].toBool());
|
|
|
|
if (m.contains("mail_notification_email"))
|
|
|
|
pref->setMailNotificationEmail(m["mail_notification_email"].toString());
|
|
|
|
if (m.contains("mail_notification_smtp"))
|
|
|
|
pref->setMailNotificationSMTP(m["mail_notification_smtp"].toString());
|
|
|
|
if (m.contains("mail_notification_ssl_enabled"))
|
|
|
|
pref->setMailNotificationSMTPSSL(m["mail_notification_ssl_enabled"].toBool());
|
|
|
|
if (m.contains("mail_notification_auth_enabled"))
|
|
|
|
pref->setMailNotificationSMTPAuth(m["mail_notification_auth_enabled"].toBool());
|
|
|
|
if (m.contains("mail_notification_username"))
|
|
|
|
pref->setMailNotificationSMTPUsername(m["mail_notification_username"].toString());
|
|
|
|
if (m.contains("mail_notification_password"))
|
|
|
|
pref->setMailNotificationSMTPPassword(m["mail_notification_password"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Run an external program on torrent completion
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("autorun_enabled"))
|
|
|
|
pref->setAutoRunEnabled(m["autorun_enabled"].toBool());
|
|
|
|
if (m.contains("autorun_program"))
|
|
|
|
pref->setAutoRunProgram(m["autorun_program"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Connection
|
2015-07-08 10:06:41 +03:00
|
|
|
// Listening Port
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("listen_port"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setPort(m["listen_port"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("upnp"))
|
2016-06-03 17:03:17 +03:00
|
|
|
Net::PortForwarder::instance()->setEnabled(m["upnp"].toBool());
|
2015-06-28 14:28:03 +03:00
|
|
|
if (m.contains("random_port"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setUseRandomPort(m["random_port"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Connections Limits
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("max_connec"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxConnections(m["max_connec"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("max_connec_per_torrent"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxConnectionsPerTorrent(m["max_connec_per_torrent"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("max_uploads"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxUploads(m["max_uploads"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("max_uploads_per_torrent"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxUploadsPerTorrent(m["max_uploads_per_torrent"].toInt());
|
|
|
|
|
2015-07-08 10:06:41 +03:00
|
|
|
// Proxy Server
|
2016-05-01 11:05:52 +03:00
|
|
|
auto proxyManager = Net::ProxyConfigurationManager::instance();
|
|
|
|
Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration();
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("proxy_type"))
|
2016-05-01 11:05:52 +03:00
|
|
|
proxyConf.type = static_cast<Net::ProxyType>(m["proxy_type"].toInt());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("proxy_ip"))
|
2016-05-01 11:05:52 +03:00
|
|
|
proxyConf.ip = m["proxy_ip"].toString();
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("proxy_port"))
|
2016-05-01 11:05:52 +03:00
|
|
|
proxyConf.port = m["proxy_port"].toUInt();
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("proxy_username"))
|
2016-05-01 11:05:52 +03:00
|
|
|
proxyConf.username = m["proxy_username"].toString();
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("proxy_password"))
|
2016-05-01 11:05:52 +03:00
|
|
|
proxyConf.password = m["proxy_password"].toString();
|
|
|
|
proxyManager->setProxyConfiguration(proxyConf);
|
|
|
|
|
|
|
|
if (m.contains("proxy_peer_connections"))
|
|
|
|
session->setProxyPeerConnectionsEnabled(m["proxy_peer_connections"].toBool());
|
|
|
|
if (m.contains("force_proxy"))
|
|
|
|
session->setForceProxyEnabled(m["force_proxy"].toBool());
|
|
|
|
|
2015-07-08 10:06:41 +03:00
|
|
|
// IP Filtering
|
|
|
|
if (m.contains("ip_filter_enabled"))
|
2016-10-29 19:14:27 +03:00
|
|
|
session->setIPFilteringEnabled(m["ip_filter_enabled"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("ip_filter_path"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setIPFilterFile(m["ip_filter_path"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("ip_filter_trackers"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setTrackerFilteringEnabled(m["ip_filter_trackers"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
|
|
|
|
// Speed
|
|
|
|
// Global Rate Limits
|
|
|
|
if (m.contains("dl_limit"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setGlobalDownloadSpeedLimit(m["dl_limit"].toInt());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("up_limit"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setGlobalUploadSpeedLimit(m["up_limit"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("enable_utp"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setUTPEnabled(m["enable_utp"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("limit_utp_rate"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setUTPRateLimited(m["limit_utp_rate"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("limit_tcp_overhead"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setIncludeOverheadInLimits(m["limit_tcp_overhead"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("alt_dl_limit"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setAltGlobalDownloadSpeedLimit(m["alt_dl_limit"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("alt_up_limit"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setAltGlobalUploadSpeedLimit(m["alt_up_limit"].toInt());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Scheduling
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("scheduler_enabled"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setBandwidthSchedulerEnabled(m["scheduler_enabled"].toBool());
|
|
|
|
if (m.contains("schedule_from_hour") && m.contains("schedule_from_min"))
|
|
|
|
pref->setSchedulerStartTime(QTime(m["schedule_from_hour"].toInt(), m["schedule_from_min"].toInt()));
|
|
|
|
if (m.contains("schedule_to_hour") && m.contains("schedule_to_min"))
|
|
|
|
pref->setSchedulerEndTime(QTime(m["schedule_to_hour"].toInt(), m["schedule_to_min"].toInt()));
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("scheduler_days"))
|
|
|
|
pref->setSchedulerDays(scheduler_days(m["scheduler_days"].toInt()));
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Bittorrent
|
2015-07-08 10:06:41 +03:00
|
|
|
// Privacy
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("dht"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setDHTEnabled(m["dht"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("pex"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setPeXEnabled(m["pex"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("lsd"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setLSDEnabled(m["lsd"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("encryption"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setEncryption(m["encryption"].toInt());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("anonymous_mode"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setAnonymousModeEnabled(m["anonymous_mode"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Torrent Queueing
|
|
|
|
if (m.contains("queueing_enabled"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setQueueingSystemEnabled(m["queueing_enabled"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("max_active_downloads"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxActiveDownloads(m["max_active_downloads"].toInt());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("max_active_torrents"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxActiveTorrents(m["max_active_torrents"].toInt());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("max_active_uploads"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxActiveUploads(m["max_active_uploads"].toInt());
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("dont_count_slow_torrents"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setIgnoreSlowTorrentsForQueueing(m["dont_count_slow_torrents"].toBool());
|
2015-07-08 10:06:41 +03:00
|
|
|
// Share Ratio Limiting
|
|
|
|
if (m.contains("max_ratio_enabled"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setGlobalMaxRatio(m["max_ratio"].toReal());
|
2015-07-08 10:06:41 +03:00
|
|
|
else
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setGlobalMaxRatio(-1);
|
2015-07-08 10:06:41 +03:00
|
|
|
if (m.contains("max_ratio_act"))
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setMaxRatioAction(static_cast<MaxRatioAction>(m["max_ratio_act"].toInt()));
|
2016-05-07 16:17:01 +03:00
|
|
|
// Add trackers
|
2016-05-01 11:05:52 +03:00
|
|
|
session->setAddTrackersEnabled(m["add_trackers_enabled"].toBool());
|
|
|
|
session->setAdditionalTrackers(m["add_trackers"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Web UI
|
2015-07-08 10:06:41 +03:00
|
|
|
// Language
|
|
|
|
if (m.contains("locale")) {
|
|
|
|
QString locale = m["locale"].toString();
|
|
|
|
if (pref->getLocale() != locale) {
|
|
|
|
QTranslator *translator = new QTranslator;
|
|
|
|
if (translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)) {
|
|
|
|
qDebug("%s locale recognized, using translation.", qPrintable(locale));
|
|
|
|
}else{
|
|
|
|
qDebug("%s locale unrecognized, using default (en).", qPrintable(locale));
|
|
|
|
}
|
|
|
|
qApp->installTranslator(translator);
|
|
|
|
|
|
|
|
pref->setLocale(locale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// HTTP Server
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("web_ui_port"))
|
|
|
|
pref->setWebUiPort(m["web_ui_port"].toUInt());
|
2015-07-09 11:42:45 +03:00
|
|
|
if (m.contains("web_ui_upnp"))
|
|
|
|
pref->setUPnPForWebUIPort(m["web_ui_upnp"].toBool());
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("use_https"))
|
|
|
|
pref->setWebUiHttpsEnabled(m["use_https"].toBool());
|
2011-06-05 20:08:30 +04:00
|
|
|
#ifndef QT_NO_OPENSSL
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("ssl_key")) {
|
|
|
|
QByteArray raw_key = m["ssl_key"].toString().toLatin1();
|
|
|
|
if (!QSslKey(raw_key, QSsl::Rsa).isNull())
|
|
|
|
pref->setWebUiHttpsKey(raw_key);
|
|
|
|
}
|
|
|
|
if (m.contains("ssl_cert")) {
|
|
|
|
QByteArray raw_cert = m["ssl_cert"].toString().toLatin1();
|
|
|
|
if (!QSslCertificate(raw_cert).isNull())
|
|
|
|
pref->setWebUiHttpsCertificate(raw_cert);
|
|
|
|
}
|
2011-06-05 20:08:30 +04:00
|
|
|
#endif
|
2015-07-08 10:06:41 +03:00
|
|
|
// Authentication
|
|
|
|
if (m.contains("web_ui_username"))
|
|
|
|
pref->setWebUiUsername(m["web_ui_username"].toString());
|
|
|
|
if (m.contains("web_ui_password"))
|
|
|
|
pref->setWebUiPassword(m["web_ui_password"].toString());
|
|
|
|
if (m.contains("bypass_local_auth"))
|
|
|
|
pref->setWebUiLocalAuthEnabled(!m["bypass_local_auth"].toBool());
|
|
|
|
// Update my dynamic domain name
|
2015-06-22 15:02:09 +03:00
|
|
|
if (m.contains("dyndns_enabled"))
|
|
|
|
pref->setDynDNSEnabled(m["dyndns_enabled"].toBool());
|
|
|
|
if (m.contains("dyndns_service"))
|
|
|
|
pref->setDynDNSService(m["dyndns_service"].toInt());
|
|
|
|
if (m.contains("dyndns_username"))
|
|
|
|
pref->setDynDNSUsername(m["dyndns_username"].toString());
|
|
|
|
if (m.contains("dyndns_password"))
|
|
|
|
pref->setDynDNSPassword(m["dyndns_password"].toString());
|
|
|
|
if (m.contains("dyndns_domain"))
|
|
|
|
pref->setDynDomainName(m["dyndns_domain"].toString());
|
2015-07-08 10:06:41 +03:00
|
|
|
|
2015-06-22 15:02:09 +03:00
|
|
|
// Save preferences
|
|
|
|
pref->apply();
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
}
|