diff options
Diffstat (limited to 'bandwagon/content/ui')
-rw-r--r-- | bandwagon/content/ui/bindings/bandwagon.css | 12 | ||||
-rw-r--r-- | bandwagon/content/ui/bindings/bandwagon.xml | 279 | ||||
-rw-r--r-- | bandwagon/content/ui/collectionsPaneController.js | 838 | ||||
-rw-r--r-- | bandwagon/content/ui/dialog.js | 4 | ||||
-rw-r--r-- | bandwagon/content/ui/feedsPaneController.js | 779 | ||||
-rw-r--r-- | bandwagon/content/ui/overlays/browserOverlay.xul | 22 | ||||
-rw-r--r-- | bandwagon/content/ui/overlays/browserOverlayController.js | 103 | ||||
-rw-r--r-- | bandwagon/content/ui/overlays/extensionsOverlay.xul | 150 | ||||
-rw-r--r-- | bandwagon/content/ui/overlays/extensionsOverlayController.js | 128 | ||||
-rw-r--r-- | bandwagon/content/ui/publish.xul | 19 | ||||
-rw-r--r-- | bandwagon/content/ui/publishController.js | 68 | ||||
-rw-r--r-- | bandwagon/content/ui/settings.xul | 296 | ||||
-rw-r--r-- | bandwagon/content/ui/settingsController.js | 439 |
13 files changed, 1855 insertions, 1282 deletions
diff --git a/bandwagon/content/ui/bindings/bandwagon.css b/bandwagon/content/ui/bindings/bandwagon.css index 1d012cc..7bb9f18 100644 --- a/bandwagon/content/ui/bindings/bandwagon.css +++ b/bandwagon/content/ui/bindings/bandwagon.css @@ -1,13 +1,13 @@ -bandwagonFeedItem { - -moz-binding: url("chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-feeditem"); +bandwagonAddon { + -moz-binding: url("chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-addon"); } -bandwagonFeedItemExpanded { - -moz-binding: url("chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-feeditem-expanded"); +bandwagonAddonExpanded { + -moz-binding: url("chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-addon-expanded"); } -bandwagonFeed { - -moz-binding: url("chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-feed"); +bandwagonCollection { + -moz-binding: url("chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-collection"); } bandwagonPublishButton { diff --git a/bandwagon/content/ui/bindings/bandwagon.xml b/bandwagon/content/ui/bindings/bandwagon.xml index 600d9f3..ac31bcf 100644 --- a/bandwagon/content/ui/bindings/bandwagon.xml +++ b/bandwagon/content/ui/bindings/bandwagon.xml @@ -44,7 +44,7 @@ xmlns:xbl="http://www.mozilla.org/xbl" xmlns:html="http://www.w3.org/1999/xhtml"> - <binding id="bandwagon-feed" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem"> + <binding id="bandwagon-collection" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem"> <resources> <stylesheet src="chrome://bandwagon/skin/extensionsOverlay.css"/> @@ -59,13 +59,13 @@ </content> <implementation> - <field name="feed"/> + <field name="collection"/> <field name="controller"/> <constructor> <![CDATA[ - if (this.feed) - this.setFeed(this.feed); + if (this.collection) + this.setCollection(this.collection); setTimeout(this.controller.bindingsReady, 100); ]]> @@ -86,7 +86,7 @@ onset="this.setAttribute('preview', val);" /> - <property name="editable" + <property name="writable" onget="return !document.getAnonymousElementByAttribute(this, 'anonid', 'star').collapsed;" onset="document.getAnonymousElementByAttribute(this, 'anonid', 'star').collapsed = !val;" /> @@ -96,16 +96,16 @@ onset="document.getAnonymousElementByAttribute(this, 'anonid', 'unread').value = val; document.getAnonymousElementByAttribute(this, 'anonid', 'unread').collapsed = (val == 0);" /> - <method name="setFeed"> - <parameter name="feed"/> + <method name="setCollection"> + <parameter name="collection"/> <body> <![CDATA[ - this.feed = feed; - this.name = (feed.name && feed.name !=""?feed.name:feed.url); - this.url = feed.url; - this.preview = feed.preview; - this.editable = feed.editable; - this.unread = feed.getUnreadFeedItems().length; + this.collection = collection; + this.name = (collection.name && collection.name !=""?collection.name:collection.resourceURL); + this.url = collection.resourceURL; + this.preview = collection.preview; + this.writable = collection.writable; + this.unread = collection.getUnreadAddons().length; ]]> </body> </method> @@ -114,14 +114,14 @@ </binding> - <binding id="bandwagon-feeditem" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem"> + <binding id="bandwagon-addon" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem"> <resources> <stylesheet src="chrome://bandwagon/skin/extensionsOverlay.css"/> </resources> <content> - <xul:stringbundle src="chrome://bandwagon/locale/bandwagonFeedItem.properties" + <xul:stringbundle src="chrome://bandwagon/locale/bandwagonAddon.properties" anonid="stringbundle"/> <xul:hbox flex="1"> @@ -144,13 +144,13 @@ </content> <implementation> - <field name="feedItem"/> + <field name="addon"/> <field name="_stringBundle">document.getAnonymousElementByAttribute(this, "anonid", "stringbundle");</field> <constructor> <![CDATA[ - if (this.feedItem) - this.setFeedItem(this.feedItem); + if (this.addon) + this.setAddon(this.addon); ]]> </constructor> @@ -197,15 +197,43 @@ </setter> </property> - <property name="author" - onget="return (document.getAnonymousElementByAttribute(this, 'anonid', 'author')?document.getAnonymousElementByAttribute(this, 'anonid', 'author').value:'')" - onset="if (document.getAnonymousElementByAttribute(this, 'anonid', 'author')) document.getAnonymousElementByAttribute(this, 'anonid', 'author').value = this._stringBundle.getFormattedString('bandwagon.feeditem.author', [val])" - /> + <property name="authors" + onget="return (document.getAnonymousElementByAttribute(this, 'anonid', 'author')?document.getAnonymousElementByAttribute(this, 'anonid', 'author').value:'')"> + <setter> + <![CDATA[ + if (document.getAnonymousElementByAttribute(this, 'anonid', 'authors')) + { + var authors = ""; + + if (!val || val.length == 0) + { + authors = "?"; + } + else + { + for each (var item in val) + { + authors += item + ", "; + } + if (authors.substring(authors.length-2) == ", ") + { + authors = authors.substring(0, authors.length-2); + } + } + + document.getAnonymousElementByAttribute(this, 'anonid', 'authors').value = this._stringBundle.getFormattedString('bandwagon.addon.author', [authors]); + } + ]]> + </setter> + </property> + + <!-- <property name="category" onget="return (document.getAnonymousElementByAttribute(this, 'anonid', 'category')?document.getAnonymousElementByAttribute(this, 'anonid', 'category').value:'')" - onset="if (document.getAnonymousElementByAttribute(this, 'anonid', 'category')) document.getAnonymousElementByAttribute(this, 'anonid', 'category').value = this._stringBundle.getFormattedString('bandwagon.feeditem.category', [val])" + onset="if (document.getAnonymousElementByAttribute(this, 'anonid', 'category')) document.getAnonymousElementByAttribute(this, 'anonid', 'category').value = this._stringBundle.getFormattedString('bandwagon.addon.category', [val])" /> + --> <property name="read" onget="return this.getAttribute('read')" @@ -226,36 +254,36 @@ if (diff < 60) { - sbString = "bandwagon.feeditem.added.justnow"; + sbString = "bandwagon.addon.added.justnow"; } else if (diff < 60 * 60) { - sbString = "bandwagon.feeditem.added.minute"; + sbString = "bandwagon.addon.added.minute"; sbVal = Math.ceil(diff/60); } else if (diff < 60 * 60 * 24) { - sbString = "bandwagon.feeditem.added.hour"; + sbString = "bandwagon.addon.added.hour"; sbVal = Math.floor(diff/60/60); } else if (diff < 60 * 60 * 24 * 7) { - sbString = "bandwagon.feeditem.added.day"; + sbString = "bandwagon.addon.added.day"; sbVal = Math.floor(diff/60/60/24); } else if (diff < 60 * 60 * 24 * 30) { - sbString = "bandwagon.feeditem.added.week"; + sbString = "bandwagon.addon.added.week"; sbVal = Math.floor(diff/60/60/24/7); } else if (diff < 60 * 60 * 24 * 356) { - sbString = "bandwagon.feeditem.added.month"; + sbString = "bandwagon.addon.added.month"; sbVal = Math.floor(diff/60/60/24/30); } else { - sbString = "bandwagon.feeditem.added.year"; + sbString = "bandwagon.addon.added.year"; sbVal = Math.floor(diff/60/60/24/356); } @@ -284,31 +312,31 @@ > <setter> <![CDATA[ - if (document.getAnonymousElementByAttribute(this, 'anonid', 'commentdesc')) document.getAnonymousElementByAttribute(this, 'anonid', 'commentdesc').firstChild.nodeValue = this._stringBundle.getFormattedString('bandwagon.feeditem.comment.description', [val.comment]); - if (document.getAnonymousElementByAttribute(this, 'anonid', 'commentauthor')) document.getAnonymousElementByAttribute(this, 'anonid', 'commentauthor').value = this._stringBundle.getFormattedString('bandwagon.feeditem.comment.author', [val.author]); + if (document.getAnonymousElementByAttribute(this, 'anonid', 'commentdesc')) document.getAnonymousElementByAttribute(this, 'anonid', 'commentdesc').firstChild.nodeValue = this._stringBundle.getFormattedString('bandwagon.addon.comment.description', [val.comment]); + if (document.getAnonymousElementByAttribute(this, 'anonid', 'commentauthor')) document.getAnonymousElementByAttribute(this, 'anonid', 'commentauthor').value = this._stringBundle.getFormattedString('bandwagon.addon.comment.author', [val.author]); ]]> </setter> </property> - <method name="setFeedItem"> - <parameter name="feedItem"/> + <method name="setAddon"> + <parameter name="addon"/> <body> <![CDATA[ - this.feedItem = feedItem; - this.name = feedItem.name; - this.guid = feedItem.guid; - this.summary = feedItem.summary; - this.description = feedItem.summary; // Use summary and not description - this.iconURL = feedItem.icon; - this.thumbnailURL = feedItem.thumbnail; - this.author = (feedItem.author?feedItem.author:"Unknown"); - this.category = (feedItem.category?feedItem.category:"Unknown"); - this.dateAdded = feedItem.dateAdded; - this.read = feedItem.read; - - if (feedItem.comments.length > 0) + this.addon = addon; + this.name = addon.name; + this.guid = addon.guid; + this.summary = addon.summary; + this.description = addon.summary; // Use summary and not description + this.iconURL = addon.icon; + this.thumbnailURL = addon.thumbnail; + this.authors = addon.authors; + //this.category = (addon.category?addon.category:"Unknown"); + this.dateAdded = addon.dateAdded; + this.read = addon.read; + + if (addon.comments.length > 0) { - this.comment = feedItem.comments[0]; + this.comment = addon.comments[0]; } else { @@ -319,7 +347,7 @@ } } - var canInstall = feedItem.canInstall(Bandwagon.Util.getHostEnvironmentInfo()); + var canInstall = addon.canInstall(Bandwagon.Util.getHostEnvironmentInfo()); this.showVersionHelper(canInstall.type, canInstall.requiredVersion); if (document.getAnonymousElementByAttribute(this, 'anonid', 'publish')) @@ -339,7 +367,7 @@ if (publishButton) { publishButton.emailAddresses = Bandwagon.Controller.ExtensionsOverlay._getEmailAddresses(); - publishButton.writableFeeds = Bandwagon.Controller.ExtensionsOverlay._getWritableFeeds(); + publishButton.writableCollections = Bandwagon.Controller.ExtensionsOverlay._getWritableCollections(); publishButton.invalidate(); } ]]> @@ -354,44 +382,44 @@ if (document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefox') && document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning')) { - if (type == Bandwagon.Model.FeedItem.INSTALL_YES) + if (type == Bandwagon.Model.Addon.INSTALL_YES) { document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefox').disabled = false; document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning').collapsed = true; } else { - if (type == Bandwagon.Model.FeedItem.INSTALL_NO_ADDON_IS_FOR_OLDER_VERSION) + if (type == Bandwagon.Model.Addon.INSTALL_NO_ADDON_IS_FOR_OLDER_VERSION) { document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning').appendChild( - document.createTextNode(this._stringBundle.getString("bandwagon.feeditem.olderversionsoffirefox"))); + document.createTextNode(this._stringBundle.getString("bandwagon.addon.olderversionsoffirefox"))); } - else if (type == Bandwagon.Model.FeedItem.INSTALL_NO_UPGRADE_TO_USE_THIS_VERSION) + else if (type == Bandwagon.Model.Addon.INSTALL_NO_UPGRADE_TO_USE_THIS_VERSION) { var atffwl = document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarninglink'); - atffwl.value = this._stringBundle.getFormattedString("bandwagon.feeditem.upgradetofirefoxn1", [version]); + atffwl.value = this._stringBundle.getFormattedString("bandwagon.addon.upgradetofirefoxn1", [version]); atffwl.collapsed = false; - atffwl.addEventListener("click", function() { Bandwagon.Controller.FeedsPane.doUpgradeToFirefoxN(version); }, true); + atffwl.addEventListener("click", function() { Bandwagon.Controller.CollectionsPane.doUpgradeToFirefoxN(version); }, true); document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning').appendChild( - document.createTextNode(this._stringBundle.getString("bandwagon.feeditem.upgradetofirefoxn2"))); + document.createTextNode(this._stringBundle.getString("bandwagon.addon.upgradetofirefoxn2"))); } - else if (type == Bandwagon.Model.FeedItem.INSTALL_NO_MUST_DOWNLOAD_BETA) + else if (type == Bandwagon.Model.Addon.INSTALL_NO_MUST_DOWNLOAD_BETA) { document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning').appendChild( - document.createTextNode(this._stringBundle.getFormattedString("bandwagon.feeditem.requiresfirefoxbeta1", [version]))); + document.createTextNode(this._stringBundle.getFormattedString("bandwagon.addon.requiresfirefoxbeta1", [version]))); var atffwl = document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarninglink'); - atffwl.value = this._stringBundle.getFormattedString("bandwagon.feeditem.requiresfirefoxbeta2", [version]); + atffwl.value = this._stringBundle.getFormattedString("bandwagon.addon.requiresfirefoxbeta2", [version]); atffwl.collapsed = false; - atffwl.addEventListener("click", function() { Bandwagon.Controller.FeedsPane.doDownloadFirefoxNBeta(version); }, true); + atffwl.addEventListener("click", function() { Bandwagon.Controller.CollectionsPane.doDownloadFirefoxNBeta(version); }, true); document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning').appendChild(atffwl); } - else if (type == Bandwagon.Model.FeedItem.INSTALL_NO_NOT_COMPATIBLE_OS) + else if (type == Bandwagon.Model.Addon.INSTALL_NO_NOT_COMPATIBLE_OS) { document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefoxwarning').appendChild( - document.createTextNode(this._stringBundle.getFormattedString("bandwagon.feeditem.notcompatible", [version]))); + document.createTextNode(this._stringBundle.getFormattedString("bandwagon.addon.notcompatible", [version]))); } document.getAnonymousElementByAttribute(this, 'anonid', 'addtofirefox').disabled = true; @@ -447,10 +475,10 @@ </implementation> </binding> - <binding id="bandwagon-feeditem-expanded" extends="chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-feeditem"> + <binding id="bandwagon-addon-expanded" extends="chrome://bandwagon/content/ui/bindings/bandwagon.xml#bandwagon-addon"> <content> - <xul:stringbundle src="chrome://bandwagon/locale/bandwagonFeedItem.properties" + <xul:stringbundle src="chrome://bandwagon/locale/bandwagonAddon.properties" anonid="stringbundle"/> <xul:hbox flex="1"> @@ -466,15 +494,17 @@ <xul:label anonid="dateadded"/> </xul:hbox> <xul:hbox anonid="byline" flex="1"> - <xul:label anonid="author"/> + <xul:label anonid="authors"/> <xul:spacer flex="1"/> - <xul:label anonid="category"/> + <!--<xul:label anonid="category"/>--> </xul:hbox> + <xul:label anonid="commentauthor" flex="1"/> + <xul:description anonid="commentdesc"> </xul:description> </xul:vbox> </xul:hbox> <xul:hbox align="stretch" anonid="fulldesc" - class="feed-item-details" + class="collection-item-details" flex="1"> <xul:vbox pack="start"> <xul:hbox anonid="bandwagonThumbnailContainer" @@ -485,15 +515,13 @@ </xul:hbox> </xul:vbox> <xul:vbox flex="1"> - <xul:description anonid="commentdesc"> </xul:description> - <xul:label anonid="commentauthor" flex="1" class="right"/> <xul:description anonid="description"> - <xul:label anonid="learnmore" class="text-link" value="&feeditem.moreinfo;" onclick="Bandwagon.Controller.FeedsPane.doMoreInfo()"/> + <xul:label anonid="learnmore" class="text-link" value="&addon.moreinfo;" onclick="Bandwagon.Controller.CollectionsPane.doMoreInfo()"/> </xul:description> <xul:spacer flex="1"/> <xul:hbox pack="end" class="publishButton"> <xul:bandwagonPublishButton anonid="publish" label="&publishto.label;"/> - <xul:button anonid="addtofirefox" label="&feeditem.addtofirefox;" oncommand="Bandwagon.Controller.FeedsPane.doAddToFirefox()"/> + <xul:button anonid="addtofirefox" label="&addon.addtofirefox;" oncommand="Bandwagon.Controller.CollectionsPane.doAddToFirefox()"/> </xul:hbox> <xul:description anonid="addtofirefoxwarning" class="right"> <xul:label anonid="addtofirefoxwarninglink" class="text-link" collapsed="true"/> @@ -530,43 +558,32 @@ <content> <xul:button label="&publishto.label;" type="menu" - anonid="publishButton1" + anonid="publishButton" class="publishButton" collapsed="true"> - <xul:menupopup anonid="writableFeeds"> - <!-- writable feeds go here --> - <xul:menuseparator anonid="writableFeedSeparator"/> - <xul:menu label="&email.address.label;" anonid="emailAddressMenu1"> - <xul:menupopup anonid="emailAddresses1"> + <xul:menupopup anonid="writableCollections"> + <!-- writable collections go here --> + <xul:menuitem label="&new.collection.label;" oncommand="Bandwagon.Controller.ExtensionsOverlay.doNewCollection();" anonid="newCollection"/> + <xul:menuseparator anonid="writableCollectionSeparator"/> + <xul:menu label="&email.address.label;" anonid="emailAddressMenu"> + <xul:menupopup anonid="emailAddresses"> <!-- email addresses go here --> - <xul:menuseparator anonid="emailAddressSeparator1"/> + <xul:menuseparator anonid="emailAddressSeparator"/> <xul:menuitem label="&new.email.address.label;" oncommand="Bandwagon.Controller.ExtensionsOverlay.doAddNewShareEmail();"/> </xul:menupopup> </xul:menu> </xul:menupopup> </xul:button> - <xul:button label="&publishto.label;" - type="menu" - anonid="publishButton2" - class="publishButton" - collapsed="true"> - <xul:menupopup anonid="emailAddresses2"> - <!-- email addresses go here --> - <xul:menuseparator anonid="emailAddressSeparator2"/> - <xul:menuitem label="&new.email.address.label;"/> - </xul:menupopup> - </xul:button> - </content> <implementation> <field name="emailAddresses"/> - <field name="writableFeeds"/> + <field name="writableCollections"/> <constructor> <![CDATA[ - if (this.emailAddresses && this.writableFeeds) + if (this.emailAddresses && this.writableCollections) { this.invalidate(); } @@ -578,21 +595,18 @@ <![CDATA[ const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - var elemWritableFeedsPopup = document.getAnonymousElementByAttribute(this, "anonid", "writableFeeds"); - var elemWritableFeedSeparator = document.getAnonymousElementByAttribute(this, "anonid", "writableFeedSeparator"); - var elemEmailAddressesPopup1 = document.getAnonymousElementByAttribute(this, "anonid", "emailAddresses1"); - var elemEmailAddressesPopup2 = document.getAnonymousElementByAttribute(this, "anonid", "emailAddresses2"); - var elemEmailAddressSeparator1 = document.getAnonymousElementByAttribute(this, "anonid", "emailAddressSeparator1"); - var elemEmailAddressSeparator2 = document.getAnonymousElementByAttribute(this, "anonid", "emailAddressSeparator2"); - var elemEmailAddressMenu1 = document.getAnonymousElementByAttribute(this, "anonid", "emailAddressMenu1"); - var elemEmailAddressMenu2 = document.getAnonymousElementByAttribute(this, "anonid", "emailAddressMenu2"); - var elemPublishButton1 = document.getAnonymousElementByAttribute(this, "anonid", "publishButton1"); - var elemPublishButton2 = document.getAnonymousElementByAttribute(this, "anonid", "publishButton2"); + var elemWritableCollectionsPopup = document.getAnonymousElementByAttribute(this, "anonid", "writableCollections"); + var elemWritableCollectionSeparator = document.getAnonymousElementByAttribute(this, "anonid", "writableCollectionSeparator"); + var elemEmailAddressesPopup = document.getAnonymousElementByAttribute(this, "anonid", "emailAddresses"); + var elemEmailAddressSeparator = document.getAnonymousElementByAttribute(this, "anonid", "emailAddressSeparator"); + var elemEmailAddressMenu = document.getAnonymousElementByAttribute(this, "anonid", "emailAddressMenu"); + var elemPublishButton = document.getAnonymousElementByAttribute(this, "anonid", "publishButton"); + var elemNewCollection = document.getAnonymousElementByAttribute(this, "anonid", "newCollection"); // populate the email address menu - var activeEmailMenu = (this.writableFeeds.length==0?elemEmailAddressesPopup2:elemEmailAddressesPopup1); - var activeEmailAddressSeparator = (this.writableFeeds.length==0?elemEmailAddressSeparator2:elemEmailAddressSeparator1); + var activeEmailMenu = elemEmailAddressesPopup; + var activeEmailAddressSeparator = elemEmailAddressSeparator; if (this.emailAddresses.length) { @@ -621,40 +635,47 @@ activeEmailAddressSeparator.collapsed = true; } - if (this.writableFeeds.length) + // populate the collections menu + + function createAddToCollectionCallbackFunction(collection) { - // populate the feeds menu + return function() { Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection(collection); } + } - function createFeedCallbackFunction(feed) - { - return function() { Bandwagon.Controller.ExtensionsOverlay.doPublishToFeed(feed); } - } + function createRemoveFromCollectionCallbackFunction(collection) + { + return function() { Bandwagon.Controller.ExtensionsOverlay.doRemoveFromCollection(collection); } + } - for (var i=0; i<this.writableFeeds.length; i++) - { - var feed = this.writableFeeds[i]; + for (var i=0; i<this.writableCollections.length; i++) + { + var collection = this.writableCollections[i]; - if (document.getAnonymousElementByAttribute(this, "anonid", "bandwagon-feed-" + feed.url)) - continue; + if (document.getAnonymousElementByAttribute(this, "anonid", "bandwagon-collection-" + collection.resourceURL)) + continue; - var callback = createFeedCallbackFunction(feed); + var callbackAdd = createAddToCollectionCallbackFunction(collection); + var callbackRemove = createRemoveFromCollectionCallbackFunction(collection); - var elemWritableFeed = document.createElementNS(XULNS, "menuitem"); - elemWritableFeed.setAttribute("label", (feed.name?feed.name:feed.url)); - elemWritableFeed.setAttribute("anonid", "bandwagon-feed-" + feed.url); - elemWritableFeed.addEventListener("command", callback, true); + var elemWritableCollection = document.createElementNS(XULNS, "menuitem"); + elemWritableCollection.setAttribute("label", (collection.name?collection.name:collection.resourceURL)); + elemWritableCollection.setAttribute("anonid", "bandwagon-collection-" + collection.resourceURL); - elemWritableFeedsPopup.insertBefore(elemWritableFeed, elemWritableFeedSeparator); + if (collection.__containsCurrentlySelectedExtension) + { + elemWritableCollection.setAttribute("checked", "true"); + elemWritableCollection.setAttribute("autocheck", "false"); + elemWritableCollection.addEventListener("command", callbackRemove, true); + } + else + { + elemWritableCollection.addEventListener("command", callbackAdd, true); } - elemPublishButton1.collapsed = false; - elemPublishButton2.collapsed = true; - } - else - { - elemPublishButton1.collapsed = true; - elemPublishButton2.collapsed = false; + elemWritableCollectionsPopup.insertBefore(elemWritableCollection, elemNewCollection); } + + elemPublishButton.collapsed = false; ]]> </body> </method> diff --git a/bandwagon/content/ui/collectionsPaneController.js b/bandwagon/content/ui/collectionsPaneController.js new file mode 100644 index 0000000..017e4fe --- /dev/null +++ b/bandwagon/content/ui/collectionsPaneController.js @@ -0,0 +1,838 @@ +/* ***** 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 + * Mozilla Corporation. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): David McNamara + * + * 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.CollectionsPane = new function() +{ + this.initialized = false; + this.initializedBindings = false; + + this.preferredCollection = null; + + this.elemBandwagonCollections = null; + this.elemBandwagonAddons = null; + this.elemBandwagonButtonViewSite = null; + //this.elemBandwagonButtonUpdate = null; + this.elemBandwagonButtonRemove = null; + this.elemBandwagonCollectionTitle = null; + this.elemBandwagonCollectionDescription = null; + this.elemBandwagonCollectionsNotification = null; + this.elemBandwagonCollectionDeck = null; + this.elemBandwagonCollectionHeader = null; + this.stringBundle = null; + + //this.previewNotificationVal = "bandwagon-collection-preview"; +} + +Bandwagon.Controller.CollectionsPane.init = function() +{ + if (Bandwagon.Controller.CollectionsPane.initialized == true) return; + + Bandwagon.Logger.debug("Initializing Bandwagon.Controller.CollectionsPane"); + + this.elemBandwagonCollections = document.getElementById("bandwagon-collections-list"); + this.elemBandwagonAddons = document.getElementById("bandwagon-addons-list"); + this.elemBandwagonButtonViewSite = document.getElementById("bandwagon-button-viewsite"); + //this.elemBandwagonButtonUpdate = document.getElementById("bandwagon-button-update"); + this.elemBandwagonButtonRemove = document.getElementById("bandwagon-button-remove"); + this.elemBandwagonExtensionsDeck = document.getElementById("bandwagon-extensions-deck"); + this.elemBandwagonCollectionTitle = document.getElementById("bandwagon-collection-title"); + this.elemBandwagonCollectionDescription = document.getElementById("bandwagon-collection-description"); + this.elemBandwagonCollectionsNotification = document.getElementById("bandwagon-collections-notification"); + this.elemBandwagonCollectionDeck = document.getElementById("bandwagon-collection-deck"); + this.elemBandwagonCollectionHeader = document.getElementById("bandwagon-collection-header"); + + Bandwagon.Controller.CollectionsPane._repopulateCollectionsList(); + Bandwagon.Controller.CollectionsPane.invalidate(); + + this.elemBandwagonCollections.addEventListener("select", Bandwagon.Controller.CollectionsPane.doShowCollection, true); + this.elemBandwagonAddons.addEventListener("select", Bandwagon.Controller.CollectionsPane.doExpandAddon, true); + + bandwagonService.registerCollectionUpdateObserver(Bandwagon.Controller.CollectionsPane.collectionUpdateObserver); + bandwagonService.registerCollectionListChangeObserver(Bandwagon.Controller.CollectionsPane.collectionListChangeObserver); + + Bandwagon.Preferences.addObserver(Bandwagon.Controller.CollectionsPane.prefObserver); + Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService).addObserver(Bandwagon.Controller.CollectionsPane.prefObserver, "nsPref:changed", false); +} + +/** + * Triggered when the user navigates to the collections pane from a different view in the extensions manager + */ +Bandwagon.Controller.CollectionsPane.onViewSelect = function() +{ + Bandwagon.Logger.debug("in Bandwagon.Controller.CollectionsPane.onViewSelect()"); + + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem != null) + { + // make sure the expanded collection item is scrolled into view + var elemsAddonExpanded = Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.getElementsByTagName("bandwagonAddonExpanded"); + + if (elemsAddonExpanded && elemsAddonExpanded[0]) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.ensureElementIsVisible(elemsAddonExpanded[0]); + } + } +} + +Bandwagon.Controller.CollectionsPane.bindingsReady = function() +{ + // the bindings are ready, do any final initialization + + if (Bandwagon.Controller.CollectionsPane.initializedBindings == false) + { + Bandwagon.Controller.CollectionsPane._selectPreferredCollection(); + Bandwagon.Controller.CollectionsPane.initializedBindings = true; + } + + Bandwagon.Controller.CollectionsPane.initialized = true; +} + +Bandwagon.Controller.CollectionsPane.uninit = function() +{ + if (Bandwagon.Controller.CollectionsPane.initialized != true) return; + + Bandwagon.Logger.debug("Uninitializing Bandwagon.Controller.CollectionsPane"); + + Bandwagon.Controller.CollectionsPane.initialized = false; + + bandwagonService.unregisterCollectionUpdateObserver(Bandwagon.Controller.CollectionsPane.collectionUpdateObserver); + bandwagonService.unregisterCollectionListChangeObserver(Bandwagon.Controller.CollectionsPane.collectionListChangeObserver); + + Bandwagon.Preferences.removeObserver(Bandwagon.Controller.CollectionsPane.prefObserver); + + // now is a good time to save collections to storage + if (Bandwagon.COMMIT_NOW) + bandwagonService.commitAll(); +} + +/** + * Updates the interface disabled-ness based on the state of the selected collection, etc. + */ +Bandwagon.Controller.CollectionsPane.invalidate = function() +{ + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem == null) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonButtonViewSite.disabled = true; + //Bandwagon.Controller.CollectionsPane.elemBandwagonButtonUpdate.disabled = true; + Bandwagon.Controller.CollectionsPane.elemBandwagonButtonRemove.disabled = true; + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionHeader.collapsed = true; + + Bandwagon.Controller.CollectionsPane._repopulateAddonsList(null); + + Bandwagon.Controller.CollectionsPane._invalidateExtensionsDeck(); + } + else + { + Bandwagon.Controller.CollectionsPane.elemBandwagonButtonViewSite.disabled = false; + //Bandwagon.Controller.CollectionsPane.elemBandwagonButtonUpdate.disabled = false; + Bandwagon.Controller.CollectionsPane.elemBandwagonButtonRemove.disabled = false; + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionHeader.collapsed = false; + + var collection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection; + + if (collection.status == collection.STATUS_LOADING) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 1; + } + else if (collection.status == collection.STATUS_LOADERROR) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 3; + } + else if (collection.hasAddon() == 0) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 2; + } + else + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 0; + } + } +} + +Bandwagon.Controller.CollectionsPane._invalidateExtensionsDeck = function() +{ + var elemsBandwagonCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.getElementsByTagName("bandwagonCollection"); + + if (elemsBandwagonCollection.length == 0) + { + if (!bandwagonService.isAMOAuthenticated()) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonExtensionsDeck.selectedIndex = 2; + } + else + { + Bandwagon.Controller.CollectionsPane.elemBandwagonExtensionsDeck.selectedIndex = 1; + } + } + else + { + Bandwagon.Controller.CollectionsPane.elemBandwagonExtensionsDeck.selectedIndex = 0; + } +} + +Bandwagon.Controller.CollectionsPane.collectionListChangeObserver = function() +{ + Bandwagon.Logger.debug("In Bandwagon.Controller.CollectionsPane.collectionListChangeObserver()"); + + var prevCollection = null; + + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem) + { + prevCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection; + } + + Bandwagon.Controller.CollectionsPane._repopulateCollectionsList(); + Bandwagon.Controller.CollectionsPane._invalidateExtensionsDeck(); + + if (prevCollection != null) + { + Bandwagon.Controller.CollectionsPane._selectCollection(prevCollection); + } +} + +Bandwagon.Controller.CollectionsPane.collectionUpdateObserver = function(collection) +{ + if (collection == null) + { + Bandwagon.Logger.debug("In Bandwagon.Controller.CollectionsPane.collectionUpdateObserver() with collection <null>"); + } + else + { + Bandwagon.Logger.debug("In Bandwagon.Controller.CollectionsPane.collectionUpdateObserver() with collection '" + collection.toString() + "'"); + + // update the unread count for this collection + + const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + var elemsBandwagonCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.getElementsByTagNameNS(XULNS, "bandwagonCollection"); + + for (var i=0; i<elemsBandwagonCollection.length; i++) + { + if (elemsBandwagonCollection[i].collection.equals(collection)) + { + elemsBandwagonCollection[i].unread = collection.getUnreadAddons().length; + break; + } + } + + // if this collection is currently selected, update the view + + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem && collection.equals(Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection)) + { + Bandwagon.Controller.CollectionsPane._repopulateAddonsList(collection); + + /* OBSOLETE + // if this is a just arrived collection preview, show the notification box + if (collection.preview) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionsNotification.notificationsHidden = false; + setTimeout(Bandwagon.Controller.CollectionsPane._createPreviewNotification, 200); + } + */ + } + } + + Bandwagon.Controller.CollectionsPane.invalidate(); +} + +Bandwagon.Controller.CollectionsPane.doUpdateAll = function(event) +{ + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 1; + + bandwagonService.forceCheckAllForUpdatesAndUpdateCollectionsList(); +} + +Bandwagon.Controller.CollectionsPane.doSubscribe = function(event) +{ + Bandwagon.Controller.CollectionsPane._openLocalizedURL(Bandwagon.COLLECTIONSPANE_DO_SUBSCRIBE_URL); +} + +Bandwagon.Controller.CollectionsPane.doLogin = function(event) +{ + Bandwagon.Controller.CollectionsPane._openLocalizedURL(Bandwagon.COLLECTIONSPANE_DO_LOGIN_URL); +} + + +Bandwagon.Controller.CollectionsPane.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.CollectionsPane.doViewSite = function(event) +{ + // TODO use url from collection + Bandwagon.Controller.CollectionsPane._openURL("http://www.google.com/search?hl=en&q=bandwagon+view+site&btnG=Search"); +} + +Bandwagon.Controller.CollectionsPane.doUpdate = function(event) +{ + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem == null) + return; + + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 1; + + var collection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection; + + if (collection == null) + return; + + bandwagonService.forceCheckForUpdates(collection); +} + +Bandwagon.Controller.CollectionsPane.doRemove = function(event) +{ + // TODO + alert('TBD'); +} + +/** OBSOLETE +Bandwagon.Controller.CollectionsPane.doRemove = function(event) +{ + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem == null) + return; + + var collection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection; + + if (collection == null) + return; + + bandwagonService.deleteCollection(collection); + + if (!collection.preview) + bandwagonService.unsubscribe(collection); +} +*/ + +Bandwagon.Controller.CollectionsPane.doShowCollection = function() +{ + var collection = null; + + var selectedElemBandwagonCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem; + + if (selectedElemBandwagonCollection != null) + { + collection = selectedElemBandwagonCollection.collection; + } + + // if collection == null, then display will be cleared + + // misc. ui + + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionTitle.setAttribute("value", (collection?(collection.name?collection.name:collection.resourceURL):"")); + + if (collection && collection.description != "") + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDescription.setAttribute("value", collection.description); + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDescription.removeAttribute("collsaped"); + } + else + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDescription.setAttribute("collapsed", true); + } + + /** OBSOLETE + // collection preview notification box + if (collection && collection.preview && collection.status != collection.STATUS_LOADING) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionsNotification.notificationsHidden = false; + + // this needs to be in a seperate thread + setTimeout(Bandwagon.Controller.CollectionsPane._createPreviewNotification, 500); + } + else + */ + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionsNotification.notificationsHidden = true; + } + + // show items + + Bandwagon.Controller.CollectionsPane._repopulateAddonsList(collection); + + // invalidate + + Bandwagon.Controller.CollectionsPane.invalidate(); + + // show the loading dialog if needed + + if (collection && collection.status == collection.STATUS_LOADING) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionDeck.selectedIndex = 1; + } + + // set all items in this collection to be "read" + // if we've just opened this dialog, don't update the read count + + if (collection) + { + collection.setAllRead(); + + if (Bandwagon.Controller.CollectionsPane.initialized) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.unread = 0; + } + } +} + +Bandwagon.Controller.CollectionsPane.doExpandAddon = function(event) +{ + if (event) + event.preventDefault(); + + if (Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem && Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem.nodeName == "bandwagonAddonExpanded") + { + return; + } + + var elemsAddonExpanded = Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.getElementsByTagName("bandwagonAddonExpanded"); + + for (var i=0; i<elemsAddonExpanded.length; i++) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.removeChild(elemsAddonExpanded[i]); + } + + var elemsAddon = Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.childNodes; + + for (var i=0; i<elemsAddon.length; i++) + { + elemsAddon[i].collapsed = false; + } + + var selectedElemBandwagonAddon = Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem; + + if (selectedElemBandwagonAddon != null && selectedElemBandwagonAddon.addon != null) + { + selectedElemBandwagonAddon.read = true; + + var addon = selectedElemBandwagonAddon.addon; + addon.read = true; + + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.unread = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection.getUnreadAddons().length; + + // collapse this, show the expanded binding + + const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + var elemBandwagonAddonExpanded = document.createElementNS(XULNS, "bandwagonAddonExpanded"); + + elemBandwagonAddonExpanded.addon = addon; + + try + { + Bandwagon.Controller.CollectionsPane.elemBandwagonAddonExpanded.setAddon(addon); + } catch (e) {} + + Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.insertBefore(elemBandwagonAddonExpanded, selectedElemBandwagonAddon); + + selectedElemBandwagonAddon.collapsed = true; + } +} + +Bandwagon.Controller.CollectionsPane.doMoreInfo = function(event) +{ + if (event) + event.preventDefault(); + + if (Bandwagon.Controller.CollectionsPane.elemBandwagonAddons == null) + return; + + Bandwagon.Controller.CollectionsPane._openURL(Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem.addon.learnmore); +} + +Bandwagon.Controller.CollectionsPane.doAddToFirefox = function() +{ + if (Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem == null) + return; + + var addon = Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem.addon; + + if (!isXPInstallEnabled()) + return; + + if (addon.eula && addon.eula != "") + { + var eula = { + name: addon.name, + text: addon.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 = addon.getInstaller(Bandwagon.Util.getHostEnvironmentInfo().os); + + if (!installer) + { + Bandwagon.Logger.warn("No compatible os targets found."); + return; + } + + var params = []; + params[addon.name] = installer; + + // TODO do some user collectionback here? + + var callback = function(url, status) + { + Bandwagon.Logger.info("Finished installing '" + url + "'; status = " + status); + + // TODO some user collectionback here? + } + + InstallTrigger.install(params, callback); +} + +Bandwagon.Controller.CollectionsPane.doUpgradeToFirefoxN = function(version) +{ + Bandwagon.Logger.info("in Bandwagon.Controller.CollectionsPane.doUpgradeToFirefoxN() with version = " + version); + + Bandwagon.Controller.CollectionsPane._openURL("http://www.mozilla.com/en-US/firefox/all.html"); +} + +Bandwagon.Controller.CollectionsPane.doDownloadFirefoxNBeta = function(version) +{ + Bandwagon.Logger.info("in Bandwagon.Controller.CollectionsPane.doDownloadFirefoxNBeta() with version = " + version); + + Bandwagon.Controller.CollectionsPane._openURL("http://www.mozilla.com/en-US/firefox/all-beta.html"); +} + +/** OBSOLETE +Bandwagon.Controller.CollectionsPane.doShowCollectionPreview = function(collectionURL) +{ + // this is executed when the browser overlay controller opens the EM window to subscribe to a new collection. + // i.e. after a custom bandwagonSubscribe is detected and handled + + Bandwagon.Logger.debug("In Bandwagon.Controller.CollectionsPane.doShowCollectionPreview() with collectionURL = " + collectionURL); + + // check if we already have this collection + + if (bandwagonService.collections[collectionURL]) + { + var collection = bandwagonService.collections[collectionURL]; + Bandwagon.Controller.CollectionsPane.preferredCollection = collection; + //Bandwagon.Controller.CollectionsPane._selectCollection(collection); + setTimeout(function() { Bandwagon.Controller.CollectionsPane._selectCollection(collection); }, 500); + return; + } + + // add and select the collection + + var collection = bandwagonService.addPreviewCollection(collectionURL); + //collection.status = collection.STATUS_LOADING; + + Bandwagon.Controller.CollectionsPane.preferredCollection = collection; + setTimeout(function() { Bandwagon.Controller.CollectionsPane._selectCollection(collection); }, 500); +} +*/ + +/** OBSOLETE +Bandwagon.Controller.CollectionsPane._createPreviewNotification = function() +{ + if (!Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionsNotification.getNotificationWithValue(Bandwagon.Controller.CollectionsPane.previewNotificationVal)) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionsNotification.appendNotification + ( + Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("collectionspane.this.is.only.a.preview"), + Bandwagon.Controller.CollectionsPane.previewNotificationVal, + null, + Bandwagon.Controller.CollectionsPane.elemBandwagonCollectionsNotification.PRIORITY_WARNING_MEDIUM, + [ + { + accessKey: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("collectionspane.dont.subscribe.accesskey"), + callback: Bandwagon.Controller.CollectionsPane.doCollectionPreviewDontSubscribe, + label: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("collectionspane.dont.subscribe"), + popup: null + }, + { + accessKey: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("collectionspane.subscribe.accesskey"), + callback: Bandwagon.Controller.CollectionsPane.doCollectionPreviewSubscribe, + label: Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("collectionspane.subscribe"), + popup: null + } + ] + ); + } +} +*/ + +/** OBSOLETE +Bandwagon.Controller.CollectionsPane.doCollectionPreviewDontSubscribe = function() +{ + Bandwagon.Logger.debug("in Bandwagon.Controller.CollectionsPane.doCollectionPreviewDontSubscribe()"); + + Bandwagon.Controller.CollectionsPane.preferredCollection = null; + + Bandwagon.Controller.CollectionsPane.doRemove(); +} +*/ + +/** OBSOLETE +Bandwagon.Controller.CollectionsPane.doCollectionPreviewSubscribe = function() +{ + Bandwagon.Logger.debug("in Bandwagon.Controller.CollectionsPane.doCollectionPreviewSubscribe()"); + + if (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem == null) + return; + + var collection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.collection; + + if (collection == null) + return; + + bandwagonService.subscribe(collection); + + if (Bandwagon.COMMIT_NOW) + bandwagonService.commit(collection); + + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem.preview = false; + Bandwagon.Controller.CollectionsPane.doShowCollection(); +} +*/ + +/** + * Refreshes the collection pane + */ +Bandwagon.Controller.CollectionsPane.refresh = function() +{ + var selectedElemBandwagonCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectedItem; + + if (selectedElemBandwagonCollection != null) + { + collection = selectedElemBandwagonCollection.collection; + Bandwagon.Controller.CollectionsPane._repopulateAddonsList(collection); + } + + Bandwagon.Controller.CollectionsPane.invalidate(); +} + +Bandwagon.Controller.CollectionsPane.prefObserver = +{ + observe: function(subject, topic, data) + { + if (topic != "nsPref:changed") + return; + + if (data.match(/addonsperpage/)) + { + Bandwagon.Controller.CollectionsPane.refresh(); + } + } +} + +/** + * Function to select a collection ui programmatically based on its collection object. + */ +Bandwagon.Controller.CollectionsPane._selectCollection = function(collection) +{ + // select the collection and show (collection == null clears the selection) + + if (collection == null) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.clearSelection(); + Bandwagon.Controller.CollectionsPane.doShowCollection(); + return; + } + + // select the richlistitem + + const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + + var elemsBandwagonCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.getElementsByTagNameNS(XULNS, "bandwagonCollection"); + var elemBandwagonCollection = null; + + for (var i=0; i<elemsBandwagonCollection.length; i++) + { + if (elemsBandwagonCollection[i].collection.equals(collection)) + { + elemBandwagonCollection = elemsBandwagonCollection[i]; + break; + } + } + + if (elemBandwagonCollection == null) + { + Bandwagon.Logger.warn("could not find a richlistitem to select"); + return; + } + + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.selectItem(elemBandwagonCollection); + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.ensureElementIsVisible(elemBandwagonCollection); + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.focus(); +} + +Bandwagon.Controller.CollectionsPane._selectPreferredCollection = function() +{ + // select a collection - last selected or the first one + var elemsBandwagonCollection = Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.getElementsByTagName("bandwagonCollection"); + + if (Bandwagon.Controller.CollectionsPane.preferredCollection != null && bandwagonService.collections[Bandwagon.Controller.CollectionsPane.preferredCollection.resourceURL] != null) + { + Bandwagon.Logger.debug("selecting preferred collection (defined)"); + Bandwagon.Controller.CollectionsPane._selectCollection(Bandwagon.Controller.CollectionsPane.preferredCollection); + } + else if (elemsBandwagonCollection.length > 0) + { + Bandwagon.Logger.debug("selecting preferred collection (the first in the list)"); + Bandwagon.Controller.CollectionsPane._selectCollection(elemsBandwagonCollection[0].collection); + } + else + { + Bandwagon.Logger.debug("preferred collection is none"); + Bandwagon.Controller.CollectionsPane._selectCollection(null); + } +} + +Bandwagon.Controller.CollectionsPane._repopulateCollectionsList = function() +{ + //Bandwagon.Logger.debug("Bandwagon.Controller.CollectionsPane: about to repopulate the collections list"); + + // first clear the list + + while (Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.hasChildNodes()) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.removeChild(Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.firstChild); + } + + // repopulate with collections + + for (var id in bandwagonService.collections) + { + var collection = bandwagonService.collections[id]; + + if (collection == null) + return; + + const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + var elemBandwagonCollection = document.createElementNS(XULNS, "bandwagonCollection"); + elemBandwagonCollection.collection = collection; + elemBandwagonCollection.controller = Bandwagon.Controller.CollectionsPane; + + Bandwagon.Controller.CollectionsPane.elemBandwagonCollections.appendChild(elemBandwagonCollection); + } +} + +Bandwagon.Controller.CollectionsPane._repopulateAddonsList = function(collection) +{ + // first clear the list + + while (Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.hasChildNodes()) + { + Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.removeChild(Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.firstChild); + } + + Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.clearSelection(); + + if (collection == null) + return; + + Bandwagon.Logger.debug("Bandwagon.Controller.CollectionsPane: repopulating collection '" + collection.resourceURL + "'"); + + // sort by addon.dateAdded + + var addonsSorted = collection.getSortedAddons(); + + // repopulate with collection items + + var addonsPerPage = bandwagonService.getAddonsPerPage(collection); + const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + + for (var i=0; (i<addonsSorted.length&&i<addonsPerPage); i++) + { + var addon = collection.addons[addonsSorted[i].guid]; + + if (addon == null) + continue; + + var elemBandwagonAddon = document.createElementNS(XULNS, "bandwagonAddon"); + elemBandwagonAddon.addon = addon; + + Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.appendChild(elemBandwagonAddon); + } +} + +Bandwagon.Controller.CollectionsPane._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); + } +} + +Bandwagon.Controller.CollectionsPane._openLocalizedURL = function(url) +{ + var locale = Bandwagon.Util.getBrowserLocale(); + + if (locale && locale != "") + url = url.replace(/en-US/, locale, "g"); + + Bandwagon.Controller.CollectionsPane._openURL(url); +} + +// when this window closes, we do any uninit stuff + +window.addEventListener("unload", Bandwagon.Controller.CollectionsPane.uninit, true); + diff --git a/bandwagon/content/ui/dialog.js b/bandwagon/content/ui/dialog.js index 33e635c..84d096f 100644 --- a/bandwagon/content/ui/dialog.js +++ b/bandwagon/content/ui/dialog.js @@ -14,11 +14,11 @@ * The Original Code is bandwagon. * * The Initial Developer of the Original Code is - * David McNamara. + * Mozilla Corporation. * Portions created by the Initial Developer are Copyright (C) 2008 * the Initial Developer. All Rights Reserved. * - * Contributor(s): + * Contributor(s): David McNamara * * 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 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); - diff --git a/bandwagon/content/ui/overlays/browserOverlay.xul b/bandwagon/content/ui/overlays/browserOverlay.xul index 619b97b..cb9d0e8 100644 --- a/bandwagon/content/ui/overlays/browserOverlay.xul +++ b/bandwagon/content/ui/overlays/browserOverlay.xul @@ -19,7 +19,7 @@ - Portions created by the Initial Developer are Copyright (C) 2008 - the Initial Developer. All Rights Reserved. - - - Contributor(s): Brian King + - Contributor(s): Brian King <brian (at) briks (dot) si> - - 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 @@ -35,6 +35,10 @@ - - ***** END LICENSE BLOCK ***** --> +<!DOCTYPE overlay SYSTEM "chrome://bandwagon/locale/browserOverlay.dtd" > + +<?xml-stylesheet href="chrome://bandwagon/skin/browserOverlay.css" type="text/css"?> + <overlay id="bandwagon-browser-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> @@ -47,9 +51,10 @@ <script src="chrome://bandwagon/content/scripts/rpc/error.js"/> <script src="chrome://bandwagon/content/scripts/rpc/event.js"/> <script src="chrome://bandwagon/content/scripts/rpc/net.js"/> - <script src="chrome://bandwagon/content/scripts/model/feed.js"/> - <script src="chrome://bandwagon/content/scripts/model/feedItem.js"/> - <script src="chrome://bandwagon/content/scripts/factory/feedFactory.js"/> + <script src="chrome://bandwagon/content/scripts/model/serviceDocument.js"/> + <script src="chrome://bandwagon/content/scripts/model/collection.js"/> + <script src="chrome://bandwagon/content/scripts/model/addon.js"/> + <script src="chrome://bandwagon/content/scripts/factory/collectionFactory.js"/> <script src="chrome://bandwagon/content/ui/overlays/browserOverlayController.js"/> @@ -57,4 +62,13 @@ <stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/browserOverlay.properties"/> </stringbundleset> + <!-- Firefox Toolbar --> + <toolbarpalette id="BrowserToolbarPalette"> + <toolbarbutton id="extensions-bandwagon-button" + class="toolbarbutton-1 bandwagon-button" + oncommand="Bandwagon.Controller.BrowserOverlay.openAddons();" + tooltiptext="&bandwagon.tooltip;" + label="&bandwagon.label;" /> + </toolbarpalette> + </overlay> diff --git a/bandwagon/content/ui/overlays/browserOverlayController.js b/bandwagon/content/ui/overlays/browserOverlayController.js index d2f3761..868ac37 100644 --- a/bandwagon/content/ui/overlays/browserOverlayController.js +++ b/bandwagon/content/ui/overlays/browserOverlayController.js @@ -14,11 +14,11 @@ * The Original Code is bandwagon. * * The Initial Developer of the Original Code is - * David McNamara. + * Mozilla Corporation. * Portions created by the Initial Developer are Copyright (C) 2008 * the Initial Developer. All Rights Reserved. * - * Contributor(s): + * Contributor(s): David McNamara * * 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 @@ -34,6 +34,8 @@ * * ***** END LICENSE BLOCK ***** */ +var bandwagonService; + Bandwagon.Controller.BrowserOverlay = new function() {} Bandwagon.Controller.BrowserOverlay.initBandwagon = function() @@ -44,7 +46,7 @@ Bandwagon.Controller.BrowserOverlay.initBandwagon = function() { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); - var bandwagonService = Components.classes["@addons.mozilla.org/bandwagonservice;1"] + bandwagonService = Components.classes["@addons.mozilla.org/bandwagonservice;1"] .getService().wrappedJSObject; // We can safely call init() for each new browser window; the service @@ -60,10 +62,44 @@ Bandwagon.Controller.BrowserOverlay.initBandwagon = function() Bandwagon.Logger.error("Error initializing bandwagon: " + e); } + /** OBSOLETE // add listener to every page loaded in the browser - listen for our custom bandwagonSubscribe event gBrowser.addEventListener("load", Bandwagon.Controller.BrowserOverlay.addSubscribeEventListenerToDocument, true); + */ + + gBrowser.addEventListener("load", Bandwagon.Controller.BrowserOverlay.addSubscriptionRefreshEventListenerToDocument, true); +} + +Bandwagon.Controller.BrowserOverlay.addSubscriptionRefreshEventListenerToDocument = function(event) +{ + if (event.originalTarget instanceof HTMLDocument) + { + var doc = event.originalTarget; + + if (event.originalTarget.defaultView.frameElement) + { + while (doc.defaultView.frameElement) + { + doc=doc.defaultView.frameElement.ownerDocument; + } + } + + // TODO only add to AMO + + doc.addEventListener("bandwagonRefresh", Bandwagon.Controller.BrowserOverlay.handleSubscriptionRefreshEvent, true); + + Bandwagon.Logger.debug("added bandwagonRefresh listener"); + } } +Bandwagon.Controller.BrowserOverlay.handleSubscriptionRefreshEvent = function(event) +{ + Bandwagon.Logger.info("Received bandwagon subscription refresh event"); + + bandwagonService.updateCollectionsList(); +} + +/** OBSOLETE Bandwagon.Controller.BrowserOverlay.addSubscribeEventListenerToDocument = function(event) { if (event.originalTarget instanceof HTMLDocument) @@ -83,24 +119,28 @@ Bandwagon.Controller.BrowserOverlay.addSubscribeEventListenerToDocument = functi //Bandwagon.Logger.debug("added bandwagonSubscribe listener"); } } +*/ +/** OBSOLETE Bandwagon.Controller.BrowserOverlay.handleSubscribeEvent = function(event) { if (event.target && event.target.getAttribute("href")) { - var feedURL = event.target.getAttribute("href"); + var collectionURL = event.target.getAttribute("href"); - Bandwagon.Logger.info("Received subscribe event for feed: " + feedURL); + Bandwagon.Logger.info("Received subscribe event for collection: " + collectionURL); - Bandwagon.Controller.BrowserOverlay._openExtensionManagerFeedsPaneWithSubscribe(feedURL); + Bandwagon.Controller.BrowserOverlay._openExtensionManagerCollectionsPaneWithSubscribe(collectionURL); } else { Bandwagon.Logger.error("Missing data payload in bandwagonSubscribe event"); } } +*/ -Bandwagon.Controller.BrowserOverlay._openExtensionManagerFeedsPaneWithSubscribe = function(feedURL) +/** OBSOLETE +Bandwagon.Controller.BrowserOverlay._openExtensionManagerCollectionsPaneWithSubscribe = function(collectionURL) { const EMTYPE = "Extension:Manager"; var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] @@ -109,23 +149,24 @@ Bandwagon.Controller.BrowserOverlay._openExtensionManagerFeedsPaneWithSubscribe if (theEM) { - // extensions manager window already open - focus, show feeds pane, call doShowFeedPreview + // extensions manager window already open - focus, show collections pane, call doShowCollectionPreview theEM.focus(); - theEM.showView('bandwagon-feeds'); + theEM.showView('bandwagon-collections'); - setTimeout(function() { Bandwagon.Controller.FeedsPane.doShowFeedPreview(feedURL); }, 500); + setTimeout(function() { Bandwagon.Controller.CollectionsPane.doShowCollectionPreview(collectionURL); }, 500); } else { - // extensions manager window NOT already open - open with 'subscribe' argument (this will show feeds pane, call doShowFeedPreview) + // extensions manager window NOT already open - open with 'subscribe' argument (this will show collection pane, call doShowCollectionPreview) const EMURL = "chrome://mozapps/content/extensions/extensions.xul"; const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable"; - window.openDialog(EMURL, "", EMFEATURES, {subscribe: feedURL}); + window.openDialog(EMURL, "", EMFEATURES, {subscribe: collectionURL}); } } +*/ Bandwagon.Controller.BrowserOverlay._removeLoadListener = function() { @@ -144,18 +185,26 @@ Bandwagon.Controller.BrowserOverlay.openFirstRunLandingPage = function() 1000); } -Bandwagon.Controller.BrowserOverlay.showNewFeedItemsAlert = function(feed) +/* Toolbar button action - Open add-ons window with Subscriptions tab focused */ +Bandwagon.Controller.BrowserOverlay.openAddons = function() +{ + const EMURL = "chrome://mozapps/content/extensions/extensions.xul"; + const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable"; + window.openDialog(EMURL, "", EMFEATURES, "bandwagon-collections"); +} + +Bandwagon.Controller.BrowserOverlay.showNewAddonsAlert = function(collection) { - Bandwagon.Logger.debug("in showNewFeedItemsAlert()"); + Bandwagon.Logger.debug("in showNewAddonsAlert()"); var bandwagonStrings = document.getElementById("bandwagon-strings"); var alertsService = Components.classes["@mozilla.org/alerts-service;1"] .getService(Components.interfaces.nsIAlertsService); - var unnotifiedCount = feed.getUnnotifiedFeedItems().length; - var feedName = (feed.name?feed.name:feed.url); - var feedURL = feed.url; + var unnotifiedCount = collection.getUnnotifiedAddons().length; + var collectionName = (collection.name?collection.name:collection.resourceURL); + var collectionURL = collection.resourceURL; var listener = { @@ -163,7 +212,7 @@ Bandwagon.Controller.BrowserOverlay.showNewFeedItemsAlert = function(feed) { if (topic == "alertclickcallback") { - var feedURL = data; + var collectionURL = data; const EMTYPE = "Extension:Manager"; var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] @@ -173,22 +222,22 @@ Bandwagon.Controller.BrowserOverlay.showNewFeedItemsAlert = function(feed) if (theEM) { theEM.focus(); - theEM.showView('bandwagon-feeds'); + theEM.showView('bandwagon-collections'); - // if the em is open, select the bandwagon-feeds pane, but don't select the feed itself. + // if the em is open, select the bandwagon-collections pane, but don't select the collection itself. // the user will be notified by the unread count in the left hand side bar - //theEM.setTimeout(function() { Bandwagon.Controller.FeedsPane._selectFeed(feed); }, 500); + //theEM.setTimeout(function() { Bandwagon.Controller.CollectionsPane._selectCollection(collection); }, 500); } else { const EMURL = "chrome://mozapps/content/extensions/extensions.xul"; const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable"; - // the em is not open - open it, and select this feed + // the em is not open - open it, and select this collection if (window) - window.openDialog(EMURL, "", EMFEATURES, {selectFeed: feedURL}); + window.openDialog(EMURL, "", EMFEATURES, {selectCollection: collectionURL}); else Bandwagon.Logger.error("No browser windows open - can't open EM"); } @@ -200,11 +249,11 @@ Bandwagon.Controller.BrowserOverlay.showNewFeedItemsAlert = function(feed) try { alertsService.showAlertNotification( - "chrome://bandwagon/skin/images/tango-addonfeed-32x32.png", - bandwagonStrings.getString("newfeeditems.alert.title"), - bandwagonStrings.getFormattedString("newfeeditems.alert.text", [feedName]), + "chrome://bandwagon/skin/images/icon32.png", + bandwagonStrings.getString("newaddons.alert.title"), + bandwagonStrings.getFormattedString("newaddons.alert.text", [collectionName]), true, - feedURL, + collectionURL, listener ); } diff --git a/bandwagon/content/ui/overlays/extensionsOverlay.xul b/bandwagon/content/ui/overlays/extensionsOverlay.xul index 0d679f1..6f546dc 100644 --- a/bandwagon/content/ui/overlays/extensionsOverlay.xul +++ b/bandwagon/content/ui/overlays/extensionsOverlay.xul @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> + <!-- ***** BEGIN LICENSE BLOCK ***** - Version: MPL 1.1/GPL 2.0/LGPL 2.1 - @@ -15,11 +16,12 @@ - The Original Code is bandwagon. - - The Initial Developer of the Original Code is - - David McNamara. + - Mozilla Corporation. - Portions created by the Initial Developer are Copyright (C) 2008 - the Initial Developer. All Rights Reserved. - - - Contributor(s): Brian King + - Contributor(s): David McNamara + - Brian King <brian (at) briks (dot) si> - - 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 @@ -46,7 +48,7 @@ <script src="chrome://bandwagon/content/ui/dialog.js"/> <script src="chrome://bandwagon/content/ui/overlays/extensionsOverlayController.js"/> - <script src="chrome://bandwagon/content/ui/feedsPaneController.js"/> + <script src="chrome://bandwagon/content/ui/collectionsPaneController.js"/> <stringbundleset> <stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/extensionOverlay.properties"/> @@ -55,10 +57,10 @@ <stack id="topStackBar"> <radiogroup id="viewGroup"> - <radio id="bandwagon-feeds-view" - label="&feeds.label;" + <radio id="bandwagon-collections-view" + label="&collections.label;" insertbefore="extensions-view" - oncommand="showView('bandwagon-feeds');" + oncommand="showView('bandwagon-collections');" persist="last-selected"/> <radio id="search-view" label="&search.label.bandwagon;" @@ -69,65 +71,89 @@ </stack> <vbox id="extensionsBox"> - <hbox id="bandwagon-feeds-panel" hidden="true" flex="1"> - <vbox id="bandwagon-feeds-list-box" persist="width"> - <richlistbox id="bandwagon-feeds-list" - seltype="single" - style="min-width: 14em; width: 16em; max-width: 36em;" - flex="1"/> - <toolbox class="bandwagon-feeds-toolbox"> - <toolbar pack="start" - align="center"> - <toolbarbutton id="bandwagon-button-subscribe" - tooltiptext="&subscribe.label;" - oncommand="Bandwagon.Controller.FeedsPane.doSubscribe();"/> - <toolbarbutton id="bandwagon-button-update-all" - tooltiptext="&reload.label;" - oncommand="Bandwagon.Controller.FeedsPane.doUpdateAll();"/> - <toolbarbutton id="bandwagon-button-settings" - tooltiptext="&settings.label;" - oncommand="Bandwagon.Controller.FeedsPane.doSettings();"/> - </toolbar> - </toolbox> - </vbox> - <splitter id="bandwagon-sidebar-splitter" /> - <notificationbox flex="1" id="bandwagon-feeds-notification"> - <toolbox class="bandwagon-feeds-toolbox"> - <toolbar pack="end"> - <button id="bandwagon-button-viewsite" label="&viewsite.label;" oncommand="Bandwagon.Controller.FeedsPane.doViewSite();"/> - <button id="bandwagon-button-update" label="&update.label;" oncommand="Bandwagon.Controller.FeedsPane.doUpdate();"/> - <button id="bandwagon-button-remove" label="&remove.label;" oncommand="Bandwagon.Controller.FeedsPane.doRemove();"/> - </toolbar> - </toolbox> - <vbox id="bandwagon-feed-header"> - <label id="bandwagon-feed-title"/> - <label id="bandwagon-feed-description"/> - </vbox> - <deck id="bandwagon-feed-deck" selectedIndex="0" flex="1"> - <hbox flex="1"> - <richlistbox id="bandwagon-feeditems-list" + <vbox id="bandwagon-collections-panel" hidden="true" flex="1"> + <deck id="bandwagon-extensions-deck" flex="1"> + <hbox id="bandwagon-subscriptions-panel" flex="1"> + <vbox id="bandwagon-collections-list-box" persist="width"> + <richlistbox id="bandwagon-collections-list" seltype="single" + style="min-width: 14em; width: 16em; max-width: 36em;" flex="1"/> - </hbox> - <vbox flex="1" align="center" pack="center"> - <label value="&nofeedssubscribed.label;"/> - <button label="&clicktosubscribe.label;" oncommand="Bandwagon.Controller.FeedsPane.doSubscribe();"/> - </vbox> - <vbox flex="1" align="center" pack="center"> - <label class="userfeedback" value="&feedisloading.label;"/> - <image src="chrome://bandwagon/skin/images/spinner.gif"/> - </vbox> - <vbox flex="1" align="center" pack="center"> - <image src="chrome://bandwagon/skin/images/information.png"/> - <label class="userfeedback" value="&feedhasnoitems.label;"/> + <toolbox class="bandwagon-collections-toolbox"> + <toolbar pack="start" + align="center"> + <toolbarbutton id="bandwagon-button-subscribe" + tooltiptext="&subscribe.label;" + oncommand="Bandwagon.Controller.CollectionsPane.doSubscribe();"/> + <toolbarbutton id="bandwagon-button-update-all" + tooltiptext="&reload.label;" + oncommand="Bandwagon.Controller.CollectionsPane.doUpdateAll();"/> + <toolbarbutton id="bandwagon-button-settings" + tooltiptext="&settings.label;" + oncommand="Bandwagon.Controller.CollectionsPane.doSettings();"/> + </toolbar> + </toolbox> </vbox> - <vbox flex="1" align="center" pack="center"> - <image src="chrome://bandwagon/skin/images/error.png"/> - <label class="userfeedback" value="&feedhaserror.label;"/> - </vbox> - </deck> - </notificationbox> - </hbox> + <splitter id="bandwagon-sidebar-splitter" /> + <notificationbox flex="1" id="bandwagon-collections-notification"> + <hbox pack="end"> + <label id="bandwagon-button-viewsite" + value="&view.label;" + class="text-link" + onclick="Bandwagon.Controller.CollectionsPane.doViewSite();"/> + <separator id="bandwagon-link-splitter"/> + <label id="bandwagon-button-remove" + value="&unsubscribe.label;" + class="text-link" + onclick="Bandwagon.Controller.CollectionsPane.doRemove();"/> + </hbox> + <vbox id="bandwagon-collection-header"> + <label id="bandwagon-collection-title"/> + <label id="bandwagon-collection-description"/> + </vbox> + <deck id="bandwagon-collection-deck" selectedIndex="0" flex="1"> + <hbox flex="1"> + <richlistbox id="bandwagon-addons-list" + seltype="single" + flex="1"/> + </hbox> + <vbox flex="1" align="center" pack="center"> + <label class="usercollectionback" value="&collectionisloading.label;"/> + <image src="chrome://bandwagon/skin/images/spinner.gif"/> + </vbox> + <vbox flex="1" align="center" pack="center"> + <image src="chrome://bandwagon/skin/images/information.png"/> + <label class="usercollectionback" value="&collectionhasnoitems.label;"/> + </vbox> + <vbox flex="1" align="center" pack="center"> + <image src="chrome://bandwagon/skin/images/error.png"/> + <label class="usercollectionback" value="&collectionhaserror.label;"/> + </vbox> + </deck> + </notificationbox> + </hbox> + <vbox id="nosubs-box" class="fs-info-panel" flex="1" > + <label id="nosubs-header" class="fs-info-panel-header" value="&nocollectionstitle.label;"/> + <separator/> + <description class="fs-info-panel-text">&nocollectionssubscribed.label;</description> + <separator/> + <hbox pack="center"> + <button label="&clicktosubscribe.label;" + oncommand="Bandwagon.Controller.CollectionsPane.doSubscribe();"/> + </hbox> + </vbox> + <vbox id="no-amo-auth-box" class="fs-info-panel" flex="1" > + <label id="no-amo-auth-header" class="fs-info-panel-header" value="&nocollectionstitle.label;"/> + <separator/> + <description class="fs-info-panel-text">&noamoauth.label;</description> + <separator/> + <hbox pack="center"> + <button label="&clicktologin.label;" + oncommand="Bandwagon.Controller.CollectionsPane.doLogin();"/> + </hbox> + </vbox> + </deck> + </vbox> </vbox> </overlay> diff --git a/bandwagon/content/ui/overlays/extensionsOverlayController.js b/bandwagon/content/ui/overlays/extensionsOverlayController.js index 3cb08b5..a1faac0 100644 --- a/bandwagon/content/ui/overlays/extensionsOverlayController.js +++ b/bandwagon/content/ui/overlays/extensionsOverlayController.js @@ -19,7 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): David McNamara - * Brian King + * Brian King <brian (at) briks (dot) si> * * 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 @@ -54,7 +54,7 @@ Bandwagon.Controller.ExtensionsOverlay.init = function() // So lets hackily hide ours in that circumstance var extView = document.getElementById("extensions-view"); - var bfv = document.getElementById("bandwagon-feeds-view"); + var bfv = document.getElementById("bandwagon-collections-view"); var lsi = extView.ownerDocument.defaultView.getComputedStyle( extView, '' ).getPropertyCSSValue("list-style-image").cssText; if (lsi == "none") @@ -82,29 +82,32 @@ Bandwagon.Controller.ExtensionsOverlay.init = function() if (inArgs) { + /** OBSOLETE if (inArgs.subscribe) { Bandwagon.Logger.debug("Have window argument subscribe = " + inArgs.subscribe); setTimeout(function() { - Bandwagon.Controller.ExtensionsOverlay._showFeedsPaneView(); - Bandwagon.Controller.FeedsPane.doShowFeedPreview(inArgs.subscribe); + Bandwagon.Controller.ExtensionsOverlay._showCollectionsPaneView(); + Bandwagon.Controller.CollectionsPane.doShowCollectionPreview(inArgs.subscribe); }, 500); } - else if (inArgs.selectFeed) + else + */ + if (inArgs.selectCollection) { - Bandwagon.Logger.debug("Have window argument selectFeed = " + inArgs.selectFeed); + Bandwagon.Logger.debug("Have window argument selectCollection = " + inArgs.selectCollection); - if (bandwagonService.feeds[inArgs.selectFeed]) + if (bandwagonService.collections[inArgs.selectCollection]) { - Bandwagon.Controller.FeedsPane.preferredFeed = bandwagonService.feeds[inArgs.selectFeed]; + Bandwagon.Controller.CollectionsPane.preferredCollection = bandwagonService.collections[inArgs.selectCollection]; } setTimeout(function() { - Bandwagon.Controller.ExtensionsOverlay._showFeedsPaneView(); + Bandwagon.Controller.ExtensionsOverlay._showCollectionsPaneView(); }, 500); } @@ -112,22 +115,48 @@ Bandwagon.Controller.ExtensionsOverlay.init = function() } } -Bandwagon.Controller.ExtensionsOverlay.doPublishToFeed = function(feed) +Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection = function(collection) { - Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doPublishToFeed() with feed = '" + feed.url + "'"); + Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection() with collection = '" + collection.toString() + "'"); var extension = Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension(); var params = { publishType: 1, - publishDestination: feed, + publishDestination: collection, publishExtension: extension }; Bandwagon.Controller.ExtensionsOverlay._openPublishDialog(params); } +Bandwagon.Controller.ExtensionsOverlay.doRemoveFromCollection = function(collection) +{ + var extension = Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension(); + + Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doRemoveFromCollection() with collection = '" + collection.toString() + "' and extension: name = '" + extension.name + "', guid = '" + extension.guid + "'"); + + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); + var check = {value: false}; + var flags = promptService.BUTTON_POS_0 * promptService.BUTTON_TITLE_IS_STRING + promptService.BUTTON_POS_1 * promptService.BUTTON_TITLE_IS_STRING; + var button = promptService.confirmEx( + window, + Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("publish.remove.title"), + Bandwagon.Controller.ExtensionsOverlay.stringBundle.getFormattedString("publish.remove.label", [extension.name, collection.name]), + flags, + Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("publish.remove.button0"), + Bandwagon.Controller.ExtensionsOverlay.stringBundle.getString("publish.remove.button1"), + null, + null, + check); + + if (button == 0) + { + bandwagonService.removeAddonFromCollection(extension.guid, collection); + } +} + Bandwagon.Controller.ExtensionsOverlay.doShareToEmail = function(emailAddress) { Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doShareToEmail() with email = '" + emailAddress + "'"); @@ -150,15 +179,15 @@ Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension = function() if (document.getElementById("extensionsView").selectedItem) { - var selectedFeedItem = document.getElementById("extensionsView").selectedItem; - extension.guid = selectedFeedItem.getAttribute("addonID"); - extension.name = selectedFeedItem.getAttribute("name"); + var selectedAddon = document.getElementById("extensionsView").selectedItem; + extension.guid = selectedAddon.getAttribute("addonID"); + extension.name = selectedAddon.getAttribute("name"); } - else if (Bandwagon.Controller.FeedsPane && Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem) + else if (Bandwagon.Controller.CollectionsPane && Bandwagon.Controller.CollectionsPane.elemBandwagonAddons && Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem) { - var selectedFeedItem = Bandwagon.Controller.FeedsPane.elemBandwagonFeedItems.selectedItem; - extension.guid = selectedFeedItem.guid; - extension.name = selectedFeedItem.name; + var selectedAddon = Bandwagon.Controller.CollectionsPane.elemBandwagonAddons.selectedItem; + extension.guid = selectedAddon.guid; + extension.name = selectedAddon.name; } else { @@ -168,6 +197,13 @@ Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension = function() return extension; } +Bandwagon.Controller.ExtensionsOverlay.doNewCollection = function() +{ + Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doNewCollection()"); + + Bandwagon.Controller.CollectionsPane._openLocalizedURL(Bandwagon.COLLECTIONSPANE_DO_NEW_COLLECTION_URL); +} + Bandwagon.Controller.ExtensionsOverlay.doAddNewShareEmail = function() { Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doAddNewShareEmail()"); @@ -241,7 +277,7 @@ Bandwagon.Controller.ExtensionsOverlay._invalidatePublishButton = function() } Bandwagon.Controller.ExtensionsOverlay._publishButton.emailAddresses = Bandwagon.Controller.ExtensionsOverlay._getEmailAddresses(); - Bandwagon.Controller.ExtensionsOverlay._publishButton.writableFeeds = Bandwagon.Controller.ExtensionsOverlay._getWritableFeeds(); + Bandwagon.Controller.ExtensionsOverlay._publishButton.writableCollections = Bandwagon.Controller.ExtensionsOverlay._getWritableCollections(); try { @@ -250,21 +286,39 @@ Bandwagon.Controller.ExtensionsOverlay._invalidatePublishButton = function() catch (e) {} } -Bandwagon.Controller.ExtensionsOverlay._getWritableFeeds = function() +Bandwagon.Controller.ExtensionsOverlay._getWritableCollections = function() { - var writableFeeds = []; + var writableCollections = []; + + var extension = Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension(); - for (var id in bandwagonService.feeds) + for (var id in bandwagonService.collections) { - if (1 || (bandwagonService.feeds[id].editable && !bandwagonService.feeds[id].preview)) + var collection = bandwagonService.collections[id]; + + //if (1 || (bandwagonService.collections[id].writable && !bandwagonService.collections[id].preview)) + + if (collection.writable) { - writableFeeds.push(bandwagonService.feeds[id]); + // Check if extension is in collection + collection.__containsCurrentlySelectedExtension = false; + + for (var id in collection.addons) + { + if (extension.guid == collection.addons[id].guid) + { + collection.__containsCurrentlySelectedExtension = true; + break; + } + } + + writableCollections.push(collection); } } - writableFeeds.sort(); + writableCollections.sort(); - return writableFeeds; + return writableCollections; } Bandwagon.Controller.ExtensionsOverlay._getEmailAddresses = function() @@ -276,12 +330,12 @@ Bandwagon.Controller.ExtensionsOverlay._getEmailAddresses = function() return previouslySharedEmailAddresses; } -Bandwagon.Controller.ExtensionsOverlay._showFeedsPaneView = function() +Bandwagon.Controller.ExtensionsOverlay._showCollectionsPaneView = function() { - Bandwagon.Logger.debug("in _showFeedsPaneView()"); + Bandwagon.Logger.debug("in _showCollectionsPaneView()"); - updateLastSelected("bandwagon-feeds"); - gView = "bandwagon-feeds"; + updateLastSelected("bandwagon-collections"); + gView = "bandwagon-collections"; document.getElementById("installFileButton").hidden = true; document.getElementById("checkUpdatesAllButton").hidden = true; @@ -301,12 +355,12 @@ Bandwagon.Controller.ExtensionsOverlay._showFeedsPaneView = function() AddonsViewBuilder.clearChildren(gExtensionsView); - document.getElementById("bandwagon-feeds-panel").hidden = false; + document.getElementById("bandwagon-collections-panel").hidden = false; updateGlobalCommands(); - Bandwagon.Controller.FeedsPane.init(); - Bandwagon.Controller.FeedsPane.onViewSelect(); + Bandwagon.Controller.CollectionsPane.init(); + Bandwagon.Controller.CollectionsPane.onViewSelect(); } // magic @@ -315,13 +369,13 @@ Bandwagon.Controller.ExtensionsOverlay._defaultShowView = showView; Bandwagon.Controller.ExtensionsOverlay._showView = function(aView) { - if (aView == "bandwagon-feeds") + if (aView == "bandwagon-collections") { - Bandwagon.Controller.ExtensionsOverlay._showFeedsPaneView(); + Bandwagon.Controller.ExtensionsOverlay._showCollectionsPaneView(); } else { - document.getElementById("bandwagon-feeds-panel").hidden = true; + document.getElementById("bandwagon-collections-panel").hidden = true; document.getElementById("extensionsView").hidden = false; document.getElementById("extensionsView").parentNode.hidden = false; diff --git a/bandwagon/content/ui/publish.xul b/bandwagon/content/ui/publish.xul index 54e9e83..380a4c2 100644 --- a/bandwagon/content/ui/publish.xul +++ b/bandwagon/content/ui/publish.xul @@ -20,7 +20,7 @@ - the Initial Developer. All Rights Reserved. - - Contributor(s): David McNamara - - Brian King + - Brian King <brian (at) briks (dot) si> - - 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 @@ -45,6 +45,7 @@ windowtype="Bandwagon:Publish" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="&window.title;" + style="&publish.style;" buttons="accept,cancel" buttonlabelcancel="&cancel.label;" buttonlabelaccept="&publish.label;" @@ -54,20 +55,18 @@ <script src="chrome://bandwagon/content/ui/dialog.js"/> <script src="chrome://bandwagon/content/ui/publishController.js"/> - <stringbundleset> - <stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/publish.properties"/> - </stringbundleset> + <stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/publish.properties"/> <vbox> - <label id="dialog-desc"/> + <!--<label id="dialog-desc"/>--> <deck id="type-deck"> <hbox id="publishing-to-box"> - <label id="publishing-to"/> + <label id="publishing-to" class="dialog-header"/> </hbox> <hbox id="sharing-with-box"> - <label id="sharing-with"/> + <description id="sharing-with" class="dialog-header" flex="1"/> </hbox> <groupbox id="new-email-box"> @@ -78,10 +77,14 @@ </groupbox> </deck> - <label value="&enter.a.personal.note.label;"/> + <separator class="thin"/> + + <description flex="1">&enter.a.personal.note.label;</description> <textbox id="personal-note" multiline="true"/> + <description id="sharing-with-new" flex="1"/> + <hbox> <image id="spinner" src="chrome://bandwagon/skin/images/spinner-small.gif" collapsed="true"/> <label id="error" style="color: red; visibility: hidden;" value=" "/> diff --git a/bandwagon/content/ui/publishController.js b/bandwagon/content/ui/publishController.js index 492d5dc..1ff0d27 100644 --- a/bandwagon/content/ui/publishController.js +++ b/bandwagon/content/ui/publishController.js @@ -19,6 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): David McNamara + * Brian King <brian (at) briks (dot) si> * * 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 @@ -38,13 +39,14 @@ Bandwagon.Controller.Publish = new function() { this.stringBundle = null; this.hasSubmitted = false; + this.hasSubmittedWithSuccess = false; this.publishType = -1; // one of the TYPE_ constants - this.publishDestination = null; // email address or feed obj + this.publishDestination = null; // email address or collection obj this.publishExtension = null; // the add-on / theme obj to publish } -Bandwagon.Controller.Publish.TYPE_FEED = 1; +Bandwagon.Controller.Publish.TYPE_COLLECTION = 1; Bandwagon.Controller.Publish.TYPE_EXISTING_EMAIL = 2; Bandwagon.Controller.Publish.TYPE_NEW_EMAIL = 3; @@ -62,27 +64,33 @@ Bandwagon.Controller.Publish.init = function() Bandwagon.Controller.Publish.publishDestination = inArgs.publishDestination; Bandwagon.Controller.Publish.publishExtension = inArgs.publishExtension; - document.getElementById("dialog-desc").value = Bandwagon.Controller.Publish.stringBundle.getFormattedString("you.are.sharing.the.add.on", [Bandwagon.Controller.Publish.publishExtension.name]); + //document.getElementById("dialog-desc").value = Bandwagon.Controller.Publish.stringBundle.getFormattedString("you.are.sharing.the.add.on", [Bandwagon.Controller.Publish.publishExtension.name]); document.getElementById("type-deck").selectedIndex = Bandwagon.Controller.Publish.publishType-1; switch (Bandwagon.Controller.Publish.publishType) { - case Bandwagon.Controller.Publish.TYPE_FEED: - document.getElementById("publishing-to").value = Bandwagon.Controller.Publish.stringBundle.getFormattedString("publishing.to", [(Bandwagon.Controller.Publish.publishDestination.name?Bandwagon.Controller.Publish.publishDestination.name:Bandwagon.Controller.Publish.publishDestination.url)]); + case Bandwagon.Controller.Publish.TYPE_COLLECTION: + document.getElementById("publishing-to").value = Bandwagon.Controller.Publish.stringBundle.getFormattedString("publishing.to", [Bandwagon.Controller.Publish.publishExtension.name, (Bandwagon.Controller.Publish.publishDestination.name?Bandwagon.Controller.Publish.publishDestination.name:Bandwagon.Controller.Publish.publishDestination.url)]); document.getElementById("new-email-box").collapsed = true; document.getElementById("sharing-with-box").collapsed = true; document.getElementById("publishing-to-box").collapsed = false; + document.getElementById("sharing-with-new").collapsed = true; break; case Bandwagon.Controller.Publish.TYPE_EXISTING_EMAIL: - document.getElementById("sharing-with").value = Bandwagon.Controller.Publish.stringBundle.getFormattedString("sharing.with", [Bandwagon.Controller.Publish.publishDestination]); + document.getElementById("sharing-with").textContent = Bandwagon.Controller.Publish.stringBundle.getFormattedString("sharing.with", [Bandwagon.Controller.Publish.publishDestination, Bandwagon.Controller.Publish.publishExtension.name]); document.getElementById("new-email-box").collapsed = true; document.getElementById("sharing-with-box").collapsed = false; document.getElementById("publishing-to-box").collapsed = true; + document.getElementById("sharing-with-new").collapsed = true; + document.getElementById("bandwagon-publish").getButton("accept").label = Bandwagon.Controller.Publish.stringBundle.getString("send.email"); break; case Bandwagon.Controller.Publish.TYPE_NEW_EMAIL: + document.getElementById("sharing-with-new").textContent = Bandwagon.Controller.Publish.stringBundle.getFormattedString("sharing.with.new", [Bandwagon.Controller.Publish.publishExtension.name]); + document.getElementById("sharing-with-new").collapsed = false; document.getElementById("new-email-box").collapsed = false; document.getElementById("sharing-with-box").collapsed = true; document.getElementById("publishing-to-box").collapsed = true; + document.getElementById("bandwagon-publish").getButton("accept").label = Bandwagon.Controller.Publish.stringBundle.getString("send.email"); break; } @@ -93,6 +101,12 @@ Bandwagon.Controller.Publish.doAccept = function() { Bandwagon.Logger.debug("In Bandwagon.Controller.Publish.doAccept();"); + if (Bandwagon.Controller.Publish.hasSubmittedWithSuccess) + { + document.getElementById("bandwagon-publish").cancelDialog(); + return true; + } + if (Bandwagon.Controller.Publish.publishType == Bandwagon.Controller.Publish.TYPE_NEW_EMAIL && document.getElementById("email-address").value == "") { Bandwagon.Controller.Publish._showError(Bandwagon.Controller.Publish.stringBundle.getString("please.enter.an.email.address")); @@ -104,8 +118,8 @@ Bandwagon.Controller.Publish.doAccept = function() switch (Bandwagon.Controller.Publish.publishType) { - case Bandwagon.Controller.Publish.TYPE_FEED: - Bandwagon.Controller.Publish._publishToFeed(); + case Bandwagon.Controller.Publish.TYPE_COLLECTION: + Bandwagon.Controller.Publish._publishToCollection(); break; case Bandwagon.Controller.Publish.TYPE_EXISTING_EMAIL: Bandwagon.Controller.Publish._shareToExistingEmail(); @@ -123,9 +137,9 @@ Bandwagon.Controller.Publish.doCancel = function() return true; } -Bandwagon.Controller.Publish._publishToFeed = function() +Bandwagon.Controller.Publish._publishToCollection = function() { - bandwagonService.publishToFeed( + bandwagonService.publishToCollection( Bandwagon.Controller.Publish.publishExtension, Bandwagon.Controller.Publish.publishDestination, document.getElementById("personal-note").value, @@ -164,22 +178,46 @@ Bandwagon.Controller.Publish.invalidate = function() Bandwagon.Controller.Publish.finished = function(event) { - Bandwagon.Controller.Publish.hasSubmitted = false; - Bandwagon.Controller.Publish.invalidate(); - if (event.isError()) { + Bandwagon.Controller.Publish.hasSubmitted = false; + Bandwagon.Controller.Publish.invalidate(); + Bandwagon.Controller.Publish._showError(event.getError()); + return; } + Bandwagon.Controller.Publish.hasSubmittedWithSuccess = true; + if (Bandwagon.Controller.Publish.publishType == Bandwagon.Controller.Publish.TYPE_NEW_EMAIL && document.getElementById("remember-email").checked) { - bandwagonService.addPreviouslySharedEmailAddress(document.getElementById("email-address").value); + bandwagonService.addPreviouslySharedEmailAddresses(document.getElementById("email-address").value); } - document.getElementById("bandwagon-publish").cancelDialog(); + if (Bandwagon.Controller.Publish.publishType == Bandwagon.Controller.Publish.TYPE_COLLECTION) + { + bandwagonService.forceCheckForUpdates(Bandwagon.Controller.Publish.publishDestination); + + document.getElementById("error").value = Bandwagon.Controller.Publish.stringBundle.getString("the.addon.has.been.published"); + } + else + { + document.getElementById("error").value = Bandwagon.Controller.Publish.stringBundle.getString("the.email.has.been.sent"); + } + + document.getElementById("error").style.visibility = "visible"; + document.getElementById("error").style.color = 'green'; + document.getElementById("spinner").collapsed = true; + document.getElementById("email-address").disabled = true; + document.getElementById("personal-note").disabled = true; + document.getElementById("bandwagon-publish").getButton("cancel").hidden = true; + document.getElementById("bandwagon-publish").getButton("accept").disabled = false; + document.getElementById("bandwagon-publish").getButton("accept").label = Bandwagon.Controller.Publish.stringBundle.getFormattedString("closing.in", ["2"]); + + setTimeout(function() { document.getElementById("bandwagon-publish").getButton("accept").label = Bandwagon.Controller.Publish.stringBundle.getFormattedString("closing.in", ["1"]); }, 2000); + setTimeout(function() { document.getElementById("bandwagon-publish").cancelDialog(); }, 3000); } Bandwagon.Controller.Publish._showError = function(message) diff --git a/bandwagon/content/ui/settings.xul b/bandwagon/content/ui/settings.xul index 90126ed..3985d6b 100644 --- a/bandwagon/content/ui/settings.xul +++ b/bandwagon/content/ui/settings.xul @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> + <!-- ***** BEGIN LICENSE BLOCK ***** - Version: MPL 1.1/GPL 2.0/LGPL 2.1 - @@ -20,7 +21,7 @@ - the Initial Developer. All Rights Reserved. - - Contributor(s): David McNamara - - Brian King + - Brian King <brian (at) briks (dot) si> - - 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 @@ -37,41 +38,115 @@ - ***** END LICENSE BLOCK ***** --> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> -<?xml-stylesheet href="chrome://bandwagon/skin/global.css" type="text/css"?> +<?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?> <?xml-stylesheet href="chrome://bandwagon/skin/settings.css" type="text/css"?> -<?xml-stylesheet href="chrome://bandwagon/content/ui/bindings/bandwagon.css" type="text/css"?> <!DOCTYPE prefwindow SYSTEM "chrome://bandwagon/locale/settings.dtd"> <prefwindow id="bandwagon-settings" - windowtype="Bandwagon:Settings" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="&window.title;" ondialogaccept="return Bandwagon.Controller.Settings.doAccept();" - ondialogcancel="return Bandwagon.Controller.Settings.doCancel();"> - - <script src="chrome://bandwagon/content/ui/dialog.js"/> - <script src="chrome://bandwagon/content/ui/settingsController.js"/> - - <stringbundleset> - <stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/settings.properties"/> - </stringbundleset> + ondialogcancel="return Bandwagon.Controller.Settings.doCancel();" + persist="lastSelected screenX screenY"> - <prefpane id="pane1" + <prefpane id="paneManage" + label="&manage.label;" flex="1"> <preferences> <preference id="extensions.bandwagon.updateall.enabled" name="extensions.bandwagon.updateall.enabled" type="bool"/> - <preference id="extensions.bandwagon.feeditemsperpage.enabled" - name="extensions.bandwagon.feeditemsperpage.enabled" + <preference id="extensions.bandwagon.addonsperpage.enabled" + name="extensions.bandwagon.addonsperpage.enabled" type="bool"/> - <preference id="extensions.bandwagon.feeditemsperpage" - name="extensions.bandwagon.feeditemsperpage" - type="int"/> <preference id="extensions.bandwagon.notifyall.enabled" name="extensions.bandwagon.notifyall.enabled" type="bool"/> + </preferences> + + <hbox> + <vbox> + <label id="collections-list-header" crop="end" value="&subscriptions.header;"/> + <richlistbox id="collections-list" flex="1"/> + </vbox> + <vbox flex="1"> + <!-- <label id="collection-name" crop="end" value=""/> --> + + <!-- Update Interval Settings --> + <groupbox> + <caption label="&frequency.label;"/> + <radiogroup id="updates-group"> + <radio id="updates-default" label="&default.label;"/> + <hbox align="center"> + <radio id="updates-custom" label="&custom.label;"/> + <label id="checkbox-updateinterval-percollection" value="&updatesingle.label;"/> + <textbox id="textbox-updateinterval-quantity-percollection" + type="number" + min="1" + size="3" + maxlength="3" + value=""/> + <menulist id="menulist-updateinterval-units-percollection" + class="" + crop="none"> + <menupopup> + <menuitem label="&minutes.label;" value="1"/> + <menuitem label="&hours.label;" value="2"/> + <menuitem label="&days.label;" value="3"/> + </menupopup> + </menulist> + </hbox> + </radiogroup> + </groupbox> + + <!-- Show Notification Settings --> + <groupbox> + <caption label="¬ifications.label;"/> + <radiogroup id="notifications-group"> + <radio id="notifications-default" label="&default.label;"/> + <hbox> + <radio id="notifications-custom" label="&custom.label;"/> + <radiogroup id="checkbox-shownotifications-percollection" + orient="horizontal"> + <radio id="shownotifications-percollection-on" label="&on.label;"/> + <radio id="shownotifications-percollection-off" label="&off.label;"/> + </radiogroup> + </hbox> + </radiogroup> + </groupbox> + + <!-- Add-ons Per Page Settings --> + <groupbox> + <caption label="&perpage.label;"/> + <radiogroup id="perpage-group"> + <radio id="perpage-default" label="&default.label;"/> + <hbox align="center"> + <radio id="perpage-custom" label="&custom.label;"/> + <label id="label-addonsshow-percollection"> &addonsleadin.label;</label> + <textbox id="textbox-addonsperpage-percollection" + type="number" + size="3"/> + <label id="label-addonsperpage-percollection"> &addonsperpage.label;</label> + </hbox> + </radiogroup> + </groupbox> + <hbox align="center" pack="end"> + <button id="remove-button" + label="&remove.label;" + oncommand="Bandwagon.Controller.Settings.doRemove();"/> + </hbox> + </vbox> + </hbox> + + </prefpane> + + <prefpane id="paneGeneral" + label="&general.label;"> + <preferences> + <preference id="extensions.bandwagon.addonsperpage" + name="extensions.bandwagon.addonsperpage" + type="int"/> <preference id="extensions.bandwagon.updateall.interval" name="extensions.bandwagon.updateall.interval" type="int"/> @@ -79,73 +154,130 @@ name="extensions.bandwagon.updateall.units" type="int"/> </preferences> + <groupbox> + <caption label="&subscriptions.label;"/> + <hbox align="center"> + <label id="updateinterval-all" value="&updateall.label;"/> + <textbox id="textbox-updateinterval-quantity" + type="number" + min="1" + size="3" + maxlength="3" + value="" + onkeypress="" + onchange="" + preference="extensions.bandwagon.updateall.interval"/> + <menulist id="menulist-updateinterval-units" class="" crop="none" preference="extensions.bandwagon.updateallglobal.units"> + <menupopup> + <menuitem label="&minutes.label;" value="1"/> + <menuitem label="&hours.label;" value="2"/> + <menuitem label="&days.label;" value="3"/> + </menupopup> + </menulist> + </hbox> + <hbox align="center"> + <label id="notify-all" value="¬ifyglobal.label;"/> + <radiogroup id="notify-all-group" orient="horizontal"> + <radio id="notify-all-on" label="&on.label;"/> + <radio id="notify-all-off" label="&off.label;"/> + </radiogroup> + </hbox> + <hbox align="center"> + <label id="label-addonsshow"> &addonsleadin.label;</label> + <textbox id="textbox-addonsperpage-global" + type="number" + size="3" + preference="extensions.bandwagon.addonsperpage"/> + <label id="label-addonsperpage"> &addonsperpage.label;</label> + </hbox> + </groupbox> - <hbox flex="1"> - <vbox> - <richlistbox id="feeds-list" flex="1"/> - <toolbox class="bandwagon-feeds-toolbox"> - <toolbar pack="start" - align="center"> - <toolbarbutton id="add-feed-button" - tooltiptext="&add.label;" - oncommand="Bandwagon.Controller.Settings.doAdd();"/> - <toolbarbutton id="remove-feed-button" - tooltiptext="&remove.label;" - oncommand="Bandwagon.Controller.Settings.doRemove();"/> - </toolbar> - </toolbox> - </vbox> - <vbox flex="1"> - <label id="feed-name" crop="end" value=""/> - - <!-- Update Interval Settings --> - - <hbox align="center"> - <checkbox id="checkbox-updateinterval-perfeed" label="&updatesingle.label;"/> - <textbox id="textbox-updateinterval-quantity" - type="number" - min="1" - size="3" - maxlength="3" - value="" - onkeypress="" - onchange="" - preference="extensions.bandwagon.updateall.interval" - /> - <menulist id="menulist-updateinterval-units" class="" crop="none" preference="extensions.bandwagon.updateall.units"> - <menupopup> - <menuitem label="&minutes.label;" value="1"/> - <menuitem label="&hours.label;" value="2"/> - <menuitem label="&days.label;" value="3"/> - </menupopup> - </menulist> - </hbox> - <checkbox id="checkbox-updateinterval-global" class="all-check" label="&applyall.label;"/> - <separator class="groove"/> - - <!-- Show Notification Settings --> - - <checkbox id="checkbox-shownotifications-perfeed" label="¬ify.label;"/> - <checkbox id="checkbox-shownotifications-global" class="all-check" label="&applyall.label;"/> - <separator class="groove"/> - - <!-- Add-ons Per Page Settings --> - - <hbox align="center"> - <textbox id="textbox-feeditemsperpage-global" - type="number" - size="3" - preference="extensions.bandwagon.feeditemsperpage"/> - <label id="label-feeditemsperpage"> &feeditemsperpage.label;</label> - </hbox> - - <!-- Auto-publish Settings --> + <groupbox> + <caption label="&data.label;"/> + <hbox align="center" pack="start"> + <label id="clear-emails-text" value="" /> + <button id="clear-emails-button" + label="&clearemails.label;" + oncommand="Bandwagon.Controller.Settings.doClearEmails();"/> + </hbox> + <hbox align="center" pack="start"> + <label id="login-status-text" value="" /> + <button id="login-button" + label="&login.label;" + oncommand="Bandwagon.Controller.Settings.doLogin();"/> + <button id="logout-button" + label="&logout.label;" + oncommand="Bandwagon.Controller.Settings.doLogout();" + collapsed="true"/> + </hbox> + </groupbox> + </prefpane> - <checkbox id="checkbox-autopublish-perfeed" label="&autopublish.label;"/> + <prefpane id="paneAuto" + label="&pub.label;"> + <!-- Auto-publish Settings --> + <!-- + <checkbox id="checkbox-autopublish-percollection" label="&autopublish.label;"/> + --> + <groupbox> + <caption label="&auto.label;"/> + <description>&autoleadin.label;</description> + <separator class="thin"/> + <grid> + <columns> + <column/> + <column/> + </columns> + <rows> + <row align="center"> + <label value="&name.label;"/> + <textbox id="auto-name"/> + </row> + <row align="center"> + <spacer/> + <checkbox id="auto-list" label="&list.label;"/> + </row> + </rows> + </grid> + <separator class="thin"/> + <grid> + <columns> + <column/> + <column/> + <column/> + </columns> + <rows> + <row align="center"> + <label value="&types.label;"/> + <checkbox id="auto-type-extensions" label="&type.extensions.label;"/> + <checkbox id="auto-type-themes" label="&type.themes.label;"/> + </row> + <row align="center"> + <spacer/> + <checkbox id="auto-type-dicts" label="&type.dicts.label;"/> + <checkbox id="auto-type-langpacks" label="&type.langpacks.label;"/> + </row> + </rows> + </grid> + </groupbox> + <hbox class="bottomBox" pack="center"> + <groupbox id="auto-groupbox" orient="horizontal"> + <button id="auto-create-button" + label="&createauto.label;" + oncommand="Bandwagon.Controller.Settings.doAutoCreate();"/> + <button id="auto-delete-button" + label="&deleteauto.label;" + oncommand="Bandwagon.Controller.Settings.doAutoDelete();" + collapsed="true"/> + <image id="auto-spinner" src="chrome://bandwagon/skin/images/spinner-small.gif" collapsed="true"/> + </groupbox> + </hbox> + <label id="auto-error" style="color: red;" value=" " collapsed="true"/> + </prefpane> - </vbox> - </hbox> + <stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/settings.properties"/> - </prefpane> + <script type="application/x-javascript" src="chrome://bandwagon/content/ui/dialog.js"/> + <script type="application/x-javascript" src="chrome://bandwagon/content/ui/settingsController.js"/> </prefwindow> diff --git a/bandwagon/content/ui/settingsController.js b/bandwagon/content/ui/settingsController.js index 34ccb8f..d521d15 100644 --- a/bandwagon/content/ui/settingsController.js +++ b/bandwagon/content/ui/settingsController.js @@ -19,7 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): David McNamara - * Brian King + * Brian King <brian (at) briks (dot) si> * * 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 @@ -37,49 +37,56 @@ Bandwagon.Controller.Settings = new function() { - this.feeds = {}; + this.collections = {}; - this.elemBandwagonFeeds = null; - this.elemFeedName = null; + this.elemBandwagonCollections = null; + this.elemCollectionName = null; this.stringBundle = null; } Bandwagon.Controller.Settings.init = function() { - //alert("Initializing Bandwagon.Controller.Settings"); Bandwagon.Logger.debug("Initializing Bandwagon.Controller.Settings"); Bandwagon.Controller.Settings.stringBundle = document.getElementById("bandwagon-strings"); - Bandwagon.Controller.Settings.elemBandwagonFeeds = document.getElementById("feeds-list"); - Bandwagon.Controller.Settings.elemBandwagonFeeds.addEventListener("select", Bandwagon.Controller.Settings.doShowFeed, true); + Bandwagon.Controller.Settings.elemBandwagonCollections = document.getElementById("collections-list"); + Bandwagon.Controller.Settings.elemBandwagonCollections.addEventListener("select", Bandwagon.Controller.Settings.doShowCollection, true); - Bandwagon.Controller.Settings.elemFeedName = document.getElementById("feed-name"); + Bandwagon.Controller.Settings.elemCollectionName = document.getElementById("collection-name"); if (document.getElementById("extensions.bandwagon.updateall.enabled").value) { - document.getElementById("checkbox-updateinterval-global").checked = true; - document.getElementById("checkbox-updateinterval-perfeed").checked = true; + document.getElementById("updates-group").selectedIndex = 0; } + else + document.getElementById("updates-group").selectedIndex = 1; - document.getElementById("checkbox-updateinterval-global").addEventListener("command", Bandwagon.Controller.Settings.doUpdateIntervalScopeChange, true); - document.getElementById("textbox-updateinterval-quantity").addEventListener("input", Bandwagon.Controller.Settings.doSaveFeed, true); - document.getElementById("textbox-updateinterval-quantity").addEventListener("command", Bandwagon.Controller.Settings.doSaveFeed, false); - document.getElementById("menulist-updateinterval-units").addEventListener("command", Bandwagon.Controller.Settings.doSaveFeed, true); + document.getElementById("updates-group").addEventListener("command", Bandwagon.Controller.Settings.doUpdateIntervalScopeChange, true); + document.getElementById("textbox-updateinterval-quantity").addEventListener("input", Bandwagon.Controller.Settings.doSaveCollection, true); + document.getElementById("textbox-updateinterval-quantity").addEventListener("command", Bandwagon.Controller.Settings.doSaveCollection, false); + document.getElementById("textbox-updateinterval-quantity-percollection").addEventListener("input", Bandwagon.Controller.Settings.doSaveCollection, true); + document.getElementById("textbox-updateinterval-quantity-percollection").addEventListener("command", Bandwagon.Controller.Settings.doSaveCollection, false); + document.getElementById("menulist-updateinterval-units-percollection").addEventListener("command", Bandwagon.Controller.Settings.doSaveCollection, true); if (document.getElementById("extensions.bandwagon.notifyall.enabled").value) { - document.getElementById("checkbox-shownotifications-global").checked = true; - document.getElementById("checkbox-shownotifications-perfeed").checked = true; + document.getElementById("notifications-group").selectedIndex = 0; } + else + document.getElementById("notifications-group").selectedIndex = 1; + + document.getElementById("notifications-group").addEventListener("command", Bandwagon.Controller.Settings.doShowNotificationsScopeChange, true); + document.getElementById("notifications-group").addEventListener("command", Bandwagon.Controller.Settings.doSaveCollection, true); - document.getElementById("checkbox-shownotifications-global").addEventListener("command", Bandwagon.Controller.Settings.doShowNotificationsScopeChange, true); - document.getElementById("checkbox-shownotifications-perfeed").addEventListener("command", Bandwagon.Controller.Settings.doSaveFeed, true); + //document.getElementById("checkbox-autopublish-percollection").addEventListener("command", Bandwagon.Controller.Settings.doSaveCollection, true); - document.getElementById("checkbox-autopublish-perfeed").addEventListener("command", Bandwagon.Controller.Settings.doSaveFeed, true); + bandwagonService.registerCollectionListChangeObserver(Bandwagon.Controller.Settings.collectionListChangeObserver); - bandwagonService.registerFeedListChangeObserver(Bandwagon.Controller.Settings.feedListChangeObserver); + Bandwagon.Controller.Settings.EmailsCheck(); + Bandwagon.Controller.Settings.LoginCheck(); + Bandwagon.Controller.Settings.AutoCheck(); setTimeout(function() { @@ -90,33 +97,33 @@ Bandwagon.Controller.Settings.init = function() Bandwagon.Controller.Settings._delayedInit = function() { - Bandwagon.Controller.Settings._repopulateFeedsList(); + Bandwagon.Controller.Settings._repopulateCollectionsList(); Bandwagon.Controller.Settings.invalidate(); } Bandwagon.Controller.Settings.uninit = function() { - bandwagonService.unregisterFeedListChangeObserver(Bandwagon.Controller.Settings.feedListChangeObserver); + bandwagonService.unregisterCollectionListChangeObserver(Bandwagon.Controller.Settings.collectionListChangeObserver); - // now is a good time to save feeds to storage + // now is a good time to save collections to storage if (Bandwagon.COMMIT_NOW) bandwagonService.commitAll(); } -Bandwagon.Controller.Settings.feedListChangeObserver = function() +Bandwagon.Controller.Settings.collectionsListChangeObserver = function() { - Bandwagon.Controller.Settings._repopulateFeedsList(); + Bandwagon.Controller.Settings._repopulateCollectionsList(); - var elemBandwagonFeed = Bandwagon.Controller.Settings.elemBandwagonFeeds.getElementsByTagName("bandwagonFeed")[0]; + var elemBandwagonCollection = Bandwagon.Controller.Settings.elemBandwagonCollections.getElementsByTagName("bandwagonCollection")[0]; - if (elemBandwagonFeed) + if (elemBandwagonCollection) { - Bandwagon.Controller.Settings.elemBandwagonFeeds.selectItem(elemBandwagonFeed); - Bandwagon.Controller.Settings.elemBandwagonFeeds.focus(); + Bandwagon.Controller.Settings.elemBandwagonCollections.selectItem(elemBandwagonCollection); + Bandwagon.Controller.Settings.elemBandwagonCollections.focus(); } else { - Bandwagon.Controller.Settings.doShowFeed(); + Bandwagon.Controller.Settings.doShowCollection(); } Bandwagon.Controller.Settings.invalidate(); @@ -124,92 +131,95 @@ Bandwagon.Controller.Settings.feedListChangeObserver = function() Bandwagon.Controller.Settings.invalidate = function() { - var feedCount = Bandwagon.Controller.Settings.elemBandwagonFeeds.getElementsByTagName("bandwagonFeed").length; - var feedSelection = Bandwagon.Controller.Settings.elemBandwagonFeeds.selectedItem; - - var disabled = (!feedSelection || feedCount == 0); - - document.getElementById("remove-feed-button").disabled = disabled; - document.getElementById("checkbox-updateinterval-perfeed").disabled = disabled; - document.getElementById("textbox-updateinterval-quantity").disabled = disabled; - document.getElementById("menulist-updateinterval-units").disabled = disabled; - document.getElementById("checkbox-updateinterval-global").disabled = disabled; - document.getElementById("checkbox-shownotifications-perfeed").disabled = disabled; - document.getElementById("checkbox-shownotifications-global").disabled = disabled; - document.getElementById("textbox-feeditemsperpage-global").disabled = disabled; - document.getElementById("checkbox-autopublish-perfeed").disabled = disabled; - document.getElementById("label-feeditemsperpage").disabled = disabled; + var collectionCount = Bandwagon.Controller.Settings.elemBandwagonCollections.getElementsByTagName("bandwagonCollection").length; + var collectionSelection = Bandwagon.Controller.Settings.elemBandwagonCollections.selectedItem; + + var disabled = (!collectionSelection || collectionCount == 0); + + // XXTODO Disable more controls + //document.getElementById("remove-collection-button").disabled = disabled; + document.getElementById("updates-group").disabled = disabled; + document.getElementById("textbox-updateinterval-quantity-percollection").disabled = disabled; + document.getElementById("menulist-updateinterval-units-percollection").disabled = disabled; + document.getElementById("notifications-group").disabled = disabled; + document.getElementById("label-addonsshow-percollection").disabled = disabled; + document.getElementById("label-addonsperpage-percollection").disabled = disabled; + document.getElementById("textbox-addonsperpage-percollection").disabled = disabled; + //document.getElementById("checkbox-autopublish-percollection").disabled = disabled; } -Bandwagon.Controller.Settings.doShowFeed = function() +Bandwagon.Controller.Settings.doShowCollection = function() { - var feed = null; - var selectedItem = Bandwagon.Controller.Settings.elemBandwagonFeeds.selectedItem; + var collection = null; + var selectedItem = Bandwagon.Controller.Settings.elemBandwagonCollections.selectedItem; - if (selectedItem && Bandwagon.Controller.Settings.elemBandwagonFeeds.selectedItem.feed) - feed = Bandwagon.Controller.Settings.feeds[Bandwagon.Controller.Settings.elemBandwagonFeeds.selectedItem.feed.url]; + if (selectedItem && Bandwagon.Controller.Settings.elemBandwagonCollections.selectedItem.collection) + collection = Bandwagon.Controller.Settings.collections[Bandwagon.Controller.Settings.elemBandwagonCollections.selectedItem.collection.resourceURL]; - Bandwagon.Logger.debug("showing feed: " + (feed?feed.url:"<none>")); + Bandwagon.Logger.debug("showing collection: " + (collection?collection.resourceURL:"<none>")); - if (!feed) + if (!collection) { - Bandwagon.Controller.Settings.elemFeedName.value = ""; + Bandwagon.Controller.Settings.elemCollectionName.value = ""; Bandwagon.Controller.Settings.invalidate(); return; } - Bandwagon.Controller.Settings.elemFeedName.value = (feed.name&&feed.name!=""?feed.name:feed.url); + if ( Bandwagon.Controller.Settings.elemCollectionName) + { + Bandwagon.Controller.Settings.elemCollectionName.value = (collection.name&&collection.name!=""?collection.name:collection.resourceURL); + } - if (document.getElementById("checkbox-updateinterval-global").checked) + if (document.getElementById("updates-group").selectedIndex == 0) // Hrm, this is not right, is it? { - // updateinterval: if "apply to all feeds" is checked - set updateinterval quantity and interval to global + // updateinterval: if "default" is selected - set updateinterval quantity and interval in default document.getElementById("textbox-updateinterval-quantity").valueNumber = parseInt(document.getElementById("extensions.bandwagon.updateall.interval").value); document.getElementById("menulist-updateinterval-units").selectedIndex = document.getElementById("extensions.bandwagon.updateall.units").value - 1; } else { - // updateinterval: if "apply to all feeds" is unchecked - set updateinterval quantity and interval to this feed + // updateinterval: if "Custom: " is selected - set updateinterval quantity and interval to this collection - var interval = Bandwagon.Util.intervalMillisecondsToUnits(feed.updateInterval*1000); + var interval = Bandwagon.Util.intervalMillisecondsToUnits(collection.updateInterval*1000); + document.getElementById("textbox-updateinterval-quantity-percollection").valueNumber = interval.interval; + document.getElementById("menulist-updateinterval-units-percollection").selectedIndex = interval.units-1; - document.getElementById("textbox-updateinterval-quantity").valueNumber = interval.interval; - document.getElementById("menulist-updateinterval-units").selectedIndex = interval.units-1; - - document.getElementById("checkbox-updateinterval-perfeed").checked = true; + document.getElementById("updates-group").selectedIndex = 1; } - if (document.getElementById("checkbox-shownotifications-global").checked) + // Turning off for now, not sure how to handle notifications when a collection is loaded + if (true) { - // shownotifications: if "apply to all feeds" is checked - set shownotifications to global - document.getElementById("checkbox-shownotifications-perfeed").checked = document.getElementById("extensions.bandwagon.notifyall.enabled").value; + // shownotifications: if "default" is selected - set shownotifications to global + } else { - // shownotifications: if "apply to all feeds" not checked - set shownotifications to this feed - document.getElementById("checkbox-shownotifications-perfeed").checked = feed.showNotifications; + // shownotifications: if "Custom" not selected - set shownotifications to this collection + } // autopublish - document.getElementById("checkbox-autopublish-perfeed").checked = feed.autoPublish; + //document.getElementById("checkbox-autopublish-percollection").checked = collection.autoPublish; Bandwagon.Controller.Settings.invalidate(); } -Bandwagon.Controller.Settings.doSaveFeed = function() +Bandwagon.Controller.Settings.doSaveCollection = function() { - Bandwagon.Logger.debug("in doSaveFeed()"); + Bandwagon.Logger.debug("in doSaveCollection()"); - // save settings to local copy of the feed objects + // save settings to local copy of the collection objects - var feed = Bandwagon.Controller.Settings.feeds[Bandwagon.Controller.Settings.elemBandwagonFeeds.selectedItem.feed.url]; + var collection = Bandwagon.Controller.Settings.collections[Bandwagon.Controller.Settings.elemBandwagonCollections.selectedItem.collection.resourceURL]; - if (!feed) + if (!collection) return; - feed.updateInterval = Bandwagon.Util.intervalUnitsToMilliseconds(document.getElementById("textbox-updateinterval-quantity").valueNumber, document.getElementById("menulist-updateinterval-units").selectedIndex+1) / 1000; - feed.showNotifications = document.getElementById("checkbox-shownotifications-perfeed").checked; - feed.autoPublish = document.getElementById("checkbox-autopublish-perfeed").checked; + collection.updateInterval = Bandwagon.Util.intervalUnitsToMilliseconds(document.getElementById("textbox-updateinterval-quantity").valueNumber, document.getElementById("menulist-updateinterval-units").selectedIndex+1) / 1000; + collection.showNotifications = (document.getElementById("notifications-group").selectedIndex == 1); + //collection.autoPublish = document.getElementById("checkbox-autopublish-percollection").checked; if (document.getElementById("bandwagon-settings").instantApply) { @@ -217,63 +227,211 @@ Bandwagon.Controller.Settings.doSaveFeed = function() } } -Bandwagon.Controller.Settings._repopulateFeedsList = function() +Bandwagon.Controller.Settings._repopulateCollectionsList = function() { // first clear the list - while (Bandwagon.Controller.Settings.elemBandwagonFeeds.hasChildNodes()) + while (Bandwagon.Controller.Settings.elemBandwagonCollections.hasChildNodes()) { - Bandwagon.Controller.Settings.elemBandwagonFeeds.removeChild(Bandwagon.Controller.Settings.elemBandwagonFeeds.firstChild); + Bandwagon.Controller.Settings.elemBandwagonCollections.removeChild(Bandwagon.Controller.Settings.elemBandwagonCollections.firstChild); } - // repopulate with feeds + // repopulate with collections - for (var id in bandwagonService.feeds) + for (var id in bandwagonService.collections) { - var feed = bandwagonService.feeds[id]; + var collection = bandwagonService.collections[id]; - if (feed == null) + if (collection == null) return; const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - var elemBandwagonFeed = document.createElementNS(XULNS, "bandwagonFeed"); - elemBandwagonFeed.setAttribute("view", "settings"); + var elemBandwagonCollection = document.createElementNS(XULNS, "bandwagonCollection"); + elemBandwagonCollection.setAttribute("view", "settings"); - elemBandwagonFeed.feed = feed; - elemBandwagonFeed.controller = Bandwagon.Controller.Settings; + elemBandwagonCollection.collection = collection; + elemBandwagonCollection.controller = Bandwagon.Controller.Settings; - Bandwagon.Controller.Settings.elemBandwagonFeeds.appendChild(elemBandwagonFeed); + Bandwagon.Controller.Settings.elemBandwagonCollections.appendChild(elemBandwagonCollection); } - // create the local copy of the feeds hash with the properties we need + // create the local copy of the collections hash with the properties we need - Bandwagon.Controller.Settings.feeds = {}; + Bandwagon.Controller.Settings.collections = {}; - for (var id in bandwagonService.feeds) + for (var id in bandwagonService.collections) { - var feed = bandwagonService.feeds[id]; + var collection = bandwagonService.collections[id]; - Bandwagon.Controller.Settings.feeds[id] = + Bandwagon.Controller.Settings.collections[id] = { - name: feed.name, - url: feed.url, - updateInterval: feed.updateInterval, - showNotifications: feed.showNotifications, - feedItemsPerPage: feed.feedItemsPerPage, - autoPublish: feed.autoPublish + name: collection.name, + url: collection.resourceURL, + updateInterval: collection.updateInterval, + showNotifications: collection.showNotifications, + addonsPerPage: collection.addonsPerPage, + autoPublish: collection.autoPublish }; } } Bandwagon.Controller.Settings.bindingsReady = function() { - var elemBandwagonFeed = Bandwagon.Controller.Settings.elemBandwagonFeeds.getElementsByTagName("bandwagonFeed")[0]; + var elemBandwagonCollection = Bandwagon.Controller.Settings.elemBandwagonCollections.getElementsByTagName("bandwagonCollection")[0]; + + if (elemBandwagonCollection) + { + Bandwagon.Controller.Settings.elemBandwagonCollections.selectItem(elemBandwagonCollection); + Bandwagon.Controller.Settings.elemBandwagonCollections.focus(); + } +} + +/* Startup check */ +Bandwagon.Controller.Settings.LoginCheck = function() +{ + var isLoggedIn = false; // XX TODO + var loginEmail = "me@example.com"; // XX TODO + var textNode = document.getElementById("login-status-text"); + if (isLoggedIn) + { + document.getElementById("login-button").collapsed = true; + document.getElementById("logout-button").removeAttribute("collapsed"); + textNode.value = Bandwagon.Controller.Settings.stringBundle.getFormattedString("login.status", [loginEmail]); + } + else + { + textNode.value = Bandwagon.Controller.Settings.stringBundle.getString("logout.status");; + } +} + +Bandwagon.Controller.Settings.doLogin = function() +{ + // XX TODO +} + +Bandwagon.Controller.Settings.doLogout = function() +{ + // XX TODO +} + +/* Startup check */ +Bandwagon.Controller.Settings.AutoCheck = function() +{ + var hasAuto = false; // XX TODO + if (hasAuto) + { + document.getElementById("auto-create-button").collapsed = true; + document.getElementById("auto-delete-button").removeAttribute("collapsed"); + } + else + { + } +} + +Bandwagon.Controller.Settings.doAutoCreate = function() +{ + // check form + document.getElementById("auto-error").value = ""; + document.getElementById("auto-error").collapsed = true; + + var collectionName = document.getElementById("auto-name").value; - if (elemBandwagonFeed) + if (!collectionName || collectionName == "") { - Bandwagon.Controller.Settings.elemBandwagonFeeds.selectItem(elemBandwagonFeed); - Bandwagon.Controller.Settings.elemBandwagonFeeds.focus(); + document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getFormattedString("auto.invalid.name", [collectionName]); + document.getElementById("auto-error").collapsed = false; + return; + } + + var autoPublishExtensions = document.getElementById("auto-type-extensions").checked; + var autoPublishThemes = document.getElementById("auto-type-themes").checked; + var autoPublishDicts = document.getElementById("auto-type-dicts").checked; + var autoPublishLangPacks = document.getElementById("auto-type-langpacks").checked; + + if (!autoPublishExtensions && !autoPublishThemes && !autoPublishDicts && !autoPublishLangPacks) + { + document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getString("auto.please.select.type"); + document.getElementById("auto-error").collapsed = false; + return; + } + + // disable ui settings, show throbber + + var toggleUIEnabledState = function(on) + { + document.getElementById("auto-create-button").disabled = on; + document.getElementById("auto-name").disabled = on; + document.getElementById("auto-list").disabled = on; + document.getElementById("auto-type-extensions").disabled = on; + document.getElementById("auto-type-themes").disabled = on; + document.getElementById("auto-type-dicts").disabled = on; + document.getElementById("auto-type-langpacks").disabled = on; + document.getElementById("auto-spinner").collapsed = !on; + } + + toggleUIEnabledState(true); + + // create the collection object + + var collection = new Bandwagon.Model.Collection(); + + collection.name = collectionName; + collection.description = collectionName; // nothing better to put here - api demands it + collection.listed = document.getElementById("auto-list").checked; + collection.writable = true; + collection.autoPublish = true; + collection.showNotifications = false; + collection.updateInterval = 60 * 60 * 24; + collection.addonsPerPage = Bandwagon.DEFAULT_ADDONS_PER_PAGE; + collection.status = collection.STATUS_NEW; + + collection.autoPublishExtensions = autoPublishExtensions; + collection.autoPublishThemes = autoPublishThemes; + collection.autoPublishDicts = autoPublishDicts; + collection.autoPublishLangPacks = autoPublishLangPacks; + + // send the api call + + var newCollectionCallback = function(event) + { + if (event.isError()) + { + document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getString("auto.internal.error"); + document.getElementById("auto-error").collapsed = false; + toggleUIEnabledState(false); + } + else + { + // on callback of above, refresh collection list + //bandwagonService.forceCheckAllForUpdatesAndUpdateCollectionsList(); + + // on callback of above, tell user we're done + document.getElementById("auto-error").style.color = 'green'; + document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getString("auto.done"); + document.getElementById("auto-error").collapsed = false; + + // clean-up + document.getElementById("auto-create-button").collapsed = true; + document.getElementById("auto-delete-button").collapsed = false; + document.getElementById("auto-spinner").collapsed = true; + } } + + bandwagonService.newCollection(collection, newCollectionCallback); +} + +Bandwagon.Controller.Settings.doAutoDelete = function() +{ + // XX TODO +} + +/* Startup check */ +Bandwagon.Controller.Settings.EmailsCheck = function() +{ + var numEmails = 0; // XX TODO + var textNode = document.getElementById("clear-emails-text"); + textNode.value = Bandwagon.Controller.Settings.stringBundle.getFormattedString("saved.emails.text", [numEmails]); + document.getElementById("clear-emails-button").disabled = (numEmails <= 0); } Bandwagon.Controller.Settings.doAccept = function() @@ -282,27 +440,27 @@ Bandwagon.Controller.Settings.doAccept = function() // called: // - when user clicks 'Ok' (on systems that show the ok button) - // - when user changes feed properties (on systems that don't show buttons) + // - when user changes collection properties (on systems that don't show buttons) - // copy the locally update settings over the global feed settings + // copy the locally update settings over the global collection settings - for (var id in Bandwagon.Controller.Settings.feeds) + for (var id in Bandwagon.Controller.Settings.collections) { - var localFeed = Bandwagon.Controller.Settings.feeds[id]; - var bwFeed = bandwagonService.feeds[id]; + var localCollection = Bandwagon.Controller.Settings.collections[id]; + var bwCollection = bandwagonService.collections[id]; - if (!localFeed || !bwFeed) + if (!localCollection || !bwCollection) continue; - if (bwFeed.feedItemsPerPage != localFeed.feedItemsPerPage) + if (bwCollection.addonsPerPage != localCollection.addonsPerPage) { - bwFeed.feedItemsPerPage = localFeed.feedItemsPerPage; - Bandwagon.Preferences.notifyObservers("feeditemsperpage:" + bwFeed.url); + bwCollection.addonsPerPage = localCollection.addonsPerPage; + Bandwagon.Preferences.notifyObservers("addonsperpage:" + bwCollection.resourceURL); } - bwFeed.updateInterval = localFeed.updateInterval; - bwFeed.showNotifications = localFeed.showNotifications; - bwFeed.autoPublish = localFeed.autoPublish; + bwCollection.updateInterval = localCollection.updateInterval; + bwCollection.showNotifications = localCollection.showNotifications; + bwCollection.autoPublish = localCollection.autoPublish; } } @@ -314,30 +472,35 @@ Bandwagon.Controller.Settings.doCancel = function() Bandwagon.Controller.Settings.doChangePassword = function() { // TODO + + alert('TBD'); } +/** OBSOLETE Bandwagon.Controller.Settings.doAdd = function() { var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); - var promptTitle = Bandwagon.Controller.Settings.stringBundle.getString("add.feed"); - var promptMsg = Bandwagon.Controller.Settings.stringBundle.getString("enter.url.to.add.feed"); + var promptTitle = Bandwagon.Controller.Settings.stringBundle.getString("add.collection"); + var promptMsg = Bandwagon.Controller.Settings.stringBundle.getString("enter.url.to.add.collection"); var input = {value: "http://"}; var check = {value: false}; var proceed = prompts.prompt(window, promptTitle, promptMsg, input, null, check); if (proceed) { - bandwagonService.addPreviewFeed(input.value); + bandwagonService.addPreviewCollection(input.value); } } +*/ +/** OBSOLETE XX Brian, er, I think not, see Remove Subscription button Bandwagon.Controller.Settings.doRemove = function() { - var feed = Bandwagon.Controller.Settings.elemBandwagonFeeds.selectedItem.feed; + var collection = Bandwagon.Controller.Settings.elemBandwagonCollections.selectedItem.collection; - if (feed == null) + if (collection == null) return; var promptService; @@ -348,8 +511,8 @@ Bandwagon.Controller.Settings.doRemove = function() promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService); } catch (e) { return; } - var promptTitle = Bandwagon.Controller.Settings.stringBundle.getString("remove.feed"); - var promptMsg = Bandwagon.Controller.Settings.stringBundle.getFormattedString("are.you.sure.you.want.to.remove", [(feed.name?feed.name:feed.url)]); + var promptTitle = Bandwagon.Controller.Settings.stringBundle.getString("remove.collection"); + var promptMsg = Bandwagon.Controller.Settings.stringBundle.getFormattedString("are.you.sure.you.want.to.remove", [(collection.name?collection.name:collection.resourceURL)]); var proceed = promptService.confirm( window, promptTitle, @@ -360,27 +523,41 @@ Bandwagon.Controller.Settings.doRemove = function() { // TODO for non-instant-apply dialogs, should we wait until 'Ok' is clicked before removal? - bandwagonService.deleteFeed(feed); + bandwagonService.deleteCollection(collection); - if (!feed.preview) - bandwagonService.unsubscribe(feed); + if (!collection.preview) + bandwagonService.unsubscribe(collection); } } +*/ + +/* See above */ +Bandwagon.Controller.Settings.doRemove = function() +{ + alert("TBD!"); +} Bandwagon.Controller.Settings.doUpdateIntervalScopeChange = function(event) { - document.getElementById("extensions.bandwagon.updateall.interval").value = document.getElementById("textbox-updateinterval-quantity").valueNumber; - document.getElementById("extensions.bandwagon.updateall.units").value = document.getElementById("menulist-updateinterval-units").selectedIndex + 1; - document.getElementById("extensions.bandwagon.updateall.enabled").value = (document.getElementById("checkbox-updateinterval-perfeed").checked && document.getElementById("checkbox-updateinterval-global").checked); + if (document.getElementById("updates-group").selectedIndex == 0) // Use default + { + document.getElementById("extensions.bandwagon.updateall.interval").value = document.getElementById("textbox-updateinterval-quantity").valueNumber; + document.getElementById("extensions.bandwagon.updateall.units").value = document.getElementById("menulist-updateinterval-units").selectedIndex + 1; + } + else + { + // Not sure if anything needs to be done here + } + document.getElementById("extensions.bandwagon.updateall.enabled").value = (document.getElementById("updates-group").selectedIndex == 0); - Bandwagon.Controller.Settings.doShowFeed(); + Bandwagon.Controller.Settings.doShowCollection(); } Bandwagon.Controller.Settings.doShowNotificationsScopeChange = function(event) { - document.getElementById("extensions.bandwagon.notifyall.enabled").value = (document.getElementById("checkbox-shownotifications-perfeed").checked && document.getElementById("checkbox-shownotifications-global").checked); + document.getElementById("extensions.bandwagon.notifyall.enabled").value = (document.getElementById("notifications-group").selectedIndex == 0); - Bandwagon.Controller.Settings.doShowFeed(); + Bandwagon.Controller.Settings.doShowCollection(); } |