⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appointmentbuilder.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
 * 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 "pim/AppointmentBuilder.h"
#include "base/Log.h"
#include "pim/difftime.h"
#include "pim/UtilsRecurrence.h"

/*
* Method to populate the appointment XML structure.
* It get every property name and value and build the XML structure to exchange with server.
*
* @param appointmentStringItem : the string that will contain the xml structure
* @param pAppointment          : the appointment object that contain every value
*
*/
void populateAppointmentStringItem(std::wstring &appointmentStringItem, IAppointment *pAppointment, BOOL isCRC) {

    BSTR element        = NULL      ;
    long elementLong    = 0         ;
    DATE startdate      = NULL      ;
    DATE enddate        = NULL      ;
    DATE date           = NULL      ;
    wstring element_s;

    //
    // FOR RECURRENCE
    // to get if a modification in the UTC goes into day before or after
    // store the initial value of day and check the last value
    //
    int x = 0, y = 0, z = 0;
    BOOL changeDay = FALSE, isBackward = FALSE;
    BOOL changeYearBackward = FALSE, changeYearForward = FALSE;


    VARIANT_BOOL variantBool = NULL; // 0==false -1==true
    wchar_t tempDate [DIM_LOCAL_TEMP];
    wchar_t* charBlob = NULL;

    appointmentStringItem = TEXT("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    appointmentStringItem +=  TEXT("<appointment>");

        // BSTR
        pAppointment->get_Subject(&element);
        element_s = wstring(element);
        encodeSpecialChar(element_s);
        appointmentStringItem  += TEXT("<Subject>") + element_s + TEXT("</Subject>");
        SysFreeString(element);

        pAppointment->get_Location(&element);
        element_s = wstring(element); encodeSpecialChar(element_s);
        appointmentStringItem  += TEXT("<Location>") + element_s + TEXT("</Location>");
        SysFreeString(element);

        pAppointment->get_Categories(&element);
        element_s = wstring(element); encodeSpecialChar(element_s);
        appointmentStringItem  +=  TEXT("<Categories>") + element_s + TEXT("</Categories>");
        SysFreeString(element);

        pAppointment->get_ReminderSoundFile(&element);
        element_s = wstring(element); encodeSpecialChar(element_s);
        appointmentStringItem  +=  TEXT("<ReminderSoundFile>") + element_s + TEXT("</ReminderSoundFile>");
        SysFreeString(element);

        pAppointment->get_Body(&element);
        removeEndCarriage(&element);
        element_s = wstring(element);  encodeSpecialChar(element_s);
        appointmentStringItem  +=  TEXT("<Body>") + element_s + TEXT("</Body>");
        SysFreeString(element);

        // DATE
        pAppointment->get_Start(&startdate);
        pAppointment->get_End(&enddate);


        /*
        * see the start and end date. If the start is 00:00 and end is 23:59 the appointment is decided to be
        * an all day event. So the AllDayEvent tag is put to 'true' only in the SIF structure. The format of the date
        * is like the birthday: yyyy-MM-dd
        *
        */

        BOOL isAllDay = FALSE;

        if (isWindowsMobile5()) {
            pAppointment->get_AllDayEvent(&variantBool);
            variantBool == -1 ? isAllDay = TRUE : isAllDay = FALSE;

            if (isAllDay)
                enddate -= 1; // to be decremented of a day if it is all day in windows mobile 5.
                // This because the end date is 00:00:00 of the next day. we want the all day
                // is represented as <startDate>2007-01-15</StartDate> and and date as the same

        } else {
            isAllDayEvent(startdate, enddate);
        }


        wsprintf(tempDate, TEXT(""));
        double toCompare = MAX_DATE_DOUBLE;
        double toCompare4000 = MAX_DATE_DOUBLE_4000;

        SYSTEMTIME st;

        if (startdate != toCompare) {
            VariantTimeToSystemTime(startdate, &st);
            x = st.wHour;
            localTimeToUTC(st);
            y = st.wHour;
            if (isAllDay) {
                doubleToSystemTimeBirthday(tempDate, startdate);
            } else {
                doubleToSystemTime(tempDate, startdate);
            }
        }
        appointmentStringItem  = appointmentStringItem + TEXT("<Start>") + tempDate + TEXT("</Start>");

        wsprintf(tempDate, TEXT(""));
        if (enddate != toCompare) {
            if (isAllDay) {
                doubleToSystemTimeBirthday(tempDate, enddate);
            } else {
                doubleToSystemTime(tempDate, enddate);
            }
        }
        appointmentStringItem  = appointmentStringItem + TEXT("<End>") + tempDate + TEXT("</End>");

        if (isAllDay) {
            wsprintf(tempDate, TEXT("1")); // TRUE
        } else {
            wsprintf(tempDate, TEXT("0")); // TRUE
        }
        appointmentStringItem  = appointmentStringItem + TEXT("<AllDayEvent>") + tempDate + TEXT("</AllDayEvent>");

        pAppointment->get_ReminderSet(&variantBool);
        wsprintf(tempDate, TEXT("%i"), variantBool);
        normalizeBoolean(tempDate);
        appointmentStringItem  = appointmentStringItem + TEXT("<ReminderSet>") + tempDate + TEXT("</ReminderSet>");

        // long
        //pAppointment->get_Duration(&elementLong);
        //wsprintf(tempDate, TEXT("%i"), elementLong);
        //appointmentStringItem  = appointmentStringItem + TEXT("<Duration>") + tempDate + TEXT("</Duration>");

        pAppointment->get_BusyStatus(&elementLong);
        wsprintf(tempDate, TEXT("%i"), elementLong);
        appointmentStringItem  = appointmentStringItem + TEXT("<BusyStatus>") + tempDate + TEXT("</BusyStatus>");

        pAppointment->get_Sensitivity(&elementLong);
        wsprintf(tempDate, TEXT("%i"), elementLong);
        appointmentStringItem  = appointmentStringItem + TEXT("<Sensitivity>") + tempDate + TEXT("</Sensitivity>");

        pAppointment->get_ReminderOptions(&elementLong);
        wsprintf(tempDate, TEXT("%i"), elementLong);
        appointmentStringItem  = appointmentStringItem + TEXT("<ReminderOptions>") + tempDate + TEXT("</ReminderOptions>");

        pAppointment->get_ReminderMinutesBeforeStart(&elementLong);
        wsprintf(tempDate, TEXT("%i"), elementLong);
        appointmentStringItem  = appointmentStringItem + TEXT("<ReminderMinutesBeforeStart>") + tempDate + TEXT("</ReminderMinutesBeforeStart>");


        /******************************************************/

        //Recurrence
        VARIANT_BOOL isRecurring;
        pAppointment->get_IsRecurring(&isRecurring);
        wsprintf(tempDate, TEXT("%i"), isRecurring);
        normalizeBoolean(tempDate);
        appointmentStringItem  = appointmentStringItem + TEXT("<IsRecurring>") + tempDate + TEXT("</IsRecurring>");

        IRecurrencePattern *pRecurrence;
        pAppointment->GetRecurrencePattern (&pRecurrence);

        wstring recurrence = L"";
        if (!isCRC || isRecurring == -1) { // variant bool to say TRUE
            recurrence = getRecurrenceTags(pRecurrence, isRecurring, x, y, olFolderCalendar, startdate, isAllDay);
        }
        // handle recurrence and exceptions events
        // wstring recurrence = getRecurrenceTags(pRecurrence, isRecurring, x, y, olFolderCalendar, startdate, isAllDay);

        pRecurrence->Release();

    appointmentStringItem += recurrence;
    appointmentStringItem = appointmentStringItem +  TEXT("</appointment>");

}

/*
wstring createExceptions(IRecurrencePattern* pRecurrence) {

    IExceptions* pExceptions;
    int numExceptions;

    pRecurrence->get_Exceptions(&pExceptions);
    pExceptions->get_Count(&numExceptions);
    wchar_t temp [DIM_LOCAL_TEMP];

    wstring exceptions = TEXT("<Exceptions>");
        wsprintf(temp, TEXT("<ExceptionNumber>%i</ExceptionNumber>"), numExceptions);
        exceptions += wstring(temp);

    for (int i = 0; i < numExceptions; i++) {
        IException* pException;
        pExceptions->Item(i + 1, &pException);
        wstring exception = createException(pException);
        exceptions += exception;
        pException->Release();
    }

    pExceptions->Release();

    exceptions +=  TEXT("</Exceptions>");

    return exceptions;
}

wstring createException(IException* pException) {

    wstring exceptionItem = TEXT("<Exception>");
    DATE originalDate = 0;
    VARIANT_BOOL varBool; // -1 = TRUE, 0 = FALSE
    SYSTEMTIME st;
    memset(&st, 0, sizeof(SYSTEMTIME));
    BSTR element        = NULL      ;
    wchar_t tempDate [DIM_LOCAL_TEMP];
    wstring element_s;

    pException->get_OriginalDate(&originalDate);
    doubleToSystemTimeBirthday(tempDate, originalDate);    // YYYY-MM-DD

    exceptionItem += TEXT("<OriginalDate>") + wstring(tempDate) + TEXT("</OriginalDate>");

    // if the recurrence is deleted get the delation and go exit
    pException->get_Deleted(&varBool);
    if (varBool == -1)
        goto finally;

    exceptionItem += TEXT("<ExAppointment>");
    IAppointment* pAppointment;
    pException->get_AppointmentItem(&pAppointment);

        pAppointment->get_Subject(&element);
        element_s = wstring(element);
        encodeSpecialChar(element_s);
        exceptionItem  += TEXT("<ExSubject>") + element_s + TEXT("</ExSubject>");
        SysFreeString(element); element = NULL;

        pAppointment->get_Location(&element);
        element_s = wstring(element);
        encodeSpecialChar(element_s);
        exceptionItem  += TEXT("<ExLocation>") + element_s + TEXT("</ExLocation>");
        SysFreeString(element); element = NULL;

        pAppointment->get_Body(&element);
        removeEndCarriage(&element);
        element_s = wstring(element);  encodeSpecialChar(element_s);
        exceptionItem  +=  TEXT("<ExBody>") + element_s + TEXT("</ExBody>");
        SysFreeString(element);

         // VARIANT

        pAppointment->get_AllDayEvent(&varBool);
        wsprintf(tempDate, TEXT("%i"), varBool);
        if (varBool == -1) {
            wsprintf(tempDate, TEXT("1")); // TRUE
        }
        exceptionItem  += TEXT("<ExAllDayEvent>") + wstring(tempDate) + TEXT("</ExAllDayEvent>");

        // DATE
        DATE startdate;
        DATE enddate;
        pAppointment->get_Start(&startdate);
        pAppointment->get_End(&enddate);

        //BOOL isAllDay = isAllDayEvent(startdate, enddate);
        BOOL isAllDay = varBool == -1 ? TRUE : FALSE;

        wsprintf(tempDate, TEXT(""));

        VariantTimeToSystemTime(startdate, &st);
        if (isAllDay) {
            doubleToSystemTimeBirthday(tempDate, startdate);
        } else {
            doubleToSystemTime(tempDate, startdate);
        }

        exceptionItem  += TEXT("<ExStart>") + wstring(tempDate) + TEXT("</ExStart>");
        wsprintf(tempDate, TEXT(""));

        if (isAllDay) {
            doubleToSystemTimeBirthday(tempDate, enddate);
        } else {
            doubleToSystemTime(tempDate, enddate);
        }

        exceptionItem += TEXT("<ExEnd>") + wstring(tempDate) + TEXT("</ExEnd>");

        long elementLong = 0;
        pAppointment->get_BusyStatus(&elementLong);
        wsprintf(tempDate, TEXT("%i"), elementLong);
        exceptionItem  += TEXT("<ExBusyStatus>") + wstring(tempDate) + TEXT("</ExBusyStatus>");

    if (pAppointment)
        pAppointment->Release();

   exceptionItem += TEXT("</ExAppointment>");
finally:

    exceptionItem += TEXT("</Exception>");
    return exceptionItem;

}
*/

/*
* Method that complete an appointment object retrieving property value by an XML structure.
* It parse the XML structure, get the every property value using its name and set it into the object.
*
* @param pAppointment : the appointment object that contain every value
* @param ptrData      : the variable that contain the xml structure
*/

void completeAppointment(IAppointment *pAppointment, wchar_t *ptrData, IP_OUTLOOK_APP* polApp, wchar_t* path) {

    wchar_t* dummy                  = NULL;
    wchar_t* dummyEvent             = NULL;
    wstring  dummyEvent_s;
    VARIANT_BOOL isNotAllDayEvent   = TRUE;
      
    //
    // FOR RECURRENCE
    // to get if a modification in the UTC goes into day before or after
    // store the initial value of day and check the last value
    //
    int x = 0, y = 0, z = 0;
    BOOL changeDay = FALSE, isBackward = FALSE;
    BOOL changeYearBackward = FALSE, changeYearForward = FALSE;

    //VARIANT_BOOL --- AllDayEvent
    dummyEvent = getElementContent(ptrData, TEXT ("AllDayEvent"), NULL);

    if (dummyEvent != NULL &&
        (wcscmp(dummyEvent, TEXT("1")) == 0 ||
         wcscmp(dummyEvent, TEXT("-1")) == 0 || // kept to be compliant with old client. Now TRUE is represented
         wcscmp(dummyEvent, TEXT("True")) == 0)) {  // with "1" only

        if (isWindowsMobile5()) {
            pAppointment->put_AllDayEvent(TRUE);
        } else {
            pAppointment->put_AllDayEvent(FALSE);
        }

        double locDate = NULL;

        dummyEvent = getElementContent(ptrData, TEXT ("Start"), NULL);

        DATE st;
        SYSTEMTIME systemTime;
        BOOL isUTC = FALSE;
        BOOL isAllDayFormat = isDateForAllDayEventFormat(dummyEvent);

        if (isAllDayFormat) {
            systemTimeToDoubleBirthFormat(dummyEvent, &st, TEXT("START"));

        }  else { // the date is in the usual format

            isUTC = getDateAndTimeAsIs(dummyEvent, &st);

            VariantTimeToSystemTime(st, &systemTime);
            x = systemTime.wHour;
            if (isUTC) {
                UTCToLocalTime2(systemTime);
            }
            y = systemTime.wHour;
            systemTime.wHour = 0;
            systemTime.wMinute = 0;
            systemTime.wMilliseconds = 0;
            SystemTimeToVariantTime(&systemTime, &st);
        }
        pAppointment->put_Start(st);

⌨️ 快捷键说明

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