summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/addrbook/public/nsIAbCard.idl
blob: 69acf7fa955197995c8d61998b7a60a10940bb78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

interface nsIProperty;
interface nsIStringBundle;
interface nsIVariant;

[scriptable, uuid(97448252-F189-11d4-A422-001083003D0C)]
interface nsIAbPreferMailFormat : nsISupports {
    const unsigned long unknown   = 0;
    const unsigned long plaintext = 1;
    const unsigned long html      = 2;
};

/**
 * An interface representing an address book card.
 *
 * None of these IDs will be reflected in the property collection. Neither
 * nsIAbCard::properties, nsIAbCard::deleteProperty, nor any of the property
 * getters and setters are able to interact with these properties.
 *
 * Fundamentally, a card is a collection of properties. Modifying a property in
 * some way on a card does not change the backend used to store the card; the
 * directory is required to do make the changes here.
 *
 * The following are the core properties that are used:
 * - Names:
 *   - FirstName, LastName
 *   - PhoneticFirstName, PhoneticLastName
 *   - DisplayName, NickName
 *   - SpouseName, FamilyName
 * - PrimaryEmail, SecondEmail
 * - Home Contact:
 *   - HomeAddress, HomeAddress2, HomeCity, HomeState, HomeZipCode, HomeCountry
 *   - HomePhone, HomePhoneType
 * - Work contact. Same as home, but with `Work' instead of `Home'
 * - Other Contact:
 *   - FaxNumber, FaxNumberType
 *   - PagerNumber, PagerNumberType
 *   - CellularNumber, CellularNumberType
 * - JobTitle, Department, Company
 * - _AimScreenName
 * - Dates:
 *   - AnniversaryYear, AnniversaryMonth, AnniversaryDay
 *   - BirthYear, BirthMonth, BirthDay
 * - WebPage1 (work), WebPage2 (home)
 * - Custom1, Custom2, Custom3, Custom4
 * - Notes
 * - Integral properties:
 *   - LastModifiedDate
 *   - PopularityIndex
 * - Photo properties:
 *   - PhotoName
 *   - PhotoType
 *   - PhotoURI
 *
 * The contract id for the standard implementation is
 * <tt>\@mozilla.org/addressbook/cardproperty;1</tt>.
 */
[scriptable, uuid(9bddf024-5178-4097-894e-d84b4ddde101)]
interface nsIAbCard : nsISupports {
  /**
   * @{
   * These constants reflect the possible values of the
   * mail.addr_book.lastnamefirst preferences. They are intended to be used in
   * generateName, defined below.
   */
   const unsigned long GENERATE_DISPLAY_NAME = 0;
   const unsigned long GENERATE_LAST_FIRST_ORDER = 1;
   const unsigned long GENERATE_FIRST_LAST_ORDER = 2;
   /** @} */

  /**
   * Generate a name from the item for display purposes.
   *
   * If this item is an nsIAbCard, then it will use the aGenerateFormat option
   * to determine the string to return.
   * If this item is not an nsIAbCard, then the aGenerateFormat option may be
   * ignored, and the displayName of the item returned.
   *
   * @param  aGenerateFormat The format to generate as per the GENERATE_*
   *                         constants above.
   * @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);

  /**
   * The UID for the nsIAbDirectory containing this card.
   *
   * The directory considered to contain this card is the directory which
   * produced this card (e.g., through nsIAbDirectory::getCardForProperty) or
   * the last directory to modify this card, if another directory did so. If the
   * last directory to modify this card deleted it, then this card is considered
   * unassociated.
   *
   * If this card is not associated with a directory, this string will be empty.
   *
   * There is no standardized way to associate a card with multiple directories.
   *
   * Consumers of this interface outside of directory implementations SHOULD
   * NOT, in general, modify this property.
   */
  attribute AUTF8String directoryUID;

  /**
   * A 128-bit unique identifier for this card. This can only be set if it is not
   * already set. The getter sets a value if there is not one.
   */
  attribute AUTF8String UID;

  /**
   * A list of all the properties that this card has as an enumerator, whose
   * members are all nsIProperty objects.
   */
  readonly attribute Array<nsIProperty> properties;

  /**
   * Returns a property for the given name.
   *
   * @param name             The case-sensitive name of the property to get.
   * @param defaultValue     The value to return if the property does not exist.
   * @exception NS_ERROR_NOT_AVAILABLE if the named property does not exist.
   * @exception NS_ERROR_CANNOT_CONVERT_DATA if the property cannot be converted
   *                                         to the desired type.
   */
  nsIVariant getProperty(in AUTF8String name, in nsIVariant defaultValue);
  /**
   * @{
   * Returns a property for the given name.  Javascript callers should NOT use these,
   * but use getProperty instead. XPConnect will do the type conversion automagically.
   *
   * These functions convert values in the same manner as the default
   * implementation of nsIVariant. Of particular note is that boolean variables
   * are converted to integers as in C/C++ (true is a non-zero value), so that
   * false will be converted to a string of "0" and not "false."
   *
   *
   * @param name             The case-sensitive name of the property to get.
   * @exception NS_ERROR_NOT_AVAILABLE if the named property does not exist.
   * @exception NS_ERROR_CANNOT_CONVERT_DATA if the property cannot be converted
   *                                         to the desired type.
   */
  AString getPropertyAsAString(in string name);
  AUTF8String getPropertyAsAUTF8String(in string name);
  unsigned long getPropertyAsUint32(in string name);

  /**
   * Returns a property for the given name.
   *
   * @param name             The case-sensitive name of the property to get.
   * @param defaultValue     The value to return if the property does not exist.
   */
  boolean getPropertyAsBool(in string name, in boolean defaultValue);

  /** @} */

  /**
   * Assigns the given to value to the property of the given name.
   *
   * Should the property exist, its value will be overwritten. An
   * implementation may impose additional semantic constraints for certain
   * properties. However, such constraints might not be checked by this method.
   *
   * @warning A value MUST be convertible to a string; if this convention is not
   * followed, consumers of cards may fail unpredictably or return incorrect
   * results.
   *
   * @param name             The case-sensitive name of the property to set.
   * @param value            The new value of the property.
   */
  void setProperty(in AUTF8String name, in nsIVariant value);

  /**
   * @{
   * Sets a property for the given name.  Javascript callers should NOT use these,
   * but use setProperty instead. XPConnect will do the type conversion automagically.
   *
   * These functions convert values in the same manner as the default
   * implementation of nsIVariant.
   */
  void setPropertyAsAString(in string name, in AString value);
  void setPropertyAsAUTF8String(in string name, in AUTF8String value);
  void setPropertyAsUint32(in string name, in unsigned long value);
  void setPropertyAsBool(in string name, in boolean value);

  /** @} */

  /**
   * Deletes the property with the given name.
   *
   * Some properties may not be deleted. However, the implementation will not
   * check this constraint at this method. If such a property is deleted, an
   * error may be thrown when the card is modified at the database level.
   *
   * @param name             The case-sensitive name of the property to set.
   */
  void deleteProperty(in AUTF8String name);

  /**
   * Whether this card supports vCard properties. Currently only AddrBookCard
   * supports vCard properties.
   */
  readonly attribute boolean supportsVCard;

  /**
   * A `VCardProperties` object for this card, or null. If `supportsVCard` is
   * true, this attribute MUST be a `VCardProperties` object, otherwise it
   * MUST be null.
   *
   * @see VCardProperties in VCardUtils.jsm
   */
  readonly attribute jsval vCardProperties;

  /**
   * @{
   * These properties are shorthand for getProperty and setProperty.
   */
  attribute AString firstName;
  attribute AString lastName;
  attribute AString displayName;
  attribute AString primaryEmail;
  /** @} */

  /**
   * All email addresses associated with this card, in order of preference.
   */
  readonly attribute Array<AString> emailAddresses;

  /**
   * Determines whether or not a card has the supplied email address in either
   * of its PrimaryEmail or SecondEmail attributes.
   *
   * Note: This function is likely to be temporary whilst we work out proper
   * APIs for multi-valued attributes in bug 118665.
   *
   * @param  aEmailAddress The email address to attempt to match against.
   * @return               True if aEmailAddress matches any of the email
   *                       addresses stored in the card.
   */
  boolean hasEmailAddress(in AUTF8String aEmailAddress);

  /**
   * A URL to a photo for this card, or an empty string if there isn't one.
   * This is probably a file: or data: URL but other schemes are possible.
   */
  readonly attribute AString photoURL;

  /**
   * Translates a card into a specific format.
   * The following types are supported:
   * - base64xml
   * - xml
   * - vcard
   *
   * @param  aType          The type of item to translate the card into.
   * @return                A string containing the translated card.
   * @exception NS_ERROR_ILLEGAL_VALUE if we do not recognize the type.
   */
  AUTF8String translateTo(in AUTF8String aType);

  /**
   * Translates a card from the specified format
   */
  //void translateFrom(in AUTF8String aType, in AUTF8String aData);

  /**
   * 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);

  /**
   * Generate a chat name from the card, containing the value of the
   * first non-empty chat field.
   *
   * @return                 A string containing the generated chat name.
   */
  AString generateChatName();

  /**
   * This function will copy all values from one card to another.
   *
   * @param  srcCard         The source card to copy values from.
   */
  void copy(in nsIAbCard aSrcCard);

  /**
   * Returns true if this card is equal to the other card.
   *
   * The default implementation defines equal as this card pointing to the
   * same object as @arg aCard; another implementation defines it as equality of
   * properties and values.
   *
   * @warning The exact nature of equality is still undefined, and actual
   *          results may not match theoretical results. Most notably, the code
   *          <tt>a.equals(b) == b.equals(a)</tt> might not return true. In
   *          particular, calling equals on cards from different address books
   *          may return inaccurate results.
   *
   *
   * @return                 Equality, as defined above.
   * @param  aCard           The card to compare against.
   */
  boolean equals(in nsIAbCard aCard);

  // PROPERTIES TO BE DELETED AS PART OF REWRITE

  attribute boolean isMailList;
  /**
   * If isMailList is true then mailListURI
   * will contain the URI of the associated
   * mail list
   */
  attribute string mailListURI;
};

%{C++
// A nice list of properties for the benefit of C++ clients
#define kUIDProperty                "UID"
#define kFirstNameProperty          "FirstName"
#define kLastNameProperty           "LastName"
#define kDisplayNameProperty        "DisplayName"
#define kNicknameProperty           "NickName"
#define kPriEmailProperty           "PrimaryEmail"
#define kLastModifiedDateProperty   "LastModifiedDate"
#define kPopularityIndexProperty    "PopularityIndex"

#define kPhoneticFirstNameProperty  "PhoneticFirstName"
#define kPhoneticLastNameProperty   "PhoneticLastName"
#define kSpouseNameProperty         "SpouseName"
#define kFamilyNameProperty         "FamilyName"
#define k2ndEmailProperty           "SecondEmail"

#define kHomeAddressProperty        "HomeAddress"
#define kHomeAddress2Property       "HomeAddress2"
#define kHomeCityProperty           "HomeCity"
#define kHomeStateProperty          "HomeState"
#define kHomeZipCodeProperty        "HomeZipCode"
#define kHomeCountryProperty        "HomeCountry"
#define kHomeWebPageProperty        "WebPage2"

#define kWorkAddressProperty        "WorkAddress"
#define kWorkAddress2Property       "WorkAddress2"
#define kWorkCityProperty           "WorkCity"
#define kWorkStateProperty          "WorkState"
#define kWorkZipCodeProperty        "WorkZipCode"
#define kWorkCountryProperty        "WorkCountry"
#define kWorkWebPageProperty        "WebPage1"

#define kHomePhoneProperty          "HomePhone"
#define kHomePhoneTypeProperty      "HomePhoneType"
#define kWorkPhoneProperty          "WorkPhone"
#define kWorkPhoneTypeProperty      "WorkPhoneType"
#define kFaxProperty                "FaxNumber"
#define kFaxTypeProperty            "FaxNumberType"
#define kPagerTypeProperty          "PagerNumberType"
#define kPagerProperty              "PagerNumber"
#define kCellularProperty           "CellularNumber"
#define kCellularTypeProperty       "CellularNumberType"

#define kJobTitleProperty           "JobTitle"
#define kDepartmentProperty         "Department"
#define kCompanyProperty            "Company"
#define kScreenNameProperty         "_AimScreenName"
#define kCustom1Property            "Custom1"
#define kCustom2Property            "Custom2"
#define kCustom3Property            "Custom3"
#define kCustom4Property            "Custom4"
#define kNotesProperty              "Notes"

#define kGtalkProperty              "_GoogleTalk"
#define kAIMProperty                "_AimScreenName"
#define kYahooProperty              "_Yahoo"
#define kSkypeProperty              "_Skype"
#define kQQProperty                 "_QQ"
#define kMSNProperty                "_MSN"
#define kICQProperty                "_ICQ"
#define kXMPPProperty               "_JabberId"
#define kIRCProperty                "_IRC"

#define kAnniversaryYearProperty    "AnniversaryYear"
#define kAnniversaryMonthProperty   "AnniversaryMonth"
#define kAnniversaryDayProperty     "AnniversaryDay"
#define kBirthYearProperty          "BirthYear"
#define kBirthMonthProperty         "BirthMonth"
#define kBirthDayProperty           "BirthDay"
%}