2 * Funambol is a mobile platform developed by Funambol, Inc.
3 * Copyright (C) 2003 - 2007 Funambol, Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by
7 * the Free Software Foundation with the addition of the following permission
8 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
10 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program; if not, see http://www.gnu.org/licenses or write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
23 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License
30 * version 3, these Appropriate Legal Notices must retain the display of the
31 * "Powered by Funambol" logo. If the display of the logo is not reasonably
32 * feasible for technical reasons, the Appropriate Legal Notices must display
33 * the words "Powered by Funambol".
37 #include "base/fscapi.h"
38 #include "base/util/utils.h"
39 #include "vocl/vCard/Contact.h"
40 #include "base/globalsdef.h"
47 businessDetail = NULL;
48 personalDetail = NULL;
50 setVersion(TEXT("2.1"));
51 setProdID(TEXT("VCARD"));
56 delete name; name = NULL;
59 delete notes; notes = NULL;
62 delete businessDetail; businessDetail = NULL;
65 delete personalDetail; personalDetail = NULL;
70 * Returns the UID of this contact
72 * @return the uid of this contact or NULL if not specified
74 WCHAR* Contact::getUID(WCHAR* buf, int size) {
76 if(!containsProperty(TEXT("UID")))
80 return (getProperty(TEXT("UID"))->getValue());
84 wcsncpy(buf, getProperty(TEXT("UID"))->getValue(), size);
86 wcscpy(buf, getProperty(TEXT("UID"))->getValue());
92 WCHAR* Contact::getTimezone (WCHAR* buf, int size) {
94 if(!containsProperty(TEXT("TZ")))
98 return (getProperty(TEXT("TZ"))->getValue());
102 wcsncpy(buf, getProperty(TEXT("TZ"))->getValue(), size);
104 wcscpy(buf, getProperty(TEXT("TZ"))->getValue());
110 ArrayList* Contact::getNotes() {
112 for(int i = 0; i<propertiesCount();i++) {
113 if(!wcscmp(getProperty(i)->getName(), TEXT("NOTE")))
114 if(getProperty(i)->getValue()) {
115 vCardProperty *property = getPropertyFromVProperty(getProperty(i));
116 Note* note = new Note();
117 note->setProperty(*property);
118 if(getProperty(i)->containsParameter(TEXT("TYPE")))
119 note->setType(getProperty(i)->getParameterValue(TEXT("TYPE")));
121 notes = new ArrayList();
122 notes->add((ArrayElement&)*note);
130 void Contact::setNotes(ArrayList& list) {
135 notes = new ArrayList();
141 for(i = 0, m = propertiesCount();i < m;i++) {
142 if(!wcscmp(getProperty(i)->getName(), TEXT("NOTE"))) {
150 for (i=0; i<s; ++i) {
151 notes->add(*list[i]);
153 note = (Note*)list[i];
154 if(note->getProperty()) {
155 vp = getVPropertyFromProperty(TEXT("NOTE"), note->getProperty());
157 vp->addParameter(TEXT("TYPE"), note->getType());
163 WCHAR* Contact::getRevision (WCHAR* buf, int size) {
164 if(!containsProperty(TEXT("REV")))
168 return (getProperty(TEXT("REV"))->getValue());
172 wcsncpy(buf, getProperty(TEXT("REV"))->getValue(), size);
174 wcscpy(buf, getProperty(TEXT("REV"))->getValue());
180 Name* Contact::getName () {
182 if(containsProperty(TEXT("N")) && getProperty(TEXT("N"))->getValue()) {
183 VProperty* vp = getProperty(TEXT("N"));
186 if(vp->getPropComponent(4)) {
187 vCardProperty *salutation = getPropertyFromVProperty(vp);
188 salutation->setValue(vp->getPropComponent(4));
189 name->setSalutation(*salutation);
193 if(vp->getPropComponent(2)) {
194 vCardProperty *firstName = getPropertyFromVProperty(vp);
195 firstName->setValue(vp->getPropComponent(2));
196 name->setFirstName(*firstName);
200 if(vp->getPropComponent(3)) {
201 vCardProperty *middleName = getPropertyFromVProperty(vp);
202 middleName->setValue(vp->getPropComponent(3));
203 name->setMiddleName(*middleName);
207 if(vp->getPropComponent(1)) {
208 vCardProperty *lastName = getPropertyFromVProperty(vp);
209 lastName->setValue(vp->getPropComponent(1));
210 name->setLastName(*lastName);
214 if(vp->getPropComponent(5)) {
215 vCardProperty *suffix = getPropertyFromVProperty(vp);
216 suffix->setValue(vp->getPropComponent(5));
217 name->setSuffix(*suffix);
223 if(containsProperty(TEXT("FN")) && getProperty(TEXT("FN"))->getValue()) {
227 VProperty* vp = getProperty(TEXT("FN"));
228 vCardProperty *displayName = getPropertyFromVProperty(vp);
229 name->setDisplayName(*displayName);
234 if(containsProperty(TEXT("NICKNAME")) && getProperty(TEXT("NICKNAME"))->getValue()) {
238 VProperty* vp = getProperty(TEXT("NICKNAME"));
239 vCardProperty *nickName = getPropertyFromVProperty(vp);
240 name->setNickname(*nickName);
248 void Contact::setName(Name& n) {
249 if (name) delete name;
253 if (containsProperty(TEXT("N")))
254 removeProperty(TEXT("N"));
255 if (containsProperty(TEXT("FN")))
256 removeProperty(TEXT("FN"));
257 if (containsProperty(TEXT("NICKNAME")))
258 removeProperty(TEXT("NICKNAME"));
261 WCHAR *nameProp = new WCHAR[MAX_VPROPERTY_VALUE + 1];
262 wcscpy(nameProp,TEXT(""));
263 if(name->getLastName())
264 wcscat(nameProp,name->getLastName()->getValue());
265 wcscat(nameProp,TEXT(";"));
267 if(name->getFirstName())
268 wcscat(nameProp,name->getFirstName()->getValue());
269 wcscat(nameProp,TEXT(";"));
271 if(name->getMiddleName())
272 wcscat(nameProp,name->getMiddleName()->getValue());
273 wcscat(nameProp,TEXT(";"));
275 if(name->getSalutation())
276 wcscat(nameProp,name->getSalutation()->getValue());
277 wcscat(nameProp,TEXT(";"));
279 if(name->getSuffix())
280 wcscat(nameProp,name->getSuffix()->getValue());
282 VProperty* vpName = new VProperty(TEXT("N"), nameProp);
283 if(name->getFirstName()) {
284 if(name->getFirstName()->getCharset())
285 vpName->addParameter(TEXT("CHARSET"), name->getFirstName()->getCharset());
286 if(name->getFirstName()->getEncoding())
287 vpName->addParameter(TEXT("ENCODING"), name->getFirstName()->getEncoding());
288 if(name->getFirstName()->getLanguage())
289 vpName->addParameter(TEXT("LANGUAGE"), name->getFirstName()->getLanguage());
291 insertProperty(vpName);
293 if(name->getDisplayName()) {
294 VProperty* vpDisplayName = getVPropertyFromProperty(TEXT("FN"), name->getDisplayName());
295 insertProperty(vpDisplayName);
297 if(name->getNickname()) {
298 VProperty* vpNickName = getVPropertyFromProperty(TEXT("NICKNAME"), name->getNickname());
299 insertProperty(vpNickName);
304 BusinessDetail* Contact::getBusinessDetail () {
305 if(!businessDetail) {
306 WCHAR* titles[MAX_TITLES];
308 ArrayList* phones = NULL;
309 ArrayList* emails = NULL;
310 ArrayList* webPages = NULL;
311 ContactDetail* contactDetail = NULL;
314 for(int i = 0; i<propertiesCount();i++) {
315 if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && getProperty(i)->isType(TEXT("WORK")))
316 if(getProperty(i)->getValue()) {
317 adr = composeAddress(getProperty(i), BUSINESS);
319 businessDetail = new BusinessDetail();
321 businessDetail->setAddress(*adr);
325 if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && getProperty(i)->isType(TEXT("WORK")))
326 if(getProperty(i)->getValue()) {
327 adr = addLabelAddress(getProperty(i), BUSINESS);
330 businessDetail = new BusinessDetail();
332 businessDetail->setAddress(*adr);
336 if(!wcscmp(getProperty(i)->getName(), TEXT("ROLE")))
337 if(getProperty(i)->getValue()) {
338 vCardProperty *prop = getPropertyFromVProperty(getProperty(i));
340 businessDetail = new BusinessDetail();
341 businessDetail->setRole(*prop);
345 if(!wcscmp(getProperty(i)->getName(), TEXT("TITLE")))
346 if(getProperty(i)->getValue()) {
347 titles[titlesIndex] = new WCHAR[MAX_VPROPERTY_VALUE + 1];
348 wcscpy(titles[titlesIndex], getProperty(i)->getValue());
352 if(!wcscmp(getProperty(i)->getName(), TEXT("ORG")))
353 if(getProperty(i)->getValue()) {
354 vCardProperty *prop = getPropertyFromVProperty(getProperty(i));
356 businessDetail = new BusinessDetail();
357 businessDetail->setCompany(*prop);
361 if(!wcscmp(getProperty(i)->getName(), TEXT("LOGO")))
362 if(getProperty(i)->getValue()) {
363 vCardProperty *prop = getPropertyFromVProperty(getProperty(i));
365 businessDetail = new BusinessDetail();
366 businessDetail->setLogo(*prop);
370 if(!wcscmp(getProperty(i)->getName(), TEXT("TEL")))
371 if(getProperty(i)->isType(TEXT("WORK"))) {
372 if(getProperty(i)->isType(TEXT("CELL"))) {
373 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
374 Phone* phone = new Phone();
375 phone->setPhoneNumber(*prop);
376 phone->setType(TEXT("MobileBusinessTelephoneNumber"));
378 phones = new ArrayList();
379 phones->add((ArrayElement&) *phone);
383 if(getProperty(i)->isType(TEXT("VOICE"))) {
384 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
385 Phone* phone = new Phone();
386 phone->setPhoneNumber(*prop);
387 phone->setType(TEXT("BusinessTelephoneNumber"));
389 phones = new ArrayList();
390 phones->add((ArrayElement&) *phone);
394 if(getProperty(i)->isType(TEXT("FAX"))) {
395 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
396 Phone* phone = new Phone();
397 phone->setPhoneNumber(*prop);
398 phone->setType(TEXT("BusinessFaxNumber"));
400 phones = new ArrayList();
401 phones->add((ArrayElement&) *phone);
405 if(!wcscmp(getProperty(i)->getName(), TEXT("EMAIL")))
406 if(getProperty(i)->containsParameter(TEXT("WORK")) && getProperty(i)->isType(TEXT("INTERNET"))) {
407 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
408 Email* email = new Email();
409 email->setEmailAddress(*prop);
410 email->setType(TEXT("Email3Address"));
412 emails = new ArrayList();
413 emails->add((ArrayElement&) *email);
416 if(!wcscmp(getProperty(i)->getName(), TEXT("URL")))
417 if(getProperty(i)->containsParameter(TEXT("WORK"))) {
418 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
419 WebPage* url = new WebPage();
420 url->setWebPage(*prop);
421 url->setType(TEXT("BusinessWebPage"));
423 webPages = new ArrayList();
424 webPages->add((ArrayElement&) *url);
430 businessDetail = new BusinessDetail();
431 businessDetail->setTitles(titles, titlesIndex);
436 contactDetail = new ContactDetail();
437 contactDetail->setPhones(*phones);
442 contactDetail = new ContactDetail();
443 contactDetail->setEmails(*emails);
448 contactDetail = new ContactDetail();
449 contactDetail->setWebPages(*webPages);
454 businessDetail = new BusinessDetail();
455 businessDetail->setContactDetail(*contactDetail);
456 delete contactDetail;
459 return businessDetail;
462 void Contact::setBusinessDetail(BusinessDetail& d) {
463 if (businessDetail) delete businessDetail;
465 businessDetail = d.clone();
467 for(int i = 0, m = propertiesCount(); i < m;i++) {
468 if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && getProperty(i)->isType(TEXT("WORK"))) {
473 if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && getProperty(i)->isType(TEXT("WORK"))) {
478 if(!wcscmp(getProperty(i)->getName(), TEXT("ROLE"))) {
483 if(!wcscmp(getProperty(i)->getName(), TEXT("TITLE"))) {
488 if(!wcscmp(getProperty(i)->getName(), TEXT("ORG"))) {
493 if(!wcscmp(getProperty(i)->getName(), TEXT("LOGO"))) {
498 if(!wcscmp(getProperty(i)->getName(), TEXT("TEL")) && getProperty(i)->isType(TEXT("WORK"))) {
503 if(!wcscmp(getProperty(i)->getName(), TEXT("EMAIL")) && getProperty(i)->containsParameter(TEXT("WORK"))
504 && getProperty(i)->isType(TEXT("INTERNET"))) {
509 if(!wcscmp(getProperty(i)->getName(), TEXT("URL")) && getProperty(i)->containsParameter(TEXT("WORK"))) {
517 if(businessDetail->getAddress()) {
518 VProperty* vp = composeVAddress(businessDetail->getAddress());
519 vp->addParameter(TEXT("TYPE"), TEXT("WORK"));
522 if(businessDetail->getAddress()->getLabel()) {
523 VProperty* vp = getVPropertyFromProperty(TEXT("LABEL"),businessDetail->getAddress()->getLabel());
524 vp->addParameter(TEXT("TYPE"), TEXT("WORK"));
528 if(businessDetail->getContactDetail()) {
529 if(businessDetail->getContactDetail()->getEmails()) {
530 ArrayList* emails = businessDetail->getContactDetail()->getEmails();
531 for (int i=0; i<emails->size(); ++i) {
532 if(((Email*) emails->get(i))->getProperty()) {
533 VProperty* vp = getVPropertyFromProperty(TEXT("EMAIL"), ((Email*)emails->get(i))->getProperty());
534 vp->addParameter(TEXT("WORK"), NULL);
535 vp->addParameter(TEXT("TYPE"),TEXT("INTERNET"));
540 if(businessDetail->getContactDetail()->getWebPages()) {
541 ArrayList* webs = businessDetail->getContactDetail()->getWebPages();
542 for (int i=0; i<webs->size(); ++i) {
543 if(((WebPage*) webs->get(i))->getProperty()) {
544 VProperty* vp = getVPropertyFromProperty(TEXT("URL"), ((WebPage*)webs->get(i))->getProperty());
545 vp->addParameter(TEXT("WORK"), NULL);
550 if(businessDetail->getContactDetail()->getPhones()) {
551 ArrayList* phones = businessDetail->getContactDetail()->getPhones();
552 for (int i=0; i<phones->size(); ++i)
553 if(((Phone*) phones->get(i))->getProperty()) {
554 VProperty* vp = getVPropertyFromProperty(TEXT("TEL"), ((Phone*)phones->get(i))->getProperty());
555 if(!wcscmp(TEXT("MobileBusinessTelephoneNumber"),((Phone*)phones->get(i))->getType()))
556 vp->addParameter(TEXT("TYPE"),TEXT("WORK,CELL"));
557 if(!wcscmp(TEXT("BusinessTelephoneNumber"),((Phone*)phones->get(i))->getType()))
558 vp->addParameter(TEXT("TYPE"),TEXT("WORK,VOICE"));
559 if(!wcscmp(TEXT("BusinessFaxNumber"),((Phone*)phones->get(i))->getType()))
560 vp->addParameter(TEXT("TYPE"),TEXT("WORK,FAX"));
565 if(businessDetail->getRole()) {
566 VProperty* vp = getVPropertyFromProperty(TEXT("ROLE"), businessDetail->getRole());
569 if(businessDetail->getLogo()) {
570 VProperty* vp = getVPropertyFromProperty(TEXT("LOGO"), businessDetail->getLogo());
573 if(businessDetail->getCompany()) {
574 VProperty* vp = getVPropertyFromProperty(TEXT("ORG"), businessDetail->getCompany());
578 if(businessDetail->getTitles()) {
579 ArrayList* titles = businessDetail->getTitles();
580 for (int i=0; i<titles->size(); ++i) {
581 if(((Title*)titles->get(i))->getProperty()) {
582 VProperty* vp = getVPropertyFromProperty(TEXT("TITLE"), ((Title*)titles->get(i))->getProperty());
590 PersonalDetail* Contact::getPersonalDetail() {
591 if(!personalDetail) {
592 ArrayList* phones = new ArrayList();
593 ArrayList* emails = new ArrayList();
594 ArrayList* webPages = new ArrayList();
595 ContactDetail* contactDetail = NULL;
598 for(int i = 0; i<propertiesCount();i++) {
599 if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && getProperty(i)->isType(TEXT("HOME")))
600 if(getProperty(i)->getValue()) {
601 adr = composeAddress(getProperty(i), HOME);
603 personalDetail = new PersonalDetail();
604 personalDetail->setAddress(*adr);
607 if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && getProperty(i)->isType(TEXT("HOME")))
608 if(getProperty(i)->getValue()) {
609 adr = addLabelAddress(getProperty(i), HOME);
611 personalDetail = new PersonalDetail();
612 personalDetail->setAddress(*adr);
615 if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && !getProperty(i)->isType(TEXT("HOME"))
616 && !getProperty(i)->isType(TEXT("WORK")))
617 if(getProperty(i)->getValue()) {
618 adr = composeAddress(getProperty(i), OTHER);
620 personalDetail = new PersonalDetail();
621 personalDetail->setOtherAddress(*adr);
624 if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && !getProperty(i)->isType(TEXT("HOME"))
625 && !getProperty(i)->isType(TEXT("WORK")))
626 if(getProperty(i)->getValue()) {
627 adr = addLabelAddress(getProperty(i), OTHER);
629 personalDetail = new PersonalDetail();
630 personalDetail->setOtherAddress(*adr);
633 if(!wcscmp(getProperty(i)->getName(), TEXT("PHOTO")))
634 if(getProperty(i)->getValue()) {
635 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
637 personalDetail = new PersonalDetail();
638 personalDetail->setPhoto(*prop);
640 if(!wcscmp(getProperty(i)->getName(), TEXT("BDAY")) && getProperty(i)->getValue()) {
642 personalDetail = new PersonalDetail();
643 personalDetail->setBirthday(getProperty(i)->getValue());
646 if(!wcscmp(getProperty(i)->getName(), TEXT("TEL"))) {
647 if(getProperty(i)->isType(TEXT("HOME"))) {
648 if(getProperty(i)->isType(TEXT("CELL"))) {
649 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
650 Phone* phone = new Phone();
651 phone->setPhoneNumber(*prop);
652 phone->setType(TEXT("MobileHomeTelephoneNumber"));
653 phones->add((ArrayElement&) *phone);
657 if(getProperty(i)->isType(TEXT("VOICE"))) {
658 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
659 Phone* phone = new Phone();
660 phone->setPhoneNumber(*prop);
661 phone->setType(TEXT("HomeTelephoneNumber"));
662 phones->add((ArrayElement&) *phone);
666 if(getProperty(i)->isType(TEXT("FAX"))) {
667 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
668 Phone* phone = new Phone();
669 phone->setPhoneNumber(*prop);
670 phone->setType(TEXT("HomeFaxNumber"));
671 phones->add((ArrayElement&) *phone);
675 if(getProperty(i)->containsParameter(TEXT("PAGER"))) {
676 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
677 Phone* phone = new Phone();
678 phone->setPhoneNumber(*prop);
679 phone->setType(TEXT("PagerNumber"));
680 phones->add((ArrayElement&) *phone);
683 if(getProperty(i)->isType(TEXT("CELL")) && !getProperty(i)->isType(TEXT("HOME"))
684 && !getProperty(i)->isType(TEXT("WORK"))) {
685 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
686 Phone* phone = new Phone();
687 phone->setPhoneNumber(*prop);
688 phone->setType(TEXT("MobileTelephoneNumber"));
689 phones->add((ArrayElement&) *phone);
692 if(getProperty(i)->isType(TEXT("VOICE")) && !getProperty(i)->isType(TEXT("HOME"))
693 && !getProperty(i)->isType(TEXT("WORK"))) {
694 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
695 Phone* phone = new Phone();
696 phone->setPhoneNumber(*prop);
697 phone->setType(TEXT("OtherTelephoneNumber"));
698 phones->add((ArrayElement&) *phone);
701 if(getProperty(i)->isType(TEXT("FAX")) && !getProperty(i)->isType(TEXT("HOME"))
702 && !getProperty(i)->isType(TEXT("WORK"))) {
703 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
704 Phone* phone = new Phone();
705 phone->setPhoneNumber(*prop);
706 phone->setType(TEXT("OtherFaxNumber"));
707 phones->add((ArrayElement&) *phone);
711 if(!wcscmp(getProperty(i)->getName(), TEXT("EMAIL"))) {
712 if(getProperty(i)->containsParameter(TEXT("HOME")) && getProperty(i)->isType(TEXT("INTERNET"))) {
713 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
714 Email* email = new Email();
715 email->setEmailAddress(*prop);
716 email->setType(TEXT("Email2Address"));
717 emails->add((ArrayElement&) *email);
720 if(getProperty(i)->isType(TEXT("INTERNET")) && !getProperty(i)->containsParameter(TEXT("HOME"))
721 && !getProperty(i)->containsParameter(TEXT("WORK"))) {
722 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
723 Email* email = new Email();
724 email->setEmailAddress(*prop);
725 email->setType(TEXT("Email1Address"));
726 emails->add((ArrayElement&) *email);
730 if(!wcscmp(getProperty(i)->getName(), TEXT("URL"))) {
731 if(getProperty(i)->containsParameter(TEXT("HOME"))) {
732 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
733 WebPage* url = new WebPage();
734 url->setWebPage(*prop);
735 url->setType(TEXT("HomeWebPage"));
736 webPages->add((ArrayElement&) *url);
739 if(!getProperty(i)->containsParameter(TEXT("HOME")) && !getProperty(i)->containsParameter(TEXT("WORK"))) {
740 vCardProperty* prop = getPropertyFromVProperty(getProperty(i));
741 WebPage* url = new WebPage();
742 url->setWebPage(*prop);
743 url->setType(TEXT("WebPage"));
744 webPages->add((ArrayElement&) *url);
748 } //end for VProperties
751 contactDetail = new ContactDetail();
752 contactDetail->setPhones(*phones);
757 contactDetail = new ContactDetail();
758 contactDetail->setEmails(*emails);
763 contactDetail = new ContactDetail();
764 contactDetail->setWebPages(*webPages);
769 personalDetail = new PersonalDetail();
770 personalDetail->setContactDetail(*contactDetail);
771 delete contactDetail;
774 return personalDetail;
777 void Contact::setPersonalDetail(PersonalDetail& d) {
778 if (personalDetail) delete personalDetail;
780 personalDetail = d.clone();
782 for(int i = 0, m = propertiesCount(); i < m ; i++) {
783 if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && getProperty(i)->isType(TEXT("HOME"))) {
788 if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && !getProperty(i)->isType(TEXT("HOME"))
789 && !getProperty(i)->isType(TEXT("WORK"))) {
794 if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && getProperty(i)->isType(TEXT("HOME"))) {
799 if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && !getProperty(i)->isType(TEXT("HOME"))
800 && !getProperty(i)->isType(TEXT("WORK"))) {
805 if(!wcscmp(getProperty(i)->getName(), TEXT("PHOTO"))) {
810 if(!wcscmp(getProperty(i)->getName(), TEXT("BDAY"))) {
815 if(!wcscmp(getProperty(i)->getName(), TEXT("TEL")) && !getProperty(i)->isType(TEXT("WORK")))
816 if(getProperty(i)->isType(TEXT("CELL")) || getProperty(i)->isType(TEXT("VOICE"))
817 || getProperty(i)->isType(TEXT("FAX"))) {
822 if(!wcscmp(getProperty(i)->getName(), TEXT("EMAIL")) && !getProperty(i)->containsParameter(TEXT("WORK"))
823 && getProperty(i)->isType(TEXT("INTERNET"))) {
828 if(!wcscmp(getProperty(i)->getName(), TEXT("URL")) && !getProperty(i)->containsParameter(TEXT("WORK"))) {
836 if(personalDetail->getAddress()) {
837 VProperty* vp = composeVAddress(personalDetail->getAddress());
838 vp->addParameter(TEXT("TYPE"),TEXT("HOME"));
841 if(personalDetail->getAddress()->getLabel()) {
842 VProperty* vp = getVPropertyFromProperty(TEXT("LABEL"),personalDetail->getAddress()->getLabel());
843 vp->addParameter(TEXT("TYPE"),TEXT("HOME"));
847 if(personalDetail->getOtherAddress()) {
848 VProperty* vp = composeVAddress(personalDetail->getOtherAddress());
851 if(personalDetail->getOtherAddress()->getLabel()) {
852 VProperty* vp = getVPropertyFromProperty(TEXT("LABEL"),personalDetail->getOtherAddress()->getLabel());
856 if(personalDetail->getContactDetail()) {
857 if(personalDetail->getContactDetail()->getEmails()) {
858 ArrayList* emails = personalDetail->getContactDetail()->getEmails();
859 for (int i=0; i<emails->size(); ++i) {
860 if(((Email*) emails->get(i))->getProperty()) {
861 VProperty* vp = getVPropertyFromProperty(TEXT("EMAIL"), ((Email*)emails->get(i))->getProperty());
862 if(!wcscmp(TEXT("Email2Address") ,((Email*)emails->get(i))->getType()))
863 vp->addParameter(TEXT("HOME"), NULL);
864 vp->addParameter(TEXT("TYPE"),TEXT("INTERNET"));
869 if(personalDetail->getContactDetail()->getWebPages()) {
870 ArrayList* webs = personalDetail->getContactDetail()->getWebPages();
871 for (int i=0; i<webs->size(); ++i) {
872 if(((WebPage*) webs->get(i))->getProperty()) {
873 VProperty* vp = getVPropertyFromProperty(TEXT("URL"), ((WebPage*)webs->get(i))->getProperty());
874 if(!wcscmp(TEXT("HomeWebPage") ,((WebPage*)webs->get(i))->getType()))
875 vp->addParameter(TEXT("HOME"), NULL);
880 if(personalDetail->getContactDetail()->getPhones()) {
881 ArrayList* phones = personalDetail->getContactDetail()->getPhones();
882 for (int i=0; i<phones->size(); ++i)
883 if(((Phone*) phones->get(i))->getProperty()) {
884 VProperty* vp = getVPropertyFromProperty(TEXT("TEL"), ((Phone*)phones->get(i))->getProperty());
885 if(!wcscmp(TEXT("MobileTelephoneNumber"),((Phone*)phones->get(i))->getType()))
886 vp->addParameter(TEXT("TYPE"), TEXT("CELL"));
887 if(!wcscmp(TEXT("MobileHomeTelephoneNumber"),((Phone*)phones->get(i))->getType()))
888 vp->addParameter(TEXT("TYPE"),TEXT("HOME,CELL"));
889 if(!wcscmp(TEXT("OtherTelephoneNumber"),((Phone*)phones->get(i))->getType()))
890 vp->addParameter(TEXT("TYPE"),TEXT("VOICE"));
891 if(!wcscmp(TEXT("HomeTelephoneNumber"),((Phone*)phones->get(i))->getType()))
892 vp->addParameter(TEXT("TYPE"),TEXT("HOME,VOICE"));
893 if(!wcscmp(TEXT("OtherFaxNumber"),((Phone*)phones->get(i))->getType()))
894 vp->addParameter(TEXT("TYPE"), TEXT("FAX"));
895 if(!wcscmp(TEXT("HomeFaxNumber"),((Phone*)phones->get(i))->getType()))
896 vp->addParameter(TEXT("TYPE"), TEXT("HOME,FAX"));
900 } //end contactDetail
901 if(personalDetail->getPhoto()) {
902 VProperty* vp = getVPropertyFromProperty(TEXT("PHOTO"), personalDetail->getPhoto());
905 if(personalDetail->getBirthday()) {
906 VProperty* vp = new VProperty(TEXT("BDAY"), personalDetail->getBirthday());
912 void Contact::setUID (WCHAR* u) {
913 if (containsProperty(TEXT("UID")))
914 getProperty(TEXT("UID"))->setValue(u);
916 insertProperty(new VProperty(TEXT("UID"),u));
919 void Contact::setTimezone (WCHAR* tz) {
920 if (containsProperty(TEXT("TZ")))
921 getProperty(TEXT("TZ"))->setValue(tz);
923 insertProperty(new VProperty(TEXT("TZ"),tz));
926 void Contact::setRevision (WCHAR* r) {
927 if (containsProperty(TEXT("REV")))
928 getProperty(TEXT("REV"))->setValue(r);
930 insertProperty(new VProperty(TEXT("REV"),r));
933 void Contact::set(WCHAR** p, WCHAR* v) {
939 vCardProperty* Contact::getPropertyFromVProperty(VProperty* vp) {
942 vCardProperty *prop = new vCardProperty(vp->getValue());
943 if(vp->getParameterValue(TEXT("ENCODING")))
944 prop->setEncoding(vp->getParameterValue(TEXT("ENCODING")));
945 if(vp->containsParameter(TEXT("BASE64")))
946 prop->setEncoding(TEXT("BASE64"));
947 if(vp->containsParameter(TEXT("QUOTED-PRINTABLE")))
948 prop->setEncoding(TEXT("QUOTED-PRINTABLE"));
949 if(vp->getParameterValue(TEXT("LANGUAGE")))
950 prop->setLanguage(vp->getParameterValue(TEXT("LANGUAGE")));
951 if(vp->getParameterValue(TEXT("CHARSET")))
952 prop->setCharset(vp->getParameterValue(TEXT("CHARSET")));
959 VProperty* Contact::getVPropertyFromProperty(WCHAR*name, vCardProperty* prop) {
961 VProperty *vprop = new VProperty(name, prop->getValue());
962 if(prop->getCharset())
963 vprop->addParameter(TEXT("CHARSET"), prop->getCharset());
964 if(prop->getLanguage())
965 vprop->addParameter(TEXT("LANGUAGE"), prop->getLanguage());
966 if(prop->getEncoding())
967 vprop->addParameter(TEXT("ENCODING"), prop->getEncoding());
974 VProperty* Contact::composeVAddress(Address* adr) {
975 WCHAR *addressValue = new WCHAR[MAX_VPROPERTY_VALUE + 1];
976 WCHAR *encoding = NULL;
977 WCHAR *language = NULL;
978 WCHAR *charset = NULL;
980 wcscpy(addressValue,TEXT(""));
981 if(adr->getPostOfficeAddress()) {
982 wcscat(addressValue, adr->getPostOfficeAddress()->getValue());
983 if(adr->getPostOfficeAddress()->getCharset()) {
984 charset = new WCHAR[MAX_VPROPERTY_VALUE +1 ];
985 wcscpy(charset, adr->getPostOfficeAddress()->getCharset());
987 if(adr->getPostOfficeAddress()->getLanguage()) {
988 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
989 wcscpy(language, adr->getPostOfficeAddress()->getLanguage());
991 if(adr->getPostOfficeAddress()->getEncoding()) {
992 encoding = new WCHAR[MAX_VPROPERTY_VALUE +1 ];
993 wcscpy(encoding, adr->getPostOfficeAddress()->getEncoding());
996 wcscat(addressValue, TEXT(";"));
997 if(adr->getRoomNumber()) {
998 wcscat(addressValue, adr->getRoomNumber()->getValue());
1000 if(adr->getRoomNumber()->getCharset()) {
1001 charset = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1002 wcscpy(charset, adr->getRoomNumber()->getCharset());
1005 if(adr->getRoomNumber()->getLanguage()) {
1006 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1007 wcscpy(language, adr->getRoomNumber()->getLanguage());
1010 if(adr->getRoomNumber()->getEncoding()) {
1011 encoding = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1012 wcscpy(encoding, adr->getRoomNumber()->getEncoding());
1015 wcscat(addressValue, TEXT(";"));
1016 if(adr->getStreet()) {
1017 wcscat(addressValue, adr->getStreet()->getValue());
1019 if(adr->getStreet()->getCharset()) {
1020 charset = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1021 wcscpy(charset, adr->getStreet()->getCharset());
1024 if(adr->getStreet()->getLanguage()) {
1025 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1026 wcscpy(language, adr->getStreet()->getLanguage());
1029 if(adr->getStreet()->getEncoding()) {
1030 encoding = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1031 wcscpy(encoding, adr->getStreet()->getEncoding());
1034 wcscat(addressValue, TEXT(";"));
1035 if(adr->getCity()) {
1036 wcscat(addressValue, adr->getCity()->getValue());
1038 if(adr->getCity()->getCharset()) {
1039 charset = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1040 wcscpy(charset, adr->getCity()->getCharset());
1043 if(adr->getCity()->getLanguage()) {
1044 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1045 wcscpy(language, adr->getCity()->getLanguage());
1048 if(adr->getCity()->getEncoding()) {
1049 encoding = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1050 wcscpy(encoding, adr->getCity()->getEncoding());
1053 wcscat(addressValue, TEXT(";"));
1054 if(adr->getState()) {
1055 wcscat(addressValue, adr->getState()->getValue());
1057 if(adr->getState()->getCharset()) {
1058 charset = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1059 wcscpy(charset, adr->getState()->getCharset());
1062 if(adr->getState()->getLanguage()) {
1063 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1064 wcscpy(language, adr->getState()->getLanguage());
1067 if(adr->getState()->getEncoding()) {
1068 encoding = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1069 wcscpy(encoding, adr->getState()->getEncoding());
1072 wcscat(addressValue, TEXT(";"));
1073 if(adr->getPostalCode()) {
1074 wcscat(addressValue, adr->getPostalCode()->getValue());
1076 if(adr->getPostalCode()->getCharset()) {
1077 charset = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1078 wcscpy(charset, adr->getPostalCode()->getCharset());
1081 if(adr->getPostalCode()->getLanguage()) {
1082 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1083 wcscpy(language, adr->getPostalCode()->getLanguage());
1086 if(adr->getPostalCode()->getEncoding()) {
1087 encoding = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1088 wcscpy(encoding, adr->getPostalCode()->getEncoding());
1091 wcscat(addressValue, TEXT(";"));
1092 if(adr->getCountry()) {
1093 wcscat(addressValue, adr->getCountry()->getValue());
1095 if(adr->getCountry()->getCharset()) {
1096 charset = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1097 wcscpy(charset, adr->getCountry()->getCharset());
1100 if(adr->getCountry()->getLanguage()) {
1101 language = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1102 wcscpy(language, adr->getCountry()->getLanguage());
1105 if(adr->getCountry()->getEncoding()) {
1106 encoding = new WCHAR[MAX_VPROPERTY_VALUE + 1];
1107 wcscpy(encoding, adr->getCountry()->getEncoding());
1111 VProperty* vp = new VProperty(TEXT("ADR"), addressValue);
1113 vp->addParameter(TEXT("CHARSET"), charset);
1115 vp->addParameter(TEXT("LANGUAGE"), language);
1117 vp->addParameter(TEXT("ENCODING"), encoding);
1122 Address* Contact::composeAddress(VProperty* vp, int type) {
1127 if(!businessDetail || !businessDetail->getAddress())
1128 adr = new Address();
1130 adr = businessDetail->getAddress()->clone();
1133 if(!personalDetail || !personalDetail->getAddress())
1134 adr = new Address();
1136 adr = personalDetail->getAddress()->clone();
1139 if(!personalDetail || !personalDetail->getOtherAddress())
1140 adr = new Address();
1142 adr = personalDetail->getOtherAddress()->clone();
1148 if(vp->getPropComponent(1)){
1149 vCardProperty *prop = getPropertyFromVProperty(vp);
1150 prop->setValue(vp->getPropComponent(1));
1151 adr->setPostOfficeAddress(*prop);
1155 if(vp->getPropComponent(2)){
1156 vCardProperty *prop = getPropertyFromVProperty(vp);
1157 prop->setValue(vp->getPropComponent(2));
1158 adr->setRoomNumber(*prop);
1162 if(vp->getPropComponent(3)){
1163 vCardProperty *prop = getPropertyFromVProperty(vp);
1164 prop->setValue(vp->getPropComponent(3));
1165 adr->setStreet(*prop);
1169 if(vp->getPropComponent(4)){
1170 vCardProperty *prop = getPropertyFromVProperty(vp);
1171 prop->setValue(vp->getPropComponent(4));
1172 adr->setCity(*prop);
1176 if(vp->getPropComponent(5)){
1177 vCardProperty *prop = getPropertyFromVProperty(vp);
1178 prop->setValue(vp->getPropComponent(5));
1179 adr->setState(*prop);
1183 if(vp->getPropComponent(6)){
1184 vCardProperty *prop = getPropertyFromVProperty(vp);
1185 prop->setValue(vp->getPropComponent(6));
1186 adr->setPostalCode(*prop);
1190 if(vp->getPropComponent(7)){
1191 vCardProperty *prop = getPropertyFromVProperty(vp);
1192 prop->setValue(vp->getPropComponent(7));
1193 adr->setCountry(*prop);
1202 Address* Contact::addLabelAddress(VProperty* vp, int type) {
1208 if(!businessDetail || !businessDetail->getAddress())
1209 adr = new Address();
1211 adr = businessDetail->getAddress()->clone();
1214 if(!personalDetail || !personalDetail->getAddress())
1215 adr = new Address();
1217 adr = personalDetail->getAddress()->clone();
1220 if(!personalDetail || !personalDetail->getOtherAddress())
1221 adr = new Address();
1223 adr = personalDetail->getOtherAddress()->clone();
1229 if(vp->getValue()) {
1230 vCardProperty *prop = getPropertyFromVProperty(vp);
1231 adr->setLabel(*prop);
1240 Contact* Contact::clone() {
1242 Contact* ret = new Contact();
1243 VProperty* property;
1245 for(int i = 0; i < this->propertiesCount(); i++) {
1246 property = (VProperty*)this->getProperty(i)->clone();
1247 ret->addProperty(property);
1252 WCHAR* Contact::toString() {
1253 if(!containsProperty(TEXT("BEGIN")) && !containsProperty(TEXT("VERSION")) && !containsProperty(TEXT("END"))) {
1254 //this means the Contact was created with new, not using vConverter::parse
1255 //we need to add BEGIN, VERSION, END to VObject properties
1256 addFirstProperty(new VProperty(TEXT("VERSION"), getVersion()));
1257 addFirstProperty(new VProperty(TEXT("BEGIN"), TEXT("VCARD")));
1258 addProperty(new VProperty(TEXT("END"), TEXT("VCARD")));
1261 return ((VObject*)this)->toString();