2011-09-14 05:10:51 +00:00
|
|
|
/**
|
|
|
|
* Copyright © Jordan Lee, Dave Perrett, Malcolm Jarvis and Bruno Bierbaumer
|
2008-07-10 23:57:46 +00:00
|
|
|
*
|
2011-09-14 05:10:51 +00:00
|
|
|
* This file is licensed under the GPLv2.
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2008-07-10 23:57:46 +00:00
|
|
|
*/
|
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()
|
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
var e;
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
// Initialize the helper classes
|
|
|
|
this.remote = new TransmissionRemote(this);
|
2011-09-02 19:29:41 +00:00
|
|
|
this.inspector = new Inspector(this, this.remote);
|
2011-09-14 05:10:51 +00:00
|
|
|
this.prefsDialog = new PrefsDialog(this.remote);
|
2011-10-26 23:19:38 +00:00
|
|
|
$(this.prefsDialog).bind('closed', $.proxy(this.onPrefsDialogClosed,this));
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
this.isMenuEnabled = !isMobileDevice;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
// Initialize the implementation fields
|
2011-08-27 21:35:19 +00:00
|
|
|
this.filterText = '';
|
2011-09-14 15:32:12 +00:00
|
|
|
this._torrents = {};
|
|
|
|
this._rows = [];
|
|
|
|
this.dirtyTorrents = {};
|
2011-09-28 18:06:04 +00:00
|
|
|
this.uriCache = {};
|
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
|
|
|
// Set up user events
|
2011-08-21 05:54:02 +00:00
|
|
|
$(".numberinput").forceNumeric();
|
2011-10-25 23:36:47 +00:00
|
|
|
$('#toolbar-pause').click($.proxy(this.stopSelectedClicked,this));
|
|
|
|
$('#toolbar-start').click($.proxy(this.startSelectedClicked,this));
|
2012-01-24 20:49:46 +00:00
|
|
|
$('#toolbar-pause-all').click($.proxy(this.stopAllClicked,this));
|
|
|
|
$('#toolbar-start-all').click($.proxy(this.startAllClicked,this));
|
2011-10-25 23:36:47 +00:00
|
|
|
$('#toolbar-remove').click($.proxy(this.removeClicked,this));
|
|
|
|
$('#toolbar-open').click($.proxy(this.openTorrentClicked,this));
|
2011-10-28 03:45:36 +00:00
|
|
|
|
|
|
|
$('#prefs-button').click($.proxy(this.togglePrefsDialogClicked,this));
|
2011-09-14 05:10:51 +00:00
|
|
|
|
|
|
|
$('#upload_confirm_button').click($.proxy(this.confirmUploadClicked,this));
|
|
|
|
$('#upload_cancel_button').click($.proxy(this.hideUploadDialog,this));
|
2012-08-18 15:46:22 +00:00
|
|
|
|
|
|
|
$('#move_confirm_button').click($.proxy(this.confirmMoveClicked,this));
|
|
|
|
$('#move_cancel_button').click($.proxy(this.hideMoveDialog,this));
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
$('#turtle-button').click($.proxy(this.toggleTurtleClicked,this));
|
|
|
|
$('#compact-button').click($.proxy(this.toggleCompactClicked,this));
|
|
|
|
|
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-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-10-25 23:36:47 +00:00
|
|
|
$('#toolbar-inspector').click($.proxy(this.toggleInspector,this));
|
2011-10-23 17:10:44 +00:00
|
|
|
|
2011-11-13 23:08:49 +00:00
|
|
|
e = $('#filter-mode');
|
|
|
|
e.val(this[Prefs._FilterMode]);
|
|
|
|
e.change($.proxy(this.onFilterModeClicked,this));
|
2011-11-13 18:04:29 +00:00
|
|
|
$('#filter-tracker').change($.proxy(this.onFilterTrackerClicked,this));
|
|
|
|
|
2011-10-23 17:10:44 +00:00
|
|
|
if (!isMobileDevice) {
|
2011-09-14 05:10:51 +00:00
|
|
|
$(document).bind('keydown', $.proxy(this.keyDown,this) );
|
|
|
|
$(document).bind('keyup', $.proxy(this.keyUp, this) );
|
|
|
|
$('#torrent_container').click( $.proxy(this.deselectAll,this) );
|
2012-01-24 21:01:06 +00:00
|
|
|
$('#torrent_container').bind('dragover', $.proxy(this.dragenter,this));
|
|
|
|
$('#torrent_container').bind('dragenter', $.proxy(this.dragenter,this));
|
|
|
|
$('#torrent_container').bind('drop', $.proxy(this.drop,this));
|
2011-09-14 05:10:51 +00:00
|
|
|
$('#inspector_link').click( $.proxy(this.toggleInspector,this) );
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
this.setupSearchBox();
|
|
|
|
this.createContextMenu();
|
|
|
|
}
|
2011-09-14 05:10:51 +00:00
|
|
|
|
|
|
|
if (this.isMenuEnabled)
|
|
|
|
this.createSettingsMenu();
|
|
|
|
|
|
|
|
e = {};
|
|
|
|
e.torrent_list = $('#torrent_list')[0];
|
|
|
|
e.toolbar_buttons = $('#toolbar ul li');
|
2011-10-25 23:36:47 +00:00
|
|
|
e.toolbar_pause_button = $('#toolbar-pause')[0];
|
|
|
|
e.toolbar_start_button = $('#toolbar-start')[0];
|
|
|
|
e.toolbar_remove_button = $('#toolbar-remove')[0];
|
2011-09-14 05:10:51 +00:00
|
|
|
this.elements = e;
|
|
|
|
|
|
|
|
// Apply the prefs settings to the 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);
|
|
|
|
|
2011-10-25 23:36:47 +00:00
|
|
|
this.updateButtonsSoon();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
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-09-14 05:10:51 +00:00
|
|
|
this.updateGuiFromSession(o);
|
2012-04-08 14:48:57 +00:00
|
|
|
this.sessionProperties = o;
|
2011-08-28 06:05:46 +00:00
|
|
|
}, this, async);
|
2009-07-28 04:53:04 +00:00
|
|
|
},
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
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
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
if (this.isMenuEnabled)
|
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() {
|
2011-09-05 07:46:55 +00:00
|
|
|
if (this.value === '') {
|
2008-08-09 04:38:51 +00:00
|
|
|
$(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
|
|
|
},
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
/**
|
2008-07-10 23:57:46 +00:00
|
|
|
* Create the torrent right-click menu
|
|
|
|
*/
|
|
|
|
createContextMenu: function() {
|
2009-05-23 02:28:04 +00:00
|
|
|
var tr = this;
|
2008-07-10 23:57:46 +00:00
|
|
|
var bindings = {
|
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); },
|
2012-08-18 15:46:22 +00:00
|
|
|
context_move: function() { tr.moveSelectedTorrents(false); },
|
2011-08-24 02:04:35 +00:00
|
|
|
context_remove: function() { tr.removeSelectedTorrents(); },
|
|
|
|
context_removedata: function() { tr.removeSelectedTorrentsAndData(); },
|
|
|
|
context_verify: function() { tr.verifySelectedTorrents(); },
|
|
|
|
context_reannounce: function() { tr.reannounceSelectedTorrents(); },
|
|
|
|
context_move_top: function() { tr.moveTop(); },
|
|
|
|
context_move_up: function() { tr.moveUp(); },
|
|
|
|
context_move_down: function() { tr.moveDown(); },
|
2012-06-04 00:28:15 +00:00
|
|
|
context_move_bottom: function() { tr.moveBottom(); },
|
|
|
|
context_select_all: function() { tr.selectAll(); },
|
|
|
|
context_deselect_all: function() { tr.deselectAll(); }
|
2008-07-10 23:57:46 +00:00
|
|
|
};
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
// Set up the context menu
|
2008-07-10 23:57:46 +00:00
|
|
|
$('ul#torrent_list').contextMenu('torrent_context_menu', {
|
|
|
|
bindings: bindings,
|
2011-09-14 05:10:51 +00:00
|
|
|
menuStyle: { width: '310px', backgroundColor: '#fff', border: 'none', padding: '5px 0', textAlign: 'left' },
|
|
|
|
itemStyle: { backgroundColor: 'transparent', margin: '0', padding: '3px 10px 3px 20px', color: '#000', cursor: 'default', border: 'none'},
|
|
|
|
itemHoverStyle: { backgroundColor: '#24e', color: '#fff', border: 'none'},
|
2008-07-10 23:57:46 +00:00
|
|
|
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
|
|
|
createSettingsMenu: function() {
|
|
|
|
$('#settings_menu').transMenu({
|
|
|
|
selected_char: '✔',
|
|
|
|
direction: 'up',
|
2011-09-14 05:10:51 +00:00
|
|
|
onClick: $.proxy(this.onMenuClicked,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
|
|
|
|
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-09-14 15:32:12 +00:00
|
|
|
getTorrentIds: function(torrents)
|
|
|
|
{
|
|
|
|
return $.map(torrents.slice(0), function(t) {return t.getId();});
|
|
|
|
},
|
|
|
|
|
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() {
|
2012-04-08 14:48:57 +00:00
|
|
|
var p = this.sessionProperties;
|
2011-08-31 14:24:35 +00:00
|
|
|
if (p && p.seedRatioLimited)
|
|
|
|
return p.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-31 14:24:35 +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-09-14 15:32:12 +00:00
|
|
|
return this.getTorrentIds(this.getSelectedTorrents());
|
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-09-14 05:10:51 +00:00
|
|
|
$(this.elements.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-09-14 05:10:51 +00:00
|
|
|
$(this.elements.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-09-14 05:10:51 +00:00
|
|
|
$(this.elements.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-09-14 15:32:12 +00:00
|
|
|
// Select a range from this row to the last clicked torrent
|
2011-08-24 02:04:35 +00:00
|
|
|
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-09-02 19:29:41 +00:00
|
|
|
|
|
|
|
this.inspector.setTorrents(this.inspectorIsVisible() ? this.getSelectedTorrents() : []);
|
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-09-14 15:32:12 +00:00
|
|
|
{
|
|
|
|
var callback = $.proxy(this.selectionChanged,this),
|
|
|
|
msec = 200;
|
|
|
|
this.selectionChangedTimer = setTimeout(callback, msec);
|
|
|
|
}
|
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-31 14:24:35 +00:00
|
|
|
rows = this._rows,
|
2011-09-03 05:12:14 +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
|
|
|
{
|
2011-08-31 14:24:35 +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
|
|
|
},
|
|
|
|
|
2011-09-14 15:32:12 +00:00
|
|
|
keyUp: function(ev) {
|
2011-08-25 10:23:19 +00:00
|
|
|
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
|
|
|
|
2011-08-31 14:24:35 +00:00
|
|
|
isButtonEnabled: function(ev) {
|
|
|
|
var p = (ev.target || ev.srcElement).parentNode;
|
|
|
|
return p.className!=='disabled'
|
|
|
|
&& p.parentNode.className!=='disabled';
|
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
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-01-24 20:49:46 +00:00
|
|
|
stopAllClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
|
|
|
this.stopAllTorrents();
|
|
|
|
this.hideMobileAddressbar();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
startAllClicked: function(ev) {
|
|
|
|
if (this.isButtonEnabled(ev)) {
|
|
|
|
this.startAllTorrents(false);
|
|
|
|
this.hideMobileAddressbar();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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-09-14 15:32:12 +00:00
|
|
|
drop: function(ev)
|
|
|
|
{
|
|
|
|
var i, uri, uris=null,
|
2012-08-18 15:46:22 +00:00
|
|
|
types = ["text/uri-list", "text/plain"],
|
2011-09-14 15:32:12 +00:00
|
|
|
paused = this.shouldAddedTorrentsStart();
|
|
|
|
|
|
|
|
if (!ev.dataTransfer || !ev.dataTransfer.types)
|
2011-05-30 15:12:42 +00:00
|
|
|
return true;
|
2011-09-14 15:32:12 +00:00
|
|
|
|
|
|
|
for (i=0; !uris && i<types.length; ++i)
|
|
|
|
if (ev.dataTransfer.types.contains(types[i]))
|
2011-08-24 02:04:35 +00:00
|
|
|
uris = ev.dataTransfer.getData(types[i]).split("\n");
|
2011-09-14 15:32:12 +00:00
|
|
|
|
|
|
|
for (i=0; uri=uris[i]; ++i) {
|
|
|
|
if (/^#/.test(uri)) // lines which start with "#" are comments
|
2011-05-30 15:12:42 +00:00
|
|
|
continue;
|
2011-09-14 15:32:12 +00:00
|
|
|
if (/^[a-z-]+:/i.test(uri)) // 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
|
|
|
}
|
2011-09-14 15:32:12 +00:00
|
|
|
|
|
|
|
ev.preventDefault();
|
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
|
|
|
},
|
|
|
|
|
2012-08-18 15:46:22 +00:00
|
|
|
hideMoveDialog: function() {
|
|
|
|
$('#move_container').hide();
|
|
|
|
this.updateButtonStates();
|
|
|
|
},
|
|
|
|
|
|
|
|
confirmMoveClicked: function() {
|
|
|
|
this.moveSelectedTorrents(true);
|
|
|
|
this.hideUploadDialog();
|
|
|
|
},
|
|
|
|
|
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-09-14 15:32:12 +00:00
|
|
|
// turn the periodic ajax session refresh on & off
|
2011-08-24 02:04:35 +00:00
|
|
|
togglePeriodicSessionRefresh: function(enabled) {
|
2011-08-31 14:24:35 +00:00
|
|
|
clearInterval(this.sessionInterval);
|
|
|
|
delete this.sessionInterval;
|
2011-08-24 02:04:35 +00:00
|
|
|
if (enabled) {
|
2011-09-14 05:10:51 +00:00
|
|
|
var callback = $.proxy(this.loadDaemonPrefs,this),
|
|
|
|
msec = 8000;
|
|
|
|
this.sessionInterval = setInterval(callback, msec);
|
2009-11-14 14:57:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
toggleTurtleClicked: function()
|
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
var o = {};
|
2011-10-23 17:10:44 +00:00
|
|
|
o[RPC._TurtleState] = !$('#turtle-button').hasClass('selected');
|
2011-09-14 05:10:51 +00:00
|
|
|
this.remote.savePrefs(o);
|
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-10-26 23:19:38 +00:00
|
|
|
onPrefsDialogClosed: function() {
|
2011-10-28 03:45:36 +00:00
|
|
|
$('#prefs-button').removeClass('selected');
|
2011-10-26 23:19:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
togglePrefsDialogClicked: function(ev)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-10-28 03:45:36 +00:00
|
|
|
var e = $('#prefs-button');
|
2011-10-26 23:19:38 +00:00
|
|
|
|
|
|
|
if (e.hasClass('selected'))
|
|
|
|
this.prefsDialog.close();
|
|
|
|
else {
|
|
|
|
e.addClass('selected');
|
|
|
|
this.prefsDialog.show();
|
|
|
|
}
|
2011-03-10 01:37:58 +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
|
|
|
},
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
onMenuClicked: function(ev)
|
|
|
|
{
|
|
|
|
var o, dir,
|
|
|
|
id = ev.target.id,
|
|
|
|
remote = this.remote,
|
|
|
|
element = $(ev.target);
|
|
|
|
|
|
|
|
if (element.hasClass('sort-mode'))
|
|
|
|
{
|
|
|
|
element.parent().find('.sort-mode').each(function() {
|
|
|
|
element.parent().deselectMenuItem();
|
|
|
|
});
|
|
|
|
element.selectMenuItem();
|
|
|
|
this.setSortMethod(id.replace(/sort_by_/, ''));
|
|
|
|
}
|
|
|
|
else if (element.hasClass('upload-speed'))
|
|
|
|
{
|
|
|
|
o = {};
|
|
|
|
o[RPC._UpSpeedLimit] = parseInt(ev.target.innerHTML);
|
|
|
|
o[RPC._UpSpeedLimited] = true;
|
|
|
|
remote.savePrefs(o);
|
|
|
|
}
|
|
|
|
else if (element.hasClass('download-speed'))
|
|
|
|
{
|
|
|
|
o = {};
|
|
|
|
o[RPC._DownSpeedLimit] = parseInt(ev.target.innerHTML);
|
|
|
|
o[RPC._DownSpeedLimited] = true;
|
|
|
|
remote.savePrefs(o);
|
|
|
|
}
|
|
|
|
else switch (id)
|
|
|
|
{
|
|
|
|
case 'statistics':
|
|
|
|
this.showStatsDialog();
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-09-15 05:16:39 +00:00
|
|
|
case 'about-button':
|
|
|
|
o = 'Transmission ' + this.serverVersion;
|
|
|
|
$('#about-dialog #about-title').html(o);
|
2011-09-15 05:27:22 +00:00
|
|
|
$('#about-dialog').dialog({
|
|
|
|
title: 'About',
|
|
|
|
show: 'fade',
|
|
|
|
hide: 'fade'
|
|
|
|
});
|
2011-09-15 05:16:39 +00:00
|
|
|
break;
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
case 'homepage':
|
|
|
|
window.open('http://www.transmissionbt.com/');
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
case 'tipjar':
|
|
|
|
window.open('http://www.transmissionbt.com/donate.php');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unlimited_download_rate':
|
2011-09-14 15:32:12 +00:00
|
|
|
o = {};
|
2011-09-14 05:10:51 +00:00
|
|
|
o[RPC._DownSpeedLimited] = false;
|
|
|
|
remote.savePrefs(o);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'limited_download_rate':
|
2011-09-14 15:32:12 +00:00
|
|
|
o = {};
|
2011-09-14 05:10:51 +00:00
|
|
|
o[RPC._DownSpeedLimited] = true;
|
|
|
|
remote.savePrefs(o);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unlimited_upload_rate':
|
|
|
|
o = {};
|
|
|
|
o[RPC._UpSpeedLimited] = false;
|
|
|
|
remote.savePrefs(o);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'limited_upload_rate':
|
|
|
|
o = {};
|
|
|
|
o[RPC._UpSpeedLimited] = true;
|
|
|
|
remote.savePrefs(o);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'reverse_sort_order':
|
|
|
|
if (element.menuItemIsSelected()) {
|
|
|
|
dir = Prefs._SortAscending;
|
|
|
|
element.deselectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
} else {
|
2011-09-14 05:10:51 +00:00
|
|
|
dir = Prefs._SortDescending;
|
|
|
|
element.selectMenuItem();
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2011-09-14 05:10:51 +00:00
|
|
|
this.setSortDirection(dir);
|
|
|
|
break;
|
|
|
|
|
2012-05-19 21:37:29 +00:00
|
|
|
case 'toggle_notifications':
|
|
|
|
Notifications && Notifications.toggle();
|
|
|
|
break;
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
default:
|
|
|
|
console.log('unhandled: ' + id);
|
2008-07-10 23:57:46 +00:00
|
|
|
break;
|
2011-09-14 05:10:51 +00:00
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
2009-05-23 02:56:55 +00:00
|
|
|
$('#settings_menu').trigger('closemenu');
|
2011-09-14 05:10:51 +00:00
|
|
|
ev.stopImmediatePropagation();
|
2008-07-10 23:57:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2011-09-03 07:10:03 +00:00
|
|
|
onTorrentChanged: function(ev, tor)
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
2011-08-27 21:35:19 +00:00
|
|
|
// update our dirty fields
|
2011-08-31 14:24:35 +00:00
|
|
|
this.dirtyTorrents[ tor.getId() ] = true;
|
2011-08-27 21:35:19 +00:00
|
|
|
|
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-09-14 15:32:12 +00:00
|
|
|
var i, o, t, id, needed, needinfo = [],
|
|
|
|
callback, fields;
|
2010-06-21 13:14:33 +00:00
|
|
|
|
2011-08-31 03:31:10 +00:00
|
|
|
for (i=0; o=updates[i]; ++i)
|
|
|
|
{
|
|
|
|
id = o.id;
|
2011-08-26 01:46:07 +00:00
|
|
|
if ((t = this._torrents[id]))
|
2011-08-31 03:31:10 +00:00
|
|
|
{
|
|
|
|
needed = t.needsMetaData();
|
2011-08-26 01:46:07 +00:00
|
|
|
t.refresh(o);
|
2011-08-31 14:24:35 +00:00
|
|
|
if (needed && !t.needsMetaData())
|
2011-08-31 03:31:10 +00:00
|
|
|
needinfo.push(id);
|
|
|
|
}
|
2011-08-26 01:46:07 +00:00
|
|
|
else {
|
2011-09-03 07:29:53 +00:00
|
|
|
t = this._torrents[id] = new Torrent(o);
|
2011-08-27 21:35:19 +00:00
|
|
|
this.dirtyTorrents[id] = true;
|
2011-09-14 15:32:12 +00:00
|
|
|
callback = $.proxy(this.onTorrentChanged,this);
|
|
|
|
$(t).bind('dataChanged',callback);
|
|
|
|
// do we need more info for this torrent?
|
2011-09-14 05:10:51 +00:00
|
|
|
if(!('name' in t.fields) || !('status' in t.fields))
|
2011-08-26 23:34:43 +00:00
|
|
|
needinfo.push(id);
|
2012-05-19 21:37:29 +00:00
|
|
|
|
|
|
|
t.notifyOnFieldChange('status', $.proxy(function (newValue, oldValue) {
|
|
|
|
if (oldValue === Torrent._StatusDownload && (newValue == Torrent._StatusSeed || newValue == Torrent._StatusSeedWait)) {
|
|
|
|
$(this).trigger('downloadComplete', [t]);
|
|
|
|
} else if (oldValue === Torrent._StatusSeed && newValue === Torrent._StatusStopped && t.isFinished()) {
|
|
|
|
$(this).trigger('seedingComplete', [t]);
|
|
|
|
} else {
|
|
|
|
$(this).trigger('statusChange', [t]);
|
|
|
|
}
|
|
|
|
}, this));
|
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.
|
2011-09-14 15:32:12 +00:00
|
|
|
fields = ['id'].concat(Torrent.Fields.Metadata,
|
|
|
|
Torrent.Fields.Stats);
|
|
|
|
this.updateTorrents(needinfo, fields);
|
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-09-02 19:29:41 +00:00
|
|
|
updateTorrents: function(ids, fields)
|
|
|
|
{
|
2011-09-14 15:32:12 +00:00
|
|
|
this.remote.updateTorrents(ids, fields,
|
|
|
|
this.updateFromTorrentGet, this);
|
2011-09-02 19:29:41 +00:00
|
|
|
},
|
|
|
|
|
2011-08-26 19:42:07 +00:00
|
|
|
refreshTorrents: function()
|
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
var callback = $.proxy(this.refreshTorrents,this),
|
|
|
|
msec = this[Prefs._RefreshRate] * 1000,
|
|
|
|
fields = ['id'].concat(Torrent.Fields.Stats);
|
|
|
|
|
2011-08-26 19:42:07 +00:00
|
|
|
// send a request right now
|
2011-09-14 05:10:51 +00:00
|
|
|
this.updateTorrents('recently-active', fields);
|
2011-08-26 19:42:07 +00:00
|
|
|
|
|
|
|
// schedule the next request
|
|
|
|
clearTimeout(this.refreshTorrentsTimeout);
|
2011-09-14 15:32:12 +00:00
|
|
|
this.refreshTorrentsTimeout = setTimeout(callback, msec);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2011-08-26 22:49:57 +00:00
|
|
|
|
|
|
|
initializeTorrents: function()
|
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
var fields = ['id'].concat(Torrent.Fields.Metadata,
|
|
|
|
Torrent.Fields.Stats);
|
|
|
|
this.updateTorrents(null, fields);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
2009-06-26 03:03:17 +00:00
|
|
|
|
2011-09-03 07:10:03 +00:00
|
|
|
onRowClicked: function(ev)
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
2011-09-14 15:32:12 +00:00
|
|
|
var meta_key = ev.metaKey || ev.ctrlKey,
|
|
|
|
row = ev.currentTarget.row;
|
2011-09-03 07:10:03 +00:00
|
|
|
|
2011-08-31 04:39:24 +00:00
|
|
|
// handle the per-row "torrent_resume" button
|
|
|
|
if (ev.target.className === 'torrent_resume') {
|
|
|
|
this.startTorrent(row.getTorrent());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle the per-row "torrent_pause" button
|
|
|
|
if (ev.target.className === 'torrent_pause') {
|
|
|
|
this.stopTorrent(row.getTorrent());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// 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-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-09-14 15:32:12 +00:00
|
|
|
var i, id;
|
|
|
|
|
2011-08-26 19:42:07 +00:00
|
|
|
if (ids && ids.length)
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
2011-09-14 15:32:12 +00:00
|
|
|
for (i=0; id=ids[i]; ++i) {
|
2011-08-30 04:27:09 +00:00
|
|
|
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-09-14 05:10:51 +00:00
|
|
|
shouldAddedTorrentsStart: function()
|
|
|
|
{
|
|
|
|
return this.prefsDialog.shouldAddedTorrentsStart();
|
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', '');
|
2011-09-14 05:10:51 +00:00
|
|
|
$('input#torrent_auto_start').attr('checked', this.shouldAddedTorrentsStart());
|
2011-08-28 13:57:25 +00:00
|
|
|
$('#upload_container').show();
|
|
|
|
$('#torrent_upload_url').focus();
|
2011-08-26 01:46:07 +00:00
|
|
|
|
|
|
|
// Submit the upload form
|
|
|
|
} else {
|
2011-09-14 15:32:12 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-18 15:46:22 +00:00
|
|
|
promptSetLocation: function(confirmed, torrents) {
|
|
|
|
if (! confirmed) {
|
|
|
|
var path;
|
|
|
|
if (torrents.length === 1) {
|
|
|
|
path = torrents[0].getDownloadDir();
|
|
|
|
} else {
|
|
|
|
path = $("#download-dir").val();
|
|
|
|
}
|
|
|
|
$('input#torrent_path').attr('value', path);
|
|
|
|
$('#move_container').show();
|
|
|
|
$('#torrent_path').focus();
|
|
|
|
} else {
|
|
|
|
var ids = this.getTorrentIds(torrents);
|
|
|
|
this.remote.moveTorrents(
|
|
|
|
ids,
|
|
|
|
$("input#torrent_path").val(),
|
|
|
|
this.refreshTorrents,
|
|
|
|
this);
|
|
|
|
$('#move_container').hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
moveSelectedTorrents: function(confirmed) {
|
|
|
|
var torrents = this.getSelectedTorrents();
|
|
|
|
if (torrents.length)
|
|
|
|
this.promptSetLocation(confirmed, torrents);
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
2012-08-18 15:46:22 +00:00
|
|
|
promptToRemoveTorrents: function(torrents) {
|
2011-09-05 07:46:55 +00:00
|
|
|
if (torrents.length === 1)
|
2011-08-25 23:06:41 +00:00
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
var torrent = torrents[0],
|
|
|
|
header = 'Remove ' + torrent.getName() + '?',
|
|
|
|
message = 'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?';
|
2011-08-26 01:46:07 +00:00
|
|
|
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrents', torrents);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
var header = 'Remove ' + torrents.length + ' transfers?',
|
|
|
|
message = 'Once removed, continuing the transfers will require the torrent files. Are you sure you want to remove them?';
|
2011-08-26 01:46:07 +00:00
|
|
|
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)
|
|
|
|
{
|
2011-09-05 07:46:55 +00:00
|
|
|
if (torrents.length === 1)
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
|
|
|
var torrent = torrents[0],
|
2011-09-14 05:10:51 +00:00
|
|
|
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?';
|
2011-08-26 01:46:07 +00:00
|
|
|
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrentsAndData', torrents);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var header = 'Remove ' + torrents.length + ' transfers and delete data?',
|
2011-09-14 05:10:51 +00:00
|
|
|
message = 'All data downloaded for these torrents will be deleted. Are you sure you want to remove them?';
|
2011-08-26 01:46:07 +00:00
|
|
|
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-09-14 05:10:51 +00:00
|
|
|
var ids = this.getTorrentIds(torrents);
|
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
|
|
|
|
2012-01-24 20:49:46 +00:00
|
|
|
startAllTorrents: function(force) {
|
|
|
|
this.startTorrents(this.getAllTorrents(), force);
|
|
|
|
},
|
2011-08-26 01:46:07 +00:00
|
|
|
startSelectedTorrents: function(force) {
|
|
|
|
this.startTorrents(this.getSelectedTorrents(), force);
|
|
|
|
},
|
|
|
|
startTorrent: function(torrent) {
|
|
|
|
this.startTorrents([ torrent ], false);
|
|
|
|
},
|
2011-09-14 05:10:51 +00:00
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
startTorrents: function(torrents, force) {
|
2011-09-14 05:10:51 +00:00
|
|
|
this.remote.startTorrents(this.getTorrentIds(torrents), force,
|
|
|
|
this.refreshTorrents, this);
|
2011-08-26 01:46:07 +00:00
|
|
|
},
|
|
|
|
verifyTorrent: function(torrent) {
|
|
|
|
this.verifyTorrents([ torrent ]);
|
|
|
|
},
|
|
|
|
verifyTorrents: function(torrents) {
|
2011-09-14 05:10:51 +00:00
|
|
|
this.remote.verifyTorrents(this.getTorrentIds(torrents),
|
2011-08-28 06:05:46 +00:00
|
|
|
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-09-14 05:10:51 +00:00
|
|
|
this.remote.reannounceTorrents(this.getTorrentIds(torrents),
|
2011-08-28 06:05:46 +00:00
|
|
|
this.refreshTorrents, this);
|
2010-01-31 02:42:48 +00:00
|
|
|
},
|
|
|
|
|
2012-01-24 20:49:46 +00:00
|
|
|
stopAllTorrents: function() {
|
|
|
|
this.stopTorrents(this.getAllTorrents());
|
|
|
|
},
|
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
|
|
|
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-09-14 05:10:51 +00:00
|
|
|
this.remote.stopTorrents(this.getTorrentIds(torrents),
|
2011-08-28 06:05:46 +00:00
|
|
|
this.refreshTorrents, this);
|
2010-02-06 16:43:48 +00:00
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
changeFileCommand: function(torrentId, rowIndices, command) {
|
|
|
|
this.remote.changeFileCommand(torrentId, rowIndices, command);
|
2010-02-06 16:43:48 +00:00
|
|
|
},
|
|
|
|
|
2011-08-31 14:24:35 +00:00
|
|
|
hideMobileAddressbar: function(delaySecs) {
|
2011-08-30 21:55:44 +00:00
|
|
|
if (isMobileDevice && !scroll_timeout) {
|
2011-09-14 05:10:51 +00:00
|
|
|
var callback = $.proxy(this.doToolbarHide,this),
|
|
|
|
msec = delaySecs*1000 || 150;
|
|
|
|
scroll_timeout = setTimeout(callback,msec);
|
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-09-15 00:52:39 +00:00
|
|
|
updateGuiFromSession: function(o)
|
|
|
|
{
|
|
|
|
var limit, limited, e, b, text,
|
|
|
|
fmt = Transmission.fmt,
|
|
|
|
menu = $('#settings_menu');
|
|
|
|
|
|
|
|
this.serverVersion = o.version;
|
2013-01-27 17:41:35 +00:00
|
|
|
this.freeSpace = o[RPC._DownloadDirFreeSpace];
|
2011-09-15 00:52:39 +00:00
|
|
|
|
|
|
|
this.prefsDialog.set(o);
|
|
|
|
|
|
|
|
if (RPC._TurtleState in o)
|
|
|
|
{
|
|
|
|
b = o[RPC._TurtleState];
|
|
|
|
e = $('#turtle-button');
|
|
|
|
text = [ 'Click to ', (b?'disable':'enable'),
|
|
|
|
' Temporary Speed Limits (',
|
|
|
|
fmt.speed(o[RPC._TurtleUpSpeedLimit]),
|
|
|
|
' up,',
|
|
|
|
fmt.speed(o[RPC._TurtleDownSpeedLimit]),
|
|
|
|
' down)' ].join('');
|
2011-10-23 17:10:44 +00:00
|
|
|
e.toggleClass('selected', b);
|
2011-09-15 00:52:39 +00:00
|
|
|
e.attr('title', text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isMenuEnabled && (RPC._DownSpeedLimited in o)
|
|
|
|
&& (RPC._DownSpeedLimit in o))
|
|
|
|
{
|
|
|
|
limit = o[RPC._DownSpeedLimit];
|
|
|
|
limited = o[RPC._DownSpeedLimited];
|
|
|
|
|
|
|
|
e = menu.find('#limited_download_rate');
|
|
|
|
e.html('Limit (' + fmt.speed(limit) + ')');
|
|
|
|
|
|
|
|
if (!limited)
|
|
|
|
e = menu.find('#unlimited_download_rate');
|
|
|
|
e.deselectMenuSiblings().selectMenuItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isMenuEnabled && (RPC._UpSpeedLimited in o)
|
|
|
|
&& (RPC._UpSpeedLimit in o))
|
|
|
|
{
|
|
|
|
limit = o[RPC._UpSpeedLimit];
|
|
|
|
limited = o[RPC._UpSpeedLimited];
|
|
|
|
|
|
|
|
e = menu.find('#limited_upload_rate');
|
|
|
|
e.html('Limit (' + fmt.speed(limit) + ')');
|
|
|
|
|
|
|
|
if (!limited)
|
|
|
|
e = menu.find('#unlimited_upload_rate');
|
|
|
|
e.deselectMenuSiblings().selectMenuItem();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateStatusbar: function()
|
|
|
|
{
|
2011-10-26 04:14:39 +00:00
|
|
|
var u=0, d=0,
|
|
|
|
i, row, text,
|
2011-09-15 00:52:39 +00:00
|
|
|
fmt = Transmission.fmt,
|
|
|
|
torrents = this.getAllTorrents();
|
|
|
|
|
|
|
|
// up/down speed
|
|
|
|
for (i=0; row=torrents[i]; ++i) {
|
|
|
|
u += row.getUploadSpeed();
|
|
|
|
d += row.getDownloadSpeed();
|
|
|
|
}
|
|
|
|
|
2011-10-26 04:14:39 +00:00
|
|
|
$('#speed-up-container').toggleClass('active', u>0 );
|
|
|
|
$('#speed-up-label').text( fmt.speedBps( u ) );
|
2011-09-15 00:52:39 +00:00
|
|
|
|
2011-10-26 04:14:39 +00:00
|
|
|
$('#speed-dn-container').toggleClass('active', d>0 );
|
|
|
|
$('#speed-dn-label').text( fmt.speedBps( d ) );
|
2011-11-13 18:04:29 +00:00
|
|
|
|
2013-01-27 17:41:35 +00:00
|
|
|
if (this.freeSpace > 0)
|
|
|
|
text = fmt.size (this.freeSpace);
|
|
|
|
else
|
|
|
|
text = '';
|
|
|
|
$('#freespace-info').text( text);
|
|
|
|
|
2011-11-13 18:04:29 +00:00
|
|
|
// visible torrents
|
2012-10-07 18:10:26 +00:00
|
|
|
$('#filter-count').text( fmt.countString('Transfer','Transfers',this._rows.length ) );
|
2011-09-15 00:52:39 +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-11-13 18:04:29 +00:00
|
|
|
updateFilterSelect: function()
|
|
|
|
{
|
|
|
|
var i, names, name, str, o,
|
|
|
|
e = $('#filter-tracker'),
|
|
|
|
trackers = this.getTrackers();
|
|
|
|
|
|
|
|
// build a sorted list of names
|
|
|
|
names = [];
|
|
|
|
for (name in trackers)
|
|
|
|
names.push (name);
|
|
|
|
names.sort();
|
|
|
|
|
|
|
|
// build the new html
|
|
|
|
if (!this.filterTracker)
|
|
|
|
str = '<option value="all" selected="selected">All</option>';
|
|
|
|
else
|
|
|
|
str = '<option value="all">All</option>';
|
|
|
|
for (i=0; name=names[i]; ++i) {
|
|
|
|
o = trackers[name];
|
|
|
|
str += '<option value="' + o.domain + '"';
|
|
|
|
if (trackers[name].domain === this.filterTracker) str += ' selected="selected"';
|
|
|
|
str += '>' + name + '</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.filterTrackersStr || (this.filterTrackersStr !== str)) {
|
|
|
|
this.filterTrackersStr = str;
|
|
|
|
$('#filter-tracker').html(str);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-28 15:16:54 +00:00
|
|
|
updateButtonsSoon: function()
|
|
|
|
{
|
|
|
|
if (!this.buttonRefreshTimer)
|
2011-09-14 05:10:51 +00:00
|
|
|
{
|
|
|
|
var callback = $.proxy(this.updateButtonStates,this),
|
|
|
|
msec = 100;
|
|
|
|
this.buttonRefreshTimer = setTimeout(callback, msec);
|
|
|
|
}
|
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-09-14 05:10:51 +00:00
|
|
|
var e = this.elements,
|
|
|
|
haveActive = false,
|
|
|
|
havePaused = false,
|
2011-09-14 15:32:12 +00:00
|
|
|
haveSel = false,
|
|
|
|
haveActiveSel = false,
|
|
|
|
havePausedSel = false;
|
2011-09-14 05:10:51 +00:00
|
|
|
|
2011-08-28 15:16:54 +00:00
|
|
|
clearTimeout(this.buttonRefreshTimer);
|
|
|
|
delete this.buttonRefreshTimer;
|
|
|
|
|
2011-09-14 05:10:51 +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;
|
2011-09-14 15:32:12 +00:00
|
|
|
if (isSelected) haveSel = true;
|
|
|
|
if (isSelected && !isStopped) haveActiveSel = true;
|
|
|
|
if (isSelected && isStopped) havePausedSel = true;
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
2011-09-14 05:10:51 +00:00
|
|
|
|
2011-10-25 23:36:47 +00:00
|
|
|
this.setEnabled(e.toolbar_pause_button, haveActiveSel);
|
|
|
|
this.setEnabled(e.toolbar_start_button, havePausedSel);
|
|
|
|
this.setEnabled(e.toolbar_remove_button, haveSel);
|
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-09-02 19:29:41 +00:00
|
|
|
inspectorIsVisible: function()
|
2011-08-26 01:46:07 +00:00
|
|
|
{
|
2011-09-02 19:29:41 +00:00
|
|
|
return $('#torrent_inspector').is(':visible');
|
2011-08-30 21:40:18 +00:00
|
|
|
},
|
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)
|
|
|
|
{
|
2011-09-14 05:10:51 +00:00
|
|
|
if (visible)
|
|
|
|
this.inspector.setTorrents(this.getSelectedTorrents());
|
|
|
|
|
2011-08-26 01:46:07 +00:00
|
|
|
// update the ui widgetry
|
|
|
|
$('#torrent_inspector').toggle(visible);
|
2011-10-25 23:36:47 +00:00
|
|
|
$('#toolbar-inspector').toggleClass('selected',visible);
|
|
|
|
this.hideMobileAddressbar();
|
2011-10-26 04:14:39 +00:00
|
|
|
if (isMobileDevice) {
|
2011-08-26 01:46:07 +00:00
|
|
|
$('body').toggleClass('inspector_showing',visible);
|
|
|
|
} else {
|
2011-10-22 06:27:07 +00:00
|
|
|
var w = visible ? $('#torrent_inspector').outerWidth() + 1 + 'px' : '0px';
|
2011-08-26 01:46:07 +00:00
|
|
|
$('#torrent_container')[0].style.right = w;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** FILTER
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
refilterSoon: function()
|
|
|
|
{
|
2011-08-31 04:39:24 +00:00
|
|
|
if (!this.refilterTimer) {
|
2011-09-14 05:10:51 +00:00
|
|
|
var tr = this,
|
|
|
|
callback = function(){tr.refilter(false);},
|
|
|
|
msec = 100;
|
|
|
|
this.refilterTimer = setTimeout(callback, msec);
|
2011-08-31 04:39:24 +00:00
|
|
|
}
|
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-09-14 05:10:51 +00:00
|
|
|
list = this.elements.torrent_list,
|
2011-08-30 21:27:30 +00:00
|
|
|
old_sel_count = $(list).children('.selected').length;
|
|
|
|
|
2011-11-13 18:04:29 +00:00
|
|
|
this.updateFilterSelect();
|
|
|
|
|
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-09-03 07:10:03 +00:00
|
|
|
e = [];
|
|
|
|
for (i=0; row=dirty_rows[i]; ++i)
|
|
|
|
e.push (row.getElement());
|
2011-08-31 16:23:38 +00:00
|
|
|
$(e).detach();
|
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-31 16:23:38 +00:00
|
|
|
e = row.getElement();
|
|
|
|
e.row = row;
|
2011-08-27 21:35:19 +00:00
|
|
|
dirty_rows.push(row);
|
2011-09-03 07:10:03 +00:00
|
|
|
$(e).click($.proxy(this.onRowClicked,this));
|
|
|
|
$(e).dblclick($.proxy(this.toggleInspector,this));
|
2011-08-27 21:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
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;
|
2011-09-14 15:32:12 +00:00
|
|
|
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-09-03 07:29:53 +00:00
|
|
|
e = []
|
2011-09-03 07:10:03 +00:00
|
|
|
for (i=0; row=rows[i]; ++i)
|
2011-09-03 07:29:53 +00:00
|
|
|
e.push(row.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();
|
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-11-13 18:04:29 +00:00
|
|
|
onFilterModeClicked: function(ev)
|
2008-07-10 23:57:46 +00:00
|
|
|
{
|
2011-11-13 18:04:29 +00:00
|
|
|
this.setFilterMode($('#filter-mode').val());
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
2008-07-10 23:57:46 +00:00
|
|
|
|
2011-11-13 18:04:29 +00:00
|
|
|
onFilterTrackerClicked: function(ev)
|
2011-08-24 02:04:35 +00:00
|
|
|
{
|
2011-11-13 18:04:29 +00:00
|
|
|
var tracker = $('#filter-tracker').val();
|
|
|
|
this.setFilterTracker(tracker==='all' ? null : tracker);
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setFilterTracker: function(domain)
|
|
|
|
{
|
|
|
|
// update which tracker is selected in the popup
|
2011-09-14 15:32:12 +00:00
|
|
|
var key = domain ? this.getReadableDomain(domain) : 'all',
|
|
|
|
id = '#show-tracker-' + key;
|
2011-08-24 02:04:35 +00:00
|
|
|
$(id).addClass('selected').siblings().removeClass('selected');
|
|
|
|
|
2011-09-14 15:32:12 +00:00
|
|
|
this.filterTracker = domain;
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2011-08-24 02:04:35 +00:00
|
|
|
},
|
|
|
|
|
2011-09-14 15:32:12 +00:00
|
|
|
// example: "tracker.ubuntu.com" returns "ubuntu.com"
|
2011-08-24 02:04:35 +00:00
|
|
|
getDomainName: function(host)
|
|
|
|
{
|
|
|
|
var dot = host.indexOf('.');
|
|
|
|
if (dot !== host.lastIndexOf('.'))
|
|
|
|
host = host.slice(dot+1);
|
|
|
|
return host;
|
|
|
|
},
|
|
|
|
|
2011-09-14 15:32:12 +00:00
|
|
|
// example: "ubuntu.com" returns "Ubuntu"
|
2011-08-24 02:04:35 +00:00
|
|
|
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();
|
2011-09-28 18:06:04 +00:00
|
|
|
for (var i=0, torrent; torrent=torrents[i]; ++i)
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
var names = [];
|
2011-08-25 23:06:41 +00:00
|
|
|
var trackers = torrent.getTrackers();
|
2011-09-28 18:06:04 +00:00
|
|
|
for (var j=0, tracker; tracker=trackers[j]; ++j)
|
|
|
|
{
|
|
|
|
var uri, announce = tracker.announce;
|
|
|
|
|
|
|
|
if (announce in this.uriCache)
|
|
|
|
uri = this.uriCache[announce];
|
|
|
|
else {
|
|
|
|
uri = this.uriCache[announce] = parseUri (announce);
|
|
|
|
uri.domain = this.getDomainName (uri.host);
|
|
|
|
uri.name = this.getReadableDomain (uri.domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(uri.name in ret))
|
|
|
|
ret[uri.name] = { 'uri': uri,
|
|
|
|
'domain': uri.domain,
|
|
|
|
'count': 0 };
|
|
|
|
|
|
|
|
if (names.indexOf(uri.name) === -1)
|
|
|
|
names.push(uri.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
|
2011-10-23 17:10:44 +00:00
|
|
|
$("#compact-button").toggleClass('selected',compact);
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
// update the ui: torrent list
|
|
|
|
this.torrentRenderer = compact ? new TorrentRendererCompact()
|
|
|
|
: new TorrentRendererFull();
|
2011-08-27 21:35:19 +00:00
|
|
|
this.refilter(true);
|
2011-09-14 16:29:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** Statistics
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
// turn the periodic ajax stats refresh on & off
|
|
|
|
togglePeriodicStatsRefresh: function(enabled) {
|
|
|
|
clearInterval(this.statsInterval);
|
|
|
|
delete this.statsInterval;
|
|
|
|
if (enabled) {
|
|
|
|
var callback = $.proxy(this.loadDaemonStats,this),
|
|
|
|
msec = 5000;
|
|
|
|
this.statsInterval = setInterval(callback, msec);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
loadDaemonStats: function(async) {
|
|
|
|
this.remote.loadDaemonStats(function(data) {
|
|
|
|
this.updateStats(data['arguments']);
|
|
|
|
}, this, async);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Process new session stats from the server
|
|
|
|
updateStats: function(stats)
|
|
|
|
{
|
|
|
|
var s, ratio,
|
|
|
|
fmt = Transmission.fmt;
|
|
|
|
|
|
|
|
s = stats["current-stats"];
|
|
|
|
ratio = Math.ratio(s.uploadedBytes,s.downloadedBytes);
|
|
|
|
$('#stats-session-uploaded').html(fmt.size(s.uploadedBytes));
|
|
|
|
$('#stats-session-downloaded').html(fmt.size(s.downloadedBytes));
|
|
|
|
$('#stats-session-ratio').html(fmt.ratioString(ratio));
|
|
|
|
$('#stats-session-duration').html(fmt.timeInterval(s.secondsActive));
|
|
|
|
|
|
|
|
s = stats["cumulative-stats"];
|
|
|
|
ratio = Math.ratio(s.uploadedBytes,s.downloadedBytes);
|
|
|
|
$('#stats-total-count').html(s.sessionCount + " times");
|
|
|
|
$('#stats-total-uploaded').html(fmt.size(s.uploadedBytes));
|
|
|
|
$('#stats-total-downloaded').html(fmt.size(s.downloadedBytes));
|
|
|
|
$('#stats-total-ratio').html(fmt.ratioString(ratio));
|
|
|
|
$('#stats-total-duration').html(fmt.timeInterval(s.secondsActive));
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
showStatsDialog: function() {
|
|
|
|
this.loadDaemonStats();
|
|
|
|
this.hideMobileAddressbar();
|
|
|
|
this.togglePeriodicStatsRefresh(true);
|
|
|
|
$('#stats-dialog').dialog({
|
2011-09-15 05:27:22 +00:00
|
|
|
close: $.proxy(this.onStatsDialogClosed,this),
|
|
|
|
show: 'fade',
|
|
|
|
hide: 'fade',
|
|
|
|
title: 'Statistics'
|
2011-09-14 16:29:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onStatsDialogClosed: function() {
|
|
|
|
this.hideMobileAddressbar();
|
|
|
|
this.togglePeriodicStatsRefresh(false);
|
2008-07-10 23:57:46 +00:00
|
|
|
}
|
|
|
|
};
|