diff --git a/src/webui/prefjson.cpp b/src/webui/prefjson.cpp
index c82fa782d..bf206df39 100644
--- a/src/webui/prefjson.cpp
+++ b/src/webui/prefjson.cpp
@@ -396,4 +396,3 @@ void prefjson::setPreferences(const QString& json)
// Save preferences
pref->apply();
}
-
diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp
index 16916b6eb..3000c3464 100644
--- a/src/webui/webapplication.cpp
+++ b/src/webui/webapplication.cpp
@@ -39,6 +39,7 @@
#include "core/preferences.h"
#include "btjson.h"
#include "prefjson.h"
+#include "jsonutils.h"
#include "core/bittorrent/session.h"
#include "core/bittorrent/trackerentry.h"
#include "core/bittorrent/torrentinfo.h"
@@ -677,8 +678,9 @@ void WebApplication::action_command_setLabel()
if( m.contains("value") ) {
QString label = m["value"].toString();
if (!hash.isEmpty()) {
- QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
- QBtSession::instance()->setLabel(h, label);
+ BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
+ if (torrent)
+ torrent->setLabel(label);
}
}
}
diff --git a/src/webui/webui.qrc b/src/webui/webui.qrc
index c77d04bdc..407b6b05f 100644
--- a/src/webui/webui.qrc
+++ b/src/webui/webui.qrc
@@ -27,6 +27,7 @@
' +
+ text + '(' + count + ')' + '';
+
+ return new Element( 'li', { id: hash, html: html } );
+ };
+
+ var allLabels = 0;
+ Object.each( label_list, function( label ) {
+ allLabels += label.torrents.length;
+ });
+
+ var unlabelled = myTable.getRowIds().length - allLabels;
+ labelList.appendChild( create_link( LABELS_ALL, 'QBT_TR(All Labels)QBT_TR', allLabels ) );
+ labelList.appendChild( create_link( LABELS_UNLABELLED, 'QBT_TR(Unlabeled)QBT_TR', unlabelled ) );
+
+ Object.each( label_list, function( label ) {
+ var labelHash = genHash( label.name );
+ labelList.appendChild( create_link( labelHash, label.name, label.torrents.length ) );
+ } );
+
+ var childrens = labelList.childNodes;
+ for (var i in childrens) {
+ if( childrens[i].id == selected_label ) {
+ childrens[i].className = "selectedFilter";
+ }
+ }
+ };
+
var syncMainDataTimer;
var syncMainData = function () {
var url = new URI('sync/maindata');
@@ -165,15 +269,26 @@ window.addEvent('load', function () {
$('error_div').set('html', '');
if (response) {
var full_update = (response['full_update'] == true);
- if (full_update)
+ if (full_update) {
myTable.rows.erase();
- if (response['rid'])
+ label_list = {};
+ Object.each( response['labels'], function( label ) {
+ var labelHash = genHash( label );
+ label_list[ labelHash ] = { name: label, torrents: [] };
+ } );
+ }
+ if (response['rid']) {
syncMainDataLastResponseId = response['rid'];
- if (response['torrents'])
+ }
+ if (response['torrents']) {
for (var key in response['torrents']) {
response['torrents'][key]['hash'] = key;
- myTable.updateRowData(response['torrents'][key]);
+ myTable.updateRowData( response['torrents'][key] );
+ addTorrentToLabelList( response['torrents'][key] );
}
+ updateLabelList();
+ updateContextMenu();
+ }
if (response['torrents_removed'])
response['torrents_removed'].each(function (hash) {
myTable.removeRow(hash);
diff --git a/src/webui/www/public/scripts/dynamicTable.js b/src/webui/www/public/scripts/dynamicTable.js
index ac1062801..c49de75c7 100644
--- a/src/webui/www/public/scripts/dynamicTable.js
+++ b/src/webui/www/public/scripts/dynamicTable.js
@@ -60,6 +60,7 @@ var dynamicTable = new Class({
this.newColumn('upspeed', 'width: 100px; cursor: pointer', 'QBT_TR(Up Speed)QBT_TR');
this.newColumn('eta', 'width: 100px; cursor: pointer', 'QBT_TR(ETA)QBT_TR');
this.newColumn('ratio', 'width: 100px; cursor: pointer', 'QBT_TR(Ratio)QBT_TR');
+ this.newColumn('label', 'width: 100px; cursor: pointer', 'QBT_TR(Label)QBT_TR');
this.columns['state_icon'].onclick = '';
this.columns['state_icon'].dataProperties[0] = 'state';
@@ -279,10 +280,13 @@ var dynamicTable = new Class({
break;
}
- if (labelName == null)
+ if (labelName == LABELS_ALL && row['full_data'].label.length > 0)
return true;
- if (labelName != row['full_data'].label)
+ if (labelName == LABELS_UNLABELLED && row['full_data'].label.length === 0)
+ return true;
+
+ if (labelName != genHash( row['full_data'].label) )
return false;
return true;
diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js
index 1fdd5e924..9ff9c36f5 100644
--- a/src/webui/www/public/scripts/mocha-init.js
+++ b/src/webui/www/public/scripts/mocha-init.js
@@ -309,6 +309,60 @@ initializeWindows = function() {
}
};
+ newLabelFN = function () {
+ var h = myTable.selectedIds();
+ if (h.length) {
+ new MochaUI.Window({
+ id: 'newLabelPage',
+ title: "QBT_TR(Torrent Label)QBT_TR",
+ loadMethod: 'iframe',
+ contentURL: 'newlabel.html?hashes=' + h.join(','),
+ scrollbars: false,
+ resizable: false,
+ maximizable: false,
+ paddingVertical: 0,
+ paddingHorizontal: 0,
+ width: 424,
+ height: 150
+ });
+ }
+ };
+
+ resetLabelFN = function () {
+ var h = myTable.selectedIds();
+ var label_json = JSON.stringify({value: ''});
+ if (h.length) {
+ h.each(function (hash, index) {
+ new Request({
+ url: 'command/setLabel',
+ method: 'post',
+ data: {
+ hash: hash,
+ label_obj: label_json
+ }
+ }).send();
+ });
+ }
+ };
+
+ updateLabelFN = function (label_hash) {
+ var label = label_list[label_hash].name;
+ var label_json = JSON.stringify({value: label});
+ var h = myTable.selectedIds();
+ if (h.length) {
+ h.each(function (hash, index) {
+ new Request({
+ url: 'command/setLabel',
+ method: 'post',
+ data: {
+ hash: hash,
+ label_obj: label_json
+ }
+ }).send();
+ });
+ }
+ };
+
['pauseAll', 'resumeAll'].each(function(item) {
addClickEvent(item, function(e) {
new Event(e).stop();