appointmentbuilder.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,079 行 · 第 1/3 页
CPP
1,079 行
if (ststart.wHour == 0 && ststart.wMinute == 0 &&
stend.wHour == 23 && stend.wMinute == 59)
ret = TRUE;
return ret;
}
void copyFields(IAppointment *pAppointmentExc, IAppointment *pAppointmentCopy) {
BSTR element = NULL;
pAppointmentExc->get_Subject(&element);
pAppointmentCopy->put_Subject(element);
SysFreeString(element);
pAppointmentExc->get_Location(&element);
pAppointmentCopy->put_Location(element);
SysFreeString(element);
pAppointmentExc->get_Body(&element);
pAppointmentCopy->put_Body(element);
SysFreeString(element);
DATE d;
pAppointmentExc->get_Start(&d);
pAppointmentCopy->put_Start(d);
pAppointmentExc->get_End(&d);
pAppointmentCopy->put_End(d);
VARIANT_BOOL vbool;
pAppointmentExc->get_AllDayEvent(&vbool);
pAppointmentCopy->put_AllDayEvent(vbool);
pAppointmentExc->get_ReminderSet(&vbool);
pAppointmentCopy->put_ReminderSet(vbool);
long elementLong = 0;
pAppointmentExc->get_BusyStatus(&elementLong);
pAppointmentCopy->put_BusyStatus(elementLong);
pAppointmentExc->get_ReminderMinutesBeforeStart(&elementLong);
pAppointmentCopy->put_ReminderMinutesBeforeStart(elementLong);
}
/*
* . Scan all the appointment and get the ones with recurrences
* . If there are any that are with exceptions remove them
* .
*/
BOOL normalizeAppointmentExceptions(IP_OUTLOOK_APP* polApp) {
IPOutlookItemCollection *pItems;
IAppointment *pAppointment;
IFolder *pFolder;
VARIANT_BOOL variantBool = FALSE;
polApp->GetDefaultFolder (olFolderCalendar, &pFolder);
pFolder->get_Items (&pItems);
int currentCountItems = 0;
pItems->get_Count(¤tCountItems);
for (int i = 0; i < currentCountItems; i++) {
VARIANT_BOOL isRecurring;
pItems->Item (i + 1, (IDispatch**)&pAppointment);
pAppointment->get_IsRecurring(&isRecurring);
if (isRecurring >= 0) { // VARIANT_BOOL true is -1. If not recurring continue
pAppointment->Release();
continue;
}
IRecurrencePattern *pRecurrence;
pAppointment->GetRecurrencePattern (&pRecurrence);
IExceptions* pExceptions;
int numExceptions;
pRecurrence->get_Exceptions(&pExceptions);
if (!pExceptions) { // there are no exception in this occurrence
continue;
}
pExceptions->get_Count(&numExceptions);
for (int i = 0; i < numExceptions; i++) {
IException* pException;
pExceptions->Item(i + 1, &pException);
// if the recurrence is deleted get the deletion and continue to the next appointment
VARIANT_BOOL isDeleted;
pException->get_Deleted(&isDeleted);
if (isDeleted == -1) {
pException->Release();
continue;
}
IAppointment* pAppointmentExc, *pAppointmentCopy, *pAppointmentNew;
pException->get_AppointmentItem(&pAppointmentExc);
HRESULT h = pAppointment->Copy(&pAppointmentCopy);
// copy the fields from the pAppintmentExc to the pAppointmentCopy
copyFields(pAppointmentExc, pAppointmentCopy);
pAppointmentExc->Delete();
pAppointmentExc->Release();
pAppointmentCopy->Save();
/*
* There is an exception in ClearRecurrencePattern on the copy appointment.
* it is safe to open a new appointment object
*/
long oid = 0;
h = pAppointmentCopy->get_Oid(&oid);
pAppointmentCopy->Release();
polApp->GetItemFromOid (oid, (IDispatch**)&pAppointmentNew);
if (pAppointmentNew) {
h = pAppointmentNew->ClearRecurrencePattern();
pAppointmentNew->Save();
pAppointmentNew->Release();
} else {
LOG.error("Appointment normalization: it is impossible to clear the pattern %i", oid);
}
pException->Release();
}
pExceptions->Release();
pRecurrence->Release();
pAppointment->Release();
}
pFolder->Release();
pItems->Release();
return TRUE;
}
/*
* The method calculate the CRC hash value for the appointment item.
* It create the XML structure and calculate the crc value.
* Use to compare for understand the modified value!
*
* @param pAppointment : the appointment object that contain every value
*/
long calculateAppointmentHash (IAppointment* pAppointment) {
wstring p;
populateAppointmentStringItem(p, pAppointment, TRUE);
long l = stringCrc32(p.data());
return l;
}
WinItem* appointmentToWinEvent(IItem *pAppointment, bool isSif) {
//MessageBox (NULL, TEXT("appbuilder"), TEXT("title"), MB_SETFOREGROUND |MB_OK);
HRESULT hr = E_FAIL;
CEPROPVAL *prgPropvalPoom = NULL;
ULONG cbBuffer = 0;
HANDLE hHeap = GetProcessHeap();
WinEvent* winE = NULL;
WinRecurrence* winRec = NULL;
IAppointment* pAppointmentOld = NULL;
IRecurrencePattern* pRecurrence = NULL;
IExceptions* pExceptions = NULL;
int numExceptions = 0;
bool isAllDay = false;
bool isRecurring = false;
wchar_t tempValue[10];
wstring value, start;
if (isSif) { winE = new WinEventSIF(); }
else { winE = new WinEvent() ; }
cbBuffer = 0;
hr = pAppointment->GetProps(PIMPR_props_app, CEDB_ALLOWREALLOC, NUM_COLS_APP, &prgPropvalPoom, &cbBuffer, hHeap);
if(FAILED(hr) || NULL == prgPropvalPoom || 0 == cbBuffer) {
goto Exit;
}
//
// Fill all appointment properties
//
for (int i = 0; i < ePIMPR_RECURRING_TYPE; i++) {
switch (i)
{
case ePIMPR_ALL_DAY_EVENT:
{
int tmp = getIntPropertyFromMapi(&prgPropvalPoom[i]);
wsprintf(tempValue, TEXT("%d"), tmp);
value = tempValue;
if (value == TEXT("1")) {
isAllDay = true;
}
break;
}
case ePIMPR_IS_RECURRING:
{
int tmp = getIntPropertyFromMapi(&prgPropvalPoom[i]);
wsprintf(tempValue, TEXT("%d"), tmp);
value = tempValue;
if (value == TEXT("1")) {
isRecurring = true;
}
break;
}
case ePIMPR_START:
case ePIMPR_END:
{
// Date values: "yyyyMMdd" or "YYYYMMDDThhmmssZ"
value = getDatePropertyFromMapi(&prgPropvalPoom[i], !isAllDay, isAllDay);
break;
}
case ePIMPR_SENSITIVITY:
case ePIMPR_REMINDER_SET:
case ePIMPR_REMINDER_OPTIONS:
//case ePIMPR_DURATION:
case ePIMPR_BUSY_STATUS:
case ePIMPR_REMINDER_MINUTES_BEFORE_START:
case ePIMPR_MEETING_STATUS:
{
// Int values.
int tmp = getIntPropertyFromMapi(&prgPropvalPoom[i]);
wsprintf(tempValue, TEXT("%d"), tmp);
value = tempValue;
break;
}
case ePIMPR_TIMEZONE:
{
// Timezone: if set, recurring props are sent in local time.
// We pass the tz structure to API.
TIME_ZONE_INFORMATION* tz = readTimezoneFromMapi(&prgPropvalPoom[i]);
if (tz) {
winE->setTimezone(tz);
delete [] tz;
}
continue;
}
default:
{
// String values.
value = getStringPropertyFromMapi(&prgPropvalPoom[i]);
break;
}
}
winE->setProperty(appointmentFields[i], value);
//LOG.info("%2d) %ls = \"%ls\"", i+1, appointmentFields[i], value.c_str());
}
if (!isRecurring) {
goto Exit;
}
//
// Manage recurring properties: need to retrieve all values together
// ---------------------------- to apply safe checks and conversions.
//
winRec = winE->getRecPattern();
if (!winRec) {
goto Exit;
}
winE->getProperty(TEXT("Start"), start);
setWinRecurrenceProps(*winRec, prgPropvalPoom, ePIMPR_RECURRING_TYPE, start, isAllDay, true);
//
// Exceptions. Use old style IAppointment interface.
// -----------
long oid = 0;
hr = pAppointment->get_Oid(&oid);
if (!oid || FAILED(hr)) { goto Exit; }
IP_OUTLOOK_APP* pOutlookApp = getOutlookApp();
if (!pOutlookApp) { goto Exit; }
hr = pOutlookApp->GetItemFromOid(oid, (IDispatch**)&pAppointmentOld);
if (!pAppointmentOld || FAILED(hr)) { goto Exit; }
hr = pAppointmentOld->GetRecurrencePattern(&pRecurrence);
if (!pRecurrence || FAILED(hr)) { goto Exit; }
hr = pRecurrence->get_Exceptions(&pExceptions);
if (!pExceptions || FAILED(hr)) { goto Exit; }
pExceptions->get_Count(&numExceptions);
if (numExceptions == 0) {
goto Exit;
}
DATE startDate = NULL;
systemTimeToDouble(start.c_str(), &startDate, NULL);
// Push all EXDATEs into WinEvent list (we have only EXDATEs)
for (int i=0; i < numExceptions; i++) {
IException* pException;
hr = pExceptions->Item(i + 1, &pException);
if (!pException || FAILED(hr)) { goto Exit; }
wstring exception = createException(pException, startDate, isAllDay);
winE->getExcludeDates()->push_back(exception);
pException->Release();
}
Exit:
// Release objects.
if (pExceptions) { pExceptions->Release(); }
if (pRecurrence) { pRecurrence->Release(); }
if (pAppointmentOld) { pAppointmentOld->Release();}
// Free memory.
HeapFree(hHeap, 0, prgPropvalPoom);
return winE;
}
HRESULT winEventToAppointment(WinEvent& winE, IItem *pAppointment, const wstring& path, long oidToUpdate) {
HRESULT hr = E_FAIL;
int incNumProp = 0;
bool exists = false;
WinRecurrence* winRec = NULL;
IAppointment* pAppointmentOld = NULL;
IRecurrencePattern* pRecurrence = NULL;
CEPROPVAL *prgPropvalPoom = new CEPROPVAL[NUM_COLS_APP]; // Warning: allocation of CEPROPVAL array is critical...
IP_OUTLOOK_APP* pOutlookApp = NULL;
FILETIME date;
wstring start, end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?