Address Book Add, Remove and Edit card landing, approved by chofmann

This commit is contained in:
chuang%netscape.com 1999-07-07 19:06:40 +00:00
Родитель 394c1ec39b
Коммит 6376604f86
31 изменённых файлов: 1542 добавлений и 762 удалений

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

@ -65,4 +65,10 @@
{0x9e, 0xb, 0x0, 0xa0, 0xc9, 0x2b, 0x5f, 0xd} \
}
#define NS_ADDRBOOKSESSION_CID \
{ /* C5339442-303F-11d3-9E13-00A0C92B5F0D */ \
0xc5339442, 0x303f, 0x11d3, \
{0x9e, 0x13, 0x0, 0xa0, 0xc9, 0x2b, 0x5f, 0xd} \
}
#endif // nsAbBaseCID_h__

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

@ -18,7 +18,6 @@
#include "nsIFactory.h"
#include "nsISupports.h"
#include "msgCore.h"
#include "nsAbBaseCID.h"
#include "pratom.h"
#include "nsIComponentManager.h"
@ -36,6 +35,7 @@
#include "nsAbCard.h"
#include "nsAddrDatabase.h"
#include "nsAddressBook.h"
#include "nsAddrBookSession.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
@ -46,6 +46,7 @@ static NS_DEFINE_CID(kAbCardDataSourceCID, NS_ABCARDDATASOURCE_CID);
static NS_DEFINE_CID(kAbCardCID, NS_ABCARDRESOURCE_CID);
static NS_DEFINE_CID(kAddressBookDB, NS_ADDRESSBOOKDB_CID);
static NS_DEFINE_CID(kAbCardPropertyCID, NS_ABCARDPROPERTY_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
////////////////////////////////////////////////////////////
//
@ -218,6 +219,19 @@ nsresult nsAbFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, voi
delete abCardProperty;
return rv;
}
else if (mClassID.Equals(kAddrBookSessionCID))
{
nsresult rv;
nsAddrBookSession * abSession = new nsAddrBookSession();
if (abSession)
rv = abSession->QueryInterface(aIID, aResult);
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv) && abSession)
delete abSession;
return rv;
}
return NS_NOINTERFACE;
}
@ -312,7 +326,12 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
if (NS_FAILED(rv)) finalResult = rv;
rv = compMgr->RegisterComponent(kAddrBookSessionCID,
"Address Book Session",
"component://netscape/addressbook/services/session",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) finalResult = rv;
return finalResult;
}
@ -346,5 +365,11 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* path)
rv = compMgr->UnregisterComponent(kAddressBookDB, path);
if (NS_FAILED(rv)) finalResult = rv;
rv = compMgr->UnregisterComponent(kAbCardPropertyCID, path);
if (NS_FAILED(rv)) finalResult = rv;
rv = compMgr->UnregisterComponent(kAddrBookSessionCID, path);
if (NS_FAILED(rv)) finalResult = rv;
return finalResult;
}

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

@ -31,6 +31,7 @@ XPIDLSRCS = \
nsIAddrDBListener.idl \
nsIAddrDatabase.idl \
nsIAddressBook.idl \
nsIAddrBookSession.idl \
$(NULL)
EXPORTS = \

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

@ -27,6 +27,7 @@ XPIDLSRCS = \
.\nsIAddrDBListener.idl \
.\nsIAddrDatabase.idl \
.\nsIAddressBook.idl \
.\nsIAddrBookSession.idl \
$(NULL)

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

@ -18,12 +18,6 @@
#include "nsICollection.idl"
%{ C++
#include "nsIAbListener.h"
%}
interface nsIAbListener;
[scriptable, uuid(013DD009-F73B-11d2-A2DA-001083003D0C)]
interface nsIAbBase : nsICollection {
@ -35,9 +29,6 @@ interface nsIAbBase : nsICollection {
nsIEnumerator GetChildNodes();
void AddAddrBookListener(in nsIAbListener listener);
void RemoveAddrBookListener(in nsIAbListener listener);
void AddUnique(in nsISupports element);
void ReplaceElement(in nsISupports element, in nsISupports newElement);

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

@ -18,6 +18,12 @@
#include "nsIAbBase.idl"
[ptr] native nsVoidArray(nsVoidArray);
%{C++
#include "nsVoidArray.h"
%}
[scriptable, uuid(FA5C977F-04C8-11d3-A2EB-001083003D0C)]
interface nsIAbCard : nsIAbBase {
@ -66,5 +72,13 @@ interface nsIAbCard : nsIAbBase {
void GetCardValue(in string attrname, out string value);
void SetCardValue(in string attrname, in string value);
void GetAnonymousAttrubutesList(out nsVoidArray attrlist);
void GetAnonymousValuesList(out nsVoidArray valuelist);
void SetAnonymousAttrubutesList(in nsVoidArray attrlist);
void SetAnonymousValuesList(in nsVoidArray valuelist);
void SetAnonymousAttribute(in string attrname, in string value);
void GetCardURI(out string uri);
void AddCardToDatabase();
void EditCardToDatabase();
void CopyCard(in nsIAbCard srcCard);
};

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

@ -18,6 +18,7 @@
#include "nsIAbBase.idl"
#include "nsIAbCard.idl"
#include "nsISupportsArray.idl"
[scriptable, uuid(1920E485-0709-11d3-A2EC-001083003D0C)]
interface nsIAbDirectory : nsIAbBase {
@ -27,4 +28,7 @@ interface nsIAbDirectory : nsIAbBase {
nsIAbCard CreateCardFromDirectory();
void AddChildCards(in string uriName, out nsIAbCard childCard);
void GetDirPosition(out unsigned long pos);
void DeleteCards(in nsISupportsArray cards);
void HasCard(in nsIAbCard cards, out boolean hasCard);
};

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

@ -17,6 +17,7 @@
*/
#include "nsISupports.idl"
#include "nsIAbCard.idl"
interface nsIAddrDBListener;
@ -29,7 +30,7 @@ interface nsIAddrDBAnnouncer : nsISupports {
void NotifyCardAttribChange(in unsigned long abCode,
in nsIAddrDBListener instigator);
void NotifyCardEntryChange (in unsigned long abCode,
in unsigned long entryID,
in nsIAbCard card,
in nsIAddrDBListener instigator);
void NotifyAnnouncerGoingAway();

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

@ -16,6 +16,7 @@
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIAbCard.idl"
interface nsIAddrDBAnnouncer;
@ -25,7 +26,7 @@ interface nsIAddrDBListener : nsISupports {
void OnCardAttribChange(in unsigned long abCode,
in nsIAddrDBListener instigator);
void OnCardEntryChange (in unsigned long abCode,
in unsigned long entryID,
in nsIAbCard card,
in nsIAddrDBListener instigator);
void OnAnnouncerGoingAway(in nsIAddrDBAnnouncer instigator);
};

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

@ -44,6 +44,9 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
void Commit(in unsigned long commitType);
void ForceClosed();
void CreateNewCardAndAddToDB(in nsIAbCard newCard, in boolean benotify);
void CreateNewCardAndAddToDB(in nsIAbCard newCard, in boolean beNotify);
void EnumerateCards(in nsIAbDirectory directory, out nsIEnumerator result);
void DeleteCard(in nsIAbCard card, in boolean beNotify);
void EditCard(in nsIAbCard card, in boolean beNotify);
void ContainsCard(in nsIAbCard card, out boolean hasCard);
};

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

@ -22,6 +22,8 @@
#include "nsIAbCard.idl"
%{C++
#include "nsIDOMNodeList.h"
#include "nsIDOMXULTreeElement.h"
#include "nsIDOMXULElement.h"
%}
@ -31,5 +33,6 @@ interface nsIAddressBook : nsISupports {
void NewCard();
/* void NewCard(in nsIRDFCompositeDataSource database, in nsIDOMXULElement parentFolderElement,
in nsIAbCard card);*/
void DeleteCards(in nsIDOMXULTreeElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node);
};

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

@ -1,3 +1,21 @@
function GetDirectoryTree()
{
var directoryTree = frames[0].frames[0].document.getElementById('dirTree');
return directoryTree;
}
function GetResultTree()
{
var cardTree = frames[0].frames[1].document.getElementById('resultTree');
return cardTree;
}
function GetResultTreeDirectory()
{
var tree = GetResultTree();
return tree.childNodes[5];
}
function AbNewCard()
{
var dialog = window.openDialog("chrome://addressbook/content/newcardDialog.xul",
@ -17,3 +35,19 @@ function AbEditCard(card)
return dialog;
}
function AbDelete()
{
var addressbook = Components.classes["component://netscape/addressbook"].createInstance();
addressbook = addressbook.QueryInterface(Components.interfaces.nsIAddressBook);
dump("\AbDelete from XUL\n");
var tree = GetResultTree();
if(tree) {
dump("tree is valid\n");
//get the selected elements
var cardList = tree.getElementsByAttribute("selected", "true");
//get the current folder
var srcDirectory = GetResultTreeDirectory();
dump("srcDirectory = " + srcDirectory + "\n");
addressbook.DeleteCards(tree, srcDirectory, cardList);
}
}

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

@ -31,7 +31,7 @@
<!ENTITY cutCmd.label ".Cut">
<!ENTITY copyCmd.label ".Copy">
<!ENTITY pasteCmd.label ".Paste">
<!ENTITY deleteCmd.label ".Delete">
<!ENTITY deleteCmd.label "Delete Card">
<!ENTITY selectAllCmd.label ".Select All">
<!ENTITY selectMenu.label ".Search for...">
<!ENTITY findAgainCmd.label ".Find Again">

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

@ -48,6 +48,7 @@ function EditCardOKButton()
SetCardValues(top.card, frames["browser.editcard"].document);
// Need to commit changes here Candice.
top.card.EditCardToDatabase();
top.window.close();
}

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

@ -35,6 +35,7 @@ EXPORTS = \
nsAddressBook.h\
nsAbCardProperty.h\
nsAbRDFResource.h\
nsAddrBookSession.h\
$(NULL)
CPPSRCS = \
@ -47,6 +48,7 @@ CPPSRCS = \
nsAddressBook.cpp\
nsAbCardProperty.cpp\
nsAbRDFResource.cpp\
nsAddrBookSession.cpp\
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

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

@ -33,6 +33,7 @@ EXPORTS= \
nsAddressBook.h \
nsAbCardProperty.h \
nsAbRDFResource.h \
nsAddrBookSession.h \
$(NULL)
################################################################################
@ -50,6 +51,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsAddressBook.obj \
.\$(OBJDIR)\nsAbCardProperty.obj \
.\$(OBJDIR)\nsAbRDFResource.obj \
.\$(OBJDIR)\nsAddrBookSession.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -28,13 +28,16 @@
#include "nsAbBaseCID.h"
#include "prmem.h"
#include "prlog.h"
#include "nsAddrDatabase.h"
#include "nsIAddrBookSession.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kAddressBookDB, NS_ADDRESSBOOKDB_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
nsABCard::nsABCard(void)
: nsRDFResource(), mListeners(nsnull),
: nsAbRDFResource(), mListeners(nsnull),
mInitialized(PR_FALSE),
mCsid(0), mDepth(0), mPrefFlags(0)
{
@ -74,9 +77,6 @@ nsABCard::~nsABCard(void)
mSubDirectories->RemoveElementAt(i);
}
if(mDatabase)
mDatabase->RemoveListener(this);
if (mListeners)
{
PRInt32 i;
@ -86,56 +86,56 @@ nsABCard::~nsABCard(void)
}
}
NS_IMPL_ISUPPORTS_INHERITED(nsABCard, nsRDFResource, nsIAbCard)
NS_IMPL_ISUPPORTS_INHERITED(nsABCard, nsAbRDFResource, nsIAbCard)
////////////////////////////////////////////////////////////////////////////////
typedef PRBool
(*nsArrayFilter)(nsISupports* element, void* data);
#if 0
static nsresult
nsFilterBy(nsISupportsArray* array, nsArrayFilter filter, void* data,
nsISupportsArray* *result)
{
nsCOMPtr<nsISupportsArray> f;
nsresult rv = NS_NewISupportsArray(getter_AddRefs(f));
if (NS_FAILED(rv)) return rv;
PRUint32 i, count;
rv = array->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
for (i = 0; i < count; i++) {
nsCOMPtr<nsISupports> element = getter_AddRefs(array->ElementAt(i));
if (filter(element, data)) {
rv = f->AppendElement(element);
if (NS_FAILED(rv)) {
return rv;
}
}
}
*result = f;
return NS_OK;
}
#endif
////////////////////////////////////////////////////////////////////////////////
/*
NS_IMETHODIMP nsABCard::OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator)
{
return NS_OK;
}
NS_IMETHODIMP nsABCard::OnCardEntryChange
(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator)
(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
{
return NS_OK;
if (abCode == AB_NotifyPropertyChanged && card)
{
PRUint32 tableID;
PRUint32 rowID;
card->GetDbTableID(&tableID);
card->GetDbRowID(&rowID);
if (m_dbTableID == tableID && m_dbRowID == rowID)
{
char* pNewStr = nsnull;
card->GetDisplayName(&pNewStr);
if (pNewStr)
NotifyPropertyChanged("DisplayName", nsnull, pNewStr);
PR_FREEIF(pNewStr);
card->GetPrimaryEmail(&pNewStr);
if (pNewStr)
NotifyPropertyChanged("PrimaryEmail", nsnull, pNewStr);
PR_FREEIF(pNewStr);
card->GetWorkPhone(&pNewStr);
if (pNewStr)
NotifyPropertyChanged("WorkPhone", nsnull, pNewStr);
PR_FREEIF(pNewStr);
}
}
return NS_OK;
}
NS_IMETHODIMP nsABCard::OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator)
nsresult nsABCard::NotifyPropertyChanged(char *property, char* oldValue, char* newValue)
{
return NS_OK;
nsCOMPtr<nsISupports> supports;
if(NS_SUCCEEDED(QueryInterface(nsCOMTypeInfo<nsISupports>::GetIID(), 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 nsABCard::AddSubNode(nsAutoString name, nsIAbCard **childCard)
{
@ -268,8 +268,3 @@ NS_IMETHODIMP nsABCard::IsParentOf(nsIAbCard *child, PRBool deep, PRBool *isPare
return rv;
}
#ifdef HAVE_DB
NS_IMETHOD GetTotalPersonsInDB(PRUint32 *totalPersons) const; // How many messages in database.
#endif

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

@ -27,7 +27,7 @@
#include "nsIAbBase.h"
#include "nsAbCardProperty.h"
#include "nsRDFResource.h"
#include "nsAbRDFResource.h"
#include "nsISupportsArray.h"
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
@ -38,7 +38,7 @@
* Address Book Directory
*/
class nsABCard: public nsRDFResource, public nsAbCardProperty
class nsABCard: public nsAbRDFResource, public nsAbCardProperty
{
public:
@ -73,7 +73,7 @@ public:
// nsIAbBase methods:
/*
NS_IMETHOD GetURI(char* *name) { return nsRDFResource::GetValue(name); }
NS_IMETHOD GetURI(char* *name) { return nsAbRDFResource::GetValue(name); }
NS_IMETHOD GetName(char **name);
NS_IMETHOD SetName(char *name);
NS_IMETHOD GetChildNamed(const char *name, nsISupports* *result);
@ -84,12 +84,6 @@ public:
NS_IMETHOD RemoveAddrBookListener(nsIAbListener * listener);
NS_IMETHOD AddUnique(nsISupports* element);
NS_IMETHOD ReplaceElement(nsISupports* element, nsISupports* newElement);
// nsIAddrDBListener methods:
NS_IMETHOD OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator);
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator);
NS_IMETHOD OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator);
*/
// NS_IMETHOD GetPrettiestName(char ** name);
@ -97,23 +91,20 @@ public:
// NS_IMETHOD OnCloseDirectory();
// NS_IMETHOD Delete();
NS_IMETHODIMP ContainsChildNamed(const char *name, PRBool* containsChild);
NS_IMETHODIMP FindParentOf(nsIAbCard * aDirectory, nsIAbCard ** aParent);
NS_IMETHODIMP IsParentOf(nsIAbCard *child, PRBool deep, PRBool *isParent);
NS_IMETHODIMP ContainsChildNamed(const char *name, PRBool* containsChild);
NS_IMETHODIMP FindParentOf(nsIAbCard * aDirectory, nsIAbCard ** aParent);
NS_IMETHODIMP IsParentOf(nsIAbCard *child, PRBool deep, PRBool *isParent);
// NS_IMETHOD CreateSubDirectory(const char *dirName);
// NS_IMETHOD Rename(const char *name);
// NS_IMETHOD GetDepth(PRUint32 *depth);
// NS_IMETHOD SetDepth(PRUint32 depth);
// nsIAddrDBListener methods:
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator);
#ifdef HAVE_DB
NS_IMETHOD GetTotalPersonsInDB(PRUint32 *totalPersons) const; // How many messages in database.
#endif
protected:
// nsresult NotifyPropertyChanged(char *property, char* oldValue, char* newValue);
nsresult NotifyPropertyChanged(char *property, char* oldValue, char* newValue);
// nsresult NotifyItemAdded(nsISupports *item);
// nsresult NotifyItemDeleted(nsISupports *item);

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

@ -27,6 +27,7 @@
#include "nsAbBaseCID.h"
#include "prmem.h"
#include "prlog.h"
#include "prprf.h"
#include "rdf.h"
#include "nsAddrDatabase.h"
@ -126,6 +127,10 @@ nsAbCardProperty::nsAbCardProperty(void)
m_dbTableID = 0;
m_dbRowID = 0;
m_pAnonymousAttributes = nsnull;
m_pAnonymousValues = nsnull;
}
nsAbCardProperty::~nsAbCardProperty(void)
@ -170,6 +175,43 @@ nsAbCardProperty::~nsAbCardProperty(void)
PR_FREEIF(m_pCustom4);
PR_FREEIF(m_pNote);
RemoveAnonymousAttrubutesList();
RemoveAnonymousValuesList();
}
nsresult nsAbCardProperty::RemoveAnonymousAttrubutesList()
{
if (m_pAnonymousAttributes)
{
PRUint32 count = m_pAnonymousAttributes->Count();
for (int i = count - 1; i >= 0; i--)
{
char* pStr = (char*)m_pAnonymousAttributes->ElementAt(i);
PR_FREEIF(pStr);
m_pAnonymousAttributes->RemoveElementAt(i);
}
delete m_pAnonymousAttributes;
m_pAnonymousAttributes = nsnull;
}
return NS_OK;
}
nsresult nsAbCardProperty::RemoveAnonymousValuesList()
{
if (m_pAnonymousValues)
{
PRUint32 count = m_pAnonymousValues->Count();
for (int i = count - 1; i >= 0; i--)
{
char* pStr = (char*)m_pAnonymousValues->ElementAt(i);
PR_FREEIF(pStr);
m_pAnonymousValues->RemoveElementAt(i);
}
delete m_pAnonymousValues;
m_pAnonymousValues = nsnull;
}
return NS_OK;
}
NS_IMPL_ADDREF(nsAbCardProperty)
@ -198,7 +240,7 @@ NS_IMETHODIMP nsAbCardProperty::OnCardAttribChange(PRUint32 abCode, nsIAddrDBLis
}
NS_IMETHODIMP nsAbCardProperty::OnCardEntryChange
(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator)
(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
{
return NS_OK;
}
@ -345,82 +387,175 @@ NS_IMETHODIMP nsAbCardProperty::GetCardValue(const char *attrname, char **value)
NS_IMETHODIMP nsAbCardProperty::SetCardValue(const char *attrname, const char *value)
{
if (!attrname && !value)
return NS_ERROR_NULL_POINTER;
nsresult rv = NS_OK;
nsAutoString cardValue(value);
char* valueStr = cardValue.ToNewCString();
if (!PL_strcmp(attrname, kFirstNameColumn))
SetFirstName(valueStr);
rv = SetFirstName(valueStr);
else if (!PL_strcmp(attrname, kLastNameColumn))
SetLastName(valueStr);
rv = SetLastName(valueStr);
else if (!PL_strcmp(attrname, kDisplayNameColumn))
SetDisplayName(valueStr);
rv = SetDisplayName(valueStr);
else if (!PL_strcmp(attrname, kNicknameColumn))
SetNickName(valueStr);
rv = SetNickName(valueStr);
else if (!PL_strcmp(attrname, kPriEmailColumn))
SetPrimaryEmail(valueStr);
rv = SetPrimaryEmail(valueStr);
else if (!PL_strcmp(attrname, k2ndEmailColumn))
SetSecondEmail(valueStr);
rv = SetSecondEmail(valueStr);
else if (!PL_strcmp(attrname, kWorkPhoneColumn))
SetWorkPhone(valueStr);
rv = SetWorkPhone(valueStr);
else if (!PL_strcmp(attrname, kHomePhoneColumn))
SetHomePhone(valueStr);
rv = SetHomePhone(valueStr);
else if (!PL_strcmp(attrname, kFaxColumn))
SetFaxNumber(valueStr);
rv = SetFaxNumber(valueStr);
else if (!PL_strcmp(attrname, kPagerColumn))
SetPagerNumber(valueStr);
rv = SetPagerNumber(valueStr);
else if (!PL_strcmp(attrname, kCellularColumn))
SetCellularNumber(valueStr);
rv = SetCellularNumber(valueStr);
else if (!PL_strcmp(attrname, kHomeAddressColumn))
SetHomeAddress(valueStr);
rv = SetHomeAddress(valueStr);
else if (!PL_strcmp(attrname, kHomeAddress2Column))
SetHomeAddress2(valueStr);
rv = SetHomeAddress2(valueStr);
else if (!PL_strcmp(attrname, kHomeCityColumn))
SetHomeCity(valueStr);
rv = SetHomeCity(valueStr);
else if (!PL_strcmp(attrname, kHomeStateColumn))
SetHomeState(valueStr);
rv = SetHomeState(valueStr);
else if (!PL_strcmp(attrname, kHomeZipCodeColumn))
SetHomeZipCode(valueStr);
rv = SetHomeZipCode(valueStr);
else if (!PL_strcmp(attrname, kHomeCountryColumn))
SetHomeCountry(valueStr);
rv = SetHomeCountry(valueStr);
else if (!PL_strcmp(attrname, kWorkAddressColumn))
SetWorkAddress(valueStr);
rv = SetWorkAddress(valueStr);
else if (!PL_strcmp(attrname, kWorkAddress2Column))
SetWorkAddress2(valueStr);
rv = SetWorkAddress2(valueStr);
else if (!PL_strcmp(attrname, kWorkCityColumn))
SetWorkCity(valueStr);
rv = SetWorkCity(valueStr);
else if (!PL_strcmp(attrname, kWorkStateColumn))
SetWorkState(valueStr);
rv = SetWorkState(valueStr);
else if (!PL_strcmp(attrname, kWorkZipCodeColumn))
SetWorkZipCode(valueStr);
rv = SetWorkZipCode(valueStr);
else if (!PL_strcmp(attrname, kWorkCountryColumn))
SetWorkCountry(valueStr);
rv = SetWorkCountry(valueStr);
else if (!PL_strcmp(attrname, kWebPage1Column))
SetWebPage1(valueStr);
rv = SetWebPage1(valueStr);
else if (!PL_strcmp(attrname, kWebPage2Column))
SetWebPage2(valueStr);
rv = SetWebPage2(valueStr);
else if (!PL_strcmp(attrname, kBirthYearColumn))
SetBirthYear(valueStr);
rv = SetBirthYear(valueStr);
else if (!PL_strcmp(attrname, kBirthMonthColumn))
SetBirthMonth(valueStr);
rv = SetBirthMonth(valueStr);
else if (!PL_strcmp(attrname, kBirthDayColumn))
SetBirthDay(valueStr);
rv = SetBirthDay(valueStr);
else if (!PL_strcmp(attrname, kCustom1Column))
SetCustom1(valueStr);
rv = SetCustom1(valueStr);
else if (!PL_strcmp(attrname, kCustom2Column))
SetCustom2(valueStr);
rv = SetCustom2(valueStr);
else if (!PL_strcmp(attrname, kCustom3Column))
SetCustom3(valueStr);
rv = SetCustom3(valueStr);
else if (!PL_strcmp(attrname, kCustom4Column))
SetCustom4(valueStr);
rv = SetCustom4(valueStr);
else if (!PL_strcmp(attrname, kNotesColumn))
SetNotes(valueStr);
/* else handle pass down attribute */
rv = SetNotes(valueStr);
else
rv = SetAnonymousAttribute(attrname, value);
delete[] valueStr;
return rv;
}
NS_IMETHODIMP nsAbCardProperty::GetAnonymousAttrubutesList(nsVoidArray **attrlist)
{
if (attrlist && m_pAnonymousAttributes)
{
*attrlist = m_pAnonymousAttributes;
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsAbCardProperty::GetAnonymousValuesList(nsVoidArray **valuelist)
{
if (valuelist && m_pAnonymousValues)
{
*valuelist = m_pAnonymousValues;
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsAbCardProperty::SetAnonymousAttrubutesList(nsVoidArray *pAttrlist)
{
if (m_pAnonymousAttributes)
RemoveAnonymousAttrubutesList();
m_pAnonymousAttributes = pAttrlist;
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::SetAnonymousValuesList(nsVoidArray *pValuelist)
{
if (m_pAnonymousValues)
RemoveAnonymousValuesList();
m_pAnonymousValues = pValuelist;
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::SetAnonymousAttribute(const char *attrname, const char *value)
{
nsresult rv = NS_OK;
if (!m_pAnonymousAttributes && !m_pAnonymousValues)
{
m_pAnonymousAttributes = new nsVoidArray();
m_pAnonymousValues = new nsVoidArray();
}
if (m_pAnonymousAttributes && m_pAnonymousValues)
{
char* pAttribute = nsnull;
char* pValue = nsnull;
pAttribute = PL_strdup(attrname);
pValue = PL_strdup(value);
if (pAttribute && pValue)
{
m_pAnonymousAttributes->AppendElement(pAttribute);
m_pAnonymousValues->AppendElement(pValue);
}
else
{
PR_FREEIF(pAttribute);
PR_FREEIF(pValue);
rv = NS_ERROR_NULL_POINTER;
}
}
else
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
/* caller need to PR_smprintf_free *uri */
NS_IMETHODIMP nsAbCardProperty::GetCardURI(char **uri)
{
char* cardURI = nsnull;
if (uri && m_dbTableID != 0 && m_dbRowID != 0)
cardURI = PR_smprintf("abcard://Pab%ld/Card%ld", m_dbTableID, m_dbRowID);
if (cardURI)
{
*uri = cardURI;
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsAbCardProperty::AddCardToDatabase()
{
// find out which database, which directory to add
@ -459,3 +594,163 @@ NS_IMETHODIMP nsAbCardProperty::AddCardToDatabase()
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::EditCardToDatabase()
{
// find out which database, which directory to add
// get RDF directory selected node
nsresult openAddrDB = NS_OK;
if (!mDatabase)
{
nsresult rv = NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv))
return rv;
nsIFileSpec* userdir;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, &userdir);
if (NS_FAILED(rv))
return rv;
nsFileSpec dbPath;
userdir->GetFileSpec(&dbPath);
dbPath += "abook.mab";
NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDB, &rv);
if (NS_SUCCEEDED(rv) && addrDBFactory)
openAddrDB = addrDBFactory->Open(&dbPath, PR_TRUE, getter_AddRefs(mDatabase), PR_TRUE);
if (mDatabase)
{
mDatabase->EditCard(this, PR_TRUE);
mDatabase->Close(PR_TRUE);
mDatabase = null_nsCOMPtr();
}
}
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::CopyCard(nsIAbCard* srcCard)
{
char *str = nsnull;
srcCard->GetFirstName(&str);
SetFirstName(str);
PR_FREEIF(str);
srcCard->GetLastName(&str);
SetLastName(str);
PR_FREEIF(str);
srcCard->GetDisplayName(&str);
SetDisplayName(str);
PR_FREEIF(str);
srcCard->GetNickName(&str);
SetNickName(str);
PR_FREEIF(str);
srcCard->GetPrimaryEmail(&str);
SetPrimaryEmail(str);
PR_FREEIF(str);
srcCard->GetSecondEmail(&str);
SetSecondEmail(str);
PR_FREEIF(str);
srcCard->GetWorkPhone(&str);
SetWorkPhone(str);
PR_FREEIF(str);
srcCard->GetHomePhone(&str);
SetHomePhone(str);
PR_FREEIF(str);
srcCard->GetFaxNumber(&str);
SetFaxNumber(str);
PR_FREEIF(str);
srcCard->GetPagerNumber(&str);
SetPagerNumber(str);
PR_FREEIF(str);
srcCard->GetCellularNumber(&str);
SetCellularNumber(str);
PR_FREEIF(str);
srcCard->GetHomeAddress(&str);
SetHomeAddress(str);
PR_FREEIF(str);
srcCard->GetHomeAddress2(&str);
SetHomeAddress2(str);
PR_FREEIF(str);
srcCard->GetHomeCity(&str);
SetHomeCity(str);
PR_FREEIF(str);
srcCard->GetHomeState(&str);
SetHomeState(str);
PR_FREEIF(str);
srcCard->GetHomeZipCode(&str);
SetHomeZipCode(str);
PR_FREEIF(str);
srcCard->GetHomeCountry(&str);
SetHomeCountry(str);
PR_FREEIF(str);
srcCard->GetWorkAddress(&str);
SetWorkAddress(str);
PR_FREEIF(str);
srcCard->GetWorkAddress2(&str);
SetWorkAddress2(str);
PR_FREEIF(str);
srcCard->GetWorkCity(&str);
SetWorkCity(str);
PR_FREEIF(str);
srcCard->GetWorkState(&str);
SetWorkState(str);
PR_FREEIF(str);
srcCard->GetWorkZipCode(&str);
SetWorkZipCode(str);
PR_FREEIF(str);
srcCard->GetWorkCountry(&str);
SetWorkCountry(str);
PR_FREEIF(str);
srcCard->GetJobTitle(&str);
SetJobTitle(str);
PR_FREEIF(str);
srcCard->GetDepartment(&str);
SetDepartment(str);
PR_FREEIF(str);
srcCard->GetCompany(&str);
SetCompany(str);
PR_FREEIF(str);
srcCard->GetWebPage1(&str);
SetWebPage1(str);
PR_FREEIF(str);
srcCard->GetWebPage2(&str);
SetWebPage2(str);
PR_FREEIF(str);
srcCard->GetBirthYear(&str);
SetBirthYear(str);
PR_FREEIF(str);
srcCard->GetBirthMonth(&str);
SetBirthMonth(str);
PR_FREEIF(str);
srcCard->GetBirthDay(&str);
SetBirthDay(str);
PR_FREEIF(str);
srcCard->GetCustom1(&str);
SetCustom1(str);
PR_FREEIF(str);
srcCard->GetCustom2(&str);
SetCustom2(str);
PR_FREEIF(str);
srcCard->GetCustom3(&str);
SetCustom3(str);
PR_FREEIF(str);
srcCard->GetCustom4(&str);
SetCustom4(str);
PR_FREEIF(str);
srcCard->GetNotes(&str);
SetNotes(str);
PR_FREEIF(str);
PRUint32 tableID, rowID;
srcCard->GetDbTableID(&tableID);
SetDbTableID(tableID);
srcCard->GetDbRowID(&rowID);
SetDbRowID(rowID);
return NS_OK;
}

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

@ -27,7 +27,6 @@
#include "nsIAbBase.h"
#include "nsIAbCard.h"
#include "nsRDFResource.h"
#include "nsISupportsArray.h"
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
@ -49,7 +48,7 @@ public:
// nsIAddrDBListener methods:
NS_IMETHOD OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator);
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator);
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator);
NS_IMETHOD OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator);
// nsICollection methods:
@ -85,8 +84,6 @@ public:
NS_IMETHOD GetParent(nsIAbBase* *parent) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetParent(nsIAbBase *parent) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetChildNodes(nsIEnumerator* *result) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD AddAddrBookListener(nsIAbListener * listener) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD RemoveAddrBookListener(nsIAbListener * listener) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD AddUnique(nsISupports* element) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD ReplaceElement(nsISupports* element, nsISupports* newElement) { return NS_ERROR_NOT_IMPLEMENTED; }
@ -176,12 +173,23 @@ public:
NS_IMETHOD GetCardValue(const char *attrname, char **value);
NS_IMETHOD SetCardValue(const char *attrname, const char *value);
NS_IMETHOD GetAnonymousAttrubutesList(nsVoidArray **attrlist);
NS_IMETHOD GetAnonymousValuesList(nsVoidArray **valuelist);
NS_IMETHOD SetAnonymousAttrubutesList(nsVoidArray *pAttrlist);
NS_IMETHOD SetAnonymousValuesList(nsVoidArray *pValuelist);
NS_IMETHOD SetAnonymousAttribute(const char *attrname, const char *value);
NS_IMETHOD GetCardURI(char **uri);
NS_IMETHOD AddCardToDatabase();
NS_IMETHOD EditCardToDatabase();
NS_IMETHOD CopyCard(nsIAbCard* srcCard);
protected:
nsresult GetAttributeName(char **aName, char* pValue);
nsresult SetAttributeName(char *aName, char** arrtibute);
nsresult RemoveAnonymousAttrubutesList();
nsresult RemoveAnonymousValuesList();
char* m_pFirstName;
char* m_pLastName;
@ -226,6 +234,9 @@ protected:
PRUint32 m_dbRowID;
nsCOMPtr<nsIAddrDatabase> mDatabase;
nsVoidArray* m_pAnonymousAttributes;
nsVoidArray* m_pAnonymousValues;
};
#endif

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

@ -16,56 +16,39 @@
* Reserved.
*/
#include "msgCore.h" // precompiled header...
#include "nsAbDirectory.h"
#include "nsIRDFService.h"
#include "nsIRDFResource.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsXPIDLString.h"
#include "nsCOMPtr.h"
#include "nsAbBaseCID.h"
#include "nsAbCard.h"
#include "nsAddrDatabase.h"
#include "nsIAbListener.h"
#include "nsIAddrBookSession.h"
#include "nsIFileSpec.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "mdb.h"
#include "prlog.h"
#include "prprf.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kAbCardCID, NS_ABCARDRESOURCE_CID);
static NS_DEFINE_CID(kAddressBookDB, NS_ADDRESSBOOKDB_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
nsABDirectory::nsABDirectory(void)
: nsRDFResource(), mListeners(nsnull),
: nsAbRDFResource(),
mInitialized(PR_FALSE), mCardInitialized(PR_FALSE),
mCsid(0), mDepth(0), mPrefFlags(0), mDatabase(nsnull)
mCsid(0), mDepth(0), mPrefFlags(0)
{
// NS_INIT_REFCNT(); done by superclass
NS_NewISupportsArray(getter_AddRefs(mSubDirectories));
NS_NewISupportsArray(getter_AddRefs(mSubCards));
//The rdf:addressdirectory datasource is going to be a listener to all nsIAbDirectory, so add
//it as a listener
nsresult rv;
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIRDFDataSource> datasource;
rv = rdfService->GetDataSource("rdf:addressdirectory", getter_AddRefs(datasource));
if(NS_SUCCEEDED(rv))
{ /*
nsCOMPtr<nsIAbListener> directoryListener(do_QueryInterface(datasource, &rv));
if(NS_SUCCEEDED(rv))
{
AddAddrBookListener(directoryListener);
}*/
}
}
}
nsABDirectory::~nsABDirectory(void)
@ -80,74 +63,63 @@ nsABDirectory::~nsABDirectory(void)
mSubDirectories->RemoveElementAt(i);
}
if(mSubCards)
{
PRUint32 count;
nsresult rv = mSubCards->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
PRInt32 i;
for (i = count - 1; i >= 0; i--)
mSubCards->RemoveElementAt(i);
}
if (mDatabase)
{
// mDatabase->RemoveListener(this);
mDatabase->Close(PR_TRUE);
mDatabase = null_nsCOMPtr();
}
if (mListeners)
{
PRInt32 i;
for (i = mListeners->Count() - 1; i >= 0; --i)
mListeners->RemoveElementAt(i);
delete mListeners;
}
}
NS_IMPL_ISUPPORTS_INHERITED(nsABDirectory, nsRDFResource, nsIAbDirectory)
NS_IMPL_ISUPPORTS_INHERITED(nsABDirectory, nsAbRDFResource, nsIAbDirectory)
////////////////////////////////////////////////////////////////////////////////
typedef PRBool
(*nsArrayFilter)(nsISupports* element, void* data);
#if 0
static nsresult
nsFilterBy(nsISupportsArray* array, nsArrayFilter filter, void* data,
nsISupportsArray* *result)
NS_IMETHODIMP
nsABDirectory::OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator)
{
nsCOMPtr<nsISupportsArray> f;
nsresult rv = NS_NewISupportsArray(getter_AddRefs(f));
if (NS_FAILED(rv)) return rv;
PRUint32 count;
rv = array->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
PRInt32 i;
for (i = 0; i < count; i++) {
nsCOMPtr<nsISupports> element = getter_AddRefs(array->ElementAt(i));
if (filter(element, data)) {
rv = f->AppendElement(element);
if (NS_FAILED(rv)) {
return rv;
}
}
}
*result = f;
return NS_OK;
}
#endif
NS_IMETHODIMP
nsABDirectory::OnCardEntryChange
(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
{
nsresult rv = NS_OK;
if (abCode == AB_NotifyInserted && card)
{
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
////////////////////////////////////////////////////////////////////////////////
if(NS_FAILED(rv))
return rv;
char* cardURI = nsnull;
rv = card->GetCardURI(&cardURI);
if (NS_FAILED(rv) || !cardURI)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIRDFResource> res;
rv = rdf->GetResource(cardURI, getter_AddRefs(res));
if(cardURI)
PR_smprintf_free(cardURI);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIAbCard> personCard = do_QueryInterface(res);
personCard->CopyCard(card);
nsCOMPtr<nsISupports> cardSupports(do_QueryInterface(personCard));
if (cardSupports)
{
NotifyItemAdded(cardSupports);
}
}
}
else if (abCode == AB_NotifyDeleted && card)
{
nsCOMPtr<nsISupports> cardSupports(do_QueryInterface(card, &rv));
if(NS_SUCCEEDED(rv))
NotifyItemDeleted(cardSupports);
}
return NS_OK;
}
NS_IMETHODIMP
nsABDirectory::AddUnique(nsISupports* element)
{
// XXX fix this
return mSubDirectories->AppendElement(element);
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
@ -220,40 +192,6 @@ nsresult nsABDirectory::AddSubDirectory(nsAutoString name, nsIAbDirectory **chil
return rv;
}
nsresult nsABDirectory::GetAbDatabase()
{
// find out which database, which directory to add
// get RDF directory selected node
nsresult openAddrDB = NS_OK;
if (!mDatabase)
{
nsresult rv = NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv))
return rv;
nsIFileSpec* userdir;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, &userdir);
if (NS_FAILED(rv))
return rv;
nsFileSpec dbPath;
userdir->GetFileSpec(&dbPath);
dbPath += "abook.mab";
NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDB, &rv);
if (NS_SUCCEEDED(rv) && addrDBFactory)
openAddrDB = addrDBFactory->Open(&dbPath, PR_TRUE, getter_AddRefs(mDatabase), PR_TRUE);
// if (mDatabase)
// mDatabase->AddListener(this);
}
return NS_OK;
}
NS_IMETHODIMP nsABDirectory::GetChildCards(nsIEnumerator* *result)
{
nsresult rv = GetAbDatabase();
@ -300,7 +238,6 @@ NS_IMETHODIMP nsABDirectory::AddChildCards(const char *uriName, nsIAbCard **chil
}
delete[] uriStr;
// mSubCards->AppendElement(personCard);
mSubDirectories->AppendElement(personCard);
*childCard = personCard;
NS_ADDREF(*childCard);
@ -308,33 +245,89 @@ NS_IMETHODIMP nsABDirectory::AddChildCards(const char *uriName, nsIAbCard **chil
return rv;
}
NS_IMETHODIMP nsABDirectory::GetDirPosition(PRUint32 *pos)
{
if (pos)
{
*pos = mPos;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsABDirectory::DeleteCards(nsISupportsArray *cards)
{
nsresult rv = NS_OK;
if (!mDatabase)
rv = GetAbDatabase();
if (NS_SUCCEEDED(rv) && mDatabase)
{
PRUint32 cardCount;
rv = cards->Count(&cardCount);
if (NS_FAILED(rv)) return rv;
for(PRUint32 i = 0; i < cardCount; i++)
{
nsCOMPtr<nsISupports> cardSupports;
nsCOMPtr<nsIAbCard> card;
cardSupports = getter_AddRefs(cards->ElementAt(i));
card = do_QueryInterface(cardSupports, &rv);
if (card)
{
mDatabase->DeleteCard(card, PR_TRUE);
}
}
mDatabase->Commit(kLargeCommit);
}
return rv;
}
NS_IMETHODIMP nsABDirectory::HasCard(nsIAbCard *cards, PRBool *hasCard)
{
if(!hasCard)
return NS_ERROR_NULL_POINTER;
nsresult rv = NS_OK;
if (!mDatabase)
rv = GetAbDatabase();
if(NS_SUCCEEDED(rv) && mDatabase)
{
if(NS_SUCCEEDED(rv))
rv = mDatabase->ContainsCard(cards, hasCard);
}
return rv;
}
NS_IMETHODIMP nsABDirectory::CreateCardFromDirectory(nsIAbCard* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsABDirectory::AddAddrBookListener(nsIAbListener * listener)
nsresult nsABDirectory::NotifyPropertyChanged(char *property, char* oldValue, char* newValue)
{
if (! mListeners)
{
mListeners = new nsVoidArray();
if(!mListeners)
return NS_ERROR_OUT_OF_MEMORY;
}
mListeners->AppendElement(listener);
return NS_OK;
}
NS_IMETHODIMP nsABDirectory::RemoveAddrBookListener(nsIAbListener * listener)
nsresult nsABDirectory::NotifyItemAdded(nsISupports *item)
{
if (! mListeners)
return NS_OK;
mListeners->RemoveElement(listener);
return NS_OK;
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
if(NS_SUCCEEDED(rv))
abSession->NotifyDirectoryItemAdded(this, item);
return NS_OK;
}
nsresult nsABDirectory::NotifyItemDeleted(nsISupports *item)
{
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
if(NS_SUCCEEDED(rv))
abSession->NotifyDirectoryItemDeleted(this, item);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
@ -371,7 +364,10 @@ NS_IMETHODIMP nsABDirectory::GetName(char **name)
if (dirUrl == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
if (!PL_strcmp(mURI, dirUrl))
{
SetName(server->description);
mPos = server->position;
}
delete[] dirUrl;
}
}
@ -497,8 +493,3 @@ NS_IMETHODIMP nsABDirectory::IsParentOf(nsIAbDirectory *child, PRBool deep, PRBo
}
#ifdef HAVE_DB
NS_IMETHOD GetTotalPersonsInDB(PRUint32 *totalPersons) const; // How many messages in database.
#endif

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

@ -25,117 +25,95 @@
#ifndef nsABDirectory_h__
#define nsABDirectory_h__
//#include "msgCore.h"
#include "nsIAbDirectory.h" /* include the interface we are going to support */
#include "nsRDFResource.h"
#include "nsAbRDFResource.h"
#include "nsIAbCard.h"
#include "nsISupportsArray.h"
#include "nsCOMPtr.h"
#include "nsDirPrefs.h"
#include "nsIAddrDatabase.h"
/*
* Address Book Directory
*/
class nsABDirectory: public nsRDFResource, public nsIAbDirectory
class nsABDirectory: public nsAbRDFResource, public nsIAbDirectory
{
public:
nsABDirectory(void);
virtual ~nsABDirectory(void);
nsABDirectory(void);
virtual ~nsABDirectory(void);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_ISUPPORTS_INHERITED
// nsICollection methods:
NS_IMETHOD Count(PRUint32 *result) {
return mSubDirectories->Count(result);
}
NS_IMETHOD GetElementAt(PRUint32 i, nsISupports* *result) {
return mSubDirectories->GetElementAt(i, result);
}
NS_IMETHOD SetElementAt(PRUint32 i, nsISupports* value) {
return mSubDirectories->SetElementAt(i, value);
}
NS_IMETHOD AppendElement(nsISupports *aElement) {
return mSubDirectories->AppendElement(aElement);
}
NS_IMETHOD RemoveElement(nsISupports *aElement) {
return mSubDirectories->RemoveElement(aElement);
}
NS_IMETHOD Enumerate(nsIEnumerator* *result) {
return mSubDirectories->Enumerate(result);
}
NS_IMETHOD Clear(void) {
return mSubDirectories->Clear();
}
// nsICollection methods:
NS_IMETHOD Count(PRUint32 *result) {
return mSubDirectories->Count(result);
}
NS_IMETHOD GetElementAt(PRUint32 i, nsISupports* *result) {
return mSubDirectories->GetElementAt(i, result);
}
NS_IMETHOD SetElementAt(PRUint32 i, nsISupports* value) {
return mSubDirectories->SetElementAt(i, value);
}
NS_IMETHOD AppendElement(nsISupports *aElement) {
return mSubDirectories->AppendElement(aElement);
}
NS_IMETHOD RemoveElement(nsISupports *aElement) {
return mSubDirectories->RemoveElement(aElement);
}
NS_IMETHOD Enumerate(nsIEnumerator* *result) {
return mSubDirectories->Enumerate(result);
}
NS_IMETHOD Clear(void) {
return mSubDirectories->Clear();
}
// nsIAbBase methods:
NS_IMETHOD GetURI(char* *name) { return nsRDFResource::GetValue(name); }
NS_IMETHOD GetName(char **name);
NS_IMETHOD SetName(char *name);
NS_IMETHOD GetChildNamed(const char *name, nsISupports* *result);
NS_IMETHOD GetParent(nsIAbBase* *parent);
NS_IMETHOD SetParent(nsIAbBase *parent);
NS_IMETHOD GetChildNodes(nsIEnumerator* *result);
NS_IMETHOD AddAddrBookListener(nsIAbListener * listener);
NS_IMETHOD RemoveAddrBookListener(nsIAbListener * listener);
// nsIAbBase methods:
NS_IMETHOD GetURI(char* *name) { return nsAbRDFResource::GetValue(name); }
NS_IMETHOD GetName(char **name);
NS_IMETHOD SetName(char *name);
NS_IMETHOD GetChildNamed(const char *name, nsISupports* *result);
NS_IMETHOD GetParent(nsIAbBase* *parent);
NS_IMETHOD SetParent(nsIAbBase *parent);
NS_IMETHOD GetChildNodes(nsIEnumerator* *result);
// nsIAbDirectory methods:
NS_IMETHOD AddUnique(nsISupports* element);
NS_IMETHOD ReplaceElement(nsISupports* element, nsISupports* newElement);
NS_IMETHOD GetChildCards(nsIEnumerator* *result);
NS_IMETHOD CreateCardFromDirectory(nsIAbCard* *result);
NS_IMETHOD AddChildCards(const char *uriName, nsIAbCard **childCard);
// NS_IMETHOD GetVisibleSubFolders(nsIEnumerator* *result);
// nsIAbDirectory methods:
NS_IMETHOD AddUnique(nsISupports* element);
NS_IMETHOD ReplaceElement(nsISupports* element, nsISupports* newElement);
NS_IMETHOD GetChildCards(nsIEnumerator* *result);
NS_IMETHOD CreateCardFromDirectory(nsIAbCard* *result);
NS_IMETHOD AddChildCards(const char *uriName, nsIAbCard **childCard);
NS_IMETHOD GetDirPosition(PRUint32 *pos);
NS_IMETHOD DeleteCards(nsISupportsArray *cards);
NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
// NS_IMETHOD GetPrettyName(char ** name);
// NS_IMETHOD SetPrettyName(char * name);
// NS_IMETHOD BuildDirectoryURL(char ** url);
NS_IMETHOD ContainsChildNamed(const char *name, PRBool* containsChild);
NS_IMETHOD FindParentOf(nsIAbDirectory * aDirectory, nsIAbDirectory ** aParent);
NS_IMETHOD IsParentOf(nsIAbDirectory *child, PRBool deep, PRBool *isParent);
// NS_IMETHOD GetPrettiestName(char ** name);
// NS_IMETHOD OnCloseDirectory();
// NS_IMETHOD Delete();
NS_IMETHODIMP ContainsChildNamed(const char *name, PRBool* containsChild);
NS_IMETHODIMP FindParentOf(nsIAbDirectory * aDirectory, nsIAbDirectory ** aParent);
NS_IMETHODIMP IsParentOf(nsIAbDirectory *child, PRBool deep, PRBool *isParent);
// NS_IMETHOD CreateSubDirectory(const char *dirName);
// NS_IMETHOD Rename(const char *name);
// NS_IMETHOD GetDepth(PRUint32 *depth);
// NS_IMETHOD SetDepth(PRUint32 depth);
#ifdef HAVE_DB
NS_IMETHOD GetTotalPersonsInDB(PRUint32 *totalPersons) const; // How many messages in database.
#endif
// nsIAddrDBListener methods:
NS_IMETHOD OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator);
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator);
protected:
// nsresult NotifyPropertyChanged(char *property, char* oldValue, char* newValue);
// nsresult NotifyItemAdded(nsISupports *item);
// nsresult NotifyItemDeleted(nsISupports *item);
nsresult AddSubDirectory(nsAutoString name, nsIAbDirectory **childDir);
nsresult GetAbDatabase();
nsresult AddChildCards(nsAutoString name, nsIAbCard **childDir);
nsresult NotifyPropertyChanged(char *property, char* oldValue, char* newValue);
nsresult NotifyItemAdded(nsISupports *item);
nsresult NotifyItemDeleted(nsISupports *item);
nsresult AddSubDirectory(nsAutoString name, nsIAbDirectory **childDir);
nsresult AddChildCards(nsAutoString name, nsIAbCard **childDir);
nsVoidArray* GetDirList(){ return DIR_GetDirectories(); }
nsVoidArray* GetDirList(){ return DIR_GetDirectories(); }
protected:
nsString mDirName;
nsCOMPtr<nsISupportsArray> mSubDirectories;
nsCOMPtr<nsISupportsArray> mSubCards;
nsVoidArray *mListeners;
PRBool mInitialized;
PRBool mCardInitialized;
nsString mDirName;
nsCOMPtr<nsISupportsArray> mSubDirectories;
PRBool mInitialized;
PRBool mCardInitialized;
PRInt16 mCsid; // default csid for folder/newsgroup - maintained by fe.
PRUint8 mDepth;
PRInt32 mPrefFlags; // prefs like MSG_PREF_OFFLINE, MSG_PREF_ONE_PANE, etc
PRInt16 mCsid;
PRUint8 mDepth;
PRInt32 mPrefFlags;
nsCOMPtr<nsIAddrDatabase> mDatabase;
PRUint32 mPos;
};

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

@ -36,6 +36,7 @@ nsAbRDFResource::nsAbRDFResource(void)
NS_INIT_REFCNT();
mDatabase = nsnull;
GetAbDatabase();
}
nsAbRDFResource::~nsAbRDFResource(void)

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

@ -30,7 +30,6 @@
#include "prprf.h"
#include "nsIServiceManager.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsICollation.h"
@ -44,33 +43,11 @@ static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
const PRInt32 kAddressBookDBVersion = 1;
enum nsAddrDBCommitType {
kSmallCommit,
kLargeCommit,
kSessionCommit,
kCompressCommit
};
typedef enum
{
AB_NotifyInserted,
AB_NotifyDeleted,
AB_NotifyPropertyChanged,
AB_NotifyAll, /* contents of the have totally changed. Listener must totally
forget anything they knew about the object. */
/* pane notifications (i.e. not tied to a particular entry */
AB_NotifyScramble, /* same contents, but the view indices have all changed
i.e the object was sorted on a different attribute */
AB_NotifyLDAPTotalContentChanged,
AB_NotifyNewTopIndex,
AB_NotifyStartSearching,
AB_NotifyStopSearching
} AB_NOTIFY_CODE;
const char *kAnonymousTableKind = "ns:addrbk:db:table:kind:anonymous";
const char *kAnonymousRowScope = "ns:addrbk:db:row:scope:anonymous:all";
const char *kAnonymousColumn = "Anonymous";
const char *kPabTableKind = "ns:addrbk:db:table:kind:pab";
const char *kBuddyTableKind = "ns:addrbk:db:table:kind:buddy";
const char *kHistoryTableKind = "ns:addrbk:db:table:kind:history";
const char *kMailListTableKind = "ns:addrbk:db:table:kind:maillist";
const char *kCategoryTableKind = "ns:addrbk:db:table:kind:category";
@ -120,19 +97,20 @@ const char *kAddressCharSetColumn = "AddrCharSet";
struct mdbOid gAddressBookTableOID;
struct mdbOid gMailListTableOID;
struct mdbOid gBuddyListTableOID;
struct mdbOid gCategoryTableOID;
struct mdbOid gAnonymousTableOID;
nsAddrDatabase::nsAddrDatabase()
: m_mdbEnv(nsnull), m_mdbStore(nsnull),
m_mdbPabTable(nsnull), m_dbName(""),
m_mdbTokensInitialized(PR_FALSE), m_ChangeListeners(nsnull),
m_pabTableKind(0),
m_buddyTableKind(0),
m_historyTableKind(0),
m_mailListTableKind(0),
m_cardRowScopeToken(0),
m_categoryTableKind(0),
m_mdbPabTable(nsnull), m_mdbRow(nsnull),
m_dbName(""), m_mdbTokensInitialized(PR_FALSE),
m_ChangeListeners(nsnull), m_mdbAnonymousTable(nsnull),
m_AnonymousTableKind(0), m_AnonymousRowScopeToken(0),
m_AnonymousColumnToken(0), m_pAnonymousAttributes(nsnull),
m_pAnonymousValues(nsnull),
m_PabTableKind(0), m_HistoryTableKind(0),
m_MailListTableKind(0), m_CategoryTableKind(0),
m_CardRowScopeToken(0),
m_FirstNameColumnToken(0),
m_LastNameColumnToken(0),
m_DisplayNameColumnToken(0),
@ -246,7 +224,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardAttribChange(PRUint32 abCode, nsIAddrDBL
return NS_OK;
}
NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator)
NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
{
if (m_ChangeListeners == nsnull)
return NS_OK;
@ -255,7 +233,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, PRUint32 en
nsIAddrDBListener *changeListener =
(nsIAddrDBListener *) m_ChangeListeners->ElementAt(i);
nsresult rv = changeListener->OnCardEntryChange(abCode, entryID, instigator);
nsresult rv = changeListener->OnCardEntryChange(abCode, card, instigator);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
@ -622,13 +600,12 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
{
ret = thumb->DoMore(m_mdbEnv, &outTotal, &outCurrent, &outDone, &outBroken);
if (ret != 0)
{// mork isn't really doing NS erorrs yet.
{
outDone = PR_TRUE;
break;
}
}
while (NS_SUCCEEDED(ret) && !outBroken && !outDone);
// m_mdbEnv->ClearErrors(); // ### temporary...
if (NS_SUCCEEDED(ret) && outDone)
{
ret = myMDBFactory->ThumbToOpenStore(m_mdbEnv, thumb, &m_mdbStore);
@ -740,18 +717,33 @@ nsresult nsAddrDatabase::InitNewDB()
nsresult err = NS_OK;
err = InitMDBInfo();
if (err == NS_OK)
if (NS_SUCCEEDED(err))
{
nsIMdbStore *store = GetStore();
// create the unique table for the dbFolderInfo.
mdb_err mdberr;
mdberr = (nsresult) store->NewTable(GetEnv(), m_cardRowScopeToken,
m_pabTableKind, PR_FALSE, &gAddressBookTableOID, &m_mdbPabTable);
err = InitPabTable();
}
return err;
}
nsresult nsAddrDatabase::InitPabTable()
{
nsIMdbStore *store = GetStore();
mdb_err mdberr = (nsresult) store->NewTable(GetEnv(), m_CardRowScopeToken,
m_PabTableKind, PR_FALSE, &gAddressBookTableOID, &m_mdbPabTable);
return mdberr;
}
nsresult nsAddrDatabase::InitAnonymousTable()
{
nsIMdbStore *store = GetStore();
mdb_err mdberr = (nsresult) store->NewTable(GetEnv(), m_AnonymousRowScopeToken,
m_AnonymousTableKind, PR_FALSE, &gAnonymousTableOID, &m_mdbAnonymousTable);
return mdberr;
}
nsresult nsAddrDatabase::InitExistingDB()
{
nsresult err = NS_OK;
@ -760,7 +752,29 @@ nsresult nsAddrDatabase::InitExistingDB()
if (err == NS_OK)
{
err = GetStore()->GetTable(GetEnv(), &gAddressBookTableOID, &m_mdbPabTable);
err = GetStore()->GetTable(GetEnv(), &gAnonymousTableOID, &m_mdbAnonymousTable);
if (m_mdbAnonymousTable)
GetAnonymousAttributesFromDB();
}
return err;
}
#ifdef GetCard
nsresult nsAddrDatabase::GetCardRow()
{
if (m_mdbPabTable)
{
nsCOMPtr <nsIMdbTableRowCursor> rowCursor;
rowPos = -1;
ret= m_mdbPabTable->GetTableRowCursor(GetEnv(), rowPos, getter_addrefs(rowCursor));
if (ret == NS_OK)
{
ret = rowCursor->NextRow(GetEnv(), &m_mdbRow, rowPos);
if (ret == NS_OK && m_mdbRow)
{
LoadMemberVariables();
}
}
nsIMdbRow* cardRow;
nsIMdbTableRowCursor* rowCursor;
mdb_pos rowPos;
@ -782,26 +796,6 @@ nsresult nsAddrDatabase::InitExistingDB()
}
} while (cardRow);
}
return err;
}
#ifdef GetCard
nsresult nsAddrDatabase::GetCardRow()
{
if (m_mdbPabTable)
{
nsCOMPtr <nsIMdbTableRowCursor> rowCursor;
rowPos = -1;
ret= m_mdbPabTable->GetTableRowCursor(GetEnv(), rowPos, getter_addrefs(rowCursor));
if (ret == NS_OK)
{
ret = rowCursor->NextRow(GetEnv(), &m_mdbRow, rowPos);
if (ret == NS_OK && m_mdbRow)
{
LoadMemberVariables();
}
}
}
return ret;
}
#endif
@ -814,7 +808,18 @@ nsresult nsAddrDatabase::InitMDBInfo()
if (!m_mdbTokensInitialized && GetStore())
{
m_mdbTokensInitialized = PR_TRUE;
err = GetStore()->StringToToken(GetEnv(), kCardRowScope, &m_cardRowScopeToken);
err = GetStore()->StringToToken(GetEnv(), kAnonymousRowScope, &m_AnonymousRowScopeToken);
if (NS_SUCCEEDED(err))
{
GetStore()->StringToToken(GetEnv(), kAnonymousColumn, &m_AnonymousColumnToken);
err = GetStore()->StringToToken(GetEnv(), kAnonymousTableKind, &m_AnonymousTableKind);
if (NS_SUCCEEDED(err))
{
gAnonymousTableOID.mOid_Scope = m_AnonymousTableKind;
gAnonymousTableOID.mOid_Id = 1;
}
}
err = GetStore()->StringToToken(GetEnv(), kCardRowScope, &m_CardRowScopeToken);
if (NS_SUCCEEDED(err))
{
GetStore()->StringToToken(GetEnv(), kFirstNameColumn, &m_FirstNameColumnToken);
@ -855,22 +860,11 @@ nsresult nsAddrDatabase::InitMDBInfo()
GetStore()->StringToToken(GetEnv(), kNotesColumn, &m_NotesColumnToken);
GetStore()->StringToToken(GetEnv(), kAddressCharSetColumn, &m_AddressCharSetColumnToken);
err = GetStore()->StringToToken(GetEnv(), kPabTableKind, &m_pabTableKind);
err = GetStore()->StringToToken(GetEnv(), kPabTableKind, &m_PabTableKind);
if (NS_SUCCEEDED(err))
{
GetStore()->StringToToken(GetEnv(), kBuddyTableKind, &m_buddyTableKind);
GetStore()->StringToToken(GetEnv(), kMailListTableKind, &m_mailListTableKind);
GetStore()->StringToToken(GetEnv(), kCategoryTableKind, &m_categoryTableKind);
// The rows have 4 mOids. Maillist , buddylist and category tables
// have the same oids as maillist , buddylist and category rows
gAddressBookTableOID.mOid_Scope = m_cardRowScopeToken;
gAddressBookTableOID.mOid_Scope = m_CardRowScopeToken;
gAddressBookTableOID.mOid_Id = 1;
gMailListTableOID.mOid_Scope = m_mailListTableKind;
gMailListTableOID.mOid_Id = 1;
gBuddyListTableOID.mOid_Scope = m_buddyTableKind;
gBuddyListTableOID.mOid_Id = 1;
gCategoryTableOID.mOid_Scope = m_categoryTableKind;
gCategoryTableOID.mOid_Id = 1;
}
}
}
@ -879,6 +873,209 @@ nsresult nsAddrDatabase::InitMDBInfo()
////////////////////////////////////////////////////////////////////////////////
nsresult nsAddrDatabase::AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *cardRow)
{
nsresult err = NS_OK;
if (!card && !cardRow )
return NS_ERROR_NULL_POINTER;
mdbOid rowOid, tableOid;
m_mdbPabTable->GetOid(GetEnv(), &tableOid);
cardRow->GetOid(GetEnv(), &rowOid);
card->SetDbTableID(tableOid.mOid_Id);
card->SetDbRowID(rowOid.mOid_Id);
// add the row to the singleton table.
if (NS_SUCCEEDED(err) && cardRow)
{
char* pStr = nsnull;
card->GetFirstName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_FirstNameColumnToken, pStr);
PR_FREEIF(pStr);
card->GetLastName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_LastNameColumnToken, pStr);
PR_FREEIF(pStr);
card->GetDisplayName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_DisplayNameColumnToken, pStr);
PR_FREEIF(pStr);
card->GetNickName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_NickNameColumnToken, pStr);
PR_FREEIF(pStr);
card->GetPrimaryEmail(&pStr);
if (pStr)
AddCardColumn(cardRow, m_PriEmailColumnToken, pStr);
PR_FREEIF(pStr);
card->GetSecondEmail(&pStr);
if (pStr)
AddCardColumn(cardRow, m_2ndEmailColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkPhone(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkPhoneColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomePhone(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomePhoneColumnToken, pStr);
PR_FREEIF(pStr);
card->GetFaxNumber(&pStr);
if (pStr)
AddCardColumn(cardRow, m_FaxColumnToken, pStr);
PR_FREEIF(pStr);
card->GetPagerNumber(&pStr);
if (pStr)
AddCardColumn(cardRow, m_PagerColumnToken, pStr);
PR_FREEIF(pStr);
card->GetCellularNumber(&pStr);
if (pStr)
AddCardColumn(cardRow, m_CellularColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomeAddress(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeAddressColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomeAddress2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeAddress2ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomeCity(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeCityColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomeState(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeStateColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomeZipCode(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeZipCodeColumnToken, pStr);
PR_FREEIF(pStr);
card->GetHomeCountry(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeCountryColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkAddress(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkAddressColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkAddress2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkAddress2ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkCity(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkCityColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkState(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkStateColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkZipCode(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkZipCodeColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWorkCountry(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkCountryColumnToken, pStr);
PR_FREEIF(pStr);
card->GetJobTitle(&pStr);
if (pStr)
AddCardColumn(cardRow, m_JobTitleColumnToken, pStr);
PR_FREEIF(pStr);
card->GetDepartment(&pStr);
if (pStr)
AddCardColumn(cardRow, m_DepartmentColumnToken, pStr);
PR_FREEIF(pStr);
card->GetCompany(&pStr);
if (pStr)
AddCardColumn(cardRow, m_CompanyColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWebPage1(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WebPage1ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetWebPage2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WebPage2ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetBirthYear(&pStr);
if (pStr)
AddCardColumn(cardRow, m_BirthYearColumnToken, pStr);
PR_FREEIF(pStr);
card->GetBirthMonth(&pStr);
if (pStr)
AddCardColumn(cardRow, m_BirthMonthColumnToken, pStr);
PR_FREEIF(pStr);
card->GetBirthDay(&pStr);
if (pStr)
AddCardColumn(cardRow, m_BirthDayColumnToken, pStr);
PR_FREEIF(pStr);
card->GetCustom1(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom1ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetCustom2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom2ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetCustom3(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom3ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetCustom4(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom4ColumnToken, pStr);
PR_FREEIF(pStr);
card->GetNotes(&pStr);
if (pStr)
AddCardColumn(cardRow, m_NotesColumnToken, pStr);
PR_FREEIF(pStr);
AddAnonymousAttributesToDB(card, cardRow);
}
return NS_OK;
}
NS_IMETHODIMP nsAddrDatabase::CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool notify /* = FALSE */)
{
nsresult err = NS_OK;
@ -887,160 +1084,11 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool
if (!newCard || !m_mdbPabTable)
return NS_ERROR_NULL_POINTER;
err = GetStore()->NewRow(GetEnv(), m_cardRowScopeToken, &cardRow);
err = GetStore()->NewRow(GetEnv(), m_CardRowScopeToken, &cardRow);
mdbOid rowOid;
cardRow->GetOid(GetEnv(), &rowOid);
// add the row to the singleton table.
if (NS_SUCCEEDED(err) && cardRow)
{
char* pStr = nsnull;
newCard->GetFirstName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_FirstNameColumnToken, pStr);
newCard->GetLastName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_LastNameColumnToken, pStr);
newCard->GetDisplayName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_DisplayNameColumnToken, pStr);
newCard->GetNickName(&pStr);
if (pStr)
AddCardColumn(cardRow, m_NickNameColumnToken, pStr);
newCard->GetPrimaryEmail(&pStr);
if (pStr)
AddCardColumn(cardRow, m_PriEmailColumnToken, pStr);
newCard->GetSecondEmail(&pStr);
if (pStr)
AddCardColumn(cardRow, m_2ndEmailColumnToken, pStr);
newCard->GetWorkPhone(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkPhoneColumnToken, pStr);
newCard->GetHomePhone(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomePhoneColumnToken, pStr);
newCard->GetFaxNumber(&pStr);
if (pStr)
AddCardColumn(cardRow, m_FaxColumnToken, pStr);
newCard->GetPagerNumber(&pStr);
if (pStr)
AddCardColumn(cardRow, m_PagerColumnToken, pStr);
newCard->GetCellularNumber(&pStr);
if (pStr)
AddCardColumn(cardRow, m_CellularColumnToken, pStr);
newCard->GetHomeAddress(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeAddressColumnToken, pStr);
newCard->GetHomeAddress2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeAddress2ColumnToken, pStr);
newCard->GetHomeCity(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeCityColumnToken, pStr);
newCard->GetHomeState(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeStateColumnToken, pStr);
newCard->GetHomeZipCode(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeZipCodeColumnToken, pStr);
newCard->GetHomeCountry(&pStr);
if (pStr)
AddCardColumn(cardRow, m_HomeCountryColumnToken, pStr);
newCard->GetWorkAddress(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkAddressColumnToken, pStr);
newCard->GetWorkAddress2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkAddress2ColumnToken, pStr);
newCard->GetWorkCity(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkCityColumnToken, pStr);
newCard->GetWorkState(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkStateColumnToken, pStr);
newCard->GetWorkZipCode(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkZipCodeColumnToken, pStr);
newCard->GetWorkCountry(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WorkCountryColumnToken, pStr);
newCard->GetJobTitle(&pStr);
if (pStr)
AddCardColumn(cardRow, m_JobTitleColumnToken, pStr);
newCard->GetDepartment(&pStr);
if (pStr)
AddCardColumn(cardRow, m_DepartmentColumnToken, pStr);
newCard->GetCompany(&pStr);
if (pStr)
AddCardColumn(cardRow, m_CompanyColumnToken, pStr);
newCard->GetWebPage1(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WebPage1ColumnToken, pStr);
newCard->GetWebPage2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_WebPage2ColumnToken, pStr);
newCard->GetBirthYear(&pStr);
if (pStr)
AddCardColumn(cardRow, m_BirthYearColumnToken, pStr);
newCard->GetBirthMonth(&pStr);
if (pStr)
AddCardColumn(cardRow, m_BirthMonthColumnToken, pStr);
newCard->GetBirthDay(&pStr);
if (pStr)
AddCardColumn(cardRow, m_BirthDayColumnToken, pStr);
newCard->GetCustom1(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom1ColumnToken, pStr);
newCard->GetCustom2(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom2ColumnToken, pStr);
newCard->GetCustom3(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom3ColumnToken, pStr);
newCard->GetCustom4(&pStr);
if (pStr)
AddCardColumn(cardRow, m_Custom4ColumnToken, pStr);
newCard->GetNotes(&pStr);
if (pStr)
AddCardColumn(cardRow, m_NotesColumnToken, pStr);
AddAttributeColumnsToRow(newCard, cardRow);
err = m_mdbPabTable->AddRow(GetEnv(), cardRow);
}
if (NS_FAILED(err)) return err;
@ -1048,11 +1096,113 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool
// do notification
if (notify)
{
NotifyCardEntryChange(AB_NotifyInserted, 0, NULL);
NotifyCardEntryChange(AB_NotifyInserted, newCard, NULL);
}
return err;
}
nsresult nsAddrDatabase::AddAnonymousAttributesToDB(nsIAbCard *newCard, nsIMdbRow *cardRow)
{
nsresult err = NS_OK;
PRUint32 count, i;
nsVoidArray *pAttrArray = nsnull;
err = newCard->GetAnonymousAttrubutesList(&pAttrArray);
nsVoidArray *pValueArray = nsnull;
err = newCard->GetAnonymousValuesList(&pValueArray);
if (pAttrArray && pValueArray)
{
if (!m_mdbAnonymousTable)
err = InitAnonymousTable();
if (NS_SUCCEEDED(err) && m_mdbAnonymousTable)
{
count = pAttrArray->Count();
for (i = 0; i < count; i++)
{
char* pAttrStr = (char*)pAttrArray->ElementAt(i);
nsIMdbRow *attributeRow;
err = GetStore()->NewRow(GetEnv(), m_AnonymousRowScopeToken, &attributeRow);
if (NS_SUCCEEDED(err) && attributeRow)
{
AddCardColumn(attributeRow, m_AnonymousColumnToken, pAttrStr);
err = m_mdbAnonymousTable->AddRow(GetEnv(), attributeRow);
}
mdb_token anonymousColumnToken;
GetStore()->StringToToken(GetEnv(), pAttrStr, &anonymousColumnToken);
char* pValueStr = (char*)pValueArray->ElementAt(i);
AddCardColumn(cardRow, anonymousColumnToken, pValueStr);
}
}
}
return err;
}
NS_IMETHODIMP nsAddrDatabase::DeleteCard(nsIAbCard *card, PRBool notify)
{
nsresult err = NS_OK;
if (!card || !m_mdbPabTable)
return NS_ERROR_NULL_POINTER;
// get the right row
nsIMdbRow* pCardRow = nsnull;
mdbOid rowOid;
rowOid.mOid_Scope = m_CardRowScopeToken;
card->GetDbRowID((PRUint32*)&rowOid.mOid_Id);
err = GetStore()->GetRow(GetEnv(), &rowOid, &pCardRow);
if (pCardRow)
{
err = m_mdbPabTable->CutRow(GetEnv(), pCardRow);
if (notify)
NotifyCardEntryChange(AB_NotifyDeleted, card, NULL);
}
return NS_OK;
}
NS_IMETHODIMP nsAddrDatabase::EditCard(nsIAbCard *card, PRBool notify)
{
if (!card || !m_mdbPabTable)
return NS_ERROR_NULL_POINTER;
nsresult err = NS_OK;
nsIMdbRow* pCardRow = nsnull;
mdbOid rowOid;
rowOid.mOid_Scope = m_CardRowScopeToken;
card->GetDbRowID((PRUint32*)&rowOid.mOid_Id);
err = GetStore()->GetRow(GetEnv(), &rowOid, &pCardRow);
if (pCardRow)
err = AddAttributeColumnsToRow(card, pCardRow);
if (NS_FAILED(err)) return err;
if (notify)
NotifyCardEntryChange(AB_NotifyPropertyChanged, card, NULL);
return NS_OK;
}
NS_IMETHODIMP nsAddrDatabase::ContainsCard(nsIAbCard *card, PRBool *hasCard)
{
if (!card || !m_mdbPabTable)
return NS_ERROR_NULL_POINTER;
nsresult err = NS_OK;
mdb_bool hasOid;
mdbOid rowOid;
rowOid.mOid_Scope = m_CardRowScopeToken;
card->GetDbRowID((PRUint32*)&rowOid.mOid_Id);
err = m_mdbPabTable->HasOid(GetEnv(), &rowOid, &hasOid);
if (NS_SUCCEEDED(err))
*hasCard = hasOid;
return err;
}
mdb_err nsAddrDatabase::AddCardColumn(nsIMdbRow* cardRow, mdb_column inColumn, char* str)
{
struct mdbYarn yarn;
@ -1063,12 +1213,11 @@ mdb_err nsAddrDatabase::AddCardColumn(nsIMdbRow* cardRow, mdb_column inColumn, c
yarn.mYarn_Fill = yarn.mYarn_Size - 1;
yarn.mYarn_Form = 0; // what to do with this? we're storing csid in the msg hdr...
mdb_err err = cardRow->AddColumn(GetEnv(), inColumn, &yarn);
PR_FREEIF(str);
return err;
}
nsresult nsAddrDatabase::GetStringColumn(nsIMdbRow *cardRow, mdb_token outToken, nsString &str)
nsresult nsAddrDatabase::GetStringColumn(nsIMdbRow *cardRow, mdb_token outToken, nsString& str)
{
nsresult err = NS_OK;
nsIMdbCell *cardCell;
@ -1087,6 +1236,42 @@ nsresult nsAddrDatabase::GetStringColumn(nsIMdbRow *cardRow, mdb_token outToken,
return err;
}
nsresult nsAddrDatabase::GetAnonymousAttributesFromDB()
{
if (m_mdbAnonymousTable)
{
nsIMdbRow* cardRow;
nsIMdbTableRowCursor* rowCursor;
mdb_pos rowPos;
m_mdbAnonymousTable->GetTableRowCursor(GetEnv(), -1, &rowCursor);
do
{
mdb_err err = rowCursor->NextRow(GetEnv(), &cardRow, &rowPos);
if (NS_SUCCEEDED(err) && cardRow)
{
nsAutoString attrString;
GetStringColumn(cardRow, m_AnonymousColumnToken, attrString);
if (attrString.Length())
{
if (!m_pAnonymousAttributes)
{
m_pAnonymousAttributes = new nsVoidArray();
m_pAnonymousValues = new nsVoidArray();
}
char* tempCString = attrString.ToNewCString();
char *attributeStr = PL_strdup(tempCString);
m_pAnonymousAttributes->AppendElement(attributeStr);
delete [] tempCString;
}
}
} while (cardRow);
}
return NS_OK;
}
nsresult nsAddrDatabase::GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow)
{
nsresult err = NS_OK;
@ -1384,6 +1569,27 @@ nsresult nsAddrDatabase::GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow)
delete [] tempCString;
}
if (m_pAnonymousAttributes && m_pAnonymousValues)
{
PRUint32 count,i;
count = m_pAnonymousAttributes->Count();
for (i = 0; i < count; i++)
{
char* pAttrStr = (char*)m_pAnonymousAttributes->ElementAt(i);
mdb_token anonymousColumnToken;
GetStore()->StringToToken(GetEnv(), pAttrStr, &anonymousColumnToken);
GetStringColumn(cardRow, anonymousColumnToken, tempString);
if (tempString.Length())
{
tempCString = tempString.ToNewCString();
char* pValue = PL_strdup(tempCString);
m_pAnonymousValues->AppendElement(pValue);
delete [] tempCString;
}
}
}
return err;
}
@ -1460,6 +1666,9 @@ NS_IMETHODIMP nsAddrDBEnumerator::CurrentItem(nsISupports **aItem)
{
nsresult rv;
rv = mDB->CreateABCard(mCurrentRow, getter_AddRefs(mResultCard));
if (mResultCard)
{
}
*aItem = mResultCard;
NS_IF_ADDREF(*aItem);
return NS_OK;
@ -1485,26 +1694,23 @@ NS_IMETHODIMP nsAddrDatabase::EnumerateCards(nsIAbDirectory *directory, nsIEnume
return NS_OK;
}
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
nsresult nsAddrDatabase::CreateABCard(nsIMdbRow* cardRow, nsIAbCard **result)
{
nsresult rv;
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
if (NS_FAILED(rv) || !rdfService) return rv;
char* cardURI = nsnull;
nsCOMPtr<nsIRDFResource> resource;
nsresult rv = NS_OK;
mdbOid outOid;
mdb_id rowID=0;
mdb_id tableID = 1; /* check: temperarily set to 1 for now */
mdb_id tableID = 0;
m_dbDirectory->GetDirPosition((PRUint32*)&tableID);
if (cardRow->GetOid(GetEnv(), &outOid) == NS_OK)
rowID = outOid.mOid_Id;
if(NS_SUCCEEDED(rv))
{
cardURI = PR_smprintf("abcard://Pab%d/Card%d", tableID, rowID);
char* cardURI = nsnull;
cardURI = PR_smprintf("abcard://Pab%ld/Card%ld", tableID, rowID);
nsCOMPtr<nsIAbCard> personCard;
rv = m_dbDirectory->AddChildCards(cardURI, getter_AddRefs(personCard));
if (personCard)
@ -1515,9 +1721,10 @@ nsresult nsAddrDatabase::CreateABCard(nsIMdbRow* cardRow, nsIAbCard **result)
}
*result = personCard;
NS_IF_ADDREF(*result);
if (cardURI)
PR_smprintf_free(cardURI);
}
if(cardURI)
PR_smprintf_free(cardURI);
return rv;
}

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

@ -27,6 +27,31 @@
#include "nsIAddrDBListener.h"
#include "nsISupportsArray.h"
typedef enum
{
AB_NotifyInserted,
AB_NotifyDeleted,
AB_NotifyPropertyChanged,
AB_NotifyAll, /* contents of the have totally changed. Listener must totally
forget anything they knew about the object. */
/* pane notifications (i.e. not tied to a particular entry */
AB_NotifyScramble, /* same contents, but the view indices have all changed
i.e the object was sorted on a different attribute */
AB_NotifyLDAPTotalContentChanged,
AB_NotifyNewTopIndex,
AB_NotifyStartSearching,
AB_NotifyStopSearching
} AB_NOTIFY_CODE;
enum nsAddrDBCommitType {
kSmallCommit,
kLargeCommit,
kSessionCommit,
kCompressCommit
};
class nsAddrDatabase : public nsIAddrDatabase
{
public:
@ -38,7 +63,7 @@ public:
NS_IMETHOD AddListener(nsIAddrDBListener *listener);
NS_IMETHOD RemoveListener(nsIAddrDBListener *listener);
NS_IMETHOD NotifyCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator);
NS_IMETHOD NotifyCardEntryChange(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator);
NS_IMETHOD NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator);
NS_IMETHOD NotifyAnnouncerGoingAway();
//////////////////////////////////////////////////////////////////////////////
@ -53,8 +78,11 @@ public:
NS_IMETHOD Commit(PRUint32 commitType);
NS_IMETHOD ForceClosed();
NS_IMETHOD CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool benotify);
NS_IMETHOD CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool notify);
NS_IMETHOD EnumerateCards(nsIAbDirectory *directory, nsIEnumerator **result);
NS_IMETHOD DeleteCard(nsIAbCard *newCard, PRBool notify);
NS_IMETHOD EditCard(nsIAbCard *card, PRBool notify);
NS_IMETHOD ContainsCard(nsIAbCard *card, PRBool *hasCard);
//////////////////////////////////////////////////////////////////////////////
// nsAddrDatabase methods:
@ -68,6 +96,7 @@ public:
PRUint32 GetCurVersion();
nsIMdbTableRowCursor *GetTableRowCursor();
nsIMdbTable *GetPabTable() {return m_mdbPabTable;}
nsIMdbTable *GetAnonymousTable() {return m_mdbAnonymousTable;}
static nsAddrDatabase* FindInCache(nsFileSpec *dbName);
@ -106,9 +135,11 @@ protected:
mdb_err AddCardColumn(nsIMdbRow* cardRow, mdb_column inColumn, char* str);
nsresult GetStringColumn(nsIMdbRow *cardRow, mdb_token outToken, nsString &str);
nsresult GetStringColumn(nsIMdbRow *cardRow, mdb_token outToken, nsString& str);
nsresult GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow);
nsresult AddAnonymousAttributesToDB(nsIAbCard *newCard, nsIMdbRow *cardRow);
nsresult GetAnonymousAttributesFromDB();
nsresult AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *cardRow);
static nsVoidArray/*<nsAddrDatabase>*/* GetDBCache();
static nsVoidArray/*<nsAddrDatabase>*/* m_dbCache;
@ -117,6 +148,8 @@ protected:
nsresult InitExistingDB();
nsresult InitNewDB();
nsresult InitMDBInfo();
nsresult InitPabTable();
nsresult InitAnonymousTable();
nsIMdbEnv *m_mdbEnv; // to be used in all the db calls.
nsIMdbStore *m_mdbStore;
@ -126,12 +159,19 @@ protected:
PRBool m_mdbTokensInitialized;
nsVoidArray/*<nsIAddrDBListener>*/ *m_ChangeListeners;
mdb_kind m_pabTableKind;
mdb_kind m_buddyTableKind;
mdb_kind m_historyTableKind;
mdb_kind m_mailListTableKind;
mdb_scope m_cardRowScopeToken;
mdb_kind m_categoryTableKind;
nsIMdbTable *m_mdbAnonymousTable;
mdb_kind m_AnonymousTableKind;
mdb_scope m_AnonymousRowScopeToken;
mdb_token m_AnonymousColumnToken;
nsVoidArray* m_pAnonymousAttributes;
nsVoidArray* m_pAnonymousValues;
mdb_kind m_PabTableKind;
mdb_kind m_HistoryTableKind;
mdb_kind m_MailListTableKind;
mdb_kind m_CategoryTableKind;
mdb_scope m_CardRowScopeToken;
mdb_token m_FirstNameColumnToken;
mdb_token m_LastNameColumnToken;

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

@ -37,6 +37,46 @@ static NS_DEFINE_CID(kAddressBookDB, NS_ADDRESSBOOKDB_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static nsresult ConvertDOMListToResourceArray(nsIDOMNodeList *nodeList, nsISupportsArray **resourceArray)
{
nsresult rv = NS_OK;
PRUint32 listLength;
nsIDOMNode *node;
nsIDOMXULTreeElement *xulElement;
nsIRDFResource *resource;
if(!resourceArray)
return NS_ERROR_NULL_POINTER;
if(NS_FAILED(rv = nodeList->GetLength(&listLength)))
return rv;
if(NS_FAILED(NS_NewISupportsArray(resourceArray)))
{
return NS_ERROR_OUT_OF_MEMORY;
}
for(PRUint32 i = 0; i < listLength; i++)
{
if(NS_FAILED(nodeList->Item(i, &node)))
return rv;
if(NS_SUCCEEDED(rv = node->QueryInterface(nsCOMTypeInfo<nsIDOMXULElement>::GetIID(), (void**)&xulElement)))
{
if(NS_SUCCEEDED(rv = xulElement->GetResource(&resource)))
{
(*resourceArray)->AppendElement(resource);
NS_RELEASE(resource);
}
NS_RELEASE(xulElement);
}
NS_RELEASE(node);
}
return rv;
}
//
// nsAddressBook
//
@ -79,7 +119,7 @@ NS_IMETHODIMP nsAddressBook::NewCard()
{
nsresult rv = NS_OK;
/* nsCOMPtr<nsIRDFResource> folderResource;
nsCOMPtr<nsISupportsArray> nameArray, folderArray;
nsCOMPtr<nsISupportsArray> nameArray, dirArray;
if(!parentFolderElement || !card)
return NS_ERROR_NULL_POINTER;
@ -94,11 +134,11 @@ NS_IMETHODIMP nsAddressBook::NewCard()
return NS_ERROR_OUT_OF_MEMORY;
}
rv = NS_NewISupportsArray(getter_AddRefs(folderArray));
rv = NS_NewISupportsArray(getter_AddRefs(dirArray));
if(NS_FAILED(rv))
return NS_ERROR_OUT_OF_MEMORY;
folderArray->AppendElement(folderResource);
dirArray->AppendElement(folderResource);
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
if(NS_SUCCEEDED(rv))
@ -108,11 +148,49 @@ NS_IMETHODIMP nsAddressBook::NewCard()
rdfService->GetLiteral(nameStr.GetUnicode(), getter_AddRefs(nameLiteral));
nameArray->AppendElement(nameLiteral);
rv = DoCommand(database, NC_RDF_NEWABCARD, folderArray, nameArray);
rv = DoCommand(database, NC_RDF_NEWABCARD, dirArray, nameArray);
}*/
return rv;
}
NS_IMETHODIMP nsAddressBook::DeleteCards
(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList)
{
nsresult rv;
if(!tree || !srcDirectory || !nodeList)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIRDFCompositeDataSource> database;
nsCOMPtr<nsISupportsArray> resourceArray, dirArray;
nsCOMPtr<nsIRDFResource> resource;
rv = srcDirectory->GetResource(getter_AddRefs(resource));
if(NS_FAILED(rv))
return rv;
rv = tree->GetDatabase(getter_AddRefs(database));
if(NS_FAILED(rv))
return rv;
rv = ConvertDOMListToResourceArray(nodeList, getter_AddRefs(resourceArray));
if(NS_FAILED(rv))
return rv;
rv = NS_NewISupportsArray(getter_AddRefs(dirArray));
if(NS_FAILED(rv))
{
return NS_ERROR_OUT_OF_MEMORY;
}
dirArray->AppendElement(resource);
rv = DoCommand(database, NC_RDF_DELETE, dirArray, resourceArray);
return rv;
}
nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, char *command,
nsISupportsArray *srcArray, nsISupportsArray *argumentArray)
{
@ -127,10 +205,6 @@ nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, char *command,
rv = rdfService->GetResource(command, getter_AddRefs(commandResource));
if(NS_SUCCEEDED(rv))
{
// ** jt - temporary solution for pickybacking the undo manager into
// the nsISupportArray
// if (mTxnMgr)
// srcArray->InsertElementAt(mTxnMgr, 0);
rv = db->DoCommand(srcArray, commandResource, argumentArray);
}

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

@ -25,7 +25,8 @@
#include "nsIAddrDatabase.h"
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewAbCARD"
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewCard"
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
class nsAddressBook : public nsIAddressBook
{
@ -40,6 +41,7 @@ public:
// NS_IMETHOD NewCard(nsIRDFCompositeDataSource *database, nsIDOMXULElement *parentFolderElement,
// nsIAbCard *card);
NS_IMETHOD NewCard();
NS_IMETHOD DeleteCards(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList);
protected:
nsresult DoCommand(nsIRDFCompositeDataSource *db, char * command, nsISupportsArray *srcArray,

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

@ -16,19 +16,19 @@
* Reserved.
*/
#include "msgCore.h" // precompiled header...
#include "nsCardDataSource.h"
#include "nsAbBaseCID.h"
#include "nsIAbCard.h"
#include "nsIMsgDatabase.h"
#include "nsIAddrBookSession.h"
#include "rdf.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsIRDFNode.h"
#include "nsEnumeratorUtils.h"
#include "nsIServiceManager.h"
#include "prprf.h"
#include "prlog.h"
#include "nsString.h"
#include "nsCOMPtr.h"
@ -44,13 +44,10 @@ typedef struct _nsAbRDFNotification {
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kAbCardDataSourceCID, NS_ABCARDDATASOURCE_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
nsIRDFResource* nsABCardDataSource::kNC_CardChild;
nsIRDFResource* nsABCardDataSource::kNC_DisplayName;
nsIRDFResource* nsABCardDataSource::kNC_PrimaryEmail;
@ -64,6 +61,7 @@ nsIRDFResource* nsABCardDataSource::kNC_NewCard;
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, CardChild);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, DisplayName);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, PrimaryEmail);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, WorkPhone);
@ -160,6 +158,7 @@ nsABCardDataSource::~nsABCardDataSource (void)
nsrefcnt refcnt;
NS_RELEASE2(kNC_CardChild, refcnt);
NS_RELEASE2(kNC_DisplayName, refcnt);
NS_RELEASE2(kNC_PrimaryEmail, refcnt);
NS_RELEASE2(kNC_City, refcnt);
@ -183,10 +182,15 @@ nsresult nsABCardDataSource::Init()
(nsISupports**) &mRDFService); // XXX probably need shutdown listener here
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
if (NS_SUCCEEDED(rv))
abSession->AddAddressBookListener(this);
mRDFService->RegisterDataSource(this, PR_FALSE);
if (! kNC_DisplayName) {
mRDFService->GetResource(kURINC_CardChild, &kNC_CardChild);
mRDFService->GetResource(kURINC_DisplayName, &kNC_DisplayName);
mRDFService->GetResource(kURINC_PrimaryEmail, &kNC_PrimaryEmail);
mRDFService->GetResource(kURINC_City, &kNC_City);
@ -352,8 +356,13 @@ NS_IMETHODIMP nsABCardDataSource::HasAssertion(nsIRDFResource* source,
PRBool tv,
PRBool* hasAssertion)
{
*hasAssertion = PR_FALSE;
return NS_OK;
nsresult rv;
nsCOMPtr<nsIAbCard> card(do_QueryInterface(source, &rv));
if(NS_SUCCEEDED(rv))
return DoCardHasAssertion(card, property, target, tv, hasAssertion);
else
*hasAssertion = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsABCardDataSource::AddObserver(nsIRDFObserver* n)
@ -532,26 +541,26 @@ nsABCardDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
nsresult rv = NS_OK;
nsresult rv = NS_OK;
// XXX need to handle batching of command applied to all sources
// XXX need to handle batching of command applied to all sources
PRUint32 i, cnt;
rv = aSources->Count(&cnt);
for (i = 0; i < cnt; i++) {
PRUint32 i, cnt;
rv = aSources->Count(&cnt);
for (i = 0; i < cnt; i++)
{
nsCOMPtr<nsISupports> supports = getter_AddRefs(aSources->ElementAt(i));
nsCOMPtr<nsIAbCard> card = do_QueryInterface(supports, &rv);
if (NS_SUCCEEDED(rv)) {
if ((aCommand == kNC_Delete)) {
rv = DoDeleteFromCard(card, aArguments);
}
else if((aCommand == kNC_NewCard)) {
rv = DoNewCard(card, aArguments);
}
}
}
return rv;
nsCOMPtr<nsIAbCard> card = do_QueryInterface(supports, &rv);
if (NS_SUCCEEDED(rv))
{
if ((aCommand == kNC_Delete))
rv = DoDeleteFromCard(card, aArguments);
else if((aCommand == kNC_NewCard))
rv = DoNewCard(card, aArguments);
}
}
//for the moment return NS_OK, because failure stops entire DoCommand process.
return NS_OK;
}
NS_IMETHODIMP nsABCardDataSource::OnItemAdded(nsIAbBase *parentDirectory, nsISupports *item)
@ -603,7 +612,7 @@ NS_IMETHODIMP nsABCardDataSource::OnItemPropertyChanged(nsISupports *item, const
const char *oldValue, const char *newValue)
{
/*
nsresult rv;
nsCOMPtr<nsIRDFResource> resource(do_QueryInterface(item, &rv));
@ -611,11 +620,17 @@ NS_IMETHODIMP nsABCardDataSource::OnItemPropertyChanged(nsISupports *item, const
{
if(PL_strcmp("DisplayName", property) == 0)
{
NotifyPropertyChanged(resource, kNC_DirName, oldValue, newValue);
NotifyPropertyChanged(resource, kNC_DisplayName, oldValue, newValue);
}
}*/
if(PL_strcmp("PrimaryEmail", property) == 0)
{
NotifyPropertyChanged(resource, kNC_PrimaryEmail, oldValue, newValue);
}
if(PL_strcmp("WorkPhone", property) == 0)
{
NotifyPropertyChanged(resource, kNC_WorkPhone, oldValue, newValue);
}
}
return NS_OK;
}
@ -623,14 +638,18 @@ nsresult nsABCardDataSource::NotifyPropertyChanged(nsIRDFResource *resource,
nsIRDFResource *propertyResource,
const char *oldValue, const char *newValue)
{
nsCOMPtr<nsIRDFNode> oldValueNode;
nsCOMPtr<nsIRDFNode> newValueNode;
nsString oldValueStr = oldValue;
nsString newValueStr = newValue;
createNode(oldValueStr, getter_AddRefs(oldValueNode));
createNode(newValueStr, getter_AddRefs(newValueNode));
NotifyObservers(resource, propertyResource, oldValueNode, PR_FALSE);
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);
}
return NS_OK;
}
@ -683,3 +702,15 @@ nsresult nsABCardDataSource::DoNewCard(nsIAbCard *card, nsISupportsArray *argume
}
return rv;
}
nsresult nsABCardDataSource::DoCardHasAssertion(nsIAbCard *card, nsIRDFResource *property, nsIRDFNode *target,
PRBool tv, PRBool *hasAssertion)
{
*hasAssertion = PR_TRUE;
return NS_OK;
}

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

@ -22,6 +22,7 @@
#include "nsIAbListener.h"
#include "nsIAbCard.h"
#include "nsISupportsArray.h"
#include "nsString.h"
/**
@ -146,12 +147,14 @@ protected:
nsresult DoDeleteFromCard(nsIAbCard *directory,
nsISupportsArray *arguments);
nsresult DoNewCard(nsIAbCard *directory,
nsISupportsArray *arguments);
nsresult DoNewCard(nsIAbCard *directory, nsISupportsArray *arguments);
nsresult DoCardHasAssertion(nsIAbCard *card, nsIRDFResource *property,
nsIRDFNode *target, PRBool tv, PRBool *hasAssertion);
static PRBool assertEnumFunc(nsISupports *aElement, void *aData);
static PRBool unassertEnumFunc(nsISupports *aElement, void *aData);
static nsIRDFResource* kNC_CardChild;
static nsIRDFResource* kNC_DisplayName;
static nsIRDFResource* kNC_PrimaryEmail;
static nsIRDFResource* kNC_WorkPhone;

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

@ -16,24 +16,25 @@
* Reserved.
*/
#include "msgCore.h" // precompiled header...
#include "nsDirectoryDataSource.h"
#include "nsAbBaseCID.h"
#include "nsAbDirectory.h"
#include "nsIMsgDatabase.h"
#include "nsIAddrBookSession.h"
#include "nsIAbCard.h"
#include "rdf.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsIRDFNode.h"
#include "nsEnumeratorUtils.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "prprf.h"
#include "prlog.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsAbRDFNotification {
@ -47,9 +48,12 @@ typedef struct _nsAbRDFNotification {
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kAbDirectoryDataSourceCID, NS_ABDIRECTORYDATASOURCE_CID);
static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORYRESOURCE_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
nsIRDFResource* nsABDirectoryDataSource::kNC_Child;
nsIRDFResource* nsABDirectoryDataSource::kNC_DirName;
nsIRDFResource* nsABDirectoryDataSource::kNC_DirChild;
nsIRDFResource* nsABDirectoryDataSource::kNC_CardChild;
@ -69,48 +73,6 @@ DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, NewDirectory);
////////////////////////////////////////////////////////////////////////
// Utilities
#if 0
static PRBool
peqSort(nsIRDFResource* r1, nsIRDFResource* r2, PRBool *isSort)
{
if(!isSort)
return PR_FALSE;
char *r1Str, *r2Str;
nsString r1nsStr, r2nsStr, r1nsSortStr;
r1->GetValue(&r1Str);
r2->GetValue(&r2Str);
r1nsStr = r1Str;
r2nsStr = r2Str;
r1nsSortStr = r1Str;
delete[] r1Str;
delete[] r2Str;
//probably need to not assume this will always come directly after property.
r1nsSortStr +="?sort=true";
if(r1nsStr == r2nsStr)
{
*isSort = PR_FALSE;
return PR_TRUE;
}
else if(r1nsSortStr == r2nsStr)
{
*isSort = PR_TRUE;
return PR_TRUE;
}
else
{
//In case the resources are equal but the values are different. I'm not sure if this
//could happen but it is feasible given interface.
*isSort = PR_FALSE;
return((r1 == r2));
}
}
#endif
void nsABDirectoryDataSource::createNode(nsString& str, nsIRDFNode **node)
{
@ -152,6 +114,11 @@ nsABDirectoryDataSource::~nsABDirectoryDataSource (void)
{
mRDFService->UnregisterDataSource(this);
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
if(NS_SUCCEEDED(rv))
abSession->RemoveAddressBookListener(this);
nsrefcnt refcnt;
NS_RELEASE2(kNC_Child, refcnt);
NS_RELEASE2(kNC_DirName, refcnt);
@ -179,7 +146,11 @@ nsABDirectoryDataSource::Init()
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
nsCOMTypeInfo<nsIRDFService>::GetIID(),
(nsISupports**) &mRDFService);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
if (NS_SUCCEEDED(rv))
abSession->AddAddressBookListener(this);
mRDFService->RegisterDataSource(this, PR_FALSE);
@ -352,7 +323,13 @@ NS_IMETHODIMP nsABDirectoryDataSource::Assert(nsIRDFResource* source,
nsIRDFNode* target,
PRBool tv)
{
return NS_RDF_ASSERTION_REJECTED;//NS_ERROR_NOT_IMPLEMENTED;
nsresult rv;
nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
//We don't handle tv = PR_FALSE at the moment.
if(NS_SUCCEEDED(rv) && tv)
return DoDirectoryAssert(directory, property, target);
else
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsABDirectoryDataSource::Unassert(nsIRDFResource* source,
@ -385,8 +362,13 @@ NS_IMETHODIMP nsABDirectoryDataSource::HasAssertion(nsIRDFResource* source,
PRBool tv,
PRBool* hasAssertion)
{
*hasAssertion = PR_FALSE;
return NS_OK;
nsresult rv;
nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
if(NS_SUCCEEDED(rv))
return DoDirectoryHasAssertion(directory, property, target, tv, hasAssertion);
else
*hasAssertion = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsABDirectoryDataSource::AddObserver(nsIRDFObserver* n)
@ -439,12 +421,12 @@ nsresult nsABDirectoryDataSource::NotifyObservers(nsIRDFResource *subject,
{
if(mObservers)
{
nsAbRDFNotification note = { subject, property, object };
if (assert)
mObservers->EnumerateForwards(assertEnumFunc, &note);
else
mObservers->EnumerateForwards(unassertEnumFunc, &note);
}
nsAbRDFNotification note = { subject, property, object };
if (assert)
mObservers->EnumerateForwards(assertEnumFunc, &note);
else
mObservers->EnumerateForwards(unassertEnumFunc, &note);
}
return NS_OK;
}
@ -565,78 +547,96 @@ nsABDirectoryDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSource
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
nsresult rv = NS_OK;
PRUint32 i, cnt;
nsresult rv = aSources->Count(&cnt);
if (NS_FAILED(rv)) return rv;
// XXX need to handle batching of command applied to all sources
PRUint32 i, cnt;
rv = aSources->Count(&cnt);
for (i = 0; i < cnt; i++) {
for (i = 0; i < cnt; i++)
{
nsCOMPtr<nsISupports> supports = getter_AddRefs(aSources->ElementAt(i));
nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(supports, &rv);
if (NS_SUCCEEDED(rv)) {
if ((aCommand == kNC_Delete)) {
rv = DoDeleteFromDirectory(directory, aArguments);
}
else if((aCommand == kNC_NewDirectory)) {
rv = DoNewDirectory(directory, aArguments);
}
}
}
return rv;
nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(supports, &rv);
if (NS_SUCCEEDED(rv))
{
if ((aCommand == kNC_Delete))
rv = DoDeleteFromDirectory(directory, aArguments);
else if((aCommand == kNC_NewDirectory))
rv = DoNewDirectory(directory, aArguments);
}
}
//for the moment return NS_OK, because failure stops entire DoCommand process.
return NS_OK;
}
NS_IMETHODIMP nsABDirectoryDataSource::OnItemAdded(nsIAbBase *parentDirectory, nsISupports *item)
{
nsresult rv;
nsCOMPtr<nsIAbDirectory> directory;
nsCOMPtr<nsIRDFResource> parentResource;
if(NS_SUCCEEDED(parentDirectory->QueryInterface(nsCOMTypeInfo<nsIRDFResource>::GetIID(), getter_AddRefs(parentResource))))
{
//If we are adding a directory
if(NS_SUCCEEDED(item->QueryInterface(nsCOMTypeInfo<nsIAbDirectory>::GetIID(), getter_AddRefs(directory))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
if(NS_SUCCEEDED(rv))
{
//Notify directories that a message was added.
NotifyObservers(parentResource, kNC_Child, itemNode, PR_TRUE);
}
}
}
return NS_OK;
}
NS_IMETHODIMP nsABDirectoryDataSource::OnItemRemoved(nsIAbBase *parentDirectory, nsISupports *item)
{
/*
nsresult rv;
nsCOMPtr<nsIAbCard> card;
nsCOMPtr<nsIAbDirectory> directory;
nsCOMPtr<nsIRDFResource> parentResource;
if(NS_SUCCEEDED(parentDirectory->QueryInterface(nsCOMTypeInfo<nsIRDFResource>::GetIID(), getter_AddRefs(parentResource))))
{
//If we are adding a card
if(NS_SUCCEEDED(item->QueryInterface(nsCOMTypeInfo<nsIAbCard>::GetIID(), getter_AddRefs(card))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
if (NS_SUCCEEDED(rv))
{
//Notify directories that a message was added.
NotifyObservers(parentResource, kNC_CardChild, itemNode, PR_TRUE);
}
}
//If we are adding a directory
else if(NS_SUCCEEDED(item->QueryInterface(nsCOMTypeInfo<nsIAbDirectory>::GetIID(), getter_AddRefs(directory))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
if(NS_SUCCEEDED(rv))
{
//Notify directories that a card was deleted.
//Notify folders that a message was added.
NotifyObservers(parentResource, kNC_Child, itemNode, PR_TRUE);
}
}
}
return NS_OK;
}
NS_IMETHODIMP nsABDirectoryDataSource::OnItemRemoved(nsIAbBase *parentDirectory, nsISupports *item)
{
nsresult rv;
nsCOMPtr<nsIAbCard> card;
nsCOMPtr<nsIAbDirectory> directory;
nsCOMPtr<nsIRDFResource> parentResource;
if(NS_SUCCEEDED(parentDirectory->QueryInterface(nsCOMTypeInfo<nsIRDFResource>::GetIID(), getter_AddRefs(parentResource))))
{
//If we are removing a card
if(NS_SUCCEEDED(item->QueryInterface(nsCOMTypeInfo<nsIAbCard>::GetIID(), getter_AddRefs(card))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
if(NS_SUCCEEDED(rv))
{
//Notify folders that a message was deleted.
NotifyObservers(parentResource, kNC_CardChild, itemNode, PR_FALSE);
}
}
}*/
return NS_OK;
//If we are removing a directory
else if(NS_SUCCEEDED(item->QueryInterface(nsCOMTypeInfo<nsIAbDirectory>::GetIID(), getter_AddRefs(directory))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
if(NS_SUCCEEDED(rv))
{
//Notify folders that a message was deleted.
NotifyObservers(parentResource, kNC_Child, itemNode, PR_FALSE);
}
}
}
return NS_OK;
}
NS_IMETHODIMP nsABDirectoryDataSource::OnItemPropertyChanged(nsISupports *item, const char *property,
const char *oldValue, const char *newValue)
{
/*
nsresult rv;
nsCOMPtr<nsIRDFResource> resource(do_QueryInterface(item, &rv));
@ -646,8 +646,7 @@ NS_IMETHODIMP nsABDirectoryDataSource::OnItemPropertyChanged(nsISupports *item,
{
NotifyPropertyChanged(resource, kNC_DirName, oldValue, newValue);
}
}*/
}
return NS_OK;
}
@ -655,14 +654,18 @@ nsresult nsABDirectoryDataSource::NotifyPropertyChanged(nsIRDFResource *resource
nsIRDFResource *propertyResource,
const char *oldValue, const char *newValue)
{
nsCOMPtr<nsIRDFNode> oldValueNode;
nsCOMPtr<nsIRDFNode> newValueNode;
nsString oldValueStr = oldValue;
nsString newValueStr = newValue;
createNode(oldValueStr, getter_AddRefs(oldValueNode));
createNode(newValueStr, getter_AddRefs(newValueNode));
NotifyObservers(resource, propertyResource, oldValueNode, PR_FALSE);
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);
}
return NS_OK;
}
@ -720,6 +723,36 @@ nsABDirectoryDataSource::createCardChildNode(nsIAbDirectory *directory,
nsresult nsABDirectoryDataSource::DoDeleteFromDirectory(nsIAbDirectory *directory, nsISupportsArray *arguments)
{
nsresult rv = NS_OK;
PRUint32 itemCount;
rv = arguments->Count(&itemCount);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> cardArray, dirArray;
NS_NewISupportsArray(getter_AddRefs(cardArray));
NS_NewISupportsArray(getter_AddRefs(dirArray));
//Split up deleted items into different type arrays to be passed to the folder
//for deletion.
for(PRUint32 item = 0; item < itemCount; item++)
{
nsCOMPtr<nsISupports> supports = getter_AddRefs(arguments->ElementAt(item));
nsCOMPtr<nsIAbCard> deletedCard(do_QueryInterface(supports));
nsCOMPtr<nsIAbDirectory> deletedDir(do_QueryInterface(supports));
if (deletedCard)
{
cardArray->AppendElement(supports);
}
else if(deletedDir)
{
dirArray->AppendElement(supports);
}
}
PRUint32 cnt;
rv = cardArray->Count(&cnt);
if (NS_FAILED(rv)) return rv;
if (cnt > 0)
rv = directory->DeleteCards(cardArray);
return rv;
}
@ -740,3 +773,37 @@ nsresult nsABDirectoryDataSource::DoNewDirectory(nsIAbDirectory *directory, nsIS
return rv;
}
nsresult nsABDirectoryDataSource::DoDirectoryAssert(nsIAbDirectory *directory, nsIRDFResource *property, nsIRDFNode *target)
{
nsresult rv = NS_ERROR_FAILURE;
return rv;
}
nsresult nsABDirectoryDataSource::DoDirectoryHasAssertion(nsIAbDirectory *directory, nsIRDFResource *property, nsIRDFNode *target,
PRBool tv, PRBool *hasAssertion)
{
nsresult rv = NS_OK;
if (!hasAssertion)
return NS_ERROR_NULL_POINTER;
//We're not keeping track of negative assertions on directory.
if (!tv)
{
*hasAssertion = PR_FALSE;
return NS_OK;
}
if((kNC_CardChild == property))
{
nsCOMPtr<nsIAbCard> card(do_QueryInterface(target, &rv));
if(NS_SUCCEEDED(rv))
rv = directory->HasCard(card, hasAssertion);
}
else
*hasAssertion = PR_FALSE;
return rv;
}

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

@ -160,6 +160,11 @@ protected:
nsresult DoNewDirectory(nsIAbDirectory *directory,
nsISupportsArray *arguments);
nsresult DoDirectoryAssert(nsIAbDirectory *directory,
nsIRDFResource *property, nsIRDFNode *target);
nsresult DoDirectoryHasAssertion(nsIAbDirectory *directory,
nsIRDFResource *property, nsIRDFNode *target,
PRBool tv, PRBool *hasAssertion);
static PRBool assertEnumFunc(nsISupports *aElement, void *aData);
static PRBool unassertEnumFunc(nsISupports *aElement, void *aData);