From 54a444d37f10499b7f304805439f5ef0991b0ce0 Mon Sep 17 00:00:00 2001 From: ngosang Date: Fri, 12 Jun 2015 17:52:01 +0200 Subject: [PATCH] [Web UI] Add Web Seeds (HTTP Sources) tab --- src/webui/btjson.cpp | 28 +++++ src/webui/btjson.h | 1 + src/webui/webapplication.cpp | 7 ++ src/webui/webapplication.h | 1 + src/webui/webui.qrc | 1 + src/webui/www/public/css/style.css | 2 +- src/webui/www/public/properties.html | 1 + src/webui/www/public/properties_content.html | 13 +++ src/webui/www/public/scripts/client.js | 15 ++- src/webui/www/public/scripts/prop-webseeds.js | 108 ++++++++++++++++++ 10 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 src/webui/www/public/scripts/prop-webseeds.js diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index d74f97033..b19959a31 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -111,6 +111,9 @@ static const char KEY_TRACKER_STATUS[] = "status"; static const char KEY_TRACKER_MSG[] = "msg"; static const char KEY_TRACKER_PEERS[] = "num_peers"; +// Web seed keys +static const char KEY_WEBSEED_URL[] = "url"; + // Torrent keys (Properties) static const char KEY_PROP_SAVE_PATH[] = "save_path"; static const char KEY_PROP_CREATION_DATE[] = "creation_date"; @@ -395,6 +398,31 @@ QByteArray btjson::getTrackersForTorrent(const QString& hash) return json::toJson(tracker_list); } +/** + * Returns the web seeds for a torrent in JSON format. + * + * The return value is a JSON-formatted list of dictionaries. + * The dictionary keys are: + * - "url": Web seed URL + */ +QByteArray btjson::getWebSeedsForTorrent(const QString& hash) +{ + CACHED_VARIABLE_FOR_HASH(QVariantList, webSeedList, CACHE_DURATION_MS, hash); + QTorrentHandle torrent = QBtSession::instance()->getTorrentHandle(hash); + if (!torrent.is_valid()) { + qWarning() << Q_FUNC_INFO << "Invalid torrent " << qPrintable(hash); + return QByteArray(); + } + + foreach (const QString &webseed, torrent.url_seeds()) { + QVariantMap webSeedDict; + webSeedDict[KEY_WEBSEED_URL] = webseed; + webSeedList.append(webSeedDict); + } + + return json::toJson(webSeedList); +} + /** * Returns the properties for a torrent in JSON format. * diff --git a/src/webui/btjson.h b/src/webui/btjson.h index fb9faf434..b033d1b56 100644 --- a/src/webui/btjson.h +++ b/src/webui/btjson.h @@ -49,6 +49,7 @@ public: QString sortedColumn = "name", bool reverse = false, int limit = 0, int offset = 0); static QByteArray getSyncMainData(int acceptedResponseId, QVariantMap &lastData, QVariantMap &lastAcceptedData); static QByteArray getTrackersForTorrent(const QString& hash); + static QByteArray getWebSeedsForTorrent(const QString& hash); static QByteArray getPropertiesForTorrent(const QString& hash); static QByteArray getFilesForTorrent(const QString& hash); static QByteArray getTransferInfo(); diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index adddbf0ec..14f6136ea 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -78,6 +78,7 @@ QMap > WebApplication::initialize ADD_ACTION(query, transferInfo); ADD_ACTION(query, propertiesGeneral); ADD_ACTION(query, propertiesTrackers); + ADD_ACTION(query, propertiesWebSeeds); ADD_ACTION(query, propertiesFiles); ADD_ACTION(sync, maindata); ADD_ACTION(command, shutdown); @@ -255,6 +256,12 @@ void WebApplication::action_query_propertiesTrackers() print(btjson::getTrackersForTorrent(args_.front()), Http::CONTENT_TYPE_JS); } +void WebApplication::action_query_propertiesWebSeeds() +{ + CHECK_URI(1); + print(btjson::getWebSeedsForTorrent(args_.front()), Http::CONTENT_TYPE_JS); +} + void WebApplication::action_query_propertiesFiles() { CHECK_URI(1); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index fad03f724..e4bef1ab1 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -52,6 +52,7 @@ private: void action_query_transferInfo(); void action_query_propertiesGeneral(); void action_query_propertiesTrackers(); + void action_query_propertiesWebSeeds(); void action_query_propertiesFiles(); void action_sync_maindata(); void action_command_shutdown(); diff --git a/src/webui/webui.qrc b/src/webui/webui.qrc index db5f1c413..c77d04bdc 100644 --- a/src/webui/webui.qrc +++ b/src/webui/webui.qrc @@ -33,6 +33,7 @@ www/public/properties_content.html www/public/scripts/prop-general.js www/public/scripts/prop-trackers.js + www/public/scripts/prop-webseeds.js www/public/scripts/prop-files.js www/public/transferlist.html www/public/upload.html diff --git a/src/webui/www/public/css/style.css b/src/webui/www/public/css/style.css index 7d3f87f27..25f1fbb0c 100644 --- a/src/webui/www/public/css/style.css +++ b/src/webui/www/public/css/style.css @@ -362,7 +362,7 @@ ul.filterList li:hover a { line-height: 20px; } -#trackersTable { +#trackersTable, #webseedsTable { line-height: 25px; } diff --git a/src/webui/www/public/properties.html b/src/webui/www/public/properties.html index 2ffd2c784..a9c04ecf0 100644 --- a/src/webui/www/public/properties.html +++ b/src/webui/www/public/properties.html @@ -2,6 +2,7 @@
diff --git a/src/webui/www/public/properties_content.html b/src/webui/www/public/properties_content.html index 13c24fce6..435b000de 100644 --- a/src/webui/www/public/properties_content.html +++ b/src/webui/www/public/properties_content.html @@ -38,6 +38,19 @@ + +