diff options
Diffstat (limited to 'bandwagon/content')
25 files changed, 3184 insertions, 2207 deletions
diff --git a/bandwagon/content/scripts/bandwagon.js b/bandwagon/content/scripts/bandwagon.js index 55039b1..ff34feb 100644 --- a/bandwagon/content/scripts/bandwagon.js +++ b/bandwagon/content/scripts/bandwagon.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 @@ -42,15 +42,26 @@ Bandwagon.RPC = new function() {} Bandwagon.EMID = "sharing@addons.mozilla.org"; Bandwagon.SQLITE_FILENAME = "bandwagon.sqlite"; -Bandwagon.FEED_UPDATE_TIMER_DELAY = 60 * 60; // interval between checking if feeds need updating (in seconds) (this will always be 30 seconds in debug mode) -Bandwagon.DEFAULT_FEED_UPDATE_INTERVAL = 24 * 60 * 60; // default individual feed update interval (in seconds) -Bandwagon.DEFAULT_FEED_ITEMS_PER_PAGE = 20; -Bandwagon.DEFAULT_FEED1_URL = "https://services.addons.mozilla.org/en-US/firefox/api/1.1/list/featured/all/10/"; -Bandwagon.DEFAULT_FEED1_NAME = "Featured Add-ons"; +Bandwagon.COLLECTION_UPDATE_TIMER_DELAY = 60 * 60; // interval between checking if collection needs updating (in seconds) (this will always be 30 seconds in debug mode) +Bandwagon.DEFAULT_COLLECTION_UPDATE_INTERVAL = 24 * 60 * 60; // default individual collection update interval (in seconds) +Bandwagon.DEFAULT_ADDONS_PER_PAGE = 20; + +// REMEMBER: when changing AMO_HOST, the service document url in scripts/rpc/constants.js also has to be changed. + +Bandwagon.AMO_HOST = "bandwagon.stage.mozilla.com"; +Bandwagon.COLLECTIONSPANE_DO_SUBSCRIBE_URL = "https://" + Bandwagon.AMO_HOST + "/en-US/collections"; +Bandwagon.COLLECTIONSPANE_DO_LOGIN_URL = "https://" + Bandwagon.AMO_HOST + "/en-US/firefox/users/login?to=en-US%2Ffirefox%2Fcollections"; +Bandwagon.COLLECTIONSPANE_DO_NEW_COLLECTION_URL = "https://" + Bandwagon.AMO_HOST + "/en-US/firefox/collections/add"; Bandwagon.FIRSTRUN_LANDING_PAGE = "http://www.google.com/search?hl=en&q=bandwagon+first+run+landing+page&btnG=Google+Search&aq=f&oq="; // TODO -Bandwagon.FEEDSPANE_DO_SUBSCRIBE_URL = "http://www.google.com/search?hl=en&q=bandwagon+subscribe+page&btnG=Search"; // TODO -Bandwagon.MAGIC_ADD_FEED_COOKIE_HOST = "www.33eels.com"; // TODO -Bandwagon.MAGIC_ADD_FEED_COOKIE_NAME = "bandwagon_addfeed"; +Bandwagon.AMO_AUTH_COOKIE_HOST = Bandwagon.AMO_HOST; +Bandwagon.AMO_AUTH_COOKIE_NAME = "AMOv3"; + +/* ** OBSOLETE +//Bandwagon.DEFAULT_COLLECTION1_URL = "https://services.addons.mozilla.org/en-US/firefox/api/1.1/list/featured/all/10/"; +//Bandwagon.DEFAULT_COLLECTION1_NAME = "Featured Add-ons"; +//Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_HOST = "www.33eels.com"; +//Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_NAME = "bandwagon_addcollection"; +*/ Bandwagon.COMMIT_NOW = 0; // 1=commit on the fly. 0=commit when browser exit. diff --git a/bandwagon/content/scripts/factory/collectionFactory.js b/bandwagon/content/scripts/factory/collectionFactory.js new file mode 100644 index 0000000..a6b59ac --- /dev/null +++ b/bandwagon/content/scripts/factory/collectionFactory.js @@ -0,0 +1,758 @@ +/* ***** 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.Factory.CollectionFactory = function(connection) +{ + this.Bandwagon = Bandwagon; + this.connection = connection; +} + +Bandwagon.Factory.CollectionFactory.prototype.openServiceDocument = function() +{ + if (!this.connection) + return null; + + var statement = this.connection.createStatement("SELECT * FROM serviceDocument LIMIT 1"); + + var serviceDocument = null; + + try + { + statement.execute(); + + while (statement.executeStep()) + { + serviceDocument = new this.Bandwagon.Model.ServiceDocument(); + serviceDocument.emailResourceURL = statement.getUTF8String(0); + serviceDocument.collectionListResourceURL = statement.getUTF8String(1); + } + } + finally + { + statement.reset(); + } + + return serviceDocument; +} + +Bandwagon.Factory.CollectionFactory.prototype.commitServiceDocument = function(serviceDocument) +{ + if (!this.connection) + return null; + + var statement1 = this.connection.createStatement("DELETE FROM serviceDocument"); + + try + { + statement1.execute(); + } + finally + { + statement1.reset(); + } + + var statement2 = this.connection.createStatement("INSERT INTO serviceDocument VALUES (?1, ?2)"); + + try + { + statement2.bindUTF8StringParameter(0, serviceDocument.emailResourceURL); + statement2.bindUTF8StringParameter(1, serviceDocument.collectionListResourceURL); + statement2.execute(); + } + finally + { + statement2.reset(); + } +} + +Bandwagon.Factory.CollectionFactory.prototype.newCollection = function() +{ + return new this.Bandwagon.Model.Collection(); +} + +Bandwagon.Factory.CollectionFactory.prototype.openCollection = function(collection_id) +{ + if (!this.connection) + return null; + + var collections = {}; + + var statement = this.connection.createStatement("SELECT * FROM collections where id = ?1"); + + try + { + statement.bindInt32Parameter(0, collection_id); + statement.execute(); + + var collection = this._openCollectionFromRS(statement); + + if (!collection) + return null; + + collection.addons = this._openAddons(collection); + + collections[collection.resourceURL] = collection; + } + finally + { + statement.reset(); + } + + return collection; +} + +Bandwagon.Factory.CollectionFactory.prototype.openCollections = function() +{ + if (!this.connection) + return null; + + var collections = {}; + + var statement = this.connection.createStatement("SELECT * FROM collections"); + + try + { + while (statement.executeStep()) + { + var collection = this._openCollectionFromRS(statement); + + if (!collection) + continue; + + collection.addons = this._openAddons(collection); + + collections[collection.resourceURL] = collection; + } + } + finally + { + statement.reset(); + } + + return collections; +} + +Bandwagon.Factory.CollectionFactory.prototype.commitCollection = function(collection) +{ + if (!this.connection) + return; + + var statement = this.connection.createStatement("REPLACE INTO collections VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17)"); + + try + { + (collection.storageID==-1?statement.bindNullParameter(0):statement.bindInt32Parameter(0, collection.storageID)); + statement.bindUTF8StringParameter(1, collection.resourceURL); + statement.bindUTF8StringParameter(2, collection.name); + statement.bindUTF8StringParameter(3, collection.description); + statement.bindInt32Parameter(4, collection.dateAdded.getTime()/1000); + (collection.dateLastCheck == null?statement.bindNullParameter(5):statement.bindInt32Parameter(5, collection.dateLastCheck.getTime()/1000)); + statement.bindInt32Parameter(6, collection.updateInterval); + statement.bindInt32Parameter(7, (collection.showNotifications?1:0)); + statement.bindInt32Parameter(8, (collection.autoPublish?1:0)); + statement.bindInt32Parameter(9, (collection.active?1:0)); + statement.bindInt32Parameter(10, collection.addonsPerPage); + statement.bindUTF8StringParameter(11, collection.creator); + statement.bindInt32Parameter(12, collection.listed); + statement.bindInt32Parameter(13, collection.writable); + statement.bindInt32Parameter(14, collection.subscribed); + (collection.lastModified == null?statement.bindNullParameter(15):statement.bindInt32Parameter(15, collection.lastModified.getTime()/1000)); + statement.bindUTF8StringParameter(16, collection.addonsResourceURL); + + statement.execute(); + } + finally + { + statement.reset(); + } + + if (collection.storageID == -1) + { + collection.storageID = this.connection.lastInsertRowID; + } + + for (var id in collection.addons) + { + this._commitAddon(collection, collection.addons[id]); + } + + return true; +} + +Bandwagon.Factory.CollectionFactory.prototype.commitCollections = function(collections) +{ + for (var id in collections) + { + this.commitCollection(collections[id]); + } +} + +Bandwagon.Factory.CollectionFactory.prototype.deleteCollection = function(collection) +{ + if (!this.connection) + return null; + + var statement1 = this.connection.createStatement("DELETE FROM collections where id = ?1"); + var statement2 = this.connection.createStatement("DELETE FROM collectionsAddons where collection = ?1"); + + try + { + // TODO transaction here? + + statement1.bindInt32Parameter(0, collection.storageID); + statement1.execute(); + + statement2.bindInt32Parameter(0, collection.storageID); + statement2.execute(); + } + finally + { + statement1.reset(); + statement2.reset(); + } + + return (statement2.lastError>0?false:true); +} + +// private methods + +Bandwagon.Factory.CollectionFactory.prototype._openCollectionFromRS = function(resultset) +{ + var collection = new this.Bandwagon.Model.Collection(); + collection.storageID = resultset.getInt32(0); + collection.resourceURL = resultset.getUTF8String(1); + collection.name = resultset.getUTF8String(2); + collection.description = resultset.getUTF8String(3); + collection.dateAdded = new Date(resultset.getInt32(4)*1000); + + if (!resultset.getIsNull(5)) + collection.dateLastCheck = new Date(resultset.getInt32(5)*1000); + + collection.updateInterval = resultset.getInt32(6); + collection.showNotifications = (resultset.getInt32(7)==1?true:false); + collection.autoPublish = (resultset.getInt32(8)==1?true:false); + collection.active = (resultset.getInt32(9)==1?true:false); + collection.addonsPerPage = resultset.getInt32(10); + collection.creator = resultset.getUTF8String(11); + collection.listed = resultset.getInt32(12); + collection.writable = resultset.getInt32(13); + collection.subscribed = resultset.getInt32(14); + + if (!resultset.getIsNull(15)) + collection.lastModified = new Date(resultset.getInt32(15)*1000); + + collection.addonsResourceURL = resultset.getUTF8String(16); + + return collection; +} + +Bandwagon.Factory.CollectionFactory.prototype._openAddons = function(collection) +{ + var addons = {}; + + var statement = this.connection.createStatement("SELECT addons.*, collectionsAddons.id, collectionsAddons.read FROM addons LEFT JOIN collectionsAddons ON addons.id = collectionsAddons.addon WHERE collectionsAddons.collection = ?1 LIMIT ?2"); + + try + { + statement.bindInt32Parameter(0, collection.storageID); + statement.bindInt32Parameter(1, this.Bandwagon.DEFAULT_ADDONS_PER_PAGE); + + while (statement.executeStep()) + { + var addon = new this.Bandwagon.Model.Addon(); + addon.Bandwagon = this.Bandwagon; + + addon.storageID = statement.getInt32(0); + addon.guid = statement.getUTF8String(1); + addon.name = statement.getUTF8String(2); + addon.type = statement.getInt32(3); + addon.version = statement.getUTF8String(4); + addon.status = statement.getInt32(5); + addon.summary = statement.getUTF8String(6); + addon.description = statement.getUTF8String(7); + addon.icon = statement.getUTF8String(8); + addon.eula = statement.getUTF8String(9); + addon.thumbnail = statement.getUTF8String(10); + addon.learnmore = statement.getUTF8String(11); + addon.author = statement.getUTF8String(12); + addon.category = statement.getUTF8String(13); + addon.dateAdded = new Date(statement.getInt32(14)*1000); + addon.collectionsAddonsStorageID = statement.getInt32(15); + addon.read = (statement.getInt32(16)==1?true:false); + + addon.compatibleApplications = this._openAddonCompatibleApplications(addon); + addon.compatibleOS = this._openAddonCompatibleOS(addon); + addon.installs = this._openAddonInstalls(addon); + addon.comments = this._openAddonComments(addon); + addon.authors = this._openAddonAuthors(addon); + + addons[addon.guid] = addon; + } + } + finally + { + statement.reset(); + } + + return addons; +} + +Bandwagon.Factory.CollectionFactory.prototype._openAddonCompatibleApplications = function(addon) +{ + var compatibleApplications = {}; + + var statement = this.connection.createStatement("SELECT * FROM addonCompatibleApplications WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addon.storageID); + + while (statement.executeStep()) + { + var application = + { + name: statement.getUTF8String(1).toString().toUpperCase(), + applicationId: statement.getInt32(2), + minVersion: statement.getUTF8String(3), + maxVersion: statement.getUTF8String(4), + guid: statement.getUTF8String(5) + }; + + compatibleApplications[application.name.toUpperCase()] = application; + } + } + finally + { + statement.reset(); + } + + return compatibleApplications; +} + +Bandwagon.Factory.CollectionFactory.prototype._openAddonCompatibleOS = function(addon) +{ + var compatibleOS = {}; + + var statement = this.connection.createStatement("SELECT * FROM addonCompatibleOS WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addon.storageID); + + while (statement.executeStep()) + { + var os = statement.getUTF8String(1).toString().toUpperCase(); + + compatibleOS[os] = os; + } + } + finally + { + statement.reset(); + } + + return compatibleOS; +} + +Bandwagon.Factory.CollectionFactory.prototype._openAddonInstalls = function(addon) +{ + var installs = {}; + + var statement = this.connection.createStatement("SELECT * FROM addonInstalls WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addon.storageID); + + while (statement.executeStep()) + { + var install = + { + url: statement.getUTF8String(1), + hash: statement.getUTF8String(2), + os: statement.getUTF8String(3).toString().toUpperCase() + }; + + installs[install.os] = install; + } + } + finally + { + statement.reset(); + } + + return installs; +} + +Bandwagon.Factory.CollectionFactory.prototype._openAddonComments = function(addon) +{ + var comments = []; + + var statement = this.connection.createStatement("SELECT * FROM addonComments WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addon.storageID); + + while (statement.executeStep()) + { + var comment = + { + comment: statement.getUTF8String(1), + author: statement.getUTF8String(2) + }; + + comments.push(comment); + } + } + finally + { + statement.reset(); + } + + return comments; +} + +Bandwagon.Factory.CollectionFactory.prototype._openAddonAuthors = function(addon) +{ + var authors = []; + + var statement = this.connection.createStatement("SELECT * FROM addonAuthors WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addon.storageID); + + while (statement.executeStep()) + { + authors.push(statement.getUTF8String(1)); + } + } + finally + { + statement.reset(); + } + + return authors; +} + +Bandwagon.Factory.CollectionFactory.prototype._commitAddon = function(collection, addon) +{ + if (!this.connection) + return; + + // addons + // if guid already exists - just update the addon + // if guid doesn't exist - insert + + var statement = this.connection.createStatement("SELECT id FROM addons where guid = ?1"); + var addonStorageID = null; + + try + { + statement.bindUTF8StringParameter(0, addon.guid); + + while (statement.executeStep()) + { + addonStorageID = statement.getInt32(0); + } + } + finally + { + statement.reset(); + } + + var statement2 = this.connection.createStatement("REPLACE INTO addons VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15)"); + + try + { + if (addonStorageID != null) + { + // addon already exists (in another collection, or from previous commit of this collection) + statement2.bindInt32Parameter(0, addonStorageID); + } + else if (addon.storageID != -1) + { + // addon doesn't already exist, but exists from a previous commit of this collection (?) + statement2.bindInt32Parameter(0, addon.storageID); + } + else + { + // new addon + statement2.bindNullParameter(0) + } + + statement2.bindUTF8StringParameter(1, addon.guid); + statement2.bindUTF8StringParameter(2, addon.name); + statement2.bindInt32Parameter(3, addon.type); + statement2.bindUTF8StringParameter(4, addon.version); + statement2.bindInt32Parameter(5, addon.status); + statement2.bindUTF8StringParameter(6, addon.summary); + statement2.bindUTF8StringParameter(7, addon.description); + statement2.bindUTF8StringParameter(8, addon.icon); + statement2.bindUTF8StringParameter(9, addon.eula); + statement2.bindUTF8StringParameter(10, addon.thumbnail); + statement2.bindUTF8StringParameter(11, addon.learnmore); + statement2.bindUTF8StringParameter(12, addon.author); + statement2.bindUTF8StringParameter(13, addon.category); + statement2.bindUTF8StringParameter(14, addon.dateAdded.getTime()/1000); + + statement2.execute(); + } + finally + { + statement2.reset(); + } + + if (addon.storageID == -1 && addonStorageID == null) + { + addonStorageID = this.connection.lastInsertRowID; + } + + // add the other addon bits + + for (var id in addon.compatibleApplications) + { + this._commitAddonCompatibleApplication(addonStorageID, addon.compatibleApplications[id]); + } + + for (var id in addon.compatibleOS) + { + this._commitAddonCompatibleOS(addonStorageID, addon.compatibleOS[id]); + } + + for (var id in addon.installs) + { + this._commitAddonInstall(addonStorageID, addon.installs[id]); + } + + for (var i=0; i<addon.comments.length; i++) + { + this._commitAddonComment(addonStorageID, addon.comments[i]); + } + + for (var id in addon.authors) + { + this._commitAddonAuthor(addonStorageID, addon.authors[id]); + } + + // add the addon connector + + var statement3 = this.connection.createStatement("REPLACE INTO collectionsAddons VALUES (?1, ?2, ?3, ?4)"); + + try + { + if (addon.collectionsAddonsStorageID == -1) + { + statement3.bindNullParameter(0); + } + else + { + statement3.bindInt32Parameter(0, addon.collectionsAddonsStorageID); + } + + statement3.bindInt32Parameter(1, collection.storageID); + statement3.bindInt32Parameter(2, addonStorageID); + statement3.bindInt32Parameter(3, (addon.read?1:0)); + + statement3.execute(); + } + finally + { + statement3.reset(); + } + + if (addon.collectionsAddonsStorageID == -1) + { + addon.collectionsAddonsStorageID = this.connection.lastInsertRowID; + } + + return true; +} + +Bandwagon.Factory.CollectionFactory.prototype._commitAddonCompatibleApplication = function(addonStorageID, application) +{ + var statement = this.connection.createStatement("DELETE FROM addonCompatibleApplications WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addonStorageID); + statement.execute(); + } + finally + { + statement.reset(); + } + + var statement2 = this.connection.createStatement("INSERT INTO addonCompatibleApplications VALUES (?1, ?2, ?3, ?4, ?5, ?6)"); + + try + { + statement2.bindInt32Parameter(0, addonStorageID); + statement2.bindUTF8StringParameter(1, application.name); + statement2.bindInt32Parameter(2, application.applicationId); + statement2.bindUTF8StringParameter(3, application.minVersion); + statement2.bindUTF8StringParameter(4, application.maxVersion); + statement2.bindUTF8StringParameter(5, application.guid); + + statement2.execute(); + } + finally + { + statement2.reset(); + } +} + +Bandwagon.Factory.CollectionFactory.prototype._commitAddonCompatibleOS = function(addonStorageID, os) +{ + var statement = this.connection.createStatement("DELETE FROM addonCompatibleOS WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addonStorageID); + statement.execute(); + } + finally + { + statement.reset(); + } + + var statement2 = this.connection.createStatement("INSERT INTO addonCompatibleOS VALUES (?1, ?2)"); + + try + { + statement2.bindInt32Parameter(0, addonStorageID); + statement2.bindUTF8StringParameter(1, os); + + statement2.execute(); + } + finally + { + statement2.reset(); + } +} + +Bandwagon.Factory.CollectionFactory.prototype._commitAddonInstall = function(addonStorageID, install) +{ + var statement = this.connection.createStatement("DELETE FROM addonInstalls WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addonStorageID); + statement.execute(); + } + finally + { + statement.reset(); + } + + var statement2 = this.connection.createStatement("INSERT INTO addonInstalls VALUES (?1, ?2, ?3, ?4)"); + + try + { + statement2.bindInt32Parameter(0, addonStorageID); + statement2.bindUTF8StringParameter(1, install.url); + statement2.bindUTF8StringParameter(2, install.hash); + statement2.bindUTF8StringParameter(3, install.os); + + statement2.execute(); + } + finally + { + statement2.reset(); + } +} + +Bandwagon.Factory.CollectionFactory.prototype._commitAddonComment = function(addonStorageID, comment) +{ + var statement = this.connection.createStatement("DELETE FROM addonComments WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addonStorageID); + statement.execute(); + } + finally + { + statement.reset(); + } + + var statement2 = this.connection.createStatement("INSERT INTO addonComments VALUES (?1, ?2, ?3)"); + + try + { + statement2.bindInt32Parameter(0, addonStorageID); + statement2.bindUTF8StringParameter(1, comment.comment); + statement2.bindUTF8StringParameter(2, comment.author); + + statement2.execute(); + } + finally + { + statement2.reset(); + } +} + +Bandwagon.Factory.CollectionFactory.prototype._commitAddonAuthor = function(addonStorageID, author) +{ + var statement = this.connection.createStatement("DELETE FROM addonAuthors WHERE addon = ?1"); + + try + { + statement.bindInt32Parameter(0, addonStorageID); + statement.execute(); + } + finally + { + statement.reset(); + } + + var statement2 = this.connection.createStatement("INSERT INTO addonAuthors VALUES (?1, ?2)"); + + try + { + statement2.bindInt32Parameter(0, addonStorageID); + statement2.bindUTF8StringParameter(1, author); + + statement2.execute(); + } + finally + { + statement2.reset(); + } +} + + diff --git a/bandwagon/content/scripts/factory/feedFactory.js b/bandwagon/content/scripts/factory/feedFactory.js deleted file mode 100644 index b58823b..0000000 --- a/bandwagon/content/scripts/factory/feedFactory.js +++ /dev/null @@ -1,626 +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.Factory.FeedFactory = function(connection) -{ - this.Bandwagon = Bandwagon; - this.connection = connection; -} - -Bandwagon.Factory.FeedFactory.prototype.newFeed = function() -{ - return new this.Bandwagon.Model.Feed(); -} - -Bandwagon.Factory.FeedFactory.prototype.openFeed = function(feed_id) -{ - if (!this.connection) - return null; - - var feeds = {}; - - var statement = this.connection.createStatement("SELECT * FROM feeds where id = ?1"); - - try - { - statement.bindInt32Parameter(0, feed_id); - statement.execute(); - - var feed = this._openFeedFromRS(statement); - - if (!feed) - return null; - - feed.feedItems = this._openFeedItems(feed); - - feeds[feed.url] = feed; - } - finally - { - statement.reset(); - } - - return feed; -} - -Bandwagon.Factory.FeedFactory.prototype.openFeeds = function() -{ - if (!this.connection) - return null; - - var feeds = {}; - - var statement = this.connection.createStatement("SELECT * FROM feeds"); - - try - { - while (statement.executeStep()) - { - var feed = this._openFeedFromRS(statement); - - if (!feed) - continue; - - feed.feedItems = this._openFeedItems(feed); - - feeds[feed.url] = feed; - } - } - finally - { - statement.reset(); - } - - return feeds; -} - -Bandwagon.Factory.FeedFactory.prototype.commitFeed = function(feed) -{ - if (!this.connection) - return; - - var statement = this.connection.createStatement("REPLACE INTO feeds VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)"); - - try - { - (feed.id==-1?statement.bindNullParameter(0):statement.bindInt32Parameter(0, feed.id)); - statement.bindUTF8StringParameter(1, feed.url); - statement.bindUTF8StringParameter(2, feed.name); - statement.bindUTF8StringParameter(3, feed.description); - statement.bindInt32Parameter(4, feed.dateAdded.getTime()/1000); - (feed.dateLastCheck == null?statement.bindNullParameter(5):statement.bindInt32Parameter(5, feed.dateLastCheck.getTime()/1000)); - statement.bindInt32Parameter(6, feed.updateInterval); - statement.bindInt32Parameter(7, (feed.showNotifications?1:0)); - statement.bindInt32Parameter(8, (feed.autoPublish?1:0)); - statement.bindInt32Parameter(9, (feed.active?1:0)); - statement.bindInt32Parameter(10, feed.feedItemsPerPage); - - statement.execute(); - } - finally - { - statement.reset(); - } - - if (feed.id == -1) - { - feed.id = this.connection.lastInsertRowID; - } - - for (var id in feed.feedItems) - { - this._commitFeedItem(feed, feed.feedItems[id]); - } - - return true; -} - -Bandwagon.Factory.FeedFactory.prototype.commitFeeds = function(feeds) -{ - for (var id in feeds) - { - this.commitFeed(feeds[id]); - } -} - -Bandwagon.Factory.FeedFactory.prototype.deleteFeed = function(feed) -{ - if (!this.connection) - return null; - - var statement1 = this.connection.createStatement("DELETE FROM feeds where id = ?1"); - var statement2 = this.connection.createStatement("DELETE FROM feedItems where feed = ?1"); - - try - { - // TODO transaction here? - - statement1.bindInt32Parameter(0, feed.id); - statement1.execute(); - - statement2.bindInt32Parameter(0, feed.id); - statement2.execute(); - } - finally - { - statement1.reset(); - statement2.reset(); - } - - return (statement2.lastError>0?false:true); -} - -// private methods - -Bandwagon.Factory.FeedFactory.prototype._openFeedFromRS = function(resultset) -{ - var feed = new this.Bandwagon.Model.Feed(); - feed.id = resultset.getInt32(0); - feed.url = resultset.getUTF8String(1); - feed.name = resultset.getUTF8String(2); - feed.description = resultset.getUTF8String(3); - feed.dateAdded = new Date(resultset.getInt32(4)*1000); - - if (!resultset.getIsNull(5)) - feed.dateLastCheck = new Date(resultset.getInt32(5)*1000); - - feed.updateInterval = resultset.getInt32(6); - feed.showNotifications = (resultset.getInt32(7)==1?true:false); - feed.autoPublish = (resultset.getInt32(8)==1?true:false); - feed.active = (resultset.getInt32(9)==1?true:false); - feed.feedItemsPerPage = resultset.getInt32(10); - - return feed; -} - -Bandwagon.Factory.FeedFactory.prototype._openFeedItems = function(feed) -{ - var feedItems = {}; - - var statement = this.connection.createStatement("SELECT addons.*, feedItems.id, feedItems.read FROM addons LEFT JOIN feedItems ON addons.id = feedItems.addon WHERE feedItems.feed = ?1 LIMIT ?2"); - - try - { - statement.bindInt32Parameter(0, feed.id); - statement.bindInt32Parameter(1, this.Bandwagon.DEFAULT_FEED_ITEMS_PER_PAGE); - - while (statement.executeStep()) - { - var feedItem = new this.Bandwagon.Model.FeedItem(); - feedItem.Bandwagon = this.Bandwagon; - - feedItem.id = statement.getInt32(0); - feedItem.guid = statement.getUTF8String(1); - feedItem.name = statement.getUTF8String(2); - feedItem.type = statement.getInt32(3); - feedItem.version = statement.getUTF8String(4); - feedItem.status = statement.getInt32(5); - feedItem.summary = statement.getUTF8String(6); - feedItem.description = statement.getUTF8String(7); - feedItem.icon = statement.getUTF8String(8); - feedItem.eula = statement.getUTF8String(9); - feedItem.thumbnail = statement.getUTF8String(10); - feedItem.learnmore = statement.getUTF8String(11); - feedItem.author = statement.getUTF8String(12); - feedItem.category = statement.getUTF8String(13); - feedItem.dateAdded = new Date(statement.getInt32(14)*1000); - feedItem.feedItemId = statement.getInt32(15); - feedItem.read = (statement.getInt32(16)==1?true:false); - - feedItem.compatibleApplications = this._openFeedItemCompatibleApplications(feedItem); - feedItem.compatibleOS = this._openFeedItemCompatibleOS(feedItem); - feedItem.installs = this._openFeedItemInstalls(feedItem); - feedItem.comments = this._openFeedItemComments(feedItem); - - feedItems[feedItem.guid] = feedItem; - } - } - finally - { - statement.reset(); - } - - return feedItems; -} - -Bandwagon.Factory.FeedFactory.prototype._openFeedItemCompatibleApplications = function(feedItem) -{ - var compatibleApplications = {}; - - var statement = this.connection.createStatement("SELECT * FROM addonCompatibleApplications WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, feedItem.id); - - while (statement.executeStep()) - { - var application = - { - name: statement.getUTF8String(1).toString().toUpperCase(), - applicationId: statement.getInt32(2), - minVersion: statement.getUTF8String(3), - maxVersion: statement.getUTF8String(4), - guid: statement.getUTF8String(5) - }; - - compatibleApplications[application.name.toUpperCase()] = application; - } - } - finally - { - statement.reset(); - } - - return compatibleApplications; -} - -Bandwagon.Factory.FeedFactory.prototype._openFeedItemCompatibleOS = function(feedItem) -{ - var compatibleOS = {}; - - var statement = this.connection.createStatement("SELECT * FROM addonCompatibleOS WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, feedItem.id); - - while (statement.executeStep()) - { - var os = statement.getUTF8String(1).toString().toUpperCase(); - - compatibleOS[os] = os; - } - } - finally - { - statement.reset(); - } - - return compatibleOS; -} - -Bandwagon.Factory.FeedFactory.prototype._openFeedItemInstalls = function(feedItem) -{ - var installs = {}; - - var statement = this.connection.createStatement("SELECT * FROM addonInstalls WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, feedItem.id); - - while (statement.executeStep()) - { - var install = - { - url: statement.getUTF8String(1), - hash: statement.getUTF8String(2), - os: statement.getUTF8String(3).toString().toUpperCase() - }; - - installs[install.os] = install; - } - } - finally - { - statement.reset(); - } - - return installs; -} - -Bandwagon.Factory.FeedFactory.prototype._openFeedItemComments = function(feedItem) -{ - var comments = []; - - var statement = this.connection.createStatement("SELECT * FROM addonComments WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, feedItem.id); - - while (statement.executeStep()) - { - var comment = - { - comment: statement.getUTF8String(1), - author: statement.getUTF8String(2) - }; - - comments.push(comment); - } - } - finally - { - statement.reset(); - } - - return comments; -} - -Bandwagon.Factory.FeedFactory.prototype._commitFeedItem = function(feed, feedItem) -{ - if (!this.connection) - return; - - // addons - // if guid already exists - just update the addon - // if guid doesn't exist - insert - - var statement = this.connection.createStatement("SELECT id FROM addons where guid = ?1"); - var addonid = null; - - try - { - statement.bindUTF8StringParameter(0, feedItem.guid); - - while (statement.executeStep()) - { - addonid = statement.getInt32(0); - } - } - finally - { - statement.reset(); - } - - var statement2 = this.connection.createStatement("REPLACE INTO addons VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15)"); - - try - { - if (addonid != null) - { - // addon already exists (in another feed, or from previous commit of this feed) - statement2.bindInt32Parameter(0, addonid); - } - else if (feedItem.id != -1) - { - // addon doesn't already exist, but exists from a previous commit of this feed (?) - statement2.bindInt32Parameter(0, feedItem.id); - } - else - { - // new addon - statement2.bindNullParameter(0) - } - - statement2.bindUTF8StringParameter(1, feedItem.guid); - statement2.bindUTF8StringParameter(2, feedItem.name); - statement2.bindInt32Parameter(3, feedItem.type); - statement2.bindUTF8StringParameter(4, feedItem.version); - statement2.bindInt32Parameter(5, feedItem.status); - statement2.bindUTF8StringParameter(6, feedItem.summary); - statement2.bindUTF8StringParameter(7, feedItem.description); - statement2.bindUTF8StringParameter(8, feedItem.icon); - statement2.bindUTF8StringParameter(9, feedItem.eula); - statement2.bindUTF8StringParameter(10, feedItem.thumbnail); - statement2.bindUTF8StringParameter(11, feedItem.learnmore); - statement2.bindUTF8StringParameter(12, feedItem.author); - statement2.bindUTF8StringParameter(13, feedItem.category); - statement2.bindUTF8StringParameter(14, feedItem.dateAdded.getTime()/1000); - - statement2.execute(); - } - finally - { - statement2.reset(); - } - - if (feedItem.id == -1 && addonid == null) - { - addonid = this.connection.lastInsertRowID; - } - - // add the other addon bits - - for (var id in feedItem.compatibleApplications) - { - this._commitAddonCompatibleApplication(addonid, feedItem.compatibleApplications[id]); - } - - for (var id in feedItem.compatibleOS) - { - this._commitAddonCompatibleOS(addonid, feedItem.compatibleOS[id]); - } - - for (var id in feedItem.installs) - { - this._commitAddonInstall(addonid, feedItem.installs[id]); - } - - for (var i=0; i<feedItem.comments.length; i++) - { - this._commitAddonComment(addonid, feedItem.comments[i]); - } - - // add the feedItem connector - - var statement3 = this.connection.createStatement("REPLACE INTO feedItems VALUES (?1, ?2, ?3, ?4)"); - - try - { - if (feedItem.feedItemId == -1) - { - statement3.bindNullParameter(0); - } - else - { - statement3.bindInt32Parameter(0, feedItem.feedItemId); - } - - statement3.bindInt32Parameter(1, feed.id); - statement3.bindInt32Parameter(2, addonid); - statement3.bindInt32Parameter(3, (feedItem.read?1:0)); - - statement3.execute(); - } - finally - { - statement3.reset(); - } - - if (feedItem.feedItemId == -1) - { - feedItem.feedItemId = this.connection.lastInsertRowID; - } - - return true; -} - -Bandwagon.Factory.FeedFactory.prototype._commitAddonCompatibleApplication = function(addonid, application) -{ - var statement = this.connection.createStatement("DELETE FROM addonCompatibleApplications WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, addonid); - statement.execute(); - } - finally - { - statement.reset(); - } - - var statement2 = this.connection.createStatement("INSERT INTO addonCompatibleApplications VALUES (?1, ?2, ?3, ?4, ?5, ?6)"); - - try - { - statement2.bindInt32Parameter(0, addonid); - statement2.bindUTF8StringParameter(1, application.name); - statement2.bindInt32Parameter(2, application.applicationId); - statement2.bindUTF8StringParameter(3, application.minVersion); - statement2.bindUTF8StringParameter(4, application.maxVersion); - statement2.bindUTF8StringParameter(5, application.guid); - - statement2.execute(); - } - finally - { - statement2.reset(); - } -} - -Bandwagon.Factory.FeedFactory.prototype._commitAddonCompatibleOS = function(addonid, os) -{ - var statement = this.connection.createStatement("DELETE FROM addonCompatibleOS WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, addonid); - statement.execute(); - } - finally - { - statement.reset(); - } - - var statement2 = this.connection.createStatement("INSERT INTO addonCompatibleOS VALUES (?1, ?2)"); - - try - { - statement2.bindInt32Parameter(0, addonid); - statement2.bindUTF8StringParameter(1, os); - - statement2.execute(); - } - finally - { - statement2.reset(); - } -} - -Bandwagon.Factory.FeedFactory.prototype._commitAddonInstall = function(addonid, install) -{ - var statement = this.connection.createStatement("DELETE FROM addonInstalls WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, addonid); - statement.execute(); - } - finally - { - statement.reset(); - } - - var statement2 = this.connection.createStatement("INSERT INTO addonInstalls VALUES (?1, ?2, ?3, ?4)"); - - try - { - statement2.bindInt32Parameter(0, addonid); - statement2.bindUTF8StringParameter(1, install.url); - statement2.bindUTF8StringParameter(2, install.hash); - statement2.bindUTF8StringParameter(3, install.os); - - statement2.execute(); - } - finally - { - statement2.reset(); - } -} - -Bandwagon.Factory.FeedFactory.prototype._commitAddonComment = function(addonid, comment) -{ - var statement = this.connection.createStatement("DELETE FROM addonComments WHERE addon = ?1"); - - try - { - statement.bindInt32Parameter(0, addonid); - statement.execute(); - } - finally - { - statement.reset(); - } - - var statement2 = this.connection.createStatement("INSERT INTO addonComments VALUES (?1, ?2, ?3)"); - - try - { - statement2.bindInt32Parameter(0, addonid); - statement2.bindUTF8StringParameter(1, comment.comment); - statement2.bindUTF8StringParameter(2, comment.author); - - statement2.execute(); - } - finally - { - statement2.reset(); - } -} - diff --git a/bandwagon/content/scripts/logger.js b/bandwagon/content/scripts/logger.js index ce8d42c..b4393df 100644 --- a/bandwagon/content/scripts/logger.js +++ b/bandwagon/content/scripts/logger.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/scripts/model/feedItem.js b/bandwagon/content/scripts/model/addon.js index b71a592..5ef72b9 100644 --- a/bandwagon/content/scripts/model/feedItem.js +++ b/bandwagon/content/scripts/model/addon.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,7 +34,7 @@ * * ***** END LICENSE BLOCK ***** */ -Bandwagon.Model.FeedItem = function() +Bandwagon.Model.Addon = function() { try { @@ -45,8 +45,8 @@ Bandwagon.Model.FeedItem = function() this.TYPE_EXTENSION = 1; this.STATUS_PUBLIC = 4; - this.id = -1; // internal bandwagon addon id - this.feedItemId = -1; // internal bandwagon feeditem id + this.storageID = -1; + this.collectionsAddonsStorageID = -1; this.name = ""; this.type = -1; @@ -65,12 +65,12 @@ Bandwagon.Model.FeedItem = function() this.compatibleOS = {}; this.installs = {}; - this.author = ""; - this.category = ""; + this.authors = {}; + this.categories = {}; this.dateAdded = new Date(); this.comments = []; - this.read = false; // has the user seen this add-on in the feeds pane + this.read = false; // has the user seen this add-on in the collections pane this.notified = false; // have we notified the user that we have a new addon // *** temp comment @@ -78,13 +78,13 @@ Bandwagon.Model.FeedItem = function() } -Bandwagon.Model.FeedItem.INSTALL_YES = 1; -Bandwagon.Model.FeedItem.INSTALL_NO_ADDON_IS_FOR_OLDER_VERSION = 2; -Bandwagon.Model.FeedItem.INSTALL_NO_UPGRADE_TO_USE_THIS_VERSION = 3; -Bandwagon.Model.FeedItem.INSTALL_NO_MUST_DOWNLOAD_BETA = 4; -Bandwagon.Model.FeedItem.INSTALL_NO_NOT_COMPATIBLE_OS = 5; +Bandwagon.Model.Addon.INSTALL_YES = 1; +Bandwagon.Model.Addon.INSTALL_NO_ADDON_IS_FOR_OLDER_VERSION = 2; +Bandwagon.Model.Addon.INSTALL_NO_UPGRADE_TO_USE_THIS_VERSION = 3; +Bandwagon.Model.Addon.INSTALL_NO_MUST_DOWNLOAD_BETA = 4; +Bandwagon.Model.Addon.INSTALL_NO_NOT_COMPATIBLE_OS = 5; -Bandwagon.Model.FeedItem.prototype.canInstall = function(env) +Bandwagon.Model.Addon.prototype.canInstall = function(env) { // check is the extension compatible with this os @@ -92,7 +92,7 @@ Bandwagon.Model.FeedItem.prototype.canInstall = function(env) { var details = { - type: Bandwagon.Model.FeedItem.INSTALL_NO_NOT_COMPATIBLE_OS, + type: Bandwagon.Model.Addon.INSTALL_NO_NOT_COMPATIBLE_OS, requiredVersion: env.os }; @@ -109,7 +109,7 @@ Bandwagon.Model.FeedItem.prototype.canInstall = function(env) var details = { - type: Bandwagon.Model.FeedItem.INSTALL_NO_NOT_COMPATIBLE_OS, + type: Bandwagon.Model.Addon.INSTALL_NO_NOT_COMPATIBLE_OS, requiredVersion: env.appName }; @@ -130,7 +130,7 @@ Bandwagon.Model.FeedItem.prototype.canInstall = function(env) { details = { - type: Bandwagon.Model.FeedItem.INSTALL_NO_MUST_DOWNLOAD_BETA, + type: Bandwagon.Model.Addon.INSTALL_NO_MUST_DOWNLOAD_BETA, requiredVersion: application.minVersion }; } @@ -138,7 +138,7 @@ Bandwagon.Model.FeedItem.prototype.canInstall = function(env) { details = { - type: Bandwagon.Model.FeedItem.INSTALL_NO_UPGRADE_TO_USE_THIS_VERSION, + type: Bandwagon.Model.Addon.INSTALL_NO_UPGRADE_TO_USE_THIS_VERSION, requiredVersion: application.minVersion }; } @@ -152,7 +152,7 @@ Bandwagon.Model.FeedItem.prototype.canInstall = function(env) var details = { - type: Bandwagon.Model.FeedItem.INSTALL_NO_ADDON_IS_FOR_OLDER_VERSION, + type: Bandwagon.Model.Addon.INSTALL_NO_ADDON_IS_FOR_OLDER_VERSION, requiredVersion: application.maxVersion }; @@ -163,17 +163,17 @@ Bandwagon.Model.FeedItem.prototype.canInstall = function(env) var details = { - type: Bandwagon.Model.FeedItem.INSTALL_YES, + type: Bandwagon.Model.Addon.INSTALL_YES, requiredVersion: "" }; return details; } -Bandwagon.Model.FeedItem.prototype.getInstaller = function(os) +Bandwagon.Model.Addon.prototype.getInstaller = function(os) { var install; - var feedItem = this; + var addon = this; os = os.toUpperCase(); @@ -193,19 +193,19 @@ Bandwagon.Model.FeedItem.prototype.getInstaller = function(os) { URL: install.url, Hash: install.hash, - IconURL: feedItem.icon, + IconURL: addon.icon, toString: function () { return this.URL; } }; return installer; } -Bandwagon.Model.FeedItem.prototype.toString = function() +Bandwagon.Model.Addon.prototype.toString = function() { return this.name + " (" + this.guid + ")"; } -Bandwagon.Model.FeedItem.prototype.equals = function(other) +Bandwagon.Model.Addon.prototype.equals = function(other) { if (other == null) return false; @@ -213,7 +213,7 @@ Bandwagon.Model.FeedItem.prototype.equals = function(other) return (this.guid == other.guid); } -Bandwagon.Model.FeedItem.prototype.unserialize = function(xaddon) +Bandwagon.Model.Addon.prototype.unserialize = function(xaddon) { this.name = xaddon.name.text().toString(); this.type = xaddon.type.attribute("id").toString(); @@ -261,21 +261,28 @@ Bandwagon.Model.FeedItem.prototype.unserialize = function(xaddon) this.compatibleApplications[application.name.toUpperCase()] = application; } - /* TODO feed is missing info for the following: - * - * - author - * - category - * - when added - * - comments - */ - - if (xaddon.dateadded && xaddon.dateadded.text().toString() != "") + for each (var xauthor in xaddon.authors.author) { - this.dateAdded = new Date(xaddon.dateadded.text().toString()); + this.authors[xauthor.text().toString()] = xauthor.text().toString(); } - else if (this.dateAdded == null) + + for each (var xcategory in xaddon.categories.category) { - this.dateAdded = new Date(); + this.categories[xcategory.text().toString()] = xcategory.text().toString(); } + + this.dateAdded = this.Bandwagon.Util.ISO8601toDate(xaddon.meta.added.text().toString()); + + this.comments = []; + + var comment0Comment = xaddon.meta.comments.text().toString(); + var comment0Author = xaddon.meta.addedby.text().toString(); + + if (!comment0Author.match(/\w/)) + comment0Author = "Unknown"; + + if (comment0Comment.match(/\w/)) + this.comments.push({comment: comment0Comment, author: comment0Author}); + } diff --git a/bandwagon/content/scripts/model/collection.js b/bandwagon/content/scripts/model/collection.js new file mode 100644 index 0000000..a29df57 --- /dev/null +++ b/bandwagon/content/scripts/model/collection.js @@ -0,0 +1,211 @@ +/* ***** 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.Model.Collection = function() +{ + this.Bandwagon = Bandwagon; + + this.storageID = -1; + this.resourceURL = ""; + this.addonsResourceURL = ""; + + this.name = ""; + this.description = ""; + this.creator = ""; + this.listed = false; + this.writable = false; + this.subscribed = false; + this.lastModified = new Date(); + + this.password = null; + this.dateAdded = new Date(); + this.dateLastCheck = null; + this.updateInterval = this.Bandwagon.DEFAULT_COLLECTION_UPDATE_INTERVAL; // in seconds + this.showNotifications = true; + this.autoPublish = false; + this.active = true; + this.addonsPerPage = this.Bandwagon.DEFAULT_ADDONS_PER_PAGE; + + //this.preview = false; + + this.status = this.STATUS_NEW; + + this.addons = {}; +} + +Bandwagon.Model.Collection.prototype.STATUS_NEW = 0; +Bandwagon.Model.Collection.prototype.STATUS_LOADING = 1; +Bandwagon.Model.Collection.prototype.STATUS_LOADERROR = 2; +Bandwagon.Model.Collection.prototype.STATUS_LOADED = 3; + +Bandwagon.Model.Collection.prototype.getUnreadAddons = function() +{ + var unreadAddons = []; + + for (var id in this.addons) + { + if (!this.addons[id].read) + { + unreadAddons.push(this.addons[id]); + } + } + + return unreadAddons; +} + +Bandwagon.Model.Collection.prototype.setAllRead = function() +{ + for (var id in this.addons) + { + this.addons[id].read = true; + } +} + +Bandwagon.Model.Collection.prototype.getUnnotifiedAddons = function() +{ + var unnotifiedAddons = []; + + for (var id in this.addons) + { + if (!this.addons[id].notified) + { + unnotifiedAddons.push(this.addons[id]); + } + } + + return unnotifiedAddons; +} + +Bandwagon.Model.Collection.prototype.setAllNotified = function() +{ + for (var id in this.addons) + { + this.addons[id].notified = true; + } +} + +Bandwagon.Model.Collection.prototype.getSortedAddons = function() +{ + var sortedAddons = []; + + for (var id in this.addons) + { + sortedAddons.push(this.addons[id]); + } + + sortedAddons.sort(function(a, b) + { + // sorting is unread, then dateadded + + if (a.read == false && b.read == true ) return -1; + if (a.read == true && b.read == false ) return 1; + + return (a.dateAdded.getTime() < b.dateAdded.getTime()?1:-1); + }); + + return sortedAddons; +} + +Bandwagon.Model.Collection.prototype.hasAddon = function() +{ + for (var id in this.addons) + { + if (this.addons[id] && this.addons[id].guid) + { + return true; + } + } + + return false; +} + +Bandwagon.Model.Collection.prototype.getNicknameFromName = function() +{ + return this.name.replace(/\W/g, "_"); +} + +Bandwagon.Model.Collection.prototype.toString = function() +{ + return this.name + " (" + this.resourceURL + ")"; +} + +Bandwagon.Model.Collection.prototype.equals = function(other) +{ + if (other == null) + return false; + + return (this.resourceURL == other.resourceURL); +} + +Bandwagon.Model.Collection.prototype.unserialize = function(xcollection) +{ + var xmlns = new Namespace('http://www.w3.org/XML/1998/namespace'); + var baseURL = xcollection.@xmlns::base.toString(); + + //this.resourceURL = baseURL + "/" + xcollection.attribute("href").toString(); + + this.name = xcollection.attribute("name").toString(); + this.description = xcollection.attribute("description").toString(); + this.creator = xcollection.attribute("creator").toString(); + this.listed = (xcollection.attribute("listed").toString()=="yes"?true:false); + this.writable = (xcollection.attribute("writable").toString()=="yes"?true:false); + this.subscribed = (xcollection.attribute("subscribed").toString()=="yes"?true:false); + this.lastModified = this.Bandwagon.Util.ISO8601toDate(xcollection.attribute("lastmodified").toString()); + + //this.addonsResourceURL = baseURL + "/" + xcollection.addons.attribute("href").toString(); + + for each (var xaddon in xcollection.addons.addon) + { + var addon = new this.Bandwagon.Model.Addon(); + addon.Bandwagon = this.Bandwagon; + + addon.unserialize(xaddon); + + if (addon.guid && addon.guid != "" && addon.name && addon.name != "") + { + if (this.addons[addon.guid]) + { + // "merge" with existing item + this.addons[addon.guid].unserialize(xaddon); + } + else + { + this.addons[addon.guid] = addon; + } + } + } +} + diff --git a/bandwagon/content/scripts/model/feed.js b/bandwagon/content/scripts/model/feed.js deleted file mode 100644 index 412ee4a..0000000 --- a/bandwagon/content/scripts/model/feed.js +++ /dev/null @@ -1,189 +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.Model.Feed = function() -{ - this.Bandwagon = Bandwagon; - - this.id = -1; // internal bandwagon id - - this.url = ""; - this.name = ""; - this.description = ""; - this.password = null; - this.dateAdded = new Date(); - this.dateLastCheck = null; - this.updateInterval = this.Bandwagon.DEFAULT_FEED_UPDATE_INTERVAL; // in seconds - this.showNotifications = true; - this.autoPublish = false; - this.active = true; - this.feedItemsPerPage = this.Bandwagon.DEFAULT_FEED_ITEMS_PER_PAGE; - - this.preview = false; - this.editable = false; - this.status = this.STATUS_NEW; - - this.feedItems = {}; -} - -Bandwagon.Model.Feed.prototype.STATUS_NEW = 0; -Bandwagon.Model.Feed.prototype.STATUS_LOADING = 1; -Bandwagon.Model.Feed.prototype.STATUS_LOADERROR = 2; -Bandwagon.Model.Feed.prototype.STATUS_LOADED = 3; - -Bandwagon.Model.Feed.prototype.getUnreadFeedItems = function() -{ - var unreadFeedItems = []; - - for (var id in this.feedItems) - { - if (!this.feedItems[id].read) - { - unreadFeedItems.push(this.feedItems[id]); - } - } - - return unreadFeedItems; -} - -Bandwagon.Model.Feed.prototype.setAllRead = function() -{ - for (var id in this.feedItems) - { - this.feedItems[id].read = true; - } -} - -Bandwagon.Model.Feed.prototype.getUnnotifiedFeedItems = function() -{ - var unnotifiedFeedItems = []; - - for (var id in this.feedItems) - { - if (!this.feedItems[id].notified) - { - unnotifiedFeedItems.push(this.feedItems[id]); - } - } - - return unnotifiedFeedItems; -} - -Bandwagon.Model.Feed.prototype.setAllNotified = function() -{ - for (var id in this.feedItems) - { - this.feedItems[id].notified = true; - } -} - -Bandwagon.Model.Feed.prototype.getSortedFeedItems = function() -{ - var sortedFeedItems = []; - - for (var id in this.feedItems) - { - sortedFeedItems.push(this.feedItems[id]); - } - - sortedFeedItems.sort(function(a, b) - { - // sorting is unread, then dateadded - - if (a.read == false && b.read == true ) return -1; - if (a.read == true && b.read == false ) return 1; - - return (a.dateAdded.getTime() < b.dateAdded.getTime()?1:-1); - }); - - return sortedFeedItems; -} - -Bandwagon.Model.Feed.prototype.hasFeedItem = function() -{ - for (var id in this.feedItems) - { - if (this.feedItems[id] && this.feedItems[id].guid) - { - return true; - } - } - - return false; -} - -Bandwagon.Model.Feed.prototype.toString = function() -{ - return this.name + " (" + this.url + ")"; -} - -Bandwagon.Model.Feed.prototype.equals = function(other) -{ - if (other == null) - return false; - - return (this.url == other.url); -} - -Bandwagon.Model.Feed.prototype.unserialize = function(xaddons) -{ - for each (var xaddon in xaddons.addon) - { - var feedItem = new this.Bandwagon.Model.FeedItem(); - feedItem.Bandwagon = this.Bandwagon; - - feedItem.unserialize(xaddon); - - if (feedItem.guid && feedItem.guid != "" && feedItem.name && feedItem.name != "") - { - if (this.feedItems[feedItem.guid]) - { - // "merge" with existing item - this.feedItems[feedItem.guid].unserialize(xaddon); - } - else - { - this.feedItems[feedItem.guid] = feedItem; - } - } - } - - /* TODO feed is missing info for the following: - * - * - site url - */ - -} diff --git a/bandwagon/content/scripts/model/serviceDocument.js b/bandwagon/content/scripts/model/serviceDocument.js new file mode 100644 index 0000000..70ae5b3 --- /dev/null +++ b/bandwagon/content/scripts/model/serviceDocument.js @@ -0,0 +1,78 @@ +/* ***** 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.Model.ServiceDocument = function() +{ + this.Bandwagon = Bandwagon; + + this.emailResourceURL = ""; + this.collectionListResourceURL = ""; + + this.collections = []; +} + +Bandwagon.Model.ServiceDocument.prototype.unserialize = function(xsharing) +{ + var xmlns = new Namespace('http://www.w3.org/XML/1998/namespace'); + var baseURL = xsharing.@xmlns::base.toString(); + + // resource urls + + this.emailResourceURL = baseURL + "/" + xsharing.email.attribute("href").toString(); + this.collectionListResourceURL = baseURL + "/" + xsharing.collections.attribute("href").toString(); + + // collections + + for each (var xcollection in xsharing.collections.collection) + { + var collection = new this.Bandwagon.Model.Collection(); + collection.Bandwagon = this.Bandwagon; + + collection.resourceURL = baseURL + "/" + xcollection.attribute("href").toString(); + + collection.name = xcollection.attribute("name").toString(); + collection.description = xcollection.attribute("description").toString(); + collection.creator = xcollection.attribute("creator").toString(); + collection.listed = (xcollection.attribute("listed").toString()=="yes"?true:false); + collection.writable = (xcollection.attribute("writable").toString()=="yes"?true:false); + collection.subscribed = (xcollection.attribute("subscribed").toString()=="yes"?true:false); + collection.lastModified = this.Bandwagon.Util.ISO8601toDate(xcollection.attribute("lastmodified").toString()); + + collection.addonsResourceURL = baseURL + "/" + xcollection.addons.attribute("href").toString(); + + this.collections.push(collection); + } +} diff --git a/bandwagon/content/scripts/rpc/constants.js b/bandwagon/content/scripts/rpc/constants.js index 7f6e7da..7ecc85e 100644 --- a/bandwagon/content/scripts/rpc/constants.js +++ b/bandwagon/content/scripts/rpc/constants.js @@ -37,11 +37,14 @@ Bandwagon.RPC.Constants = new function() { - this.BANDWAGON_RPC_BASE_URL = "https://preview.addons.mozilla.org/en-US/"; - this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_ACTION = "firefox/api/recommend_email"; + this.BANDWAGON_RPC_SERVICE_DOCUMENT = "https://bandwagon.stage.mozilla.com/en-US/firefox/api/1.3/sharing"; - this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_FEED_COMPLETE = 100; - this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_COMPLETE = 200; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_SERVICE_DOCUMENT_COMPLETE = 100; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_COLLECTION_COMPLETE = 200; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_COMPLETE = 300; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_PUBLISH_COMPLETE = 400; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_REMOVE_ADDON_FROM_COLLECTION_COMPLETE = 500; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_NEW_COLLECTION_COMPLETE = 600; // xhr layer constants @@ -63,7 +66,7 @@ Bandwagon.RPC.Constants = new function() this.BANDWAGON_RPC_SERVICE_ERROR_BAD_REQUEST = 1400; //400 BAD REQUEST = Invalid request URI or header, or unsupported nonstandard parameter. this.BANDWAGON_RPC_SERVICE_ERROR_UNAUTHORIZED = 1401; //401 UNAUTHORIZED = Authorization required. this.BANDWAGON_RPC_SERVICE_ERROR_FORBIDDEN = 1403; //403 FORBIDDEN = Unsupported standard parameter, or authentication or authorization failed. - this.BANDWAGON_RPC_SERVICE_ERROR_NOT_FOUND = 1404; //404 NOT FOUND = Resource (such as a feed or entry) not found. + this.BANDWAGON_RPC_SERVICE_ERROR_NOT_FOUND = 1404; //404 NOT FOUND = Resource (such as a collection or entry) not found. this.BANDWAGON_RPC_SERVICE_ERROR_CONFLICT = 1409; //409 CONFLICT = Specified version number doesn't match resource's latest version number. this.BANDWAGON_RPC_SERVICE_ERROR_BAD_CONTEXT = 1422; //422 BAD CONTENT = The data within this entry's <content> is not valid. For example, this may indicate not "well-formed" XML this.BANDWAGON_RPC_SERVICE_ERROR_INTERNAL_SERVER_ERROR = 1500; //500 INTERNAL SERVER ERROR = Internal error. This is the default code that is used for all unrecognized errors. diff --git a/bandwagon/content/scripts/rpc/net.js b/bandwagon/content/scripts/rpc/net.js index 82c712e..28c3340 100644 --- a/bandwagon/content/scripts/rpc/net.js +++ b/bandwagon/content/scripts/rpc/net.js @@ -117,9 +117,12 @@ Bandwagon.RPC.Net = function(Bandwagon, Components) // parse xml here instead, put in response var var xmlStr = rpcnetrequest.responseText; - // workaround for E4X bug/feature + // workaround for E4X bugs/features xmlStr = xmlStr.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551 + //default xml namespace = 'http://addons.mozilla.org/'; + xmlStr = xmlStr.replace(/xmlns="http:\/\/addons.mozilla.org\/"/, ""); + response = new XML(xmlStr); //rpcnet._logger.debug("Bandwagon.RPC.Net.send.onreadystatechange: ' + rpcnet.id + ': XML representation: '" + response.toXMLString() + "'"); @@ -257,10 +260,16 @@ Bandwagon.RPC.Net.prototype.setMethod = function(method) { this._method = 'POST'; } - else + else if (method == 'DELETE') + { + this._method = 'DELETE'; + } + else { this._method = 'GET'; } + + this._method = method; } Bandwagon.RPC.Net.prototype.setCredentials = function(username, password) diff --git a/bandwagon/content/scripts/rpc/service.js b/bandwagon/content/scripts/rpc/service.js index 3d86270..dbf2eef 100644 --- a/bandwagon/content/scripts/rpc/service.js +++ b/bandwagon/content/scripts/rpc/service.js @@ -46,7 +46,8 @@ Bandwagon.RPC.Service = function() // private instance variables this._observers = new Array(); this._logger = null; - this._serviceRootURL = this.Bandwagon.RPC.Constants.BANDWAGON_RPC_BASE_URL; + this._serviceDocument = null; + this._serviceRootURL = this.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_DOCUMENT; this.rpcComplete = function(rpcnet, result, response, type, callback) { @@ -119,6 +120,10 @@ Bandwagon.RPC.Service = function() rpcnet.setMethod("POST"); rpcnet.setPostData(data); } + else if (method == "DELETE") + { + rpcnet.setMethod("DELETE"); + } else { rpcnet.setMethod("GET"); @@ -189,30 +194,59 @@ Bandwagon.RPC.Service.prototype.unregisterObserver = function(observerId) * Bandwagon Protocol Methods Below Here */ -Bandwagon.RPC.Service.prototype.getFeed = function(feed, callback) +Bandwagon.RPC.Service.prototype.getServiceDocument = function(callback) +{ + var service = this; + + this._logger.debug("Bandwagon.RPC.Service.getServiceDocument: getting service document for logged in user"); + + var internalCallback = function(event) + { + if (event.isError()) + { + } + else + { + event.serviceDocument = new Bandwagon.Model.ServiceDocument(); + event.serviceDocument.unserialize(event.getData()); + } + + if (callback) + { + callback(event); + } + } + + this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_SERVICE_DOCUMENT_COMPLETE, + internalCallback, + service.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_DOCUMENT, + "GET", + null); +} + +Bandwagon.RPC.Service.prototype.getCollection = function(collection, callback) { var service = this; - this._logger.debug("Bandwagon.RPC.Service.login: getting updates for feed '" + feed.url + "' ..."); + this._logger.debug("Bandwagon.RPC.Service.getCollection: getting updates for collection '" + collection.toString() + "' ..."); - feed.status = feed.STATUS_LOADING; + collection.status = collection.STATUS_LOADING; - // TODO feed.password handling goes here var data = null; var internalCallback = function(event) { if (event.isError()) { - feed.status = feed.STATUS_LOADERROR; + collection.status = collection.STATUS_LOADERROR; } else { - feed.unserialize(event.getData()); - feed.status = feed.STATUS_LOADED; + collection.unserialize(event.getData()); + collection.status = collection.STATUS_LOADED; } - event.feed = feed; + event.collection = collection; if (callback) { @@ -220,53 +254,143 @@ Bandwagon.RPC.Service.prototype.getFeed = function(feed, callback) } } - this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_FEED_COMPLETE, + this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_COLLECTION_COMPLETE, internalCallback, - feed.url, + collection.resourceURL, "GET", data); } -Bandwagon.RPC.Service.prototype.subscribeFeed = function(feed, callback) +Bandwagon.RPC.Service.prototype.newCollection = function(collection, callback) +{ + var service = this; + + this._logger.debug("Bandwagon.RPC.Service.newCollection: creating new collection '" + collection.toString() + "' ..."); + + if (collection.name == "" || service._serviceDocument == null) + { + if (callback) + callback(new this.Bandwagon.RPC.Event()); + + return; + } + + var data = { + name: collection.name, + description: collection.description, + nickname: collection.getNicknameFromName(), + listed: (collection.listed?1:0) + }; + + var internalCallback = function(event) + { + if (event.isError()) + { + collection.status = collection.STATUS_LOADERROR; + } + else + { + collection.unserialize(event.getData()); + collection.status = collection.STATUS_LOADED; + } + + event.collection = collection; + + if (callback) + { + callback(event); + } + } + + this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_NEW_COLLECTION_COMPLETE, + internalCallback, + service._serviceDocument.collectionListResourceURL, + "POST", + data); +} + + +/** OBSOLETE +Bandwagon.RPC.Service.prototype.subscribeCollection = function(collection, callback) { - Bandwagon.Logger.debug("Bandwagon.RPC.Service.subscribeFeed: TBD"); + Bandwagon.Logger.debug("Bandwagon.RPC.Service.subscribeCollection: TBD"); // TODO if (callback) callback(new this.Bandwagon.RPC.Event()); } +*/ -Bandwagon.RPC.Service.prototype.unsubscribeFeed = function(feed, callback) +/** OBSOLETE +Bandwagon.RPC.Service.prototype.unsubscribeCollection = function(collection, callback) { - Bandwagon.Logger.debug("Bandwagon.RPC.Service.unsubscribeFeed: TBD"); + Bandwagon.Logger.debug("Bandwagon.RPC.Service.unsubscribeCollection: TBD"); // TODO if (callback) callback(new this.Bandwagon.RPC.Event()); } +*/ -Bandwagon.RPC.Service.prototype.publishToFeed = function(extension, feed, personalNote, callback) +Bandwagon.RPC.Service.prototype.removeAddonFromCollection = function(guid, collection, callback) { - Bandwagon.Logger.debug("Bandwagon.RPC.Service.publishToFeed: extension.guid = '" + extension.guid + "', extension.name = '" + extension.name + "', feed = '" + feed.url + "', personalNote = '" + personalNote + "'"); - Bandwagon.Logger.debug("Bandwagon.RPC.Service.publishToFeed: TBD"); + var service = this; - // TODO + if (guid.substring(0,1) == "{") + { + guid = guid.substring(1, guid.length-2); + } - if (callback) + Bandwagon.Logger.debug("Bandwagon.RPC.Service.removeAddonFromCollection: extension.guid = '" + guid + "', collection = '" + collection.resourceURL); + + var internalCallback = function(event) + { + // don't need to do anything here + if (callback) + callback(event); + } + + this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_REMOVE_ADDON_FROM_COLLECTION_COMPLETE, + internalCallback, + collection.addonsResourceURL + guid, + "DELETE", + null); +} + +Bandwagon.RPC.Service.prototype.publishToCollection = function(extension, collection, personalNote, callback) +{ + var service = this; + + Bandwagon.Logger.debug("Bandwagon.RPC.Service.publishToCollection: extension.guid = '" + extension.guid + "', extension.name = '" + extension.name + "', collection = '" + collection.resourceURL + "', personalNote = '" + personalNote + "'"); + + var data = { + "guid": extension.guid, + "comments": personalNote + }; + + var internalCallback = function(event) { - setTimeout(function() { callback(new this.Bandwagon.RPC.Event()) }, 2000); + // don't need to do anything here + if (callback) + callback(event); } + + this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_PUBLISH_COMPLETE, + internalCallback, + collection.addonsResourceURL, + "POST", + data); } Bandwagon.RPC.Service.prototype.shareToEmail = function(extension, emailAddress, personalNote, callback) { var service = this; - Bandwagon.Logger.debug("Bandwagon.RPC.Service.publishToFeed: extension.guid = '" + extension.guid + "', extension.name = '" + extension.name + "', emailAddress = '" + emailAddress + "', personalNote = '" + personalNote + "'"); + Bandwagon.Logger.debug("Bandwagon.RPC.Service.shareToEmail: extension.guid = '" + extension.guid + "', extension.name = '" + extension.name + "', emailAddress = '" + emailAddress + "', personalNote = '" + personalNote + "'"); - if (!extension.guid || extension.guid == "" || !emailAddress || emailAddress == "") + if (!extension.guid || extension.guid == "" || !emailAddress || emailAddress == "" || service._serviceDocument == null) { if (callback) callback(new this.Bandwagon.RPC.Event()); @@ -274,48 +398,22 @@ Bandwagon.RPC.Service.prototype.shareToEmail = function(extension, emailAddress, return; } - var data = null; - var data = { "guid": extension.guid, - "emails[0]": emailAddress, - "message": personalNote + "to": emailAddress, + "comments": personalNote }; var internalCallback = function(event) { - if (!event.isError()) - { - // check for service level errors - - var response = event.getData(); - - // success has a body of "<success/>" - // failure has a body e.g. "<error>Add-on not found!</error>" - - if (response.name() == "success") - { - // all ok - } - else if (response.name() == "error") - { - // "expected" error -- update the event to indicate this error - event.setError(new service.Bandwagon.RPC.Error(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR, response.text().toString())); - } - else - { - // unknown response -- update the event to indicate an error - event.setError(new service.Bandwagon.RPC.Error(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_UNEXPECTED_XML)); - } - } - + // don't need to do anything here if (callback) callback(event); } this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_COMPLETE, internalCallback, - service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_ACTION, + service._serviceDocument.emailResourceURL, "POST", data); } diff --git a/bandwagon/content/scripts/util.js b/bandwagon/content/scripts/util.js index 9dde8bb..8044f31 100644 --- a/bandwagon/content/scripts/util.js +++ b/bandwagon/content/scripts/util.js @@ -249,3 +249,47 @@ Bandwagon.Util.getInstalledExtensions = function() return items; } +Bandwagon.Util.ISO8601toDate = function(dString) +{ + var x = new Date(); + + var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/; + + if (dString.toString().match(new RegExp(regexp))) { + var d = dString.match(new RegExp(regexp)); + var offset = 0; + + x.setUTCDate(1); + x.setUTCFullYear(parseInt(d[1],10)); + x.setUTCMonth(parseInt(d[3],10) - 1); + x.setUTCDate(parseInt(d[5],10)); + x.setUTCHours(parseInt(d[7],10)); + x.setUTCMinutes(parseInt(d[9],10)); + x.setUTCSeconds(parseInt(d[11],10)); + if (d[12]) + x.setUTCMilliseconds(parseFloat(d[12]) * 1000); + else + x.setUTCMilliseconds(0); + if (d[13] != 'Z') { + offset = (d[15] * 60) + parseInt(d[17],10); + offset *= ((d[14] == '-') ? -1 : 1); + x.setTime(x.getTime() - offset * 60 * 1000); + } + } + else + { + x.setTime(Date.parse(dString)); + } + + return x; +}; + +Bandwagon.Util.getBrowserLocale = function() +{ + var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefService); + + return prefSvc.getCharPref("general.useragent.locale"); +}; + + 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(); } |