📄 contact.cpp
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#include "base/fscapi.h"
#include "base/util/utils.h"
#include "vocl/vCard/Contact.h"
Contact::Contact() {
name = NULL;
notes = NULL;
businessDetail = NULL;
personalDetail = NULL;
setVersion(TEXT("2.1"));
setProdID(TEXT("VCARD"));
}
Contact::~Contact() {
if (name) {
delete name; name = NULL;
}
if (notes) {
delete notes; notes = NULL;
}
if (businessDetail) {
delete businessDetail; businessDetail = NULL;
}
if (personalDetail) {
delete personalDetail; personalDetail = NULL;
}
}
/**
* Returns the UID of this contact
*
* @return the uid of this contact or NULL if not specified
*/
WCHAR* Contact::getUID(WCHAR* buf, int size) {
if(!containsProperty(TEXT("UID")))
return NULL;
if (buf == NULL) {
return (getProperty(TEXT("UID"))->getValue());
}
if (size >= 0) {
wcsncpy(buf, getProperty(TEXT("UID"))->getValue(), size);
} else {
wcscpy(buf, getProperty(TEXT("UID"))->getValue());
}
return buf;
}
WCHAR* Contact::getTimezone (WCHAR* buf, int size) {
if(!containsProperty(TEXT("TZ")))
return NULL;
if (buf == NULL) {
return (getProperty(TEXT("TZ"))->getValue());
}
if (size >= 0) {
wcsncpy(buf, getProperty(TEXT("TZ"))->getValue(), size);
} else {
wcscpy(buf, getProperty(TEXT("TZ"))->getValue());
}
return buf;
}
ArrayList* Contact::getNotes() {
if(!notes) {
for(int i = 0; i<propertiesCount();i++) {
if(!wcscmp(getProperty(i)->getName(), TEXT("NOTE")))
if(getProperty(i)->getValue()) {
vCardProperty *property = getPropertyFromVProperty(getProperty(i));
Note* note = new Note();
note->setProperty(*property);
if(getProperty(i)->containsParameter(TEXT("TYPE")))
note->setType(getProperty(i)->getParameterValue(TEXT("TYPE")));
if(!notes)
notes = new ArrayList();
notes->add((ArrayElement&)*note);
}
}
}
return notes;
}
void Contact::setNotes(ArrayList& list) {
int i,m;
if (notes) {
notes->clear();
} else {
notes = new ArrayList();
}
Note *note = NULL;
VProperty *vp;
for(i = 0, m = propertiesCount();i < m;i++) {
if(!wcscmp(getProperty(i)->getName(), TEXT("NOTE"))) {
removeProperty(i);
--i;
--m;
}
}
int s = list.size();
for (i=0; i<s; ++i) {
notes->add(*list[i]);
note = (Note*)list[i];
if(note->getProperty()) {
vp = getVPropertyFromProperty(TEXT("NOTE"), note->getProperty());
if(note->getType())
vp->addParameter(TEXT("TYPE"), note->getType());
insertProperty(vp);
}
}
}
WCHAR* Contact::getRevision (WCHAR* buf, int size) {
if(!containsProperty(TEXT("REV")))
return NULL;
if (buf == NULL) {
return (getProperty(TEXT("REV"))->getValue());
}
if (size >= 0) {
wcsncpy(buf, getProperty(TEXT("REV"))->getValue(), size);
} else {
wcscpy(buf, getProperty(TEXT("REV"))->getValue());
}
return buf;
}
Name* Contact::getName () {
if (!name) {
if(containsProperty(TEXT("N")) && getProperty(TEXT("N"))->getValue()) {
VProperty* vp = getProperty(TEXT("N"));
name = new Name();
if(vp->getPropComponent(4)) {
vCardProperty *salutation = getPropertyFromVProperty(vp);
salutation->setValue(vp->getPropComponent(4));
name->setSalutation(*salutation);
delete salutation;
}
if(vp->getPropComponent(2)) {
vCardProperty *firstName = getPropertyFromVProperty(vp);
firstName->setValue(vp->getPropComponent(2));
name->setFirstName(*firstName);
delete firstName;
}
if(vp->getPropComponent(3)) {
vCardProperty *middleName = getPropertyFromVProperty(vp);
middleName->setValue(vp->getPropComponent(3));
name->setMiddleName(*middleName);
delete middleName;
}
if(vp->getPropComponent(1)) {
vCardProperty *lastName = getPropertyFromVProperty(vp);
lastName->setValue(vp->getPropComponent(1));
name->setLastName(*lastName);
delete lastName;
}
if(vp->getPropComponent(5)) {
vCardProperty *suffix = getPropertyFromVProperty(vp);
suffix->setValue(vp->getPropComponent(5));
name->setSuffix(*suffix);
delete suffix;
}
}
if(containsProperty(TEXT("FN")) && getProperty(TEXT("FN"))->getValue()) {
if (!name)
name = new Name();
VProperty* vp = getProperty(TEXT("FN"));
vCardProperty *displayName = getPropertyFromVProperty(vp);
name->setDisplayName(*displayName);
delete displayName;
}
if(containsProperty(TEXT("NICKNAME")) && getProperty(TEXT("NICKNAME"))->getValue()) {
if (!name)
name = new Name();
VProperty* vp = getProperty(TEXT("NICKNAME"));
vCardProperty *nickName = getPropertyFromVProperty(vp);
name->setNickname(*nickName);
delete nickName;
}
}
return name;
}
void Contact::setName(Name& n) {
if (name) delete name;
name = n.clone();
if (containsProperty(TEXT("N")))
removeProperty(TEXT("N"));
if (containsProperty(TEXT("FN")))
removeProperty(TEXT("FN"));
if (containsProperty(TEXT("NICKNAME")))
removeProperty(TEXT("NICKNAME"));
if(name) {
WCHAR *nameProp = new WCHAR[MAX_VPROPERTY_VALUE + 1];
wcscpy(nameProp,TEXT(""));
if(name->getLastName())
wcscat(nameProp,name->getLastName()->getValue());
wcscat(nameProp,TEXT(";"));
if(name->getFirstName())
wcscat(nameProp,name->getFirstName()->getValue());
wcscat(nameProp,TEXT(";"));
if(name->getMiddleName())
wcscat(nameProp,name->getMiddleName()->getValue());
wcscat(nameProp,TEXT(";"));
if(name->getSalutation())
wcscat(nameProp,name->getSalutation()->getValue());
wcscat(nameProp,TEXT(";"));
if(name->getSuffix())
wcscat(nameProp,name->getSuffix()->getValue());
VProperty* vpName = new VProperty(TEXT("N"), nameProp);
if(name->getFirstName()) {
if(name->getFirstName()->getCharset())
vpName->addParameter(TEXT("CHARSET"), name->getFirstName()->getCharset());
if(name->getFirstName()->getEncoding())
vpName->addParameter(TEXT("ENCODING"), name->getFirstName()->getEncoding());
if(name->getFirstName()->getLanguage())
vpName->addParameter(TEXT("LANGUAGE"), name->getFirstName()->getLanguage());
}
insertProperty(vpName);
if(name->getDisplayName()) {
VProperty* vpDisplayName = getVPropertyFromProperty(TEXT("FN"), name->getDisplayName());
insertProperty(vpDisplayName);
}
if(name->getNickname()) {
VProperty* vpNickName = getVPropertyFromProperty(TEXT("NICKNAME"), name->getNickname());
insertProperty(vpNickName);
}
}
}
BusinessDetail* Contact::getBusinessDetail () {
if(!businessDetail) {
WCHAR* titles[MAX_TITLES];
int titlesIndex = 0;
ArrayList* phones = NULL;
ArrayList* emails = NULL;
ArrayList* webPages = NULL;
ContactDetail* contactDetail = NULL;
Address* adr = NULL;
for(int i = 0; i<propertiesCount();i++) {
if(!wcscmp(getProperty(i)->getName(), TEXT("ADR")) && getProperty(i)->isType(TEXT("WORK")))
if(getProperty(i)->getValue()) {
adr = composeAddress(getProperty(i), BUSINESS);
if(!businessDetail)
businessDetail = new BusinessDetail();
businessDetail->setAddress(*adr);
delete adr;
}
if(!wcscmp(getProperty(i)->getName(), TEXT("LABEL")) && getProperty(i)->isType(TEXT("WORK")))
if(getProperty(i)->getValue()) {
adr = addLabelAddress(getProperty(i), BUSINESS);
if(!businessDetail)
businessDetail = new BusinessDetail();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -