[Pkg-mozext-commits] [firetray] 209/399: add themable icon names to options

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:44 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 175f48661e4c1bcd007797a59e96c9211c860943
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Tue Mar 13 12:51:40 2012 +0100

    add themable icon names to options
---
 src/chrome/content/options.js            |   54 +++++++++++++++++++---
 src/chrome/content/options.xul           |   72 ++++++++++++++++++++++++------
 src/chrome/locale/en-US/options.dtd      |   13 ++++--
 src/defaults/preferences/prefs.js        |    5 +++
 src/modules/FiretrayHandler.jsm          |   10 +++++
 src/modules/commons.js                   |   17 +++++--
 src/modules/linux/FiretrayStatusIcon.jsm |   27 +++++++++--
 7 files changed, 169 insertions(+), 29 deletions(-)

diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index 862ba55..06c2511 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -19,16 +19,18 @@ var firetrayUIOptions = {
   onLoad: function(e) {
     this.strings = document.getElementById("firetray-options-strings");
 
-    this.updateWindowAndIconOptions();
-    this.updateScrollOptions();
-
-    if(firetray.Handler.inMailApp) {
+    if (firetray.Handler.inMailApp) {
       Cu.import("resource://firetray/FiretrayMessaging.jsm");
       this.initMailControls();
     } else {
       let mailTab = document.getElementById("mail_tab");
       this.hideElement(mailTab, true);
     }
+
+    this.updateWindowAndIconOptions();
+    this.updateScrollOptions();
+    this.initAppIconType();
+    this.initIconNames();
   },
 
   onQuit: function(e) {
@@ -76,6 +78,42 @@ var firetrayUIOptions = {
     this.disableGroup(document.getElementById("ui_radiogroup_scroll"), !scroll_hides);
   },
 
+  initAppIconType: function() {
+    document.getElementById("ui_app_icon_type_themed").value =
+      FIRETRAY_APPLICATION_ICON_TYPE_THEMED;
+    document.getElementById("ui_app_icon_type_custom").value =
+      FIRETRAY_APPLICATION_ICON_TYPE_CUSTOM;
+    document.getElementById("ui_app_icon_type").selectedIndex =
+      firetray.Utils.prefService.getIntPref("app_icon_type");
+   },
+
+  initIconNames: function() {
+    let appIconNames = firetray.Utils.getArrayPref(firetray.StatusIcon.prefAppIconNames);
+    LOG("appIconNames="+appIconNames);
+    let len = appIconNames.length;
+    if (len>2)
+      throw new RangeError("Too many icon names");
+    for (let i=0; i<len; ++i) {
+      let textbox = document.getElementById("app_icon_type_themed_name"+(i+1));
+      textbox.value = appIconNames[i];
+    }
+    let textbox = document.getElementById("app_icon_type_themed_name3");
+    textbox.value = firetray.Handler.appNameOriginal.toLowerCase();
+  },
+
+  updateIconNames: function(textbox) {
+    let appIconNames = [];
+    for (let i=1; i<3; ++i) {
+      let tb = document.getElementById("app_icon_type_themed_name"+i);
+      let val = tb.value.trim();
+      LOG("val="+val);
+      if (val)
+        appIconNames.push(val);
+    }
+    LOG("appIconNames="+appIconNames);
+    firetray.Utils.setArrayPref(firetray.StatusIcon.prefAppIconNames, appIconNames);
+  },
+
   initMailControls: function() {
     this.populateExcludedFoldersList();
     this.populateTreeAccountsOrServerTypes();
@@ -187,6 +225,12 @@ var firetrayUIOptions = {
     this.disableMessageCountMaybe(messageCountType);
   },
 
+  chooseAppIconFile: function() {
+    var filepath = document.getElementById("app_icon_custom_filename");
+    this._chooseIconFile(filepath);
+    firetray.Handler.setIconImageDefault();
+  },
+
   chooseMailIconFile: function() {
     var filepath = document.getElementById("custom_mail_icon_filename");
     this._chooseIconFile(filepath);
@@ -252,7 +296,7 @@ var firetrayUIOptions = {
   _disableTreeRow: function(row, disable) {
     let that = this;
     try {
-      let cells = row.childNodes; // .getElementsByTagName('treecell');
+      let cells = row.childNodes;
       LOG("CELLS: "+cells);
       for (let i=0, len=cells.length; i<len; ++i) {
         LOG("i: "+i+", cell:"+cells[i]);
diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul
index 6fe63a3..60f4272 100644
--- a/src/chrome/content/options.xul
+++ b/src/chrome/content/options.xul
@@ -25,6 +25,8 @@
       <preference id="pref_start_hidden" name="extensions.firetray.start_hidden" type="bool"/>
       <preference id="pref_show_activates" name="extensions.firetray.show_activates" type="bool"/>
       <preference id="pref_show_icon_on_hide" name="extensions.firetray.show_icon_on_hide" type="bool"/>
+      <preference id="pref_app_icon_type" name="extensions.firetray.app_icon_type" type="int"/>
+      <preference id="pref_app_icon_filename" name="extensions.firetray.app_icon_filename" type="string"/>
       <preference id="pref_scroll_hides" name="extensions.firetray.scroll_hides" type="bool" />
       <preference id="pref_scroll_mode" name="extensions.firetray.scroll_mode" type="string" />
       <preference id="pref_icon_text_color" name="extensions.firetray.icon_text_color" type="string" />
@@ -36,7 +38,8 @@
 
     <tabbox>
       <tabs>
-        <tab label="&windows_icon_options;"/>
+        <tab label="&windows_options;"/>
+        <tab label="&icon_options;"/>
         <tab label="&mail_options;" id="mail_tab" />
       </tabs>
       <tabpanels flex="1">
@@ -44,8 +47,6 @@
         <tabpanel id="general_tabpanel" flex="1">
           <vbox pack="start" align="left" flex="1">
 
-          <groupbox>
-            <caption label="&windows_behaviour;" />
             <checkbox id="ui_hides_on_close" preference="pref_hides_on_close"
                       label="&bool_hides_on_close.label;"
                       accesskey="&bool_hides_on_close.accesskey;"
@@ -65,13 +66,45 @@
                       label="&bool_show_activates.label;"
                       accesskey="&bool_show_activates.accesskey;"
                       tooltiptext="&bool_show_activates.tooltip;"/>
-          </groupbox>
 
-          <groupbox>
-            <caption label="&icon_settings;" />
+          </vbox>
+        </tabpanel>
+
+
+        <tabpanel id="icon_tabpanel" flex="1">
+          <vbox pack="start" align="left" flex="1">
+
+            <radiogroup id="ui_app_icon_type" preference="pref_app_icon_type">
+              <vbox align="left" flex="1">
+                <label class="header">&app_icon_type;</label>
+
+                <hbox>
+                  <radio id="ui_app_icon_type_themed" label="&app_icon_themed.label;"
+                         accesskey="&app_icon_themed.accesskey;" tooltiptext="&app_icon_themed.tooltip;" />
+                  <textbox id="app_icon_type_themed_name1" size="12" placeholder="&app_icon_themed_name;"
+                           onchange="firetrayUIOptions.updateIconNames(this);" flex="1" />
+                  <textbox id="app_icon_type_themed_name2" size="12" placeholder="&app_icon_themed_name;"
+                           onchange="firetrayUIOptions.updateIconNames(this);" flex="1" />
+                  <textbox id="app_icon_type_themed_name3" size="12" placeholder="&app_icon_themed_name;"
+                           onchange="firetrayUIOptions.updateIconNames(this);" flex="1"
+                           disabled="true"/>
+                </hbox>
+                <hbox>
+                  <radio id="ui_app_icon_type_custom" label="&app_icon_custom.label;"
+                         accesskey="&app_icon_custom.accesskey;" />
+                  <textbox id="app_icon_custom_filename" preference="pref_app_icon_filename" flex="1" />
+                  <button id="app_icon_custom_select" label="&choose;"
+                          accesskey="&choose.accesskey;"
+                          oncommand="firetrayUIOptions.chooseAppIconFile()" />
+                </hbox>
+
+              </vbox>
+            </radiogroup>
+
             <checkbox id="ui_show_icon_on_hide" preference="pref_show_icon_on_hide"
                       label="&bool_show_icon_on_hide.label;"
                       accesskey="&bool_show_icon_on_hide.accesskey;"/>
+
             <checkbox id="ui_scroll_hides" preference="pref_scroll_hides"
                       label="&enable_mouse_scroll.label;"
                       accesskey="&enable_mouse_scroll.accesskey;"
@@ -80,7 +113,6 @@
               <radio id="ui_radio_scroll_down_hides" label="&down;=&hide;, &up;=&restore;" value="down_hides" />
               <radio id="ui_radio_scroll_up_hides" label="&up;=&hide;, &down;=&restore;" value="up_hides" />
             </radiogroup>
-          </groupbox>
 
           </vbox>
         </tabpanel>
@@ -130,18 +162,30 @@
                                observes="broadcaster-notification-disabled"/>
                 </hbox>
               </hbox>
-              <radio id="ui_radio_mail_notification_newmail_icon" label="&mail_notification_newmail_icon.label;"
-                     accesskey="&mail_notification_newmail_icon.accesskey;"
-                     oncommand="firetrayUIOptions.updateNotificationSettings()"
-                     observes="broadcaster-notification-disabled" />
+              <hbox>
+                <radio id="ui_radio_mail_notification_newmail_icon" label="&mail_notification_newmail_icon.label;"
+                       accesskey="&mail_notification_newmail_icon.accesskey;"
+                       oncommand="firetrayUIOptions.updateNotificationSettings()"
+                       observes="broadcaster-notification-disabled" />
+                <!-- TODO -->
+                <textbox id="radio_mail_notification_newmail_icon_name1" size="12"
+                         placeholder="&app_icon_themed_name;" onchange="" flex="1"
+                         observes="broadcaster-notification-disabled" />
+                <textbox id="radio_mail_notification_newmail_icon_name2" size="12"
+                         placeholder="&app_icon_themed_name;" onchange="" flex="1"
+                         observes="broadcaster-notification-disabled" />
+                <textbox id="radio_mail_notification_newmail_icon_name3" size="12"
+                         placeholder="&app_icon_themed_name;" onchange="" flex="1"
+                         observes="broadcaster-notification-disabled" />
+              </hbox>
               <hbox>
                 <radio id="ui_radio_mail_notification_custom_mail_icon" label="&mail_notification_custom_mail_icon.label;"
                        accesskey="&mail_notification_custom_mail_icon.accesskey;"
-                       oncommand="firetrayUIOptions.updateNotificationSettings()" 
+                       oncommand="firetrayUIOptions.updateNotificationSettings()"
                        observes="broadcaster-notification-disabled" />
                 <hbox id="custom_mail_icon" align="center" flex="1" >
                   <textbox id="custom_mail_icon_filename" preference="pref_custom_mail_icon"
-                           onblur="firetray.Messaging.updateMsgCount();" flex="1" />
+                           onchange="firetray.Messaging.updateMsgCount();" flex="1" />
                   <button id="custom_mail_icon_select" label="&choose;"
                           accesskey="&choose.accesskey;"
                           oncommand="firetrayUIOptions.chooseMailIconFile()" />
@@ -204,7 +248,7 @@
 
           </vbox>
         </tabpanel>
-        
+
       </tabpanels>
     </tabbox>
 
diff --git a/src/chrome/locale/en-US/options.dtd b/src/chrome/locale/en-US/options.dtd
index 681d826..5e5d905 100644
--- a/src/chrome/locale/en-US/options.dtd
+++ b/src/chrome/locale/en-US/options.dtd
@@ -4,10 +4,10 @@
 
 <!ENTITY NOT_IMPLEMENTED_YET "NOT IMPLEMENTED YET">
 
-<!ENTITY windows_icon_options "Windows and Icon">
+<!ENTITY windows_options "Windows">
+<!ENTITY icon_options "Icon">
 <!ENTITY mail_options "Mail">
 
-<!ENTITY windows_behaviour "Windows behaviour">
 <!ENTITY bool_hides_on_close.label "Closing window hides to tray">
 <!ENTITY bool_hides_on_close.accesskey "C">
 <!ENTITY bool_hides_on_minimize.label "Minimizing window hides to tray">
@@ -21,9 +21,16 @@
 <!ENTITY bool_show_activates.accesskey "e">
 <!ENTITY bool_show_activates.tooltip "restored windows raise on top and get focus">
 
-<!ENTITY icon_settings "Icon settings">
 <!ENTITY bool_show_icon_on_hide.label "Show tray icon only if a window is hidden">
 <!ENTITY bool_show_icon_on_hide.accesskey "w">
+<!ENTITY app_icon_type "Application icon">
+<!ENTITY app_icon_themed.label "Default themed">
+<!ENTITY app_icon_themed.accesskey "D">
+<!ENTITY app_icon_themed_name "icon-name">
+<!ENTITY app_icon_themed.tooltip "Icon names provided by graphical environment">
+<!ENTITY app_icon_custom.label "Custom">
+<!ENTITY app_icon_custom.accesskey "u">
+
 <!ENTITY mouse_wheel_options "Mouse wheel options" >
 <!ENTITY enable_mouse_scroll.label "Handle mouse scroll on tray icon" >
 <!ENTITY enable_mouse_scroll.accesskey "l">
diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js
index e24b252..67e6907 100644
--- a/src/defaults/preferences/prefs.js
+++ b/src/defaults/preferences/prefs.js
@@ -13,6 +13,11 @@ pref("extensions.firetray.hides_single_window", false);
 pref("extensions.firetray.start_hidden", false);
 pref("extensions.firetray.show_activates", false);
 
+pref("extensions.firetray.app_icon_type", 0);
+pref("extensions.firetray.app_browser_icon_names", '[]');
+pref("extensions.firetray.app_mail_icon_names", '["indicator-messages", "applications-email-panel"]');
+pref("extensions.firetray.app_default_icon_names", '[]');
+pref("extensions.firetray.app_icon_filename", "");
 pref("extensions.firetray.show_icon_on_hide", false);
 pref("extensions.firetray.scroll_hides", true);
 pref("extensions.firetray.scroll_mode", "down_hides");
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index 2e2ca78..42b633f 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -370,6 +370,16 @@ firetray.PrefListener = new PrefListener(
     case 'message_count_type':
       firetray.Messaging.updateMsgCount();
       break;
+    case 'app_mail_icon_names':
+    case 'app_browser_icon_names':
+    case 'app_default_icon_names':
+      firetray.StatusIcon.loadThemedIcons();
+    case 'app_icon_type':
+      if (firetray.Handler.inMailApp)
+        firetray.Messaging.updateMsgCount();
+      else
+        firetray.Handler.setIconImageDefault();
+      break;
     default:
     }
   });
diff --git a/src/modules/commons.js b/src/modules/commons.js
index 6b64292..b1f1e81 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -4,9 +4,10 @@
    provided by this module */
 var EXPORTED_SYMBOLS =
   [ "firetray", "LOG", "WARN", "ERROR", "FIREFOX_ID", "THUNDERBIRD_ID",
-    "SEAMONKEY_ID", "FIRETRAY_ID", "FIRETRAY_SPLASH_PAGE", "getType",
-    "isArray", "isEmpty", "strEquals",
-    "FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT",
+    "SEAMONKEY_ID", "FIRETRAY_ID", "FIRETRAY_SPLASH_PAGE",
+    "FIRETRAY_APPLICATION_ICON_TYPE_THEMED",
+    "FIRETRAY_APPLICATION_ICON_TYPE_CUSTOM", "getType", "isArray", "isEmpty",
+    "strEquals", "FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT",
     "FIRETRAY_NOTIFICATION_NEWMAIL_ICON", "FIRETRAY_NOTIFICATION_CUSTOM_ICON",
     "FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
     "FIRETRAY_DELAY_NOWAIT_MILLISECONDS", "FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD",
@@ -29,6 +30,9 @@ const CHATZILLA_ID   = "{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}";
 const FIRETRAY_ID          = "{9533f794-00b4-4354-aa15-c2bbda6989f8}";
 const FIRETRAY_SPLASH_PAGE = "http://foudfou.github.com/FireTray/";
 
+const FIRETRAY_APPLICATION_ICON_TYPE_THEMED      = 0;
+const FIRETRAY_APPLICATION_ICON_TYPE_CUSTOM      = 1;
+
 const FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT = 0;
 const FIRETRAY_NOTIFICATION_NEWMAIL_ICON         = 1;
 const FIRETRAY_NOTIFICATION_CUSTOM_ICON          = 3;
@@ -216,6 +220,13 @@ if(!Object.keys) Object.keys = function(o){
   return ret;
 };
 
+// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim
+if(!String.prototype.trim) {
+  String.prototype.trim = function () {
+    return this.replace(/^\s+|\s+$/g,'');
+  };
+}
+
 // http://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object-from-json
 function isEmpty(obj) {
   for(var prop in obj) {
diff --git a/src/modules/linux/FiretrayStatusIcon.jsm b/src/modules/linux/FiretrayStatusIcon.jsm
index 3385d92..fd601a4 100644
--- a/src/modules/linux/FiretrayStatusIcon.jsm
+++ b/src/modules/linux/FiretrayStatusIcon.jsm
@@ -30,6 +30,7 @@ firetray.StatusIcon = {
   trayIcon: null,
   themedIconApp: null,
   themedIconNewMail: null,
+  prefAppIconNames: null,
 
   init: function() {
     try {
@@ -39,9 +40,7 @@ firetray.StatusIcon = {
       LOG("gtkIconTheme="+gtkIconTheme);
       gtk.gtk_icon_theme_append_search_path(gtkIconTheme, this.GTK_THEME_ICON_PATH);
 
-      // TODO: make related options
-      this.themedIconApp     = this.initThemedIcon(["indicator-messages", "applications-email-panel", firetray.Handler.appNameOriginal.toLowerCase()]);
-      this.themedIconNewMail = this.initThemedIcon(["indicator-messages-new", "mail-message-new"]);
+      this.loadThemedIcons();
 
       this.trayIcon  = gtk.gtk_status_icon_new();
 
@@ -69,6 +68,20 @@ firetray.StatusIcon = {
     this.initialized = false;
   },
 
+  loadThemedIcons: function() {
+    if (firetray.Handler.inMailApp) {
+      this.prefAppIconNames = "app_mail_icon_names";
+      this.themedIconNewMail = this.initThemedIcon(["indicator-messages-new", "mail-message-new"]); // TODO
+    } else if (firetray.Handler.inBrowserApp) {
+      this.prefAppIconNames = "app_browser_icon_names";
+    } else {
+      this.prefAppIconNames = "app_default_icon_names";
+    }
+    let appIconNames = firetray.Utils.getArrayPref(this.prefAppIconNames);
+    appIconNames.push(firetray.Handler.appNameOriginal.toLowerCase());
+    this.themedIconApp = this.initThemedIcon(appIconNames);
+  },
+
   initThemedIcon: function(names) {
     if (!isArray(names)) throw new TypeError();
     let namesLen = names.length;
@@ -162,7 +175,13 @@ firetray.Handler.setIconImageFromFile = firetray.StatusIcon.setIconImageFromFile
 firetray.Handler.setIconImageDefault = function() {
   if (!firetray.StatusIcon.themedIconApp)
     throw "Default application themed icon not set";
-  firetray.Handler.setIconImage(firetray.StatusIcon.themedIconApp);
+  let appIconType = firetray.Utils.prefService.getIntPref("app_icon_type");
+  if (appIconType === FIRETRAY_APPLICATION_ICON_TYPE_THEMED)
+    firetray.Handler.setIconImage(firetray.StatusIcon.themedIconApp);
+  else if (appIconType === FIRETRAY_APPLICATION_ICON_TYPE_CUSTOM) {
+    let appIconFilename = firetray.Utils.prefService.getCharPref("app_icon_filename");
+    firetray.Handler.setIconImageFromFile(appIconFilename);
+  }
 };
 
 // GTK bug: Gdk-CRITICAL **: IA__gdk_window_get_root_coords: assertion `GDK_IS_WINDOW (window)' failed

-- 
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