-rw-r--r-- | libopie/pim/ocontact.cpp | 1433 |
1 files changed, 1433 insertions, 0 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp new file mode 100644 index 0000000..66632f5 --- a/dev/null +++ b/libopie/pim/ocontact.cpp | |||
@@ -0,0 +1,1433 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #define QTOPIA_INTERNAL_CONTACT_MRE | ||
22 | |||
23 | #include "ocontact.h" | ||
24 | #include "vobject_p.h" | ||
25 | #include "qfiledirect_p.h" | ||
26 | |||
27 | #include <qpe/stringutil.h> | ||
28 | #include <qpe/timeconversion.h> | ||
29 | |||
30 | #include <qobject.h> | ||
31 | #include <qregexp.h> | ||
32 | #include <qstylesheet.h> | ||
33 | #include <qfileinfo.h> | ||
34 | #include <qmap.h> | ||
35 | |||
36 | #include <stdio.h> | ||
37 | |||
38 | /*! | ||
39 | \class Contact contact.h | ||
40 | \brief The Contact class holds the data of an address book entry. | ||
41 | |||
42 | This data includes information the name of the person, contact | ||
43 | information, and business information such as deparment and job title. | ||
44 | |||
45 | \ingroup qtopiaemb | ||
46 | \ingroup qtopiadesktop | ||
47 | */ | ||
48 | |||
49 | Qtopia::UidGen OContact::sUidGen( Qtopia::UidGen::Qtopia ); | ||
50 | |||
51 | /*! | ||
52 | Creates a new, empty contact. | ||
53 | */ | ||
54 | OContact::OContact() | ||
55 | : OPimRecord(), mMap(), d( 0 ) | ||
56 | { | ||
57 | } | ||
58 | |||
59 | /*! | ||
60 | \internal | ||
61 | Creates a new contact. The properties of the contact are | ||
62 | set from \a fromMap. | ||
63 | */ | ||
64 | OContact::OContact( const QMap<int, QString> &fromMap ) : | ||
65 | OPimRecord(), mMap( fromMap ), d( 0 ) | ||
66 | { | ||
67 | QString cats = mMap[ Qtopia::AddressCategory ]; | ||
68 | if ( !cats.isEmpty() ) | ||
69 | setCategories( idsFromString( cats ) ); | ||
70 | QString uidStr = find( Qtopia::AddressUid ); | ||
71 | |||
72 | if ( uidStr.isEmpty() ) | ||
73 | setUid( uidGen().generate() ); | ||
74 | else | ||
75 | setUid( uidStr.toInt() ); | ||
76 | |||
77 | if ( !uidStr.isEmpty() ) | ||
78 | setUid( uidStr.toInt() ); | ||
79 | } | ||
80 | |||
81 | /*! | ||
82 | Destroys a contact. | ||
83 | */ | ||
84 | OContact::~OContact() | ||
85 | { | ||
86 | } | ||
87 | |||
88 | /*! \fn void OContact::setTitle( const QString &str ) | ||
89 | Sets the title of the contact to \a str. | ||
90 | */ | ||
91 | |||
92 | /*! \fn void OContact::setFirstName( const QString &str ) | ||
93 | Sets the first name of the contact to \a str. | ||
94 | */ | ||
95 | |||
96 | /*! \fn void OContact::setMiddleName( const QString &str ) | ||
97 | Sets the middle name of the contact to \a str. | ||
98 | */ | ||
99 | |||
100 | /*! \fn void OContact::setLastName( const QString &str ) | ||
101 | Sets the last name of the contact to \a str. | ||
102 | */ | ||
103 | |||
104 | /*! \fn void OContact::setSuffix( const QString &str ) | ||
105 | Sets the suffix of the contact to \a str. | ||
106 | */ | ||
107 | |||
108 | /*! \fn void OContact::setFileAs( const QString &str ) | ||
109 | Sets the contact to filed as \a str. | ||
110 | */ | ||
111 | |||
112 | /*! \fn void OContact::setDefaultEmail( const QString &str ) | ||
113 | Sets the default email of the contact to \a str. | ||
114 | */ | ||
115 | |||
116 | /*! \fn void OContact::setHomeStreet( const QString &str ) | ||
117 | Sets the home street address of the contact to \a str. | ||
118 | */ | ||
119 | |||
120 | /*! \fn void OContact::setHomeCity( const QString &str ) | ||
121 | Sets the home city of the contact to \a str. | ||
122 | */ | ||
123 | |||
124 | /*! \fn void OContact::setHomeState( const QString &str ) | ||
125 | Sets the home state of the contact to \a str. | ||
126 | */ | ||
127 | |||
128 | /*! \fn void OContact::setHomeZip( const QString &str ) | ||
129 | Sets the home zip code of the contact to \a str. | ||
130 | */ | ||
131 | |||
132 | /*! \fn void OContact::setHomeCountry( const QString &str ) | ||
133 | Sets the home country of the contact to \a str. | ||
134 | */ | ||
135 | |||
136 | /*! \fn void OContact::setHomePhone( const QString &str ) | ||
137 | Sets the home phone number of the contact to \a str. | ||
138 | */ | ||
139 | |||
140 | /*! \fn void OContact::setHomeFax( const QString &str ) | ||
141 | Sets the home fax number of the contact to \a str. | ||
142 | */ | ||
143 | |||
144 | /*! \fn void OContact::setHomeMobile( const QString &str ) | ||
145 | Sets the home mobile phone number of the contact to \a str. | ||
146 | */ | ||
147 | |||
148 | /*! \fn void OContact::setHomeWebpage( const QString &str ) | ||
149 | Sets the home webpage of the contact to \a str. | ||
150 | */ | ||
151 | |||
152 | /*! \fn void OContact::setCompany( const QString &str ) | ||
153 | Sets the company for contact to \a str. | ||
154 | */ | ||
155 | |||
156 | /*! \fn void OContact::setJobTitle( const QString &str ) | ||
157 | Sets the job title of the contact to \a str. | ||
158 | */ | ||
159 | |||
160 | /*! \fn void OContact::setDepartment( const QString &str ) | ||
161 | Sets the department for contact to \a str. | ||
162 | */ | ||
163 | |||
164 | /*! \fn void OContact::setOffice( const QString &str ) | ||
165 | Sets the office for contact to \a str. | ||
166 | */ | ||
167 | |||
168 | /*! \fn void OContact::setBusinessStreet( const QString &str ) | ||
169 | Sets the business street address of the contact to \a str. | ||
170 | */ | ||
171 | |||
172 | /*! \fn void OContact::setBusinessCity( const QString &str ) | ||
173 | Sets the business city of the contact to \a str. | ||
174 | */ | ||
175 | |||
176 | /*! \fn void OContact::setBusinessState( const QString &str ) | ||
177 | Sets the business state of the contact to \a str. | ||
178 | */ | ||
179 | |||
180 | /*! \fn void OContact::setBusinessZip( const QString &str ) | ||
181 | Sets the business zip code of the contact to \a str. | ||
182 | */ | ||
183 | |||
184 | /*! \fn void OContact::setBusinessCountry( const QString &str ) | ||
185 | Sets the business country of the contact to \a str. | ||
186 | */ | ||
187 | |||
188 | /*! \fn void OContact::setBusinessPhone( const QString &str ) | ||
189 | Sets the business phone number of the contact to \a str. | ||
190 | */ | ||
191 | |||
192 | /*! \fn void OContact::setBusinessFax( const QString &str ) | ||
193 | Sets the business fax number of the contact to \a str. | ||
194 | */ | ||
195 | |||
196 | /*! \fn void OContact::setBusinessMobile( const QString &str ) | ||
197 | Sets the business mobile phone number of the contact to \a str. | ||
198 | */ | ||
199 | |||
200 | /*! \fn void OContact::setBusinessPager( const QString &str ) | ||
201 | Sets the business pager number of the contact to \a str. | ||
202 | */ | ||
203 | |||
204 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) | ||
205 | Sets the business webpage of the contact to \a str. | ||
206 | */ | ||
207 | |||
208 | /*! \fn void OContact::setProfession( const QString &str ) | ||
209 | Sets the profession of the contact to \a str. | ||
210 | */ | ||
211 | |||
212 | /*! \fn void OContact::setAssistant( const QString &str ) | ||
213 | Sets the assistant of the contact to \a str. | ||
214 | */ | ||
215 | |||
216 | /*! \fn void OContact::setManager( const QString &str ) | ||
217 | Sets the manager of the contact to \a str. | ||
218 | */ | ||
219 | |||
220 | /*! \fn void OContact::setSpouse( const QString &str ) | ||
221 | Sets the spouse of the contact to \a str. | ||
222 | */ | ||
223 | |||
224 | /*! \fn void OContact::setGender( const QString &str ) | ||
225 | Sets the gender of the contact to \a str. | ||
226 | */ | ||
227 | |||
228 | /*! \fn void OContact::setBirthday( const QString &str ) | ||
229 | Sets the birthday for the contact to \a str. | ||
230 | */ | ||
231 | |||
232 | /*! \fn void OContact::setAnniversary( const QString &str ) | ||
233 | Sets the anniversary of the contact to \a str. | ||
234 | */ | ||
235 | |||
236 | /*! \fn void OContact::setNickname( const QString &str ) | ||
237 | Sets the nickname of the contact to \a str. | ||
238 | */ | ||
239 | |||
240 | /*! \fn void OContact::setNotes( const QString &str ) | ||
241 | Sets the notes about the contact to \a str. | ||
242 | */ | ||
243 | |||
244 | /*! \fn QString OContact::title() const | ||
245 | Returns the title of the contact. | ||
246 | */ | ||
247 | |||
248 | /*! \fn QString OContact::firstName() const | ||
249 | Returns the first name of the contact. | ||
250 | */ | ||
251 | |||
252 | /*! \fn QString OContact::middleName() const | ||
253 | Returns the middle name of the contact. | ||
254 | */ | ||
255 | |||
256 | /*! \fn QString OContact::lastName() const | ||
257 | Returns the last name of the contact. | ||
258 | */ | ||
259 | |||
260 | /*! \fn QString OContact::suffix() const | ||
261 | Returns the suffix of the contact. | ||
262 | */ | ||
263 | |||
264 | /*! \fn QString OContact::fileAs() const | ||
265 | Returns the string the contact is filed as. | ||
266 | */ | ||
267 | |||
268 | /*! \fn QString OContact::defaultEmail() const | ||
269 | Returns the default email address of the contact. | ||
270 | */ | ||
271 | |||
272 | /*! \fn QString OContact::emails() const | ||
273 | Returns the list of email address for a contact separated by ';'s in a single | ||
274 | string. | ||
275 | */ | ||
276 | |||
277 | /*! \fn QString OContact::homeStreet() const | ||
278 | Returns the home street address of the contact. | ||
279 | */ | ||
280 | |||
281 | /*! \fn QString OContact::homeCity() const | ||
282 | Returns the home city of the contact. | ||
283 | */ | ||
284 | |||
285 | /*! \fn QString OContact::homeState() const | ||
286 | Returns the home state of the contact. | ||
287 | */ | ||
288 | |||
289 | /*! \fn QString OContact::homeZip() const | ||
290 | Returns the home zip of the contact. | ||
291 | */ | ||
292 | |||
293 | /*! \fn QString OContact::homeCountry() const | ||
294 | Returns the home country of the contact. | ||
295 | */ | ||
296 | |||
297 | /*! \fn QString OContact::homePhone() const | ||
298 | Returns the home phone number of the contact. | ||
299 | */ | ||
300 | |||
301 | /*! \fn QString OContact::homeFax() const | ||
302 | Returns the home fax number of the contact. | ||
303 | */ | ||
304 | |||
305 | /*! \fn QString OContact::homeMobile() const | ||
306 | Returns the home mobile number of the contact. | ||
307 | */ | ||
308 | |||
309 | /*! \fn QString OContact::homeWebpage() const | ||
310 | Returns the home webpage of the contact. | ||
311 | */ | ||
312 | |||
313 | /*! \fn QString OContact::company() const | ||
314 | Returns the company for the contact. | ||
315 | */ | ||
316 | |||
317 | /*! \fn QString OContact::department() const | ||
318 | Returns the department for the contact. | ||
319 | */ | ||
320 | |||
321 | /*! \fn QString OContact::office() const | ||
322 | Returns the office for the contact. | ||
323 | */ | ||
324 | |||
325 | /*! \fn QString OContact::jobTitle() const | ||
326 | Returns the job title of the contact. | ||
327 | */ | ||
328 | |||
329 | /*! \fn QString OContact::profession() const | ||
330 | Returns the profession of the contact. | ||
331 | */ | ||
332 | |||
333 | /*! \fn QString OContact::assistant() const | ||
334 | Returns the assistant of the contact. | ||
335 | */ | ||
336 | |||
337 | /*! \fn QString OContact::manager() const | ||
338 | Returns the manager of the contact. | ||
339 | */ | ||
340 | |||
341 | /*! \fn QString OContact::businessStreet() const | ||
342 | Returns the business street address of the contact. | ||
343 | */ | ||
344 | |||
345 | /*! \fn QString OContact::businessCity() const | ||
346 | Returns the business city of the contact. | ||
347 | */ | ||
348 | |||
349 | /*! \fn QString OContact::businessState() const | ||
350 | Returns the business state of the contact. | ||
351 | */ | ||
352 | |||
353 | /*! \fn QString OContact::businessZip() const | ||
354 | Returns the business zip of the contact. | ||
355 | */ | ||
356 | |||
357 | /*! \fn QString OContact::businessCountry() const | ||
358 | Returns the business country of the contact. | ||
359 | */ | ||
360 | |||
361 | /*! \fn QString OContact::businessPhone() const | ||
362 | Returns the business phone number of the contact. | ||
363 | */ | ||
364 | |||
365 | /*! \fn QString OContact::businessFax() const | ||
366 | Returns the business fax number of the contact. | ||
367 | */ | ||
368 | |||
369 | /*! \fn QString OContact::businessMobile() const | ||
370 | Returns the business mobile number of the contact. | ||
371 | */ | ||
372 | |||
373 | /*! \fn QString OContact::businessPager() const | ||
374 | Returns the business pager number of the contact. | ||
375 | */ | ||
376 | |||
377 | /*! \fn QString OContact::businessWebpage() const | ||
378 | Returns the business webpage of the contact. | ||
379 | */ | ||
380 | |||
381 | /*! \fn QString OContact::spouse() const | ||
382 | Returns the spouse of the contact. | ||
383 | */ | ||
384 | |||
385 | /*! \fn QString OContact::gender() const | ||
386 | Returns the gender of the contact. | ||
387 | */ | ||
388 | |||
389 | /*! \fn QString OContact::birthday() const | ||
390 | Returns the birthday of the contact. | ||
391 | */ | ||
392 | |||
393 | /*! \fn QString OContact::anniversary() const | ||
394 | Returns the anniversary of the contact. | ||
395 | */ | ||
396 | |||
397 | /*! \fn QString OContact::nickname() const | ||
398 | Returns the nickname of the contact. | ||
399 | */ | ||
400 | |||
401 | /*! \fn QString OContact::children() const | ||
402 | Returns the children of the contact. | ||
403 | */ | ||
404 | |||
405 | /*! \fn QString OContact::notes() const | ||
406 | Returns the notes relating to the the contact. | ||
407 | */ | ||
408 | |||
409 | /*! \fn QString OContact::groups() const | ||
410 | \internal | ||
411 | Returns the groups for the contact. | ||
412 | */ | ||
413 | |||
414 | /*! \fn QStringList OContact::groupList() const | ||
415 | \internal | ||
416 | */ | ||
417 | |||
418 | /*! \fn QString OContact::field(int) const | ||
419 | \internal | ||
420 | */ | ||
421 | |||
422 | /*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) | ||
423 | \internal | ||
424 | */ | ||
425 | |||
426 | /*! \fn void OContact::setUid( int id ) | ||
427 | \internal | ||
428 | Sets the uid for this record to \a id. | ||
429 | */ | ||
430 | |||
431 | /*! \enum OContact::journal_action | ||
432 | \internal | ||
433 | */ | ||
434 | |||
435 | /*! | ||
436 | \internal | ||
437 | */ | ||
438 | QMap<int, QString> OContact::toMap() const | ||
439 | { | ||
440 | QMap<int, QString> map = mMap; | ||
441 | QString cats = idsToString( categories() ); | ||
442 | if ( !cats.isEmpty() ) | ||
443 | map.insert( Qtopia::AddressCategory, cats ); | ||
444 | return map; | ||
445 | } | ||
446 | |||
447 | /*! | ||
448 | Returns a rich text formatted QString representing the contents the contact. | ||
449 | */ | ||
450 | QString OContact::toRichText() const | ||
451 | { | ||
452 | QString text; | ||
453 | QString value, comp, state; | ||
454 | |||
455 | // name, jobtitle and company | ||
456 | if ( !(value = fullName()).isEmpty() ) | ||
457 | text += "<b>" + Qtopia::escapeString(value) + "</b><br>"; | ||
458 | if ( !(value = jobTitle()).isEmpty() ) | ||
459 | text += Qtopia::escapeString(value) + "<br>"; | ||
460 | |||
461 | comp = company(); | ||
462 | if ( !(value = department()).isEmpty() ) { | ||
463 | text += Qtopia::escapeString(value); | ||
464 | if ( comp ) | ||
465 | text += ", "; | ||
466 | else | ||
467 | text += "<br>"; | ||
468 | } | ||
469 | if ( !comp.isEmpty() ) | ||
470 | text += Qtopia::escapeString(comp) + "<br>"; | ||
471 | |||
472 | // business address | ||
473 | if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || | ||
474 | !businessZip().isEmpty() || !businessCountry().isEmpty() ) { | ||
475 | text += "<br>"; | ||
476 | text += QObject::tr( "<b>Work Address:</b>" ); | ||
477 | text += "<br>"; | ||
478 | } | ||
479 | |||
480 | if ( !(value = businessStreet()).isEmpty() ) | ||
481 | text += Qtopia::escapeString(value) + "<br>"; | ||
482 | state = businessState(); | ||
483 | if ( !(value = businessCity()).isEmpty() ) { | ||
484 | text += Qtopia::escapeString(value); | ||
485 | if ( state ) | ||
486 | text += ", " + Qtopia::escapeString(state); | ||
487 | text += "<br>"; | ||
488 | } else if ( !state.isEmpty() ) | ||
489 | text += Qtopia::escapeString(state) + "<br>"; | ||
490 | if ( !(value = businessZip()).isEmpty() ) | ||
491 | text += Qtopia::escapeString(value) + "<br>"; | ||
492 | if ( !(value = businessCountry()).isEmpty() ) | ||
493 | text += Qtopia::escapeString(value) + "<br>"; | ||
494 | |||
495 | // home address | ||
496 | if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || | ||
497 | !homeZip().isEmpty() || !homeCountry().isEmpty() ) { | ||
498 | text += "<br>"; | ||
499 | text += QObject::tr( "<b>Home Address:</b>" ); | ||
500 | text += "<br>"; | ||
501 | } | ||
502 | |||
503 | if ( !(value = homeStreet()).isEmpty() ) | ||
504 | text += Qtopia::escapeString(value) + "<br>"; | ||
505 | state = homeState(); | ||
506 | if ( !(value = homeCity()).isEmpty() ) { | ||
507 | text += Qtopia::escapeString(value); | ||
508 | if ( !state.isEmpty() ) | ||
509 | text += ", " + Qtopia::escapeString(state); | ||
510 | text += "<br>"; | ||
511 | } else if (!state.isEmpty()) | ||
512 | text += Qtopia::escapeString(state) + "<br>"; | ||
513 | if ( !(value = homeZip()).isEmpty() ) | ||
514 | text += Qtopia::escapeString(value) + "<br>"; | ||
515 | if ( !(value = homeCountry()).isEmpty() ) | ||
516 | text += Qtopia::escapeString(value) + "<br>"; | ||
517 | |||
518 | // the others... | ||
519 | QString str; | ||
520 | str = emails(); | ||
521 | if ( !str.isEmpty() ) | ||
522 | text += "<b>" + QObject::tr("Email Addresses: ") + "</b>" | ||
523 | + Qtopia::escapeString(str) + "<br>"; | ||
524 | str = homePhone(); | ||
525 | if ( !str.isEmpty() ) | ||
526 | text += "<b>" + QObject::tr("Home Phone: ") + "</b>" | ||
527 | + Qtopia::escapeString(str) + "<br>"; | ||
528 | str = homeFax(); | ||
529 | if ( !str.isEmpty() ) | ||
530 | text += "<b>" + QObject::tr("Home Fax: ") + "</b>" | ||
531 | + Qtopia::escapeString(str) + "<br>"; | ||
532 | str = homeMobile(); | ||
533 | if ( !str.isEmpty() ) | ||
534 | text += "<b>" + QObject::tr("Home Mobile: ") + "</b>" | ||
535 | + Qtopia::escapeString(str) + "<br>"; | ||
536 | str = homeWebpage(); | ||
537 | if ( !str.isEmpty() ) | ||
538 | text += "<b>" + QObject::tr("Home Web Page: ") + "</b>" | ||
539 | + Qtopia::escapeString(str) + "<br>"; | ||
540 | str = businessWebpage(); | ||
541 | if ( !str.isEmpty() ) | ||
542 | text += "<b>" + QObject::tr("Business Web Page: ") + "</b>" | ||
543 | + Qtopia::escapeString(str) + "<br>"; | ||
544 | str = office(); | ||
545 | if ( !str.isEmpty() ) | ||
546 | text += "<b>" + QObject::tr("Office: ") + "</b>" | ||
547 | + Qtopia::escapeString(str) + "<br>"; | ||
548 | str = businessPhone(); | ||
549 | if ( !str.isEmpty() ) | ||
550 | text += "<b>" + QObject::tr("Business Phone: ") + "</b>" | ||
551 | + Qtopia::escapeString(str) + "<br>"; | ||
552 | str = businessFax(); | ||
553 | if ( !str.isEmpty() ) | ||
554 | text += "<b>" + QObject::tr("Business Fax: ") + "</b>" | ||
555 | + Qtopia::escapeString(str) + "<br>"; | ||
556 | str = businessMobile(); | ||
557 | if ( !str.isEmpty() ) | ||
558 | text += "<b>" + QObject::tr("Business Mobile: ") + "</b>" | ||
559 | + Qtopia::escapeString(str) + "<br>"; | ||
560 | str = businessPager(); | ||
561 | if ( !str.isEmpty() ) | ||
562 | text += "<b>" + QObject::tr("Business Pager: ") + "</b>" | ||
563 | + Qtopia::escapeString(str) + "<br>"; | ||
564 | str = profession(); | ||
565 | if ( !str.isEmpty() ) | ||
566 | text += "<b>" + QObject::tr("Profession: ") + "</b>" | ||
567 | + Qtopia::escapeString(str) + "<br>"; | ||
568 | str = assistant(); | ||
569 | if ( !str.isEmpty() ) | ||
570 | text += "<b>" + QObject::tr("Assistant: ") + "</b>" | ||
571 | + Qtopia::escapeString(str) + "<br>"; | ||
572 | str = manager(); | ||
573 | if ( !str.isEmpty() ) | ||
574 | text += "<b>" + QObject::tr("Manager: ") + "</b>" | ||
575 | + Qtopia::escapeString(str) + "<br>"; | ||
576 | str = gender(); | ||
577 | if ( !str.isEmpty() && str.toInt() != 0 ) { | ||
578 | if ( str.toInt() == 1 ) | ||
579 | str = QObject::tr( "Male" ); | ||
580 | else if ( str.toInt() == 2 ) | ||
581 | str = QObject::tr( "Female" ); | ||
582 | text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; | ||
583 | } | ||
584 | str = spouse(); | ||
585 | if ( !str.isEmpty() ) | ||
586 | text += "<b>" + QObject::tr("Spouse: ") + "</b>" | ||
587 | + Qtopia::escapeString(str) + "<br>"; | ||
588 | str = birthday(); | ||
589 | if ( !str.isEmpty() ) | ||
590 | text += "<b>" + QObject::tr("Birthday: ") + "</b>" | ||
591 | + Qtopia::escapeString(str) + "<br>"; | ||
592 | str = anniversary(); | ||
593 | if ( !str.isEmpty() ) | ||
594 | text += "<b>" + QObject::tr("Anniversary: ") + "</b>" | ||
595 | + Qtopia::escapeString(str) + "<br>"; | ||
596 | str = nickname(); | ||
597 | if ( !str.isEmpty() ) | ||
598 | text += "<b>" + QObject::tr("Nickname: ") + "</b>" | ||
599 | + Qtopia::escapeString(str) + "<br>"; | ||
600 | |||
601 | // notes last | ||
602 | if ( (value = notes()) ) { | ||
603 | QRegExp reg("\n"); | ||
604 | |||
605 | //QString tmp = Qtopia::escapeString(value); | ||
606 | QString tmp = QStyleSheet::convertFromPlainText(value); | ||
607 | //tmp.replace( reg, "<br>" ); | ||
608 | text += "<br>" + tmp + "<br>"; | ||
609 | } | ||
610 | return text; | ||
611 | } | ||
612 | |||
613 | /*! | ||
614 | \internal | ||
615 | */ | ||
616 | void OContact::insert( int key, const QString &v ) | ||
617 | { | ||
618 | QString value = v.stripWhiteSpace(); | ||
619 | if ( value.isEmpty() ) | ||
620 | mMap.remove( key ); | ||
621 | else | ||
622 | mMap.insert( key, value ); | ||
623 | } | ||
624 | |||
625 | /*! | ||
626 | \internal | ||
627 | */ | ||
628 | void OContact::replace( int key, const QString & v ) | ||
629 | { | ||
630 | QString value = v.stripWhiteSpace(); | ||
631 | if ( value.isEmpty() ) | ||
632 | mMap.remove( key ); | ||
633 | else | ||
634 | mMap.replace( key, value ); | ||
635 | } | ||
636 | |||
637 | /*! | ||
638 | \internal | ||
639 | */ | ||
640 | QString OContact::find( int key ) const | ||
641 | { | ||
642 | return mMap[key]; | ||
643 | } | ||
644 | |||
645 | /*! | ||
646 | \internal | ||
647 | */ | ||
648 | QString OContact::displayAddress( const QString &street, | ||
649 | const QString &city, | ||
650 | const QString &state, | ||
651 | const QString &zip, | ||
652 | const QString &country ) const | ||
653 | { | ||
654 | QString s = street; | ||
655 | if ( !street.isEmpty() ) | ||
656 | s+= "\n"; | ||
657 | s += city; | ||
658 | if ( !city.isEmpty() && !state.isEmpty() ) | ||
659 | s += ", "; | ||
660 | s += state; | ||
661 | if ( !state.isEmpty() && !zip.isEmpty() ) | ||
662 | s += " "; | ||
663 | s += zip; | ||
664 | if ( !country.isEmpty() && !s.isEmpty() ) | ||
665 | s += "\n"; | ||
666 | s += country; | ||
667 | return s; | ||
668 | } | ||
669 | |||
670 | /*! | ||
671 | \internal | ||
672 | */ | ||
673 | QString OContact::displayBusinessAddress() const | ||
674 | { | ||
675 | return displayAddress( businessStreet(), businessCity(), | ||
676 | businessState(), businessZip(), | ||
677 | businessCountry() ); | ||
678 | } | ||
679 | |||
680 | /*! | ||
681 | \internal | ||
682 | */ | ||
683 | QString OContact::displayHomeAddress() const | ||
684 | { | ||
685 | return displayAddress( homeStreet(), homeCity(), | ||
686 | homeState(), homeZip(), | ||
687 | homeCountry() ); | ||
688 | } | ||
689 | |||
690 | /*! | ||
691 | Returns the full name of the contact | ||
692 | */ | ||
693 | QString OContact::fullName() const | ||
694 | { | ||
695 | QString title = find( Qtopia::Title ); | ||
696 | QString firstName = find( Qtopia::FirstName ); | ||
697 | QString middleName = find( Qtopia::MiddleName ); | ||
698 | QString lastName = find( Qtopia::LastName ); | ||
699 | QString suffix = find( Qtopia::Suffix ); | ||
700 | |||
701 | QString name = title; | ||
702 | if ( !firstName.isEmpty() ) { | ||
703 | if ( !name.isEmpty() ) | ||
704 | name += " "; | ||
705 | name += firstName; | ||
706 | } | ||
707 | if ( !middleName.isEmpty() ) { | ||
708 | if ( !name.isEmpty() ) | ||
709 | name += " "; | ||
710 | name += middleName; | ||
711 | } | ||
712 | if ( !lastName.isEmpty() ) { | ||
713 | if ( !name.isEmpty() ) | ||
714 | name += " "; | ||
715 | name += lastName; | ||
716 | } | ||
717 | if ( !suffix.isEmpty() ) { | ||
718 | if ( !name.isEmpty() ) | ||
719 | name += " "; | ||
720 | name += suffix; | ||
721 | } | ||
722 | return name.simplifyWhiteSpace(); | ||
723 | } | ||
724 | |||
725 | /*! | ||
726 | Returns a list of the names of the children of the contact. | ||
727 | */ | ||
728 | QStringList OContact::childrenList() const | ||
729 | { | ||
730 | return QStringList::split( " ", find( Qtopia::Children ) ); | ||
731 | } | ||
732 | |||
733 | /*! \fn void OContact::insertEmail( const QString &email ) | ||
734 | |||
735 | Insert \a email into the email list. Ensures \a email can only be added | ||
736 | once. If there is no default email address set, it sets it to the \a email. | ||
737 | */ | ||
738 | |||
739 | /*! \fn void OContact::removeEmail( const QString &email ) | ||
740 | |||
741 | Removes the \a email from the email list. If the default email was \a email, | ||
742 | then the default email address is assigned to the first email in the | ||
743 | email list | ||
744 | */ | ||
745 | |||
746 | /*! \fn void OContact::clearEmails() | ||
747 | |||
748 | Clears the email list. | ||
749 | */ | ||
750 | |||
751 | /*! \fn void OContact::insertEmails( const QStringList &emailList ) | ||
752 | |||
753 | Appends the \a emailList to the exiting email list | ||
754 | */ | ||
755 | |||
756 | /*! | ||
757 | Returns a list of email addresses belonging to the contact, including | ||
758 | the default email address. | ||
759 | */ | ||
760 | QStringList OContact::emailList() const | ||
761 | { | ||
762 | QString emailStr = emails(); | ||
763 | |||
764 | QStringList r; | ||
765 | if ( !emailStr.isEmpty() ) { | ||
766 | qDebug(" emailstr "); | ||
767 | QStringList l = QStringList::split( emailSeparator(), emailStr ); | ||
768 | for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) | ||
769 | r += (*it).simplifyWhiteSpace(); | ||
770 | } | ||
771 | |||
772 | return r; | ||
773 | } | ||
774 | |||
775 | /*! | ||
776 | \overload | ||
777 | |||
778 | Generates the string for the contact to be filed as from the first, | ||
779 | middle and last name of the contact. | ||
780 | */ | ||
781 | void OContact::setFileAs() | ||
782 | { | ||
783 | QString lastName, firstName, middleName, fileas; | ||
784 | |||
785 | lastName = find( Qtopia::LastName ); | ||
786 | firstName = find( Qtopia::FirstName ); | ||
787 | middleName = find( Qtopia::MiddleName ); | ||
788 | if ( !lastName.isEmpty() && !firstName.isEmpty() | ||
789 | && !middleName.isEmpty() ) | ||
790 | fileas = lastName + ", " + firstName + " " + middleName; | ||
791 | else if ( !lastName.isEmpty() && !firstName.isEmpty() ) | ||
792 | fileas = lastName + ", " + firstName; | ||
793 | else if ( !lastName.isEmpty() || !firstName.isEmpty() || | ||
794 | !middleName.isEmpty() ) | ||
795 | fileas = firstName + ( firstName.isEmpty() ? "" : " " ) | ||
796 | + middleName + ( middleName.isEmpty() ? "" : " " ) | ||
797 | + lastName; | ||
798 | |||
799 | replace( Qtopia::FileAs, fileas ); | ||
800 | } | ||
801 | |||
802 | /*! | ||
803 | \internal | ||
804 | Appends the contact information to \a buf. | ||
805 | */ | ||
806 | void OContact::save( QString &buf ) const | ||
807 | { | ||
808 | static const QStringList SLFIELDS = fields(); | ||
809 | // I'm expecting "<Contact " in front of this... | ||
810 | for ( QMap<int, QString>::ConstIterator it = mMap.begin(); | ||
811 | it != mMap.end(); ++it ) { | ||
812 | const QString &value = it.data(); | ||
813 | int key = it.key(); | ||
814 | if ( !value.isEmpty() ) { | ||
815 | if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) | ||
816 | continue; | ||
817 | |||
818 | key -= Qtopia::AddressCategory+1; | ||
819 | buf += SLFIELDS[key]; | ||
820 | buf += "=\"" + Qtopia::escapeString(value) + "\" "; | ||
821 | } | ||
822 | } | ||
823 | buf += customToXml(); | ||
824 | if ( categories().count() > 0 ) | ||
825 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; | ||
826 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; | ||
827 | // You need to close this yourself | ||
828 | } | ||
829 | |||
830 | /*! | ||
831 | \internal | ||
832 | Returns the list of fields belonging to a contact | ||
833 | */ | ||
834 | QStringList OContact::fields() | ||
835 | { | ||
836 | QStringList list; | ||
837 | |||
838 | list.append( "Title" ); // Not Used! | ||
839 | list.append( "FirstName" ); | ||
840 | list.append( "MiddleName" ); | ||
841 | list.append( "LastName" ); | ||
842 | list.append( "Suffix" ); | ||
843 | list.append( "FileAs" ); | ||
844 | |||
845 | list.append( "JobTitle" ); | ||
846 | list.append( "Department" ); | ||
847 | list.append( "Company" ); | ||
848 | list.append( "BusinessPhone" ); | ||
849 | list.append( "BusinessFax" ); | ||
850 | list.append( "BusinessMobile" ); | ||
851 | |||
852 | list.append( "DefaultEmail" ); | ||
853 | list.append( "Emails" ); | ||
854 | |||
855 | list.append( "HomePhone" ); | ||
856 | list.append( "HomeFax" ); | ||
857 | list.append( "HomeMobile" ); | ||
858 | |||
859 | list.append( "BusinessStreet" ); | ||
860 | list.append( "BusinessCity" ); | ||
861 | list.append( "BusinessState" ); | ||
862 | list.append( "BusinessZip" ); | ||
863 | list.append( "BusinessCountry" ); | ||
864 | list.append( "BusinessPager" ); | ||
865 | list.append( "BusinessWebPage" ); | ||
866 | |||
867 | list.append( "Office" ); | ||
868 | list.append( "Profession" ); | ||
869 | list.append( "Assistant" ); | ||
870 | list.append( "Manager" ); | ||
871 | |||
872 | list.append( "HomeStreet" ); | ||
873 | list.append( "HomeCity" ); | ||
874 | list.append( "HomeState" ); | ||
875 | list.append( "HomeZip" ); | ||
876 | list.append( "HomeCountry" ); | ||
877 | list.append( "HomeWebPage" ); | ||
878 | |||
879 | list.append( "Spouse" ); | ||
880 | list.append( "Gender" ); | ||
881 | list.append( "Birthday" ); | ||
882 | list.append( "Anniversary" ); | ||
883 | list.append( "Nickname" ); | ||
884 | list.append( "Children" ); | ||
885 | |||
886 | list.append( "Notes" ); | ||
887 | list.append( "Groups" ); | ||
888 | |||
889 | return list; | ||
890 | } | ||
891 | |||
892 | /*! | ||
893 | \internal | ||
894 | Returns a translated list of field names for a contact. | ||
895 | */ | ||
896 | QStringList OContact::trfields() | ||
897 | { | ||
898 | QStringList list; | ||
899 | |||
900 | list.append( QObject::tr( "Name Title") ); | ||
901 | list.append( QObject::tr( "First Name" ) ); | ||
902 | list.append( QObject::tr( "Middle Name" ) ); | ||
903 | list.append( QObject::tr( "Last Name" ) ); | ||
904 | list.append( QObject::tr( "Suffix" ) ); | ||
905 | list.append( QObject::tr( "File As" ) ); | ||
906 | |||
907 | list.append( QObject::tr( "Job Title" ) ); | ||
908 | list.append( QObject::tr( "Department" ) ); | ||
909 | list.append( QObject::tr( "Company" ) ); | ||
910 | list.append( QObject::tr( "Business Phone" ) ); | ||
911 | list.append( QObject::tr( "Business Fax" ) ); | ||
912 | list.append( QObject::tr( "Business Mobile" ) ); | ||
913 | |||
914 | list.append( QObject::tr( "Default Email" ) ); | ||
915 | list.append( QObject::tr( "Emails" ) ); | ||
916 | |||
917 | list.append( QObject::tr( "Home Phone" ) ); | ||
918 | list.append( QObject::tr( "Home Fax" ) ); | ||
919 | list.append( QObject::tr( "Home Mobile" ) ); | ||
920 | |||
921 | list.append( QObject::tr( "Business Street" ) ); | ||
922 | list.append( QObject::tr( "Business City" ) ); | ||
923 | list.append( QObject::tr( "Business State" ) ); | ||
924 | list.append( QObject::tr( "Business Zip" ) ); | ||
925 | list.append( QObject::tr( "Business Country" ) ); | ||
926 | list.append( QObject::tr( "Business Pager" ) ); | ||
927 | list.append( QObject::tr( "Business WebPage" ) ); | ||
928 | |||
929 | list.append( QObject::tr( "Office" ) ); | ||
930 | list.append( QObject::tr( "Profession" ) ); | ||
931 | list.append( QObject::tr( "Assistant" ) ); | ||
932 | list.append( QObject::tr( "Manager" ) ); | ||
933 | |||
934 | list.append( QObject::tr( "Home Street" ) ); | ||
935 | list.append( QObject::tr( "Home City" ) ); | ||
936 | list.append( QObject::tr( "Home State" ) ); | ||
937 | list.append( QObject::tr( "Home Zip" ) ); | ||
938 | list.append( QObject::tr( "Home Country" ) ); | ||
939 | list.append( QObject::tr( "Home Web Page" ) ); | ||
940 | |||
941 | list.append( QObject::tr( "Spouse" ) ); | ||
942 | list.append( QObject::tr( "Gender" ) ); | ||
943 | list.append( QObject::tr( "Birthday" ) ); | ||
944 | list.append( QObject::tr( "Anniversary" ) ); | ||
945 | list.append( QObject::tr( "Nickname" ) ); | ||
946 | list.append( QObject::tr( "Children" ) ); | ||
947 | |||
948 | list.append( QObject::tr( "Notes" ) ); | ||
949 | list.append( QObject::tr( "Groups" ) ); | ||
950 | |||
951 | return list; | ||
952 | } | ||
953 | |||
954 | /*! | ||
955 | Sets the list of email address for contact to those contained in \a str. | ||
956 | Email address should be separated by ';'s. | ||
957 | */ | ||
958 | void OContact::setEmails( const QString &str ) | ||
959 | { | ||
960 | replace( Qtopia::Emails, str ); | ||
961 | if ( str.isEmpty() ) | ||
962 | setDefaultEmail( QString::null ); | ||
963 | } | ||
964 | |||
965 | /*! | ||
966 | Sets the list of children for the contact to those contained in \a str. | ||
967 | */ | ||
968 | void OContact::setChildren( const QString &str ) | ||
969 | { | ||
970 | replace( Qtopia::Children, str ); | ||
971 | } | ||
972 | |||
973 | // vcard conversion code | ||
974 | /*! | ||
975 | \internal | ||
976 | */ | ||
977 | static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) | ||
978 | { | ||
979 | VObject *ret = 0; | ||
980 | if ( o && !value.isEmpty() ) | ||
981 | ret = addPropValue( o, prop, value.latin1() ); | ||
982 | return ret; | ||
983 | } | ||
984 | |||
985 | /*! | ||
986 | \internal | ||
987 | */ | ||
988 | static inline VObject *safeAddProp( VObject *o, const char *prop) | ||
989 | { | ||
990 | VObject *ret = 0; | ||
991 | if ( o ) | ||
992 | ret = addProp( o, prop ); | ||
993 | return ret; | ||
994 | } | ||
995 | |||
996 | /*! | ||
997 | \internal | ||
998 | */ | ||
999 | static VObject *createVObject( const OContact &c ) | ||
1000 | { | ||
1001 | VObject *vcard = newVObject( VCCardProp ); | ||
1002 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | ||
1003 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | ||
1004 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | ||
1005 | |||
1006 | // full name | ||
1007 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | ||
1008 | |||
1009 | // name properties | ||
1010 | VObject *name = safeAddProp( vcard, VCNameProp ); | ||
1011 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | ||
1012 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | ||
1013 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | ||
1014 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | ||
1015 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | ||
1016 | |||
1017 | // home properties | ||
1018 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | ||
1019 | safeAddProp( home_adr, VCHomeProp ); | ||
1020 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | ||
1021 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | ||
1022 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); | ||
1023 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); | ||
1024 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); | ||
1025 | |||
1026 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); | ||
1027 | safeAddProp( home_phone, VCHomeProp ); | ||
1028 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); | ||
1029 | safeAddProp( home_phone, VCHomeProp ); | ||
1030 | safeAddProp( home_phone, VCCellularProp ); | ||
1031 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); | ||
1032 | safeAddProp( home_phone, VCHomeProp ); | ||
1033 | safeAddProp( home_phone, VCFaxProp ); | ||
1034 | |||
1035 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); | ||
1036 | safeAddProp( url, VCHomeProp ); | ||
1037 | |||
1038 | // work properties | ||
1039 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); | ||
1040 | safeAddProp( work_adr, VCWorkProp ); | ||
1041 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); | ||
1042 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); | ||
1043 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); | ||
1044 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); | ||
1045 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | ||
1046 | |||
1047 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | ||
1048 | safeAddProp( work_phone, VCWorkProp ); | ||
1049 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | ||
1050 | safeAddProp( work_phone, VCWorkProp ); | ||
1051 | safeAddProp( work_phone, VCCellularProp ); | ||
1052 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | ||
1053 | safeAddProp( work_phone, VCWorkProp ); | ||
1054 | safeAddProp( work_phone, VCFaxProp ); | ||
1055 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | ||
1056 | safeAddProp( work_phone, VCWorkProp ); | ||
1057 | safeAddProp( work_phone, VCPagerProp ); | ||
1058 | |||
1059 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | ||
1060 | safeAddProp( url, VCWorkProp ); | ||
1061 | |||
1062 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | ||
1063 | safeAddProp( title, VCWorkProp ); | ||
1064 | |||
1065 | |||
1066 | QStringList emails = c.emailList(); | ||
1067 | emails.prepend( c.defaultEmail() ); | ||
1068 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | ||
1069 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | ||
1070 | safeAddProp( email, VCInternetProp ); | ||
1071 | } | ||
1072 | |||
1073 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | ||
1074 | |||
1075 | safeAddPropValue( vcard, VCBirthDateProp, c.birthday() ); | ||
1076 | |||
1077 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | ||
1078 | VObject *org = safeAddProp( vcard, VCOrgProp ); | ||
1079 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | ||
1080 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | ||
1081 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | ||
1082 | } | ||
1083 | |||
1084 | // some values we have to export as custom fields | ||
1085 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | ||
1086 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | ||
1087 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | ||
1088 | |||
1089 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | ||
1090 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | ||
1091 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", c.anniversary() ); | ||
1092 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | ||
1093 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | ||
1094 | |||
1095 | return vcard; | ||
1096 | } | ||
1097 | |||
1098 | |||
1099 | /*! | ||
1100 | \internal | ||
1101 | */ | ||
1102 | static OContact parseVObject( VObject *obj ) | ||
1103 | { | ||
1104 | OContact c; | ||
1105 | |||
1106 | VObjectIterator it; | ||
1107 | initPropIterator( &it, obj ); | ||
1108 | while( moreIteration( &it ) ) { | ||
1109 | VObject *o = nextVObject( &it ); | ||
1110 | QCString name = vObjectName( o ); | ||
1111 | QCString value = vObjectStringZValue( o ); | ||
1112 | if ( name == VCNameProp ) { | ||
1113 | VObjectIterator nit; | ||
1114 | initPropIterator( &nit, o ); | ||
1115 | while( moreIteration( &nit ) ) { | ||
1116 | VObject *o = nextVObject( &nit ); | ||
1117 | QCString name = vObjectTypeInfo( o ); | ||
1118 | QString value = vObjectStringZValue( o ); | ||
1119 | if ( name == VCNamePrefixesProp ) | ||
1120 | c.setTitle( value ); | ||
1121 | else if ( name == VCNameSuffixesProp ) | ||
1122 | c.setSuffix( value ); | ||
1123 | else if ( name == VCFamilyNameProp ) | ||
1124 | c.setLastName( value ); | ||
1125 | else if ( name == VCGivenNameProp ) | ||
1126 | c.setFirstName( value ); | ||
1127 | else if ( name == VCAdditionalNamesProp ) | ||
1128 | c.setMiddleName( value ); | ||
1129 | } | ||
1130 | } | ||
1131 | else if ( name == VCAdrProp ) { | ||
1132 | bool work = TRUE; // default address is work address | ||
1133 | QString street; | ||
1134 | QString city; | ||
1135 | QString region; | ||
1136 | QString postal; | ||
1137 | QString country; | ||
1138 | |||
1139 | VObjectIterator nit; | ||
1140 | initPropIterator( &nit, o ); | ||
1141 | while( moreIteration( &nit ) ) { | ||
1142 | VObject *o = nextVObject( &nit ); | ||
1143 | QCString name = vObjectName( o ); | ||
1144 | QString value = vObjectStringZValue( o ); | ||
1145 | if ( name == VCHomeProp ) | ||
1146 | work = FALSE; | ||
1147 | else if ( name == VCWorkProp ) | ||
1148 | work = TRUE; | ||
1149 | else if ( name == VCStreetAddressProp ) | ||
1150 | street = value; | ||
1151 | else if ( name == VCCityProp ) | ||
1152 | city = value; | ||
1153 | else if ( name == VCRegionProp ) | ||
1154 | region = value; | ||
1155 | else if ( name == VCPostalCodeProp ) | ||
1156 | postal = value; | ||
1157 | else if ( name == VCCountryNameProp ) | ||
1158 | country = value; | ||
1159 | } | ||
1160 | if ( work ) { | ||
1161 | c.setBusinessStreet( street ); | ||
1162 | c.setBusinessCity( city ); | ||
1163 | c.setBusinessCountry( country ); | ||
1164 | c.setBusinessZip( postal ); | ||
1165 | c.setBusinessState( region ); | ||
1166 | } else { | ||
1167 | c.setHomeStreet( street ); | ||
1168 | c.setHomeCity( city ); | ||
1169 | c.setHomeCountry( country ); | ||
1170 | c.setHomeZip( postal ); | ||
1171 | c.setHomeState( region ); | ||
1172 | } | ||
1173 | } | ||
1174 | else if ( name == VCTelephoneProp ) { | ||
1175 | enum { | ||
1176 | HOME = 0x01, | ||
1177 | WORK = 0x02, | ||
1178 | VOICE = 0x04, | ||
1179 | CELL = 0x08, | ||
1180 | FAX = 0x10, | ||
1181 | PAGER = 0x20, | ||
1182 | UNKNOWN = 0x80 | ||
1183 | }; | ||
1184 | int type = 0; | ||
1185 | |||
1186 | VObjectIterator nit; | ||
1187 | initPropIterator( &nit, o ); | ||
1188 | while( moreIteration( &nit ) ) { | ||
1189 | VObject *o = nextVObject( &nit ); | ||
1190 | QCString name = vObjectTypeInfo( o ); | ||
1191 | if ( name == VCHomeProp ) | ||
1192 | type |= HOME; | ||
1193 | else if ( name == VCWorkProp ) | ||
1194 | type |= WORK; | ||
1195 | else if ( name == VCVoiceProp ) | ||
1196 | type |= VOICE; | ||
1197 | else if ( name == VCCellularProp ) | ||
1198 | type |= CELL; | ||
1199 | else if ( name == VCFaxProp ) | ||
1200 | type |= FAX; | ||
1201 | else if ( name == VCPagerProp ) | ||
1202 | type |= PAGER; | ||
1203 | else if ( name == VCPreferredProp ) | ||
1204 | ; | ||
1205 | else | ||
1206 | type |= UNKNOWN; | ||
1207 | } | ||
1208 | if ( (type & UNKNOWN) != UNKNOWN ) { | ||
1209 | if ( ( type & (HOME|WORK) ) == 0 ) // default | ||
1210 | type |= HOME; | ||
1211 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | ||
1212 | type |= VOICE; | ||
1213 | |||
1214 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) | ||
1215 | c.setHomePhone( value ); | ||
1216 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | ||
1217 | c.setHomeFax( value ); | ||
1218 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | ||
1219 | c.setHomeMobile( value ); | ||
1220 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) | ||
1221 | c.setBusinessPhone( value ); | ||
1222 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | ||
1223 | c.setBusinessFax( value ); | ||
1224 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | ||
1225 | c.setBusinessMobile( value ); | ||
1226 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | ||
1227 | c.setBusinessPager( value ); | ||
1228 | } | ||
1229 | } | ||
1230 | else if ( name == VCEmailAddressProp ) { | ||
1231 | QString email = vObjectStringZValue( o ); | ||
1232 | bool valid = TRUE; | ||
1233 | VObjectIterator nit; | ||
1234 | initPropIterator( &nit, o ); | ||
1235 | while( moreIteration( &nit ) ) { | ||
1236 | VObject *o = nextVObject( &nit ); | ||
1237 | QCString name = vObjectTypeInfo( o ); | ||
1238 | if ( name != VCInternetProp && name != VCHomeProp && | ||
1239 | name != VCWorkProp && | ||
1240 | name != VCPreferredProp ) | ||
1241 | // ### preffered should map to default email | ||
1242 | valid = FALSE; | ||
1243 | } | ||
1244 | if ( valid ) { | ||
1245 | c.insertEmail( email ); | ||
1246 | } | ||
1247 | } | ||
1248 | else if ( name == VCURLProp ) { | ||
1249 | VObjectIterator nit; | ||
1250 | initPropIterator( &nit, o ); | ||
1251 | while( moreIteration( &nit ) ) { | ||
1252 | VObject *o = nextVObject( &nit ); | ||
1253 | QCString name = vObjectTypeInfo( o ); | ||
1254 | if ( name == VCHomeProp ) | ||
1255 | c.setHomeWebpage( value ); | ||
1256 | else if ( name == VCWorkProp ) | ||
1257 | c.setBusinessWebpage( value ); | ||
1258 | } | ||
1259 | } | ||
1260 | else if ( name == VCOrgProp ) { | ||
1261 | VObjectIterator nit; | ||
1262 | initPropIterator( &nit, o ); | ||
1263 | while( moreIteration( &nit ) ) { | ||
1264 | VObject *o = nextVObject( &nit ); | ||
1265 | QCString name = vObjectName( o ); | ||
1266 | QString value = vObjectStringZValue( o ); | ||
1267 | if ( name == VCOrgNameProp ) | ||
1268 | c.setCompany( value ); | ||
1269 | else if ( name == VCOrgUnitProp ) | ||
1270 | c.setDepartment( value ); | ||
1271 | else if ( name == VCOrgUnit2Prop ) | ||
1272 | c.setOffice( value ); | ||
1273 | } | ||
1274 | } | ||
1275 | else if ( name == VCTitleProp ) { | ||
1276 | c.setJobTitle( value ); | ||
1277 | } | ||
1278 | else if ( name == "X-Qtopia-Profession" ) { | ||
1279 | c.setProfession( value ); | ||
1280 | } | ||
1281 | else if ( name == "X-Qtopia-Manager" ) { | ||
1282 | c.setManager( value ); | ||
1283 | } | ||
1284 | else if ( name == "X-Qtopia-Assistant" ) { | ||
1285 | c.setAssistant( value ); | ||
1286 | } | ||
1287 | else if ( name == "X-Qtopia-Spouse" ) { | ||
1288 | c.setSpouse( value ); | ||
1289 | } | ||
1290 | else if ( name == "X-Qtopia-Gender" ) { | ||
1291 | c.setGender( value ); | ||
1292 | } | ||
1293 | else if ( name == "X-Qtopia-Anniversary" ) { | ||
1294 | c.setAnniversary( value ); | ||
1295 | } | ||
1296 | else if ( name == "X-Qtopia-Nickname" ) { | ||
1297 | c.setNickname( value ); | ||
1298 | } | ||
1299 | else if ( name == "X-Qtopia-Children" ) { | ||
1300 | c.setChildren( value ); | ||
1301 | } | ||
1302 | |||
1303 | |||
1304 | #if 0 | ||
1305 | else { | ||
1306 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | ||
1307 | VObjectIterator nit; | ||
1308 | initPropIterator( &nit, o ); | ||
1309 | while( moreIteration( &nit ) ) { | ||
1310 | VObject *o = nextVObject( &nit ); | ||
1311 | QCString name = vObjectName( o ); | ||
1312 | QString value = vObjectStringZValue( o ); | ||
1313 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | ||
1314 | } | ||
1315 | } | ||
1316 | #endif | ||
1317 | } | ||
1318 | c.setFileAs(); | ||
1319 | return c; | ||
1320 | } | ||
1321 | |||
1322 | /*! | ||
1323 | Writes the list of \a contacts as a set of VCards to the file \a filename. | ||
1324 | */ | ||
1325 | void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) | ||
1326 | { | ||
1327 | QFileDirect f( filename.utf8().data() ); | ||
1328 | if ( !f.open( IO_WriteOnly ) ) { | ||
1329 | qWarning("Unable to open vcard write"); | ||
1330 | return; | ||
1331 | } | ||
1332 | |||
1333 | QValueList<OContact>::ConstIterator it; | ||
1334 | for( it = contacts.begin(); it != contacts.end(); ++it ) { | ||
1335 | VObject *obj = createVObject( *it ); | ||
1336 | writeVObject(f.directHandle() , obj ); | ||
1337 | cleanVObject( obj ); | ||
1338 | } | ||
1339 | cleanStrTbl(); | ||
1340 | } | ||
1341 | |||
1342 | /*! | ||
1343 | writes \a contact as a VCard to the file \a filename. | ||
1344 | */ | ||
1345 | void OContact::writeVCard( const QString &filename, const OContact &contact) | ||
1346 | { | ||
1347 | QFileDirect f( filename.utf8().data() ); | ||
1348 | if ( !f.open( IO_WriteOnly ) ) { | ||
1349 | qWarning("Unable to open vcard write"); | ||
1350 | return; | ||
1351 | } | ||
1352 | |||
1353 | VObject *obj = createVObject( contact ); | ||
1354 | writeVObject( f.directHandle() , obj ); | ||
1355 | cleanVObject( obj ); | ||
1356 | |||
1357 | cleanStrTbl(); | ||
1358 | } | ||
1359 | |||
1360 | /*! | ||
1361 | Returns the set of contacts read as VCards from the file \a filename. | ||
1362 | */ | ||
1363 | QValueList<OContact> OContact::readVCard( const QString &filename ) | ||
1364 | { | ||
1365 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); | ||
1366 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); | ||
1367 | |||
1368 | qDebug("vobject = %p", obj ); | ||
1369 | |||
1370 | QValueList<OContact> contacts; | ||
1371 | |||
1372 | while ( obj ) { | ||
1373 | contacts.append( parseVObject( obj ) ); | ||
1374 | |||
1375 | VObject *t = obj; | ||
1376 | obj = nextVObjectInList(obj); | ||
1377 | cleanVObject( t ); | ||
1378 | } | ||
1379 | |||
1380 | return contacts; | ||
1381 | } | ||
1382 | |||
1383 | /*! | ||
1384 | Returns TRUE if the contact matches the regular expression \a regexp. | ||
1385 | Otherwise returns FALSE. | ||
1386 | */ | ||
1387 | bool OContact::match( const QString ®exp ) const | ||
1388 | { | ||
1389 | return match(QRegExp(regexp)); | ||
1390 | } | ||
1391 | |||
1392 | /*! | ||
1393 | \overload | ||
1394 | Returns TRUE if the contact matches the regular expression \a regexp. | ||
1395 | Otherwise returns FALSE. | ||
1396 | */ | ||
1397 | bool OContact::match( const QRegExp &r ) const | ||
1398 | { | ||
1399 | bool match; | ||
1400 | match = false; | ||
1401 | QMap<int, QString>::ConstIterator it; | ||
1402 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | ||
1403 | if ( (*it).find( r ) > -1 ) { | ||
1404 | match = true; | ||
1405 | break; | ||
1406 | } | ||
1407 | } | ||
1408 | return match; | ||
1409 | } | ||
1410 | |||
1411 | |||
1412 | // Noch nicht definiert ! :SX | ||
1413 | QString OContact::toShortText() const | ||
1414 | { | ||
1415 | return ( QString::fromLatin1( "Not defined!") ); | ||
1416 | } | ||
1417 | QString OContact::type() const | ||
1418 | { | ||
1419 | return QString::fromLatin1( "OContact" ); | ||
1420 | } | ||
1421 | |||
1422 | // Noch nicht definiert ! :SX | ||
1423 | QMap<QString,QString> OContact::toExtraMap() const | ||
1424 | { | ||
1425 | QMap <QString,QString> useless; | ||
1426 | return useless; | ||
1427 | } | ||
1428 | |||
1429 | // Noch nicht definiert ! :SX | ||
1430 | class QString OContact::recordField(int) const | ||
1431 | { | ||
1432 | return QString::fromLatin1( "Noch nicht implementiert !" ); | ||
1433 | } | ||