fix icon path (retrieved from chrome-registery)

This commit is contained in:
foudfou 2011-09-08 00:55:34 +02:00
parent 25644e0a88
commit 11a238f21b
4 changed files with 45 additions and 13 deletions

View File

@ -1,3 +1,3 @@
extensions.moztray@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

View File

@ -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);
},

View File

@ -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");
let localizedMessage = PluralForm.get(
this._unreadMsgCount, mozt.Utils.strings.GetStringFromName("icon.tooltip.unread_messages"))
.replace("#1", this._unreadMsgCount);;
mozt.IconLinux.setTooltip(localizedMessage);
}
else {
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("tooltip.unread_messages"))
.replace("#1", this._unreadMsgCount);;
mozt.IconLinux.setTooltip(localizedMessage);
} else {
ERROR("negative unread messages' count ?"); // should never happen
throw "negative message count"; // should never happen
}
}

View File

@ -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;
}
};