?? wincontact.cpp
字號:
/*
* Copyright (C) 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 "vocl/WinContact.h"
#include "vocl/VConverter.h"
#include "vocl/constants.h"
#include "base/stringUtils.h"
using namespace std;
// Constructor
WinContact::WinContact() {
vCard = L"";
}
// Constructor: fills propertyMap parsing the passed vCard string
WinContact::WinContact(const wstring dataString) {
vCard = L"";
parse(dataString);
}
// Destructor
WinContact::~WinContact() {
}
//
// Format and return a vCard string from the propertyMap.
//
wstring WinContact::toString() {
vCard = L"";
//
// Conversion: WinContact -> vObject.
// ----------------------------------
//
VObject* vo = new VObject();
wstring element;
VProperty* vp = NULL;
bool found = false;
vp = new VProperty(L"BEGIN", L"VCARD");
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(L"VERSION", VCARD_VERSION);
vo->addProperty(vp);
delete vp; vp = NULL;
// ------- Name -------
// Add only if at least 1 property is supported, but include
// all elements in the right order.
found = false;
vp = new VProperty(L"N");
if (getProperty(L"LastName", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"FirstName", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"MiddleName", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"Title", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"Suffix", element)) found = true;
vp->addValue(element.c_str());
if (found) {
vo->addProperty(vp);
}
delete vp; vp = NULL;
if (getProperty(L"Birthday", element)) {
vp = new VProperty(L"BDAY", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Body", element)) {
vp = new VProperty(L"NOTE", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"BusinessFaxNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"WORK", NULL);
vp->addParameter(L"FAX", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"BusinessTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"VOICE", NULL);
vp->addParameter(L"WORK", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Business2TelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"VOICE", NULL);
vp->addParameter(L"WORK", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"BusinessWebPage", element)) {
vp = new VProperty(L"URL", element.c_str());
vp->addParameter(L"WORK", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"CarTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"CAR", NULL);
vp->addParameter(L"VOICE", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Categories", element)) {
vp = new VProperty(L"CATEGORIES", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"CompanyMainTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"WORK", NULL);
vp->addParameter(L"PREF", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"FileAs", element)) {
vp = new VProperty(L"FN", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
// Mapping is:
// Email1Address <-> EMAIL;INTERNET:
// Email2Address <-> EMAIL;INTERNET;HOME:
// Email3Address <-> EMAIL;INTERNET;WORK:
if (getProperty(L"Email1Address", element)) {
vp = new VProperty(L"EMAIL", element.c_str());
vp->addParameter(L"INTERNET", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Email2Address", element)) {
vp = new VProperty(L"EMAIL", element.c_str());
vp->addParameter(L"INTERNET", NULL);
vp->addParameter(L"HOME", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Email3Address", element)) {
vp = new VProperty(L"EMAIL", element.c_str());
vp->addParameter(L"INTERNET", NULL);
vp->addParameter(L"WORK", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"JobTitle", element)) {
vp = new VProperty(L"TITLE", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"HomeTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"VOICE", NULL);
vp->addParameter(L"HOME", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Home2TelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"VOICE", NULL);
vp->addParameter(L"HOME", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"HomeFaxNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"HOME", NULL);
vp->addParameter(L"FAX", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"HomeWebPage", element)) {
vp = new VProperty(L"URL", element.c_str());
vp->addParameter(L"HOME", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Importance", element)) {
vp = new VProperty(L"PRIORITY", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"MobileTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"CELL", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"NickName", element)) {
vp = new VProperty(L"NICKNAME", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"OtherFaxNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"FAX", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"OtherTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"VOICE", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"PagerNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"PAGER", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"PrimaryTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"PREF", NULL);
vp->addParameter(L"VOICE", NULL);
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Profession", element)) {
vp = new VProperty(L"ROLE", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Sensitivity", element)) {
long sensitivity = _wtoi(element.c_str());
vp = new VProperty(TEXT("CLASS"));
if(sensitivity == winPrivate) {
vp->addValue(TEXT("PRIVATE"));
}
else if (sensitivity == winConfidential) {
vp->addValue(TEXT("CONFIDENTIAL"));
}
else { // default value
vp->addValue(TEXT("PUBLIC"));
}
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"WebPage", element)) {
vp = new VProperty(L"URL", element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
// ----- ORG -----
// Add only if at least 1 property is supported, but include
// all elements in the right order.
found = false;
vp = new VProperty(L"ORG");
if (getProperty(L"CompanyName", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"Department", element)) found = true;
vp->addValue(element.c_str());
if (getProperty(L"OfficeLocation", element)) found = true;
vp->addValue(element.c_str());
if (found) {
vo->addProperty(vp);
}
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"Picture", 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");
vp->addParameter(L"TYPE", L"JPEG");
}
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(L"CallbackTelephoneNumber", element)) {
vp = new VProperty(L"TEL", element.c_str());
vp->addParameter(L"X-FUNAMBOL-CALLBACK", NULL);
vo->addProperty(vp);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -