Browse Source

Add auto torrent management to webui context menu (addresses #6815)

adaptive-webui-19844
Thomas Piccirello 7 years ago committed by Chocobo1
parent
commit
771033a449
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 2
      src/webui/btjson.cpp
  2. 16
      src/webui/webapplication.cpp
  3. 1
      src/webui/webapplication.h
  4. 3
      src/webui/www/private/index.html
  5. 13
      src/webui/www/public/scripts/contextmenu.js
  6. 21
      src/webui/www/public/scripts/mocha-init.js
  7. 3
      src/webui/www/public/transferlist.html

2
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_SEEN_COMPLETE_TIME[] = "seen_complete";
static const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity"; static const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity";
static const char KEY_TORRENT_TOTAL_SIZE[] = "total_size"; static const char KEY_TORRENT_TOTAL_SIZE[] = "total_size";
static const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[] = "auto_tmm";
// Peer keys // Peer keys
static const char KEY_PEER_IP[] = "ip"; 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_AMOUNT_COMPLETED] = torrent->completedSize();
ret[KEY_TORRENT_RATIO_LIMIT] = torrent->maxRatio(); ret[KEY_TORRENT_RATIO_LIMIT] = torrent->maxRatio();
ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent->lastSeenComplete().toTime_t(); ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent->lastSeenComplete().toTime_t();
ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent->isAutoTMMEnabled();
if (torrent->isPaused() || torrent->isChecking()) if (torrent->isPaused() || torrent->isChecking())
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0; ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0;

16
src/webui/webapplication.cpp

@ -122,6 +122,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, bottomPrio); ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, setLocation); ADD_ACTION(command, setLocation);
ADD_ACTION(command, rename); ADD_ACTION(command, rename);
ADD_ACTION(command, setAutoTMM);
ADD_ACTION(command, recheck); ADD_ACTION(command, recheck);
ADD_ACTION(command, setCategory); ADD_ACTION(command, setCategory);
ADD_ACTION(command, addCategory); 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() void WebApplication::action_command_recheck()
{ {
CHECK_URI(0); CHECK_URI(0);

1
src/webui/webapplication.h

@ -92,6 +92,7 @@ private:
void action_command_bottomPrio(); void action_command_bottomPrio();
void action_command_setLocation(); void action_command_setLocation();
void action_command_rename(); void action_command_rename();
void action_command_setAutoTMM();
void action_command_recheck(); void action_command_recheck();
void action_command_setCategory(); void action_command_setCategory();
void action_command_addCategory(); void action_command_addCategory();

3
src/webui/www/private/index.html

@ -115,6 +115,9 @@
<a href="#Category" class="arrow-right"><img src="theme/view-categories" alt="QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]</a> <a href="#Category" class="arrow-right"><img src="theme/view-categories" alt="QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]</a>
<ul id="contextCategoryList" class="scrollableMenu"></ul> <ul id="contextCategoryList" class="scrollableMenu"></ul>
</li> </li>
<li>
<a href="#AutoTorrentManagement"><img src="theme/checked" alt="QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget]</a>
</li>
<li id="queueingMenuItems" class="separator"> <li id="queueingMenuItems" class="separator">
<a href="#priority" class="arrow-right"><span style="display: inline-block; width:16px"></span> QBT_TR(Priority)QBT_TR[CONTEXT=TransferListWidget]</a> <a href="#priority" class="arrow-right"><span style="display: inline-block; width:16px"></span> QBT_TR(Priority)QBT_TR[CONTEXT=TransferListWidget]</a>
<ul> <ul>

13
src/webui/www/public/scripts/contextmenu.js

@ -255,6 +255,8 @@ var TorrentsTableContextMenu = new Class({
all_are_force_start = true; all_are_force_start = true;
there_are_force_start = false; there_are_force_start = false;
all_are_super_seeding = true; all_are_super_seeding = true;
all_are_auto_tmm = true;
there_are_auto_tmm = false;
var h = torrentsTable.selectedRowsIds(); var h = torrentsTable.selectedRowsIds();
h.each(function(item, index){ h.each(function(item, index){
@ -284,6 +286,11 @@ var TorrentsTableContextMenu = new Class({
all_are_force_start = false; all_are_force_start = false;
else else
there_are_force_start = true; 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; show_seq_dl = true;
@ -336,6 +343,12 @@ var TorrentsTableContextMenu = new Class({
this.hideItem('ForceStart'); this.hideItem('ForceStart');
else if (!there_are_paused && !there_are_force_start) else if (!there_are_paused && !there_are_force_start)
this.hideItem('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) { updateCategoriesSubMenu : function (category_list) {

21
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() { recheckFN = function() {
var hashes = torrentsTable.selectedRowsIds(); var hashes = torrentsTable.selectedRowsIds();
if (hashes.length) { if (hashes.length) {

3
src/webui/www/public/transferlist.html

@ -70,6 +70,9 @@
toggleFirstLastPiecePrioFN(); toggleFirstLastPiecePrioFN();
}, },
AutoTorrentManagement : function (element, ref) {
autoTorrentManagementFN();
},
ForceRecheck : function (element, ref) { ForceRecheck : function (element, ref) {
recheckFN(); recheckFN();
}, },

Loading…
Cancel
Save