Beispiel #1
0
// Format and return a vNote string from the propertyMap.
wstring& WinNote::toString() {

    vNote = L"";

    //
    // Conversion: WinNote -> vObject.
    // -------------------------------
    //
    VObject* vo = new VObject();
    VProperty* vp  = NULL;
    wstring element;

    vp = new VProperty(TEXT("BEGIN"), TEXT("VNOTE"));
    vo->addProperty(vp);
    delete vp; vp = NULL;

    vp = new VProperty(TEXT("VERSION"), VNOTE_VERSION);
    vo->addProperty(vp);
    delete vp; vp = NULL;


    // Folder path.
    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"Subject", element)) {
        vp = new VProperty(TEXT("SUMMARY"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(L"Body", element)) {
        vp = new VProperty(TEXT("BODY"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(L"Categories", element)) {
        vp = new VProperty(TEXT("CATEGORIES"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }


    //
    // ---- Other Funambol defined properties ----
    // Support for other fields that don't have a
    // specific correspondence in vCalendar.
    if (getProperty(L"Color", element)) {
        long color = _wtoi(element.c_str());
        vp = new VProperty(TEXT("X-FUNAMBOL-COLOR"));

        if (color < 0 || color >= NUM_NOTE_COLOR) {
            color = 1;  // Default = yellow.
        }
        vp->addValue(colorName[color]);

        vo->addProperty(vp);
        delete vp; vp = NULL;
    }


    bool found = false;
    vp = new VProperty(TEXT("X-FUNAMBOL-POSITION"));
    if (getProperty(L"Top", element)) {
        found = true;
        vp->addValue(element.c_str());
    }
    if (getProperty(L"Left", element)) {
        found = true;
        vp->addValue(element.c_str());
    }
    if (getProperty(L"Height", element)) {
        found = true;
        vp->addValue(element.c_str());
    }
    if (getProperty(L"Width", element)) {
        found = true;
        vp->addValue(element.c_str());
    }
    if (found) {
        vo->addProperty(vp);
    }
    delete vp; vp = NULL;


    vp = new VProperty(TEXT("END"), TEXT("VNOTE"));
    vo->addProperty(vp);
    delete vp; vp = NULL;


    //
    // Format the vNote.
    // -----------------
    //
    WCHAR* tmp = vo->toString();
    if (tmp) {
        vNote = tmp;
        delete [] tmp;
    }
    return vNote;
}
//
// 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"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-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-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-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;
    }
    if (vo) { delete vo; vo = NULL; }
    return vCard;
}