diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 436254b02..104449f23 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -32,6 +32,7 @@ #include "eventmanager.h" #include "bittorrent.h" #include "misc.h" +#include "preferences.h" #include "proplistdelegate.h" #include "torrentpersistentdata.h" #include @@ -118,6 +119,17 @@ QList EventManager::getPropFilesInfo(QString hash) const { return files; } +QVariantMap EventManager::getGlobalPreferences() const { + QVariantMap data; + data["dl_limit"] = Preferences::getGlobalDownloadLimit(); + data["up_limit"] = Preferences::getGlobalUploadLimit(); + data["dht"] = Preferences::isDHTEnabled(); + data["max_connec"] = Preferences::getMaxConnecs(); + data["max_connec_per_torrent"] = Preferences::getMaxConnecsPerTorrent(); + data["max_uploads_per_torrent"] = Preferences::getMaxUploadsPerTorrent(); + return data; +} + QVariantMap EventManager::getPropGeneralInfo(QString hash) const { QVariantMap data; QTorrentHandle h = BTSession->getTorrentHandle(hash); diff --git a/src/eventmanager.h b/src/eventmanager.h index d83ccc4ec..e4af282bc 100644 --- a/src/eventmanager.h +++ b/src/eventmanager.h @@ -54,6 +54,7 @@ class EventManager : public QObject QVariantMap getPropGeneralInfo(QString hash) const; QList getPropTrackersInfo(QString hash) const; QList getPropFilesInfo(QString hash) const; + QVariantMap getGlobalPreferences() const; public slots: void addedTorrent(QTorrentHandle& h); diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index 92f50aea2..b12c68b09 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -32,6 +32,7 @@ #include "httpconnection.h" #include "httpserver.h" #include "eventmanager.h" +#include "preferences.h" #include "json.h" #include "bittorrent.h" #include @@ -102,7 +103,7 @@ void HttpConnection::write() } QString HttpConnection::translateDocument(QString data) { - std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget", "PropertiesWidget", "GUI", "MainWindow", "HttpServer", "confirmDeletionDlg", "TrackerList", "TorrentFilesModel"}; + std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget", "PropertiesWidget", "GUI", "MainWindow", "HttpServer", "confirmDeletionDlg", "TrackerList", "TorrentFilesModel", "options_imp"}; int i=0; bool found = false; do { @@ -117,7 +118,7 @@ QString HttpConnection::translateDocument(QString data) { do { translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().data(), 0, QCoreApplication::UnicodeUTF8, 1); ++context_index; - }while(translation == word && context_index < 9); + }while(translation == word && context_index < 10); //qDebug("Translation is %s", translation.toUtf8().data()); data = data.replace(i, regex.matchedLength(), translation); i += translation.length(); @@ -172,6 +173,10 @@ void HttpConnection::respond() respondFilesPropertiesJson(hash); return; } + } else { + if(list[1] == "preferences") { + respondPreferencesJson(); + } } } if (list[0] == "command") @@ -254,6 +259,14 @@ void HttpConnection::respondFilesPropertiesJson(QString hash) { write(); } +void HttpConnection::respondPreferencesJson() { + EventManager* manager = parent->eventManager(); + QString string = json::toJson(manager->getGlobalPreferences()); + generator.setStatusLine(200, "OK"); + generator.setContentTypeByExt("js"); + generator.setMessage(string); + write(); +} void HttpConnection::respondCommand(QString command) { @@ -306,10 +319,43 @@ void HttpConnection::respondCommand(QString command) emit pauseAllTorrents(); return; } - if(command == "resume") { + if(command == "resume") { emit resumeTorrent(parser.post("hash")); return; } + if(command == "setPreferences") { + bool ok = false; + int dl_limit = parser.post("dl_limit").toInt(&ok); + if(ok) { + BTSession->setDownloadRateLimit(dl_limit*1024); + Preferences::setGlobalDownloadLimit(dl_limit); + } + int up_limit = parser.post("up_limit").toInt(&ok); + if(ok) { + BTSession->setUploadRateLimit(up_limit*1024); + Preferences::setGlobalUploadLimit(up_limit); + } + int dht_state = parser.post("dht").toInt(&ok); + if(ok) { + BTSession->enableDHT(dht_state == 1); + Preferences::setDHTEnabled(dht_state == 1); + } + int mac_connec = parser.post("mac_connec").toInt(&ok); + if(ok) { + BTSession->setMaxConnections(mac_connec); + Preferences::setMaxConnecs(mac_connec); + } + int max_connec_per_torrent = parser.post("mac_connec_per_torrent").toInt(&ok); + if(ok) { + BTSession->setMaxConnectionsPerTorrent(max_connec_per_torrent); + Preferences::setMaxConnecsPerTorrent(max_connec_per_torrent); + } + int max_uploads_per_torrent = parser.post("mac_uploads_per_torrent").toInt(&ok); + if(ok) { + BTSession->setMaxUploadsPerTorrent(max_uploads_per_torrent); + Preferences::setMaxUploadsPerTorrent(max_uploads_per_torrent); + } + } if(command == "setFilePrio") { QString hash = parser.post("hash"); int file_id = parser.post("id").toInt(); diff --git a/src/httpconnection.h b/src/httpconnection.h index 20fa39b0a..bcd4fdebe 100644 --- a/src/httpconnection.h +++ b/src/httpconnection.h @@ -59,6 +59,7 @@ class HttpConnection : public QObject void respondGenPropertiesJson(QString hash); void respondTrackersPropertiesJson(QString hash); void respondFilesPropertiesJson(QString hash); + void respondPreferencesJson(); void respondCommand(QString command); void respondNotFound(); void processDownloadedFile(QString, QString); diff --git a/src/preferences.h b/src/preferences.h index 25d834782..379a08659 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -33,6 +33,7 @@ #include #include +#include class Preferences { public: @@ -311,21 +312,41 @@ public: return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt(); } + static void setMaxConnecs(int val) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), val); + } + static int getMaxConnecsPerTorrent() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt(); } + static void setMaxConnecsPerTorrent(int val) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), val); + } + static int getMaxUploadsPerTorrent() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt(); } + static void setMaxUploadsPerTorrent(int val) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), val); + } + static bool isDHTEnabled() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool(); } + static void setDHTEnabled(bool enabled) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Bittorrent/DHT"), enabled); + } + static bool isDHTPortSameAsBT() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool(); diff --git a/src/webui.qrc b/src/webui.qrc index f6af6ac7f..7864dd0d2 100644 --- a/src/webui.qrc +++ b/src/webui.qrc @@ -13,6 +13,7 @@ webui/properties.html webui/uploadlimit.html webui/downloadlimit.html + webui/preferences.html webui/css/mocha.css webui/css/dynamicTable.css webui/css/style.css diff --git a/src/webui/index.html b/src/webui/index.html index 1d20051a8..0a5da4ad1 100644 --- a/src/webui/index.html +++ b/src/webui/index.html @@ -47,6 +47,12 @@
  • _(Delete from HD)
  • +
  • + _(Options) + +
  • _(Help)
      @@ -59,17 +65,18 @@
    - - - - - - - - + + + + + + + + + - - + +
    diff --git a/src/webui/scripts/mocha-init.js b/src/webui/scripts/mocha-init.js index 7a29ceabb..e37afdcb7 100644 --- a/src/webui/scripts/mocha-init.js +++ b/src/webui/scripts/mocha-init.js @@ -23,7 +23,7 @@ initializeWindows = function(){ new Event(e).stop(); new MochaUI.Window({ id: 'downloadPage', - title: "(Download from URL)", + title: "_(Download from URL)", loadMethod: 'iframe', contentURL:'download.html', scrollbars: false, @@ -37,6 +37,24 @@ initializeWindows = function(){ }); }); + addClickEvent('preferences', function(e) { + new Event(e).stop(); + new MochaUI.Window({ + id: 'preferencesPage', + title: "_(Preferences)", + loadMethod: 'iframe', + contentURL:'preferences.html', + scrollbars: false, + resizable: false, + maximizable: false, + closable: true, + paddingVertical: 0, + paddingHorizontal: 0, + width: 500, + height: 270 + }); + }); + addClickEvent('upload', function(e){ new Event(e).stop(); new MochaUI.Window({