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();
|
2009-11-23 09:16:32 +00:00
|
|
|
ajaxfn = function(){};
|
2009-11-27 15:48:45 +00:00
|
|
|
setSortedColumn = function(index){
|
|
|
|
myTable.setSortedColumn(index);
|
|
|
|
};
|
2008-12-24 11:28:02 +00:00
|
|
|
|
2009-12-05 14:19:37 +00:00
|
|
|
window.addEvent('load', function(){
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2009-11-24 16:08:23 +00:00
|
|
|
var saveColumnSizes = function() {
|
|
|
|
var filters_width = $('Filters').getSize().x;
|
2010-06-07 13:41:32 +00:00
|
|
|
var properties_height = $('propertiesPanel').getSize().y;
|
2009-11-24 16:08:23 +00:00
|
|
|
// Save it in a cookie
|
|
|
|
Cookie.write('filters_width', filters_width);
|
|
|
|
Cookie.write('properties_height', properties_height);
|
|
|
|
}
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2009-12-05 14:19:37 +00:00
|
|
|
/*MochaUI.Desktop = new MochaUI.Desktop();
|
2008-12-23 23:47:30 +00:00
|
|
|
MochaUI.Desktop.desktop.setStyles({
|
|
|
|
'background': '#fff',
|
|
|
|
'visibility': 'visible'
|
2009-12-05 14:19:37 +00:00
|
|
|
});*/
|
|
|
|
MochaUI.Desktop.initialize();
|
|
|
|
|
2009-11-25 10:35:31 +00:00
|
|
|
var filt_w = Cookie.read('filters_width');
|
|
|
|
if($defined(filt_w))
|
|
|
|
filt_w = filt_w.toInt();
|
|
|
|
else
|
2009-11-24 16:08:23 +00:00
|
|
|
filt_w = 120;
|
2009-11-23 19:12:44 +00:00
|
|
|
new MochaUI.Column({
|
|
|
|
id: 'filtersColumn',
|
|
|
|
placement: 'left',
|
2009-11-24 16:08:23 +00:00
|
|
|
onResize: saveColumnSizes,
|
|
|
|
width: filt_w,
|
2009-11-23 19:12:44 +00:00
|
|
|
resizeLimit: [100, 300]
|
|
|
|
});
|
|
|
|
new MochaUI.Column({
|
|
|
|
id: 'mainColumn',
|
2012-07-01 14:44:14 +03:00
|
|
|
placement: 'main',
|
2009-11-23 19:12:44 +00:00
|
|
|
width: null,
|
|
|
|
resizeLimit: [100, 300]
|
|
|
|
});
|
2009-12-05 14:19:37 +00:00
|
|
|
MochaUI.Desktop.setDesktopSize();
|
2009-11-23 19:12:44 +00:00
|
|
|
new MochaUI.Panel({
|
|
|
|
id: 'Filters',
|
|
|
|
title: 'Panel',
|
2009-12-05 14:19:37 +00:00
|
|
|
header: false,
|
|
|
|
padding: { top: 0, right: 0, bottom: 0, left: 0 },
|
2009-11-23 19:12:44 +00:00
|
|
|
loadMethod: 'xhr',
|
|
|
|
contentURL: 'filters.html',
|
|
|
|
column: 'filtersColumn',
|
|
|
|
height: 300
|
|
|
|
});
|
2008-12-23 23:47:30 +00:00
|
|
|
initializeWindows();
|
2008-12-24 10:05:09 +00:00
|
|
|
var r=0;
|
|
|
|
var waiting=false;
|
2010-02-15 20:07:15 +00:00
|
|
|
var waitingTrInfo = false;
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2008-09-28 11:30:24 +00:00
|
|
|
var stateToImg = function(state){
|
2010-05-24 14:43:31 +00:00
|
|
|
if(state == "pausedUP" || state == "pausedDL") {
|
|
|
|
state = "paused";
|
|
|
|
} else {
|
|
|
|
if(state == "queuedUP" || state == "queuedDL") {
|
|
|
|
state = "queued";
|
|
|
|
} else {
|
|
|
|
if(state == "checkingUP" || state == "checkingDL") {
|
|
|
|
state = "checking";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-25 12:09:10 +00:00
|
|
|
return 'images/skin/'+state+'.png';
|
2010-02-15 20:07:15 +00:00
|
|
|
};
|
|
|
|
var loadTransferInfo = function() {
|
|
|
|
var url = 'json/transferInfo';
|
|
|
|
if(!waitingTrInfo) {
|
|
|
|
waitingTrInfo = true;
|
|
|
|
var request = new Request.JSON({
|
|
|
|
url: url,
|
|
|
|
noCache: true,
|
|
|
|
method: 'get',
|
|
|
|
onFailure: function() {
|
2011-01-14 19:03:48 +00:00
|
|
|
$('error_div').set('html', '_(qBittorrent client is not reachable)');
|
2010-02-15 20:07:15 +00:00
|
|
|
waitingTrInfo=false;
|
|
|
|
loadTransferInfo.delay(4000);
|
|
|
|
},
|
|
|
|
onSuccess: function(info) {
|
|
|
|
if(info) {
|
2014-11-08 16:13:00 +01:00
|
|
|
$("DlInfos").set('html', "_(D: %1 - T: %2)".replace("%1", friendlyUnit(info.dl_info_speed, true))
|
|
|
|
.replace("%2", friendlyUnit(info.dl_info_data, false)));
|
|
|
|
$("UpInfos").set('html', "_(U: %1 - T: %2)".replace("%1", friendlyUnit(info.up_info_speed, true))
|
|
|
|
.replace("%2", friendlyUnit(info.up_info_data, false)));
|
2010-02-15 20:07:15 +00:00
|
|
|
waitingTrInfo=false;
|
|
|
|
loadTransferInfo.delay(3000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
2008-09-28 11:30:24 +00:00
|
|
|
};
|
2010-02-15 20:57:55 +00:00
|
|
|
$('DlInfos').addEvent('click', globalDownloadLimitFN);
|
|
|
|
$('UpInfos').addEvent('click', globalUploadLimitFN);
|
2012-07-01 14:44:14 +03:00
|
|
|
|
2008-05-17 12:44:42 +00:00
|
|
|
var ajaxfn = function(){
|
2008-12-29 22:46:18 +00:00
|
|
|
var queueing_enabled = false;
|
2012-05-26 20:42:44 +03:00
|
|
|
var url = 'json/torrents';
|
2008-05-17 12:44:42 +00:00
|
|
|
if (!waiting){
|
|
|
|
waiting=true;
|
2008-09-14 10:14:54 +00:00
|
|
|
var request = new Request.JSON({
|
|
|
|
url: url,
|
2009-12-05 14:19:37 +00:00
|
|
|
noCache: true,
|
2008-05-17 12:44:42 +00:00
|
|
|
method: 'get',
|
2008-12-25 16:20:30 +00:00
|
|
|
onFailure: function() {
|
2011-04-18 16:58:13 +00:00
|
|
|
$('error_div').set('html', '_(qBittorrent client is not reachable)');
|
2008-12-25 16:20:30 +00:00
|
|
|
waiting=false;
|
|
|
|
ajaxfn.delay(2000);
|
|
|
|
},
|
|
|
|
onSuccess: function(events) {
|
|
|
|
$('error_div').set('html', '');
|
2008-09-28 11:30:24 +00:00
|
|
|
if(events){
|
|
|
|
// Add new torrents or update them
|
2009-11-23 09:16:32 +00:00
|
|
|
torrent_hashes = myTable.getRowIds();
|
2008-09-28 11:30:24 +00:00
|
|
|
events_hashes = new Array();
|
|
|
|
events.each(function(event){
|
|
|
|
events_hashes[events_hashes.length] = event.hash;
|
2008-09-27 19:55:56 +00:00
|
|
|
var row = new Array();
|
2009-11-23 10:40:16 +00:00
|
|
|
row.length = 10;
|
2008-09-28 11:30:24 +00:00
|
|
|
row[0] = stateToImg(event.state);
|
|
|
|
row[1] = event.name;
|
2014-11-08 16:13:00 +01:00
|
|
|
row[2] = event.priority > -1 ? event.priority : null;
|
|
|
|
row[3] = friendlyUnit(event.size, false);
|
2009-11-25 11:36:36 +00:00
|
|
|
row[4] = (event.progress*100).round(1);
|
2010-11-12 17:16:44 +00:00
|
|
|
if(row[4] == 100.0 && event.progress != 1.0)
|
|
|
|
row[4] = 99.9;
|
2014-11-08 16:13:00 +01:00
|
|
|
row[5] = event.num_seeds;
|
|
|
|
if (event.num_complete != -1)
|
|
|
|
row[5] += " (" + event.num_complete + ")";
|
|
|
|
row[6] = event.num_leechs;
|
|
|
|
if (event.num_incomplete != -1)
|
|
|
|
row[6] += " (" + event.num_incomplete + ")";
|
|
|
|
row[7] = friendlyUnit(event.dlspeed, true);
|
|
|
|
row[8] = friendlyUnit(event.upspeed, true);
|
|
|
|
row[9] = friendlyDuration(event.eta);
|
|
|
|
if(event.ratio == -1)
|
|
|
|
row[10] = "∞";
|
|
|
|
else
|
|
|
|
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
|
|
|
|
if(row[2] != null)
|
2008-12-29 22:46:18 +00:00
|
|
|
queueing_enabled = true;
|
2009-11-23 09:16:32 +00:00
|
|
|
if(!torrent_hashes.contains(event.hash)) {
|
2008-09-28 11:30:24 +00:00
|
|
|
// New unfinished torrent
|
2009-11-23 13:35:46 +00:00
|
|
|
torrent_hashes[torrent_hashes.length] = event.hash;
|
|
|
|
//alert("Inserting row");
|
2009-11-26 11:01:21 +00:00
|
|
|
myTable.insertRow(event.hash, row, event.state);
|
2008-09-28 11:30:24 +00:00
|
|
|
} else {
|
|
|
|
// Update torrent data
|
2009-11-23 09:16:32 +00:00
|
|
|
myTable.updateRow(event.hash, row, event.state);
|
2008-09-28 11:30:24 +00:00
|
|
|
}
|
|
|
|
});
|
2008-12-24 10:05:09 +00:00
|
|
|
// Remove deleted torrents
|
2009-11-23 09:16:32 +00:00
|
|
|
torrent_hashes.each(function(hash){
|
2008-09-28 11:30:24 +00:00
|
|
|
if(!events_hashes.contains(hash)) {
|
|
|
|
myTable.removeRow(hash);
|
|
|
|
}
|
|
|
|
});
|
2008-12-29 23:04:45 +00:00
|
|
|
if(queueing_enabled) {
|
2008-12-29 22:46:18 +00:00
|
|
|
$('queueingButtons').removeClass('invisible');
|
2008-12-29 23:04:45 +00:00
|
|
|
myTable.showPriority();
|
|
|
|
} else {
|
2008-12-29 22:46:18 +00:00
|
|
|
$('queueingButtons').addClass('invisible');
|
2008-12-29 23:04:45 +00:00
|
|
|
myTable.hidePriority();
|
|
|
|
}
|
2008-05-17 12:44:42 +00:00
|
|
|
}
|
|
|
|
waiting=false;
|
2009-11-26 11:04:14 +00:00
|
|
|
ajaxfn.delay(1500);
|
2008-05-17 12:44:42 +00:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
};
|
2010-04-23 08:12:06 +00: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() {
|
|
|
|
ajaxfn();
|
|
|
|
},
|
|
|
|
column: 'mainColumn',
|
|
|
|
onResize: saveColumnSizes,
|
|
|
|
height: null
|
|
|
|
});
|
2010-04-23 16:48:17 +00:00
|
|
|
var prop_h = Cookie.read('properties_height');
|
|
|
|
if($defined(prop_h))
|
|
|
|
prop_h = prop_h.toInt();
|
|
|
|
else
|
2011-12-29 00:24:09 +02:00
|
|
|
prop_h = Window.getSize().y / 2.;
|
2010-04-23 16:48:17 +00:00
|
|
|
new MochaUI.Panel({
|
2010-06-07 13:41:32 +00:00
|
|
|
id: 'propertiesPanel',
|
2010-04-23 16:48:17 +00:00
|
|
|
title: 'Panel',
|
|
|
|
header: true,
|
|
|
|
padding: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
|
|
contentURL: 'prop-general.html',
|
|
|
|
require: {
|
|
|
|
css: ['css/Tabs.css']
|
|
|
|
},
|
|
|
|
tabsURL: 'properties.html',
|
|
|
|
column: 'mainColumn',
|
|
|
|
height: prop_h
|
|
|
|
});
|
2010-04-23 08:04:21 +00:00
|
|
|
//ajaxfn();
|
2012-07-01 14:44:14 +03:00
|
|
|
loadTransferInfo();
|
2009-11-23 10:37:55 +00:00
|
|
|
|
|
|
|
setFilter = function(f) {
|
2009-11-23 13:56:10 +00:00
|
|
|
// Visually Select the right filter
|
|
|
|
$("all_filter").removeClass("selectedFilter");
|
|
|
|
$("downloading_filter").removeClass("selectedFilter");
|
|
|
|
$("completed_filter").removeClass("selectedFilter");
|
2010-05-24 19:05:07 +00:00
|
|
|
$("paused_filter").removeClass("selectedFilter");
|
2009-11-23 13:56:10 +00:00
|
|
|
$("active_filter").removeClass("selectedFilter");
|
|
|
|
$("inactive_filter").removeClass("selectedFilter");
|
|
|
|
$(f+"_filter").addClass("selectedFilter");
|
2009-11-23 10:37:55 +00:00
|
|
|
myTable.setFilter(f);
|
|
|
|
ajaxfn();
|
2009-12-04 21:03:50 +00:00
|
|
|
// Remember this via Cookie
|
|
|
|
Cookie.write('selected_filter', f);
|
2009-11-23 10:37:55 +00:00
|
|
|
}
|
2009-11-23 09:16:32 +00:00
|
|
|
|
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() {
|
|
|
|
MochaUI.closeAll();
|
|
|
|
}
|
|
|
|
|
2008-09-28 16:23:08 +00:00
|
|
|
window.addEvent('keydown', function(event){
|
|
|
|
if (event.key == 'a' && event.control) {
|
2008-09-28 16:25:51 +00:00
|
|
|
event.stop();
|
2009-11-23 10:37:55 +00:00
|
|
|
myTable.selectAll();
|
2008-09-28 16:23:08 +00:00
|
|
|
}
|
2008-10-27 20:15:17 +00:00
|
|
|
});
|