Bug 408180 Generating a name from a card should be a function of nsIAbCard and not of nsIAddrBookSession. r=Neil,sr=bienvenu

This commit is contained in:
bugzilla%standard8.plus.com 2007-12-19 17:42:44 +00:00
Родитель 777b74a7b7
Коммит 6d35f462b2
11 изменённых файлов: 253 добавлений и 297 удалений

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

@ -195,7 +195,7 @@ function GoIM()
function DisplayCardViewPane(card)
{
var generatedName = gAddrbookSession.generateNameFromCard(card, gPrefs.getIntPref("mail.addr_book.lastnamefirst"));
var generatedName = card.generateName(gPrefs.getIntPref("mail.addr_book.lastnamefirst"));
var data = top.cvData;
var visible;

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

@ -37,6 +37,8 @@
#include "nsISupports.idl"
interface nsIStringBundle;
[scriptable, uuid(97448252-F189-11d4-A422-001083003D0C)]
interface nsIAbPreferMailFormat {
const unsigned long unknown = 0;
@ -44,7 +46,7 @@ interface nsIAbPreferMailFormat {
const unsigned long html = 2;
};
[scriptable, uuid(511887fc-4096-4981-be2b-aa0f7d30f97a)]
[scriptable, uuid(193d5026-7d1e-41b4-9fc3-c57d4a4937f3)]
interface nsIAbCard : nsISupports {
// Card properties
attribute AString firstName;
@ -138,4 +140,39 @@ interface nsIAbCard : nsISupports {
string convertToBase64EncodedXML();
AString convertToXMLPrintData();
string convertToEscapedVCard();
/**
* Generate a name from the card for display purposes. Using the firstName,
* lastName and the displayName. We allow the caller to cache the pref value,
* so we don't have to go to prefs every time.
*
* The format follows the "mail.addr_book.lastnamefirst" pref values:
*
* 0 = generated name is displayName
* 1 = lastFirst, formatted following lastFirstFormat
* 2 = firstLast, formatted following firstLastFormat
*
* lastFirstFormat and firstLastFormat are defined in addressBook.properties.
*
* @param aGenerateFormat The format to generate as per the above definition.
* @param aBundle An optional parameter that is a pointer to a string
* bundle that holds:
* chrome://messenger/locale/addressbook/addressBook.properties
* If this bundle is not supplied, then the function
* will obtain the bundle itself. If cached by the
* caller and supplied to this function, then
* performance will be improved over many calls.
* @return A string containing the generated name.
*/
AString generateName(in long aGenerateFormat,
[optional] in nsIStringBundle aBundle);
/**
* Generate a phonetic name from the card, using the firstName and lastName
* values.
*
* @param aLastNameFirst Set to True to put the last name before the first.
* @return A string containing the generated phonetic name.
*/
AString generatePhoneticName(in boolean aLastNameFirst);
};

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

@ -1,141 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/*
* The mail session is a replacement for the old 4.x MSG_Master object. It
* contains mail session generic information such as the account manager, etc
* I'm starting this off as an empty interface and as people feel they need to
* add more information to it, they can. I think this is a better approach
* than trying to port over the old MSG_Master in its entirety as that had a
* lot of cruft in it....
*/
#include "nsISupports.idl"
#include "nsIAbListener.idl"
#include "nsIAbDirectory.idl"
#include "nsIAbCard.idl"
interface nsILocalFile;
[scriptable, uuid(90533607-7205-473f-b688-ffb50eeb5d57)]
interface nsIAddrBookSession : nsISupports {
/**
* Adds a nsIAbListener to receive notifications of address book updates
* according to the specified notifyFlags.
*
* @param listener The listener that is to receive updates.
*
* @param notifyFlags A bitwise-or of abListenerNotifyFlagValue items
* specifying which notifications to receive.
*
*/
void addAddressBookListener(in nsIAbListener listener, in abListenerNotifyFlagValue notifyFlags);
/**
* These flags specify when to receive notifications of address book updates
* to be passed to addAddressBookListener.
*/
/**
* An address book, mailing list or card is added.
*/
const abListenerNotifyFlagValue added = 0x1;
/**
* A mailing list or card is removed from an address book.
*/
const abListenerNotifyFlagValue directoryItemRemoved = 0x2;
/**
* An address book is removed
*/
const abListenerNotifyFlagValue directoryRemoved = 0x4;
/**
* An address book, mailing list or card is changed.
*/
const abListenerNotifyFlagValue changed = 0x8;
/**
* All of the above notifications are to be received.
*/
const abListenerNotifyFlagValue all = 0xFFFFFFFF;
/**
* Removes a nsIAbListener from receive notifications of address book
* updates.
*
* @param listener The listener that is to no longer receive updates.
*
*/
void removeAddressBookListener(in nsIAbListener listener);
void notifyItemPropertyChanged(in nsISupports item,
in string property,
in wstring oldValue,
in wstring newValue);
void notifyDirectoryItemAdded(in nsIAbDirectory directory, in nsISupports item);
/**
* when a card is deleted
*/
void notifyDirectoryItemDeleted(in nsIAbDirectory directory, in nsISupports item);
/**
* when a directory is deleted
*/
void notifyDirectoryDeleted(in nsIAbDirectory directory, in nsISupports item);
readonly attribute nsILocalFile userProfileDirectory;
/**
* generate the name from the card, using the firstName and lastName and the displayName
*
* format follows the "mail.addr_book.lastnamefirst" pref values
*
* 0 = generated name is displayName
* 1 = lastFirst, formatted following lastFirstFormat (see addressBook.properties)
* 2 = firstLast, formatted following firstLastFormat (see addressBook.properties)
*
* we allow the caller to cache the pref value, so we don't have to go to prefs every time.
*/
wstring generateNameFromCard(in nsIAbCard card, in long generateFormat);
/**
* generate the phonetic name from the card, using the firstName and lastName
*
*/
wstring generatePhoneticNameFromCard(in nsIAbCard aCard, in boolean aLastNameFirst);
};

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

@ -194,7 +194,7 @@ function GoIM()
function DisplayCardViewPane(card)
{
var generatedName = gAddrbookSession.generateNameFromCard(card, gPrefs.getIntPref("mail.addr_book.lastnamefirst"));
var generatedName = card.generateName(gPrefs.getIntPref("mail.addr_book.lastnamefirst"));
var data = top.cvData;
var visible;

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

@ -43,7 +43,6 @@
#include "nsIPrefService.h"
#include "nsIAddrDatabase.h"
#include "plbase64.h"
#include "nsIAddrBookSession.h"
#include "nsIStringBundle.h"
#include "plstr.h"
#include "nsIRDFResource.h"
@ -59,6 +58,9 @@
#include "mozITXTToHTMLConv.h"
#define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst"
#define kDisplayName 0
#define kLastFirst 1
#define kFirstLast 2
const char sAddrbookProperties[] = "chrome://messenger/locale/addressbook/addressBook.properties";
@ -1211,11 +1213,15 @@ NS_IMETHODIMP nsAbCardProperty::ConvertToXMLPrintData(nsAString &aXMLSubstr)
rv = prefBranch->GetIntPref(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, &generatedNameFormat);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv,rv);
nsString generatedName;
rv = abSession->GenerateNameFromCard(this, generatedNameFormat, getter_Copies(generatedName));
rv = GenerateName(generatedNameFormat, bundle, generatedName);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<mozITXTToHTMLConv> conv = do_CreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID, &rv);
@ -1225,14 +1231,6 @@ NS_IMETHODIMP nsAbCardProperty::ConvertToXMLPrintData(nsAString &aXMLSubstr)
xmlStr.SetLength(4096); // to reduce allocations. should be enough for most cards
xmlStr.AssignLiteral("<GeneratedName>\n");
nsCOMPtr<nsIStringBundle> bundle;
nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv,rv);
nsString heading;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("headingCardFor").get(), getter_Copies(heading));
NS_ENSURE_SUCCESS(rv, rv);
@ -1562,3 +1560,79 @@ nsresult nsAbCardProperty::AppendCityStateZip(const AppendItem &aItem,
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::GenerateName(PRInt32 aGenerateFormat,
nsIStringBundle* aBundle,
nsAString &aResult)
{
// No need to check for aBundle present straight away, only do that if we're
// actually going to use it.
if (aGenerateFormat == kDisplayName)
aResult = m_DisplayName;
else if (m_LastName.IsEmpty())
aResult = m_FirstName;
else if (m_FirstName.IsEmpty())
aResult = m_LastName;
else {
nsresult rv;
nsCOMPtr<nsIStringBundle> bundle(aBundle);
if (!bundle) {
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = stringBundleService->CreateBundle(sAddrbookProperties,
getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
}
nsString result;
if (aGenerateFormat == kLastFirst) {
const PRUnichar *stringParams[2] = {m_LastName.get(), m_FirstName.get()};
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("lastFirstFormat").get(),
stringParams, 2, getter_Copies(result));
}
else {
const PRUnichar *stringParams[2] = {m_FirstName.get(), m_LastName.get()};
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("firstLastFormat").get(),
stringParams, 2, getter_Copies(result));
}
NS_ENSURE_SUCCESS(rv, rv);
aResult.Assign(result);
}
if (aResult.IsEmpty())
{
// see bug #211078
// if there is no generated name at this point
// use the userid from the email address
// it is better than nothing.
aResult = m_PrimaryEmail;
PRInt32 index = aResult.FindChar('@');
if (index != -1)
aResult.SetLength(index);
}
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::GeneratePhoneticName(PRBool aLastNameFirst,
nsAString &aResult)
{
if (aLastNameFirst)
{
aResult = m_PhoneticLastName;
aResult += m_PhoneticFirstName;
}
else
{
aResult = m_PhoneticFirstName;
aResult += m_PhoneticLastName;
}
return NS_OK;
}

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

@ -1415,11 +1415,8 @@ NS_IMETHODIMP nsAbOutlookDirectory::ModifyCard(nsIAbCard *aModifiedCard)
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]));
rv = aModifiedCard->GenerateName(format, nsnull,
properties[index_DisplayName]);
NS_ENSURE_SUCCESS(rv,rv);
if (*properties[index_DisplayName].get() == 0) {

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 2; 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
*
@ -60,7 +60,6 @@
#include "nsIPrefLocalizedString.h"
#include "nsIAddrDatabase.h" // for kPriEmailColumn
#include "rdf.h"
#define CARD_NOT_FOUND -1
@ -190,10 +189,19 @@ nsresult nsAbView::RemovePrefObservers()
NS_IMETHODIMP nsAbView::Init(const char *aURI, PRBool aSearchView, nsIAbViewListener *abViewListener,
const PRUnichar *colID, const PRUnichar *sortDirection, PRUnichar **result)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(result);
nsresult rv;
if (!mABBundle)
{
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = stringBundleService->CreateBundle("chrome://messenger/locale/addressbook/addressBook.properties", getter_AddRefs(mABBundle));
NS_ENSURE_SUCCESS(rv,rv);
}
mURI = aURI;
mAbViewListener = nsnull;
if (mTree)
@ -250,7 +258,7 @@ NS_IMETHODIMP nsAbView::Init(const char *aURI, PRBool aSearchView, nsIAbViewList
// need to check if _Generic is valid. GetCardValue() will always return NS_OK for _Generic
// we're going to have to ask mDirectory if it is.
// it might not be. example: _ScreenName is valid in Netscape, but not Mozilla.
rv = GetCardValue(card, colID, getter_Copies(value));
rv = GetCardValue(card, colID, value);
if (NS_FAILED(rv))
actualSortColumn = generatedNameColumnId.get();
else
@ -454,7 +462,8 @@ NS_IMETHODIMP nsAbView::GetCellValue(PRInt32 row, nsITreeColumn* col, nsAString&
return NS_OK;
}
nsresult nsAbView::GetCardValue(nsIAbCard *card, const PRUnichar *colID, PRUnichar **_retval)
nsresult nsAbView::GetCardValue(nsIAbCard *card, const PRUnichar *colID,
nsAString &_retval)
{
nsresult rv;
@ -468,19 +477,14 @@ nsresult nsAbView::GetCardValue(nsIAbCard *card, const PRUnichar *colID, PRUnich
NS_ENSURE_SUCCESS(rv,rv);
if (colID[0] == PRUnichar('G'))
rv = abSession->GenerateNameFromCard(card, mGeneratedNameFormat, _retval);
rv = card->GenerateName(mGeneratedNameFormat, mABBundle, _retval);
else
// use LN/FN order for the phonetic name
rv = abSession->GeneratePhoneticNameFromCard(card, PR_TRUE, _retval);
rv = card->GeneratePhoneticName(PR_TRUE, _retval);
NS_ENSURE_SUCCESS(rv,rv);
}
else {
nsString cardValue;
rv = card->GetCardValue(NS_LossyConvertUTF16toASCII(colID).get(),
cardValue);
*_retval = ToNewUnicode(cardValue);
if (!_retval)
return NS_ERROR_OUT_OF_MEMORY;
rv = card->GetCardValue(NS_LossyConvertUTF16toASCII(colID).get(), _retval);
}
return rv;
}
@ -522,13 +526,9 @@ NS_IMETHODIMP nsAbView::GetCellText(PRInt32 row, nsITreeColumn* col, nsAString&
NS_ENSURE_TRUE(row >= 0 && row < mCards.Count(), NS_ERROR_UNEXPECTED);
nsIAbCard *card = ((AbCard *)(mCards.ElementAt(row)))->card;
// XXX fix me by converting GetCardValue to take an nsAString&
const PRUnichar* colID;
col->GetIdConst(&colID);
nsString cellText;
nsresult rv = GetCardValue(card, colID, getter_Copies(cellText));
_retval.Assign(cellText);
return rv;
return GetCardValue(card, colID, _retval);
}
NS_IMETHODIMP nsAbView::SetTree(nsITreeBoxObject *tree)
@ -798,7 +798,7 @@ nsresult nsAbView::GenerateCollationKeysForCard(const PRUnichar *colID, AbCard *
NS_ENSURE_SUCCESS(rv, rv);
}
rv = GetCardValue(abcard->card, colID, getter_Copies(value));
rv = GetCardValue(abcard->card, colID, value);
NS_ENSURE_SUCCESS(rv,rv);
PR_FREEIF(abcard->primaryCollationKey);
@ -806,11 +806,10 @@ nsresult nsAbView::GenerateCollationKeysForCard(const PRUnichar *colID, AbCard *
value, &(abcard->primaryCollationKey), &(abcard->primaryCollationKeyLen));
NS_ENSURE_SUCCESS(rv,rv);
// XXX todo
// fix me, do this with a const getter, to avoid the strcpy
// hardcode email to be our secondary key
rv = GetCardValue(abcard->card, NS_LITERAL_STRING(kPriEmailColumn).get(), getter_Copies(value));
// Hardcode email to be our secondary key. As we are doing this, just call
// the card's GetCardValue direct, rather than our own function which will
// end up doing the same as then we can save a bit of time.
rv = abcard->card->GetCardValue(NS_LITERAL_CSTRING(kPriEmailColumn).get(), value);
NS_ENSURE_SUCCESS(rv,rv);
PR_FREEIF(abcard->secondaryCollationKey);

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

@ -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
*
@ -54,6 +54,7 @@
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsMemory.h"
#include "nsIStringBundle.h"
typedef struct AbCard
{
@ -95,7 +96,7 @@ private:
nsresult SetGeneratedNameFormatFromPrefs();
nsresult GetSelectedCards(nsISupportsArray **cards);
nsresult ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard);
nsresult GetCardValue(nsIAbCard *card, const PRUnichar *colID, PRUnichar **_retval);
nsresult GetCardValue(nsIAbCard *card, const PRUnichar *colID, nsAString &_retval);
nsresult RefreshTree();
nsCString mURI;
@ -106,6 +107,7 @@ private:
nsString mSortDirection;
nsCOMPtr<nsICollation> mCollationKeyGenerator;
nsCOMPtr<nsIAbViewListener> mAbViewListener;
nsCOMPtr<nsIStringBundle> mABBundle;
PRPackedBool mSearchView;
PRPackedBool mSuppressSelectionChange;

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

@ -45,6 +45,7 @@
#include "nsDirectoryServiceUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsStringGlue.h"
#include "nsIAbDirectory.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAddrBookSession, nsIAddrBookSession)
@ -194,111 +195,3 @@ NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsILocalFile * *userDir
return NS_NewNativeLocalFile(pathBuf, PR_TRUE, userDir);
}
#define kDisplayName 0
#define kLastFirst 1
#define kFirstLast 2
NS_IMETHODIMP nsAddrBookSession::GenerateNameFromCard(nsIAbCard *card, PRInt32 generateFormat, PRUnichar **aName)
{
nsresult rv = NS_OK;
nsAutoString name;
if (generateFormat == kDisplayName) {
rv = card->GetDisplayName(name);
}
else {
nsAutoString firstName;
nsAutoString lastName;
rv = card->GetFirstName(firstName);
NS_ENSURE_SUCCESS(rv, rv);
rv = card->GetLastName(lastName);
NS_ENSURE_SUCCESS(rv,rv);
if (!lastName.IsEmpty() && !firstName.IsEmpty()) {
if (!mBundle) {
nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = stringBundleService->CreateBundle("chrome://messenger/locale/addressbook/addressBook.properties", getter_AddRefs(mBundle));
NS_ENSURE_SUCCESS(rv,rv);
}
nsString generatedName;
if (generateFormat == kLastFirst) {
const PRUnichar *stringParams[2] = {lastName.get(), firstName.get()};
rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("lastFirstFormat").get(), stringParams, 2,
getter_Copies(generatedName));
}
else {
const PRUnichar *stringParams[2] = {firstName.get(), lastName.get()};
rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("firstLastFormat").get(), stringParams, 2,
getter_Copies(generatedName));
}
NS_ENSURE_SUCCESS(rv,rv);
name = generatedName;
}
else {
if (lastName.Length())
name = lastName;
else {
// name may be empty here, but that's ok.
name = firstName;
}
}
}
if (name.IsEmpty())
{
// see bug #211078
// if there is no generated name at this point
// use the userid from the email address
// it is better than nothing.
card->GetPrimaryEmail(name);
PRInt32 index = name.FindChar('@');
if (index != -1)
name.SetLength(index);
}
*aName = ToNewUnicode(name);
return NS_OK;
}
NS_IMETHODIMP nsAddrBookSession::GeneratePhoneticNameFromCard(nsIAbCard *aCard, PRBool aLastNameFirst, PRUnichar **aName)
{
NS_ENSURE_ARG_POINTER(aCard);
NS_ENSURE_ARG_POINTER(aName);
nsAutoString firstName;
nsAutoString lastName;
nsAutoString fullName;
nsresult rv = aCard->GetPhoneticFirstName(firstName);
NS_ENSURE_SUCCESS(rv, rv);
rv = aCard->GetPhoneticLastName(lastName);
NS_ENSURE_SUCCESS(rv, rv);
if (aLastNameFirst)
{
fullName = lastName;
fullName += firstName;
*aName = ToNewUnicode(fullName);
}
else
{
fullName = firstName;
fullName += lastName;
*aName = ToNewUnicode(fullName);
}
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

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

@ -40,7 +40,7 @@
#include "nsIAddrBookSession.h"
#include "nsISupports.h"
#include "nsIStringBundle.h"
#include "nsISupportsArray.h"
#include "nsUInt32Array.h"
class nsAddrBookSession : public nsIAddrBookSession
@ -55,7 +55,6 @@ public:
protected:
nsCOMPtr <nsISupportsArray> mListeners;
nsUInt32Array mListenerNotifyFlags;
nsCOMPtr<nsIStringBundle> mBundle;
};
#endif /* nsAddrBookSession_h__ */

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

@ -0,0 +1,96 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Test suite for basic nsIAbCard functions.
*/
var testnum = 0;
// Intersperse these with UTF-8 values to check we handle them correctly.
const kFNValue = "testFirst\u00D0";
const kLNValue = "testLast";
const kDNValue = "testDisplay\u00D1";
const kEmailValue = "testEmail\u00D2@invalid.com";
// Email without the @ or anything after it.
const kEmailReducedValue = "testEmail\u00D2";
function run_test() {
try {
// Create a new card
var card = Components.classes["@mozilla.org/addressbook/cardproperty;1"]
.createInstance(Components.interfaces.nsIAbCard);
++testnum; // Test 1 - Set First, Last and Display Names and Email Address
// via setCardValue, and check correctly saved via their
// attributes. We're using firstName to check UTF-8 values.
card.setCardValue("FirstName", kFNValue);
card.setCardValue("LastName", kLNValue);
card.setCardValue("DisplayName", kDNValue);
card.setCardValue("PrimaryEmail", kEmailValue);
do_check_eq(card.firstName, kFNValue);
do_check_eq(card.lastName, kLNValue);
do_check_eq(card.displayName, kDNValue);
do_check_eq(card.primaryEmail, kEmailValue);
++testnum; // Test 2 - generateName. Note: if the addressBook.properties
// value changes, this will affect these tests.
do_check_eq(card.generateName(0), kDNValue);
do_check_eq(card.generateName(1), kLNValue + ", " + kFNValue);
do_check_eq(card.generateName(2), kFNValue + " " + kLNValue);
++testnum; // Test 3 - geneateName, with missing items.
card.displayName = "";
do_check_eq(card.generateName(0), kEmailReducedValue);
card.firstName = "";
do_check_eq(card.generateName(1), kLNValue);
do_check_eq(card.generateName(2), kLNValue);
card.firstName = kFNValue;
card.lastName = "";
do_check_eq(card.generateName(1), kFNValue);
do_check_eq(card.generateName(2), kFNValue);
card.firstName = "";
do_check_eq(card.generateName(1), kEmailReducedValue);
do_check_eq(card.generateName(2), kEmailReducedValue);
card.primaryEmail = "";
do_check_eq(card.generateName(1), "");
do_check_eq(card.generateName(2), "");
++testnum; // Test 4 - generateNameWithBundle, most of this will have
// been tested above.
card.setCardValue("FirstName", kFNValue);
card.setCardValue("LastName", kLNValue);
var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var bundle = sbs.createBundle("chrome://messenger/locale/addressbook/addressBook.properties");
do_check_eq(card.generateName(1, bundle), kLNValue + ", " + kFNValue);
++testnum; // Test 5 - generatePhoneticName
card.phoneticFirstName = kFNValue;
card.phoneticLastName = kLNValue;
do_check_eq(card.generatePhoneticName(false), kFNValue + kLNValue);
do_check_eq(card.generatePhoneticName(true), kLNValue + kFNValue);
card.phoneticLastName = "";
do_check_eq(card.generatePhoneticName(false), kFNValue);
do_check_eq(card.generatePhoneticName(true), kFNValue);
card.phoneticFirstName = "";
card.phoneticLastName = kLNValue;
do_check_eq(card.generatePhoneticName(false), kLNValue);
do_check_eq(card.generatePhoneticName(true), kLNValue);
} catch (e) {
throw "FAILED in basic nsIAbCard tests, test #" + testnum + ": " + e;
}
}