Back to index

lightning-sunbird  0.9+nobinonly
nsAbMDBDirectory.h
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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /********************************************************************************************************
00039  
00040    Interface for representing Address Book Directory
00041  
00042 *********************************************************************************************************/
00043 
00044 #ifndef nsAbMDBDirectory_h__
00045 #define nsAbMDBDirectory_h__
00046 
00047 #include "nsAbMDBDirProperty.h"  
00048 #include "nsIAbCard.h"
00049 #include "nsCOMArray.h"
00050 #include "nsISupportsArray.h"
00051 #include "nsCOMPtr.h"
00052 #include "nsDirPrefs.h"
00053 #include "nsIAbDirectorySearch.h"
00054 #include "nsAbDirSearchListener.h"
00055 #include "nsHashtable.h"
00056 #include "nsRDFResource.h"
00057 #include "nsIAddrDBListener.h"
00058 
00059 /* 
00060  * Address Book Directory
00061  */ 
00062 
00063 class nsAbMDBDirectory:
00064   public nsRDFResource, 
00065   public nsAbMDBDirProperty,       // nsIAbDirectory, nsIAbMDBDirectory
00066   public nsAbDirSearchListenerContext,
00067   public nsIAddrDBListener, 
00068   public nsIAbDirectorySearch
00069 {
00070 public: 
00071   nsAbMDBDirectory(void);
00072   virtual ~nsAbMDBDirectory(void);
00073 
00074   NS_DECL_ISUPPORTS_INHERITED
00075   NS_DECL_NSIADDRDBLISTENER
00076 
00077   // nsIRDFResource methods:
00078   NS_IMETHOD Init(const char* aURI);
00079 
00080   // nsIAbMDBDirectory methods
00081   NS_IMETHOD ClearDatabase();
00082   NS_IMETHOD NotifyDirItemAdded(nsISupports *item) { return NotifyItemAdded(item);}
00083   NS_IMETHOD RemoveElementsFromAddressList();
00084   NS_IMETHOD RemoveEmailAddressAt(PRUint32 aIndex);
00085   NS_IMETHOD AddDirectory(const char *uriName, nsIAbDirectory **childDir);
00086   NS_IMETHOD GetDirUri(char **uri);
00087   NS_IMETHOD HasCardForEmailAddress(const char * aEmailAddress, PRBool * aCardExists);
00088   NS_IMETHOD CardForEmailAddress(const char * aEmailAddress, nsIAbCard ** aAbCard);
00089 
00090   // nsIAbDirectory methods:
00091   NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result);
00092   NS_IMETHOD GetChildCards(nsIEnumerator* *result);
00093   NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties);
00094   NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
00095   NS_IMETHOD DeleteCards(nsISupportsArray *cards);
00096   NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
00097   NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
00098   NS_IMETHOD CreateNewDirectory(nsIAbDirectoryProperties *aProperties);
00099   NS_IMETHOD CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating);
00100   NS_IMETHOD AddMailList(nsIAbDirectory *list);
00101   NS_IMETHOD AddMailListWithKey(nsIAbDirectory *list, PRUint32 *key);
00102   NS_IMETHOD AddCard(nsIAbCard *card, nsIAbCard **addedCard);
00103   NS_IMETHOD DropCard(nsIAbCard *card, PRBool needToCopyCard);
00104   NS_IMETHOD EditMailListToDatabase(const char *uri, nsIAbCard *listCard);
00105 
00106   // nsIAbDirectorySearch methods
00107   NS_DECL_NSIABDIRECTORYSEARCH
00108 
00109   // nsAbDirSearchListenerContext methods
00110   nsresult OnSearchFinished (PRInt32 result);
00111   nsresult OnSearchFoundCard (nsIAbCard* card);
00112 
00113   PRBool IsMailingList(){ return (mIsMailingList == 1); }
00114 
00115 protected:
00116   nsresult NotifyPropertyChanged(nsIAbDirectory *list, const char *property, const PRUnichar* oldValue, const PRUnichar* newValue);
00117   nsresult NotifyItemAdded(nsISupports *item);
00118   nsresult NotifyItemDeleted(nsISupports *item);
00119   nsresult NotifyItemChanged(nsISupports *item);
00120   nsresult RemoveCardFromAddressList(nsIAbCard* card);
00121   nsresult InternalAddMailList(nsIAbDirectory *list, PRUint32 *key);
00122 
00123   nsresult GetAbDatabase();
00124   nsCOMPtr<nsIAddrDatabase> mDatabase;  
00125 
00126 protected:
00127   nsCOMArray<nsIAbDirectory> mSubDirectories;
00128   PRBool mInitialized;
00129   PRInt16 mIsMailingList;
00130 
00131   PRBool mIsValidURI;
00132   PRBool mIsQueryURI;
00133   nsCString mPath;
00134   nsCString mQueryString;
00135   nsCString mURINoQuery;
00136   
00137   PRInt32 mContext;
00138   PRBool mPerformingQuery;
00139   nsSupportsHashtable mSearchCache;
00140 };
00141 
00142 #endif