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:
|
|
|
|
*
|
|
|
|
* 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();
|
2009-11-23 09:16:32 +00:00
|
|
|
ajaxfn = function(){};
|
2008-12-24 11:28:02 +00:00
|
|
|
|
2008-05-17 12:44:42 +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'
|
|
|
|
});
|
|
|
|
initializeWindows();
|
2008-12-30 11:23:18 +00:00
|
|
|
myTable.setup('myTable', 3);
|
2008-12-24 10:05:09 +00:00
|
|
|
var r=0;
|
|
|
|
var waiting=false;
|
2008-09-28 11:30:24 +00:00
|
|
|
var stateToImg = function(state){
|
|
|
|
switch (state)
|
|
|
|
{
|
2009-11-23 09:16:32 +00:00
|
|
|
case 'pausedUP':
|
|
|
|
case 'pausedDL':
|
2008-09-28 11:30:24 +00:00
|
|
|
return '<img src="images/skin/paused.png"/>';
|
|
|
|
case 'seeding':
|
2009-11-23 09:16:32 +00:00
|
|
|
case 'stalledUP':
|
2008-09-28 11:30:24 +00:00
|
|
|
return '<img src="images/skin/seeding.png"/>';
|
2009-11-23 09:16:32 +00:00
|
|
|
case 'checkingUP':
|
|
|
|
case 'checkingDL':
|
2009-11-08 10:26:39 +00:00
|
|
|
return '<img src="images/oxygen/run-build.png"/>';
|
2008-09-28 11:30:24 +00:00
|
|
|
case 'downloading':
|
|
|
|
return '<img src="images/skin/downloading.png"/>';
|
2009-11-23 09:16:32 +00:00
|
|
|
case 'stalledDL':
|
2008-09-28 11:30:24 +00:00
|
|
|
return '<img src="images/skin/stalled.png"/>';
|
2009-11-23 09:16:32 +00:00
|
|
|
case 'queuedUP':
|
|
|
|
case 'queuedDL':
|
2009-11-08 10:26:39 +00:00
|
|
|
return '<img src="images/oxygen/mail-queue.png"/>';
|
2008-12-30 11:52:22 +00:00
|
|
|
default:
|
|
|
|
return '<img src="images/skin/stalled.png"/>';
|
2008-09-28 11:30:24 +00:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
2008-05-17 12:44:42 +00:00
|
|
|
var round1 = function(val){return Math.round(val*10)/10};
|
|
|
|
var fspeed = function(val){return round1(val/1024) + ' KiB/s';};
|
|
|
|
var fsize = function(val){
|
|
|
|
var units = ['B', 'KiB', 'MiB', 'GiB'];
|
|
|
|
for(var i=0; i<5; i++){
|
|
|
|
if (val < 1024) {
|
|
|
|
return round1(val) + ' ' + units[i];
|
|
|
|
}
|
|
|
|
val /= 1024;
|
|
|
|
}
|
|
|
|
return round1(val) + ' TiB';
|
|
|
|
};
|
|
|
|
var ajaxfn = function(){
|
2008-12-29 22:46:18 +00:00
|
|
|
var queueing_enabled = false;
|
2008-09-28 11:30:24 +00:00
|
|
|
var url = 'json/events';
|
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,
|
2008-05-17 12:44:42 +00:00
|
|
|
method: 'get',
|
2008-12-25 16:20:30 +00:00
|
|
|
onFailure: function() {
|
|
|
|
$('error_div').set('html', 'qBittorrent client is not reachable');
|
|
|
|
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();
|
2008-09-28 11:30:24 +00:00
|
|
|
row.length = 6;
|
|
|
|
row[0] = stateToImg(event.state);
|
|
|
|
row[1] = event.name;
|
2008-09-27 20:31:50 +00:00
|
|
|
row[2] = fsize(event.size);
|
2008-12-30 11:23:18 +00:00
|
|
|
row[3] = round1(event.progress*100);
|
2008-09-27 20:31:50 +00:00
|
|
|
row[4] = fspeed(event.dlspeed);
|
|
|
|
row[5] = fspeed(event.upspeed);
|
2008-12-29 22:46:18 +00:00
|
|
|
row[6] = event.priority
|
|
|
|
if(row[6] != -1)
|
|
|
|
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 09:16:32 +00:00
|
|
|
torrent_hashes[torrent_hashes.length] = event.hash;
|
2008-09-28 11:30:24 +00:00
|
|
|
myTable.insertRow(event.hash, row);
|
|
|
|
} 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;
|
2008-12-26 15:48:07 +00:00
|
|
|
ajaxfn.delay(1000);
|
2008-05-17 12:44:42 +00:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ajaxfn();
|
|
|
|
// ajaxfn.periodical(5000);
|
2009-11-23 09:16:32 +00:00
|
|
|
setFilter = function(f) {
|
|
|
|
myTable.setFilter(f);
|
|
|
|
ajaxfn();
|
|
|
|
}
|
|
|
|
|
2008-05-17 12:44:42 +00:00
|
|
|
});
|
2008-09-28 16:23:08 +00:00
|
|
|
|
2008-12-23 23:47:30 +00:00
|
|
|
// This runs when a person leaves your page.
|
|
|
|
|
|
|
|
window.addEvent('unload', function(){
|
|
|
|
if (MochaUI) MochaUI.garbageCleanUp();
|
|
|
|
});
|
|
|
|
|
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();
|
2008-09-28 16:23:08 +00:00
|
|
|
if($("Tab1").hasClass('active')) {
|
|
|
|
myTable.selectAll();
|
|
|
|
} else {
|
|
|
|
myTableUP.selectAll();
|
|
|
|
}
|
|
|
|
}
|
2008-10-27 20:15:17 +00:00
|
|
|
});
|