diff --git a/mailnews/addrbook/public/nsIAbDirectory.idl b/mailnews/addrbook/public/nsIAbDirectory.idl index 2096f0ac980..6a04b720297 100644 --- a/mailnews/addrbook/public/nsIAbDirectory.idl +++ b/mailnews/addrbook/public/nsIAbDirectory.idl @@ -63,7 +63,7 @@ interface nsIAbDirectoryProperties : nsISupports { attribute long position; }; -[scriptable, uuid(AA920C90-1DD1-11B2-96D3-AA81268ADAFC)] +[scriptable, uuid(2edfc712-e6c5-11d8-9a39-000a95dc234c)] interface nsIAbDirectory : nsISupports { // Types of operation @@ -97,10 +97,11 @@ interface nsIAbDirectory : nsISupports { // Get the children directories readonly attribute nsISimpleEnumerator childNodes; - // Get the cards associated with the directory - // This will return the cards associated with - // the mailing lists too - readonly attribute nsIEnumerator childCards; + /** + * Get the cards associated with the directory. This will return the cards + * associated with the mailing lists too. + */ + readonly attribute nsISimpleEnumerator childCards; // Modifies a top level directory, // which also updates the preferences diff --git a/mailnews/addrbook/public/nsIAddrDatabase.idl b/mailnews/addrbook/public/nsIAddrDatabase.idl index c9537b75ac3..5deba8f9659 100644 --- a/mailnews/addrbook/public/nsIAddrDatabase.idl +++ b/mailnews/addrbook/public/nsIAddrDatabase.idl @@ -128,7 +128,7 @@ interface nsIMdbRow; %} -[scriptable, uuid(ca536e0e-1dd1-11b2-951a-e02b86e4f60e)] +[scriptable, uuid(14d89995-e6c5-11d8-9a39-000a95dc234c)] interface nsAddrDBCommitType { const long kSmallCommit = 0; @@ -155,8 +155,24 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer { void createNewListCardAndAddToDB(in nsIAbDirectory list, in unsigned long listRowID, in nsIAbCard newCard, in boolean aNotify); void createMailListAndAddToDB(in nsIAbDirectory newList, in boolean aNotify); void createMailListAndAddToDBWithKey(in nsIAbDirectory newList, in boolean aNotify, out PRUint32 key); - nsIEnumerator enumerateCards(in nsIAbDirectory directory); - nsIEnumerator enumerateListAddresses(in nsIAbDirectory directory); + + /** + * Enumerate the cards in the directory. The enumerator will return the + * cards associated with mailing lists too. + * + * @param directory the directory of which to enumerate the cards. + * @return an enumerator. + */ + nsISimpleEnumerator enumerateCards(in nsIAbDirectory directory); + + /** + * Enumerate the cards associated with the mailing lists in the directory. + * + * @param directory the directory of which to enumerate the cards. + * @return an enumerator. + */ + nsISimpleEnumerator enumerateListAddresses(in nsIAbDirectory directory); + void getMailingListsFromDB(in nsIAbDirectory parentDir); void deleteCard(in nsIAbCard card, in boolean aNotify); void editCard(in nsIAbCard card, in boolean aNotify); diff --git a/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp b/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp index 26bdec76fa6..1c8aa4f8314 100644 --- a/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp +++ b/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp @@ -401,7 +401,7 @@ nsAbAutoCompleteSession::CheckEntry(nsAbAutoCompleteSearchString* searchStr, nsresult nsAbAutoCompleteSession::SearchCards(nsIAbDirectory* directory, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results) { nsresult rv; - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; nsCOMPtr card; PRInt32 i; @@ -409,9 +409,10 @@ nsresult nsAbAutoCompleteSession::SearchCards(nsIAbDirectory* directory, nsAbAut if (NS_SUCCEEDED(rv) && cardsEnumerator) { nsCOMPtr item; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_SUCCEEDED(rv)) { card = do_QueryInterface(item, &rv); diff --git a/mailnews/addrbook/src/nsAbDirProperty.cpp b/mailnews/addrbook/src/nsAbDirProperty.cpp index d908e6ce4ea..c5da57319b7 100644 --- a/mailnews/addrbook/src/nsAbDirProperty.cpp +++ b/mailnews/addrbook/src/nsAbDirProperty.cpp @@ -221,7 +221,7 @@ nsAbDirProperty::GetChildNodes(nsISimpleEnumerator **childList) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -nsAbDirProperty::GetChildCards(nsIEnumerator **childCards) +nsAbDirProperty::GetChildCards(nsISimpleEnumerator **childCards) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP diff --git a/mailnews/addrbook/src/nsAbDirectoryQuery.cpp b/mailnews/addrbook/src/nsAbDirectoryQuery.cpp index c3ee891b110..1e9af2e003e 100644 --- a/mailnews/addrbook/src/nsAbDirectoryQuery.cpp +++ b/mailnews/addrbook/src/nsAbDirectoryQuery.cpp @@ -441,7 +441,7 @@ nsresult nsAbDirectoryQuery::queryCards (nsIAbDirectory* directory, { nsresult rv = NS_OK; - nsCOMPtr cards; + nsCOMPtr cards; rv = directory->GetChildCards(getter_AddRefs(cards)); if (NS_FAILED(rv)) { @@ -454,14 +454,11 @@ nsresult nsAbDirectoryQuery::queryCards (nsIAbDirectory* directory, if (!cards) return NS_OK; - rv = cards->First(); - if (NS_FAILED(rv)) - return NS_OK; - - do + PRBool more; + while (NS_SUCCEEDED(cards->HasMoreElements(&more)) && more) { nsCOMPtr item; - rv = cards->CurrentItem(getter_AddRefs(item)); + rv = cards->GetNext(getter_AddRefs(item)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr card(do_QueryInterface(item, &rv)); @@ -472,8 +469,6 @@ nsresult nsAbDirectoryQuery::queryCards (nsIAbDirectory* directory, if (*resultLimit == 0) return NS_OK; - - rv = cards->Next (); } while (rv == NS_OK); diff --git a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp index 0ba3bd31f74..7523ecdb8cc 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp +++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp @@ -217,7 +217,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChildNodes(nsISimpleEnumerator* *aResult) return NS_NewArrayEnumerator(aResult, children); } -NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsIEnumerator** result) +NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsISimpleEnumerator** result) { nsresult rv; @@ -264,13 +264,8 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsIEnumerator** result) // Start the search rv = StartSearch(); NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr array; - NS_NewISupportsArray(getter_AddRefs(array)); - if (!array) - return NS_ERROR_OUT_OF_MEMORY; - - rv = array->Enumerate(result); + + rv = NS_NewEmptyEnumerator(result); } NS_ENSURE_SUCCESS(rv,rv); diff --git a/mailnews/addrbook/src/nsAbLDAPDirectory.h b/mailnews/addrbook/src/nsAbLDAPDirectory.h index ca13e9548b2..d2099f55326 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectory.h +++ b/mailnews/addrbook/src/nsAbLDAPDirectory.h @@ -67,7 +67,7 @@ public: // nsIAbDirectory methods NS_IMETHOD GetOperations(PRInt32 *aOperations); NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result); - NS_IMETHOD GetChildCards(nsIEnumerator* *result); + NS_IMETHOD GetChildCards(nsISimpleEnumerator* *result); NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard); NS_IMETHOD GetSupportsMailingLists(PRBool *aSupportsMailingsLists); NS_IMETHOD GetIsRemote(PRBool *aIsRemote); diff --git a/mailnews/addrbook/src/nsAbMDBDirectory.cpp b/mailnews/addrbook/src/nsAbMDBDirectory.cpp index f259e711ea3..2dc4484762c 100644 --- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp +++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp @@ -56,7 +56,7 @@ #include "nsAbQueryStringToExpression.h" #include "nsArrayEnumerator.h" #include "nsAbMDBCardProperty.h" - +#include "nsEnumeratorUtils.h" #include "mdb.h" #include "prprf.h" @@ -386,7 +386,7 @@ PR_STATIC_CALLBACK(PRBool) enumerateSearchCache(nsHashKey *aKey, void *aData, vo return PR_TRUE; } -NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result) +NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsISimpleEnumerator* *result) { if (mIsQueryURI) { @@ -400,7 +400,7 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result) nsCOMPtr array; NS_NewISupportsArray(getter_AddRefs(array)); mSearchCache.Enumerate(enumerateSearchCache, (void*)array); - return array->Enumerate(result); + return NS_NewArrayEnumerator(result, array); } NS_ASSERTION(!mURI.IsEmpty(), "Not Initialized?"); diff --git a/mailnews/addrbook/src/nsAbMDBDirectory.h b/mailnews/addrbook/src/nsAbMDBDirectory.h index b6e1daaff3d..ab753f64517 100644 --- a/mailnews/addrbook/src/nsAbMDBDirectory.h +++ b/mailnews/addrbook/src/nsAbMDBDirectory.h @@ -88,7 +88,7 @@ public: // nsIAbDirectory methods: NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result); - NS_IMETHOD GetChildCards(nsIEnumerator* *result); + NS_IMETHOD GetChildCards(nsISimpleEnumerator* *result); NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties); NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory); NS_IMETHOD DeleteCards(nsISupportsArray *cards); diff --git a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp index a86e65420e9..551ba6e7bd8 100644 --- a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp +++ b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp @@ -163,7 +163,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsISimpleEnumerator **aNodes) return retCode; } -NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards) +NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsISimpleEnumerator **aCards) { if (!aCards) { return NS_ERROR_NULL_POINTER ; } *aCards = nsnull ; @@ -184,7 +184,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards) PRUint32 nbCards = 0 ; nsCOMPtr element ; - cardList->Enumerate(aCards) ; + NS_NewArrayEnumerator(aCards, cardList); cardList->Count(&nbCards) ; for (PRUint32 i = 0 ; i < nbCards ; ++ i) { cardList->GetElementAt(i, getter_AddRefs(element)) ; diff --git a/mailnews/addrbook/src/nsAbOutlookDirectory.h b/mailnews/addrbook/src/nsAbOutlookDirectory.h index 7463113f3cf..711482d9fb8 100644 --- a/mailnews/addrbook/src/nsAbOutlookDirectory.h +++ b/mailnews/addrbook/src/nsAbOutlookDirectory.h @@ -62,7 +62,7 @@ public: virtual ~nsAbOutlookDirectory(void) ; // nsAbDirProperty methods - NS_IMETHOD GetChildCards(nsIEnumerator **aCards) ; + NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards) ; NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes) ; NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard) ; NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory) ; diff --git a/mailnews/addrbook/src/nsAbView.cpp b/mailnews/addrbook/src/nsAbView.cpp index 5bd69da663b..3748c096447 100644 --- a/mailnews/addrbook/src/nsAbView.cpp +++ b/mailnews/addrbook/src/nsAbView.cpp @@ -283,7 +283,7 @@ NS_IMETHODIMP nsAbView::GetDirectory(nsIAbDirectory **aDirectory) nsresult nsAbView::EnumerateCards() { nsresult rv; - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; nsCOMPtr card; if (!mDirectory) @@ -293,9 +293,10 @@ nsresult nsAbView::EnumerateCards() if (NS_SUCCEEDED(rv) && cardsEnumerator) { nsCOMPtr item; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_SUCCEEDED(rv)) { nsCOMPtr card = do_QueryInterface(item); diff --git a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp index c34e6d0567d..0c2a8491d7d 100644 --- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp +++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp @@ -259,7 +259,7 @@ nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory, NS_ENSURE_ARG_POINTER(aDirectory); nsresult rv; - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; nsCOMPtr card; aOutput.AppendLiteral("\n" @@ -287,9 +287,10 @@ nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory, if (NS_SUCCEEDED(rv) && cardsEnumerator) { nsCOMPtr item; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_SUCCEEDED(rv)) { nsCOMPtr card = do_QueryInterface(item); diff --git a/mailnews/addrbook/src/nsAddrDatabase.cpp b/mailnews/addrbook/src/nsAddrDatabase.cpp index a755fdf77f7..2297e3fcbd3 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.cpp +++ b/mailnews/addrbook/src/nsAddrDatabase.cpp @@ -3098,233 +3098,221 @@ nsresult nsAddrDatabase::GetListFromDB(nsIAbDirectory *newList, nsIMdbRow* listR return err; } -class nsAddrDBEnumerator : public nsIEnumerator +class nsAddrDBEnumerator : public nsISimpleEnumerator { public: NS_DECL_ISUPPORTS - // nsIEnumerator methods: - NS_DECL_NSIENUMERATOR + // nsISimpleEnumerator methods: + NS_DECL_NSISIMPLEENUMERATOR // nsAddrDBEnumerator methods: - nsAddrDBEnumerator(nsAddrDatabase* db); - virtual ~nsAddrDBEnumerator(); + nsAddrDBEnumerator(nsAddrDatabase* aDb); protected: - nsCOMPtr mDB; - nsCOMPtr mResultList; - nsCOMPtr mResultCard; - nsIMdbTable* mDbTable; - nsIMdbTableRowCursor* mRowCursor; - nsIMdbRow* mCurrentRow; - mdb_pos mRowPos; - PRBool mDone; - PRBool mCurrentRowIsList; + nsRefPtr mDb; + nsIMdbTable *mDbTable; + nsCOMPtr mRowCursor; + nsCOMPtr mCurrentRow; + mdb_pos mRowPos; }; -nsAddrDBEnumerator::nsAddrDBEnumerator(nsAddrDatabase* db) - : mDB(db), mRowCursor(nsnull), mCurrentRow(nsnull), mDone(PR_FALSE) +nsAddrDBEnumerator::nsAddrDBEnumerator(nsAddrDatabase* aDb) + : mDb(aDb), + mDbTable(aDb->GetPabTable()), + mRowPos(-1) { - mDbTable = mDB->GetPabTable(); - mCurrentRowIsList = PR_FALSE; } -nsAddrDBEnumerator::~nsAddrDBEnumerator() +NS_IMPL_ISUPPORTS1(nsAddrDBEnumerator, nsISimpleEnumerator) + +NS_IMETHODIMP +nsAddrDBEnumerator::HasMoreElements(PRBool *aResult) { - NS_IF_RELEASE(mRowCursor); -} + *aResult = PR_FALSE; -NS_IMPL_ISUPPORTS1(nsAddrDBEnumerator, nsIEnumerator) - -NS_IMETHODIMP nsAddrDBEnumerator::First(void) -{ - nsresult rv = 0; - mDone = PR_FALSE; - - if (!mDB || !mDbTable || !mDB->GetEnv()) - return NS_ERROR_NULL_POINTER; - - mDbTable->GetTableRowCursor(mDB->GetEnv(), -1, &mRowCursor); - if (rv != NS_OK) return NS_ERROR_FAILURE; - return Next(); -} - -NS_IMETHODIMP nsAddrDBEnumerator::Next(void) -{ - if (!mRowCursor) + if (!mDb || !mDbTable || !mDb->GetEnv()) { - mDone = PR_TRUE; - return NS_ERROR_FAILURE; + return NS_ERROR_NULL_POINTER; } - NS_IF_RELEASE(mCurrentRow); - nsresult rv = mRowCursor->NextRow(mDB->GetEnv(), &mCurrentRow, &mRowPos); - if (mCurrentRow && NS_SUCCEEDED(rv)) + + nsCOMPtr rowCursor; + mDbTable->GetTableRowCursor(mDb->GetEnv(), mRowPos, + getter_AddRefs(mRowCursor)); + NS_ENSURE_TRUE(rowCursor, NS_ERROR_FAILURE); + + nsCOMPtr currentRow; + mdb_pos rowPos; + rowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(currentRow), &rowPos); + while (currentRow) { mdbOid rowOid; - - if (mCurrentRow->GetOid(mDB->GetEnv(), &rowOid) == NS_OK) + if (NS_SUCCEEDED(mCurrentRow->GetOid(mDb->GetEnv(), &rowOid))) { - if (mDB->IsListRowScopeToken(rowOid.mOid_Scope)) + if (mDb->IsListRowScopeToken(rowOid.mOid_Scope) || + mDb->IsCardRowScopeToken(rowOid.mOid_Scope)) { - mCurrentRowIsList = PR_TRUE; + *aResult = PR_TRUE; + return NS_OK; } - else if (mDB->IsCardRowScopeToken(rowOid.mOid_Scope)) + + if (!mDb->IsDataRowScopeToken(rowOid.mOid_Scope)) { - mCurrentRowIsList = PR_FALSE; - return NS_OK; - } - else if (mDB->IsDataRowScopeToken(rowOid.mOid_Scope)) - { - return Next(); - } - else return NS_ERROR_FAILURE; + } } + + mRowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(currentRow), &rowPos); } - else if (!mCurrentRow) + + return NS_OK; +} + +NS_IMETHODIMP +nsAddrDBEnumerator::GetNext(nsISupports **aResult) +{ + *aResult = nsnull; + + if (!mDb || !mDbTable || !mDb->GetEnv()) { - mDone = PR_TRUE; return NS_ERROR_NULL_POINTER; } - else if (NS_FAILED(rv)) + + if (!mRowCursor) { - mDone = PR_TRUE; - return NS_ERROR_FAILURE; + mDbTable->GetTableRowCursor(mDb->GetEnv(), -1, + getter_AddRefs(mRowCursor)); + NS_ENSURE_TRUE(mRowCursor, NS_ERROR_FAILURE); } + + nsCOMPtr resultCard; + mRowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(mCurrentRow), &mRowPos); + while (mCurrentRow) + { + mdbOid rowOid; + if (NS_SUCCEEDED(mCurrentRow->GetOid(mDb->GetEnv(), &rowOid))) + { + nsresult rv; + if (mDb->IsListRowScopeToken(rowOid.mOid_Scope)) + { + rv = mDb->CreateABListCard(mCurrentRow, + getter_AddRefs(resultCard)); + NS_ENSURE_SUCCESS(rv, rv); + } + else if (mDb->IsCardRowScopeToken(rowOid.mOid_Scope)) + { + rv = mDb->CreateABCard(mCurrentRow, 0, + getter_AddRefs(resultCard)); + NS_ENSURE_SUCCESS(rv, rv); + } + else if (!mDb->IsDataRowScopeToken(rowOid.mOid_Scope)) + { + return NS_ERROR_FAILURE; + } + + if (resultCard) + { + return CallQueryInterface(resultCard, aResult); + } + } + + mRowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(mCurrentRow), + &mRowPos); + } + return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsAddrDBEnumerator::CurrentItem(nsISupports **aItem) -{ - if (mCurrentRow) - { - nsresult rv; - if (mCurrentRowIsList) - { - rv = mDB->CreateABListCard(mCurrentRow, getter_AddRefs(mResultCard)); - *aItem = mResultCard; - } - else - { - rv = mDB->CreateABCard(mCurrentRow, 0, getter_AddRefs(mResultCard)); - *aItem = mResultCard; - } - NS_IF_ADDREF(*aItem); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP nsAddrDBEnumerator::IsDone(void) -{ - return mDone ? NS_OK : NS_ERROR_FAILURE; -} - -class nsListAddressEnumerator : public nsIEnumerator +class nsListAddressEnumerator : public nsISimpleEnumerator { public: NS_DECL_ISUPPORTS // nsIEnumerator methods: - NS_DECL_NSIENUMERATOR + NS_DECL_NSISIMPLEENUMERATOR - // nsAddrDBEnumerator methods: + // nsListAddressEnumerator methods: - nsListAddressEnumerator(nsAddrDatabase* db, mdb_id rowID); - virtual ~nsListAddressEnumerator(); + nsListAddressEnumerator(nsAddrDatabase* aDb, mdb_id aRowID); protected: - nsCOMPtr mDB; - nsCOMPtr mResultCard; - nsIMdbTable* mDbTable; - nsIMdbRow* mListRow; - nsIMdbRow* mCurrentRow; - mdb_id mListRowID; - PRBool mDone; - PRUint32 mAddressTotal; - PRUint16 mAddressPos; + nsRefPtr mDb; + nsIMdbTable *mDbTable; + nsCOMPtr mListRow; + mdb_id mListRowID; + PRUint32 mAddressTotal; + PRUint16 mAddressPos; }; -nsListAddressEnumerator::nsListAddressEnumerator(nsAddrDatabase* db, mdb_id rowID) - : mDB(db), mCurrentRow(nsnull), mListRowID(rowID), mDone(PR_FALSE) +nsListAddressEnumerator::nsListAddressEnumerator(nsAddrDatabase* aDb, + mdb_id aRowID) + : mDb(aDb), + mDbTable(aDb->GetPabTable()), + mListRowID(aRowID), + mAddressPos(0) { - mDbTable = mDB->GetPabTable(); - mDB->GetListRowByRowID(mListRowID, &mListRow); - mAddressTotal = mDB->GetListAddressTotal(mListRow); - mAddressPos = 0; + mDb->GetListRowByRowID(mListRowID, getter_AddRefs(mListRow)); + mAddressTotal = aDb->GetListAddressTotal(mListRow); } -nsListAddressEnumerator::~nsListAddressEnumerator() +NS_IMPL_ISUPPORTS1(nsListAddressEnumerator, nsISimpleEnumerator) + +NS_IMETHODIMP +nsListAddressEnumerator::HasMoreElements(PRBool *aResult) { - NS_IF_RELEASE(mListRow); -} + *aResult = PR_FALSE; -NS_IMPL_ISUPPORTS1(nsListAddressEnumerator, nsIEnumerator) - -NS_IMETHODIMP nsListAddressEnumerator::First(void) -{ - mDone = PR_FALSE; - - if (!mDB || !mDbTable || !mDB->GetEnv()) + if (!mDb || !mDbTable || !mDb->GetEnv()) + { return NS_ERROR_NULL_POINTER; - - //got total address count and start - if (mAddressTotal) - return Next(); - else - return NS_ERROR_FAILURE; -} + } -NS_IMETHODIMP nsListAddressEnumerator::Next(void) -{ - //go to the next address column - if (mCurrentRow) + if (mAddressPos + 1 <= mAddressTotal) { - NS_RELEASE(mCurrentRow); - mCurrentRow = nsnull; - } - mAddressPos++; - if (mAddressPos <= mAddressTotal) - { - nsresult err; - err = mDB->GetAddressRowByPos(mListRow, mAddressPos, &mCurrentRow); - if (mCurrentRow) - return NS_OK; - else - { - mDone = PR_TRUE; - return NS_ERROR_FAILURE; - } - } - else - { - mDone = PR_TRUE; - return NS_ERROR_FAILURE; - } -} + nsCOMPtr currentRow; + nsresult rv = mDb->GetAddressRowByPos(mListRow, mAddressPos + 1, + getter_AddRefs(currentRow)); + NS_ENSURE_SUCCESS(rv, rv); + + *aResult = currentRow == nsnull; + } -NS_IMETHODIMP nsListAddressEnumerator::CurrentItem(nsISupports **aItem) -{ - if (mCurrentRow) - { - nsresult rv; - rv = mDB->CreateABCard(mCurrentRow, mListRowID, getter_AddRefs(mResultCard)); - NS_IF_ADDREF(*aItem = mResultCard); return NS_OK; - } - return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsListAddressEnumerator::IsDone(void) +NS_IMETHODIMP +nsListAddressEnumerator::GetNext(nsISupports **aResult) { - return mDone ? NS_OK : NS_ERROR_FAILURE; + *aResult = nsnull; + + if (!mDb || !mDbTable || !mDb->GetEnv()) + { + return NS_ERROR_NULL_POINTER; + } + + if (++mAddressPos <= mAddressTotal) + { + nsCOMPtr currentRow; + nsresult rv = mDb->GetAddressRowByPos(mListRow, mAddressPos, + getter_AddRefs(currentRow)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr resultCard; + rv = mDb->CreateABCard(currentRow, mListRowID, + getter_AddRefs(resultCard)); + NS_ENSURE_SUCCESS(rv, rv); + + return CallQueryInterface(resultCard, aResult); + } + + return NS_ERROR_FAILURE; } //////////////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsAddrDatabase::EnumerateCards(nsIAbDirectory *directory, nsIEnumerator **result) +NS_IMETHODIMP nsAddrDatabase::EnumerateCards(nsIAbDirectory *directory, nsISimpleEnumerator **result) { nsAddrDBEnumerator* e = new nsAddrDBEnumerator(this); m_dbDirectory = directory; @@ -3374,7 +3362,7 @@ NS_IMETHODIMP nsAddrDatabase::GetMailingListsFromDB(nsIAbDirectory *parentDir) return NS_OK; } -NS_IMETHODIMP nsAddrDatabase::EnumerateListAddresses(nsIAbDirectory *directory, nsIEnumerator **result) +NS_IMETHODIMP nsAddrDatabase::EnumerateListAddresses(nsIAbDirectory *directory, nsISimpleEnumerator **result) { nsresult rv = NS_OK; mdb_id rowID; diff --git a/mailnews/addrbook/src/nsAddrDatabase.h b/mailnews/addrbook/src/nsAddrDatabase.h index 69dbd576ac4..88e1ed62c39 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.h +++ b/mailnews/addrbook/src/nsAddrDatabase.h @@ -88,9 +88,9 @@ public: NS_IMETHOD CreateNewListCardAndAddToDB(nsIAbDirectory *list, PRUint32 listRowID, nsIAbCard *newCard, PRBool notify); NS_IMETHOD CreateMailListAndAddToDB(nsIAbDirectory *newList, PRBool notify); NS_IMETHOD CreateMailListAndAddToDBWithKey(nsIAbDirectory *newList, PRBool notify, PRUint32 *key); - NS_IMETHOD EnumerateCards(nsIAbDirectory *directory, nsIEnumerator **result); + NS_IMETHOD EnumerateCards(nsIAbDirectory *directory, nsISimpleEnumerator **result); NS_IMETHOD GetMailingListsFromDB(nsIAbDirectory *parentDir); - NS_IMETHOD EnumerateListAddresses(nsIAbDirectory *directory, nsIEnumerator **result); + NS_IMETHOD EnumerateListAddresses(nsIAbDirectory *directory, nsISimpleEnumerator **result); NS_IMETHOD DeleteCard(nsIAbCard *newCard, PRBool notify); NS_IMETHOD EditCard(nsIAbCard *card, PRBool notify); NS_IMETHOD ContainsCard(nsIAbCard *card, PRBool *hasCard); diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index 7075cde4bc4..98c867d1519 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -638,7 +638,7 @@ NS_IMETHODIMP nsAddressBook::ExportAddressBook(nsIDOMWindow *aParentWin, nsIAbDi nsresult nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const char *aDelim, PRUint32 aDelimLen, nsILocalFile *aLocalFile) { - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; nsCOMPtr card; nsresult rv; @@ -695,8 +695,9 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const rv = aDirectory->GetChildCards(getter_AddRefs(cardsEnumerator)); if (NS_SUCCEEDED(rv) && cardsEnumerator) { nsCOMPtr item; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_SUCCEEDED(rv)) { nsCOMPtr card = do_QueryInterface(item, &rv); NS_ENSURE_SUCCESS(rv,rv); @@ -809,7 +810,7 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const nsresult nsAddressBook::ExportDirectoryToLDIF(nsIAbDirectory *aDirectory, nsILocalFile *aLocalFile) { - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; nsCOMPtr card; nsresult rv; @@ -831,8 +832,9 @@ nsAddressBook::ExportDirectoryToLDIF(nsIAbDirectory *aDirectory, nsILocalFile *a rv = aDirectory->GetChildCards(getter_AddRefs(cardsEnumerator)); if (NS_SUCCEEDED(rv) && cardsEnumerator) { nsCOMPtr item; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_SUCCEEDED(rv)) { nsCOMPtr card = do_QueryInterface(item, &rv); NS_ENSURE_SUCCESS(rv,rv); diff --git a/mailnews/addrbook/src/nsDirectoryDataSource.cpp b/mailnews/addrbook/src/nsDirectoryDataSource.cpp index 9fb5937d05b..6a528e65f9c 100644 --- a/mailnews/addrbook/src/nsDirectoryDataSource.cpp +++ b/mailnews/addrbook/src/nsDirectoryDataSource.cpp @@ -48,7 +48,6 @@ #include "nsRDFCID.h" #include "nsIRDFNode.h" #include "nsEnumeratorUtils.h" -#include "nsAdapterEnumerator.h" #include "nsIObserverService.h" #include "nsString.h" @@ -256,19 +255,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::GetTargets(nsIRDFResource* source, } else if((kNC_CardChild == property)) { - nsCOMPtr cardChild; - - rv = directory->GetChildCards(getter_AddRefs(cardChild)); - if (NS_SUCCEEDED(rv) && cardChild) - { - nsAdapterEnumerator* cursor = - new nsAdapterEnumerator(cardChild); - if (cursor == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(cursor); - *targets = cursor; - return NS_OK; - } + return directory->GetChildCards(targets); } } return NS_NewEmptyEnumerator(targets); diff --git a/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp b/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp index fc1bf845477..a0698b10e1b 100644 --- a/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp +++ b/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp @@ -365,7 +365,7 @@ nsresult nsAbPalmHotSync::GetAllCards(PRInt32 * aCount, lpnsABCOMCardStruct * aC return NS_ERROR_OUT_OF_MEMORY; } - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; rv = mABDB->EnumerateCards(mDirectory, getter_AddRefs(cardsEnumerator)); if (NS_FAILED(rv) || !cardsEnumerator) { mABDB->Close(PR_FALSE); @@ -374,8 +374,9 @@ nsresult nsAbPalmHotSync::GetAllCards(PRInt32 * aCount, lpnsABCOMCardStruct * aC nsCOMPtr item; nsCOMPtr card; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_FAILED(rv)) continue; @@ -561,7 +562,7 @@ nsresult nsAbPalmHotSync::LoadNewModifiedCardsSinceLastSync() if(!mDBOpen || !mABDB || !mInitialized) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr cardsEnumerator; + nsCOMPtr cardsEnumerator; nsresult rv = mABDB->EnumerateCards(mDirectory, getter_AddRefs(cardsEnumerator)); if (NS_FAILED(rv) || !cardsEnumerator) return NS_ERROR_NOT_AVAILABLE; // no cards available @@ -569,9 +570,10 @@ nsresult nsAbPalmHotSync::LoadNewModifiedCardsSinceLastSync() // create the list of cards to be sent to Palm nsCOMPtr item; nsCOMPtr card; - for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) + PRBool more; + while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { - rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_FAILED(rv)) return rv;