WebUI: Implement 'Force Start' feature.

This commit is contained in:
Gabriele 2015-04-15 19:13:18 +02:00
parent 2c5edf8652
commit b5b40abb56
7 changed files with 43 additions and 0 deletions

View File

@ -103,6 +103,7 @@ static const char KEY_TORRENT_SEQUENTIAL_DOWNLOAD[] = "seq_dl";
static const char KEY_TORRENT_FIRST_LAST_PIECE_PRIO[] = "f_l_piece_prio";
static const char KEY_TORRENT_LABEL[] = "label";
static const char KEY_TORRENT_SUPER_SEEDING[] = "super_seeding";
static const char KEY_TORRENT_FORCE_START[] = "force_start";
// Tracker keys
static const char KEY_TRACKER_URL[] = "url";
@ -234,6 +235,7 @@ private:
* - "state": Torrent state
* - "seq_dl": Torrent sequential download state
* - "f_l_piece_prio": Torrent first last piece priority state
* - "force_start": Torrent force start state
*/
QByteArray btjson::getTorrents(QString filter, QString label,
QString sortedColumn, bool reverse, int limit, int offset)
@ -582,6 +584,7 @@ QVariantMap toMap(const QTorrentHandle& h)
ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = h.first_last_piece_first();
ret[KEY_TORRENT_LABEL] = TorrentPersistentData::instance()->getLabel(h.hash());
ret[KEY_TORRENT_SUPER_SEEDING] = status.super_seeding;
ret[KEY_TORRENT_FORCE_START] = h.is_forced(status);
return ret;
}

View File

@ -103,6 +103,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, toggleSequentialDownload);
ADD_ACTION(command, toggleFirstLastPiecePrio);
ADD_ACTION(command, setSuperSeeding);
ADD_ACTION(command, setForceStart);
ADD_ACTION(command, delete);
ADD_ACTION(command, deletePerm);
ADD_ACTION(command, increasePrio);
@ -551,6 +552,19 @@ void WebApplication::action_command_setSuperSeeding()
}
}
void WebApplication::action_command_setForceStart()
{
CHECK_URI(0);
CHECK_PARAMETERS("hashes" << "value");
bool value = request().posts["value"] == "true";
QStringList hashes = request().posts["hashes"].split("|");
foreach (const QString &hash, hashes) {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
QBtSession::instance()->resumeTorrent(hash, value);
}
}
void WebApplication::action_command_delete()
{
CHECK_URI(0);

View File

@ -77,6 +77,7 @@ private:
void action_command_toggleSequentialDownload();
void action_command_toggleFirstLastPiecePrio();
void action_command_setSuperSeeding();
void action_command_setForceStart();
void action_command_delete();
void action_command_deletePerm();
void action_command_increasePrio();

View File

@ -96,6 +96,7 @@
</div>
<ul id="contextmenu">
<li><a href="#Start"><img src="theme/media-playback-start" alt="QBT_TR(Resume)QBT_TR"/> QBT_TR(Resume)QBT_TR</a></li>
<li><a href="#ForceStart"><img src="theme/checked" alt="QBT_TR(Force Resume)QBT_TR"/> QBT_TR(Force Resume)QBT_TR</a></li>
<li><a href="#Pause"><img src="theme/media-playback-pause" alt="QBT_TR(Pause)QBT_TR"/> QBT_TR(Pause)QBT_TR</a></li>
<li class="separator"><a href="#Delete"><img src="theme/list-remove" alt="QBT_TR(Delete)QBT_TR"/> QBT_TR(Delete)QBT_TR</a></li>
<li id="queueingMenuItems" class="separator">

View File

@ -137,6 +137,7 @@ var ContextMenu = new Class({
all_are_paused = true;
there_are_paused = false;
all_are_super_seeding = true;
all_are_force_start = true;
var h = myTable.selectedIds();
h.each(function(item, index){
@ -152,6 +153,9 @@ var ContextMenu = new Class({
else
there_are_f_l_piece_prio = true;
if (data['force_start'] != true)
all_are_force_start = false;
if (data['progress'] != 1.0) // not downloaded
all_are_downloaded = false;
else if (data['super_seeding'] != true)
@ -174,6 +178,8 @@ var ContextMenu = new Class({
if (!all_are_f_l_piece_prio && there_are_f_l_piece_prio)
show_f_l_piece_prio = false;
this.setItemChecked('ForceStart', all_are_force_start);
if (all_are_downloaded) {
this.hideItem('SequentialDownload');
this.hideItem('FirstLastPiecePrio');

View File

@ -181,6 +181,21 @@ initializeWindows = function() {
}
};
setForceStartFN = function(val) {
var h = myTable.selectedIds();
if (h.length) {
new Request({
url: 'command/setForceStart',
method: 'post',
data: {
value: val,
hashes: h.join("|")
}
}).send();
updateMainData();
}
};
globalDownloadLimitFN = function() {
new MochaUI.Window({
id: 'downloadLimitPage',

View File

@ -54,6 +54,9 @@
},
SuperSeeding : function (element, ref) {
setSuperSeedingFN(!ref.getItemChecked('SuperSeeding'));
},
ForceStart : function (element, ref) {
setForceStartFN(!ref.getItemChecked('ForceStart'));
}
},
offsets : {