1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-16 17:50:01 +00:00

201 lines
5.9 KiB
JavaScript
Raw Normal View History

2008-07-03 14:59:31 +00:00
/*
* MIT License
* 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:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 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();
ajaxfn = function(){};
2008-12-24 11:28:02 +00:00
window.addEvent('domready', function(){
2008-12-23 23:47:30 +00:00
MochaUI.Desktop = new MochaUI.Desktop();
MochaUI.Desktop.desktop.setStyles({
'background': '#fff',
'visibility': 'visible'
});
new MochaUI.Column({
id: 'filtersColumn',
placement: 'left',
width: 120,
resizeLimit: [100, 300]
});
new MochaUI.Column({
id: 'mainColumn',
placement: 'main',
width: null,
resizeLimit: [100, 300]
});
new MochaUI.Panel({
id: 'Filters',
title: 'Panel',
loadMethod: 'xhr',
contentURL: 'filters.html',
column: 'filtersColumn',
height: 300
});
new MochaUI.Panel({
id: 'transferList',
title: 'Panel',
loadMethod: 'xhr',
contentURL: 'transferlist.html',
column: 'mainColumn',
height: null
});
new MochaUI.Panel({
id: 'properties',
title: 'Panel',
loadMethod: 'xhr',
contentURL: 'properties.html',
column: 'mainColumn',
height: 200
});
2008-12-23 23:47:30 +00:00
initializeWindows();
2008-12-24 10:05:09 +00:00
var r=0;
var waiting=false;
var stateToImg = function(state){
switch (state)
{
case 'pausedUP':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/pausedUP.png"/>';
case 'pausedDL':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/pausedDL.png"/>';
case 'seeding':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/uploading.png"/>';
case 'stalledUP':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/stalledUP.png"/>';
case 'checkingUP':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/checkingUP.png"/>';
case 'checkingDL':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/checkingDL.png"/>';
case 'downloading':
return '<img src="images/skin/downloading.png"/>';
case 'stalledDL':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/stalledDL.png"/>';
case 'queuedUP':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/queuedUP.png"/>';
case 'queuedDL':
2009-11-23 16:43:51 +00:00
return '<img src="images/skin/queuedDL.png"/>';
default:
2009-11-23 16:43:51 +00:00
return '';
}
return '';
};
2009-11-23 14:01:03 +00:00
var round1 = function(val){return Math.round(val*10)/10};
var ajaxfn = function(){
2008-12-29 22:46:18 +00:00
var queueing_enabled = false;
var url = 'json/events';
if (!waiting){
waiting=true;
var request = new Request.JSON({
url: url,
method: 'get',
onFailure: function() {
$('error_div').set('html', 'qBittorrent client is not reachable');
waiting=false;
ajaxfn.delay(2000);
},
onSuccess: function(events) {
$('error_div').set('html', '');
if(events){
// Add new torrents or update them
torrent_hashes = myTable.getRowIds();
events_hashes = new Array();
events.each(function(event){
events_hashes[events_hashes.length] = event.hash;
var row = new Array();
2009-11-23 10:40:16 +00:00
row.length = 10;
row[0] = stateToImg(event.state);
row[1] = event.name;
row[2] = event.priority
row[3] = event.size;
2009-11-23 14:01:03 +00:00
row[4] = round1(event.progress*100);
row[5] = event.num_seeds;
row[6] = event.num_leechs;
row[7] = event.dlspeed;
row[8] = event.upspeed;
row[9] = event.eta;
2009-11-23 10:40:16 +00:00
row[10] = event.ratio;
2009-11-23 13:35:46 +00:00
if(row[2] != "*")
2008-12-29 22:46:18 +00:00
queueing_enabled = true;
if(!torrent_hashes.contains(event.hash)) {
// New unfinished torrent
2009-11-23 13:35:46 +00:00
torrent_hashes[torrent_hashes.length] = event.hash;
//alert("Inserting row");
myTable.insertRow(event.hash, row);
} else {
// Update torrent data
myTable.updateRow(event.hash, row, event.state);
}
});
2008-12-24 10:05:09 +00:00
// Remove deleted torrents
torrent_hashes.each(function(hash){
if(!events_hashes.contains(hash)) {
myTable.removeRow(hash);
}
});
if(queueing_enabled) {
2008-12-29 22:46:18 +00:00
$('queueingButtons').removeClass('invisible');
myTable.showPriority();
} else {
2008-12-29 22:46:18 +00:00
$('queueingButtons').addClass('invisible');
myTable.hidePriority();
}
}
waiting=false;
ajaxfn.delay(1000);
}
}).send();
}
};
ajaxfn();
// ajaxfn.periodical(5000);
setFilter = function(f) {
// Visually Select the right filter
$("all_filter").removeClass("selectedFilter");
$("downloading_filter").removeClass("selectedFilter");
$("completed_filter").removeClass("selectedFilter");
$("active_filter").removeClass("selectedFilter");
$("inactive_filter").removeClass("selectedFilter");
$(f+"_filter").addClass("selectedFilter");
myTable.setFilter(f);
ajaxfn();
}
});
function closeWindows() {
MochaUI.closeAll();
}
2008-12-23 23:47:30 +00:00
// This runs when a person leaves your page.
window.addEvent('unload', function(){
if (MochaUI) MochaUI.garbageCleanUp();
});
window.addEvent('keydown', function(event){
if (event.key == 'a' && event.control) {
event.stop();
myTable.selectAll();
}
});