Back to index

lightning-sunbird  0.9+nobinonly
nsAddrDatabase.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) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.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 
00039 #ifndef _nsAddrDatabase_H_
00040 #define _nsAddrDatabase_H_
00041 
00042 #include "nsIAddrDatabase.h"
00043 #include "mdb.h"
00044 #include "nsVoidArray.h"
00045 #include "nsString.h"
00046 #include "nsFileSpec.h"
00047 #include "nsIAddrDBListener.h"
00048 #include "nsISupportsArray.h"
00049 #include "nsCOMPtr.h"
00050 
00051 typedef enum 
00052 {
00053        AB_NotifyInserted,
00054        AB_NotifyDeleted,
00055        AB_NotifyPropertyChanged,
00056 
00057        AB_NotifyAll,           /* contents of the have totally changed. Listener must totally
00058                                                    forget anything they knew about the object. */
00059        /* pane notifications (i.e. not tied to a particular entry */
00060        AB_NotifyScramble,     /* same contents, but the view indices have all changed 
00061                                                 i.e the object was sorted on a different attribute */
00062        AB_NotifyLDAPTotalContentChanged,
00063        AB_NotifyNewTopIndex,
00064        AB_NotifyStartSearching,
00065        AB_NotifyStopSearching
00066 
00067 } AB_NOTIFY_CODE;
00068 
00069 class nsAddrDatabase : public nsIAddrDatabase 
00070 {
00071 public:
00072   NS_DECL_ISUPPORTS
00073   NS_DECL_NSIADDRDBANNOUNCER
00074 
00076        // nsIAddrDatabase methods:
00077 
00078   NS_IMETHOD GetDbPath(nsFileSpec * *aDbPath);
00079   NS_IMETHOD SetDbPath(nsFileSpec * aDbPath);
00080   NS_IMETHOD Open(nsIFile *aMabFile, PRBool aCreate, PRBool upgrading, nsIAddrDatabase **pCardDB);
00081   NS_IMETHOD Close(PRBool forceCommit);
00082   NS_IMETHOD OpenMDB(nsFileSpec *dbName, PRBool create);
00083   NS_IMETHOD CloseMDB(PRBool commit);
00084   NS_IMETHOD Commit(PRUint32 commitType);
00085   NS_IMETHOD ForceClosed();
00086 
00087   NS_IMETHOD CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool notify);
00088   NS_IMETHOD CreateNewCardAndAddToDBWithKey(nsIAbCard *newCard, PRBool notify, PRUint32 *key);    
00089   NS_IMETHOD CreateNewListCardAndAddToDB(nsIAbDirectory *list, PRUint32 listRowID, nsIAbCard *newCard, PRBool notify);
00090   NS_IMETHOD CreateMailListAndAddToDB(nsIAbDirectory *newList, PRBool notify);
00091   NS_IMETHOD CreateMailListAndAddToDBWithKey(nsIAbDirectory *newList, PRBool notify, PRUint32 *key);
00092   NS_IMETHOD EnumerateCards(nsIAbDirectory *directory, nsIEnumerator **result);
00093   NS_IMETHOD GetMailingListsFromDB(nsIAbDirectory *parentDir);
00094   NS_IMETHOD EnumerateListAddresses(nsIAbDirectory *directory, nsIEnumerator **result);
00095   NS_IMETHOD DeleteCard(nsIAbCard *newCard, PRBool notify);
00096   NS_IMETHOD EditCard(nsIAbCard *card, PRBool notify);
00097   NS_IMETHOD ContainsCard(nsIAbCard *card, PRBool *hasCard);
00098   NS_IMETHOD DeleteMailList(nsIAbDirectory *mailList, PRBool notify);
00099   NS_IMETHOD EditMailList(nsIAbDirectory *mailList, nsIAbCard *listCard, PRBool notify);
00100   NS_IMETHOD ContainsMailList(nsIAbDirectory *mailList, PRBool *hasCard);
00101   NS_IMETHOD DeleteCardFromMailList(nsIAbDirectory *mailList, nsIAbCard *card, PRBool aNotify);
00102   NS_IMETHOD GetCardFromAttribute(nsIAbDirectory *directory, const char *aName, const char *aValue, PRBool aCaseInsensitive, nsIAbCard **card);    
00103   NS_IMETHOD GetNewRow(nsIMdbRow * *newRow); 
00104   NS_IMETHOD GetNewListRow(nsIMdbRow * *newRow); 
00105   NS_IMETHOD AddCardRowToDB(nsIMdbRow *newRow);
00106   NS_IMETHOD AddLdifListMember(nsIMdbRow* row, const char * value);
00107 
00108   NS_IMETHOD GetDeletedCardList(PRUint32 *aCount, nsISupportsArray **aDeletedList);
00109   NS_IMETHOD GetDeletedCardCount(PRUint32 *count);
00110   NS_IMETHOD PurgeDeletedCardTable();
00111   
00112   NS_IMETHOD AddFirstName(nsIMdbRow * row, const char * value)
00113   { return AddCharStringColumn(row, m_FirstNameColumnToken, value); }
00114 
00115   NS_IMETHOD AddLastName(nsIMdbRow * row, const char * value)
00116   { return AddCharStringColumn(row, m_LastNameColumnToken, value); }
00117 
00118   NS_IMETHOD AddPhoneticFirstName(nsIMdbRow * row, const char * value)
00119   { return AddCharStringColumn(row, m_PhoneticFirstNameColumnToken, value); }
00120 
00121   NS_IMETHOD AddPhoneticLastName(nsIMdbRow * row, const char * value)
00122   { return AddCharStringColumn(row, m_PhoneticLastNameColumnToken, value); }
00123 
00124   NS_IMETHOD AddDisplayName(nsIMdbRow * row, const char * value)
00125   { return AddCharStringColumn(row, m_DisplayNameColumnToken, value); }
00126 
00127   NS_IMETHOD AddNickName(nsIMdbRow * row, const char * value)
00128   { return AddCharStringColumn(row, m_NickNameColumnToken, value); }
00129 
00130   NS_IMETHOD AddPrimaryEmail(nsIMdbRow * row, const char * value);
00131 
00132   NS_IMETHOD Add2ndEmail(nsIMdbRow * row, const char * value)
00133   { return AddCharStringColumn(row, m_2ndEmailColumnToken, value); }
00134 
00135   NS_IMETHOD AddDefaultEmail(nsIMdbRow * row, const char * value)
00136   { return AddCharStringColumn(row, m_DefaultEmailColumnToken, value); }
00137 
00138   NS_IMETHOD AddCardType(nsIMdbRow * row, const char * value)
00139   { return AddCharStringColumn(row, m_CardTypeColumnToken, value); }
00140 
00141   NS_IMETHOD AddPreferMailFormat(nsIMdbRow * row, PRUint32 value)
00142   { return AddIntColumn(row, m_MailFormatColumnToken, value); }
00143 
00144   NS_IMETHOD AddPopularityIndex(nsIMdbRow * row, PRUint32 value)
00145   { return AddIntColumn(row, m_PopularityIndexColumnToken, value); }
00146 
00147   NS_IMETHOD AddAllowRemoteContent(nsIMdbRow * row, PRBool value)
00148   { return AddBoolColumn(row, m_AllowRemoteContentColumnToken, value); }
00149 
00150   NS_IMETHOD AddWorkPhone(nsIMdbRow * row, const char * value)
00151   { return AddCharStringColumn(row, m_WorkPhoneColumnToken, value); }
00152 
00153   NS_IMETHOD AddHomePhone(nsIMdbRow * row, const char * value)
00154   { return AddCharStringColumn(row, m_HomePhoneColumnToken, value); }
00155 
00156   NS_IMETHOD AddFaxNumber(nsIMdbRow * row, const char * value)
00157   { return AddCharStringColumn(row, m_FaxColumnToken, value); }
00158 
00159   NS_IMETHOD AddPagerNumber(nsIMdbRow * row, const char * value)
00160   { return AddCharStringColumn(row, m_PagerColumnToken, value); }
00161 
00162   NS_IMETHOD AddCellularNumber(nsIMdbRow * row, const char * value)
00163   { return AddCharStringColumn(row, m_CellularColumnToken, value); }
00164 
00165   NS_IMETHOD AddWorkPhoneType(nsIMdbRow * row, const char * value)
00166   { return AddCharStringColumn(row, m_WorkPhoneTypeColumnToken, value); }
00167 
00168   NS_IMETHOD AddHomePhoneType(nsIMdbRow * row, const char * value)
00169   { return AddCharStringColumn(row, m_HomePhoneTypeColumnToken, value); }
00170 
00171   NS_IMETHOD AddFaxNumberType(nsIMdbRow * row, const char * value)
00172   { return AddCharStringColumn(row, m_FaxTypeColumnToken, value); }
00173 
00174   NS_IMETHOD AddPagerNumberType(nsIMdbRow * row, const char * value)
00175   { return AddCharStringColumn(row, m_PagerTypeColumnToken, value); }
00176 
00177   NS_IMETHOD AddCellularNumberType(nsIMdbRow * row, const char * value)
00178   { return AddCharStringColumn(row, m_CellularTypeColumnToken, value); }
00179 
00180        NS_IMETHOD AddHomeAddress(nsIMdbRow * row, const char * value)
00181        { return AddCharStringColumn(row, m_HomeAddressColumnToken, value); }
00182 
00183        NS_IMETHOD AddHomeAddress2(nsIMdbRow * row, const char * value)
00184        { return AddCharStringColumn(row, m_HomeAddress2ColumnToken, value); }
00185 
00186        NS_IMETHOD AddHomeCity(nsIMdbRow * row, const char * value)
00187        { return AddCharStringColumn(row, m_HomeCityColumnToken, value); }
00188 
00189        NS_IMETHOD AddHomeState(nsIMdbRow * row, const char * value)
00190        { return AddCharStringColumn(row, m_HomeStateColumnToken, value); }
00191 
00192        NS_IMETHOD AddHomeZipCode(nsIMdbRow * row, const char * value)
00193        { return AddCharStringColumn(row, m_HomeZipCodeColumnToken, value); }
00194 
00195        NS_IMETHOD AddHomeCountry(nsIMdbRow * row, const char * value)
00196        { return AddCharStringColumn(row, m_HomeCountryColumnToken, value); }
00197 
00198        NS_IMETHOD AddWorkAddress(nsIMdbRow * row, const char * value)
00199        { return AddCharStringColumn(row, m_WorkAddressColumnToken, value); }
00200 
00201        NS_IMETHOD AddWorkAddress2(nsIMdbRow * row, const char * value)
00202        { return AddCharStringColumn(row, m_WorkAddress2ColumnToken, value); }
00203 
00204        NS_IMETHOD AddWorkCity(nsIMdbRow * row, const char * value) 
00205        { return AddCharStringColumn(row, m_WorkCityColumnToken, value); }
00206 
00207        NS_IMETHOD AddWorkState(nsIMdbRow * row, const char * value)
00208        { return AddCharStringColumn(row, m_WorkStateColumnToken, value); }
00209 
00210        NS_IMETHOD AddWorkZipCode(nsIMdbRow * row, const char * value)
00211        { return AddCharStringColumn(row, m_WorkZipCodeColumnToken, value); }
00212 
00213        NS_IMETHOD AddWorkCountry(nsIMdbRow * row, const char * value)
00214        { return AddCharStringColumn(row, m_WorkCountryColumnToken, value); }
00215 
00216        NS_IMETHOD AddJobTitle(nsIMdbRow * row, const char * value)
00217        { return AddCharStringColumn(row, m_JobTitleColumnToken, value); }
00218 
00219        NS_IMETHOD AddDepartment(nsIMdbRow * row, const char * value)
00220        { return AddCharStringColumn(row, m_DepartmentColumnToken, value); }
00221 
00222        NS_IMETHOD AddCompany(nsIMdbRow * row, const char * value)
00223        { return AddCharStringColumn(row, m_CompanyColumnToken, value); }
00224 
00225   NS_IMETHOD AddAimScreenName(nsIMdbRow * row, const char * value)
00226   { return AddCharStringColumn(row, m_AimScreenNameColumnToken, value); }
00227 
00228   NS_IMETHOD AddAnniversaryYear(nsIMdbRow * row, const char * value)
00229   { return AddCharStringColumn(row, m_AnniversaryYearColumnToken, value); }
00230 
00231   NS_IMETHOD AddAnniversaryMonth(nsIMdbRow * row, const char * value)
00232   { return AddCharStringColumn(row, m_AnniversaryMonthColumnToken, value); }
00233 
00234   NS_IMETHOD AddAnniversaryDay(nsIMdbRow * row, const char * value)
00235   { return AddCharStringColumn(row, m_AnniversaryDayColumnToken, value); }
00236 
00237   NS_IMETHOD AddSpouseName(nsIMdbRow * row, const char * value)
00238   { return AddCharStringColumn(row, m_SpouseNameColumnToken, value); }
00239 
00240   NS_IMETHOD AddFamilyName(nsIMdbRow * row, const char * value)
00241   { return AddCharStringColumn(row, m_FamilyNameColumnToken, value); }
00242 
00243   NS_IMETHOD AddDefaultAddress(nsIMdbRow * row, const char * value)
00244   { return AddCharStringColumn(row, m_DefaultAddressColumnToken, value); }
00245 
00246   NS_IMETHOD AddCategory(nsIMdbRow * row, const char * value)
00247   { return AddCharStringColumn(row, m_CategoryColumnToken, value); }
00248 
00249        NS_IMETHOD AddWebPage1(nsIMdbRow * row, const char * value)
00250        { return AddCharStringColumn(row, m_WebPage1ColumnToken, value); }
00251 
00252        NS_IMETHOD AddWebPage2(nsIMdbRow * row, const char * value)
00253        { return AddCharStringColumn(row, m_WebPage2ColumnToken, value); }
00254 
00255        NS_IMETHOD AddBirthYear(nsIMdbRow * row, const char * value)
00256        { return AddCharStringColumn(row, m_BirthYearColumnToken, value); }
00257 
00258        NS_IMETHOD AddBirthMonth(nsIMdbRow * row, const char * value)
00259        { return AddCharStringColumn(row, m_BirthMonthColumnToken, value); }
00260 
00261        NS_IMETHOD AddBirthDay(nsIMdbRow * row, const char * value)
00262        { return AddCharStringColumn(row, m_BirthDayColumnToken, value); }
00263 
00264        NS_IMETHOD AddCustom1(nsIMdbRow * row, const char * value)
00265        { return AddCharStringColumn(row, m_Custom1ColumnToken, value); }
00266 
00267        NS_IMETHOD AddCustom2(nsIMdbRow * row, const char * value)
00268        { return AddCharStringColumn(row, m_Custom2ColumnToken, value); }
00269 
00270        NS_IMETHOD AddCustom3(nsIMdbRow * row, const char * value)
00271        { return AddCharStringColumn(row, m_Custom3ColumnToken, value); }
00272 
00273        NS_IMETHOD AddCustom4(nsIMdbRow * row, const char * value)
00274        { return AddCharStringColumn(row, m_Custom4ColumnToken, value); }
00275 
00276        NS_IMETHOD AddNotes(nsIMdbRow * row, const char * value)
00277        { return AddCharStringColumn(row, m_NotesColumnToken, value); }
00278 
00279        NS_IMETHOD AddListName(nsIMdbRow * row, const char * value);
00280 
00281        NS_IMETHOD AddListNickName(nsIMdbRow * row, const char * value)
00282        { return AddCharStringColumn(row, m_ListNickNameColumnToken, value); }
00283 
00284        NS_IMETHOD AddListDescription(nsIMdbRow * row, const char * value)
00285        { return AddCharStringColumn(row, m_ListDescriptionColumnToken, value); }
00286 
00287 
00288        NS_IMETHOD AddListDirNode(nsIMdbRow * listRow);
00289        NS_IMETHOD GetDirectoryName(PRUnichar **name);
00290 
00291        NS_IMETHOD FindMailListbyUnicodeName(const PRUnichar *listName, PRBool *exist);
00292 
00293        NS_IMETHOD GetCardCount(PRUint32 *count);
00294 
00295   NS_IMETHOD SetCardValue(nsIAbCard *card, const char *name, const PRUnichar *value, PRBool notify);
00296   NS_IMETHOD GetCardValue(nsIAbCard *card, const char *name, PRUnichar **value);
00297   NS_IMETHOD AddRowValue(nsIMdbRow *aRow, const nsACString & aLDIFAttributeName, const nsAString & aColValue);
00298 
00299        // nsAddrDatabase methods:
00300 
00301        nsAddrDatabase();
00302        virtual ~nsAddrDatabase();
00303 
00304        nsIMdbFactory *GetMDBFactory();
00305        nsIMdbEnv            *GetEnv() {return m_mdbEnv;}
00306        PRUint32             GetCurVersion();
00307        nsIMdbTableRowCursor *GetTableRowCursor();
00308        nsIMdbTable          *GetPabTable() {return m_mdbPabTable;}
00309 
00310        static nsAddrDatabase*      FindInCache(nsFileSpec *dbName);
00311 
00312        static void          CleanupCache();
00313 
00314        nsresult CreateABCard(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result);
00315        nsresult CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result);
00316        nsresult CreateABList(nsIMdbRow* listRow, nsIAbDirectory **result);
00317 
00318        PRBool IsListRowScopeToken(mdb_scope scope) { return (scope == m_ListRowScopeToken) ? PR_TRUE: PR_FALSE; }
00319        PRBool IsCardRowScopeToken(mdb_scope scope) { return (scope == m_CardRowScopeToken) ? PR_TRUE: PR_FALSE;  }
00320        PRBool IsDataRowScopeToken(mdb_scope scope) { return (scope == m_DataRowScopeToken) ? PR_TRUE: PR_FALSE; }
00321        nsresult GetCardRowByRowID(mdb_id rowID, nsIMdbRow **dbRow);
00322        nsresult GetListRowByRowID(mdb_id rowID, nsIMdbRow **dbRow);
00323 
00324        PRUint32 GetListAddressTotal(nsIMdbRow* listRow);
00325        nsresult GetAddressRowByPos(nsIMdbRow* listRow, PRUint16 pos, nsIMdbRow** cardRow);
00326 
00327     NS_IMETHOD AddListCardColumnsToRow(nsIAbCard *aPCard, nsIMdbRow *aPListRow, PRUint32 aPos, nsIAbCard** aPNewCard, PRBool aInMailingList);
00328     NS_IMETHOD InitCardFromRow(nsIAbCard *aNewCard, nsIMdbRow* aCardRow);
00329     NS_IMETHOD SetListAddressTotal(nsIMdbRow* aListRow, PRUint32 aTotal);
00330     NS_IMETHOD FindRowByCard(nsIAbCard * card,nsIMdbRow **aRow);
00331 
00332 protected:
00333   
00334   static void        AddToCache(nsAddrDatabase* pAddrDB) {GetDBCache()->AppendElement(pAddrDB);}
00335        static void          RemoveFromCache(nsAddrDatabase* pAddrDB);
00336        static PRInt32       FindInCache(nsAddrDatabase* pAddrDB);
00337        PRBool               MatchDbName(nsFileSpec *dbName);   // returns TRUE if they match
00338 
00339 #if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MAC)      // this should go away when we can provide our own file stream to MDB/Mork
00340        static void          UnixToNative(char*& ioPath);
00341 #endif
00342 
00343 
00344        void YarnToUInt32(struct mdbYarn *yarn, PRUint32 *pResult);
00345        void GetCharStringYarn(char* str, struct mdbYarn* strYarn);
00346        void GetStringYarn(const nsAString & aStr, struct mdbYarn* strYarn);
00347        void GetIntYarn(PRUint32 nValue, struct mdbYarn* intYarn);
00348        nsresult AddCharStringColumn(nsIMdbRow* cardRow, mdb_column inColumn, const char* str);
00349        nsresult AddStringColumn(nsIMdbRow* aCardRow, mdb_column aInColumn, const nsAString & aStr);
00350        nsresult AddIntColumn(nsIMdbRow* cardRow, mdb_column inColumn, PRUint32 nValue);
00351        nsresult AddBoolColumn(nsIMdbRow* cardRow, mdb_column inColumn, PRBool bValue);
00352        nsresult GetStringColumn(nsIMdbRow *cardRow, mdb_token outToken, nsString& str);
00353        nsresult GetIntColumn(nsIMdbRow *cardRow, mdb_token outToken, 
00354                                                  PRUint32* pValue, PRUint32 defaultValue);
00355        nsresult GetBoolColumn(nsIMdbRow *cardRow, mdb_token outToken, PRBool* pValue);
00356        nsresult GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* listRow);
00357        nsresult GetListFromDB(nsIAbDirectory *newCard, nsIMdbRow* listRow);
00358        nsresult AddRecordKeyColumnToRow(nsIMdbRow *pRow);
00359        nsresult AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *cardRow);
00360        nsresult AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIMdbRow *listRow);
00361        nsresult CreateCard(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result);
00362        nsresult CreateCardFromDeletedCardsTable(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result);
00363        nsresult DeleteCardFromListRow(nsIMdbRow* pListRow, mdb_id cardRowID);
00364        void DeleteCardFromAllMailLists(mdb_id cardRowID);
00365        nsresult NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir);
00366 
00367        nsresult AddLowercaseColumn(nsIMdbRow * row, mdb_token columnToken, const char* utf8String);
00368   nsresult GetRowFromAttribute(const char *aName, const char *aUTF8Value, PRBool aCaseInsensitive, nsIMdbRow    **aCardRow);
00369 
00370        static nsVoidArray/*<nsAddrDatabase>*/ * GetDBCache();
00371        static nsVoidArray/*<nsAddrDatabase>*/ * m_dbCache;
00372 
00373        // mdb bookkeeping stuff
00374   nsresult                  InitExistingDB();
00375   nsresult                  InitNewDB();
00376   nsresult                  InitMDBInfo();
00377   nsresult                  InitPabTable();
00378   nsresult      InitDeletedCardsTable(PRBool aCreate);
00379   nsresult                  AddRowToDeletedCardsTable(nsIAbCard *card, nsIMdbRow **pCardRow);
00380   nsresult                  DeleteRowFromDeletedCardsTable(nsIMdbRow *pCardRow);  
00381   nsresult                  InitLastRecorKey();
00382   nsresult                  GetDataRow(nsIMdbRow **pDataRow);
00383   nsresult                  GetLastRecordKey();
00384   nsresult                  UpdateLastRecordKey();
00385   nsresult                  CheckAndUpdateRecordKey();
00386   nsresult                  UpdateLowercaseEmailListName();
00387   nsresult                  ConvertAndAddLowercaseColumn(nsIMdbRow * row, mdb_token fromCol, mdb_token toCol);
00388   nsresult                  AddUnicodeToColumn(nsIMdbRow * row, mdb_token colToken, mdb_token lowerCaseColToken, const PRUnichar* pUnicodeStr);
00389   nsresult                  CreateCardsForMailList(nsIMdbRow *pListRow, nsIEnumerator **result);  
00390   nsresult                  DeleteRow(nsIMdbTable* dbTable, nsIMdbRow* dbRow);
00391 
00392   nsIMdbEnv   *m_mdbEnv;    // to be used in all the db calls.
00393   nsIMdbStore *m_mdbStore;
00394   nsIMdbTable *m_mdbPabTable;
00395   nsIMdbTable *m_mdbDeletedCardsTable;
00396   nsFileSpec             m_dbName;
00397   PRBool                           m_mdbTokensInitialized;
00398   nsVoidArray /*<nsIAddrDBListener>*/ *m_ChangeListeners;
00399 
00400   mdb_kind                  m_PabTableKind;
00401   mdb_kind                  m_MailListTableKind;
00402   mdb_kind                  m_DeletedCardsTableKind;
00403 
00404   mdb_scope                 m_CardRowScopeToken;
00405   mdb_scope                 m_ListRowScopeToken;
00406   mdb_scope                 m_DataRowScopeToken;
00407 
00408   mdb_token                 m_FirstNameColumnToken;
00409   mdb_token                 m_LastNameColumnToken;
00410   mdb_token                 m_PhoneticFirstNameColumnToken;
00411   mdb_token                 m_PhoneticLastNameColumnToken;
00412   mdb_token                 m_DisplayNameColumnToken;
00413   mdb_token                 m_NickNameColumnToken;
00414   mdb_token                 m_PriEmailColumnToken;
00415   mdb_token                 m_2ndEmailColumnToken;
00416   mdb_token                 m_DefaultEmailColumnToken;
00417   mdb_token                 m_CardTypeColumnToken;
00418   mdb_token                 m_WorkPhoneColumnToken;
00419   mdb_token                 m_HomePhoneColumnToken;
00420   mdb_token                 m_FaxColumnToken;
00421   mdb_token                 m_PagerColumnToken;
00422   mdb_token                 m_CellularColumnToken;
00423   mdb_token                 m_WorkPhoneTypeColumnToken;
00424   mdb_token                 m_HomePhoneTypeColumnToken;
00425   mdb_token                 m_FaxTypeColumnToken;
00426   mdb_token                 m_PagerTypeColumnToken;
00427   mdb_token                 m_CellularTypeColumnToken;
00428   mdb_token                 m_HomeAddressColumnToken;
00429   mdb_token                 m_HomeAddress2ColumnToken;
00430   mdb_token                 m_HomeCityColumnToken;
00431   mdb_token                 m_HomeStateColumnToken;
00432   mdb_token                 m_HomeZipCodeColumnToken;
00433   mdb_token                 m_HomeCountryColumnToken;
00434   mdb_token                 m_WorkAddressColumnToken;
00435   mdb_token                 m_WorkAddress2ColumnToken;
00436   mdb_token                 m_WorkCityColumnToken;
00437   mdb_token                 m_WorkStateColumnToken;
00438   mdb_token                 m_WorkZipCodeColumnToken;
00439   mdb_token                 m_WorkCountryColumnToken;
00440   mdb_token                 m_JobTitleColumnToken;
00441   mdb_token                 m_DepartmentColumnToken;
00442   mdb_token                 m_CompanyColumnToken;
00443   mdb_token                 m_AimScreenNameColumnToken;
00444   mdb_token                 m_AnniversaryYearColumnToken;
00445   mdb_token                 m_AnniversaryMonthColumnToken;
00446   mdb_token                 m_AnniversaryDayColumnToken;
00447   mdb_token                 m_SpouseNameColumnToken;
00448   mdb_token                 m_FamilyNameColumnToken;
00449   mdb_token                 m_DefaultAddressColumnToken;
00450   mdb_token                 m_CategoryColumnToken;
00451   mdb_token                 m_WebPage1ColumnToken;
00452   mdb_token                 m_WebPage2ColumnToken;
00453   mdb_token                 m_BirthYearColumnToken;
00454   mdb_token                 m_BirthMonthColumnToken;
00455   mdb_token                 m_BirthDayColumnToken;
00456   mdb_token                 m_Custom1ColumnToken;
00457   mdb_token                 m_Custom2ColumnToken;
00458   mdb_token                 m_Custom3ColumnToken;
00459   mdb_token                 m_Custom4ColumnToken;
00460   mdb_token                 m_NotesColumnToken;
00461   mdb_token                 m_LastModDateColumnToken;
00462   mdb_token                 m_RecordKeyColumnToken;
00463   mdb_token                 m_LowerPriEmailColumnToken;
00464 
00465   mdb_token                 m_MailFormatColumnToken;
00466   mdb_token     m_PopularityIndexColumnToken;
00467   mdb_token     m_AllowRemoteContentColumnToken;
00468                                           
00469   mdb_token                 m_AddressCharSetColumnToken;
00470   mdb_token                 m_LastRecordKeyColumnToken;
00471 
00472   mdb_token                 m_ListNameColumnToken;
00473   mdb_token                 m_ListNickNameColumnToken;
00474   mdb_token                 m_ListDescriptionColumnToken;
00475   mdb_token                 m_ListTotalColumnToken;
00476   mdb_token                 m_LowerListNameColumnToken;
00477 
00478   PRUint32                  m_LastRecordKey;
00479   nsIAbDirectory*           m_dbDirectory;
00480 
00481 private:
00482   nsresult GetRowForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, PRBool bIsCard, nsIMdbRow **findRow);
00483   PRBool HasRowButDeletedForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, PRBool aIsCard, nsIMdbRow **aFindRow);
00484   nsresult OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase **pCardDB);
00485   nsresult AlertAboutCorruptMabFile(const PRUnichar *aOldFileName, const PRUnichar *aNewFileName);
00486   nsresult AlertAboutLockedMabFile(const PRUnichar *aFileName);
00487   nsresult DisplayAlert(const PRUnichar *titleName, const PRUnichar *alertStringName, 
00488                         const PRUnichar **formatStrings, PRInt32 numFormatStrings);
00489 };
00490 
00491 #endif