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 Transmission
|
|
|
|
*/
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
function Transmission(){
|
|
|
|
this.initialize();
|
2009-08-12 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
Transmission.prototype =
|
|
|
|
{
|
|
|
|
/*--------------------------------------------
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
* C O N S T R U C T O R
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
*--------------------------------------------*/
|
|
|
|
|
|
|
|
initialize: function()
|
|
|
|
{
|
|
|
|
// Initialize the helper classes
|
|
|
|
this.remote = new TransmissionRemote(this);
|
|
|
|
|
|
|
|
// Initialize the implementation fields
|
|
|
|
this._current_search = '';
|
2009-06-07 23:55:42 +00:00
|
|
|
this._torrents = { };
|
2008-07-10 23:57:46 +00:00
|
|
|
this._rows = [ ];
|
|
|
|
|
|
|
|
// Initialize the clutch preferences
|
|
|
|
Prefs.getClutchPrefs( this );
|
|
|
|
|
|
|
|
this.preloadImages();
|
|
|
|
|
|
|
|
// Set up user events
|
2009-05-22 22:45:09 +00:00
|
|
|
var tr = this;
|
2009-05-23 02:28:04 +00:00
|
|
|
$('#pause_all_link').bind('click', function(e){ tr.stopAllClicked(e); });
|
|
|
|
$('#resume_all_link').bind('click', function(e){ tr.startAllClicked(e); });
|
|
|
|
$('#pause_selected_link').bind('click', function(e){ tr.stopSelectedClicked(e); } );
|
|
|
|
$('#resume_selected_link').bind('click', function(e){ tr.startSelectedClicked(e); });
|
|
|
|
$('#remove_link').bind('click', function(e){ tr.removeClicked(e); });
|
|
|
|
$('#filter_all_link').parent().bind('click', function(e){ tr.showAllClicked(e); });
|
|
|
|
$('#filter_downloading_link').parent().bind('click', function(e){ tr.showDownloadingClicked(e); });
|
|
|
|
$('#filter_seeding_link').parent().bind('click', function(e){ tr.showSeedingClicked(e); });
|
|
|
|
$('#filter_paused_link').parent().bind('click', function(e){ tr.showPausedClicked(e); });
|
|
|
|
$('#prefs_save_button').bind('click', function(e) { tr.savePrefsClicked(e); return false;});
|
|
|
|
$('#prefs_cancel_button').bind('click', function(e){ tr.cancelPrefsClicked(e); return false; });
|
2010-03-11 04:50:04 +00:00
|
|
|
$('#stats_close_button').bind('click', function(e){ tr.closeStatsClicked(e); return false; });
|
2009-05-23 04:07:24 +00:00
|
|
|
$('.inspector_tab').bind('click', function(e){ tr.inspectorTabClicked(e, this); });
|
2009-05-25 04:07:48 +00:00
|
|
|
$('.file_wanted_control').live('click', function(e){ tr.fileWantedClicked(e, this); });
|
|
|
|
$('.file_priority_control').live('click', function(e){ tr.filePriorityClicked(e, this); });
|
2009-12-06 03:21:08 +00:00
|
|
|
$('#files_select_all').live('click', function(e){ tr.filesSelectAllClicked(e, this); });
|
|
|
|
$('#files_deselect_all').live('click', function(e){ tr.filesDeselectAllClicked(e, this); });
|
2009-07-07 01:11:30 +00:00
|
|
|
$('#open_link').bind('click', function(e){ tr.openTorrentClicked(e); });
|
|
|
|
$('#upload_confirm_button').bind('click', function(e){ tr.confirmUploadClicked(e); return false;});
|
|
|
|
$('#upload_cancel_button').bind('click', function(e){ tr.cancelUploadClicked(e); return false; });
|
2009-11-10 05:42:57 +00:00
|
|
|
$('#turtle_button').bind('click', function(e){ tr.toggleTurtleClicked(e); return false; });
|
2009-11-10 05:43:14 +00:00
|
|
|
$('#prefs_tab_general_tab').click(function(e){ changeTab(this, 'prefs_tab_general') });
|
|
|
|
$('#prefs_tab_speed_tab').click(function(e){ changeTab(this, 'prefs_tab_speed') });
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
if (iPhone) {
|
2009-06-23 01:52:20 +00:00
|
|
|
$('#inspector_close').bind('click', function(e){ tr.hideInspector(); });
|
2009-05-23 02:28:04 +00:00
|
|
|
$('#preferences_link').bind('click', function(e){ tr.releaseClutchPreferencesButton(e); });
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
2009-05-23 02:28:04 +00:00
|
|
|
$(document).bind('keydown', function(e){ tr.keyDown(e); });
|
2009-05-25 13:31:03 +00:00
|
|
|
$('#torrent_container').bind('click', function(e){ tr.deselectAll( true ); });
|
2009-05-23 02:28:04 +00:00
|
|
|
$('#filter_toggle_link').bind('click', function(e){ tr.toggleFilterClicked(e); });
|
|
|
|
$('#inspector_link').bind('click', function(e){ tr.toggleInspectorClicked(e); });
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
this.setupSearchBox();
|
|
|
|
this.createContextMenu();
|
|
|
|
this.createSettingsMenu();
|
|
|
|
}
|
2009-11-10 05:42:57 +00:00
|
|
|
this.initTurtleDropDowns();
|
2009-05-23 18:09:56 +00:00
|
|
|
|
2009-05-24 15:48:18 +00:00
|
|
|
this._torrent_list = $('#torrent_list')[0];
|
|
|
|
this._inspector_file_list = $('#inspector_file_list')[0];
|
2010-01-31 02:42:48 +00:00
|
|
|
this._inspector_trackers_list = $('#inspector_trackers_list')[0];
|
2009-05-24 15:48:18 +00:00
|
|
|
this._inspector_tab_files = $('#inspector_tab_files')[0];
|
|
|
|
this._toolbar_buttons = $('#torrent_global_menu ul li');
|
|
|
|
this._toolbar_pause_button = $('li#pause_selected')[0];
|
|
|
|
this._toolbar_pause_all_button = $('li#pause_all')[0];
|
|
|
|
this._toolbar_start_button = $('li#resume_selected')[0];
|
|
|
|
this._toolbar_start_all_button = $('li#resume_all')[0];
|
|
|
|
this._toolbar_remove_button = $('li#remove')[0];
|
|
|
|
this._context_pause_button = $('li#context_pause_selected')[0];
|
|
|
|
this._context_start_button = $('li#context_resume_selected')[0];
|
2009-05-24 18:39:21 +00:00
|
|
|
|
|
|
|
var ti = '#torrent_inspector_';
|
|
|
|
this._inspector = { };
|
|
|
|
this._inspector._info_tab = { };
|
2010-04-20 01:48:40 +00:00
|
|
|
this._inspector._info_tab.availability = $(ti+'availability')[0];
|
2009-05-24 18:39:21 +00:00
|
|
|
this._inspector._info_tab.comment = $(ti+'comment')[0];
|
|
|
|
this._inspector._info_tab.creator_date = $(ti+'creator_date')[0];
|
|
|
|
this._inspector._info_tab.creator = $(ti+'creator')[0];
|
2009-06-26 03:03:17 +00:00
|
|
|
this._inspector._info_tab.download_dir = $(ti+'download_dir')[0];
|
2009-05-24 18:39:21 +00:00
|
|
|
this._inspector._info_tab.downloaded = $(ti+'downloaded')[0];
|
|
|
|
this._inspector._info_tab.download_from = $(ti+'download_from')[0];
|
|
|
|
this._inspector._info_tab.download_speed = $(ti+'download_speed')[0];
|
|
|
|
this._inspector._info_tab.error = $(ti+'error')[0];
|
|
|
|
this._inspector._info_tab.hash = $(ti+'hash')[0];
|
|
|
|
this._inspector._info_tab.have = $(ti+'have')[0];
|
|
|
|
this._inspector._info_tab.name = $(ti+'name')[0];
|
|
|
|
this._inspector._info_tab.progress = $(ti+'progress')[0];
|
|
|
|
this._inspector._info_tab.ratio = $(ti+'ratio')[0];
|
|
|
|
this._inspector._info_tab.secure = $(ti+'secure')[0];
|
|
|
|
this._inspector._info_tab.size = $(ti+'size')[0];
|
|
|
|
this._inspector._info_tab.state = $(ti+'state')[0];
|
2009-10-31 02:19:45 +00:00
|
|
|
this._inspector._info_tab.pieces = $(ti+'pieces')[0];
|
2009-05-24 18:39:21 +00:00
|
|
|
this._inspector._info_tab.uploaded = $(ti+'uploaded')[0];
|
|
|
|
this._inspector._info_tab.upload_speed = $(ti+'upload_speed')[0];
|
|
|
|
this._inspector._info_tab.upload_to = $(ti+'upload_to')[0];
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Setup the preference box
|
|
|
|
this.setupPrefConstraints();
|
|
|
|
|
|
|
|
// Setup the prefs gui
|
|
|
|
this.initializeSettings( );
|
|
|
|
|
|
|
|
// Get preferences & torrents from the daemon
|
2009-05-22 22:45:09 +00:00
|
|
|
var tr = this;
|
2009-07-28 04:53:08 +00:00
|
|
|
var async = false;
|
|
|
|
this.loadDaemonPrefs( async );
|
2010-03-11 04:50:04 +00:00
|
|
|
this.loadDaemonStats( async );
|
2009-07-28 05:23:30 +00:00
|
|
|
this.initializeAllTorrents();
|
2009-05-22 22:45:09 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
this.togglePeriodicRefresh( true );
|
2009-11-14 14:57:47 +00:00
|
|
|
this.togglePeriodicSessionRefresh( true );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2009-07-28 04:53:08 +00:00
|
|
|
loadDaemonPrefs: function( async ){
|
2009-07-28 04:53:04 +00:00
|
|
|
var tr = this;
|
|
|
|
this.remote.loadDaemonPrefs( function(data){
|
|
|
|
var o = data.arguments;
|
|
|
|
Prefs.getClutchPrefs( o );
|
|
|
|
tr.updatePrefs( o );
|
2009-07-28 04:53:08 +00:00
|
|
|
}, async );
|
2009-07-28 04:53:04 +00:00
|
|
|
},
|
|
|
|
|
2010-03-11 04:50:04 +00:00
|
|
|
loadDaemonStats: function( async ){
|
|
|
|
var tr = this;
|
|
|
|
this.remote.loadDaemonStats( function(data){
|
|
|
|
var o = data.arguments;
|
|
|
|
tr.updateStats( o );
|
|
|
|
}, async );
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
preloadImages: function() {
|
|
|
|
if (iPhone) {
|
|
|
|
this.loadImages(
|
|
|
|
'images/buttons/info_general.png',
|
2009-03-14 21:33:08 +00:00
|
|
|
'images/buttons/info_activity.png',
|
|
|
|
'images/buttons/info_files.png',
|
2008-07-10 23:57:46 +00:00
|
|
|
'images/buttons/toolbar_buttons.png',
|
|
|
|
'images/graphics/filter_bar.png',
|
|
|
|
'images/graphics/iphone_chrome.png',
|
2009-03-14 21:33:08 +00:00
|
|
|
'images/graphics/logo.png'
|
2008-07-10 23:57:46 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.loadImages(
|
|
|
|
'images/buttons/info_general.png',
|
2009-03-14 21:33:08 +00:00
|
|
|
'images/buttons/info_activity.png',
|
|
|
|
'images/buttons/info_files.png',
|
2008-07-10 23:57:46 +00:00
|
|
|
'images/buttons/tab_backgrounds.png',
|
|
|
|
'images/buttons/toolbar_buttons.png',
|
|
|
|
'images/buttons/torrent_buttons.png',
|
2009-03-14 21:33:08 +00:00
|
|
|
'images/buttons/file_wanted_buttons.png',
|
|
|
|
'images/buttons/file_priority_buttons.png',
|
2008-07-10 23:57:46 +00:00
|
|
|
'images/graphics/chrome.png',
|
|
|
|
'images/graphics/filter_bar.png',
|
|
|
|
'images/graphics/logo.png',
|
|
|
|
'images/graphics/transfer_arrows.png',
|
|
|
|
'images/progress/progress.png'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadImages: function() {
|
2009-05-24 16:05:28 +00:00
|
|
|
for( var i=0, row; row=arguments[i]; ++i )
|
|
|
|
jQuery("<img>").attr("src", row);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Set up the preference validation
|
|
|
|
*/
|
|
|
|
setupPrefConstraints: function() {
|
|
|
|
// only allow integers for speed limit & port options
|
|
|
|
$('div.preference input[@type=text]:not(#download_location)').blur( function() {
|
|
|
|
this.value = this.value.replace(/[^0-9]/gi, '');
|
|
|
|
if (this.value == '') {
|
|
|
|
if ($(this).is('#refresh_rate')) {
|
|
|
|
this.value = 5;
|
|
|
|
} else {
|
|
|
|
this.value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Load the clutch prefs and init the GUI according to those prefs
|
|
|
|
*/
|
|
|
|
initializeSettings: function( )
|
|
|
|
{
|
|
|
|
Prefs.getClutchPrefs( this );
|
|
|
|
|
|
|
|
// iPhone conditions in the section allow us to not
|
|
|
|
// include transmenu js to save some bandwidth; if we
|
|
|
|
// start using prefs on iPhone we need to weed
|
|
|
|
// transmenu refs out of that too.
|
|
|
|
|
|
|
|
$('#filter_' + this[Prefs._FilterMode] + '_link').parent().addClass('selected');
|
|
|
|
|
|
|
|
if (!iPhone) $('#sort_by_' + this[Prefs._SortMethod] ).selectMenuItem();
|
|
|
|
|
|
|
|
if (!iPhone && ( this[Prefs._SortDirection] == Prefs._SortDescending ) )
|
|
|
|
$('#reverse_sort_order').selectMenuItem();
|
|
|
|
|
|
|
|
if( this[Prefs._ShowFilter] )
|
|
|
|
this.showFilter( );
|
2009-06-23 01:52:20 +00:00
|
|
|
|
|
|
|
if( !iPhone && this[Prefs._ShowInspector] )
|
2008-07-10 23:57:46 +00:00
|
|
|
this.showInspector( );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the search box
|
|
|
|
*/
|
|
|
|
setupSearchBox: function()
|
|
|
|
{
|
|
|
|
var tr = this;
|
|
|
|
var search_box = $('#torrent_search');
|
2008-08-09 04:38:51 +00:00
|
|
|
search_box.bind('keyup click', {transmission: this}, function(event) {
|
2008-07-10 23:57:46 +00:00
|
|
|
tr.setSearch(this.value);
|
|
|
|
});
|
2008-08-09 04:38:51 +00:00
|
|
|
if (!$.browser.safari)
|
|
|
|
{
|
2008-09-18 21:25:23 +00:00
|
|
|
search_box.addClass('blur');
|
2008-08-09 04:38:51 +00:00
|
|
|
search_box[0].value = 'Filter';
|
|
|
|
search_box.bind('blur', {transmission: this}, function(event) {
|
|
|
|
if (this.value == '') {
|
|
|
|
$(this).addClass('blur');
|
|
|
|
this.value = 'Filter';
|
|
|
|
tr.setSearch(null);
|
|
|
|
}
|
|
|
|
}).bind('focus', {}, function(event) {
|
|
|
|
if ($(this).is('.blur')) {
|
|
|
|
this.value = '';
|
|
|
|
$(this).removeClass('blur');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
contextStopSelected: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.stopSelectedTorrents( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
contextStartSelected: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.startSelectedTorrents( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
contextRemoveSelected: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.removeSelectedTorrents( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-02-12 17:20:43 +00:00
|
|
|
contextRemoveDataSelected: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.removeSelectedTorrentsAndData( );
|
2009-02-12 17:20:43 +00:00
|
|
|
},
|
2009-03-04 00:19:11 +00:00
|
|
|
contextVerifySelected: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.verifySelectedTorrents( );
|
2009-03-04 00:19:11 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
contextToggleInspector: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.toggleInspector( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
contextSelectAll: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.selectAll( true );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
contextDeselectAll: function( ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.deselectAll( true );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Create the torrent right-click menu
|
|
|
|
*/
|
|
|
|
createContextMenu: function() {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
var bindings = {
|
2009-05-23 02:28:04 +00:00
|
|
|
context_pause_selected: function(e){ tr.contextStopSelected(e); },
|
|
|
|
context_resume_selected: function(e){ tr.contextStartSelected(e); },
|
|
|
|
context_remove: function(e){ tr.contextRemoveSelected(e); },
|
|
|
|
context_removedata: function(e){ tr.contextRemoveDataSelected(e); },
|
|
|
|
context_verify: function(e){ tr.contextVerifySelected(e); },
|
|
|
|
context_toggle_inspector: function(e){ tr.contextToggleInspector(e); },
|
|
|
|
context_select_all: function(e){ tr.contextSelectAll(e); },
|
|
|
|
context_deselect_all: function(e){ tr.contextDeselectAll(e); }
|
2008-07-10 23:57:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Setup the context menu
|
|
|
|
$('ul#torrent_list').contextMenu('torrent_context_menu', {
|
|
|
|
bindings: bindings,
|
|
|
|
menuStyle: Menu.context.menu_style,
|
|
|
|
itemStyle: Menu.context.item_style,
|
|
|
|
itemHoverStyle: Menu.context.item_hover_style,
|
|
|
|
itemDisabledStyle: Menu.context.item_disabled_style,
|
|
|
|
shadow: false,
|
|
|
|
boundingElement: $('div#torrent_container'),
|
|
|
|
boundingRightPad: 20,
|
2009-05-25 15:46:25 +00:00
|
|
|
boundingBottomPad: 5,
|
2009-08-12 14:40:32 +00:00
|
|
|
onContextMenu: function(e) {
|
2010-03-14 17:31:16 +00:00
|
|
|
var closestRow = $(e.target).closest('.torrent')[0]._torrent;
|
|
|
|
if(!closestRow.isSelected())
|
|
|
|
tr.setSelectedTorrent( closestRow, true );
|
|
|
|
return true;
|
2009-05-25 15:46:25 +00:00
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
});
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Create the footer settings menu
|
|
|
|
*/
|
|
|
|
createSettingsMenu: function() {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#settings_menu').transMenu({
|
|
|
|
selected_char: '✔',
|
|
|
|
direction: 'up',
|
2009-05-23 02:56:55 +00:00
|
|
|
onClick: function(e){ return tr.processSettingsMenuEvent(e); }
|
2008-07-10 23:57:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#unlimited_download_rate').selectMenuItem();
|
|
|
|
$('#unlimited_upload_rate').selectMenuItem();
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2009-11-10 05:42:57 +00:00
|
|
|
initTurtleDropDowns: function() {
|
2009-12-09 04:19:37 +00:00
|
|
|
var i, out, hour, mins, start, end, value, content;
|
2009-11-10 05:42:57 +00:00
|
|
|
// Build the list of times
|
|
|
|
out = "";
|
2009-12-09 04:19:37 +00:00
|
|
|
start = $('#turtle_start_time')[0];
|
|
|
|
end = $('#turtle_end_time')[0];
|
2009-11-10 05:42:57 +00:00
|
|
|
for (i = 0; i < 24 * 4; i++) {
|
|
|
|
hour = parseInt(i / 4);
|
|
|
|
mins = ((i % 4) * 15);
|
2009-12-09 04:19:37 +00:00
|
|
|
|
|
|
|
value = (i * 15);
|
|
|
|
content = hour + ":" + (mins == 0 ? "00" : mins);
|
|
|
|
start.options[i] = new Option(content, value);
|
|
|
|
end.options[i] = new Option(content, value);
|
2009-11-10 05:42:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*--------------------------------------------
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
* U T I L I T I E S
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
*--------------------------------------------*/
|
|
|
|
|
|
|
|
getAllTorrents: function()
|
|
|
|
{
|
2009-06-07 23:55:42 +00:00
|
|
|
var torrents = [];
|
|
|
|
for(var key in this._torrents)
|
|
|
|
torrents.push(this._torrents[key]);
|
|
|
|
return torrents;
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getVisibleTorrents: function()
|
|
|
|
{
|
|
|
|
var torrents = [ ];
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=this._rows[i]; ++i )
|
2009-05-25 13:31:03 +00:00
|
|
|
if( row._torrent && ( row[0].style.display != 'none' ) )
|
2009-05-24 15:48:18 +00:00
|
|
|
torrents.push( row._torrent );
|
2008-07-10 23:57:46 +00:00
|
|
|
return torrents;
|
|
|
|
},
|
|
|
|
|
|
|
|
getSelectedTorrents: function()
|
|
|
|
{
|
|
|
|
var v = this.getVisibleTorrents( );
|
|
|
|
var s = [ ];
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=v[i]; ++i )
|
|
|
|
if( row.isSelected( ) )
|
|
|
|
s.push( row );
|
2008-07-10 23:57:46 +00:00
|
|
|
return s;
|
|
|
|
},
|
2009-03-14 21:33:08 +00:00
|
|
|
|
|
|
|
getDeselectedTorrents: function() {
|
|
|
|
var visible_torrent_ids = jQuery.map(this.getVisibleTorrents(), function(t) { return t.id(); } );
|
|
|
|
var s = [ ];
|
|
|
|
jQuery.each( this.getAllTorrents( ), function() {
|
|
|
|
var visible = (-1 != jQuery.inArray(this.id(), visible_torrent_ids));
|
|
|
|
if (!this.isSelected() || !visible)
|
|
|
|
s.push( this );
|
|
|
|
} );
|
|
|
|
return s;
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
getVisibleRows: function()
|
|
|
|
{
|
|
|
|
var rows = [ ];
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=this._rows[i]; ++i )
|
2009-05-25 13:31:03 +00:00
|
|
|
if( row[0].style.display != 'none' )
|
2009-05-24 15:48:18 +00:00
|
|
|
rows.push( row );
|
2008-07-10 23:57:46 +00:00
|
|
|
return rows;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTorrentIndex: function( rows, torrent )
|
|
|
|
{
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=rows[i]; ++i )
|
|
|
|
if( row._torrent == torrent )
|
2008-07-10 23:57:46 +00:00
|
|
|
return i;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPref: function( key, val )
|
|
|
|
{
|
|
|
|
this[key] = val;
|
|
|
|
Prefs.setValue( key, val );
|
|
|
|
},
|
|
|
|
|
|
|
|
scrollToElement: function( e )
|
|
|
|
{
|
2009-05-25 13:31:03 +00:00
|
|
|
if( iPhone )
|
|
|
|
return;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
var container = $('#torrent_container');
|
|
|
|
var scrollTop = container.scrollTop( );
|
|
|
|
var innerHeight = container.innerHeight( );
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
var offsetTop = e[0].offsetTop;
|
|
|
|
var offsetHeight = e.outerHeight( );
|
|
|
|
|
|
|
|
if( offsetTop < scrollTop )
|
|
|
|
container.scrollTop( offsetTop );
|
|
|
|
else if( innerHeight + scrollTop < offsetTop + offsetHeight )
|
|
|
|
container.scrollTop( offsetTop + offsetHeight - innerHeight );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2009-07-28 05:23:34 +00:00
|
|
|
seedRatioLimit: function(){
|
2009-07-28 04:52:47 +00:00
|
|
|
if(this._prefs && this._prefs['seedRatioLimited'])
|
|
|
|
return this._prefs['seedRatioLimit'];
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
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 L E C T I O N
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
*--------------------------------------------*/
|
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
setSelectedTorrent: function( torrent, doUpdate ) {
|
2008-07-10 23:57:46 +00:00
|
|
|
this.deselectAll( );
|
2009-05-25 13:31:03 +00:00
|
|
|
this.selectTorrent( torrent, doUpdate );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
selectElement: function( e, doUpdate ) {
|
2010-01-15 03:41:39 +00:00
|
|
|
e.addClass('selected');
|
2008-07-10 23:57:46 +00:00
|
|
|
this.scrollToElement( e );
|
|
|
|
if( doUpdate )
|
|
|
|
this.selectionChanged( );
|
2009-05-25 13:31:03 +00:00
|
|
|
},
|
|
|
|
selectRow: function( rowIndex, doUpdate ) {
|
|
|
|
this.selectElement( this._rows[rowIndex], doUpdate );
|
|
|
|
},
|
|
|
|
selectTorrent: function( torrent, doUpdate ) {
|
|
|
|
if( torrent._element )
|
|
|
|
this.selectElement( torrent._element, doUpdate );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
deselectElement: function( e, doUpdate ) {
|
2010-01-15 03:41:39 +00:00
|
|
|
e.removeClass('selected');
|
2008-07-10 23:57:46 +00:00
|
|
|
if( doUpdate )
|
|
|
|
this.selectionChanged( );
|
|
|
|
},
|
2009-05-25 13:31:03 +00:00
|
|
|
deselectTorrent: function( torrent, doUpdate ) {
|
|
|
|
if( torrent._element )
|
|
|
|
this.deselectElement( torrent._element, doUpdate );
|
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
selectAll: function( doUpdate ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=tr._rows[i]; ++i )
|
|
|
|
tr.selectElement( row );
|
2008-07-10 23:57:46 +00:00
|
|
|
if( doUpdate )
|
|
|
|
tr.selectionChanged();
|
|
|
|
},
|
|
|
|
deselectAll: function( doUpdate ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=tr._rows[i]; ++i )
|
|
|
|
tr.deselectElement( row );
|
2009-05-25 13:31:03 +00:00
|
|
|
tr._last_torrent_clicked = null;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( doUpdate )
|
|
|
|
tr.selectionChanged( );
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Select a range from this torrent to the last clicked torrent
|
|
|
|
*/
|
2009-05-25 13:31:03 +00:00
|
|
|
selectRange: function( torrent, doUpdate )
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2009-05-25 13:31:03 +00:00
|
|
|
if( !this._last_torrent_clicked )
|
|
|
|
{
|
|
|
|
this.selectTorrent( torrent );
|
|
|
|
}
|
|
|
|
else // select the range between the prevous & current
|
|
|
|
{
|
|
|
|
var rows = this.getVisibleRows( );
|
|
|
|
var i = this.getTorrentIndex( rows, this._last_torrent_clicked );
|
|
|
|
var end = this.getTorrentIndex( rows, torrent );
|
|
|
|
var step = i < end ? 1 : -1;
|
|
|
|
for( ; i!=end; i+=step )
|
|
|
|
this.selectRow( i );
|
|
|
|
this.selectRow( i );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( doUpdate )
|
|
|
|
this.selectionChanged( );
|
|
|
|
},
|
2009-03-14 21:33:08 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
selectionChanged: function()
|
|
|
|
{
|
|
|
|
this.updateButtonStates();
|
|
|
|
this.updateInspector();
|
|
|
|
},
|
|
|
|
|
|
|
|
/*--------------------------------------------
|
2009-08-12 14:40:32 +00:00
|
|
|
*
|
2008-07-10 23:57:46 +00:00
|
|
|
* E V E N T 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
|
|
|
*--------------------------------------------*/
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Process key event
|
|
|
|
*/
|
|
|
|
keyDown: function(event)
|
|
|
|
{
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
var sel = tr.getSelectedTorrents( );
|
|
|
|
var rows = tr.getVisibleRows( );
|
|
|
|
var i = -1;
|
|
|
|
|
|
|
|
if( event.keyCode == 40 ) // down arrow
|
|
|
|
{
|
|
|
|
var t = sel.length ? sel[sel.length-1] : null;
|
|
|
|
i = t==null ? null : tr.getTorrentIndex(rows,t)+1;
|
|
|
|
if( i == rows.length || i == null )
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
else if( event.keyCode == 38 ) // up arrow
|
|
|
|
{
|
|
|
|
var t = sel.length ? sel[0] : null
|
|
|
|
i = t==null ? null : tr.getTorrentIndex(rows,t)-1;
|
|
|
|
if( i == -1 || i == null )
|
|
|
|
i = rows.length - 1;
|
|
|
|
}
|
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
if( 0<=i && i<rows.length ) {
|
|
|
|
tr.deselectAll( );
|
|
|
|
tr.selectRow( i, true );
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
isButtonEnabled: function(e) {
|
|
|
|
var p = e.target ? e.target.parentNode : e.srcElement.parentNode;
|
|
|
|
return p.className!='disabled' && p.parentNode.className!='disabled';
|
|
|
|
},
|
|
|
|
|
|
|
|
stopAllClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) ) {
|
|
|
|
tr.stopAllTorrents( );
|
|
|
|
tr.hideiPhoneAddressbar( );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
stopSelectedClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) ) {
|
|
|
|
tr.stopSelectedTorrents( );
|
|
|
|
tr.hideiPhoneAddressbar( );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
startAllClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) ) {
|
|
|
|
tr.startAllTorrents( );
|
|
|
|
tr.hideiPhoneAddressbar( );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
startSelectedClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) ) {
|
|
|
|
tr.startSelectedTorrents( );
|
|
|
|
tr.hideiPhoneAddressbar( );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
openTorrentClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) ) {
|
|
|
|
$('body').addClass('open_showing');
|
|
|
|
tr.uploadTorrentFile( );
|
|
|
|
}
|
|
|
|
tr.updateButtonStates();
|
|
|
|
},
|
|
|
|
|
|
|
|
hideUploadDialog: function( ) {
|
|
|
|
$('body.open_showing').removeClass('open_showing');
|
|
|
|
if (!iPhone && Safari3) {
|
|
|
|
$('div#upload_container div.dialog_window').css('top', '-205px');
|
|
|
|
setTimeout("$('#upload_container').hide();",500);
|
|
|
|
} else {
|
|
|
|
$('#upload_container').hide();
|
|
|
|
}
|
2009-05-23 02:28:04 +00:00
|
|
|
this.updateButtonStates();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelUploadClicked: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hideUploadDialog( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
confirmUploadClicked: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.uploadTorrentFile( true );
|
|
|
|
this.hideUploadDialog( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelPrefsClicked: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hidePrefsDialog( );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
savePrefsClicked: function(event)
|
|
|
|
{
|
|
|
|
// handle the clutch prefs locally
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
var rate = parseInt( $('#prefs_form #refresh_rate')[0].value );
|
|
|
|
if( rate != tr[Prefs._RefreshRate] ) {
|
|
|
|
tr.setPref( Prefs._RefreshRate, rate );
|
|
|
|
tr.togglePeriodicRefresh( false );
|
|
|
|
tr.togglePeriodicRefresh( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass the new prefs upstream to the RPC server
|
|
|
|
var o = { };
|
2010-03-17 19:23:03 +00:00
|
|
|
o[RPC._StartAddedTorrent] = $('#prefs_form #auto_start')[0].checked;
|
2009-11-10 05:42:57 +00:00
|
|
|
o[RPC._PeerPort] = parseInt( $('#prefs_form #port')[0].value );
|
|
|
|
o[RPC._UpSpeedLimit] = parseInt( $('#prefs_form #upload_rate')[0].value );
|
|
|
|
o[RPC._DownSpeedLimit] = parseInt( $('#prefs_form #download_rate')[0].value );
|
|
|
|
o[RPC._DownloadDir] = $('#prefs_form #download_location')[0].value;
|
|
|
|
o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload')[0].checked;
|
|
|
|
o[RPC._DownSpeedLimited] = $('#prefs_form #limit_download')[0].checked;
|
|
|
|
o[RPC._Encryption] = $('#prefs_form #encryption')[0].checked
|
|
|
|
? RPC._EncryptionRequired
|
|
|
|
: RPC._EncryptionPreferred;
|
|
|
|
o[RPC._TurtleDownSpeedLimit] = parseInt( $('#prefs_form #turtle_download_rate')[0].value );
|
|
|
|
o[RPC._TurtleUpSpeedLimit] = parseInt( $('#prefs_form #turtle_upload_rate')[0].value );
|
|
|
|
o[RPC._TurtleTimeEnabled] = $('#prefs_form #turtle_schedule')[0].checked;
|
|
|
|
o[RPC._TurtleTimeBegin] = parseInt( $('#prefs_form #turtle_start_time').val() );
|
|
|
|
o[RPC._TurtleTimeEnd] = parseInt( $('#prefs_form #turtle_end_time').val() );
|
|
|
|
o[RPC._TurtleTimeDay] = parseInt( $('#prefs_form #turtle_days').val() );
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
tr.remote.savePrefs( o );
|
|
|
|
|
|
|
|
tr.hidePrefsDialog( );
|
|
|
|
},
|
|
|
|
|
2010-03-11 04:50:04 +00:00
|
|
|
closeStatsClicked: function(event) {
|
|
|
|
this.hideStatsDialog( );
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
removeClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) ) {
|
|
|
|
tr.removeSelectedTorrents( );
|
|
|
|
tr.hideiPhoneAddressbar( );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleInspectorClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( tr.isButtonEnabled( event ) )
|
|
|
|
tr.toggleInspector( );
|
|
|
|
},
|
|
|
|
|
2009-05-23 04:07:24 +00:00
|
|
|
inspectorTabClicked: function(event, tab) {
|
2008-07-10 23:57:46 +00:00
|
|
|
if (iPhone) event.stopPropagation();
|
|
|
|
|
|
|
|
// Select the clicked tab, unselect the others,
|
|
|
|
// and display the appropriate info
|
2009-05-23 04:07:24 +00:00
|
|
|
var tab_ids = $(tab).parent('#inspector_tabs').find('.inspector_tab').map(
|
2009-08-12 14:40:32 +00:00
|
|
|
function() { return $(this).attr('id'); }
|
2009-03-14 21:33:08 +00:00
|
|
|
);
|
2009-05-24 16:05:28 +00:00
|
|
|
for( var i=0, row; row=tab_ids[i]; ++i ) {
|
|
|
|
if (tab.id == row) {
|
|
|
|
$('#'+row).addClass('selected');
|
|
|
|
$('#'+row+'_container').show();
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
2009-05-24 16:05:28 +00:00
|
|
|
$('#'+row).removeClass('selected');
|
|
|
|
$('#'+row+'_container').hide();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hideiPhoneAddressbar();
|
2009-05-23 20:39:55 +00:00
|
|
|
|
|
|
|
this.updateVisibleFileLists();
|
2010-01-31 02:42:48 +00:00
|
|
|
this.updateTrackersLists();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-05-25 04:07:48 +00:00
|
|
|
|
|
|
|
fileWantedClicked: function(event, element){
|
|
|
|
this.extractFileFromElement(element).fileWantedControlClicked(event);
|
|
|
|
},
|
|
|
|
|
|
|
|
filePriorityClicked: function(event, element){
|
|
|
|
this.extractFileFromElement(element).filePriorityControlClicked(event, element);
|
|
|
|
},
|
|
|
|
|
2009-12-06 03:21:08 +00:00
|
|
|
filesSelectAllClicked: function(event) {
|
|
|
|
var tr = this;
|
|
|
|
var ids = jQuery.map(this.getSelectedTorrents( ), function(t) { return t.id(); } );
|
|
|
|
var files_list = this.toggleFilesWantedDisplay(ids, true);
|
|
|
|
for (i = 0; i < ids.length; ++i) {
|
|
|
|
if (files_list[i].length)
|
|
|
|
this.remote.filesSelectAll( [ ids[i] ], files_list[i], function() { tr.refreshTorrents( ids ); } );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
filesDeselectAllClicked: function(event) {
|
|
|
|
var tr = this;
|
|
|
|
var ids = jQuery.map(this.getSelectedTorrents( ), function(t) { return t.id(); } );
|
|
|
|
var files_list = this.toggleFilesWantedDisplay(ids, false);
|
|
|
|
for (i = 0; i < ids.length; ++i) {
|
|
|
|
if (files_list[i].length)
|
|
|
|
this.remote.filesDeselectAll( [ ids[i] ], files_list[i], function() { tr.refreshTorrents( ids ); } );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-05-25 04:07:48 +00:00
|
|
|
extractFileFromElement: function(element) {
|
|
|
|
var match = $(element).closest('.inspector_torrent_file_list_entry').attr('id').match(/^t(\d+)f(\d+)$/);
|
|
|
|
var torrent_id = match[1];
|
|
|
|
var file_id = match[2];
|
2009-06-07 23:55:42 +00:00
|
|
|
var torrent = this._torrents[torrent_id];
|
2009-05-25 04:07:48 +00:00
|
|
|
return torrent._file_view[file_id];
|
|
|
|
},
|
|
|
|
|
2009-12-06 03:21:08 +00:00
|
|
|
toggleFilesWantedDisplay: function(ids, wanted) {
|
|
|
|
var i, j, k, torrent, files_list = [ ];
|
|
|
|
for (i = 0; i < ids.length; ++i) {
|
|
|
|
torrent = this._torrents[ids[i]];
|
|
|
|
files_list[i] = [ ];
|
|
|
|
for (j = k = 0; j < torrent._file_view.length; ++j) {
|
|
|
|
if (torrent._file_view[j].isEditable() && torrent._file_view[j]._wanted != wanted) {
|
|
|
|
torrent._file_view[j].setWanted(wanted, false);
|
|
|
|
files_list[i][k++] = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
torrent.refreshFileView;
|
|
|
|
}
|
|
|
|
return files_list;
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
toggleFilterClicked: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
if (this.isButtonEnabled(event))
|
|
|
|
this.toggleFilter();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2008-08-10 15:48:14 +00:00
|
|
|
setFilter: function( mode )
|
|
|
|
{
|
|
|
|
// update the radiobuttons
|
|
|
|
var c;
|
|
|
|
switch( mode ) {
|
|
|
|
case Prefs._FilterAll: c = '#filter_all_link'; break;
|
|
|
|
case Prefs._FilterSeeding: c = '#filter_seeding_link'; break;
|
|
|
|
case Prefs._FilterDownloading: c = '#filter_downloading_link'; break;
|
|
|
|
case Prefs._FilterPaused: c = '#filter_paused_link'; break;
|
|
|
|
}
|
|
|
|
$(c).parent().siblings().removeClass('selected');
|
|
|
|
$(c).parent().addClass('selected');
|
|
|
|
|
|
|
|
// do the filtering
|
2008-07-10 23:57:46 +00:00
|
|
|
this.setPref( Prefs._FilterMode, mode );
|
|
|
|
this.refilter( );
|
|
|
|
},
|
|
|
|
showAllClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.setFilter( Prefs._FilterAll );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
showDownloadingClicked: function( event ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.setFilter( Prefs._FilterDownloading );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
showSeedingClicked: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.setFilter( Prefs._FilterSeeding );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
showPausedClicked: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.setFilter( Prefs._FilterPaused );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'Clutch Preferences' was clicked (iPhone only)
|
|
|
|
*/
|
|
|
|
releaseClutchPreferencesButton: function(event) {
|
|
|
|
$('div#prefs_container div#pref_error').hide();
|
|
|
|
$('div#prefs_container h2.dialog_heading').show();
|
|
|
|
this.showPrefsDialog( );
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2009-11-14 14:57:47 +00:00
|
|
|
* Turn the periodic ajax torrents refresh on & off
|
2008-07-10 23:57:46 +00:00
|
|
|
*/
|
|
|
|
togglePeriodicRefresh: function(state) {
|
2009-05-22 22:45:09 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if (state && this._periodic_refresh == null) {
|
|
|
|
// sanity check
|
|
|
|
if( !this[Prefs._RefreshRate] )
|
|
|
|
this[Prefs._RefreshRate] = 5;
|
2009-03-14 21:33:08 +00:00
|
|
|
remote = this.remote;
|
2009-05-22 22:45:09 +00:00
|
|
|
this._periodic_refresh = setInterval(function(){ tr.refreshTorrents(); }, this[Prefs._RefreshRate] * 1000 );
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
|
|
|
clearInterval(this._periodic_refresh);
|
|
|
|
this._periodic_refresh = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-11-14 14:57:47 +00:00
|
|
|
/*
|
|
|
|
* Turn the periodic ajax session refresh on & off
|
|
|
|
*/
|
|
|
|
togglePeriodicSessionRefresh: function(state) {
|
|
|
|
var tr = this;
|
|
|
|
if (state && this._periodic_session_refresh == null) {
|
|
|
|
// sanity check
|
|
|
|
if( !this[Prefs._SessionRefreshRate] )
|
|
|
|
this[Prefs._SessionRefreshRate] = 5;
|
|
|
|
remote = this.remote;
|
|
|
|
this._periodic_session_refresh = setInterval(
|
|
|
|
function(){ tr.loadDaemonPrefs(); }, this[Prefs._SessionRefreshRate] * 1000
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
clearInterval(this._periodic_session_refresh);
|
|
|
|
this._periodic_session_refresh = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-03-11 04:50:04 +00:00
|
|
|
/*
|
|
|
|
* Turn the periodic ajax stats refresh on & off
|
|
|
|
*/
|
|
|
|
togglePeriodicStatsRefresh: function(state) {
|
|
|
|
var tr = this;
|
|
|
|
if (state && this._periodic_stats_refresh == null) {
|
|
|
|
// sanity check
|
|
|
|
if( !this[Prefs._SessionRefreshRate] )
|
|
|
|
this[Prefs._SessionRefreshRate] = 5;
|
|
|
|
remote = this.remote;
|
|
|
|
this._periodic_stats_refresh = setInterval(
|
|
|
|
function(){ tr.loadDaemonStats(); }, this[Prefs._SessionRefreshRate] * 1000
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
clearInterval(this._periodic_stats_refresh);
|
|
|
|
this._periodic_stats_refresh = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-11-10 05:42:57 +00:00
|
|
|
toggleTurtleClicked: function() {
|
|
|
|
// Toggle the value
|
|
|
|
this[Prefs._TurtleState] = !this[Prefs._TurtleState];
|
|
|
|
// Store the result
|
|
|
|
var args = { };
|
|
|
|
args[RPC._TurtleState] = this[Prefs._TurtleState];
|
|
|
|
this.remote.savePrefs( args );
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTurtleButton: function() {
|
2010-03-01 16:35:54 +00:00
|
|
|
var w = $('#turtle_button');
|
|
|
|
var t;
|
2009-11-10 05:42:57 +00:00
|
|
|
if ( this[Prefs._TurtleState] ) {
|
2010-03-01 16:35:54 +00:00
|
|
|
w.addClass('turtleEnabled');
|
|
|
|
w.removeClass('turtleDisabled');
|
|
|
|
t = "Click to disable Temporary Speed Limits";
|
2009-11-10 05:42:57 +00:00
|
|
|
} else {
|
2010-03-01 16:35:54 +00:00
|
|
|
w.removeClass('turtleEnabled');
|
|
|
|
w.addClass('turtleDisabled');
|
|
|
|
t = "Click to enable Temporary Speed Limits";
|
2009-11-10 05:42:57 +00:00
|
|
|
}
|
2010-03-01 16:35:54 +00:00
|
|
|
t += " (" + this._prefs[RPC._TurtleUpSpeedLimit] + " kB/s up, "
|
|
|
|
+ this._prefs[RPC._TurtleDownSpeedLimit] + " kB/s down)";
|
|
|
|
w.attr( 'title', t );
|
2009-11-10 05:42:57 +00:00
|
|
|
},
|
|
|
|
|
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
|
|
|
*--------------------------------------------*/
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2009-03-14 21:33:08 +00:00
|
|
|
showPrefsDialog: function( ) {
|
2008-07-10 23:57:46 +00:00
|
|
|
$('body').addClass('prefs_showing');
|
|
|
|
$('#prefs_container').show();
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hideiPhoneAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
if( Safari3 )
|
|
|
|
setTimeout("$('div#prefs_container div.dialog_window').css('top', '0px');",10);
|
|
|
|
this.updateButtonStates( );
|
2009-11-14 14:57:47 +00:00
|
|
|
this.togglePeriodicSessionRefresh(false);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hidePrefsDialog: function( )
|
|
|
|
{
|
|
|
|
$('body.prefs_showing').removeClass('prefs_showing');
|
|
|
|
if (iPhone) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hideiPhoneAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#prefs_container').hide();
|
|
|
|
} else if (Safari3) {
|
|
|
|
$('div#prefs_container div.dialog_window').css('top', '-425px');
|
|
|
|
setTimeout("$('#prefs_container').hide();",500);
|
|
|
|
} else {
|
|
|
|
$('#prefs_container').hide();
|
|
|
|
}
|
|
|
|
this.updateButtonStates( );
|
2009-11-14 14:57:47 +00:00
|
|
|
this.togglePeriodicSessionRefresh(true);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Process got some new session data from the server
|
|
|
|
*/
|
|
|
|
updatePrefs: function( prefs )
|
|
|
|
{
|
|
|
|
// remember them for later
|
|
|
|
this._prefs = prefs;
|
|
|
|
|
2008-10-29 18:06:33 +00:00
|
|
|
var down_limit = prefs[RPC._DownSpeedLimit];
|
2008-07-10 23:57:46 +00:00
|
|
|
var down_limited = prefs[RPC._DownSpeedLimited];
|
2008-10-29 18:06:33 +00:00
|
|
|
var up_limit = prefs[RPC._UpSpeedLimit];
|
2008-07-10 23:57:46 +00:00
|
|
|
var up_limited = prefs[RPC._UpSpeedLimited];
|
2009-09-02 01:03:38 +00:00
|
|
|
|
2009-03-25 19:18:00 +00:00
|
|
|
$('div.download_location input')[0].value = prefs[RPC._DownloadDir];
|
|
|
|
$('div.port input')[0].value = prefs[RPC._PeerPort];
|
2010-03-17 19:23:03 +00:00
|
|
|
$('div.auto_start input')[0].checked = prefs[RPC._StartAddedTorrent];
|
2009-09-02 01:03:38 +00:00
|
|
|
$('input#limit_download')[0].checked = down_limited;
|
2008-07-10 23:57:46 +00:00
|
|
|
$('input#download_rate')[0].value = down_limit;
|
2009-09-02 01:03:38 +00:00
|
|
|
$('input#limit_upload')[0].checked = up_limited;
|
2008-07-10 23:57:46 +00:00
|
|
|
$('input#upload_rate')[0].value = up_limit;
|
|
|
|
$('input#refresh_rate')[0].value = prefs[Prefs._RefreshRate];
|
|
|
|
$('div.encryption input')[0].checked = prefs[RPC._Encryption] == RPC._EncryptionRequired;
|
2009-11-10 05:42:57 +00:00
|
|
|
$('input#turtle_download_rate')[0].value = prefs[RPC._TurtleDownSpeedLimit];
|
|
|
|
$('input#turtle_upload_rate')[0].value = prefs[RPC._TurtleUpSpeedLimit];
|
|
|
|
$('input#turtle_schedule')[0].checked = prefs[RPC._TurtleTimeEnabled];
|
|
|
|
$('select#turtle_start_time').val( prefs[RPC._TurtleTimeBegin] );
|
|
|
|
$('select#turtle_end_time').val( prefs[RPC._TurtleTimeEnd] );
|
|
|
|
$('select#turtle_days').val( prefs[RPC._TurtleTimeDay] );
|
2009-12-20 21:06:20 +00:00
|
|
|
$('#transmission_version').text( prefs[RPC._DaemonVersion] );
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
if (!iPhone)
|
|
|
|
{
|
2010-04-28 01:26:46 +00:00
|
|
|
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + down_limit + ' KiB/s)' );
|
2008-07-10 23:57:46 +00:00
|
|
|
var key = down_limited ? '#limited_download_rate'
|
|
|
|
: '#unlimited_download_rate';
|
|
|
|
$(key).deselectMenuSiblings().selectMenuItem();
|
|
|
|
|
2010-04-28 01:26:46 +00:00
|
|
|
setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + up_limit + ' KiB/s)' );
|
2008-07-10 23:57:46 +00:00
|
|
|
key = up_limited ? '#limited_upload_rate'
|
|
|
|
: '#unlimited_upload_rate';
|
|
|
|
$(key).deselectMenuSiblings().selectMenuItem();
|
|
|
|
}
|
2009-11-10 05:42:57 +00:00
|
|
|
|
|
|
|
this[Prefs._TurtleState] = prefs[RPC._TurtleState];
|
|
|
|
this.updateTurtleButton();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2010-03-11 04:50:04 +00:00
|
|
|
showStatsDialog: function( ) {
|
|
|
|
this.loadDaemonStats();
|
|
|
|
$('body').addClass('stats_showing');
|
|
|
|
$('#stats_container').show();
|
|
|
|
this.hideiPhoneAddressbar();
|
|
|
|
if( Safari3 )
|
|
|
|
setTimeout("$('div#stats_container div.dialog_window').css('top', '0px');",10);
|
|
|
|
this.updateButtonStates( );
|
|
|
|
this.togglePeriodicStatsRefresh(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
hideStatsDialog: function( ){
|
|
|
|
$('body.stats_showing').removeClass('stats_showing');
|
|
|
|
if (iPhone) {
|
|
|
|
this.hideiPhoneAddressbar();
|
|
|
|
$('#stats_container').hide();
|
|
|
|
} else if (Safari3) {
|
|
|
|
$('div#stats_container div.dialog_window').css('top', '-425px');
|
|
|
|
setTimeout("$('#stats_container').hide();",500);
|
|
|
|
} else {
|
|
|
|
$('#stats_container').hide();
|
|
|
|
}
|
|
|
|
this.updateButtonStates( );
|
|
|
|
this.togglePeriodicStatsRefresh(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process got some new session stats from the server
|
|
|
|
*/
|
|
|
|
updateStats: function( stats )
|
|
|
|
{
|
|
|
|
// can't think of a reason to remember this
|
|
|
|
//this._stats = stats;
|
|
|
|
|
|
|
|
var session = stats["current-stats"];
|
|
|
|
var total = stats["cumulative-stats"];
|
|
|
|
|
|
|
|
setInnerHTML( $('#stats_session_uploaded')[0], Math.formatBytes(session["uploadedBytes"]) );
|
|
|
|
setInnerHTML( $('#stats_session_downloaded')[0], Math.formatBytes(session["downloadedBytes"]) );
|
|
|
|
setInnerHTML( $('#stats_session_ratio')[0], Math.ratio(session["uploadedBytes"],session["downloadedBytes"]));
|
|
|
|
setInnerHTML( $('#stats_session_duration')[0], Math.formatSeconds(session["secondsActive"]) );
|
|
|
|
setInnerHTML( $('#stats_total_count')[0], total["sessionCount"] + " times" );
|
|
|
|
setInnerHTML( $('#stats_total_uploaded')[0], Math.formatBytes(total["uploadedBytes"]) );
|
|
|
|
setInnerHTML( $('#stats_total_downloaded')[0], Math.formatBytes(total["downloadedBytes"]) );
|
|
|
|
setInnerHTML( $('#stats_total_ratio')[0], Math.ratio(total["uploadedBytes"],total["downloadedBytes"]));
|
|
|
|
setInnerHTML( $('#stats_total_duration')[0], Math.formatSeconds(total["secondsActive"]) );
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
setSearch: function( search ) {
|
|
|
|
this._current_search = search ? search.trim() : null;
|
|
|
|
this.refilter( );
|
|
|
|
},
|
|
|
|
|
|
|
|
setSortMethod: function( sort_method ) {
|
|
|
|
this.setPref( Prefs._SortMethod, sort_method );
|
|
|
|
this.refilter( );
|
|
|
|
},
|
|
|
|
|
|
|
|
setSortDirection: function( direction ) {
|
|
|
|
this.setPref( Prefs._SortDirection, direction );
|
|
|
|
this.refilter( );
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an event in the footer-menu
|
|
|
|
*/
|
|
|
|
processSettingsMenuEvent: function(event) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
|
|
|
var $element = $(event.target);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Figure out which menu has been clicked
|
2009-05-23 02:28:04 +00:00
|
|
|
switch ($element.parent()[0].id) {
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Display the preferences dialog
|
|
|
|
case 'footer_super_menu':
|
2009-05-23 02:28:04 +00:00
|
|
|
if ($element[0].id == 'preferences') {
|
2008-07-10 23:57:46 +00:00
|
|
|
$('div#prefs_container div#pref_error').hide();
|
|
|
|
$('div#prefs_container h2.dialog_heading').show();
|
2009-05-23 02:28:04 +00:00
|
|
|
tr.showPrefsDialog( );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2010-03-11 04:50:04 +00:00
|
|
|
else if ($element[0].id == 'statistics') {
|
|
|
|
$('div#stats_container div#stats_error').hide();
|
|
|
|
$('div#stats_container h2.dialog_heading').show();
|
|
|
|
tr.showStatsDialog( );
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Limit the download rate
|
|
|
|
case 'footer_download_rate_menu':
|
|
|
|
var args = { };
|
2009-05-23 02:28:04 +00:00
|
|
|
var rate = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
|
|
|
|
if ($element.is('#unlimited_download_rate')) {
|
|
|
|
$element.deselectMenuSiblings().selectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
args[RPC._DownSpeedLimited] = false;
|
|
|
|
} else {
|
2010-04-28 01:26:46 +00:00
|
|
|
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + rate + ' KiB/s)' );
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#limited_download_rate').deselectMenuSiblings().selectMenuItem();
|
|
|
|
$('div.preference input#download_rate')[0].value = rate;
|
|
|
|
args[RPC._DownSpeedLimit] = parseInt( rate );
|
|
|
|
args[RPC._DownSpeedLimited] = true;
|
|
|
|
}
|
|
|
|
$('div.preference input#limit_download')[0].checked = args[RPC._DownSpeedLimited];
|
2009-05-23 02:28:04 +00:00
|
|
|
tr.remote.savePrefs( args );
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Limit the upload rate
|
|
|
|
case 'footer_upload_rate_menu':
|
|
|
|
var args = { };
|
2009-05-23 02:28:04 +00:00
|
|
|
var rate = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
|
|
|
|
if ($element.is('#unlimited_upload_rate')) {
|
|
|
|
$element.deselectMenuSiblings().selectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
args[RPC._UpSpeedLimited] = false;
|
|
|
|
} else {
|
2010-04-28 01:26:46 +00:00
|
|
|
setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + rate + ' KiB/s)' );
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#limited_upload_rate').deselectMenuSiblings().selectMenuItem();
|
|
|
|
$('div.preference input#upload_rate')[0].value = rate;
|
|
|
|
args[RPC._UpSpeedLimit] = parseInt( rate );
|
|
|
|
args[RPC._UpSpeedLimited] = true;
|
|
|
|
}
|
|
|
|
$('div.preference input#limit_upload')[0].checked = args[RPC._UpSpeedLimited];
|
2009-05-23 02:28:04 +00:00
|
|
|
tr.remote.savePrefs( args );
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-12 14:40:32 +00:00
|
|
|
// Sort the torrent list
|
2008-07-10 23:57:46 +00:00
|
|
|
case 'footer_sort_menu':
|
|
|
|
|
|
|
|
// The 'reverse sort' option state can be toggled independently of the other options
|
2009-05-23 02:28:04 +00:00
|
|
|
if ($element.is('#reverse_sort_order')) {
|
2010-03-31 19:22:42 +00:00
|
|
|
if(!$element.is('#reverse_sort_order.active')) break;
|
2008-07-10 23:57:46 +00:00
|
|
|
var dir;
|
2009-05-23 02:28:04 +00:00
|
|
|
if ($element.menuItemIsSelected()) {
|
|
|
|
$element.deselectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
dir = Prefs._SortAscending;
|
|
|
|
} else {
|
2009-05-23 02:28:04 +00:00
|
|
|
$element.selectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
dir = Prefs._SortDescending;
|
|
|
|
}
|
2009-05-23 02:28:04 +00:00
|
|
|
tr.setSortDirection( dir );
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Otherwise, deselect all other options (except reverse-sort) and select this one
|
|
|
|
} else {
|
2009-05-23 02:28:04 +00:00
|
|
|
$element.parent().find('span.selected').each( function() {
|
|
|
|
if (! $element.parent().is('#reverse_sort_order')) {
|
|
|
|
$element.parent().deselectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
});
|
2009-05-23 02:28:04 +00:00
|
|
|
$element.selectMenuItem();
|
|
|
|
var method = $element[0].id.replace(/sort_by_/, '');
|
|
|
|
tr.setSortMethod( method );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-23 02:56:55 +00:00
|
|
|
$('#settings_menu').trigger('closemenu');
|
|
|
|
return false; // to prevent the event from bubbling up
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2009-05-25 13:31:03 +00:00
|
|
|
setLastTorrentClicked: function( torrent )
|
|
|
|
{
|
|
|
|
this._last_torrent_clicked = torrent;
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Update the inspector with the latest data for the selected torrents
|
|
|
|
*/
|
|
|
|
updateInspector: function()
|
|
|
|
{
|
|
|
|
if( !this[Prefs._ShowInspector] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var torrents = this.getSelectedTorrents( );
|
|
|
|
if( !torrents.length && iPhone ) {
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hideInspector();
|
2008-07-10 23:57:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var creator = 'N/A';
|
|
|
|
var comment = 'N/A';
|
2009-06-26 03:03:17 +00:00
|
|
|
var download_dir = 'N/A';
|
2008-07-10 23:57:46 +00:00
|
|
|
var date_created = 'N/A';
|
|
|
|
var error = '';
|
|
|
|
var hash = 'N/A';
|
|
|
|
var have_public = false;
|
|
|
|
var have_private = false;
|
|
|
|
var name;
|
2008-07-16 14:35:58 +00:00
|
|
|
var sizeWhenDone = 0;
|
|
|
|
var sizeDone = 0;
|
2008-07-10 23:57:46 +00:00
|
|
|
var total_completed = 0;
|
|
|
|
var total_download = 0;
|
|
|
|
var total_download_peers = 0;
|
|
|
|
var total_download_speed = 0;
|
2010-04-20 01:48:40 +00:00
|
|
|
var total_availability = 0;
|
2008-07-10 23:57:46 +00:00
|
|
|
var total_have = 0;
|
|
|
|
var total_size = 0;
|
|
|
|
var total_state = null;
|
2009-10-31 02:19:45 +00:00
|
|
|
var pieces = 'N/A';
|
2008-07-10 23:57:46 +00:00
|
|
|
var total_upload = 0;
|
|
|
|
var total_upload_peers = 0;
|
|
|
|
var total_upload_speed = 0;
|
|
|
|
var total_verified = 0;
|
2008-08-29 17:57:53 +00:00
|
|
|
var na = 'N/A';
|
2009-06-23 01:52:20 +00:00
|
|
|
var tab = this._inspector._info_tab;
|
2008-09-19 16:17:35 +00:00
|
|
|
|
|
|
|
$("#torrent_inspector_size, .inspector_row div").css('color', '#222');
|
2009-03-14 21:33:08 +00:00
|
|
|
|
2008-08-29 17:57:53 +00:00
|
|
|
if( torrents.length == 0 )
|
|
|
|
{
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.name, 'No Selection' );
|
|
|
|
setInnerHTML( tab.size, na );
|
2009-10-31 02:19:45 +00:00
|
|
|
setInnerHTML( tab.pieces, na );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.hash, na );
|
|
|
|
setInnerHTML( tab.state, na );
|
|
|
|
setInnerHTML( tab.download_speed, na );
|
|
|
|
setInnerHTML( tab.upload_speed, na );
|
|
|
|
setInnerHTML( tab.uploaded, na );
|
|
|
|
setInnerHTML( tab.downloaded, na );
|
2010-04-20 01:48:40 +00:00
|
|
|
setInnerHTML( tab.availability, na );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.ratio, na );
|
|
|
|
setInnerHTML( tab.have, na );
|
|
|
|
setInnerHTML( tab.upload_to, na );
|
|
|
|
setInnerHTML( tab.download_from, na );
|
|
|
|
setInnerHTML( tab.secure, na );
|
|
|
|
setInnerHTML( tab.creator_date, na );
|
|
|
|
setInnerHTML( tab.progress, na );
|
|
|
|
setInnerHTML( tab.comment, na );
|
|
|
|
setInnerHTML( tab.creator, na );
|
2010-01-15 04:34:42 +00:00
|
|
|
setInnerHTML( tab.download_dir, na );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.error, na );
|
2009-03-14 21:33:08 +00:00
|
|
|
this.updateVisibleFileLists();
|
2010-01-31 02:42:48 +00:00
|
|
|
this.updateTrackersLists();
|
2008-09-19 16:17:35 +00:00
|
|
|
$("#torrent_inspector_size, .inspector_row > div:contains('N/A')").css('color', '#666');
|
2008-08-29 17:57:53 +00:00
|
|
|
return;
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
|
2008-08-29 17:57:53 +00:00
|
|
|
name = torrents.length == 1
|
|
|
|
? torrents[0].name()
|
|
|
|
: torrents.length+' Transfers Selected';
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
if( torrents.length == 1 )
|
|
|
|
{
|
|
|
|
var t = torrents[0];
|
2009-08-05 01:25:36 +00:00
|
|
|
var err = t.getErrorMessage( );
|
|
|
|
if( err )
|
|
|
|
error = err;
|
2008-08-29 17:57:53 +00:00
|
|
|
if( t._comment)
|
|
|
|
comment = t._comment ;
|
|
|
|
if( t._creator )
|
|
|
|
creator = t._creator ;
|
2009-06-26 03:03:17 +00:00
|
|
|
if( t._download_dir)
|
|
|
|
download_dir = t._download_dir;
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
hash = t.hash();
|
2009-10-31 02:19:45 +00:00
|
|
|
pieces = t._pieceCount + ', ' + Math.formatBytes(t._pieceSize);
|
2008-07-10 23:57:46 +00:00
|
|
|
date_created = Math.formatTimestamp( t._creator_date );
|
|
|
|
}
|
|
|
|
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, t; t=torrents[i]; ++i ) {
|
2008-07-16 14:35:58 +00:00
|
|
|
sizeWhenDone += t._sizeWhenDone;
|
|
|
|
sizeDone += t._sizeWhenDone - t._leftUntilDone;
|
2008-07-10 23:57:46 +00:00
|
|
|
total_completed += t.completed();
|
|
|
|
total_verified += t._verified;
|
|
|
|
total_size += t.size();
|
|
|
|
total_upload += t.uploadTotal();
|
|
|
|
total_download += t.downloadTotal();
|
|
|
|
total_upload_speed += t.uploadSpeed();
|
|
|
|
total_download_speed += t.downloadSpeed();
|
2008-07-25 14:34:25 +00:00
|
|
|
total_upload_peers += t.peersGettingFromUs();
|
|
|
|
total_download_peers += t.peersSendingToUs();
|
2010-04-20 01:48:40 +00:00
|
|
|
total_availability += t._sizeWhenDone - t._leftUntilDone + t._desiredAvailable;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( total_state == null )
|
|
|
|
total_state = t.stateStr();
|
|
|
|
else if ( total_state.search ( t.stateStr() ) == -1 )
|
|
|
|
total_state += '/' + t.stateStr();
|
|
|
|
if( t._is_private )
|
|
|
|
have_private = true;
|
|
|
|
else
|
|
|
|
have_public = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var private_string = '';
|
|
|
|
if( have_private && have_public ) private_string = 'Mixed';
|
|
|
|
else if( have_private ) private_string = 'Private Torrent';
|
2008-09-19 16:17:35 +00:00
|
|
|
else if( have_public ) private_string = 'Public Torrent';
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.name, name );
|
|
|
|
setInnerHTML( tab.size, torrents.length ? Math.formatBytes( total_size ) : na );
|
2009-10-31 02:19:45 +00:00
|
|
|
setInnerHTML( tab.pieces, pieces );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.hash, hash );
|
|
|
|
setInnerHTML( tab.state, total_state );
|
|
|
|
setInnerHTML( tab.download_speed, torrents.length ? Math.formatBytes( total_download_speed ) + '/s' : na );
|
|
|
|
setInnerHTML( tab.upload_speed, torrents.length ? Math.formatBytes( total_upload_speed ) + '/s' : na );
|
|
|
|
setInnerHTML( tab.uploaded, torrents.length ? Math.formatBytes( total_upload ) : na );
|
|
|
|
setInnerHTML( tab.downloaded, torrents.length ? Math.formatBytes( total_download ) : na );
|
2010-04-20 01:48:40 +00:00
|
|
|
setInnerHTML( tab.availability, torrents.length ? Math.ratio( total_availability*100, sizeWhenDone ) + '%' : na );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.ratio, torrents.length ? Math.ratio( total_upload, total_download ) : na );
|
|
|
|
setInnerHTML( tab.have, torrents.length ? Math.formatBytes(total_completed) + ' (' + Math.formatBytes(total_verified) + ' verified)' : na );
|
|
|
|
setInnerHTML( tab.upload_to, torrents.length ? total_upload_peers : na );
|
|
|
|
setInnerHTML( tab.download_from, torrents.length ? total_download_peers : na );
|
|
|
|
setInnerHTML( tab.secure, private_string );
|
|
|
|
setInnerHTML( tab.creator_date, date_created );
|
|
|
|
setInnerHTML( tab.progress, torrents.length ? Math.ratio( sizeDone*100, sizeWhenDone ) + '%' : na );
|
2010-01-15 05:17:55 +00:00
|
|
|
setInnerHTML( tab.comment, comment == na ? comment : comment.replace(/\//g, '/​') );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.creator, creator );
|
2010-01-15 05:17:55 +00:00
|
|
|
setInnerHTML( tab.download_dir, download_dir == na ? download_dir : download_dir.replace(/([\/_\.])/g, "$1​") );
|
2009-05-24 18:39:21 +00:00
|
|
|
setInnerHTML( tab.error, error );
|
2008-09-19 16:17:35 +00:00
|
|
|
|
2010-01-31 02:42:48 +00:00
|
|
|
this.updateTrackersLists();
|
2008-09-19 16:17:35 +00:00
|
|
|
$(".inspector_row > div:contains('N/A')").css('color', '#666');
|
2009-03-14 21:33:08 +00:00
|
|
|
this.updateVisibleFileLists();
|
|
|
|
},
|
2009-05-23 20:39:55 +00:00
|
|
|
|
|
|
|
fileListIsVisible: function() {
|
|
|
|
return this._inspector_tab_files.className.indexOf('selected') != -1;
|
|
|
|
},
|
2009-03-14 21:33:08 +00:00
|
|
|
|
|
|
|
updateVisibleFileLists: function() {
|
2009-05-23 20:39:55 +00:00
|
|
|
if( this.fileListIsVisible( ) === true ) {
|
2009-12-06 03:21:08 +00:00
|
|
|
var selected = this.getSelectedTorrents();
|
|
|
|
jQuery.each( selected, function() { this.showFileList(); } );
|
2009-05-23 20:39:55 +00:00
|
|
|
jQuery.each( this.getDeselectedTorrents(), function() { this.hideFileList(); } );
|
2009-12-06 03:21:08 +00:00
|
|
|
// Check if we need to display the select all buttions
|
|
|
|
if ( !selected.length ) {
|
|
|
|
if ( $("#select_all_button_container").is(':visible') )
|
|
|
|
$("#select_all_button_container").hide();
|
|
|
|
} else {
|
|
|
|
if ( !$("#select_all_button_container").is(':visible') )
|
|
|
|
$("#select_all_button_container").show();
|
|
|
|
}
|
2009-05-23 20:39:55 +00:00
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2010-01-31 02:42:48 +00:00
|
|
|
updateTrackersLists: function() {
|
|
|
|
// By building up the HTML as as string, then have the browser
|
|
|
|
// turn this into a DOM tree, this is a fast operation.
|
2010-02-01 01:08:17 +00:00
|
|
|
var tr = this;
|
2010-01-31 02:42:48 +00:00
|
|
|
var html = '';
|
|
|
|
var na = 'N/A';
|
|
|
|
var torrents = this.getSelectedTorrents( );
|
|
|
|
if( $(this._inspector_trackers_list).is(':visible') && torrents.length == 1 ) {
|
|
|
|
for( var i=0, tier; tier=torrents[0]._trackerStats[i]; ++i ) {
|
|
|
|
html += '<div class="inspector_group"><div class="inspector_group_label">';
|
|
|
|
html += 'Tier ' + (i + 1) + '</div><ul class="tier_list">';
|
|
|
|
for( var j=0, tracker; tracker=tier[j]; ++j ) {
|
2010-02-01 01:08:17 +00:00
|
|
|
var lastAnnounceStatusHash = tr.lastAnnounceStatus(tracker);
|
|
|
|
var announceState = tr.announceState(tracker);
|
|
|
|
var lastScrapeStatusHash = tr.lastScrapeStatus(tracker);
|
|
|
|
|
|
|
|
// Display construction
|
2010-01-31 02:42:48 +00:00
|
|
|
var parity = ((j+1) % 2 == 0 ? 'even' : 'odd');
|
2010-02-01 01:08:17 +00:00
|
|
|
html += '<li class="inspector_tracker_entry ' + parity + '"><div class="tracker_host" title="' + tracker.announce + '">';
|
|
|
|
html += tracker.host + '</div>';
|
|
|
|
html += '<div class="tracker_activity">';
|
|
|
|
html += '<div>' + lastAnnounceStatusHash['label'] + ': ' + lastAnnounceStatusHash['value'] + '</div>';
|
|
|
|
html += '<div>' + announceState + '</div>';
|
|
|
|
html += '<div>' + lastScrapeStatusHash['label'] + ': ' + lastScrapeStatusHash['value'] + '</div>';
|
|
|
|
html += '</div><table class="tracker_stats">';
|
2010-01-31 02:42:48 +00:00
|
|
|
html += '<tr><th>Seeders:</th><td>' + (tracker.seederCount > -1 ? tracker.seederCount : na) + '</td></tr>';
|
|
|
|
html += '<tr><th>Leechers:</th><td>' + (tracker.leecherCount > -1 ? tracker.leecherCount : na) + '</td></tr>';
|
|
|
|
html += '<tr><th>Downloads:</th><td>' + (tracker.downloadCount > -1 ? tracker.downloadCount : na)+ '</td></tr>';
|
|
|
|
html += '</table></li>';
|
|
|
|
}
|
|
|
|
html += '</ul></div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setInnerHTML(this._inspector_trackers_list, html);
|
|
|
|
},
|
|
|
|
|
2010-02-01 01:08:17 +00:00
|
|
|
lastAnnounceStatus: function(tracker){
|
|
|
|
var lastAnnounceLabel = 'Last Announce';
|
|
|
|
var lastAnnounce = 'N/A';
|
|
|
|
if (tracker.hasAnnounced) {
|
|
|
|
var lastAnnounceTime = Math.formatTimestamp(tracker.lastAnnounceTime);
|
|
|
|
if (tracker.lastAnnounceSucceeded) {
|
|
|
|
lastAnnounce = lastAnnounceTime;
|
|
|
|
lastAnnounce += ' (got ' + tracker.lastAnnouncePeerCount + ' peer';
|
|
|
|
if (tracker.lastAnnouncePeerCount != 1){ lastAnnounce += 's'; }
|
|
|
|
lastAnnounce += ')';
|
|
|
|
} else {
|
|
|
|
lastAnnounceLabel = 'Announce error';
|
|
|
|
lastAnnounce = (tracker.lastAnnounceResult ? tracker.lastAnnounceResult + ' - ' : '') + lastAnnounceTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {'label':lastAnnounceLabel, 'value':lastAnnounce};
|
|
|
|
},
|
|
|
|
|
|
|
|
announceState: function(tracker){
|
|
|
|
var announceState = '';
|
|
|
|
switch (tracker.announceState) {
|
|
|
|
case Torrent._TrackerActive:
|
|
|
|
announceState = 'Announce in progress';
|
|
|
|
break;
|
|
|
|
case Torrent._TrackerWaiting:
|
|
|
|
var timeUntilAnnounce = tracker.nextAnnounceTime - ((new Date()).getTime() / 1000);
|
|
|
|
if(timeUntilAnnounce < 0){
|
|
|
|
timeUntilAnnounce = 0;
|
|
|
|
}
|
|
|
|
announceState = 'Next announce in ' + Math.formatSeconds(timeUntilAnnounce);
|
|
|
|
break;
|
|
|
|
case Torrent._TrackerQueued:
|
|
|
|
announceState = 'Announce is queued';
|
|
|
|
break;
|
|
|
|
case Torrent._TrackerInactive:
|
|
|
|
announceState = tracker.isBackup ?
|
|
|
|
'Tracker will be used as a backup' :
|
|
|
|
'Announce not scheduled';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
announceState = 'unknown announce state: ' + tracker.announceState;
|
|
|
|
}
|
|
|
|
return announceState;
|
|
|
|
},
|
|
|
|
|
|
|
|
lastScrapeStatus: function(tracker){
|
|
|
|
var lastScrapeLabel = 'Last Scrape';
|
|
|
|
var lastScrape = 'N/A';
|
|
|
|
if (tracker.hasScraped) {
|
|
|
|
var lastScrapeTime = Math.formatTimestamp(tracker.lastScrapeTime);
|
|
|
|
if (tracker.lastScrapeSucceeded) {
|
|
|
|
lastScrape = lastScrapeTime;
|
|
|
|
} else {
|
|
|
|
lastScrapeLabel = 'Scrape error';
|
|
|
|
lastScrape = (tracker.lastScrapeResult ? tracker.lastScrapeResult + ' - ' : '') + lastScrapeTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {'label':lastScrapeLabel, 'value':lastScrape}
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Toggle the visibility of the inspector (used by the context menu)
|
|
|
|
*/
|
|
|
|
toggleInspector: function() {
|
|
|
|
if( this[Prefs._ShowInspector] )
|
|
|
|
this.hideInspector( );
|
|
|
|
else
|
|
|
|
this.showInspector( );
|
|
|
|
},
|
2009-03-14 21:33:08 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
showInspector: function() {
|
|
|
|
$('#torrent_inspector').show();
|
|
|
|
if (iPhone) {
|
|
|
|
$('body').addClass('inspector_showing');
|
2009-06-23 01:52:20 +00:00
|
|
|
$('#inspector_close').show();
|
2008-07-10 23:57:46 +00:00
|
|
|
this.hideiPhoneAddressbar();
|
|
|
|
} else {
|
|
|
|
var w = $('#torrent_inspector').width() + 1 + 'px';
|
|
|
|
$('#torrent_filter_bar')[0].style.right = w;
|
|
|
|
$('#torrent_container')[0].style.right = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
setInnerHTML( $('ul li#context_toggle_inspector')[0], 'Hide Inspector' );
|
|
|
|
|
|
|
|
this.setPref( Prefs._ShowInspector, true );
|
|
|
|
this.updateInspector( );
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Hide the inspector
|
|
|
|
*/
|
|
|
|
hideInspector: function() {
|
|
|
|
|
|
|
|
$('#torrent_inspector').hide();
|
|
|
|
|
|
|
|
if (iPhone) {
|
2009-06-07 04:46:17 +00:00
|
|
|
this.deselectAll( );
|
2008-07-10 23:57:46 +00:00
|
|
|
$('body.inspector_showing').removeClass('inspector_showing');
|
2009-06-23 01:52:20 +00:00
|
|
|
$('#inspector_close').hide();
|
2009-05-23 02:28:04 +00:00
|
|
|
this.hideiPhoneAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
|
|
|
$('#torrent_filter_bar')[0].style.right = '0px';
|
|
|
|
$('#torrent_container')[0].style.right = '0px';
|
|
|
|
setInnerHTML( $('ul li#context_toggle_inspector')[0], 'Show Inspector' );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setPref( Prefs._ShowInspector, false );
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toggle the visibility of the filter bar
|
|
|
|
*/
|
|
|
|
toggleFilter: function() {
|
|
|
|
if( this[Prefs._ShowFilter] )
|
|
|
|
this.hideFilter();
|
|
|
|
else
|
|
|
|
this.showFilter();
|
|
|
|
},
|
|
|
|
|
|
|
|
showFilter: function( ) {
|
2009-02-19 23:02:22 +00:00
|
|
|
var container_top = parseInt($('#torrent_container').position().top) + $('#torrent_filter_bar').height() + 1;
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#torrent_container').css('top', container_top + 'px');
|
|
|
|
$('#torrent_filter_bar').show();
|
|
|
|
this.setPref( Prefs._ShowFilter, true );
|
|
|
|
},
|
|
|
|
|
2008-08-10 15:48:14 +00:00
|
|
|
hideFilter: function()
|
|
|
|
{
|
2008-07-10 23:57:46 +00:00
|
|
|
var container_top = parseInt($('#torrent_container').css('top')) - $('#torrent_filter_bar').height() - 1;
|
|
|
|
$('#torrent_container').css('top', container_top + 'px');
|
|
|
|
$('#torrent_filter_bar').hide();
|
|
|
|
this.setPref( Prefs._ShowFilter, false );
|
2008-08-10 15:48:14 +00:00
|
|
|
this.setFilter( Prefs._FilterAll );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2010-02-06 16:43:48 +00:00
|
|
|
refreshMetaData: function(ids) {
|
|
|
|
var tr = this;
|
|
|
|
this.remote.getMetaDataFor(ids, function(active, removed){ tr.updateMetaData(active); });
|
|
|
|
},
|
|
|
|
|
|
|
|
updateMetaData: function( torrents )
|
|
|
|
{
|
|
|
|
var tr = this;
|
|
|
|
var refresh_files_for = [ ];
|
|
|
|
jQuery.each( torrents, function( ) {
|
|
|
|
var t = tr._torrents[ this.id ];
|
|
|
|
if( t ) {
|
|
|
|
t.refreshMetaData( this );
|
|
|
|
if( t.isSelected( ) )
|
|
|
|
refresh_files_for.push( t.id( ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
if( refresh_files_for.length > 0 )
|
|
|
|
tr.remote.loadTorrentFiles( refresh_files_for );
|
|
|
|
},
|
|
|
|
|
2009-06-30 03:37:40 +00:00
|
|
|
refreshTorrents: function(ids) {
|
2009-03-14 21:33:08 +00:00
|
|
|
var tr = this;
|
2009-06-30 03:37:40 +00:00
|
|
|
if (!ids)
|
|
|
|
ids = 'recently-active';
|
|
|
|
|
|
|
|
this.remote.getUpdatedDataFor(ids, function(active, removed){ tr.updateTorrentsData(active, removed); });
|
2009-05-22 22:45:09 +00:00
|
|
|
},
|
|
|
|
|
2009-06-30 03:37:40 +00:00
|
|
|
updateTorrentsData: function( updated, removed_ids ) {
|
2009-05-22 22:45:09 +00:00
|
|
|
var tr = this;
|
|
|
|
var new_torrent_ids = [];
|
|
|
|
var refresh_files_for = [];
|
2009-06-30 03:37:40 +00:00
|
|
|
jQuery.each( updated, function() {
|
2009-06-07 23:55:42 +00:00
|
|
|
var t = tr._torrents[this.id];
|
2009-05-22 22:45:09 +00:00
|
|
|
if (t){
|
|
|
|
t.refresh(this);
|
|
|
|
if(t.isSelected())
|
|
|
|
refresh_files_for.push(t.id());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new_torrent_ids.push(this.id);
|
2009-03-14 21:33:08 +00:00
|
|
|
} );
|
2009-05-22 22:45:09 +00:00
|
|
|
|
2009-05-22 23:46:14 +00:00
|
|
|
if(refresh_files_for.length > 0)
|
|
|
|
tr.remote.loadTorrentFiles( refresh_files_for );
|
2009-05-22 22:45:09 +00:00
|
|
|
|
|
|
|
if(new_torrent_ids.length > 0)
|
|
|
|
tr.remote.getInitialDataFor(new_torrent_ids, function(torrents){ tr.addTorrents(torrents) } );
|
|
|
|
|
|
|
|
var removedAny = tr.deleteTorrents(removed_ids);
|
|
|
|
|
|
|
|
if( ( new_torrent_ids.length != 0 ) || removedAny ) {
|
|
|
|
tr.hideiPhoneAddressbar();
|
|
|
|
tr.deselectAll( true );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2009-05-22 22:45:09 +00:00
|
|
|
|
|
|
|
this.refilter();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTorrentsFileData: function( torrents ){
|
|
|
|
var tr = this;
|
2009-05-23 20:39:55 +00:00
|
|
|
var listIsVisible = tr.fileListIsVisible( );
|
2009-05-22 22:45:09 +00:00
|
|
|
jQuery.each( torrents, function() {
|
2009-06-07 23:55:42 +00:00
|
|
|
var t = tr._torrents[this.id];
|
2009-05-23 20:39:55 +00:00
|
|
|
if (t) {
|
|
|
|
t.refreshFileModel(this);
|
|
|
|
if( listIsVisible && t.isSelected())
|
|
|
|
t.refreshFileView();
|
|
|
|
}
|
2009-05-22 22:45:09 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2009-07-28 05:23:30 +00:00
|
|
|
initializeAllTorrents: function(){
|
2009-05-22 22:45:09 +00:00
|
|
|
var tr = this;
|
|
|
|
this.remote.getInitialDataFor( null ,function(torrents) { tr.addTorrents(torrents); } );
|
|
|
|
},
|
|
|
|
|
2009-05-24 19:34:54 +00:00
|
|
|
addTorrents: function( new_torrents )
|
|
|
|
{
|
|
|
|
var transferFragment = document.createDocumentFragment( );
|
|
|
|
var fileFragment = document.createDocumentFragment( );
|
|
|
|
|
2009-06-07 23:55:42 +00:00
|
|
|
for( var i=0, row; row=new_torrents[i]; ++i ) {
|
|
|
|
var new_torrent = new Torrent( transferFragment, fileFragment, this, row );
|
|
|
|
this._torrents[new_torrent.id()] = new_torrent;
|
|
|
|
}
|
2009-05-24 19:34:54 +00:00
|
|
|
|
|
|
|
this._inspector_file_list.appendChild( fileFragment );
|
|
|
|
this._torrent_list.appendChild( transferFragment );
|
|
|
|
|
2009-05-24 01:29:03 +00:00
|
|
|
this.refilter( );
|
2009-05-22 22:45:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteTorrents: function(torrent_ids){
|
|
|
|
if(typeof torrent_ids == 'undefined')
|
|
|
|
return false;
|
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
var removedAny = false;
|
2009-05-22 22:45:09 +00:00
|
|
|
$.each( torrent_ids, function(index, id){
|
2009-06-07 23:55:42 +00:00
|
|
|
var torrent = tr._torrents[id];
|
2009-05-22 22:45:09 +00:00
|
|
|
|
|
|
|
if(torrent) {
|
|
|
|
removedAny = true;
|
|
|
|
var e = torrent.element();
|
2008-07-10 23:57:46 +00:00
|
|
|
if( e ) {
|
2009-05-22 22:45:09 +00:00
|
|
|
var row_index = tr.getTorrentIndex(tr._rows, torrent);
|
|
|
|
delete e._torrent; //remove circular refernce to help IE garbage collect
|
|
|
|
tr._rows.splice(row_index, 1)
|
|
|
|
e.remove();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2009-05-22 22:45:09 +00:00
|
|
|
|
|
|
|
torrent.hideFileList();
|
2009-05-27 23:12:06 +00:00
|
|
|
torrent.deleteFiles();
|
2009-06-07 23:55:42 +00:00
|
|
|
delete tr._torrents[torrent.id()];
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2009-05-22 22:45:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return removedAny;
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the alternating background colors for torrents
|
|
|
|
*/
|
|
|
|
setTorrentBgColors: function( )
|
|
|
|
{
|
|
|
|
var rows = this.getVisibleRows( );
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=rows[i]; ++i ) {
|
2009-05-25 13:31:03 +00:00
|
|
|
var wasEven = row[0].className.indexOf('even') != -1;
|
2009-05-23 15:05:58 +00:00
|
|
|
var isEven = ((i+1) % 2 == 0);
|
2009-05-24 15:48:18 +00:00
|
|
|
if( wasEven != isEven )
|
2009-05-25 13:31:03 +00:00
|
|
|
row.toggleClass('even', isEven);
|
2009-05-23 15:05:58 +00:00
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
updateStatusbar: function()
|
|
|
|
{
|
|
|
|
var torrents = this.getAllTorrents();
|
|
|
|
var torrentCount = torrents.length;
|
|
|
|
var visibleCount = this.getVisibleTorrents().length;
|
|
|
|
|
|
|
|
// calculate the overall speed
|
|
|
|
var upSpeed = 0;
|
|
|
|
var downSpeed = 0;
|
2009-05-24 15:48:18 +00:00
|
|
|
for( var i=0, row; row=torrents[i]; ++i ) {
|
|
|
|
upSpeed += row.uploadSpeed( );
|
|
|
|
downSpeed += row.downloadSpeed( );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update torrent count label
|
|
|
|
var s;
|
|
|
|
if( torrentCount == visibleCount )
|
|
|
|
s = torrentCount + ' Transfers';
|
|
|
|
else
|
|
|
|
s = visibleCount + ' of ' + torrentCount + ' Transfers';
|
|
|
|
setInnerHTML( $('#torrent_global_transfer')[0], s );
|
|
|
|
|
|
|
|
// update the speeds
|
|
|
|
s = Math.formatBytes( upSpeed ) + '/s';
|
|
|
|
if( iPhone ) s = 'UL: ' + s;
|
|
|
|
setInnerHTML( $('#torrent_global_upload')[0], s );
|
|
|
|
|
|
|
|
// download speeds
|
|
|
|
s = Math.formatBytes( downSpeed ) + '/s';
|
|
|
|
if( iPhone ) s = 'DL: ' + s;
|
|
|
|
setInnerHTML( $('#torrent_global_download')[0], s );
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
/*
|
|
|
|
* Select a torrent file to upload
|
|
|
|
* FIXME
|
|
|
|
*/
|
|
|
|
uploadTorrentFile: function(confirmed)
|
|
|
|
{
|
|
|
|
// Display the upload dialog
|
|
|
|
if (! confirmed) {
|
|
|
|
$('input#torrent_upload_file').attr('value', '');
|
2009-08-12 14:40:32 +00:00
|
|
|
$('input#torrent_upload_url').attr('value', '');
|
2010-03-17 19:23:03 +00:00
|
|
|
$('input#torrent_auto_start').attr('checked', $('#prefs_form #auto_start')[0].checked);
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#upload_container').show();
|
|
|
|
if (!iPhone && Safari3) {
|
|
|
|
setTimeout("$('div#upload_container div.dialog_window').css('top', '0px');",10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submit the upload form
|
|
|
|
} else {
|
|
|
|
var tr = this;
|
|
|
|
var args = { };
|
2009-12-06 03:21:16 +00:00
|
|
|
var paused = !$('#torrent_auto_start').is(':checked');
|
2009-01-20 03:41:19 +00:00
|
|
|
if ('' != $('#torrent_upload_url').val()) {
|
2009-12-06 03:21:16 +00:00
|
|
|
tr.remote.addTorrentByUrl($('#torrent_upload_url').val(), { paused: paused });
|
2009-01-20 03:41:19 +00:00
|
|
|
} else {
|
2009-12-06 03:21:16 +00:00
|
|
|
args.url = '/transmission/upload?paused=' + paused;
|
2009-01-20 03:41:19 +00:00
|
|
|
args.type = 'POST';
|
2009-05-14 17:21:07 +00:00
|
|
|
args.data = { 'X-Transmission-Session-Id' : tr.remote._token };
|
2009-01-20 03:41:19 +00:00
|
|
|
args.dataType = 'xml';
|
|
|
|
args.iframe = true;
|
|
|
|
args.success = function( data ) {
|
2009-05-22 22:45:09 +00:00
|
|
|
tr.refreshTorrents();
|
2009-01-20 03:41:19 +00:00
|
|
|
tr.togglePeriodicRefresh( true );
|
|
|
|
};
|
2009-03-14 21:33:08 +00:00
|
|
|
tr.togglePeriodicRefresh( false );
|
2009-01-20 03:41:19 +00:00
|
|
|
$('#torrent_upload_form').ajaxSubmit( args );
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
removeSelectedTorrents: function() {
|
|
|
|
var torrents = this.getSelectedTorrents( );
|
|
|
|
if( torrents.length )
|
|
|
|
this.promptToRemoveTorrents( torrents );
|
|
|
|
},
|
|
|
|
|
2009-02-12 17:20:43 +00:00
|
|
|
removeSelectedTorrentsAndData: function() {
|
|
|
|
var torrents = this.getSelectedTorrents( );
|
|
|
|
if( torrents.length )
|
|
|
|
this.promptToRemoveTorrentsAndData( torrents );
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
promptToRemoveTorrents:function( torrents )
|
|
|
|
{
|
|
|
|
if( torrents.length == 1 )
|
|
|
|
{
|
|
|
|
var torrent = torrents[0];
|
|
|
|
var header = 'Remove ' + torrent.name() + '?';
|
2008-08-18 01:45:13 +00:00
|
|
|
var message = 'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?';
|
2008-07-10 23:57:46 +00:00
|
|
|
dialog.confirm( header, message, 'Remove', 'transmission.removeTorrents', torrents );
|
|
|
|
}
|
2009-08-12 14:40:32 +00:00
|
|
|
else
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2008-08-18 01:42:57 +00:00
|
|
|
var header = 'Remove ' + torrents.length + ' transfers?';
|
|
|
|
var message = 'Once removed, continuing the transfers will require the torrent files. Are you sure you want to remove them?';
|
2008-07-10 23:57:46 +00:00
|
|
|
dialog.confirm( header, message, 'Remove', 'transmission.removeTorrents', torrents );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-02-12 17:20:43 +00:00
|
|
|
promptToRemoveTorrentsAndData:function( torrents )
|
|
|
|
{
|
|
|
|
if( torrents.length == 1 )
|
|
|
|
{
|
|
|
|
var torrent = torrents[0],
|
|
|
|
header = 'Remove ' + torrent.name() + ' and delete data?',
|
|
|
|
message = 'All data downloaded for this torrent will be deleted. Are you sure you want to remove it?';
|
|
|
|
dialog.confirm( header, message, 'Remove', 'transmission.removeTorrentsAndData', torrents );
|
|
|
|
}
|
2009-08-12 14:40:32 +00:00
|
|
|
else
|
2009-02-12 17:20:43 +00:00
|
|
|
{
|
|
|
|
var header = 'Remove ' + torrents.length + ' transfers and delete data?',
|
|
|
|
message = 'All data downloaded for these torrents will be deleted. Are you sure you want to remove them?';
|
|
|
|
dialog.confirm( header, message, 'Remove', 'transmission.removeTorrentsAndData', torrents );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
removeTorrents: function( torrents ) {
|
2009-08-12 02:53:45 +00:00
|
|
|
var torrent_ids = jQuery.map(torrents, function(t) { return t.id(); } );
|
|
|
|
var tr = this;
|
|
|
|
this.remote.removeTorrents( torrent_ids, function(){ tr.refreshTorrents() } );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2009-02-12 17:20:43 +00:00
|
|
|
removeTorrentsAndData: function( torrents ) {
|
|
|
|
this.remote.removeTorrentsAndData( torrents );
|
|
|
|
},
|
|
|
|
|
2009-03-04 00:19:11 +00:00
|
|
|
verifySelectedTorrents: function() {
|
|
|
|
this.verifyTorrents( this.getSelectedTorrents( ) );
|
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
startSelectedTorrents: function( ) {
|
|
|
|
this.startTorrents( this.getSelectedTorrents( ) );
|
|
|
|
},
|
|
|
|
startAllTorrents: function( ) {
|
|
|
|
this.startTorrents( this.getAllTorrents( ) );
|
|
|
|
},
|
|
|
|
startTorrent: function( torrent ) {
|
|
|
|
this.startTorrents( [ torrent ] );
|
|
|
|
},
|
|
|
|
startTorrents: function( torrents ) {
|
2009-08-12 02:53:45 +00:00
|
|
|
var torrent_ids = jQuery.map(torrents, function(t) { return t.id(); } );
|
|
|
|
var tr = this;
|
|
|
|
this.remote.startTorrents( torrent_ids, function(){ tr.refreshTorrents(torrent_ids) } );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-03-04 00:19:11 +00:00
|
|
|
verifyTorrent: function( torrent ) {
|
|
|
|
this.verifyTorrents( [ torrent ] );
|
|
|
|
},
|
|
|
|
verifyTorrents: function( torrents ) {
|
2009-08-12 02:53:45 +00:00
|
|
|
var torrent_ids = jQuery.map(torrents, function(t) { return t.id(); } );
|
|
|
|
var tr = this;
|
|
|
|
this.remote.verifyTorrents( torrent_ids, function(){ tr.refreshTorrents(torrent_ids) } );
|
2009-03-04 00:19:11 +00:00
|
|
|
},
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
stopSelectedTorrents: function( ) {
|
|
|
|
this.stopTorrents( this.getSelectedTorrents( ) );
|
|
|
|
},
|
|
|
|
stopAllTorrents: function( ) {
|
|
|
|
this.stopTorrents( this.getAllTorrents( ) );
|
|
|
|
},
|
|
|
|
stopTorrent: function( torrent ) {
|
|
|
|
this.stopTorrents( [ torrent ] );
|
|
|
|
},
|
|
|
|
stopTorrents: function( torrents ) {
|
2009-08-12 02:53:45 +00:00
|
|
|
var torrent_ids = jQuery.map(torrents, function(t) { return t.id(); } );
|
|
|
|
var tr = this;
|
|
|
|
this.remote.stopTorrents( torrent_ids, function(){ tr.refreshTorrents(torrent_ids )} );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-03-14 21:33:08 +00:00
|
|
|
changeFileCommand: function(command, torrent, file) {
|
|
|
|
this.remote.changeFileCommand(command, torrent, file)
|
|
|
|
},
|
2009-05-25 04:07:48 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
hideiPhoneAddressbar: function(timeInSeconds) {
|
2009-06-07 04:46:17 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
if( iPhone ) {
|
|
|
|
var delayLength = timeInSeconds ? timeInSeconds*1000 : 150;
|
|
|
|
// not currently supported on iPhone
|
|
|
|
if(/*document.body.scrollTop!=1 && */scroll_timeout==null) {
|
2009-06-07 04:46:17 +00:00
|
|
|
scroll_timeout = setTimeout(function(){ tr.doToolbarHide(); }, delayLength);
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
doToolbarHide: function() {
|
|
|
|
window.scrollTo(0,1);
|
|
|
|
scroll_timeout=null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
refilter: function()
|
|
|
|
{
|
|
|
|
// decide which torrents to keep showing
|
|
|
|
var allTorrents = this.getAllTorrents( );
|
|
|
|
var keep = [ ];
|
2009-05-24 16:05:28 +00:00
|
|
|
for( var i=0, t; t=allTorrents[i]; ++i )
|
2008-07-10 23:57:46 +00:00
|
|
|
if( t.test( this[Prefs._FilterMode], this._current_search ) )
|
|
|
|
keep.push( t );
|
|
|
|
|
|
|
|
// sort the keepers
|
|
|
|
Torrent.sortTorrents( keep, this[Prefs._SortMethod],
|
|
|
|
this[Prefs._SortDirection] );
|
|
|
|
|
|
|
|
// make a backup of the selection
|
|
|
|
var sel = this.getSelectedTorrents( );
|
|
|
|
this.deselectAll( );
|
|
|
|
|
|
|
|
// hide the ones we're not keeping
|
2009-05-24 16:05:28 +00:00
|
|
|
for( var i=keep.length, e; e=this._rows[i]; ++i ) {
|
2008-07-10 23:57:46 +00:00
|
|
|
delete e._torrent;
|
2009-05-25 13:31:03 +00:00
|
|
|
e[0].style.display = 'none';
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// show the ones we're keeping
|
|
|
|
sel.sort( Torrent.compareById );
|
|
|
|
for( var i=0, len=keep.length; i<len; ++i ) {
|
|
|
|
var e = this._rows[i];
|
2009-05-25 13:31:03 +00:00
|
|
|
e[0].style.display = 'block';
|
2008-07-10 23:57:46 +00:00
|
|
|
var t = keep[i];
|
|
|
|
t.setElement( e );
|
|
|
|
if( Torrent.indexOf( sel, t.id() ) != -1 )
|
|
|
|
this.selectElement( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
// sync gui
|
|
|
|
this.setTorrentBgColors( );
|
|
|
|
this.updateStatusbar( );
|
|
|
|
this.selectionChanged( );
|
|
|
|
},
|
|
|
|
|
|
|
|
setEnabled: function( key, flag )
|
|
|
|
{
|
2009-05-24 15:48:18 +00:00
|
|
|
$(key).toggleClass( 'disabled', !flag );
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateButtonStates: function()
|
|
|
|
{
|
|
|
|
var showing_dialog = new RegExp("(prefs_showing|dialog_showing|open_showing)").test(document.body.className);
|
2009-05-23 21:39:16 +00:00
|
|
|
this._toolbar_buttons.toggleClass( 'disabled', showing_dialog );
|
|
|
|
|
|
|
|
if (!showing_dialog)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
|
|
|
var torrents = this.getVisibleTorrents( );
|
|
|
|
var haveSelection = false;
|
|
|
|
var haveActive = false;
|
|
|
|
var haveActiveSelection = false;
|
|
|
|
var havePaused = false;
|
|
|
|
var havePausedSelection = false;
|
|
|
|
|
|
|
|
for( var i=0, len=torrents.length; !haveSelection && i<len; ++i ) {
|
|
|
|
var isActive = torrents[i].isActive( );
|
|
|
|
var isSelected = torrents[i].isSelected( );
|
|
|
|
if( isActive ) haveActive = true;
|
|
|
|
if( !isActive ) havePaused = true;
|
|
|
|
if( isSelected ) haveSelection = true;
|
|
|
|
if( isSelected && isActive ) haveActiveSelection = true;
|
|
|
|
if( isSelected && !isActive ) havePausedSelection = true;
|
|
|
|
}
|
|
|
|
|
2009-05-24 15:48:18 +00:00
|
|
|
this.setEnabled( this._toolbar_pause_button, haveActiveSelection );
|
|
|
|
this.setEnabled( this._context_pause_button, haveActiveSelection );
|
|
|
|
this.setEnabled( this._toolbar_start_button, havePausedSelection );
|
|
|
|
this.setEnabled( this._context_start_button, havePausedSelection );
|
|
|
|
this.setEnabled( this._toolbar_remove_button, haveSelection );
|
|
|
|
this.setEnabled( this._toolbar_pause_all_button, haveActive );
|
|
|
|
this.setEnabled( this._toolbar_start_all_button, havePaused );
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|