Back to index

lightning-sunbird  0.9+nobinonly
nsAbOSXDirectory.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  * Peter Van der Beken.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Peter Van der Beken <peterv@propagandism.org>
00024  *
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsAbOSXDirectory_h___
00041 #define nsAbOSXDirectory_h___
00042 
00043 #include "nsAbBaseCID.h"
00044 #include "nsAbDirectoryRDFResource.h"
00045 #include "nsAbDirProperty.h"
00046 #include "nsIAbDirectoryQuery.h"
00047 #include "nsIAbDirectorySearch.h"
00048 #include "nsAbDirSearchListener.h"
00049 #include "nsTHashtable.h"
00050 
00051 class nsIAddrBookSession;
00052 
00053 #define NS_ABOSXDIRECTORY_URI_PREFIX NS_ABOSXDIRECTORY_PREFIX "://"
00054 
00055 class nsIAbCardHashKey : public PLDHashEntryHdr
00056 {
00057 public:
00058     typedef nsIAbCard* KeyType;
00059     typedef const nsIAbCard* KeyTypePointer;
00060 
00061     nsIAbCardHashKey(const nsIAbCard* key)
00062         : mCard(NS_CONST_CAST(nsIAbCard*, key))
00063     {
00064     }
00065     nsIAbCardHashKey(const nsIAbCardHashKey& toCopy)
00066         : mCard(toCopy.mCard)
00067     {
00068     }
00069     ~nsIAbCardHashKey()
00070     {
00071     }
00072 
00073     KeyType GetCard() const
00074     {
00075         return mCard;
00076     }
00077     KeyTypePointer GetKeyPointer() const
00078     {
00079         return mCard;
00080     }
00081 
00082     PRBool KeyEquals(KeyTypePointer aKey) const
00083     {
00084         return aKey == mCard;
00085     }
00086 
00087     static KeyTypePointer KeyToPointer(KeyType aKey)
00088     {
00089         return aKey;
00090     }
00091     static PLDHashNumber HashKey(KeyTypePointer aKey)
00092     {
00093         return NS_PTR_TO_INT32(aKey) >> 2;
00094     }
00095     enum { ALLOW_MEMMOVE = PR_TRUE };
00096 
00097 private:
00098     nsCOMPtr<nsIAbCard> mCard;
00099 };
00100 
00101 #define NS_IABOSXDIRECTORY_IID \
00102   { 0x87ee4bd9, 0x8552, 0x498f, \
00103     { 0x80, 0x85, 0x34, 0xf0, 0x2a, 0xbb, 0x56, 0x16 } }
00104 
00105 class nsIAbOSXDirectory : public nsISupports
00106 {
00107 public:
00108     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IABOSXDIRECTORY_IID)
00109 
00110     virtual nsresult AssertChildNodes() = 0;
00111     virtual nsresult Update() = 0;
00112     virtual nsresult AssertDirectory(nsIAddrBookSession *aSession,
00113                                      nsIAbDirectory *aDirectory) = 0;
00114     virtual nsresult AssertCard(nsIAddrBookSession *aSession,
00115                                 nsIAbCard *aCard) = 0;
00116     virtual nsresult UnassertDirectory(nsIAddrBookSession *aSession,
00117                                        nsIAbDirectory *aDirectory) = 0;
00118     virtual nsresult UnassertCard(nsIAddrBookSession *aSession,
00119                                   nsIAbCard *aCard) = 0;
00120     virtual void GetURI(nsACString &aURI) = 0;
00121 };
00122 
00123 class nsAbOSXDirectory : public nsAbDirectoryRDFResource,
00124                          public nsAbDirProperty,
00125                          public nsAbDirSearchListenerContext,
00126                          public nsIAbOSXDirectory
00127 {
00128 public:
00129     ~nsAbOSXDirectory();
00130 
00131     NS_DECL_ISUPPORTS_INHERITED
00132 
00133     // nsAbDirectoryRDFResource method
00134     NS_IMETHOD Init(const char *aUri);
00135 
00136     // nsAbDirProperty methods
00137     NS_IMETHOD GetOperations(PRInt32 *aOperations);
00138     NS_IMETHOD GetChildCards(nsIEnumerator **aCards);
00139     NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
00140     NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
00141     NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
00142 
00143     // nsAbDirSearchListenerContext methods
00144     nsresult OnSearchFinished(PRInt32 aResult);
00145     nsresult OnSearchFoundCard(nsIAbCard *aCard);
00146 
00147     // nsIAbOSXDirectory
00148     nsresult AssertChildNodes();
00149     nsresult AssertDirectory(nsIAddrBookSession *aSession,
00150                              nsIAbDirectory *aDirectory);
00151     nsresult AssertCard(nsIAddrBookSession *aSession,
00152                         nsIAbCard *aCard);
00153     nsresult UnassertDirectory(nsIAddrBookSession *aSession,
00154                                nsIAbDirectory *aDirectory);
00155     nsresult UnassertCard(nsIAddrBookSession *aSession,
00156                           nsIAbCard *aCard);
00157 
00158     nsresult Update();
00159     void GetURI(nsACString &aURI)
00160     {
00161         aURI = mURI;
00162     }
00163 
00164 private:
00165     static nsresult GetEnumerator(nsISupportsArray *aArray,
00166                                   nsIEnumerator **aEnumerator)
00167     {
00168         nsIBidirectionalEnumerator *enumerator;
00169         nsresult rv = NS_NewISupportsArrayEnumerator(aArray,
00170                                                      &enumerator);
00171         NS_ENSURE_SUCCESS(rv, rv);
00172 
00173         *aEnumerator = enumerator;
00174 
00175         return NS_OK;
00176     }
00177     nsresult FallbackSearch(nsIAbBooleanExpression *aExpression,
00178                             nsIEnumerator **aCards);
00179 
00180     nsTHashtable<nsIAbCardHashKey> mCardList;
00181 };
00182 
00183 #endif // nsAbOSXDirectory_h___