Back to index

lightning-sunbird  0.9+nobinonly
nsMessengerOS2Integration.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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  *   Peter Weilbacher <mozilla@Weilbacher.org>
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 #define INCL_DOSMEMMGR
00042 #define INCL_DOSERRORS
00043 #include <os2.h>
00044 
00045 #include "nsMessengerOS2Integration.h"
00046 #include "nsIMsgAccountManager.h"
00047 #include "nsMsgBaseCID.h"
00048 
00049 #define WARPCENTER_SHAREDMEM "\\sharemem\\inbox.mem"
00050 
00051 nsMessengerOS2Integration::nsMessengerOS2Integration()
00052 {
00053   PVOID pvObject = NULL;
00054   PULONG pUnreadState = NULL;
00055   APIRET rc = DosGetNamedSharedMem((PVOID *)&pUnreadState, WARPCENTER_SHAREDMEM,
00056                                    PAG_READ | PAG_WRITE);
00057 
00058   if (rc != NO_ERROR) {
00059     rc = DosAllocSharedMem(&pvObject, WARPCENTER_SHAREDMEM, sizeof(ULONG),
00060                            PAG_COMMIT | PAG_WRITE);
00061     pUnreadState = (PULONG)pvObject;
00062   }
00063   *pUnreadState = 0;
00064 
00065   mBiffStateAtom = do_GetAtom("BiffState");
00066   mTotalUnreadMessagesAtom = do_GetAtom("TotalUnreadMessages");
00067 }
00068 
00069 nsMessengerOS2Integration::~nsMessengerOS2Integration()
00070 {
00071   PULONG pUnreadState = NULL;
00072   APIRET rc = DosGetNamedSharedMem((PVOID *)&pUnreadState, WARPCENTER_SHAREDMEM,
00073                                    PAG_READ | PAG_WRITE);
00074 
00075   if (rc != NO_ERROR) {
00076     rc = DosFreeMem(pUnreadState);
00077   }
00078 }
00079 
00080 NS_IMPL_ISUPPORTS2(nsMessengerOS2Integration, nsIMessengerOSIntegration, nsIFolderListener)
00081 
00082 nsresult
00083 nsMessengerOS2Integration::Init()
00084 {
00085   nsresult rv;
00086 
00087   nsCOMPtr <nsIMsgAccountManager> accountManager = 
00088     do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
00089   NS_ENSURE_SUCCESS(rv,rv);
00090 
00091   // because we care if the default server changes
00092   rv = accountManager->AddRootFolderListener(this);
00093   NS_ENSURE_SUCCESS(rv,rv);
00094 
00095   return NS_OK;
00096 }
00097 
00098 NS_IMETHODIMP
00099 nsMessengerOS2Integration::OnItemPropertyChanged(nsIRDFResource *, nsIAtom *, char const *, char const *)
00100 {
00101   return NS_OK;
00102 }
00103 
00104 NS_IMETHODIMP
00105 nsMessengerOS2Integration::OnItemUnicharPropertyChanged(nsIRDFResource *, nsIAtom *, const PRUnichar *, const PRUnichar *)
00106 {
00107   return NS_OK;
00108 }
00109 
00110 NS_IMETHODIMP
00111 nsMessengerOS2Integration::OnItemRemoved(nsIRDFResource *, nsISupports *)
00112 {
00113   return NS_OK;
00114 }
00115 
00116 NS_IMETHODIMP
00117 nsMessengerOS2Integration::OnItemPropertyFlagChanged(nsIMsgDBHdr *item, nsIAtom *property, PRUint32 oldFlag, PRUint32 newFlag)
00118 {
00119   return NS_OK;
00120 }
00121 
00122 NS_IMETHODIMP
00123 nsMessengerOS2Integration::OnItemAdded(nsIRDFResource *, nsISupports *)
00124 {
00125   return NS_OK;
00126 }
00127 
00128 NS_IMETHODIMP
00129 nsMessengerOS2Integration::OnItemBoolPropertyChanged(nsIRDFResource *aItem, nsIAtom *aProperty, PRBool aOldValue, PRBool aNewValue)
00130 {
00131   return NS_OK;
00132 }
00133 
00134 NS_IMETHODIMP
00135 nsMessengerOS2Integration::OnItemEvent(nsIMsgFolder *, nsIAtom *)
00136 {
00137   return NS_OK;
00138 }
00139 
00140 NS_IMETHODIMP
00141 nsMessengerOS2Integration::OnItemIntPropertyChanged(nsIRDFResource *aItem, nsIAtom *aProperty, PRInt32 aOldValue, PRInt32 aNewValue)
00142 {
00143   PULONG pUnreadState = NULL;
00144   APIRET rc = DosGetNamedSharedMem((PVOID *)&pUnreadState, WARPCENTER_SHAREDMEM,
00145                                    PAG_READ | PAG_WRITE);
00146   if (rc != NO_ERROR)
00147     return NS_OK;
00148 
00149   if (aProperty == mBiffStateAtom) {
00150     if (aNewValue == nsIMsgFolder::nsMsgBiffState_NewMail) {
00151       *pUnreadState = 1;
00152     } else if (aNewValue == nsIMsgFolder::nsMsgBiffState_NoMail) {
00153       *pUnreadState = 0;
00154     } else {
00155       // setting nothing, unknown state (nsIMsgFolder::nsMsgBiffState_Unknown)
00156     }
00157   } else if (aProperty == mTotalUnreadMessagesAtom) {
00158     // do nothing for now
00159     // (we just want to reflect the statusbar mail biff in the system)
00160   }
00161 
00162   return NS_OK;
00163 }