2008-07-03 14:59:31 +00:00
|
|
|
/*
|
|
|
|
* MIT License
|
2008-09-28 11:57:09 +00:00
|
|
|
* Copyright (c) 2008 Ishan Arora <ishan@qbittorrent.org>,
|
|
|
|
* Christophe Dumez <chris@qbittorrent.org>
|
2008-07-03 14:59:31 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2012-07-01 14:44:14 +03:00
|
|
|
*
|
2008-07-03 14:59:31 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2012-07-01 14:44:14 +03:00
|
|
|
*
|
2008-07-03 14:59:31 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2008-07-04 07:48:15 +00:00
|
|
|
*/
|
2008-07-03 14:59:31 +00:00
|
|
|
|
2008-12-24 11:28:02 +00:00
|
|
|
myTable = new dynamicTable();
|
|
|
|
|
2014-12-11 00:01:04 +01:00
|
|
|
var updatePropertiesPanel = function(){};
|
2015-01-06 23:24:54 +03:00
|
|
|
var updateMainData = function(){};
|
2014-12-19 17:24:56 +01:00
|
|
|
var alternativeSpeedLimits = false;
|
2015-01-29 16:42:04 +03:00
|
|
|
var queueing_enabled = true;
|
2014-12-11 00:01:04 +01:00
|
|
|
|
2014-12-24 04:39:18 +03:00
|
|
|
selected_filter = getLocalStorageItem('selected_filter', 'all');
|
|
|
|
selected_label = null;
|
|
|
|
|
|
|
|
var loadSelectedLabel = function () {
|
|
|
|
if (getLocalStorageItem('any_label', '1') == '0')
|
|
|
|
selected_label = getLocalStorageItem('selected_label', '');
|
|
|
|
else
|
|
|
|
selected_label = null;
|
|
|
|
}
|
|
|
|
loadSelectedLabel();
|
|
|
|
|
|
|
|
var saveSelectedLabel = function () {
|
|
|
|
if (selected_label == null)
|
|
|
|
localStorage.setItem('any_label', '1');
|
|
|
|
else {
|
|
|
|
localStorage.setItem('any_label', '0');
|
|
|
|
localStorage.setItem('selected_label', selected_label);
|
2014-12-08 02:15:31 +03:00
|
|
|
}
|
2014-12-24 04:39:18 +03:00
|
|
|
}
|
2014-12-08 02:15:31 +03:00
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
window.addEvent('load', function () {
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
var saveColumnSizes = function () {
|
|
|
|
var filters_width = $('Filters').getSize().x;
|
2014-12-14 10:00:00 +01:00
|
|
|
var properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y;
|
2014-11-22 09:35:56 +03:00
|
|
|
localStorage.setItem('filters_width', filters_width);
|
2014-12-14 10:00:00 +01:00
|
|
|
localStorage.setItem('properties_height_rel', properties_height_rel);
|
2014-11-22 09:35:56 +03:00
|
|
|
}
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2014-12-14 10:00:00 +01:00
|
|
|
window.addEvent('resize', function() {
|
|
|
|
// Resizing might takes some time.
|
|
|
|
saveColumnSizes.delay(200);
|
|
|
|
});
|
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
/*MochaUI.Desktop = new MochaUI.Desktop();
|
|
|
|
MochaUI.Desktop.desktop.setStyles({
|
|
|
|
'background': '#fff',
|
|
|
|
'visibility': 'visible'
|
|
|
|
});*/
|
|
|
|
MochaUI.Desktop.initialize();
|
2009-12-05 14:19:37 +00:00
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
var filt_w = localStorage.getItem('filters_width');
|
|
|
|
if ($defined(filt_w))
|
|
|
|
filt_w = filt_w.toInt();
|
|
|
|
else
|
|
|
|
filt_w = 120;
|
|
|
|
new MochaUI.Column({
|
|
|
|
id : 'filtersColumn',
|
|
|
|
placement : 'left',
|
|
|
|
onResize : saveColumnSizes,
|
|
|
|
width : filt_w,
|
|
|
|
resizeLimit : [100, 300]
|
|
|
|
});
|
|
|
|
new MochaUI.Column({
|
|
|
|
id : 'mainColumn',
|
|
|
|
placement : 'main',
|
|
|
|
width : null,
|
|
|
|
resizeLimit : [100, 300]
|
|
|
|
});
|
|
|
|
MochaUI.Desktop.setDesktopSize();
|
2014-12-08 04:31:04 +03:00
|
|
|
|
|
|
|
setFilter = function (f) {
|
|
|
|
// Visually Select the right filter
|
|
|
|
$("all_filter").removeClass("selectedFilter");
|
|
|
|
$("downloading_filter").removeClass("selectedFilter");
|
|
|
|
$("completed_filter").removeClass("selectedFilter");
|
|
|
|
$("paused_filter").removeClass("selectedFilter");
|
2015-01-29 20:30:54 +03:00
|
|
|
$("resumed_filter").removeClass("selectedFilter");
|
2014-12-08 04:31:04 +03:00
|
|
|
$("active_filter").removeClass("selectedFilter");
|
|
|
|
$("inactive_filter").removeClass("selectedFilter");
|
|
|
|
$(f + "_filter").addClass("selectedFilter");
|
2014-12-24 04:39:18 +03:00
|
|
|
selected_filter = f;
|
2014-12-08 04:31:04 +03:00
|
|
|
localStorage.setItem('selected_filter', f);
|
|
|
|
// Reload torrents
|
|
|
|
if (typeof myTable.table != 'undefined')
|
2015-01-06 23:24:54 +03:00
|
|
|
updateMainData();
|
2014-12-08 04:31:04 +03:00
|
|
|
}
|
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
new MochaUI.Panel({
|
|
|
|
id : 'Filters',
|
|
|
|
title : 'Panel',
|
|
|
|
header : false,
|
|
|
|
padding : {
|
|
|
|
top : 0,
|
|
|
|
right : 0,
|
|
|
|
bottom : 0,
|
|
|
|
left : 0
|
|
|
|
},
|
|
|
|
loadMethod : 'xhr',
|
|
|
|
contentURL : 'filters.html',
|
2014-12-08 04:31:04 +03:00
|
|
|
onContentLoaded : function () {
|
2014-12-24 04:39:18 +03:00
|
|
|
setFilter(selected_filter);
|
2014-12-08 04:31:04 +03:00
|
|
|
},
|
2014-11-22 09:35:56 +03:00
|
|
|
column : 'filtersColumn',
|
|
|
|
height : 300
|
|
|
|
});
|
|
|
|
initializeWindows();
|
2014-11-30 21:13:02 +01:00
|
|
|
|
|
|
|
var speedInTitle = localStorage.getItem('speed_in_browser_title_bar') == "true";
|
|
|
|
if (!speedInTitle)
|
|
|
|
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
|
|
|
|
|
2015-01-06 23:24:54 +03:00
|
|
|
var syncMainDataLastResponseId = 0;
|
|
|
|
var serverState = {};
|
|
|
|
|
|
|
|
var syncMainDataTimer;
|
|
|
|
var syncMainData = function () {
|
|
|
|
var url = new URI('sync/maindata');
|
|
|
|
url.setData('rid', syncMainDataLastResponseId);
|
2014-12-14 10:00:00 +01:00
|
|
|
var request = new Request.JSON({
|
|
|
|
url : url,
|
|
|
|
noCache : true,
|
|
|
|
method : 'get',
|
|
|
|
onFailure : function () {
|
2014-12-17 14:58:32 +03:00
|
|
|
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR');
|
2015-01-06 23:24:54 +03:00
|
|
|
clearTimeout(syncMainDataTimer);
|
|
|
|
syncMainDataTimer = syncMainData.delay(2000);
|
2014-12-14 10:00:00 +01:00
|
|
|
},
|
2014-12-24 04:39:18 +03:00
|
|
|
onSuccess : function (response) {
|
2014-12-14 10:00:00 +01:00
|
|
|
$('error_div').set('html', '');
|
2014-12-24 04:39:18 +03:00
|
|
|
if (response) {
|
2015-01-06 23:24:54 +03:00
|
|
|
var full_update = (response['full_update'] == true);
|
|
|
|
if (full_update)
|
|
|
|
myTable.rows.erase();
|
|
|
|
if (response['rid'])
|
|
|
|
syncMainDataLastResponseId = response['rid'];
|
|
|
|
if (response['torrents'])
|
|
|
|
for (var key in response['torrents']) {
|
|
|
|
response['torrents'][key]['hash'] = key;
|
|
|
|
myTable.updateRowData(response['torrents'][key]);
|
|
|
|
}
|
|
|
|
myTable.updateTable(full_update);
|
|
|
|
if (response['torrents_removed'])
|
|
|
|
response['torrents_removed'].each(function (hash) {
|
|
|
|
myTable.removeRow(hash);
|
|
|
|
});
|
2014-12-14 10:00:00 +01:00
|
|
|
myTable.altRow();
|
2015-01-06 23:24:54 +03:00
|
|
|
if (response['server_state']) {
|
|
|
|
var tmp = response['server_state'];
|
|
|
|
for(var key in tmp)
|
|
|
|
serverState[key] = tmp[key];
|
|
|
|
processServerState();
|
|
|
|
}
|
2014-12-14 10:00:00 +01:00
|
|
|
}
|
2015-01-06 23:24:54 +03:00
|
|
|
clearTimeout(syncMainDataTimer);
|
|
|
|
syncMainDataTimer = syncMainData.delay(1500);
|
2014-12-14 10:00:00 +01:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
|
|
|
|
2015-01-06 23:24:54 +03:00
|
|
|
updateMainData = function() {
|
2014-12-24 04:39:18 +03:00
|
|
|
myTable.updateTable();
|
2015-01-06 23:24:54 +03:00
|
|
|
clearTimeout(syncMainDataTimer);
|
|
|
|
syncMainDataTimer = syncMainData.delay(100);
|
2014-12-14 10:00:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-06 23:24:54 +03:00
|
|
|
var processServerState = function () {
|
|
|
|
var transfer_info = "";
|
|
|
|
if (serverState.dl_rate_limit > 0)
|
|
|
|
transfer_info += "[" + friendlyUnit(serverState.dl_rate_limit, true) + "] ";
|
|
|
|
transfer_info += friendlyUnit(serverState.dl_info_speed, true);
|
|
|
|
transfer_info += " (" + friendlyUnit(serverState.dl_info_data, false) + ")"
|
|
|
|
$("DlInfos").set('html', transfer_info);
|
|
|
|
transfer_info = "";
|
|
|
|
if (serverState.up_rate_limit > 0)
|
|
|
|
transfer_info += "[" + friendlyUnit(serverState.up_rate_limit, true) + "] ";
|
|
|
|
transfer_info += friendlyUnit(serverState.up_info_speed, true)
|
|
|
|
transfer_info += " (" + friendlyUnit(serverState.up_info_data, false) + ")"
|
|
|
|
$("UpInfos").set('html', transfer_info);
|
|
|
|
if (speedInTitle)
|
|
|
|
document.title = "QBT_TR(D:%1 U:%2)QBT_TR".replace("%1", friendlyUnit(serverState.dl_info_speed, true)).replace("%2", friendlyUnit(serverState.up_info_speed, true));
|
|
|
|
else
|
|
|
|
document.title = "QBT_TR(qBittorrent web User Interface)QBT_TR";
|
|
|
|
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR'.replace("%1", serverState.dht_nodes));
|
|
|
|
if (serverState.connection_status == "connected")
|
|
|
|
$('connectionStatus').src = 'images/skin/connected.png';
|
|
|
|
else if (serverState.connection_status == "firewalled")
|
|
|
|
$('connectionStatus').src = 'images/skin/firewalled.png';
|
|
|
|
else
|
|
|
|
$('connectionStatus').src = 'images/skin/disconnected.png';
|
2015-01-29 16:42:04 +03:00
|
|
|
|
|
|
|
if (queueing_enabled != serverState.queueing) {
|
|
|
|
queueing_enabled = serverState.queueing;
|
|
|
|
myTable.columns['priority'].force_hide = !queueing_enabled;
|
|
|
|
myTable.updateColumn('priority');
|
|
|
|
if (queueing_enabled) {
|
|
|
|
$('queueingButtons').removeClass('invisible');
|
|
|
|
$('queueingMenuItems').removeClass('invisible');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('queueingButtons').addClass('invisible');
|
|
|
|
$('queueingMenuItems').addClass('invisible');
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 19:56:14 +03:00
|
|
|
|
|
|
|
if (alternativeSpeedLimits != serverState.use_alt_speed_limits) {
|
|
|
|
alternativeSpeedLimits = serverState.use_alt_speed_limits;
|
|
|
|
updateAltSpeedIcon(alternativeSpeedLimits);
|
|
|
|
}
|
2014-11-22 09:35:56 +03:00
|
|
|
};
|
2014-11-26 21:26:29 +01:00
|
|
|
|
2014-12-14 10:00:00 +01:00
|
|
|
var updateAltSpeedIcon = function(enabled) {
|
|
|
|
if (enabled)
|
|
|
|
$('alternativeSpeedLimits').src = "images/slow.png";
|
|
|
|
else
|
|
|
|
$('alternativeSpeedLimits').src = "images/slow_off.png"
|
|
|
|
}
|
|
|
|
|
|
|
|
$('alternativeSpeedLimits').addEvent('click', function() {
|
|
|
|
// Change icon immediately to give some feedback
|
2014-12-19 17:24:56 +01:00
|
|
|
updateAltSpeedIcon(!alternativeSpeedLimits);
|
2014-12-14 10:00:00 +01:00
|
|
|
|
|
|
|
new Request({url: 'command/toggleAlternativeSpeedLimits',
|
|
|
|
method: 'post',
|
|
|
|
onComplete: function() {
|
2014-12-19 17:24:56 +01:00
|
|
|
alternativeSpeedLimits = !alternativeSpeedLimits;
|
2015-01-06 23:24:54 +03:00
|
|
|
updateMainData();
|
2014-12-14 10:00:00 +01:00
|
|
|
},
|
|
|
|
onFailure: function() {
|
|
|
|
// Restore icon in case of failure
|
2014-12-19 17:24:56 +01:00
|
|
|
updateAltSpeedIcon(alternativeSpeedLimits)
|
2014-12-14 10:00:00 +01:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
});
|
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
$('DlInfos').addEvent('click', globalDownloadLimitFN);
|
|
|
|
$('UpInfos').addEvent('click', globalUploadLimitFN);
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2014-11-26 12:45:09 +03:00
|
|
|
setSortedColumn = function (column) {
|
|
|
|
myTable.setSortedColumn(column);
|
2015-01-06 23:24:54 +03:00
|
|
|
updateMainData();
|
2014-11-26 12:45:09 +03:00
|
|
|
};
|
|
|
|
|
2014-11-30 21:13:02 +01:00
|
|
|
$('speedInBrowserTitleBarLink').addEvent('click', function(e) {
|
|
|
|
speedInTitle = !speedInTitle;
|
|
|
|
localStorage.setItem('speed_in_browser_title_bar', speedInTitle.toString());
|
|
|
|
if (speedInTitle)
|
|
|
|
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '1';
|
2014-11-30 14:35:26 +01:00
|
|
|
else
|
2014-11-30 21:13:02 +01:00
|
|
|
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
|
2015-01-06 23:24:54 +03:00
|
|
|
updateMainData();
|
2014-11-30 14:35:26 +01:00
|
|
|
});
|
|
|
|
|
2014-11-22 09:35:56 +03:00
|
|
|
new MochaUI.Panel({
|
|
|
|
id : 'transferList',
|
|
|
|
title : 'Panel',
|
|
|
|
header : false,
|
|
|
|
padding : {
|
|
|
|
top : 0,
|
|
|
|
right : 0,
|
|
|
|
bottom : 0,
|
|
|
|
left : 0
|
|
|
|
},
|
|
|
|
loadMethod : 'xhr',
|
|
|
|
contentURL : 'transferlist.html',
|
|
|
|
onContentLoaded : function () {
|
2015-01-06 23:24:54 +03:00
|
|
|
updateMainData();
|
2014-11-22 09:35:56 +03:00
|
|
|
},
|
|
|
|
column : 'mainColumn',
|
|
|
|
onResize : saveColumnSizes,
|
|
|
|
height : null
|
|
|
|
});
|
2014-12-14 10:00:00 +01:00
|
|
|
var prop_h = localStorage.getItem('properties_height_rel');
|
2014-11-22 09:35:56 +03:00
|
|
|
if ($defined(prop_h))
|
2014-12-14 10:00:00 +01:00
|
|
|
prop_h = prop_h.toFloat() * Window.getSize().y;
|
2010-04-23 16:48:17 +00:00
|
|
|
else
|
2014-11-22 09:35:56 +03:00
|
|
|
prop_h = Window.getSize().y / 2.;
|
2010-04-23 16:48:17 +00:00
|
|
|
new MochaUI.Panel({
|
2014-11-22 09:35:56 +03:00
|
|
|
id : 'propertiesPanel',
|
|
|
|
title : 'Panel',
|
|
|
|
header : true,
|
|
|
|
padding : {
|
|
|
|
top : 0,
|
|
|
|
right : 0,
|
|
|
|
bottom : 0,
|
|
|
|
left : 0
|
|
|
|
},
|
2014-12-08 21:00:00 +01:00
|
|
|
contentURL : 'properties_content.html',
|
2014-11-22 09:35:56 +03:00
|
|
|
require : {
|
2014-12-08 21:00:00 +01:00
|
|
|
css : ['css/Tabs.css'],
|
|
|
|
js : ['scripts/prop-general.js', 'scripts/prop-trackers.js', 'scripts/prop-files.js'],
|
2014-11-22 09:35:56 +03:00
|
|
|
},
|
|
|
|
tabsURL : 'properties.html',
|
2014-12-08 21:00:00 +01:00
|
|
|
tabsOnload : function() {
|
|
|
|
MochaUI.initializeTabs('propertiesTabs');
|
|
|
|
|
2014-12-11 00:01:04 +01:00
|
|
|
updatePropertiesPanel = function() {
|
|
|
|
if (!$('prop_general').hasClass('invisible'))
|
|
|
|
updateTorrentData();
|
|
|
|
else if (!$('prop_trackers').hasClass('invisible'))
|
|
|
|
updateTrackersData();
|
|
|
|
else if (!$('prop_files').hasClass('invisible'))
|
|
|
|
updateTorrentFilesData();
|
|
|
|
}
|
|
|
|
|
2014-12-08 21:00:00 +01:00
|
|
|
$('PropGeneralLink').addEvent('click', function(e){
|
|
|
|
$('prop_general').removeClass("invisible");
|
|
|
|
$('prop_trackers').addClass("invisible");
|
|
|
|
$('prop_files').addClass("invisible");
|
2014-12-11 00:01:04 +01:00
|
|
|
updatePropertiesPanel();
|
2014-12-08 21:00:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$('PropTrackersLink').addEvent('click', function(e){
|
|
|
|
$('prop_trackers').removeClass("invisible");
|
|
|
|
$('prop_general').addClass("invisible");
|
|
|
|
$('prop_files').addClass("invisible");
|
2014-12-11 00:01:04 +01:00
|
|
|
updatePropertiesPanel();
|
2014-12-08 21:00:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$('PropFilesLink').addEvent('click', function(e){
|
|
|
|
$('prop_files').removeClass("invisible");
|
|
|
|
$('prop_general').addClass("invisible");
|
|
|
|
$('prop_trackers').addClass("invisible");
|
2014-12-11 00:01:04 +01:00
|
|
|
updatePropertiesPanel();
|
2014-12-08 21:00:00 +01:00
|
|
|
});
|
|
|
|
},
|
2014-11-22 09:35:56 +03:00
|
|
|
column : 'mainColumn',
|
|
|
|
height : prop_h
|
|
|
|
});
|
2008-05-17 12:44:42 +00:00
|
|
|
});
|
2008-09-28 16:23:08 +00:00
|
|
|
|
2009-11-23 14:21:07 +00:00
|
|
|
function closeWindows() {
|
2014-11-22 09:35:56 +03:00
|
|
|
MochaUI.closeAll();
|
2015-01-29 22:29:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
var keyboardEvents = new Keyboard({
|
|
|
|
defaultEventType: 'keydown',
|
|
|
|
events: {
|
|
|
|
'ctrl+a': function(event) {
|
|
|
|
myTable.selectAll();
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
'delete': function(event) {
|
|
|
|
deleteFN();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2014-11-22 09:35:56 +03:00
|
|
|
}
|
2008-10-27 20:15:17 +00:00
|
|
|
});
|
2015-01-29 22:29:28 +03:00
|
|
|
|
|
|
|
keyboardEvents.activate();
|