/* * 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 */ function Torrent(controller,data) { this.initialize(controller,data); } // 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 Torrent.prototype = { /* * Constructor */ initialize: function(controller, data) { this._id = data.id; this._is_private = data.isPrivate; this._hashString = data.hashString; this._date = data.addedDate; this._size = data.totalSize; this._tracker = data.announceURL; this._comment = data.comment; this._creator = data.creator; this._creator_date = data.dateCreated; this._sizeWhenDone = data.sizeWhenDone; this._name = data.name; this._name_lc = this._name.toLowerCase( ); // Create a new
  • element var element = $('
  • '); element.addClass('torrent'); element[0].id = 'torrent_' + data.id; element._torrent = this; this._element = element; this._controller = controller; controller._rows.push( element ); // Create the 'name'
    var e = document.createElement( 'div' ); e.className = 'torrent_name'; element[0].appendChild( e ); element._name_container = e; // Create the 'progress details'
    e = document.createElement( 'div' ); e.className = 'torrent_progress_details'; element[0].appendChild( e ); element._progress_details_container = e; // Create the 'in progress' bar e = document.createElement( 'div' ); e.className = 'torrent_progress_bar incomplete'; e.style.width = '0%'; element[0].appendChild( e ); element._progress_complete_container = e; // Create the 'incomplete' bar (initially hidden) e = document.createElement( 'div' ); e.className = 'torrent_progress_bar incomplete'; e.style.display = 'none'; element[0].appendChild( e ); element._progress_incomplete_container = e; // Add the pause/resume button - don't specify the // image or alt text until the 'refresh()' function // (depends on torrent state) var image = document.createElement( 'div' ); image.className = 'torrent_pause'; e = document.createElement( 'a' ); e.appendChild( image ); element[0].appendChild( e ); element._pause_resume_button_image = image; //element._pause_resume_button = e; if (!iPhone) $(e).bind('click', {element: element}, this.clickPauseResumeButton); // Create the 'peer details'
    e = document.createElement( 'div' ); e.className = 'torrent_peer_details'; element[0].appendChild( e ); element._peer_details_container = e; // Set the torrent click observer element.bind('click', {element: element}, this.clickTorrent); if (!iPhone) element.bind('contextmenu', {element: element}, this.rightClickTorrent); // Safari hack - first torrent needs to be moved down for some reason. Seems to be ok when // using
  • 's in straight html, but adding through the DOM gets a bit odd. if ($.browser.safari) this._element.css('margin-top', '7px'); // insert the element $('#torrent_list').append(this._element); this._files = []; this.initializeTorrentFilesInspectorGroup(); if(data.files){ if(data.files.length == 1) this._fileList.addClass('single_file'); for (var i = 0; i < data.files.length; i++) { var file = data.files[i]; file.index = i; file.torrent = this; file.priority = data.fileStats[i].priority; file.wanted = data.fileStats[i].wanted; var torrentFile = new TorrentFile(file); this._files.push(torrentFile); var class = (i % 2 ? 'even' : 'odd') + ' inspector_torrent_file_list_entry'; torrentFile.element()[0].className = class; this._fileList[0].appendChild(torrentFile.element()[0]); } } // Update all the labels etc this.refresh(data); }, initializeTorrentFilesInspectorGroup: function(length) { this._fileList = $('