diff options
Diffstat (limited to 'bandwagon/content/ui/feedsPaneController.js')
-rw-r--r-- | bandwagon/content/ui/feedsPaneController.js | 779 |
1 files changed, 0 insertions, 779 deletions
diff --git a/bandwagon/content/ui/feedsPaneController.js b/bandwagon/content/ui/feedsPaneController.js deleted file mode 100644 index af23cf7..0000000 --- a/bandwagon/content/ui/feedsPaneController.js +++ /dev/null @@ -1,779 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is bandwagon. - * - * The Initial Developer of the Original Code is - * David McNamara. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -Bandwagon.Controller.FeedsPane = new function() -{ - this.initialized = false; - this.initializedBindings = false; - - this.preferredFeed = null; - - this.elemBandwagonFeeds = null; - this.elemBandwagonFeedItems = null; - this.elemBandwagonButtonViewSite = null; - this.elemBandwagonButtonUpdate = null; - this.elemBandwagonButtonRemove = null; - this.elemBandwagonFeedTitle = null; - this.elemBandwagonFeedDescription = null; - this.elemBandwagonFeedsNotification = null; - this.elemBandwagonFeedDeck = null; - this.elemBandwagonFeedHeader = null; - this.stringBundle = null; - - this.previewNotificationVal = "bandwagon-feed-preview"; -} - -Bandwagon.Controller.FeedsPane.init = function() -{ - if (Bandwagon.Controller.FeedsPane.initialized == true) return; - - Bandwagon.Logger.debug("Initializing Bandwagon.Controller.FeedsPane"); - - this.elemBandwagonFeeds = document.getElementById("bandwagon-feeds-list"); - this.elemBandwagonFeedItems = document.getElementById("bandwagon-feeditems-list"); - this.elemBandwagonButtonViewSite = document.getElementById("bandwagon-button-viewsite"); - this.elemBandwagonButtonUpdate = document.getElementById("bandwagon-button-update"); - this.elemBandwagonButtonRemove = document.getElementById("bandwagon-button-remove"); - this.elemBandwagonFeedTitle = document.getElementById("bandwagon-feed-title"); - this.elemBandwagonFeedDescription = document.getElementById("bandwagon-feed-description"); - this.elemBandwagonFeedsNotification = document.getElementById("bandwagon-feeds-notification"); - this.elemBandwagonFeedDeck = document.getElementById("bandwagon-feed-deck"); - this.elemBandwagonFeedHeader = document.getElementById("bandwagon-feed-header"); - - Bandwagon.Controller.FeedsPane._repopulateFeedsList(); - Bandwagon.Controller.FeedsPane.invalidate(); - - this.elemBandwagonFeeds.addEventListener("select", Bandwagon.Controller.FeedsPane.doShowFeed, true); - this.elemBandwagonFeedItems.addEventListener("select", Bandwagon.Controller.FeedsPane.doExpandFeedItem, true); - - bandwagonService.registerFeedUpdateObserver(Bandwagon.Controller.FeedsPane.feedUpdateObserver); - bandwagonService.registerFeedListChangeObserver(Bandwagon.Controller.FeedsPane.feedListChangeObserver); - - Bandwagon.Preferences.addObserver(Bandwagon.Controller.FeedsPane.prefObserver); - Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService).addObserver(Bandwagon.Controller.FeedsPane.prefObserver, "nsPref:changed", false); -} - -/** - * Triggered when the user navigates to the feeds pane from a different view in the extensions manager - */ -Bandwagon.Controller.FeedsPane.onViewSelect = function() -{ - Bandwagon.Logger.debug("in Bandwagon.Controller.FeedsPane.onViewSelect()"); - - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem != null) - { - // make sure the expanded feed item is scrolled into view - var elemsFeedItemExpanded = Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.getElementsByTagName("bandwagonFeedItemExpanded"); - - if (elemsFeedItemExpanded && elemsFeedItemExpanded[0]) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.ensureElementIsVisible(elemsFeedItemExpanded[0]); - } - } -} - -Bandwagon.Controller.FeedsPane.bindingsReady = function() -{ - // the bindings are ready, do any final initialization - - if (Bandwagon.Controller.FeedsPane.initializedBindings == false) - { - Bandwagon.Controller.FeedsPane._selectPreferredFeed(); - Bandwagon.Controller.FeedsPane.initializedBindings = true; - } - - Bandwagon.Controller.FeedsPane.initialized = true; -} - -Bandwagon.Controller.FeedsPane.uninit = function() -{ - if (Bandwagon.Controller.FeedsPane.initialized != true) return; - - Bandwagon.Logger.debug("Uninitializing Bandwagon.Controller.FeedsPane"); - - Bandwagon.Controller.FeedsPane.initialized = false; - - bandwagonService.unregisterFeedUpdateObserver(Bandwagon.Controller.FeedsPane.feedUpdateObserver); - bandwagonService.unregisterFeedListChangeObserver(Bandwagon.Controller.FeedsPane.feedListChangeObserver); - - Bandwagon.Preferences.removeObserver(Bandwagon.Controller.FeedsPane.prefObserver); - - // now is a good time to save feeds to storage - if (Bandwagon.COMMIT_NOW) - bandwagonService.commitAll(); -} - -/** - * Updates the interface disabled-ness based on the state of the selected feed, etc. - */ -Bandwagon.Controller.FeedsPane.invalidate = function() -{ - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem == null) - { - Bandwagon.Controller.FeedsPane.elemBandwagonButtonViewSite.disabled = true; - Bandwagon.Controller.FeedsPane.elemBandwagonButtonUpdate.disabled = true; - Bandwagon.Controller.FeedsPane.elemBandwagonButtonRemove.disabled = true; - Bandwagon.Controller.FeedsPane.elemBandwagonFeedHeader.collapsed = true; - - Bandwagon.Controller.FeedsPane._repopulateFeedItemsList(null); - - var elemsBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.getElementsByTagName("bandwagonFeed"); - - if (elemsBandwagonFeed.length == 0) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 1; - } - else - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 0; - } - } - else - { - Bandwagon.Controller.FeedsPane.elemBandwagonButtonViewSite.disabled = false; - Bandwagon.Controller.FeedsPane.elemBandwagonButtonUpdate.disabled = false; - Bandwagon.Controller.FeedsPane.elemBandwagonButtonRemove.disabled = false; - Bandwagon.Controller.FeedsPane.elemBandwagonFeedHeader.collapsed = false; - - var feed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed; - - if (feed.status == feed.STATUS_LOADING) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 2; - } - else if (feed.status == feed.STATUS_LOADERROR) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 4; - } - else if (feed.hasFeedItem() == 0) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 3; - } - else - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 0; - } - } -} - -Bandwagon.Controller.FeedsPane.feedListChangeObserver = function() -{ - Bandwagon.Logger.debug("In Bandwagon.Controller.FeedsPane.feedListChangeObserver()"); - - Bandwagon.Controller.FeedsPane._repopulateFeedsList(); - Bandwagon.Controller.FeedsPane._selectPreferredFeed(); -} - -Bandwagon.Controller.FeedsPane.feedUpdateObserver = function(feed) -{ - if (feed == null) - { - Bandwagon.Logger.debug("In Bandwagon.Controller.FeedsPane.feedUpdateObserver() with feed <null>"); - } - else - { - Bandwagon.Logger.debug("In Bandwagon.Controller.FeedsPane.feedUpdateObserver() with feed '" + feed.url + "'"); - - // update the unread count for this feed - - const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - var elemsBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.getElementsByTagNameNS(XULNS, "bandwagonFeed"); - - for (var i=0; i<elemsBandwagonFeed.length; i++) - { - if (elemsBandwagonFeed[i].feed.equals(feed)) - { - elemsBandwagonFeed[i].unread = feed.getUnreadFeedItems().length; - break; - } - } - - // if this feed is currently selected, update the view - - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem && feed.equals(Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed)) - { - Bandwagon.Controller.FeedsPane._repopulateFeedItemsList(feed); - - // if this is a just arrived feed preview, show the notification box - if (feed.preview) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedsNotification.notificationsHidden = false; - setTimeout(Bandwagon.Controller.FeedsPane._createPreviewNotification, 200); - } - } - } - - Bandwagon.Controller.FeedsPane.invalidate(); -} - -Bandwagon.Controller.FeedsPane.doUpdateAll = function(event) -{ - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 2; - - bandwagonService.forceCheckAllForUpdates(); -} - -Bandwagon.Controller.FeedsPane.doSubscribe = function(event) -{ - Bandwagon.Controller.FeedsPane._openURL(Bandwagon.FEEDSPANE_DO_SUBSCRIBE_URL); -} - -Bandwagon.Controller.FeedsPane.doSettings = function(event) -{ - var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]. - getService(Components.interfaces.nsIPrefService); - var prefServiceCache = prefSvc.getBranch(null); - var instantApply = prefServiceCache.getBoolPref("browser.preferences.instantApply"); - var flags = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal"); - - var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); - var win = wm.getMostRecentWindow("Bandwagon:Settings"); - - if (win) - { - win.focus(); - } - else - { - window.openDialog("chrome://bandwagon/content/ui/settings.xul", - "bandwagonsettings", - flags); - } -} - -Bandwagon.Controller.FeedsPane.doViewSite = function(event) -{ - // TODO use url from feed - Bandwagon.Controller.FeedsPane._openURL("http://www.google.com/search?hl=en&q=bandwagon+view+site&btnG=Search"); -} - -Bandwagon.Controller.FeedsPane.doUpdate = function(event) -{ - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem == null) - return; - - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 2; - - var feed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed; - - if (feed == null) - return; - - bandwagonService.forceCheckForUpdates(feed); -} - -Bandwagon.Controller.FeedsPane.doRemove = function(event) -{ - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem == null) - return; - - var feed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed; - - if (feed == null) - return; - - bandwagonService.deleteFeed(feed); - - if (!feed.preview) - bandwagonService.unsubscribe(feed); -} - -Bandwagon.Controller.FeedsPane.doShowFeed = function() -{ - var feed = null; - - var selectedElemBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem; - - if (selectedElemBandwagonFeed != null) - { - feed = selectedElemBandwagonFeed.feed; - } - - // if feed == null, then display will be cleared - - // misc. ui - - Bandwagon.Controller.FeedsPane.elemBandwagonFeedTitle.setAttribute("value", (feed?(feed.name?feed.name:feed.url):"")); - - if (feed && feed.description != "") - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDescription.setAttribute("value", feed.description); - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDescription.removeAttribute("collsaped"); - } - else - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDescription.setAttribute("collapsed", true); - } - - // feed preview notification box - - if (feed && feed.preview && feed.status != feed.STATUS_LOADING) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedsNotification.notificationsHidden = false; - - // this needs to be in a seperate thread - setTimeout(Bandwagon.Controller.FeedsPane._createPreviewNotification, 500); - } - else - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedsNotification.notificationsHidden = true; - } - - // show items - - Bandwagon.Controller.FeedsPane._repopulateFeedItemsList(feed); - - // invalidate - - Bandwagon.Controller.FeedsPane.invalidate(); - - // show the loading dialog if needed - - if (feed && feed.status == feed.STATUS_LOADING) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedDeck.selectedIndex = 2; - } - - // set all items in this feed to be "read" - // if we've just opened this dialog, don't update the read count - - if (feed) - { - feed.setAllRead(); - - if (Bandwagon.Controller.FeedsPane.initialized) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.unread = 0; - } - } -} - -Bandwagon.Controller.FeedsPane.doExpandFeedItem = function(event) -{ - if (event) - event.preventDefault(); - - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem && Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem.nodeName == "bandwagonFeedItemExpanded") - { - return; - } - - var elemsFeedItemExpanded = Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.getElementsByTagName("bandwagonFeedItemExpanded"); - - for (var i=0; i<elemsFeedItemExpanded.length; i++) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.removeChild(elemsFeedItemExpanded[i]); - } - - var elemsFeedItem = Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.childNodes; - - for (var i=0; i<elemsFeedItem.length; i++) - { - elemsFeedItem[i].collapsed = false; - } - - var selectedElemBandwagonFeedItem = Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem; - - if (selectedElemBandwagonFeedItem != null && selectedElemBandwagonFeedItem.feedItem != null) - { - selectedElemBandwagonFeedItem.read = true; - - var feedItem = selectedElemBandwagonFeedItem.feedItem; - feedItem.read = true; - - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.unread = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed.getUnreadFeedItems().length; - - // collapse this, show the expanded binding - - const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - var elemBandwagonFeedItemExpanded = document.createElementNS(XULNS, "bandwagonFeedItemExpanded"); - - elemBandwagonFeedItemExpanded.feedItem = feedItem; - - try - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItemExpanded.setFeedItem(feedItem); - } catch (e) {} - - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.insertBefore(elemBandwagonFeedItemExpanded, selectedElemBandwagonFeedItem); - - selectedElemBandwagonFeedItem.collapsed = true; - } -} - -Bandwagon.Controller.FeedsPane.doMoreInfo = function(event) -{ - if (event) - event.preventDefault(); - - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems == null) - return; - - Bandwagon.Controller.FeedsPane._openURL(Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem.feedItem.learnmore); -} - -Bandwagon.Controller.FeedsPane.doAddToFirefox = function() -{ - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem == null) - return; - - var feedItem = Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem.feedItem; - - if (!isXPInstallEnabled()) - return; - - if (feedItem.eula && feedItem.eula != "") - { - var eula = { - name: feedItem.name, - text: feedItem.eula, - accepted: false - }; - - window.openDialog("chrome://mozapps/content/extensions/eula.xul", "_blank", - "chrome,dialog,modal,centerscreen,resizable=no", eula); - - if (!eula.accepted) - return; - } - - var installer = feedItem.getInstaller(Bandwagon.Util.getHostEnvironmentInfo().os); - - if (!installer) - { - Bandwagon.Logger.warn("No compatible os targets found."); - return; - } - - var params = []; - params[feedItem.name] = installer; - - // TODO do some user feedback here? - - var callback = function(url, status) - { - Bandwagon.Logger.info("Finished installing '" + url + "'; status = " + status); - - // TODO some user feedback here? - } - - InstallTrigger.install(params, callback); -} - -Bandwagon.Controller.FeedsPane.doUpgradeToFirefoxN = function(version) -{ - Bandwagon.Logger.info("in Bandwagon.Controller.FeedsPane.doUpgradeToFirefoxN() with version = " + version); - - Bandwagon.Controller.FeedsPane._openURL("http://www.mozilla.com/en-US/firefox/all.html"); -} - -Bandwagon.Controller.FeedsPane.doDownloadFirefoxNBeta = function(version) -{ - Bandwagon.Logger.info("in Bandwagon.Controller.FeedsPane.doDownloadFirefoxNBeta() with version = " + version); - - Bandwagon.Controller.FeedsPane._openURL("http://www.mozilla.com/en-US/firefox/all-beta.html"); -} - -Bandwagon.Controller.FeedsPane.doShowFeedPreview = function(feedURL) -{ - // this is executed when the browser overlay controller opens the EM window to subscribe to a new feed. - // i.e. after a custom bandwagonSubscribe is detected and handled - - Bandwagon.Logger.debug("In Bandwagon.Controller.FeedsPane.doShowFeedPreview() with feedURL = " + feedURL); - - // check if we already have this feed - - if (bandwagonService.feeds[feedURL]) - { - var feed = bandwagonService.feeds[feedURL]; - Bandwagon.Controller.FeedsPane.preferredFeed = feed; - //Bandwagon.Controller.FeedsPane._selectFeed(feed); - setTimeout(function() { Bandwagon.Controller.FeedsPane._selectFeed(feed); }, 500); - return; - } - - // add and select the feed - - var feed = bandwagonService.addPreviewFeed(feedURL); - //feed.status = feed.STATUS_LOADING; - - Bandwagon.Controller.FeedsPane.preferredFeed = feed; - setTimeout(function() { Bandwagon.Controller.FeedsPane._selectFeed(feed); }, 500); -} - -Bandwagon.Controller.FeedsPane._createPreviewNotification = function() -{ - if (!Bandwagon.Controller.FeedsPane.elemBandwagonFeedsNotification.getNotificationWithValue(Bandwagon.Controller.FeedsPane.previewNotificationVal)) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedsNotification.appendNotification - ( - Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("feedspane.this.is.only.a.preview"), - Bandwagon.Controller.FeedsPane.previewNotificationVal, - null, - Bandwagon.Controller.FeedsPane.elemBandwagonFeedsNotification.PRIORITY_WARNING_MEDIUM, - [ - { - accessKey: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("feedspane.dont.subscribe.accesskey"), - callback: Bandwagon.Controller.FeedsPane.doFeedPreviewDontSubscribe, - label: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("feedspane.dont.subscribe"), - popup: null - }, - { - accessKey: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("feedspane.subscribe.accesskey"), - callback: Bandwagon.Controller.FeedsPane.doFeedPreviewSubscribe, - label: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("feedspane.subscribe"), - popup: null - } - ] - ); - } -} - -Bandwagon.Controller.FeedsPane.doFeedPreviewDontSubscribe = function() -{ - Bandwagon.Logger.debug("in Bandwagon.Controller.FeedsPane.doFeedPreviewDontSubscribe()"); - - Bandwagon.Controller.FeedsPane.preferredFeed = null; - - Bandwagon.Controller.FeedsPane.doRemove(); -} - -Bandwagon.Controller.FeedsPane.doFeedPreviewSubscribe = function() -{ - Bandwagon.Logger.debug("in Bandwagon.Controller.FeedsPane.doFeedPreviewSubscribe()"); - - if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem == null) - return; - - var feed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed; - - if (feed == null) - return; - - bandwagonService.subscribe(feed); - - if (Bandwagon.COMMIT_NOW) - bandwagonService.commit(feed); - - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.preview = false; - Bandwagon.Controller.FeedsPane.doShowFeed(); -} - - -/** - * Refreshes the feed pane - */ -Bandwagon.Controller.FeedsPane.refresh = function() -{ - var selectedElemBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem; - - if (selectedElemBandwagonFeed != null) - { - feed = selectedElemBandwagonFeed.feed; - Bandwagon.Controller.FeedsPane._repopulateFeedItemsList(feed); - } - - Bandwagon.Controller.FeedsPane.invalidate(); -} - -Bandwagon.Controller.FeedsPane.prefObserver = -{ - observe: function(subject, topic, data) - { - if (topic != "nsPref:changed") - return; - - if (data.match(/feeditemsperpage/)) - { - Bandwagon.Controller.FeedsPane.refresh(); - } - } -} - -/** - * Function to select a feed ui programmatically based on its feed object. - */ -Bandwagon.Controller.FeedsPane._selectFeed = function(feed) -{ - // select the feed and show (feed == null clears the selection) - - if (feed == null) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.clearSelection(); - Bandwagon.Controller.FeedsPane.doShowFeed(); - return; - } - - // select the richlistitem - - const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - - var elemsBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.getElementsByTagNameNS(XULNS, "bandwagonFeed"); - var elemBandwagonFeed = null; - - for (var i=0; i<elemsBandwagonFeed.length; i++) - { - if (elemsBandwagonFeed[i].feed.equals(feed)) - { - elemBandwagonFeed = elemsBandwagonFeed[i]; - break; - } - } - - if (elemBandwagonFeed == null) - { - Bandwagon.Logger.warn("could not find a richlistitem to select"); - return; - } - - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectItem(elemBandwagonFeed); - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.ensureElementIsVisible(elemBandwagonFeed); - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.focus(); -} - -Bandwagon.Controller.FeedsPane._selectPreferredFeed = function() -{ - // select a feed - last selected or the first one - var elemsBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.getElementsByTagName("bandwagonFeed"); - - if (Bandwagon.Controller.FeedsPane.preferredFeed != null && bandwagonService.feeds[Bandwagon.Controller.FeedsPane.preferredFeed.url] != null) - { - Bandwagon.Logger.debug("selecting preferred feed (defined)"); - Bandwagon.Controller.FeedsPane._selectFeed(Bandwagon.Controller.FeedsPane.preferredFeed); - } - else if (elemsBandwagonFeed.length > 0) - { - Bandwagon.Logger.debug("selecting preferred feed (the first in the list)"); - Bandwagon.Controller.FeedsPane._selectFeed(elemsBandwagonFeed[0].feed); - } - else - { - Bandwagon.Logger.debug("preferred feed is none"); - Bandwagon.Controller.FeedsPane._selectFeed(null); - } -} - -Bandwagon.Controller.FeedsPane._repopulateFeedsList = function() -{ - //Bandwagon.Logger.debug("Bandwagon.Controller.FeedsPane: about to repopulate the feeds list"); - - // first clear the list - - while (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.hasChildNodes()) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.removeChild(Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.firstChild); - } - - // repopulate with feeds - - for (var id in bandwagonService.feeds) - { - var feed = bandwagonService.feeds[id]; - - if (feed == null) - return; - - const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - var elemBandwagonFeed = document.createElementNS(XULNS, "bandwagonFeed"); - elemBandwagonFeed.feed = feed; - elemBandwagonFeed.controller = Bandwagon.Controller.FeedsPane; - - Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.appendChild(elemBandwagonFeed); - } -} - -Bandwagon.Controller.FeedsPane._repopulateFeedItemsList = function(feed) -{ - // first clear the list - - while (Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.hasChildNodes()) - { - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.removeChild(Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.firstChild); - } - - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.clearSelection(); - - if (feed == null) - return; - - Bandwagon.Logger.debug("Bandwagon.Controller.FeedsPane: repopulating feed '" + feed.url + "'"); - - // sort by feedItem.dateAdded - - var feedItemsSorted = feed.getSortedFeedItems(); - - // repopulate with feed items - - var feedItemsPerPage = bandwagonService.getFeedItemsPerPage(feed); - const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - - for (var i=0; (i<feedItemsSorted.length&&i<feedItemsPerPage); i++) - { - var feedItem = feed.feedItems[feedItemsSorted[i].guid]; - - if (feedItem == null) - continue; - - var elemBandwagonFeedItem = document.createElementNS(XULNS, "bandwagonFeedItem"); - elemBandwagonFeedItem.feedItem = feedItem; - - Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.appendChild(elemBandwagonFeedItem); - } -} - -Bandwagon.Controller.FeedsPane._openURL = function(url) -{ - var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); - var mainWindow = wm.getMostRecentWindow("navigator:browser"); - - if (mainWindow) - { - var tab = mainWindow.getBrowser().addTab(url); - mainWindow.getBrowser().selectedTab = tab; - mainWindow.focus(); - } - else - { - window.open(url); - } -} - -// when this window closes, we do any uninit stuff - -window.addEventListener("unload", Bandwagon.Controller.FeedsPane.uninit, true); - |