diff options
Diffstat (limited to 'bandwagon/content/scripts')
-rw-r--r-- | bandwagon/content/scripts/bandwagon.js | 31 | ||||
-rw-r--r-- | bandwagon/content/scripts/factory/collectionFactory.js | 758 | ||||
-rw-r--r-- | bandwagon/content/scripts/factory/feedFactory.js | 626 | ||||
-rw-r--r-- | bandwagon/content/scripts/logger.js | 4 | ||||
-rw-r--r-- | bandwagon/content/scripts/model/addon.js (renamed from bandwagon/content/scripts/model/feedItem.js) | 83 | ||||
-rw-r--r-- | bandwagon/content/scripts/model/collection.js | 211 | ||||
-rw-r--r-- | bandwagon/content/scripts/model/feed.js | 189 | ||||
-rw-r--r-- | bandwagon/content/scripts/model/serviceDocument.js | 78 | ||||
-rw-r--r-- | bandwagon/content/scripts/rpc/constants.js | 13 | ||||
-rw-r--r-- | bandwagon/content/scripts/rpc/net.js | 13 | ||||
-rw-r--r-- | bandwagon/content/scripts/rpc/service.js | 204 | ||||
-rw-r--r-- | bandwagon/content/scripts/util.js | 44 |
12 files changed, 1329 insertions, 925 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"); +}; + + |