Back to index

lightning-sunbird  0.9+nobinonly
nsAbWinHelper.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  * Sun Microsystems, Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef nsAbWinHelper_h___
00039 #define nsAbWinHelper_h___
00040 
00041 #include <windows.h>
00042 #include <mapix.h>
00043 
00044 #include "nsString.h"
00045 #include "nsVoidArray.h"
00046 #include "nsXPIDLString.h"
00047  
00048 struct nsMapiEntry
00049 {
00050     ULONG     mByteCount ;
00051     LPENTRYID mEntryId ;
00052 
00053     nsMapiEntry(void) ;
00054     ~nsMapiEntry(void) ;
00055     nsMapiEntry(ULONG aByteCount, LPENTRYID aEntryId) ;
00056 
00057     void Assign(ULONG aByteCount, LPENTRYID aEntryId) ;
00058     void Assign(const nsCString& aString) ;
00059     void ToString(nsCString& aString) const ;
00060     void Dump(void) const ;
00061 } ;
00062 
00063 struct nsMapiEntryArray 
00064 {
00065     nsMapiEntry *mEntries ;
00066     ULONG      mNbEntries ;
00067 
00068     nsMapiEntryArray(void) ;
00069     ~nsMapiEntryArray(void) ;
00070 
00071     const nsMapiEntry& operator [] (int aIndex) const { return mEntries [aIndex] ; }
00072     void CleanUp(void) ;
00073 } ;
00074 
00075 class nsAbWinHelper
00076 {
00077 public:
00078     nsAbWinHelper(void) ;
00079     virtual ~nsAbWinHelper(void) ;
00080 
00081     // Get the top address books
00082     BOOL GetFolders(nsMapiEntryArray& aFolders) ;
00083     // Get a list of entries for cards/mailing lists in a folder/mailing list
00084     BOOL GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
00085                   nsMapiEntryArray& aCards) ;
00086     // Get a list of mailing lists in a folder
00087     BOOL GetNodes(const nsMapiEntry& aParent, nsMapiEntryArray& aNodes) ;
00088     // Get the number of cards/mailing lists in a folder/mailing list
00089     BOOL GetCardsCount(const nsMapiEntry& aParent, ULONG& aNbCards) ;
00090     // Access last MAPI error
00091     HRESULT LastError(void) const { return mLastError ; }
00092     // Get the value of a MAPI property of type string
00093     BOOL GetPropertyString(const nsMapiEntry& aObject, ULONG aPropertyTag, nsCString& aValue) ;
00094     // Same as previous, but string is returned as unicode
00095     BOOL GetPropertyUString(const nsMapiEntry& aObject, ULONG aPropertyTag, nsString& aValue) ;
00096     // Get multiple string MAPI properties in one call.
00097     BOOL GetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag, 
00098                               ULONG aNbProperties, nsStringArray& aValues) ;
00099     // Get the value of a MAPI property of type SYSTIME
00100     BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag, 
00101                          WORD& aYear, WORD& aMonth, WORD& aDay) ;
00102     // Get the value of a MAPI property of type LONG
00103     BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
00104     // Get the value of a MAPI property of type BIN
00105     BOOL GetPropertyBin(const nsMapiEntry& aObject, ULONG aPropertyTag, nsMapiEntry& aValue) ;
00106     // Tests if a container contains an entry
00107     BOOL TestOpenEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
00108     // Delete an entry in the address book
00109     BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
00110     // Set the value of a MAPI property of type string in unicode
00111     BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag, 
00112                              const PRUnichar *aValue) ;
00113     // Same as previous, but with a bunch of properties in one call
00114     BOOL SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
00115                               ULONG aNbProperties, nsXPIDLString *aValues) ;
00116     // Set the value of a MAPI property of type SYSTIME
00117     BOOL SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag, 
00118                          WORD aYear, WORD aMonth, WORD aDay) ;
00119     // Create entry in the address book
00120     BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
00121     // Create a distribution list in the address book
00122     BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
00123     // Copy an existing entry in the address book
00124     BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
00125     // Get a default address book container
00126     BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
00127     // Is the helper correctly initialised?
00128     BOOL IsOK(void) const { return mAddressBook != NULL ; }
00129 
00130 protected:
00131     HRESULT mLastError ;
00132     LPADRBOOK mAddressBook ;
00133     static PRUint32 mEntryCounter ;
00134     static PRLock *mMutex ;
00135 
00136     // Retrieve the contents of a container, with an optional restriction
00137     BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
00138                      nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ;
00139     // Retrieve the values of a set of properties on a MAPI object
00140     BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
00141                            ULONG aNbProperties,
00142                            LPSPropValue& aValues, ULONG& aValueCount) ;
00143     // Set the values of a set of properties on a MAPI object
00144     BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
00145                            const LPSPropValue& aValues) ;
00146     // Clean-up a rowset returned by QueryRows
00147     void MyFreeProws(LPSRowSet aSet) ;
00148     // Allocation of a buffer for transmission to interfaces
00149     virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) = 0 ;
00150     // Destruction of a buffer provided by the interfaces
00151     virtual void FreeBuffer(LPVOID aBuffer) = 0 ;
00152 
00153 private:
00154 } ;
00155 
00156 enum nsAbWinType 
00157 {
00158     nsAbWinType_Unknown,
00159     nsAbWinType_Outlook,
00160     nsAbWinType_OutlookExp
00161 } ;
00162 
00163 class nsAbWinHelperGuard 
00164 {
00165 public :
00166     nsAbWinHelperGuard(PRUint32 aType) ;
00167     ~nsAbWinHelperGuard(void) ;
00168 
00169     nsAbWinHelper *operator ->(void) { return mHelper ; }
00170 
00171 private:
00172     nsAbWinHelper *mHelper ;
00173 } ;
00174 
00175 extern const char *kOutlookDirectoryScheme ;
00176 extern const char *kOutlookStub ;
00177 extern const char *kOutlookExpStub ;
00178 extern const char *kOutlookCardScheme ;
00179 
00180 nsAbWinType getAbWinType(const char *aScheme, const char *aUri, 
00181                          nsCString& aStub, nsCString& aEntry) ;
00182 void buildAbWinUri(const char *aScheme, PRUint32 aType, nsCString& aUri) ;
00183 
00184 #endif // nsAbWinHelper_h___
00185 
00186 
00187