From f6bfacda2c4195583c3e8b1a02cfd7727a39346e Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 15 Feb 2010 20:07:15 +0000 Subject: [PATCH] FEATURE: Global transfer information are displayed in the new Web UI status bar --- Changelog | 1 + src/httpconnection.cpp | 17 +++++++++++++++++ src/httpconnection.h | 1 + src/httpserver.h | 1 + src/webui/index.html | 7 +++++++ src/webui/scripts/client.js | 26 ++++++++++++++++++++++++++ 6 files changed, 53 insertions(+) diff --git a/Changelog b/Changelog index 69cdb66b8..004890769 100644 --- a/Changelog +++ b/Changelog @@ -10,6 +10,7 @@ - FEATURE: Torrents can be automatically rechecked on completion - FEATURE: If 2 torrents have the same hash, add new trackers/URL seeds to the existing torrent - FEATURE: Trackers can be added from Web UI + - FEATURE: Global transfer information are displayed in the new Web UI status bar - COSMETIC: Improved style management * Mon Jan 18 2010 - Christophe Dumez - v2.1.0 diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index 3ce963052..aa7e25f9b 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -35,6 +35,7 @@ #include "preferences.h" #include "json.h" #include "bittorrent.h" +#include "misc.h" #include #include #include @@ -203,6 +204,10 @@ void HttpConnection::respond() { } else { if(list[1] == "preferences") { respondPreferencesJson(); + } else { + if(list[1] == "transferInfo") { + respondGlobalTransferInfoJson(); + } } } } @@ -298,6 +303,18 @@ void HttpConnection::respondPreferencesJson() { write(); } +void HttpConnection::respondGlobalTransferInfoJson() { + QVariantMap info; + session_status sessionStatus = parent->getBTSession()->getSessionStatus(); + info["DlInfos"] = 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["UpInfos"] = 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)); + QString string = json::toJson(info); + generator.setStatusLine(200, "OK"); + generator.setContentTypeByExt("js"); + generator.setMessage(string); + write(); +} + void HttpConnection::respondCommand(QString command) { if(command == "download") diff --git a/src/httpconnection.h b/src/httpconnection.h index bcd4fdebe..8aceebf7f 100644 --- a/src/httpconnection.h +++ b/src/httpconnection.h @@ -60,6 +60,7 @@ class HttpConnection : public QObject void respondTrackersPropertiesJson(QString hash); void respondFilesPropertiesJson(QString hash); void respondPreferencesJson(); + void respondGlobalTransferInfoJson(); void respondCommand(QString command); void respondNotFound(); void processDownloadedFile(QString, QString); diff --git a/src/httpserver.h b/src/httpserver.h index 373708efe..6966accbf 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -60,6 +60,7 @@ class HttpServer : public QTcpServer { EventManager *eventManager() const; QString generateNonce() const; QHash client_failed_attempts; + Bittorrent *getBTSession() const { return BTSession; } private slots: void newHttpConnection(); diff --git a/src/webui/index.html b/src/webui/index.html index 26689829b..6b5e0665f 100644 --- a/src/webui/index.html +++ b/src/webui/index.html @@ -97,5 +97,12 @@
  • _(Limit upload rate)
  • _(Force recheck)
  • +
    +
    + + +
    +
    +
    diff --git a/src/webui/scripts/client.js b/src/webui/scripts/client.js index 00f6eb46c..8f719df9e 100644 --- a/src/webui/scripts/client.js +++ b/src/webui/scripts/client.js @@ -106,9 +106,34 @@ window.addEvent('load', function(){ initializeWindows(); var r=0; var waiting=false; + var waitingTrInfo = false; var stateToImg = function(state){ return 'images/skin/'+state+'.png'; + }; + var loadTransferInfo = function() { + var url = 'json/transferInfo'; + if(!waitingTrInfo) { + waitingTrInfo = true; + var request = new Request.JSON({ + url: url, + noCache: true, + method: 'get', + onFailure: function() { + $('error_div').set('html', 'qBittorrent client is not reachable'); + waitingTrInfo=false; + loadTransferInfo.delay(4000); + }, + onSuccess: function(info) { + if(info) { + $("DlInfos").set('html', info.DlInfos); + $("UpInfos").set('html', info.UpInfos); + waitingTrInfo=false; + loadTransferInfo.delay(3000); + } + } + }).send(); + } }; var ajaxfn = function(){ var queueing_enabled = false; @@ -178,6 +203,7 @@ window.addEvent('load', function(){ } }; ajaxfn(); + loadTransferInfo(); // ajaxfn.periodical(5000); setFilter = function(f) {