Preparation for fix for bug 203927 (Add ability to read from Mac OS X system Address Book): Switch to nsISimpleEnumerator. r=bienvenu, sr=dmose.

This commit is contained in:
peterv%propagandism.org 2005-08-18 14:41:10 +00:00
Родитель 6aedf0028b
Коммит a737e0b3c5
18 изменённых файлов: 224 добавлений и 235 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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);

Просмотреть файл

@ -401,7 +401,7 @@ nsAbAutoCompleteSession::CheckEntry(nsAbAutoCompleteSearchString* searchStr,
nsresult nsAbAutoCompleteSession::SearchCards(nsIAbDirectory* directory, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results)
{
nsresult rv;
nsCOMPtr<nsIEnumerator> cardsEnumerator;
nsCOMPtr<nsISimpleEnumerator> cardsEnumerator;
nsCOMPtr<nsIAbCard> card;
PRInt32 i;
@ -409,9 +409,10 @@ nsresult nsAbAutoCompleteSession::SearchCards(nsIAbDirectory* directory, nsAbAut
if (NS_SUCCEEDED(rv) && cardsEnumerator)
{
nsCOMPtr<nsISupports> 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);

Просмотреть файл

@ -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

Просмотреть файл

@ -441,7 +441,7 @@ nsresult nsAbDirectoryQuery::queryCards (nsIAbDirectory* directory,
{
nsresult rv = NS_OK;
nsCOMPtr<nsIEnumerator> cards;
nsCOMPtr<nsISimpleEnumerator> 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<nsISupports> item;
rv = cards->CurrentItem(getter_AddRefs(item));
rv = cards->GetNext(getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbCard> 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);

Просмотреть файл

@ -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;
@ -265,12 +265,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsIEnumerator** result)
rv = StartSearch();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsArray> 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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<nsISupportsArray> 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?");

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<nsISupports> element ;
cardList->Enumerate(aCards) ;
NS_NewArrayEnumerator(aCards, cardList);
cardList->Count(&nbCards) ;
for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
cardList->GetElementAt(i, getter_AddRefs(element)) ;

Просмотреть файл

@ -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) ;

Просмотреть файл

@ -283,7 +283,7 @@ NS_IMETHODIMP nsAbView::GetDirectory(nsIAbDirectory **aDirectory)
nsresult nsAbView::EnumerateCards()
{
nsresult rv;
nsCOMPtr<nsIEnumerator> cardsEnumerator;
nsCOMPtr<nsISimpleEnumerator> cardsEnumerator;
nsCOMPtr<nsIAbCard> card;
if (!mDirectory)
@ -293,9 +293,10 @@ nsresult nsAbView::EnumerateCards()
if (NS_SUCCEEDED(rv) && cardsEnumerator)
{
nsCOMPtr<nsISupports> 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 <nsIAbCard> card = do_QueryInterface(item);

Просмотреть файл

@ -259,7 +259,7 @@ nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory,
NS_ENSURE_ARG_POINTER(aDirectory);
nsresult rv;
nsCOMPtr<nsIEnumerator> cardsEnumerator;
nsCOMPtr<nsISimpleEnumerator> cardsEnumerator;
nsCOMPtr<nsIAbCard> card;
aOutput.AppendLiteral("<?xml version=\"1.0\"?>\n"
@ -287,9 +287,10 @@ nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory,
if (NS_SUCCEEDED(rv) && cardsEnumerator)
{
nsCOMPtr<nsISupports> 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 <nsIAbCard> card = do_QueryInterface(item);

Просмотреть файл

@ -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<nsAddrDatabase> mDB;
nsCOMPtr<nsIAbDirectory> mResultList;
nsCOMPtr<nsIAbCard> mResultCard;
nsIMdbTable* mDbTable;
nsIMdbTableRowCursor* mRowCursor;
nsIMdbRow* mCurrentRow;
nsRefPtr<nsAddrDatabase> mDb;
nsIMdbTable *mDbTable;
nsCOMPtr<nsIMdbTableRowCursor> mRowCursor;
nsCOMPtr<nsIMdbRow> mCurrentRow;
mdb_pos mRowPos;
PRBool mDone;
PRBool mCurrentRowIsList;
};
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<nsIMdbTableRowCursor> rowCursor;
mDbTable->GetTableRowCursor(mDb->GetEnv(), mRowPos,
getter_AddRefs(mRowCursor));
NS_ENSURE_TRUE(rowCursor, NS_ERROR_FAILURE);
nsCOMPtr<nsIMdbRow> currentRow;
mdb_pos rowPos;
rowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(currentRow), &rowPos);
while (currentRow)
{
mdbOid rowOid;
if (NS_SUCCEEDED(mCurrentRow->GetOid(mDb->GetEnv(), &rowOid)))
{
if (mDb->IsListRowScopeToken(rowOid.mOid_Scope) ||
mDb->IsCardRowScopeToken(rowOid.mOid_Scope))
{
*aResult = PR_TRUE;
if (mCurrentRow->GetOid(mDB->GetEnv(), &rowOid) == NS_OK)
{
if (mDB->IsListRowScopeToken(rowOid.mOid_Scope))
{
mCurrentRowIsList = 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;
}
}
else if (!mCurrentRow)
mRowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(currentRow), &rowPos);
}
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))
{
mDone = PR_TRUE;
return NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsAddrDBEnumerator::CurrentItem(nsISupports **aItem)
{
if (mCurrentRow)
if (!mRowCursor)
{
mDbTable->GetTableRowCursor(mDb->GetEnv(), -1,
getter_AddRefs(mRowCursor));
NS_ENSURE_TRUE(mRowCursor, NS_ERROR_FAILURE);
}
nsCOMPtr<nsIAbCard> resultCard;
mRowCursor->NextRow(mDb->GetEnv(), getter_AddRefs(mCurrentRow), &mRowPos);
while (mCurrentRow)
{
mdbOid rowOid;
if (NS_SUCCEEDED(mCurrentRow->GetOid(mDb->GetEnv(), &rowOid)))
{
nsresult rv;
if (mCurrentRowIsList)
if (mDb->IsListRowScopeToken(rowOid.mOid_Scope))
{
rv = mDB->CreateABListCard(mCurrentRow, getter_AddRefs(mResultCard));
*aItem = mResultCard;
rv = mDb->CreateABListCard(mCurrentRow,
getter_AddRefs(resultCard));
NS_ENSURE_SUCCESS(rv, rv);
}
else
else if (mDb->IsCardRowScopeToken(rowOid.mOid_Scope))
{
rv = mDB->CreateABCard(mCurrentRow, 0, getter_AddRefs(mResultCard));
*aItem = mResultCard;
rv = mDb->CreateABCard(mCurrentRow, 0,
getter_AddRefs(resultCard));
NS_ENSURE_SUCCESS(rv, rv);
}
NS_IF_ADDREF(*aItem);
return NS_OK;
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::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<nsAddrDatabase> mDB;
nsCOMPtr<nsIAbCard> mResultCard;
nsIMdbTable* mDbTable;
nsIMdbRow* mListRow;
nsIMdbRow* mCurrentRow;
nsRefPtr<nsAddrDatabase> mDb;
nsIMdbTable *mDbTable;
nsCOMPtr<nsIMdbRow> mListRow;
mdb_id mListRowID;
PRBool mDone;
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)
{
NS_RELEASE(mCurrentRow);
mCurrentRow = nsnull;
}
mAddressPos++;
if (mAddressPos <= mAddressTotal)
if (mAddressPos + 1 <= mAddressTotal)
{
nsresult err;
err = mDB->GetAddressRowByPos(mListRow, mAddressPos, &mCurrentRow);
if (mCurrentRow)
nsCOMPtr<nsIMdbRow> currentRow;
nsresult rv = mDb->GetAddressRowByPos(mListRow, mAddressPos + 1,
getter_AddRefs(currentRow));
NS_ENSURE_SUCCESS(rv, rv);
*aResult = currentRow == nsnull;
}
return NS_OK;
else
{
mDone = PR_TRUE;
return NS_ERROR_FAILURE;
}
}
else
{
mDone = PR_TRUE;
return NS_ERROR_FAILURE;
}
}
NS_IMETHODIMP nsListAddressEnumerator::CurrentItem(nsISupports **aItem)
NS_IMETHODIMP
nsListAddressEnumerator::GetNext(nsISupports **aResult)
{
if (mCurrentRow)
{
nsresult rv;
rv = mDB->CreateABCard(mCurrentRow, mListRowID, getter_AddRefs(mResultCard));
NS_IF_ADDREF(*aItem = mResultCard);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
*aResult = nsnull;
NS_IMETHODIMP nsListAddressEnumerator::IsDone(void)
{
return mDone ? NS_OK : NS_ERROR_FAILURE;
if (!mDb || !mDbTable || !mDb->GetEnv())
{
return NS_ERROR_NULL_POINTER;
}
if (++mAddressPos <= mAddressTotal)
{
nsCOMPtr<nsIMdbRow> currentRow;
nsresult rv = mDb->GetAddressRowByPos(mListRow, mAddressPos,
getter_AddRefs(currentRow));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbCard> 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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -638,7 +638,7 @@ NS_IMETHODIMP nsAddressBook::ExportAddressBook(nsIDOMWindow *aParentWin, nsIAbDi
nsresult
nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const char *aDelim, PRUint32 aDelimLen, nsILocalFile *aLocalFile)
{
nsCOMPtr <nsIEnumerator> cardsEnumerator;
nsCOMPtr <nsISimpleEnumerator> cardsEnumerator;
nsCOMPtr <nsIAbCard> card;
nsresult rv;
@ -695,8 +695,9 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const
rv = aDirectory->GetChildCards(getter_AddRefs(cardsEnumerator));
if (NS_SUCCEEDED(rv) && cardsEnumerator) {
nsCOMPtr<nsISupports> 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 <nsIAbCard> 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 <nsIEnumerator> cardsEnumerator;
nsCOMPtr <nsISimpleEnumerator> cardsEnumerator;
nsCOMPtr <nsIAbCard> 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<nsISupports> 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 <nsIAbCard> card = do_QueryInterface(item, &rv);
NS_ENSURE_SUCCESS(rv,rv);

Просмотреть файл

@ -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<nsIEnumerator> 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);

Просмотреть файл

@ -365,7 +365,7 @@ nsresult nsAbPalmHotSync::GetAllCards(PRInt32 * aCount, lpnsABCOMCardStruct * aC
return NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIEnumerator> cardsEnumerator;
nsCOMPtr<nsISimpleEnumerator> 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<nsISupports> item;
nsCOMPtr<nsIAbCard> 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<nsIEnumerator> cardsEnumerator;
nsCOMPtr<nsISimpleEnumerator> 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<nsISupports> item;
nsCOMPtr<nsIAbCard> 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;