From a10b63a8b2bfdcad4a6bc9b3b38afc3730edddae Mon Sep 17 00:00:00 2001 From: foudfou Date: Sat, 8 Feb 2014 22:41:47 +0100 Subject: [PATCH] * fix firetray's chat support policy handling * implement windowGetAttention(), setIconImageDefault(), setIconImageNewMail() At this stage, we must consider adapting the preferences' UI. --- src/modules/FiretrayHandler.jsm | 12 ++++-- src/modules/FiretrayMessaging.jsm | 6 +-- src/modules/ctypes/winnt/user32.jsm | 23 ++++++++++ src/modules/linux/FiretrayWindow.jsm | 4 ++ src/modules/winnt/FiretrayStatusIcon.jsm | 55 ++++++++++++++++++------ src/modules/winnt/FiretrayWindow.jsm | 24 +++++++++++ 6 files changed, 105 insertions(+), 19 deletions(-) diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm index e7abaf8..24f6a2f 100644 --- a/src/modules/FiretrayHandler.jsm +++ b/src/modules/FiretrayHandler.jsm @@ -113,7 +113,7 @@ firetray.Handler = { let chatIsProvided = this.isChatProvided(); log.info('isChatProvided='+chatIsProvided); if (chatIsProvided) { - if (FIRETRAY_CHAT_SUPPORTED_OS.indexOf(this.runtimeOS) > -1) { + if (this.isChatSupported()) { Cu.import("resource://firetray/FiretrayMessaging.jsm"); // needed for existsChatAccount Cu.import("resource://firetray/"+this.runtimeOS+"/FiretrayChat.jsm"); firetray.Utils.addObservers(firetray.Handler, [ @@ -163,7 +163,8 @@ firetray.Handler = { shutdown: function() { log.debug("Disabling Handler"); - if (firetray.Handler.isChatProvided() && firetray.Chat.initialized) + if (firetray.Handler.isChatProvided() && firetray.Handler.isChatSupported() + && firetray.Chat.initialized) firetray.Chat.shutdown(); if (this.inMailApp) @@ -191,6 +192,10 @@ firetray.Handler = { return this.appHasChat && Services.prefs.getBoolPref("mail.chat.enabled"); }, + isChatSupported: function() { + return FIRETRAY_CHAT_SUPPORTED_OS.indexOf(this.runtimeOS) > -1; + }, + tryCloseLibs: function() { try { for (let libName in this.ctypesLibs) { @@ -332,6 +337,7 @@ firetray.Handler = { showWindow: function(winId) {}, activateLastWindowCb: function(gtkStatusIcon, gdkEvent, userData) {}, getActiveWindow: function() {}, + windowGetAttention: function(winId) {}, showAllWindows: function() { log.debug("showAllWindows"); @@ -565,7 +571,7 @@ firetray.MailChatPrefListener = new PrefListener( let enableChatCond = (firetray.Handler.appHasChat && firetray.Utils.prefService.getBoolPref("chat_icon_enable") && - FIRETRAY_CHAT_SUPPORTED_OS.indexOf(this.runtimeOS) > -1); + firetray.Handler.isChatSupported()); if (!enableChatCond) return; if (Services.prefs.getBoolPref("mail.chat.enabled")) { diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm index dcb1d1f..a8adfaf 100644 --- a/src/modules/FiretrayMessaging.jsm +++ b/src/modules/FiretrayMessaging.jsm @@ -183,10 +183,10 @@ firetray.Messaging = { if (mailChangeTriggerFile) firetray.Messaging.runProcess(mailChangeTriggerFile, [newMsgCount.toString()]); - let setUrgency = firetray.Utils.prefService.getBoolPref("mail_urgency_hint"); - if (setUrgency && (newMsgCount > currentMsgCount)) + let getAttention = firetray.Utils.prefService.getBoolPref("mail_urgency_hint"); // FIXME: rename! + if (getAttention && (newMsgCount > currentMsgCount)) for (let winId in firetray.Handler.windows) - firetray.Window.setUrgency(winId, true); + firetray.Handler.windowGetAttention(winId); } }; diff --git a/src/modules/ctypes/winnt/user32.jsm b/src/modules/ctypes/winnt/user32.jsm index 3022040..8b2abbf 100644 --- a/src/modules/ctypes/winnt/user32.jsm +++ b/src/modules/ctypes/winnt/user32.jsm @@ -218,6 +218,29 @@ function user32_defines(lib) { lib.lazy_bind("GetWindowThreadProcessId", win32.DWORD, win32.HWND, win32.LPDWORD); + this.FLASHWINFO = ctypes.StructType("FLASHWINFO", [ + { "cbSize": win32.UINT }, + { "hwnd": win32.HWND }, + { "dwFlags": win32.DWORD }, + { "uCount": win32.UINT }, + { "dwTimeout": win32.DWORD } + ]); + this.PFLASHWINFO = this.FLASHWINFO.ptr; + + lib.lazy_bind("FlashWindow", win32.BOOL, win32.HWND, win32.BOOL); + lib.lazy_bind("FlashWindowEx", win32.BOOL, this.PFLASHWINFO); + + this.FLASHW_STOP = 0; + this.FLASHW_CAPTION = 0x00000001; + this.FLASHW_TRAY = 0x00000002; + this.FLASHW_ALL =(this.FLASHW_CAPTION | this.FLASHW_TRAY); + this.FLASHW_TIMER = 0x00000004; + this.FLASHW_TIMERNOFG = 0x0000000C; + + lib.lazy_bind("SystemParametersInfoW", win32.BOOL, win32.UINT, win32.UINT, win32.PVOID, win32.UINT); + this.SPI_GETFOREGROUNDFLASHCOUNT = 0x2004; + lib.lazy_bind("GetForegroundWindow", win32.HWND); + } new ctypes_library(USER32_LIBNAME, USER32_ABIS, user32_defines, this); diff --git a/src/modules/linux/FiretrayWindow.jsm b/src/modules/linux/FiretrayWindow.jsm index 55672e6..8ba273a 100644 --- a/src/modules/linux/FiretrayWindow.jsm +++ b/src/modules/linux/FiretrayWindow.jsm @@ -736,6 +736,10 @@ firetray.Handler.getActiveWindow = function() { return activeWin; }; +firetray.Handler.windowGetAttention = function(winId) { + firetray.Window.setUrgency(winId, true); +}; + /** * init X11 Display and handled XAtoms. diff --git a/src/modules/winnt/FiretrayStatusIcon.jsm b/src/modules/winnt/FiretrayStatusIcon.jsm index a0bf959..1a8f5fa 100644 --- a/src/modules/winnt/FiretrayStatusIcon.jsm +++ b/src/modules/winnt/FiretrayStatusIcon.jsm @@ -36,14 +36,13 @@ firetray.StatusIcon = { notifyIconData: null, hwndProxy: null, icons: null, - iconsPaths: {}, WNDCLASS_NAME: "FireTrayHiddenWindowClass", WNDCLASS_ATOM: null, init: function() { this.loadIcons(); + // this.defineIconNames(); // FIXME: linux-only this.create(); - firetray.Handler.setIconImageNewMail(); // TESTING this.initialized = true; return true; @@ -56,16 +55,37 @@ firetray.StatusIcon = { this.destroyIcons(); this.initialized = false; + return true; + }, + + defineIconNames: function() { // FIXME: linux-only + this.prefAppIconNames = (function() { + if (firetray.Handler.inMailApp) { + return "app_mail_icon_names"; + } else if (firetray.Handler.inBrowserApp) { + return "app_browser_icon_names"; + } else { + return "app_default_icon_names"; + } + })(); + this.defaultAppIconName = firetray.Handler.appName.toLowerCase(); + + this.prefNewMailIconNames = "new_mail_icon_names"; + this.defaultNewMailIconName = "mail-unread"; }, loadIcons: function() { this.icons = new ctypesMap(win32.HICON); + // the Mozilla hidden window has the default Mozilla icon + let hwnd_hidden_moz = user32.FindWindowW("MozillaHiddenWindowClass", null); + log.debug("=== hwnd_hidden_moz="+hwnd_hidden_moz); + this.icons.insert('app', this.getIconFromWindow(hwnd_hidden_moz)); + /* we'll take the first icon in the .ico file. To get the icon count in the file, pass ctypes.cast(ctypes.int(-1), win32.UINT); */ for (let ico_name in FIRETRAY_ICON_CHROME_PATHS) { let path = firetray.Utils.chromeToPath(FIRETRAY_ICON_CHROME_PATHS[ico_name]); - this.iconsPaths[ico_name] = path; let hicon = shell32.ExtractIconW(null, path, 0); // ERROR_INVALID_HANDLE(6) ignored (_Reserved_ HINSTANCE hInst ?) this.icons.insert(ico_name, hicon); @@ -76,6 +96,11 @@ firetray.StatusIcon = { destroyIcons: function() { let success = true, errors = []; let keys = this.icons.keys; + + // 'app' must not get DestroyIcon'd + var idx_app = keys.indexOf('app'); + if (idx_app > -1) keys.splice(idx_app, 1); + for (let i=0, len=keys.length; i