@ -23,7 +23,6 @@
* /
* /
myTable = new dynamicTable ( ) ;
myTable = new dynamicTable ( ) ;
ajaxfn = function ( ) { } ;
window . addEvent ( 'load' , function ( ) {
window . addEvent ( 'load' , function ( ) {
@ -77,8 +76,6 @@ window.addEvent('load', function () {
} ) ;
} ) ;
initializeWindows ( ) ;
initializeWindows ( ) ;
var r = 0 ;
var r = 0 ;
var waiting = false ;
var waitingTrInfo = false ;
var stateToImg = function ( state ) {
var stateToImg = function ( state ) {
if ( state == "pausedUP" || state == "pausedDL" ) {
if ( state == "pausedUP" || state == "pausedDL" ) {
@ -94,140 +91,146 @@ window.addEvent('load', function () {
}
}
return 'images/skin/' + state + '.png' ;
return 'images/skin/' + state + '.png' ;
} ;
} ;
var loadTransferInfoTimer ;
var loadTransferInfo = function ( ) {
var loadTransferInfo = function ( ) {
var url = 'json/transferInfo' ;
var url = 'json/transferInfo' ;
if ( ! waitingTrInfo ) {
var request = new Request . JSON ( {
waitingTrInfo = true ;
url : url ,
var request = new Request . JSON ( {
noCache : true ,
url : url ,
method : 'get' ,
noCache : true ,
onFailure : function ( ) {
method : 'get' ,
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
onFailure : function ( ) {
loadTransferInfoTimer = loadTransferInfo . delay ( 4000 ) ;
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
} ,
waitingTrInfo = false ;
onSuccess : function ( info ) {
loadTransferInfo . delay ( 4000 ) ;
if ( info ) {
} ,
$ ( "DlInfos" ) . set ( 'html' , "_(D: %1 - T: %2)"
onSuccess : function ( info ) {
. replace ( "%1" , friendlyUnit ( info . dl _info _speed , true ) )
if ( info ) {
. replace ( "%2" , friendlyUnit ( info . dl _info _data , false ) ) ) ;
$ ( "DlInfos" ) . set ( 'html' , "_(D: %1 - T: %2)"
$ ( "UpInfos" ) . set ( 'html' , "_(U: %1 - T: %2)"
. replace ( "%1" , friendlyUnit ( info . dl _info _speed , true ) )
. replace ( "%1" , friendlyUnit ( info . up _info _speed , true ) )
. replace ( "%2" , friendlyUnit ( info . dl _info _data , false ) ) ) ;
. replace ( "%2" , friendlyUnit ( info . up _info _data , false ) ) ) ;
$ ( "UpInfos" ) . set ( 'html' , "_(U: %1 - T: %2)"
if ( localStorage . getItem ( 'speed_in_browser_title_bar' ) == 'true' )
. replace ( "%1" , friendlyUnit ( info . up _info _speed , true ) )
document . title = "_(D:%1 U:%2)" . replace ( "%1" , friendlyUnit ( info . dl _info _speed , true ) ) . replace ( "%2" , friendlyUnit ( info . up _info _speed , true ) ) ;
. replace ( "%2" , friendlyUnit ( info . up _info _data , false ) ) ) ;
else
if ( localStorage . getItem ( 'speed_in_browser_title_bar' ) == 'true' )
document . title = "_(qBittorrent web User Interface)" ;
document . title = "_(D:%1 U:%2)" . replace ( "%1" , friendlyUnit ( info . dl _info _speed , true ) ) . replace ( "%2" , friendlyUnit ( info . up _info _speed , true ) ) ;
loadTransferInfoTimer = loadTransferInfo . delay ( 3000 ) ;
else
}
document . title = "_(qBittorrent web User Interface)" ;
}
waitingTrInfo = false ;
} ) . send ( ) ;
loadTransferInfo . delay ( 3000 ) ;
}
}
} ) . send ( ) ;
}
} ;
} ;
var updateTransferInfo = function ( ) {
clearTimeout ( loadTransferInfoTimer ) ;
loadTransferInfoTimer = loadTransferInfo ( ) ;
}
// Start fetching data now
loadTransferInfo ( ) ;
$ ( 'DlInfos' ) . addEvent ( 'click' , globalDownloadLimitFN ) ;
$ ( 'DlInfos' ) . addEvent ( 'click' , globalDownloadLimitFN ) ;
$ ( 'UpInfos' ) . addEvent ( 'click' , globalUploadLimitFN ) ;
$ ( 'UpInfos' ) . addEvent ( 'click' , globalUploadLimitFN ) ;
var ajaxfnTimer ;
var ajaxfn = function ( ) {
var ajaxfn = function ( ) {
var queueing _enabled = false ;
var queueing _enabled = false ;
var url = new URI ( 'json/torrents' ) ;
var url = new URI ( 'json/torrents' ) ;
url . setData ( 'filter' , filter ) ;
url . setData ( 'filter' , filter ) ;
url . setData ( 'sort' , myTable . table . sortedColumn ) ;
url . setData ( 'sort' , myTable . table . sortedColumn ) ;
url . setData ( 'reverse' , myTable . table . reverseSort ) ;
url . setData ( 'reverse' , myTable . table . reverseSort ) ;
if ( ! waiting ) {
var request = new Request . JSON ( {
waiting = true ;
url : url ,
var request = new Request . JSON ( {
noCache : true ,
url : url ,
method : 'get' ,
noCache : true ,
onFailure : function ( ) {
method : 'get' ,
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
onFailure : function ( ) {
ajaxfnTimer = ajaxfn . delay ( 2000 ) ;
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
} ,
waiting = false ;
onSuccess : function ( events ) {
ajaxfn . delay ( 2000 ) ;
$ ( 'error_div' ) . set ( 'html' , '' ) ;
} ,
if ( events ) {
onSuccess : function ( events ) {
// Add new torrents or update them
$ ( 'error_div' ) . set ( 'html' , '' ) ;
torrent _hashes = myTable . getRowIds ( ) ;
if ( events ) {
events _hashes = new Array ( ) ;
// Add new torrents or update them
pos = 0 ;
torrent _hashes = myTable . getRowIds ( ) ;
events . each ( function ( event ) {
events _hashes = new Array ( ) ;
events _hashes [ events _hashes . length ] = event . hash ;
pos = 0 ;
var row = new Array ( ) ;
events . each ( function ( event ) {
var data = new Array ( ) ;
events _hashes [ events _hashes . length ] = event . hash ;
row . length = 10 ;
var row = new Array ( ) ;
row [ 0 ] = stateToImg ( event . state ) ;
var data = new Array ( ) ;
row [ 1 ] = event . name ;
row . length = 10 ;
row [ 2 ] = event . priority > - 1 ? event . priority : null ;
row [ 0 ] = stateToImg ( event . state ) ;
data [ 2 ] = event . priority ;
row [ 1 ] = event . name ;
row [ 3 ] = friendlyUnit ( event . size , false ) ;
row [ 2 ] = event . priority > - 1 ? event . priority : null ;
data [ 3 ] = event . size ;
data [ 2 ] = event . priority ;
row [ 4 ] = ( event . progress * 100 ) . round ( 1 ) ;
row [ 3 ] = friendlyUnit ( event . size , false ) ;
if ( row [ 4 ] == 100.0 && event . progress != 1.0 )
data [ 3 ] = event . size ;
row [ 4 ] = 99.9 ;
row [ 4 ] = ( event . progress * 100 ) . round ( 1 ) ;
data [ 4 ] = event . progress ;
if ( row [ 4 ] == 100.0 && event . progress != 1.0 )
row [ 5 ] = event . num _seeds ;
row [ 4 ] = 99.9 ;
if ( event . num _complete != - 1 )
data [ 4 ] = event . progress ;
row [ 5 ] += " (" + event . num _complete + ")" ;
row [ 5 ] = event . num _seeds ;
data [ 5 ] = event . num _seeds ;
if ( event . num _complete != - 1 )
row [ 6 ] = event . num _leechs ;
row [ 5 ] += " (" + event . num _complete + ")" ;
if ( event . num _incomplete != - 1 )
data [ 5 ] = event . num _seeds ;
row [ 6 ] += " (" + event . num _incomplete + ")" ;
row [ 6 ] = event . num _leechs ;
data [ 6 ] = event . num _leechs ;
if ( event . num _incomplete != - 1 )
row [ 7 ] = friendlyUnit ( event . dlspeed , true ) ;
row [ 6 ] += " (" + event . num _incomplete + ")" ;
data [ 7 ] = event . dlspeed ;
data [ 6 ] = event . num _leechs ;
row [ 8 ] = friendlyUnit ( event . upspeed , true ) ;
row [ 7 ] = friendlyUnit ( event . dlspeed , true ) ;
data [ 8 ] = event . upspeed ;
data [ 7 ] = event . dlspeed ;
row [ 9 ] = friendlyDuration ( event . eta ) ;
row [ 8 ] = friendlyUnit ( event . upspeed , true ) ;
data [ 9 ] = event . eta ;
data [ 8 ] = event . upspeed ;
if ( event . ratio == - 1 )
row [ 9 ] = friendlyDuration ( event . eta ) ;
row [ 10 ] = "∞" ;
data [ 9 ] = event . eta ;
else
if ( event . ratio == - 1 )
row [ 10 ] = ( Math . floor ( 100 * event . ratio ) / 100 ) . toFixed ( 2 ) ; //Don't round up
row [ 10 ] = "∞" ;
data [ 10 ] = event . ratio ;
else
if ( row [ 2 ] != null )
row [ 10 ] = ( Math . floor ( 100 * event . ratio ) / 100 ) . toFixed ( 2 ) ; //Don't round up
queueing _enabled = true ;
data [ 10 ] = event . ratio ;
if ( ! torrent _hashes . contains ( event . hash ) ) {
if ( row [ 2 ] != null )
// New unfinished torrent
queueing _enabled = true ;
torrent _hashes [ torrent _hashes . length ] = event . hash ;
if ( ! torrent _hashes . contains ( event . hash ) ) {
//alert("Inserting row");
// New unfinished torrent
myTable . insertRow ( event . hash , row , data , event . state , pos ) ;
torrent _hashes [ torrent _hashes . length ] = event . hash ;
} else {
//alert("Inserting row");
// Update torrent data
myTable . insertRow ( event . hash , row , data , event . state , pos ) ;
myTable . updateRow ( event . hash , row , data , event . state , pos ) ;
} else {
}
// Update torrent data
myTable . updateRow ( event . hash , row , data , event . state , pos ) ;
pos ++ ;
}
} ) ;
// Remove deleted torrents
pos ++ ;
torrent _hashes . each ( function ( hash ) {
} ) ;
if ( ! events _hashes . contains ( hash ) ) {
// Remove deleted torrents
myTable . removeRow ( hash ) ;
torrent _hashes . each ( function ( hash ) {
if ( ! events _hashes . contains ( hash ) ) {
myTable . removeRow ( hash ) ;
}
} ) ;
if ( queueing _enabled ) {
$ ( 'queueingButtons' ) . removeClass ( 'invisible' ) ;
myTable . showPriority ( ) ;
} else {
$ ( 'queueingButtons' ) . addClass ( 'invisible' ) ;
myTable . hidePriority ( ) ;
}
myTable . altRow ( ) ;
}
}
waiting = false ;
} ) ;
ajaxfn . delay ( 1500 ) ;
if ( queueing _enabled ) {
$ ( 'queueingButtons' ) . removeClass ( 'invisible' ) ;
myTable . showPriority ( ) ;
} else {
$ ( 'queueingButtons' ) . addClass ( 'invisible' ) ;
myTable . hidePriority ( ) ;
}
}
} ) . send ( ) ;
}
myTable . altRow ( ) ;
}
ajaxfnTimer = ajaxfn . delay ( 1500 ) ;
}
} ) . send ( ) ;
} ;
} ;
var updateTransferList = function ( ) {
clearTimeout ( ajaxfnTimer ) ;
ajaxfnTimer = ajaxfn ( ) ;
}
setSortedColumn = function ( column ) {
setSortedColumn = function ( column ) {
myTable . setSortedColumn ( column ) ;
myTable . setSortedColumn ( column ) ;
// reload torrents
updateTransferList ( ) ;
ajaxfn ( ) ;
} ;
} ;
new MochaUI . Panel ( {
new MochaUI . Panel ( {
@ -243,7 +246,7 @@ window.addEvent('load', function () {
loadMethod : 'xhr' ,
loadMethod : 'xhr' ,
contentURL : 'transferlist.html' ,
contentURL : 'transferlist.html' ,
onContentLoaded : function ( ) {
onContentLoaded : function ( ) {
ajaxfn ( ) ;
updateTransferList ( ) ;
} ,
} ,
column : 'mainColumn' ,
column : 'mainColumn' ,
onResize : saveColumnSizes ,
onResize : saveColumnSizes ,
@ -272,8 +275,6 @@ window.addEvent('load', function () {
column : 'mainColumn' ,
column : 'mainColumn' ,
height : prop _h
height : prop _h
} ) ;
} ) ;
//ajaxfn();
loadTransferInfo ( ) ;
setFilter = function ( f ) {
setFilter = function ( f ) {
// Visually Select the right filter
// Visually Select the right filter
@ -287,7 +288,7 @@ window.addEvent('load', function () {
filter = f ;
filter = f ;
localStorage . setItem ( 'selected_filter' , f ) ;
localStorage . setItem ( 'selected_filter' , f ) ;
// Reload torrents
// Reload torrents
ajaxfn ( ) ;
updateTransferList ( ) ;
}
}
} ) ;
} ) ;