📄 taskbuilder.cpp
字号:
/*
* 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
*/
//
// @author Marco Magistrali
//
#include "pim/TaskBuilder.h"
/*
* Method to populate the task XML structure.
* It get every property name and value and build the XML structure to exchange with server.
*
* @param taskStringItem : the string that will contain the xml structure
* @param pTask : the task object that contain every value
* @param isCRC : it says if the sif is calculated for the crc or not. If we are looking at the crc
* we have to consider the recurrence fields only if the task is recurring
*/
void populateTaskStringItem (std::wstring &taskStringItem, ITask *pTask, BOOL isCRC) {
BSTR element = NULL;
long elementLong = 0;
DATE date = NULL, startdate = NULL;
std::wstring element_s;
VARIANT_BOOL variantBool = NULL; // 0==false -1==true
wchar_t tempDate [DIM_LOCAL_TEMP];
wchar_t* charBlob = NULL;
//
// 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;
taskStringItem = TEXT("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
taskStringItem += TEXT("<task>");
// BSTR
pTask->get_Subject(&element);
element_s = std::wstring(element); encodeSpecialChar(element_s);
taskStringItem += TEXT("<Subject>") + element_s + TEXT("</Subject>");
SysFreeString(element);
pTask->get_Categories(&element);
element_s = std::wstring(element); encodeSpecialChar(element_s);
taskStringItem += TEXT("<Categories>") + element_s + TEXT("</Categories>");
SysFreeString(element);
pTask->get_ReminderSoundFile(&element);
element_s = (std::wstring)element; encodeSpecialChar(element_s);
taskStringItem += TEXT("<ReminderSoundFile>") + element_s + TEXT("</ReminderSoundFile>");
SysFreeString(element);
pTask->get_Body(&element);
removeEndCarriage(&element);
element_s = wstring(element); encodeSpecialChar(element_s);
taskStringItem += TEXT("<Body>") + element_s + TEXT("</Body>");
SysFreeString(element);
// VARIANT_BOOL
pTask->get_ReminderSet(&variantBool);
wsprintf(tempDate, TEXT("%i"), variantBool);
normalizeBoolean(tempDate);
taskStringItem += TEXT("<ReminderSet>") + wstring(tempDate) + TEXT("</ReminderSet>");
pTask->get_Complete(&variantBool);
wsprintf(tempDate, TEXT("%i"), variantBool);
normalizeBoolean(tempDate);
taskStringItem += TEXT("<Complete>") + wstring(tempDate) + TEXT("</Complete>");
pTask->get_TeamTask(&variantBool);
wsprintf(tempDate, TEXT("%i"), variantBool);
normalizeBoolean(tempDate);
taskStringItem += TEXT("<TeamTask>") + wstring(tempDate) + TEXT("</TeamTask>");
// DATE
pTask->get_StartDate(&startdate);
wsprintf(tempDate, TEXT(""));
double toCompare = MAX_DATE_DOUBLE;
double toCompare4000 = MAX_DATE_DOUBLE_4000;
SYSTEMTIME st;
if (startdate != toCompare) {
doubleToSystemTimeBirthday(tempDate, startdate);
//doubleToSystemTime(tempDate, date);
VariantTimeToSystemTime(startdate, &st);
x = st.wHour;
localTimeToUTC(st);
y = st.wHour;
}
taskStringItem += TEXT("<StartDate>") + wstring(tempDate) + TEXT("</StartDate>");
pTask->get_DueDate(&date);
wsprintf(tempDate, TEXT(""));
if (date != toCompare) {
doubleToSystemTimeBirthday(tempDate, date);
//doubleToSystemTime(tempDate, date);
}
taskStringItem += TEXT("<DueDate>") + wstring(tempDate) + TEXT("</DueDate>");
/*
pTask->get_DateCompleted(&date);
wsprintf(tempDate, TEXT(""));
if (date != toCompare) {
doubleToSystemTime(tempDate, date);
}
taskStringItem = taskStringItem + TEXT("<DateCompleted>") + tempDate + TEXT("</DateCompleted>");
*/
pTask->get_ReminderTime(&date);
wsprintf(tempDate, TEXT(""));
if (date != toCompare) {
doubleToSystemTime(tempDate, date);
}
taskStringItem += TEXT("<ReminderTime>") + wstring(tempDate) + TEXT("</ReminderTime>");
// long
pTask->get_Sensitivity(&elementLong);
wsprintf(tempDate, TEXT("%i"), elementLong);
taskStringItem += TEXT("<Sensitivity>") + wstring(tempDate) + TEXT("</Sensitivity>");
pTask->get_ReminderOptions(&elementLong);
wsprintf(tempDate, TEXT("%i"), elementLong);
taskStringItem += TEXT("<ReminderOptions>") + wstring(tempDate) + TEXT("</ReminderOptions>");
pTask->get_Importance(&elementLong);
wsprintf(tempDate, TEXT("%i"), elementLong);
taskStringItem += TEXT("<Importance>") + wstring(tempDate) + TEXT("</Importance>");
/******************************************************/
//Recurrence
VARIANT_BOOL isRecurring;
pTask->get_IsRecurring(&isRecurring);
wsprintf(tempDate, TEXT("%i"), isRecurring);
normalizeBoolean(tempDate);
taskStringItem += TEXT("<IsRecurring>") + wstring(tempDate) + TEXT("</IsRecurring>");
IRecurrencePattern *pRecurrence;
pTask->GetRecurrencePattern (&pRecurrence);
wstring recurrence = L"";
if (!isCRC || isRecurring == -1) { // variant bool to say TRUE
recurrence = getRecurrenceTags(pRecurrence, isRecurring, 0, 0, olFolderTasks, startdate, TRUE);
}
/*
long recurrenceType = 0,
interval = 0,
monthOfYear = 0,
dayOfMonth = 0,
dayOfWeekMask = 0,
instance = 0;
pRecurrence->get_RecurrenceType(&recurrenceType);
pRecurrence->get_Interval(&interval);
pRecurrence->get_MonthOfYear(&monthOfYear);
pRecurrence->get_DayOfMonth(&dayOfMonth);
pRecurrence->get_Instance(&instance);
pRecurrence->get_DayOfWeekMask(&dayOfWeekMask);
//
// Modification to get right information about changing day, month...
//
TIME_ZONE_INFORMATION tmz;
int k = GetTimeZoneInformation(&tmz);
z = (x-y) < 0 ? (x-y)*(-1) : (x-y) ;
//
// Change day?
//
changeDay = z > 12 ? TRUE : FALSE;
if (changeDay) {
if (tmz.Bias < 0)
isBackward = TRUE;
else
isBackward = FALSE;
}
if (recurrenceType < 0) {
recurrenceType = 0;
}
wsprintf(tempDate, TEXT("%i"), recurrenceType);
taskStringItem = taskStringItem + TEXT("<RecurrenceType>") + tempDate + TEXT("</RecurrenceType>");
pRecurrence->get_Interval(&elementLong);
wsprintf(tempDate, TEXT("%i"), elementLong);
taskStringItem = taskStringItem + TEXT("<Interval>") + tempDate + TEXT("</Interval>");
//
// Day of Month
//
if (dayOfMonth != 0) {
if (changeDay) {
if (isBackward) {
dayOfMonth = dayOfMonth - 1;
if (dayOfMonth == 0) {
if (monthOfYear == 5 || monthOfYear == 7 || monthOfYear == 10) {
// if May, July, October the month before has 30 days
dayOfMonth = 30;
} else {
dayOfMonth = 31;
}
changeYearBackward = TRUE;
}
} else { // is
dayOfMonth = dayOfMonth + 1;
if (dayOfMonth > 31 ||
(dayOfMonth == 31 &&
(monthOfYear == 4 || monthOfYear == 6 || monthOfYear == 9)
)
) {
dayOfMonth = 1;
changeYearForward = TRUE;
}
}
}
wsprintf(tempDate, TEXT("%i"), dayOfMonth);
taskStringItem = taskStringItem + TEXT("<DayOfMonth>") + tempDate + TEXT("</DayOfMonth>");
} else {
taskStringItem = taskStringItem + TEXT("<DayOfMonth>0</DayOfMonth>");
}
//
// Month of Year
//
if (monthOfYear != 0) {
if (changeYearBackward) {
monthOfYear = monthOfYear - 1;
if (monthOfYear == 0) {
monthOfYear = 12;
}
} else if (changeYearForward) {
monthOfYear = monthOfYear + 1;
if (monthOfYear > 12) {
monthOfYear = 1;
}
}
wsprintf(tempDate, TEXT("%i"), monthOfYear);
taskStringItem = taskStringItem + TEXT("<MonthOfYear>") + tempDate + TEXT("</MonthOfYear>");
} else {
taskStringItem = taskStringItem + TEXT("<MonthOfYear>0</MonthOfYear>");
}
//
// DayOfWeekMask
//
if (dayOfWeekMask != 0) {
if (changeDay) {
if (isBackward) {
dayOfWeekMask = convertDayOfWeekMaskBackward2(dayOfWeekMask);
} else {
dayOfWeekMask = convertDayOfWeekMaskForward2(dayOfWeekMask);
}
}
wsprintf(tempDate, TEXT("%i"), dayOfWeekMask);
taskStringItem = taskStringItem + TEXT("<DayOfWeekMask>") + tempDate + TEXT("</DayOfWeekMask>");
} else {
taskStringItem = taskStringItem + TEXT("<DayOfWeekMask>0</DayOfWeekMask>");
}
//
// Instance
//
if (instance != 0) {
wsprintf(tempDate, TEXT("%i"), instance);
taskStringItem = taskStringItem + TEXT("<Instance>") + tempDate + TEXT("</Instance>");
} else {
taskStringItem = taskStringItem + TEXT("<Instance>0</Instance>");
}
//
// Pattern Start Date
//
pRecurrence->get_PatternStartDate(&date);
wsprintf(tempDate, TEXT(""));
toCompare = MAX_DATE_DOUBLE;
if (date != toCompare && date < toCompare4000 ) {
doubleToSystemTime(tempDate, date);
}
taskStringItem = taskStringItem + TEXT("<PatternStartDate>") + tempDate + TEXT("</PatternStartDate>");
//
// No End Date
//
pRecurrence->get_NoEndDate(&variantBool);
wsprintf(tempDate, TEXT("%i"), variantBool);
normalizeBoolean(tempDate);
taskStringItem = taskStringItem + TEXT("<NoEndDate>") + tempDate + TEXT("</NoEndDate>");
//
// Pattern End Date
//
pRecurrence->get_PatternEndDate(&date);
wsprintf(tempDate, TEXT(""));
toCompare = MAX_DATE_DOUBLE;
if (date != toCompare && date < toCompare4000 ) {
doubleToSystemTime(tempDate, date);
}
taskStringItem = taskStringItem + TEXT("<PatternEndDate>") + tempDate + TEXT("</PatternEndDate>");
//
// Occurrences
//
pRecurrence->get_Occurrences(&elementLong);
if (elementLong < 0) {
elementLong = 0;
}
wsprintf(tempDate, TEXT("%i"), elementLong);
taskStringItem = taskStringItem + TEXT("<Occurrences>") + tempDate + TEXT("</Occurrences>");
*/
taskStringItem += recurrence;
taskStringItem += TEXT("</task>");
}
/*
* Method that complete an task 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 pTask : the task object that contain every value
* @param ptrData : the variable that contain the xml structure
*/
void completeTask (ITask *pTask, wchar_t * ptrData) {
wchar_t* dummy = NULL;
wchar_t* dummyEvent = NULL;
wstring dummyEvent_s;
//pTask->ClearRecurrencePattern ();
//VARIANT_BOOL -- ReminderSet
dummyEvent = getElementContent(ptrData, TEXT ("ReminderSet"), NULL);
if (dummyEvent != NULL &&
(wcscmp(dummyEvent, TEXT("1")) == 0 ||
wcscmp(dummyEvent, TEXT("-1")) == 0 ||
wcscmp(dummyEvent, TEXT("True")) == 0)) {
pTask->put_ReminderSet(VARIANT_TRUE);
if (dummyEvent != NULL) { delete [] dummyEvent; dummyEvent=NULL; }
dummyEvent = getElementContent(ptrData, TEXT ("ReminderTime"), NULL);
if (dummyEvent != NULL) {
DATE st;
systemTimeToDouble(dummyEvent, &st, NULL);
pTask->put_ReminderTime(st);
}
}
else {
pTask->put_ReminderSet(VARIANT_FALSE);
}
if (dummyEvent != NULL)
delete [] dummyEvent;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -