?? winevent.cpp
字號:
/*
* Copyright (C) 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
*/
#include "base/util/utils.h"
#include "vocl/WinEvent.h"
#include "vocl/VConverter.h"
#include "base/stringUtils.h"
#include "base/timeUtils.h"
using namespace std;
// Constructor
WinEvent::WinEvent() {
vCalendar = L"";
}
// Constructor: fills propertyMap parsing the passed data
WinEvent::WinEvent(const wstring dataString) {
vCalendar = L"";
parse(dataString);
}
// Destructor
WinEvent::~WinEvent() {
}
// Format and return a vCalendar string from the propertyMap.
wstring& WinEvent::toString() {
vCalendar = L"";
//
// Conversion: WinContact -> vObject.
// ----------------------------------
//
VObject* vo = new VObject();
VProperty* vp = NULL;
DATE startdate = NULL;
wstring element;
vp = new VProperty(TEXT("BEGIN"), TEXT("VCALENDAR"));
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(TEXT("VERSION"), VCALENDAR_VERSION);
vo->addProperty(vp);
delete vp; vp = NULL;
vp = new VProperty(TEXT("BEGIN"), TEXT("VEVENT"));
vo->addProperty(vp);
delete vp; vp = NULL;
// Folder path.
if (getProperty(L"Folder", element)) {
vp = new VProperty(L"X-FUNAMBOL-FOLDER");
vp->addValue(element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"AllDayEvent", element)) {
vp = new VProperty(TEXT("X-FUNAMBOL-ALLDAY"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Start", element)) {
replaceAll(L"-", L"", element); // **** To be removed!!! ****
stringTimeToDouble(element, &startdate); // Used later for reminder...
vp = new VProperty(TEXT("DTSTART"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"End", element)) {
replaceAll(L"-", L"", element); // **** To be removed!!! ****
vp = new VProperty(TEXT("DTEND"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"BusyStatus", element)) {
vp = new VProperty(TEXT("X-MICROSOFT-CDO-BUSYSTATUS"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Categories", element)) {
vp = new VProperty(TEXT("CATEGORIES"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Body", element)) {
vp = new VProperty(TEXT("DESCRIPTION"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Location", element)) {
vp = new VProperty(TEXT("LOCATION"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Importance", element)) {
vp = new VProperty(TEXT("PRIORITY"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"MeetingStatus", element)) {
vp = new VProperty(TEXT("STATUS"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"ReplyTime", element)) {
vp = new VProperty(TEXT("X-MICROSOFT-CDO-REPLYTIME"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Subject", element)) {
vp = new VProperty(TEXT("SUMMARY"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Sensitivity", element)) {
long sensitivity = _wtoi(element.c_str());
vp = new VProperty(TEXT("CLASS"));
if(sensitivity == winPrivate) {
vp->addValue(TEXT("PRIVATE"));
}
else if (sensitivity == winConfidential) {
vp->addValue(TEXT("CONFIDENTIAL"));
}
else { // default value
vp->addValue(TEXT("PUBLIC"));
}
vo->addProperty(vp);
delete vp; vp = NULL;
}
//
// ReminderSet
//
if (getProperty(L"ReminderSet", element)) {
BOOL bReminder = _wtoi(element.c_str());
if(bReminder == TRUE) {
long minBefore;
if (getProperty(L"ReminderMinutesBeforeStart", element)) {
minBefore = _wtoi(element.c_str());
double minStartDate = startdate * 1440;
//subtract the alarm
minStartDate -= minBefore;
wstring runtime;
doubleToStringTime(runtime, minStartDate/1440);
vp = new VProperty(L"AALARM");
vp->addValue(runtime.c_str()); // "RunTime"
vp->addValue(L""); // "Snooze Time" (empty)
vp->addValue(L"0"); // "Repeat Count"
getProperty(L"ReminderSoundFile", element); // (empty if not found)
vp->addValue(element.c_str()); // "Audio Content" = sound file path
vo->addProperty(vp);
delete vp; vp = NULL;
}
}
else {
// No reminder: send empty "AALARM:"
vp = new VProperty(L"AALARM");
vo->addProperty(vp);
delete vp; vp = NULL;
}
}
if (getProperty(L"IsRecurring", element)) {
BOOL isRec = _wtoi(element.c_str());
if(isRec) {
//
// Recurrence pattern -> RRULE
//
wstring rRule = recPattern.toString();
if(rRule != L"") {
vp = new VProperty(TEXT("RRULE"), rRule.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
list<wstring>::iterator it;
// Exceptions: EXDATE
vp = new VProperty(TEXT("EXDATE"));
for (it = excludeDate.begin(); it != excludeDate.end(); it++) {
vp->addValue((*it).c_str());
}
vo->addProperty(vp);
delete vp; vp = NULL;
// Exceptions: RDATE (should be empty for Outlook and WM)
vp = new VProperty(TEXT("RDATE"));
for (it = includeDate.begin(); it != includeDate.end(); it++) {
vp->addValue((*it).c_str());
}
vo->addProperty(vp);
delete vp; vp = NULL;
}
else {
// Not recurring: send empty "RRULE:"
vp = new VProperty(TEXT("RRULE"));
vo->addProperty(vp);
delete vp; vp = NULL;
}
}
//
// ---- Other Funambol defined properties ----
// Support for other fields that don't have a
// specific correspondence in vCalendar.
if (getProperty(L"Companies", element)) {
vp = new VProperty(TEXT("X-FUNAMBOL-COMPANIES"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
if (getProperty(L"Mileage", element)) {
vp = new VProperty(TEXT("X-FUNAMBOL-MILEAGE"), element.c_str());
vo->addProperty(vp);
delete vp; vp = NULL;
}
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;
//
// Format the vCalendar.
// ---------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -