/* * Copyright © Dave Perrett and Malcolm Jarvis * This code is licensed under the GPL version 2. * For details, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Class Transmission */ function Transmission(){ this.initialize(); } Transmission.prototype = { /*-------------------------------------------- * * C O N S T R U C T O R * *--------------------------------------------*/ initialize: function() { // Before we do anything, browser compatability test if ($.browser.msie) { $('div.torrent_footer').hide(); $('div#unsupported_browser').show(); return; } // Initialize the helper classes this.remote = new TransmissionRemote(this); // Initialize the implementation fields this._current_search = ''; this._torrents = [ ]; this._rows = [ ]; // Initialize the clutch preferences Prefs.getClutchPrefs( this ); this.preloadImages(); // Set up user events $('#pause_all_link').bind('click', this.stopAllClicked ); $('#resume_all_link').bind('click', this.startAllClicked); $('#pause_selected_link').bind('click', this.stopSelectedClicked ); $('#resume_selected_link').bind('click', this.startSelectedClicked); $('#remove_link').bind('click', this.removeClicked); $('#filter_all_link').parent().bind('click', this.showAllClicked); $('#filter_downloading_link').parent().bind('click', this.showDownloadingClicked); $('#filter_seeding_link').parent().bind('click', this.showSeedingClicked); $('#filter_paused_link').parent().bind('click', this.showPausedClicked); $('#prefs_save_button').bind('click', this.savePrefsClicked); $('#prefs_cancel_button').bind('click', this.cancelPrefsClicked); $('#inspector_tab_info').bind('click', this.inspectorTabClicked); $('#inspector_tab_activity').bind('click', this.inspectorTabClicked); if (iPhone) { $('#torrent_inspector').bind('click', this.hideInspector); $('#preferences_link').bind('click', this.releaseClutchPreferencesButton); } else { $(document).bind('keydown', this.keyDown); $('#torrent_container').bind('click', this.deselectAll); $('#open_link').bind('click', this.openTorrentClicked); $('#filter_toggle_link').bind('click', this.toggleFilterClicked); $('#inspector_link').bind('click', this.toggleInspectorClicked); $('#upload_confirm_button').bind('click', this.confirmUploadClicked); $('#upload_cancel_button').bind('click', this.cancelUploadClicked); this.setupSearchBox(); this.createContextMenu(); this.createSettingsMenu(); } // Setup the preference box this.setupPrefConstraints(); // Setup the prefs gui this.initializeSettings( ); // Get preferences & torrents from the daemon this.remote.loadDaemonPrefs( ); this.remote.loadTorrents( ); this.togglePeriodicRefresh( true ); }, preloadImages: function() { if (iPhone) { this.loadImages( 'images/buttons/info_activity.png', 'images/buttons/info_general.png', 'images/buttons/toolbar_buttons.png', 'images/graphics/filter_bar.png', 'images/graphics/iphone_chrome.png', 'images/graphics/logo.png', 'images/progress/progress.png' ); } else { this.loadImages( 'images/buttons/info_activity.png', 'images/buttons/info_general.png', 'images/buttons/tab_backgrounds.png', 'images/buttons/toolbar_buttons.png', 'images/buttons/torrent_buttons.png', 'images/graphics/chrome.png', 'images/graphics/filter_bar.png', 'images/graphics/logo.png', 'images/graphics/transfer_arrows.png', 'images/progress/progress.png' ); } }, loadImages: function() { for(var i = 0; i").attr("src", arguments[i]); } }, /* * Set up the preference validation */ setupPrefConstraints: function() { // only allow integers for speed limit & port options $('div.preference input[@type=text]:not(#download_location)').blur( function() { this.value = this.value.replace(/[^0-9]/gi, ''); if (this.value == '') { if ($(this).is('#refresh_rate')) { this.value = 5; } else { this.value = 0; } } }); }, /* * Load the clutch prefs and init the GUI according to those prefs */ initializeSettings: function( ) { Prefs.getClutchPrefs( this ); // iPhone conditions in the section allow us to not // include transmenu js to save some bandwidth; if we // start using prefs on iPhone we need to weed // transmenu refs out of that too. $('#filter_' + this[Prefs._FilterMode] + '_link').parent().addClass('selected'); if (!iPhone) $('#sort_by_' + this[Prefs._SortMethod] ).selectMenuItem(); if (!iPhone && ( this[Prefs._SortDirection] == Prefs._SortDescending ) ) $('#reverse_sort_order').selectMenuItem(); if( this[Prefs._ShowFilter] ) this.showFilter( ); if( this[Prefs._ShowInspector] ) this.showInspector( ); }, /* * Set up the search box */ setupSearchBox: function() { var tr = this; var search_box = $('#torrent_search'); search_box.bind('keyup click', {transmission: this}, function(event) { tr.setSearch(this.value); }); if (!$.browser.safari) { (this).addClass('blur'); search_box[0].value = 'Filter'; search_box.bind('blur', {transmission: this}, function(event) { if (this.value == '') { $(this).addClass('blur'); this.value = 'Filter'; tr.setSearch(null); } }).bind('focus', {}, function(event) { if ($(this).is('.blur')) { this.value = ''; $(this).removeClass('blur'); } }); } }, contextStopSelected: function( ) { transmission.stopSelectedTorrents( ); }, contextStartSelected: function( ) { transmission.startSelectedTorrents( ); }, contextRemoveSelected: function( ) { transmission.removeSelectedTorrents( ); }, contextToggleInspector: function( ) { transmission.toggleInspector( ); }, contextSelectAll: function( ) { transmission.selectAll( true ); }, contextDeselectAll: function( ) { transmission.deselectAll( true ); }, /* * Create the torrent right-click menu */ createContextMenu: function() { var bindings = { context_pause_selected: this.contextStopSelected, context_resume_selected: this.contextStartSelected, context_remove: this.contextRemoveSelected, context_toggle_inspector: this.contextToggleInspector, context_select_all: this.contextSelectAll, context_deselect_all: this.contextDeselectAll }; // 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, boundingBottomPad: 5 }); }, /* * Create the footer settings menu */ createSettingsMenu: function() { $('#settings_menu').transMenu({ selected_char: '✔', direction: 'up', onClick: this.processSettingsMenuEvent }); $('#unlimited_download_rate').selectMenuItem(); $('#unlimited_upload_rate').selectMenuItem(); }, /*-------------------------------------------- * * U T I L I T I E S * *--------------------------------------------*/ getAllTorrents: function() { return this._torrents; }, getVisibleTorrents: function() { var torrents = [ ]; for( var i=0, len=this._rows.length; i