wintask.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 546 行 · 第 1/2 页

CPP
546
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * 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 Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission 
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License 
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably 
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#include "base/util/utils.h"
#include "vocl/WinTask.h"
#include "vocl/VConverter.h"
#include "base/stringUtils.h"
#include "base/timeUtils.h"
#include "base/globalsdef.h"

USE_NAMESPACE

using namespace std;



// Constructor
WinTask::WinTask() {
    vCalendar = L"";
}

// Constructor: fills propertyMap parsing the passed data
WinTask::WinTask(const wstring dataString) {
    vCalendar = L"";
    parse(dataString);
}

// Destructor
WinTask::~WinTask() {
}




// Format and return a vCalendar string from the propertyMap.
wstring& WinTask::toString() {

    vCalendar = L"";

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


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

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

    vp = new VProperty(TEXT("BEGIN"), TEXT("VTODO"));
    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;
    }

    // Tasks are ALWAYS all-day-event!
    vp = new VProperty(TEXT("X-FUNAMBOL-ALLDAY"), TEXT("1"));
    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("DESCRIPTION"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }

    if (getProperty(L"DateCompleted", element)) {
        replaceAll(L"-", L"", element);                         // **** To be removed!!! ****
        //if (element.size() == 8) { 
        //    element += TEXT("T000000");
        //}
        vp = new VProperty(TEXT("COMPLETED"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(L"DueDate", element)) {
        replaceAll(L"-", L"", element);                         // **** To be removed!!! ****
        //if (element.size() == 8) { 
        //    element += TEXT("T235900");
        //}
        vp = new VProperty(TEXT("DUE"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(L"StartDate", element)) {
        replaceAll(L"-", L"", element);                         // **** To be removed!!! ****
        //if (element.size() == 8) { 
        //    element += TEXT("T000000");
        //}
        vp = new VProperty(TEXT("DTSTART"), 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;
    }
    if (getProperty(L"Complete", element)) {
        bool isCompleted = (element != TEXT("0"));
        if (isCompleted) { 
            vp = new VProperty(TEXT("STATUS"), TEXT("COMPLETED"));
            vo->addProperty(vp);
            delete vp; vp = NULL;
        }
    }
    if (getProperty(L"Importance", element)) {
        vp = new VProperty(TEXT("PRIORITY"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(L"PercentComplete", element)) {
        vp = new VProperty(TEXT("PERCENT-COMPLETE"), 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;
    }

    //
    // **** "Status"?   mapping is missing! ****
    // **** "TeamTask"? mapping is missing! ****
    //

    //
    // Recurrence pattern -> RRULE
    //
    if (getProperty(L"IsRecurring", element)) {
        bool isRec = (element != TEXT("0"));
        if(isRec) {
            wstring rRule = recPattern.toString();
            if(rRule != L"") {
                vp = new VProperty(TEXT("RRULE"), rRule.c_str());
                vo->addProperty(vp);
                delete vp; vp = NULL;
            }
        }
        else {
            // Not recurring: send empty "RRULE:"
            vp = new VProperty(TEXT("RRULE"));
            vo->addProperty(vp);
            delete vp; vp = NULL;
        }
    }


    //
    // ReminderSet
    //
    if (getProperty(L"ReminderSet", element)) {
        bool bReminder = (element != TEXT("0"));
        if(bReminder == true) {
            if (getProperty(L"ReminderTime", element)) {

                vp = new VProperty(L"AALARM");
                vp->addValue(element.c_str());                      // "RunTime"
                vp->addValue(L"");                                  // "Snooze Time" (empty)
                vp->addValue(L"0");                                 // "Repeat Count"

                getProperty(L"ReminderSoundFile", element);         // (empty if not found)
                vp->addValue(element.c_str());                      // "Audio Content" = sound file path

                vo->addProperty(vp);
                delete vp; vp = NULL;
            }
        }
        else {
            // No reminder: send empty "AALARM:"
            vp = new VProperty(L"AALARM");
            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(TEXT("ActualWork"), element)) {
        vp = new VProperty(TEXT("X-FUNAMBOL-ACTUALWORK"), 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(TEXT("Companies"), element)) {
        vp = new VProperty(TEXT("X-FUNAMBOL-COMPANIES"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(TEXT("Mileage"), element)) {
        vp = new VProperty(TEXT("X-FUNAMBOL-MILEAGE"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(L"ReminderOptions", element)) {
        vp = new VProperty(TEXT("X-FUNAMBOL-AALARMOPTIONS"), element.c_str());
        vo->addProperty(vp);
        delete vp; vp = NULL;
    }
    if (getProperty(TEXT("TeamTask"), element)) {
        vp = new VProperty(TEXT("X-FUNAMBOL-TEAMTASK"), element.c_str());
        vo->addProperty(vp);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?