[Pkg-mozext-commits] [firetray] 378/399: * handle chat_icon_blink and chat_icon_enable prefs properly * better use of ChatStatusIcon timers
David Prévot
taffit at alioth.debian.org
Tue Oct 29 18:24:18 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 35ed1efb6fb7e2642cf6967fee0e766a08dad072
Author: foudfou <foudil.newbie+git at gmail.com>
Date: Sun Jun 23 21:45:15 2013 +0200
* handle chat_icon_blink and chat_icon_enable prefs properly
* better use of ChatStatusIcon timers
---
src/modules/FiretrayChat.jsm | 41 ++++++++-----
src/modules/FiretrayHandler.jsm | 28 ++++-----
src/modules/linux/FiretrayChatStatusIcon.jsm | 81 +++++++++++++++++---------
3 files changed, 91 insertions(+), 59 deletions(-)
diff --git a/src/modules/FiretrayChat.jsm b/src/modules/FiretrayChat.jsm
index 456ec24..a8b7c54 100644
--- a/src/modules/FiretrayChat.jsm
+++ b/src/modules/FiretrayChat.jsm
@@ -15,6 +15,10 @@ let log = firetray.Logging.getLogger("firetray.Chat");
firetray.Chat = {
initialized: false,
observedTopics: {},
+ convsToAcknowledge: {
+ ids: {},
+ length: function(){return Object.keys(this.ids).length;}
+ },
init: function() {
if (this.initialized) {
@@ -31,6 +35,9 @@ firetray.Chat = {
]);
firetray.ChatStatusIcon.init();
+ if (firetray.Utils.prefService.getBoolPref("chat_icon_blink") &&
+ firetray.Chat.convsToAcknowledge.length())
+ this.startGetAttention();
this.updateIcon();
this.initialized = true;
@@ -40,6 +47,9 @@ firetray.Chat = {
if (!this.initialized) return;
log.debug("Disabling Chat");
+ if (firetray.Chat.convsToAcknowledge.length())
+ this.stopGetAttention();
+
firetray.ChatStatusIcon.shutdown();
firetray.Utils.removeAllObservers(firetray.Chat);
@@ -118,25 +128,25 @@ firetray.Chat = {
startGetAttentionMaybe: function(conv) {
log.debug('startGetAttentionMaybe conv.id='+conv.id);
- if (!firetray.Utils.prefService.getBoolPref("chat_icon_blink")) return;
let convIsCurrentlyShown =
this.isConvCurrentlyShown(conv, firetray.Handler.findActiveWindow());
log.debug("convIsCurrentlyShown="+convIsCurrentlyShown);
if (convIsCurrentlyShown) return; // don't blink when conv tab already on top
- this.startGetAttention(conv);
+ log.debug("firetray.ChatStatusIcon.isBlinking="+firetray.ChatStatusIcon.isBlinking);
+ if (firetray.Utils.prefService.getBoolPref("chat_icon_blink") &&
+ !firetray.ChatStatusIcon.isBlinking)
+ this.startGetAttention(conv);
- firetray.ChatStatusIcon.convsToAcknowledge.ids[conv.id] = conv;
- log.debug(conv.id+' added to convsToAcknowledge, length='+firetray.ChatStatusIcon.convsToAcknowledge.length());
+ this.convsToAcknowledge.ids[conv.id] = conv;
+ log.debug(conv.id+' added to convsToAcknowledge, length='+this.convsToAcknowledge.length());
},
startGetAttention: function(conv) {
log.debug("startGetAttention");
- this.setUrgencyMaybe(conv);
-
- log.debug("firetray.ChatStatusIcon.isBlinking="+firetray.ChatStatusIcon.isBlinking);
- if (firetray.ChatStatusIcon.isBlinking) return;
+ if (conv)
+ this.setUrgencyMaybe(conv);
let blinkStyle = firetray.Utils.prefService.getIntPref("chat_icon_blink_style");
log.debug("chat_icon_blink_style="+blinkStyle);
@@ -153,27 +163,30 @@ firetray.Chat = {
*/
stopGetAttentionMaybe: function(xid) {
log.debug("stopGetAttentionMaybe");
- log.debug("convsToAcknowledgeLength="+firetray.ChatStatusIcon.convsToAcknowledge.length());
- if (!firetray.ChatStatusIcon.isBlinking) return; // instead of pref chat_icon_blink — if pref was just unset
+ log.debug("convsToAcknowledgeLength="+this.convsToAcknowledge.length());
+ if (!firetray.ChatStatusIcon.isBlinking) return;
let selectedConv = this.getSelectedConv(xid);
if (!selectedConv) return;
- for (let convId in firetray.ChatStatusIcon.convsToAcknowledge.ids) {
+ for (let convId in this.convsToAcknowledge.ids) {
log.debug(convId+" == "+selectedConv.id);
if (convId == selectedConv.id) {
- delete firetray.ChatStatusIcon.convsToAcknowledge.ids[convId];
+ delete this.convsToAcknowledge.ids[convId];
break;
}
}
- if (firetray.ChatStatusIcon.convsToAcknowledge.length() === 0)
+ // don't check chat_icon_blink: stopGetAttention even if it was unset
+ log.debug("convsToAcknowledge.length()="+this.convsToAcknowledge.length());
+ if (this.convsToAcknowledge.length() === 0)
this.stopGetAttention(xid);
},
stopGetAttention: function(xid) {
log.debug("do stop get attention !!!");
- firetray.ChatStatusIcon.setUrgency(xid, false);
+ if (xid)
+ firetray.ChatStatusIcon.setUrgency(xid, false);
let blinkStyle = firetray.Utils.prefService.getIntPref("chat_icon_blink_style");
if (blinkStyle === FIRETRAY_CHAT_ICON_BLINK_STYLE_NORMAL)
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index f6cc031..3e2b4a3 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -283,8 +283,8 @@ firetray.Handler = {
} else {
for (let winId in firetray.Handler.windows) {
- firetray.ChatStatusIcon.detachOnFocusInCallback(winId);
firetray.Chat.detachSelectListeners(firetray.Handler.windows[winId].chromeWin);
+ firetray.ChatStatusIcon.detachOnFocusInCallback(winId);
}
firetray.Chat.shutdown();
}
@@ -482,11 +482,13 @@ firetray.PrefListener = new PrefListener(
break;
case 'chat_icon_blink':
- if (!firetray.Utils.prefService.getBoolPref('chat_icon_blink') &&
- firetray.ChatStatusIcon.isBlinking) {
- /* FIXME: stopGetAttention() needs a window id. For now just pass the
- active window */
- firetray.Chat.stopGetAttention(firetray.Handler.findActiveWindow());
+ if (!firetray.ChatStatusIcon.isBlinking)
+ return;
+ let startBlinking = firetray.Utils.prefService.getBoolPref('chat_icon_blink');
+ if (startBlinking) {
+ firetray.Chat.startGetAttention();
+ } else {
+ firetray.Chat.stopGetAttention();
}
break;
@@ -495,18 +497,8 @@ firetray.PrefListener = new PrefListener(
!firetray.ChatStatusIcon.isBlinking)
break;
- switch (firetray.Utils.prefService.getIntPref("chat_icon_blink_style")) {
- case FIRETRAY_CHAT_ICON_BLINK_STYLE_NORMAL:
- firetray.ChatStatusIcon.stopFading();
- firetray.ChatStatusIcon.startBlinking();
- break;
- case FIRETRAY_CHAT_ICON_BLINK_STYLE_FADE:
- firetray.ChatStatusIcon.stopBlinking();
- firetray.ChatStatusIcon.startFading();
- break;
- default:
- throw new Error("Undefined chat icon blink style.");
- }
+ firetray.ChatStatusIcon.toggleBlinkStyle(
+ firetray.Utils.prefService.getIntPref("chat_icon_blink_style"));
break;
default:
diff --git a/src/modules/linux/FiretrayChatStatusIcon.jsm b/src/modules/linux/FiretrayChatStatusIcon.jsm
index e928e3d..2c2e473 100644
--- a/src/modules/linux/FiretrayChatStatusIcon.jsm
+++ b/src/modules/linux/FiretrayChatStatusIcon.jsm
@@ -23,9 +23,10 @@ if ("undefined" == typeof(firetray.Handler))
let log = firetray.Logging.getLogger("firetray.ChatStatusIcon");
-const ALPHA_STEP = 5;
-const ALPHA_STEP_SLEEP_MILLISECONDS = 10;
-const FADE_OVER_SLEEP_MILLISECONDS = 500;
+const ALPHA_STEP = 5;
+const ALPHA_STEP_SLEEP_MILLISECONDS = 10;
+const FADE_OVER_SLEEP_MILLISECONDS = 500;
+const BLINK_TOGGLE_PERIOD_MILLISECONDS = 500;
firetray.ChatStatusIcon = {
@@ -43,15 +44,11 @@ firetray.ChatStatusIcon = {
})(),
themedIconNameCurrent: null,
signals: {'focus-in': {callback: {}, handler: {}}},
- timers: {},
+ timers: {'blink': null, 'fade-step': null, 'fade-loop': null},
events: {},
generators: {},
pixBuffer: {},
- convsToAcknowledge: {
- ids: {},
- length: function(){return Object.keys(this.ids).length;}
- },
- get isBlinking () {return (this.convsToAcknowledge.length() > 0);},
+ get isBlinking () {return (firetray.Chat.convsToAcknowledge.length() > 0);},
init: function() {
if (!firetray.Handler.inMailApp) throw "ChatStatusIcon for mail app only";
@@ -59,14 +56,16 @@ firetray.ChatStatusIcon = {
this.trayIcon = gtk.gtk_status_icon_new();
this.loadThemedIcons();
- this.setIconImage(FIRETRAY_IM_STATUS_OFFLINE);
+ this.setIconImage(this.themedIconNameCurrent || FIRETRAY_IM_STATUS_OFFLINE); // updated in Chat anyway
this.setIconTooltipDefault();
+ this.initTimers();
this.initialized = true;
return true;
},
shutdown: function() {
+ this.destroyTimers();
this.destroyIcons();
this.initialized = false;
},
@@ -107,6 +106,19 @@ firetray.ChatStatusIcon = {
gtk.gtk_status_icon_set_from_pixbuf(this.trayIcon, null);
},
+ initTimers: function() {
+ for (let tname in this.timers)
+ this.timers[tname] = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ },
+
+ destroyTimers: function() {
+ for (let tname in this.timers) {
+ this.timers[tname].cancel();
+ this.timers[tname] = null;
+ }
+ this.events = {};
+ },
+
buildPixBuf: function() {
let icon_theme = gtk.gtk_icon_theme_get_for_screen(gdk.gdk_screen_get_default());
@@ -189,19 +201,19 @@ firetray.ChatStatusIcon = {
fadeStep: function() {
try {
if (firetray.ChatStatusIcon.generators['fade'].next())
- firetray.ChatStatusIcon.timers['fade-step'] = firetray.Utils.timer(
- ALPHA_STEP_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT,
- firetray.ChatStatusIcon.fadeStep);
+ firetray.ChatStatusIcon.timers['fade-step'].initWithCallback(
+ { notify: firetray.ChatStatusIcon.fadeStep },
+ ALPHA_STEP_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
+
+
} catch (e if e instanceof StopIteration) {
if (firetray.ChatStatusIcon.events['stop-fade']) {
log.debug("stop-fade");
delete firetray.ChatStatusIcon.events['stop-fade'];
delete firetray.ChatStatusIcon.generators['fade'];
- delete firetray.ChatStatusIcon.timers['fade-step'];
- delete firetray.ChatStatusIcon.timers['fade-loop'];
firetray.ChatStatusIcon.setIconImage(firetray.ChatStatusIcon.themedIconNameCurrent);
- firetray.ChatStatusIcon.dropPixBuf(p);
+ firetray.ChatStatusIcon.dropPixBuf();
return;
}
@@ -209,16 +221,14 @@ firetray.ChatStatusIcon = {
delete firetray.ChatStatusIcon.events['icon-changed'];
firetray.ChatStatusIcon.dropPixBuf();
firetray.ChatStatusIcon.buildPixBuf();
- firetray.ChatStatusIcon.timers['fade-loop'] = firetray.Utils.timer(
- FADE_OVER_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT, function(){
- firetray.ChatStatusIcon.fadeLoop();}
- );
+ firetray.ChatStatusIcon.timers['fade-loop'].initWithCallback(
+ { notify: firetray.ChatStatusIcon.fadeLoop },
+ FADE_OVER_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
} else {
- firetray.ChatStatusIcon.timers['fade-loop'] = firetray.Utils.timer(
- FADE_OVER_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT, function(){
- firetray.ChatStatusIcon.fadeLoop();}
- );
+ firetray.ChatStatusIcon.timers['fade-loop'].initWithCallback(
+ { notify: firetray.ChatStatusIcon.fadeLoop },
+ FADE_OVER_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
}
};
},
@@ -241,22 +251,39 @@ firetray.ChatStatusIcon = {
startBlinking: function() { // gtk_status_icon_set_blinking() deprecated
this.on = true;
- firetray.ChatStatusIcon.timers['blink'] = firetray.Utils.timer(
- 500, Ci.nsITimer.TYPE_REPEATING_SLACK, function() {
+ firetray.ChatStatusIcon.timers['blink'].initWithCallback({
+ notify: function() {
if (firetray.ChatStatusIcon.on)
firetray.ChatStatusIcon.setIconVoid();
else
firetray.ChatStatusIcon.setIconImage(firetray.ChatStatusIcon.themedIconNameCurrent);
firetray.ChatStatusIcon.on = !firetray.ChatStatusIcon.on;
- });
+ }
+ }, BLINK_TOGGLE_PERIOD_MILLISECONDS, Ci.nsITimer.TYPE_REPEATING_SLACK);
},
stopBlinking: function() {
+ log.debug("stopBlinking");
this.timers['blink'].cancel();
this.setIconImage(firetray.ChatStatusIcon.themedIconNameCurrent);
this.on = false;
},
+ toggleBlinkStyle: function(blinkStyle) {
+ switch (blinkStyle) {
+ case FIRETRAY_CHAT_ICON_BLINK_STYLE_NORMAL:
+ this.stopFading();
+ this.startBlinking();
+ break;
+ case FIRETRAY_CHAT_ICON_BLINK_STYLE_FADE:
+ this.stopBlinking();
+ this.startFading();
+ break;
+ default:
+ throw new Error("Undefined chat icon blink style.");
+ }
+ },
+
setUrgency: function(xid, urgent) {
gtk.gtk_window_set_urgency_hint(firetray.Handler.gtkWindows.get(xid), urgent);
},
--
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