1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Seth Spitzer <sspitzer@netscape.com>
24 * Mark Banner <mark@standard8.demon.co.uk>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 #include "nsIAddrDBAnnouncer.idl"
41 #include "nsIAbCard.idl"
42 #include "nsIAbDirectory.idl"
43
44 interface nsIFile;
45 interface nsIMdbTableRowCursor;
46 interface nsIMdbEnv;
47 interface nsIMdbRow;
48 interface nsIArray;
49
50 %{C++
51 // this is the prefix we for attributes that are specific
52 // to the mozilla addressbook, and weren't in 4.x and aren't specified in
53 // RFC 2789. used when exporting and import LDIF
54 // see nsTextAddress.cpp, nsAddressBook.cpp
55 #define MOZ_AB_LDIF_PREFIX "mozilla"
56
57 // note, GeneratedName is not a real column
58 // if you change any of this, make sure to change
59 // Get / Set CardValue in nsAbCardProperty.cpp
60 #define kFirstNameColumn "FirstName"
61 #define kLastNameColumn "LastName"
62 #define kPhoneticFirstNameColumn "PhoneticFirstName"
63 #define kPhoneticLastNameColumn "PhoneticLastName"
64 #define kPhoneticNameColumn "_PhoneticName"
65 #define kDisplayNameColumn "DisplayName"
66 #define kNicknameColumn "NickName"
67 #define kPriEmailColumn "PrimaryEmail"
68 #define k2ndEmailColumn "SecondEmail"
69 #define kPreferMailFormatColumn "PreferMailFormat"
70 #define kPopularityIndexColumn "PopularityIndex"
71 #define kAllowRemoteContentColumn "AllowRemoteContent"
72 #define kWorkPhoneColumn "WorkPhone"
73 #define kHomePhoneColumn "HomePhone"
74 #define kFaxColumn "FaxNumber"
75 #define kPagerColumn "PagerNumber"
76 #define kCellularColumn "CellularNumber"
77 #define kWorkPhoneTypeColumn "WorkPhoneType"
78 #define kHomePhoneTypeColumn "HomePhoneType"
79 #define kFaxTypeColumn "FaxNumberType"
80 #define kPagerTypeColumn "PagerNumberType"
81 #define kCellularTypeColumn "CellularNumberType"
82 #define kHomeAddressColumn "HomeAddress"
83 #define kHomeAddress2Column "HomeAddress2"
84 #define kHomeCityColumn "HomeCity"
85 #define kHomeStateColumn "HomeState"
86 #define kHomeZipCodeColumn "HomeZipCode"
87 #define kHomeCountryColumn "HomeCountry"
88 #define kWorkAddressColumn "WorkAddress"
89 #define kWorkAddress2Column "WorkAddress2"
90 #define kWorkCityColumn "WorkCity"
91 #define kWorkStateColumn "WorkState"
92 #define kWorkZipCodeColumn "WorkZipCode"
93 #define kWorkCountryColumn "WorkCountry"
94 #define kJobTitleColumn "JobTitle"
95 #define kDepartmentColumn "Department"
96 #define kCompanyColumn "Company"
97 #define kAimScreenNameColumn "_AimScreenName"
98 #define kAnniversaryYearColumn "AnniversaryYear"
99 #define kAnniversaryMonthColumn "AnniversaryMonth"
100 #define kAnniversaryDayColumn "AnniversaryDay"
101 #define kSpouseNameColumn "SpouseName"
102 #define kFamilyNameColumn "FamilyName"
103 #define kDefaultAddressColumn "DefaultAddress"
104 #define kCategoryColumn "Category"
105 // webPage1 is work web page
106 #define kWebPage1Column "WebPage1"
107 // webPage2 is home web page
108 #define kWebPage2Column "WebPage2"
109 #define kBirthYearColumn "BirthYear"
110 #define kBirthMonthColumn "BirthMonth"
111 #define kBirthDayColumn "BirthDay"
112 #define kCustom1Column "Custom1"
113 #define kCustom2Column "Custom2"
114 #define kCustom3Column "Custom3"
115 #define kCustom4Column "Custom4"
116 #define kNotesColumn "Notes"
117 #define kLastModifiedDateColumn "LastModifiedDate"
118 #define kAddressCharSetColumn "AddrCharSet"
119 #define kMailListName "ListName"
120 #define kMailListNickName "ListNickName"
121 #define kMailListDescription "ListDescription"
122 #define kMailListTotalAddresses "ListTotalAddresses"
123 // not shown in the UI
124 #define kLowerPriEmailColumn "LowercasePrimaryEmail"
125
126 // Palm Integration
127 #define CARD_ATTRIB_PALMID "PalmRecId"
128 #define CARD_ATTRIB_DISPLAY "DisplayName"
129
130 %}
131
132 [scriptable, uuid(14d89995-e6c5-11d8-9a39-000a95dc234c)]
133 interface nsAddrDBCommitType
134 {
135 const long kSmallCommit = 0;
136 const long kLargeCommit = 1;
137 const long kSessionCommit = 2;
138 const long kCompressCommit = 3;
139 };
140
141 [scriptable, uuid(ae789049-8b41-492c-a210-8dc36a7e731f)]
142 interface nsIAddrDatabase : nsIAddrDBAnnouncer {
143
144 /**
145 * Path to the address book database that this instance represents.
146 */
147 attribute nsIFile dbPath;
148 nsIAddrDatabase open(in nsIFile dbFile, in boolean create, in boolean upgrading);
149
150 void close(in boolean forceCommit);
151
152 /**
153 * Open the MDB database synchronously creating it if required. If
154 * successful, this routine will set up the m_mdbStore and m_mdbEnv of the
155 * database object so other database calls can work.
156 *
157 * @param dbName The location of the database file
158 * to open.
159 * @param create If set to true, will create the
160 * database file if it does not
161 * already exist.
162 * @exception NS_ERROR_FILE_NOT_FOUND The file was not found at the
163 * specified location (and create was
164 * false).
165 * @exception NS_ERROR_FILE_ACCESS_DENIED The file could not be opened as
166 * access was denied.
167 */
168 void openMDB(in nsIFile dbName, in boolean create);
169 void closeMDB(in boolean commit);
170
171 void commit(in unsigned long commitType);
172 void forceClosed();
173
174 /**
175 * Create a new card and add to the database
176 *
177 * @param aNewCard the card to be added
178 * @param aNotify if set to true, all the listeners of the
179 * database will be notified.
180 * @param aParent parent directory or mailing list to which the
181 * card is added. If set to null, listeners of the
182 * database will not be notified of card creation.
183 */
184 void createNewCardAndAddToDB(in nsIAbCard aNewCard, in boolean aNotify, in nsIAbDirectory aParent);
185
186 void createNewListCardAndAddToDB(in nsIAbDirectory list, in unsigned long listRowID, in nsIAbCard newCard, in boolean aNotify);
187
188 /**
189 * Create a new mailing list and add to the database
190 *
191 * @param aNewList the mailing list to be added.
192 * @param aNotify if set to true, all the listeners of the
193 * database will be notified.
194 * @param aParent parent directory to which the mailing list
195 * is added. If set to null, listeners of the database
196 * will not be notified of mailing list creation.
197 */
198 void createMailListAndAddToDB(in nsIAbDirectory aNewList, in boolean aNotify, in nsIAbDirectory aParent);
199
200 /**
201 * Enumerate the cards in the directory. The enumerator will return the
202 * cards associated with mailing lists too.
203 *
204 * @param directory the directory of which to enumerate the cards.
205 * @return an enumerator.
206 */
207 nsISimpleEnumerator enumerateCards(in nsIAbDirectory directory);
208
209 /**
210 * Enumerate the cards associated with the mailing lists in the directory.
211 *
212 * @param directory the directory of which to enumerate the cards.
213 * @return an enumerator.
214 */
215 nsISimpleEnumerator enumerateListAddresses(in nsIAbDirectory directory);
216
217 void getMailingListsFromDB(in nsIAbDirectory parentDir);
218
219 /**
220 * Delete a card from the database.
221 *
222 * @param aCard the card to be deleted.
223 * @param aNotify if set to true, all the listeners of the
224 * database will be notified.
225 * @param aParent parent directory from which the card
226 * is to be deleted. If set to null, listeners of
227 * the database will not be notified of card deletion.
228 */
229 void deleteCard(in nsIAbCard aCard, in boolean aNotify, in nsIAbDirectory aParent);
230
231 /**
232 * Edit a card in the database.
233 *
234 * @param aCard the card to be edited.
235 * @param aNotify if set to true, all the listeners of the
236 * database will be notified.
237 * @param aParent parent directory in which the card
238 * is to be edited. If set to null, listeners of
239 * the database will not be notified of card entry
240 * change.
241 */
242 void editCard(in nsIAbCard aCard, in boolean aNotify, in nsIAbDirectory aParent);
243 boolean containsCard(in nsIAbCard card);
244 void deleteMailList(in nsIAbDirectory mailList, in boolean aNotify);
245 void editMailList(in nsIAbDirectory mailList, in nsIAbCard listCard, in boolean aNotify);
246 boolean containsMailList(in nsIAbDirectory mailList);
247 void deleteCardFromMailList(in nsIAbDirectory mailList, in nsIAbCard card, in boolean aNotify);
248
249 /**
250 * Gets the first card which matches the attribute/value pair supplied.
251 *
252 * @param aDirectory The current nsIAbDirectory associated with this
253 * instance of the database.
254 * @param aName The attribute to look up the value in.
255 * @param aUTF8Value The value to look up in UTF8 format.
256 * @param aCaseInsensitive Set to true for case-insenstive matching.
257 * @result Returns an nsIAbCard if one is found, otherwise
258 * NULL.
259 */
260 nsIAbCard getCardFromAttribute(in nsIAbDirectory aDirectory, in string aName,
261 in AUTF8String aUTF8Value,
262 in boolean aCaseInsensitive);
263
264 PRBool findMailListbyUnicodeName(in wstring listName);
265
266 void getCardCount(out PRUint32 count);
267
268 [noscript] readonly attribute nsIMdbRow newRow;
269 [noscript] readonly attribute nsIMdbRow newListRow;
270 [noscript] void addCardRowToDB(in nsIMdbRow newRow);
271 [noscript] void addLdifListMember(in nsIMdbRow row, in string value);
272 [noscript] void addFirstName(in nsIMdbRow row, in string value);
273 [noscript] void addLastName(in nsIMdbRow row, in string value);
274 [noscript] void addPhoneticFirstName(in nsIMdbRow row, in string value);
275 [noscript] void addPhoneticLastName(in nsIMdbRow row, in string value);
276 [noscript] void addDisplayName(in nsIMdbRow row, in string value);
277 [noscript] void addNickName(in nsIMdbRow row, in string value);
278 [noscript] void addPrimaryEmail(in nsIMdbRow row, in string value);
279 [noscript] void add2ndEmail(in nsIMdbRow row, in string value);
280 [noscript] void addWorkPhone(in nsIMdbRow row, in string value);
281 [noscript] void addHomePhone(in nsIMdbRow row, in string value);
282 [noscript] void addFaxNumber(in nsIMdbRow row, in string value);
283 [noscript] void addPagerNumber(in nsIMdbRow row, in string value);
284 [noscript] void addCellularNumber(in nsIMdbRow row, in string value);
285 [noscript] void addWorkPhoneType(in nsIMdbRow row, in string value);
286 [noscript] void addHomePhoneType(in nsIMdbRow row, in string value);
287 [noscript] void addFaxNumberType(in nsIMdbRow row, in string value);
288 [noscript] void addPagerNumberType(in nsIMdbRow row, in string value);
289 [noscript] void addCellularNumberType(in nsIMdbRow row, in string value);
290 [noscript] void addHomeAddress(in nsIMdbRow row, in string value);
291 [noscript] void addHomeAddress2(in nsIMdbRow row, in string value);
292 [noscript] void addHomeCity(in nsIMdbRow row, in string value);
293 [noscript] void addHomeState(in nsIMdbRow row, in string value);
294 [noscript] void addHomeZipCode(in nsIMdbRow row, in string value);
295 [noscript] void addHomeCountry(in nsIMdbRow row, in string value);
296 [noscript] void addWorkAddress(in nsIMdbRow row, in string value);
297 [noscript] void addWorkAddress2(in nsIMdbRow row, in string value);
298 [noscript] void addWorkCity(in nsIMdbRow row, in string value);
299 [noscript] void addWorkState(in nsIMdbRow row, in string value);
300 [noscript] void addWorkZipCode(in nsIMdbRow row, in string value);
301 [noscript] void addWorkCountry(in nsIMdbRow row, in string value);
302 [noscript] void addJobTitle(in nsIMdbRow row, in string value);
303 [noscript] void addDepartment(in nsIMdbRow row, in string value);
304 [noscript] void addCompany(in nsIMdbRow row, in string value);
305 [noscript] void addAimScreenName(in nsIMdbRow row, in string value);
306 [noscript] void addAnniversaryYear(in nsIMdbRow row, in string value);
307 [noscript] void addAnniversaryMonth(in nsIMdbRow row, in string value);
308 [noscript] void addAnniversaryDay(in nsIMdbRow row, in string value);
309 [noscript] void addSpouseName(in nsIMdbRow row, in string value);
310 [noscript] void addFamilyName(in nsIMdbRow row, in string value);
311 [noscript] void addDefaultAddress(in nsIMdbRow row, in string value);
312 [noscript] void addCategory(in nsIMdbRow row, in string value);
313 [noscript] void addWebPage1(in nsIMdbRow row, in string value);
314 [noscript] void addWebPage2(in nsIMdbRow row, in string value);
315 [noscript] void addBirthYear(in nsIMdbRow row, in string value);
316 [noscript] void addBirthMonth(in nsIMdbRow row, in string value);
317 [noscript] void addBirthDay(in nsIMdbRow row, in string value);
318 [noscript] void addCustom1(in nsIMdbRow row, in string value);
319 [noscript] void addCustom2(in nsIMdbRow row, in string value);
320 [noscript] void addCustom3(in nsIMdbRow row, in string value);
321 [noscript] void addCustom4(in nsIMdbRow row, in string value);
322 [noscript] void addNotes(in nsIMdbRow row, in string value);
323 [noscript] void addPreferMailFormat(in nsIMdbRow row, in unsigned long value);
324 [noscript] void addPopularityIndex(in nsIMdbRow row, in unsigned long value);
325 [noscript] void addAllowRemoteContent(in nsIMdbRow row, in boolean value);
326
327 [noscript] void addListName(in nsIMdbRow row, in string value);
328 [noscript] void addListNickName(in nsIMdbRow row, in string value);
329 [noscript] void addListDescription(in nsIMdbRow row, in string value);
330 [noscript] void addListDirNode(in nsIMdbRow listRow);
331
332 /**
333 * use for getting and setting generic string attributes
334 * like _AimScreenName
335 */
336 void setCardValue(in nsIAbCard card, in string name, in wstring value, in boolean notify);
337 wstring getCardValue(in nsIAbCard card, in string name);
338
339 /**
340 * Returns an array of the deleted cards currently stored in the mork file.
341 */
342 readonly attribute nsIArray deletedCardList;
343
344 /**
345 * Returns the count of the deleted card currently stored in the mork file.
346 */
347 readonly attribute unsigned long deletedCardCount;
348
349 /**
350 * Add the column representing the card to the mailing list row
351 * in the database.
352 *
353 * @param aPCard the card to be added.
354 * @param aPListRow the row to which the column will be added.
355 * @param aPos the position of the card in the mailing list.
356 * @param aPNewCard a pointer to hold the new card added to the row.
357 * @param aInMailingList If set to true, the card is already present
358 * in the mailing list
359 * @param aParent parent mailing list to which the card
360 * is added. If set to null, listeners of the
361 * database will not be notified of card creation.
362 */
363 void AddListCardColumnsToRow(in nsIAbCard aPCard,
364 in nsIMdbRow aPListRow,
365 in unsigned long aPos,
366 out nsIAbCard aPNewCard,
367 in boolean aInMailingList,
368 in nsIAbDirectory aParent);
369 void InitCardFromRow(in nsIAbCard aNewCard,in nsIMdbRow aCardRow);
370 void SetListAddressTotal(in nsIMdbRow aListRow, in PRUint32 aTotal);
371 nsIMdbRow FindRowByCard(in nsIAbCard aCard);
372 };