diff --git a/mailnews/absync/src/nsAbSync.cpp b/mailnews/absync/src/nsAbSync.cpp index d716003990e9..11b577a47089 100644 --- a/mailnews/absync/src/nsAbSync.cpp +++ b/mailnews/absync/src/nsAbSync.cpp @@ -608,8 +608,7 @@ NS_IMETHODIMP nsAbSync::PerformAbSync(nsIDOMWindowInternal *aDOMWindow, PRInt32 // syncing with... // NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv); - if (NS_FAILED(rv) || !prefs) - return NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv, rv); prefs->CopyCharPref("mail.absync.address_book", &mAbSyncAddressBook); prefs->GetIntPref ("mail.absync.last_change", &mLastChangeNum); @@ -651,8 +650,7 @@ NS_IMETHODIMP nsAbSync::PerformAbSync(nsIDOMWindowInternal *aDOMWindow, PRInt32 if (!mPostEngine) { rv = nsComponentManager::CreateInstance(kCAbSyncPostEngineCID, NULL, NS_GET_IID(nsIAbSyncPostEngine), getter_AddRefs(mPostEngine)); - if ( NS_FAILED(rv) || (!mPostEngine) ) - return NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv, rv); mPostEngine->AddPostListener((nsIAbSyncPostListener *)this); } @@ -750,7 +748,11 @@ nsAbSync::GenerateProtocolForCard(nsIAbCard *aCard, PRBool aAddId, nsString &pro if (aAddId) { PRUint32 aKey; - if (NS_FAILED(aCard->GetKey(&aKey))) + nsresult rv = NS_OK; + + nsCOMPtr dbcard(do_QueryInterface(aCard, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(dbcard->GetKey(&aKey))) return NS_ERROR_FAILURE; #ifdef DEBUG_rhp @@ -1024,7 +1026,10 @@ nsAbSync::ThisCardHasChanged(nsIAbCard *aCard, syncMappingRecord *newSyncRecord, { newSyncRecord->flags |= SYNC_ADD; - if (NS_FAILED(aCard->GetKey(&aKey))) + nsresult rv = NS_OK; + nsCOMPtr dbcard(do_QueryInterface(aCard, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(dbcard->GetKey(&aKey))) return PR_FALSE; // Ugh...this should never happen...BUT?? @@ -1136,9 +1141,9 @@ nsAbSync::AnalyzeAllRecords(nsIAddrDatabase *aDatabase, nsIAbDirectory *director nsCOMPtr lockFile; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(historyFile)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = historyFile->Append("absync.dat"); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // TODO: Convert the rest of the code to use // nsIFile and avoid this conversion hack. @@ -1252,7 +1257,11 @@ nsAbSync::AnalyzeAllRecords(nsIAddrDatabase *aDatabase, nsIAbDirectory *director // be the ID from the local database for this card entry // PRUint32 aKey; - if (NS_FAILED(card->GetKey(&aKey))) + nsresult rv = NS_OK; + nsCOMPtr dbcard(do_QueryInterface(card, &rv)); + if (NS_FAILED(rv) || !dbcard) + continue; + if (NS_FAILED(dbcard->GetKey(&aKey))) continue; // Ugh...this should never happen...BUT?? @@ -1382,7 +1391,11 @@ nsAbSync::AnalyzeAllRecords(nsIAddrDatabase *aDatabase, nsIAbDirectory *director // be the ID from the local database for this card entry // PRUint32 aKey; - if (NS_FAILED(card->GetKey(&aKey))) + nsresult rv = NS_OK; + nsCOMPtr dbcard(do_QueryInterface(card, &rv)); + if (NS_FAILED(rv) || !dbcard) + continue; + if (NS_FAILED(dbcard->GetKey(&aKey))) continue; // Ugh...this should never happen...BUT?? @@ -1533,7 +1546,8 @@ nsAbSync::AnalyzeTheLocalAddressBook() // this should not be hardcoded to abook.mab // this works for any address book...not sure why - rv = rdfService->GetResource("abdirectory://abook.mab", getter_AddRefs(resource)); + // absync on go againt abook.mab - candice + rv = rdfService->GetResource("abmdbdirectory://abook.mab", getter_AddRefs(resource)); if (NS_FAILED(rv)) goto EarlyExit; @@ -1791,7 +1805,8 @@ nsAbSync::DeleteCardByServerID(PRInt32 aServerID) // this should not be hardcoded to abook.mab // this works for any address book...not sure why - rv = rdfService->GetResource("abdirectory://abook.mab", getter_AddRefs(resource)); + // absync on go againt abook.mab - candice + rv = rdfService->GetResource("abmdbdirectory://abook.mab", getter_AddRefs(resource)); if (NS_FAILED(rv)) goto EarlyExit; @@ -1820,7 +1835,11 @@ nsAbSync::DeleteCardByServerID(PRInt32 aServerID) nsCOMPtr card; card = do_QueryInterface(obj, &rv); - if (NS_FAILED(card->GetKey(&aKey))) + nsresult rv = NS_OK; + nsCOMPtr dbcard(do_QueryInterface(card, &rv)); + if (NS_FAILED(rv) || !dbcard) + continue; + if (NS_FAILED(dbcard->GetKey(&aKey))) continue; if ((PRInt32) aKey == clientID) @@ -2392,7 +2411,11 @@ nsAbSync::FindCardByClientID(PRInt32 aClientID, nsCOMPtr card; card = do_QueryInterface(obj, &rv); - if (NS_FAILED(card->GetKey(&aKey))) + nsresult rv=NS_OK; + nsCOMPtr dbcard(do_QueryInterface(card, &rv)); + if (NS_FAILED(rv) || !dbcard) + continue; + if (NS_FAILED(dbcard->GetKey(&aKey))) continue; // Found IT! @@ -2543,7 +2566,8 @@ nsAbSync::AddNewUsers() // this should not be hardcoded to abook.mab // this works for any address book...not sure why - rv = rdfService->GetResource("abdirectory://abook.mab", getter_AddRefs(resource)); + // absync on go againt abook.mab - candice + rv = rdfService->GetResource("abmdbdirectory://abook.mab", getter_AddRefs(resource)); if (NS_FAILED(rv)) goto EarlyExit; diff --git a/mailnews/absync/src/nsAbSync.h b/mailnews/absync/src/nsAbSync.h index 013902fafa73..9a82f8cb0788 100644 --- a/mailnews/absync/src/nsAbSync.h +++ b/mailnews/absync/src/nsAbSync.h @@ -29,6 +29,7 @@ #include "nsCOMPtr.h" #include "nsIAddrDatabase.h" #include "nsIAbDirectory.h" +#include "nsIAbMDBCard.h" #include "nsAbSyncCRCModel.h" #include "nsVoidArray.h" #include "nsIStringBundle.h" diff --git a/mailnews/addrbook/build/nsAbBaseCID.h b/mailnews/addrbook/build/nsAbBaseCID.h index f37cf3be8687..7feecb7392c9 100644 --- a/mailnews/addrbook/build/nsAbBaseCID.h +++ b/mailnews/addrbook/build/nsAbBaseCID.h @@ -42,54 +42,72 @@ { 0x9e, 0x7, 0x0, 0xa0, 0xc9, 0x2b, 0x5f, 0xd } \ } + + // // nsAbDirectoryDataSource // #define NS_ABDIRECTORYDATASOURCE_CONTRACTID \ NS_RDF_DATASOURCE_CONTRACTID_PREFIX "addressdirectory" -#define NS_ABDIRECTORYDATASOURCE_CID \ +#define NS_ABDIRECTORYDATASOURCE_CID \ { /* 0A79186D-F754-11d2-A2DA-001083003D0C */ \ - 0xa79186d, 0xf754, 0x11d2, \ + 0xa79186d, 0xf754, 0x11d2, \ {0xa2, 0xda, 0x0, 0x10, 0x83, 0x0, 0x3d, 0xc} \ } -// -// nsAbDirectory -// -#define NS_ABDIRECTORY_CONTRACTID \ - NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "abdirectory" - -#define NS_ABDIRECTORY_CID \ -{ /* {6C21831D-FCC2-11d2-A2E2-001083003D0C}*/ \ - 0x6c21831d, 0xfcc2, 0x11d2, \ - {0xa2, 0xe2, 0x0, 0x10, 0x83, 0x0, 0x3d, 0xc} \ -} - // // nsAbCardDataSource // #define NS_ABCARDDATASOURCE_CONTRACTID \ NS_RDF_DATASOURCE_CONTRACTID_PREFIX "addresscard" -#define NS_ABCARDDATASOURCE_CID \ +#define NS_ABCARDDATASOURCE_CID \ { /* 1920E486-0709-11d3-A2EC-001083003D0C */ \ - 0x1920e486, 0x709, 0x11d3, \ + 0x1920e486, 0x709, 0x11d3, \ {0xa2, 0xec, 0x0, 0x10, 0x83, 0x0, 0x3d, 0xc} \ } -// -// nsAbCard -// -#define NS_ABCARD_CONTRACTID \ - NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "abcard" -#define NS_ABCARD_CID \ -{ /* {1920E487-0709-11d3-A2EC-001083003D0C}*/ \ - 0x1920e487, 0x709, 0x11d3, \ - {0xa2, 0xec, 0x0, 0x10, 0x83, 0x0, 0x3d, 0xc} \ +// +// nsAbBSDirectory +// +#define NS_ABDIRECTORY_CONTRACTID \ + NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "abdirectory" + +#define NS_ABDIRECTORY_CID \ +{ /* {012D3C24-1DD2-11B2-BA79-B4AD359FC461}*/ \ + 0x012D3C24, 0x1DD2, 0x11B2, \ + {0xBA, 0x79, 0xB4, 0xAD, 0x35, 0x9F, 0xC4, 0x61} \ } + +// +// nsAbMDBDirectory +// +#define NS_ABMDBDIRECTORY_CONTRACTID \ + NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "abmdbdirectory" + +#define NS_ABMDBDIRECTORY_CID \ +{ /* {e618f894-1dd1-11b2-889c-9aaefaa90dde}*/ \ + 0xe618f894, 0x1dd1, 0x11b2, \ + {0x88, 0x9c, 0x9a, 0xae, 0xfa, 0xa9, 0x0d, 0xde} \ +} + +// +// nsAbMDBCard +// +#define NS_ABMDBCARD_CONTRACTID \ + NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "abmdbcard" + +#define NS_ABMDBCARD_CID \ +{ /* {f578a5d2-1dd1-11b2-8841-f45cc5e765f8} */ \ + 0xf578a5d2, 0x1dd1, 0x11b2, \ + {0x88, 0x41, 0xf4, 0x5c, 0xc5, 0xe7, 0x65, 0xf8} \ +} + + + // // nsAddressBookDB // diff --git a/mailnews/addrbook/build/nsAbFactory.cpp b/mailnews/addrbook/build/nsAbFactory.cpp index e8b6a945fde8..63801c1c8159 100644 --- a/mailnews/addrbook/build/nsAbFactory.cpp +++ b/mailnews/addrbook/build/nsAbFactory.cpp @@ -38,8 +38,12 @@ #include "nsDirectoryDataSource.h" #include "nsCardDataSource.h" -#include "nsAbDirectory.h" -#include "nsAbCard.h" + +#include "nsAbBSDirectory.h" + +#include "nsAbMDBDirectory.h" +#include "nsAbMDBCard.h" + #include "nsAddrDatabase.h" #include "nsAddressBook.h" #include "nsAddrBookSession.h" @@ -50,13 +54,19 @@ #include "nsAddbookUrl.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddressBook) + NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbDirectoryDataSource,Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectory) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbCardDataSource,Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbCard) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbCardProperty) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddrDatabase) + NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirProperty) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbCardProperty) + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbBSDirectory) + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbMDBDirectory) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbMDBCard) + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddrDatabase) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddrBookSession) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbAutoCompleteSession) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbAddressCollecter) @@ -70,36 +80,54 @@ static nsModuleComponentInfo components[] = NS_ADDRESSBOOK_CID, NS_ADDRESSBOOK_CONTRACTID, nsAddressBookConstructor }, + { "Address Book Startup Handler", NS_ADDRESSBOOK_CID, NS_ADDRESSBOOKSTARTUPHANDLER_CONTRACTID, nsAddressBookConstructor, nsAddressBook::RegisterProc, nsAddressBook::UnregisterProc }, + { "Address Book Directory Datasource", NS_ABDIRECTORYDATASOURCE_CID, NS_ABDIRECTORYDATASOURCE_CONTRACTID, nsAbDirectoryDataSourceConstructor }, - { "Address Book Directory", - NS_ABDIRECTORY_CID, - NS_ABDIRECTORY_CONTRACTID, - nsAbDirectoryConstructor }, + { "Address Book Card Datasource", NS_ABCARDDATASOURCE_CID, NS_ABCARDDATASOURCE_CONTRACTID, nsAbCardDataSourceConstructor }, - { "Address Book Card", - NS_ABCARD_CID, - NS_ABCARD_CONTRACTID, - nsAbCardConstructor }, + + + + { "Address Boot Strap Directory", + NS_ABDIRECTORY_CID, + NS_ABDIRECTORY_CONTRACTID, + nsAbBSDirectoryConstructor }, + + + + { "Address MDB Book Directory", + NS_ABMDBDIRECTORY_CID, + NS_ABMDBDIRECTORY_CONTRACTID, + nsAbMDBDirectoryConstructor }, + + { "Address MDB Book Card", + NS_ABMDBCARD_CID, + NS_ABMDBCARD_CONTRACTID, + nsAbMDBCardConstructor }, + + { "Address Database", NS_ADDRDATABASE_CID, NS_ADDRDATABASE_CONTRACTID, nsAddrDatabaseConstructor }, + { "Address Book Card Property", NS_ABCARDPROPERTY_CID, NS_ABCARDPROPERTY_CONTRACTID, nsAbCardPropertyConstructor }, + { "Address Book Directory Property", NS_ABDIRPROPERTY_CID, NS_ABDIRPROPERTY_CONTRACTID, diff --git a/mailnews/addrbook/public/Makefile.in b/mailnews/addrbook/public/Makefile.in index d34f37326ea2..d58e5158e0b1 100644 --- a/mailnews/addrbook/public/Makefile.in +++ b/mailnews/addrbook/public/Makefile.in @@ -32,6 +32,8 @@ XPIDLSRCS = \ nsIAbListener.idl \ nsIAbDirectory.idl \ nsIAbCard.idl \ + nsIAbMDBDirectory.idl \ + nsIAbMDBCard.idl \ nsIAddrDBAnnouncer.idl \ nsIAddrDBListener.idl \ nsIAddrDatabase.idl \ diff --git a/mailnews/addrbook/public/makefile.win b/mailnews/addrbook/public/makefile.win index 079610b2a05e..9b810ac129b5 100644 --- a/mailnews/addrbook/public/makefile.win +++ b/mailnews/addrbook/public/makefile.win @@ -26,7 +26,9 @@ XPIDLSRCS = \ .\nsIAbListener.idl \ .\nsIAbBase.idl \ .\nsIAbDirectory.idl \ + .\nsIAbMDBDirectory.idl \ .\nsIAbCard.idl \ + .\nsIAbMDBCard.idl \ .\nsIAddrDBAnnouncer.idl \ .\nsIAddrDBListener.idl \ .\nsIAddrDatabase.idl \ diff --git a/mailnews/addrbook/public/nsIAbCard.idl b/mailnews/addrbook/public/nsIAbCard.idl index efd9e11b52e2..e5a21abf688f 100644 --- a/mailnews/addrbook/public/nsIAbCard.idl +++ b/mailnews/addrbook/public/nsIAbCard.idl @@ -40,6 +40,7 @@ interface nsIAbPreferMailFormat { [scriptable, uuid(FA5C977F-04C8-11d3-A2EB-001083003D0C)] interface nsIAbCard : nsISupports { + // Card properties attribute wstring firstName; attribute wstring lastName; attribute wstring displayName; @@ -78,37 +79,52 @@ interface nsIAbCard : nsISupports { attribute wstring notes; attribute unsigned long lastModifiedDate; attribute wstring name; - readonly attribute string printCardUrl; - readonly attribute unsigned long key; attribute unsigned long preferMailFormat; attribute boolean isMailList; - - attribute unsigned long dbTableID; - attribute unsigned long dbRowID; + // If isMailList==true then this string + // will contain the URI of the associated + // mail list + attribute string mailListURI; wstring getCardValue(in string attrname); void setCardValue(in string attrname, in wstring value); - void setAbDatabase(in nsIAddrDatabase database); - [noscript] readonly attribute nsVoidArray anonymousStrAttrubutesList; - [noscript] readonly attribute nsVoidArray anonymousStrValuesList; - [noscript] readonly attribute nsVoidArray anonymousIntAttrubutesList; - [noscript] readonly attribute nsVoidArray anonymousIntValuesList; - [noscript] readonly attribute nsVoidArray anonymousBoolAttrubutesList; - [noscript] readonly attribute nsVoidArray anonymousBoolValuesList; + // Copies the card attributes from srcCard + void copy(in nsIAbCard srcCard); + + readonly attribute string printCardUrl; - void setAnonymousStringAttribute(in string attrname, in string value); - void setAnonymousIntAttribute(in string attrname, in unsigned long value); - void setAnonymousBoolAttribute(in string attrname, in boolean value); - void addAnonymousAttributesToDB(); - void editAnonymousAttributesInDB(); + // Adds a new card to the directory defined by 'uri' + // Rename to addCardToDirectory + // + // Returns an intstance of a card which + // is an RDF resource component + nsIAbCard addCardToDatabase(in string uri); - readonly attribute string cardURI; - void addCardToDatabase(in string uri); - void editCardToDatabase(in string uri); - void copyCard(in nsIAbCard srcCard); + // Behaviour wise this is very similar to the + // addCardToDatabase method, except that it + // assumes the uri refers to a directory that + // is not a mail list + // This method is rendundent, droping a card + // onto a list should be allowed. + // Rename to dropCardToDirectory + // + // Returns an intstance of a card which + // is an RDF resource component + nsIAbCard dropCardToDatabase(in string uri); + + // Edits an existing card in the directory defined by 'uri' + // Rename to editCardInDirectory + // Component will be an RDF card, since it has already + // been created + // + void editCardToDatabase(in string uri); + + // Not sure what this does. Used by the + // card data source for values of collation + // properties, somthing to do with locales + // and sorting. Gets called when selecting + // table headers like Name and Email. wstring getCollationKey(in wstring str); - void setRecordKey(in unsigned long key); - void dropCardToDatabase(in string uri); }; diff --git a/mailnews/addrbook/public/nsIAbDirectory.idl b/mailnews/addrbook/public/nsIAbDirectory.idl index 41de20c9cdb3..365a3e400ced 100644 --- a/mailnews/addrbook/public/nsIAbDirectory.idl +++ b/mailnews/addrbook/public/nsIAbDirectory.idl @@ -32,42 +32,97 @@ #include "nsDirPrefs.h" %} -[scriptable, uuid(1920E485-0709-11d3-A2EC-001083003D0C)] +[scriptable, uuid(AA920C90-1DD1-11B2-96D3-AA81268ADAFC)] interface nsIAbDirectory : nsISupports { + // The name of the directory attribute wstring dirName; attribute unsigned long lastModifiedDate; - [noscript] attribute DIR_Server server; - readonly attribute string dirFilePath; + // Defines wether this directory is a mail + // list or not + attribute PRBool isMailList; + + + // Get the children directories readonly attribute nsIEnumerator childNodes; - readonly attribute nsIEnumerator childCards; - nsIAbCard addChildCards(in string uriName); - nsIAbDirectory addDirectory(in string uriName); - void deleteDirectory(in nsIAbDirectory dierctory); - void deleteCards(in nsISupportsArray cards); - boolean hasCard(in nsIAbCard cards); - boolean hasDirectory(in nsIAbDirectory dir); - void createNewDirectory(in wstring dirName, in string fileName, in boolean migrating); - void createNewMailingList(in string uri, in nsIAbDirectory list); - string getDirUri(); - void addMailListToDirectory(in nsIAbDirectory mailList); - void copyMailList(in nsIAbDirectory srcList); + // Get the cards associated with the directory + // This will return the cards associated with + // the mailing lists too + readonly attribute nsIEnumerator childCards; + + + // Deletes either a mailing list or a top + // level directory, which also updates the + // preferences + void deleteDirectory(in nsIAbDirectory dierctory); + + // Delete the + void deleteCards(in nsISupportsArray cards); + + + // Check if directory contains card + boolean hasCard(in nsIAbCard cards); + + // Check if directory contains directory + boolean hasDirectory(in nsIAbDirectory dir); + + // Creates a new card in the directory + // with the properties defined by card + nsIAbCard addCard(in nsIAbCard card); + nsIAbCard dropCard(in nsIAbCard card); + + + // Mail list specific + // + + // This attribute servers two purposes + // depending if the directory is a mail list. + // If not mail list directories are stored here + // If so mail list card entries are stored here + attribute nsISupportsArray addressLists; + + // Specific to a directory which stores mail lists + // + + // Creates a new mailing list in the directory + // with the properties defined by list + void addMailList (in nsIAbDirectory list); + + // Specific to a directory which is a mail list + // + + // listName is not needed, dirName could be used + // instead attribute wstring listName; attribute wstring listNickName; attribute wstring description; - attribute unsigned long dbRowID; - attribute PRBool isMailList; - attribute nsISupportsArray addressLists; - void addAddressToList(in nsIAbCard card); + // Adds a new mail list into the directory + // defined by the uri void addMailListToDatabase(in string uri); - void editMailListToDatabase(in string uri); - void removeEmailAddressAt(in unsigned long aIndex); - [noscript] void clearDatabase(); - [noscript] void notifyDirItemAdded(in nsISupports item); - [noscript] void removeElementsFromAddressList(); - + // Edits an existing mail in the directory + // defined by the uri + void editMailListToDatabase(in string uri); + + // Copies mail list properties from the srcList + void copyMailList(in nsIAbDirectory srcList); + + /* + Only creates a top level address book + which is stored in the preferences + + Need to change to factory based approach + to create new address books + + This method should become redundant or + be only associated with card folders + */ + void createNewDirectory(in unsigned long prefCount,[array, size_is(prefCount)] in string prefName, [array, size_is(prefCount)] in wstring prefValue); + + /* create a directory by passing the display name and address book uri */ + void CreateDirectoryByURI(in wstring displayName, in string uri, in boolean migrating); + }; diff --git a/mailnews/addrbook/public/nsIAddressBook.idl b/mailnews/addrbook/public/nsIAddressBook.idl index 09917303c825..d53192a52bbe 100644 --- a/mailnews/addrbook/public/nsIAddressBook.idl +++ b/mailnews/addrbook/public/nsIAddressBook.idl @@ -38,16 +38,16 @@ interface nsIFileSpec; [scriptable, uuid(D60B84F1-2A8C-11d3-9E07-00A0C92B5F0D)] interface nsIAddressBook : nsISupports { - void deleteCards(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node); - void newAddressBook(in nsIRDFCompositeDataSource db, in nsIDOMXULElement srcDir, in wstring name); - void deleteAddressBooks(in nsIRDFCompositeDataSource db, in nsISupportsArray parentDir, in nsIDOMNodeList node); - void printCard(); - void printAddressbook(); - void setDocShellWindow(in nsIDOMWindowInternal win); + void deleteCards(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node); + void newAddressBook(in nsIRDFCompositeDataSource db, in nsIDOMXULElement srcDir, in unsigned long prefCount,[array, size_is(prefCount)] in string prefName, [array, size_is(prefCount)] in wstring prefValue); + void deleteAddressBooks(in nsIRDFCompositeDataSource db, in nsISupportsArray parentDir, in nsIDOMNodeList node); + void printCard(); + void printAddressbook(); + void setDocShellWindow(in nsIDOMWindowInternal win); void importAddressBook(); - void convertLDIFtoMAB(in nsIFileSpec fileSpec, in boolean migrating); - void convertNA2toLDIF(in nsIFileSpec srcFileSpec, in nsIFileSpec dstFileSpec); - void getAbDatabaseFromURI(in string URI, out nsIAddrDatabase db); + void convertLDIFtoMAB(in nsIFileSpec fileSpec, in boolean migrating); + void convertNA2toLDIF(in nsIFileSpec srcFileSpec, in nsIFileSpec dstFileSpec); + void getAbDatabaseFromURI(in string URI, out nsIAddrDatabase db); boolean mailListNameExistsInDB(in wstring name, in string URI); boolean mailListNameExists(in wstring name); }; diff --git a/mailnews/addrbook/resources/content/abCardOverlay.js b/mailnews/addrbook/resources/content/abCardOverlay.js index b1b12e2dd40a..4ae7ffd6e407 100644 --- a/mailnews/addrbook/resources/content/abCardOverlay.js +++ b/mailnews/addrbook/resources/content/abCardOverlay.js @@ -43,7 +43,7 @@ function OnLoadNewCard() if ("selectedAB" in window.arguments[0]) editCard.selectedAB = window.arguments[0].selectedAB; else - editCard.selectedAB = "abdirectory://abook.mab"; + editCard.selectedAB = "abmdbdirectory://abook.mab"; // we may have been given properties to pre-initialize the window with.... // we'll fill these in here... @@ -108,6 +108,8 @@ function OnLoadEditCard() editCard.okCallback = window.arguments[0].okCallback; if ( window.arguments[0].abURI ) editCard.abURI = window.arguments[0].abURI; + if ( window.arguments[0].abCardURI ) + editCard.abCardURI = window.arguments[0].abCardURI; } // set global state variables diff --git a/mailnews/addrbook/resources/content/abCommon.js b/mailnews/addrbook/resources/content/abCommon.js index fefb18b4f2d2..ddf6d41790a8 100644 --- a/mailnews/addrbook/resources/content/abCommon.js +++ b/mailnews/addrbook/resources/content/abCommon.js @@ -164,13 +164,12 @@ function AbEditCard() var card = rdf.GetResource(uri); card = card.QueryInterface(Components.interfaces.nsIAbCard); if (card.isMailList) { - var dirUri = dirTree.selectedItems[0].getAttribute("id"); - var listUri = dirUri + "/MailList" + card.dbRowID; + listUri = card.mailListURI; goEditListDialog(resultsTree.getAttribute("ref"), listUri); } else { var updateFunc = ("gUpdateCardView" in top) ? top.gUpdateCardView : null; - goEditCardDialog(resultsTree.getAttribute("ref"), card, updateFunc); + goEditCardDialog(resultsTree.getAttribute("ref"), card, updateFunc, uri); } } } diff --git a/mailnews/addrbook/resources/content/abMailListDialog.js b/mailnews/addrbook/resources/content/abMailListDialog.js index 15091fddb19d..0ae65945c37b 100644 --- a/mailnews/addrbook/resources/content/abMailListDialog.js +++ b/mailnews/addrbook/resources/content/abMailListDialog.js @@ -95,7 +95,16 @@ function GetListValue(mailList, doAdd) if (fieldValue == "") { if (doAdd == false && cardproperty) - mailList.removeEmailAddressAt(pos); + try + { + mailList.addressLists.DeleteElementAt(pos); + } + catch(ex) + { + // Ignore attempting to remove an item + // at a position greater than the number + // of elements in the addressLists attribute + } } else if (cardproperty) { @@ -122,7 +131,7 @@ function GetListValue(mailList, doAdd) if (doAdd == false && i < oldTotal) { for (var j = i; j < oldTotal; j++) - mailList.addressLists.RemoveElementAt(j); + mailList.addressLists.DeleteElementAt(j); } return true; } @@ -169,7 +178,7 @@ function OnLoadMailList() if ( window.arguments[0].selectedAB ) selectedAB = window.arguments[0].selectedAB; else - selectedAB = "abdirectory://abook.mab"; + selectedAB = "abmdbdirectory://abook.mab"; } // set popup with address book names @@ -240,7 +249,6 @@ function OnLoadEditList() if (editList.addressLists) { var total = editList.addressLists.Count(); -dump("*** editList.Count = "+total+"\n"); if (total) { var treeChildren = document.getElementById('addressList'); @@ -303,7 +311,6 @@ function SetInputValue(inputValue, parentNode, templateNode) function awNotAnEmptyArea(event) { //This is temporary until i figure out how to ensure to always having an empty space after the last row - dump("awNotAnEmptyArea\n"); var lastInput = awGetInputElement(top.MAX_RECIPIENTS); if ( lastInput && lastInput.value ) @@ -314,10 +321,9 @@ function awNotAnEmptyArea(event) function awClickEmptySpace(targ, setFocus) { - if ("localName" in targ && targ.localName != 'treechildren') + if (targ.localName != 'treechildren') return; - dump("awClickEmptySpace\n"); var lastInput = awGetInputElement(top.MAX_RECIPIENTS); if ( lastInput && lastInput.value ) @@ -329,7 +335,6 @@ function awClickEmptySpace(targ, setFocus) function awReturnHit(inputElement) { - dump("***** awReturnHit\n"); var row = awGetRowByInputElement(inputElement); if ( inputElement.value ) @@ -344,7 +349,6 @@ function awReturnHit(inputElement) function awInputChanged(inputElement) { - dump("awInputChanged\n"); // AutoCompleteAddress(inputElement); //Do we need to add a new row? diff --git a/mailnews/addrbook/resources/content/addressbook.js b/mailnews/addrbook/resources/content/addressbook.js index b7824cc2b307..8a4eae1d012b 100644 --- a/mailnews/addrbook/resources/content/addressbook.js +++ b/mailnews/addrbook/resources/content/addressbook.js @@ -5,7 +5,7 @@ var gAddressBookBundle; function OnLoadAddressBook() { - gAddressBookBundle = document.getElementById("bundle_addressBook"); + gAddressBookBundle = document.getElementById("bundle_addressBook"); verifyAccounts(); // this will do migration, if we need to. top.addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(); @@ -161,7 +161,11 @@ function AbNewAddressBook() function AbCreateNewAddressBook(name) { - top.addressbook.newAddressBook(dirTree.database, resultsTree, name); + var prefsAttr = new Array; + var prefsValue = new Array; + prefsAttr[0] = "description"; + prefsValue[0] = name; + top.addressbook.newAddressBook(dirTree.database, resultsTree, 1, prefsAttr, prefsValue); } function AbPrintCard() @@ -267,8 +271,8 @@ function AbDeleteDirectory() // check to see if personal or collected address books is selected for deletion. // if yes, prompt the user an appropriate message saying these cannot be deleted // if no, mark the selected items for deletion - if ((selArray[i].getAttribute("id") != "abdirectory://history.mab") && - (selArray[i].getAttribute("id") != "abdirectory://abook.mab")) + if ((selArray[i].getAttribute("id") != "abmdbdirectory://history.mab") && + (selArray[i].getAttribute("id") != "abmdbdirectory://abook.mab")) { var parent = selArray[i].parentNode.parentNode; if (parent) @@ -317,4 +321,3 @@ function clickResultsTree(event) if ( event.detail == 2 ) top.AbEditCard(); } - diff --git a/mailnews/addrbook/src/Makefile.in b/mailnews/addrbook/src/Makefile.in index 8eb2ff9e8dc0..5712656adf44 100644 --- a/mailnews/addrbook/src/Makefile.in +++ b/mailnews/addrbook/src/Makefile.in @@ -34,11 +34,9 @@ CPPSRCS = \ nsAddressBook.cpp \ nsAddrBookSession.cpp \ nsAbRDFDataSource.cpp \ - nsAbRDFResource.cpp \ + nsAbMDBRDFResource.cpp \ nsCardDataSource.cpp \ nsDirectoryDataSource.cpp \ - nsAbCard.cpp \ - nsAbDirectory.cpp \ nsAbCardProperty.cpp \ nsDirPrefs.cpp \ nsAddrDatabase.cpp \ @@ -46,6 +44,11 @@ CPPSRCS = \ nsAbAutoCompleteSession.cpp \ nsAbAddressCollecter.cpp \ nsAddbookProtocolHandler.cpp \ + nsAbMDBDirProperty.cpp \ + nsAbMDBDirectory.cpp \ + nsAbMDBCardProperty.cpp \ + nsAbMDBCard.cpp \ + nsAbBSDirectory.cpp \ nsAddbookUrl.cpp \ $(NULL) @@ -53,11 +56,9 @@ EXPORTS = \ nsAddressBook.h \ nsAddrBookSession.h \ nsAbRDFDataSource.h \ - nsAbRDFResource.h \ + nsAbMDBRDFResource.h \ nsCardDataSource.h \ nsDirectoryDataSource.h \ - nsAbCard.h \ - nsAbDirectory.h \ nsAbCardProperty.h \ nsDirPrefs.h \ nsAddrDatabase.h \ @@ -66,6 +67,11 @@ EXPORTS = \ nsAbAddressCollecter.h \ nsAddbookProtocolHandler.h \ nsAddbookUrl.h \ + nsAbMDBDirProperty.h \ + nsAbMDBDirectory.h \ + nsAbMDBCardProperty.h \ + nsAbMDBCard.h \ + nsAbBSDirectory.h \ $(NULL) # we don't want the shared lib, but we want to force the creation of a static lib. diff --git a/mailnews/addrbook/src/makefile.win b/mailnews/addrbook/src/makefile.win index ac1daeab0eaa..39552623a47f 100644 --- a/mailnews/addrbook/src/makefile.win +++ b/mailnews/addrbook/src/makefile.win @@ -31,11 +31,9 @@ EXPORTS= \ nsAddressBook.h \ nsAddrBookSession.h \ nsAbRDFDataSource.h \ - nsAbRDFResource.h \ + nsAbMDBRDFResource.h \ nsCardDataSource.h \ nsDirectoryDataSource.h \ - nsAbCard.h \ - nsAbDirectory.h \ nsAbCardProperty.h \ nsDirPrefs.h \ nsAddrDatabase.h \ @@ -43,6 +41,11 @@ EXPORTS= \ nsAbAutoCompleteSession.h \ nsAbAddressCollecter.h \ nsAddbookProtocolHandler.h \ + nsAbMDBDirProperty.h \ + nsAbMDBDirectory.h \ + nsAbMDBCardProperty.h \ + nsAbMDBCard.h \ + nsAbBSDirectory.h \ nsAddbookUrl.h \ $(NULL) @@ -55,11 +58,9 @@ CPP_OBJS= \ .\$(OBJDIR)\nsAddressBook.obj \ .\$(OBJDIR)\nsAddrBookSession.obj \ .\$(OBJDIR)\nsAbRDFDataSource.obj \ - .\$(OBJDIR)\nsAbRDFResource.obj \ + .\$(OBJDIR)\nsAbMDBRDFResource.obj \ .\$(OBJDIR)\nsCardDataSource.obj \ .\$(OBJDIR)\nsDirectoryDataSource.obj \ - .\$(OBJDIR)\nsAbCard.obj \ - .\$(OBJDIR)\nsAbDirectory.obj \ .\$(OBJDIR)\nsAbCardProperty.obj \ .\$(OBJDIR)\nsDirPrefs.obj \ .\$(OBJDIR)\nsAddrDatabase.obj \ @@ -67,6 +68,11 @@ CPP_OBJS= \ .\$(OBJDIR)\nsAbAutoCompleteSession.obj \ .\$(OBJDIR)\nsAbAddressCollecter.obj \ .\$(OBJDIR)\nsAddbookProtocolHandler.obj \ + .\$(OBJDIR)\nsAbMDBDirProperty.obj \ + .\$(OBJDIR)\nsAbMDBDirectory.obj \ + .\$(OBJDIR)\nsAbMDBCardProperty.obj \ + .\$(OBJDIR)\nsAbMDBCard.obj \ + .\$(OBJDIR)\nsAbBSDirectory.obj \ .\$(OBJDIR)\nsAddbookUrl.obj \ $(NULL) diff --git a/mailnews/addrbook/src/nsABSyncDriver.cpp b/mailnews/addrbook/src/nsABSyncDriver.cpp index 724deeb22547..5da3db8df4a1 100644 --- a/mailnews/addrbook/src/nsABSyncDriver.cpp +++ b/mailnews/addrbook/src/nsABSyncDriver.cpp @@ -70,8 +70,7 @@ NS_IMETHODIMP nsAbSyncDriver::KickIt() { nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAbSync, sync, kAbSync, &rv); - if (NS_FAILED(rv) || !sync) - return rv; + NS_ENSURE_SUCCESS(rv, rv); // Add ourselves to the party! sync->AddSyncListener((nsIAbSyncListener *)this); diff --git a/mailnews/addrbook/src/nsAbAddressCollecter.cpp b/mailnews/addrbook/src/nsAbAddressCollecter.cpp index 62862ebc796c..4b6a1cb98259 100644 --- a/mailnews/addrbook/src/nsAbAddressCollecter.cpp +++ b/mailnews/addrbook/src/nsAbAddressCollecter.cpp @@ -96,8 +96,7 @@ NS_IMETHODIMP nsAbAddressCollecter::CollectAddress(const char *address) return NS_OK; NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv); - if (NS_FAILED(rv) || !pPref) - return NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv, rv); if(sizeLimitEnabled == -1){ rv = pPref->GetBoolPref(PREF_COLLECT_EMAIL_ADDRESS_ENABLE_SIZE_LIMIT, &sizeLimitEnabled); @@ -146,6 +145,7 @@ NS_IMETHODIMP nsAbAddressCollecter::CollectAddress(const char *address) if (NS_SUCCEEDED(rv) && !exclude) { nsCOMPtr existingCard; + nsCOMPtr cardInstance; rv = m_historyAB->GetCardForEmailAddress(m_historyDirectory, curAddress, getter_AddRefs(existingCard)); @@ -171,7 +171,7 @@ NS_IMETHODIMP nsAbAddressCollecter::CollectAddress(const char *address) } nsAutoString email; email.AssignWithConversion(curAddress); senderCard->SetPrimaryEmail((PRUnichar*)email.GetUnicode()); - senderCard->AddCardToDatabase(kCollectedAddressbookUri); + senderCard->AddCardToDatabase(kCollectedAddressbookUri, getter_AddRefs (cardInstance)); } } else //address is already in the CAB @@ -182,7 +182,7 @@ NS_IMETHODIMP nsAbAddressCollecter::CollectAddress(const char *address) m_historyAB->DeleteCard( existingCard, PR_TRUE ); SetNamesForCard(existingCard, curName); //append it to the bottom. - existingCard->AddCardToDatabase(kCollectedAddressbookUri); + existingCard->AddCardToDatabase(kCollectedAddressbookUri, getter_AddRefs (cardInstance)); } else { @@ -236,13 +236,11 @@ nsresult nsAbAddressCollecter::OpenHistoryAB(nsIAddrDatabase **aDatabase) delete dbPath; } NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr resource; rv = rdfService->GetResource(kCollectedAddressbookUri, getter_AddRefs(resource)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); // query interface m_historyDirectory = do_QueryInterface(resource, &rv); diff --git a/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp b/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp index 112475e53eea..32fbd1d4db72 100644 --- a/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp +++ b/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp @@ -386,46 +386,46 @@ nsresult nsAbAutoCompleteSession::SearchDirectory(nsString& fileName, nsAbAutoCo { nsresult rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr resource; char * strFileName = fileName.ToNewCString(); rv = rdfService->GetResource(strFileName, getter_AddRefs(resource)); Recycle(strFileName); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // query interface nsCOMPtr directory(do_QueryInterface(resource, &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); - if (!fileName.EqualsWithConversion(kDirectoryDataSourceRoot)) + if (!fileName.EqualsWithConversion("abdirectory://")) rv = SearchCards(directory, searchStr, results); if (!searchSubDirectory) return rv; nsCOMPtr subDirectories; - if (NS_SUCCEEDED(directory->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories) - { - nsCOMPtr item; - if (NS_SUCCEEDED(subDirectories->First())) - { - do - { + if (NS_SUCCEEDED(directory->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories) + { + nsCOMPtr item; + if (NS_SUCCEEDED(subDirectories->First())) + { + do + { if (NS_SUCCEEDED(subDirectories->CurrentItem(getter_AddRefs(item)))) { directory = do_QueryInterface(item, &rv); if (NS_SUCCEEDED(rv)) { - DIR_Server *server = nsnull; - if (NS_SUCCEEDED(directory->GetServer(&server)) && server) - { - nsAutoString subFileName(fileName); - if (subFileName.Last() != '/') - subFileName.AppendWithConversion("/"); - subFileName.AppendWithConversion(server->fileName); - rv = SearchDirectory(subFileName, searchStr, results, PR_TRUE); - } + nsCOMPtr subResource(do_QueryInterface(item, &rv)); + if (NS_SUCCEEDED(rv)) + { + nsXPIDLCString URI; + subResource->GetValue(getter_Copies(URI)); + nsAutoString subURI; + subURI.AssignWithConversion(URI); + rv = SearchDirectory(subURI, searchStr, results, PR_TRUE); + } } } } while (NS_SUCCEEDED(subDirectories->Next())); @@ -443,8 +443,7 @@ nsresult nsAbAutoCompleteSession::SearchPreviousResults(nsAbAutoCompleteSearchSt nsresult rv; rv = previousSearchResult->GetSearchString(getter_Copies(prevSearchString)); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv, rv); if (!(const PRUnichar*)prevSearchString || ((const PRUnichar*)prevSearchString)[0] == 0) return NS_ERROR_FAILURE; @@ -465,30 +464,30 @@ nsresult nsAbAutoCompleteSession::SearchPreviousResults(nsAbAutoCompleteSearchSt if (NS_FAILED(rv) || nbrOfItems <= 0) return NS_ERROR_FAILURE; - nsCOMPtr item; - nsCOMPtr resultItem; + nsCOMPtr item; + nsCOMPtr resultItem; nsAbAutoCompleteParam *param; - for (i = 0, pos = 0; i < nbrOfItems; i ++, pos ++) - { - rv = array->QueryElementAt(pos, NS_GET_IID(nsIAutoCompleteItem), - getter_AddRefs(resultItem)); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - + for (i = 0, pos = 0; i < nbrOfItems; i ++, pos ++) + { + rv = array->QueryElementAt(pos, NS_GET_IID(nsIAutoCompleteItem), + getter_AddRefs(resultItem)); + NS_ENSURE_SUCCESS(rv, rv); + rv = resultItem->GetParam(getter_AddRefs(item)); - if (NS_FAILED(rv) || !item) + NS_ENSURE_SUCCESS(rv, rv); + if (!item) return NS_ERROR_FAILURE; param = (nsAbAutoCompleteParam *)(void *)item; - MatchType matchType; - if (CheckEntry(searchStr, param->mNickName, param->mDisplayName, param->mFirstName, param->mLastName, param->mEmailAddress, &matchType)) - AddToResult(param->mNickName, param->mDisplayName, param->mFirstName, param->mLastName, param->mEmailAddress, - param->mNotes, param->mIsMailList, matchType, results); + MatchType matchType; + if (CheckEntry(searchStr, param->mNickName, param->mDisplayName, param->mFirstName, param->mLastName, param->mEmailAddress, &matchType)) + AddToResult(param->mNickName, param->mDisplayName, param->mFirstName, param->mLastName, param->mEmailAddress, + param->mNotes, param->mIsMailList, matchType, results); - } - return NS_OK; + } + return NS_OK; } return NS_ERROR_ABORT; @@ -504,8 +503,7 @@ NS_IMETHODIMP nsAbAutoCompleteSession::OnStartLookup(const PRUnichar *uSearchStr PRBool enableAutocomplete = PR_TRUE; NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv); - if (NS_FAILED(rv) || !pPref) - return NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv, rv); pPref->GetBoolPref("mail.enable_autocomplete", &enableAutocomplete); @@ -531,7 +529,7 @@ NS_IMETHODIMP nsAbAutoCompleteSession::OnStartLookup(const PRUnichar *uSearchStr if (NS_SUCCEEDED(rv)) if (NS_FAILED(SearchPreviousResults(&searchStrings, previousSearchResult, results))) { - nsAutoString root; root.AssignWithConversion(kDirectoryDataSourceRoot); + nsAutoString root; root.AssignWithConversion("abdirectory://"); rv = SearchDirectory(root, &searchStrings, results, PR_TRUE); } diff --git a/mailnews/addrbook/src/nsAbBSDirectory.cpp b/mailnews/addrbook/src/nsAbBSDirectory.cpp index 12d528138671..e678dc03bbe9 100644 --- a/mailnews/addrbook/src/nsAbBSDirectory.cpp +++ b/mailnews/addrbook/src/nsAbBSDirectory.cpp @@ -142,7 +142,7 @@ NS_IMETHODIMP nsAbBSDirectory::GetChildNodes(nsIEnumerator* *result) if (server->dirType == PABDirectory) { - nsString name; name.AssignWithConversion(server->fileName); + nsAutoString name; name.AssignWithConversion(server->fileName); PRInt32 pos = name.Find("na2"); if (pos >= 0) /* check: this is a 4.x file, remove when conversion is done */ continue; @@ -180,7 +180,7 @@ NS_IMETHODIMP nsAbBSDirectory::GetChildNodes(nsIEnumerator* *result) nsFileSpec* dbPath; abSession->GetUserProfileDirectory(&dbPath); - nsString file; file.AssignWithConversion(server->fileName); + nsAutoString file; file.AssignWithConversion(server->fileName); (*dbPath) += file; NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, &rv); @@ -217,13 +217,13 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 prefCount, const char switch (tolower(prefName[jk][0])) { case 'd': - if (!PL_strcasecmp(prefName[jk], "description")) + if (!nsCRT::strcasecmp(prefName[jk], "description")) { unicharDescription = (PRUnichar *)prefValue[jk]; } break; case 'f': - if (!PL_strcasecmp(prefName[jk], "fileName")) + if (!nsCRT::strcasecmp(prefName[jk], "fileName")) { nsString descString(prefValue[jk]); PRInt32 unicharLength = descString.Length(); @@ -231,12 +231,12 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 prefCount, const char } break; case 'm': - if (!PL_strcasecmp(prefName[jk], "migrating")) + if (!nsCRT::strcasecmp(prefName[jk], "migrating")) { nsString descString(prefValue[jk]); PRInt32 unicharLength = descString.Length(); INTL_ConvertFromUnicode(prefValue[jk], unicharLength, &charMigrate); - if (!PL_strcasecmp(charMigrate, "true")) + if (!nsCRT::strcasecmp(charMigrate, "true")) { migrating = PR_TRUE; } @@ -251,12 +251,7 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 prefCount, const char } else { - char *uri = nsnull; - if (PL_strstr(charFileName, ".mab")) - uri = PR_smprintf("%s%s", kDirectoryDataSourceRoot, charFileName); - rv = CreateDirectoryByURI(unicharDescription, uri, migrating); - if (uri) - PR_smprintf_free(uri); + rv = CreateDirectoryPAB(unicharDescription, charFileName, migrating); } if (charFileName) @@ -267,6 +262,37 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 prefCount, const char return rv; } +nsresult nsAbBSDirectory::CreateDirectoryPAB(const PRUnichar *displayName, const char *fileName, PRBool migrating) +{ + if (!displayName ) + { + return NS_ERROR_NULL_POINTER; + } + + DIR_Server * server = nsnull; + DirectoryType dirType = PABDirectory; + + DIR_AddNewAddressBook(displayName, fileName, migrating, dirType, &server); + + char *uri = PR_smprintf("%s%s",kDirectoryDataSourceRoot, server->fileName); + + nsCOMPtr newDir; + nsresult rv = AddDirectory(uri, getter_AddRefs(newDir)); + + if (uri) + PR_smprintf_free(uri); + if (NS_SUCCEEDED(rv) && newDir) + { + newDir->SetDirName((PRUnichar *)displayName); + nsVoidKey key((void *)newDir); + mServers.Put (&key, (void *)server); + NotifyItemAdded(newDir); + return NS_OK; + } + else + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsAbBSDirectory::CreateDirectoryByURI(const PRUnichar *displayName, const char *uri, PRBool migrating) { if (!displayName || !uri) @@ -330,7 +356,7 @@ NS_IMETHODIMP nsAbBSDirectory::DeleteDirectory(nsIAbDirectory *directory) { nsCOMPtr listDir(do_QueryInterface(pSupport, &rv)); nsCOMPtr dblistDir(do_QueryInterface(pSupport, &rv)); - if (listDir) + if (listDir && dblistDir) { directory->DeleteDirectory(listDir); dblistDir->RemoveElementsFromAddressList(); diff --git a/mailnews/addrbook/src/nsAbBSDirectory.h b/mailnews/addrbook/src/nsAbBSDirectory.h index b940cde706ee..b2cd3fc7e83d 100644 --- a/mailnews/addrbook/src/nsAbBSDirectory.h +++ b/mailnews/addrbook/src/nsAbBSDirectory.h @@ -52,6 +52,7 @@ protected: nsresult NotifyItemAdded(nsISupports *item); nsresult NotifyItemDeleted(nsISupports *item); + nsresult CreateDirectoryPAB(const PRUnichar *displayName, const char *fileName, PRBool migrating); protected: PRBool mInitialized; diff --git a/mailnews/addrbook/src/nsAbCard.cpp b/mailnews/addrbook/src/nsAbCard.cpp index ba8a4bf4d33b..e56923cb6e67 100644 --- a/mailnews/addrbook/src/nsAbCard.cpp +++ b/mailnews/addrbook/src/nsAbCard.cpp @@ -180,9 +180,7 @@ nsresult nsAbCard::AddSubNode(nsAutoString name, nsIAbCard **childCard) nsresult rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCAutoString uri; uri.Append(mURI); @@ -196,11 +194,9 @@ nsresult nsAbCard::AddSubNode(nsAutoString name, nsIAbCard **childCard) nsCOMPtr res; rv = rdf->GetResource(uri.get(), getter_AddRefs(res)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr card(do_QueryInterface(res, &rv)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); *childCard = card; NS_IF_ADDREF(*childCard); diff --git a/mailnews/addrbook/src/nsAbCardProperty.cpp b/mailnews/addrbook/src/nsAbCardProperty.cpp index 863235086bea..c85b6b3c98f9 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.cpp +++ b/mailnews/addrbook/src/nsAbCardProperty.cpp @@ -33,21 +33,11 @@ #include "rdf.h" #include "nsCOMPtr.h" -#include "nsAddrDatabase.h" -#include "nsIAddrBookSession.h" #include "nsIPref.h" -#include "nsIAddressBook.h" +#include "nsIAbDirectory.h" -static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID); -static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); -static NS_DEFINE_CID(kAddrBookCID, NS_ADDRESSBOOK_CID); - - -/* The definition is nsAddressBook.cpp */ -extern const char *kDirectoryDataSourceRoot; -extern const char *kCardDataSourceRoot; /* The definition is nsAddrDatabase.cpp */ extern const char *kMainPersonalAddressBook; @@ -96,56 +86,16 @@ nsAbCardProperty::nsAbCardProperty(void) NS_INIT_REFCNT(); m_LastModDate = 0; - m_Key = 0; + m_PreferMailFormat = nsIAbPreferMailFormat::unknown; - m_bIsMailList = PR_FALSE; + m_MailListURI = 0; - m_dbTableID = 0; - m_dbRowID = 0; - m_pAnonymousStrAttributes = nsnull; - m_pAnonymousStrValues = nsnull; - m_pAnonymousIntAttributes = nsnull; - m_pAnonymousIntValues = nsnull; - m_pAnonymousBoolAttributes = nsnull; - m_pAnonymousBoolValues = nsnull; } nsAbCardProperty::~nsAbCardProperty(void) { - if (m_pAnonymousStrAttributes) - RemoveAnonymousList(m_pAnonymousStrAttributes); - if (m_pAnonymousIntAttributes) - RemoveAnonymousList(m_pAnonymousIntAttributes); - if (m_pAnonymousBoolAttributes) - RemoveAnonymousList(m_pAnonymousBoolAttributes); - - if (m_pAnonymousStrValues) - RemoveAnonymousList(m_pAnonymousStrValues); - if (m_pAnonymousIntValues) - RemoveAnonymousList(m_pAnonymousIntValues); - if (m_pAnonymousBoolValues) - RemoveAnonymousList(m_pAnonymousBoolValues); - - if (mCardDatabase) - mCardDatabase = null_nsCOMPtr(); -} - -nsresult nsAbCardProperty::RemoveAnonymousList(nsVoidArray* pArray) -{ - if (pArray) - { - PRUint32 count = pArray->Count(); - for (int i = count - 1; i >= 0; i--) - { - void* pPtr = pArray->ElementAt(i); - PR_FREEIF(pPtr); - pArray->RemoveElementAt(i); - } - delete pArray; - } - return NS_OK; } NS_IMPL_ADDREF(nsAbCardProperty) @@ -191,7 +141,7 @@ nsresult nsAbCardProperty::SetAttributeName(const PRUnichar *aName, nsString& ar NS_IMETHODIMP nsAbCardProperty::GetPreferMailFormat(PRUint32 *aFormat) { - *aFormat = m_PreferMailFormat; + *aFormat = m_PreferMailFormat; return NS_OK; } @@ -213,28 +163,31 @@ NS_IMETHODIMP nsAbCardProperty::SetIsMailList(PRBool aIsMailList) return NS_OK; } -NS_IMETHODIMP nsAbCardProperty::GetDbTableID(PRUint32 *aDbTableID) +NS_IMETHODIMP nsAbCardProperty::GetMailListURI(char **aMailListURI) { - *aDbTableID = m_dbTableID; - return NS_OK; + if (aMailListURI) + { + if (m_MailListURI) + *aMailListURI = nsCRT::strdup(m_MailListURI); + else + *aMailListURI = nsCRT::strdup(""); + + return NS_OK; + } + else + return NS_ERROR_NULL_POINTER; } -NS_IMETHODIMP nsAbCardProperty::SetDbTableID(PRUint32 aDbTableID) +NS_IMETHODIMP nsAbCardProperty::SetMailListURI(const char *aMailListURI) { - m_dbTableID = aDbTableID; - return NS_OK; -} - -NS_IMETHODIMP nsAbCardProperty::GetDbRowID(PRUint32 *aDbRowID) -{ - *aDbRowID = m_dbRowID; - return NS_OK; -} - -NS_IMETHODIMP nsAbCardProperty::SetDbRowID(PRUint32 aDbRowID) -{ - m_dbRowID = aDbRowID; - return NS_OK; + if (aMailListURI) + { + nsCRT::free (m_MailListURI); + m_MailListURI = nsCRT::strdup(aMailListURI); + return NS_OK; + } + else + return NS_ERROR_NULL_POINTER; } NS_IMETHODIMP nsAbCardProperty::GetCardValue(const char *attrname, PRUnichar **value) @@ -311,10 +264,11 @@ NS_IMETHODIMP nsAbCardProperty::GetCardValue(const char *attrname, PRUnichar **v GetCustom4(value); else if (!PL_strcmp(attrname, kNotesColumn)) GetNotes(value); - else if (!PL_strcmp(attrname, kPreferMailFormatColumn)) - { // PreferMailFormat is interger, not a string - return NS_OK; - } + else if (!PL_strcmp(attrname, kPreferMailFormatColumn)) + { // PreferMailFormat is interger, not a string + return NS_OK; + } + /* else handle pass down attribute */ return NS_OK; @@ -397,486 +351,17 @@ NS_IMETHODIMP nsAbCardProperty::SetCardValue(const char *attrname, const PRUnich rv = SetDepartment((PRUnichar *)value); else if (!PL_strcmp(attrname, kCompanyColumn)) rv = SetCompany((PRUnichar *)value); - else if (!PL_strcmp(attrname, kPreferMailFormatColumn)) - { // PreferMailFormat is interger, not a string - return NS_OK; - } - else - { - nsAutoString cardValue(value); - char* valueStr = cardValue.ToNewUTF8String(); - rv = SetAnonymousStringAttribute(attrname, valueStr); - nsMemory::Free(valueStr); - } - return rv; -} - -NS_IMETHODIMP nsAbCardProperty::SetAbDatabase(nsIAddrDatabase* database) -{ - mCardDatabase = database; - return NS_OK; -} - -NS_IMETHODIMP nsAbCardProperty::GetAnonymousStrAttrubutesList(nsVoidArray **attrlist) -{ - if (attrlist && m_pAnonymousStrAttributes) - { - *attrlist = m_pAnonymousStrAttributes; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -NS_IMETHODIMP nsAbCardProperty::GetAnonymousStrValuesList(nsVoidArray **valuelist) -{ - if (valuelist && m_pAnonymousStrValues) - { - *valuelist = m_pAnonymousStrValues; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -NS_IMETHODIMP nsAbCardProperty::GetAnonymousIntAttrubutesList(nsVoidArray **attrlist) -{ - if (attrlist && m_pAnonymousIntAttributes) - { - *attrlist = m_pAnonymousIntAttributes; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -NS_IMETHODIMP nsAbCardProperty::GetAnonymousIntValuesList(nsVoidArray **valuelist) -{ - if (valuelist && m_pAnonymousIntValues) - { - *valuelist = m_pAnonymousIntValues; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -NS_IMETHODIMP nsAbCardProperty::GetAnonymousBoolAttrubutesList(nsVoidArray **attrlist) -{ - if (attrlist && m_pAnonymousBoolAttributes) - { - *attrlist = m_pAnonymousBoolAttributes; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -NS_IMETHODIMP nsAbCardProperty::GetAnonymousBoolValuesList(nsVoidArray **valuelist) -{ - if (valuelist && m_pAnonymousBoolValues) - { - *valuelist = m_pAnonymousBoolValues; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -nsresult nsAbCardProperty::SetAnonymousAttribute -(nsVoidArray** pAttrAray, nsVoidArray** pValueArray, void *attrname, void *value) -{ - nsresult rv = NS_OK; - nsVoidArray* pAttributes = *pAttrAray; - nsVoidArray* pValues = *pValueArray; - - if (!pAttributes && !pValues) - { - pAttributes = new nsVoidArray(); - pValues = new nsVoidArray(); - *pAttrAray = pAttributes; - *pValueArray = pValues; - } - if (pAttributes && pValues) - { - if (attrname && value) - { - pAttributes->AppendElement(attrname); - pValues->AppendElement(value); - } - } - else - { - rv = NS_ERROR_FAILURE; - } - - return rv; -} - - -NS_IMETHODIMP nsAbCardProperty::SetAnonymousStringAttribute -(const char *attrname, const char *value) -{ - nsresult rv = NS_OK; - - char* pAttribute = PL_strdup(attrname); - char* pValue = PL_strdup(value); - if (pAttribute && pValue) - { - rv = SetAnonymousAttribute(&m_pAnonymousStrAttributes, - &m_pAnonymousStrValues, pAttribute, pValue); - } - else - { - PR_FREEIF(pAttribute); - PR_FREEIF(pValue); - rv = NS_ERROR_NULL_POINTER; - } - return rv; -} - -NS_IMETHODIMP nsAbCardProperty::SetAnonymousIntAttribute -(const char *attrname, PRUint32 value) -{ - nsresult rv = NS_OK; - - char* pAttribute = PL_strdup(attrname); - PRUint32* pValue = (PRUint32 *)PR_Calloc(1, sizeof(PRUint32)); - *pValue = value; - if (pAttribute && pValue) - { - rv = SetAnonymousAttribute(&m_pAnonymousIntAttributes, - &m_pAnonymousIntValues, pAttribute, pValue); - } - else - { - PR_FREEIF(pAttribute); - PR_FREEIF(pValue); - rv = NS_ERROR_NULL_POINTER; - } - return rv; -} - -NS_IMETHODIMP nsAbCardProperty::SetAnonymousBoolAttribute -(const char *attrname, PRBool value) -{ - nsresult rv = NS_OK; - - char* pAttribute = PL_strdup(attrname); - PRBool* pValue = (PRBool *)PR_Calloc(1, sizeof(PRBool)); - *pValue = value; - if (pAttribute && pValue) - { - rv = SetAnonymousAttribute(&m_pAnonymousBoolAttributes, - &m_pAnonymousBoolValues, pAttribute, pValue); - } - else - { - PR_FREEIF(pAttribute); - PR_FREEIF(pValue); - rv = NS_ERROR_NULL_POINTER; - } - return rv; -} - -NS_IMETHODIMP nsAbCardProperty::AddAnonymousAttributesToDB() -{ - nsresult rv = NS_OK; - if (mCardDatabase) - mCardDatabase = null_nsCOMPtr(); - rv = GetCardDatabase(kPersonalAddressbookUri); - if (NS_SUCCEEDED(rv) && mCardDatabase) - rv = mCardDatabase->AddAnonymousAttributesFromCard(this); - return rv; -} - -NS_IMETHODIMP nsAbCardProperty::EditAnonymousAttributesInDB() -{ - nsresult rv = NS_OK; - if (mCardDatabase) - mCardDatabase = null_nsCOMPtr(); - rv = GetCardDatabase(kPersonalAddressbookUri); - if (NS_SUCCEEDED(rv) && mCardDatabase) - rv = mCardDatabase->EditAnonymousAttributesFromCard(this); - return rv; -} - -/* caller need to PR_smprintf_free *uri */ -NS_IMETHODIMP nsAbCardProperty::GetCardURI(char **uri) -{ - char* cardURI = nsnull; - nsFileSpec *filePath = nsnull; - if (mCardDatabase) - { - mCardDatabase->GetDbPath(&filePath); - if (filePath) - { - char* file = nsnull; - file = filePath->GetLeafName(); - if (file && m_dbRowID) - { - if (m_bIsMailList) - cardURI = PR_smprintf("%s%s/ListCard%ld", kCardDataSourceRoot, file, m_dbRowID); - else - cardURI = PR_smprintf("%s%s/Card%ld", kCardDataSourceRoot, file, m_dbRowID); - } - if (file) - nsCRT::free(file); - delete filePath; - } - } - if (cardURI) - { - *uri = cardURI; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -nsresult nsAbCardProperty::GetCardDatabase(const char *uri) -{ - nsresult rv = NS_OK; - - NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv); - if (NS_SUCCEEDED(rv)) - { - nsFileSpec* dbPath; - abSession->GetUserProfileDirectory(&dbPath); - - const char* file = nsnull; - file = &(uri[PL_strlen(kDirectoryDataSourceRoot)]); - (*dbPath) += file; - - if (dbPath->Exists()) - { - NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, &rv); - - if (NS_SUCCEEDED(rv) && addrDBFactory) - rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(mCardDatabase), PR_TRUE); - } - else - rv = NS_ERROR_FAILURE; - delete dbPath; - } - return rv; -} - -NS_IMETHODIMP nsAbCardProperty::AddCardToDatabase(const char *uri) -{ - nsresult rv = NS_OK; - PRBool bInMailList = PR_FALSE; - - if (!mCardDatabase && uri) - rv = GetCardDatabase(uri); - if (NS_FAILED(rv)) //maillist - { - NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv); - if (NS_SUCCEEDED(rv)) - rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(mCardDatabase)); - bInMailList = PR_TRUE; - } - - if (mCardDatabase) - { - if (bInMailList) - { - char* listString = PL_strrstr(uri, "MailList"); - if (listString) - { - listString += PL_strlen("MailList"); - PRInt32 listID = atoi(listString); - mCardDatabase->CreateNewListCardAndAddToDB(listID, this, PR_TRUE); - } - else - return NS_ERROR_FAILURE; - } - else - mCardDatabase->CreateNewCardAndAddToDB(this, PR_TRUE); - mCardDatabase->Commit(kLargeCommit); - return NS_OK; - } - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP nsAbCardProperty::DropCardToDatabase(const char *uri) -{ - nsresult rv = NS_OK; - nsCOMPtr dropDatabase; - - NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv); - if (NS_SUCCEEDED(rv)) - rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(dropDatabase)); - - if (dropDatabase) - { - dropDatabase->CreateNewCardAndAddToDB(this, PR_FALSE); - dropDatabase->Commit(kLargeCommit); - return NS_OK; - } - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP nsAbCardProperty::EditCardToDatabase(const char *uri) -{ - if (!mCardDatabase && uri) - GetCardDatabase(uri); - - if (mCardDatabase) - { - mCardDatabase->EditCard(this, PR_TRUE); - mCardDatabase->Commit(kLargeCommit); - return NS_OK; - } - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP nsAbCardProperty::CopyCard(nsIAbCard* srcCard) -{ - PRUnichar *str = nsnull; - srcCard->GetFirstName(&str); - SetFirstName(str); - PR_FREEIF(str); - - srcCard->GetLastName(&str); - SetLastName(str); - PR_FREEIF(str); - srcCard->GetDisplayName(&str); - SetDisplayName(str); - PR_FREEIF(str); - srcCard->GetNickName(&str); - SetNickName(str); - PR_FREEIF(str); - srcCard->GetPrimaryEmail(&str); - SetPrimaryEmail(str); - PR_FREEIF(str); - srcCard->GetSecondEmail(&str); - SetSecondEmail(str); - PR_FREEIF(str); - - PRUint32 format = nsIAbPreferMailFormat::unknown; - srcCard->GetPreferMailFormat(&format); - SetPreferMailFormat(format); - - srcCard->GetWorkPhone(&str); - SetWorkPhone(str); - PR_FREEIF(str); - srcCard->GetHomePhone(&str); - SetHomePhone(str); - PR_FREEIF(str); - srcCard->GetFaxNumber(&str); - SetFaxNumber(str); - PR_FREEIF(str); - srcCard->GetPagerNumber(&str); - SetPagerNumber(str); - PR_FREEIF(str); - srcCard->GetCellularNumber(&str); - SetCellularNumber(str); - PR_FREEIF(str); - srcCard->GetHomeAddress(&str); - SetHomeAddress(str); - PR_FREEIF(str); - srcCard->GetHomeAddress2(&str); - SetHomeAddress2(str); - PR_FREEIF(str); - srcCard->GetHomeCity(&str); - SetHomeCity(str); - PR_FREEIF(str); - srcCard->GetHomeState(&str); - SetHomeState(str); - PR_FREEIF(str); - srcCard->GetHomeZipCode(&str); - SetHomeZipCode(str); - PR_FREEIF(str); - srcCard->GetHomeCountry(&str); - SetHomeCountry(str); - PR_FREEIF(str); - srcCard->GetWorkAddress(&str); - SetWorkAddress(str); - PR_FREEIF(str); - srcCard->GetWorkAddress2(&str); - SetWorkAddress2(str); - PR_FREEIF(str); - srcCard->GetWorkCity(&str); - SetWorkCity(str); - PR_FREEIF(str); - srcCard->GetWorkState(&str); - SetWorkState(str); - PR_FREEIF(str); - srcCard->GetWorkZipCode(&str); - SetWorkZipCode(str); - PR_FREEIF(str); - srcCard->GetWorkCountry(&str); - SetWorkCountry(str); - PR_FREEIF(str); - srcCard->GetJobTitle(&str); - SetJobTitle(str); - PR_FREEIF(str); - srcCard->GetDepartment(&str); - SetDepartment(str); - PR_FREEIF(str); - srcCard->GetCompany(&str); - SetCompany(str); - PR_FREEIF(str); - srcCard->GetWebPage1(&str); - SetWebPage1(str); - PR_FREEIF(str); - srcCard->GetWebPage2(&str); - SetWebPage2(str); - PR_FREEIF(str); - srcCard->GetBirthYear(&str); - SetBirthYear(str); - PR_FREEIF(str); - srcCard->GetBirthMonth(&str); - SetBirthMonth(str); - PR_FREEIF(str); - srcCard->GetBirthDay(&str); - SetBirthDay(str); - PR_FREEIF(str); - srcCard->GetCustom1(&str); - SetCustom1(str); - PR_FREEIF(str); - srcCard->GetCustom2(&str); - SetCustom2(str); - PR_FREEIF(str); - srcCard->GetCustom3(&str); - SetCustom3(str); - PR_FREEIF(str); - srcCard->GetCustom4(&str); - SetCustom4(str); - PR_FREEIF(str); - srcCard->GetNotes(&str); - SetNotes(str); - PR_FREEIF(str); - - PRUint32 tableID, rowID; - srcCard->GetDbTableID(&tableID); - SetDbTableID(tableID); - srcCard->GetDbRowID(&rowID); - SetDbRowID(rowID); - - return NS_OK; -} - -NS_IMETHODIMP nsAbCardProperty::GetCollationKey(const PRUnichar *str, PRUnichar **key) -{ - nsresult rv = NS_OK; - nsAutoString resultStr; - - if (mCardDatabase) - { - rv = mCardDatabase->CreateCollationKey(str, resultStr); - *key = resultStr.ToNewUnicode(); - } - else + else if (!PL_strcmp(attrname, kPreferMailFormatColumn)) + { // PreferMailFormat is interger, not a string + return NS_OK; + } + else rv = NS_ERROR_FAILURE; - return rv; + return rv; } + NS_IMETHODIMP nsAbCardProperty::GetFirstName(PRUnichar * *aFirstName) { return GetAttributeName(aFirstName, m_FirstName); } @@ -1025,14 +510,6 @@ NS_IMETHODIMP nsAbCardProperty::GetLastModifiedDate(PRUint32 *aLastModifiedDate) { *aLastModifiedDate = m_LastModDate; return NS_OK; } -NS_IMETHODIMP -nsAbCardProperty::GetKey(PRUint32 *aKey) -{ *aKey = m_Key; return NS_OK; } - -NS_IMETHODIMP -nsAbCardProperty::SetRecordKey(PRUint32 key) -{ m_Key = key; return NS_OK; } - NS_IMETHODIMP nsAbCardProperty::SetFirstName(const PRUnichar * aFirstName) { return SetAttributeName(aFirstName, m_FirstName); } @@ -1181,6 +658,13 @@ NS_IMETHODIMP nsAbCardProperty::SetLastModifiedDate(PRUint32 aLastModifiedDate) { return m_LastModDate = aLastModifiedDate; } + + +NS_IMETHODIMP +nsAbCardProperty::SetName(const PRUnichar * aName) +{ + return NS_OK; +} NS_IMETHODIMP nsAbCardProperty::GetName(PRUnichar * *aName) { @@ -1188,8 +672,7 @@ nsAbCardProperty::GetName(PRUnichar * *aName) // get name depend on "mail.addr_book.lastnamefirst" // 0= displayname, 1= lastname first, 2=firstname first NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv); - if (NS_FAILED(rv) || !pPref) - return NS_ERROR_FAILURE; + NS_ENSURE_SUCCESS(rv, rv); PRInt32 lastNameFirst = 0; rv = pPref->GetIntPref("mail.addr_book.lastnamefirst", &lastNameFirst); @@ -1202,18 +685,16 @@ nsAbCardProperty::GetName(PRUnichar * *aName) nsString name; nsString firstName; nsString lastName; - PRUnichar *str = nsnull; - GetFirstName(&str); + nsXPIDLString str; + GetFirstName(getter_Copies(str)); if (str) { firstName = str; - PR_FREEIF(str); } - GetLastName(&str); + GetLastName(getter_Copies(str)); if (str) { lastName = str; - PR_FREEIF(str); } if (lastName.Length() == 0) @@ -1250,51 +731,147 @@ nsAbCardProperty::GetName(PRUnichar * *aName) return NS_OK; } -NS_IMETHODIMP -nsAbCardProperty::SetName(const PRUnichar * aName) +NS_IMETHODIMP nsAbCardProperty::Copy(nsIAbCard* srcCard) { - return NS_OK; -} + nsXPIDLString str; + srcCard->GetFirstName(getter_Copies(str)); + SetFirstName(str); -NS_IMETHODIMP -nsAbCardProperty::GetPrintCardUrl(char * *aPrintCardUrl) -{ -static const char *kAbPrintUrlFormat = "addbook:printone?email=%s&folder=%s"; + srcCard->GetLastName(getter_Copies(str)); + SetLastName(str); + srcCard->GetDisplayName(getter_Copies(str)); + SetDisplayName(str); + srcCard->GetNickName(getter_Copies(str)); + SetNickName(str); + srcCard->GetPrimaryEmail(getter_Copies(str)); + SetPrimaryEmail(str); + srcCard->GetSecondEmail(getter_Copies(str)); + SetSecondEmail(str); - if (!aPrintCardUrl) - return NS_OK; + PRUint32 format = nsIAbPreferMailFormat::unknown; + srcCard->GetPreferMailFormat(&format); + SetPreferMailFormat(format); - PRUnichar *email = nsnull; - GetPrimaryEmail(&email); - nsString emailStr(email); - - if (emailStr.Length() == 0) - { - *aPrintCardUrl = PR_smprintf(""); - return NS_OK; - } - PRUnichar *dirName = nsnull; - if (mCardDatabase) - mCardDatabase->GetDirectoryName(&dirName); - nsString dirNameStr(dirName); - if (dirNameStr.Length() == 0) - { - *aPrintCardUrl = PR_smprintf(""); - return NS_OK; - } - dirNameStr.ReplaceSubstring(NS_ConvertASCIItoUCS2(" "), NS_ConvertASCIItoUCS2("%20")); - - char *emailCharStr = emailStr.ToNewUTF8String(); - char *dirCharStr = dirNameStr.ToNewUTF8String(); - - *aPrintCardUrl = PR_smprintf(kAbPrintUrlFormat, emailCharStr, dirCharStr); - - nsMemory::Free(emailCharStr); - nsMemory::Free(dirCharStr); - - PR_FREEIF(dirName); - PR_FREEIF(email); + srcCard->GetWorkPhone(getter_Copies(str)); + SetWorkPhone(str); + srcCard->GetHomePhone(getter_Copies(str)); + SetHomePhone(str); + srcCard->GetFaxNumber(getter_Copies(str)); + SetFaxNumber(str); + srcCard->GetPagerNumber(getter_Copies(str)); + SetPagerNumber(str); + srcCard->GetCellularNumber(getter_Copies(str)); + SetCellularNumber(str); + srcCard->GetHomeAddress(getter_Copies(str)); + SetHomeAddress(str); + srcCard->GetHomeAddress2(getter_Copies(str)); + SetHomeAddress2(str); + srcCard->GetHomeCity(getter_Copies(str)); + SetHomeCity(str); + srcCard->GetHomeState(getter_Copies(str)); + SetHomeState(str); + srcCard->GetHomeZipCode(getter_Copies(str)); + SetHomeZipCode(str); + srcCard->GetHomeCountry(getter_Copies(str)); + SetHomeCountry(str); + srcCard->GetWorkAddress(getter_Copies(str)); + SetWorkAddress(str); + srcCard->GetWorkAddress2(getter_Copies(str)); + SetWorkAddress2(str); + srcCard->GetWorkCity(getter_Copies(str)); + SetWorkCity(str); + srcCard->GetWorkState(getter_Copies(str)); + SetWorkState(str); + srcCard->GetWorkZipCode(getter_Copies(str)); + SetWorkZipCode(str); + srcCard->GetWorkCountry(getter_Copies(str)); + SetWorkCountry(str); + srcCard->GetJobTitle(getter_Copies(str)); + SetJobTitle(str); + srcCard->GetDepartment(getter_Copies(str)); + SetDepartment(str); + srcCard->GetCompany(getter_Copies(str)); + SetCompany(str); + srcCard->GetWebPage1(getter_Copies(str)); + SetWebPage1(str); + srcCard->GetWebPage2(getter_Copies(str)); + SetWebPage2(str); + srcCard->GetBirthYear(getter_Copies(str)); + SetBirthYear(str); + srcCard->GetBirthMonth(getter_Copies(str)); + SetBirthMonth(str); + srcCard->GetBirthDay(getter_Copies(str)); + SetBirthDay(str); + srcCard->GetCustom1(getter_Copies(str)); + SetCustom1(str); + srcCard->GetCustom2(getter_Copies(str)); + SetCustom2(str); + srcCard->GetCustom3(getter_Copies(str)); + SetCustom3(str); + srcCard->GetCustom4(getter_Copies(str)); + SetCustom4(str); + srcCard->GetNotes(getter_Copies(str)); + SetNotes(str); return NS_OK; } +NS_IMETHODIMP nsAbCardProperty::AddCardToDatabase(const char *uri, nsIAbCard **_retval) +{ + nsresult rv = NS_OK; + NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr res; + rv = rdf->GetResource(uri, getter_AddRefs(res)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr directory(do_QueryInterface(res, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr cardInstance; + rv = directory->AddCard (this, getter_AddRefs (cardInstance)); + + *_retval = cardInstance; + NS_IF_ADDREF(*_retval); + return rv; +} + +NS_IMETHODIMP nsAbCardProperty::DropCardToDatabase(const char *uri, nsIAbCard **_retval) +{ + nsresult rv = NS_OK; + NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr res; + rv = rdf->GetResource(uri, getter_AddRefs(res)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr directory(do_QueryInterface(res, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr cardInstance; + rv = directory->DropCard (this, getter_AddRefs (cardInstance)); + + *_retval = cardInstance; + NS_IF_ADDREF(*_retval); + return rv; +} + + +// nsIAbCard NOT IMPLEMENTED methods + +NS_IMETHODIMP nsAbCardProperty::EditCardToDatabase(const char *uri) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsAbCardProperty::GetPrintCardUrl(char * *aPrintCardUrl) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsAbCardProperty::GetCollationKey(const PRUnichar *str, PRUnichar **key) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mailnews/addrbook/src/nsAbCardProperty.h b/mailnews/addrbook/src/nsAbCardProperty.h index b87562aa9b2f..aa14c1c7664d 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.h +++ b/mailnews/addrbook/src/nsAbCardProperty.h @@ -44,21 +44,15 @@ class nsAbCardProperty: public nsIAbCard public: NS_DECL_ISUPPORTS - NS_DECL_NSIABCARD + NS_DECL_NSIABCARD + nsAbCardProperty(void); virtual ~nsAbCardProperty(void); - // nsIAbCard methods: - - protected: - nsresult GetCardDatabase(const char *uri); nsresult GetAttributeName(PRUnichar **aName, nsString& value); nsresult SetAttributeName(const PRUnichar *aName, nsString& arrtibute); - nsresult RemoveAnonymousList(nsVoidArray* pArray); - nsresult SetAnonymousAttribute(nsVoidArray** pAttrAray, - nsVoidArray** pValueArray, void *attrname, void *value); nsString m_FirstName; nsString m_LastName; @@ -97,23 +91,11 @@ protected: nsString m_Custom4; nsString m_Note; PRUint32 m_LastModDate; - PRUint32 m_Key; + PRUint32 m_Key; PRUint32 m_PreferMailFormat; PRBool m_bIsMailList; - - PRUint32 m_dbTableID; - PRUint32 m_dbRowID; - - nsCOMPtr mCardDatabase; - - nsVoidArray* m_pAnonymousStrAttributes; - nsVoidArray* m_pAnonymousStrValues; - nsVoidArray* m_pAnonymousIntAttributes; - nsVoidArray* m_pAnonymousIntValues; - nsVoidArray* m_pAnonymousBoolAttributes; - nsVoidArray* m_pAnonymousBoolValues; - + char* m_MailListURI; }; #endif diff --git a/mailnews/addrbook/src/nsAbDirProperty.cpp b/mailnews/addrbook/src/nsAbDirProperty.cpp index e94ecba0c324..80b10e12d62d 100644 --- a/mailnews/addrbook/src/nsAbDirProperty.cpp +++ b/mailnews/addrbook/src/nsAbDirProperty.cpp @@ -29,30 +29,19 @@ #include "nsXPIDLString.h" #include "nsCOMPtr.h" #include "nsAbBaseCID.h" -#include "nsAbCard.h" -#include "nsAddrDatabase.h" -#include "nsIAbListener.h" -#include "nsIAddrBookSession.h" -#include "nsIAddressBook.h" +#include "nsIAbCard.h" + +#include "rdf.h" #include "mdb.h" #include "prlog.h" #include "prprf.h" #include "prmem.h" -/* The definition is nsAddressBook.cpp */ -extern const char *kDirectoryDataSourceRoot; - - static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); -static NS_DEFINE_CID(kAbCardCID, NS_ABCARD_CID); -static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID); -static NS_DEFINE_CID(kAddrBookCID, NS_ADDRESSBOOK_CID); - nsAbDirProperty::nsAbDirProperty(void) - : m_LastModifiedDate(0), - m_DbPath(nsnull), m_Server(nsnull) + : m_LastModifiedDate(0) { NS_INIT_REFCNT(); @@ -61,7 +50,6 @@ nsAbDirProperty::nsAbDirProperty(void) nsAbDirProperty::~nsAbDirProperty(void) { - PR_FREEIF(m_DbPath); } NS_IMPL_ADDREF(nsAbDirProperty) @@ -83,28 +71,6 @@ NS_IMETHODIMP nsAbDirProperty::QueryInterface(REFNSIID aIID, void** aResult) //////////////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsAbDirProperty::GetDirFilePath(char **dbPath) -{ - if (m_Server && m_Server->fileName) - { - nsresult rv = NS_OK; - nsFileSpec* dbFile = nsnull; - - NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv); - if(NS_SUCCEEDED(rv)) - abSession->GetUserProfileDirectory(&dbFile); - - (*dbFile) += m_Server->fileName; - char* file = PL_strdup(dbFile->GetCString()); - *dbPath = file; - - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -//////////////////////////////////////////////////////////////////////////////// - NS_IMETHODIMP nsAbDirProperty::GetDirName(PRUnichar **aDirName) { if (aDirName) @@ -146,83 +112,6 @@ NS_IMETHODIMP nsAbDirProperty::SetLastModifiedDate(PRUint32 aLastModifiedDate) return NS_OK; } -NS_IMETHODIMP nsAbDirProperty::GetServer(DIR_Server * *aServer) -{ - if (aServer) - { - *aServer = m_Server; - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -} - -NS_IMETHODIMP nsAbDirProperty::SetServer(DIR_Server * aServer) -{ - m_Server = aServer; - return NS_OK; -} - -NS_IMETHODIMP -nsAbDirProperty::GetChildNodes(nsIEnumerator **childList) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::GetChildCards(nsIEnumerator **childCards) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::AddChildCards(const char *uriName, nsIAbCard **childCard) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::AddDirectory(const char *uriName, nsIAbDirectory **childDir) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::DeleteDirectory(nsIAbDirectory *dierctory) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::DeleteCards(nsISupportsArray *cards) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::HasCard(nsIAbCard *cards, PRBool *hasCard) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::CreateNewDirectory(const PRUnichar *dirName, const char *fileName, PRBool migrating) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::CreateNewMailingList(const char* uri, nsIAbDirectory *list) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::GetDirUri(char **uri) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::ClearDatabase() -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::NotifyDirItemAdded(nsISupports *item) -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::RemoveElementsFromAddressList() -{ return NS_OK; } - -NS_IMETHODIMP -nsAbDirProperty::RemoveEmailAddressAt(PRUint32 aIndex) -{ return NS_OK; } - nsresult nsAbDirProperty::GetAttributeName(PRUnichar **aName, nsString& value) { if (aName) @@ -263,18 +152,6 @@ NS_IMETHODIMP nsAbDirProperty::GetDescription(PRUnichar * *aDescription) NS_IMETHODIMP nsAbDirProperty::SetDescription(const PRUnichar * aDescription) { return SetAttributeName(aDescription, m_Description); } -NS_IMETHODIMP nsAbDirProperty::GetDbRowID(PRUint32 *aDbRowID) -{ - *aDbRowID = m_dbRowID; - return NS_OK; -} - -NS_IMETHODIMP nsAbDirProperty::SetDbRowID(PRUint32 aDbRowID) -{ - m_dbRowID = aDbRowID; - return NS_OK; -} - NS_IMETHODIMP nsAbDirProperty::GetIsMailList(PRBool *aIsMailList) { *aIsMailList = m_bIsMailList; @@ -290,7 +167,9 @@ NS_IMETHODIMP nsAbDirProperty::SetIsMailList(PRBool aIsMailList) NS_IMETHODIMP nsAbDirProperty::GetAddressLists(nsISupportsArray * *aAddressLists) { if (!m_AddressList) + { NS_NewISupportsArray(getter_AddRefs(m_AddressList)); + } *aAddressLists = m_AddressList; NS_ADDREF(*aAddressLists); @@ -303,119 +182,33 @@ NS_IMETHODIMP nsAbDirProperty::SetAddressLists(nsISupportsArray * aAddressLists) return NS_OK; } -/* add mailing list to the parent directory */ -NS_IMETHODIMP nsAbDirProperty::AddMailListToDirectory(nsIAbDirectory *mailList) -{ - if (!m_AddressList) - NS_NewISupportsArray(getter_AddRefs(m_AddressList)); - PRUint32 i, count; - m_AddressList->Count(&count); - for (i = 0; i < count; i++) - { - nsresult err; - nsCOMPtr pSupport = getter_AddRefs(m_AddressList->ElementAt(i)); - nsCOMPtr pList(do_QueryInterface(pSupport, &err)); - if (mailList == pList.get()) - return NS_OK; - } - m_AddressList->AppendElement(mailList); - return NS_OK; -} - -/* add addresses to the mailing list */ -NS_IMETHODIMP nsAbDirProperty::AddAddressToList(nsIAbCard *card) -{ - if (!m_AddressList) - NS_NewISupportsArray(getter_AddRefs(m_AddressList)); - PRUint32 i, count; - m_AddressList->Count(&count); - for (i = 0; i < count; i++) - { - nsresult err; - nsCOMPtr pSupport = getter_AddRefs(m_AddressList->ElementAt(i)); - nsCOMPtr pCard(do_QueryInterface(pSupport, &err)); - if (card == pCard.get()) - return NS_OK; - } - m_AddressList->AppendElement(card); - return NS_OK; -} - NS_IMETHODIMP nsAbDirProperty::AddMailListToDatabase(const char *uri) { nsresult rv = NS_OK; + NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr listDatabase; + nsCOMPtr res; + rv = rdf->GetResource(uri, getter_AddRefs(res)); + NS_ENSURE_SUCCESS(rv, rv); - NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv); - if (NS_SUCCEEDED(rv)) - rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(listDatabase)); + nsCOMPtr directory(do_QueryInterface(res, &rv)); + NS_ENSURE_SUCCESS(rv, rv); - if (listDatabase) - { - listDatabase->CreateMailListAndAddToDB(this, PR_TRUE); - listDatabase->Commit(kLargeCommit); - listDatabase = null_nsCOMPtr(); + rv = directory->AddMailList(this); - NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if(NS_FAILED(rv)) - return rv; - nsCOMPtr parentResource; - rv = rdfService->GetResource(uri, getter_AddRefs(parentResource)); - nsCOMPtr parentDir = do_QueryInterface(parentResource); - if (!parentDir) - return NS_ERROR_NULL_POINTER; - - char *listUri = PR_smprintf("%s/MailList%ld", uri, m_dbRowID); - if (listUri) - { - parentDir->CreateNewMailingList(listUri, this); - PR_smprintf_free(listUri); - return NS_OK; - } - else - return NS_ERROR_FAILURE; - } - else - return NS_ERROR_FAILURE; + return rv; } -NS_IMETHODIMP nsAbDirProperty::EditMailListToDatabase(const char *uri) -{ - nsresult rv = NS_OK; - - nsCOMPtr listDatabase; - - NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv); - if (NS_SUCCEEDED(rv)) - rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(listDatabase)); - - if (listDatabase) - { - listDatabase->EditMailList(this, PR_TRUE); - listDatabase->Commit(kLargeCommit); - listDatabase = null_nsCOMPtr(); - - return NS_OK; - - } - else - return NS_ERROR_FAILURE; -} - - NS_IMETHODIMP nsAbDirProperty::CopyMailList(nsIAbDirectory* srcList) { - PRUnichar *str = nsnull; - srcList->GetListName(&str); + nsXPIDLString str; + srcList->GetListName(getter_Copies(str)); SetListName(str); - PR_FREEIF(str); - srcList->GetListNickName(&str); + srcList->GetListNickName(getter_Copies(str)); SetListNickName(str); - PR_FREEIF(str); - srcList->GetDescription(&str); + srcList->GetDescription(getter_Copies(str)); SetDescription(str); - PR_FREEIF(str); SetIsMailList(PR_TRUE); @@ -424,9 +217,57 @@ NS_IMETHODIMP nsAbDirProperty::CopyMailList(nsIAbDirectory* srcList) NS_IF_ADDREF(pAddressLists); SetAddressLists(pAddressLists); - PRUint32 rowID; - srcList->GetDbRowID(&rowID); - SetDbRowID(rowID); - return NS_OK; } + + + + + + + + +// nsIAbDirectory NOT IMPLEMENTED methods + +NS_IMETHODIMP +nsAbDirProperty::GetChildNodes(nsIEnumerator **childList) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsAbDirProperty::GetChildCards(nsIEnumerator **childCards) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsAbDirProperty::DeleteDirectory(nsIAbDirectory *dierctory) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsAbDirProperty::DeleteCards(nsISupportsArray *cards) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsAbDirProperty::HasCard(nsIAbCard *cards, PRBool *hasCard) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsAbDirProperty::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsAbDirProperty::CreateNewDirectory(PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP nsAbDirProperty::CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP nsAbDirProperty::AddMailList(nsIAbDirectory *list) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP nsAbDirProperty::EditMailListToDatabase(const char *uri) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP nsAbDirProperty::AddCard(nsIAbCard *childCard, nsIAbCard **_retval) +{ return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP nsAbDirProperty::DropCard(nsIAbCard *childCard, nsIAbCard **_retval) +{ return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mailnews/addrbook/src/nsAbDirProperty.h b/mailnews/addrbook/src/nsAbDirProperty.h index 8255e858853c..5d6e42bdab9e 100644 --- a/mailnews/addrbook/src/nsAbDirProperty.h +++ b/mailnews/addrbook/src/nsAbDirProperty.h @@ -30,7 +30,6 @@ #define nsAbDirProperty_h__ #include "nsIAbDirectory.h" /* include the interface we are going to support */ -#include "nsAbRDFResource.h" #include "nsIAbCard.h" #include "nsISupportsArray.h" #include "nsCOMPtr.h" @@ -58,13 +57,10 @@ protected: nsString m_DirName; PRUint32 m_LastModifiedDate; - nsFileSpec* m_DbPath; - DIR_Server* m_Server; nsString m_ListName; nsString m_ListNickName; nsString m_Description; - PRUint32 m_dbRowID; PRBool m_bIsMailList; nsCOMPtr m_AddressList; diff --git a/mailnews/addrbook/src/nsAbDirectory.cpp b/mailnews/addrbook/src/nsAbDirectory.cpp index 52978476f3de..d4c7efa73f88 100644 --- a/mailnews/addrbook/src/nsAbDirectory.cpp +++ b/mailnews/addrbook/src/nsAbDirectory.cpp @@ -99,13 +99,12 @@ NS_IMETHODIMP nsAbDirectory::OnCardEntryChange if (abCode == AB_NotifyInserted && card) { NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); char* cardURI = nsnull; rv = card->GetCardURI(&cardURI); - if (NS_FAILED(rv) || !cardURI) + NS_ENSURE_SUCCESS(rv, rv); + if (!cardURI) return NS_ERROR_NULL_POINTER; nsCOMPtr res; @@ -122,8 +121,7 @@ NS_IMETHODIMP nsAbDirectory::OnCardEntryChange { personCard->SetAbDatabase(mDatabase); nsCOMPtr listener(do_QueryInterface(personCard, &rv)); - if (NS_FAILED(rv)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(rv, rv); mDatabase->AddListener(listener); } nsCOMPtr cardSupports(do_QueryInterface(personCard)); @@ -215,7 +213,7 @@ NS_IMETHODIMP nsAbDirectory::GetChildNodes(nsIEnumerator* *result) nsFileSpec* dbPath; abSession->GetUserProfileDirectory(&dbPath); - nsString file; file.AssignWithConversion(server->fileName); + nsAutoString file; file.AssignWithConversion(server->fileName); (*dbPath) += file; NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, &rv); @@ -242,18 +240,14 @@ NS_IMETHODIMP nsAbDirectory::AddDirectory(const char *uriName, nsIAbDirectory ** nsresult rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr res; rv = rdf->GetResource(uriName, getter_AddRefs(res)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr directory(do_QueryInterface(res, &rv)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); mSubDirectories->AppendElement(directory); *childDir = directory; @@ -269,18 +263,14 @@ nsresult nsAbDirectory::AddMailList(const char *uriName) nsresult rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr res; rv = rdf->GetResource(uriName, getter_AddRefs(res)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr directory(do_QueryInterface(res, &rv)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); mSubDirectories->AppendElement(directory); @@ -291,7 +281,7 @@ NS_IMETHODIMP nsAbDirectory::GetChildCards(nsIEnumerator* *result) { if (mURI && mIsMailingList == -1) { - nsString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); + nsAutoString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); PRInt32 pos = file.Find("/"); if (pos != -1) mIsMailingList = 1; @@ -317,7 +307,7 @@ NS_IMETHODIMP nsAbDirectory::CreateNewDirectory(const PRUnichar *dirName, const return NS_ERROR_NULL_POINTER; DIR_Server * server = nsnull; - nsresult rv = DIR_AddNewAddressBook(dirName, fileName, migrating, &server); + nsresult rv = DIR_AddNewAddressBook(dirName, fileName, PABDirectory, &server); nsCOMPtr newDir; char *uri = PR_smprintf("%s%s", kDirectoryDataSourceRoot, server->fileName); @@ -360,8 +350,7 @@ NS_IMETHODIMP nsAbDirectory::CreateNewMailingList(const char* uri, nsIAbDirector if (listDatabase) { nsCOMPtr listener(do_QueryInterface(newList, &rv)); - if (NS_FAILED(rv)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(rv, rv); listDatabase->AddListener(listener); } newList->CopyMailList(list); @@ -380,23 +369,20 @@ NS_IMETHODIMP nsAbDirectory::AddChildCards(const char *uriName, nsIAbCard **chil nsresult rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr res; rv = rdf->GetResource(uriName, getter_AddRefs(res)); - if (NS_FAILED(rv)) - { - return rv; - } + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr personCard(do_QueryInterface(res, &rv)); if (NS_FAILED(rv)) { rv = nsComponentManager::CreateInstance(kAbCardCID, nsnull, NS_GET_IID(nsIAbCard), getter_AddRefs(personCard)); - if (NS_FAILED(rv) || !personCard) + NS_ENSURE_SUCCESS(rv, rv); + if (!personCard) { - return rv; + return NS_ERROR_NULL_POINTER; } } @@ -477,7 +463,7 @@ NS_IMETHODIMP nsAbDirectory::DeleteCards(nsISupportsArray *cards) PRUint32 cardCount; PRUint32 i; rv = cards->Count(&cardCount); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); for (i = 0; i < cardCount; i++) { nsCOMPtr cardSupports; @@ -526,8 +512,7 @@ NS_IMETHODIMP nsAbDirectory::DeleteCards(nsISupportsArray *cards) { rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr listResource; rv = rdfService->GetResource(listUri, getter_AddRefs(listResource)); nsCOMPtr listDir = do_QueryInterface(listResource); @@ -610,7 +595,7 @@ nsresult nsAbDirectory::DeleteDirectoryCards(nsIAbDirectory* directory, DIR_Serv { PRUint32 cardCount; rv = cardArray->Count(&cardCount); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); for(PRUint32 i = 0; i < cardCount; i++) { nsCOMPtr cardSupports = getter_AddRefs(cardArray->ElementAt(i)); @@ -674,7 +659,7 @@ NS_IMETHODIMP nsAbDirectory::DeleteDirectory(nsIAbDirectory *directory) nsXPIDLCString uri; rv = directory->GetDirUri(getter_Copies(uri)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr database; NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv); @@ -727,7 +712,7 @@ NS_IMETHODIMP nsAbDirectory::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir) { nsXPIDLCString uri; rv = dir->GetDirUri(getter_Copies(uri)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr database; NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv); if (NS_SUCCEEDED(rv)) diff --git a/mailnews/addrbook/src/nsAbMDBCardProperty.cpp b/mailnews/addrbook/src/nsAbMDBCardProperty.cpp index f6f3e99bd44b..7e7e0c59fde4 100644 --- a/mailnews/addrbook/src/nsAbMDBCardProperty.cpp +++ b/mailnews/addrbook/src/nsAbMDBCardProperty.cpp @@ -209,8 +209,8 @@ NS_IMETHODIMP nsAbMDBCardProperty::SetAnonymousStringAttribute { nsresult rv = NS_OK; - char* pAttribute = PL_strdup(attrname); - char* pValue = PL_strdup(value); + char* pAttribute = nsCRT::strdup(attrname); + char* pValue = nsCRT::strdup(value); if (pAttribute && pValue) { rv = SetAnonymousAttribute(&m_pAnonymousStrAttributes, @@ -218,8 +218,8 @@ NS_IMETHODIMP nsAbMDBCardProperty::SetAnonymousStringAttribute } else { - PR_FREEIF(pAttribute); - PR_FREEIF(pValue); + nsCRT::free(pAttribute); + nsCRT::free(pValue); rv = NS_ERROR_NULL_POINTER; } return rv; @@ -230,7 +230,7 @@ NS_IMETHODIMP nsAbMDBCardProperty::SetAnonymousIntAttribute { nsresult rv = NS_OK; - char* pAttribute = PL_strdup(attrname); + char* pAttribute = nsCRT::strdup(attrname); PRUint32* pValue = (PRUint32 *)PR_Calloc(1, sizeof(PRUint32)); *pValue = value; if (pAttribute && pValue) @@ -240,7 +240,7 @@ NS_IMETHODIMP nsAbMDBCardProperty::SetAnonymousIntAttribute } else { - PR_FREEIF(pAttribute); + nsCRT::free(pAttribute); PR_FREEIF(pValue); rv = NS_ERROR_NULL_POINTER; } @@ -252,7 +252,7 @@ NS_IMETHODIMP nsAbMDBCardProperty::SetAnonymousBoolAttribute { nsresult rv = NS_OK; - char* pAttribute = PL_strdup(attrname); + char* pAttribute = nsCRT::strdup(attrname); PRBool* pValue = (PRBool *)PR_Calloc(1, sizeof(PRBool)); *pValue = value; if (pAttribute && pValue) @@ -261,8 +261,8 @@ NS_IMETHODIMP nsAbMDBCardProperty::SetAnonymousBoolAttribute &m_pAnonymousBoolValues, pAttribute, pValue); } else - { - PR_FREEIF(pAttribute); + { + nsCRT::free(pAttribute); PR_FREEIF(pValue); rv = NS_ERROR_NULL_POINTER; } @@ -304,126 +304,89 @@ NS_IMETHODIMP nsAbMDBCardProperty::GetCardURI(char **uri) NS_IMETHODIMP nsAbMDBCardProperty::CopyCard(nsIAbMDBCard* srcCardDB) { - nsresult err = NS_OK; - nsCOMPtr srcCard(do_QueryInterface(srcCardDB, &err)); - if (NS_FAILED(err)) - return NS_ERROR_NULL_POINTER; + nsresult rv = NS_OK; + nsCOMPtr srcCard(do_QueryInterface(srcCardDB, &rv)); + NS_ENSURE_SUCCESS(rv, rv); - PRUnichar *str = nsnull; - srcCard->GetFirstName(&str); + nsXPIDLString str; + srcCard->GetFirstName(getter_Copies(str)); SetFirstName(str); - PR_FREEIF(str); - srcCard->GetLastName(&str); + srcCard->GetLastName(getter_Copies(str)); SetLastName(str); - PR_FREEIF(str); - srcCard->GetDisplayName(&str); + srcCard->GetDisplayName(getter_Copies(str)); SetDisplayName(str); - PR_FREEIF(str); - srcCard->GetNickName(&str); + srcCard->GetNickName(getter_Copies(str)); SetNickName(str); - PR_FREEIF(str); - srcCard->GetPrimaryEmail(&str); + srcCard->GetPrimaryEmail(getter_Copies(str)); SetPrimaryEmail(str); - PR_FREEIF(str); - srcCard->GetSecondEmail(&str); + srcCard->GetSecondEmail(getter_Copies(str)); SetSecondEmail(str); - PR_FREEIF(str); - PRUint32 format = nsIAbPreferMailFormat::unknown; - srcCard->GetPreferMailFormat(&format); - SetPreferMailFormat(format); + PRUint32 format = nsIAbPreferMailFormat::unknown; + srcCard->GetPreferMailFormat(&format); + SetPreferMailFormat(format); - srcCard->GetWorkPhone(&str); + srcCard->GetWorkPhone(getter_Copies(str)); SetWorkPhone(str); - PR_FREEIF(str); - srcCard->GetHomePhone(&str); + srcCard->GetHomePhone(getter_Copies(str)); SetHomePhone(str); - PR_FREEIF(str); - srcCard->GetFaxNumber(&str); + srcCard->GetFaxNumber(getter_Copies(str)); SetFaxNumber(str); - PR_FREEIF(str); - srcCard->GetPagerNumber(&str); + srcCard->GetPagerNumber(getter_Copies(str)); SetPagerNumber(str); - PR_FREEIF(str); - srcCard->GetCellularNumber(&str); + srcCard->GetCellularNumber(getter_Copies(str)); SetCellularNumber(str); - PR_FREEIF(str); - srcCard->GetHomeAddress(&str); + srcCard->GetHomeAddress(getter_Copies(str)); SetHomeAddress(str); - PR_FREEIF(str); - srcCard->GetHomeAddress2(&str); + srcCard->GetHomeAddress2(getter_Copies(str)); SetHomeAddress2(str); - PR_FREEIF(str); - srcCard->GetHomeCity(&str); + srcCard->GetHomeCity(getter_Copies(str)); SetHomeCity(str); - PR_FREEIF(str); - srcCard->GetHomeState(&str); + srcCard->GetHomeState(getter_Copies(str)); SetHomeState(str); - PR_FREEIF(str); - srcCard->GetHomeZipCode(&str); + srcCard->GetHomeZipCode(getter_Copies(str)); SetHomeZipCode(str); - PR_FREEIF(str); - srcCard->GetHomeCountry(&str); + srcCard->GetHomeCountry(getter_Copies(str)); SetHomeCountry(str); - PR_FREEIF(str); - srcCard->GetWorkAddress(&str); + srcCard->GetWorkAddress(getter_Copies(str)); SetWorkAddress(str); - PR_FREEIF(str); - srcCard->GetWorkAddress2(&str); + srcCard->GetWorkAddress2(getter_Copies(str)); SetWorkAddress2(str); - PR_FREEIF(str); - srcCard->GetWorkCity(&str); + srcCard->GetWorkCity(getter_Copies(str)); SetWorkCity(str); - PR_FREEIF(str); - srcCard->GetWorkState(&str); + srcCard->GetWorkState(getter_Copies(str)); SetWorkState(str); - PR_FREEIF(str); - srcCard->GetWorkZipCode(&str); + srcCard->GetWorkZipCode(getter_Copies(str)); SetWorkZipCode(str); - PR_FREEIF(str); - srcCard->GetWorkCountry(&str); + srcCard->GetWorkCountry(getter_Copies(str)); SetWorkCountry(str); - PR_FREEIF(str); - srcCard->GetJobTitle(&str); + srcCard->GetJobTitle(getter_Copies(str)); SetJobTitle(str); - PR_FREEIF(str); - srcCard->GetDepartment(&str); + srcCard->GetDepartment(getter_Copies(str)); SetDepartment(str); - PR_FREEIF(str); - srcCard->GetCompany(&str); + srcCard->GetCompany(getter_Copies(str)); SetCompany(str); - PR_FREEIF(str); - srcCard->GetWebPage1(&str); + srcCard->GetWebPage1(getter_Copies(str)); SetWebPage1(str); - PR_FREEIF(str); - srcCard->GetWebPage2(&str); + srcCard->GetWebPage2(getter_Copies(str)); SetWebPage2(str); - PR_FREEIF(str); - srcCard->GetBirthYear(&str); + srcCard->GetBirthYear(getter_Copies(str)); SetBirthYear(str); - PR_FREEIF(str); - srcCard->GetBirthMonth(&str); + srcCard->GetBirthMonth(getter_Copies(str)); SetBirthMonth(str); - PR_FREEIF(str); - srcCard->GetBirthDay(&str); + srcCard->GetBirthDay(getter_Copies(str)); SetBirthDay(str); - PR_FREEIF(str); - srcCard->GetCustom1(&str); + srcCard->GetCustom1(getter_Copies(str)); SetCustom1(str); - PR_FREEIF(str); - srcCard->GetCustom2(&str); + srcCard->GetCustom2(getter_Copies(str)); SetCustom2(str); - PR_FREEIF(str); - srcCard->GetCustom3(&str); + srcCard->GetCustom3(getter_Copies(str)); SetCustom3(str); - PR_FREEIF(str); - srcCard->GetCustom4(&str); + srcCard->GetCustom4(getter_Copies(str)); SetCustom4(str); - PR_FREEIF(str); - srcCard->GetNotes(&str); + srcCard->GetNotes(getter_Copies(str)); SetNotes(str); - PR_FREEIF(str); PRUint32 tableID, rowID; srcCardDB->GetDbTableID(&tableID); @@ -473,19 +436,19 @@ static const char *kAbPrintUrlFormat = "addbook:printone?email=%s&folder=%s"; if (!aPrintCardUrl) return NS_OK; - PRUnichar *email = nsnull; - GetPrimaryEmail(&email); - nsString emailStr(email); + nsXPIDLString email; + GetPrimaryEmail(getter_Copies(email)); + nsAutoString emailStr(email); if (emailStr.Length() == 0) { *aPrintCardUrl = PR_smprintf(""); return NS_OK; } - PRUnichar *dirName = nsnull; + nsXPIDLString dirName; if (mCardDatabase) - mCardDatabase->GetDirectoryName(&dirName); - nsString dirNameStr(dirName); + mCardDatabase->GetDirectoryName(getter_Copies(dirName)); + nsAutoString dirNameStr(dirName); if (dirNameStr.Length() == 0) { *aPrintCardUrl = PR_smprintf(""); @@ -501,9 +464,6 @@ static const char *kAbPrintUrlFormat = "addbook:printone?email=%s&folder=%s"; nsMemory::Free(emailCharStr); nsMemory::Free(dirCharStr); - PR_FREEIF(dirName); - PR_FREEIF(email); - return NS_OK; } diff --git a/mailnews/addrbook/src/nsAbMDBDirectory.cpp b/mailnews/addrbook/src/nsAbMDBDirectory.cpp index 8c68e16992dc..0d319f468120 100644 --- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp +++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp @@ -343,7 +343,7 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result) { if (mURI && mIsMailingList == -1) { - nsString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); + nsAutoString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); PRInt32 pos = file.Find("/"); if (pos != -1) mIsMailingList = 1; @@ -648,7 +648,7 @@ NS_IMETHODIMP nsAbMDBDirectory::AddMailList(nsIAbDirectory *list) if (NS_SUCCEEDED(rv) && newList) { nsCOMPtr listener(do_QueryInterface(newList, &rv)); - NS_ENSURE_SUCCESS(rv, NS_ERROR_NULL_POINTER); + NS_ENSURE_SUCCESS(rv, rv); mDatabase->AddListener(listener); dbnewList->CopyDBMailList (dblist); @@ -715,7 +715,7 @@ NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* card, nsIAbCard **_retval) if (mURI && mIsMailingList == -1) { - nsString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); + nsAutoString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); PRInt32 pos = file.Find("/"); if (pos != -1) mIsMailingList = 1; @@ -792,20 +792,18 @@ NS_IMETHODIMP nsAbMDBDirectory::OnCardEntryChange NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - char* cardURI = nsnull; nsCOMPtr dbcard(do_QueryInterface(card, &rv)); NS_ENSURE_SUCCESS(rv, rv); if (!dbcard) return NS_ERROR_FAILURE; - rv = dbcard->GetCardURI(&cardURI); + nsXPIDLCString cardURI; + rv = dbcard->GetCardURI(getter_Copies(cardURI)); if (!cardURI) return NS_ERROR_NULL_POINTER; nsCOMPtr res; rv = rdf->GetResource(cardURI, getter_AddRefs(res)); - if(cardURI) - PR_smprintf_free(cardURI); if (NS_SUCCEEDED(rv)) { nsCOMPtr dbpersonCard = do_QueryInterface(res); @@ -816,7 +814,7 @@ NS_IMETHODIMP nsAbMDBDirectory::OnCardEntryChange { dbpersonCard->SetAbDatabase(mDatabase); nsCOMPtr listener(do_QueryInterface(dbpersonCard, &rv)); - NS_ENSURE_SUCCESS(rv, NS_ERROR_NULL_POINTER); + NS_ENSURE_SUCCESS(rv, rv); mDatabase->AddListener(listener); } nsCOMPtr cardSupports(do_QueryInterface(dbpersonCard)); diff --git a/mailnews/addrbook/src/nsAbMDBRDFResource.cpp b/mailnews/addrbook/src/nsAbMDBRDFResource.cpp index f905a440b1c7..e54c5d85fb88 100644 --- a/mailnews/addrbook/src/nsAbMDBRDFResource.cpp +++ b/mailnews/addrbook/src/nsAbMDBRDFResource.cpp @@ -95,7 +95,7 @@ nsresult nsAbMDBRDFResource::GetAbDatabase() if(NS_SUCCEEDED(rv)) abSession->GetUserProfileDirectory(&dbPath); - nsString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); + nsAutoString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); PRInt32 pos = file.Find("/"); if (pos != -1) file.Truncate(pos); diff --git a/mailnews/addrbook/src/nsAbRDFDataSource.cpp b/mailnews/addrbook/src/nsAbRDFDataSource.cpp index 5e941ea5d602..b1fbd3248a82 100644 --- a/mailnews/addrbook/src/nsAbRDFDataSource.cpp +++ b/mailnews/addrbook/src/nsAbRDFDataSource.cpp @@ -23,7 +23,7 @@ #include "nsAbRDFDataSource.h" #include "nsAbBaseCID.h" -#include "nsAbDirectory.h" +#include "nsIAbDirectory.h" #include "nsIAddrBookSession.h" #include "nsIAbCard.h" @@ -60,9 +60,9 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); nsresult nsAbRDFDataSource::createNode(nsString& str, nsIRDFNode **node) { *node = nsnull; - nsresult rv; - NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - if (NS_FAILED(rv)) return rv; // always check this before proceeding + nsresult rv; + NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); // always check this before proceeding nsCOMPtr value; rv = rdf->GetLiteral(str.GetUnicode(), getter_AddRefs(value)); if (NS_SUCCEEDED(rv)) @@ -177,7 +177,7 @@ nsresult nsAbRDFDataSource::Init() nsresult rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); mRDFService->RegisterDataSource(this, PR_FALSE); @@ -273,7 +273,7 @@ NS_IMETHODIMP nsAbRDFDataSource::AddObserver(nsIRDFObserver* n) if (! mObservers) { nsresult rv; rv = NS_NewISupportsArray(getter_AddRefs(mObservers)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } mObservers->AppendElement(n); return NS_OK; diff --git a/mailnews/addrbook/src/nsAbRDFResource.cpp b/mailnews/addrbook/src/nsAbRDFResource.cpp index 4d0972a95c8c..89f279982040 100644 --- a/mailnews/addrbook/src/nsAbRDFResource.cpp +++ b/mailnews/addrbook/src/nsAbRDFResource.cpp @@ -95,7 +95,7 @@ nsresult nsAbRDFResource::GetAbDatabase() if(NS_SUCCEEDED(rv)) abSession->GetUserProfileDirectory(&dbPath); - nsString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); + nsAutoString file; file.AssignWithConversion(&(mURI[PL_strlen(kDirectoryDataSourceRoot)])); PRInt32 pos = file.Find("/"); if (pos != -1) file.Truncate(pos); diff --git a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp index b8f532b4c786..7a2c628998d1 100644 --- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp +++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp @@ -37,6 +37,7 @@ #include "nsNetUtil.h" #include "nsIStringStream.h" #include "nsIAddrBookSession.h" +#include "nsIAbMDBCard.h" #include "nsIAbDirectory.h" #include "nsIRDFResource.h" #include "nsIRDFService.h" @@ -103,7 +104,7 @@ nsAddbookProtocolHandler::~nsAddbookProtocolHandler() mReportColumns = nsnull; } -NS_IMPL_ISUPPORTS1(nsAddbookProtocolHandler, nsIProtocolHandler) +NS_IMPL_ISUPPORTS1(nsAddbookProtocolHandler, nsIProtocolHandler); NS_METHOD nsAddbookProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -121,7 +122,7 @@ NS_IMETHODIMP nsAddbookProtocolHandler::GetScheme(char * *aScheme) { nsresult rv = NS_OK; if (aScheme) - *aScheme = PL_strdup("addbook"); + *aScheme = nsCRT::strdup("addbook"); else rv = NS_ERROR_NULL_POINTER; return rv; @@ -168,15 +169,12 @@ nsAddbookProtocolHandler::GenerateHTMLOutputChannel( char *aHtmlOutput, return NS_ERROR_FAILURE; rv = NS_NewStringInputStream(getter_AddRefs(s), NS_ConvertASCIItoUCS2(aHtmlOutput)); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); inStr = do_QueryInterface(s, &rv); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/html", aHtmlOutputSize); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); *_retval = channel; return rv; @@ -303,9 +301,12 @@ nsAddbookProtocolHandler::FindPossibleAbName(nsIAbCard *aCard, nsVoidArray *attrlist = nsnull; nsVoidArray *valuelist = nsnull; - if (NS_SUCCEEDED(aCard->GetAnonymousStrAttrubutesList(&attrlist)) && attrlist) + nsCOMPtr dbaCard(do_QueryInterface(aCard, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + if (NS_SUCCEEDED(dbaCard->GetAnonymousStrAttrubutesList(&attrlist)) && attrlist) { - if (NS_SUCCEEDED(aCard->GetAnonymousStrValuesList(&valuelist)) && valuelist) + if (NS_SUCCEEDED(dbaCard->GetAnonymousStrValuesList(&valuelist)) && valuelist) { char *attr = nsnull; @@ -402,8 +403,7 @@ nsAddbookProtocolHandler::GeneratePrintOutput(nsIAddbookUrl *addbookUrl, // Now, open the database...for now, make it the default rv = OpenAB(abFileName, &aDatabase); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); // RICHIE - this works for any address book...not sure why rv = rdfService->GetResource(kPersonalAddressbookUri, getter_AddRefs(resource)); @@ -452,7 +452,8 @@ nsAddbookProtocolHandler::BuildSingleHTML(nsIAddrDatabase *aDatabase, nsIAbDirec return NS_ERROR_FAILURE; nsresult rv = aDatabase->GetCardForEmailAddress(directory, charEmail, getter_AddRefs(workCard)); - if (NS_FAILED(rv) || (!workCard)) + NS_ENSURE_SUCCESS(rv, rv); + if (!workCard) return NS_ERROR_FAILURE; // Ok, build a little HTML for output... @@ -487,7 +488,8 @@ nsAddbookProtocolHandler::BuildAllHTML(nsIAddrDatabase *aDatabase, nsIAbDirector nsIEnumerator *cardEnum = nsnull; rv = aDatabase->EnumerateCards(directory, &cardEnum); - if (NS_FAILED(rv) || (!cardEnum)) + NS_ENSURE_SUCCESS(rv, rv); + if (!cardEnum) return NS_ERROR_FAILURE; InitPrintColumns(); diff --git a/mailnews/addrbook/src/nsAddrBookSession.cpp b/mailnews/addrbook/src/nsAddrBookSession.cpp index a5c9fb4266fc..214063a83b27 100644 --- a/mailnews/addrbook/src/nsAddrBookSession.cpp +++ b/mailnews/addrbook/src/nsAddrBookSession.cpp @@ -122,9 +122,9 @@ NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsFileSpec * *userDir) nsXPIDLCString pathBuf; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = profileDir->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *userDir = new nsFileSpec(pathBuf); NS_ENSURE_TRUE(*userDir, NS_ERROR_OUT_OF_MEMORY); diff --git a/mailnews/addrbook/src/nsAddrDatabase.cpp b/mailnews/addrbook/src/nsAddrDatabase.cpp index d651667f3563..ac6cde080365 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.cpp +++ b/mailnews/addrbook/src/nsAddrDatabase.cpp @@ -29,8 +29,9 @@ #include "nsString.h" #include "nsAbBaseCID.h" #include "nsIAbCard.h" +#include "nsIAbMDBCard.h" #include "nsIAbDirectory.h" -#include "nsAbCard.h" +#include "nsIAbMDBDirectory.h" #include "nsIAddrBookSession.h" #include "prmem.h" @@ -321,8 +322,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardAttribChange(PRUint32 abCode, nsIAddrDBL (nsIAddrDBListener *) m_ChangeListeners->ElementAt(i); nsresult rv = changeListener->OnCardAttribChange(abCode, instigator); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } @@ -339,7 +339,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard * (nsIAddrDBListener *) m_ChangeListeners->ElementAt(i); nsresult rv = changeListener->OnCardEntryChange(abCode, card, instigator); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } @@ -356,7 +356,7 @@ nsresult nsAddrDatabase::NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory * (nsIAddrDBListener *) m_ChangeListeners->ElementAt(i); nsresult rv = changeListener->OnListEntryChange(abCode, dir, instigator); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } @@ -364,8 +364,8 @@ nsresult nsAddrDatabase::NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory * NS_IMETHODIMP nsAddrDatabase::NotifyAnnouncerGoingAway(void) { - if (m_ChangeListeners == nsnull) - return NS_OK; + if (m_ChangeListeners == nsnull) + return NS_OK; // run loop backwards because listeners remove themselves from the list // on this notification PRInt32 i; @@ -375,10 +375,9 @@ NS_IMETHODIMP nsAddrDatabase::NotifyAnnouncerGoingAway(void) (nsIAddrDBListener *) m_ChangeListeners->ElementAt(i); nsresult rv = changeListener->OnAnnouncerGoingAway(this); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); } - return NS_OK; + return NS_OK; } @@ -637,7 +636,7 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) { nsIMdbThumb *thumb = nsnull; const char *pFilename = dbName->GetCString(); /* do not free */ - char *nativeFileName = PL_strdup(pFilename); + char *nativeFileName = nsCRT::strdup(pFilename); nsIMdbHeap* dbHeap = 0; mdb_bool dbFrozen = mdbBool_kFalse; // not readonly, we want modifiable @@ -683,7 +682,7 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) } } - PR_FREEIF(nativeFileName); + nsCRT::free(nativeFileName); if (NS_SUCCEEDED(ret) && thumb) { @@ -1129,11 +1128,11 @@ nsresult nsAddrDatabase::ConvertAndAddLowercaseColumn /* Chnage the unicode string to lowercase, then convert to UTF8 string to store in db */ -nsresult nsAddrDatabase::AddUnicodeToColumn(nsIMdbRow * row, mdb_token colToken, PRUnichar* pUnicodeStr) +nsresult nsAddrDatabase::AddUnicodeToColumn(nsIMdbRow * row, mdb_token colToken, const PRUnichar* pUnicodeStr) { nsresult err = NS_OK; nsAutoString displayString(pUnicodeStr); - char* pDisplayUTF8Str = displayString.ToNewUTF8String(); + char* pDisplayUTF8Str = displayString.ToNewUTF8String(); nsAutoString newUnicodeString(pUnicodeStr); newUnicodeString.ToLowerCase(); char* pUTF8Str = newUnicodeString.ToNewUTF8String(); @@ -1261,446 +1260,378 @@ nsresult nsAddrDatabase::AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *ca m_mdbPabTable->GetOid(GetEnv(), &tableOid); cardRow->GetOid(GetEnv(), &rowOid); - card->SetDbTableID(tableOid.mOid_Id); - card->SetDbRowID(rowOid.mOid_Id); - + nsCOMPtr dbcard(do_QueryInterface(card, &err)); + if(NS_SUCCEEDED(err) && dbcard) + { + dbcard->SetDbTableID(tableOid.mOid_Id); + dbcard->SetDbRowID(rowOid.mOid_Id); + } // add the row to the singleton table. - if (NS_SUCCEEDED(err) && cardRow) + if (card && cardRow) { - PRUnichar* pUnicodeStr = nsnull; + nsXPIDLString unicodeStr; PRInt32 unicharLength = 0; - char* pUTF8Str = nsnull; - card->GetFirstName(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + nsXPIDLCString utf8Str; + card->GetFirstName(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) + { + AddFirstName(cardRow, utf8Str); + } + } + card->GetLastName(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) + { + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddFirstName(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddLastName(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetLastName(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetDisplayName(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddLastName(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddDisplayName(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetDisplayName(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetNickName(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddDisplayName(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddNickName(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetNickName(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) - { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) - { - AddNickName(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); - } - } - PR_FREEIF(pUnicodeStr); - card->GetPrimaryEmail(&pUnicodeStr); - if (pUnicodeStr) - AddUnicodeToColumn(cardRow, m_PriEmailColumnToken, pUnicodeStr); - PR_FREEIF(pUnicodeStr); + card->GetPrimaryEmail(getter_Copies(unicodeStr)); + if (unicodeStr) + AddUnicodeToColumn(cardRow, m_PriEmailColumnToken, unicodeStr); - card->GetSecondEmail(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetSecondEmail(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - Add2ndEmail(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + Add2ndEmail(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); PRUint32 format = nsIAbPreferMailFormat::unknown; card->GetPreferMailFormat(&format); AddPreferMailFormat(cardRow, format); - card->GetWorkPhone(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkPhone(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkPhone(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkPhone(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomePhone(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomePhone(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomePhone(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomePhone(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetFaxNumber(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetFaxNumber(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddFaxNumber(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddFaxNumber(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetPagerNumber(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetPagerNumber(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddPagerNumber(cardRow,pUTF8Str); - PR_FREEIF(pUTF8Str); + AddPagerNumber(cardRow,utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetCellularNumber(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetCellularNumber(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddCellularNumber(cardRow,pUTF8Str); - PR_FREEIF(pUTF8Str); + AddCellularNumber(cardRow,utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomeAddress(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomeAddress(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomeAddress(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomeAddress(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomeAddress2(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomeAddress2(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomeAddress2(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomeAddress2(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomeCity(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomeCity(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomeCity(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomeCity(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomeState(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomeState(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomeState(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomeState(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomeZipCode(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomeZipCode(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomeZipCode(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomeZipCode(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetHomeCountry(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetHomeCountry(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddHomeCountry(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddHomeCountry(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWorkAddress(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkAddress(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkAddress(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkAddress(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWorkAddress2(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkAddress2(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkAddress2(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkAddress2(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWorkCity(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkCity(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkCity(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkCity(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWorkState(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkState(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkState(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkState(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWorkZipCode(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkZipCode(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkZipCode(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkZipCode(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWorkCountry(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWorkCountry(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWorkCountry(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWorkCountry(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetJobTitle(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetJobTitle(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddJobTitle(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddJobTitle(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetDepartment(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetDepartment(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddDepartment(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddDepartment(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetCompany(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetCompany(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddCompany(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddCompany(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWebPage1(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWebPage1(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWebPage1(cardRow,pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWebPage1(cardRow,utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetWebPage2(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetWebPage2(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddWebPage2(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddWebPage2(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetBirthYear(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetBirthYear(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddBirthYear(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddBirthYear(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetBirthMonth(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetBirthMonth(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddBirthMonth(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddBirthMonth(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetBirthDay(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetBirthDay(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddBirthDay(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddBirthDay(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetCustom1(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetCustom1(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddCustom1(cardRow,pUTF8Str); - PR_FREEIF(pUTF8Str); + AddCustom1(cardRow,utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetCustom2(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetCustom2(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddCustom2(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddCustom2(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetCustom3(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetCustom3(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddCustom3(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddCustom3(cardRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - card->GetCustom4(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetCustom4(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) - { - AddCustom4(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); - } + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) + { + AddCustom4(cardRow, utf8Str); + } } - PR_FREEIF(pUnicodeStr); - card->GetNotes(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + card->GetNotes(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) - { - AddNotes(cardRow, pUTF8Str); - PR_FREEIF(pUTF8Str); - } + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) + { + AddNotes(cardRow, utf8Str); + } } - PR_FREEIF(pUnicodeStr); } return NS_OK; } @@ -1780,13 +1711,13 @@ nsresult nsAddrDatabase::AddListCardColumnsToRow return NS_ERROR_NULL_POINTER; nsresult err = NS_OK; - PRUnichar *email = nsnull; - pCard->GetPrimaryEmail(&email); + nsXPIDLString email; + pCard->GetPrimaryEmail(getter_Copies(email)); PRInt32 emailLength = nsCRT::strlen(email); if (email) { - char* pUTF8Email = nsnull; - INTL_ConvertFromUnicode(email, emailLength, (char**)&pUTF8Email); + nsXPIDLCString pUTF8Email; + INTL_ConvertFromUnicode(email, emailLength, getter_Copies(pUTF8Email)); if (pUTF8Email) { nsIMdbRow *pCardRow = nsnull; @@ -1844,7 +1775,6 @@ nsresult nsAddrDatabase::AddListCardColumnsToRow } } } - PR_FREEIF(pUTF8Email); if (!pCardRow) return NS_ERROR_NULL_POINTER; @@ -1866,7 +1796,6 @@ nsresult nsAddrDatabase::AddListCardColumnsToRow pCardRow->CutStrongRef(GetEnv()); } } - PR_FREEIF(email); return NS_OK; } @@ -1882,45 +1811,42 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM m_mdbPabTable->GetOid(GetEnv(), &tableOid); listRow->GetOid(GetEnv(), &rowOid); - list->SetDbRowID(rowOid.mOid_Id); + nsCOMPtr dblist(do_QueryInterface(list,&err)); + if (NS_SUCCEEDED(err)) + dblist->SetDbRowID(rowOid.mOid_Id); // add the row to the singleton table. if (NS_SUCCEEDED(err) && listRow) { - PRUnichar* pUnicodeStr = nsnull; + nsXPIDLString unicodeStr; PRInt32 unicharLength = 0; - char* pUTF8Str = nsnull; + nsXPIDLCString utf8Str; - list->GetListName(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) - AddUnicodeToColumn(listRow, m_ListNameColumnToken, pUnicodeStr); - PR_FREEIF(pUnicodeStr); + list->GetListName(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) + AddUnicodeToColumn(listRow, m_ListNameColumnToken, unicodeStr); - list->GetListNickName(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + list->GetListNickName(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddListNickName(listRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddListNickName(listRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); - list->GetDescription(&pUnicodeStr); - unicharLength = nsCRT::strlen(pUnicodeStr); - if (pUnicodeStr) + list->GetDescription(getter_Copies(unicodeStr)); + unicharLength = nsCRT::strlen(unicodeStr); + if (unicodeStr) { - INTL_ConvertFromUnicode(pUnicodeStr, unicharLength, (char**)&pUTF8Str); - if (pUTF8Str) + INTL_ConvertFromUnicode(unicodeStr, unicharLength, getter_Copies(utf8Str)); + if (utf8Str) { - AddListDescription(listRow, pUTF8Str); - PR_FREEIF(pUTF8Str); + AddListDescription(listRow, utf8Str); } } - PR_FREEIF(pUnicodeStr); nsISupportsArray* pAddressLists; list->GetAddressLists(&pAddressLists); @@ -1928,6 +1854,7 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM PRUint32 count; pAddressLists->Count(&count); + nsXPIDLString email; PRUint32 i, total; total = 0; for (i = 0; i < count; i++) @@ -1938,12 +1865,10 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM if (NS_FAILED(err)) continue; - PRUnichar *email = nsnull; - pCard->GetPrimaryEmail(&email); + pCard->GetPrimaryEmail(getter_Copies(email)); PRInt32 emailLength = nsCRT::strlen(email); if (email && emailLength) total++; - PR_FREEIF(email); } SetListAddressTotal(listRow, total); @@ -1956,8 +1881,7 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM if (NS_FAILED(err)) continue; pos = i + 1; - PRUnichar *email = nsnull; - pCard->GetPrimaryEmail(&email); + pCard->GetPrimaryEmail(getter_Copies(email)); PRInt32 emailLength = nsCRT::strlen(email); if (email && emailLength) { @@ -1966,7 +1890,6 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM if (pNewCard) pAddressLists->ReplaceElementAt(pNewCard, i); } - PR_FREEIF(email); } } return NS_OK; @@ -1993,7 +1916,7 @@ nsresult nsAddrDatabase::GetAddressRowByPos(nsIMdbRow* listRow, PRUint16 pos, ns sprintf(columnStr, kMailListAddressFormat, pos); GetStore()->StringToToken(GetEnv(), columnStr, &listAddressColumnToken); - nsAutoString tempString; + nsAutoString tempString; mdb_id rowID; nsresult err = GetIntColumn(listRow, listAddressColumnToken, (PRUint32*)&rowID, 0); if (NS_SUCCEEDED(err)) @@ -2248,8 +2171,8 @@ nsresult nsAddrDatabase::DoAnonymousAttributesTransaction(AB_NOTIFY_CODE code) if (!m_mdbAnonymousTable) err = InitAnonymousTable(); - - if (NS_FAILED(err) || !m_mdbAnonymousTable) + NS_ENSURE_SUCCESS(err, err); + if (!m_mdbAnonymousTable) return NS_ERROR_FAILURE; DoStringAnonymousTransaction(m_pAnonymousStrAttributes, m_pAnonymousStrValues, code); @@ -2263,18 +2186,23 @@ nsresult nsAddrDatabase::DoAnonymousAttributesTransaction(AB_NOTIFY_CODE code) void nsAddrDatabase::GetAnonymousAttributesFromCard(nsIAbCard* card) { nsresult err = NS_OK; - RemoveAnonymousList(m_pAnonymousStrAttributes); - RemoveAnonymousList(m_pAnonymousStrValues); - RemoveAnonymousList(m_pAnonymousIntAttributes); - RemoveAnonymousList(m_pAnonymousIntValues); - RemoveAnonymousList(m_pAnonymousBoolAttributes); - RemoveAnonymousList(m_pAnonymousBoolValues); - err = card->GetAnonymousStrAttrubutesList(&m_pAnonymousStrAttributes); - err = card->GetAnonymousStrValuesList(&m_pAnonymousStrValues); - err = card->GetAnonymousIntAttrubutesList(&m_pAnonymousIntAttributes); - err = card->GetAnonymousIntValuesList(&m_pAnonymousIntValues); - err = card->GetAnonymousBoolAttrubutesList(&m_pAnonymousBoolAttributes); - err = card->GetAnonymousBoolValuesList(&m_pAnonymousBoolValues); + + nsCOMPtr dbcard(do_QueryInterface(card, &err)); + if(NS_SUCCEEDED(err) && dbcard) + { + RemoveAnonymousList(m_pAnonymousStrAttributes); + RemoveAnonymousList(m_pAnonymousStrValues); + RemoveAnonymousList(m_pAnonymousIntAttributes); + RemoveAnonymousList(m_pAnonymousIntValues); + RemoveAnonymousList(m_pAnonymousBoolAttributes); + RemoveAnonymousList(m_pAnonymousBoolValues); + err = dbcard->GetAnonymousStrAttrubutesList(&m_pAnonymousStrAttributes); + err = dbcard->GetAnonymousStrValuesList(&m_pAnonymousStrValues); + err = dbcard->GetAnonymousIntAttrubutesList(&m_pAnonymousIntAttributes); + err = dbcard->GetAnonymousIntValuesList(&m_pAnonymousIntValues); + err = dbcard->GetAnonymousBoolAttrubutesList(&m_pAnonymousBoolAttributes); + err = dbcard->GetAnonymousBoolValuesList(&m_pAnonymousBoolValues); + } } NS_IMETHODIMP nsAddrDatabase::AddAnonymousAttributesFromCard(nsIAbCard* card) @@ -2356,7 +2284,12 @@ NS_IMETHODIMP nsAddrDatabase::DeleteCard(nsIAbCard *card, PRBool notify) rowOid.mOid_Scope = m_ListRowScopeToken; else rowOid.mOid_Scope = m_CardRowScopeToken; - card->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + + nsCOMPtr dbcard(do_QueryInterface(card, &err)); + NS_ENSURE_SUCCESS(err, err); + + dbcard->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + err = GetStore()->GetRow(GetEnv(), &rowOid, &pCardRow); if (pCardRow) { @@ -2370,8 +2303,7 @@ NS_IMETHODIMP nsAddrDatabase::DeleteCard(nsIAbCard *card, PRBool notify) { nsCOMPtr listener(do_QueryInterface(card, &err)); - if (NS_FAILED(err)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(err, err); RemoveListener(listener); if (notify) @@ -2440,20 +2372,29 @@ NS_IMETHODIMP nsAddrDatabase::DeleteCardFromMailList(nsIAbDirectory *mailList, n nsIMdbRow* pListRow = nsnull; mdbOid listRowOid; listRowOid.mOid_Scope = m_ListRowScopeToken; - mailList->GetDbRowID((PRUint32*)&listRowOid.mOid_Id); + + nsCOMPtr dbmailList(do_QueryInterface(mailList,&err)); + if(NS_FAILED(err)) + return NS_ERROR_NULL_POINTER; + dbmailList->GetDbRowID((PRUint32*)&listRowOid.mOid_Id); + err = GetStore()->GetRow(GetEnv(), &listRowOid, &pListRow); if (pListRow) { PRUint32 cardRowID; - card->GetDbRowID(&cardRowID); + + nsCOMPtr dbcard(do_QueryInterface(card, &err)); + if(NS_FAILED(err) || !dbcard) + return NS_ERROR_NULL_POINTER; + dbcard->GetDbRowID(&cardRowID); + err = DeleteCardFromListRow(pListRow, cardRowID); if (NS_SUCCEEDED(err)) { nsCOMPtr listener(do_QueryInterface(card, &err)); - if (NS_FAILED(err)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(err, err); RemoveListener(listener); if (beNotify) @@ -2474,11 +2415,15 @@ NS_IMETHODIMP nsAddrDatabase::EditCard(nsIAbCard *card, PRBool notify) nsIMdbRow* pCardRow = nsnull; mdbOid rowOid; rowOid.mOid_Scope = m_CardRowScopeToken; - card->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + + nsCOMPtr dbcard(do_QueryInterface(card, &err)); + NS_ENSURE_SUCCESS(err, err); + dbcard->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + err = GetStore()->GetRow(GetEnv(), &rowOid, &pCardRow); if (pCardRow) err = AddAttributeColumnsToRow(card, pCardRow); - if (NS_FAILED(err)) return err; + NS_ENSURE_SUCCESS(err, err); if (notify) NotifyCardEntryChange(AB_NotifyPropertyChanged, card, NULL); @@ -2499,15 +2444,21 @@ NS_IMETHODIMP nsAddrDatabase::ContainsCard(nsIAbCard *card, PRBool *hasCard) PRBool bIsMailList; card->GetIsMailList(&bIsMailList); - + if (bIsMailList) rowOid.mOid_Scope = m_ListRowScopeToken; else rowOid.mOid_Scope = m_CardRowScopeToken; - card->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + + nsCOMPtr dbcard(do_QueryInterface(card, &err)); + NS_ENSURE_SUCCESS(err, err); + dbcard->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + err = m_mdbPabTable->HasOid(GetEnv(), &rowOid, &hasOid); if (NS_SUCCEEDED(err)) + { *hasCard = hasOid; + } return err; } @@ -2523,7 +2474,11 @@ NS_IMETHODIMP nsAddrDatabase::DeleteMailList(nsIAbDirectory *mailList, PRBool no nsIMdbRow* pListRow = nsnull; mdbOid rowOid; rowOid.mOid_Scope = m_ListRowScopeToken; - mailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + + nsCOMPtr dbmailList(do_QueryInterface(mailList,&err)); + NS_ENSURE_SUCCESS(err, err); + dbmailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + err = GetStore()->GetRow(GetEnv(), &rowOid, &pListRow); if (pListRow) { @@ -2533,8 +2488,7 @@ NS_IMETHODIMP nsAddrDatabase::DeleteMailList(nsIAbDirectory *mailList, PRBool no { nsCOMPtr listener(do_QueryInterface(mailList, &err)); - if (NS_FAILED(err)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(err, err); RemoveListener(listener); } pListRow->CutStrongRef(GetEnv()); @@ -2552,13 +2506,17 @@ NS_IMETHODIMP nsAddrDatabase::EditMailList(nsIAbDirectory *mailList, PRBool noti nsIMdbRow* pListRow = nsnull; mdbOid rowOid; rowOid.mOid_Scope = m_ListRowScopeToken; - mailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + + nsCOMPtr dbmailList(do_QueryInterface(mailList,&err)); + NS_ENSURE_SUCCESS(err, err); + dbmailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + err = GetStore()->GetRow(GetEnv(), &rowOid, &pListRow); if (pListRow) { err = AddListAttributeColumnsToRow(mailList, pListRow); } - if (NS_FAILED(err)) return err; + NS_ENSURE_SUCCESS(err, err); if (notify) { @@ -2600,7 +2558,11 @@ NS_IMETHODIMP nsAddrDatabase::ContainsMailList(nsIAbDirectory *mailList, PRBool mdbOid rowOid; rowOid.mOid_Scope = m_ListRowScopeToken; - mailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + + nsCOMPtr dbmailList(do_QueryInterface(mailList,&err)); + NS_ENSURE_SUCCESS(err, err); + dbmailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id); + err = m_mdbPabTable->HasOid(GetEnv(), &rowOid, &hasOid); if (err == NS_OK) *hasList = hasOid; @@ -2896,8 +2858,8 @@ NS_IMETHODIMP nsAddrDatabase::SetAnonymousStringAttribute { nsresult rv = NS_OK; - char* pAttribute = PL_strdup(attrname); - char* pValue = PL_strdup(value); + char* pAttribute = nsCRT::strdup(attrname); + char* pValue = nsCRT::strdup(value); if (pAttribute && pValue) { rv = SetAnonymousAttribute(&m_pAnonymousStrAttributes, @@ -2905,8 +2867,8 @@ NS_IMETHODIMP nsAddrDatabase::SetAnonymousStringAttribute } else { - PR_FREEIF(pAttribute); - PR_FREEIF(pValue); + nsCRT::free(pAttribute); + nsCRT::free(pValue); rv = NS_ERROR_NULL_POINTER; } return rv; @@ -2917,7 +2879,7 @@ NS_IMETHODIMP nsAddrDatabase::SetAnonymousIntAttribute { nsresult rv = NS_OK; - char* pAttribute = PL_strdup(attrname); + char* pAttribute = nsCRT::strdup(attrname); PRUint32* pValue = (PRUint32 *)PR_Calloc(1, sizeof(PRUint32)); *pValue = value; if (pAttribute && pValue) @@ -2927,7 +2889,7 @@ NS_IMETHODIMP nsAddrDatabase::SetAnonymousIntAttribute } else { - PR_FREEIF(pAttribute); + nsCRT::free(pAttribute); PR_FREEIF(pValue); rv = NS_ERROR_NULL_POINTER; } @@ -2939,7 +2901,7 @@ NS_IMETHODIMP nsAddrDatabase::SetAnonymousBoolAttribute { nsresult rv = NS_OK; - char* pAttribute = PL_strdup(attrname); + char* pAttribute = nsCRT::strdup(attrname); PRBool* pValue = (PRBool *)PR_Calloc(1, sizeof(PRBool)); *pValue = value; if (pAttribute && pValue) @@ -2949,7 +2911,7 @@ NS_IMETHODIMP nsAddrDatabase::SetAnonymousBoolAttribute } else { - PR_FREEIF(pAttribute); + nsCRT::free(pAttribute); PR_FREEIF(pValue); rv = NS_ERROR_NULL_POINTER; } @@ -2980,8 +2942,8 @@ NS_IMETHODIMP nsAddrDatabase::GetAnonymousStringAttribute(const char *attrname, err = GetStringColumn(cardRow, anonymousColumnToken, tempString); if (NS_SUCCEEDED(err) && tempString.Length()) { - tempCString = tempString.ToNewUTF8String(); - *value = PL_strdup(tempCString); + tempCString = tempString.ToNewUTF8String(); + *value = nsCRT::strdup(tempCString); Recycle(tempCString); return NS_OK; } @@ -3097,22 +3059,22 @@ value is UTF8 string, need to convert back to lowercase unicode then back to UTF8 string */ nsresult nsAddrDatabase::AddLowercaseColumn -(nsIMdbRow * row, mdb_token columnToken, const char* utf8String) +(nsIMdbRow * row, mdb_token columnToken, const char* utf8Str) { nsresult err = NS_OK; - if (utf8String) + if (utf8Str) { PRUnichar *unicodeStr = nsnull; - INTL_ConvertToUnicode((const char *)utf8String, nsCRT::strlen(utf8String), (void**)&unicodeStr); + INTL_ConvertToUnicode((const char *)utf8Str, nsCRT::strlen(utf8Str), (void**)&unicodeStr); if (unicodeStr) { nsAutoString newUnicodeString(unicodeStr); newUnicodeString.ToLowerCase(); - char * pUTF8Str = newUnicodeString.ToNewUTF8String(); - if (pUTF8Str) + char * utf8Str = newUnicodeString.ToNewUTF8String(); + if (utf8Str) { - err = AddCharStringColumn(row, columnToken, pUTF8Str); - Recycle(pUTF8Str); + err = AddCharStringColumn(row, columnToken, utf8Str); + Recycle(utf8Str); } PR_FREEIF(unicodeStr); } @@ -3126,7 +3088,7 @@ nsresult nsAddrDatabase::GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow) if (!newCard || !cardRow) return NS_ERROR_NULL_POINTER; - nsAutoString tempString; + nsAutoString tempString; err = GetStringColumn(cardRow, m_FirstNameColumnToken, tempString); if (NS_SUCCEEDED(err) && tempString.Length()) @@ -3351,7 +3313,11 @@ nsresult nsAddrDatabase::GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow) PRUint32 key = 0; err = GetIntColumn(cardRow, m_RecordKeyColumnToken, &key, 0); if (NS_SUCCEEDED(err)) - newCard->SetRecordKey(key); + { + nsCOMPtr dbnewCard(do_QueryInterface(newCard, &err)); + if (NS_SUCCEEDED(err) && dbnewCard) + dbnewCard->SetRecordKey(key); + } return err; } @@ -3383,7 +3349,11 @@ nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* listR PRUint32 key = 0; err = GetIntColumn(listRow, m_RecordKeyColumnToken, &key, 0); if (NS_SUCCEEDED(err)) - listCard->SetRecordKey(key); + { + nsCOMPtr dblistCard(do_QueryInterface(listCard, &err)); + if (NS_SUCCEEDED(err) && dblistCard) + dblistCard->SetRecordKey(key); + } return err; } @@ -3430,7 +3400,11 @@ nsresult nsAddrDatabase::GetListFromDB(nsIAbDirectory *newList, nsIMdbRow* listR { nsCOMPtr card; err = CreateABCard(cardRow, getter_AddRefs(card)); - newList->AddAddressToList(card); + + nsCOMPtr + dbnewList(do_QueryInterface(newList, &err)); + if(NS_SUCCEEDED(err)) + dbnewList->AddAddressToList(card); } // NS_IF_ADDREF(card); } @@ -3724,15 +3698,23 @@ NS_IMETHODIMP nsAddrDatabase::GetMailingListsFromDB(nsIAbDirectory *parentDir) NS_IMETHODIMP nsAddrDatabase::EnumerateListAddresses(nsIAbDirectory *directory, nsIEnumerator **result) { - mdb_id rowID; - directory->GetDbRowID((PRUint32*)&rowID); + nsresult rv = NS_OK; + mdb_id rowID; + + nsCOMPtr dbdirectory(do_QueryInterface(directory,&rv)); + + if(NS_SUCCEEDED(rv)) + { + dbdirectory->GetDbRowID((PRUint32*)&rowID); + nsListAddressEnumerator* e = new nsListAddressEnumerator(this, rowID); m_dbDirectory = directory; if (e == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(e); *result = e; - return NS_OK; + } + return rv; } nsresult nsAddrDatabase::CreateCard(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result) @@ -3755,23 +3737,30 @@ nsresult nsAddrDatabase::CreateCard(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbC cardURI = PR_smprintf("%s%s/MailList%ld/Card%ld", kCardDataSourceRoot, file, listRowID, rowID); else cardURI = PR_smprintf("%s%s/Card%ld", kCardDataSourceRoot, file, rowID); + nsCOMPtr personCard; - rv = m_dbDirectory->AddChildCards(cardURI, getter_AddRefs(personCard)); - if (personCard) + nsCOMPtr dbm_dbDirectory(do_QueryInterface(m_dbDirectory,&rv)); + if (NS_SUCCEEDED(rv) && dbm_dbDirectory) + rv = dbm_dbDirectory->AddChildCards(cardURI, getter_AddRefs(personCard)); + + nsCOMPtr dbpersonCard (do_QueryInterface(personCard, &rv)); + + if (NS_SUCCEEDED(rv) && dbpersonCard) { GetCardFromDB(personCard, cardRow); mdbOid tableOid; m_mdbPabTable->GetOid(GetEnv(), &tableOid); - personCard->SetDbTableID(tableOid.mOid_Id); - personCard->SetDbRowID(rowID); - personCard->SetAbDatabase(this); + + dbpersonCard->SetDbTableID(tableOid.mOid_Id); + dbpersonCard->SetDbRowID(rowID); + dbpersonCard->SetAbDatabase(this); nsCOMPtr listener(do_QueryInterface(personCard, &rv)); - if (NS_FAILED(rv)) - return NS_ERROR_NULL_POINTER; - + NS_ENSURE_SUCCESS(rv, rv); + AddListener(listener); } + *result = personCard; NS_IF_ADDREF(*result); @@ -3802,6 +3791,7 @@ nsresult nsAddrDatabase::CreateABCardInList(nsIMdbRow* cardRow, nsIAbCard **resu /* create a card for mailing list in the address book */ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result) { + nsresult rv = NS_OK; mdbOid outOid; @@ -3810,39 +3800,50 @@ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result if (listRow->GetOid(GetEnv(), &outOid) == NS_OK) rowID = outOid.mOid_Id; - if(NS_SUCCEEDED(rv)) - { - char* cardURI = nsnull; - char* file = nsnull; + char* cardURI = nsnull; + char* listURI = nsnull; + char* file = nsnull; + file = m_dbName.GetLeafName(); + cardURI = PR_smprintf("%s%s/ListCard%ld", kCardDataSourceRoot, file, rowID); + listURI = PR_smprintf("%s%s/MailList%ld", kDirectoryDataSourceRoot, file, rowID); + + nsCOMPtr personCard; + nsCOMPtr dbm_dbDirectory(do_QueryInterface(m_dbDirectory, &rv)); + if(NS_SUCCEEDED(rv) && dbm_dbDirectory) + { + rv = dbm_dbDirectory->AddChildCards(cardURI, getter_AddRefs(personCard)); - file = m_dbName.GetLeafName(); - cardURI = PR_smprintf("%s%s/ListCard%ld", kCardDataSourceRoot, file, rowID); - nsCOMPtr personCard; - rv = m_dbDirectory->AddChildCards(cardURI, getter_AddRefs(personCard)); if (personCard) { GetListCardFromDB(personCard, listRow); mdbOid tableOid; m_mdbPabTable->GetOid(GetEnv(), &tableOid); - personCard->SetDbTableID(tableOid.mOid_Id); - personCard->SetDbRowID(rowID); - personCard->SetAbDatabase(this); + + nsCOMPtr dbpersonCard(do_QueryInterface(personCard, &rv)); + if (NS_SUCCEEDED(rv) && dbpersonCard) + { + dbpersonCard->SetDbTableID(tableOid.mOid_Id); + dbpersonCard->SetDbRowID(rowID); + dbpersonCard->SetAbDatabase(this); + } personCard->SetIsMailList(PR_TRUE); + personCard->SetMailListURI(listURI); nsCOMPtr listener(do_QueryInterface(personCard, &rv)); - if (NS_FAILED(rv)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(rv, rv); AddListener(listener); } + *result = personCard; NS_IF_ADDREF(*result); - - if (file) - nsCRT::free(file); - if (cardURI) - PR_smprintf_free(cardURI); } + if (file) + nsCRT::free(file); + if (cardURI) + PR_smprintf_free(cardURI); + if (listURI) + PR_smprintf_free(listURI); return rv; } @@ -3861,38 +3862,43 @@ nsresult nsAddrDatabase::CreateABList(nsIMdbRow* listRow, nsIAbDirectory **resul if (listRow->GetOid(GetEnv(), &outOid) == NS_OK) rowID = outOid.mOid_Id; - if(NS_SUCCEEDED(rv)) - { - char* listURI = nsnull; - char* file = nsnull; + char* listURI = nsnull; + char* file = nsnull; + + file = m_dbName.GetLeafName(); + listURI = PR_smprintf("%s%s/MailList%ld", kDirectoryDataSourceRoot, file, rowID); + + nsCOMPtr mailList; + nsCOMPtr dbm_dbDirectory(do_QueryInterface(m_dbDirectory, &rv)); + if(NS_SUCCEEDED(rv) && dbm_dbDirectory) + { + rv = dbm_dbDirectory->AddDirectory(listURI, getter_AddRefs(mailList)); + + nsCOMPtr dbmailList (do_QueryInterface(mailList, &rv)); - file = m_dbName.GetLeafName(); - listURI = PR_smprintf("%s%s/MailList%ld", kDirectoryDataSourceRoot, file, rowID); - nsCOMPtr mailList; - rv = m_dbDirectory->AddDirectory(listURI, getter_AddRefs(mailList)); if (mailList) - { + { GetListFromDB(mailList, listRow); - mailList->SetDbRowID(rowID); + dbmailList->SetDbRowID(rowID); mailList->SetIsMailList(PR_TRUE); nsCOMPtr listener(do_QueryInterface(mailList, &rv)); - if (NS_FAILED(rv)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(rv, rv); + AddListener(listener); - m_dbDirectory->AddMailListToDirectory(mailList); + dbm_dbDirectory->AddMailListToDirectory(mailList); *result = mailList; NS_IF_ADDREF(*result); } - - if (file) - nsCRT::free(file); - if (listURI) - PR_smprintf_free(listURI); } + if (file) + nsCRT::free(file); + if (listURI) + PR_smprintf_free(listURI); + return rv; } @@ -3966,7 +3972,7 @@ nsresult nsAddrDatabase::GetCollationKeyGenerator() nsCOMPtr locale; NS_WITH_SERVICE(nsILocaleService, localeSvc, kLocaleServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale)); if (NS_SUCCEEDED(rv) && locale) @@ -3974,7 +3980,8 @@ nsresult nsAddrDatabase::GetCollationKeyGenerator() nsCOMPtr factory; rv = nsComponentManager::CreateInstance(kCollationFactoryCID, NULL, - NS_GET_IID(nsICollationFactory), getter_AddRefs(factory)); + NS_GET_IID(nsICollationFactory), + getter_AddRefs(factory)); if (NS_SUCCEEDED(rv) && factory) { rv = factory->CreateCollation(locale, getter_AddRefs(m_collationKeyGenerator)); @@ -4031,9 +4038,8 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow) nsresult rv = NS_OK; NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv); - if (NS_FAILED(rv)) { - return rv; - } + NS_ENSURE_SUCCESS(rv, rv); + NS_WITH_PROXIED_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, NS_UI_THREAD_EVENTQ, &rv); if (NS_SUCCEEDED(rv)) { @@ -4051,14 +4057,18 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow) nsCOMPtr mailList; rv = CreateABList(listRow, getter_AddRefs(mailList)); if (mailList) - parentDir->NotifyDirItemAdded(mailList); + { + nsCOMPtr dbparentDir(do_QueryInterface(parentDir, &rv)); + if(NS_SUCCEEDED(rv)) + dbparentDir->NotifyDirItemAdded(mailList); + } } if (parentUri) PR_smprintf_free(parentUri); if (file) nsCRT::free(file); } - return NS_OK; + return rv; } NS_IMETHODIMP nsAddrDatabase::FindMailListbyUnicodeName(const PRUnichar *listName, PRBool *exist) @@ -4197,8 +4207,7 @@ NS_IMETHODIMP nsAddrDatabase::RemoveExtraCardsInCab(PRUint32 cardTotal, PRUint32 if (card) { nsCOMPtr listener(do_QueryInterface(card, &err)); - if (NS_FAILED(err)) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(err, err); RemoveListener(listener); NotifyCardEntryChange(AB_NotifyDeleted, card, NULL); diff --git a/mailnews/addrbook/src/nsAddrDatabase.h b/mailnews/addrbook/src/nsAddrDatabase.h index c4e7298335e3..fcf8980ec3c5 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.h +++ b/mailnews/addrbook/src/nsAddrDatabase.h @@ -342,7 +342,7 @@ protected: nsresult CheckAndUpdateRecordKey(); nsresult UpdateLowercaseEmailListName(); nsresult ConvertAndAddLowercaseColumn(nsIMdbRow * row, mdb_token fromCol, mdb_token toCol); - nsresult AddUnicodeToColumn(nsIMdbRow * row, mdb_token colToken, PRUnichar* pUnicodeStr); + nsresult AddUnicodeToColumn(nsIMdbRow * row, mdb_token colToken, const PRUnichar* pUnicodeStr); nsresult GetRowForCharColumn(const char *lowerUTF8String, mdb_column findColumn, PRBool bIsCard, nsIMdbRow **findRow); nsresult GetRowForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index 8fc62f839355..5052a52e5fe2 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -26,7 +26,7 @@ #include "nsAbBaseCID.h" #include "nsDirPrefs.h" #include "nsIAddrBookSession.h" -#include "nsAbRDFResource.h" +// #include "nsAbRDFResource.h" #include "nsIAddrDatabase.h" #include "plstr.h" @@ -59,14 +59,15 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID); static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID); -static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID); +// static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID); static NS_DEFINE_CID(kAbCardPropertyCID, NS_ABCARDPROPERTY_CID); static NS_DEFINE_CID(kAB4xUpgraderServiceCID, NS_AB4xUPGRADER_CID); const char *kDirectoryDataSourceRoot = kDirectoryRoot; const char *kCardDataSourceRoot = kCardRoot; - +//use this for creating new address book or directory +static const char *kBSDDirectoryRoot = "abdirectory://"; static nsresult ConvertDOMListToResourceArray(nsIDOMNodeList *nodeList, nsISupportsArray **resourceArray) { @@ -142,23 +143,16 @@ NS_IMETHODIMP nsAddressBook::DeleteCards nsCOMPtr resource; rv = srcDirectory->GetResource(getter_AddRefs(resource)); - - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = tree->GetDatabase(getter_AddRefs(database)); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = ConvertDOMListToResourceArray(nodeList, getter_AddRefs(resourceArray)); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewISupportsArray(getter_AddRefs(dirArray)); - if(NS_FAILED(rv)) - { - return NS_ERROR_OUT_OF_MEMORY; - } + NS_ENSURE_SUCCESS(rv, rv); dirArray->AppendElement(resource); @@ -168,42 +162,27 @@ NS_IMETHODIMP nsAddressBook::DeleteCards } NS_IMETHODIMP nsAddressBook::NewAddressBook -(nsIRDFCompositeDataSource* db, nsIDOMXULElement *srcDirectory, const PRUnichar *name) +(nsIRDFCompositeDataSource* db, nsIDOMXULElement *srcDirectory, PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue) { - if(!db || !srcDirectory || !name) + if(!db || !srcDirectory || !*prefName || !*prefValue) return NS_ERROR_NULL_POINTER; nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if(NS_FAILED(rv)) - return rv; - - nsCOMPtr nameArray, dirArray; - - rv = NS_NewISupportsArray(getter_AddRefs(dirArray)); - if(NS_FAILED(rv)) - return NS_ERROR_OUT_OF_MEMORY; + NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr parentResource; - char *parentUri = PR_smprintf("%s", kDirectoryDataSourceRoot); + char *parentUri = PR_smprintf("%s", kBSDDirectoryRoot); rv = rdfService->GetResource(parentUri, getter_AddRefs(parentResource)); - nsCOMPtr parentDir = do_QueryInterface(parentResource); - if (!parentDir) - return NS_ERROR_NULL_POINTER; if (parentUri) PR_smprintf_free(parentUri); - dirArray->AppendElement(parentResource); + NS_ENSURE_SUCCESS(rv, rv); - rv = NS_NewISupportsArray(getter_AddRefs(nameArray)); - if(NS_FAILED(rv)) - return NS_ERROR_OUT_OF_MEMORY; - nsString nameStr(name); - nsCOMPtr nameLiteral; + nsCOMPtr parentDir = do_QueryInterface(parentResource, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + rv = parentDir->CreateNewDirectory (prefCount, prefName, prefValue); - rdfService->GetLiteral(nameStr.GetUnicode(), getter_AddRefs(nameLiteral)); - nameArray->AppendElement(nameLiteral); - - DoCommand(db, NC_RDF_NEWDIRECTORY, dirArray, nameArray); return rv; } @@ -215,13 +194,11 @@ NS_IMETHODIMP nsAddressBook::DeleteAddressBooks nsresult rv = NS_OK; NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr resourceArray; rv = ConvertDOMListToResourceArray(nodeList, getter_AddRefs(resourceArray)); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); DoCommand(db, NC_RDF_DELETE, parentDir, resourceArray); return rv; @@ -233,9 +210,8 @@ nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, char *command, nsresult rv; - NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if(NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr commandResource; rv = rdfService->GetResource(command, getter_AddRefs(commandResource)); @@ -329,7 +305,7 @@ NS_IMETHODIMP nsAddressBook::GetAbDatabaseFromURI(const char *uri, nsIAddrDataba if(NS_SUCCEEDED(rv)) abSession->GetUserProfileDirectory(&dbPath); - nsString file; file.AssignWithConversion(&(uri[PL_strlen(kDirectoryDataSourceRoot)])); + nsAutoString file; file.AssignWithConversion(&(uri[PL_strlen(kDirectoryDataSourceRoot)])); PRInt32 pos = file.Find("/"); if (pos != -1) file.Truncate(pos); @@ -362,7 +338,7 @@ nsresult nsAddressBook::GetAbDatabaseFromFile(char* pDbFile, nsIAddrDatabase **d if(NS_SUCCEEDED(rv)) abSession->GetUserProfileDirectory(&dbPath); - nsString file; file.AssignWithConversion(pDbFile); + nsAutoString file; file.AssignWithConversion(pDbFile); (*dbPath) += file; NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, &rv); @@ -407,7 +383,7 @@ NS_IMETHODIMP nsAddressBook::MailListNameExists(const PRUnichar *name, PRBool *e DIR_Server *server = (DIR_Server *)pDirectories->ElementAt(i); if (server->dirType == PABDirectory) { - nsString dbfile; dbfile.AssignWithConversion(server->fileName); + nsAutoString dbfile; dbfile.AssignWithConversion(server->fileName); PRInt32 pos = dbfile.Find("na2"); if (pos >= 0) /* check: this is a 4.x file, remove when conversion is done */ continue; @@ -517,6 +493,8 @@ nsresult AddressBookParser::ParseFile() mDbUri = PR_smprintf("%s%s.mab", kDirectoryDataSourceRoot, leafName); } + // to do: we should use only one "return rv;" at the very end, instead of this + // multi return structure nsresult rv = NS_OK; nsFileSpec* dbPath = nsnull; char* fileName = PR_smprintf("%s.mab", leafName); @@ -533,15 +511,12 @@ nsresult AddressBookParser::ParseFile() if (NS_SUCCEEDED(rv) && addrDBFactory) rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(mDatabase), PR_TRUE); } + NS_ENSURE_SUCCESS(rv, rv); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - - NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); - if(NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr parentResource; - char *parentUri = PR_smprintf("%s", kDirectoryDataSourceRoot); + char *parentUri = PR_smprintf("%s", kBSDDirectoryRoot); rv = rdfService->GetResource(parentUri, getter_AddRefs(parentResource)); nsCOMPtr parentDir = do_QueryInterface(parentResource); if (!parentDir) @@ -557,14 +532,14 @@ nsresult AddressBookParser::ParseFile() return nsnull; PRUnichar *dirName = nsnull; rv = pPref->GetLocalizedUnicharPref("ldap_2.servers.pab.description", &dirName); - parentDir->CreateNewDirectory(dirName, fileName, mMigrating); + parentDir->CreateDirectoryByURI(dirName, mDbUri, mMigrating); nsMemory::Free(dirName); } else - parentDir->CreateNewDirectory(fileString.GetUnicode(), fileName, mMigrating); - + parentDir->CreateDirectoryByURI(fileString.GetUnicode(), mDbUri, mMigrating); + // Initialize the parser for a run... - mLine.Truncate(); + mLine.Truncate(); if (mFileType == TABFile) rv = ParseTabFile(); @@ -573,14 +548,12 @@ nsresult AddressBookParser::ParseFile() else rv = NS_ERROR_FAILURE; - if(NS_FAILED(rv)) - return rv; - if (leafName) nsCRT::free(leafName); if (fileName) PR_smprintf_free(fileName); - return NS_OK; + + return rv; } nsresult AddressBookParser::ParseTabFile() @@ -1410,7 +1383,7 @@ NS_IMETHODIMP nsAddressBook::ConvertNA2toLDIF(nsIFileSpec *srcFileSpec, nsIFileS if (!srcFileSpec || !dstFileSpec) return NS_ERROR_NULL_POINTER; nsCOMPtr abUpgrader = do_GetService(NS_AB4xUPGRADER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!abUpgrader) return NS_ERROR_FAILURE; rv = abUpgrader->StartUpgrade4xAddrBook(srcFileSpec, dstFileSpec); @@ -1432,12 +1405,12 @@ NS_IMETHODIMP nsAddressBook::ConvertLDIFtoMAB(nsIFileSpec *fileSpec, PRBool migr if (!fileSpec) return NS_ERROR_FAILURE; rv = fileSpec->OpenStreamForReading(); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); AddressBookParser abParser(fileSpec, migrating); rv = abParser.ParseFile(); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = fileSpec->CloseStream(); return rv; @@ -1448,7 +1421,7 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook() nsresult rv = NS_ERROR_FAILURE; nsCOMPtr filePicker = do_CreateInstance("@mozilla.org/filepicker;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); filePicker->Init(nsnull, nsnull, nsIFilePicker::modeOpen); @@ -1460,12 +1433,12 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook() nsCOMPtr localFile; rv = filePicker->GetFile(getter_AddRefs(localFile)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsXPIDLCString path; localFile->GetPath(getter_Copies(path)); nsCOMPtr fileSpec = do_CreateInstance("@mozilla.org/filespec;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); fileSpec->SetNativePath(path); // todo, check that we have a file, not a directory, and that is readable @@ -1473,7 +1446,7 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook() nsXPIDLCString leafName; rv = fileSpec->GetLeafName(getter_Copies(leafName)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // todo: detect na2 files a better way PRBool isNA2File = PR_FALSE; @@ -1493,15 +1466,15 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook() nsCOMPtr tmpLDIFFile; nsSpecialSystemDirectory file(nsSpecialSystemDirectory::OS_TemporaryDirectory); rv = NS_NewFileSpecWithSpec(file, getter_AddRefs(tmpLDIFFile)); - NS_ASSERTION(NS_SUCCEEDED(rv) && tmpLDIFFile,"failed to get the tmp dir"); - if (NS_FAILED(rv)) return rv; + NS_ASSERTION(NS_SUCCEEDED(rv) && tmpLDIFFile,"failed to get the tmp dir"); + NS_ENSURE_SUCCESS(rv, rv); if (!tmpLDIFFile) return NS_ERROR_FAILURE; nsCAutoString tmpFileName; tmpFileName = (const char *)leafName; tmpFileName += ".ldif"; rv = tmpLDIFFile->AppendRelativeUnixPath((const char *)tmpFileName); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // todo: // check to see that that file doesn't exist. @@ -1513,21 +1486,21 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook() // have no idea what the charset was (it's in the 4.x prefs file) // so we just guess that it is the system charset. rv = abUpgrader->SetCurrentCharset(""); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = ConvertNA2toLDIF(fileSpec, tmpLDIFFile); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); - rv = ConvertLDIFtoMAB(tmpLDIFFile, PR_FALSE /* migrating */); - if (NS_FAILED(rv)) return rv; + rv = ConvertLDIFtoMAB(tmpLDIFFile, PR_FALSE /* migrating */); + NS_ENSURE_SUCCESS(rv, rv); rv = tmpLDIFFile->Delete(PR_TRUE); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } else { // this will convert ldif and tab files - rv = ConvertLDIFtoMAB(fileSpec, PR_FALSE /* migrating */); - if (NS_FAILED(rv)) return rv; + rv = ConvertLDIFtoMAB(fileSpec, PR_FALSE /* migrating */); + NS_ENSURE_SUCCESS(rv, rv); } return rv; } diff --git a/mailnews/addrbook/src/nsCardDataSource.cpp b/mailnews/addrbook/src/nsCardDataSource.cpp index 0a8c87b2ae33..aa1558a309e0 100644 --- a/mailnews/addrbook/src/nsCardDataSource.cpp +++ b/mailnews/addrbook/src/nsCardDataSource.cpp @@ -203,7 +203,7 @@ nsresult nsAbCardDataSource::Init() nsresult rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); // XXX probably need shutdown listener here - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv); if (NS_SUCCEEDED(rv)) @@ -416,8 +416,7 @@ nsAbCardDataSource::getCardArcLabelsOut(nsIAbCard *card, { nsresult rv; rv = NS_NewISupportsArray(arcs); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); (*arcs)->AppendElement(kNC_DisplayName); (*arcs)->AppendElement(kNC_Name); @@ -445,7 +444,7 @@ nsAbCardDataSource::GetAllCommands(nsIRDFResource* source, nsCOMPtr card(do_QueryInterface(source, &rv)); if (NS_SUCCEEDED(rv)) { rv = NS_NewISupportsArray(getter_AddRefs(cmds)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); cmds->AppendElement(kNC_Delete); cmds->AppendElement(kNC_NewCard); } @@ -653,8 +652,7 @@ nsresult nsAbCardDataSource::createCardNode(nsIAbCard* card, nsCRT::free(tempStr); } } - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); if (name) { nsString nameString(name); diff --git a/mailnews/addrbook/src/nsDirPrefs.cpp b/mailnews/addrbook/src/nsDirPrefs.cpp index 741684c43fec..e52307bb1492 100644 --- a/mailnews/addrbook/src/nsDirPrefs.cpp +++ b/mailnews/addrbook/src/nsDirPrefs.cpp @@ -451,10 +451,10 @@ nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir) return NS_OK; } -nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DIR_Server** pServer) +nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DirectoryType dirType, DIR_Server** pServer) { DIR_Server * server = (DIR_Server *) PR_Malloc(sizeof(DIR_Server)); - DIR_InitServerWithType (server, PABDirectory); + DIR_InitServerWithType (server, dirType); if (!dir_ServerList) DIR_GetDirServers(); if (dir_ServerList) diff --git a/mailnews/addrbook/src/nsDirPrefs.h b/mailnews/addrbook/src/nsDirPrefs.h index 316a4c46b0d4..e54145722ed0 100644 --- a/mailnews/addrbook/src/nsDirPrefs.h +++ b/mailnews/addrbook/src/nsDirPrefs.h @@ -37,12 +37,12 @@ PRInt32 INTL_ConvertFromUnicode(const PRUnichar* uniBuffer, #define PREF_LDAP_VERSION_NAME "ldap_2.version" #define PREF_LDAP_SERVER_TREE_NAME "ldap_2.servers" -#define kCardRoot "abcard://" -#define kDirectoryRoot "abdirectory://" +#define kCardRoot "abmdbcard://" +#define kDirectoryRoot "abmdbdirectory://" #define kPersonalAddressbook "abook.mab" -#define kPersonalAddressbookUri "abdirectory://abook.mab" +#define kPersonalAddressbookUri "abmdbdirectory://abook.mab" #define kCollectedAddressbook "history.mab" -#define kCollectedAddressbookUri "abdirectory://history.mab" +#define kCollectedAddressbookUri "abmdbdirectory://history.mab" /* DIR_Server.dirType */ typedef enum @@ -248,7 +248,7 @@ nsVoidArray* DIR_GetDirectories(); nsresult DIR_GetDirServers(); nsresult DIR_ShutDown(void); /* FEs should call this when the app is shutting down. It frees all DIR_Servers regardless of ref count values! */ -nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DIR_Server** pServer); +nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DirectoryType dirType, DIR_Server** pServer); nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir); nsresult DIR_DecrementServerRefCount (DIR_Server *); diff --git a/mailnews/addrbook/src/nsDirectoryDataSource.cpp b/mailnews/addrbook/src/nsDirectoryDataSource.cpp index 4d49a39bdd99..7097e340d10f 100644 --- a/mailnews/addrbook/src/nsDirectoryDataSource.cpp +++ b/mailnews/addrbook/src/nsDirectoryDataSource.cpp @@ -23,7 +23,7 @@ #include "nsDirectoryDataSource.h" #include "nsAbBaseCID.h" -#include "nsAbDirectory.h" +#include "nsIAbDirectory.h" #include "nsIAddrBookSession.h" #include "nsIAbCard.h" @@ -51,7 +51,7 @@ typedef struct _nsAbRDFNotification { static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kAbDirectoryDataSourceCID, NS_ABDIRECTORYDATASOURCE_CID); -static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID); +// static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID); static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID); nsIRDFResource* nsAbDirectoryDataSource::kNC_Child = nsnull; @@ -123,7 +123,7 @@ nsAbDirectoryDataSource::Init() nsresult rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv); if (NS_SUCCEEDED(rv)) @@ -146,8 +146,6 @@ nsAbDirectoryDataSource::Init() CreateLiterals(mRDFService); - DIR_GetDirServers(); - mInitialized = PR_TRUE; return NS_OK; } @@ -217,7 +215,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::GetTargets(nsIRDFResource* source, nsCOMPtr subDirectories; rv = directory->GetChildNodes(getter_AddRefs(subDirectories)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsAdapterEnumerator* cursor = new nsAdapterEnumerator(subDirectories); if (cursor == nsnull) @@ -339,8 +337,7 @@ nsAbDirectoryDataSource::getDirectoryArcLabelsOut(nsIAbDirectory *directory, { nsresult rv; rv = NS_NewISupportsArray(arcs); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); (*arcs)->AppendElement(kNC_DirName); (*arcs)->AppendElement(kNC_Child); @@ -360,7 +357,7 @@ nsAbDirectoryDataSource::GetAllCommands(nsIRDFResource* source, nsCOMPtr directory(do_QueryInterface(source, &rv)); if (NS_SUCCEEDED(rv)) { rv = NS_NewISupportsArray(getter_AddRefs(cmds)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); cmds->AppendElement(kNC_Delete); cmds->AppendElement(kNC_DeleteCards); cmds->AppendElement(kNC_NewDirectory); @@ -405,7 +402,7 @@ nsAbDirectoryDataSource::DoCommand(nsISupportsArray/**/* aSource { PRUint32 i, cnt; nsresult rv = aSources->Count(&cnt); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if ((aCommand == kNC_Delete)) rv = DoDeleteFromDirectory(aSources, aArguments); @@ -541,7 +538,7 @@ nsresult nsAbDirectoryDataSource::createDirectoryNameNode(nsIAbDirectory *direct rv = directory->GetListName(&name); else rv = directory->GetDirName(&name); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsString nameString(name); createNode(nameString, target); nsCRT::free(name); @@ -551,10 +548,12 @@ nsresult nsAbDirectoryDataSource::createDirectoryNameNode(nsIAbDirectory *direct nsresult nsAbDirectoryDataSource::createDirectoryUriNode(nsIAbDirectory *directory, nsIRDFNode **target) { + nsCOMPtr source(do_QueryInterface(directory)); + nsXPIDLCString uri; - nsresult rv = directory->GetDirUri(getter_Copies(uri)); - if (NS_FAILED(rv)) return rv; - nsString nameString; nameString.AssignWithConversion(uri); + nsresult rv = source->GetValue(getter_Copies(uri)); + NS_ENSURE_SUCCESS(rv, rv); + nsAutoString nameString; nameString.AssignWithConversion(uri); createNode(nameString, target); return NS_OK; } @@ -577,7 +576,9 @@ nsAbDirectoryDataSource::createDirectoryChildNode(nsIAbDirectory *directory, PRBool bIsMailList = PR_FALSE; directory->GetIsMailList(&bIsMailList); if (bIsMailList) + { return NS_RDF_NO_VALUE; + } PRUint32 i; for (i = 0; i < total; i++) @@ -602,7 +603,7 @@ nsAbDirectoryDataSource::createDirectoryIsMailListNode(nsIAbDirectory* directory nsresult rv; PRBool bIsMailList = PR_FALSE; rv = directory->GetIsMailList(&bIsMailList); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *target = nsnull; @@ -629,7 +630,7 @@ nsresult nsAbDirectoryDataSource::DoDeleteFromDirectory(nsISupportsArray *parent { PRUint32 item, itemCount; nsresult rv = parentDirs->Count(&itemCount); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr dirArray; NS_NewISupportsArray(getter_AddRefs(dirArray)); @@ -656,7 +657,7 @@ nsresult nsAbDirectoryDataSource::DoDeleteCardsFromDirectory(nsIAbDirectory *dir nsresult rv = NS_OK; PRUint32 itemCount; rv = arguments->Count(&itemCount); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr cardArray; NS_NewISupportsArray(getter_AddRefs(cardArray)); @@ -675,7 +676,7 @@ nsresult nsAbDirectoryDataSource::DoDeleteCardsFromDirectory(nsIAbDirectory *dir } PRUint32 cnt; rv = cardArray->Count(&cnt); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (cnt > 0) rv = directory->DeleteCards(cardArray); return rv; @@ -691,8 +692,33 @@ nsresult nsAbDirectoryDataSource::DoNewDirectory(nsIAbDirectory *directory, nsIS PRUnichar *name; literal->GetValue(&name); - rv = directory->CreateNewDirectory(name, nsnull, PR_FALSE /* migrating */); - nsMemory::Free(name); + PRUint32 prefCount = 1; + char **prefNames = (char **) nsMemory::Alloc(prefCount * (sizeof (char *))); + PRUnichar ** prefValues = (PRUnichar **) nsMemory::Alloc(prefCount * (sizeof(PRUnichar *))); + + if (prefNames && prefValues) + { + + prefNames[0] = PR_smprintf("description"); + prefValues[0] = name; + + rv = directory->CreateNewDirectory((unsigned int) prefCount, (const char**)prefNames, (const PRUnichar**)prefValues); + + if (prefNames[0]) + PR_smprintf_free(prefNames[0]); + if (prefValues[0]) + nsMemory::Free(prefValues[0]); + } + else + { + rv = NS_ERROR_NULL_POINTER; + } + + if (prefNames) + nsMemory::Free(prefNames); + if (prefValues) + nsMemory::Free(prefValues); + } return rv; } @@ -734,8 +760,7 @@ nsresult nsAbDirectoryDataSource::DoDirectoryHasAssertion(nsIAbDirectory *direct else if ((kNC_IsMailList == property)) { nsCOMPtr dirResource(do_QueryInterface(directory, &rv)); - if(NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = GetTargetHasAssertion(this, dirResource, property, tv, target, hasAssertion); } else