Part of Bug 410177 Drop nsISupportsArray usage from Address Book where possible - Fix nsIAbDirectory::DeleteCards. r/sr=Neil

This commit is contained in:
bugzilla%standard8.plus.com 2008-01-10 16:57:03 +00:00
Родитель f75d968297
Коммит cec7bb05ab
16 изменённых файлов: 203 добавлений и 153 удалений

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

@ -39,7 +39,10 @@
#include "nsISupports.idl"
#include "nsIAbCard.idl"
#include "nsISupportsArray.idl"
interface nsISimpleEnumerator;
interface nsIArray;
interface nsISupportsArray;
%{C++
/* RDF root for all types of address books */
@ -56,7 +59,7 @@
#define kABFileName_CurrentSuffix ".mab" /* v3 address book extension */
%}
[scriptable, uuid(97d7858d-9222-45c0-813e-2f3b0ea9ac03)]
[scriptable, uuid(2c0af941-5b77-4f26-923b-f3c5de286046)]
interface nsIAbDirectory : nsISupports {
/**
@ -149,9 +152,11 @@ interface nsIAbDirectory : nsISupports {
void modifyCard(in nsIAbCard modifiedCard);
/**
* Deletes the array of cards from the database
* Deletes the array of cards from the database.
*
* @param aCards The cards to delete from the database.
*/
void deleteCards(in nsISupportsArray cards);
void deleteCards(in nsIArray aCards);
void dropCard(in nsIAbCard card, in boolean needToCopyCard);

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

@ -311,7 +311,7 @@ NS_IMETHODIMP nsAbDirProperty::AddCard(nsIAbCard *childCard, nsIAbCard **addedCa
NS_IMETHODIMP nsAbDirProperty::ModifyCard(nsIAbCard *aModifiedCard)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP nsAbDirProperty::DeleteCards(nsISupportsArray *cards)
NS_IMETHODIMP nsAbDirProperty::DeleteCards(nsIArray *cards)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP nsAbDirProperty::DropCard(nsIAbCard *childCard, PRBool needToCopyCard)

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

@ -47,6 +47,7 @@
#include "nsStringGlue.h"
#include "nsUnicharUtils.h"
#include "nsIAbDirSearchListener.h"
#include "nsISimpleEnumerator.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbDirectoryQuerySimpleBooleanExpression, nsIAbBooleanExpression)

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

@ -66,6 +66,7 @@
#include "nsILDAPService.h"
#include "nsIAbLDAPCard.h"
#include "nsAbUtils.h"
#include "nsArrayUtils.h"
#define kDefaultMaxHits 100
@ -721,13 +722,13 @@ NS_IMETHODIMP nsAbLDAPDirectory::AddCard(nsIAbCard *aUpdatedCard,
return NS_OK;
}
NS_IMETHODIMP nsAbLDAPDirectory::DeleteCards(nsISupportsArray *aCards)
NS_IMETHODIMP nsAbLDAPDirectory::DeleteCards(nsIArray *aCards)
{
PRUint32 cardCount;
PRUint32 i;
nsCAutoString cardDN;
nsresult rv = aCards->Count(&cardCount);
nsresult rv = aCards->GetLength(&cardCount);
NS_ENSURE_SUCCESS(rv, rv);
for (i = 0; i < cardCount; ++i)

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

@ -79,7 +79,7 @@ public:
NS_IMETHOD GetSearchDuringLocalAutocomplete(PRBool *aSearchDuringLocalAutocomplete);
NS_IMETHOD AddCard(nsIAbCard *aChildCard, nsIAbCard **aAddedCard);
NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
NS_IMETHOD DeleteCards(nsISupportsArray *aCards);
NS_IMETHOD DeleteCards(nsIArray *aCards);
// nsIAbDirectorySearch methods
NS_DECL_NSIABDIRECTORYSEARCH

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

@ -39,6 +39,7 @@
#define __nsAbLDIFService_h
#include "nsIAbLDIFService.h"
#include "nsCOMPtr.h"
class nsIMdbRow;

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

@ -64,6 +64,7 @@
#include "nsILocalFile.h"
#include "nsComponentManagerUtils.h"
#include "nsMemory.h"
#include "nsArrayUtils.h"
// XXX todo
// fix this -1,0,1 crap, use an enum or #define
@ -497,7 +498,7 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsISimpleEnumerator* *result)
return rv;
}
NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards)
NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsIArray *aCards)
{
nsresult rv = NS_OK;
@ -520,7 +521,7 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards)
nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(resource, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = directory->DeleteCards(cards);
rv = directory->DeleteCards(aCards);
NS_ENSURE_SUCCESS(rv, rv);
rv = database->RemoveListener(this);
@ -535,16 +536,16 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards)
{
PRUint32 cardCount;
PRUint32 i;
rv = cards->Count(&cardCount);
rv = aCards->GetLength(&cardCount);
NS_ENSURE_SUCCESS(rv, rv);
for (i = 0; i < cardCount; i++)
{
nsCOMPtr<nsIAbCard> card;
nsCOMPtr<nsIAbMDBCard> dbcard;
card = do_QueryElementAt(cards, i, &rv);
nsCOMPtr<nsIAbCard> card(do_QueryElementAt(aCards, i, &rv));
NS_ENSURE_SUCCESS(rv, rv);
dbcard = do_QueryInterface(card, &rv);
nsCOMPtr<nsIAbMDBCard> dbcard(do_QueryInterface(card, &rv));
NS_ENSURE_SUCCESS(rv, rv);
if (card)
{
if (IsMailingList())
@ -589,30 +590,23 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards)
nsCOMPtr<nsIRDFService> rdfService =
do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
if(NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIRDFResource> listResource;
rv = rdfService->GetResource(listUri,
getter_AddRefs(listResource));
nsCOMPtr<nsIAbDirectory> listDir = do_QueryInterface(listResource, &rv);
if(NS_SUCCEEDED(rv))
{
if (m_AddressList)
m_AddressList->RemoveElement(listDir);
rv = mSubDirectories.RemoveObject(listDir);
if (listDir)
NotifyItemDeleted(listDir);
}
else
{
return rv;
}
}
else
{
if (NS_FAILED(rv))
return rv;
}
nsCOMPtr<nsIRDFResource> listResource;
rv = rdfService->GetResource(listUri,
getter_AddRefs(listResource));
nsCOMPtr<nsIAbDirectory> listDir = do_QueryInterface(listResource, &rv);
if (NS_FAILED(rv))
return rv;
if (m_AddressList)
m_AddressList->RemoveElement(listDir);
mSubDirectories.RemoveObject(listDir);
if (listDir)
NotifyItemDeleted(listDir);
}
}
else

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

@ -47,7 +47,6 @@
#include "nsAbMDBDirProperty.h"
#include "nsIAbCard.h"
#include "nsCOMArray.h"
#include "nsISupportsArray.h"
#include "nsCOMPtr.h"
#include "nsDirPrefs.h"
#include "nsIAbDirectorySearch.h"
@ -94,7 +93,7 @@ public:
NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result);
NS_IMETHOD GetChildCards(nsISimpleEnumerator* *result);
NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
NS_IMETHOD DeleteCards(nsISupportsArray *cards);
NS_IMETHOD DeleteCards(nsIArray *cards);
NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
NS_IMETHOD AddMailList(nsIAbDirectory *list);

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

@ -59,8 +59,8 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsCRTGlue.h"
#include "nsIArray.h"
#include "nsArrayUtils.h"
#include "nsArrayEnumerator.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gAbOutlookDirectoryLog
@ -257,39 +257,40 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsISimpleEnumerator **aNodes)
NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsISimpleEnumerator **aCards)
{
if (!aCards) { return NS_ERROR_NULL_POINTER ; }
*aCards = nsnull ;
nsCOMPtr<nsISupportsArray> cardList ;
nsresult retCode ;
NS_ENSURE_ARG_POINTER(aCards);
*aCards = nsnull;
nsresult retCode;
nsCOMPtr<nsIMutableArray> cardList(do_CreateInstance(NS_ARRAY_CONTRACTID, &retCode));
mCardList.Reset() ;
if (mIsQueryURI) {
retCode = StartSearch() ;
NS_NewISupportsArray(getter_AddRefs(cardList)) ;
}
else {
retCode = GetChildCards(getter_AddRefs(cardList), nsnull) ;
}
retCode = mIsQueryURI ? StartSearch() : GetChildCards(cardList, nsnull);
if (NS_SUCCEEDED(retCode)) {
// Fill the results array and update the card list
// Also update the address list and notify any changes.
PRUint32 nbCards = 0 ;
nsCOMPtr<nsISupports> element ;
NS_NewArrayEnumerator(aCards, cardList);
cardList->Count(&nbCards) ;
for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
cardList->GetElementAt(i, getter_AddRefs(element)) ;
nsVoidKey newKey (static_cast<void *>(element)) ;
cardList->GetLength(&nbCards);
nsCOMPtr<nsIAbCard> card;
for (PRUint32 i = 0; i < nbCards; ++i) {
card = do_QueryElementAt(cardList, i, &retCode);
if (NS_FAILED(retCode))
continue;
nsVoidKey newKey (static_cast<void *>(card));
nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
if (!oldElement) {
// We are dealing with a new element (probably directly
// added from Outlook), we may need to sync m_AddressList
mCardList.Put(&newKey, element) ;
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
mCardList.Put(&newKey, card);
NS_ENSURE_SUCCESS(retCode, retCode) ;
PRBool isMailList = PR_FALSE ;
retCode = card->GetIsMailList(&isMailList) ;
@ -316,9 +317,8 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsISimpleEnumerator **aCards)
NotifyItemAddition(card) ;
}
}
else {
NS_ASSERTION(oldElement == element, "Different card stored") ;
}
else
NS_WARNING("Card wasn't stored");
}
}
return retCode ;
@ -377,7 +377,7 @@ static nsresult ExtractDirectoryEntry(nsIAbDirectory *aDirectory, nsCString& aEn
return ExtractEntryFromUri(resource, aEntry, kOutlookDirectoryScheme) ;
}
NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsIArray *aCardList)
{
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
if (!aCardList) { return NS_ERROR_NULL_POINTER ; }
@ -387,19 +387,15 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = aCardList->Count(&nbCards) ;
retCode = aCardList->GetLength(&nbCards);
NS_ENSURE_SUCCESS(retCode, retCode) ;
PRUint32 i = 0 ;
nsCOMPtr<nsISupports> element ;
nsCAutoString entryString ;
nsMapiEntry cardEntry ;
for (i = 0 ; i < nbCards ; ++ i) {
retCode = aCardList->GetElementAt(i, getter_AddRefs(element)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsIAbCard> card(do_QueryElementAt(aCardList, i, &retCode));
NS_ENSURE_SUCCESS(retCode, retCode);
retCode = ExtractCardEntry(card, entryString) ;
if (NS_SUCCEEDED(retCode) && !entryString.IsEmpty()) {
@ -409,11 +405,12 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
PRINTF(("Cannot delete card %s.\n", entryString.get())) ;
}
else {
nsVoidKey key (static_cast<void *>(element)) ;
nsVoidKey key (static_cast<void *>(card));
mCardList.Remove(&key) ;
if (m_IsMailList) { m_AddressList->RemoveElement(element) ; }
retCode = NotifyItemDeletion(element) ;
if (m_IsMailList)
m_AddressList->RemoveElement(card);
retCode = NotifyItemDeletion(card);
NS_ENSURE_SUCCESS(retCode, retCode) ;
}
}
@ -1100,15 +1097,17 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
retCode = BuildRestriction(aArguments, arguments);
NS_ENSURE_SUCCESS(retCode, retCode);
nsCOMPtr<nsISupportsArray> resultsArray;
PRUint32 nbResults = 0;
retCode = GetChildCards(getter_AddRefs(resultsArray),
nsCOMPtr<nsIMutableArray> resultsArray(do_CreateInstance(NS_ARRAY_CONTRACTID,
&retCode));
NS_ENSURE_SUCCESS(retCode, retCode);
retCode = GetChildCards(resultsArray,
arguments.rt == RES_COMMENT ? nsnull : &arguments);
DestroyRestriction(arguments);
NS_ENSURE_SUCCESS(retCode, retCode);
retCode = resultsArray->Count(&nbResults);
PRUint32 nbResults = 0;
retCode = resultsArray->GetLength(&nbResults);
NS_ENSURE_SUCCESS(retCode, retCode);
if (aResultLimit > 0 && nbResults > static_cast<PRUint32>(aResultLimit)) {
@ -1116,13 +1115,10 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
}
PRUint32 i = 0;
nsCOMPtr<nsISupports> element;
nsCOMPtr<nsIAbCard> card;
for (i = 0 ; i < nbResults ; ++ i) {
retCode = resultsArray->GetElementAt(i, getter_AddRefs(element));
NS_ENSURE_SUCCESS(retCode, retCode);
nsCOMPtr<nsIAbCard> card(do_QueryInterface(element, &retCode));
card = do_QueryElementAt(resultsArray, i, &retCode);
NS_ENSURE_SUCCESS(retCode, retCode);
aListener->OnSearchFoundCard(card);
@ -1136,6 +1132,8 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
EmptyString());
return retCode;
}
// This version supports nsISupportsArray whilst we are completing bug 410177
nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
void *aRestriction)
{
@ -1176,6 +1174,48 @@ nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
return retCode ;
}
// This function expects the aCards array to already be created.
nsresult nsAbOutlookDirectory::GetChildCards(nsCOMPtr<nsIMutableArray> &aCards,
void *aRestriction)
{
nsAbWinHelperGuard mapiAddBook(mAbWinType);
if (!mapiAddBook->IsOK())
return NS_ERROR_FAILURE;
nsMapiEntryArray cardEntries;
LPSRestriction restriction = (LPSRestriction) aRestriction;
if (!mapiAddBook->GetCards(*mMapiData, restriction, cardEntries)) {
PRINTF(("Cannot get cards.\n"));
return NS_ERROR_FAILURE;
}
nsCAutoString entryId;
nsCAutoString uriName;
nsCOMPtr<nsIRDFResource> resource;
nsCOMPtr<nsIAbCard> childCard;
nsresult rv;
for (ULONG card = 0; card < cardEntries.mNbEntries; ++card) {
cardEntries.mEntries[card].ToString(entryId);
buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName);
uriName.Append(entryId);
childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
resource = do_QueryInterface(childCard, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = resource->Init(uriName.get());
NS_ENSURE_SUCCESS(rv, rv);
aCards->AppendElement(childCard, PR_FALSE);
}
return rv;
}
nsresult nsAbOutlookDirectory::GetChildNodes(nsISupportsArray **aNodes)
{
if (!aNodes) { return NS_ERROR_NULL_POINTER ; }
@ -1234,38 +1274,45 @@ nsresult nsAbOutlookDirectory::NotifyItemAddition(nsISupports *aItem)
// list is supposed to contain at the end.
nsresult nsAbOutlookDirectory::CommitAddressList(void)
{
nsresult retCode = NS_OK ;
nsCOMPtr<nsISupportsArray> oldList ;
PRUint32 nbCards = 0 ;
PRUint32 i = 0 ;
if (!m_IsMailList) {
PRINTF(("We are not in a mailing list, no commit can be done.\n")) ;
return NS_ERROR_UNEXPECTED ;
}
retCode = GetChildCards(getter_AddRefs(oldList), nsnull) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
retCode = m_AddressList->Count(&nbCards) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsISupports> element ;
nsCOMPtr<nsIAbCard> newCard ;
if (!m_IsMailList) {
PRINTF(("We are not in a mailing list, no commit can be done.\n"));
return NS_ERROR_UNEXPECTED;
}
for (i = 0 ; i < nbCards ; ++ i) {
retCode = m_AddressList->GetElementAt(i, getter_AddRefs(element)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
if (!oldList->RemoveElement(element)) {
// The entry was not already there
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
nsresult rv;
PRUint32 i = 0;
nsCOMPtr<nsIMutableArray> oldList(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
retCode = CreateCard(card, getter_AddRefs(newCard)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
m_AddressList->ReplaceElementAt(newCard, i) ;
}
rv = GetChildCards(oldList, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 nbCards = 0;
rv = m_AddressList->Count(&nbCards);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> element;
nsCOMPtr<nsIAbCard> newCard;
PRUint32 pos;
for (i = 0; i < nbCards; ++i) {
rv = m_AddressList->GetElementAt(i, getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_SUCCEEDED(oldList->IndexOf(0, element, &pos))) {
rv = oldList->RemoveElementAt(pos);
NS_ENSURE_SUCCESS(rv, rv);
// The entry was not already there
nsCOMPtr<nsIAbCard> card(do_QueryInterface(element, &rv));
NS_ENSURE_SUCCESS(rv, rv);
rv = CreateCard(card, getter_AddRefs(newCard));
NS_ENSURE_SUCCESS(rv, rv);
m_AddressList->ReplaceElementAt(newCard, i);
}
retCode = DeleteCards(oldList) ;
return retCode ;
}
return DeleteCards(oldList);
}
nsresult nsAbOutlookDirectory::UpdateAddressList(void)

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

@ -44,7 +44,7 @@
#include "nsIAbDirectorySearch.h"
#include "nsIAbDirSearchListener.h"
#include "nsHashtable.h"
#include "nsIMutableArray.h"
#include "nsISupportsArray.h"
struct nsMapiEntry ;
@ -70,7 +70,7 @@ public:
NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
NS_IMETHOD DeleteCards(nsISupportsArray *aCardList);
NS_IMETHOD DeleteCards(nsIArray *aCardList);
NS_IMETHOD DeleteDirectory(nsIAbDirectory *aDirectory);
NS_IMETHOD AddCard(nsIAbCard *aData, nsIAbCard **addedCard);
NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
@ -93,6 +93,7 @@ public:
protected:
// Retrieve hierarchy as cards, with an optional restriction
nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction);
nsresult GetChildCards(nsCOMPtr<nsIMutableArray> &aCards, void *aRestriction);
// Retrieve hierarchy as directories
nsresult GetChildNodes(nsISupportsArray **aNodes);
// Create a new card

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

@ -53,12 +53,12 @@
#include "nsISupportsPrimitives.h"
#include "nsITreeColumns.h"
#include "nsCRTGlue.h"
#include "nsIMutableArray.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIStringBundle.h"
#include "nsIPrefLocalizedString.h"
#include "nsArrayUtils.h"
#include "nsIAddrDatabase.h" // for kPriEmailColumn
#include "rdf.h"
@ -730,9 +730,9 @@ NS_IMETHODIMP nsAbView::SortBy(const PRUnichar *colID, const PRUnichar *sortDir)
SortClosure closure;
SetSortClosure(sortColumn.get(), sortDirection.get(), this, &closure);
nsCOMPtr <nsISupportsArray> selectedCards;
nsCOMPtr<nsIArray> selectedCards;
rv = GetSelectedCards(getter_AddRefs(selectedCards));
NS_ENSURE_SUCCESS(rv,rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbCard> indexCard;
@ -751,7 +751,7 @@ NS_IMETHODIMP nsAbView::SortBy(const PRUnichar *colID, const PRUnichar *sortDir)
mCards.Sort(inplaceSortCallback, (void *)(&closure));
rv = ReselectCards(selectedCards, indexCard);
NS_ENSURE_SUCCESS(rv,rv);
NS_ENSURE_SUCCESS(rv, rv);
mSortColumn = sortColumn.get();
mSortDirection = sortDirection.get();
@ -1073,22 +1073,22 @@ NS_IMETHODIMP nsAbView::GetSortColumn(nsAString & aColumn)
return NS_OK;
}
nsresult nsAbView::ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard)
nsresult nsAbView::ReselectCards(nsIArray *aCards, nsIAbCard *aIndexCard)
{
PRUint32 count;
PRUint32 i;
if (!mTreeSelection || !cards)
if (!mTreeSelection || !aCards)
return NS_OK;
nsresult rv = mTreeSelection->ClearSelection();
NS_ENSURE_SUCCESS(rv,rv);
rv = cards->Count(&count);
rv = aCards->GetLength(&count);
NS_ENSURE_SUCCESS(rv, rv);
for (i = 0; i < count; i++) {
nsCOMPtr <nsIAbCard> card = do_QueryElementAt(cards, i);
nsCOMPtr<nsIAbCard> card = do_QueryElementAt(aCards, i);
if (card) {
PRInt32 index = FindIndexForCard(card);
if (index != CARD_NOT_FOUND) {
@ -1098,8 +1098,8 @@ nsresult nsAbView::ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard)
}
// reset the index card, and ensure it is visible
if (indexCard) {
PRInt32 currentIndex = FindIndexForCard(indexCard);
if (aIndexCard) {
PRInt32 currentIndex = FindIndexForCard(aIndexCard);
rv = mTreeSelection->SetCurrentIndex(currentIndex);
NS_ENSURE_SUCCESS(rv, rv);
@ -1114,34 +1114,34 @@ nsresult nsAbView::ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard)
NS_IMETHODIMP nsAbView::DeleteSelectedCards()
{
nsCOMPtr <nsISupportsArray> cardsToDelete;
nsCOMPtr<nsIArray> cardsToDelete;
nsresult rv = GetSelectedCards(getter_AddRefs(cardsToDelete));
NS_ENSURE_SUCCESS(rv,rv);
NS_ENSURE_SUCCESS(rv, rv);
// mDirectory should not be null
// bullet proof (and assert) to help figure out bug #127748
NS_ENSURE_TRUE(mDirectory, NS_ERROR_UNEXPECTED);
rv = mDirectory->DeleteCards(cardsToDelete);
NS_ENSURE_SUCCESS(rv,rv);
NS_ENSURE_SUCCESS(rv, rv);
return rv;
}
nsresult nsAbView::GetSelectedCards(nsISupportsArray **selectedCards)
nsresult nsAbView::GetSelectedCards(nsIArray **aSelectedCards)
{
*selectedCards = nsnull;
*aSelectedCards = nsnull;
if (!mTreeSelection)
return NS_OK;
PRInt32 selectionCount;
nsresult rv = mTreeSelection->GetRangeCount(&selectionCount);
NS_ENSURE_SUCCESS(rv,rv);
NS_ENSURE_SUCCESS(rv, rv);
if (!selectionCount)
return NS_OK;
rv = NS_NewISupportsArray(selectedCards);
nsCOMPtr<nsIMutableArray> result(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv,rv);
for (PRInt32 i = 0; i < selectionCount; i++)
@ -1158,14 +1158,14 @@ nsresult nsAbView::GetSelectedCards(nsISupportsArray **selectedCards)
rv = GetCardFromRow(rangeIndex, getter_AddRefs(abCard));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsISupports> supports = do_QueryInterface(abCard, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = (*selectedCards)->AppendElement(supports);
NS_ENSURE_SUCCESS(rv,rv);
rv = result->AppendElement(abCard, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
NS_ADDREF(*aSelectedCards = result);
return NS_OK;
}
@ -1306,18 +1306,16 @@ NS_IMETHODIMP nsAbView::GetSelectedAddresses(nsISupportsArray **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsCOMPtr<nsISupportsArray> selectedCards;
nsCOMPtr<nsIArray> selectedCards;
nsresult rv = GetSelectedCards(getter_AddRefs(selectedCards));
NS_ENSURE_SUCCESS(rv,rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsArray> addresses(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID));
PRUint32 count;
selectedCards->Count(&count);
selectedCards->GetLength(&count);
for (PRUint32 i = 0; i < count; i++) {
nsCOMPtr<nsISupports> supports;
selectedCards->GetElementAt(i, getter_AddRefs(supports));
nsCOMPtr<nsIAbCard> card = do_QueryInterface(supports, &rv);
nsCOMPtr<nsIAbCard> card(do_QueryElementAt(selectedCards, i, &rv));
NS_ENSURE_SUCCESS(rv, rv);
PRBool isMailList;

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

@ -94,8 +94,8 @@ private:
nsresult AddPrefObservers();
nsresult RemovePrefObservers();
nsresult SetGeneratedNameFormatFromPrefs();
nsresult GetSelectedCards(nsISupportsArray **cards);
nsresult ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard);
nsresult GetSelectedCards(nsIArray **aSelectedCards);
nsresult ReselectCards(nsIArray *aCards, nsIAbCard *aIndexCard);
nsresult GetCardValue(nsIAbCard *card, const PRUnichar *colID, nsAString &_retval);
nsresult RefreshTree();

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

@ -46,6 +46,7 @@
#include "nsStringGlue.h"
#include "nsIAddrDBListener.h"
#include "nsCOMPtr.h"
#include "nsIEnumerator.h"
typedef enum
{

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

@ -317,10 +317,10 @@ function run_test()
// First delete all existing cards
var childCards = CAB.childCards;
var cardsToDelete = Components.classes["@mozilla.org/supports-array;1"]
.createInstance(Components.interfaces.nsISupportsArray);
var cardsToDelete = Components.classes["@mozilla.org/array;1"]
.createInstance(Components.interfaces.nsIMutableArray);
while (childCards.hasMoreElements()) {
cardsToDelete.AppendElement(childCards.getNext());
cardsToDelete.appendElement(childCards.getNext(), false);
}
CAB.deleteCards(cardsToDelete);

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

@ -44,6 +44,7 @@
#include "nsISupportsObsolete.h"
#include "nsCRTGlue.h"
#include "ImportDebug.h"
#include "nsCOMPtr.h"
////////////////////////////////////////////////////////////////////////

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

@ -71,6 +71,7 @@
#include "nsIPrefBranch.h"
#include "TextDebugLog.h"
#include "nsNetUtil.h"
#include "nsISupportsArray.h"
#define TEXT_MSGS_URL "chrome://messenger/locale/textImportMsgs.properties"
#define TEXTIMPORT_NAME 2000