wincontact.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 929 行 · 第 1/3 页
CPP
929 行
delete vp; vp = NULL;
// ----- Address HOME -----
// Add only if at least 1 property is supported, but include
// all elements in the right order.
// "AddressPostOfficeBox" is not supported by WM.
// "AddressExtended" is not supported by Outlook/WM.
found = false;
vp = new VProperty(L"ADR");
vp->addParameter(L"HOME", NULL);
if (getProperty(L"HomeAddressPostOfficeBox", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"HomeAddressExtended", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"HomeAddressStreet", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"HomeAddressCity", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"HomeAddressState", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"HomeAddressPostalCode", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"HomeAddressCountry", element)) found = true;
vp->addValue(element.c_str());
if (found) {
vo->addProperty(vp);
}
delete vp; vp = NULL;
// ----- Address -----
// Add only if at least 1 property is supported, but include
// all elements in the right order.
// "AddressPostOfficeBox" is not supported by WM.
// "AddressExtended" is not supported by Outlook/WM.
found = false;
vp = new VProperty(L"ADR");
if (getProperty(L"OtherAddressPostOfficeBox", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OtherAddressExtended", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OtherAddressStreet", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OtherAddressCity", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OtherAddressState", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OtherAddressPostalCode", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OtherAddressCountry", element)) found = true;
vp->addValue(element.c_str());
if (found) {
vo->addProperty(vp);
}
delete vp; vp = NULL;
// ----- Address WORK -----
// Add only if at least 1 property is supported, but include
// all elements in the right order.
// "AddressPostOfficeBox" is not supported by WM.
// "AddressExtended" is not supported by Outlook/WM.
found = false;
vp = new VProperty(L"ADR");
vp->addParameter(L"WORK", NULL);
if (getProperty(L"BusinessAddressPostOfficeBox", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"BusinessAddressExtended", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"BusinessAddressStreet", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"BusinessAddressCity", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"BusinessAddressState", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"BusinessAddressPostalCode", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"BusinessAddressCountry", element)) found = true;
vp->addValue(element.c_str());
if (found) {
vo->addProperty(vp);
}
delete vp; vp = NULL;
//PHOTO
if (getProperty(L"Photo", element)) {
vp = new VProperty(L"PHOTO", element.c_str());
if (element != L"") {
vp->addParameter(L"CONTENT-VALUE", L"UNCHANGED");
vp->addParameter(L"ENCODING", L"b");
if (photoType.length() > 0) {
vp->addParameter(L"TYPE", photoType.c_str());
}
}
vo->addProperty(vp);
delete vp; vp = NULL;
}
//
// ---- Funambol defined properties ----
// Support for other fields that don't have a
// specific correspondence in vCard.
if (getProperty(L"Anniversary", element)) {
vp = new VProperty(L"X-FUNAMBOL-ANNIVERSARY");
vp->addValue(element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(TEXT("BillingInformation"), element)) {
vp = new VProperty(TEXT("X-FUNAMBOL-BILLINGINFO"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"CallbackTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"X-FUNAMBOL-CALLBACK", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Children", element)) {
vp = new VProperty(L"X-FUNAMBOL-CHILDREN", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Companies", element)) {
vp = new VProperty(L"X-FUNAMBOL-COMPANIES", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"CustomerID", element)) {
vp = new VProperty(L"X-FUNAMBOL-CUSTOMERID", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Folder", element)) {
vp = new VProperty(L"X-FUNAMBOL-FOLDER");
vp->addValue(element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Gender", element)) {
vp = new VProperty(L"X-FUNAMBOL-GENDER", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"GovernmentIDNumber", element)) {
vp = new VProperty(L"X-FUNAMBOL-GOVERNMENTID", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Hobby", element)) {
vp = new VProperty(L"X-FUNAMBOL-HOBBIES", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"IMAddress", element)) {
vp = new VProperty(L"EMAIL", element.c_str());
vp->addParameter(L"INTERNET", NULL);
vp->addParameter(L"HOME", NULL);
vp->addParameter(L"X-FUNAMBOL-INSTANTMESSENGER", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"IM2Address", element)) {
vp = new VProperty(L"EMAIL", element.c_str());
vp->addParameter(L"INTERNET", NULL);
vp->addParameter(L"HOME", NULL);
vp->addParameter(L"X-FUNAMBOL-INSTANTMESSENGER", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"IM3Address", element)) {
vp = new VProperty(L"EMAIL", element.c_str());
vp->addParameter(L"INTERNET", NULL);
vp->addParameter(L"HOME", NULL);
vp->addParameter(L"X-FUNAMBOL-INSTANTMESSENGER", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Initials", element)) {
vp = new VProperty(L"X-FUNAMBOL-INITIALS", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Language", element)) {
vp = new VProperty(L"X-FUNAMBOL-LANGUAGES", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"ManagerName", element)) {
vp = new VProperty(L"X-FUNAMBOL-MANAGER", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Mileage", element)) {
vp = new VProperty(L"X-FUNAMBOL-MILEAGE", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"OrganizationalIDNumber", element)) {
vp = new VProperty(L"X-FUNAMBOL-ORGANIZATIONALID", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"RadioTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"X-FUNAMBOL-RADIO", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Spouse", element)) {
vp = new VProperty(L"X-FUNAMBOL-SPOUSE", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Subject", element)) {
vp = new VProperty(L"X-FUNAMBOL-SUBJECT", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"TelexNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"X-FUNAMBOL-TELEX", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"YomiCompanyName", element)) {
vp = new VProperty(L"X-FUNAMBOL-YOMICOMPANYNAME", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"YomiFirstName", element)) {
vp = new VProperty(L"X-FUNAMBOL-YOMIFIRSTNAME", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"YomiLastName", element)) {
vp = new VProperty(L"X-FUNAMBOL-YOMILASTNAME", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
vp = new VProperty(L"END", L"VCARD");
vo->addProperty(vp);
delete vp; vp = NULL;
//
// Format the vCard.
// -----------------
//
WCHAR* tmp = vo->toString();
if (tmp) {
vCard = tmp;
delete [] tmp;
}
return vCard;
}
//
// Parse a vCard string and fills the propertyMap.
//
int WinContact::parse(const wstring dataString) {
int businessTel = 0;
int homeTel = 0;
int imAddress = 0;
WCHAR* name = NULL;
WCHAR* element = NULL;
//
// Parse the vCard and fill the VObject.
// -------------------------------------
//
VObject* vo = VConverter::parse(dataString.c_str());
if (!vo) {
//sprintf(lastErrorMsg, ERR_ITEM_VOBJ_PARSE);
setError(1, ERR_ITEM_VOBJ_PARSE);
LOG.error("%s", getLastErrorMsg());
return 1;
}
// Check if VObject type and version are the correct ones.
if (!checkVCardTypeAndVersion(vo)) {
if (vo) delete vo;
return 1;
}
//
// Conversion: vObject -> WinContact.
// ----------------------------------
// Note: only properties found are added to the propertyMap, so that the
// map will contain only properties effectively received.
//
propertyMap.clear();
for(int i=0; i < vo->propertiesCount(); i++) {
VProperty* vp = vo->getProperty(i);
name = vp->getName();
element = vp->getValue(0); // the first value of the property.
if(!wcscmp(name, L"N")) {
if(element = vp->getPropComponent(1)) setProperty(L"LastName", element);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?