Bug 32286 Edit mailing list in address book, r=putterman

This commit is contained in:
chuang%netscape.com 2000-06-15 05:10:03 +00:00
Родитель 9c83ce14a6
Коммит 83bdd40bf0
6 изменённых файлов: 130 добавлений и 55 удалений

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

@ -67,5 +67,6 @@ interface nsIAbDirectory : nsISupports {
[noscript] void clearDatabase();
[noscript] void notifyDirItemAdded(in nsISupports item);
[noscript] void removeElementsFromAddressList();
};

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

@ -215,6 +215,10 @@ NS_IMETHODIMP
nsAbDirProperty::NotifyDirItemAdded(nsISupports *item)
{ return NS_OK; }
NS_IMETHODIMP
nsAbDirProperty::RemoveElementsFromAddressList()
{ return NS_OK; }
nsresult nsAbDirProperty::GetAttributeName(PRUnichar **aName, nsString& value)
{
if (aName)

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

@ -406,6 +406,55 @@ NS_IMETHODIMP nsAbDirectory::AddChildCards(const char *uriName, nsIAbCard **chil
return rv;
}
NS_IMETHODIMP nsAbDirectory::RemoveElementsFromAddressList()
{
if (m_AddressList)
{
PRUint32 count;
nsresult rv = m_AddressList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
PRInt32 i;
for (i = count - 1; i >= 0; i--)
m_AddressList->RemoveElementAt(i);
}
m_AddressList = null_nsCOMPtr();
return NS_OK;
}
nsresult nsAbDirectory::RemoveCardFromAddressList(const nsIAbCard* card)
{
nsresult rv = NS_OK;
PRUint32 listTotal;
PRInt32 i, j;
rv = m_AddressList->Count(&listTotal);
for (i = listTotal - 1; i >= 0; i--)
{
nsISupports* pSupport = m_AddressList->ElementAt(i);
if (!pSupport)
continue;
nsCOMPtr<nsIAbDirectory> listDir(do_QueryInterface(pSupport, &rv));
if (listDir)
{
nsISupportsArray* pAddressLists;
listDir->GetAddressLists(&pAddressLists);
if (pAddressLists)
{
PRUint32 total;
rv = pAddressLists->Count(&total);
for (j = total - 1; j >= 0; j--)
{
nsISupports* pSupport = pAddressLists->ElementAt(j);
nsCOMPtr<nsIAbCard> cardInList(do_QueryInterface(pSupport, &rv));
if (card == cardInList.get())
pAddressLists->RemoveElementAt(j);
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP nsAbDirectory::DeleteCards(nsISupportsArray *cards)
{
nsresult rv = NS_OK;
@ -416,9 +465,10 @@ NS_IMETHODIMP nsAbDirectory::DeleteCards(nsISupportsArray *cards)
if (NS_SUCCEEDED(rv) && mDatabase)
{
PRUint32 cardCount;
PRUint32 i;
rv = cards->Count(&cardCount);
if (NS_FAILED(rv)) return rv;
for(PRUint32 i = 0; i < cardCount; i++)
for (i = 0; i < cardCount; i++)
{
nsCOMPtr<nsISupports> cardSupports;
nsCOMPtr<nsIAbCard> card;
@ -454,9 +504,12 @@ NS_IMETHODIMP nsAbDirectory::DeleteCards(nsISupportsArray *cards)
if (listDir)
NotifyItemDeleted(listDir);
PR_smprintf_free(listUri);
return NS_OK;
}
}
else
{
RemoveCardFromAddressList(card);
}
}
}
}
@ -542,70 +595,72 @@ nsresult nsAbDirectory::DeleteDirectoryCards(nsIAbDirectory* directory, DIR_Serv
NS_IMETHODIMP nsAbDirectory::DeleteDirectory(nsIAbDirectory *directory)
{
nsresult rv = NS_ERROR_FAILURE;
nsresult rv = NS_OK;
if (!directory)
return NS_ERROR_FAILURE;
if (directory)
{
DIR_Server *server = nsnull;
rv = directory->GetServer(&server);
if (server)
{ //it's an address book
DeleteDirectoryCards(directory, server);
nsISupportsArray* pAddressLists;
directory->GetAddressLists(&pAddressLists);
if (pAddressLists)
{ //remove mailing list node
PRUint32 total;
rv = pAddressLists->Count(&total);
if (total)
DIR_Server *server = nsnull;
rv = directory->GetServer(&server);
if (server)
{ //it's an address book
nsISupportsArray* pAddressLists;
directory->GetAddressLists(&pAddressLists);
if (pAddressLists)
{ //remove mailing list node
PRUint32 total;
rv = pAddressLists->Count(&total);
if (total)
{
PRInt32 i;
for (i = total - 1; i >= 0; i--)
{
PRInt32 i;
for (i = total - 1; i >= 0; i--)
nsISupports* pSupport = pAddressLists->ElementAt(i);
if (pSupport)
{
nsISupports* pSupport = pAddressLists->ElementAt(i);
if (pSupport)
nsCOMPtr<nsIAbDirectory> listDir(do_QueryInterface(pSupport, &rv));
if (listDir)
{
nsCOMPtr<nsIAbDirectory> listDir(do_QueryInterface(pSupport, &rv));
if (listDir)
directory->DeleteDirectory(listDir);
directory->DeleteDirectory(listDir);
listDir->RemoveElementsFromAddressList();
}
}
pAddressLists->RemoveElement(pSupport);
}
}
DIR_DeleteServerFromList(server);
directory->ClearDatabase();
rv = mSubDirectories->RemoveElement(directory);
NotifyItemDeleted(directory);
}
else
{ //it's a mailing list
nsresult rv = NS_OK;
DIR_DeleteServerFromList(server);
directory->ClearDatabase();
char *uri;
rv = directory->GetDirUri(&uri);
if (NS_FAILED(rv)) return rv;
rv = mSubDirectories->RemoveElement(directory);
NotifyItemDeleted(directory);
}
else
{ //it's a mailing list
nsresult rv = NS_OK;
char *uri;
rv = directory->GetDirUri(&uri);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIAddrDatabase> database;
NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv);
if (NS_SUCCEEDED(rv))
{
rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(database));
nsMemory::Free(uri);
nsCOMPtr<nsIAddrDatabase> database;
NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv);
if (NS_SUCCEEDED(rv))
{
rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(database));
nsMemory::Free(uri);
rv = database->DeleteMailList(directory, PR_TRUE);
if (NS_SUCCEEDED(rv))
rv = database->DeleteMailList(directory, PR_TRUE);
if (NS_SUCCEEDED(rv))
database->Commit(kLargeCommit);
if (NS_SUCCEEDED(rv))
database->Commit(kLargeCommit);
if (m_AddressList)
m_AddressList->RemoveElement(directory);
rv = mSubDirectories->RemoveElement(directory);
if (m_AddressList)
m_AddressList->RemoveElement(directory);
rv = mSubDirectories->RemoveElement(directory);
NotifyItemDeleted(directory);
}
NotifyItemDeleted(directory);
}
}

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

@ -68,6 +68,7 @@ public:
NS_IMETHOD ClearDatabase();
NS_IMETHOD NotifyDirItemAdded(nsISupports *item) { return NotifyItemAdded(item);}
NS_IMETHOD RemoveElementsFromAddressList();
PRBool IsMailingList(){ return (mIsMailingList == 1); }
@ -77,6 +78,7 @@ protected:
nsresult NotifyItemDeleted(nsISupports *item);
nsresult AddChildCards(nsAutoString name, nsIAbCard **childDir);
nsresult DeleteDirectoryCards(nsIAbDirectory* directory, DIR_Server *server);
nsresult RemoveCardFromAddressList(const nsIAbCard* card);
nsresult AddMailList(const char *uriName);

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

@ -1635,7 +1635,8 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewListCardAndAddToDB(PRUint32 listRowID, ns
{
PRUint32 totalAddress = GetListAddressTotal(pListRow) + 1;
SetListAddressTotal(pListRow, totalAddress);
err = AddListCardColumnsToRow(newCard, pListRow, totalAddress);
nsCOMPtr<nsIAbCard> pNewCard;
err = AddListCardColumnsToRow(newCard, pListRow, totalAddress, getter_AddRefs(pNewCard));
// do notification
if (notify)
{
@ -1646,7 +1647,8 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewListCardAndAddToDB(PRUint32 listRowID, ns
}
nsresult nsAddrDatabase::AddListCardColumnsToRow(nsIAbCard *pCard, nsIMdbRow *pListRow, PRUint32 pos)
nsresult nsAddrDatabase::AddListCardColumnsToRow
(nsIAbCard *pCard, nsIMdbRow *pListRow, PRUint32 pos, nsIAbCard** pNewCard)
{
if (!pCard && !pListRow )
return NS_ERROR_NULL_POINTER;
@ -1678,6 +1680,9 @@ nsresult nsAddrDatabase::AddListCardColumnsToRow(nsIAbCard *pCard, nsIMdbRow *pL
//notify RDF a new card row
nsCOMPtr<nsIAbCard> newCard;
CreateABCard(pCardRow, getter_AddRefs(newCard));
*pNewCard = newCard;
NS_IF_ADDREF(*pNewCard);
NotifyCardEntryChange(AB_NotifyInserted, newCard, NULL);
}
PR_FREEIF(pUTF8Email);
@ -1800,7 +1805,12 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM
pCard->GetPrimaryEmail(&email);
PRInt32 emailLength = nsCRT::strlen(email);
if (email && emailLength)
err = AddListCardColumnsToRow(pCard, listRow, pos);
{
nsCOMPtr<nsIAbCard> pNewCard;
err = AddListCardColumnsToRow(pCard, listRow, pos, getter_AddRefs(pNewCard));
if (pNewCard)
pAddressLists->ReplaceElementAt(pNewCard, i);
}
}
}
return NS_OK;
@ -3957,3 +3967,6 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow)
}
return NS_OK;
}

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

@ -301,7 +301,7 @@ protected:
nsresult GetAnonymousAttributesFromDB();
nsresult AddRecordKeyColumnToRow(nsIMdbRow *pRow);
nsresult AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *cardRow);
nsresult AddListCardColumnsToRow(nsIAbCard *pCard, nsIMdbRow *pListRow, PRUint32 pos);
nsresult AddListCardColumnsToRow(nsIAbCard *pCard, nsIMdbRow *pListRow, PRUint32 pos, nsIAbCard** pNewCard);
nsresult AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIMdbRow *listRow);
nsresult RemoveAnonymousList(nsVoidArray* pArray);
nsresult SetAnonymousAttribute(nsVoidArray** pAttrAray,