Bug 760748: Add the category of the application to the desktop entry file - Part 2; r=fabrice
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Mon, 06 Aug 2012 18:23:00 -0700
changeset 101621 b8b948b3565a2ccd10d4ab7eb6feed5d402a5872
parent 101620 c6452db0947308313f20cadc9de30292a9ad09ba
child 101622 9c4db6a32c93eb1922cdc7fe2d00650d69aee502
push id23245
push useremorley@mozilla.com
push dateTue, 07 Aug 2012 13:39:24 +0000
treeherdermozilla-central@2637d896de91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs760748
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 760748: Add the category of the application to the desktop entry file - Part 2; r=fabrice
toolkit/webapps/WebappsInstaller.jsm
--- a/toolkit/webapps/WebappsInstaller.jsm
+++ b/toolkit/webapps/WebappsInstaller.jsm
@@ -105,18 +105,16 @@ function NativeApp(aData) {
     shortDesc = firstLine.length <= 256
                 ? firstLine
                 : firstLine.substr(0, 253) + "...";
   }
   this.shortDescription = sanitize(shortDesc);
 
   this.appcacheDefined = (app.manifest.appcache_path != undefined);
 
-  this.manifest = app.manifest;
-
   // The app registry is the Firefox profile from which the app
   // was installed.
   this.registryFolder = Services.dirsvc.get("ProfD", Ci.nsIFile);
 
   this.webappJson = {
     "registryDir": this.registryFolder.path,
     "app": app
   };
@@ -761,16 +759,51 @@ LinuxNativeApp.prototype = {
                     .getService(Ci.nsIToolkitProfileService);
 
     try {
       this.appProfile = profSvc.createDefaultProfileForApp(this.installDir.leafName,
                                                            null, null);
     } catch (ex if ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {}
   },
 
+  /**
+   * Translate marketplace categories to freedesktop.org categories.
+   *
+   * @link http://standards.freedesktop.org/menu-spec/menu-spec-latest.html#category-registry
+   *
+   * @return an array of categories
+   */
+  _translateCategories: function() {
+    let translations = {
+      "books-reference": "Education;Literature",
+      "business": "Finance",
+      "education": "Education",
+      "entertainment-sports": "Amusement;Sports",
+      "games": "Game",
+      "health-fitness": "MedicalSoftware",
+      "lifestyle": "Amusement",
+      "music": "Audio;Music",
+      "news-weather": "News",
+      "photos-media": "AudioVideo",
+      "productivity": "Office",
+      "shopping": "Amusement",
+      "social": "Chat",
+      "travel": "Amusement",
+      "utilities": "Utility"
+    };
+
+    // The trailing semicolon is needed as written in the freedesktop specification
+    let categories = "";
+    for (let category of this.app.categories) {
+      categories += translations[category] + ";";
+    }
+
+    return categories;
+  },
+
   _createConfigFiles: function() {
     // ${InstallDir}/webapp.json
     writeToFile(this.configJson, JSON.stringify(this.webappJson), function() {});
 
     let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
                     .getService(Ci.nsIINIParserFactory);
 
     // ${InstallDir}/webapp.ini
@@ -785,16 +818,21 @@ LinuxNativeApp.prototype = {
 
     writer = factory.createINIParser(this.desktopINI).QueryInterface(Ci.nsIINIParserWriter);
     writer.setString("Desktop Entry", "Name", this.appName);
     writer.setString("Desktop Entry", "Comment", this.shortDescription);
     writer.setString("Desktop Entry", "Exec", '"'+this.webapprt.path+'"');
     writer.setString("Desktop Entry", "Icon", this.iconFile.path);
     writer.setString("Desktop Entry", "Type", "Application");
     writer.setString("Desktop Entry", "Terminal", "false");
+
+    let categories = this._translateCategories();
+    if (categories)
+      writer.setString("Desktop Entry", "Categories", categories);
+
     writer.writeFile();
   },
 
   /**
    * This variable specifies if the icon retrieval process should
    * use a temporary file in the system or a binary stream. This
    * is accessed by a common function in WebappsIconHelpers.js and
    * is different for each platform.