# HG changeset patch # Parent f5a33f4b3f2be57856bb40ca8efcae23ae6e3b35 # User Gian-Carlo Pascutto Bug 499557 - Don't popup notifications when fullscreen/presenting. r= diff --git a/mailnews/base/src/nsMessengerWinIntegration.cpp b/mailnews/base/src/nsMessengerWinIntegration.cpp --- a/mailnews/base/src/nsMessengerWinIntegration.cpp +++ b/mailnews/base/src/nsMessengerWinIntegration.cpp @@ -79,16 +79,17 @@ #include "mozilla/LookAndFeel.h" #include "nsToolkitCompsCID.h" #include #define PROFILE_COMMANDLINE_ARG " -profile " #define XP_SHSetUnreadMailCounts "SHSetUnreadMailCountW" #define XP_SHEnumerateUnreadMailAccounts "SHEnumerateUnreadMailAccountsW" +#define XP_SHQueryUserNotificationState "SHQueryUserNotificationState" #define NOTIFICATIONCLASSNAME "MailBiffNotificationMessageWindow" #define UNREADMAILNODEKEY "Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\" #define SHELL32_DLL NS_LITERAL_CSTRING("shell32.dll") #define DOUBLE_QUOTE "\"" #define MAIL_COMMANDLINE_ARG " -mail" #define IDI_MAILBIFF 32576 #define UNREAD_UPDATE_INTERVAL (20 * 1000) // 20 seconds #define ALERT_CHROME_URL "chrome://messenger/content/newmailalert.xul" @@ -383,16 +384,17 @@ nsMessengerWinIntegration::Init() HMODULE hModule = ::LoadLibrary(mShellDllPath.get()); if (!hModule) return NS_OK; // get process addresses for the unread mail count functions if (hModule) { mSHSetUnreadMailCount = (fnSHSetUnreadMailCount)GetProcAddress(hModule, XP_SHSetUnreadMailCounts); mSHEnumerateUnreadMailAccounts = (fnSHEnumerateUnreadMailAccounts)GetProcAddress(hModule, XP_SHEnumerateUnreadMailAccounts); + mSHQueryUserNotificationState = (fnSHQueryUserNotificationState)GetProcAddress(hModule, XP_SHQueryUserNotificationState); } // if failed to get either of the process addresses, this is not XP platform // so we aren't storing unread counts if (mSHSetUnreadMailCount && mSHEnumerateUnreadMailAccounts) mStoreUnreadCounts = PR_TRUE; nsCOMPtr accountManager = @@ -530,16 +532,26 @@ nsresult nsMessengerWinIntegration::Show ::wcsncpy( sBiffIconData.szInfo, aAlertText.get(), kMaxBalloonSize); } bool showAlert = true; if (prefBranch) prefBranch->GetBoolPref(SHOW_ALERT_PREF, &showAlert); + // check if we are allowed to show a notification + if (mSHQueryUserNotificationState) { + QUERY_USER_NOTIFICATION_STATE qstate; + if (SUCCEEDED(mSHQueryUserNotificationState(&qstate))) { + if (qstate != QUNS_ACCEPTS_NOTIFICATIONS) { + showAlert = false; + } + } + } + if (showAlert) { nsCOMPtr argsArray; rv = NS_NewISupportsArray(getter_AddRefs(argsArray)); NS_ENSURE_SUCCESS(rv, rv); // pass in the array of folders with unread messages nsCOMPtr ifptr = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); diff --git a/mailnews/base/src/nsMessengerWinIntegration.h b/mailnews/base/src/nsMessengerWinIntegration.h --- a/mailnews/base/src/nsMessengerWinIntegration.h +++ b/mailnews/base/src/nsMessengerWinIntegration.h @@ -50,21 +50,31 @@ #include "nsIFolderListener.h" #include "nsIAtom.h" #include "nsITimer.h" #include "nsCOMPtr.h" #include "nsStringGlue.h" #include "nsISupportsArray.h" #include "nsIObserver.h" +typedef enum tagQUERY_USER_NOTIFICATION_STATE { + QUNS_NOT_PRESENT = 1, + QUNS_BUSY = 2, + QUNS_RUNNING_D3D_FULL_SCREEN = 3, + QUNS_PRESENTATION_MODE = 4, + QUNS_ACCEPTS_NOTIFICATIONS = 5 +} QUERY_USER_NOTIFICATION_STATE; + // this function is exported by shell32.dll version 5.60 or later (Windows XP or greater) extern "C" { typedef HRESULT (__stdcall *fnSHSetUnreadMailCount)(LPCWSTR pszMailAddress, DWORD dwCount, LPCWSTR pszShellExecuteCommand); typedef HRESULT (__stdcall *fnSHEnumerateUnreadMailAccounts)(HKEY hKeyUser, DWORD dwIndex, LPCWSTR pszMailAddress, int cchMailAddress); +// Vista or later +typedef HRESULT (__stdcall *fnSHQueryUserNotificationState)(QUERY_USER_NOTIFICATION_STATE *pquns); } #define NS_MESSENGERWININTEGRATION_CID \ {0xf62f3d3a, 0x1dd1, 0x11b2, \ {0xa5, 0x16, 0xef, 0xad, 0xb1, 0x31, 0x61, 0x5c}} class nsIStringBundle; @@ -128,16 +138,17 @@ private: nsresult UpdateUnreadCount(); nsCOMPtr mDefaultServerAtom; nsCOMPtr mTotalUnreadMessagesAtom; nsCOMPtr mUnreadCountUpdateTimer; fnSHSetUnreadMailCount mSHSetUnreadMailCount; fnSHEnumerateUnreadMailAccounts mSHEnumerateUnreadMailAccounts; + fnSHQueryUserNotificationState mSHQueryUserNotificationState; nsCString mInboxURI; nsCString mEmail; nsString mAppName; nsString mEmailPrefix; nsCString mShellDllPath;