2011-08-16 18:49:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright © Jordan Lee
|
|
|
|
* This code is licensed under the GPL version 2.
|
|
|
|
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
function TorrentRendererHelper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TorrentRendererHelper.getProgressInfo = function( controller, t )
|
|
|
|
{
|
|
|
|
var seed_ratio_limit = t.seedRatioLimit( controller );
|
|
|
|
|
|
|
|
var pct = 0;
|
|
|
|
if( t.needsMetaData( ) )
|
2011-08-20 21:17:12 +00:00
|
|
|
pct = t.getMetadataPercentComplete() * 100;
|
2011-08-16 18:49:26 +00:00
|
|
|
else if( !t.isDone( ) )
|
|
|
|
pct = Math.round( t.getPercentDone() * 100 );
|
|
|
|
else if( seed_ratio_limit > 0 )
|
2011-08-20 21:17:12 +00:00
|
|
|
pct = Math.round( t.getUploadRatio() * 100 / seed_ratio_limit );
|
2011-08-16 18:49:26 +00:00
|
|
|
else
|
|
|
|
pct = 100;
|
|
|
|
|
|
|
|
var extra;
|
|
|
|
if( t.isStopped( ) )
|
|
|
|
extra = 'paused';
|
|
|
|
else if( t.isSeeding( ) )
|
|
|
|
extra = 'seeding';
|
|
|
|
else if( t.needsMetaData( ) )
|
|
|
|
extra = 'magnet';
|
|
|
|
else
|
|
|
|
extra = 'leeching';
|
|
|
|
|
|
|
|
return {
|
|
|
|
percent: pct,
|
|
|
|
complete: [ 'torrent_progress_bar', 'complete', extra ].join(' '),
|
|
|
|
incomplete: [ 'torrent_progress_bar', 'incomplete', extra ].join(' ')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-08-20 15:31:34 +00:00
|
|
|
TorrentRendererHelper.createProgressbar = function( classes )
|
|
|
|
{
|
|
|
|
var complete = document.createElement( 'div' );
|
|
|
|
complete.className = 'torrent_progress_bar complete';
|
|
|
|
var incomplete = document.createElement( 'div' );
|
|
|
|
incomplete.className = 'torrent_progress_bar incomplete';
|
|
|
|
var progressbar = document.createElement( 'div' );
|
|
|
|
progressbar.className = 'torrent_progress_bar_container ' + classes;
|
|
|
|
progressbar.appendChild( complete );
|
|
|
|
progressbar.appendChild( incomplete );
|
|
|
|
return { 'element': progressbar, 'complete': complete, 'incomplete': incomplete }
|
|
|
|
}
|
|
|
|
|
|
|
|
TorrentRendererHelper.renderProgressbar = function( controller, t, progressbar )
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
var info = TorrentRendererHelper.getProgressInfo( controller, t );
|
|
|
|
var e;
|
2011-08-20 15:31:34 +00:00
|
|
|
e = progressbar.complete;
|
2011-08-16 18:49:26 +00:00
|
|
|
e.style.width = '' + info.percent + "%";
|
|
|
|
e.className = info.complete;
|
|
|
|
e.style.display = info.percent<=0 ? 'none' : 'block';
|
2011-08-20 15:31:34 +00:00
|
|
|
e = progressbar.incomplete;
|
2011-08-16 18:49:26 +00:00
|
|
|
e.className = info.incomplete;
|
|
|
|
e.style.display = info.percent>=100 ? 'none' : 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
TorrentRendererHelper.formatUL = function( t )
|
|
|
|
{
|
2011-08-20 21:17:12 +00:00
|
|
|
return 'UL: ' + Transmission.fmt.speedBps( t.getUploadSpeed( ) );
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TorrentRendererHelper.formatDL = function( t )
|
|
|
|
{
|
2011-08-20 21:17:12 +00:00
|
|
|
return 'DL: ' + Transmission.fmt.speedBps( t.getDownloadSpeed( ) );
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
function TorrentRendererFull()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
TorrentRendererFull.prototype =
|
|
|
|
{
|
|
|
|
createRow: function( )
|
|
|
|
{
|
|
|
|
var root = document.createElement( 'li' );
|
|
|
|
root.className = 'torrent';
|
|
|
|
|
|
|
|
var name = document.createElement( 'div' );
|
|
|
|
name.className = 'torrent_name';
|
|
|
|
|
|
|
|
var peers = document.createElement( 'div' );
|
|
|
|
peers.className = 'torrent_peer_details';
|
|
|
|
|
2011-08-20 15:31:34 +00:00
|
|
|
var progressbar = TorrentRendererHelper.createProgressbar( 'full' );
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
var details = document.createElement( 'div' );
|
|
|
|
details.className = 'torrent_progress_details';
|
|
|
|
|
|
|
|
var image = document.createElement( 'div' );
|
|
|
|
var button = document.createElement( 'a' );
|
|
|
|
button.appendChild( image );
|
|
|
|
|
|
|
|
root.appendChild( name );
|
|
|
|
root.appendChild( peers );
|
|
|
|
root.appendChild( button );
|
2011-08-20 15:31:34 +00:00
|
|
|
root.appendChild( progressbar.element );
|
2011-08-16 18:49:26 +00:00
|
|
|
root.appendChild( details );
|
|
|
|
|
|
|
|
root._name_container = name;
|
|
|
|
root._peer_details_container = peers;
|
|
|
|
root._progress_details_container = details;
|
2011-08-20 15:31:34 +00:00
|
|
|
root._progressbar = progressbar;
|
2011-08-16 18:49:26 +00:00
|
|
|
root._pause_resume_button_image = image;
|
|
|
|
root._toggle_running_button = button;
|
|
|
|
|
|
|
|
return root;
|
|
|
|
},
|
|
|
|
|
|
|
|
getPeerDetails: function( t )
|
|
|
|
{
|
|
|
|
var err;
|
|
|
|
if(( err = t.getErrorMessage()))
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if( t.isDownloading( ) )
|
|
|
|
return [ 'Downloading from',
|
2011-08-20 21:17:12 +00:00
|
|
|
t.getPeersSendingToUs(),
|
2011-08-16 18:49:26 +00:00
|
|
|
'of',
|
2011-08-20 21:17:12 +00:00
|
|
|
t.getPeersConnected(),
|
2011-08-16 18:49:26 +00:00
|
|
|
'peers',
|
|
|
|
'-',
|
|
|
|
TorrentRendererHelper.formatDL(t),
|
|
|
|
TorrentRendererHelper.formatUL(t) ].join(' ');
|
|
|
|
|
|
|
|
if( t.isSeeding( ) )
|
|
|
|
return [ 'Seeding to',
|
2011-08-20 21:17:12 +00:00
|
|
|
t.getPeersGettingFromUs(),
|
2011-08-16 18:49:26 +00:00
|
|
|
'of',
|
2011-08-20 21:17:12 +00:00
|
|
|
t.getPeersConnected(),
|
2011-08-16 18:49:26 +00:00
|
|
|
'peers',
|
|
|
|
'-',
|
|
|
|
TorrentRendererHelper.formatUL(t) ].join(' ');
|
|
|
|
|
2011-08-20 21:17:12 +00:00
|
|
|
if( t.isChecking( ) )
|
2011-08-16 18:49:26 +00:00
|
|
|
return [ 'Verifying local data (',
|
2011-08-20 21:17:12 +00:00
|
|
|
Transmission.fmt.percentString( 100.0 * t.getRecheckProgress() ),
|
2011-08-16 18:49:26 +00:00
|
|
|
'% tested)' ].join('');
|
|
|
|
|
2011-08-20 21:17:12 +00:00
|
|
|
return t.getStateString( );
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getProgressDetails: function( controller, t )
|
|
|
|
{
|
|
|
|
if( t.needsMetaData() ) {
|
2011-08-20 21:17:12 +00:00
|
|
|
var percent = 100 * t.getMetadataPercentComplete();
|
2011-08-16 18:49:26 +00:00
|
|
|
return [ "Magnetized transfer - retrieving metadata (",
|
|
|
|
Transmission.fmt.percentString( percent ),
|
|
|
|
"%)" ].join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
var c;
|
2011-08-20 21:17:12 +00:00
|
|
|
var sizeWhenDone = t.getSizeWhenDone()
|
|
|
|
var totalSize = t.getTotalSize()
|
|
|
|
var is_done = ( t.isDone( ) ) || ( t.isSeeding() )
|
|
|
|
|
2011-08-16 18:49:26 +00:00
|
|
|
if( is_done ) {
|
2011-08-20 21:17:12 +00:00
|
|
|
if( totalSize == sizeWhenDone ) // seed: '698.05 MiB'
|
|
|
|
c = [ Transmission.fmt.size( totalSize ) ];
|
2011-08-16 18:49:26 +00:00
|
|
|
else // partial seed: '127.21 MiB of 698.05 MiB (18.2%)'
|
2011-08-20 21:17:12 +00:00
|
|
|
c = [ Transmission.fmt.size( sizeWhenDone ),
|
2011-08-16 18:49:26 +00:00
|
|
|
' of ',
|
2011-08-20 21:17:12 +00:00
|
|
|
Transmission.fmt.size( t.getTotalSize() ),
|
2011-08-16 18:49:26 +00:00
|
|
|
' (', t.getPercentDoneStr, '%)' ];
|
|
|
|
// append UL stats: ', uploaded 8.59 GiB (Ratio: 12.3)'
|
|
|
|
c.push( ', uploaded ',
|
2011-08-20 21:17:12 +00:00
|
|
|
Transmission.fmt.size( t.getUploadedEver() ),
|
2011-08-16 18:49:26 +00:00
|
|
|
' (Ratio ',
|
2011-08-20 21:17:12 +00:00
|
|
|
Transmission.fmt.ratioString( t.getUploadRatio() ),
|
2011-08-16 18:49:26 +00:00
|
|
|
')' );
|
|
|
|
} else { // not done yet
|
2011-08-20 21:17:12 +00:00
|
|
|
c = [ Transmission.fmt.size( sizeWhenDone - t.getLeftUntilDone() ),
|
|
|
|
' of ', Transmission.fmt.size( sizeWhenDone ),
|
2011-08-16 18:49:26 +00:00
|
|
|
' (', t.getPercentDoneStr(), '%)' ];
|
|
|
|
}
|
|
|
|
|
|
|
|
// maybe append eta
|
2011-08-20 21:17:12 +00:00
|
|
|
if( !t.isStopped() && ( !is_done || t.seedRatioLimit(controller)>0 ) ) {
|
2011-08-16 18:49:26 +00:00
|
|
|
c.push(' - ');
|
2011-08-20 21:17:12 +00:00
|
|
|
var eta = t.getETA()
|
|
|
|
if (eta < 0 || eta >= (999*60*60) /* arbitrary */ )
|
2011-08-16 18:49:26 +00:00
|
|
|
c.push( 'remaining time unknown' );
|
|
|
|
else
|
2011-08-20 21:17:12 +00:00
|
|
|
c.push( Transmission.fmt.timeInterval(t.getETA()),
|
2011-08-16 18:49:26 +00:00
|
|
|
' remaining' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.join('');
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function( controller, t, root )
|
|
|
|
{
|
|
|
|
// name
|
2011-08-20 21:17:12 +00:00
|
|
|
setInnerHTML( root._name_container, t.getName() );
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
// progressbar
|
2011-08-20 15:31:34 +00:00
|
|
|
TorrentRendererHelper.renderProgressbar( controller, t, root._progressbar );
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
// peer details
|
2011-08-20 21:17:12 +00:00
|
|
|
var has_error = t.getError() !== Torrent._ErrNone;
|
2011-08-16 18:49:26 +00:00
|
|
|
var e = root._peer_details_container;
|
|
|
|
$(e).toggleClass('error',has_error);
|
|
|
|
setInnerHTML( e, this.getPeerDetails( t ) );
|
|
|
|
|
|
|
|
// progress details
|
|
|
|
e = root._progress_details_container;
|
|
|
|
setInnerHTML( e, this.getProgressDetails( controller, t ) );
|
|
|
|
|
|
|
|
// pause/resume button
|
2011-08-20 21:17:12 +00:00
|
|
|
var is_stopped = t.isStopped()
|
|
|
|
e = root._pause_resume_button_image
|
|
|
|
e.alt = is_stopped ? 'Resume' : 'Pause'
|
|
|
|
e.className = is_stopped ? 'torrent_resume' : 'torrent_pause'
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
function TorrentRendererCompact()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
TorrentRendererCompact.prototype =
|
|
|
|
{
|
|
|
|
createRow: function( )
|
|
|
|
{
|
2011-08-20 15:31:34 +00:00
|
|
|
var progressbar = TorrentRendererHelper.createProgressbar( 'compact' );
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
var details = document.createElement( 'div' );
|
|
|
|
details.className = 'torrent_peer_details compact';
|
|
|
|
|
|
|
|
var name = document.createElement( 'div' );
|
|
|
|
name.className = 'torrent_name';
|
|
|
|
|
|
|
|
var root = document.createElement( 'li' );
|
2011-08-20 15:31:34 +00:00
|
|
|
root.appendChild( progressbar.element );
|
2011-08-16 18:49:26 +00:00
|
|
|
root.appendChild( details );
|
|
|
|
root.appendChild( name );
|
|
|
|
root.className = 'torrent compact';
|
2011-08-20 15:31:34 +00:00
|
|
|
root._progressbar = progressbar;
|
2011-08-16 18:49:26 +00:00
|
|
|
root._details_container = details;
|
|
|
|
root._name_container = name;
|
|
|
|
return root;
|
|
|
|
},
|
|
|
|
|
|
|
|
getPeerDetails: function( t )
|
|
|
|
{
|
|
|
|
var c;
|
|
|
|
if(( c = t.getErrorMessage()))
|
|
|
|
return c;
|
|
|
|
if( t.isDownloading( ) )
|
|
|
|
return [ TorrentRendererHelper.formatDL(t),
|
|
|
|
TorrentRendererHelper.formatUL(t) ].join(' ');
|
|
|
|
if( t.isSeeding( ) )
|
|
|
|
return TorrentRendererHelper.formatUL(t);
|
2011-08-20 21:17:12 +00:00
|
|
|
return t.getStateString( );
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function( controller, t, root )
|
|
|
|
{
|
|
|
|
// name
|
2011-08-20 21:17:12 +00:00
|
|
|
var is_stopped = t.isStopped()
|
2011-08-16 18:49:26 +00:00
|
|
|
var e = root._name_container;
|
|
|
|
$(e).toggleClass( 'paused', is_stopped );
|
2011-08-20 21:17:12 +00:00
|
|
|
setInnerHTML( e, t.getName() );
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
// peer details
|
2011-08-20 21:17:12 +00:00
|
|
|
var has_error = t.getError() !== Torrent._ErrNone;
|
2011-08-16 18:49:26 +00:00
|
|
|
e = root._details_container;
|
|
|
|
$(e).toggleClass('error', has_error );
|
|
|
|
setInnerHTML( e, this.getPeerDetails( t ) );
|
|
|
|
|
|
|
|
// progressbar
|
2011-08-20 15:31:34 +00:00
|
|
|
TorrentRendererHelper.renderProgressbar( controller, t, root._progressbar );
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2011-08-20 15:31:34 +00:00
|
|
|
function TorrentRow( view )
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
2011-08-20 15:31:34 +00:00
|
|
|
this.initialize( view );
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
TorrentRow.prototype =
|
|
|
|
{
|
2011-08-20 15:31:34 +00:00
|
|
|
initialize: function( view ) {
|
|
|
|
this._view = view;
|
|
|
|
this._element = view.createRow( );
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
getElement: function( ) {
|
|
|
|
return this._element;
|
|
|
|
},
|
|
|
|
render: function( controller ) {
|
|
|
|
var tor = this.getTorrent( );
|
|
|
|
if( tor !== null )
|
2011-08-20 15:31:34 +00:00
|
|
|
this._view.render( controller, tor, this.getElement( ) );
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
isSelected: function( ) {
|
|
|
|
return this.getElement().className.indexOf('selected') != -1;
|
|
|
|
},
|
|
|
|
setSelected: function( flag ) {
|
|
|
|
$(this.getElement()).toggleClass( 'selected', flag );
|
|
|
|
},
|
|
|
|
|
|
|
|
getToggleRunningButton: function( ) {
|
|
|
|
return this.getElement()._toggle_running_button;
|
|
|
|
},
|
|
|
|
|
|
|
|
setVisible: function( visible ) {
|
|
|
|
this.getElement().style.display = visible ? 'block' : 'none';
|
|
|
|
|
|
|
|
if( !visible )
|
|
|
|
this.setSelected( false );
|
|
|
|
},
|
|
|
|
isVisible: function( visible ) {
|
|
|
|
return this.getElement().style.display === 'block';
|
|
|
|
},
|
|
|
|
|
|
|
|
setTorrent: function( controller, t ) {
|
|
|
|
if( this._torrent !== t ) {
|
2011-08-20 15:31:34 +00:00
|
|
|
var key = 'dataChanged.renderer';
|
2011-08-16 18:49:26 +00:00
|
|
|
if( this._torrent )
|
2011-08-20 15:31:34 +00:00
|
|
|
$(this).unbind(key);
|
2011-08-16 18:49:26 +00:00
|
|
|
if(( this._torrent = t ))
|
2011-08-20 15:31:34 +00:00
|
|
|
$(this).bind(key,this.render(controller));
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
getTorrent: function() {
|
|
|
|
return this._torrent;
|
|
|
|
},
|
|
|
|
isEven: function() {
|
|
|
|
return this.getElement().className.indexOf('even') != -1;
|
|
|
|
},
|
|
|
|
setEven: function( even ) {
|
|
|
|
if( this.isEven() != even )
|
|
|
|
$(this.getElement()).toggleClass('even', even);
|
|
|
|
}
|
|
|
|
};
|