Bug 360777 Change nsIAbCard::EditCardToDatabase to nsIAbDirectory::ModifyCard. r=bienvenu,sr=mscott (relanding now windows compilation issues should be fixed).

This commit is contained in:
bugzilla%standard8.demon.co.uk 2006-12-04 17:04:43 +00:00
Родитель 141cadb9df
Коммит 951c2ff9a8
21 изменённых файлов: 339 добавлений и 357 удалений

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

@ -2353,7 +2353,7 @@ function allowRemoteContentForSender()
{
// set the property for remote content
cardForEmailAddress.allowRemoteContent = true;
cardForEmailAddress.editCardToDatabase("");
addrbook.modifyCard(cardForEmailAddress);
allowRemoteContent = true;
}
else

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

@ -237,7 +237,7 @@ function EditCardOKButton()
CheckAndSetCardValues(gEditCard.card, document, false);
gEditCard.card.editCardToDatabase(gEditCard.abURI);
directory.modifyCard(gEditCard.card);
for (i=0; i < foundDirectoriesCount; i++) {
// Update the addressLists item for this card
@ -245,7 +245,7 @@ function EditCardOKButton()
SetElementAt(foundDirectories[i].index, gEditCard.card);
}
NotifySaveListeners();
NotifySaveListeners(directory);
// callback to allow caller to update
if (gOkCallback)
@ -325,7 +325,7 @@ function RegisterSaveListener(func)
// this is used by people who extend the ab card dialog
// like Netscape does for screenname
function NotifySaveListeners()
function NotifySaveListeners(directory)
{
if (!gOnSaveListeners.length)
return;
@ -335,7 +335,7 @@ function NotifySaveListeners()
// the save listeners might have tweaked the card
// in which case we need to commit it.
gEditCard.card.editCardToDatabase(gEditCard.abURI);
directory.modifyCard(gEditCard.card);
}
function InitPhoneticFields()

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

@ -64,12 +64,6 @@
#include "nsAddbookUrl.h"
#include "nsCURILoader.h"
#if defined(XP_WIN) && !defined(__MINGW32__)
#include "nsAbOutlookDirectory.h"
#include "nsAbOutlookCard.h"
#include "nsAbOutlookDirFactory.h"
#endif
#include "nsAbDirectoryQuery.h"
#include "nsAbBooleanExpression.h"
#include "nsAbDirectoryQueryProxy.h"
@ -90,6 +84,15 @@
#include "nsLDAPAutoCompleteSession.h"
#endif
#if defined(XP_WIN) && !defined(__MINGW32__)
#include "nsAbOutlookDirFactory.h"
// These two cause windows.h to be included, if not placed after *DirFactory.h
// then this can cause problems with CreateDirectory not being
// defined.
#include "nsAbOutlookDirectory.h"
#include "nsAbOutlookCard.h"
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddressBook)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbDirectoryDataSource,Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirProperty)

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

@ -44,7 +44,7 @@ interface nsIAbPreferMailFormat {
const unsigned long html = 2;
};
[scriptable, uuid(6B46BDD5-10DB-44f4-99C9-C7FFE0D3D954)]
[scriptable, uuid(e4e2a043-4b06-43a3-b52b-146e155d9ec5)]
interface nsIAbCard : nsISupports {
// Card properties
attribute wstring firstName;
@ -123,17 +123,13 @@ interface nsIAbCard : nsISupports {
void setCardValue(in string attrname, in wstring value);
// Copies the card attributes from srcCard
void copy(in nsIAbCard srcCard);
/**
* This function will copy all values from one card to another.
*
* @param srcCard The source card to copy values from.
*/
void copy(in nsIAbCard srcCard);
// Edits an existing card in the directory defined by 'uri'
// Rename to editCardInDirectory
// Component will be an RDF card, since it has already
// been created
//
// XXX FIX ME, this should not be a the card, it should be on the addressbook.
void editCardToDatabase(in string uri);
boolean equals(in nsIAbCard card);
string convertToBase64EncodedXML();

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

@ -72,7 +72,7 @@ interface nsIAbDirectoryProperties : nsISupports {
attribute long position;
};
[scriptable, uuid(b81e0275-7b19-46e2-9f4a-086f1fc55080)]
[scriptable, uuid(831251b9-3d8d-462a-9460-71674e505f6c)]
interface nsIAbDirectory : nsISupports {
// Types of operation
@ -142,10 +142,7 @@ interface nsIAbDirectory : nsISupports {
// Deletes either a mailing list or a top
// level directory, which also updates the
// preferences
void deleteDirectory(in nsIAbDirectory dierctory);
// Delete the array of cards
void deleteCards(in nsISupportsArray cards);
void deleteDirectory(in nsIAbDirectory directory);
// Check if directory contains card
// If the implementation is asynchronous the card
@ -159,14 +156,23 @@ interface nsIAbDirectory : nsISupports {
boolean hasDirectory(in nsIAbDirectory dir);
/**
* return value is the card that got added
* we need to do this, as the card we pass in might
* be an abstract nsIAbCard, and the caller might need
* the "real" card (the mdbcard or similar) to get / set
* non-standard card values
* Adds a card to the database. card may be an abstract card.
*
* @return "Real" card (eg nsIAbMDBCard) that can be used for some
* extra functions.
*/
nsIAbCard addCard(in nsIAbCard card);
/**
* Modifies a card in the database to match that supplied.
*/
void modifyCard(in nsIAbCard modifiedCard);
/**
* Deletes the array of cards from the database
*/
void deleteCards(in nsISupportsArray cards);
void dropCard(in nsIAbCard card, in boolean needToCopyCard);
/**

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

@ -236,14 +236,14 @@ function EditCardOKButton()
CheckAndSetCardValues(gEditCard.card, document, false);
gEditCard.card.editCardToDatabase(gEditCard.abURI);
directory.modifyCard(gEditCard.card);
for (i=0; i<foundDirectoriesCount; i++) {
// Update the addressLists item for this card
foundDirectories[i].directory.addressLists.
SetElementAt(foundDirectories[i].index, gEditCard.card);
}
NotifySaveListeners();
NotifySaveListeners(directory);
// callback to allow caller to update
if (gOkCallback)
@ -323,7 +323,7 @@ function RegisterSaveListener(func)
// this is used by people who extend the ab card dialog
// like Netscape does for screenname
function NotifySaveListeners()
function NotifySaveListeners(directory)
{
if (!gOnSaveListeners.length)
return;
@ -333,7 +333,7 @@ function NotifySaveListeners()
// the save listeners might have tweaked the card
// in which case we need to commit it.
gEditCard.card.editCardToDatabase(gEditCard.abURI);
directory.modifyCard(gEditCard.card);
}
function InitPhoneticFields()

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

@ -190,8 +190,8 @@ NS_IMETHODIMP nsAbAddressCollecter::CollectAddress(const char *aAddress, PRBool
}
}
if (setScreenName || setNames || setPreferMailFormat)
existingCard->EditCardToDatabase(m_abURI.get());
if ((setScreenName || setNames || setPreferMailFormat) && m_directory)
m_directory->ModifyCard(existingCard);
}
curName += strlen(curName) + 1;

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

@ -1166,8 +1166,12 @@ NS_IMETHODIMP
nsAbCardProperty::SetLastModifiedDate(PRUint32 aLastModifiedDate)
{ return m_LastModDate = aLastModifiedDate; }
// This function may be overriden by derived classes for
// nsAb*Card specific implementations.
NS_IMETHODIMP nsAbCardProperty::Copy(nsIAbCard* srcCard)
{
NS_ENSURE_ARG_POINTER(srcCard);
nsXPIDLString str;
srcCard->GetFirstName(getter_Copies(str));
SetFirstName(str);
@ -1288,12 +1292,15 @@ NS_IMETHODIMP nsAbCardProperty::Copy(nsIAbCard* srcCard)
srcCard->GetNotes(getter_Copies(str));
SetNotes(str);
return NS_OK;
}
PRBool isMailList;
srcCard->GetIsMailList(&isMailList);
SetIsMailList(isMailList);
NS_IMETHODIMP nsAbCardProperty::EditCardToDatabase(const char *uri)
{
return NS_ERROR_NOT_IMPLEMENTED;
nsXPIDLCString mailListURI;
srcCard->GetMailListURI(getter_Copies(mailListURI));
SetMailListURI(mailListURI);
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::Equals(nsIAbCard *card, PRBool *result)

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

@ -260,13 +260,8 @@ NS_IMETHODIMP
nsAbDirProperty::ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP
nsAbDirProperty::DeleteDirectory(nsIAbDirectory *dierctory)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP
nsAbDirProperty::DeleteCards(nsISupportsArray *cards)
nsAbDirProperty::DeleteDirectory(nsIAbDirectory *directory)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP
@ -293,6 +288,12 @@ NS_IMETHODIMP nsAbDirProperty::EditMailListToDatabase(const char *uri, nsIAbCard
NS_IMETHODIMP nsAbDirProperty::AddCard(nsIAbCard *childCard, nsIAbCard **addedCard)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP nsAbDirProperty::ModifyCard(nsIAbCard *aModifiedCard)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP nsAbDirProperty::DeleteCards(nsISupportsArray *cards)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP nsAbDirProperty::DropCard(nsIAbCard *childCard, PRBool needToCopyCard)
{ return NS_ERROR_NOT_IMPLEMENTED; }

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

@ -38,6 +38,10 @@
#include "nsAbLDAPCard.h"
// XXX Although this has no real use at the moment, its planned to be
// used for writeable ldap directories as part of bug 86405 so we don't
// want to remove it just to add it back in later...
nsAbLDAPCard::nsAbLDAPCard()
{
}
@ -46,11 +50,5 @@ nsAbLDAPCard::~nsAbLDAPCard()
{
}
NS_IMETHODIMP nsAbLDAPCard::EditCardToDatabase(const char *aURI)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_ISUPPORTS_INHERITED0(nsAbLDAPCard, nsAbCardProperty)

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

@ -47,8 +47,6 @@ class nsAbLDAPCard : public nsAbCardProperty
public:
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD EditCardToDatabase(const char *aURI);
nsAbLDAPCard();
virtual ~nsAbLDAPCard();
};

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

@ -73,5 +73,3 @@ nsresult nsAbMDBCard::NotifyPropertyChanged(const char *property, const PRUnicha
return NS_OK;
}

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

@ -129,55 +129,6 @@ NS_IMETHODIMP nsAbMDBCardProperty::GetStringAttribute(const char *name, PRUnicha
return mCardDatabase->GetCardValue(this, name, value);
}
NS_IMETHODIMP nsAbMDBCardProperty::EditCardToDatabase(const char *uri)
{
if (!mCardDatabase && uri)
GetCardDatabase(uri);
if (mCardDatabase)
{
mCardDatabase->EditCard(this, PR_TRUE);
mCardDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
return NS_OK;
}
else
return NS_ERROR_FAILURE;
}
// protected class methods
nsresult nsAbMDBCardProperty::GetCardDatabase(const char *uri)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIAddrBookSession> abSession =
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsILocalFile> dbPath;
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
NS_ENSURE_SUCCESS(rv, rv);
rv = dbPath->AppendNative(nsDependentCString(&(uri[kMDBDirectoryRootLen])));
NS_ENSURE_SUCCESS(rv, rv);
PRBool fileExists;
rv = dbPath->Exists(&fileExists);
if (NS_SUCCEEDED(rv) && fileExists)
{
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && addrDBFactory)
rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE, getter_AddRefs(mCardDatabase));
}
else
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP nsAbMDBCardProperty::Equals(nsIAbCard *card, PRBool *result)
{
nsresult rv;

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

@ -53,11 +53,8 @@ public:
nsAbMDBCardProperty(void);
virtual ~nsAbMDBCardProperty();
NS_IMETHOD EditCardToDatabase(const char *uri);
NS_IMETHOD Equals(nsIAbCard *card, PRBool *result);
protected:
nsresult GetCardDatabase(const char *uri);
PRUint32 m_key;
PRUint32 m_dbTableID;

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

@ -698,6 +698,22 @@ NS_IMETHODIMP nsAbMDBDirectory::AddCard(nsIAbCard* card, nsIAbCard **addedCard)
return NS_OK;
}
NS_IMETHODIMP nsAbMDBDirectory::ModifyCard(nsIAbCard *aModifiedCard)
{
NS_ENSURE_ARG_POINTER(aModifiedCard);
nsresult rv;
if (!mDatabase)
{
rv = GetAbDatabase();
NS_ENSURE_SUCCESS(rv, rv);
}
rv = mDatabase->EditCard(aModifiedCard, PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
return mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
}
NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* aCard, PRBool needToCopyCard)
{
NS_ENSURE_ARG_POINTER(aCard);

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

@ -97,6 +97,7 @@ public:
NS_IMETHOD CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating);
NS_IMETHOD AddMailList(nsIAbDirectory *list);
NS_IMETHOD AddCard(nsIAbCard *card, nsIAbCard **addedCard);
NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
NS_IMETHOD DropCard(nsIAbCard *card, PRBool needToCopyCard);
NS_IMETHOD EditMailListToDatabase(const char *uri, nsIAbCard *listCard);

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

@ -37,12 +37,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsAbOutlookCard.h"
#include "nsAbWinHelper.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIAddrBookSession.h"
#include "nsAbBaseCID.h"
#include "nsServiceManagerUtils.h"
#include "nsCRT.h"
#include "prlog.h"
@ -92,63 +86,6 @@ static void wordToUnicode(WORD aWord, nsString& aUnicode)
aUnicode.AppendInt((PRInt32) aWord) ;
}
enum
{
index_DisplayName = 0,
index_EmailAddress,
index_FirstName,
index_LastName,
index_NickName,
index_WorkPhoneNumber,
index_HomePhoneNumber,
index_WorkFaxNumber,
index_PagerNumber,
index_MobileNumber,
index_HomeCity,
index_HomeState,
index_HomeZip,
index_HomeCountry,
index_WorkCity,
index_WorkState,
index_WorkZip,
index_WorkCountry,
index_JobTitle,
index_Department,
index_Company,
index_WorkWebPage,
index_HomeWebPage,
index_Comments,
index_LastProp
} ;
static const ULONG OutlookCardMAPIProps [] =
{
PR_DISPLAY_NAME_W,
PR_EMAIL_ADDRESS_W,
PR_GIVEN_NAME_W,
PR_SURNAME_W,
PR_NICKNAME_W,
PR_BUSINESS_TELEPHONE_NUMBER_W,
PR_HOME_TELEPHONE_NUMBER_W,
PR_BUSINESS_FAX_NUMBER_W,
PR_PAGER_TELEPHONE_NUMBER_W,
PR_MOBILE_TELEPHONE_NUMBER_W,
PR_HOME_ADDRESS_CITY_W,
PR_HOME_ADDRESS_STATE_OR_PROVINCE_W,
PR_HOME_ADDRESS_POSTAL_CODE_W,
PR_HOME_ADDRESS_COUNTRY_W,
PR_BUSINESS_ADDRESS_CITY_W,
PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_W,
PR_BUSINESS_ADDRESS_POSTAL_CODE_W,
PR_BUSINESS_ADDRESS_COUNTRY_W,
PR_TITLE_W,
PR_DEPARTMENT_NAME_W,
PR_COMPANY_NAME_W,
PR_BUSINESS_HOME_PAGE_W,
PR_PERSONAL_HOME_PAGE_W,
PR_COMMENT_W
} ;
nsresult nsAbOutlookCard::Init(const char *aUri)
{
nsresult retCode = nsRDFResource::Init(aUri) ;
@ -233,125 +170,3 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
}
return retCode ;
}
static void UnicodeToWord(const PRUnichar *aUnicode, WORD& aWord)
{
aWord = 0 ;
if (aUnicode == nsnull || *aUnicode == 0) { return ; }
PRInt32 errorCode = 0 ;
nsAutoString unichar (aUnicode) ;
aWord = NS_STATIC_CAST(WORD, unichar.ToInteger(&errorCode)) ;
if (errorCode != 0) {
PRINTF(("Error conversion string %S: %08x.\n", unichar.get(), errorCode)) ;
}
}
#define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst"
NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUru)
{
nsresult retCode = NS_OK ;
nsXPIDLString *properties = nsnull ;
nsAutoString utility ;
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
// First, all the standard properties in one go
properties = new nsXPIDLString [index_LastProp] ;
if (!properties) {
return NS_ERROR_OUT_OF_MEMORY ;
}
GetFirstName(getter_Copies(properties [index_FirstName])) ;
GetLastName(getter_Copies(properties [index_LastName])) ;
// This triple search for something to put in the name
// is because in the case of a mailing list edition in
// Mozilla, the display name will not be provided, and
// MAPI doesn't allow that, so we fall back on an optional
// name, and when all fails, on the email address.
GetDisplayName(getter_Copies(properties [index_DisplayName])) ;
if (*properties [index_DisplayName].get() == 0) {
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
PRInt32 format;
rv = prefBranch->GetIntPref(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, &format);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = abSession->GenerateNameFromCard(this, format, getter_Copies(properties [index_DisplayName]));
NS_ENSURE_SUCCESS(rv,rv);
if (*properties[index_DisplayName].get() == 0) {
GetPrimaryEmail(getter_Copies(properties [index_DisplayName])) ;
}
}
SetDisplayName(properties [index_DisplayName]) ;
GetNickName(getter_Copies(properties [index_NickName])) ;
GetPrimaryEmail(getter_Copies(properties [index_EmailAddress])) ;
GetWorkPhone(getter_Copies(properties [index_WorkPhoneNumber])) ;
GetHomePhone(getter_Copies(properties [index_HomePhoneNumber])) ;
GetFaxNumber(getter_Copies(properties [index_WorkFaxNumber])) ;
GetPagerNumber(getter_Copies(properties [index_PagerNumber])) ;
GetCellularNumber(getter_Copies(properties [index_MobileNumber])) ;
GetHomeCity(getter_Copies(properties [index_HomeCity])) ;
GetHomeState(getter_Copies(properties [index_HomeState])) ;
GetHomeZipCode(getter_Copies(properties [index_HomeZip])) ;
GetHomeCountry(getter_Copies(properties [index_HomeCountry])) ;
GetWorkCity(getter_Copies(properties [index_WorkCity])) ;
GetWorkState(getter_Copies(properties [index_WorkState])) ;
GetWorkZipCode(getter_Copies(properties [index_WorkZip])) ;
GetWorkCountry(getter_Copies(properties [index_WorkCountry])) ;
GetJobTitle(getter_Copies(properties [index_JobTitle])) ;
GetDepartment(getter_Copies(properties [index_Department])) ;
GetCompany(getter_Copies(properties [index_Company])) ;
GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ;
GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ;
GetNotes(getter_Copies(properties [index_Comments])) ;
if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
index_LastProp, properties)) {
PRINTF(("Cannot set general properties.\n")) ;
}
delete [] properties ;
nsXPIDLString unichar ;
nsXPIDLString unichar2 ;
WORD year = 0 ;
WORD month = 0 ;
WORD day = 0 ;
GetHomeAddress(getter_Copies(unichar)) ;
GetHomeAddress2(getter_Copies(unichar2)) ;
utility.Assign(unichar.get()) ;
if (!utility.IsEmpty()) { utility.AppendWithConversion(CRLF) ; }
utility.Append(unichar2.get()) ;
if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, utility.get())) {
PRINTF(("Cannot set home address.\n")) ;
}
GetWorkAddress(getter_Copies(unichar)) ;
GetWorkAddress2(getter_Copies(unichar2)) ;
utility.Assign(unichar.get()) ;
if (!utility.IsEmpty()) { utility.AppendWithConversion(CRLF) ; }
utility.Append(unichar2.get()) ;
if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, utility.get())) {
PRINTF(("Cannot set work address.\n")) ;
}
GetBirthYear(getter_Copies(unichar)) ;
UnicodeToWord(unichar.get(), year) ;
GetBirthMonth(getter_Copies(unichar)) ;
UnicodeToWord(unichar.get(), month) ;
GetBirthDay(getter_Copies(unichar)) ;
UnicodeToWord(unichar.get(), day) ;
if (!mapiAddBook->SetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) {
PRINTF(("Cannot set date.\n")) ;
}
return retCode ;
}

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

@ -40,9 +40,67 @@
#include "nsRDFResource.h"
#include "nsAbCardProperty.h"
#include "nsAbWinHelper.h"
struct nsMapiEntry ;
enum
{
index_DisplayName = 0,
index_EmailAddress,
index_FirstName,
index_LastName,
index_NickName,
index_WorkPhoneNumber,
index_HomePhoneNumber,
index_WorkFaxNumber,
index_PagerNumber,
index_MobileNumber,
index_HomeCity,
index_HomeState,
index_HomeZip,
index_HomeCountry,
index_WorkCity,
index_WorkState,
index_WorkZip,
index_WorkCountry,
index_JobTitle,
index_Department,
index_Company,
index_WorkWebPage,
index_HomeWebPage,
index_Comments,
index_LastProp
} ;
static const ULONG OutlookCardMAPIProps[] =
{
PR_DISPLAY_NAME_W,
PR_EMAIL_ADDRESS_W,
PR_GIVEN_NAME_W,
PR_SURNAME_W,
PR_NICKNAME_W,
PR_BUSINESS_TELEPHONE_NUMBER_W,
PR_HOME_TELEPHONE_NUMBER_W,
PR_BUSINESS_FAX_NUMBER_W,
PR_PAGER_TELEPHONE_NUMBER_W,
PR_MOBILE_TELEPHONE_NUMBER_W,
PR_HOME_ADDRESS_CITY_W,
PR_HOME_ADDRESS_STATE_OR_PROVINCE_W,
PR_HOME_ADDRESS_POSTAL_CODE_W,
PR_HOME_ADDRESS_COUNTRY_W,
PR_BUSINESS_ADDRESS_CITY_W,
PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_W,
PR_BUSINESS_ADDRESS_POSTAL_CODE_W,
PR_BUSINESS_ADDRESS_COUNTRY_W,
PR_TITLE_W,
PR_DEPARTMENT_NAME_W,
PR_COMPANY_NAME_W,
PR_BUSINESS_HOME_PAGE_W,
PR_PERSONAL_HOME_PAGE_W,
PR_COMMENT_W
} ;
class nsAbOutlookCard : public nsRDFResource,
public nsAbCardProperty
{
@ -54,9 +112,7 @@ public:
// nsIRDFResource method
NS_IMETHOD Init(const char *aUri) ;
// nsIAbCard methods
NS_IMETHOD EditCardToDatabase(const char *aUri) ;
protected:
nsMapiEntry *mMapiData ;
PRUint32 mAbWinType ;

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -43,6 +43,7 @@
#include "nsAbBaseCID.h"
#include "nsIAbCard.h"
#include "nsAbOutlookCard.h"
#include "nsXPIDLString.h"
#include "nsAbDirectoryQuery.h"
#include "nsIAbBooleanExpression.h"
@ -57,6 +58,8 @@
#include "nsCRT.h"
#include "prlog.h"
#include "prthread.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gAbOutlookDirectoryLog
@ -1334,10 +1337,142 @@ nsresult nsAbOutlookDirectory::CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard
if (!didCopy) {
retCode = newCard->Copy(aData) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
retCode = newCard->EditCardToDatabase(mURINoQuery.get()) ;
retCode = ModifyCard(newCard) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
}
*aNewCard = newCard ;
NS_ADDREF(*aNewCard) ;
return retCode ;
}
static void UnicodeToWord(const PRUnichar *aUnicode, WORD& aWord)
{
aWord = 0 ;
if (aUnicode == nsnull || *aUnicode == 0) { return ; }
PRInt32 errorCode = 0 ;
nsAutoString unichar (aUnicode) ;
aWord = NS_STATIC_CAST(WORD, unichar.ToInteger(&errorCode)) ;
if (errorCode != 0) {
PRINTF(("Error conversion string %S: %08x.\n", unichar.get(), errorCode)) ;
}
}
#define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst"
NS_IMETHODIMP nsAbOutlookDirectory::ModifyCard(nsIAbCard *aModifiedCard)
{
NS_ENSURE_ARG_POINTER(aModifiedCard);
nsresult retCode = NS_OK;
nsXPIDLString *properties = nsnull;
nsAutoString utility;
nsAbWinHelperGuard mapiAddBook(mAbWinType);
if (!mapiAddBook->IsOK())
return NS_ERROR_FAILURE;
// First, all the standard properties in one go
properties = new nsXPIDLString[index_LastProp];
if (!properties) {
return NS_ERROR_OUT_OF_MEMORY;
}
aModifiedCard->GetFirstName(getter_Copies(properties[index_FirstName]));
aModifiedCard->GetLastName(getter_Copies(properties[index_LastName]));
// This triple search for something to put in the name
// is because in the case of a mailing list edition in
// Mozilla, the display name will not be provided, and
// MAPI doesn't allow that, so we fall back on an optional
// name, and when all fails, on the email address.
aModifiedCard->GetDisplayName(getter_Copies(properties[index_DisplayName]));
if (*properties[index_DisplayName].get() == 0) {
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefBranch =
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
PRInt32 format;
rv = prefBranch->GetIntPref(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, &format);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIAddrBookSession> abSession =
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = abSession->GenerateNameFromCard(aModifiedCard, format, getter_Copies(properties [index_DisplayName]));
NS_ENSURE_SUCCESS(rv,rv);
if (*properties[index_DisplayName].get() == 0) {
aModifiedCard->GetPrimaryEmail(getter_Copies(properties[index_DisplayName]));
}
}
aModifiedCard->SetDisplayName(properties[index_DisplayName]);
aModifiedCard->GetNickName(getter_Copies(properties[index_NickName]));
aModifiedCard->GetPrimaryEmail(getter_Copies(properties[index_EmailAddress]));
aModifiedCard->GetWorkPhone(getter_Copies(properties[index_WorkPhoneNumber]));
aModifiedCard->GetHomePhone(getter_Copies(properties[index_HomePhoneNumber]));
aModifiedCard->GetFaxNumber(getter_Copies(properties[index_WorkFaxNumber]));
aModifiedCard->GetPagerNumber(getter_Copies(properties[index_PagerNumber]));
aModifiedCard->GetCellularNumber(getter_Copies(properties[index_MobileNumber]));
aModifiedCard->GetHomeCity(getter_Copies(properties[index_HomeCity]));
aModifiedCard->GetHomeState(getter_Copies(properties[index_HomeState]));
aModifiedCard->GetHomeZipCode(getter_Copies(properties[index_HomeZip]));
aModifiedCard->GetHomeCountry(getter_Copies(properties[index_HomeCountry]));
aModifiedCard->GetWorkCity(getter_Copies(properties[index_WorkCity]));
aModifiedCard->GetWorkState(getter_Copies(properties[index_WorkState]));
aModifiedCard->GetWorkZipCode(getter_Copies(properties[index_WorkZip]));
aModifiedCard->GetWorkCountry(getter_Copies(properties[index_WorkCountry]));
aModifiedCard->GetJobTitle(getter_Copies(properties[index_JobTitle]));
aModifiedCard->GetDepartment(getter_Copies(properties[index_Department]));
aModifiedCard->GetCompany(getter_Copies(properties[index_Company]));
aModifiedCard->GetWebPage1(getter_Copies(properties[index_WorkWebPage]));
aModifiedCard->GetWebPage2(getter_Copies(properties[index_HomeWebPage]));
aModifiedCard->GetNotes(getter_Copies(properties[index_Comments]));
if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
index_LastProp, properties)) {
PRINTF(("Cannot set general properties.\n")) ;
}
delete [] properties;
nsXPIDLString unichar;
nsXPIDLString unichar2;
WORD year = 0;
WORD month = 0;
WORD day = 0;
aModifiedCard->GetHomeAddress(getter_Copies(unichar));
aModifiedCard->GetHomeAddress2(getter_Copies(unichar2));
utility.Assign(unichar.get());
if (!utility.IsEmpty())
utility.AppendWithConversion(CRLF);
utility.Append(unichar2.get());
if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, utility.get())) {
PRINTF(("Cannot set home address.\n")) ;
}
aModifiedCard->GetWorkAddress(getter_Copies(unichar));
aModifiedCard->GetWorkAddress2(getter_Copies(unichar2));
utility.Assign(unichar.get());
if (!utility.IsEmpty())
utility.AppendWithConversion(CRLF);
utility.Append(unichar2.get());
if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, utility.get())) {
PRINTF(("Cannot set work address.\n")) ;
}
aModifiedCard->GetBirthYear(getter_Copies(unichar));
UnicodeToWord(unichar.get(), year);
aModifiedCard->GetBirthMonth(getter_Copies(unichar));
UnicodeToWord(unichar.get(), month);
aModifiedCard->GetBirthDay(getter_Copies(unichar));
UnicodeToWord(unichar.get(), day);
if (!mapiAddBook->SetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) {
PRINTF(("Cannot set date.\n")) ;
}
return retCode;
}

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -58,63 +58,64 @@ class nsAbOutlookDirectory : public nsAbDirectoryRDFResource, // nsIRDFResource
public:
NS_DECL_ISUPPORTS_INHERITED
nsAbOutlookDirectory(void) ;
virtual ~nsAbOutlookDirectory(void) ;
nsAbOutlookDirectory(void);
virtual ~nsAbOutlookDirectory(void);
// nsAbDirProperty methods
NS_IMETHOD GetURI(nsACString &aURI);
NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards) ;
NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes) ;
NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard) ;
NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory) ;
NS_IMETHOD DeleteCards(nsISupportsArray *aCardList) ;
NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties);
NS_IMETHOD DeleteDirectory(nsIAbDirectory *aDirectory) ;
NS_IMETHOD GetURI(nsACString &aURI);
NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards);
NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
NS_IMETHOD DeleteCards(nsISupportsArray *aCardList);
NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties);
NS_IMETHOD DeleteDirectory(nsIAbDirectory *aDirectory);
NS_IMETHOD AddCard(nsIAbCard *aData, nsIAbCard **addedCard);
NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
NS_IMETHOD DropCard(nsIAbCard *aData, PRBool needToCopyCard);
NS_IMETHOD AddMailList(nsIAbDirectory *aMailList) ;
NS_IMETHOD EditMailListToDatabase(const char *aUri, nsIAbCard *listCard) ;
NS_IMETHOD AddMailList(nsIAbDirectory *aMailList);
NS_IMETHOD EditMailListToDatabase(const char *aUri, nsIAbCard *listCard);
// nsAbDirectoryRDFResource method
NS_IMETHOD Init(const char *aUri) ;
// nsIAbDirectoryQuery methods
NS_DECL_NSIABDIRECTORYQUERY
// nsIAbDirectorySearch methods
NS_DECL_NSIABDIRECTORYSEARCH
// nsAbDirSearchListenerContext methods
nsresult OnSearchFinished(PRInt32 aResult) ;
nsresult OnSearchFoundCard(nsIAbCard *aCard) ;
// Perform a MAPI query (function executed in a separate thread)
nsresult ExecuteQuery(nsIAbDirectoryQueryArguments *aArguments,
nsIAbDirectoryQueryResultListener *aListener,
PRInt32 aResultLimit, PRInt32 aTimeout,
PRInt32 aThreadId) ;
// nsAbDirectoryRDFResource method
NS_IMETHOD Init(const char *aUri);
// nsIAbDirectoryQuery methods
NS_DECL_NSIABDIRECTORYQUERY
// nsIAbDirectorySearch methods
NS_DECL_NSIABDIRECTORYSEARCH
// nsAbDirSearchListenerContext methods
nsresult OnSearchFinished(PRInt32 aResult);
nsresult OnSearchFoundCard(nsIAbCard *aCard);
// Perform a MAPI query (function executed in a separate thread)
nsresult ExecuteQuery(nsIAbDirectoryQueryArguments *aArguments,
nsIAbDirectoryQueryResultListener *aListener,
PRInt32 aResultLimit, PRInt32 aTimeout,
PRInt32 aThreadId);
protected:
// Retrieve hierarchy as cards, with an optional restriction
nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction) ;
// Retrieve hierarchy as directories
nsresult GetChildNodes(nsISupportsArray **aNodes) ;
// Create a new card
nsresult CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard) ;
// Notification for the UI
nsresult NotifyItemDeletion(nsISupports *aItem) ;
nsresult NotifyItemAddition(nsISupports *aItem) ;
// Force update of MAPI repository for mailing list
nsresult CommitAddressList(void) ;
// Read MAPI repository
nsresult UpdateAddressList(void) ;
// Retrieve hierarchy as cards, with an optional restriction
nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction);
// Retrieve hierarchy as directories
nsresult GetChildNodes(nsISupportsArray **aNodes);
// Create a new card
nsresult CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard);
// Notification for the UI
nsresult NotifyItemDeletion(nsISupports *aItem);
nsresult NotifyItemAddition(nsISupports *aItem);
// Force update of MAPI repository for mailing list
nsresult CommitAddressList(void);
// Read MAPI repository
nsresult UpdateAddressList(void);
nsMapiEntry *mMapiData ;
// Container for the query threads
nsHashtable mQueryThreads ;
PRInt32 mCurrentQueryId ;
PRLock *mProtector ;
// Data for the search interfaces
nsSupportsHashtable mCardList ;
PRInt32 mSearchContext ;
// Windows AB type
PRUint32 mAbWinType ;
nsMapiEntry *mMapiData;
// Container for the query threads
nsHashtable mQueryThreads;
PRInt32 mCurrentQueryId;
PRLock *mProtector;
// Data for the search interfaces
nsSupportsHashtable mCardList;
PRInt32 mSearchContext;
// Windows AB type
PRUint32 mAbWinType;
};
#endif // nsAbOutlookDirectory_h___

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

@ -139,12 +139,6 @@
#include "nsAddbookProtocolHandler.h"
#include "nsAddbookUrl.h"
#if defined(XP_WIN) && !defined(__MINGW32__)
#include "nsAbOutlookDirectory.h"
#include "nsAbOutlookCard.h"
#include "nsAbOutlookDirFactory.h"
#endif
#include "nsAbDirectoryQuery.h"
#include "nsAbBooleanExpression.h"
#include "nsAbDirectoryQueryProxy.h"
@ -165,6 +159,15 @@
#include "nsLDAPAutoCompleteSession.h"
#endif
#if defined(XP_WIN) && !defined(__MINGW32__)
#include "nsAbOutlookDirFactory.h"
// These two cause windows.h to be included, if not placed after *DirFactory.h
// then this can cause problems with CreateDirectory not being
// defined.
#include "nsAbOutlookDirectory.h"
#include "nsAbOutlookCard.h"
#endif
////////////////////////////////////////////////////////////////////////////////
// bayesian spam filter includes
////////////////////////////////////////////////////////////////////////////////