From 66b86888fc1328619480c4dac38e0fb1512ed576 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 14 Aug 2017 19:44:56 +0800 Subject: [PATCH 1/3] Add uploadLimit, downloadLimit fields to AddTorrentData & AddTorrentParams --- src/base/bittorrent/addtorrentparams.h | 2 ++ src/base/bittorrent/session.cpp | 2 ++ src/base/bittorrent/torrenthandle.cpp | 4 ++++ src/base/bittorrent/torrenthandle.h | 2 ++ 4 files changed, 10 insertions(+) diff --git a/src/base/bittorrent/addtorrentparams.h b/src/base/bittorrent/addtorrentparams.h index 6976746f5..280849abd 100644 --- a/src/base/bittorrent/addtorrentparams.h +++ b/src/base/bittorrent/addtorrentparams.h @@ -52,5 +52,7 @@ namespace BitTorrent bool skipChecking = false; TriStateBool createSubfolder; TriStateBool useAutoTMM; + int uploadLimit = -1; + int downloadLimit = -1; }; } diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index c00dadfc3..52ce82819 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2193,6 +2193,8 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri p.max_connections = maxConnectionsPerTorrent(); p.max_uploads = maxUploadsPerTorrent(); p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); + p.upload_limit = addData.uploadLimit; + p.download_limit = addData.downloadLimit; m_addingTorrents.insert(hash, addData); // Adding torrent to BitTorrent session diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 9f3f4a4d4..eefc7d5d9 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -95,6 +95,8 @@ AddTorrentData::AddTorrentData() , hasRootFolder(true) , addForced(false) , addPaused(false) + , uploadLimit(-1) + , downloadLimit(-1) , ratioLimit(TorrentHandle::USE_GLOBAL_RATIO) , seedingTimeLimit(TorrentHandle::USE_GLOBAL_SEEDING_TIME) { @@ -118,6 +120,8 @@ AddTorrentData::AddTorrentData(const AddTorrentParams ¶ms) , addPaused(params.addPaused == TriStateBool::Undefined ? Session::instance()->isAddTorrentPaused() : params.addPaused == TriStateBool::True) + , uploadLimit(params.uploadLimit) + , downloadLimit(params.downloadLimit) , filePriorities(params.filePriorities) , ratioLimit(params.ignoreShareLimits ? TorrentHandle::NO_RATIO_LIMIT : TorrentHandle::USE_GLOBAL_RATIO) , seedingTimeLimit(params.ignoreShareLimits ? TorrentHandle::NO_SEEDING_TIME_LIMIT : TorrentHandle::USE_GLOBAL_SEEDING_TIME) diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 167fec71d..d6dbbb56b 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -104,6 +104,8 @@ namespace BitTorrent bool hasRootFolder; bool addForced; bool addPaused; + int uploadLimit; + int downloadLimit; // for new torrents QVector filePriorities; // for resumed torrents From f350977cb485345d4ebe9f752587fe617c629c24 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 21 Sep 2017 20:43:19 +0800 Subject: [PATCH 2/3] WebUI: add optional parameters for /command/download & /command/upload Specifically: torrent name: string download limit, upload limit: number in bytes, default: -1 (unlimited) sequential download, first last piece prio: boolean true/false, default: false --- src/webui/extra_translations.h | 9 ++++++--- src/webui/webapplication.cpp | 20 ++++++++++++++++++++ src/webui/www/public/download.html | 21 +++++++++++++++++++++ src/webui/www/public/upload.html | 22 +++++++++++++++++++++- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/webui/extra_translations.h b/src/webui/extra_translations.h index 7048c085f..d5bf319fa 100644 --- a/src/webui/extra_translations.h +++ b/src/webui/extra_translations.h @@ -73,9 +73,12 @@ static const char *__TRANSLATIONS__[] = { QT_TRANSLATE_NOOP("HttpServer", "Invalid category name:\nPlease do not use any special characters in the category name."), QT_TRANSLATE_NOOP("HttpServer", "Unknown"), QT_TRANSLATE_NOOP("HttpServer", "Hard Disk"), - QT_TRANSLATE_NOOP("HttpServer", "Share ratio limit must be between 0 and 9998.") - QT_TRANSLATE_NOOP("HttpServer", "Seeding time limit must be between 0 and 525600 minutes.") - QT_TRANSLATE_NOOP("HttpServer", "Set location") + QT_TRANSLATE_NOOP("HttpServer", "Share ratio limit must be between 0 and 9998."), + QT_TRANSLATE_NOOP("HttpServer", "Seeding time limit must be between 0 and 525600 minutes."), + QT_TRANSLATE_NOOP("HttpServer", "Set location"), + QT_TRANSLATE_NOOP("HttpServer", "Limit upload rate"), + QT_TRANSLATE_NOOP("HttpServer", "Limit download rate"), + QT_TRANSLATE_NOOP("HttpServer", "Rename torrent") }; static const struct { const char *source; const char *comment; } __COMMENTED_TRANSLATIONS__[] = { diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 9923e991a..f305c76c5 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -414,11 +414,16 @@ void WebApplication::action_command_download() const QString urls = request().posts.value("urls"); const bool skipChecking = parseBool(request().posts.value("skip_checking"), false); + const bool seqDownload = parseBool(request().posts.value("sequentialDownload"), false); + const bool firstLastPiece = parseBool(request().posts.value("firstLastPiecePrio"), false); const TriStateBool addPaused = parseTristatebool(request().posts.value("paused")); const TriStateBool rootFolder = parseTristatebool(request().posts.value("root_folder")); const QString savepath = request().posts.value("savepath").trimmed(); const QString category = request().posts.value("category").trimmed(); const QString cookie = request().posts.value("cookie"); + const QString torrentName = request().posts.value("rename").trimmed(); + const int upLimit = request().posts.value("upLimit").toInt(); + const int dlLimit = request().posts.value("dlLimit").toInt(); QList cookies; if (!cookie.isEmpty()) { @@ -437,10 +442,15 @@ void WebApplication::action_command_download() BitTorrent::AddTorrentParams params; // TODO: Check if destination actually exists params.skipChecking = skipChecking; + params.sequential = seqDownload; + params.firstLastPiecePriority = firstLastPiece; params.addPaused = addPaused; params.createSubfolder = rootFolder; params.savePath = savepath; params.category = category; + params.name = torrentName; + params.uploadLimit = (upLimit > 0) ? upLimit : -1; + params.downloadLimit = (dlLimit > 0) ? dlLimit : -1; bool partialSuccess = false; for (QString url : urls.split('\n')) { @@ -462,10 +472,15 @@ void WebApplication::action_command_upload() CHECK_URI(0); const bool skipChecking = parseBool(request().posts.value("skip_checking"), false); + const bool seqDownload = parseBool(request().posts.value("sequentialDownload"), false); + const bool firstLastPiece = parseBool(request().posts.value("firstLastPiecePrio"), false); const TriStateBool addPaused = parseTristatebool(request().posts.value("paused")); const TriStateBool rootFolder = parseTristatebool(request().posts.value("root_folder")); const QString savepath = request().posts.value("savepath").trimmed(); const QString category = request().posts.value("category").trimmed(); + const QString torrentName = request().posts.value("rename").trimmed(); + const int upLimit = request().posts.value("upLimit").toInt(); + const int dlLimit = request().posts.value("dlLimit").toInt(); for (const Http::UploadedFile &torrent : request().files) { const QString filePath = saveTmpFile(torrent.data); @@ -485,10 +500,15 @@ void WebApplication::action_command_upload() BitTorrent::AddTorrentParams params; // TODO: Check if destination actually exists params.skipChecking = skipChecking; + params.sequential = seqDownload; + params.firstLastPiecePriority = firstLastPiece; params.addPaused = addPaused; params.createSubfolder = rootFolder; params.savePath = savepath; params.category = category; + params.name = torrentName; + params.uploadLimit = (upLimit > 0) ? upLimit : -1; + params.downloadLimit = (dlLimit > 0) ? dlLimit : -1; if (!BitTorrent::Session::instance()->addTorrent(torrentInfo, params)) { status(500, "Internal Server Error"); diff --git a/src/webui/www/public/download.html b/src/webui/www/public/download.html index 2f2d3be65..267c89253 100644 --- a/src/webui/www/public/download.html +++ b/src/webui/www/public/download.html @@ -25,6 +25,10 @@ +
+ + +
@@ -42,6 +46,23 @@
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
diff --git a/src/webui/www/public/upload.html b/src/webui/www/public/upload.html index 4dd86ce27..c689fbaf1 100644 --- a/src/webui/www/public/upload.html +++ b/src/webui/www/public/upload.html @@ -21,9 +21,13 @@ +
+ + +
- +
@@ -38,6 +42,22 @@
+
+ + +
+
+ + +
+
+ + +
+
+ + +
From e78d8b9fccdf656fc0f2550947831e22eb8ca5e9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 11 Oct 2017 20:27:19 +0800 Subject: [PATCH 3/3] Convert tab into whitespaces --- src/webui/www/private/login.html | 20 +++++++++--------- src/webui/www/public/addtrackers.html | 16 +++++++------- src/webui/www/public/preferences.html | 12 +++++------ src/webui/www/public/upload.html | 30 +++++++++++++-------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/webui/www/private/login.html b/src/webui/www/private/login.html index a073fb980..ba3c8f302 100644 --- a/src/webui/www/private/login.html +++ b/src/webui/www/private/login.html @@ -69,19 +69,19 @@ -
+

qBittorrent QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]

- -
-
+ +
+


- -
-
-
+ +
+
+
diff --git a/src/webui/www/public/addtrackers.html b/src/webui/www/public/addtrackers.html index c816e3f4c..c2f988571 100644 --- a/src/webui/www/public/addtrackers.html +++ b/src/webui/www/public/addtrackers.html @@ -1,11 +1,11 @@ - + QBT_TR(Trackers addition dialog)QBT_TR[CONTEXT=TrackersAdditionDlg] - - - + + + + - + + + +

-

- -
+
+ +

- +
- +
- +
@@ -68,13 +68,13 @@ var submitted = false; $('uploadForm').addEventListener("submit", function() { - $('upload_spinner').style.display = "block"; - submitted = true; + $('upload_spinner').style.display = "block"; + submitted = true; }); $('upload_frame').addEventListener("load", function() { - if (submitted) - window.parent.closeWindows(); + if (submitted) + window.parent.closeWindows(); }); $('start_torrent').addEventListener('change', function() {