@ -25,6 +25,9 @@
@@ -25,6 +25,9 @@
myTable = new dynamicTable ( ) ;
var updatePropertiesPanel = function ( ) { } ;
var updateTransferInfo = function ( ) { } ;
var updateTransferList = function ( ) { } ;
var alternativeSpeedsLimit = false ;
var stateToImg = function ( state ) {
if ( state == "pausedUP" || state == "pausedDL" ) {
@ -43,122 +46,20 @@ var stateToImg = function (state) {
@@ -43,122 +46,20 @@ var stateToImg = function (state) {
filter = getLocalStorageItem ( 'selected_filter' , 'all' ) ;
var loadTorrentsInfoTimer ;
var loadTorrentsInfo = function ( ) {
var queueing _enabled = false ;
var url = new URI ( 'json/torrents' ) ;
url . setData ( 'filter' , filter ) ;
url . setData ( 'sort' , myTable . table . sortedColumn ) ;
url . setData ( 'reverse' , myTable . table . reverseSort ) ;
var request = new Request . JSON ( {
url : url ,
noCache : true ,
method : 'get' ,
onFailure : function ( ) {
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
clearTimeout ( loadTorrentsInfoTimer ) ;
loadTorrentsInfoTimer = loadTorrentsInfo . 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 ( ) ;
pos = 0 ;
events . each ( function ( event ) {
events _hashes [ events _hashes . length ] = event . hash ;
var row = new Array ( ) ;
var data = new Array ( ) ;
row . length = 10 ;
row [ 0 ] = stateToImg ( event . state ) ;
row [ 1 ] = event . name ;
row [ 2 ] = event . priority > - 1 ? event . priority : null ;
data [ 2 ] = event . priority ;
row [ 3 ] = friendlyUnit ( event . size , false ) ;
data [ 3 ] = event . size ;
row [ 4 ] = ( event . progress * 100 ) . round ( 1 ) ;
if ( row [ 4 ] == 100.0 && event . progress != 1.0 )
row [ 4 ] = 99.9 ;
data [ 4 ] = event . progress ;
row [ 5 ] = event . num _seeds ;
if ( event . num _complete != - 1 )
row [ 5 ] += " (" + event . num _complete + ")" ;
data [ 5 ] = event . num _seeds ;
row [ 6 ] = event . num _leechs ;
if ( event . num _incomplete != - 1 )
row [ 6 ] += " (" + event . num _incomplete + ")" ;
data [ 6 ] = event . num _leechs ;
row [ 7 ] = friendlyUnit ( event . dlspeed , true ) ;
data [ 7 ] = event . dlspeed ;
row [ 8 ] = friendlyUnit ( event . upspeed , true ) ;
data [ 8 ] = event . upspeed ;
row [ 9 ] = friendlyDuration ( event . eta ) ;
data [ 9 ] = event . eta ;
if ( event . ratio == - 1 )
row [ 10 ] = "∞" ;
else
row [ 10 ] = ( Math . floor ( 100 * event . ratio ) / 100 ) . toFixed ( 2 ) ; //Don't round up
data [ 10 ] = event . ratio ;
if ( row [ 2 ] != null )
queueing _enabled = true ;
attrs = { } ;
attrs [ 'downloaded' ] = ( event . progress == 1.0 ) ;
attrs [ 'state' ] = event . state ;
attrs [ 'seq_dl' ] = ( event . seq _dl == true ) ;
attrs [ 'f_l_piece_prio' ] = ( event . f _l _piece _prio == true ) ;
if ( ! torrent _hashes . contains ( event . hash ) ) {
// New unfinished torrent
torrent _hashes [ torrent _hashes . length ] = event . hash ;
//alert("Inserting row");
myTable . insertRow ( event . hash , row , data , attrs , pos ) ;
} else {
// Update torrent data
myTable . updateRow ( event . hash , row , data , attrs , pos ) ;
}
pos ++ ;
} ) ;
// Remove deleted torrents
torrent _hashes . each ( function ( hash ) {
if ( ! events _hashes . contains ( hash ) ) {
myTable . removeRow ( hash ) ;
}
} ) ;
if ( queueing _enabled ) {
$ ( 'queueingButtons' ) . removeClass ( 'invisible' ) ;
$ ( 'queueingMenuItems' ) . removeClass ( 'invisible' ) ;
myTable . showPriority ( ) ;
} else {
$ ( 'queueingButtons' ) . addClass ( 'invisible' ) ;
$ ( 'queueingMenuItems' ) . addClass ( 'invisible' ) ;
myTable . hidePriority ( ) ;
}
myTable . altRow ( ) ;
}
clearTimeout ( loadTorrentsInfoTimer ) ;
loadTorrentsInfoTimer = loadTorrentsInfo . delay ( 1500 ) ;
}
} ) . send ( ) ;
} ;
var updateTransferList = function ( ) {
clearTimeout ( loadTorrentsInfoTimer ) ;
loadTorrentsInfo ( ) ;
}
window . addEvent ( 'load' , function ( ) {
var saveColumnSizes = function ( ) {
var filters _width = $ ( 'Filters' ) . getSize ( ) . x ;
var properties _height = $ ( 'propertiesPanel' ) . getSize ( ) . y ;
var properties _height _rel = $ ( 'propertiesPanel' ) . getSize ( ) . y / Window . getSize ( ) . y ;
localStorage . setItem ( 'filters_width' , filters _width ) ;
localStorage . setItem ( 'properties_height' , properties _height ) ;
localStorage . setItem ( 'properties_height_rel' , properties _height _rel ) ;
}
window . addEvent ( 'resize' , function ( ) {
// Resizing might takes some time.
saveColumnSizes . delay ( 200 ) ;
} ) ;
/ * M o c h a U I . D e s k t o p = n e w M o c h a U I . D e s k t o p ( ) ;
MochaUI . Desktop . desktop . setStyles ( {
'background' : '#fff' ,
@ -226,6 +127,113 @@ window.addEvent('load', function () {
@@ -226,6 +127,113 @@ window.addEvent('load', function () {
if ( ! speedInTitle )
$ ( 'speedInBrowserTitleBarLink' ) . firstChild . style . opacity = '0' ;
var loadTorrentsInfoTimer ;
var loadTorrentsInfo = function ( ) {
var queueing _enabled = false ;
var url = new URI ( 'json/torrents' ) ;
url . setData ( 'filter' , filter ) ;
url . setData ( 'sort' , myTable . table . sortedColumn ) ;
url . setData ( 'reverse' , myTable . table . reverseSort ) ;
var request = new Request . JSON ( {
url : url ,
noCache : true ,
method : 'get' ,
onFailure : function ( ) {
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
clearTimeout ( loadTorrentsInfoTimer ) ;
loadTorrentsInfoTimer = loadTorrentsInfo . 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 ( ) ;
pos = 0 ;
events . each ( function ( event ) {
events _hashes [ events _hashes . length ] = event . hash ;
var row = new Array ( ) ;
var data = new Array ( ) ;
row . length = 10 ;
row [ 0 ] = stateToImg ( event . state ) ;
row [ 1 ] = event . name ;
row [ 2 ] = event . priority > - 1 ? event . priority : null ;
data [ 2 ] = event . priority ;
row [ 3 ] = friendlyUnit ( event . size , false ) ;
data [ 3 ] = event . size ;
row [ 4 ] = ( event . progress * 100 ) . round ( 1 ) ;
if ( row [ 4 ] == 100.0 && event . progress != 1.0 )
row [ 4 ] = 99.9 ;
data [ 4 ] = event . progress ;
row [ 5 ] = event . num _seeds ;
if ( event . num _complete != - 1 )
row [ 5 ] += " (" + event . num _complete + ")" ;
data [ 5 ] = event . num _seeds ;
row [ 6 ] = event . num _leechs ;
if ( event . num _incomplete != - 1 )
row [ 6 ] += " (" + event . num _incomplete + ")" ;
data [ 6 ] = event . num _leechs ;
row [ 7 ] = friendlyUnit ( event . dlspeed , true ) ;
data [ 7 ] = event . dlspeed ;
row [ 8 ] = friendlyUnit ( event . upspeed , true ) ;
data [ 8 ] = event . upspeed ;
row [ 9 ] = friendlyDuration ( event . eta ) ;
data [ 9 ] = event . eta ;
if ( event . ratio == - 1 )
row [ 10 ] = "∞" ;
else
row [ 10 ] = ( Math . floor ( 100 * event . ratio ) / 100 ) . toFixed ( 2 ) ; //Don't round up
data [ 10 ] = event . ratio ;
if ( row [ 2 ] != null )
queueing _enabled = true ;
attrs = { } ;
attrs [ 'downloaded' ] = ( event . progress == 1.0 ) ;
attrs [ 'state' ] = event . state ;
attrs [ 'seq_dl' ] = ( event . seq _dl == true ) ;
attrs [ 'f_l_piece_prio' ] = ( event . f _l _piece _prio == true ) ;
if ( ! torrent _hashes . contains ( event . hash ) ) {
// New unfinished torrent
torrent _hashes [ torrent _hashes . length ] = event . hash ;
//alert("Inserting row");
myTable . insertRow ( event . hash , row , data , attrs , pos ) ;
} else {
// Update torrent data
myTable . updateRow ( event . hash , row , data , attrs , pos ) ;
}
pos ++ ;
} ) ;
// Remove deleted torrents
torrent _hashes . each ( function ( hash ) {
if ( ! events _hashes . contains ( hash ) ) {
myTable . removeRow ( hash ) ;
}
} ) ;
if ( queueing _enabled ) {
$ ( 'queueingButtons' ) . removeClass ( 'invisible' ) ;
$ ( 'queueingMenuItems' ) . removeClass ( 'invisible' ) ;
myTable . showPriority ( ) ;
} else {
$ ( 'queueingButtons' ) . addClass ( 'invisible' ) ;
$ ( 'queueingMenuItems' ) . addClass ( 'invisible' ) ;
myTable . hidePriority ( ) ;
}
myTable . altRow ( ) ;
}
clearTimeout ( loadTorrentsInfoTimer ) ;
loadTorrentsInfoTimer = loadTorrentsInfo . delay ( 1500 ) ;
}
} ) . send ( ) ;
} ;
updateTransferList = function ( ) {
clearTimeout ( loadTorrentsInfoTimer ) ;
loadTorrentsInfo ( ) ;
}
var loadTransferInfoTimer ;
var loadTransferInfo = function ( ) {
var url = 'json/transferInfo' ;
@ -240,24 +248,29 @@ window.addEvent('load', function () {
@@ -240,24 +248,29 @@ window.addEvent('load', function () {
} ,
onSuccess : function ( info ) {
if ( info ) {
dl _limit = "" ;
var transfer _info = "" ;
if ( info . dl _rate _limit != undefined )
dl _limit = "[%1] " . replace ( "%1" , friendlyUnit ( info . dl _rate _limit , true ) ) ;
$ ( "DlInfos" ) . set ( 'html' , "%3_(D: %1 - T: %2)"
. replace ( "%1" , friendlyUnit ( info . dl _info _speed , true ) )
. replace ( "%2" , friendlyUnit ( info . dl _info _data , false ) )
. replace ( "%3" , dl _limit ) ) ;
up _limit = "" ;
transfer _info += "[" + friendlyUnit ( info . dl _rate _limit , true ) + "] " ;
transfer _info += friendlyUnit ( info . dl _info _speed , true ) ;
transfer _info += " (" + friendlyUnit ( info . dl _info _data , false ) + ")"
$ ( "DlInfos" ) . set ( 'html' , transfer _info ) ;
transfer _info = "" ;
if ( info . up _rate _limit != undefined )
up _limit = "[%1] " . replace ( "%1" , friendlyUnit ( info . up _rate _limit , true ) ) ;
$ ( "UpInfos" ) . set ( 'html' , "%3_(U: %1 - T: %2)"
. replace ( "%1" , friendlyUnit ( info . up _info _speed , true ) )
. replace ( "%2" , friendlyUnit ( info . up _info _data , false ) )
. replace ( "%3" , up _limit ) ) ;
transfer _info += "[" + friendlyUnit ( info . up _rate _limit , true ) + "] " ;
transfer _info += friendlyUnit ( info . up _info _speed , true )
transfer _info += " (" + friendlyUnit ( info . up _info _data , false ) + ")"
$ ( "UpInfos" ) . set ( 'html' , transfer _info ) ;
if ( speedInTitle )
document . title = "_(D:%1 U:%2)" . replace ( "%1" , friendlyUnit ( info . dl _info _speed , true ) ) . replace ( "%2" , friendlyUnit ( info . up _info _speed , true ) ) ;
else
document . title = "_(qBittorrent web User Interface)" ;
$ ( 'DHTNodes' ) . set ( 'html' , '_(DHT: %1 nodes)' . replace ( "%1" , info . dht _nodes ) ) ;
if ( info . connection _status == "connected" )
$ ( 'connectionStatus' ) . src = 'images/skin/connected.png' ;
else if ( info . connection _status == "firewalled" )
$ ( 'connectionStatus' ) . src = 'images/skin/firewalled.png' ;
else
$ ( 'connectionStatus' ) . src = 'images/skin/disconnected.png' ;
clearTimeout ( loadTransferInfoTimer ) ;
loadTransferInfoTimer = loadTransferInfo . delay ( 3000 ) ;
}
@ -265,7 +278,7 @@ window.addEvent('load', function () {
@@ -265,7 +278,7 @@ window.addEvent('load', function () {
} ) . send ( ) ;
} ;
var updateTransferInfo = function ( ) {
updateTransferInfo = function ( ) {
clearTimeout ( loadTransferInfoTimer ) ;
loadTransferInfo ( ) ;
}
@ -273,6 +286,40 @@ window.addEvent('load', function () {
@@ -273,6 +286,40 @@ window.addEvent('load', function () {
// Start fetching data now
loadTransferInfo ( ) ;
var updateAltSpeedIcon = function ( enabled ) {
if ( enabled )
$ ( 'alternativeSpeedLimits' ) . src = "images/slow.png" ;
else
$ ( 'alternativeSpeedLimits' ) . src = "images/slow_off.png"
}
// Determine whether the alternative speed limits are enabled or not
new Request ( { url : 'command/alternativeSpeedLimitsEnabled' ,
method : 'get' ,
onSuccess : function ( isEnabled ) {
alternativeSpeedsLimit = ! ! isEnabled ;
if ( alternativeSpeedsLimit )
$ ( 'alternativeSpeedLimits' ) . src = "images/slow.png"
}
} ) . send ( ) ;
$ ( 'alternativeSpeedLimits' ) . addEvent ( 'click' , function ( ) {
// Change icon immediately to give some feedback
updateAltSpeedIcon ( ! alternativeSpeedsLimit ) ;
new Request ( { url : 'command/toggleAlternativeSpeedLimits' ,
method : 'post' ,
onComplete : function ( ) {
alternativeSpeedsLimit = ! alternativeSpeedsLimit ;
updateTransferInfo ( ) ;
} ,
onFailure : function ( ) {
// Restore icon in case of failure
updateAltSpeedIcon ( alternativeSpeedsLimit )
}
} ) . send ( ) ;
} ) ;
$ ( 'DlInfos' ) . addEvent ( 'click' , globalDownloadLimitFN ) ;
$ ( 'UpInfos' ) . addEvent ( 'click' , globalUploadLimitFN ) ;
@ -310,9 +357,9 @@ window.addEvent('load', function () {
@@ -310,9 +357,9 @@ window.addEvent('load', function () {
onResize : saveColumnSizes ,
height : null
} ) ;
var prop _h = localStorage . getItem ( 'properties_height' ) ;
var prop _h = localStorage . getItem ( 'properties_height_rel ' ) ;
if ( $defined ( prop _h ) )
prop _h = prop _h . toInt ( ) ;
prop _h = prop _h . toFloat ( ) * Window . getSize ( ) . y ;
else
prop _h = Window . getSize ( ) . y / 2. ;
new MochaUI . Panel ( {