📄 appointmentbuilder.cpp
字号:
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;
}
VObject* AppointmentToVObject(IAppointment *pAppointment) {
BSTR element = NULL;
DATE startdate = NULL;
DATE enddate = NULL;
VObject* vo = new VObject();
VProperty* vp = NULL;
wchar_t* dateValue = new wchar_t[20];
vp = new VProperty(TEXT("BEGIN"), TEXT("VCALENDAR"));
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(TEXT("VERSION"), TEXT("2.0"));
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(TEXT("BEGIN"), TEXT("VEVENT"));
vo->addProperty(vp);
delete vp; vp = NULL;
pAppointment->get_Subject(&element);
if(wcscmp(element, TEXT(""))) {
vp = new VProperty(TEXT("SUMMARY"), element);
vo->addProperty(vp);
delete vp; vp = NULL;
}
pAppointment->get_Location(&element);
if(wcscmp(element, TEXT(""))) {
vp = new VProperty(TEXT("LOCATION"), element);
vo->addProperty(vp);
delete vp; vp = NULL;
}
pAppointment->get_Body(&element);
if(wcscmp(element, TEXT(""))) {
vp = new VProperty(TEXT("DESCRIPTION"), element);
vo->addProperty(vp);
delete vp; vp = NULL;
}
pAppointment->get_Start(&startdate);
dateValue[0] = 0;
doubleToSystemTime(dateValue, startdate);
vp = new VProperty(TEXT("DTSTART"), dateValue);
vo->addProperty(vp);
delete vp; vp = NULL;
pAppointment->get_End(&enddate);
dateValue[0] = 0;
doubleToSystemTime(dateValue, enddate);
vp = new VProperty(TEXT("DTEND"), dateValue);
vo->addProperty(vp);
delete [] vp; vp = NULL;
pAppointment->get_Categories(&element);
if(wcscmp(element, TEXT(""))) {
vp = new VProperty(TEXT("CATEGORIES"), element);
vo->addProperty(vp);
delete vp; vp = NULL;
}
long sensitivity;
pAppointment->get_Sensitivity(&sensitivity);
vp = new VProperty(TEXT("CLASS"));
if(sensitivity == olPrivate)
vp->addValue(TEXT("PRIVATE"));
else
vp->addValue(TEXT("PUBLIC"));
vo->addProperty(vp);
delete vp; vp = NULL;
IRecipients* pRecipients;
pAppointment->get_Recipients(&pRecipients);
int countRecipient = 0;
pRecipients->get_Count(&countRecipient);
for(int i = 0; i < countRecipient; i++) {
IRecipient* pRecipient;
pRecipients->Item(i + 1, &pRecipient);
wchar_t* attedee = new wchar_t[100];
pRecipient->get_Name(&element);
wcscat(attedee, element);
wcscat(attedee, TEXT(" "));
pRecipient->get_Address(&element);
wcscat(attedee, element);
vp = new VProperty(TEXT("ATTENDEE"), attedee);
vo->addProperty(vp);
delete vp; vp = NULL;
delete [] attedee; attedee = NULL;
pRecipient->Release();
}
pRecipients->Release();
if(dateValue)
{
delete [] dateValue; dateValue = NULL;
}
VARIANT_BOOL bReminder;
pAppointment->get_ReminderSet(&bReminder);
if(bReminder == VARIANT_TRUE) {
long minBefore;
pAppointment->get_ReminderMinutesBeforeStart(&minBefore);
double minStartDate = startdate * 1440;
//subtract the alarm
minStartDate -= minBefore;
if(dateValue)
{ delete [] dateValue; dateValue = NULL; }
dateValue = new wchar_t[30];
doubleToSystemTime(dateValue, minStartDate/1440);
vp = new VProperty(TEXT("AALARM"));
vp->addValue(dateValue); // "RunTime"
vp->addValue(TEXT("")); // "Snooze Time" (empty)
vp->addValue(TEXT("0")); // "Repeat Count"
vp->addValue(TEXT("reminder")); // "Audio Content"
vo->addProperty(vp);
delete vp; vp = NULL;
if(dateValue)
{ delete [] dateValue; dateValue = NULL; }
}
//recurrence
VARIANT_BOOL isRec;
pAppointment->get_IsRecurring(&isRec);
if(isRec == VARIANT_TRUE) {
IRecurrencePattern* pRecPat;
pAppointment->GetRecurrencePattern(& pRecPat);
wchar_t* recRule = NULL;
recRule = extractRrule(pRecPat);
if(recRule) {
vp = new VProperty(TEXT("RRULE"), recRule);
vo->addProperty(vp);
delete vp; vp = NULL;
delete [] recRule; recRule = NULL;
}
pRecPat->Release();
}
vp = new VProperty(TEXT("END"), TEXT("VEVENT"));
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(TEXT("END"), TEXT("VCALENDAR"));
vo->addProperty(vp);
delete vp; vp = NULL;
return vo;
}
void VObjectToAppointment(IAppointment *pAppointment, VObject *vo) {
int i = 0;
pAppointment->ClearRecurrencePattern ();
if(vo->containsProperty(TEXT("SUMMARY")) && vo->getProperty(TEXT("SUMMARY"))->getValue())
pAppointment->put_Subject(vo->getProperty(TEXT("SUMMARY"))->getValue());
if(vo->containsProperty(TEXT("LOCATION")) && vo->getProperty(TEXT("LOCATION"))->getValue())
pAppointment->put_Location(vo->getProperty(TEXT("LOCATION"))->getValue());
if(vo->containsProperty(TEXT("DESCRIPTION")) && vo->getProperty(TEXT("DESCRIPTION"))->getValue())
pAppointment->put_Body(vo->getProperty(TEXT("DESCRIPTION"))->getValue());
DATE startdate = NULL;
DATE enddate = NULL;
if(vo->containsProperty(TEXT("DTSTART")) && vo->getProperty(TEXT("DTSTART"))->getValue()) {
systemTimeToDouble(vo->getProperty(TEXT("DTSTART"))->getValue(), &startdate, NULL);
pAppointment->put_Start(startdate);
}
if(vo->containsProperty(TEXT("DTEND")) && vo->getProperty(TEXT("DTEND"))->getValue()) {
systemTimeToDouble(vo->getProperty(TEXT("DTEND"))->getValue(), &enddate, NULL);
pAppointment->put_End(enddate);
}
BOOL isAllDay = isAllDayEvent(startdate, enddate);
if(isAllDay)
pAppointment->put_AllDayEvent(VARIANT_TRUE);
else
pAppointment->put_AllDayEvent(VARIANT_FALSE);
if(vo->containsProperty(TEXT("CATEGORIES")) && vo->getProperty(TEXT("CATEGORIES"))->getValue())
pAppointment->put_Categories(vo->getProperty(TEXT("CATEGORIES"))->getValue());
if(vo->containsProperty(TEXT("CLASS")) && vo->getProperty(TEXT("CLASS"))->getValue()) {
wchar_t* calClass = new wchar_t[20];
wcscpy(calClass, vo->getProperty(TEXT("CLASS"))->getValue());
if(!wcscmp(calClass, TEXT("PRIVATE")) || !wcscmp(calClass, TEXT("CONFIDENTIAL")))
pAppointment->put_Sensitivity(olPrivate);
else
pAppointment->put_Sensitivity(olNormal);
delete [] calClass;
}
else
pAppointment->put_Sensitivity(olNormal);
//ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:John Smith <jsmith@host1.com>
//ATTENDEE;ROLE=ATTENDEE;STATUS=CONFIRMED;VALUE=URL;TYPE=VCARD:http://www.xyz.com/~myvcard.vcf
IRecipients* pRecipients;
pAppointment->get_Recipients(&pRecipients);
int countRecipient = 0;
pRecipients->get_Count(&countRecipient);
for (i = 0; i < countRecipient; i++) {
pRecipients->Remove(i + 1);
}
for(i = 0; i<vo->propertiesCount(); i++)
if(!wcscmp(vo->getProperty(i)->getName(), TEXT("ATTENDEE")) &&
vo->getProperty(i)->getValue() &&
!vo->getProperty(i)->containsParameter(TEXT("VALUE"))) {
wchar_t* attendee = new wchar_t[300];
wcscpy(attendee, vo->getProperty(i)->getValue());
wchar_t separator[] = TEXT("<");
wchar_t* pos = NULL;
pos = wcsstr(attendee, separator);
if(pos) {
wchar_t* name = new wchar_t[200];
wcscpy(name, TEXT(""));
if((pos - attendee)-1 > 0) {
wcsncpy(name, attendee, (pos - attendee)-1);
name[pos - attendee] = TEXT('\0');
}
wchar_t* addr = new wchar_t[200];
wcscpy(addr, pos+1);
addr[wcslen(addr) - 1] = TEXT('\0');
IRecipient* pRecipient;
pRecipients->Add(name, &pRecipient);
pRecipient->put_Address(addr);
pRecipient->Release();
delete [] name;
delete [] addr;
}
}
pRecipients->Release();
//alarm
//The value consists of: Run Time, Snooze Time; Repeat Count, Audio Content
if(vo->containsProperty(TEXT("AALARM")) && vo->getProperty(TEXT("AALARM"))->getValue()) {
DATE runTime;
systemTimeToDouble(vo->getProperty(TEXT("AALARM"))->getPropComponent(1), &runTime, NULL);
long minBeforeEvent = long((startdate - runTime) * 1440);
pAppointment->put_ReminderSet(VARIANT_TRUE);
pAppointment->put_ReminderMinutesBeforeStart(minBeforeEvent);
}
//recurrence
if((vo->containsProperty(TEXT("RRULE")) && vo->getProperty(TEXT("RRULE"))->getValue())) {
pAppointment->ClearRecurrencePattern();
IRecurrencePattern* pRecPat;
pAppointment->GetRecurrencePattern(& pRecPat);
DATE startDate;
pAppointment->get_Start(&startDate);
bool ret = convertRrule(pRecPat, vo->getProperty(TEXT("RRULE"))->getValue(), startDate);
if(!ret)
pAppointment->ClearRecurrencePattern();
pRecPat->Release();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -