Back to index

lightning-sunbird  0.9+nobinonly
nsMessengerWinIntegration.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *   Bhuvan Racham <racham@netscape.com>
00025  *   Scott MacGregor <mscott@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef __nsMessengerWinIntegration_h
00042 #define __nsMessengerWinIntegration_h
00043 
00044 #include <windows.h>
00045 
00046 // shellapi.h is needed to build with WIN32_LEAN_AND_MEAN
00047 #include <shellapi.h>
00048 
00049 #include "nsIMessengerOSIntegration.h"
00050 #include "nsIFolderListener.h"
00051 #include "nsIAlertsService.h"
00052 #include "nsIAtom.h"
00053 #include "nsITimer.h"
00054 #include "nsCOMPtr.h"
00055 #include "nsString.h"
00056 #include "nsInt64.h"
00057 #include "nsISupportsArray.h"
00058 #include "nsIObserver.h"
00059 
00060 // this function is exported by shell32.dll version 5.60 or later (Windows XP or greater)
00061 extern "C"
00062 {
00063 typedef HRESULT (__stdcall *fnSHSetUnreadMailCount)(LPCWSTR pszMailAddress, DWORD dwCount, LPCWSTR pszShellExecuteCommand);
00064 typedef HRESULT (__stdcall *fnSHEnumerateUnreadMailAccounts)(HKEY hKeyUser, DWORD dwIndex, LPCWSTR pszMailAddress, int cchMailAddress);
00065 typedef BOOL (_stdcall *fnShellNotifyW)(DWORD dwMessage, PNOTIFYICONDATAW lpdata);
00066 }
00067 
00068 #define NS_MESSENGERWININTEGRATION_CID \
00069   {0xf62f3d3a, 0x1dd1, 0x11b2, \
00070     {0xa5, 0x16, 0xef, 0xad, 0xb1, 0x31, 0x61, 0x5c}}
00071 
00072 class nsIStringBundle; 
00073 
00074 class nsMessengerWinIntegration : public nsIMessengerOSIntegration,
00075                                   public nsIFolderListener,
00076                                   public nsIObserver
00077 {
00078 public:
00079   nsMessengerWinIntegration();
00080   virtual ~nsMessengerWinIntegration();
00081   virtual nsresult Init();
00082 
00083   NS_DECL_ISUPPORTS
00084   NS_DECL_NSIMESSENGEROSINTEGRATION
00085   NS_DECL_NSIFOLDERLISTENER
00086   NS_DECL_NSIOBSERVER
00087 
00088 #ifdef MOZ_THUNDERBIRD
00089   nsresult ShowNewAlertNotification(PRBool aUserInitiated);
00090 #endif
00091 
00092 private:
00093   nsresult AlertFinished();
00094   nsresult AlertClicked();
00095 
00096   static NOTIFYICONDATAW sWideBiffIconData; 
00097   static NOTIFYICONDATA  sNativeBiffIconData;
00098 
00099   void InitializeBiffStatusIcon(); 
00100   void FillToolTipInfo();
00101   void GenericShellNotify(DWORD aMessage);
00102   void SetToolTipStringOnIconData(const PRUnichar * aToolTipString);
00103   void DestroyBiffIcon();
00104   void RevertToNonUnicodeShellAPI();
00105 
00106   PRUint32 GetToolTipSize(); // available space for the tooltip string
00107 #ifndef MOZ_THUNDERBIRD
00108   nsresult ShowAlertMessage(const PRUnichar * aAlertTitle, const PRUnichar * aAlertText, const char * aFolderURI);
00109 #endif
00110   nsresult GetFirstFolderWithNewMail(char ** aFolderURI);
00111 
00112   nsresult GetStringBundle(nsIStringBundle **aBundle);
00113   nsCOMPtr<nsISupportsArray> mFoldersWithNewMail;  // keep track of all the root folders with pending new mail
00114   fnShellNotifyW mShellNotifyWideChar;
00115   nsCOMPtr<nsIAtom> mBiffStateAtom;
00116   PRUint32 mCurrentBiffState;
00117 
00118   PRPackedBool mUseWideCharBiffIcon; 
00119   PRPackedBool mStoreUnreadCounts;   // for windows XP, we do a lot of work to store the last unread count for the inbox
00120                                      // this flag is set to true when we are doing that
00121   PRPackedBool mBiffIconVisible;
00122   PRPackedBool mBiffIconInitialized;
00123   PRPackedBool mSuppressBiffIcon;
00124   PRPackedBool mAlertInProgress;
00125   
00126   // "might" because we don't know until we check 
00127   // what type of server is associated with the default account
00128   PRPackedBool    mDefaultAccountMightHaveAnInbox;
00129 
00130   // True if the timer is running
00131   PRPackedBool mUnreadTimerActive;
00132 
00133   nsresult ResetCurrent();
00134   nsresult RemoveCurrentFromRegistry();
00135   nsresult UpdateRegistryWithCurrent();
00136   nsresult SetupInbox();
00137 
00138   nsresult SetupUnreadCountUpdateTimer();
00139   static void OnUnreadCountUpdateTimer(nsITimer *timer, void *osIntegration);
00140   nsresult UpdateUnreadCount();
00141 
00142   nsCOMPtr <nsIAtom> mDefaultServerAtom;
00143   nsCOMPtr <nsIAtom> mTotalUnreadMessagesAtom;
00144   nsCOMPtr <nsITimer> mUnreadCountUpdateTimer;
00145 
00146   fnSHSetUnreadMailCount mSHSetUnreadMailCount;
00147   fnSHEnumerateUnreadMailAccounts mSHEnumerateUnreadMailAccounts;
00148 
00149   char *mInboxURI;
00150   char *mEmail;
00151 
00152   nsAutoString mAppName;      
00153   nsAutoString mEmailPrefix;  
00154   nsCString mShellDllPath;
00155 
00156 #ifdef MOZ_THUNDERBIRD
00157   nsString mProfilePath;
00158 #else
00159   nsXPIDLString mProfileName;
00160 #endif
00161 
00162 
00163   PRInt32   mCurrentUnreadCount;
00164   PRInt32   mLastUnreadCountWrittenToRegistry;
00165 };
00166 
00167 #endif // __nsMessengerWinIntegration_h