Bug 32286, 40007, 40764 Edit mailing list related nsbeta2 bugs, r=putterman

This commit is contained in:
chuang%netscape.com 2000-06-08 01:49:57 +00:00
Родитель ad1d7f4412
Коммит f8776d0c8e
14 изменённых файлов: 319 добавлений и 112 удалений

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

@ -64,4 +64,8 @@ interface nsIAbDirectory : nsISupports {
void addAddressToList(in nsIAbCard card);
void addMailListToDatabase(in string uri);
void editMailListToDatabase(in string uri);
[noscript] void clearDatabase();
[noscript] void notifyDirItemAdded(in nsISupports item);
};

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

@ -83,7 +83,9 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
void editAnonymousAttributesFromCard(in nsIAbCard card);
[noscript] readonly attribute nsIMdbRow newRow;
[noscript] readonly attribute nsIMdbRow newListRow;
[noscript] void addCardRowToDB(in nsIMdbRow newRow);
[noscript] void addLdifListMember(in nsIMdbRow row, in string value);
[noscript] void addFirstName(in nsIMdbRow row, in string value);
[noscript] void addLastName(in nsIMdbRow row, in string value);
[noscript] void addDisplayName(in nsIMdbRow row, in string value);
@ -122,6 +124,11 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
[noscript] void addCustom4(in nsIMdbRow row, in string value);
[noscript] void addNotes(in nsIMdbRow row, in string value);
[noscript] void addListName(in nsIMdbRow row, in string value);
[noscript] void addListNickName(in nsIMdbRow row, in string value);
[noscript] void addListDescription(in nsIMdbRow row, in string value);
[noscript] void AddListDirNode(in nsIMdbRow listRow);
[noscript] void createCollationKey(in wstring sourceStr, in nsStringRef resultStr);
};

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

@ -543,7 +543,6 @@ function AbNewList()
function goEditListDialog(abURI, listURI)
{
return;
window.openDialog("chrome://messenger/content/addressbook/abEditListDialog.xul",
"",
"chrome,resizeable=no",

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

@ -71,7 +71,7 @@ Rights Reserved.
<treecell allowevents="true">
<textfield id="address#1"
flex="100%"
onkeydown="if (event.which == 9) awReturnHit(this);"
onkeypress="handleKeyPress(this, event);"
onclick="awNotAnEmptyArea(event);"
autocomplete="true"
timeout="300"

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

@ -25,6 +25,16 @@ var inputElementType = "";
var mailList;
var parentURI;
var editList;
var hitReturnInList = false;
function handleKeyPress(element, event)
{
if (event.which == 13)
{
hitReturnInList = true;
awReturnHit(element);
}
}
function GetListValue(mailList, doAdd)
{
@ -41,12 +51,13 @@ function GetListValue(mailList, doAdd)
mailList.listNickName = document.getElementById('ListNickName').value;
mailList.description = document.getElementById('ListDescription').value;
var oldTotal = mailList.addressLists.Count();
var i = 1;
var pos = 0;
while ((inputField = awGetInputElement(i)))
{
fieldValue = inputField.value;
if (doAdd)
if (doAdd || (doAdd == false && pos >= oldTotal))
var cardproperty = Components.classes["component://netscape/addressbook/cardproperty"].createInstance();
else
var cardproperty = mailList.addressLists.GetElementAt(pos);
@ -67,7 +78,7 @@ function GetListValue(mailList, doAdd)
}
else
cardproperty.primaryEmail = fieldValue;
if (doAdd)
if (doAdd || (doAdd == false && pos >= oldTotal))
mailList.addressLists.AppendElement(cardproperty);
pos++;
}
@ -88,6 +99,11 @@ function GetListValue(mailList, doAdd)
function MailListOKButton()
{
if (hitReturnInList)
{
hitReturnInList = false;
return false;
}
var popup = document.getElementById('abPopup');
if ( popup )
{
@ -151,6 +167,11 @@ function OnLoadMailList()
function EditListOKButton()
{
if (hitReturnInList)
{
hitReturnInList = false;
return false;
}
//Add mailing list to database
if (GetListValue(editList, false))
{
@ -404,8 +425,6 @@ function awRemoveNodeAndChildren(parent, nodeToRemove)
function awSetFocus(row, inputElement)
{
return;
top.awRow = row;
top.awInputElement = inputElement;
top.awFocusRetry = 0;

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

@ -72,10 +72,12 @@ NS_IMETHODIMP nsAbCard::OnCardEntryChange
{
PRUint32 tableID;
PRUint32 rowID;
PRBool bMailList;
card->GetDbTableID(&tableID);
card->GetDbRowID(&rowID);
if (m_dbTableID == tableID && m_dbRowID == rowID)
card->GetIsMailList(&bMailList);
if (m_dbTableID == tableID && m_dbRowID == rowID && m_bIsMailList == bMailList)
{
nsXPIDLString pDisplayName;
card->GetDisplayName(getter_Copies(pDisplayName));

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

@ -62,15 +62,6 @@ nsAbDirProperty::nsAbDirProperty(void)
nsAbDirProperty::~nsAbDirProperty(void)
{
PR_FREEIF(m_DbPath);
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);
}
}
NS_IMPL_ADDREF(nsAbDirProperty)
@ -216,6 +207,14 @@ 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; }
nsresult nsAbDirProperty::GetAttributeName(PRUnichar **aName, nsString& value)
{
if (aName)
@ -370,7 +369,6 @@ NS_IMETHODIMP nsAbDirProperty::EditMailListToDatabase(const char *uri)
listDatabase->Commit(kLargeCommit);
listDatabase = null_nsCOMPtr();
//notify RDF property change
return NS_OK;
}

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

@ -135,49 +135,23 @@ NS_IMETHODIMP nsAbDirectory::OnCardEntryChange
NS_IMETHODIMP nsAbDirectory::OnListEntryChange
(PRUint32 abCode, nsIAbDirectory *list, nsIAddrDBListener *instigator)
{
return NS_OK;
nsresult rv = NS_OK;
if (abCode == AB_NotifyInserted && list)
{
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
if(NS_FAILED(rv))
return rv;
char* listURI = nsnull;
rv = list->GetDirUri(&listURI);
if (NS_FAILED(rv) || !listURI)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIRDFResource> res;
rv = rdf->GetResource(listURI, getter_AddRefs(res));
if(listURI)
nsMemory::Free(listURI);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIAbDirectory> listDir = do_QueryInterface(res);
if (listDir)
{
listDir->CopyMailList(list);
if (mDatabase)
{
nsCOMPtr<nsIAddrDBListener> listener(do_QueryInterface(listDir, &rv));
if (NS_FAILED(rv))
return NS_ERROR_NULL_POINTER;
mDatabase->AddListener(listener);
}
nsCOMPtr<nsISupports> listSupports(do_QueryInterface(listDir));
if (listSupports)
NotifyItemAdded(listSupports);
}
}
}
else if (abCode == AB_NotifyDeleted && list)
if (abCode == AB_NotifyPropertyChanged && list)
{
nsCOMPtr<nsISupports> listSupports(do_QueryInterface(list, &rv));
if(NS_SUCCEEDED(rv))
NotifyItemDeleted(listSupports);
PRBool bIsMailList = PR_FALSE;
list->GetIsMailList(&bIsMailList);
PRUint32 rowID;
list->GetDbRowID(&rowID);
if (bIsMailList && m_dbRowID == rowID)
{
nsXPIDLString pListName;
list->GetListName(getter_Copies(pListName));
if (pListName)
NotifyPropertyChanged("DirName", nsnull,
NS_CONST_CAST(PRUnichar*, (const PRUnichar*)pListName));
}
}
return NS_OK;
}
@ -371,6 +345,17 @@ NS_IMETHODIMP nsAbDirectory::CreateNewMailingList(const char* uri, nsIAbDirector
nsresult rv = AddDirectory(uri, getter_AddRefs(newList));
if (NS_SUCCEEDED(rv) && newList)
{
nsCOMPtr<nsIAddrDatabase> listDatabase;
NS_WITH_SERVICE(nsIAddressBook, addresBook, kAddrBookCID, &rv);
if (NS_SUCCEEDED(rv))
rv = addresBook->GetAbDatabaseFromURI(uri, getter_AddRefs(listDatabase));
if (listDatabase)
{
nsCOMPtr<nsIAddrDBListener> listener(do_QueryInterface(newList, &rv));
if (NS_FAILED(rv))
return NS_ERROR_NULL_POINTER;
listDatabase->AddListener(listener);
}
newList->CopyMailList(list);
AddMailListToDirectory(newList);
NotifyItemAdded(newList);
@ -566,8 +551,30 @@ NS_IMETHODIMP nsAbDirectory::DeleteDirectory(nsIAbDirectory *directory)
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)
{
PRInt32 i;
for (i = total - 1; i >= 0; i--)
{
nsISupports* pSupport = pAddressLists->ElementAt(i);
if (pSupport)
{
nsCOMPtr<nsIAbDirectory> listDir(do_QueryInterface(pSupport, &rv));
if (listDir)
directory->DeleteDirectory(listDir);
}
}
}
}
DIR_DeleteServerFromList(server);
directory->ClearDatabase();
rv = mSubDirectories->RemoveElement(directory);
NotifyItemDeleted(directory);
@ -659,7 +666,17 @@ NS_IMETHODIMP nsAbDirectory::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir)
nsresult nsAbDirectory::NotifyPropertyChanged(char *property, PRUnichar* oldValue, PRUnichar* newValue)
{
return NS_OK;
nsCOMPtr<nsISupports> supports;
if(NS_SUCCEEDED(QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(supports))))
{
//Notify listeners who listen to every folder
nsresult rv;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
if(NS_SUCCEEDED(rv))
abSession->NotifyItemPropertyChanged(supports, property, oldValue, newValue);
}
return NS_OK;
}
nsresult nsAbDirectory::NotifyItemAdded(nsISupports *item)
@ -695,4 +712,12 @@ NS_IMETHODIMP nsAbDirectory::GetDirUri(char **uri)
return NS_RDF_NO_VALUE;
}
NS_IMETHODIMP nsAbDirectory::ClearDatabase()
{
if (mDatabase)
{
mDatabase->RemoveListener(this);
mDatabase = null_nsCOMPtr();
}
return NS_OK;
}

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

@ -66,6 +66,9 @@ public:
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator);
NS_IMETHOD OnListEntryChange(PRUint32 abCode, nsIAbDirectory *list, nsIAddrDBListener *instigator);
NS_IMETHOD ClearDatabase();
NS_IMETHOD NotifyDirItemAdded(nsISupports *item) { return NotifyItemAdded(item);}
PRBool IsMailingList(){ return (mIsMailingList == 1); }
protected:

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

@ -77,6 +77,18 @@ void nsAbRDFDataSource::createNode(PRUint32 value, nsIRDFNode **node)
PR_smprintf_free(valueStr);
}
PRBool nsAbRDFDataSource::changeEnumFunc(nsISupports *aElement, void *aData)
{
nsAbRDFNotification* note = (nsAbRDFNotification *)aData;
nsIRDFObserver* observer = (nsIRDFObserver *)aElement;
observer->OnChange(note->subject,
note->property,
nsnull, note->object);
return PR_TRUE;
}
PRBool nsAbRDFDataSource::assertEnumFunc(nsISupports *aElement, void *aData)
{
nsAbRDFNotification *note = (nsAbRDFNotification *)aData;
@ -100,14 +112,20 @@ PRBool nsAbRDFDataSource::unassertEnumFunc(nsISupports *aElement, void *aData)
}
nsresult nsAbRDFDataSource::NotifyObservers(nsIRDFResource *subject,
nsIRDFResource *property,
nsIRDFNode *object,
PRBool assert)
nsIRDFResource *property,
nsIRDFNode *object,
PRBool assert,
PRBool change)
{
if(mObservers)
NS_ASSERTION(!(change && assert),
"Can't change and assert at the same time!\n");
if (mObservers)
{
nsAbRDFNotification note = { subject, property, object };
if (assert)
if (change)
mObservers->EnumerateForwards(changeEnumFunc, &note);
else if (assert)
mObservers->EnumerateForwards(assertEnumFunc, &note);
else
mObservers->EnumerateForwards(unassertEnumFunc, &note);
@ -117,20 +135,13 @@ nsresult nsAbRDFDataSource::NotifyObservers(nsIRDFResource *subject,
nsresult nsAbRDFDataSource::NotifyPropertyChanged(nsIRDFResource *resource,
nsIRDFResource *propertyResource,
const PRUnichar *oldValue, const PRUnichar *newValue)
const PRUnichar *oldValue,
const PRUnichar *newValue)
{
nsCOMPtr<nsIRDFNode> newValueNode;
nsString newValueStr = newValue;
createNode(newValueStr, getter_AddRefs(newValueNode));
NotifyObservers(resource, propertyResource, newValueNode, PR_TRUE);
if (oldValue)
{
nsCOMPtr<nsIRDFNode> oldValueNode;
nsString oldValueStr = oldValue;
createNode(oldValueStr, getter_AddRefs(oldValueNode));
NotifyObservers(resource, propertyResource, oldValueNode, PR_FALSE);
}
NotifyObservers(resource, propertyResource, newValueNode, PR_FALSE, PR_TRUE);
return NS_OK;
}

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

@ -60,10 +60,11 @@ protected:
const PRUnichar *oldValue, const PRUnichar *newValue);
nsresult NotifyObservers(nsIRDFResource *subject, nsIRDFResource *property,
nsIRDFNode *object, PRBool assert);
nsIRDFNode *object, PRBool assert, PRBool change);
static PRBool assertEnumFunc(nsISupports *aElement, void *aData);
static PRBool unassertEnumFunc(nsISupports *aElement, void *aData);
static PRBool changeEnumFunc(nsISupports *aElement, void *aData);
};

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

@ -49,12 +49,18 @@
#include "nsIPref.h"
#include "nsIMdbFactoryFactory.h"
#include "nsXPIDLString.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsProxyObjectManager.h"
#include "nsProxiedService.h"
static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
static NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
/* The definition is nsAddressBook.cpp */
extern const char *kCardDataSourceRoot;
@ -338,6 +344,24 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *
return NS_OK;
}
nsresult nsAddrDatabase::NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir, nsIAddrDBListener *instigator)
{
if (m_ChangeListeners == nsnull)
return NS_OK;
PRInt32 i;
PRInt32 count = m_ChangeListeners->Count();
for (i = 0; i < count; i++)
{
nsIAddrDBListener *changeListener =
(nsIAddrDBListener *) m_ChangeListeners->ElementAt(i);
nsresult rv = changeListener->OnListEntryChange(abCode, dir, instigator);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
NS_IMETHODIMP nsAddrDatabase::NotifyAnnouncerGoingAway(void)
{
if (m_ChangeListeners == nsnull)
@ -588,12 +612,12 @@ NS_IMETHODIMP nsAddrDatabase::Open
pAddressBookDB->SetDbPath(pabName);
GetDBCache()->AppendElement(pAddressBookDB);
*pAddrDB = pAddressBookDB;
NS_IF_ADDREF(*pAddrDB);
}
else
{
*pAddrDB = nsnull;
if (pAddressBookDB)
delete pAddressBookDB;
NS_IF_RELEASE(pAddressBookDB);
pAddressBookDB = nsnull;
}
@ -1794,6 +1818,7 @@ nsresult nsAddrDatabase::SetListAddressTotal(nsIMdbRow* listRow, PRUint32 total)
return AddIntColumn(listRow, m_ListTotalColumnToken, total);
}
nsresult nsAddrDatabase::GetAddressRowByPos(nsIMdbRow* listRow, PRUint16 pos, nsIMdbRow** cardRow)
{
mdb_token listAddressColumnToken;
@ -1824,7 +1849,7 @@ NS_IMETHODIMP nsAddrDatabase::CreateMailListAndAddToDB(nsIAbDirectory *newList,
if (!newList || !m_mdbPabTable)
return NS_ERROR_NULL_POINTER;
err = GetStore()->NewRow(GetEnv(), m_ListRowScopeToken, &listRow);
err = GetNewListRow(&listRow);
if (NS_SUCCEEDED(err) && listRow)
{
@ -2356,9 +2381,36 @@ NS_IMETHODIMP nsAddrDatabase::EditMailList(nsIAbDirectory *mailList, PRBool noti
mailList->GetDbRowID((PRUint32*)&rowOid.mOid_Id);
err = GetStore()->GetRow(GetEnv(), &rowOid, &pListRow);
if (pListRow)
{
err = AddListAttributeColumnsToRow(mailList, pListRow);
}
if (NS_FAILED(err)) return err;
if (notify)
{
NotifyListEntryChange(AB_NotifyPropertyChanged, mailList, nsnull);
char* listCardURI = nsnull;
char* file = nsnull;
file = m_dbName.GetLeafName();
listCardURI = PR_smprintf("%s%s/ListCard%ld", kCardDataSourceRoot, file, rowOid.mOid_Id);
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &err);
if(NS_FAILED(err))
return err;
nsCOMPtr<nsIRDFResource> listCardResource;
err = rdfService->GetResource(listCardURI, getter_AddRefs(listCardResource));
nsCOMPtr<nsIAbCard> listCard = do_QueryInterface(listCardResource);
if (listCard)
{
GetListCardFromDB(listCard, pListRow);
NotifyCardEntryChange(AB_NotifyPropertyChanged, listCard, nsnull);
}
if (file)
nsCRT::free(file);
if (listCardURI)
PR_smprintf_free(listCardURI);
}
if (pListRow)
pListRow->CutStrongRef(GetEnv());
return NS_OK;
@ -2391,6 +2443,15 @@ NS_IMETHODIMP nsAddrDatabase::GetNewRow(nsIMdbRow * *newRow)
return err;
}
NS_IMETHODIMP nsAddrDatabase::GetNewListRow(nsIMdbRow * *newRow)
{
nsresult err = NS_OK;
nsIMdbRow *row = nsnull;
err = GetStore()->NewRow(GetEnv(), m_ListRowScopeToken, &row);
*newRow = row;
return err;
}
NS_IMETHODIMP nsAddrDatabase::AddCardRowToDB(nsIMdbRow *newRow)
{
if (m_mdbPabTable)
@ -2399,6 +2460,41 @@ NS_IMETHODIMP nsAddrDatabase::AddCardRowToDB(nsIMdbRow *newRow)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsAddrDatabase::AddLdifListMember(nsIMdbRow* listRow, const char* value)
{
PRUint32 total = GetListAddressTotal(listRow);
//add member
nsCAutoString valueString(value);
nsCAutoString email;
PRInt32 emailPos = valueString.Find("mail=");
emailPos += nsCRT::strlen("mail=");
valueString.Right(email, valueString.Length() - emailPos);
char* emailAddress = (char*)email.ToNewCString();
nsIMdbRow *cardRow = nsnull;
mdb_err result = GetRowForEmailAddress(emailAddress, &cardRow);
if (cardRow)
{
mdbOid outOid;
mdb_id rowID = 0;
if (cardRow->GetOid(GetEnv(), &outOid) == NS_OK)
rowID = outOid.mOid_Id;
total += 1;
mdb_token listAddressColumnToken;
char columnStr[16];
sprintf(columnStr, kMailListAddressFormat, total); //let it starts from 1
GetStore()->StringToToken(GetEnv(), columnStr, &listAddressColumnToken);
result = AddIntColumn(listRow, listAddressColumnToken, rowID);
SetListAddressTotal(listRow, total);
cardRow->CutStrongRef(GetEnv());
}
if (emailAddress)
delete [] emailAddress;
return NS_OK;
}
void nsAddrDatabase::GetCharStringYarn(char* str, struct mdbYarn* strYarn)
{
strYarn->mYarn_Grow = NULL;
@ -3154,10 +3250,10 @@ nsresult nsAddrDatabase::GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow)
return err;
}
nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* cardRow)
nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* listRow)
{
nsresult err = NS_OK;
if (!listCard || !cardRow)
if (!listCard || !listRow)
return NS_ERROR_NULL_POINTER;
nsAutoString tempString;
@ -3165,7 +3261,7 @@ nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* cardR
PRUnichar *unicodeStr = nsnull;
PRInt32 unicharLength = 0;
err = GetStringColumn(cardRow, m_ListNameColumnToken, tempString);
err = GetStringColumn(listRow, m_ListNameColumnToken, tempString);
if (NS_SUCCEEDED(err) && tempString.Length())
{
tempCString = tempString.ToNewCString();
@ -3175,7 +3271,7 @@ nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* cardR
nsMemory::Free(tempCString);
PR_Free(unicodeStr);
}
err = GetStringColumn(cardRow, m_ListNickNameColumnToken, tempString);
err = GetStringColumn(listRow, m_ListNickNameColumnToken, tempString);
if (NS_SUCCEEDED(err) && tempString.Length())
{
tempCString = tempString.ToNewCString();
@ -3184,7 +3280,7 @@ nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* cardR
nsMemory::Free(tempCString);
PR_Free(unicodeStr);
}
err = GetStringColumn(cardRow, m_ListDescriptionColumnToken, tempString);
err = GetStringColumn(listRow, m_ListDescriptionColumnToken, tempString);
if (NS_SUCCEEDED(err) && tempString.Length())
{
tempCString = tempString.ToNewCString();
@ -3194,7 +3290,7 @@ nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* cardR
PR_Free(unicodeStr);
}
PRUint32 key = 0;
err = GetIntColumn(cardRow, m_RecordKeyColumnToken, &key, 0);
err = GetIntColumn(listRow, m_RecordKeyColumnToken, &key, 0);
if (NS_SUCCEEDED(err))
listCard->SetRecordKey(key);
return err;
@ -3253,10 +3349,13 @@ nsresult nsAddrDatabase::GetListFromDB(nsIAbDirectory *newList, nsIMdbRow* listR
nsIMdbRow* cardRow;
err = GetIntColumn(listRow, listAddressColumnToken, (PRUint32*)&rowID, 0);
err = GetCardRowByRowID(rowID, &cardRow);
nsCOMPtr<nsIAbCard> card;
err = CreateABCard(cardRow, getter_AddRefs(card));
newList->AddAddressToList(card);
if (cardRow)
{
nsCOMPtr<nsIAbCard> card;
err = CreateABCard(cardRow, getter_AddRefs(card));
newList->AddAddressToList(card);
}
// NS_IF_ADDREF(card);
}
@ -3625,14 +3724,14 @@ nsresult nsAddrDatabase::CreateABCardInList(nsIMdbRow* cardRow, nsIAbCard **resu
}
/* create a card for mailing list in the address book */
nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* cardRow, nsIAbCard **result)
nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result)
{
nsresult rv = NS_OK;
mdbOid outOid;
mdb_id rowID=0;
if (cardRow->GetOid(GetEnv(), &outOid) == NS_OK)
if (listRow->GetOid(GetEnv(), &outOid) == NS_OK)
rowID = outOid.mOid_Id;
if(NS_SUCCEEDED(rv))
@ -3646,7 +3745,7 @@ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* cardRow, nsIAbCard **result
rv = m_dbDirectory->AddChildCards(cardURI, getter_AddRefs(personCard));
if (personCard)
{
GetListCardFromDB(personCard, cardRow);
GetListCardFromDB(personCard, listRow);
mdbOid tableOid;
m_mdbPabTable->GetOid(GetEnv(), &tableOid);
personCard->SetDbTableID(tableOid.mOid_Id);
@ -3701,10 +3800,10 @@ nsresult nsAddrDatabase::CreateABList(nsIMdbRow* listRow, nsIAbDirectory **resul
mailList->SetDbRowID(rowID);
mailList->SetIsMailList(PR_TRUE);
/* nsCOMPtr<nsIAddrDBListener> listener(do_QueryInterface(mailList, &rv));
nsCOMPtr<nsIAddrDBListener> listener(do_QueryInterface(mailList, &rv));
if (NS_FAILED(rv))
return NS_ERROR_NULL_POINTER;
AddListener(listener);*/
AddListener(listener);
m_dbDirectory->AddMailListToDirectory(mailList);
@ -3824,3 +3923,37 @@ NS_IMETHODIMP nsAddrDatabase::GetDirectoryName(PRUnichar **name)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow)
{
nsresult rv = NS_OK;
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
NS_WITH_PROXIED_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIRDFResource> parentResource;
char* file = m_dbName.GetLeafName();
char *parentUri = PR_smprintf("%s%s", kDirectoryDataSourceRoot, file);
rv = rdfService->GetResource( parentUri, getter_AddRefs(parentResource));
nsCOMPtr<nsIAbDirectory> parentDir;
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID( nsIAbDirectory),
parentResource, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( parentDir));
if (parentDir)
{
m_dbDirectory = parentDir;
nsCOMPtr<nsIAbDirectory> mailList;
rv = CreateABList(listRow, getter_AddRefs(mailList));
if (mailList)
parentDir->NotifyDirItemAdded(mailList);
}
if (parentUri)
PR_smprintf_free(parentUri);
if (file)
nsCRT::free(file);
}
return NS_OK;
}

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

@ -109,7 +109,9 @@ public:
NS_IMETHOD EditAnonymousAttributesFromCard(nsIAbCard *card);
NS_IMETHOD GetNewRow(nsIMdbRow * *newRow);
NS_IMETHOD GetNewListRow(nsIMdbRow * *newRow);
NS_IMETHOD AddCardRowToDB(nsIMdbRow *newRow);
NS_IMETHOD AddLdifListMember(nsIMdbRow* row, const char * value);
NS_IMETHOD AddFirstName(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_FirstNameColumnToken, value); }
@ -222,6 +224,17 @@ public:
NS_IMETHOD AddNotes(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_NotesColumnToken, value); }
NS_IMETHOD AddListName(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_ListNameColumnToken, value); }
NS_IMETHOD AddListNickName(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_ListNickNameColumnToken, value); }
NS_IMETHOD AddListDescription(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_ListDescriptionColumnToken, value); }
NS_IMETHOD AddListDirNode(nsIMdbRow * listRow);
NS_IMETHOD CreateCollationKey(const PRUnichar *sourceStr, nsString& resultStr);
NS_IMETHOD GetDirectoryName(PRUnichar **name);
@ -245,7 +258,7 @@ public:
nsresult CreateABCard(nsIMdbRow* cardRow, nsIAbCard **result);
nsresult CreateABCardInList(nsIMdbRow* cardRow, nsIAbCard **result, mdb_id listRowID);
nsresult CreateABListCard(nsIMdbRow* cardRow, nsIAbCard **result);
nsresult CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result);
nsresult CreateABList(nsIMdbRow* listRow, nsIAbDirectory **result);
PRBool IsListRowScopeToken(mdb_scope scope) { return (scope == m_ListRowScopeToken) ? PR_TRUE: PR_FALSE; }
@ -283,8 +296,8 @@ protected:
PRUint32* pValue, PRUint32 defaultValue);
nsresult GetBoolColumn(nsIMdbRow *cardRow, mdb_token outToken, PRBool* pValue);
nsresult GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow);
nsresult GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* cardRow);
nsresult GetListFromDB(nsIAbDirectory *newCard, nsIMdbRow* cardRow);
nsresult GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* listRow);
nsresult GetListFromDB(nsIAbDirectory *newCard, nsIMdbRow* listRow);
nsresult GetAnonymousAttributesFromDB();
nsresult AddRecordKeyColumnToRow(nsIMdbRow *pRow);
nsresult AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *cardRow);
@ -304,18 +317,10 @@ protected:
nsresult SetListAddressTotal(nsIMdbRow* listRow, PRUint32 total);
nsresult DeleteCardFromListRow(nsIMdbRow* pListRow, mdb_id cardRowID);
void DeleteCardFromAllMailLists(mdb_id cardRowID);
nsresult NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir, nsIAddrDBListener *instigator);
nsresult GetCollationKeyGenerator();
nsresult AddListName(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_ListNameColumnToken, value); }
nsresult AddListNickName(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_ListNickNameColumnToken, value); }
nsresult AddListDescription(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_ListDescriptionColumnToken, value); }
static nsVoidArray/*<nsAddrDatabase>*/* GetDBCache();
static nsVoidArray/*<nsAddrDatabase>*/* m_dbCache;

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

@ -425,7 +425,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::OnItemAdded(nsISupports *parentDirectory,
if (NS_SUCCEEDED(rv))
{
//Notify directories that a message was added.
NotifyObservers(parentResource, kNC_CardChild, itemNode, PR_TRUE);
NotifyObservers(parentResource, kNC_CardChild, itemNode, PR_TRUE, PR_FALSE);
}
}
//If we are adding a directory
@ -435,7 +435,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::OnItemAdded(nsISupports *parentDirectory,
if(NS_SUCCEEDED(rv))
{
//Notify a directory was added.
NotifyObservers(parentResource, kNC_Child, itemNode, PR_TRUE);
NotifyObservers(parentResource, kNC_Child, itemNode, PR_TRUE, PR_FALSE);
}
}
}
@ -459,7 +459,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::OnItemRemoved(nsISupports *parentDirector
if(NS_SUCCEEDED(rv))
{
//Notify directories that a card was deleted.
NotifyObservers(parentResource, kNC_CardChild, itemNode, PR_FALSE);
NotifyObservers(parentResource, kNC_CardChild, itemNode, PR_FALSE, PR_FALSE);
}
}
//If we are removing a directory
@ -469,7 +469,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::OnItemRemoved(nsISupports *parentDirector
if(NS_SUCCEEDED(rv))
{
//Notify a directory was deleted.
NotifyObservers(parentResource, kNC_Child, itemNode, PR_FALSE);
NotifyObservers(parentResource, kNC_Child, itemNode, PR_FALSE, PR_FALSE);
}
}
}