2008-07-10 23:57:46 +00:00
|
|
|
/*
|
2011-03-10 01:37:58 +00:00
|
|
|
* Copyright © Dave Perrett, Malcolm Jarvis and Bruno Bierbaumer
|
2008-07-10 23:57:46 +00:00
|
|
|
* 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
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
function Transmission()
|
|
|
|
{
|
2008-07-10 23:57:46 +00:00
|
|
|
this.initialize();
|
2009-08-12 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
Transmission.prototype =
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** STARTUP
|
|
|
|
*****
|
|
|
|
****/
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
initialize: function()
|
|
|
|
{
|
|
|
|
// Initialize the helper classes
|
|
|
|
this.remote = new TransmissionRemote(this);
|
|
|
|
|
|
|
|
// Initialize the implementation fields
|
2011-08-27 21:35:19 +00:00
|
|
|
this.filterText = '';
|
|
|
|
this._torrents = { };
|
|
|
|
this._rows = [ ];
|
|
|
|
this.dirtyTorrents = { };
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Initialize the clutch preferences
|
2011-08-24 02:04:35 +00:00
|
|
|
Prefs.getClutchPrefs(this);
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
this.preloadImages();
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Set up user events
|
2009-05-22 22:45:09 +00:00
|
|
|
var tr = this;
|
2011-08-21 05:54:02 +00:00
|
|
|
$(".numberinput").forceNumeric();
|
2011-08-24 02:04:35 +00:00
|
|
|
$('#pause_all_link').click(function(e) { tr.stopAllClicked(e); });
|
|
|
|
$('#resume_all_link').click(function(e) { tr.startAllClicked(e); });
|
|
|
|
$('#pause_selected_link').click(function(e) { tr.stopSelectedClicked(e); });
|
|
|
|
$('#resume_selected_link').click(function(e) { tr.startSelectedClicked(e); });
|
|
|
|
$('#remove_link').click(function(e) { tr.removeClicked(e); });
|
|
|
|
$('#prefs_save_button').click(function(e) { tr.savePrefsClicked(e); return false;});
|
2011-08-25 07:15:38 +00:00
|
|
|
$('#prefs_cancel_button').click(function(e) { tr.hidePrefsDialog(); return false; });
|
|
|
|
$('#block_update_button').click(function(e) { tr.remote.updateBlocklist(); return false; });
|
|
|
|
$('#stats_close_button').click(function(e) { tr.hideStatsDialog(); return false; });
|
2011-08-24 02:04:35 +00:00
|
|
|
$('.inspector_tab').click(function(e) { tr.inspectorTabClicked(e, this); });
|
|
|
|
$('#files_select_all').live('click', function(e) { tr.filesSelectAllClicked(e, this); });
|
|
|
|
$('#files_deselect_all').live('click', function(e) { tr.filesDeselectAllClicked(e, this); });
|
|
|
|
$('#open_link').click(function(e) { tr.openTorrentClicked(e); });
|
|
|
|
$('#upload_confirm_button').click(function(e) { tr.confirmUploadClicked(e); return false;});
|
2011-08-25 07:15:38 +00:00
|
|
|
$('#upload_cancel_button').click(function(e) { tr.hideUploadDialog(); return false; });
|
2011-08-30 00:16:34 +00:00
|
|
|
$('#turtle-button').click(function() { tr.toggleTurtleClicked(); });
|
|
|
|
$('#compact-button').click(function() { tr.toggleCompactClicked(); });
|
2011-08-25 08:03:19 +00:00
|
|
|
$('#prefs-tab-general').click(function() { tr.selectPrefsTab('general'); });
|
|
|
|
$('#prefs-tab-speed').click(function() { tr.selectPrefsTab('speed'); });
|
|
|
|
$('#prefs-tab-peers').click(function() { tr.selectPrefsTab('peers'); });
|
|
|
|
$('#prefs-tab-network').click(function() { tr.selectPrefsTab('network'); });
|
2011-08-24 02:04:35 +00:00
|
|
|
$('#torrent_upload_form').submit(function() { $('#upload_confirm_button').click(); return false; });
|
|
|
|
$('#torrent_container').bind('dragover', function(e) { return tr.dragenter(e); });
|
|
|
|
$('#torrent_container').bind('dragenter', function(e) { return tr.dragenter(e); });
|
|
|
|
$('#torrent_container').bind('drop', function(e) { return tr.drop(e); });
|
2011-05-30 15:12:42 +00:00
|
|
|
// tell jQuery to copy the dataTransfer property from events over if it exists
|
|
|
|
jQuery.event.props.push("dataTransfer");
|
|
|
|
|
2011-08-28 16:33:22 +00:00
|
|
|
$(document).delegate('#torrent_list > li', 'click', function(ev) {tr.onRowClicked(ev,ev.currentTarget.row);});
|
2011-08-27 21:35:19 +00:00
|
|
|
$(document).delegate('#torrent_list > li', 'dblclick', function(e) {tr.toggleInspector();});
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
$('#torrent_upload_form').submit(function() { $('#upload_confirm_button').click(); return false; });
|
2009-11-10 05:43:14 +00:00
|
|
|
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) {
|
2011-08-25 23:06:41 +00:00
|
|
|
$('#inspector_close').bind('click', function() { tr.setInspectorVisible(false); });
|
2011-08-24 02:04:35 +00:00
|
|
|
$('#preferences_link').bind('click', function(e) { tr.releaseClutchPreferencesButton(e); });
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
2011-08-28 16:33:22 +00:00
|
|
|
$(document).bind('keydown', function(e) { return tr.keyDown(e); });
|
|
|
|
$(document).bind('keyup', function(e) { tr.keyUp(e); });
|
|
|
|
$(document).delegate('#torrent_container', 'click', function() { tr.deselectAll(); });
|
2011-08-25 23:06:41 +00:00
|
|
|
$('#inspector_link').click(function(e) { tr.toggleInspector(); });
|
2010-06-21 13:14:33 +00:00
|
|
|
|
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-06-17 04:40:06 +00:00
|
|
|
this._inspector_peers_list = $('#inspector_peers_list')[0];
|
2010-01-31 02:42:48 +00:00
|
|
|
this._inspector_trackers_list = $('#inspector_trackers_list')[0];
|
2011-08-24 02:04:35 +00:00
|
|
|
this._toolbar_buttons = $('#toolbar ul li');
|
|
|
|
this._toolbar_pause_button = $('#toolbar #pause_selected')[0];
|
|
|
|
this._toolbar_pause_all_button = $('#toolbar #pause_all')[0];
|
|
|
|
this._toolbar_start_button = $('#toolbar #resume_selected')[0];
|
|
|
|
this._toolbar_start_all_button = $('#toolbar #resume_all')[0];
|
|
|
|
this._toolbar_remove_button = $('#toolbar #remove')[0];
|
2009-05-24 15:48:18 +00:00
|
|
|
this._context_pause_button = $('li#context_pause_selected')[0];
|
|
|
|
this._context_start_button = $('li#context_resume_selected')[0];
|
2011-08-01 22:24:24 +00:00
|
|
|
this._context_start_now_button = $('li#context_resume_now_selected')[0];
|
2011-08-06 15:19:29 +00:00
|
|
|
this._context_move_top = $('li#context_move_top')[0];
|
|
|
|
this._context_move_up = $('li#context_move_up')[0];
|
|
|
|
this._context_move_down = $('li#context_move_down')[0];
|
|
|
|
this._context_move_bottom = $('li#context_move_bottom')[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];
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Setup the prefs gui
|
2011-08-24 02:04:35 +00:00
|
|
|
this.initializeSettings();
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Get preferences & torrents from the daemon
|
2009-07-28 04:53:08 +00:00
|
|
|
var async = false;
|
2011-08-24 02:04:35 +00:00
|
|
|
this.loadDaemonPrefs(async);
|
|
|
|
this.loadDaemonStats(async);
|
2011-08-26 22:49:57 +00:00
|
|
|
this.initializeTorrents();
|
2011-08-26 19:42:07 +00:00
|
|
|
this.refreshTorrents();
|
2011-08-24 02:04:35 +00:00
|
|
|
this.togglePeriodicSessionRefresh(true);
|
|
|
|
|
|
|
|
this.filterSetup();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-25 08:03:19 +00:00
|
|
|
selectPrefsTab: function(name) {
|
|
|
|
$('#prefs-tab-'+name).addClass('selected').siblings('.prefs-tab').removeClass('selected');
|
|
|
|
$('#prefs-page-'+name).show().siblings('.prefs-page').hide();
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
loadDaemonPrefs: function(async) {
|
|
|
|
this.remote.loadDaemonPrefs(function(data) {
|
2011-08-24 13:17:45 +00:00
|
|
|
var o = data['arguments'];
|
2011-08-24 02:04:35 +00:00
|
|
|
Prefs.getClutchPrefs(o);
|
2011-08-28 06:05:46 +00:00
|
|
|
this.updatePrefs(o);
|
|
|
|
}, this, async);
|
2009-07-28 04:53:04 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
loadDaemonStats: function(async) {
|
|
|
|
this.remote.loadDaemonStats(function(data) {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.updateStats(data['arguments']);
|
|
|
|
}, this, async);
|
2010-03-11 04:50:04 +00:00
|
|
|
},
|
2011-08-24 02:04:35 +00:00
|
|
|
checkPort: function(async) {
|
|
|
|
$('#port_test').text('checking ...');
|
|
|
|
this.remote.checkPort(function(data) {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.updatePortStatus(data['arguments']);
|
|
|
|
}, this, async);
|
2011-03-10 01:37:58 +00:00
|
|
|
},
|
2010-03-11 04:50:04 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
preloadImages: function() {
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) {
|
2008-07-10 23:57:46 +00:00
|
|
|
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() {
|
2011-08-24 02:04:35 +00:00
|
|
|
for (var i=0, row; row=arguments[i]; ++i)
|
2009-05-24 16:05:28 +00:00
|
|
|
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
|
|
|
/*
|
|
|
|
* Load the clutch prefs and init the GUI according to those prefs
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
initializeSettings: function()
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
Prefs.getClutchPrefs(this);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// iPhone conditions in the section allow us to not
|
|
|
|
// include transmenu js to save some bandwidth; if we
|
2011-08-28 17:24:56 +00:00
|
|
|
// start using prefs on mobile devices we need to weed
|
2008-07-10 23:57:46 +00:00
|
|
|
// transmenu refs out of that too.
|
2011-08-28 17:24:56 +00:00
|
|
|
if (!isMobileDevice)
|
2011-08-26 18:36:09 +00:00
|
|
|
{
|
|
|
|
$('#sort_by_' + this[Prefs._SortMethod]).selectMenuItem();
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-26 18:36:09 +00:00
|
|
|
if (this[Prefs._SortDirection] === Prefs._SortDescending)
|
|
|
|
$('#reverse_sort_order').selectMenuItem();
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
this.initCompactMode();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the search box
|
|
|
|
*/
|
|
|
|
setupSearchBox: function()
|
|
|
|
{
|
|
|
|
var tr = this;
|
|
|
|
var search_box = $('#torrent_search');
|
2011-08-27 21:35:19 +00:00
|
|
|
search_box.bind('keyup click', function() {
|
|
|
|
tr.setFilterText(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';
|
2011-08-24 02:04:35 +00:00
|
|
|
search_box.bind('blur', function() {
|
2008-08-09 04:38:51 +00:00
|
|
|
if (this.value == '') {
|
|
|
|
$(this).addClass('blur');
|
|
|
|
this.value = 'Filter';
|
2011-08-27 21:35:19 +00:00
|
|
|
tr.setFilterText(null);
|
2008-08-09 04:38:51 +00:00
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
}).bind('focus', function() {
|
2008-08-09 04:38:51 +00:00
|
|
|
if ($(this).is('.blur')) {
|
|
|
|
this.value = '';
|
|
|
|
$(this).removeClass('blur');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
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 = {
|
2011-08-24 02:04:35 +00:00
|
|
|
context_pause_selected: function() { tr.stopSelectedTorrents(); },
|
|
|
|
context_resume_selected: function() { tr.startSelectedTorrents(false); },
|
|
|
|
context_resume_now_selected: function() { tr.startSelectedTorrents(true); },
|
|
|
|
context_remove: function() { tr.removeSelectedTorrents(); },
|
|
|
|
context_removedata: function() { tr.removeSelectedTorrentsAndData(); },
|
|
|
|
context_verify: function() { tr.verifySelectedTorrents(); },
|
|
|
|
context_reannounce: function() { tr.reannounceSelectedTorrents(); },
|
|
|
|
context_toggle_inspector: function() { tr.toggleInspector(); },
|
|
|
|
context_select_all: function() { tr.selectAll(); },
|
|
|
|
context_deselect_all: function() { tr.deselectAll(); },
|
|
|
|
context_move_top: function() { tr.moveTop(); },
|
|
|
|
context_move_up: function() { tr.moveUp(); },
|
|
|
|
context_move_down: function() { tr.moveDown(); },
|
|
|
|
context_move_bottom: function() { tr.moveBottom(); }
|
2008-07-10 23:57:46 +00:00
|
|
|
};
|
2010-06-21 13:14:33 +00:00
|
|
|
|
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,
|
2011-08-29 20:29:45 +00:00
|
|
|
onContextMenu: function(ev) {
|
|
|
|
var element = $(ev.target).closest('.torrent')[0];
|
|
|
|
var i = $('#torrent_list > li').index(element);
|
|
|
|
if ((i!==-1) && !tr._rows[i].isSelected())
|
|
|
|
tr.setSelectedRow(tr._rows[i]);
|
2010-06-21 13:14:33 +00:00
|
|
|
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() {
|
|
|
|
$('#settings_menu').transMenu({
|
|
|
|
selected_char: '✔',
|
|
|
|
direction: 'up',
|
2011-08-30 21:55:44 +00:00
|
|
|
onClick: $.proxy(this.processSettingsMenuEvent,this)
|
2008-07-10 23:57:46 +00:00
|
|
|
});
|
2010-06-21 13:14:33 +00:00
|
|
|
|
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() {
|
2011-08-24 02:04:35 +00:00
|
|
|
var i, hour, mins, start, end, value, content;
|
2009-11-10 05:42:57 +00:00
|
|
|
// Build the list of times
|
2010-09-03 00:03:21 +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++) {
|
2011-08-24 02:04:35 +00:00
|
|
|
hour = parseInt(i / 4, 10);
|
2009-11-10 05:42:57 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** UTILITIES
|
|
|
|
*****
|
|
|
|
****/
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
getAllTorrents: function()
|
|
|
|
{
|
2009-06-07 23:55:42 +00:00
|
|
|
var torrents = [];
|
2011-08-24 02:04:35 +00:00
|
|
|
for (var key in this._torrents)
|
2011-08-26 18:36:09 +00:00
|
|
|
torrents.push(this._torrents[key]);
|
2008-07-10 23:57:46 +00:00
|
|
|
return torrents;
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
scrollToRow: function(row)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) // FIXME: why?
|
2011-08-24 02:04:35 +00:00
|
|
|
return;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
var list = $('#torrent_container'),
|
|
|
|
scrollTop = list.scrollTop(),
|
|
|
|
innerHeight = list.innerHeight(),
|
|
|
|
offsetTop = row.getElement().offsetTop,
|
|
|
|
offsetHeight = $(row.getElement()).outerHeight();
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
if (offsetTop < scrollTop)
|
|
|
|
list.scrollTop(offsetTop);
|
|
|
|
else if (innerHeight + scrollTop < offsetTop + offsetHeight)
|
|
|
|
list.scrollTop(offsetTop + offsetHeight - innerHeight);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
seedRatioLimit: function() {
|
|
|
|
if (this._prefs && this._prefs['seedRatioLimited'])
|
|
|
|
return this._prefs['seedRatioLimit'];
|
2011-08-26 18:36:09 +00:00
|
|
|
return -1;
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
setPref: function(key, val)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
|
|
|
this[key] = val;
|
2011-08-24 02:04:35 +00:00
|
|
|
Prefs.setValue(key, val);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** SELECTION
|
|
|
|
*****
|
|
|
|
****/
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getSelectedRows: function() {
|
2011-08-26 18:36:09 +00:00
|
|
|
return $.grep(this._rows, function(r) {return r.isSelected();});
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getSelectedTorrents: function() {
|
2011-08-26 18:36:09 +00:00
|
|
|
return $.map(this.getSelectedRows(),function(r) {return r.getTorrent();});
|
2009-07-28 04:52:47 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getSelectedTorrentIds: function() {
|
2011-08-26 18:36:09 +00:00
|
|
|
return $.map(this.getSelectedRows(),function(r) {return r.getTorrentId();});
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
setSelectedRow: function(row) {
|
2011-08-30 21:31:10 +00:00
|
|
|
$(this._torrent_list).children('.selected').removeClass('selected');
|
2011-08-24 02:04:35 +00:00
|
|
|
this.selectRow(row);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
selectRow: function(row) {
|
2011-08-30 21:31:10 +00:00
|
|
|
$(row.getElement()).addClass('selected');
|
2011-08-16 18:49:26 +00:00
|
|
|
this.callSelectionChangedSoon();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
deselectRow: function(row) {
|
2011-08-30 21:31:10 +00:00
|
|
|
$(row.getElement()).removeClass('selected');
|
2011-08-16 18:49:26 +00:00
|
|
|
this.callSelectionChangedSoon();
|
2009-05-25 13:31:03 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
selectAll: function() {
|
2011-08-30 21:31:10 +00:00
|
|
|
$(this._torrent_list).children().addClass('selected');
|
2011-08-16 18:49:26 +00:00
|
|
|
this.callSelectionChangedSoon();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2011-08-24 02:04:35 +00:00
|
|
|
deselectAll: function() {
|
2011-08-30 21:31:10 +00:00
|
|
|
$(this._torrent_list).children('.selected').removeClass('selected');
|
2011-08-16 18:49:26 +00:00
|
|
|
this.callSelectionChangedSoon();
|
2011-08-24 02:04:35 +00:00
|
|
|
delete this._last_torrent_clicked;
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-25 10:23:19 +00:00
|
|
|
indexOfLastTorrent: function() {
|
|
|
|
for (var i=0, r; r=this._rows[i]; ++i)
|
2011-08-26 00:43:35 +00:00
|
|
|
if (r.getTorrentId() === this._last_torrent_clicked)
|
2011-08-25 10:23:19 +00:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/* Select a range from this torrent to the last clicked torrent */
|
|
|
|
selectRange: function(row)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-25 10:23:19 +00:00
|
|
|
var last = this.indexOfLastTorrent();
|
|
|
|
|
|
|
|
if (last === -1)
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
this.selectRow(row);
|
2011-08-25 10:23:19 +00:00
|
|
|
}
|
|
|
|
else // select the range between the prevous & current
|
|
|
|
{
|
|
|
|
var next = this._rows.indexOf(row);
|
|
|
|
var min = Math.min(last, next);
|
|
|
|
var max = Math.max(last, next);
|
|
|
|
for (var i=min; i<=max; ++i)
|
|
|
|
this.selectRow(this._rows[i]);
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
this.callSelectionChangedSoon();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2009-03-14 21:33:08 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
selectionChanged: function()
|
|
|
|
{
|
|
|
|
this.updateButtonStates();
|
2011-08-30 21:40:18 +00:00
|
|
|
this.inspectorSelectionChanged();
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
clearTimeout(this.selectionChangedTimer);
|
|
|
|
delete this.selectionChangedTimer;
|
2011-08-30 21:40:18 +00:00
|
|
|
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
callSelectionChangedSoon: function()
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
if (!this.selectionChangedTimer)
|
2011-08-30 21:55:44 +00:00
|
|
|
this.selectionChangedTimer = setTimeout($.proxy(this.selectionChanged,this),200);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*--------------------------------------------
|
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
|
|
|
|
*/
|
2011-08-21 14:02:28 +00:00
|
|
|
keyDown: function(ev)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-28 16:33:22 +00:00
|
|
|
var handled = false,
|
2011-08-28 19:30:17 +00:00
|
|
|
rows = this._rows,
|
2011-08-28 16:33:22 +00:00
|
|
|
up = ev.keyCode === 38; // up key pressed
|
2011-08-28 13:57:25 +00:00
|
|
|
dn = ev.keyCode === 40, // down key pressed
|
|
|
|
shift = ev.keyCode === 16; // shift key pressed
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-28 19:30:17 +00:00
|
|
|
if ((up || dn) && rows.length)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-28 19:30:17 +00:00
|
|
|
var last = this.indexOfLastTorrent(),
|
2011-08-28 13:57:25 +00:00
|
|
|
i = last,
|
2011-08-30 02:03:17 +00:00
|
|
|
anchor = this._shift_index,
|
|
|
|
r,
|
|
|
|
min = 0,
|
|
|
|
max = rows.length - 1;
|
|
|
|
|
|
|
|
if (dn && (i+1 <= max))
|
|
|
|
++i;
|
|
|
|
else if (up && (i-1 >= min))
|
|
|
|
--i;
|
2011-08-24 02:04:35 +00:00
|
|
|
|
2011-08-25 11:25:13 +00:00
|
|
|
var r = rows[i];
|
2011-08-25 10:23:19 +00:00
|
|
|
|
2011-08-26 18:36:09 +00:00
|
|
|
if (anchor >= 0)
|
2011-08-25 10:23:19 +00:00
|
|
|
{
|
|
|
|
// user is extending the selection with the shift + arrow keys...
|
2011-08-26 18:36:09 +00:00
|
|
|
if ( ((anchor <= last) && (last < i))
|
|
|
|
|| ((anchor >= last) && (last > i)))
|
2011-08-25 10:23:19 +00:00
|
|
|
{
|
|
|
|
this.selectRow(r);
|
|
|
|
}
|
2011-08-26 18:36:09 +00:00
|
|
|
else if (((anchor >= last) && (i > last))
|
|
|
|
|| ((anchor <= last) && (last > i)))
|
2011-08-25 10:23:19 +00:00
|
|
|
{
|
|
|
|
this.deselectRow(rows[last]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ev.shiftKey)
|
|
|
|
this.selectRange(r);
|
|
|
|
else
|
|
|
|
this.setSelectedRow(r);
|
|
|
|
}
|
2011-08-26 00:43:35 +00:00
|
|
|
this._last_torrent_clicked = r.getTorrentId();
|
2011-08-25 10:23:19 +00:00
|
|
|
this.scrollToRow(r);
|
2011-08-28 16:33:22 +00:00
|
|
|
handled = true;
|
2009-05-25 13:31:03 +00:00
|
|
|
}
|
2011-08-25 10:23:19 +00:00
|
|
|
else if (shift)
|
|
|
|
{
|
|
|
|
this._shift_index = this.indexOfLastTorrent();
|
|
|
|
}
|
2011-08-28 16:33:22 +00:00
|
|
|
|
|
|
|
return !handled;
|
2011-08-25 10:23:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
keyUp: function(ev)
|
|
|
|
{
|
|
|
|
if (ev.keyCode === 16) // shift key pressed
|
|
|
|
delete this._shift_index;
|
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';
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
stopAllClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
2011-08-24 02:04:35 +00:00
|
|
|
this.stopAllTorrents();
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
stopSelectedClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
2011-08-24 02:04:35 +00:00
|
|
|
this.stopSelectedTorrents();
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
startAllClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
2011-08-24 02:04:35 +00:00
|
|
|
this.startAllTorrents();
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
startSelectedClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
2011-08-24 02:04:35 +00:00
|
|
|
this.startSelectedTorrents(false);
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
openTorrentClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
2008-07-10 23:57:46 +00:00
|
|
|
$('body').addClass('open_showing');
|
2011-08-24 02:04:35 +00:00
|
|
|
this.uploadTorrentFile();
|
|
|
|
this.updateButtonStates();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
dragenter: function(ev) {
|
|
|
|
if (ev.dataTransfer && ev.dataTransfer.types) {
|
2011-05-30 15:12:42 +00:00
|
|
|
var types = ["text/uri-list", "text/plain"];
|
2011-08-24 02:04:35 +00:00
|
|
|
for (var i = 0; i < types.length; ++i) {
|
2011-08-28 13:57:25 +00:00
|
|
|
// it would be better to look at the links here;
|
|
|
|
// sadly, with Firefox, trying would throw.
|
|
|
|
if (ev.dataTransfer.types.contains(types[i])) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.dropEffect = "copy";
|
2011-05-30 15:12:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-28 13:57:25 +00:00
|
|
|
else if (ev.dataTransfer) {
|
|
|
|
ev.dataTransfer.dropEffect = "none";
|
2011-05-30 15:12:42 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
drop: function(ev) {
|
|
|
|
if (!ev.dataTransfer || !ev.dataTransfer.types) {
|
2011-05-30 15:12:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
ev.preventDefault();
|
2011-05-30 15:12:42 +00:00
|
|
|
var uris = null;
|
|
|
|
var types = ["text/uri-list", "text/plain"];
|
2011-08-24 02:04:35 +00:00
|
|
|
for (var i = 0; i < types.length; ++i) {
|
|
|
|
if (ev.dataTransfer.types.contains(types[i])) {
|
|
|
|
uris = ev.dataTransfer.getData(types[i]).split("\n");
|
2011-05-30 15:12:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var paused = $('#prefs_form #auto_start')[0].checked;
|
2011-08-24 02:04:35 +00:00
|
|
|
for (i = 0; i < uris.length; ++i) {
|
2011-05-30 15:12:42 +00:00
|
|
|
var uri = uris[i];
|
2011-08-24 02:04:35 +00:00
|
|
|
if (/^#/.test(uri)) {
|
2011-05-30 15:12:42 +00:00
|
|
|
// lines which start with "#" are comments
|
|
|
|
continue;
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
if (/^[a-z-]+:/i.test(uri)) {
|
2011-05-30 15:12:42 +00:00
|
|
|
// close enough to a url
|
2011-08-24 02:04:35 +00:00
|
|
|
this.remote.addTorrentByUrl(uri, paused);
|
2011-05-30 15:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
hideUploadDialog: function() {
|
2008-07-10 23:57:46 +00:00
|
|
|
$('body.open_showing').removeClass('open_showing');
|
2011-08-28 17:24:56 +00:00
|
|
|
$('#upload_container').hide();
|
2009-05-23 02:28:04 +00:00
|
|
|
this.updateButtonStates();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
confirmUploadClicked: function() {
|
|
|
|
this.uploadTorrentFile(true);
|
|
|
|
this.hideUploadDialog();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
savePrefsClicked: function()
|
2010-09-03 00:03:21 +00:00
|
|
|
{
|
|
|
|
// handle the clutch prefs locally
|
2011-08-24 02:04:35 +00:00
|
|
|
var rate = parseInt ($('#prefs_form #refresh_rate')[0].value, 10);
|
2011-08-30 21:55:44 +00:00
|
|
|
if (rate != this[Prefs._RefreshRate])
|
|
|
|
this.setPref (Prefs._RefreshRate, rate);
|
2010-09-03 00:03:21 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
var up_bytes = parseInt($('#prefs_form #upload_rate').val(), 10),
|
|
|
|
dn_bytes = parseInt($('#prefs_form #download_rate').val(), 10),
|
|
|
|
turtle_up_bytes = parseInt($('#prefs_form #turtle_upload_rate').val(), 10),
|
|
|
|
turtle_dn_bytes = parseInt($('#prefs_form #turtle_download_rate').val(), 10);
|
2010-09-03 00:03:21 +00:00
|
|
|
|
|
|
|
// pass the new prefs upstream to the RPC server
|
|
|
|
var o = { };
|
|
|
|
o[RPC._StartAddedTorrent] = $('#prefs_form #auto_start')[0].checked;
|
2011-08-24 12:49:10 +00:00
|
|
|
o[RPC._PeerPort] = parseInt($('#prefs_form #port').val(), 10);
|
2010-09-03 00:03:21 +00:00
|
|
|
o[RPC._UpSpeedLimit] = up_bytes;
|
|
|
|
o[RPC._DownSpeedLimit] = dn_bytes;
|
2011-08-24 12:49:10 +00:00
|
|
|
o[RPC._DownloadDir] = $('#prefs_form #download_location').val();
|
|
|
|
o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload').prop('checked');
|
|
|
|
o[RPC._DownSpeedLimited] = $('#prefs_form #limit_download').prop('checked');
|
|
|
|
o[RPC._Encryption] = $('#prefs_form #encryption').prop('checked')
|
2010-09-03 00:03:21 +00:00
|
|
|
? RPC._EncryptionRequired
|
|
|
|
: RPC._EncryptionPreferred;
|
|
|
|
o[RPC._TurtleDownSpeedLimit] = turtle_dn_bytes;
|
|
|
|
o[RPC._TurtleUpSpeedLimit] = turtle_up_bytes;
|
2011-08-24 12:49:10 +00:00
|
|
|
o[RPC._TurtleTimeEnabled] = $('#prefs_form #turtle_schedule').prop('checked');
|
2011-08-24 02:04:35 +00:00
|
|
|
o[RPC._TurtleTimeBegin] = parseInt($('#prefs_form #turtle_start_time').val(), 10);
|
|
|
|
o[RPC._TurtleTimeEnd] = parseInt($('#prefs_form #turtle_end_time').val(), 10);
|
|
|
|
o[RPC._TurtleTimeDay] = parseInt($('#prefs_form #turtle_days').val(), 10);
|
2010-09-03 00:03:21 +00:00
|
|
|
|
2011-03-10 01:37:58 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
o[RPC._PeerLimitGlobal] = parseInt($('#prefs_form #conn_global').val(), 10);
|
|
|
|
o[RPC._PeerLimitPerTorrent] = parseInt($('#prefs_form #conn_torrent').val(), 10);
|
2011-08-24 12:49:10 +00:00
|
|
|
o[RPC._PexEnabled] = $('#prefs_form #conn_pex').prop('checked');
|
|
|
|
o[RPC._DhtEnabled] = $('#prefs_form #conn_dht').prop('checked');
|
|
|
|
o[RPC._LpdEnabled] = $('#prefs_form #conn_lpd').prop('checked');
|
|
|
|
o[RPC._BlocklistEnabled] = $('#prefs_form #block_enable').prop('checked');
|
2011-03-10 01:37:58 +00:00
|
|
|
o[RPC._BlocklistURL] = $('#prefs_form #block_url').val();
|
2011-08-24 12:49:10 +00:00
|
|
|
o[RPC._UtpEnabled] = $('#prefs_form #network_utp').prop('checked');
|
|
|
|
o[RPC._PeerPortRandom] = $('#prefs_form #port_rand').prop('checked');
|
|
|
|
o[RPC._PortForwardingEnabled]= $('#prefs_form #port_forward').prop('checked');
|
2011-03-10 01:37:58 +00:00
|
|
|
|
2011-08-30 21:55:44 +00:00
|
|
|
this.remote.savePrefs(o);
|
2010-09-03 00:03:21 +00:00
|
|
|
|
2011-08-30 21:55:44 +00:00
|
|
|
this.hidePrefsDialog();
|
2010-09-03 00:03:21 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
removeClicked: function(ev) {
|
2011-08-25 07:15:38 +00:00
|
|
|
if (this.isButtonEnabled(ev)) {
|
|
|
|
this.removeSelectedTorrents();
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2011-08-28 17:24:56 +00:00
|
|
|
* 'Clutch Preferences' was clicked (isMobileDevice only)
|
2008-07-10 23:57:46 +00:00
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
releaseClutchPreferencesButton: function() {
|
2008-07-10 23:57:46 +00:00
|
|
|
$('div#prefs_container div#pref_error').hide();
|
|
|
|
$('div#prefs_container h2.dialog_heading').show();
|
2011-08-24 02:04:35 +00:00
|
|
|
this.showPrefsDialog();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getIntervalMsec: function(key, min)
|
|
|
|
{
|
|
|
|
var interval = this[key];
|
|
|
|
if (!interval || (interval < min))
|
|
|
|
interval = min;
|
|
|
|
return interval * 1000;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Turn the periodic ajax session refresh on & off */
|
|
|
|
togglePeriodicSessionRefresh: function(enabled) {
|
|
|
|
clearInterval(this._periodic_session_refresh);
|
|
|
|
delete this._periodic_session_refresh;
|
|
|
|
if (enabled) {
|
|
|
|
var msec = this.getIntervalMsec(Prefs._SessionRefreshRate, 5);
|
2011-08-30 21:55:44 +00:00
|
|
|
this._periodic_session_refresh = setInterval($.proxy(this.loadDaemonPrefs,this), msec);
|
2009-11-14 14:57:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/* Turn the periodic ajax stats refresh on & off */
|
|
|
|
togglePeriodicStatsRefresh: function(enabled) {
|
|
|
|
clearInterval(this._periodic_stats_refresh);
|
|
|
|
delete this._periodic_stats_refresh;
|
|
|
|
if (enabled) {
|
|
|
|
var msec = this.getIntervalMsec(Prefs._SessionRefreshRate, 5);
|
2011-08-30 21:55:44 +00:00
|
|
|
this._periodic_stats_refresh = setInterval($.proxy(this.loadDaemonStats,this), msec);
|
2010-03-11 04:50:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
toggleTurtleClicked: function()
|
|
|
|
{
|
|
|
|
// toggle it
|
|
|
|
var p = Prefs._TurtleState;
|
|
|
|
this[p] = !this[p];
|
|
|
|
|
|
|
|
// send it to the session
|
2010-09-03 00:03:21 +00:00
|
|
|
var args = { };
|
2011-08-24 02:04:35 +00:00
|
|
|
args[RPC._TurtleState] = this[p];
|
|
|
|
this.remote.savePrefs(args);
|
2009-11-10 05:42:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateTurtleButton: function() {
|
2011-08-30 00:16:34 +00:00
|
|
|
var enabled = this[Prefs._TurtleState],
|
|
|
|
w = $('#turtle-button'),
|
|
|
|
t = [ 'Click to ', (enabled?'disable':'enable'), ' Temporary Speed Limits',
|
|
|
|
'(', Transmission.fmt.speed(this._prefs[RPC._TurtleUpSpeedLimit]), 'up,',
|
|
|
|
Transmission.fmt.speed(this._prefs[RPC._TurtleDownSpeedLimit]), 'down)' ];
|
|
|
|
w.toggleClass('enabled',enabled);
|
2011-08-24 02:04:35 +00:00
|
|
|
w.attr('title', t.join(' '));
|
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
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
showPrefsDialog: function() {
|
2011-03-10 01:37:58 +00:00
|
|
|
this.checkPort(true);
|
2010-09-03 00:03:21 +00:00
|
|
|
$('body').addClass('prefs_showing');
|
|
|
|
$('#prefs_container').show();
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2011-08-24 02:04:35 +00:00
|
|
|
this.updateButtonStates();
|
2010-09-03 00:03:21 +00:00
|
|
|
this.togglePeriodicSessionRefresh(false);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
hidePrefsDialog: function()
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2010-09-03 00:03:21 +00:00
|
|
|
$('body.prefs_showing').removeClass('prefs_showing');
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice)
|
|
|
|
this.hideMobileAddressbar();
|
|
|
|
$('#prefs_container').hide();
|
2011-08-24 02:04:35 +00:00
|
|
|
this.updateButtonStates();
|
2010-09-03 00:03:21 +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
|
|
|
|
*/
|
2011-08-24 12:49:10 +00:00
|
|
|
updatePrefs: function(p)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
|
|
|
// remember them for later
|
2011-08-24 12:49:10 +00:00
|
|
|
this._prefs = p;
|
|
|
|
|
|
|
|
var up_limited = p[RPC._UpSpeedLimited];
|
|
|
|
var dn_limited = p[RPC._DownSpeedLimited];
|
|
|
|
var up_limit_k = p[RPC._UpSpeedLimit];
|
|
|
|
var dn_limit_k = p[RPC._DownSpeedLimit];
|
|
|
|
var turtle_up_limit_k = p[RPC._TurtleUpSpeedLimit];
|
|
|
|
var turtle_dn_limit_k = p[RPC._TurtleDownSpeedLimit];
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
if (p.units)
|
|
|
|
Transmission.fmt.updateUnits(p.units);
|
2011-08-24 12:49:10 +00:00
|
|
|
|
|
|
|
$('div.download_location input').val( p[RPC._DownloadDir]);
|
|
|
|
$('div.port input').val( p[RPC._PeerPort]);
|
|
|
|
$('div.auto_start input').prop('checked', p[RPC._StartAddedTorrent]);
|
|
|
|
$('input#limit_download').prop('checked', dn_limited);
|
|
|
|
$('input#download_rate').val( dn_limit_k);
|
|
|
|
$('input#limit_upload').prop('checked', up_limited);
|
|
|
|
$('input#upload_rate').val( up_limit_k);
|
|
|
|
$('input#refresh_rate').val( p[Prefs._RefreshRate]);
|
|
|
|
$('div.encryption input').val( p[RPC._Encryption] == RPC._EncryptionRequired);
|
|
|
|
$('input#turtle_download_rate').val( turtle_dn_limit_k);
|
|
|
|
$('input#turtle_upload_rate').val( turtle_up_limit_k);
|
|
|
|
$('input#turtle_schedule').prop('checked', p[RPC._TurtleTimeEnabled]);
|
|
|
|
$('select#turtle_start_time').val( p[RPC._TurtleTimeBegin]);
|
|
|
|
$('select#turtle_end_time').val( p[RPC._TurtleTimeEnd]);
|
|
|
|
$('select#turtle_days').val( p[RPC._TurtleTimeDay]);
|
|
|
|
$('#transmission_version').text( p[RPC._DaemonVersion]);
|
|
|
|
$('#conn_global').val( p[RPC._PeerLimitGlobal]);
|
|
|
|
$('#conn_torrent').val( p[RPC._PeerLimitPerTorrent]);
|
|
|
|
$('#conn_pex').prop('checked', p[RPC._PexEnabled]);
|
|
|
|
$('#conn_dht').prop('checked', p[RPC._DhtEnabled]);
|
|
|
|
$('#conn_lpd').prop('checked', p[RPC._LpdEnabled]);
|
|
|
|
$('#block_enable').prop('checked', p[RPC._BlocklistEnabled]);
|
|
|
|
$('#block_url').val( p[RPC._BlocklistURL]);
|
|
|
|
$('#block_size').text( p[RPC._BlocklistSize]+' IP rules in the list');
|
|
|
|
$('#network_utp').prop('checked', p[RPC._UtpEnabled]);
|
|
|
|
$('#port_rand').prop('checked', p[RPC._PeerPortRandom]);
|
|
|
|
$('#port_forward').prop('checked', p[RPC._PortForwardingEnabled]);
|
2011-03-10 01:37:58 +00:00
|
|
|
|
2011-08-28 17:24:56 +00:00
|
|
|
if (!isMobileDevice)
|
2010-09-03 00:03:21 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
setInnerHTML($('#limited_download_rate')[0], [ 'Limit (', Transmission.fmt.speed(dn_limit_k), ')' ].join(''));
|
2010-09-03 00:03:21 +00:00
|
|
|
var key = dn_limited ? '#limited_download_rate'
|
|
|
|
: '#unlimited_download_rate';
|
|
|
|
$(key).deselectMenuSiblings().selectMenuItem();
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
setInnerHTML($('#limited_upload_rate')[0], [ 'Limit (', Transmission.fmt.speed(up_limit_k), ')' ].join(''));
|
2010-09-03 00:03:21 +00:00
|
|
|
key = up_limited ? '#limited_upload_rate'
|
|
|
|
: '#unlimited_upload_rate';
|
|
|
|
$(key).deselectMenuSiblings().selectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2009-11-10 05:42:57 +00:00
|
|
|
|
2011-08-24 17:04:59 +00:00
|
|
|
this[Prefs._TurtleState] = p[RPC._TurtleState];
|
2010-09-03 00:03:21 +00:00
|
|
|
this.updateTurtleButton();
|
2011-08-24 17:04:59 +00:00
|
|
|
this.setCompactMode(p[Prefs._CompactDisplayState]);
|
2010-03-11 04:50:04 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
updatePortStatus: function(status) {
|
|
|
|
if (status['port-is-open'])
|
2011-03-10 01:37:58 +00:00
|
|
|
$('#port_test').text('Port is open');
|
|
|
|
else
|
|
|
|
$('#port_test').text('Port is closed');
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
showStatsDialog: function() {
|
2010-09-03 00:03:21 +00:00
|
|
|
this.loadDaemonStats();
|
|
|
|
$('body').addClass('stats_showing');
|
|
|
|
$('#stats_container').show();
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2011-08-24 02:04:35 +00:00
|
|
|
this.updateButtonStates();
|
2010-09-03 00:03:21 +00:00
|
|
|
this.togglePeriodicStatsRefresh(true);
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
hideStatsDialog: function() {
|
2010-09-03 00:03:21 +00:00
|
|
|
$('body.stats_showing').removeClass('stats_showing');
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice)
|
|
|
|
this.hideMobileAddressbar();
|
|
|
|
$('#stats_container').hide();
|
2011-08-24 02:04:35 +00:00
|
|
|
this.updateButtonStates();
|
2010-09-03 00:03:21 +00:00
|
|
|
this.togglePeriodicStatsRefresh(false);
|
2010-03-11 04:50:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process got some new session stats from the server
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
updateStats: function(stats)
|
2010-03-11 04:50:04 +00:00
|
|
|
{
|
2010-09-18 23:06:03 +00:00
|
|
|
var fmt = Transmission.fmt;
|
2010-03-11 04:50:04 +00:00
|
|
|
|
2011-08-26 18:36:09 +00:00
|
|
|
var s = stats["current-stats"];
|
|
|
|
$('#stats_session_uploaded').html(fmt.size(s.uploadedBytes));
|
|
|
|
$('#stats_session_downloaded').html(fmt.size(s.downloadedBytes));
|
|
|
|
$('#stats_session_ratio').html(fmt.ratioString(Math.ratio(s.uploadedBytes,s.downloadedBytes)));
|
|
|
|
$('#stats_session_duration').html(fmt.timeInterval(s.secondsActive));
|
|
|
|
|
|
|
|
var t = stats["cumulative-stats"];
|
|
|
|
$('#stats_total_count').html(t.sessionCount + " times");
|
|
|
|
$('#stats_total_uploaded').html(fmt.size(t.uploadedBytes));
|
|
|
|
$('#stats_total_downloaded').html(fmt.size(t.downloadedBytes));
|
|
|
|
$('#stats_total_ratio').html(fmt.ratioString(Math.ratio(t.uploadedBytes,t.downloadedBytes)));
|
|
|
|
$('#stats_total_duration').html(fmt.timeInterval(t.secondsActive));
|
2010-03-11 04:50:04 +00:00
|
|
|
},
|
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
setFilterText: function(search) {
|
|
|
|
this.filterText = search ? search.trim() : null;
|
|
|
|
this.refilter(true);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
setSortMethod: function(sort_method) {
|
|
|
|
this.setPref(Prefs._SortMethod, sort_method);
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
setSortDirection: function(direction) {
|
|
|
|
this.setPref(Prefs._SortDirection, direction);
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an event in the footer-menu
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
processSettingsMenuEvent: function(ev) {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2011-08-24 02:04:35 +00:00
|
|
|
var $element = $(ev.target);
|
2010-06-21 13:14:33 +00:00
|
|
|
|
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) {
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-16 18:49:26 +00:00
|
|
|
// Display the preferences dialog
|
2008-07-10 23:57:46 +00:00
|
|
|
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();
|
2011-08-24 02:04:35 +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();
|
2011-08-24 02:04:35 +00:00
|
|
|
tr.showStatsDialog();
|
2010-03-11 04:50:04 +00:00
|
|
|
}
|
2010-10-13 19:28:55 +00:00
|
|
|
else if ($element[0].id == 'homepage') {
|
|
|
|
window.open('http://www.transmissionbt.com/');
|
|
|
|
}
|
|
|
|
else if ($element[0].id == 'tipjar') {
|
|
|
|
window.open('http://www.transmissionbt.com/donate.php');
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Limit the download rate
|
|
|
|
case 'footer_download_rate_menu':
|
2010-09-03 00:03:21 +00:00
|
|
|
var args = { };
|
2009-05-23 02:28:04 +00:00
|
|
|
if ($element.is('#unlimited_download_rate')) {
|
|
|
|
$element.deselectMenuSiblings().selectMenuItem();
|
2010-09-03 00:03:21 +00:00
|
|
|
args[RPC._DownSpeedLimited] = false;
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
2011-08-24 02:04:35 +00:00
|
|
|
var rate_str = $element[0].innerHTML;
|
|
|
|
var rate_val = parseInt(rate_str, 10);
|
|
|
|
setInnerHTML($('#limited_download_rate')[0], [ 'Limit (', Transmission.fmt.speed(rate_val), ')' ].join(''));
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#limited_download_rate').deselectMenuSiblings().selectMenuItem();
|
2010-09-03 00:03:21 +00:00
|
|
|
$('div.preference input#download_rate')[0].value = rate_str;
|
|
|
|
args[RPC._DownSpeedLimit] = rate_val;
|
|
|
|
args[RPC._DownSpeedLimited] = true;
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2010-09-03 00:03:21 +00:00
|
|
|
$('div.preference input#limit_download')[0].checked = args[RPC._DownSpeedLimited];
|
2011-08-24 02:04:35 +00:00
|
|
|
tr.remote.savePrefs(args);
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Limit the upload rate
|
|
|
|
case 'footer_upload_rate_menu':
|
|
|
|
var args = { };
|
2009-05-23 02:28:04 +00:00
|
|
|
if ($element.is('#unlimited_upload_rate')) {
|
|
|
|
$element.deselectMenuSiblings().selectMenuItem();
|
2010-09-03 00:03:21 +00:00
|
|
|
args[RPC._UpSpeedLimited] = false;
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
2011-08-24 02:04:35 +00:00
|
|
|
var rate_str = $element[0].innerHTML;
|
|
|
|
var rate_val = parseInt(rate_str, 10);
|
|
|
|
setInnerHTML($('#limited_upload_rate')[0], [ 'Limit (', Transmission.fmt.speed(rate_val), ')' ].join(''));
|
2008-07-10 23:57:46 +00:00
|
|
|
$('#limited_upload_rate').deselectMenuSiblings().selectMenuItem();
|
2010-09-03 00:03:21 +00:00
|
|
|
$('div.preference input#upload_rate')[0].value = rate_str;
|
|
|
|
args[RPC._UpSpeedLimit] = rate_val;
|
|
|
|
args[RPC._UpSpeedLimited] = true;
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2010-09-03 00:03:21 +00:00
|
|
|
$('div.preference input#limit_upload')[0].checked = args[RPC._UpSpeedLimited];
|
2011-08-24 02:04:35 +00:00
|
|
|
tr.remote.savePrefs(args);
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
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')) {
|
2011-08-24 02:04:35 +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;
|
|
|
|
}
|
2011-08-24 02:04:35 +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 {
|
2011-08-24 02:04:35 +00:00
|
|
|
$element.parent().find('span.selected').each(function() {
|
2009-05-23 02:28:04 +00:00
|
|
|
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_/, '');
|
2011-08-24 02:04:35 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
onTorrentChanged: function(tor)
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
2011-08-27 21:35:19 +00:00
|
|
|
var id = tor.getId();
|
|
|
|
|
|
|
|
// update our dirty fields
|
|
|
|
this.dirtyTorrents[id] = true;
|
|
|
|
|
2011-08-28 15:16:54 +00:00
|
|
|
// enqueue ui refreshes
|
2011-08-26 01:46:07 +00:00
|
|
|
this.refilterSoon();
|
2011-08-28 15:16:54 +00:00
|
|
|
this.updateButtonsSoon();
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
updateFromTorrentGet: function(updates, removed_ids)
|
|
|
|
{
|
2011-08-26 23:34:43 +00:00
|
|
|
var needinfo = [];
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
for (var i=0, o; o=updates[i]; ++i) {
|
|
|
|
var t;
|
|
|
|
var id = o.id;
|
|
|
|
if ((t = this._torrents[id]))
|
|
|
|
t.refresh(o);
|
|
|
|
else {
|
2011-08-26 22:49:57 +00:00
|
|
|
var tr = this;
|
|
|
|
t = tr._torrents[id] = new Torrent(o);
|
2011-08-27 21:35:19 +00:00
|
|
|
this.dirtyTorrents[id] = true;
|
|
|
|
$(t).bind('dataChanged',function(ev,tor) {tr.onTorrentChanged(tor);});
|
2011-08-26 23:34:43 +00:00
|
|
|
if(!('name' in t.fields) || !('status' in t.fields)) // missing some fields...
|
|
|
|
needinfo.push(id);
|
2011-08-26 01:46:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-26 23:34:43 +00:00
|
|
|
if (needinfo.length) {
|
2011-08-26 22:49:57 +00:00
|
|
|
// whee, new torrents! get their initial information.
|
|
|
|
var fields = ['id'].concat(Torrent.Fields.Metadata, Torrent.Fields.Stats);
|
2011-08-26 23:34:43 +00:00
|
|
|
this.remote.updateTorrents(needinfo, fields, this.updateFromTorrentGet, this);
|
2011-08-26 01:46:07 +00:00
|
|
|
this.refilterSoon();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
if (removed_ids) {
|
|
|
|
this.deleteTorrents(removed_ids);
|
|
|
|
this.refilterSoon();
|
|
|
|
}
|
|
|
|
},
|
2008-08-29 17:57:53 +00:00
|
|
|
|
2011-08-26 19:42:07 +00:00
|
|
|
refreshTorrents: function()
|
|
|
|
{
|
|
|
|
// send a request right now
|
2011-08-30 21:55:44 +00:00
|
|
|
this.remote.updateTorrents('recently-active',
|
|
|
|
['id'].concat(Torrent.Fields.Stats),
|
|
|
|
this.updateFromTorrentGet,
|
|
|
|
this);
|
2011-08-26 19:42:07 +00:00
|
|
|
|
|
|
|
// schedule the next request
|
|
|
|
clearTimeout(this.refreshTorrentsTimeout);
|
2011-08-30 21:55:44 +00:00
|
|
|
this.refreshTorrentsTimeout = setTimeout($.proxy(this.refreshTorrents,this), this[Prefs._RefreshRate]*1000);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2011-08-26 22:49:57 +00:00
|
|
|
|
|
|
|
initializeTorrents: function()
|
|
|
|
{
|
|
|
|
// to bootstrap, we only need to ask for the servers's torrents' ids.
|
|
|
|
// updateFromTorrentGet() automatically asks for the rest of the info when it gets a new id.
|
2011-08-26 23:34:43 +00:00
|
|
|
var fields = ['id'].concat(Torrent.Fields.Metadata, Torrent.Fields.Stats);
|
|
|
|
this.remote.updateTorrents(null, fields, this.updateFromTorrentGet, this);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2011-08-26 22:49:57 +00:00
|
|
|
|
2011-08-30 02:49:01 +00:00
|
|
|
needsExtraInfo: function(ids)
|
|
|
|
{
|
|
|
|
var i, id, tor;
|
|
|
|
|
|
|
|
for (i=0; id=ids[i]; ++i)
|
|
|
|
if ((tor = this._torrents[id]))
|
|
|
|
if (!tor.hasExtraInfo())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-08-30 02:57:00 +00:00
|
|
|
refreshInspectorTorrents: function(full)
|
2011-08-26 22:49:57 +00:00
|
|
|
{
|
|
|
|
// some torrent fields are only used by the inspector, so we defer loading them
|
|
|
|
// until the user is viewing the torrent in the inspector.
|
2011-08-30 04:54:37 +00:00
|
|
|
if (this.inspectorIsVisible()) {
|
2011-08-26 22:49:57 +00:00
|
|
|
var ids = this.getSelectedTorrentIds();
|
|
|
|
if (ids && ids.length) {
|
|
|
|
var fields = ['id'].concat(Torrent.Fields.StatsExtra);
|
2011-08-30 02:49:01 +00:00
|
|
|
if (this.needsExtraInfo(ids))
|
2011-08-27 00:22:56 +00:00
|
|
|
fields = fields.concat(Torrent.Fields.InfoExtra);
|
2011-08-26 22:49:57 +00:00
|
|
|
this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2009-06-26 03:03:17 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
onRowClicked: function(ev, row)
|
|
|
|
{
|
|
|
|
// Prevents click carrying to parent element
|
|
|
|
// which deselects all on click
|
|
|
|
ev.stopPropagation();
|
|
|
|
// but still hide the context menu if it is showing
|
|
|
|
$('#jqContextMenu').hide();
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// 'Apple' button emulation on PC :
|
|
|
|
// Need settable meta-key and ctrl-key variables for mac emulation
|
|
|
|
var meta_key = ev.metaKey;
|
|
|
|
if (ev.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") == -1)
|
|
|
|
meta_key = true;
|
2011-08-20 21:17:12 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// Shift-Click - selects a range from the last-clicked row to this one
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) {
|
2011-08-26 01:46:07 +00:00
|
|
|
if (row.isSelected())
|
|
|
|
this.setInspectorVisible(true);
|
|
|
|
this.setSelectedRow(row);
|
2010-10-12 17:38:03 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
this.selectRange(row);
|
|
|
|
// Need to deselect any selected text
|
|
|
|
window.focus();
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// Apple-Click, not selected
|
|
|
|
} else if (!row.isSelected() && meta_key) {
|
|
|
|
this.selectRow(row);
|
2011-08-24 02:04:35 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// Regular Click, not selected
|
|
|
|
} else if (!row.isSelected()) {
|
|
|
|
this.setSelectedRow(row);
|
2010-06-17 04:40:06 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// Apple-Click, selected
|
|
|
|
} else if (row.isSelected() && meta_key) {
|
|
|
|
this.deselectRow(row);
|
2009-05-23 20:39:55 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// Regular Click, selected
|
|
|
|
} else if (row.isSelected()) {
|
|
|
|
this.setSelectedRow(row);
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-08-26 01:46:07 +00:00
|
|
|
|
|
|
|
this._last_torrent_clicked = row.getTorrentId();
|
2009-05-23 20:39:55 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
|
2011-08-26 19:42:07 +00:00
|
|
|
deleteTorrents: function(ids)
|
2011-08-25 23:06:41 +00:00
|
|
|
{
|
2011-08-26 19:42:07 +00:00
|
|
|
if (ids && ids.length)
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
2011-08-30 04:27:09 +00:00
|
|
|
for (var i=0, id; id=ids[i]; ++i) {
|
|
|
|
this.dirtyTorrents[id] = true;
|
2011-08-26 01:46:07 +00:00
|
|
|
delete this._torrents[id];
|
2011-08-30 04:27:09 +00:00
|
|
|
}
|
2011-08-26 01:46:07 +00:00
|
|
|
this.refilter();
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
updateStatusbar: function()
|
|
|
|
{
|
|
|
|
this.refreshFilterButton();
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// up/down speed
|
|
|
|
var u=0, d=0;
|
|
|
|
var torrents = this.getAllTorrents();
|
|
|
|
for (var i=0, row; row=torrents[i]; ++i) {
|
|
|
|
u += row.getUploadSpeed();
|
|
|
|
d += row.getDownloadSpeed();
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-08-26 20:02:40 +00:00
|
|
|
|
|
|
|
var fmt = Transmission.fmt;
|
|
|
|
setInnerHTML($('#statusbar #speed-up-label')[0], u ? '↑ ' + fmt.speedBps(u) : '');
|
|
|
|
setInnerHTML($('#statusbar #speed-dn-label')[0], d ? '↓ ' + fmt.speedBps(d) : '');
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
/*
|
|
|
|
* Select a torrent file to upload
|
|
|
|
* FIXME
|
|
|
|
*/
|
|
|
|
uploadTorrentFile: function(confirmed)
|
2011-08-25 23:06:41 +00:00
|
|
|
{
|
2011-08-26 01:46:07 +00:00
|
|
|
// Display the upload dialog
|
|
|
|
if (! confirmed) {
|
2011-08-28 13:57:25 +00:00
|
|
|
$('input#torrent_upload_file').attr('value', '');
|
|
|
|
$('input#torrent_upload_url').attr('value', '');
|
|
|
|
$('input#torrent_auto_start').attr('checked', $('#prefs_form #auto_start')[0].checked);
|
|
|
|
$('#upload_container').show();
|
|
|
|
$('#torrent_upload_url').focus();
|
2011-08-26 01:46:07 +00:00
|
|
|
|
|
|
|
// Submit the upload form
|
|
|
|
} else {
|
|
|
|
var args = { };
|
2011-08-30 21:55:44 +00:00
|
|
|
var remote = this.remote;
|
2011-08-26 01:46:07 +00:00
|
|
|
var paused = !$('#torrent_auto_start').is(':checked');
|
|
|
|
if ('' != $('#torrent_upload_url').val()) {
|
2011-08-30 21:55:44 +00:00
|
|
|
remote.addTorrentByUrl($('#torrent_upload_url').val(), { paused: paused });
|
2011-08-26 01:46:07 +00:00
|
|
|
} else {
|
|
|
|
args.url = '../upload?paused=' + paused;
|
|
|
|
args.type = 'POST';
|
2011-08-30 21:55:44 +00:00
|
|
|
args.data = { 'X-Transmission-Session-Id' : remote._token };
|
2011-08-26 01:46:07 +00:00
|
|
|
args.dataType = 'xml';
|
|
|
|
args.iframe = true;
|
|
|
|
$('#torrent_upload_form').ajaxSubmit(args);
|
2011-08-25 23:06:41 +00:00
|
|
|
}
|
2010-06-17 04:40:06 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
removeSelectedTorrents: function() {
|
|
|
|
var torrents = this.getSelectedTorrents();
|
|
|
|
if (torrents.length)
|
|
|
|
this.promptToRemoveTorrents(torrents);
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
removeSelectedTorrentsAndData: function() {
|
2011-08-24 02:04:35 +00:00
|
|
|
var torrents = this.getSelectedTorrents();
|
2011-08-26 01:46:07 +00:00
|
|
|
if (torrents.length)
|
|
|
|
this.promptToRemoveTorrentsAndData(torrents);
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
promptToRemoveTorrents:function(torrents)
|
|
|
|
{
|
|
|
|
if (torrents.length == 1)
|
2011-08-25 23:06:41 +00:00
|
|
|
{
|
2011-08-26 01:46:07 +00:00
|
|
|
var torrent = torrents[0];
|
|
|
|
var header = 'Remove ' + torrent.getName() + '?';
|
|
|
|
var message = 'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?';
|
|
|
|
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrents', torrents);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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?';
|
|
|
|
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrents', torrents);
|
|
|
|
}
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
promptToRemoveTorrentsAndData:function(torrents)
|
|
|
|
{
|
|
|
|
if (torrents.length == 1)
|
|
|
|
{
|
|
|
|
var torrent = torrents[0],
|
|
|
|
header = 'Remove ' + torrent.getName() + ' 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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
removeTorrents: function(torrents) {
|
2011-08-26 19:42:07 +00:00
|
|
|
var ids = $.map(torrents, function(t) { return t.getId(); });
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.removeTorrents(ids, this.refreshTorrents, this);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
removeTorrentsAndData: function(torrents) {
|
|
|
|
this.remote.removeTorrentsAndData(torrents);
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
verifySelectedTorrents: function() {
|
|
|
|
this.verifyTorrents(this.getSelectedTorrents());
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
reannounceSelectedTorrents: function() {
|
|
|
|
this.reannounceTorrents(this.getSelectedTorrents());
|
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
startSelectedTorrents: function(force) {
|
|
|
|
this.startTorrents(this.getSelectedTorrents(), force);
|
|
|
|
},
|
|
|
|
startAllTorrents: function() {
|
|
|
|
this.startTorrents(this.getAllTorrents(), false);
|
|
|
|
},
|
|
|
|
startTorrent: function(torrent) {
|
|
|
|
this.startTorrents([ torrent ], false);
|
|
|
|
},
|
|
|
|
startTorrents: function(torrents, force) {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.startTorrents($.map(torrents, function(t) {return t.getId();}),
|
|
|
|
force, this.refreshTorrents, this);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
|
|
|
verifyTorrent: function(torrent) {
|
|
|
|
this.verifyTorrents([ torrent ]);
|
|
|
|
},
|
|
|
|
verifyTorrents: function(torrents) {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.verifyTorrents($.map(torrents, function(t) {return t.getId();}),
|
|
|
|
this.refreshTorrents, this);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2011-08-25 23:06:41 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
reannounceTorrent: function(torrent) {
|
|
|
|
this.reannounceTorrents([ torrent ]);
|
|
|
|
},
|
|
|
|
reannounceTorrents: function(torrents) {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.reannounceTorrents($.map(torrents, function(t) {return t.getId();}),
|
|
|
|
this.refreshTorrents, this);
|
2010-01-31 02:42:48 +00:00
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
stopSelectedTorrents: function() {
|
|
|
|
this.stopTorrents(this.getSelectedTorrents());
|
2010-02-01 01:08:17 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
stopAllTorrents: function() {
|
|
|
|
this.stopTorrents(this.getAllTorrents());
|
2010-02-01 01:08:17 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
stopTorrent: function(torrent) {
|
|
|
|
this.stopTorrents([ torrent ]);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
stopTorrents: function(torrents) {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.stopTorrents($.map(torrents.slice(0), function(t) {return t.getId();}),
|
|
|
|
this.refreshTorrents, this);
|
2010-02-06 16:43:48 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
changeFileCommand: function(command, rows) {
|
|
|
|
this.remote.changeFileCommand(command, rows);
|
2010-02-06 16:43:48 +00:00
|
|
|
},
|
|
|
|
|
2011-08-28 17:24:56 +00:00
|
|
|
hideMobileAddressbar: function(timeInSeconds) {
|
2011-08-30 21:55:44 +00:00
|
|
|
if (isMobileDevice && !scroll_timeout) {
|
2011-08-26 01:46:07 +00:00
|
|
|
var delayLength = timeInSeconds ? timeInSeconds*1000 : 150;
|
2011-08-30 21:55:44 +00:00
|
|
|
scroll_timeout = setTimeout($.proxy(this.doToolbarHide,this), delayLength);
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
|
|
|
doToolbarHide: function() {
|
|
|
|
window.scrollTo(0,1);
|
|
|
|
scroll_timeout=null;
|
2009-05-22 22:45:09 +00:00
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// Queue
|
|
|
|
moveTop: function() {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.moveTorrentsToTop(this.getSelectedTorrentIds(),
|
|
|
|
this.refreshTorrents, this);
|
2011-08-25 23:06:41 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
moveUp: function() {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.moveTorrentsUp(this.getSelectedTorrentIds(),
|
|
|
|
this.refreshTorrents, this);
|
2011-08-25 23:06:41 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
moveDown: function() {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.moveTorrentsDown(this.getSelectedTorrentIds(),
|
|
|
|
this.refreshTorrents, this);
|
2011-08-25 23:06:41 +00:00
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
moveBottom: function() {
|
2011-08-28 06:05:46 +00:00
|
|
|
this.remote.moveTorrentsToBottom(this.getSelectedTorrentIds(),
|
|
|
|
this.refreshTorrents, this);
|
2009-05-22 22:45:09 +00:00
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2011-08-25 09:21:05 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
onToggleRunningClicked: function(ev)
|
|
|
|
{
|
|
|
|
var torrent = ev.data.r.getTorrent();
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
if (torrent.isStopped())
|
|
|
|
this.startTorrent(torrent);
|
|
|
|
else
|
|
|
|
this.stopTorrent(torrent);
|
2011-08-25 09:21:05 +00:00
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
setEnabled: function(key, flag)
|
2011-08-24 02:04:35 +00:00
|
|
|
{
|
2011-08-26 01:46:07 +00:00
|
|
|
$(key).toggleClass('disabled', !flag);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-28 15:16:54 +00:00
|
|
|
updateButtonsSoon: function()
|
|
|
|
{
|
|
|
|
if (!this.buttonRefreshTimer)
|
2011-08-30 21:55:44 +00:00
|
|
|
this.buttonRefreshTimer = setTimeout($.proxy(this.updateButtonStates,this), 100);
|
2011-08-28 15:16:54 +00:00
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
updateButtonStates: function()
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-28 15:16:54 +00:00
|
|
|
clearTimeout(this.buttonRefreshTimer);
|
|
|
|
delete this.buttonRefreshTimer;
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
var showing_dialog = new RegExp("(prefs_showing|dialog_showing|open_showing)").test(document.body.className);
|
|
|
|
this._toolbar_buttons.toggleClass('disabled', showing_dialog);
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
if (!showing_dialog)
|
|
|
|
{
|
2011-08-28 06:20:32 +00:00
|
|
|
var haveSelection = false,
|
|
|
|
haveActive = false,
|
|
|
|
haveActiveSelection = false,
|
|
|
|
havePaused = false,
|
|
|
|
havePausedSelection = false;
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
for (var i=0, row; row=this._rows[i]; ++i) {
|
|
|
|
var isStopped = row.getTorrent().isStopped();
|
|
|
|
var isSelected = row.isSelected();
|
|
|
|
if (!isStopped) haveActive = true;
|
|
|
|
if (isStopped) havePaused = true;
|
|
|
|
if (isSelected) haveSelection = true;
|
|
|
|
if (isSelected && !isStopped) haveActiveSelection = true;
|
|
|
|
if (isSelected && isStopped) havePausedSelection = true;
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-08-24 02:04:35 +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._context_move_top_button, haveSelection);
|
|
|
|
this.setEnabled(this._context_move_up_button, haveSelection);
|
|
|
|
this.setEnabled(this._context_move_down_button, haveSelection);
|
|
|
|
this.setEnabled(this._context_move_bottom_button, haveSelection);
|
|
|
|
this.setEnabled(this._context_start_now_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);
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** INSPECTOR
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2011-08-30 04:54:37 +00:00
|
|
|
inspectorIsVisible: function() {
|
|
|
|
return $('#torrent_inspector').is(':visible');
|
|
|
|
},
|
|
|
|
|
2011-08-26 18:36:09 +00:00
|
|
|
filesSelectAllClicked: function() {
|
|
|
|
var t = this._file_torrent;
|
|
|
|
if (t)
|
|
|
|
this.toggleFilesWantedDisplay(t, true);
|
|
|
|
},
|
|
|
|
filesDeselectAllClicked: function() {
|
|
|
|
var t = this._file_torrent;
|
|
|
|
if (t)
|
|
|
|
this.toggleFilesWantedDisplay(t, false);
|
|
|
|
},
|
|
|
|
toggleFilesWantedDisplay: function(torrent, wanted) {
|
|
|
|
var rows = [ ];
|
|
|
|
for (var i=0, row; row=this._file_rows[i]; ++i)
|
|
|
|
if (row.isEditable() && (torrent.getFile(i).wanted !== wanted))
|
|
|
|
rows.push(row);
|
|
|
|
if (rows.length > 0) {
|
|
|
|
var command = wanted ? 'files-wanted' : 'files-unwanted';
|
|
|
|
this.changeFileCommand(command, rows);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
inspectorTabClicked: function(ev, tab)
|
|
|
|
{
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) ev.stopPropagation();
|
2011-08-26 01:46:07 +00:00
|
|
|
|
|
|
|
// select this tab and deselect the others
|
|
|
|
$(tab).addClass('selected').siblings().removeClass('selected');
|
|
|
|
|
|
|
|
// show this tab and hide the others
|
|
|
|
$('#'+tab.id+'_container').show().siblings('.inspector_container').hide();
|
|
|
|
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2011-08-26 01:46:07 +00:00
|
|
|
this.updatePeersLists();
|
|
|
|
this.updateTrackersLists();
|
|
|
|
this.updateFileList();
|
|
|
|
},
|
|
|
|
/*
|
|
|
|
* Update the inspector with the latest data for the selected torrents
|
|
|
|
*/
|
|
|
|
updateInspector: function()
|
|
|
|
{
|
2011-08-30 04:54:37 +00:00
|
|
|
if (!this.inspectorIsVisible())
|
2011-08-26 01:46:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
var torrents = this.getSelectedTorrents();
|
2011-08-28 17:24:56 +00:00
|
|
|
if (!torrents.length && isMobileDevice) {
|
2011-08-26 01:46:07 +00:00
|
|
|
this.setInspectorVisible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-28 06:20:32 +00:00
|
|
|
var creator = 'N/A',
|
|
|
|
comment = 'N/A',
|
|
|
|
download_dir = 'N/A',
|
|
|
|
date_created = 'N/A',
|
|
|
|
error = 'None',
|
|
|
|
hash = 'N/A',
|
|
|
|
have_public = false,
|
|
|
|
have_private = false,
|
|
|
|
name,
|
|
|
|
sizeWhenDone = 0,
|
|
|
|
sizeDone = 0,
|
|
|
|
total_completed = 0,
|
|
|
|
total_download = 0,
|
|
|
|
total_download_peers = 0,
|
|
|
|
total_download_speed = 0,
|
|
|
|
total_availability = 0,
|
|
|
|
total_size = 0,
|
|
|
|
total_state = [ ],
|
|
|
|
pieces = 'N/A',
|
|
|
|
total_upload = 0,
|
|
|
|
total_upload_peers = 0,
|
|
|
|
total_upload_speed = 0,
|
|
|
|
total_verified = 0,
|
|
|
|
na = 'N/A',
|
|
|
|
tab = this._inspector._info_tab,
|
|
|
|
fmt = Transmission.fmt;
|
2011-08-26 01:46:07 +00:00
|
|
|
|
|
|
|
$("#torrent_inspector_size, .inspector_row div").css('color', '#222');
|
|
|
|
|
|
|
|
if (torrents.length == 0)
|
|
|
|
{
|
|
|
|
setInnerHTML(tab.name, 'No Selection');
|
|
|
|
setInnerHTML(tab.size, na);
|
|
|
|
setInnerHTML(tab.pieces, na);
|
|
|
|
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);
|
|
|
|
setInnerHTML(tab.availability, na);
|
|
|
|
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);
|
|
|
|
setInnerHTML(tab.download_dir, na);
|
|
|
|
setInnerHTML(tab.error, na);
|
|
|
|
this.updateFileList();
|
|
|
|
this.updatePeersLists();
|
|
|
|
this.updateTrackersLists();
|
|
|
|
$("#torrent_inspector_size, .inspector_row > div:contains('N/A')").css('color', '#666');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = torrents.length == 1
|
|
|
|
? torrents[0].getName()
|
|
|
|
: torrents.length+' Transfers Selected';
|
|
|
|
|
|
|
|
if (torrents.length == 1)
|
|
|
|
{
|
|
|
|
var text;
|
|
|
|
var t = torrents[0];
|
|
|
|
var err = t.getErrorMessage();
|
|
|
|
if (err)
|
|
|
|
error = err;
|
|
|
|
if ((text = t.getComment()))
|
|
|
|
comment = text;
|
|
|
|
if ((text = t.getCreator()))
|
|
|
|
creator = text;
|
|
|
|
if ((text = t.getDownloadDir()))
|
|
|
|
download_dir = text;
|
|
|
|
|
|
|
|
hash = t.getHashString();
|
2011-08-26 18:36:09 +00:00
|
|
|
pieces = [ t.getPieceCount(), 'pieces @', fmt.mem(t.getPieceSize()) ].join(' ');
|
|
|
|
date_created = fmt.timestamp(t.getDateCreated());
|
2011-08-26 01:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0, t; t=torrents[i]; ++i) {
|
|
|
|
var l = t.getLeftUntilDone();
|
|
|
|
var d = t.getSizeWhenDone();
|
|
|
|
sizeWhenDone += d;
|
|
|
|
sizeDone += d - l;
|
|
|
|
total_completed += t.getHave();
|
|
|
|
total_verified += t.getHaveValid();
|
|
|
|
total_size += t.getTotalSize();
|
|
|
|
total_upload += t.getUploadedEver();
|
|
|
|
total_download += t.getDownloadedEver();
|
|
|
|
total_upload_speed += t.getUploadSpeed();
|
|
|
|
total_download_speed += t.getDownloadSpeed();
|
|
|
|
total_upload_peers += t.getPeersGettingFromUs();
|
|
|
|
total_download_peers += t.getPeersSendingToUs();
|
|
|
|
total_availability += sizeWhenDone - l + t.getDesiredAvailable();
|
|
|
|
|
|
|
|
var s = t.getStateString();
|
|
|
|
if (total_state.indexOf(s) == -1)
|
|
|
|
total_state.push(s);
|
|
|
|
|
|
|
|
if (t.getPrivateFlag())
|
|
|
|
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';
|
|
|
|
else if (have_public) private_string = 'Public Torrent';
|
|
|
|
|
|
|
|
setInnerHTML(tab.name, name);
|
|
|
|
setInnerHTML(tab.size, torrents.length ? fmt.size(total_size) : na);
|
|
|
|
setInnerHTML(tab.pieces, pieces);
|
|
|
|
setInnerHTML(tab.hash, hash);
|
|
|
|
setInnerHTML(tab.state, total_state.join('/'));
|
|
|
|
setInnerHTML(tab.download_speed, torrents.length ? fmt.speedBps(total_download_speed) : na);
|
|
|
|
setInnerHTML(tab.upload_speed, torrents.length ? fmt.speedBps(total_upload_speed) : na);
|
|
|
|
setInnerHTML(tab.uploaded, torrents.length ? fmt.size(total_upload) : na);
|
|
|
|
setInnerHTML(tab.downloaded, torrents.length ? fmt.size(total_download) : na);
|
|
|
|
setInnerHTML(tab.availability, torrents.length ? fmt.percentString(Math.ratio(total_availability*100, sizeWhenDone)) + '%' : na);
|
|
|
|
setInnerHTML(tab.ratio, torrents.length ? fmt.ratioString(Math.ratio(total_upload, total_download)) : na);
|
|
|
|
setInnerHTML(tab.have, torrents.length ? fmt.size(total_completed) + ' (' + fmt.size(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 ? fmt.percentString(Math.ratio(sizeDone*100, sizeWhenDone)) + '%' : na);
|
|
|
|
setInnerHTML(tab.comment, comment);
|
|
|
|
setInnerHTML(tab.creator, creator);
|
|
|
|
setInnerHTML(tab.download_dir, download_dir);
|
|
|
|
setInnerHTML(tab.error, error);
|
|
|
|
|
|
|
|
this.updatePeersLists();
|
|
|
|
this.updateTrackersLists();
|
|
|
|
$(".inspector_row > div:contains('N/A')").css('color', '#666');
|
|
|
|
this.updateFileList();
|
|
|
|
},
|
|
|
|
|
|
|
|
onFileWantedToggled: function(row, want) {
|
|
|
|
var command = want ? 'files-wanted' : 'files-unwanted';
|
|
|
|
this.changeFileCommand(command, [ row ]);
|
|
|
|
},
|
|
|
|
onFilePriorityToggled: function(row, priority) {
|
|
|
|
var command;
|
|
|
|
switch(priority) {
|
|
|
|
case -1: command = 'priority-low'; break;
|
|
|
|
case 1: command = 'priority-high'; break;
|
|
|
|
default: command = 'priority-normal'; break;
|
|
|
|
}
|
|
|
|
this.changeFileCommand(command, [ row ]);
|
|
|
|
},
|
|
|
|
clearFileList: function()
|
|
|
|
{
|
|
|
|
$(this._inspector_file_list).empty();
|
|
|
|
delete this._file_torrent;
|
|
|
|
delete this._file_rows;
|
|
|
|
},
|
|
|
|
updateFileList: function()
|
|
|
|
{
|
2011-08-29 21:12:05 +00:00
|
|
|
var i, n, tr, sel, row, torrent, fragment;
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
if (!$(this._inspector_file_list).is(':visible'))
|
|
|
|
return;
|
|
|
|
|
2011-08-29 21:12:05 +00:00
|
|
|
sel = this.getSelectedTorrents();
|
2011-08-26 01:46:07 +00:00
|
|
|
if (sel.length !== 1) {
|
|
|
|
this.clearFileList();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// build the file list
|
2011-08-29 21:12:05 +00:00
|
|
|
torrent = sel[0];
|
2011-08-26 01:46:07 +00:00
|
|
|
this.clearFileList();
|
|
|
|
this._file_torrent = torrent;
|
2011-08-29 21:12:05 +00:00
|
|
|
n = torrent.getFileCount();
|
2011-08-26 01:46:07 +00:00
|
|
|
this._file_rows = [];
|
2011-08-29 21:12:05 +00:00
|
|
|
fragment = document.createDocumentFragment();
|
|
|
|
tr = this;
|
|
|
|
for (i=0; i<n; ++i) {
|
|
|
|
row = this._file_rows[i] = new FileRow(torrent, i);
|
2011-08-26 01:46:07 +00:00
|
|
|
fragment.appendChild(row.getElement());
|
|
|
|
$(row).bind('wantedToggled',function(e,row,want) {tr.onFileWantedToggled(row,want);});
|
|
|
|
$(row).bind('priorityToggled',function(e,row,priority) {tr.onFilePriorityToggled(row,priority);});
|
|
|
|
}
|
|
|
|
this._inspector_file_list.appendChild(fragment);
|
|
|
|
},
|
|
|
|
|
|
|
|
updatePeersLists: function()
|
|
|
|
{
|
|
|
|
if (!$(this._inspector_peers_list).is(':visible'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var html = [ ];
|
|
|
|
var fmt = Transmission.fmt;
|
|
|
|
var torrents = this.getSelectedTorrents();
|
|
|
|
|
|
|
|
for (var k=0, torrent; torrent=torrents[k]; ++k) {
|
|
|
|
var peers = torrent.getPeers();
|
|
|
|
html.push('<div class="inspector_group">');
|
|
|
|
if (torrents.length > 1) {
|
|
|
|
html.push('<div class="inspector_torrent_label">', torrent.getName(), '</div>');
|
|
|
|
}
|
|
|
|
if (!peers || !peers.length) {
|
|
|
|
html.push('<br></div>'); // firefox won't paint the top border if the div is empty
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
html.push('<table class="peer_list">',
|
|
|
|
'<tr class="inspector_peer_entry even">',
|
|
|
|
'<th class="encryptedCol"></th>',
|
|
|
|
'<th class="upCol">Up</th>',
|
|
|
|
'<th class="downCol">Down</th>',
|
|
|
|
'<th class="percentCol">%</th>',
|
|
|
|
'<th class="statusCol">Status</th>',
|
|
|
|
'<th class="addressCol">Address</th>',
|
|
|
|
'<th class="clientCol">Client</th>',
|
|
|
|
'</tr>');
|
|
|
|
for (var i=0, peer; peer=peers[i]; ++i) {
|
|
|
|
var parity = ((i+1) % 2 == 0 ? 'even' : 'odd');
|
|
|
|
html.push('<tr class="inspector_peer_entry ', parity, '">',
|
|
|
|
'<td>', (peer.isEncrypted ? '<img src="images/graphics/lock_icon.png" alt="Encrypted"/>' : ''), '</td>',
|
|
|
|
'<td>', (peer.rateToPeer ? fmt.speedBps(peer.rateToPeer) : ''), '</td>',
|
|
|
|
'<td>', (peer.rateToClient ? fmt.speedBps(peer.rateToClient) : ''), '</td>',
|
|
|
|
'<td class="percentCol">', Math.floor(peer.progress*100), '%', '</td>',
|
|
|
|
'<td>', fmt.peerStatus(peer.flagStr), '</td>',
|
|
|
|
'<td>', peer.address, '</td>',
|
|
|
|
'<td class="clientCol">', peer.clientName, '</td>',
|
|
|
|
'</tr>');
|
|
|
|
}
|
|
|
|
html.push('</table></div>');
|
|
|
|
}
|
|
|
|
|
|
|
|
setInnerHTML(this._inspector_peers_list, html.join(''));
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTrackersLists: function() {
|
|
|
|
if (!$(this._inspector_trackers_list).is(':visible'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var html = [ ];
|
|
|
|
var na = 'N/A';
|
|
|
|
var torrents = this.getSelectedTorrents();
|
|
|
|
|
|
|
|
// By building up the HTML as as string, then have the browser
|
|
|
|
// turn this into a DOM tree, this is a fast operation.
|
|
|
|
for (var i=0, torrent; torrent=torrents[i]; ++i)
|
|
|
|
{
|
|
|
|
html.push ('<div class="inspector_group">');
|
|
|
|
|
|
|
|
if (torrents.length > 1)
|
|
|
|
html.push('<div class="inspector_torrent_label">', torrent.getName(), '</div>');
|
|
|
|
|
|
|
|
var tier = -1;
|
|
|
|
var trackers = torrent.getTrackers();
|
|
|
|
for (var j=0, tracker; tracker=trackers[j]; ++j)
|
|
|
|
{
|
|
|
|
if (tier != tracker.tier)
|
|
|
|
{
|
|
|
|
if (tier !== -1) // close previous tier
|
|
|
|
html.push('</ul></div>');
|
|
|
|
|
|
|
|
tier = tracker.tier;
|
|
|
|
|
|
|
|
html.push('<div class="inspector_group_label">',
|
|
|
|
'Tier ', tier, '</div>',
|
|
|
|
'<ul class="tier_list">');
|
|
|
|
}
|
|
|
|
|
2011-08-28 06:05:46 +00:00
|
|
|
var lastAnnounceStatusHash = this.lastAnnounceStatus(tracker);
|
|
|
|
var announceState = this.announceState(tracker);
|
|
|
|
var lastScrapeStatusHash = this.lastScrapeStatus(tracker);
|
2011-08-26 01:46:07 +00:00
|
|
|
|
|
|
|
// Display construction
|
|
|
|
var parity = ((j+1) % 2 == 0 ? 'even' : 'odd');
|
|
|
|
html.push('<li class="inspector_tracker_entry ', parity, '"><div class="tracker_host" title="', tracker.announce, '">',
|
|
|
|
tracker.host, '</div>',
|
|
|
|
'<div class="tracker_activity">',
|
|
|
|
'<div>', lastAnnounceStatusHash['label'], ': ', lastAnnounceStatusHash['value'], '</div>',
|
|
|
|
'<div>', announceState, '</div>',
|
|
|
|
'<div>', lastScrapeStatusHash['label'], ': ', lastScrapeStatusHash['value'], '</div>',
|
|
|
|
'</div><table class="tracker_stats">',
|
|
|
|
'<tr><th>Seeders:</th><td>', (tracker.seederCount > -1 ? tracker.seederCount : na), '</td></tr>',
|
|
|
|
'<tr><th>Leechers:</th><td>', (tracker.leecherCount > -1 ? tracker.leecherCount : na), '</td></tr>',
|
|
|
|
'<tr><th>Downloads:</th><td>', (tracker.downloadCount > -1 ? tracker.downloadCount : na), '</td></tr>',
|
|
|
|
'</table></li>');
|
|
|
|
}
|
|
|
|
if (tier !== -1) // close last tier
|
|
|
|
html.push('</ul></div>');
|
|
|
|
|
|
|
|
html.push('</div>'); // inspector_group
|
|
|
|
}
|
|
|
|
|
|
|
|
setInnerHTML(this._inspector_trackers_list, html.join(''));
|
|
|
|
},
|
|
|
|
|
|
|
|
lastAnnounceStatus: function(tracker) {
|
|
|
|
var lastAnnounceLabel = 'Last Announce';
|
|
|
|
var lastAnnounce = [ 'N/A' ];
|
|
|
|
if (tracker.hasAnnounced) {
|
|
|
|
var lastAnnounceTime = Transmission.fmt.timestamp(tracker.lastAnnounceTime);
|
|
|
|
if (tracker.lastAnnounceSucceeded) {
|
|
|
|
lastAnnounce = [ lastAnnounceTime, ' (got ', Transmission.fmt.plural(tracker.lastAnnouncePeerCount, 'peer'), ')' ];
|
|
|
|
} else {
|
|
|
|
lastAnnounceLabel = 'Announce error';
|
|
|
|
lastAnnounce = [ (tracker.lastAnnounceResult ? (tracker.lastAnnounceResult + ' - ') : ''), lastAnnounceTime ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { 'label':lastAnnounceLabel, 'value':lastAnnounce.join('') };
|
|
|
|
},
|
|
|
|
|
|
|
|
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 ' + Transmission.fmt.timeInterval(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 = Transmission.fmt.timestamp(tracker.lastScrapeTime);
|
|
|
|
if (tracker.lastScrapeSucceeded) {
|
|
|
|
lastScrape = lastScrapeTime;
|
|
|
|
} else {
|
|
|
|
lastScrapeLabel = 'Scrape error';
|
|
|
|
lastScrape = (tracker.lastScrapeResult ? tracker.lastScrapeResult + ' - ' : '') + lastScrapeTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {'label':lastScrapeLabel, 'value':lastScrape};
|
|
|
|
},
|
|
|
|
|
2011-08-30 21:40:18 +00:00
|
|
|
inspectorSelectionChanged: function()
|
|
|
|
{
|
|
|
|
var i;
|
|
|
|
|
|
|
|
// if the inspector's hidden, don't create new ones
|
|
|
|
if (this.inspectorIsVisible())
|
|
|
|
{
|
|
|
|
// update the inspector when a selected torrent's data changes.
|
|
|
|
$(this.getAllTorrents()).unbind('dataChanged.inspector');
|
|
|
|
$(this.getSelectedTorrents()).bind('dataChanged.inspector', $.proxy(this.updateInspector,this));
|
|
|
|
|
|
|
|
// periodically ask for updates to the inspector's torrents
|
|
|
|
i = this._inspector;
|
|
|
|
clearInterval(i.refreshInterval);
|
|
|
|
i.refreshInterval = setInterval($.proxy(this.refreshInspectorTorrents,this), 2000);
|
|
|
|
this.refreshInspectorTorrents();
|
|
|
|
|
|
|
|
// refresh the inspector's UI
|
|
|
|
this.updateInspector();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
toggleInspector: function()
|
|
|
|
{
|
2011-08-30 04:54:37 +00:00
|
|
|
this.setInspectorVisible(!this.inspectorIsVisible());
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
|
|
|
setInspectorVisible: function(visible)
|
|
|
|
{
|
|
|
|
// update the ui widgetry
|
|
|
|
$('#torrent_inspector').toggle(visible);
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) {
|
2011-08-26 01:46:07 +00:00
|
|
|
$('body').toggleClass('inspector_showing',visible);
|
|
|
|
$('#inspector_close').toggle(visible);
|
2011-08-28 17:24:56 +00:00
|
|
|
this.hideMobileAddressbar();
|
2011-08-26 01:46:07 +00:00
|
|
|
} else {
|
|
|
|
var w = visible ? $('#torrent_inspector').width() + 1 + 'px' : '0px';
|
|
|
|
$('#torrent_container')[0].style.right = w;
|
|
|
|
}
|
|
|
|
setInnerHTML($('ul li#context_toggle_inspector')[0], (visible?'Hide':'Show')+' Inspector');
|
2011-08-30 21:40:18 +00:00
|
|
|
|
|
|
|
this.inspectorSelectionChanged();
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** FILTER
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
filterSetup: function()
|
|
|
|
{
|
|
|
|
var popup = $('#filter-popup');
|
|
|
|
popup.dialog({
|
|
|
|
autoOpen: false,
|
2011-08-28 17:24:56 +00:00
|
|
|
position: isMobileDevice ? [0,0] : [40,80],
|
2011-08-24 02:04:35 +00:00
|
|
|
show: 'blind',
|
|
|
|
hide: 'blind',
|
|
|
|
title: 'Show',
|
|
|
|
width: 315
|
|
|
|
});
|
|
|
|
var tr = this;
|
|
|
|
$('#filter-button').click(function() {
|
|
|
|
if (popup.is(":visible"))
|
|
|
|
popup.dialog('close');
|
|
|
|
else {
|
|
|
|
tr.refreshFilterPopup();
|
|
|
|
popup.dialog('open');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.refreshFilterButton();
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshFilterButton: function()
|
|
|
|
{
|
2011-08-28 06:20:32 +00:00
|
|
|
var text,
|
|
|
|
state = this[Prefs._FilterMode],
|
|
|
|
state_all = state == Prefs._FilterAll,
|
|
|
|
state_string = this.getStateString(state),
|
|
|
|
tracker = this.filterTracker,
|
|
|
|
tracker_all = !tracker,
|
|
|
|
tracker_string = tracker ? this.getReadableDomain(tracker) : '',
|
|
|
|
torrent_count = Object.keys(this._torrents).length,
|
|
|
|
visible_count = this._rows.length;
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
text = 'Show <span class="filter-selection">';
|
2011-08-24 02:04:35 +00:00
|
|
|
if (state_all && tracker_all)
|
2011-08-28 13:57:25 +00:00
|
|
|
text += 'All';
|
2011-08-24 02:04:35 +00:00
|
|
|
else if (state_all)
|
2011-08-28 13:57:25 +00:00
|
|
|
text += tracker_string;
|
2011-08-24 02:04:35 +00:00
|
|
|
else if (tracker_all)
|
2011-08-28 13:57:25 +00:00
|
|
|
text += state_string;
|
2011-08-24 02:04:35 +00:00
|
|
|
else
|
2011-08-28 13:57:25 +00:00
|
|
|
text += state_string + '</span> at <span class="filter-selection">' + tracker_string;
|
|
|
|
text += '</span> — ';
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
if (torrent_count === visible_count)
|
2011-08-28 13:57:25 +00:00
|
|
|
text += torrent_count + ' Transfers';
|
2011-08-24 02:04:35 +00:00
|
|
|
else
|
2011-08-28 13:57:25 +00:00
|
|
|
text += visible_count + ' of ' + torrent_count;
|
|
|
|
$('#filter-button').html(text);
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
refilterSoon: function()
|
|
|
|
{
|
|
|
|
if (!this.refilterTimer)
|
2011-08-30 21:55:44 +00:00
|
|
|
this.refilterTimer = setTimeout($.proxy(this.refilter,this), 100);
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
sortRows: function(rows)
|
|
|
|
{
|
|
|
|
var i, tor, row,
|
|
|
|
id2row = {},
|
|
|
|
torrents = [];
|
|
|
|
|
|
|
|
for (i=0; row=rows[i]; ++i) {
|
|
|
|
tor = row.getTorrent();
|
|
|
|
torrents.push(tor);
|
|
|
|
id2row[ tor.getId() ] = row;
|
|
|
|
}
|
|
|
|
|
|
|
|
Torrent.sortTorrents(torrents, this[Prefs._SortMethod],
|
|
|
|
this[Prefs._SortDirection]);
|
|
|
|
|
|
|
|
for (i=0; tor=torrents[i]; ++i)
|
|
|
|
rows[i] = id2row[ tor.getId() ];
|
|
|
|
},
|
|
|
|
|
|
|
|
refilter: function(rebuildEverything)
|
2011-08-24 02:04:35 +00:00
|
|
|
{
|
2011-08-31 00:09:21 +00:00
|
|
|
var i, e, id, t, row, tmp, rows, clean_rows, dirty_rows, frag,
|
2011-08-28 04:14:58 +00:00
|
|
|
sort_mode = this[Prefs._SortMethod],
|
|
|
|
sort_direction = this[Prefs._SortDirection],
|
|
|
|
filter_mode = this[Prefs._FilterMode],
|
|
|
|
filter_text = this.filterText,
|
|
|
|
filter_tracker = this.filterTracker,
|
|
|
|
renderer = this.torrentRenderer,
|
2011-08-30 21:27:30 +00:00
|
|
|
list = this._torrent_list,
|
|
|
|
old_sel_count = $(list).children('.selected').length;
|
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
clearTimeout(this.refilterTimer);
|
|
|
|
delete this.refilterTimer;
|
|
|
|
|
2011-08-28 04:14:58 +00:00
|
|
|
if (rebuildEverything) {
|
|
|
|
$(list).empty();
|
|
|
|
this._rows = [];
|
2011-08-27 21:35:19 +00:00
|
|
|
for (id in this._torrents)
|
2011-08-28 04:14:58 +00:00
|
|
|
this.dirtyTorrents[id] = true;
|
|
|
|
}
|
2011-08-27 21:35:19 +00:00
|
|
|
|
|
|
|
// rows that overlap with dirtyTorrents need to be refiltered.
|
|
|
|
// those that don't are 'clean' and don't need refiltering.
|
2011-08-28 04:14:58 +00:00
|
|
|
clean_rows = [];
|
|
|
|
dirty_rows = [];
|
2011-08-27 21:35:19 +00:00
|
|
|
for (i=0; row=this._rows[i]; ++i) {
|
|
|
|
if(row.getTorrentId() in this.dirtyTorrents)
|
|
|
|
dirty_rows.push(row);
|
|
|
|
else
|
|
|
|
clean_rows.push(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the dirty rows from the dom
|
2011-08-28 04:14:58 +00:00
|
|
|
e = $.map(dirty_rows.slice(0), function(r) {
|
2011-08-27 21:35:19 +00:00
|
|
|
return r.getElement();
|
|
|
|
});
|
2011-08-28 04:14:58 +00:00
|
|
|
$(e).remove();
|
2011-08-27 21:35:19 +00:00
|
|
|
|
|
|
|
// drop any dirty rows that don't pass the filter test
|
2011-08-28 04:14:58 +00:00
|
|
|
tmp = [];
|
2011-08-27 21:35:19 +00:00
|
|
|
for (i=0; row=dirty_rows[i]; ++i) {
|
2011-08-30 04:27:09 +00:00
|
|
|
id = row.getTorrentId();
|
|
|
|
t = this._torrents[ id ];
|
|
|
|
if (t && t.test(filter_mode, filter_text, filter_tracker))
|
2011-08-27 21:35:19 +00:00
|
|
|
tmp.push(row);
|
2011-08-30 04:27:09 +00:00
|
|
|
delete this.dirtyTorrents[id];
|
2011-08-27 21:35:19 +00:00
|
|
|
}
|
|
|
|
dirty_rows = tmp;
|
|
|
|
|
|
|
|
// make new rows for dirty torrents that pass the filter test
|
|
|
|
// but don't already have a row
|
|
|
|
for (id in this.dirtyTorrents) {
|
|
|
|
t = this._torrents[id];
|
2011-08-30 04:27:09 +00:00
|
|
|
if (t && t.test(filter_mode, filter_text, filter_tracker)) {
|
2011-08-30 21:27:30 +00:00
|
|
|
row = new TorrentRow(renderer, this, t);
|
2011-08-27 21:35:19 +00:00
|
|
|
row.getElement().row = row;
|
|
|
|
dirty_rows.push(row);
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
// sort the dirty rows
|
|
|
|
this.sortRows (dirty_rows);
|
|
|
|
|
|
|
|
// now we have two sorted arrays of rows
|
|
|
|
// and can do a simple two-way sorted merge.
|
2011-08-28 04:14:58 +00:00
|
|
|
rows = [];
|
2011-08-27 21:35:19 +00:00
|
|
|
var ci=0, cmax=clean_rows.length;
|
|
|
|
var di=0, dmax=dirty_rows.length;
|
2011-08-31 00:09:21 +00:00
|
|
|
frag = document.createDocumentFragment();
|
2011-08-27 21:35:19 +00:00
|
|
|
while (ci!=cmax || di!=dmax)
|
2011-08-24 02:04:35 +00:00
|
|
|
{
|
2011-08-27 21:35:19 +00:00
|
|
|
var push_clean;
|
2011-08-26 00:43:35 +00:00
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
if (ci==cmax)
|
|
|
|
push_clean = false;
|
|
|
|
else if (di==dmax)
|
|
|
|
push_clean = true;
|
|
|
|
else {
|
2011-08-28 13:57:25 +00:00
|
|
|
var c = Torrent.compareTorrents(
|
|
|
|
clean_rows[ci].getTorrent(),
|
|
|
|
dirty_rows[di].getTorrent(),
|
|
|
|
sort_mode, sort_direction);
|
2011-08-27 21:35:19 +00:00
|
|
|
push_clean = (c < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (push_clean)
|
|
|
|
rows.push(clean_rows[ci++]);
|
|
|
|
else {
|
2011-08-28 04:14:58 +00:00
|
|
|
row = dirty_rows[di++];
|
|
|
|
e = row.getElement();
|
2011-08-27 21:35:19 +00:00
|
|
|
if (ci !== cmax)
|
|
|
|
list.insertBefore(e, clean_rows[ci].getElement());
|
|
|
|
else
|
2011-08-31 00:09:21 +00:00
|
|
|
frag.appendChild(e);
|
2011-08-26 00:43:35 +00:00
|
|
|
rows.push(row);
|
2011-08-24 02:04:35 +00:00
|
|
|
}
|
2011-08-27 21:35:19 +00:00
|
|
|
}
|
2011-08-31 00:09:21 +00:00
|
|
|
list.appendChild(frag);
|
2011-08-26 00:43:35 +00:00
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
// update our implementation fields
|
|
|
|
this._rows = rows;
|
|
|
|
this.dirtyTorrents = { };
|
2011-08-26 01:27:16 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
// jquery's even/odd starts with 1 not 0, so invert its logic
|
2011-08-28 04:14:58 +00:00
|
|
|
e = $.map(rows.slice(0), function(r){return r.getElement();});
|
|
|
|
$(e).filter(":odd").addClass('even');
|
|
|
|
$(e).filter(":even").removeClass('even');
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// sync gui
|
2011-08-24 02:04:35 +00:00
|
|
|
this.updateStatusbar();
|
|
|
|
this.refreshFilterButton();
|
2011-08-30 21:27:30 +00:00
|
|
|
if (old_sel_count !== $(list).children('.selected').length)
|
2011-08-28 15:16:54 +00:00
|
|
|
this.selectionChanged();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
setFilterMode: function(mode)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
// set the state
|
|
|
|
this.setPref(Prefs._FilterMode, mode);
|
|
|
|
|
|
|
|
// refilter
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
refreshFilterPopup: function()
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
var tr = this;
|
2009-05-23 21:39:16 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/***
|
|
|
|
**** States
|
|
|
|
***/
|
|
|
|
|
|
|
|
var counts = { };
|
|
|
|
var states = [ Prefs._FilterAll,
|
|
|
|
Prefs._FilterActive,
|
|
|
|
Prefs._FilterDownloading,
|
2011-08-25 06:26:07 +00:00
|
|
|
Prefs._FilterSeeding,
|
2011-08-24 02:04:35 +00:00
|
|
|
Prefs._FilterPaused,
|
|
|
|
Prefs._FilterFinished ];
|
|
|
|
for (var i=0, state; state=states[i]; ++i)
|
|
|
|
counts[state] = 0;
|
|
|
|
var torrents = this.getAllTorrents();
|
|
|
|
for (var i=0, tor; tor=torrents[i]; ++i)
|
|
|
|
for (var j=0, s; s=states[j]; ++j)
|
|
|
|
if (tor.testState(s))
|
|
|
|
counts[s]++;
|
|
|
|
var sel_state = tr[Prefs._FilterMode];
|
|
|
|
var fragment = document.createDocumentFragment();
|
|
|
|
for (var i=0, s; s=states[i]; ++i)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.id = 'show-state-' + s;
|
|
|
|
div.className = 'row' + (s === sel_state ? ' selected':'');
|
|
|
|
div.innerHTML = '<span class="filter-img"></span>'
|
|
|
|
+ '<span class="filter-name">' + tr.getStateString(s) + '</span>'
|
|
|
|
+ '<span class="count">' + counts[s] + '</span>';
|
2011-08-27 21:35:19 +00:00
|
|
|
$(div).click({'state':s}, function(ev) {
|
|
|
|
tr.setFilterMode(ev.data.state);
|
|
|
|
$('#filter-popup').dialog('close');
|
|
|
|
});
|
2011-08-24 02:04:35 +00:00
|
|
|
fragment.appendChild(div);
|
|
|
|
}
|
|
|
|
$('#filter-by-state .row').remove();
|
|
|
|
$('#filter-by-state')[0].appendChild(fragment);
|
|
|
|
|
|
|
|
/***
|
|
|
|
**** Trackers
|
|
|
|
***/
|
|
|
|
|
|
|
|
var trackers = this.getTrackers();
|
2011-08-27 00:22:56 +00:00
|
|
|
var names = Object.keys(trackers).sort();
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
var fragment = document.createDocumentFragment();
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.id = 'show-tracker-all';
|
|
|
|
div.className = 'row' + (tr.filterTracker ? '' : ' selected');
|
|
|
|
div.innerHTML = '<span class="filter-img"></span>'
|
|
|
|
+ '<span class="filter-name">All</span>'
|
|
|
|
+ '<span class="count">' + torrents.length + '</span>';
|
2011-08-27 21:35:19 +00:00
|
|
|
$(div).click(function() {
|
|
|
|
tr.setFilterTracker(null);
|
|
|
|
$('#filter-popup').dialog('close');
|
|
|
|
});
|
2011-08-24 02:04:35 +00:00
|
|
|
fragment.appendChild(div);
|
|
|
|
for (var i=0, name; name=names[i]; ++i) {
|
|
|
|
var div = document.createElement('div');
|
|
|
|
var o = trackers[name];
|
|
|
|
div.id = 'show-tracker-' + name;
|
|
|
|
div.className = 'row' + (o.domain === tr.filterTracker ? ' selected':'');
|
|
|
|
div.innerHTML = '<img class="filter-img" src="http://'+o.domain+'/favicon.ico"/>'
|
|
|
|
+ '<span class="filter-name">'+ name + '</span>'
|
|
|
|
+ '<span class="count">'+ o.count + '</span>';
|
2011-08-27 21:35:19 +00:00
|
|
|
$(div).click({domain:o.domain}, function(ev) {
|
|
|
|
tr.setFilterTracker(ev.data.domain);
|
|
|
|
$('#filter-popup').dialog('close');
|
|
|
|
});
|
2011-08-24 02:04:35 +00:00
|
|
|
fragment.appendChild(div);
|
|
|
|
}
|
|
|
|
$('#filter-by-tracker .row').remove();
|
|
|
|
$('#filter-by-tracker')[0].appendChild(fragment);
|
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getStateString: function(mode)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case Prefs._FilterActive: return 'Active';
|
|
|
|
case Prefs._FilterSeeding: return 'Seeding';
|
|
|
|
case Prefs._FilterDownloading: return 'Downloading';
|
|
|
|
case Prefs._FilterPaused: return 'Paused';
|
|
|
|
case Prefs._FilterFinished: return 'Finished';
|
|
|
|
default: return 'All';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setFilterTracker: function(domain)
|
|
|
|
{
|
|
|
|
this.filterTracker = domain;
|
|
|
|
|
|
|
|
// update which tracker is selected in the popup
|
|
|
|
var key = domain ? this.getReadableDomain(domain) : 'all';
|
|
|
|
var id = '#show-tracker-' + key;
|
|
|
|
$(id).addClass('selected').siblings().removeClass('selected');
|
|
|
|
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* example: "tracker.ubuntu.com" returns "ubuntu.com" */
|
|
|
|
getDomainName: function(host)
|
|
|
|
{
|
|
|
|
var dot = host.indexOf('.');
|
|
|
|
if (dot !== host.lastIndexOf('.'))
|
|
|
|
host = host.slice(dot+1);
|
|
|
|
return host;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* example: "ubuntu.com" returns "Ubuntu" */
|
|
|
|
getReadableDomain: function(name)
|
|
|
|
{
|
|
|
|
if (name.length)
|
|
|
|
name = name.charAt(0).toUpperCase() + name.slice(1);
|
|
|
|
var dot = name.indexOf('.');
|
|
|
|
if (dot !== -1)
|
|
|
|
name = name.slice(0, dot);
|
|
|
|
return name;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTrackers: function()
|
|
|
|
{
|
2011-08-25 23:06:41 +00:00
|
|
|
var ret = {};
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
var torrents = this.getAllTorrents();
|
|
|
|
for (var i=0, torrent; torrent=torrents[i]; ++i) {
|
|
|
|
var names = [];
|
2011-08-25 23:06:41 +00:00
|
|
|
var trackers = torrent.getTrackers();
|
|
|
|
for (var j=0, tracker; tracker=trackers[j]; ++j) {
|
|
|
|
var uri = parseUri(tracker.announce);
|
|
|
|
var domain = this.getDomainName(uri.host);
|
|
|
|
var name = this.getReadableDomain(domain);
|
|
|
|
if (!(name in ret))
|
|
|
|
ret[name] = { 'uri': uri, 'domain': domain, 'count': 0 };
|
|
|
|
if (names.indexOf(name) === -1)
|
|
|
|
names.push(name);
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
for (var j=0, name; name=names[j]; ++j)
|
2011-08-25 23:06:41 +00:00
|
|
|
ret[name].count++;
|
2011-08-24 02:04:35 +00:00
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-08-25 23:06:41 +00:00
|
|
|
return ret;
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** Compact Mode
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
toggleCompactClicked: function()
|
|
|
|
{
|
|
|
|
this.setCompactMode(!this[Prefs._CompactDisplayState]);
|
|
|
|
},
|
|
|
|
setCompactMode: function(is_compact)
|
|
|
|
{
|
2011-08-28 13:57:25 +00:00
|
|
|
var key = Prefs._CompactDisplayState,
|
|
|
|
was_compact = this[key];
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
if (was_compact !== is_compact) {
|
|
|
|
this.setPref(key, is_compact);
|
|
|
|
this.onCompactModeChanged();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
|
|
|
initCompactMode: function()
|
|
|
|
{
|
|
|
|
this.onCompactModeChanged();
|
|
|
|
},
|
|
|
|
onCompactModeChanged: function()
|
|
|
|
{
|
|
|
|
var compact = this[Prefs._CompactDisplayState];
|
|
|
|
|
|
|
|
// update the ui: footer button
|
|
|
|
$("#compact-button").toggleClass('enabled',compact);
|
|
|
|
|
|
|
|
// update the ui: torrent list
|
|
|
|
this.torrentRenderer = compact ? new TorrentRendererCompact()
|
|
|
|
: new TorrentRendererFull();
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
};
|