taskbuilder.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 827 行 · 第 1/2 页
CPP
827 行
/*
* 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 "pim/TaskBuilder.h"
#include "pim/UtilsRecurrence.h"
#include "pim/MAPIUtils.h"
#include "base/util/utils.h"
/**
* Enumeration of task fields used by WM plugin.
* @note Don't change the order of these properties!
* This list MUST be synchronized with PIMPR_props_task array of CEPROPID fields.
*/
enum {
ePIMPR_SUBJECT ,
ePIMPR_SENSITIVITY ,
ePIMPR_IS_RECURRING ,
ePIMPR_REMINDER_SET ,
// ePIMPR_REMINDER_SOUND_FILE ,
ePIMPR_REMINDER_OPTIONS ,
ePIMPR_IMPORTANCE ,
ePIMPR_TEAM_TASK ,
ePIMPR_START_DATE ,
ePIMPR_DUE_DATE ,
ePIMPR_DATE_COMPLETED ,
ePIMPR_COMPLETE ,
ePIMPR_REMINDER_TIME ,
// ePIMPR_RECURRING_REGENERATING ,
ePIMPR_CATEGORIES ,
ePIMPR_BODY_TEXT ,
// --- Recurring fields from here ---
ePIMPR_RECURRING_TYPE ,
ePIMPR_RECURRING_PATTERNSTARTDATE ,
ePIMPR_RECURRING_PATTERNENDDATE ,
// ePIMPR_RECURRING_STARTTIME ,
// ePIMPR_RECURRING_ENDTIME ,
ePIMPR_RECURRING_NOEND ,
ePIMPR_RECURRING_OCCURRENCES ,
ePIMPR_RECURRING_INTERVAL ,
ePIMPR_RECURRING_DAYOFWEEKMASK ,
ePIMPR_RECURRING_DAYOFMONTH ,
ePIMPR_RECURRING_INSTANCE ,
// ePIMPR_RECURRING_DURATION ,
ePIMPR_RECURRING_MONTHOFYEAR ,
// This is the total number of appointment properties supported (including recurring ones)
NUM_COLS_TASK
};
/**
* Array of task fields used by WM plugin.
* ***************************************
*
* Recurring properties are appended at the end.
* @note Don't change the order of these properties!
*/
static CEPROPID PIMPR_props_task[] = {
PIMPR_SUBJECT ,
PIMPR_SENSITIVITY ,
PIMPR_IS_RECURRING ,
PIMPR_REMINDER_SET ,
// PIMPR_REMINDER_SOUND_FILE ,
PIMPR_REMINDER_OPTIONS ,
PIMPR_IMPORTANCE ,
PIMPR_TEAM_TASK ,
PIMPR_START_DATE ,
PIMPR_DUE_DATE ,
PIMPR_DATE_COMPLETED ,
PIMPR_COMPLETE ,
PIMPR_REMINDER_TIME ,
// PIMPR_RECURRING_REGENERATING ,
PIMPR_CATEGORIES ,
PIMPR_BODY_TEXT ,
// --- Recurring fields from here ---
PIMPR_RECURRING_TYPE ,
PIMPR_RECURRING_PATTERNSTARTDATE ,
PIMPR_RECURRING_PATTERNENDDATE ,
// PIMPR_RECURRING_STARTTIME ,
// PIMPR_RECURRING_ENDTIME ,
PIMPR_RECURRING_NOEND ,
PIMPR_RECURRING_OCCURRENCES ,
PIMPR_RECURRING_INTERVAL ,
PIMPR_RECURRING_DAYOFWEEKMASK ,
PIMPR_RECURRING_DAYOFMONTH ,
PIMPR_RECURRING_INSTANCE ,
// PIMPR_RECURRING_DURATION ,
PIMPR_RECURRING_MONTHOFYEAR
};
/**
* Array of task fields names for SIF format.
* Recurring fields are listed in recurrenceFields[] array.
* @note Don't change the order of these properties!
* This list MUST be synchronized with PIMPR_props_task array of CEPROPID fields.
*/
const wchar_t* taskFields[] = {
{L"Subject" }, // Returns or sets the subject for the Outlook item. This property corresponds to the MAPI property PR_SUBJECT. The Subject property is the default property for Outlook items.
{L"Sensitivity" }, // Returns or sets the sensitivity for the Outlook item. Can be one of the following OlSensitivity constants: olConfidential(3), olNormal(0), olPersonal(1), or olPrivate(2). This property corresponds to the MAPI property PR_SENSITIVITY
{L"IsRecurring" }, // True if the appointment or task is a recurring appointment or task. When the GetRecurrencePattern method is used with an AppointmentItem or TaskItem object, this property is set to True
{L"ReminderSet" }, // True if a reminder has been set for this appointment, mail item or task.
// {L"ReminderSoundFile" }, // Returns or sets the path and filename of the sound file to play when the reminder occurs for the appointment or task. This property is only valid if the ReminderOverrideDefault and ReminderPlaySound properties are set to True
{L"ReminderOptions" }, // What actions to take when the reminder occurs. (LED=1, Vibrate=2, Dialog=4, Sound=8, Repeat=16)
{L"Importance" }, // Returns or sets the relative importance level for the Outlook item. Can be one of the following OlImportance constants: olImportanceHigh(2), olImportanceLow(0), or olImportanceNormal(1). This property corresponds to the MAPI property PR_IMPORTANCE.
{L"TeamTask" }, // True if the task is a team task
{L"StartDate" }, // Returns or sets the starting date and time for the task
{L"DueDate" }, // Returns or sets a Date indicating the due date for the task.
{L"DateCompleted" }, // Returns or sets the completion date of the task
{L"Complete" }, // True if the task is completed
{L"ReminderTime" }, // Returns or sets the date and time at which the reminder should occur for this item.
// {L"RecurringRegenerating" }, // A value indicating whether the task recurs after it has been marked as completed.
{L"Categories" }, // Returns or sets the categories assigned to the Outlook item.
{L"Body" }, // Returns or sets the clear-text body of the Outlook item.
{NULL}
};
/*
* 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) {
// We use local time "YYYYMMDDThhmmss" (since 6.5.6)
doubleToSystemTimeHourZero(tempDate, date, FALSE, FALSE);
}
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);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?