From 771033a4499c56f1e4666f819f2419bec57c9c4a Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 5 Jul 2017 01:47:23 -0400 Subject: [PATCH 1/2] Add auto torrent management to webui context menu (addresses #6815) --- src/webui/btjson.cpp | 2 ++ src/webui/webapplication.cpp | 16 ++++++++++++++++ src/webui/webapplication.h | 1 + src/webui/www/private/index.html | 3 +++ src/webui/www/public/scripts/contextmenu.js | 13 +++++++++++++ src/webui/www/public/scripts/mocha-init.js | 21 +++++++++++++++++++++ src/webui/www/public/transferlist.html | 3 +++ 7 files changed, 59 insertions(+) diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index 827505fed..34bca0112 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -110,6 +110,7 @@ static const char KEY_TORRENT_RATIO_LIMIT[] = "ratio_limit"; static const char KEY_TORRENT_LAST_SEEN_COMPLETE_TIME[] = "seen_complete"; static const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity"; static const char KEY_TORRENT_TOTAL_SIZE[] = "total_size"; +static const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[] = "auto_tmm"; // Peer keys static const char KEY_PEER_IP[] = "ip"; @@ -824,6 +825,7 @@ QVariantMap toMap(BitTorrent::TorrentHandle *const torrent) ret[KEY_TORRENT_AMOUNT_COMPLETED] = torrent->completedSize(); ret[KEY_TORRENT_RATIO_LIMIT] = torrent->maxRatio(); ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent->lastSeenComplete().toTime_t(); + ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent->isAutoTMMEnabled(); if (torrent->isPaused() || torrent->isChecking()) ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0; diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index bbf6deed2..559f5abd6 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -122,6 +122,7 @@ QMap > WebApplication::initialize ADD_ACTION(command, bottomPrio); ADD_ACTION(command, setLocation); ADD_ACTION(command, rename); + ADD_ACTION(command, setAutoTMM); ADD_ACTION(command, recheck); ADD_ACTION(command, setCategory); ADD_ACTION(command, addCategory); @@ -822,6 +823,21 @@ void WebApplication::action_command_rename() } } +void WebApplication::action_command_setAutoTMM() +{ + CHECK_URI(0); + CHECK_PARAMETERS("hashes" << "enable"); + + QStringList hashes = request().posts["hashes"].split("|"); + QString enableStr = request().posts["enable"]; + + foreach (const QString &hash, hashes) { + BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); + if (torrent) + torrent->setAutoTMMEnabled(enableStr == "true"); + } +} + void WebApplication::action_command_recheck() { CHECK_URI(0); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 3f39946e6..8909268fe 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -92,6 +92,7 @@ private: void action_command_bottomPrio(); void action_command_setLocation(); void action_command_rename(); + void action_command_setAutoTMM(); void action_command_recheck(); void action_command_setCategory(); void action_command_addCategory(); diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 9cfb2cc94..95992837f 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -115,6 +115,9 @@ QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget] +
  • + QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget] +
  • QBT_TR(Priority)QBT_TR[CONTEXT=TransferListWidget]
      diff --git a/src/webui/www/public/scripts/contextmenu.js b/src/webui/www/public/scripts/contextmenu.js index 10c67bc99..9036a8afc 100644 --- a/src/webui/www/public/scripts/contextmenu.js +++ b/src/webui/www/public/scripts/contextmenu.js @@ -255,6 +255,8 @@ var TorrentsTableContextMenu = new Class({ all_are_force_start = true; there_are_force_start = false; all_are_super_seeding = true; + all_are_auto_tmm = true; + there_are_auto_tmm = false; var h = torrentsTable.selectedRowsIds(); h.each(function(item, index){ @@ -284,6 +286,11 @@ var TorrentsTableContextMenu = new Class({ all_are_force_start = false; else there_are_force_start = true; + + if (data['auto_tmm'] != true) + all_are_auto_tmm = false; + else + there_are_auto_tmm = true; }); show_seq_dl = true; @@ -336,6 +343,12 @@ var TorrentsTableContextMenu = new Class({ this.hideItem('ForceStart'); else if (!there_are_paused && !there_are_force_start) this.hideItem('Start'); + + if (!all_are_auto_tmm && there_are_auto_tmm) + this.hideItem('AutoTorrentManagement'); + else + this.setItemChecked('AutoTorrentManagement', all_are_auto_tmm); + }, updateCategoriesSubMenu : function (category_list) { diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index 0c9bb35c0..eeb9ef392 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -303,6 +303,27 @@ initializeWindows = function() { } }; + autoTorrentManagementFN = function() { + var hashes = torrentsTable.selectedRowsIds(); + if (hashes.length) { + var enable = false; + hashes.each(function(hash, index) { + var row = torrentsTable.rows[hash]; + if (!row.full_data.auto_tmm) + enable = true; + }); + new Request({ + url: 'command/setAutoTMM', + method: 'post', + data: { + hashes: hashes.join("|"), + enable: enable + } + }).send(); + updateMainData(); + } + }; + recheckFN = function() { var hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { diff --git a/src/webui/www/public/transferlist.html b/src/webui/www/public/transferlist.html index fd2f3ccc6..0d9b239d5 100644 --- a/src/webui/www/public/transferlist.html +++ b/src/webui/www/public/transferlist.html @@ -70,6 +70,9 @@ toggleFirstLastPiecePrioFN(); }, + AutoTorrentManagement : function (element, ref) { + autoTorrentManagementFN(); + }, ForceRecheck : function (element, ref) { recheckFN(); }, From 4846b0ec28a475dc36d1eb80c1a0436cec34b7ba Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Tue, 18 Jul 2017 22:06:38 -0400 Subject: [PATCH 2/2] Use single quotes for char. Use case insensitive compare. Swap conditionals --- src/webui/webapplication.cpp | 34 ++++++++++----------- src/webui/www/public/scripts/contextmenu.js | 6 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 559f5abd6..f4eb9e410 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -596,7 +596,7 @@ void WebApplication::action_command_getTorrentsUpLimit() { CHECK_URI(0); CHECK_PARAMETERS("hashes"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); print(btjson::getTorrentsRatesLimits(hashes, false), Http::CONTENT_TYPE_JSON); } @@ -604,7 +604,7 @@ void WebApplication::action_command_getTorrentsDlLimit() { CHECK_URI(0); CHECK_PARAMETERS("hashes"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); print(btjson::getTorrentsRatesLimits(hashes, true), Http::CONTENT_TYPE_JSON); } @@ -617,7 +617,7 @@ void WebApplication::action_command_setTorrentsUpLimit() if (limit == 0) limit = -1; - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) @@ -634,7 +634,7 @@ void WebApplication::action_command_setTorrentsDlLimit() if (limit == 0) limit = -1; - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) @@ -660,7 +660,7 @@ void WebApplication::action_command_toggleSequentialDownload() { CHECK_URI(0); CHECK_PARAMETERS("hashes"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) @@ -672,7 +672,7 @@ void WebApplication::action_command_toggleFirstLastPiecePrio() { CHECK_URI(0); CHECK_PARAMETERS("hashes"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) @@ -685,7 +685,7 @@ void WebApplication::action_command_setSuperSeeding() CHECK_URI(0); CHECK_PARAMETERS("hashes" << "value"); bool value = request().posts["value"] == "true"; - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) @@ -698,7 +698,7 @@ void WebApplication::action_command_setForceStart() CHECK_URI(0); CHECK_PARAMETERS("hashes" << "value"); bool value = request().posts["value"] == "true"; - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) @@ -710,7 +710,7 @@ void WebApplication::action_command_delete() { CHECK_URI(0); CHECK_PARAMETERS("hashes"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) BitTorrent::Session::instance()->deleteTorrent(hash, false); } @@ -719,7 +719,7 @@ void WebApplication::action_command_deletePerm() { CHECK_URI(0); CHECK_PARAMETERS("hashes"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); foreach (const QString &hash, hashes) BitTorrent::Session::instance()->deleteTorrent(hash, true); } @@ -734,7 +734,7 @@ void WebApplication::action_command_increasePrio() return; } - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); BitTorrent::Session::instance()->increaseTorrentsPriority(hashes); } @@ -748,7 +748,7 @@ void WebApplication::action_command_decreasePrio() return; } - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); BitTorrent::Session::instance()->decreaseTorrentsPriority(hashes); } @@ -762,7 +762,7 @@ void WebApplication::action_command_topPrio() return; } - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); BitTorrent::Session::instance()->topTorrentsPriority(hashes); } @@ -776,7 +776,7 @@ void WebApplication::action_command_bottomPrio() return; } - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); BitTorrent::Session::instance()->bottomTorrentsPriority(hashes); } @@ -828,13 +828,13 @@ void WebApplication::action_command_setAutoTMM() CHECK_URI(0); CHECK_PARAMETERS("hashes" << "enable"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); QString enableStr = request().posts["enable"]; foreach (const QString &hash, hashes) { BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); if (torrent) - torrent->setAutoTMMEnabled(enableStr == "true"); + torrent->setAutoTMMEnabled(QString::compare(enableStr, "true", Qt::CaseInsensitive) == 0); } } @@ -853,7 +853,7 @@ void WebApplication::action_command_setCategory() CHECK_URI(0); CHECK_PARAMETERS("hashes" << "category"); - QStringList hashes = request().posts["hashes"].split("|"); + QStringList hashes = request().posts["hashes"].split('|'); QString category = request().posts["category"].trimmed(); foreach (const QString &hash, hashes) { diff --git a/src/webui/www/public/scripts/contextmenu.js b/src/webui/www/public/scripts/contextmenu.js index 9036a8afc..f8f559f61 100644 --- a/src/webui/www/public/scripts/contextmenu.js +++ b/src/webui/www/public/scripts/contextmenu.js @@ -287,10 +287,10 @@ var TorrentsTableContextMenu = new Class({ else there_are_force_start = true; - if (data['auto_tmm'] != true) - all_are_auto_tmm = false; - else + if (data['auto_tmm'] === true) there_are_auto_tmm = true; + else + all_are_auto_tmm = false; }); show_seq_dl = true;