wintask.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 546 行 · 第 1/2 页
CPP
546 行
delete vp; vp = NULL;
}
if (getProperty(TEXT("TotalWork"), element)) {
vp = new VProperty(TEXT("X-FUNAMBOL-TOTALWORK"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
vp = new VProperty(TEXT("END"), TEXT("VTODO"));
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(TEXT("END"), TEXT("VCALENDAR"));
vo->addProperty(vp);
delete vp; vp = NULL;
//
// Format the vCalendar.
// ---------------------
//
WCHAR* tmp = vo->toString();
if (tmp) {
vCalendar = tmp;
delete [] tmp;
}
return vCalendar;
}
//
// Parse a vCalendar string and fills the propertyMap.
//
int WinTask::parse(const wstring dataString) {
WCHAR* element = NULL;
DATE startDate = NULL;
//
// Parse the vCalendar and fill the VObject.
// -----------------------------------------
//
VObject* vo = VConverter::parse(dataString.c_str());
if (!vo) {
setError(1, ERR_ITEM_VOBJ_PARSE);
LOG.error("%s", getLastErrorMsg());
return 1;
}
// Check if VObject type and version are the correct ones.
if (!checkVCalendarTypeAndVersion(vo)) {
if (vo) delete vo;
return 1;
}
//
// Conversion: vObject -> WinTask.
// -------------------------------
// Note: properties found are added to the propertyMap, so that the
// map will contain only parsed properties after this process.
//
if (element = getVObjectPropertyValue(vo, L"SUMMARY")) {
setProperty(L"Subject", element);
}
if (element = getVObjectPropertyValue(vo, L"DESCRIPTION")) {
setProperty(L"Body", element);
}
if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-FOLDER")) {
setProperty(L"Folder", element);
}
// Tasks are ALWAYS all-day-events!
setProperty(L"AllDayEvent", TEXT("1"));
if (element = getVObjectPropertyValue(vo, L"DTSTART")){
setProperty(L"StartDate", element);
stringTimeToDouble(element, &startDate); // 'startDate' will be used also for RRULE parsing
}
if (element = getVObjectPropertyValue(vo, L"DUE")){
setProperty(L"DueDate", element);
}
if (element = getVObjectPropertyValue(vo, L"COMPLETED")){
setProperty(L"DateCompleted", element);
}
if (element = getVObjectPropertyValue(vo, L"CATEGORIES")) {
setProperty(L"Categories", element);
}
if (element = getVObjectPropertyValue(vo, L"CLASS")) {
WCHAR tmp[10];
if (!wcscmp(element, TEXT("CONFIDENTIAL")) ) {
wsprintf(tmp, TEXT("%i"), winConfidential); // Confidential = 3
}
else if (!wcscmp(element, TEXT("PRIVATE")) ) {
wsprintf(tmp, TEXT("%i"), winPrivate); // Private = 2
}
else {
wsprintf(tmp, TEXT("%i"), winNormal); // Normal = 0
}
setProperty(L"Sensitivity", tmp);
}
if (element = getVObjectPropertyValue(vo, L"PERCENT-COMPLETE")) {
setProperty(L"PercentComplete", element);
}
if (element = getVObjectPropertyValue(vo, L"PRIORITY")) {
setProperty(L"Importance", element);
}
if (element = getVObjectPropertyValue(vo, L"STATUS")) {
if(!wcscmp(element, TEXT("COMPLETED"))) {
setProperty(L"Complete", TEXT("1"));
}
}
//
// **** "Status"? mapping is missing! ****
// **** "TeamTask"? mapping is missing! ****
//
//
// AALARM
// The value consists of: RunTime, SnoozeTime, RepeatCount, AudioContent
//
if(element = getVObjectPropertyValue(vo, L"AALARM")) {
WCHAR* runTimeValue = vo->getProperty(TEXT("AALARM"))->getPropComponent(1);
if (wcslen(runTimeValue) > 0) {
setProperty(TEXT("ReminderSet"), TEXT("1"));
setProperty(TEXT("ReminderTime"), runTimeValue);
// Reminder sound file path
WCHAR* filePath = vo->getProperty(TEXT("AALARM"))->getPropComponent(4);
if (filePath && wcslen(filePath)>0) {
setProperty(TEXT("ReminderSoundFile"), filePath);
}
else {
setProperty(TEXT("ReminderSoundFile"), TEXT(""));
}
}
else {
// RunTime not found -> no reminder
setProperty(TEXT("ReminderSet"), TEXT("0"));
}
}
else {
// AALARM not found -> reset reminder!
// Note: this is done for compatibility with most devices: if alarm not set
// AALARM property is not sent.
setProperty(TEXT("ReminderSet"), TEXT("0"));
}
//
// RRULE -> Recurrence pattern
// Fill recPattern propertyMap.
//
if ( (element = getVObjectPropertyValue(vo, L"RRULE")) &&
(wcslen(element) > 0) ) {
setProperty(L"IsRecurring", L"1");
recPattern.setStartDate(startDate);
recPattern.parse(element);
}
else {
// Not recurring.
setProperty(L"IsRecurring", L"0");
}
//
// ---- Other Funambol defined properties ----
// Support for other fields that don't have a
// specific correspondence in vCalendar.
if (element = getVObjectPropertyValue(vo, TEXT("X-FUNAMBOL-ACTUALWORK"))) {
setProperty(TEXT("ActualWork"), element);
}
if (element = getVObjectPropertyValue(vo, TEXT("X-FUNAMBOL-BILLINGINFO"))) {
setProperty(TEXT("BillingInformation"), element);
}
if (element = getVObjectPropertyValue(vo, TEXT("X-FUNAMBOL-COMPANIES"))) {
setProperty(TEXT("Companies"), element);
}
if (element = getVObjectPropertyValue(vo, TEXT("X-FUNAMBOL-MILEAGE"))) {
setProperty(TEXT("Mileage"), element);
}
if(element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-AALARMOPTIONS")) {
setProperty(L"ReminderOptions", element);
}
if (element = getVObjectPropertyValue(vo, TEXT("X-FUNAMBOL-TEAMTASK"))) {
setProperty(TEXT("TeamTask"), element);
}
if (element = getVObjectPropertyValue(vo, TEXT("X-FUNAMBOL-TOTALWORK"))) {
setProperty(TEXT("TotalWork"), element);
}
return 0;
}
// Utility to check the productID and version of VObject passed.
bool WinTask::checkVCalendarTypeAndVersion(VObject* vo) {
WCHAR* prodID = vo->getProdID();
WCHAR* version = vo->getVersion();
if (!prodID) {
LOG.error(ERR_ITEM_VOBJ_TYPE_NOTFOUND, L"VCALENDAR");
return false;
}
if (wcscmp(prodID, L"VCALENDAR")) {
LOG.error(ERR_ITEM_VOBJ_WRONG_TYPE, prodID, L"VCALENDAR");
return false;
}
if (!version) {
// Just log a warning...
LOG.info(INFO_ITEM_VOBJ_VERSION_NOTFOUND, VCALENDAR_VERSION);
}
else if (wcscmp(version, VCALENDAR_VERSION)) {
// Just log a warning...
LOG.info(INFO_ITEM_VOBJ_WRONG_VERSION, version, VCALENDAR_VERSION);
}
return true;
}
WinRecurrence* WinTask::getRecPattern() {
return &recPattern;
}
long WinTask::getCRC() {
wstring values;
// Event props
mapIterator it = propertyMap.begin();
while (it != propertyMap.end()) {
values.append(it->second);
it ++;
}
// Append rec props only if recurring
wstring isRec;
if (getProperty(TEXT("IsRecurring"), isRec)) {
if (isRec == TEXT("1")) {
it = getRecPattern()->propertyMap.begin();
while (it != getRecPattern()->propertyMap.end()) {
values.append(it->second);
it ++;
}
}
}
const WCHAR* s = values.c_str();
unsigned long crc32 = 0;
unsigned long dwErrorCode = NO_ERROR;
unsigned char byte = 0;
crc32 = 0xFFFFFFFF;
while(*s != TEXT('\0')) {
byte = (unsigned char) *s;
crc32 = ((crc32) >> 8) ^ crc32Table[(byte) ^ ((crc32) & 0x000000FF)];
s++;
}
crc32 = ~crc32;
return crc32;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?