Browse Source

Use new JSON parser/generator.

Qt4: Use QJson (http://qjson.sourceforge.net).
Qt5: Use native Qt JSON API.
adaptive-webui-19844
Vladimir Golovnev (Glassez) 11 years ago
parent
commit
9f310318c2
  1. 134
      src/webui/btjson.cpp
  2. 10
      src/webui/btjson.h
  3. 66
      src/webui/jsonutils.h
  4. 153
      src/webui/prefjson.cpp
  5. 2
      src/webui/prefjson.h

134
src/webui/btjson.cpp

@ -29,12 +29,11 @@ @@ -29,12 +29,11 @@
*/
#include "btjson.h"
#include "jsondict.h"
#include "jsonlist.h"
#include "misc.h"
#include "fs_utils.h"
#include "qbtsession.h"
#include "torrentpersistentdata.h"
#include "jsonutils.h"
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
#include <QElapsedTimer>
@ -49,20 +48,20 @@ using namespace libtorrent; @@ -49,20 +48,20 @@ using namespace libtorrent;
static QElapsedTimer cacheTimer; \
static bool initialized = false; \
if (initialized && !cacheTimer.hasExpired(DUR)) \
return VAR.toString(); \
return json::toJson(VAR); \
initialized = true; \
cacheTimer.start(); \
VAR.clear()
VAR = VARTYPE()
#define CACHED_VARIABLE_FOR_HASH(VARTYPE, VAR, DUR, HASH) \
static VARTYPE VAR; \
static QString prev_hash; \
static QElapsedTimer cacheTimer; \
if (prev_hash == HASH && !cacheTimer.hasExpired(DUR)) \
return VAR.toString(); \
return json::toJson(VAR); \
prev_hash = HASH; \
cacheTimer.start(); \
VAR.clear()
VAR = VARTYPE()
#else
// We don't support caching for Qt < 4.7 at the moment
@ -122,31 +121,31 @@ static const char KEY_FILE_IS_SEED[] = "is_seed"; @@ -122,31 +121,31 @@ static const char KEY_FILE_IS_SEED[] = "is_seed";
static const char KEY_TRANSFER_DLSPEED[] = "dl_info";
static const char KEY_TRANSFER_UPSPEED[] = "up_info";
static JsonDict toJson(const QTorrentHandle& h)
static QVariantMap toMap(const QTorrentHandle& h)
{
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters);
JsonDict ret;
ret.add(KEY_TORRENT_HASH, h.hash());
ret.add(KEY_TORRENT_NAME, h.name());
ret.add(KEY_TORRENT_SIZE, misc::friendlyUnit(status.total_wanted)); // FIXME: Should pass as Number, not formatted String (for sorting).
ret.add(KEY_TORRENT_PROGRESS, (double)h.progress(status));
ret.add(KEY_TORRENT_DLSPEED, misc::friendlyUnit(status.download_payload_rate, true)); // FIXME: Should be passed as a Number
ret.add(KEY_TORRENT_UPSPEED, misc::friendlyUnit(status.upload_payload_rate, true)); // FIXME: Should be passed as a Number
QVariantMap ret;
ret[KEY_TORRENT_HASH] = h.hash();
ret[KEY_TORRENT_NAME] = h.name();
ret[KEY_TORRENT_SIZE] = misc::friendlyUnit(h.actual_size()); // FIXME: Should pass as Number, not formatted String (for sorting).
ret[KEY_TORRENT_PROGRESS] = (double)h.progress(status);
ret[KEY_TORRENT_DLSPEED] = misc::friendlyUnit(status.download_payload_rate, true); // FIXME: Should be passed as a Number
ret[KEY_TORRENT_UPSPEED] = misc::friendlyUnit(status.upload_payload_rate, true); // FIXME: Should be passed as a Number
if (QBtSession::instance()->isQueueingEnabled() && h.queue_position() >= 0)
ret.add(KEY_TORRENT_PRIORITY, QString::number(h.queue_position()));
ret[KEY_TORRENT_PRIORITY] = QString::number(h.queue_position());
else
ret.add(KEY_TORRENT_PRIORITY, "*");
ret[KEY_TORRENT_PRIORITY] = "*";
QString seeds = QString::number(status.num_seeds);
if (status.num_complete > 0)
seeds += " ("+QString::number(status.num_complete)+")";
ret.add(KEY_TORRENT_SEEDS, seeds);
ret[KEY_TORRENT_SEEDS] = seeds;
QString leechs = QString::number(status.num_peers - status.num_seeds);
if (status.num_incomplete > 0)
leechs += " ("+QString::number(status.num_incomplete)+")";
ret.add(KEY_TORRENT_LEECHS, leechs);
ret[KEY_TORRENT_LEECHS] = leechs;
const qreal ratio = QBtSession::instance()->getRealRatio(status);
ret.add(KEY_TORRENT_RATIO, (ratio > 100.) ? QString::fromUtf8("") : misc::accurateDoubleToString(ratio, 1));
ret[KEY_TORRENT_RATIO] = (ratio > 100.) ? QString::fromUtf8("") : misc::accurateDoubleToString(ratio, 1);
QString eta;
QString state;
if (h.is_paused(status)) {
@ -179,8 +178,8 @@ static JsonDict toJson(const QTorrentHandle& h) @@ -179,8 +178,8 @@ static JsonDict toJson(const QTorrentHandle& h)
}
}
}
ret.add(KEY_TORRENT_ETA, eta.isEmpty() ? QString::fromUtf8("") : eta);
ret.add(KEY_TORRENT_STATE, state);
ret[KEY_TORRENT_ETA] = eta.isEmpty() ? QString::fromUtf8("") : eta;
ret[KEY_TORRENT_STATE] = state;
return ret;
}
@ -203,16 +202,16 @@ static JsonDict toJson(const QTorrentHandle& h) @@ -203,16 +202,16 @@ static JsonDict toJson(const QTorrentHandle& h)
* - "eta": Torrent ETA
* - "state": Torrent state
*/
QString btjson::getTorrents()
QByteArray btjson::getTorrents()
{
CACHED_VARIABLE(JsonList, torrent_list, CACHE_DURATION_MS);
CACHED_VARIABLE(QVariantList, torrent_list, CACHE_DURATION_MS);
std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
std::vector<torrent_handle>::const_iterator it = torrents.begin();
std::vector<torrent_handle>::const_iterator end = torrents.end();
for( ; it != end; ++it) {
torrent_list.append(toJson(QTorrentHandle(*it)));
torrent_list.append(toMap(QTorrentHandle(*it)));
}
return torrent_list.toString();
return json::toJson(torrent_list);
}
/**
@ -225,9 +224,9 @@ QString btjson::getTorrents() @@ -225,9 +224,9 @@ QString btjson::getTorrents()
* - "num_peers": Tracker peer count
* - "msg": Tracker message (last)
*/
QString btjson::getTrackersForTorrent(const QString& hash)
QByteArray btjson::getTrackersForTorrent(const QString& hash)
{
CACHED_VARIABLE_FOR_HASH(JsonList, tracker_list, CACHE_DURATION_MS, hash);
CACHED_VARIABLE_FOR_HASH(QVariantList, tracker_list, CACHE_DURATION_MS, hash);
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
QHash<QString, TrackerInfos> trackers_data = QBtSession::instance()->getTrackersInfo(hash);
@ -235,9 +234,9 @@ QString btjson::getTrackersForTorrent(const QString& hash) @@ -235,9 +234,9 @@ QString btjson::getTrackersForTorrent(const QString& hash)
std::vector<announce_entry>::const_iterator it = vect_trackers.begin();
std::vector<announce_entry>::const_iterator end = vect_trackers.end();
for (; it != end; ++it) {
JsonDict tracker_dict;
QVariantMap tracker_dict;
const QString tracker_url = misc::toQString(it->url);
tracker_dict.add(KEY_TRACKER_URL, tracker_url);
tracker_dict[KEY_TRACKER_URL] = tracker_url;
const TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
QString status;
if (it->verified)
@ -248,18 +247,18 @@ QString btjson::getTrackersForTorrent(const QString& hash) @@ -248,18 +247,18 @@ QString btjson::getTrackersForTorrent(const QString& hash)
else
status = it->fails > 0 ? tr("Not working") : tr("Not contacted yet");
}
tracker_dict.add(KEY_TRACKER_STATUS, status);
tracker_dict.add(KEY_TRACKER_PEERS, QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers));
tracker_dict.add(KEY_TRACKER_MSG, data.last_message.trimmed());
tracker_dict[KEY_TRACKER_STATUS] = status;
tracker_dict[KEY_TRACKER_PEERS] = QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers);
tracker_dict[KEY_TRACKER_MSG] = data.last_message.trimmed();
tracker_list.append(tracker_dict);
}
} catch(const std::exception& e) {
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
return QString();
return QByteArray();
}
return tracker_list.toString();
return json::toJson(tracker_list);
}
/**
@ -280,43 +279,42 @@ QString btjson::getTrackersForTorrent(const QString& hash) @@ -280,43 +279,42 @@ QString btjson::getTrackersForTorrent(const QString& hash)
* - "nb_connections": Torrent connection count
* - "share_ratio": Torrent share ratio
*/
QString btjson::getPropertiesForTorrent(const QString& hash)
QByteArray btjson::getPropertiesForTorrent(const QString& hash)
{
CACHED_VARIABLE_FOR_HASH(JsonDict, data, CACHE_DURATION_MS, hash);
CACHED_VARIABLE_FOR_HASH(QVariantMap, data, CACHE_DURATION_MS, hash);
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters);
if (!status.has_metadata)
return QString();
return QByteArray();
// Save path
QString save_path = fsutils::toNativePath(TorrentPersistentData::getSavePath(hash));
if (save_path.isEmpty())
save_path = fsutils::toNativePath(h.save_path());
data.add(KEY_PROP_SAVE_PATH, save_path);
data.add(KEY_PROP_CREATION_DATE, h.creation_date());
data.add(KEY_PROP_PIECE_SIZE, misc::friendlyUnit(h.piece_length()));
data.add(KEY_PROP_COMMENT, h.comment());
data.add(KEY_PROP_WASTED, misc::friendlyUnit(status.total_failed_bytes + status.total_redundant_bytes));
data.add(KEY_PROP_UPLOADED, QString(misc::friendlyUnit(status.all_time_upload) + " (" + misc::friendlyUnit(status.total_payload_upload) + " " + tr("this session") + ")"));
data.add(KEY_PROP_DOWNLOADED, QString(misc::friendlyUnit(status.all_time_download) + " (" + misc::friendlyUnit(status.total_payload_download) + " " + tr("this session") + ")"));
data.add(KEY_PROP_UP_LIMIT, h.upload_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.upload_limit(), true));
data.add(KEY_PROP_DL_LIMIT, h.download_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.download_limit(), true));
data[KEY_PROP_SAVE_PATH] = save_path;
data[KEY_PROP_CREATION_DATE] = h.creation_date();
data[KEY_PROP_PIECE_SIZE] = misc::friendlyUnit(h.piece_length());
data[KEY_PROP_COMMENT] = h.comment();
data[KEY_PROP_WASTED] = misc::friendlyUnit(status.total_failed_bytes + status.total_redundant_bytes);
data[KEY_PROP_UPLOADED] = QString(misc::friendlyUnit(status.all_time_upload) + " (" + misc::friendlyUnit(status.total_payload_upload) + " " + tr("this session") + ")");
data[KEY_PROP_DOWNLOADED] = QString(misc::friendlyUnit(status.all_time_download) + " (" + misc::friendlyUnit(status.total_payload_download) + " " + tr("this session") + ")");
data[KEY_PROP_UP_LIMIT] = h.upload_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.upload_limit(), true);
data[KEY_PROP_DL_LIMIT] = h.download_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.download_limit(), true);
QString elapsed_txt = misc::userFriendlyDuration(status.active_time);
if (h.is_seed(status))
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(status.seeding_time))+")";
data.add(KEY_PROP_TIME_ELAPSED, elapsed_txt);
data.add(KEY_PROP_CONNECT_COUNT, QString(QString::number(status.num_connections) + " (" + tr("%1 max", "e.g. 10 max").arg(QString::number(status.connections_limit)) + ")"));
data[KEY_PROP_TIME_ELAPSED] = elapsed_txt;
data[KEY_PROP_CONNECT_COUNT] = QString(QString::number(status.num_connections) + " (" + tr("%1 max", "e.g. 10 max").arg(QString::number(status.connections_limit)) + ")");
const qreal ratio = QBtSession::instance()->getRealRatio(status);
data.add(KEY_PROP_RATIO, ratio > 100. ? QString::fromUtf8("") : misc::accurateDoubleToString(ratio, 1));
data[KEY_PROP_RATIO] = ratio > 100. ? QString::fromUtf8("") : misc::accurateDoubleToString(ratio, 1);
} catch(const std::exception& e) {
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
return QString();
return QByteArray();
}
return data.toString();
return json::toJson(data);
}
/**
@ -330,38 +328,38 @@ QString btjson::getPropertiesForTorrent(const QString& hash) @@ -330,38 +328,38 @@ QString btjson::getPropertiesForTorrent(const QString& hash)
* - "priority": File priority
* - "is_seed": Flag indicating if torrent is seeding/complete
*/
QString btjson::getFilesForTorrent(const QString& hash)
QByteArray btjson::getFilesForTorrent(const QString& hash)
{
CACHED_VARIABLE_FOR_HASH(JsonList, file_list, CACHE_DURATION_MS, hash);
CACHED_VARIABLE_FOR_HASH(QVariantList, file_list, CACHE_DURATION_MS, hash);
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (!h.has_metadata())
return QString();
return QByteArray();
const std::vector<int> priorities = h.file_priorities();
std::vector<size_type> fp;
h.file_progress(fp);
for (int i = 0; i < h.num_files(); ++i) {
JsonDict file_dict;
QVariantMap file_dict;
QString fileName = h.filename_at(i);
if (fileName.endsWith(".!qB", Qt::CaseInsensitive))
fileName.chop(4);
file_dict.add(KEY_FILE_NAME, fsutils::toNativePath(fileName));
file_dict[KEY_FILE_NAME] = fsutils::toNativePath(fileName);
const size_type size = h.filesize_at(i);
file_dict.add(KEY_FILE_SIZE, misc::friendlyUnit(size));
file_dict.add(KEY_FILE_PROGRESS, (size > 0) ? (fp[i] / (double) size) : 1.);
file_dict.add(KEY_FILE_PRIORITY, priorities[i]);
file_dict[KEY_FILE_SIZE] = misc::friendlyUnit(size);
file_dict[KEY_FILE_PROGRESS] = (size > 0) ? (fp[i] / (double) size) : 1.;
file_dict[KEY_FILE_PRIORITY] = priorities[i];
if (i == 0)
file_dict.add(KEY_FILE_IS_SEED, h.is_seed());
file_dict[KEY_FILE_IS_SEED] = h.is_seed();
file_list.append(file_dict);
}
} catch (const std::exception& e) {
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
return QString();
return QByteArray();
}
return file_list.toString();
return json::toJson(file_list);
}
/**
@ -372,11 +370,11 @@ QString btjson::getFilesForTorrent(const QString& hash) @@ -372,11 +370,11 @@ QString btjson::getFilesForTorrent(const QString& hash)
* - "dl_info": Global download info
* - "up_info": Global upload info
*/
QString btjson::getTransferInfo()
QByteArray btjson::getTransferInfo()
{
CACHED_VARIABLE(JsonDict, info, CACHE_DURATION_MS);
CACHED_VARIABLE(QVariantMap, info, CACHE_DURATION_MS);
session_status sessionStatus = QBtSession::instance()->getSessionStatus();
info.add(KEY_TRANSFER_DLSPEED, tr("D: %1/s - T: %2", "Download speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_download_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_download)));
info.add(KEY_TRANSFER_UPSPEED, tr("U: %1/s - T: %2", "Upload speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_upload_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_upload)));
return info.toString();
info[KEY_TRANSFER_DLSPEED] = tr("D: %1/s - T: %2", "Download speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_download_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_download));
info[KEY_TRANSFER_UPSPEED] = tr("U: %1/s - T: %2", "Upload speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_upload_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_upload));
return json::toJson(info);
}

10
src/webui/btjson.h

@ -41,11 +41,11 @@ private: @@ -41,11 +41,11 @@ private:
btjson() {}
public:
static QString getTorrents();
static QString getTrackersForTorrent(const QString& hash);
static QString getPropertiesForTorrent(const QString& hash);
static QString getFilesForTorrent(const QString& hash);
static QString getTransferInfo();
static QByteArray getTorrents();
static QByteArray getTrackersForTorrent(const QString& hash);
static QByteArray getPropertiesForTorrent(const QString& hash);
static QByteArray getFilesForTorrent(const QString& hash);
static QByteArray getTransferInfo();
}; // class btjson
#endif // BTJSON_H

66
src/webui/jsonutils.h

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : glassez@yandex.ru
*/
#ifndef JSONUTILS_H
#define JSONUTILS_H
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#else
#include <QString>
#include "qjson/parser.h"
#include "qjson/serializer.h"
#endif
namespace json {
inline QByteArray toJson(const QVariant& var)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return QJsonDocument::fromVariant(var).toJson();
#else
return QJson::Serializer().serialize(var);
#endif
}
inline QVariant fromJson(const QString& json)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return QJsonDocument::fromJson(json.toUtf8()).toVariant();
#else
return QJson::Parser().parse(json.toUtf8());
#endif
}
}
#endif // JSONUTILS_H

153
src/webui/prefjson.cpp

@ -29,9 +29,7 @@ @@ -29,9 +29,7 @@
*/
#include "prefjson.h"
#include "jsondict.h"
#include "preferences.h"
#include "json.h"
#include "qbtsession.h"
#include "scannedfoldersmodel.h"
@ -41,110 +39,111 @@ @@ -41,110 +39,111 @@
#include <QSslKey>
#endif
#include <QTranslator>
#include "jsonutils.h"
prefjson::prefjson()
{
}
QString prefjson::getPreferences()
QByteArray prefjson::getPreferences()
{
const Preferences pref;
JsonDict data;
QVariantMap data;
// UI
data.add("locale", pref.getLocale());
data["locale"] = pref.getLocale();
// Downloads
data.add("save_path", fsutils::toNativePath(pref.getSavePath()));
data.add("temp_path_enabled", pref.isTempPathEnabled());
data.add("temp_path", fsutils::toNativePath(pref.getTempPath()));
QStringList l;
data["save_path"] = fsutils::toNativePath(pref.getSavePath());
data["temp_path_enabled"] = pref.isTempPathEnabled();
data["temp_path"] = fsutils::toNativePath(pref.getTempPath());
QVariantList l;
foreach (const QString& s, pref.getScanDirs()) {
l << fsutils::toNativePath(s);
}
data.add("scan_dirs", l);
data["scan_dirs"] = l;
QVariantList var_list;
foreach (bool b, pref.getDownloadInScanDirs()) {
var_list << b;
}
data.add("download_in_scan_dirs", var_list);
data.add("export_dir_enabled", pref.isTorrentExportEnabled());
data.add("export_dir", fsutils::toNativePath(pref.getTorrentExportDir()));
data.add("mail_notification_enabled", pref.isMailNotificationEnabled());
data.add("mail_notification_email", pref.getMailNotificationEmail());
data.add("mail_notification_smtp", pref.getMailNotificationSMTP());
data.add("mail_notification_ssl_enabled", pref.getMailNotificationSMTPSSL());
data.add("mail_notification_auth_enabled", pref.getMailNotificationSMTPAuth());
data.add("mail_notification_username", pref.getMailNotificationSMTPUsername());
data.add("mail_notification_password", pref.getMailNotificationSMTPPassword());
data.add("autorun_enabled", pref.isAutoRunEnabled());
data.add("autorun_program", fsutils::toNativePath(pref.getAutoRunProgram()));
data.add("preallocate_all", pref.preAllocateAllFiles());
data.add("queueing_enabled", pref.isQueueingSystemEnabled());
data.add("max_active_downloads", pref.getMaxActiveDownloads());
data.add("max_active_torrents", pref.getMaxActiveTorrents());
data.add("max_active_uploads", pref.getMaxActiveUploads());
data.add("dont_count_slow_torrents", pref.ignoreSlowTorrentsForQueueing());
data.add("incomplete_files_ext", pref.useIncompleteFilesExtension());
data["download_in_scan_dirs"] = var_list;
data["export_dir_enabled"] = pref.isTorrentExportEnabled();
data["export_dir"] = fsutils::toNativePath(pref.getTorrentExportDir());
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();
data["autorun_enabled"] = pref.isAutoRunEnabled();
data["autorun_program"] = fsutils::toNativePath(pref.getAutoRunProgram());
data["preallocate_all"] = pref.preAllocateAllFiles();
data["queueing_enabled"] = pref.isQueueingSystemEnabled();
data["max_active_downloads"] = pref.getMaxActiveDownloads();
data["max_active_torrents"] = pref.getMaxActiveTorrents();
data["max_active_uploads"] = pref.getMaxActiveUploads();
data["dont_count_slow_torrents"] = pref.ignoreSlowTorrentsForQueueing();
data["incomplete_files_ext"] = pref.useIncompleteFilesExtension();
// Connection
data.add("listen_port", pref.getSessionPort());
data.add("upnp", pref.isUPnPEnabled());
data.add("dl_limit", pref.getGlobalDownloadLimit());
data.add("up_limit", pref.getGlobalUploadLimit());
data.add("max_connec", pref.getMaxConnecs());
data.add("max_connec_per_torrent", pref.getMaxConnecsPerTorrent());
data.add("max_uploads_per_torrent", pref.getMaxUploadsPerTorrent());
data.add("enable_utp", pref.isuTPEnabled());
data.add("limit_utp_rate", pref.isuTPRateLimited());
data.add("limit_tcp_overhead", pref.includeOverheadInLimits());
data.add("alt_dl_limit", pref.getAltGlobalDownloadLimit());
data.add("alt_up_limit", pref.getAltGlobalUploadLimit());
data.add("scheduler_enabled", pref.isSchedulerEnabled());
data["listen_port"] = pref.getSessionPort();
data["upnp"] = pref.isUPnPEnabled();
data["dl_limit"] = pref.getGlobalDownloadLimit();
data["up_limit"] = pref.getGlobalUploadLimit();
data["max_connec"] = pref.getMaxConnecs();
data["max_connec_per_torrent"] = pref.getMaxConnecsPerTorrent();
data["max_uploads_per_torrent"] = pref.getMaxUploadsPerTorrent();
data["enable_utp"] = pref.isuTPEnabled();
data["limit_utp_rate"] = pref.isuTPRateLimited();
data["limit_tcp_overhead"] = pref.includeOverheadInLimits();
data["alt_dl_limit"] = pref.getAltGlobalDownloadLimit();
data["alt_up_limit"] = pref.getAltGlobalUploadLimit();
data["scheduler_enabled"] = pref.isSchedulerEnabled();
const QTime start_time = pref.getSchedulerStartTime();
data.add("schedule_from_hour", start_time.hour());
data.add("schedule_from_min", start_time.minute());
data["schedule_from_hour"] = start_time.hour();
data["schedule_from_min"] = start_time.minute();
const QTime end_time = pref.getSchedulerEndTime();
data.add("schedule_to_hour", end_time.hour());
data.add("schedule_to_min", end_time.minute());
data.add("scheduler_days", pref.getSchedulerDays());
data["schedule_to_hour"] = end_time.hour();
data["schedule_to_min"] = end_time.minute();
data["scheduler_days"] = pref.getSchedulerDays();
// Bittorrent
data.add("dht", pref.isDHTEnabled());
data.add("dhtSameAsBT", pref.isDHTPortSameAsBT());
data.add("dht_port", pref.getDHTPort());
data.add("pex", pref.isPeXEnabled());
data.add("lsd", pref.isLSDEnabled());
data.add("encryption", pref.getEncryptionSetting());
data.add("anonymous_mode", pref.isAnonymousModeEnabled());
data["dht"] = pref.isDHTEnabled();
data["dhtSameAsBT"] = pref.isDHTPortSameAsBT();
data["dht_port"] = pref.getDHTPort();
data["pex"] = pref.isPeXEnabled();
data["lsd"] = pref.isLSDEnabled();
data["encryption"] = pref.getEncryptionSetting();
data["anonymous_mode"] = pref.isAnonymousModeEnabled();
// Proxy
data.add("proxy_type", pref.getProxyType());
data.add("proxy_ip", pref.getProxyIp());
data.add("proxy_port", pref.getProxyPort());
data.add("proxy_peer_connections", pref.proxyPeerConnections());
data.add("proxy_auth_enabled", pref.isProxyAuthEnabled());
data.add("proxy_username", pref.getProxyUsername());
data.add("proxy_password", pref.getProxyPassword());
data["proxy_type"] = pref.getProxyType();
data["proxy_ip"] = pref.getProxyIp();
data["proxy_port"] = pref.getProxyPort();
data["proxy_peer_connections"] = pref.proxyPeerConnections();
data["proxy_auth_enabled"] = pref.isProxyAuthEnabled();
data["proxy_username"] = pref.getProxyUsername();
data["proxy_password"] = pref.getProxyPassword();
// IP Filter
data.add("ip_filter_enabled", pref.isFilteringEnabled());
data.add("ip_filter_path", fsutils::toNativePath(pref.getFilter()));
data["ip_filter_enabled"] = pref.isFilteringEnabled();
data["ip_filter_path"] = fsutils::toNativePath(pref.getFilter());
// Web UI
data.add("web_ui_port", pref.getWebUiPort());
data.add("web_ui_username", pref.getWebUiUsername());
data.add("web_ui_password", pref.getWebUiPassword());
data.add("bypass_local_auth", !pref.isWebUiLocalAuthEnabled());
data.add("use_https", pref.isWebUiHttpsEnabled());
data.add("ssl_key", QString::fromLatin1(pref.getWebUiHttpsKey()));
data.add("ssl_cert", QString::fromLatin1(pref.getWebUiHttpsCertificate()));
data["web_ui_port"] = pref.getWebUiPort();
data["web_ui_username"] = pref.getWebUiUsername();
data["web_ui_password"] = pref.getWebUiPassword();
data["bypass_local_auth"] = !pref.isWebUiLocalAuthEnabled();
data["use_https"] = pref.isWebUiHttpsEnabled();
data["ssl_key"] = QString::fromLatin1(pref.getWebUiHttpsKey());
data["ssl_cert"] = QString::fromLatin1(pref.getWebUiHttpsCertificate());
// DynDns
data.add("dyndns_enabled", pref.isDynDNSEnabled());
data.add("dyndns_service", pref.getDynDNSService());
data.add("dyndns_username", pref.getDynDNSUsername());
data.add("dyndns_password", pref.getDynDNSPassword());
data.add("dyndns_domain", pref.getDynDomainName());
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();
return data.toString();
return json::toJson(data);
}
void prefjson::setPreferences(const QString& json)
{
const QVariantMap m = json::fromJson(json);
const QVariantMap m = json::fromJson(json).toMap();
// UI
Preferences pref;

2
src/webui/prefjson.h

@ -39,7 +39,7 @@ private: @@ -39,7 +39,7 @@ private:
prefjson();
public:
static QString getPreferences();
static QByteArray getPreferences();
static void setPreferences(const QString& json);
};

Loading…
Cancel
Save