2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright © Dave Perrett and Malcolm Jarvis
|
|
|
|
* This code is licensed under the GPL version 2.
|
|
|
|
* For details, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
*
|
|
|
|
* Class Torrent
|
|
|
|
*/
|
|
|
|
|
2009-05-24 19:34:54 +00:00
|
|
|
function Torrent( transferListParent, fileListParent, controller, data) {
|
2009-06-24 14:09:46 +00:00
|
|
|
this.initialize( transferListParent, fileListParent, controller, data);
|
2009-08-12 14:40:32 +00:00
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
Torrent._StatusWaitingToCheck = 1;
|
|
|
|
Torrent._StatusChecking = 2;
|
|
|
|
Torrent._StatusDownloading = 4;
|
|
|
|
Torrent._StatusSeeding = 8;
|
|
|
|
Torrent._StatusPaused = 16;
|
|
|
|
Torrent._InfiniteTimeRemaining = 215784000; // 999 Hours - may as well be infinite
|
|
|
|
|
2009-07-28 04:52:52 +00:00
|
|
|
Torrent._RatioUseGlobal = 0;
|
|
|
|
Torrent._RatioUseLocal = 1;
|
|
|
|
Torrent._RatioUnlimited = 2;
|
|
|
|
|
2009-08-05 01:25:36 +00:00
|
|
|
Torrent._ErrNone = 0;
|
|
|
|
Torrent._ErrTrackerWarning = 1;
|
|
|
|
Torrent._ErrTrackerError = 2;
|
|
|
|
Torrent._ErrLocalError = 3;
|
|
|
|
|
2010-02-01 01:08:17 +00:00
|
|
|
Torrent._TrackerInactive = 0;
|
|
|
|
Torrent._TrackerWaiting = 1;
|
|
|
|
Torrent._TrackerQueued = 2;
|
|
|
|
Torrent._TrackerActive = 3;
|
|
|
|
|
|
|
|
|
2010-02-06 16:43:48 +00:00
|
|
|
Torrent._StaticFields = [ 'hashString', 'id' ]
|
|
|
|
|
|
|
|
Torrent._MetaDataFields = [ 'addedDate', 'comment', 'creator', 'dateCreated',
|
|
|
|
'isPrivate', 'name', 'totalSize', 'pieceCount', 'pieceSize' ]
|
|
|
|
|
2009-08-07 00:39:07 +00:00
|
|
|
Torrent._DynamicFields = [ 'downloadedEver', 'error', 'errorString', 'eta',
|
2010-06-17 04:40:06 +00:00
|
|
|
'haveUnchecked', 'haveValid', 'leftUntilDone', 'metadataPercentComplete', 'peers',
|
|
|
|
'peersConnected', 'peersGettingFromUs', 'peersSendingToUs', 'rateDownload', 'rateUpload',
|
2010-04-20 01:48:40 +00:00
|
|
|
'recheckProgress', 'sizeWhenDone', 'status', 'trackerStats', 'desiredAvailable',
|
2010-04-02 17:57:25 +00:00
|
|
|
'uploadedEver', 'uploadRatio', 'seedRatioLimit', 'seedRatioMode', 'downloadDir', 'isFinished' ]
|
2009-08-07 00:39:07 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
Torrent.prototype =
|
|
|
|
{
|
2010-02-06 16:43:48 +00:00
|
|
|
initMetaData: function( data ) {
|
|
|
|
this._date = data.addedDate;
|
|
|
|
this._comment = data.comment;
|
|
|
|
this._creator = data.creator;
|
|
|
|
this._creator_date = data.dateCreated;
|
|
|
|
this._is_private = data.isPrivate;
|
|
|
|
this._name = data.name;
|
|
|
|
this._name_lc = this._name.toLowerCase( );
|
|
|
|
this._size = data.totalSize;
|
|
|
|
this._pieceCount = data.pieceCount;
|
|
|
|
this._pieceSize = data.pieceSize;
|
|
|
|
|
|
|
|
if( data.files ) {
|
|
|
|
for( var i=0, row; row=data.files[i]; ++i ) {
|
|
|
|
this._file_model[i] = {
|
|
|
|
'index': i,
|
|
|
|
'torrent': this,
|
|
|
|
'length': row.length,
|
|
|
|
'name': row.name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Constructor
|
|
|
|
*/
|
2009-05-24 19:34:54 +00:00
|
|
|
initialize: function( transferListParent, fileListParent, controller, data) {
|
2009-05-22 22:45:09 +00:00
|
|
|
this._id = data.id;
|
|
|
|
this._hashString = data.hashString;
|
|
|
|
this._sizeWhenDone = data.sizeWhenDone;
|
2010-01-31 02:42:48 +00:00
|
|
|
this._trackerStats = this.buildTrackerStats(data.trackerStats);
|
2009-05-23 20:39:55 +00:00
|
|
|
this._file_model = [ ];
|
|
|
|
this._file_view = [ ];
|
2010-02-06 16:43:48 +00:00
|
|
|
this.initMetaData( data );
|
2009-05-22 22:45:09 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Create a new <li> element
|
2009-05-25 13:31:03 +00:00
|
|
|
var top_e = document.createElement( 'li' );
|
|
|
|
top_e.className = 'torrent';
|
|
|
|
top_e.id = 'torrent_' + data.id;
|
2009-05-25 15:46:25 +00:00
|
|
|
top_e._torrent = this;
|
2009-05-25 13:31:03 +00:00
|
|
|
var element = $(top_e);
|
2010-06-18 13:53:54 +00:00
|
|
|
$(element).bind('dblclick', function(e) { transmission.toggleInspector(); });
|
2008-07-10 23:57:46 +00:00
|
|
|
element._torrent = this;
|
2010-06-18 13:53:54 +00:00
|
|
|
element._id = this._id;
|
2008-07-10 23:57:46 +00:00
|
|
|
this._element = element;
|
|
|
|
this._controller = controller;
|
|
|
|
controller._rows.push( element );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Create the 'name' <div>
|
2009-05-23 15:05:58 +00:00
|
|
|
var e = document.createElement( 'div' );
|
|
|
|
e.className = 'torrent_name';
|
2009-05-25 13:31:03 +00:00
|
|
|
top_e.appendChild( e );
|
2008-07-10 23:57:46 +00:00
|
|
|
element._name_container = e;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-06-19 16:36:00 +00:00
|
|
|
// Create the 'peer details' <div>
|
2009-05-23 15:05:58 +00:00
|
|
|
e = document.createElement( 'div' );
|
2010-06-19 16:36:00 +00:00
|
|
|
e.className = 'torrent_peer_details';
|
2009-05-25 13:31:03 +00:00
|
|
|
top_e.appendChild( e );
|
2010-06-19 16:36:00 +00:00
|
|
|
element._peer_details_container = e;
|
|
|
|
|
|
|
|
//Create a progress bar container
|
|
|
|
top_a = document.createElement( 'div' );
|
|
|
|
top_a.className = 'torrent_progress_bar_container';
|
|
|
|
element._progress_bar_container = top_a;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Create the 'in progress' bar
|
2009-05-23 15:05:58 +00:00
|
|
|
e = document.createElement( 'div' );
|
|
|
|
e.className = 'torrent_progress_bar incomplete';
|
|
|
|
e.style.width = '0%';
|
2010-06-19 16:36:00 +00:00
|
|
|
top_a.appendChild( e );
|
2008-07-10 23:57:46 +00:00
|
|
|
element._progress_complete_container = e;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Create the 'incomplete' bar (initially hidden)
|
2009-05-23 15:05:58 +00:00
|
|
|
e = document.createElement( 'div' );
|
|
|
|
e.className = 'torrent_progress_bar incomplete';
|
|
|
|
e.style.display = 'none';
|
2010-06-19 16:36:00 +00:00
|
|
|
top_a.appendChild( e );
|
2008-07-10 23:57:46 +00:00
|
|
|
element._progress_incomplete_container = e;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-06-19 16:36:00 +00:00
|
|
|
//Add the progress bar container to the torrent
|
|
|
|
top_e.appendChild(top_a);
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Add the pause/resume button - don't specify the
|
|
|
|
// image or alt text until the 'refresh()' function
|
|
|
|
// (depends on torrent state)
|
2009-05-23 15:05:58 +00:00
|
|
|
var image = document.createElement( 'div' );
|
|
|
|
image.className = 'torrent_pause';
|
|
|
|
e = document.createElement( 'a' );
|
|
|
|
e.appendChild( image );
|
2009-05-25 13:31:03 +00:00
|
|
|
top_e.appendChild( e );
|
2008-07-10 23:57:46 +00:00
|
|
|
element._pause_resume_button_image = image;
|
2009-06-23 01:52:20 +00:00
|
|
|
if (!iPhone) $(e).bind('click', function(e) { element._torrent.clickPauseResumeButton(e); });
|
2010-06-19 16:36:00 +00:00
|
|
|
|
|
|
|
// Create the 'progress details' <div>
|
2009-05-23 15:05:58 +00:00
|
|
|
e = document.createElement( 'div' );
|
2010-06-19 16:36:00 +00:00
|
|
|
e.className = 'torrent_progress_details';
|
2009-05-25 13:31:03 +00:00
|
|
|
top_e.appendChild( e );
|
2010-06-19 16:36:00 +00:00
|
|
|
element._progress_details_container = e;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
// Set the torrent click observer
|
2009-06-23 01:52:20 +00:00
|
|
|
element.bind('click', function(e){ element._torrent.clickTorrent(e) });
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Safari hack - first torrent needs to be moved down for some reason. Seems to be ok when
|
|
|
|
// using <li>'s in straight html, but adding through the DOM gets a bit odd.
|
|
|
|
if ($.browser.safari)
|
|
|
|
this._element.css('margin-top', '7px');
|
2009-05-22 22:45:09 +00:00
|
|
|
|
2009-05-24 19:34:54 +00:00
|
|
|
this.initializeTorrentFilesInspectorGroup( fileListParent );
|
2009-05-23 20:39:55 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Update all the labels etc
|
|
|
|
this.refresh(data);
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-24 15:48:18 +00:00
|
|
|
// insert the element
|
2009-05-25 13:31:03 +00:00
|
|
|
transferListParent.appendChild(top_e);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-24 19:34:54 +00:00
|
|
|
initializeTorrentFilesInspectorGroup: function( fileListParent ) {
|
2009-05-23 18:09:56 +00:00
|
|
|
var e = document.createElement( 'ul' );
|
|
|
|
e.className = 'inspector_torrent_file_list inspector_group';
|
|
|
|
e.style.display = 'none';
|
2009-05-24 19:34:54 +00:00
|
|
|
fileListParent.appendChild( e );
|
2009-05-23 18:09:56 +00:00
|
|
|
this._fileList = e;
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
fileList: function() {
|
2009-05-23 18:09:56 +00:00
|
|
|
return $(this._fileList);
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-01-31 02:42:48 +00:00
|
|
|
buildTrackerStats: function(trackerStats) {
|
|
|
|
result = [];
|
|
|
|
for( var i=0, tracker; tracker=trackerStats[i]; ++i ) {
|
2010-02-15 23:52:41 +00:00
|
|
|
tier = result[tracker.tier] || [];
|
2010-01-31 02:42:48 +00:00
|
|
|
tier[tier.length] = {
|
|
|
|
'host': tracker.host,
|
2010-02-01 01:08:17 +00:00
|
|
|
'announce': tracker.announce,
|
|
|
|
'hasAnnounced': tracker.hasAnnounced,
|
|
|
|
'lastAnnounceTime': tracker.lastAnnounceTime,
|
|
|
|
'lastAnnounceSucceeded': tracker.lastAnnounceSucceeded,
|
|
|
|
'lastAnnounceResult': tracker.lastAnnounceResult,
|
|
|
|
'lastAnnouncePeerCount': tracker.lastAnnouncePeerCount,
|
|
|
|
'announceState': tracker.announceState,
|
|
|
|
'nextAnnounceTime': tracker.nextAnnounceTime,
|
|
|
|
'isBackup': tracker.isBackup,
|
|
|
|
'hasScraped': tracker.hasScraped,
|
|
|
|
'lastScrapeTime': tracker.lastScrapeTime,
|
|
|
|
'lastScrapeSucceeded': tracker.lastScrapeSucceeded,
|
|
|
|
'lastScrapeResult': tracker.lastScrapeResult,
|
2010-01-31 02:42:48 +00:00
|
|
|
'seederCount': tracker.seederCount,
|
|
|
|
'leecherCount': tracker.leecherCount,
|
|
|
|
'downloadCount': tracker.downloadCount
|
|
|
|
};
|
2010-02-15 23:52:41 +00:00
|
|
|
result[tracker.tier] = tier;
|
2010-01-31 02:42:48 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*--------------------------------------------
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
* S E T T E R S / G E T T E R S
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
*--------------------------------------------*/
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/* Return the DOM element for this torrent (a <LI> element) */
|
|
|
|
element: function() {
|
|
|
|
return this._element;
|
|
|
|
},
|
|
|
|
|
|
|
|
setElement: function( element ) {
|
|
|
|
this._element = element;
|
|
|
|
element._torrent = this;
|
2009-05-25 15:46:25 +00:00
|
|
|
element[0]._torrent = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
this.refreshHTML( );
|
|
|
|
},
|
|
|
|
|
|
|
|
activity: function() { return this._download_speed + this._upload_speed; },
|
|
|
|
comment: function() { return this._comment; },
|
|
|
|
completed: function() { return this._completed; },
|
|
|
|
creator: function() { return this._creator; },
|
|
|
|
dateAdded: function() { return this._date; },
|
|
|
|
downloadSpeed: function() { return this._download_speed; },
|
|
|
|
downloadTotal: function() { return this._download_total; },
|
|
|
|
hash: function() { return this._hashString; },
|
|
|
|
id: function() { return this._id; },
|
2010-06-17 04:38:03 +00:00
|
|
|
isActiveFilter: function() { return this.peersGettingFromUs() > 0
|
2011-01-19 00:07:59 +00:00
|
|
|
|| this.peersSendingToUs() > 0
|
|
|
|
|| this.webseedsSendingToUs() > 0
|
|
|
|
|| this.state() == Torrent._StatusChecking; },
|
2008-07-10 23:57:46 +00:00
|
|
|
isActive: function() { return this.state() != Torrent._StatusPaused; },
|
|
|
|
isDownloading: function() { return this.state() == Torrent._StatusDownloading; },
|
2010-09-03 00:20:40 +00:00
|
|
|
isFinished: function() { return this._isFinishedSeeding; },
|
2008-07-10 23:57:46 +00:00
|
|
|
isSeeding: function() { return this.state() == Torrent._StatusSeeding; },
|
|
|
|
name: function() { return this._name; },
|
2011-01-19 00:07:59 +00:00
|
|
|
webseedsSendingToUs: function() { return this._webseeds_sending_to_us; },
|
2008-07-25 14:34:25 +00:00
|
|
|
peersSendingToUs: function() { return this._peers_sending_to_us; },
|
|
|
|
peersGettingFromUs: function() { return this._peers_getting_from_us; },
|
2009-12-04 04:31:29 +00:00
|
|
|
needsMetaData: function(){ return this._metadataPercentComplete < 1 },
|
2008-07-16 14:35:58 +00:00
|
|
|
getPercentDone: function() {
|
|
|
|
if( !this._sizeWhenDone ) return 1.0;
|
2008-09-19 16:17:35 +00:00
|
|
|
if( !this._leftUntilDone ) return 1.0;
|
2009-03-14 21:33:08 +00:00
|
|
|
return ( this._sizeWhenDone - this._leftUntilDone ) / this._sizeWhenDone;
|
2008-07-16 14:35:58 +00:00
|
|
|
},
|
|
|
|
getPercentDoneStr: function() {
|
2010-06-22 22:30:58 +00:00
|
|
|
return Transmission.fmt.percentString( 100 * this.getPercentDone() );
|
2008-07-16 14:35:58 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
size: function() { return this._size; },
|
|
|
|
state: function() { return this._state; },
|
|
|
|
stateStr: function() {
|
|
|
|
switch( this.state() ) {
|
|
|
|
case Torrent._StatusSeeding: return 'Seeding';
|
|
|
|
case Torrent._StatusDownloading: return 'Downloading';
|
2010-09-03 00:20:40 +00:00
|
|
|
case Torrent._StatusPaused: return this.isFinished() ? 'Seeding complete' : 'Paused';
|
2008-07-10 23:57:46 +00:00
|
|
|
case Torrent._StatusChecking: return 'Verifying local data';
|
|
|
|
case Torrent._StatusWaitingToCheck: return 'Waiting to verify';
|
|
|
|
default: return 'error';
|
|
|
|
}
|
|
|
|
},
|
2010-01-31 02:42:48 +00:00
|
|
|
trackerStats: function() { return this._trackerStats; },
|
2008-07-10 23:57:46 +00:00
|
|
|
uploadSpeed: function() { return this._upload_speed; },
|
|
|
|
uploadTotal: function() { return this._upload_total; },
|
2009-05-25 00:41:44 +00:00
|
|
|
showFileList: function() {
|
|
|
|
if(this.fileList().is(':visible'))
|
|
|
|
return;
|
|
|
|
this.ensureFileListExists();
|
|
|
|
this.refreshFileView();
|
|
|
|
this.fileList().show();
|
|
|
|
},
|
2009-04-29 11:59:29 +00:00
|
|
|
hideFileList: function() { this.fileList().hide(); },
|
2009-07-28 05:23:34 +00:00
|
|
|
seedRatioLimit: function(){
|
2009-07-28 04:52:52 +00:00
|
|
|
switch( this._seed_ratio_mode ) {
|
2009-07-28 05:23:34 +00:00
|
|
|
case Torrent._RatioUseGlobal: return this._controller.seedRatioLimit();
|
2009-07-28 04:52:52 +00:00
|
|
|
case Torrent._RatioUseLocal: return this._seed_ratio_limit;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
/*--------------------------------------------
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2009-05-25 13:31:03 +00:00
|
|
|
* E V E N T F U N C T I O N S
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2009-05-25 13:31:03 +00:00
|
|
|
*--------------------------------------------*/
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
/*
|
|
|
|
* Process a click event on this torrent
|
|
|
|
*/
|
|
|
|
clickTorrent: function( event )
|
|
|
|
{
|
|
|
|
// Prevents click carrying to parent element
|
|
|
|
// which deselects all on click
|
|
|
|
event.stopPropagation();
|
2009-12-13 18:37:36 +00:00
|
|
|
// but still hide the context menu if it is showing
|
|
|
|
$('#jqContextMenu').hide();
|
|
|
|
|
2009-06-23 01:52:20 +00:00
|
|
|
var torrent = this;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
// 'Apple' button emulation on PC :
|
|
|
|
// Need settable meta-key and ctrl-key variables for mac emulation
|
|
|
|
var meta_key = event.metaKey;
|
|
|
|
var ctrl_key = event.ctrlKey;
|
|
|
|
if (event.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") == -1) {
|
|
|
|
meta_key = true;
|
|
|
|
ctrl_key = false;
|
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
// Shift-Click - Highlight a range between this torrent and the last-clicked torrent
|
|
|
|
if (iPhone) {
|
2009-06-23 01:52:20 +00:00
|
|
|
if ( torrent.isSelected() )
|
|
|
|
torrent._controller.showInspector();
|
2009-05-25 13:31:03 +00:00
|
|
|
torrent._controller.setSelectedTorrent( torrent, true );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
} else if (event.shiftKey) {
|
|
|
|
torrent._controller.selectRange( torrent, true );
|
|
|
|
// Need to deselect any selected text
|
|
|
|
window.focus();
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
// Apple-Click, not selected
|
|
|
|
} else if (!torrent.isSelected() && meta_key) {
|
|
|
|
torrent._controller.selectTorrent( torrent, true );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
// Regular Click, not selected
|
|
|
|
} else if (!torrent.isSelected()) {
|
|
|
|
torrent._controller.setSelectedTorrent( torrent, true );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
|
|
|
// Apple-Click, selected
|
2009-05-25 13:31:03 +00:00
|
|
|
} else if (torrent.isSelected() && meta_key) {
|
|
|
|
torrent._controller.deselectTorrent( torrent, true );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
// Regular Click, selected
|
|
|
|
} else if (torrent.isSelected()) {
|
|
|
|
torrent._controller.setSelectedTorrent( torrent, true );
|
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
torrent._controller.setLastTorrentClicked(torrent);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a click event on the pause/resume button
|
|
|
|
*/
|
|
|
|
clickPauseResumeButton: function( event )
|
|
|
|
{
|
|
|
|
// prevent click event resulting in selection of torrent
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
// either stop or start the torrent
|
2009-06-23 01:52:20 +00:00
|
|
|
var torrent = this;
|
2009-05-25 13:31:03 +00:00
|
|
|
if( torrent.isActive( ) )
|
|
|
|
torrent._controller.stopTorrent( torrent );
|
|
|
|
else
|
|
|
|
torrent._controller.startTorrent( torrent );
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*--------------------------------------------
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
* I N T E R F A C E F U N C T I O N S
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
*--------------------------------------------*/
|
2010-02-06 16:43:48 +00:00
|
|
|
|
|
|
|
refreshMetaData: function(data) {
|
|
|
|
this.initMetaData( data );
|
|
|
|
this.ensureFileListExists();
|
|
|
|
this.refreshFileView();
|
|
|
|
this.refreshHTML( );
|
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
refresh: function(data) {
|
|
|
|
this.refreshData( data );
|
|
|
|
this.refreshHTML( );
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Refresh display
|
|
|
|
*/
|
2010-02-06 16:43:48 +00:00
|
|
|
refreshData: function(data)
|
|
|
|
{
|
|
|
|
if( this.needsMetaData() && ( data.metadataPercentComplete >= 1 ) )
|
|
|
|
transmission.refreshMetaData( [ this._id ] );
|
|
|
|
|
2009-12-04 04:31:29 +00:00
|
|
|
this._completed = data.haveUnchecked + data.haveValid;
|
|
|
|
this._verified = data.haveValid;
|
|
|
|
this._leftUntilDone = data.leftUntilDone;
|
|
|
|
this._download_total = data.downloadedEver;
|
|
|
|
this._upload_total = data.uploadedEver;
|
|
|
|
this._upload_ratio = data.uploadRatio;
|
|
|
|
this._seed_ratio_limit = data.seedRatioLimit;
|
|
|
|
this._seed_ratio_mode = data.seedRatioMode;
|
|
|
|
this._download_speed = data.rateDownload;
|
|
|
|
this._upload_speed = data.rateUpload;
|
2010-06-17 04:40:06 +00:00
|
|
|
this._peers = data.peers;
|
2009-12-04 04:31:29 +00:00
|
|
|
this._peers_connected = data.peersConnected;
|
|
|
|
this._peers_getting_from_us = data.peersGettingFromUs;
|
|
|
|
this._peers_sending_to_us = data.peersSendingToUs;
|
2011-01-19 00:07:59 +00:00
|
|
|
this._webseeds_sending_to_us = data.webseedsSendingToUs;
|
2009-12-04 04:31:29 +00:00
|
|
|
this._sizeWhenDone = data.sizeWhenDone;
|
|
|
|
this._recheckProgress = data.recheckProgress;
|
|
|
|
this._error = data.error;
|
|
|
|
this._error_string = data.errorString;
|
|
|
|
this._eta = data.eta;
|
2010-01-31 02:42:48 +00:00
|
|
|
this._trackerStats = this.buildTrackerStats(data.trackerStats);
|
2009-12-04 04:31:29 +00:00
|
|
|
this._state = data.status;
|
|
|
|
this._download_dir = data.downloadDir;
|
|
|
|
this._metadataPercentComplete = data.metadataPercentComplete;
|
2010-04-02 17:57:25 +00:00
|
|
|
this._isFinishedSeeding = data.isFinished;
|
2010-04-20 01:48:40 +00:00
|
|
|
this._desiredAvailable = data.desiredAvailable;
|
2009-05-23 20:39:55 +00:00
|
|
|
|
|
|
|
if (data.fileStats)
|
|
|
|
this.refreshFileModel( data );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2009-05-23 20:39:55 +00:00
|
|
|
refreshFileModel: function(data) {
|
|
|
|
for( var i=0; i<data.fileStats.length; ++i ) {
|
|
|
|
var src = data.fileStats[i];
|
|
|
|
var tgt = this._file_model[i];
|
|
|
|
if( !tgt )
|
|
|
|
tgt = this._file_model[i] = { };
|
|
|
|
tgt.wanted = src.wanted;
|
|
|
|
tgt.priority = src.priority;
|
|
|
|
tgt.bytesCompleted = src.bytesCompleted;
|
2009-05-22 22:45:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-08-05 01:25:36 +00:00
|
|
|
getErrorMessage: function()
|
2009-06-24 14:09:46 +00:00
|
|
|
{
|
2009-08-05 01:25:36 +00:00
|
|
|
if( this._error == Torrent._ErrTrackerWarning )
|
|
|
|
return 'Tracker returned a warning: ' + this._error_string;
|
|
|
|
if( this._error == Torrent._ErrTrackerError )
|
|
|
|
return 'Tracker returned an error: ' + this._error_string;
|
|
|
|
if( this._error == Torrent._ErrLocalError )
|
|
|
|
return 'Error: ' + this._error_string;
|
|
|
|
return null;
|
|
|
|
},
|
2009-06-24 14:09:46 +00:00
|
|
|
|
2010-06-19 18:40:07 +00:00
|
|
|
formatUL: function() {
|
2010-09-12 01:13:38 +00:00
|
|
|
return 'UL: ' + Transmission.fmt.speedBps(this._upload_speed);
|
2010-06-19 18:40:07 +00:00
|
|
|
},
|
|
|
|
formatDL: function() {
|
2010-09-12 01:13:38 +00:00
|
|
|
return 'DL: ' + Transmission.fmt.speedBps(this._download_speed);
|
2010-06-19 18:40:07 +00:00
|
|
|
},
|
|
|
|
|
2009-08-05 01:25:36 +00:00
|
|
|
getPeerDetails: function()
|
|
|
|
{
|
2009-06-24 14:09:46 +00:00
|
|
|
var c;
|
2009-08-05 01:25:36 +00:00
|
|
|
|
2010-06-19 16:36:00 +00:00
|
|
|
var compact_mode = this._controller[Prefs._CompactDisplayState];
|
2009-08-05 01:25:36 +00:00
|
|
|
if(( c = this.getErrorMessage( )))
|
|
|
|
return c;
|
|
|
|
|
2009-06-24 14:09:46 +00:00
|
|
|
var st = this.state( );
|
|
|
|
switch( st )
|
|
|
|
{
|
|
|
|
case Torrent._StatusPaused:
|
|
|
|
case Torrent._StatusWaitingToCheck:
|
|
|
|
c = this.stateStr( );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Torrent._StatusDownloading:
|
2010-09-12 02:07:43 +00:00
|
|
|
var a = [ ];
|
|
|
|
if(!compact_mode)
|
|
|
|
a.push( 'Downloading from', this.peersSendingToUs(), 'of', this._peers_connected, 'peers', '-' );
|
|
|
|
a.push( this.formatDL(), this.formatUL() );
|
|
|
|
c = a.join(' ');
|
2009-06-24 14:09:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Torrent._StatusSeeding:
|
2010-06-19 16:36:00 +00:00
|
|
|
if(compact_mode){
|
2010-09-03 00:03:21 +00:00
|
|
|
c = this.formatUL();
|
2010-06-19 16:36:00 +00:00
|
|
|
} else {
|
|
|
|
// 'Seeding to 13 of 22 peers - UL: 36.2 KiB/s'
|
2010-09-12 02:07:43 +00:00
|
|
|
c = [ 'Seeding to', this.peersGettingFromUs(), 'of', this._peers_connected, 'peers', '-', this.formatUL() ].join(' ');
|
2010-06-19 16:36:00 +00:00
|
|
|
}
|
2009-06-24 14:09:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Torrent._StatusChecking:
|
|
|
|
// 'Verifying local data (40% tested)'
|
2010-09-12 02:07:43 +00:00
|
|
|
c = [ 'Verifying local data (', Transmission.fmt.percentString( 100.0 * this._recheckProgress ), '% tested)' ].join('');
|
2009-06-24 14:09:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
},
|
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
refreshHTML: function() {
|
2009-05-25 01:18:51 +00:00
|
|
|
var c;
|
|
|
|
var e;
|
2008-07-10 23:57:46 +00:00
|
|
|
var progress_details;
|
|
|
|
var root = this._element;
|
2008-07-16 14:35:58 +00:00
|
|
|
var MaxBarWidth = 100; // reduce this to make the progress bar shorter (%)
|
2010-06-19 16:36:00 +00:00
|
|
|
var compact_mode = this._controller[Prefs._CompactDisplayState];
|
|
|
|
var compact = '';
|
|
|
|
if(compact_mode){
|
|
|
|
compact = ' compact';
|
|
|
|
root._peer_details_container.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
root._peer_details_container.style.display = 'block';
|
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-06-19 16:36:00 +00:00
|
|
|
root._progress_details_container.className = 'torrent_progress_details'+compact
|
|
|
|
root._progress_bar_container.className = 'torrent_progress_bar_container'+compact;
|
|
|
|
root._name_container.className = 'torrent_name'+compact;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-23 15:05:58 +00:00
|
|
|
setInnerHTML( root._name_container, this._name );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Add the progress bar
|
2009-06-24 14:09:46 +00:00
|
|
|
var notDone = this._leftUntilDone > 0;
|
2008-08-10 19:24:26 +00:00
|
|
|
|
|
|
|
// Fix for situation
|
|
|
|
// when a verifying/downloading torrent gets state seeding
|
2009-05-25 01:18:51 +00:00
|
|
|
if( this._state === Torrent._StatusSeeding )
|
2008-08-10 19:24:26 +00:00
|
|
|
notDone = false ;
|
2009-12-04 04:31:29 +00:00
|
|
|
|
|
|
|
if( this.needsMetaData() ){
|
2010-06-22 22:30:58 +00:00
|
|
|
var metaPercentComplete = this._metadataPercentComplete * 100;
|
2010-10-12 17:38:03 +00:00
|
|
|
progress_details = [ "Magnetized transfer - retrieving metadata (",
|
|
|
|
Transmission.fmt.percentString( metaPercentComplete ),
|
|
|
|
"%)" ].join('');
|
2009-12-04 04:31:29 +00:00
|
|
|
|
|
|
|
var empty = "";
|
|
|
|
if(metaPercentComplete == 0)
|
|
|
|
empty = "empty";
|
|
|
|
|
|
|
|
root._progress_complete_container.style.width = metaPercentComplete + "%";
|
2010-06-19 16:36:00 +00:00
|
|
|
root._progress_complete_container.className = 'torrent_progress_bar in_progress meta ' + empty+compact;
|
2009-12-04 04:31:29 +00:00
|
|
|
root._progress_incomplete_container.style.width = 100 - metaPercentComplete + "%"
|
2010-06-19 16:36:00 +00:00
|
|
|
root._progress_incomplete_container.className = 'torrent_progress_bar incomplete compact meta'+compact;
|
2009-12-04 04:31:29 +00:00
|
|
|
root._progress_incomplete_container.style.display = 'block';
|
|
|
|
}
|
|
|
|
else if( notDone )
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2010-10-12 17:38:03 +00:00
|
|
|
// Create the 'progress details' label
|
|
|
|
// Eg: '101 MiB of 631 MiB (16.02%) - 2 hr remaining'
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-10-12 17:38:03 +00:00
|
|
|
c = [ Transmission.fmt.size( this._sizeWhenDone - this._leftUntilDone ),
|
|
|
|
' of ', Transmission.fmt.size( this._sizeWhenDone ),
|
|
|
|
' (', this.getPercentDoneStr(), '%)' ];
|
|
|
|
if( this.isActive( ) ) {
|
|
|
|
c.push( ' - ' );
|
2008-07-10 23:57:46 +00:00
|
|
|
if (this._eta < 0 || this._eta >= Torrent._InfiniteTimeRemaining )
|
2010-10-12 17:38:03 +00:00
|
|
|
c.push( 'remaining time unknown' );
|
2008-07-10 23:57:46 +00:00
|
|
|
else
|
2010-10-12 17:38:03 +00:00
|
|
|
c.push( Transmission.fmt.timeInterval(this._eta) + ' remaining' );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2010-10-12 17:38:03 +00:00
|
|
|
progress_details = c.join('');
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-16 14:35:58 +00:00
|
|
|
// Figure out the percent completed
|
2010-06-22 22:30:58 +00:00
|
|
|
var css_completed_width = ( this.getPercentDone() * MaxBarWidth ).toTruncFixed( 2 );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Update the 'in progress' bar
|
2009-05-25 01:18:51 +00:00
|
|
|
e = root._progress_complete_container;
|
2010-10-12 17:38:03 +00:00
|
|
|
c = [ 'torrent_progress_bar'+compact,
|
|
|
|
this.isActive() ? 'in_progress' : 'incomplete_stopped' ];
|
|
|
|
if(css_completed_width === 0) { c.push( 'empty' ); }
|
|
|
|
e.className = c.join(' ');
|
2009-05-23 15:05:58 +00:00
|
|
|
e.style.width = css_completed_width + '%';
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Update the 'incomplete' bar
|
|
|
|
e = root._progress_incomplete_container;
|
2009-12-04 04:31:29 +00:00
|
|
|
e.className = 'torrent_progress_bar incomplete'
|
2009-05-23 15:05:58 +00:00
|
|
|
e.style.width = (MaxBarWidth - css_completed_width) + '%';
|
|
|
|
e.style.display = 'block';
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-12 17:38:03 +00:00
|
|
|
// Create the 'progress details' label
|
|
|
|
|
|
|
|
if( this._size == this._sizeWhenDone )
|
|
|
|
{
|
|
|
|
// seed: '698.05 MiB'
|
|
|
|
c = [ Transmission.fmt.size( this._size ) ];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// partial seed: '127.21 MiB of 698.05 MiB (18.2%)'
|
|
|
|
c = [ Transmission.fmt.size( this._sizeWhenDone ), ' of ', Transmission.fmt.size( this._size ),
|
|
|
|
' (', Transmission.fmt.percentString( 100.0 * this._sizeWhenDone / this._size ), '%)' ];
|
|
|
|
}
|
|
|
|
|
|
|
|
// append UL stats: ', uploaded 8.59 GiB (Ratio: 12.3)'
|
|
|
|
c.push( ', uploaded ', Transmission.fmt.size( this._upload_total ),
|
|
|
|
' (Ratio ', Transmission.fmt.ratioString( this._upload_ratio ), ')' );
|
2010-03-14 05:28:25 +00:00
|
|
|
|
2010-10-12 17:38:03 +00:00
|
|
|
// maybe append remaining time
|
2010-03-14 05:28:25 +00:00
|
|
|
if( this.isActive( ) && this.seedRatioLimit( ) > 0 )
|
|
|
|
{
|
2010-10-12 17:38:03 +00:00
|
|
|
c.push(' - ');
|
|
|
|
|
2010-03-14 05:28:25 +00:00
|
|
|
if (this._eta < 0 || this._eta >= Torrent._InfiniteTimeRemaining )
|
2010-10-12 17:38:03 +00:00
|
|
|
c.push( 'remaining time unknown' );
|
2010-03-14 05:28:25 +00:00
|
|
|
else
|
2010-10-12 17:38:03 +00:00
|
|
|
c.push( Transmission.fmt.timeInterval(this._eta), ' remaining' );
|
2010-03-14 05:28:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 17:38:03 +00:00
|
|
|
progress_details = c.join('');
|
2009-07-28 04:52:59 +00:00
|
|
|
|
|
|
|
var status = this.isActive() ? 'complete' : 'complete_stopped';
|
|
|
|
|
2009-07-28 05:23:34 +00:00
|
|
|
if(this.isActive() && this.seedRatioLimit() > 0){
|
2009-07-28 04:52:59 +00:00
|
|
|
status = 'complete seeding'
|
2009-07-28 05:23:34 +00:00
|
|
|
var seedRatioRatio = this._upload_ratio / this.seedRatioLimit();
|
2009-07-28 04:52:59 +00:00
|
|
|
var seedRatioPercent = Math.round( seedRatioRatio * 100 * MaxBarWidth ) / 100;
|
|
|
|
|
2009-07-30 19:03:37 +00:00
|
|
|
// Set progress to percent seeded
|
|
|
|
root._progress_complete_container.style.width = seedRatioPercent + '%';
|
|
|
|
|
|
|
|
// Update the 'incomplete' bar
|
2009-07-28 04:52:59 +00:00
|
|
|
root._progress_incomplete_container.className = 'torrent_progress_bar incomplete seeding'
|
|
|
|
root._progress_incomplete_container.style.display = 'block';
|
2009-07-30 19:03:37 +00:00
|
|
|
root._progress_incomplete_container.style.width = MaxBarWidth - seedRatioPercent + '%';
|
2009-07-28 04:52:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Hide the 'incomplete' bar
|
|
|
|
root._progress_incomplete_container.className = 'torrent_progress_bar incomplete'
|
|
|
|
root._progress_incomplete_container.style.display = 'none';
|
|
|
|
|
|
|
|
// Set progress to maximum
|
|
|
|
root._progress_complete_container.style.width = MaxBarWidth + '%';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the 'in progress' bar
|
|
|
|
e = root._progress_complete_container;
|
|
|
|
e.className = 'torrent_progress_bar ' + status;
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-07-29 17:45:23 +00:00
|
|
|
var hasError = this.getErrorMessage( ) != undefined;
|
2008-07-10 23:57:46 +00:00
|
|
|
// Update the progress details
|
2010-07-29 17:45:23 +00:00
|
|
|
if(compact_mode){
|
2010-06-19 16:36:00 +00:00
|
|
|
progress_details = this.getPeerDetails();
|
2010-07-29 17:45:23 +00:00
|
|
|
$(root._progress_details_container).toggleClass('error',hasError);
|
|
|
|
} else {
|
|
|
|
$(root._peer_details_container).toggleClass('error',hasError);
|
|
|
|
}
|
2009-05-23 15:05:58 +00:00
|
|
|
setInnerHTML( root._progress_details_container, progress_details );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2010-07-31 16:28:00 +00:00
|
|
|
if( compact ){
|
|
|
|
var width = root._progress_details_container.offsetLeft - root._name_container.offsetLeft;
|
|
|
|
root._name_container.style.width = width + 'px';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
root._name_container.style.width = '100%';
|
|
|
|
}
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Update the peer details and pause/resume button
|
2009-05-23 15:05:58 +00:00
|
|
|
e = root._pause_resume_button_image;
|
2009-05-25 01:18:51 +00:00
|
|
|
if ( this.state() === Torrent._StatusPaused ) {
|
2008-07-10 23:57:46 +00:00
|
|
|
e.alt = 'Resume';
|
2010-06-19 16:36:00 +00:00
|
|
|
e.className = "torrent_resume"+compact;
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
|
|
|
e.alt = 'Pause';
|
2010-06-19 16:36:00 +00:00
|
|
|
e.className = "torrent_pause"+compact;
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-06-24 14:09:46 +00:00
|
|
|
setInnerHTML( root._peer_details_container, this.getPeerDetails( ) );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
|
|
|
this.refreshFileView( );
|
2009-04-29 11:59:29 +00:00
|
|
|
},
|
|
|
|
|
2009-05-23 20:39:55 +00:00
|
|
|
refreshFileView: function() {
|
|
|
|
if( this._file_view.length )
|
|
|
|
for( var i=0; i<this._file_model.length; ++i )
|
|
|
|
this._file_view[i].update( this._file_model[i] );
|
|
|
|
},
|
|
|
|
|
|
|
|
ensureFileListExists: function() {
|
|
|
|
if( this._file_view.length == 0 ) {
|
2009-05-25 04:13:08 +00:00
|
|
|
if(this._file_model.length == 1)
|
|
|
|
this._fileList.className += ' single_file';
|
2009-05-25 01:18:51 +00:00
|
|
|
var v, e;
|
2009-05-23 20:39:55 +00:00
|
|
|
for( var i=0; i<this._file_model.length; ++i ) {
|
2009-05-25 01:18:51 +00:00
|
|
|
v = new TorrentFile( this._file_model[i] );
|
2009-05-23 20:39:55 +00:00
|
|
|
this._file_view[i] = v;
|
2009-05-25 01:18:51 +00:00
|
|
|
e = v.domElement( );
|
2009-05-23 20:39:55 +00:00
|
|
|
e.className = (i % 2 ? 'even' : 'odd') + ' inspector_torrent_file_list_entry';
|
|
|
|
this._fileList.appendChild( e );
|
|
|
|
}
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2009-05-27 23:12:06 +00:00
|
|
|
deleteFiles: function(){
|
|
|
|
if (this._fileList)
|
|
|
|
$(this._fileList).remove();
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Return true if this torrent is selected
|
|
|
|
*/
|
|
|
|
isSelected: function() {
|
2009-05-25 13:31:03 +00:00
|
|
|
return this.element()[0].className.indexOf('selected') != -1;
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param filter one of Prefs._Filter*
|
|
|
|
* @param search substring to look for, or null
|
|
|
|
* @return true if it passes the test, false if it fails
|
|
|
|
*/
|
|
|
|
test: function( filter, search )
|
|
|
|
{
|
|
|
|
var pass = false;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
switch( filter )
|
|
|
|
{
|
2010-06-17 04:38:03 +00:00
|
|
|
case Prefs._FilterActive:
|
|
|
|
pass = this.isActiveFilter();
|
|
|
|
break;
|
2008-07-10 23:57:46 +00:00
|
|
|
case Prefs._FilterSeeding:
|
|
|
|
pass = this.isSeeding();
|
|
|
|
break;
|
|
|
|
case Prefs._FilterDownloading:
|
|
|
|
pass = this.isDownloading();
|
|
|
|
break;
|
|
|
|
case Prefs._FilterPaused:
|
|
|
|
pass = !this.isActive();
|
|
|
|
break;
|
2010-09-03 00:20:40 +00:00
|
|
|
case Prefs._FilterFinished:
|
|
|
|
pass = this.isFinished();
|
|
|
|
break;
|
2008-07-10 23:57:46 +00:00
|
|
|
default:
|
|
|
|
pass = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
if( !pass )
|
|
|
|
return false;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
if( !search || !search.length )
|
|
|
|
return pass;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 01:18:51 +00:00
|
|
|
return this._name_lc.indexOf( search.toLowerCase() ) !== -1;
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper function for Torrent.sortTorrents(). */
|
|
|
|
Torrent.compareById = function( a, b ) {
|
|
|
|
return a.id() - b.id();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper function for sortTorrents(). */
|
|
|
|
Torrent.compareByAge = function( a, b ) {
|
|
|
|
return a.dateAdded() - b.dateAdded();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper function for sortTorrents(). */
|
|
|
|
Torrent.compareByName = function( a, b ) {
|
|
|
|
return a._name_lc.compareTo( b._name_lc );
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper function for sortTorrents(). */
|
|
|
|
Torrent.compareByState = function( a, b ) {
|
|
|
|
return a.state() - b.state();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper function for sortTorrents(). */
|
|
|
|
Torrent.compareByActivity = function( a, b ) {
|
|
|
|
return a.activity() - b.activity();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper function for sortTorrents(). */
|
|
|
|
Torrent.compareByProgress = function( a, b ) {
|
2008-09-19 16:17:35 +00:00
|
|
|
if( a.getPercentDone() !== b.getPercentDone() )
|
|
|
|
return a.getPercentDone() - b.getPercentDone();
|
2008-07-10 23:57:46 +00:00
|
|
|
var a_ratio = Math.ratio( a._upload_total, a._download_total );
|
|
|
|
var b_ratio = Math.ratio( b._upload_total, b._download_total );
|
|
|
|
return a_ratio - b_ratio;
|
2009-05-25 01:18:51 +00:00
|
|
|
};
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param torrents an array of Torrent objects
|
|
|
|
* @param sortMethod one of Prefs._SortBy*
|
|
|
|
* @param sortDirection Prefs._SortAscending or Prefs._SortDescending
|
|
|
|
*/
|
|
|
|
Torrent.sortTorrents = function( torrents, sortMethod, sortDirection )
|
|
|
|
{
|
|
|
|
switch( sortMethod )
|
|
|
|
{
|
|
|
|
case Prefs._SortByActivity:
|
|
|
|
torrents.sort( this.compareByActivity );
|
|
|
|
break;
|
|
|
|
case Prefs._SortByAge:
|
|
|
|
torrents.sort( this.compareByAge );
|
|
|
|
break;
|
|
|
|
case Prefs._SortByQueue:
|
|
|
|
torrents.sort( this.compareById );
|
|
|
|
break;
|
|
|
|
case Prefs._SortByProgress:
|
|
|
|
torrents.sort( this.compareByProgress );
|
|
|
|
break;
|
|
|
|
case Prefs._SortByState:
|
|
|
|
torrents.sort( this.compareByState );
|
|
|
|
break;
|
|
|
|
case Prefs._SortByName:
|
|
|
|
torrents.sort( this.compareByName );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.warn( "unknown sort method: " + sortMethod );
|
|
|
|
break;
|
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 01:18:51 +00:00
|
|
|
if( sortDirection === Prefs._SortDescending )
|
2008-07-10 23:57:46 +00:00
|
|
|
torrents.reverse( );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
return torrents;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief fast binary search to find a torrent
|
|
|
|
* @param torrents an array of torrents sorted by Id
|
|
|
|
* @param id the id to search for
|
|
|
|
* @return the index, or -1
|
|
|
|
*/
|
|
|
|
Torrent.indexOf = function( torrents, id )
|
|
|
|
{
|
|
|
|
var low = 0;
|
|
|
|
var high = torrents.length;
|
|
|
|
while( low < high ) {
|
|
|
|
var mid = Math.floor( ( low + high ) / 2 );
|
|
|
|
if( torrents[mid].id() < id )
|
|
|
|
low = mid + 1;
|
|
|
|
else
|
|
|
|
high = mid;
|
|
|
|
}
|
|
|
|
if( ( low < torrents.length ) && ( torrents[low].id() == id ) ) {
|
|
|
|
return low;
|
|
|
|
} else {
|
|
|
|
return -1; // not found
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
function TorrentFile(file_data) {
|
|
|
|
this.initialize(file_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TorrentFile.prototype = {
|
|
|
|
initialize: function(file_data) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._dirty = true;
|
2009-03-14 21:33:08 +00:00
|
|
|
this._torrent = file_data.torrent;
|
2009-05-24 00:02:43 +00:00
|
|
|
this._index = file_data.index;
|
2009-05-25 01:18:51 +00:00
|
|
|
var name = file_data.name.substring (file_data.name.lastIndexOf('/')+1);
|
2009-03-14 21:33:08 +00:00
|
|
|
this.readAttributes(file_data);
|
2009-05-23 06:09:57 +00:00
|
|
|
|
|
|
|
var li = document.createElement('li');
|
2009-05-25 04:07:48 +00:00
|
|
|
li.id = 't' + this._torrent.id() + 'f' + this._index;
|
2009-05-24 16:05:28 +00:00
|
|
|
li.classNameConst = 'inspector_torrent_file_list_entry ' + ((this._index%2)?'odd':'even');
|
2009-05-24 00:02:43 +00:00
|
|
|
li.className = li.classNameConst;
|
2009-05-23 06:09:57 +00:00
|
|
|
|
|
|
|
var wanted_div = document.createElement('div');
|
|
|
|
wanted_div.className = "file_wanted_control";
|
|
|
|
|
|
|
|
var pri_div = document.createElement('div');
|
2009-05-24 00:02:43 +00:00
|
|
|
pri_div.classNameConst = "file_priority_control";
|
|
|
|
pri_div.className = pri_div.classNameConst;
|
2009-05-23 06:09:57 +00:00
|
|
|
|
|
|
|
var file_div = document.createElement('div');
|
|
|
|
file_div.className = "inspector_torrent_file_list_entry_name";
|
2009-05-25 01:18:51 +00:00
|
|
|
file_div.innerHTML = name.replace(/([\/_\.])/g, "$1​");
|
2009-05-23 06:09:57 +00:00
|
|
|
|
|
|
|
var prog_div = document.createElement('div');
|
|
|
|
prog_div.className = "inspector_torrent_file_list_entry_progress";
|
|
|
|
|
|
|
|
li.appendChild(wanted_div);
|
|
|
|
li.appendChild(pri_div);
|
|
|
|
li.appendChild(file_div);
|
|
|
|
li.appendChild(prog_div);
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-23 18:09:56 +00:00
|
|
|
this._element = li;
|
2009-05-24 00:02:43 +00:00
|
|
|
this._priority_control = pri_div;
|
2009-05-23 06:09:57 +00:00
|
|
|
this._progress = $(prog_div);
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2009-05-23 20:39:55 +00:00
|
|
|
|
|
|
|
update: function(file_data) {
|
|
|
|
this.readAttributes(file_data);
|
|
|
|
this.refreshHTML();
|
|
|
|
},
|
2009-05-25 01:18:51 +00:00
|
|
|
|
|
|
|
isDone: function () {
|
|
|
|
return this._done >= this._size;
|
|
|
|
},
|
|
|
|
|
|
|
|
isEditable: function () {
|
|
|
|
return (this._torrent._file_model.length>1) && !this.isDone();
|
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
readAttributes: function(file_data) {
|
2009-05-25 01:18:51 +00:00
|
|
|
if( file_data.index !== undefined && file_data.index !== this._index ) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._index = file_data.index;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2009-05-25 01:18:51 +00:00
|
|
|
if( file_data.bytesCompleted !== undefined && file_data.bytesCompleted !== this._done ) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._done = file_data.bytesCompleted;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2009-05-25 01:18:51 +00:00
|
|
|
if( file_data.length !== undefined && file_data.length !== this._size ) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._size = file_data.length;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2009-05-25 01:18:51 +00:00
|
|
|
if( file_data.priority !== undefined && file_data.priority !== this._prio ) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._prio = file_data.priority;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2009-05-25 01:18:51 +00:00
|
|
|
if( file_data.wanted !== undefined && file_data.wanted !== this._wanted ) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._wanted = file_data.wanted;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
element: function() {
|
2009-05-23 18:09:56 +00:00
|
|
|
return $(this._element);
|
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-23 18:09:56 +00:00
|
|
|
domElement: function() {
|
2009-03-14 21:33:08 +00:00
|
|
|
return this._element;
|
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 01:18:51 +00:00
|
|
|
setPriority: function(prio) {
|
|
|
|
if (this.isEditable()) {
|
|
|
|
var cmd;
|
|
|
|
switch( prio ) {
|
|
|
|
case 1: cmd = 'priority-high'; break;
|
|
|
|
case -1: cmd = 'priority-low'; break;
|
|
|
|
default: cmd = 'priority-normal'; break;
|
|
|
|
}
|
|
|
|
this._prio = prio;
|
|
|
|
this._dirty = true;
|
|
|
|
this._torrent._controller.changeFileCommand( cmd, this._torrent, this );
|
|
|
|
}
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-12-06 03:21:08 +00:00
|
|
|
setWanted: function(wanted, process) {
|
2009-04-29 11:59:29 +00:00
|
|
|
this._dirty = true;
|
2009-03-14 21:33:08 +00:00
|
|
|
this._wanted = wanted;
|
2009-07-06 23:51:02 +00:00
|
|
|
if(!iPhone)
|
2010-06-21 13:14:33 +00:00
|
|
|
this.element().toggleClass( 'skip', !wanted );
|
2009-12-06 03:21:08 +00:00
|
|
|
if (process) {
|
|
|
|
var command = wanted ? 'files-wanted' : 'files-unwanted';
|
|
|
|
this._torrent._controller.changeFileCommand(command, this._torrent, this);
|
|
|
|
}
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
toggleWanted: function() {
|
2009-05-25 01:18:51 +00:00
|
|
|
if (this.isEditable())
|
2009-12-06 03:21:08 +00:00
|
|
|
this.setWanted( !this._wanted, true );
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
refreshHTML: function() {
|
2009-04-29 11:59:29 +00:00
|
|
|
if( this._dirty ) {
|
|
|
|
this._dirty = false;
|
|
|
|
this.refreshProgressHTML();
|
|
|
|
this.refreshWantedHTML();
|
|
|
|
this.refreshPriorityHTML();
|
|
|
|
}
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
refreshProgressHTML: function() {
|
2010-10-12 17:38:03 +00:00
|
|
|
var c = [ Transmission.fmt.size(this._done),
|
|
|
|
' of ',
|
|
|
|
Transmission.fmt.size(this._size),
|
|
|
|
' (',
|
|
|
|
this._size ? Transmission.fmt.percentString(100 * this._done / this._size) : '100',
|
|
|
|
'%)' ].join('');
|
2009-05-25 01:18:51 +00:00
|
|
|
setInnerHTML(this._progress[0], c);
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
refreshWantedHTML: function() {
|
2009-05-25 01:18:51 +00:00
|
|
|
var e = this.domElement();
|
2010-10-12 17:38:03 +00:00
|
|
|
var c = [ e.classNameConst ];
|
|
|
|
if(!this._wanted) { c.push( 'skip' ); }
|
|
|
|
if(this.isDone()) { c.push( 'complete' ); }
|
|
|
|
e.className = c.join(' ');
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
refreshPriorityHTML: function() {
|
2009-05-24 00:02:43 +00:00
|
|
|
var e = this._priority_control;
|
2010-10-12 17:38:03 +00:00
|
|
|
var c = [ e.classNameConst ];
|
2009-05-24 00:02:43 +00:00
|
|
|
switch( this._prio ) {
|
2010-10-12 17:38:03 +00:00
|
|
|
case 1 : c.push( 'high' ); break;
|
|
|
|
case -1 : c.push( 'low' ); break;
|
|
|
|
default : c.push( 'normal' ); break;
|
2009-05-24 00:02:43 +00:00
|
|
|
}
|
2010-10-12 17:38:03 +00:00
|
|
|
e.className = c.join(' ');
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
fileWantedControlClicked: function(event) {
|
2009-05-25 04:07:48 +00:00
|
|
|
this.toggleWanted();
|
2009-03-14 21:33:08 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2009-05-25 04:07:48 +00:00
|
|
|
filePriorityControlClicked: function(event, element) {
|
2009-03-14 21:33:08 +00:00
|
|
|
var x = event.pageX;
|
2009-05-25 04:07:48 +00:00
|
|
|
while (element !== null) {
|
|
|
|
x = x - element.offsetLeft;
|
|
|
|
element = element.offsetParent;
|
2009-03-14 21:33:08 +00:00
|
|
|
}
|
2009-05-25 04:07:48 +00:00
|
|
|
|
2009-05-25 01:18:51 +00:00
|
|
|
var prio;
|
2009-07-06 23:51:02 +00:00
|
|
|
if(iPhone)
|
|
|
|
{
|
|
|
|
if( x < 8 ) prio = -1;
|
|
|
|
else if( x < 27 ) prio = 0;
|
|
|
|
else prio = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( x < 12 ) prio = -1;
|
|
|
|
else if( x < 23 ) prio = 0;
|
|
|
|
else prio = 1;
|
|
|
|
}
|
2009-05-25 04:07:48 +00:00
|
|
|
this.setPriority( prio );
|
2009-03-14 21:33:08 +00:00
|
|
|
}
|
|
|
|
};
|