mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
new files. not part of the build
This commit is contained in:
parent
61bb30722b
commit
a1afedd8df
480
mailnews/addrbook/src/nsAbCardProperty.cpp
Normal file
480
mailnews/addrbook/src/nsAbCardProperty.cpp
Normal file
@ -0,0 +1,480 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsAbCardProperty.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsIFileLocator.h"
|
||||
#include "nsFileLocations.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "prmem.h"
|
||||
#include "prlog.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_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
nsAbCardProperty::nsAbCardProperty(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
m_pListName = nsnull;
|
||||
m_pWorkCity = nsnull;
|
||||
m_pOrganization = nsnull;
|
||||
|
||||
m_pFirstName = nsnull;
|
||||
m_pLastName = nsnull;
|
||||
m_pDisplayName = nsnull;
|
||||
m_pNickName = nsnull;
|
||||
m_pPrimaryEmail = nsnull;
|
||||
m_pSecondEmail = nsnull;
|
||||
m_pWorkPhone = nsnull;
|
||||
m_pHomePhone = nsnull;
|
||||
m_pFaxNumber = nsnull;
|
||||
m_pPagerNumber = nsnull;
|
||||
m_pCellularNumber = nsnull;
|
||||
|
||||
m_dbTableID = -1;
|
||||
m_dbRowID = -1;
|
||||
}
|
||||
|
||||
nsAbCardProperty::~nsAbCardProperty(void)
|
||||
{
|
||||
if(mDatabase)
|
||||
mDatabase->RemoveListener(this);
|
||||
|
||||
PR_FREEIF(m_pListName);
|
||||
PR_FREEIF(m_pWorkCity);
|
||||
PR_FREEIF(m_pOrganization);
|
||||
|
||||
PR_FREEIF(m_pFirstName);
|
||||
PR_FREEIF(m_pLastName);
|
||||
PR_FREEIF(m_pDisplayName);
|
||||
PR_FREEIF(m_pNickName);
|
||||
PR_FREEIF(m_pPrimaryEmail);
|
||||
PR_FREEIF(m_pSecondEmail);
|
||||
PR_FREEIF(m_pWorkPhone);
|
||||
PR_FREEIF(m_pHomePhone);
|
||||
PR_FREEIF(m_pFaxNumber);
|
||||
PR_FREEIF(m_pPagerNumber);
|
||||
PR_FREEIF(m_pCellularNumber);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsAbCardProperty)
|
||||
NS_IMPL_RELEASE(nsAbCardProperty)
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::QueryInterface(REFNSIID aIID, void** aResult)
|
||||
{
|
||||
if (aResult == NULL)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(nsIAbCard::GetIID()) ||
|
||||
aIID.Equals(nsIAddrDBListener::GetIID()) ||
|
||||
aIID.Equals(::nsISupports::GetIID())) {
|
||||
*aResult = NS_STATIC_CAST(nsIAbCard*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::OnCardEntryChange
|
||||
(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetListName(char **listname)
|
||||
{
|
||||
SetListName("List1");
|
||||
if (listname && m_pListName)
|
||||
*listname = PL_strdup(m_pListName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetWorkCity(char **city)
|
||||
{
|
||||
SetWorkCity("Mountain View");
|
||||
if (city && m_pWorkCity)
|
||||
*city = PL_strdup(m_pWorkCity);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetFirstName(char * *aFirstName)
|
||||
{
|
||||
if (aFirstName && m_pFirstName)
|
||||
*aFirstName = PL_strdup(m_pFirstName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetLastName(char * *aLastName)
|
||||
{
|
||||
if (aLastName && m_pLastName)
|
||||
*aLastName = PL_strdup(m_pLastName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetDisplayName(char * *aDisplayName)
|
||||
{
|
||||
if (aDisplayName && m_pDisplayName)
|
||||
*aDisplayName = PL_strdup(m_pDisplayName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetPrimaryEmail(char * *aPrimaryEmail)
|
||||
{
|
||||
if (aPrimaryEmail && m_pPrimaryEmail)
|
||||
*aPrimaryEmail = PL_strdup(m_pPrimaryEmail);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsAbCardProperty::GetSecondEmail(char * *aSecondEmail)
|
||||
{
|
||||
if (aSecondEmail && m_pSecondEmail)
|
||||
*aSecondEmail = PL_strdup(m_pSecondEmail);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetWorkPhone(char * *aWorkPhone)
|
||||
{
|
||||
if (aWorkPhone && m_pWorkPhone)
|
||||
*aWorkPhone = PL_strdup(m_pWorkPhone);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetHomePhone(char * *aHomePhone)
|
||||
{
|
||||
if (aHomePhone && m_pHomePhone)
|
||||
*aHomePhone = PL_strdup(m_pHomePhone);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetFaxNumber(char * *aFaxNumber)
|
||||
{
|
||||
if (aFaxNumber && m_pFaxNumber)
|
||||
*aFaxNumber = PL_strdup(m_pFaxNumber);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetPagerNumber(char * *aPagerNumber)
|
||||
{
|
||||
if (aPagerNumber && m_pPagerNumber)
|
||||
*aPagerNumber = PL_strdup(m_pPagerNumber);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetCellularNumber(char * *aCellularNumber)
|
||||
{
|
||||
if (aCellularNumber && m_pCellularNumber)
|
||||
*aCellularNumber = PL_strdup(m_pCellularNumber);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetOrganization(char * *aOrganization)
|
||||
{
|
||||
SetOrganization("Mail");
|
||||
if (aOrganization && m_pOrganization)
|
||||
*aOrganization = PL_strdup(m_pOrganization);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetNickName(char * *aNickName)
|
||||
{
|
||||
if (aNickName && m_pNickName)
|
||||
*aNickName = PL_strdup(m_pNickName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetListName(char * aListName)
|
||||
{
|
||||
if (aListName)
|
||||
{
|
||||
PR_FREEIF(m_pListName);
|
||||
m_pListName = PL_strdup(aListName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetFirstName(char * aFirstName)
|
||||
{
|
||||
if (aFirstName)
|
||||
{
|
||||
PR_FREEIF(m_pFirstName);
|
||||
m_pFirstName = PL_strdup(aFirstName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetLastName(char * aLastName)
|
||||
{
|
||||
if (aLastName)
|
||||
{
|
||||
PR_FREEIF(m_pLastName);
|
||||
m_pLastName = PL_strdup(aLastName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetDisplayName(char * aDisplayName)
|
||||
{
|
||||
if (aDisplayName)
|
||||
{
|
||||
PR_FREEIF(m_pDisplayName);
|
||||
m_pDisplayName = PL_strdup(aDisplayName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetPrimaryEmail(char * aPrimaryEmail)
|
||||
{
|
||||
if (aPrimaryEmail)
|
||||
{
|
||||
PR_FREEIF(m_pPrimaryEmail);
|
||||
m_pPrimaryEmail = PL_strdup(aPrimaryEmail);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetSecondEmail(char * aSecondEmail)
|
||||
{
|
||||
if (aSecondEmail)
|
||||
{
|
||||
PR_FREEIF(m_pSecondEmail);
|
||||
m_pSecondEmail = PL_strdup(aSecondEmail);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetWorkPhone(char * aWorkPhone)
|
||||
{
|
||||
if (aWorkPhone)
|
||||
{
|
||||
PR_FREEIF(m_pWorkPhone);
|
||||
m_pWorkPhone = PL_strdup(aWorkPhone);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetHomePhone(char * aHomePhone)
|
||||
{
|
||||
if (aHomePhone)
|
||||
{
|
||||
PR_FREEIF(m_pHomePhone);
|
||||
m_pHomePhone = PL_strdup(aHomePhone);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetFaxNumber(char * aFaxNumber)
|
||||
{
|
||||
if (aFaxNumber)
|
||||
{
|
||||
PR_FREEIF(m_pFaxNumber);
|
||||
m_pFaxNumber = PL_strdup(aFaxNumber);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetPagerNumber(char * aPagerNumber)
|
||||
{
|
||||
if (aPagerNumber)
|
||||
{
|
||||
PR_FREEIF(m_pPagerNumber);
|
||||
m_pPagerNumber = PL_strdup(aPagerNumber);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetCellularNumber(char * aCellularNumber)
|
||||
{
|
||||
if (aCellularNumber)
|
||||
{
|
||||
PR_FREEIF(m_pCellularNumber);
|
||||
m_pCellularNumber = PL_strdup(aCellularNumber);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetWorkCity(char * aWorkCity)
|
||||
{
|
||||
if (aWorkCity)
|
||||
{
|
||||
PR_FREEIF(m_pWorkCity);
|
||||
m_pWorkCity = PL_strdup(aWorkCity);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetOrganization(char * aOrganization)
|
||||
{
|
||||
if (aOrganization)
|
||||
{
|
||||
PR_FREEIF(m_pOrganization);
|
||||
m_pOrganization = PL_strdup(aOrganization);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetNickName(char * aNickName)
|
||||
{
|
||||
if (aNickName)
|
||||
{
|
||||
PR_FREEIF(m_pNickName);
|
||||
m_pNickName = PL_strdup(aNickName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetDbTableID(PRUint32 *aDbTableID)
|
||||
{
|
||||
*aDbTableID = m_dbTableID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetDbTableID(PRUint32 aDbTableID)
|
||||
{
|
||||
m_dbTableID = aDbTableID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetDbRowID(PRUint32 *aDbRowID)
|
||||
{
|
||||
*aDbRowID = m_dbRowID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetDbRowID(PRUint32 aDbRowID)
|
||||
{
|
||||
m_dbRowID = aDbRowID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::GetCardValue(const char *attrname, char **value)
|
||||
{
|
||||
if (!PL_strcmp(attrname, "firstname"))
|
||||
GetFirstName(value);
|
||||
else if (!PL_strcmp(attrname, "lastname"))
|
||||
GetLastName(value);
|
||||
else if (!PL_strcmp(attrname, "displayname"))
|
||||
GetDisplayName(value);
|
||||
else if (!PL_strcmp(attrname, "nickname"))
|
||||
GetNickName(value);
|
||||
else if (!PL_strcmp(attrname, "primaryemail"))
|
||||
GetPrimaryEmail(value);
|
||||
else if (!PL_strcmp(attrname, "secondemail"))
|
||||
GetSecondEmail(value);
|
||||
else if (!PL_strcmp(attrname, "workphone"))
|
||||
GetWorkPhone(value);
|
||||
else if (!PL_strcmp(attrname, "homephone"))
|
||||
GetHomePhone(value);
|
||||
else if (!PL_strcmp(attrname, "faxnumber"))
|
||||
GetFaxNumber(value);
|
||||
else if (!PL_strcmp(attrname, "pagernumber"))
|
||||
GetPagerNumber(value);
|
||||
else if (!PL_strcmp(attrname, "cellularnumber"))
|
||||
GetCellularNumber(value);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::SetCardValue(const char *attrname, const char *value)
|
||||
{
|
||||
nsAutoString cardValue(value);
|
||||
char* valueStr = cardValue.ToNewCString();
|
||||
if (!PL_strcmp(attrname, "firstname"))
|
||||
SetFirstName(valueStr);
|
||||
else if (!PL_strcmp(attrname, "lastname"))
|
||||
SetLastName(valueStr);
|
||||
else if (!PL_strcmp(attrname, "displayname"))
|
||||
SetDisplayName(valueStr);
|
||||
else if (!PL_strcmp(attrname, "nickname"))
|
||||
SetNickName(valueStr);
|
||||
else if (!PL_strcmp(attrname, "primaryemail"))
|
||||
SetPrimaryEmail(valueStr);
|
||||
else if (!PL_strcmp(attrname, "secondemail"))
|
||||
SetSecondEmail(valueStr);
|
||||
else if (!PL_strcmp(attrname, "workphone"))
|
||||
SetWorkPhone(valueStr);
|
||||
else if (!PL_strcmp(attrname, "homephone"))
|
||||
SetHomePhone(valueStr);
|
||||
else if (!PL_strcmp(attrname, "faxnumber"))
|
||||
SetFaxNumber(valueStr);
|
||||
else if (!PL_strcmp(attrname, "pagernumber"))
|
||||
SetPagerNumber(valueStr);
|
||||
else if (!PL_strcmp(attrname, "cellularnumber"))
|
||||
SetCellularNumber(valueStr);
|
||||
|
||||
delete[] valueStr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbCardProperty::AddCardToDatabase()
|
||||
{
|
||||
// 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->CreateNewCardAndAddToDB(this, PR_TRUE);
|
||||
mDatabase->Close(PR_TRUE);
|
||||
mDatabase = null_nsCOMPtr();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
}
|
158
mailnews/addrbook/src/nsAbCardProperty.h
Normal file
158
mailnews/addrbook/src/nsAbCardProperty.h
Normal file
@ -0,0 +1,158 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/********************************************************************************************************
|
||||
|
||||
Interface for representing Address Book Person Card Property
|
||||
|
||||
*********************************************************************************************************/
|
||||
|
||||
#ifndef nsAbCardProperty_h__
|
||||
#define nsAbCardProperty_h__
|
||||
|
||||
#include "nsIAbBase.h"
|
||||
#include "nsIAbCard.h"
|
||||
#include "nsRDFResource.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIAddrDBListener.h"
|
||||
#include "nsIAddrDatabase.h"
|
||||
|
||||
/*
|
||||
* Address Book Card Property
|
||||
*/
|
||||
|
||||
class nsAbCardProperty: public nsIAbCard, public nsIAddrDBListener
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsAbCardProperty(void);
|
||||
virtual ~nsAbCardProperty(void);
|
||||
|
||||
// nsIAddrDBListener methods:
|
||||
NS_IMETHOD OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator);
|
||||
NS_IMETHOD OnCardEntryChange(PRUint32 abCode, PRUint32 entryID, nsIAddrDBListener *instigator);
|
||||
NS_IMETHOD OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator);
|
||||
|
||||
// nsICollection methods:
|
||||
|
||||
NS_IMETHOD Count(PRUint32 *result) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD GetElementAt(PRUint32 i, nsISupports* *result) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD SetElementAt(PRUint32 i, nsISupports* value) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD AppendElement(nsISupports *aElement) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD RemoveElement(nsISupports *aElement) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Clear(void) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// nsIAbBase methods:
|
||||
|
||||
NS_IMETHOD GetURI(char* *name) { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetName(char **name) { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD SetName(char *name) { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetChildNamed(const char *name, nsISupports* *result) { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
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; }
|
||||
|
||||
|
||||
// nsIAbCard methods:
|
||||
NS_IMETHOD GetListName(char * *listName);
|
||||
NS_IMETHOD SetListName(char * listName);
|
||||
|
||||
NS_IMETHOD GetFirstName(char * *aFirstName);
|
||||
NS_IMETHOD SetFirstName(char * aFirstName);
|
||||
NS_IMETHOD GetLastName(char * *aLastName);
|
||||
NS_IMETHOD SetLastName(char * aLastName);
|
||||
NS_IMETHOD GetDisplayName(char * *aDisplayName);
|
||||
NS_IMETHOD SetDisplayName(char * aDisplayName);
|
||||
NS_IMETHOD GetPrimaryEmail(char * *aPrimaryEmail);
|
||||
NS_IMETHOD SetPrimaryEmail(char * aPrimaryEmail);
|
||||
NS_IMETHOD GetSecondEmail(char * *aSecondEmail);
|
||||
NS_IMETHOD SetSecondEmail(char * aSecondEmail);
|
||||
NS_IMETHOD GetWorkPhone(char * *aWorkPhone);
|
||||
NS_IMETHOD SetWorkPhone(char * aWorkPhone);
|
||||
NS_IMETHOD GetHomePhone(char * *aHomePhone);
|
||||
NS_IMETHOD SetHomePhone(char * aHomePhone);
|
||||
NS_IMETHOD GetFaxNumber(char * *aFaxNumber);
|
||||
NS_IMETHOD SetFaxNumber(char * aFaxNumber);
|
||||
NS_IMETHOD GetPagerNumber(char * *aPagerNumber);
|
||||
NS_IMETHOD SetPagerNumber(char * aPagerNumber);
|
||||
NS_IMETHOD GetCellularNumber(char * *aCellularNumber);
|
||||
NS_IMETHOD SetCellularNumber(char * aCellularNumber);
|
||||
NS_IMETHOD GetWorkCity(char * *aWorkCity);
|
||||
NS_IMETHOD SetWorkCity(char * aWorkCity);
|
||||
NS_IMETHOD GetOrganization(char * *aOrganization);
|
||||
NS_IMETHOD SetOrganization(char * aOrganization);
|
||||
NS_IMETHOD GetNickName(char * *aNickName);
|
||||
NS_IMETHOD SetNickName(char * aNickName);
|
||||
|
||||
NS_IMETHOD GetDbTableID(PRUint32 *aDbTableID);
|
||||
NS_IMETHOD SetDbTableID(PRUint32 aDbTableID);
|
||||
NS_IMETHOD GetDbRowID(PRUint32 *aDbRowID);
|
||||
NS_IMETHOD SetDbRowID(PRUint32 aDbRowID);
|
||||
|
||||
NS_IMETHOD GetCardValue(const char *attrname, char **value);
|
||||
NS_IMETHOD SetCardValue(const char *attrname, const char *value);
|
||||
NS_IMETHOD AddCardToDatabase();
|
||||
|
||||
protected:
|
||||
|
||||
char* m_pListName;
|
||||
char* m_pWorkCity;
|
||||
char* m_pOrganization;
|
||||
|
||||
char* m_pFirstName;
|
||||
char* m_pLastName;
|
||||
char* m_pDisplayName;
|
||||
char* m_pNickName;
|
||||
char* m_pPrimaryEmail;
|
||||
char* m_pSecondEmail;
|
||||
char* m_pWorkPhone;
|
||||
char* m_pHomePhone;
|
||||
char* m_pFaxNumber;
|
||||
char* m_pPagerNumber;
|
||||
char* m_pCellularNumber;
|
||||
|
||||
PRUint32 m_dbTableID;
|
||||
PRUint32 m_dbRowID;
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> mDatabase;
|
||||
};
|
||||
|
||||
#endif
|
144
mailnews/addrbook/src/nsAddressBook.cpp
Normal file
144
mailnews/addrbook/src/nsAddressBook.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIAddressBook.h"
|
||||
#include "nsAddressBook.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIFileLocator.h"
|
||||
#include "nsFileLocations.h"
|
||||
|
||||
// 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_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kAddressBookDB, NS_ADDRESSBOOKDB_CID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
|
||||
|
||||
//
|
||||
// nsAddressBook
|
||||
//
|
||||
nsAddressBook::nsAddressBook()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsAddressBook::~nsAddressBook()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAddressBook, nsIAddressBook::GetIID());
|
||||
/*
|
||||
NS_IMPL_ADDREF(nsAddressBook)
|
||||
NS_IMPL_RELEASE(nsAddressBook)
|
||||
|
||||
NS_IMETHODIMP nsAddressBook::QueryInterface(REFNSIID aIID, void** aResult)
|
||||
{
|
||||
if (aResult == NULL)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(nsIAddressBook::GetIID()) ||
|
||||
aIID.Equals(nsIAbCard::GetIID()) ||
|
||||
aIID.Equals(::nsISupports::GetIID())) {
|
||||
*aResult = NS_STATIC_CAST(nsIAddressBook*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
*/
|
||||
//
|
||||
// nsIAddressBook
|
||||
//
|
||||
|
||||
//NS_IMETHODIMP nsAddressBook::NewCard(nsIRDFCompositeDataSource *database, nsIDOMXULElement *parentFolderElement,
|
||||
// nsIAbCard *card)
|
||||
NS_IMETHODIMP nsAddressBook::NewCard()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
/* nsCOMPtr<nsIRDFResource> folderResource;
|
||||
nsCOMPtr<nsISupportsArray> nameArray, folderArray;
|
||||
|
||||
if(!parentFolderElement || !card)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
rv = parentFolderElement->GetResource(getter_AddRefs(folderResource));
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(nameArray));
|
||||
if(NS_FAILED(rv))
|
||||
{
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(folderArray));
|
||||
if(NS_FAILED(rv))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
folderArray->AppendElement(folderResource);
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsString nameStr"person";
|
||||
nsCOMPtr<nsIRDFLiteral> nameLiteral;
|
||||
|
||||
rdfService->GetLiteral(nameStr.GetUnicode(), getter_AddRefs(nameLiteral));
|
||||
nameArray->AppendElement(nameLiteral);
|
||||
rv = DoCommand(database, NC_RDF_NEWABCARD, folderArray, nameArray);
|
||||
}*/
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, char *command,
|
||||
nsISupportsArray *srcArray, nsISupportsArray *argumentArray)
|
||||
{
|
||||
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> commandResource;
|
||||
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);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
51
mailnews/addrbook/src/nsAddressBook.h
Normal file
51
mailnews/addrbook/src/nsAddressBook.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsAddressBook_h
|
||||
#define __nsAddressBook_h
|
||||
|
||||
#include "nsIAddressBook.h"
|
||||
#include "nsIAbCard.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIAddrDatabase.h"
|
||||
|
||||
|
||||
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewAbCARD"
|
||||
|
||||
class nsAddressBook : public nsIAddressBook
|
||||
{
|
||||
|
||||
public:
|
||||
nsAddressBook();
|
||||
virtual ~nsAddressBook();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIAddressBook
|
||||
// NS_IMETHOD NewCard(nsIRDFCompositeDataSource *database, nsIDOMXULElement *parentFolderElement,
|
||||
// nsIAbCard *card);
|
||||
NS_IMETHOD NewCard();
|
||||
|
||||
protected:
|
||||
nsresult DoCommand(nsIRDFCompositeDataSource *db, char * command, nsISupportsArray *srcArray,
|
||||
nsISupportsArray *arguments);
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user