[Pkg-mozext-commits] [firetray] 36/399: fix icon path (retrieved from chrome-registery)

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:09 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch dfsg-clean
in repository firetray.

commit 11a238f21b1d65f52a7b8353287a8e770c5a46f9
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Thu Sep 8 00:55:34 2011 +0200

    fix icon path (retrieved from chrome-registery)
---
 src/chrome/locale/en-US/overlay.properties |    2 +-
 src/modules/MoztIconLinux.jsm              |    6 +++---
 src/modules/MoztMessaging.jsm              |   18 ++++++++++-------
 src/modules/commons.js                     |   30 +++++++++++++++++++++++++++-
 4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/chrome/locale/en-US/overlay.properties b/src/chrome/locale/en-US/overlay.properties
index 81bd21d..3e9ed4a 100644
--- a/src/chrome/locale/en-US/overlay.properties
+++ b/src/chrome/locale/en-US/overlay.properties
@@ -1,3 +1,3 @@
 extensions.moztray at foudil.fr.description=A system tray extension for linux.
 popupMenu.itemLabel.Quit=Quit
-icon.tooltip.unread_messages=#1 unread message;#1 unread messages
+tooltip.unread_messages=#1 unread message;#1 unread messages
diff --git a/src/modules/MoztIconLinux.jsm b/src/modules/MoztIconLinux.jsm
index fba42df..ac39221 100644
--- a/src/modules/MoztIconLinux.jsm
+++ b/src/modules/MoztIconLinux.jsm
@@ -26,7 +26,6 @@ mozt.IconLinux = {
   menu: null,
   appName: null,
   ICON_FILENAME_DEFAULT: null,
-  ICON_DIR: "chrome/skin/", // FIXME: retrieve from chromeregistery
   ICON_SUFFIX: "32.png",
 
   init: function() {
@@ -36,7 +35,8 @@ mozt.IconLinux = {
       // init tray icon, some variables
       this.trayIcon  = LibGtkStatusIcon.gtk_status_icon_new();
       this.appName = Services.appinfo.name.toLowerCase();
-      this.ICON_FILENAME_DEFAULT = this.ICON_DIR + this.appName + this.ICON_SUFFIX;
+      this.ICON_FILENAME_DEFAULT = mozt.Utils.chromeToPath(
+        "chrome://moztray/skin/" +  this.appName + this.ICON_SUFFIX);
 
       this.setDefaultImage();
 
@@ -87,6 +87,7 @@ mozt.IconLinux = {
   setImage: function(filename) {
     if (!this.trayIcon)
       return false;
+    LOG(filename);
 
     try {
       LibGtkStatusIcon.gtk_status_icon_set_from_file(this.trayIcon,
@@ -101,7 +102,6 @@ mozt.IconLinux = {
   setDefaultImage: function() {
     if (!this.ICON_FILENAME_DEFAULT)
       throw "Default application icon filename not set";
-    LOG(this.ICON_FILENAME_DEFAULT);
     this.setImage(this.ICON_FILENAME_DEFAULT);
   },
 
diff --git a/src/modules/MoztMessaging.jsm b/src/modules/MoztMessaging.jsm
index e290e09..e1752d3 100644
--- a/src/modules/MoztMessaging.jsm
+++ b/src/modules/MoztMessaging.jsm
@@ -100,16 +100,20 @@ mozt.Messaging = {
     LOG("TotalUnread="+this._unreadMsgCount);
 
     // update icon
-    if (this._unreadMsgCount > 0) {
-      mozt.IconLinux.setImage(mozt.IconLinux.ICON_DIR + "message-mail-new.png");
+    if (this._unreadMsgCount == 0) {
+      mozt.IconLinux.setDefaultImage();
+      mozt.IconLinux.setDefaultTooltip();
+    } else if (this._unreadMsgCount > 0) {
+      mozt.IconLinux.setImage(
+        mozt.Utils.chromeToPath("chrome://moztray/skin/message-mail-new.png"));
       let localizedMessage = PluralForm.get(
-        this._unreadMsgCount, mozt.Utils.strings.GetStringFromName("icon.tooltip.unread_messages"))
+        this._unreadMsgCount,
+        mozt.Utils.strings.GetStringFromName("tooltip.unread_messages"))
         .replace("#1", this._unreadMsgCount);;
       mozt.IconLinux.setTooltip(localizedMessage);
-    }
-    else {
-      mozt.IconLinux.setDefaultImage();
-      mozt.IconLinux.setDefaultTooltip();
+    } else {
+      ERROR("negative unread messages' count ?"); // should never happen
+      throw "negative message count"; // should never happen
     }
   }
 
diff --git a/src/modules/commons.js b/src/modules/commons.js
index 0ff85c8..b8c4618 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -36,5 +36,33 @@ if ("undefined" == typeof(mozt)) {
 
 mozt.Utils = {
   prefService: Services.prefs.getBranch("extensions.moztray."),
-  strings: Services.strings.createBundle("chrome://moztray/locale/overlay.properties")
+  strings: Services.strings.createBundle("chrome://moztray/locale/overlay.properties"),
+
+  // adapted from http://forums.mozillazine.org/viewtopic.php?p=921150#921150
+  chromeToPath: function(aPath) {
+    if (!aPath || !(/^chrome:/.test(aPath)))
+      return null;              // not a chrome url
+
+    let uri = Services.io.newURI(aPath, "UTF-8", null);
+    let registeryValue = Cc['@mozilla.org/chrome/chrome-registry;1']
+      .getService(Ci.nsIChromeRegistry)
+      .convertChromeURL(uri).spec;
+
+    if (/^file:/.test(registeryValue))
+      registeryValue = this._urlToPath(registeryValue);
+    else
+      registeryValue = this._urlToPath("file://"+registeryValue);
+
+    return registeryValue;
+  },
+
+  _urlToPath: function (aPath) {
+    if (!aPath || !/^file:/.test(aPath))
+      return null;
+
+    let protocolHandler = Cc["@mozilla.org/network/protocol;1?name=file"]
+      .createInstance(Ci.nsIFileProtocolHandler);
+    return protocolHandler.getFileFromURLSpec(aPath).path;
+  }
+
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git



More information about the Pkg-mozext-commits mailing list