[Pkg-mozext-commits] [firetray] 126/399: * catch RangeError when ctypesMap overflows * store appName in its original form (not lower-cased)

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:27 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 389bb317cc38b762a43d1a4118496aee6bd54d1e
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Sun Jan 1 13:30:42 2012 +0100

    * catch RangeError when ctypesMap overflows
    * store appName in its original form (not lower-cased)
---
 TODO                                    |   10 ++-
 src/modules/FiretrayHandler.jsm         |  112 +-------------------------
 src/modules/ctypesMap.jsm               |    4 +-
 src/modules/gtk2/FiretrayStatusIcon.jsm |    4 +-
 src/modules/gtk2/FiretrayWindow.jsm     |  130 ++++++++++++++++++++++++++++---
 5 files changed, 134 insertions(+), 126 deletions(-)

diff --git a/TODO b/TODO
index 1182f09..6dacb54 100644
--- a/TODO
+++ b/TODO
@@ -1,10 +1,9 @@
 TODO
 ----
 
-* convert to a https://developer.mozilla.org/en/Extensions/Bootstrapped_extensions
+* restore window state
 
-see ../restartless-restart-ffext/ and
-http://erikvold.com/blog/index.cfm/2010/10/28/restartless-firefox-addons-part-1-giving-your-addon-the-bootstrap
+* add entry to popup menu when registering
 
 WONTFIX
 -------
@@ -16,6 +15,11 @@ WONTFIX
   user may be toggling them after we store the previous values (and before we
   restore them)
 
+* convert to a
+  [Bootstrapped extension](https://developer.mozilla.org/en/Extensions/Bootstrapped_extensions),
+  nor to an JetPack/Restartable because not supported yet by Thunderbird
+
+
 ROADMAP
 -------
 
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index 69e387b..61f2b64 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -28,7 +28,7 @@ if ("undefined" == typeof(firetray)) {
 // (https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management)
 firetray.Handler = {
   initialized: false,
-  appName: null,
+  appNameOriginal: null,
   FILENAME_DEFAULT: null,
   FILENAME_SUFFIX: "32.png",
   FILENAME_BLANK: null,
@@ -40,9 +40,9 @@ firetray.Handler = {
   visibleWindowsCount: 0,
 
   init: function() {            // does creates icon
-    this.appName = Services.appinfo.name.toLowerCase();
+    this.appNameOriginal = Services.appinfo.name;
     this.FILENAME_DEFAULT = firetray.Utils.chromeToPath(
-      "chrome://firetray/skin/" +  this.appName + this.FILENAME_SUFFIX);
+      "chrome://firetray/skin/" +  this.appNameOriginal.toLowerCase() + this.FILENAME_SUFFIX);
     this.FILENAME_BLANK = firetray.Utils.chromeToPath(
       "chrome://firetray/skin/blank-icon.png");
     this.FILENAME_NEWMAIL = firetray.Utils.chromeToPath(
@@ -159,112 +159,6 @@ firetray.Handler = {
     return winOut;
   },
 
-
-/* GTK TEST */
-
-  // /*
-  //  * DAMN IT ! getZOrderDOMWindowEnumerator doesn't work on Linux :-(
-  //  * https://bugzilla.mozilla.org/show_bug.cgi?id=156333, and all windows
-  //  * seem to have the same zlevel ("normalZ") which is different from the
-  //  * z-order. There seems to be no means to get/set the z-order at this
-  //  * time...
-  //  */
-  // _updateHandledDOMWindows: function() {
-  //   LOG("_updateHandledDOMWindows");
-  //   this._handledDOMWindows = [];
-  //   var windowsEnumerator = Services.wm.getEnumerator(null); // returns a nsIDOMWindow
-  //   while (windowsEnumerator.hasMoreElements()) {
-  //     this._handledDOMWindows[this._handledDOMWindows.length] =
-  //       windowsEnumerator.getNext();
-  //   }
-  // },
-
-  // showHideToTray: function(a1) { // unused param
-  //   LOG("showHideToTray");
-
-  //   /*
-  //    * we update _handledDOMWindows only when hiding, because remembered{X,Y}
-  //    * properties are attached to them, and we suppose there won't be
-  //    * created/delete windows when all are hidden.
-  //    *
-  //    * NOTE: this may not be a good design if we want to show/hide one window
-  //    * at a time... might need win.QueryInterface(Ci.nsIInterfaceRequestor)
-  //    * .getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
-  //    */
-  //   if (!this._windowsHidden)   // hide
-  //     this._updateHandledDOMWindows();
-  //   LOG("nb Windows: " + this._handledDOMWindows.length);
-
-  //   for(let i=0; i<this._handledDOMWindows.length; i++) {
-  //     let bw = this._getBaseOrXULWindowFromDOMWindow(
-  //       this._handledDOMWindows[i], "BaseWindow");
-
-  //     LOG('isHidden: ' + this._windowsHidden);
-  //     LOG("bw.visibility: " + bw.visibility);
-  //     try {
-  //       if (this._windowsHidden) { // show
-
-  //         // correct position, size and state
-  //         let x = this._handledDOMWindows[i].rememberedX;
-  //         let y = this._handledDOMWindows[i].rememberedY;
-  //         let cx = this._handledDOMWindows[i].rememberedWidth;
-  //         let cy = this._handledDOMWindows[i].rememberedHeight;
-  //         LOG("set bw.position: " + x + ", " + y + ", " + cx + ", " + cy);
-  //         let windowState = this._handledDOMWindows[i].rememberedState;
-  //         LOG("set windowState: " + windowState);
-
-  //         switch (windowState) {
-  //         case Ci.nsIDOMChromeWindow.STATE_MAXIMIZED: // 1
-  //           this._handledDOMWindows[i].QueryInterface(Ci.nsIDOMChromeWindow).maximize();
-  //           break;
-  //         case Ci.nsIDOMChromeWindow.STATE_MINIMIZED: // 2
-  //           let prefHidesOnMinimize = firetray.Utils.prefService.getBoolPref("hides_on_minimize");
-  //           if (!prefHidesOnMinimize)
-  //             this._handledDOMWindows[i].QueryInterface(Ci.nsIDOMChromeWindow).minimize();
-  //           break;
-  //         case Ci.nsIDOMChromeWindow.STATE_NORMAL: // 3
-  //           bw.setPositionAndSize(x, y, cx, cy, false); // repaint
-  //           break;
-  //         case Ci.nsIDOMChromeWindow.STATE_FULLSCREEN: // 4
-  //           // FIXME: NOT IMPLEMENTED YET
-  //         default:
-  //         }
-  //         LOG("maximize after: " + this._handledDOMWindows[i].QueryInterface(Ci.nsIDOMChromeWindow).windowState);
-
-  //         bw.visibility = true;
-
-  //       } else {                // hide
-
-  //         // remember position and size
-  //         let x = {}, y = {}, cx = {}, cy = {};
-  //         bw.getPositionAndSize(x, y, cx, cy);
-  //         LOG("remember bw.position: " + x.value + ", " + y.value + ", " + cx.value + ", " + cy.value);
-  //         this._handledDOMWindows[i].rememberedX = x.value;
-  //         this._handledDOMWindows[i].rememberedY = y.value;
-  //         this._handledDOMWindows[i].rememberedWidth = cx.value;
-  //         this._handledDOMWindows[i].rememberedHeight = cy.value;
-  //         this._handledDOMWindows[i].rememberedState = this._handledDOMWindows[i]
-  //           .QueryInterface(Ci.nsIDOMChromeWindow).windowState;
-  //         LOG("maximized: " + this._handledDOMWindows[i].rememberedState);
-
-  //         bw.visibility = false;
-  //       }
-
-  //     } catch (x) {
-  //       LOG(x);
-  //     }
-  //     LOG("bw.visibility: " + bw.visibility);
-  //     LOG("bw.title: " + bw.title);
-  //   }
-
-  //   if (this._windowsHidden) {
-  //     this._windowsHidden = false;
-  //   } else {
-  //     this._windowsHidden = true;
-  //   }
-
-  // }, // showHideToTray
-
   quitApplication: function() {
     try {
       let appStartup = Cc['@mozilla.org/toolkit/app-startup;1']
diff --git a/src/modules/ctypesMap.jsm b/src/modules/ctypesMap.jsm
index 6fc430c..dff95b9 100644
--- a/src/modules/ctypesMap.jsm
+++ b/src/modules/ctypesMap.jsm
@@ -1,6 +1,6 @@
 /* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
-var EXPORTED_SYMBOLS = [ "ctypesMap", "CTYPES_ARRAY_MAX_SIZE" ];
+var EXPORTED_SYMBOLS = [ "ctypesMap", "FIRETRAY_WINDOW_COUNT_MAX" ];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
@@ -31,7 +31,7 @@ ctypesMap.prototype.get = function(key) {
 };
 
 ctypesMap.prototype.insert = function(key, item) {
-  if (this.map.hasOwnProperty(key)) { // replace
+  if (this.map.hasOwnProperty(key)) {
     LOG("REPLACE");
     this.array[this.map[key]] = item;
 
diff --git a/src/modules/gtk2/FiretrayStatusIcon.jsm b/src/modules/gtk2/FiretrayStatusIcon.jsm
index 2428891..3710d2c 100644
--- a/src/modules/gtk2/FiretrayStatusIcon.jsm
+++ b/src/modules/gtk2/FiretrayStatusIcon.jsm
@@ -150,9 +150,9 @@ firetray.Handler.setTooltip = function(toolTipStr) {
 };
 
 firetray.Handler.setTooltipDefault = function() {
-  if (!this.appName)
+  if (!this.appNameOriginal)
     throw "application name not initialized";
-  this.setTooltip(this.appName);
+  this.setTooltip(this.appNameOriginal);
 };
 
 firetray.Handler.setText = function(text, color) { // TODO: split into smaller functions;
diff --git a/src/modules/gtk2/FiretrayWindow.jsm b/src/modules/gtk2/FiretrayWindow.jsm
index d3278a3..fcbc1d0 100644
--- a/src/modules/gtk2/FiretrayWindow.jsm
+++ b/src/modules/gtk2/FiretrayWindow.jsm
@@ -173,7 +173,6 @@ firetray.Window = {
     } catch (x) {
       ERROR(x);
     }
-
   },
 
   restoreWindowPositionSizeState: function(xid) {
@@ -189,13 +188,12 @@ firetray.Window = {
     // well. And unfortunately, we need to show the window before restoring
     // position and size :-( TODO: Might be worth trying with x11 or
     // BaseWindow.visibility ?
-    try {
-      gtk.gtk_window_move(gtkWin, firetray.Handler.windows[xid].savedX, firetray.Handler.windows[xid].savedY);
-      gtk.gtk_window_resize(gtkWin, firetray.Handler.windows[xid].savedWidth, firetray.Handler.windows[xid].savedHeight);
-      // firetray.Handler.windows[xid].savedState
-    } catch (x) {
-      ERROR(x);
-    }
+    gtk.gtk_window_move(gtkWin, firetray.Handler.windows[xid].savedX, firetray.Handler.windows[xid].savedY);
+    gtk.gtk_window_resize(gtkWin, firetray.Handler.windows[xid].savedWidth, firetray.Handler.windows[xid].savedHeight);
+
+    // TODO: restore state
+    firetray.Handler.windows[xid].win.setCursor("help");
+    // firetray.Handler.windows[xid].savedState
   },
 
   onWindowState: function(gtkWidget, gdkEventState, userData){
@@ -230,8 +228,15 @@ firetray.Handler.registerWindow = function(win) {
   let [gtkWin, gdkWin, xid] = firetray.Window.getWindowsFromChromeWindow(win);
   this.windows[xid] = {};
   this.windows[xid].win = win;
-  this.gtkWindows.insert(xid, gtkWin);
-  this.gdkWindows.insert(xid, gdkWin);
+  try {
+    this.gtkWindows.insert(xid, gtkWin);
+    this.gdkWindows.insert(xid, gdkWin);
+  } catch (x) {
+    if (x.name === "RangeError") // instanceof not working :-(
+      win.alert(x+"\n\nYou seem to have more than "+FIRETRAY_WINDOW_COUNT_MAX
+                +" windows open. This breaks FireTray and most probably "
+                +firetray.Handler.appNameOriginal+".");
+  }
   this.windowsCount += 1;
   this.visibleWindowsCount += 1;
   this.windows[xid].visibility = true;
@@ -335,3 +340,108 @@ firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {
   let stopPropagation = true;
   return stopPropagation;
 };
+
+/* GTK TEST */
+
+// /*
+//  * DAMN IT ! getZOrderDOMWindowEnumerator doesn't work on Linux :-(
+//  * https://bugzilla.mozilla.org/show_bug.cgi?id=156333, and all windows
+//  * seem to have the same zlevel ("normalZ") which is different from the
+//  * z-order. There seems to be no means to get/set the z-order at this
+//  * time...
+//  */
+// _updateHandledDOMWindows: function() {
+//   LOG("_updateHandledDOMWindows");
+//   this._handledDOMWindows = [];
+//   var windowsEnumerator = Services.wm.getEnumerator(null); // returns a nsIDOMWindow
+//   while (windowsEnumerator.hasMoreElements()) {
+//     this._handledDOMWindows[this._handledDOMWindows.length] =
+//       windowsEnumerator.getNext();
+//   }
+// },
+
+// showHideToTray: function(a1) { // unused param
+//   LOG("showHideToTray");
+
+//   /*
+//    * we update _handledDOMWindows only when hiding, because remembered{X,Y}
+//    * properties are attached to them, and we suppose there won't be
+//    * created/delete windows when all are hidden.
+//    *
+//    * NOTE: this may not be a good design if we want to show/hide one window
+//    * at a time... might need win.QueryInterface(Ci.nsIInterfaceRequestor)
+//    * .getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
+//    */
+//   if (!this._windowsHidden)   // hide
+//     this._updateHandledDOMWindows();
+//   LOG("nb Windows: " + this._handledDOMWindows.length);
+
+//   for(let i=0; i<this._handledDOMWindows.length; i++) {
+//     let bw = this._getBaseOrXULWindowFromDOMWindow(
+//       this._handledDOMWindows[i], "BaseWindow");
+
+//     LOG('isHidden: ' + this._windowsHidden);
+//     LOG("bw.visibility: " + bw.visibility);
+//     try {
+//       if (this._windowsHidden) { // show
+
+//         // correct position, size and state
+//         let x = this._handledDOMWindows[i].rememberedX;
+//         let y = this._handledDOMWindows[i].rememberedY;
+//         let cx = this._handledDOMWindows[i].rememberedWidth;
+//         let cy = this._handledDOMWindows[i].rememberedHeight;
+//         LOG("set bw.position: " + x + ", " + y + ", " + cx + ", " + cy);
+//         let windowState = this._handledDOMWindows[i].rememberedState;
+//         LOG("set windowState: " + windowState);
+
+//         switch (windowState) {
+//         case Ci.nsIDOMChromeWindow.STATE_MAXIMIZED: // 1
+//           this._handledDOMWindows[i].QueryInterface(Ci.nsIDOMChromeWindow).maximize();
+//           break;
+//         case Ci.nsIDOMChromeWindow.STATE_MINIMIZED: // 2
+//           let prefHidesOnMinimize = firetray.Utils.prefService.getBoolPref("hides_on_minimize");
+//           if (!prefHidesOnMinimize)
+//             this._handledDOMWindows[i].QueryInterface(Ci.nsIDOMChromeWindow).minimize();
+//           break;
+//         case Ci.nsIDOMChromeWindow.STATE_NORMAL: // 3
+//           bw.setPositionAndSize(x, y, cx, cy, false); // repaint
+//           break;
+//         case Ci.nsIDOMChromeWindow.STATE_FULLSCREEN: // 4
+//           // FIXME: NOT IMPLEMENTED YET
+//         default:
+//         }
+//         LOG("maximize after: " + this._handledDOMWindows[i].QueryInterface(Ci.nsIDOMChromeWindow).windowState);
+
+//         bw.visibility = true;
+
+//       } else {                // hide
+
+//         // remember position and size
+//         let x = {}, y = {}, cx = {}, cy = {};
+//         bw.getPositionAndSize(x, y, cx, cy);
+//         LOG("remember bw.position: " + x.value + ", " + y.value + ", " + cx.value + ", " + cy.value);
+//         this._handledDOMWindows[i].rememberedX = x.value;
+//         this._handledDOMWindows[i].rememberedY = y.value;
+//         this._handledDOMWindows[i].rememberedWidth = cx.value;
+//         this._handledDOMWindows[i].rememberedHeight = cy.value;
+//         this._handledDOMWindows[i].rememberedState = this._handledDOMWindows[i]
+//           .QueryInterface(Ci.nsIDOMChromeWindow).windowState;
+//         LOG("maximized: " + this._handledDOMWindows[i].rememberedState);
+
+//         bw.visibility = false;
+//       }
+
+//     } catch (x) {
+//       LOG(x);
+//     }
+//     LOG("bw.visibility: " + bw.visibility);
+//     LOG("bw.title: " + bw.title);
+//   }
+
+//   if (this._windowsHidden) {
+//     this._windowsHidden = false;
+//   } else {
+//     this._windowsHidden = true;
+//   }
+
+// }, // showHideToTray

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