2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dpl/log/log.h>
23 #include <Commons/Exception.h>
24 #include "EventWrapper.h"
27 using namespace TizenApis::Api::Calendar;
28 using namespace WrtDeviceApis::Commons;
31 const char WEEKDAYS[] = "0111110";
32 const int NEW_EVENT_ID = -1;
39 EventWrapper::EventWrapper(CalendarEvent::CalendarType type) :
40 m_platformEvent(NULL),
41 m_abstractEvent(NULL),
45 m_abstractEvent = CalendarEventPtr(new CalendarEvent());
46 if (!m_abstractEvent) {
47 ThrowMsg(UnknownException, "abstract object is not created");
51 EventWrapper::EventWrapper(const CalendarEventPtr &event, CalendarEvent::CalendarType type) :
52 m_platformEvent(NULL),
53 m_abstractEvent(event),
59 EventWrapper::EventWrapper(cal_struct *event, CalendarEvent::CalendarType type) :
60 m_platformEvent(event),
61 m_abstractEvent(NULL),
65 m_abstractEvent = CalendarEventPtr(new CalendarEvent());
66 if (!m_abstractEvent) {
67 ThrowMsg(UnknownException, "abstract object is not created");
71 EventWrapper::~EventWrapper()
77 int EventWrapper::getIdFromPlatformEvent() const
80 if (m_platformEvent == NULL) {
81 ThrowMsg(NullPointerException, "m_platformEvent is not set");
84 return calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_INDEX);
87 void EventWrapper::setCalendarId(const std::string &value)
89 LogInfo("calendar id "<<value);
91 std::istringstream stream(m_calendarId);
94 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
95 CAL_VALUE_INT_CALENDAR_ID,
98 ThrowMsg(PlatformException, "Can't set calendar id.");
102 void EventWrapper::setCalendarAccountId(const int value)
104 LogInfo("account id "<<value);
105 m_calendarAccountId = value;
106 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
107 CAL_VALUE_INT_ACCOUNT_ID,
108 m_calendarAccountId))
110 ThrowMsg(PlatformException, "Can't set calendar account id.");
114 void EventWrapper::saveEvent()
117 if (m_platformEvent == NULL) {
118 ThrowMsg(NullPointerException, "m_platformEvent is not set");
121 int eventId = getIdFromPlatformEvent();
122 LogDebug("Before saving/update eventId: " << eventId);
124 //displayPlatformEvent();
126 //insert new record or update existing one
128 int returnValue = calendar_svc_insert(m_platformEvent);
129 if (CAL_SUCCESS > returnValue) {
130 LogError("Can't insert new event, error code: " << returnValue);
131 ThrowMsg(PlatformException, "Can't insert new event.");
133 m_abstractEvent->setId(returnValue);
134 LogInfo("New calendar item inserted with id "<<returnValue);
136 int errorCode = calendar_svc_update(m_platformEvent);
137 if (CAL_SUCCESS != errorCode) {
138 ThrowMsg(PlatformException, "Can't update new event with error code: "<<errorCode);
140 LogDebug("Calendar event updated");
144 void EventWrapper::loadEvent(int id)
146 LogDebug("Item id to load: " << id);
149 const char *dataType;
150 if(getType() == CalendarEvent::TASK_TYPE) {
151 dataType = CAL_STRUCT_TODO;
153 dataType = CAL_STRUCT_SCHEDULE;
156 int errorCode = calendar_svc_get(dataType, id, NULL, &m_platformEvent);
157 if (CAL_SUCCESS!=errorCode) {
158 if (m_platformEvent) {
159 calendar_svc_struct_free(&m_platformEvent);
161 ThrowMsg(NotFoundException, "Can't get item with id = " << id << ", error code: " <<errorCode);
164 int isDeleted = calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_IS_DELETED);
166 if (m_platformEvent) {
167 calendar_svc_struct_free(&m_platformEvent);
169 ThrowMsg(NotFoundException, "Item already deleted.");
172 convertPlatformEventToAbstractEvent();
173 m_abstractEvent->setCalendarType(m_calendarType);
174 //displayAbstractEvent();
177 void EventWrapper::deleteEvent()
179 if (m_platformEvent == NULL) {
180 ThrowMsg(NullPointerException, "Platform event is null.");
183 // If the recurrenceId is set, delete the instance of recurring event only.
184 int itemId = getIdFromPlatformEvent();
185 long long int recurrenceId = m_abstractEvent->getRecurrenceId();
186 LogDebug("itemId to delete: " << itemId << ", recurrenceId: " << recurrenceId << ", type: " << getType());
188 cal_struct *item = NULL;
189 const char *dataType;
190 if(getType() == CalendarEvent::TASK_TYPE) {
191 dataType = CAL_STRUCT_TODO;
193 dataType = CAL_STRUCT_SCHEDULE;
196 int error = calendar_svc_get(dataType, itemId, NULL, &item);
197 if (CAL_SUCCESS != error) {
199 calendar_svc_struct_free(&item);
201 ThrowMsg(NotFoundException, "Can't get calendar item. Error code: "<<error);
204 int isDeleted = calendar_svc_struct_get_int(item, CAL_VALUE_INT_IS_DELETED);
207 calendar_svc_struct_free(&item);
209 ThrowMsg(NotFoundException, "Item already deleted.");
213 calendar_svc_struct_free(&item);
216 if ( 0>=recurrenceId ||
217 !(EventRecurrenceRule::DAILY_RECURRENCE <= m_abstractEvent->getRecurrenceRule()->getFrequency()
218 && m_abstractEvent->getRecurrenceRule()->getFrequency() <= EventRecurrenceRule::YEARLY_RECURRENCE)) {
219 // Remove the parent and child instances by the given uid.
220 int parentId = itemId;
222 // First, the parent event.
223 error = calendar_svc_delete(dataType, parentId);
224 if (CAL_SUCCESS != error) {
225 if(CAL_ERR_NO_DATA==error) {
226 ThrowMsg(NotFoundException, "Item not found.");
228 ThrowMsg(PlatformException, "Can't delete calendar item. Error code " << error);
231 m_abstractEvent->resetId();
232 setIdToPlatformEvent();
234 if(CalendarEvent::EVENT_TYPE==getType()) {
235 LogDebug("The event parent item is deleted.");
237 // Next, all the detached instances.
238 cal_iter *iter = NULL;
239 cal_struct *platformEvent = NULL;
240 if(CAL_SUCCESS != calendar_svc_find_event_list(m_calendarAccountId, CAL_VALUE_INT_ORIGINAL_EVENT_ID, (void*) parentId, &iter)) {
241 LogInfo("Founding detached instances failed.");
244 while (CAL_SUCCESS == calendar_svc_iter_next(iter)) {
245 LogInfo("Deleting a detached instance...");
246 platformEvent = NULL;
247 if (CAL_SUCCESS != calendar_svc_iter_get_info(iter, &platformEvent)) {
249 calendar_svc_iter_remove(&iter);
251 ThrowMsg(PlatformException, "Can't get event info.");
254 int detachedEventId = calendar_svc_struct_get_int(platformEvent, CAL_VALUE_INT_INDEX);
255 LogDebug("detachedEventId "<<detachedEventId);
256 error = calendar_svc_delete(dataType, detachedEventId);
257 if (CAL_SUCCESS != error) {
259 calendar_svc_iter_remove(&iter);
262 if(CAL_ERR_NO_DATA==error) {
263 ThrowMsg(NotFoundException, "Item not found.");
265 ThrowMsg(PlatformException, "Can't delete calendar event. Error code " << error);
268 LogDebug("Deleted a detached event by id: "<<detachedEventId);
273 calendar_svc_iter_remove(&iter);
276 LogInfo("Deleting a task finished.");
279 error = calendar_svc_event_delete_normal_instance(itemId, recurrenceId);
280 if(error!=CAL_SUCCESS) {
281 ThrowMsg(PlatformException, "Can't delete the instance. Error code " << error);
284 m_abstractEvent->getRecurrenceRule()->getExceptions().push_back(recurrenceId);
285 LogDebug("The recurring event is updated.");
289 void EventWrapper::createEventFromString(std::string value)
292 ThrowMsg(NullPointerException, "Failed to create an item from string.");
294 LogInfo("string to convert: "<<value);
300 returnValue = calendar_svc_read_schedules(value.c_str(), &items);
301 if (CAL_SUCCESS != returnValue) {
302 ThrowMsg(PlatformException, "Can't convert string. Error code: "<<returnValue);
305 ThrowMsg(PlatformException, "No items converted.");
309 m_platformEvent = (cal_struct*)items->data;
310 if (NULL==m_platformEvent) {
311 items = g_list_next(items);
314 // We only cover one event per string.
318 items = g_list_next(items);
321 //displayPlatformEvent();
324 std::string EventWrapper::exportEventToString()
326 char *vStrings = NULL;
329 std::string returnString;
331 items = g_list_append(items, m_platformEvent);
333 returnValue = calendar_svc_write_schedules(items, &vStrings);
334 if (CAL_SUCCESS != returnValue) {
335 ThrowMsg(PlatformException, "Can't convert item to string. Error code: "<<returnValue);
337 if (NULL==vStrings) {
338 ThrowMsg(PlatformException, "No items converted.");
341 returnString = std::string(vStrings);
346 cal_struct* EventWrapper::getPlatformEvent() const
348 return m_platformEvent;
351 CalendarEventPtr EventWrapper::getAbstractEvent() const
353 return m_abstractEvent;
356 void EventWrapper::freePlatformEvent()
359 if (m_platformEvent != NULL) {
360 if (CAL_SUCCESS != calendar_svc_struct_free(&m_platformEvent)) {
361 LogError("Can't free calendar event struct.");
363 m_platformEvent = NULL;
367 cal_struct* EventWrapper::convertAbstractEventToPlatformEvent()
371 const char *dataType;
373 if(getType() == CalendarEvent::TASK_TYPE) {
374 dataType = CAL_STRUCT_TODO;
376 dataType = CAL_STRUCT_SCHEDULE;
378 m_platformEvent = calendar_svc_struct_new(dataType);
379 if (!m_platformEvent) {
380 ThrowMsg(UnknownException, "cannot create platform event");
383 setDescriptionToPlatformEvent();
384 setSummaryToPlatformEvent();
385 setStartTimeToPlatformEvent();
386 setEndTimeToPlatformEvent(); // replacement for duration
387 setLocationToPlatformEvent();
388 setCategoriesToPlatformEvent();
389 setStatusToPlatformEvent();
390 setAlarmsToPlatformEvent();
391 setIsAllDayToPlatformEvent();
392 setOrganizerToPlatformEvent();
393 setAttendeesToPlatformEvent();
394 setPositionToPlatformEvent();
395 setVisibilityToPlatformEvent();
396 //setLastModifiedDateToPlatformEvent(); // read-only in platform.
397 setAvailabilityToPlatformEvent();
398 setRecurrenceRuleToPlatformEvent();
399 setIdToPlatformEvent();
400 //setUIdToPlatformEvent(); // We don't set uid but use id field instead.
401 setParentIdToPlatformEvent();
402 setPriorityToPlatformEvent();
403 setCreatedDateToPlatformEvent();
404 setCompletedDateToPlatformEvent();
405 setProgressToPlatformEvent();
407 return getPlatformEvent();
410 void EventWrapper::setDescriptionToPlatformEvent()
412 if (!m_platformEvent) {
413 ThrowMsg(UnknownException, "Null platform pointer.");
415 if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
416 CAL_VALUE_TXT_DESCRIPTION,
418 getDescription().c_str()))
420 ThrowMsg(PlatformException, "Can't set event description.");
424 void EventWrapper::setSummaryToPlatformEvent()
426 if (!m_platformEvent) {
427 ThrowMsg(UnknownException, "Null platform pointer.");
429 if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
430 CAL_VALUE_TXT_SUMMARY,
431 m_abstractEvent->getSubject()
433 ThrowMsg(PlatformException, "Can't set event subject.");
437 void EventWrapper::setStartTimeToPlatformEvent()
439 if (!m_platformEvent) {
440 ThrowMsg(UnknownException, "Null platform pointer.");
443 long long int time = m_abstractEvent->getStartTime();
445 time = m_abstractEvent->getEndTime();
448 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
449 CALS_VALUE_INT_DTSTART_TYPE,
451 ThrowMsg(PlatformException, "Can't set start time type.");
454 if (CAL_SUCCESS != calendar_svc_struct_set_lli(m_platformEvent,
455 CALS_VALUE_LLI_DTSTART_UTIME,
457 ThrowMsg(PlatformException, "Can't set event start time.");
460 const char* timeZone = m_abstractEvent->getTimeZone().c_str();
461 if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
462 CALS_VALUE_TXT_DTSTART_TZID,
464 ThrowMsg(PlatformException, "Can't set event time zone.");
468 void EventWrapper::setEndTimeToPlatformEvent()
470 if (!m_platformEvent) {
471 ThrowMsg(UnknownException, "Null platform pointer.");
474 long long int time = m_abstractEvent->getEndTime();
476 time = m_abstractEvent->getStartTime();
479 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
480 CALS_VALUE_INT_DTEND_TYPE,
482 ThrowMsg(PlatformException, "Can't set end time type.");
485 if (CAL_SUCCESS != calendar_svc_struct_set_lli(m_platformEvent,
486 CALS_VALUE_LLI_DTEND_UTIME,
488 ThrowMsg(PlatformException, "Can't set event end time.");
492 void EventWrapper::setLocationToPlatformEvent()
494 if (!m_platformEvent) {
495 ThrowMsg(UnknownException, "Null platform pointer.");
497 if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
498 CAL_VALUE_TXT_LOCATION,
499 m_abstractEvent->getLocation()
501 ThrowMsg(PlatformException, "Can't set event location.");
505 void EventWrapper::setRecurrenceRuleToPlatformEvent()
508 if (!m_platformEvent) {
509 ThrowMsg(UnknownException, "Null platform pointer.");
512 EventRecurrenceRulePtr rrule = m_abstractEvent->getRecurrenceRule();
514 LogInfo("rrule is not set.");
519 LogInfo("frequency "<<rrule->getFrequency());
520 switch (rrule->getFrequency()) {
521 case EventRecurrenceRule::NO_RECURRENCE:
522 if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_ONCE)) {
523 ThrowMsg(PlatformException, "Failed setting frequency.");
526 case EventRecurrenceRule::DAILY_RECURRENCE:
527 if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_DAILY)) {
528 ThrowMsg(PlatformException, "Failed setting frequency.");
531 case EventRecurrenceRule::WEEKLY_RECURRENCE:
533 if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_WEEKLY)) {
534 ThrowMsg(PlatformException, "Failed setting frequency.");
538 case EventRecurrenceRule::MONTHLY_RECURRENCE:
540 if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY)) {
541 ThrowMsg(PlatformException, "Failed setting frequency.");
545 case EventRecurrenceRule::YEARLY_RECURRENCE:
547 if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CAL_REPEAT_EVERY_YEAR)) {
548 ThrowMsg(PlatformException, "Failed setting frequency.");
552 case EventRecurrenceRule::UNDEFINED_RECURRENCE:
554 ThrowMsg(UnknownException, "Invalid reccurence rule frequency "<<rrule->getFrequency());
559 std::vector<std::string> daysOfTheWeek = rrule->getDaysOfTheWeek();
560 if( 0 != daysOfTheWeek.size() ) {
561 std::string byday = "";
562 for(unsigned int i=0; i<daysOfTheWeek.size(); i++) {
563 byday.append(daysOfTheWeek.at(i));
564 if(i!=daysOfTheWeek.size()-1) {
569 LogInfo("byday: "<<byday);
570 if (CAL_SUCCESS!=calendar_svc_struct_set_str(m_platformEvent, CALS_VALUE_TXT_RRULE_BYDAY, byday.c_str())) {
571 ThrowMsg(PlatformException, "Can't set byday.");
575 // set the ocurrence count
576 if (-1 != rrule->getOccurrenceCount()) {
577 LogInfo("Set the occurrence count: "<<rrule->getOccurrenceCount());
579 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_COUNT)) {
580 ThrowMsg(PlatformException, "Can't set rrule range type.");
583 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_COUNT, rrule->getOccurrenceCount())) {
584 ThrowMsg(PlatformException, "Can't set occurrence count.");
588 // set the exceptions
589 if ( !rrule->getExceptions().empty() )
591 LogInfo("Set the exceptions of length: "<<rrule->getExceptions().size());
593 std::string exdate = "";
594 for( unsigned int i=0; i<rrule->getExceptions().size(); i++ )
596 std::stringstream ss;
597 ss<<rrule->getExceptions().at(i);
598 exdate.append(ss.str());
599 if(i!=rrule->getExceptions().size()-1) {
603 if (CAL_SUCCESS!=calendar_svc_struct_set_str(m_platformEvent, CAL_VALUE_TXT_EXDATE, exdate.c_str())) {
604 ThrowMsg(PlatformException, "Can't save exceptions.");
608 // set the recurrence interval
609 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
610 CALS_VALUE_INT_RRULE_INTERVAL,
611 rrule->getInterval()))
613 ThrowMsg(PlatformException, "Can't set interval.");
616 // set the recurrence end date. This is automatically calculated by platform if empty.
617 if (UNDEFINED_TIME!=rrule->getEndDate()) {
618 LogInfo("Setting the end date: "<<rrule->getEndDate());
620 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_UNTIL)) {
621 ThrowMsg(PlatformException, "Can't set rrule range type.");
624 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_UNTIL_TYPE, CALS_TIME_UTIME)) {
625 ThrowMsg(PlatformException, "Can't set rrule until type.");
628 if (CAL_SUCCESS != calendar_svc_struct_set_lli(m_platformEvent, CALS_VALUE_LLI_RRULE_UNTIL_UTIME, m_abstractEvent->getRecurrenceRule()->getEndDate())) {
629 ThrowMsg(PlatformException, "Can't set recurrence end date.");
634 void EventWrapper::setAlarmsToPlatformEvent()
636 if (!m_platformEvent) {
637 ThrowMsg(UnknownException, "Null platform pointer.");
640 if( 0 != m_abstractEvent->getAlarmsTick().size() ) {
642 calendar_svc_struct_get_list(m_platformEvent, CAL_VALUE_LST_ALARM, &list);
644 for( unsigned int i=0; i<m_abstractEvent->getAlarmsTick().size(); i++ )
646 LogInfo("Set the alarms #"<<i);
648 cal_value *value = calendar_svc_value_new(CAL_VALUE_LST_ALARM);
650 // We have to use alarm tick and tick unit for alarm creation.
651 int errorCode = calendar_svc_value_set_int(
653 CAL_VALUE_INT_ALARMS_TICK,
654 m_abstractEvent->getAlarmsTick().at(i));
655 if (CAL_SUCCESS != errorCode) {
657 calendar_svc_value_free(&value);
659 LogError("Can't set CAL_VALUE_INT_ALARMS_TICK, error: " << errorCode);
660 ThrowMsg(PlatformException, "Can't set alarm tick.");
662 errorCode = calendar_svc_value_set_int(
664 CAL_VALUE_INT_ALARMS_TICK_UNIT,
665 CAL_SCH_TIME_UNIT_MIN);
666 if (CAL_SUCCESS != errorCode) {
668 calendar_svc_value_free(&value);
670 LogError("Can't set CAL_VALUE_INT_ALARMS_TICK_UNIT, error: " << errorCode);
671 ThrowMsg(PlatformException, "Can't set alarm tick unit.");
674 // Set the alarm type.
675 cal_alert_type_t alarmType = CAL_ALERT_MELODY;
676 switch (m_abstractEvent->getAlarmsType().at(i)) {
677 case CalendarEvent::NO_ALARM:
678 alarmType = CAL_ALERT_MUTE;
680 case CalendarEvent::SOUND_ALARM:
681 alarmType = CAL_ALERT_MELODY;
683 case CalendarEvent::SILENT_ALARM:
684 alarmType = CAL_ALERT_VIBRATION;
687 LogDebug("Use the default alarm type");
690 errorCode = calendar_svc_value_set_int(
692 CAL_VALUE_INT_ALARMS_TYPE,
694 if (CAL_SUCCESS != errorCode) {
696 calendar_svc_value_free(&value);
698 LogError("Can't set CAL_VALUE_INT_ALARMS_TYPE, error: " << errorCode);
699 ThrowMsg(PlatformException, "Can't set alarm type.");
702 // Set the display text
703 errorCode = calendar_svc_value_set_str(
705 CAL_VALUE_TXT_ALARMS_DESCRIPTION,
706 m_abstractEvent->getAlarmsDescription().at(i).c_str());
707 if (CAL_SUCCESS != errorCode) {
709 calendar_svc_value_free(&value);
711 LogError("Can't set CAL_VALUE_TXT_ALARMS_DESCRIPTION, error: " << errorCode);
712 ThrowMsg(PlatformException, "Can't set alarm description.");
715 list = g_list_append(list, value);
718 if (CAL_SUCCESS!=calendar_svc_struct_store_list(m_platformEvent, CAL_VALUE_LST_ALARM, list)) {
719 ThrowMsg(PlatformException, "cannot save the alarms");
724 void EventWrapper::setStatusToPlatformEvent()
726 if (!m_platformEvent) {
727 ThrowMsg(UnknownException, "Null platform pointer.");
730 cals_status_t status;
732 switch (m_abstractEvent->getStatus()) {
733 case CalendarEvent::TENTATIVE_STATUS:
734 status = CALS_EVENT_STATUS_TENTATIVE;
736 case CalendarEvent::CONFIRMED_STATUS:
737 status = CALS_EVENT_STATUS_CONFIRMED;
739 case CalendarEvent::CANCELLED_STATUS:
740 status = CALS_EVENT_STATUS_CANCELLED;
742 case CalendarEvent::NEEDS_ACTION_STATUS:
743 status = CALS_TODO_STATUS_NEEDS_ACTION;
745 case CalendarEvent::COMPLETED_STATUS:
746 status = CALS_TODO_STATUS_COMPLETED;
748 case CalendarEvent::IN_PROCESS_STATUS:
749 status = CALS_TODO_STATUS_IN_PROCESS;
752 status = CALS_EVENT_STATUS_NONE;
756 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
757 CAL_VALUE_INT_TASK_STATUS,
759 ThrowMsg(PlatformException, "Can't set event status.");
763 void EventWrapper::setCategoriesToPlatformEvent()
765 if (!m_platformEvent) {
766 ThrowMsg(UnknownException, "Null platform pointer.");
769 std::string categories = "";
770 // Need to concatenate all categories into one string separated by a comma.
771 for (size_t i = 0; i < m_abstractEvent->getCategories()->size(); ++i) {
773 categories.append(m_abstractEvent->getCategories()->at(i));
775 categories.append("," + m_abstractEvent->getCategories()->at(i));
779 LogInfo("Saving categories: "<<categories);
782 calendar_svc_struct_set_str(m_platformEvent, CAL_VALUE_TXT_CATEGORIES,
783 categories.c_str())) {
784 ThrowMsg(PlatformException, "Cannot save categories.");
788 void EventWrapper::setIdToPlatformEvent()
790 if (!m_platformEvent) {
791 ThrowMsg(UnknownException, "Null platform pointer.");
793 if (m_abstractEvent->getIdIsSet()) {
794 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
796 m_abstractEvent->getId()))
798 ThrowMsg(PlatformException, "Can't set event Id.");
801 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
804 ThrowMsg(PlatformException, "Can't set event Id.");
809 void EventWrapper::setParentIdToPlatformEvent()
811 if (!m_platformEvent) {
812 ThrowMsg(UnknownException, "Null platform pointer.");
815 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
816 CAL_VALUE_INT_ORIGINAL_EVENT_ID,
817 m_abstractEvent->getParentId()))
819 ThrowMsg(PlatformException, "Can't set parent Id.");
823 void EventWrapper::setIsAllDayToPlatformEvent()
825 if (!m_platformEvent) {
826 ThrowMsg(UnknownException, "Null platform pointer.");
829 cals_time_type timeType = CALS_TIME_UTIME;
830 if(m_abstractEvent->getIsAllDay()) {
831 timeType = CALS_TIME_LOCALTIME;
834 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
835 CALS_VALUE_INT_DTSTART_TYPE,
837 ThrowMsg(PlatformException, "Can't set event isAllDay.");
841 void EventWrapper::setOrganizerToPlatformEvent()
843 if (!m_platformEvent) {
844 ThrowMsg(UnknownException, "Null platform pointer.");
846 if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
847 CAL_VALUE_TXT_ORGANIZER_NAME,
848 m_abstractEvent->getOrganizer().c_str())) {
849 ThrowMsg(PlatformException, "Can't set event organizer.");
853 void EventWrapper::setLastModifiedDateToPlatformEvent()
855 if (!m_platformEvent) {
856 ThrowMsg(UnknownException, "Null platform pointer.");
859 long long int time = m_abstractEvent->getLastModifiedDate();
861 if (CAL_SUCCESS!=calendar_svc_struct_set_lli(m_platformEvent,
862 CALS_VALUE_LLI_LASTMOD,
864 ThrowMsg(PlatformException, "Can't set event lastModifiedDate.");
868 void EventWrapper::setVisibilityToPlatformEvent()
870 if (!m_platformEvent) {
871 ThrowMsg(UnknownException, "Null platform pointer.");
874 int visibility = PUBLIC_VISIBILITY; // default value
875 switch (m_abstractEvent->getVisibility()) {
876 case CalendarEvent::PUBLIC_VISIBILITY:
877 visibility = PUBLIC_VISIBILITY;
879 case CalendarEvent::PRIVATE_VISIBILITY:
880 visibility = PRIVATE_VISIBILITY;
882 case CalendarEvent::CONFIDENTIAL_VISIBILITY:
883 visibility = CONFIDENTIAL_VISIBILITY;
886 LogDebug("Use the default visibility");
889 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
890 CAL_VALUE_INT_SENSITIVITY,
892 ThrowMsg(PlatformException, "Can't set visibility.");
896 void EventWrapper::setAvailabilityToPlatformEvent()
898 if (!m_platformEvent) {
899 ThrowMsg(UnknownException, "Null platform pointer.");
902 cal_event_availability_type_t availability = EVENT_FREE_FB;
903 switch (m_abstractEvent->getAvailability()) {
904 case CalendarEvent::BUSY_FB:
905 availability = EVENT_BUSY_FB;
907 case CalendarEvent::BUSY_UNAVAILABLE_FB:
908 availability = EVENT_BUSY_UNAVAILABLE_FB;
910 case CalendarEvent::FREE_FB:
911 availability = EVENT_FREE_FB;
913 case CalendarEvent::BUSY_TENTATIVE_FB:
914 availability = EVENT_BUSY_TENTATIVE_FB;
917 LogDebug("Use the default availability");
920 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
921 CAL_VALUE_INT_AVAILABILITY,
923 ThrowMsg(PlatformException, "Can't set availability.");
927 void EventWrapper::setUIdToPlatformEvent()
929 if (!m_platformEvent) {
930 ThrowMsg(UnknownException, "Null platform pointer.");
932 if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
934 m_abstractEvent->getUId().c_str())) {
935 ThrowMsg(PlatformException, "Can't set event uid.");
939 void EventWrapper::setAttendeesToPlatformEvent()
941 if (!m_platformEvent) {
942 ThrowMsg(UnknownException, "Null platform pointer.");
945 EventAttendeeListPtr attendeeList = m_abstractEvent->getAttendees();
946 if (NULL==attendeeList) {
947 LogInfo("attendeeList is not set.");
951 GList *attendees = NULL;
952 cal_value* attendee = NULL;
955 for (size_t i = 0; i < attendeeList->size(); ++i) {
956 LogDebug("adding attendee " << i+1 << " over " <<
957 attendeeList->size());
959 attendee = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
960 if (NULL == attendee) {
961 LogError("error during creating attendee");
962 ThrowMsg(PlatformException,
963 "Cannot create attendee object");
968 calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME,
969 attendeeList->at(i)->getName().c_str())) {
970 LogError("error during setting attendee name");
971 calendar_svc_value_free(&attendee);
972 ThrowMsg(PlatformException, "Cannot set attendee name");
977 calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL,
978 attendeeList->at(i)->getURI().c_str())) {
979 LogError("error during setting attendee URI");
980 calendar_svc_value_free(&attendee);
981 ThrowMsg(PlatformException, "Cannot set attendee URI");
985 cal_event_attendee_role_type_t role = EVENT_ATTENDEE_CHAIR_ROLE;
986 switch (attendeeList->at(i)->getRole()) {
987 case EventAttendee::REQ_PARTICIPANT_ROLE:
988 role = EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE;
990 case EventAttendee::OPT_PARTICIPANT_ROLE:
991 role = EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE;
993 case EventAttendee::NON_PARTICIPANT_ROLE:
994 role = EVENT_ATTENDEE_NON_PARTICIPANT_ROLE;
996 case EventAttendee::CHAIR_ROLE:
997 role = EVENT_ATTENDEE_CHAIR_ROLE;
1000 LogDebug("Use the default role");
1004 calendar_svc_value_set_int(attendee, CAL_VALUE_INT_ATTENDEE_ROLE,
1006 LogError("error during setting attendee role");
1007 calendar_svc_value_free(&attendee);
1008 ThrowMsg(PlatformException, "Cannot set attendee role");
1012 cal_event_attendee_status_type_t status = EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS;
1013 switch (attendeeList->at(i)->getStatus()) {
1014 case EventAttendee::PENDING_AT_STATUS:
1015 status = EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS;
1017 case EventAttendee::ACCEPTED_AT_STATUS:
1018 status = EVENT_ATTENDEE_ACCEPTED_AT_STATUS;
1020 case EventAttendee::DECLINED_AT_STATUS:
1021 status = EVENT_ATTENDEE_DECLINED_AT_STATUS;
1023 case EventAttendee::TENTATIVE_AT_STATUS:
1024 status = EVENT_ATTENDEE_TENTATIVE_AT_STATUS;
1026 case EventAttendee::DELEGATED_AT_STATUS:
1027 status = EVENT_ATTENDEE_DELEGATED_AT_STATUS;
1029 case EventAttendee::COMPLETED_AT_STATUS:
1030 status = EVENT_ATTENDEE_COMPLETED_AT_STATUS;
1032 case EventAttendee::IN_PROCESS_AT_STATUS:
1033 status = EVENT_ATTENDEE_IN_PROCESS_AT_STATUS;
1036 LogDebug("Use the default status");
1040 calendar_svc_value_set_int(attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS,
1042 LogError("error during setting attendee status");
1043 calendar_svc_value_free(&attendee);
1044 ThrowMsg(PlatformException, "Cannot set attendee status");
1049 calendar_svc_value_set_int(attendee, CAL_VALUE_INT_ATTENDEE_RSVP,
1050 attendeeList->at(i)->getRSVP())) {
1051 LogError("error during setting attendee RSVP");
1052 calendar_svc_value_free(&attendee);
1053 ThrowMsg(PlatformException, "Cannot set attendee RSVP");
1057 cal_event_attendee_type_t type = EVENT_ATTENDEE_INDIVIDUAL_TYPE;
1058 switch (attendeeList->at(i)->getType()) {
1059 case EventAttendee::INDIVIDUAL_TYPE:
1060 type = EVENT_ATTENDEE_INDIVIDUAL_TYPE;
1062 case EventAttendee::GROUP_TYPE:
1063 type = EVENT_ATTENDEE_GROUP_TYPE;
1065 case EventAttendee::RESOURCE_TYPE:
1066 type = EVENT_ATTENDEE_RESOURCE_TYPE;
1068 case EventAttendee::ROOM_TYPE:
1069 type = EVENT_ATTENDEE_ROOM_TYPE;
1071 case EventAttendee::UNKNOWN_TYPE:
1072 type = EVENT_ATTENDEE_UNKNOWN_TYPE;
1075 LogDebug("Use the default type");
1079 calendar_svc_value_set_int(attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_TYPE,
1081 LogError("error during setting attendee type");
1082 calendar_svc_value_free(&attendee);
1083 ThrowMsg(PlatformException, "Cannot set attendee type");
1088 calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_GROUP,
1089 attendeeList->at(i)->getGroup().c_str())) {
1090 LogError("error during setting attendee group");
1091 calendar_svc_value_free(&attendee);
1092 ThrowMsg(PlatformException, "Cannot set attendee group");
1095 // save delegatorURI
1097 calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_DELEGATOR_URI,
1098 attendeeList->at(i)->getDelegatorURI().c_str())) {
1099 LogError("error during setting attendee delegator uri");
1100 calendar_svc_value_free(&attendee);
1101 ThrowMsg(PlatformException, "Cannot set attendee delegator uri");
1106 calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_DELEGATE_URI,
1107 attendeeList->at(i)->getDelegateURI().c_str())) {
1108 LogError("error during setting attendee delegate uri");
1109 calendar_svc_value_free(&attendee);
1110 ThrowMsg(PlatformException, "Cannot set attendee delegate uri");
1115 calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_UID,
1116 attendeeList->at(i)->getContactId().c_str())) {
1117 LogError("error during setting attendee uid");
1118 calendar_svc_value_free(&attendee);
1119 ThrowMsg(PlatformException, "Cannot set attendee uid");
1122 // save addressBookId
1123 std::stringstream ss(attendeeList->at(i)->getAddressBookId());
1127 calendar_svc_value_set_int(attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX,
1129 LogError("error during setting attendee address book id");
1130 calendar_svc_value_free(&attendee);
1131 ThrowMsg(PlatformException, "Cannot set attendee address book id");
1134 attendees = g_list_append(attendees, attendee);
1137 LogDebug("m_abstractEvent->getAttendees()->size() " << attendeeList->size());
1139 calendar_svc_struct_store_list(m_platformEvent,
1140 CAL_VALUE_LST_ATTENDEE_LIST,
1143 Catch(PlatformException)
1145 LogError("error during setting attendees");
1146 calendar_svc_struct_store_list(m_platformEvent,
1147 CAL_VALUE_LST_ATTENDEE_LIST,
1149 for (; attendees; attendees = g_list_next(attendees)) {
1150 attendee = static_cast<cal_value*>(attendees->data);
1151 calendar_svc_value_free(&attendee);
1153 g_list_free(attendees);
1154 ReThrow(PlatformException);
1158 void EventWrapper::setPositionToPlatformEvent()
1160 if (!m_platformEvent) {
1161 ThrowMsg(UnknownException, "Null platform pointer.");
1164 if (CAL_SUCCESS != calendar_svc_struct_set_double(m_platformEvent,
1165 CAL_VALUE_DBL_LATITUDE,
1166 m_abstractEvent->getLatitude())) {
1167 ThrowMsg(PlatformException, "Can't set latitude.");
1170 if (CAL_SUCCESS != calendar_svc_struct_set_double(m_platformEvent,
1171 CAL_VALUE_DBL_LONGITUDE,
1172 m_abstractEvent->getLongitude())) {
1173 ThrowMsg(PlatformException, "Can't set longitude.");
1177 void EventWrapper::setPriorityToPlatformEvent()
1179 if (!m_platformEvent) {
1180 ThrowMsg(UnknownException, "Null platform pointer.");
1183 cal_priority_type_t priority = (cal_priority_type_t)-1;
1185 switch (m_abstractEvent->getPriority()) {
1186 case CalendarEvent::HIGH_PRIORITY:
1187 priority = EVENT_PRIORITY_HIGH;
1189 case CalendarEvent::MEDIUM_PRIORITY:
1190 priority = EVENT_PRIORITY_NORMAL;
1192 case CalendarEvent::LOW_PRIORITY:
1193 priority = EVENT_PRIORITY_LOW;
1199 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
1200 CAL_VALUE_INT_PRIORITY,
1203 ThrowMsg(PlatformException, "Can't set task priority.");
1207 void EventWrapper::setCreatedDateToPlatformEvent()
1209 if (!m_platformEvent) {
1210 ThrowMsg(UnknownException, "Null platform pointer.");
1213 long long int time = m_abstractEvent->getCreatedDate();
1214 if (CAL_SUCCESS != calendar_svc_struct_set_lli(m_platformEvent,
1215 CAL_VALUE_LLI_CREATED_TIME,
1217 ThrowMsg(PlatformException, "Can't set created time.");
1221 void EventWrapper::setCompletedDateToPlatformEvent()
1223 if (!m_platformEvent) {
1224 ThrowMsg(UnknownException, "Null platform pointer.");
1227 long long int time = m_abstractEvent->getCompletedDate();
1228 if (CAL_SUCCESS != calendar_svc_struct_set_lli(m_platformEvent,
1229 CAL_VALUE_LLI_COMPLETED_TIME,
1231 ThrowMsg(PlatformException, "Can't set completed time.");
1235 void EventWrapper::setProgressToPlatformEvent()
1237 if (!m_platformEvent) {
1238 ThrowMsg(UnknownException, "Null platform pointer.");
1241 int progress = m_abstractEvent->getProgress();
1242 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
1243 CAL_VALUE_INT_PROGRESS,
1245 ThrowMsg(PlatformException, "Can't set visibility.");
1249 CalendarEventPtr EventWrapper::convertPlatformEventToAbstractEvent()
1251 LogDebug("entered");
1252 setDescriptionFromPlatformEvent();
1253 setSummaryFromPlatformEvent();
1254 setStartTimeFromPlatformEvent();
1255 setEndTimeFromPlatformEvent(); // replace for duration
1256 setLocationFromPlatformEvent();
1257 setCategoriesFromPlatformEvent();
1258 setStatusFromPlatformEvent();
1259 setAlarmsFromPlatformEvent();
1260 setIsAllDayFromPlatformEvent();
1261 setOrganizerFromPlatformEvent();
1262 setAttendeesFromPlatformEvent();
1263 setPositionFromPlatformEvent();
1264 setVisibilityFromPlatformEvent();
1265 setLastModifiedDateFromPlatformEvent();
1266 setAvailabilityFromPlatformEvent();
1267 setRecurrenceRuleFromPlatformEvent();
1268 setIdFromPlatformEvent();
1269 setParentIdFromPlatformEvent();
1270 //setUIdFromPlatformEvent(); // We set the uid value as the same with id.
1271 setPriorityFromPlatformEvent();
1272 setCreatedDateFromPlatformEvent();
1273 setCompletedDateFromPlatformEvent();
1274 setProgressFromPlatformEvent();
1275 setIsDetachedFromPlatformEvent();
1277 return getAbstractEvent();
1280 void EventWrapper::setDescriptionFromPlatformEvent()
1282 if (!m_platformEvent) {
1283 ThrowMsg(UnknownException, "Null platform pointer.");
1285 const char *description = calendar_svc_struct_get_str(
1287 CAL_VALUE_TXT_DESCRIPTION);
1289 m_abstractEvent->setDescription(description);
1293 void EventWrapper::setSummaryFromPlatformEvent()
1295 if (!m_platformEvent) {
1296 ThrowMsg(UnknownException, "Null platform pointer.");
1298 const char *summary = calendar_svc_struct_get_str(m_platformEvent,
1299 CAL_VALUE_TXT_SUMMARY);
1301 m_abstractEvent->setSubject(summary);
1305 void EventWrapper::setStartTimeFromPlatformEvent()
1307 if (!m_platformEvent) {
1308 ThrowMsg(UnknownException, "Null platform pointer.");
1310 long long int startTime = calendar_svc_struct_get_lli(
1312 CALS_VALUE_LLI_DTSTART_UTIME);
1313 m_abstractEvent->setStartTime(startTime);
1315 // Retrive the time zone info only when the start time is loaded.
1316 char* timeZone = calendar_svc_struct_get_str(
1318 CALS_VALUE_TXT_DTSTART_TZID);
1320 LogInfo("timeZone: "<<timeZone);
1321 m_abstractEvent->setTimeZone(std::string(timeZone));
1323 LogWarning("Cannot read timeZone from platform!");
1325 LogInfo("startTime: "<<startTime);
1328 void EventWrapper::setEndTimeFromPlatformEvent()
1330 if (!m_platformEvent) {
1331 ThrowMsg(UnknownException, "Null platform pointer.");
1333 long long int endTime = calendar_svc_struct_get_lli(m_platformEvent,
1334 CALS_VALUE_LLI_DTEND_UTIME);
1335 m_abstractEvent->setEndTime(endTime);
1338 void EventWrapper::setLocationFromPlatformEvent()
1340 if (!m_platformEvent) {
1341 ThrowMsg(UnknownException, "Null platform pointer.");
1343 const char* location = calendar_svc_struct_get_str(m_platformEvent,
1344 CAL_VALUE_TXT_LOCATION);
1346 m_abstractEvent->setLocation(location);
1350 void EventWrapper::setRecurrenceRuleFromPlatformEvent()
1352 LogDebug("entered");
1353 if (!m_platformEvent) {
1354 ThrowMsg(UnknownException, "Null platform pointer.");
1357 EventRecurrenceRulePtr rrule(new EventRecurrenceRule());
1359 // load the recurrence frequency
1360 int frequency = calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ);
1361 LogInfo("frequency "<<frequency);
1362 switch (frequency) {
1363 case CALS_FREQ_ONCE:
1364 rrule->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
1366 case CALS_FREQ_DAILY:
1367 rrule->setFrequency(EventRecurrenceRule::DAILY_RECURRENCE);
1369 case CALS_FREQ_WEEKLY:
1370 rrule->setFrequency(EventRecurrenceRule::WEEKLY_RECURRENCE);
1372 case CALS_FREQ_MONTHLY:
1373 rrule->setFrequency(EventRecurrenceRule::MONTHLY_RECURRENCE);
1375 case CALS_FREQ_YEARLY:
1376 rrule->setFrequency(EventRecurrenceRule::YEARLY_RECURRENCE);
1379 LogWarning("Unknown recurrence frequency.");
1380 rrule->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
1385 std::vector<std::string> daysOfTheWeek;
1386 char* byday = calendar_svc_struct_get_str(m_platformEvent, CALS_VALUE_TXT_RRULE_BYDAY);
1387 LogInfo("Loaded byday: "<<byday);
1388 char* pch = strtok(byday, ",");
1389 while (NULL != pch) {
1390 daysOfTheWeek.push_back(pch);
1391 pch = strtok(NULL, ",");
1393 rrule->setDaysOfTheWeek(daysOfTheWeek);
1394 LogInfo("Number of daysOfTheWeek: "<<rrule->getDaysOfTheWeek().size());
1396 // load the recurrence interval
1397 int interval = calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_INTERVAL);
1398 rrule->setInterval(interval);
1400 // load the ocurrence count
1401 int occurrrenceCount = calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_COUNT);
1402 rrule->setOccurrenceCount(occurrrenceCount);
1404 // load the recurrence end date
1405 long long int endDate = calendar_svc_struct_get_lli(m_platformEvent, CALS_VALUE_LLI_RRULE_UNTIL_UTIME);
1406 rrule->setEndDate(endDate);
1407 LogDebug("endDate from platform = " << endDate);
1409 // load the exceptions
1410 std::vector<long long int> exceptions;
1411 char* exdate = calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_EXDATE);
1412 LogInfo("Loaded exdate: "<<exdate);
1413 pch = strtok(exdate, ",");
1414 while (NULL != pch) {
1415 std::stringstream ss(pch);
1416 long long int oneException;
1418 exceptions.push_back(oneException);
1419 pch = strtok(NULL, ",");
1421 rrule->setExceptions(exceptions);
1422 LogInfo("Number of exceptions: "<<rrule->getExceptions().size());
1424 // set the loaded recurrence rule
1425 m_abstractEvent->setRecurrenceRule(rrule);
1428 void EventWrapper::setAlarmsFromPlatformEvent()
1430 if (!m_platformEvent) {
1431 ThrowMsg(UnknownException, "Null platform pointer.");
1434 std::vector<long> alarmsTick;
1435 std::vector<CalendarEvent::EventAlarmType> alarmsType;
1436 std::vector<std::string> alarmsDescription;
1438 GList* alarmList = NULL;
1439 calendar_svc_struct_get_list(m_platformEvent, CAL_VALUE_LST_ALARM, &alarmList);
1440 cal_value* alarmValue = NULL;
1441 for (; alarmList; alarmList = g_list_next(alarmList)) {
1442 LogDebug("Processing alarm...");
1443 alarmValue = static_cast<cal_value*>(alarmList->data);
1445 int tick = calendar_svc_value_get_int(alarmValue, CAL_VALUE_INT_ALARMS_TICK);
1446 if (CAL_ERR_FAIL == tick) {
1447 LogError("Cannot read alarm tick. Stop processing alarms.");
1450 alarmsTick.push_back(tick);
1452 cal_alert_type_t type = static_cast<cal_alert_type_t>(calendar_svc_value_get_int(alarmValue, CAL_VALUE_INT_ALARMS_TYPE));
1454 LogError("Cannot read alarm type. Setting the default value.");
1457 case CAL_ALERT_VIBRATION:
1458 alarmsType.push_back(CalendarEvent::SILENT_ALARM);
1460 case CAL_ALERT_MELODY:
1461 case CAL_ALERT_INCREASING_MELODY:
1462 case CAL_ALERT_VIBRATION_THEN_MELODY:
1463 case CAL_ALERT_VIBMELODY:
1464 case CAL_ALERT_VIB_INCREASING_MELODY:
1465 alarmsType.push_back(CalendarEvent::SOUND_ALARM);
1467 case CAL_ALERT_MUTE:
1469 alarmsType.push_back(CalendarEvent::NO_ALARM);
1473 char* description = calendar_svc_value_get_str(alarmValue, CAL_VALUE_TXT_ALARMS_DESCRIPTION);
1474 if (NULL == description) {
1475 LogError("Cannot read alarm description. Setting NULL.");
1476 alarmsDescription.push_back("");
1478 alarmsDescription.push_back(description);
1481 // Save the vectors.
1482 m_abstractEvent->setAlarmsTick(alarmsTick);
1483 m_abstractEvent->setAlarmsType(alarmsType);
1484 m_abstractEvent->setAlarmsDescription(alarmsDescription);
1486 LogInfo("Number of alarms: "<<m_abstractEvent->getAlarmsTick().size());
1489 void EventWrapper::setStatusFromPlatformEvent()
1491 if (!m_platformEvent) {
1492 ThrowMsg(UnknownException, "Null platform pointer.");
1495 cals_status_t status = static_cast<cals_status_t>(calendar_svc_struct_get_int(m_platformEvent,
1496 CAL_VALUE_INT_TASK_STATUS));
1498 case CALS_EVENT_STATUS_TENTATIVE:
1499 m_abstractEvent->setStatus(CalendarEvent::TENTATIVE_STATUS);
1501 case CALS_EVENT_STATUS_CONFIRMED:
1502 m_abstractEvent->setStatus(CalendarEvent::CONFIRMED_STATUS);
1504 case CALS_EVENT_STATUS_CANCELLED:
1505 case CALS_TODO_STATUS_CANCELLED:
1506 m_abstractEvent->setStatus(CalendarEvent::CANCELLED_STATUS);
1508 case CALS_TODO_STATUS_NEEDS_ACTION:
1509 m_abstractEvent->setStatus(CalendarEvent::NEEDS_ACTION_STATUS);
1511 case CALS_TODO_STATUS_COMPLETED:
1512 m_abstractEvent->setStatus(CalendarEvent::COMPLETED_STATUS);
1514 case CALS_TODO_STATUS_IN_PROCESS:
1515 m_abstractEvent->setStatus(CalendarEvent::IN_PROCESS_STATUS);
1518 m_abstractEvent->setStatus(CalendarEvent::UNDEFINED_STATUS);
1523 void EventWrapper::setCategoriesFromPlatformEvent()
1525 if (!m_platformEvent) {
1526 ThrowMsg(UnknownException, "Null platform pointer.");
1528 m_abstractEvent->getCategories()->clear();
1530 char *categories = calendar_svc_struct_get_str(
1532 CAL_VALUE_TXT_CATEGORIES);
1535 LogInfo("Loaded categories: "<<categories);
1537 char* pch = strtok(categories, ",");
1538 while (NULL != pch) {
1539 m_abstractEvent->getCategories()->push_back(pch);
1540 pch = strtok(NULL, ",");
1544 LogInfo("Number of categories: "<<m_abstractEvent->getCategories()->size());
1547 void EventWrapper::setIdFromPlatformEvent()
1549 if (!m_platformEvent) {
1550 ThrowMsg(UnknownException, "Null platform pointer.");
1552 m_abstractEvent->setId(getIdFromPlatformEvent());
1554 // Set the uid also.
1555 std::stringstream ss;
1556 ss<<getIdFromPlatformEvent();
1557 m_abstractEvent->setUId(ss.str());
1560 void EventWrapper::setParentIdFromPlatformEvent()
1562 if (!m_platformEvent) {
1563 ThrowMsg(UnknownException, "Null platform pointer.");
1566 int parentId = calendar_svc_struct_get_int(m_platformEvent,
1567 CAL_VALUE_INT_ORIGINAL_EVENT_ID);
1569 m_abstractEvent->setParentId(parentId);
1572 void EventWrapper::setIsAllDayFromPlatformEvent()
1574 if (!m_platformEvent) {
1575 ThrowMsg(UnknownException, "Null platform pointer.");
1578 int timeType = calendar_svc_struct_get_int(m_platformEvent,
1579 CALS_VALUE_INT_DTSTART_TYPE);
1581 if(timeType==CALS_TIME_LOCALTIME) {
1582 m_abstractEvent->setIsAllDay(true);
1584 m_abstractEvent->setIsAllDay(false);
1588 void EventWrapper::setOrganizerFromPlatformEvent()
1590 if (!m_platformEvent) {
1591 ThrowMsg(UnknownException, "Null platform pointer.");
1593 const char* organizer = calendar_svc_struct_get_str(m_platformEvent,
1594 CAL_VALUE_TXT_ORGANIZER_NAME);
1596 m_abstractEvent->setOrganizer(organizer);
1600 void EventWrapper::setLastModifiedDateFromPlatformEvent()
1602 if (!m_platformEvent) {
1603 ThrowMsg(UnknownException, "Null platform pointer.");
1605 long long int lastModifiedDate = calendar_svc_struct_get_lli(
1607 CALS_VALUE_LLI_LASTMOD);
1608 m_abstractEvent->setLastModifiedDate(lastModifiedDate);
1611 void EventWrapper::setVisibilityFromPlatformEvent()
1613 if (!m_platformEvent) {
1614 ThrowMsg(UnknownException, "Null platform pointer.");
1617 int visibility = calendar_svc_struct_get_int(m_platformEvent,
1618 CAL_VALUE_INT_SENSITIVITY);
1619 switch (visibility) {
1620 case PUBLIC_VISIBILITY:
1621 m_abstractEvent->setVisibility(CalendarEvent::PUBLIC_VISIBILITY);
1623 case PRIVATE_VISIBILITY:
1624 m_abstractEvent->setVisibility(CalendarEvent::PRIVATE_VISIBILITY);
1626 case CONFIDENTIAL_VISIBILITY:
1627 m_abstractEvent->setVisibility(CalendarEvent::CONFIDENTIAL_VISIBILITY);
1630 m_abstractEvent->setVisibility(CalendarEvent::PUBLIC_VISIBILITY);
1635 void EventWrapper::setAvailabilityFromPlatformEvent()
1637 if (!m_platformEvent) {
1638 ThrowMsg(UnknownException, "Null platform pointer.");
1641 cal_status_type_t availability =
1642 static_cast<cal_status_type_t>(calendar_svc_struct_get_int(
1644 CAL_VALUE_INT_AVAILABILITY));
1645 switch (availability) {
1647 m_abstractEvent->setAvailability(CalendarEvent::BUSY_FB);
1649 case EVENT_BUSY_UNAVAILABLE_FB:
1650 m_abstractEvent->setAvailability(CalendarEvent::BUSY_UNAVAILABLE_FB);
1653 m_abstractEvent->setAvailability(CalendarEvent::FREE_FB);
1655 case EVENT_BUSY_TENTATIVE_FB:
1656 m_abstractEvent->setAvailability(CalendarEvent::BUSY_TENTATIVE_FB);
1659 m_abstractEvent->setAvailability(CalendarEvent::FREE_FB);
1664 void EventWrapper::setUIdFromPlatformEvent()
1666 if (!m_platformEvent) {
1667 ThrowMsg(UnknownException, "Null platform pointer.");
1669 const char* uid = calendar_svc_struct_get_str(m_platformEvent,
1672 m_abstractEvent->setUId(uid);
1676 void EventWrapper::setAttendeesFromPlatformEvent()
1678 LogDebug("entered");
1680 if (!m_platformEvent) {
1681 ThrowMsg(UnknownException, "Null platform pointer.");
1684 if ( NULL != m_abstractEvent->getAttendees() )
1685 m_abstractEvent->getAttendees()->clear();
1687 GList *attendees = NULL;
1689 calendar_svc_struct_get_list(m_platformEvent,
1690 CAL_VALUE_LST_ATTENDEE_LIST,
1692 LogError("Cannot read attendees list");
1695 cal_value* attendee = NULL;
1696 for (; attendees; attendees = g_list_next(attendees)) {
1697 LogDebug("Processing attendee...");
1698 attendee = static_cast<cal_value*>(attendees->data);
1699 EventAttendeePtr attendeePtr(new EventAttendee());
1702 char* attendeeName = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME);
1703 if (NULL == attendeeName) {
1704 LogError("Cannot read attendee name. Setting an empty string.");
1705 attendeePtr->setName("");
1707 attendeePtr->setName(attendeeName);
1711 char* attendeeURI = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL);
1712 if (NULL == attendeeURI) {
1713 LogError("Cannot read attendee URI. Setting an empty string.");
1714 attendeePtr->setURI("");
1716 attendeePtr->setURI(attendeeURI);
1720 cal_event_attendee_role_type_t attendeeRole =
1721 static_cast<cal_event_attendee_role_type_t>(calendar_svc_value_get_int(
1723 CAL_VALUE_INT_ATTENDEE_ROLE));
1724 if (0 > attendeeRole) {
1725 LogError("Cannot read attendee role. Setting the default value.");
1727 switch (attendeeRole) {
1728 case EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE:
1729 attendeePtr->setRole(EventAttendee::REQ_PARTICIPANT_ROLE);
1731 case EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE:
1732 attendeePtr->setRole(EventAttendee::OPT_PARTICIPANT_ROLE);
1734 case EVENT_ATTENDEE_NON_PARTICIPANT_ROLE:
1735 attendeePtr->setRole(EventAttendee::NON_PARTICIPANT_ROLE);
1737 case EVENT_ATTENDEE_CHAIR_ROLE:
1738 attendeePtr->setRole(EventAttendee::CHAIR_ROLE);
1741 attendeePtr->setRole(EventAttendee::REQ_PARTICIPANT_ROLE);
1746 cal_event_attendee_status_type_t attendeeStatus =
1747 static_cast<cal_event_attendee_status_type_t>(calendar_svc_value_get_int(
1749 CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS));
1750 if (0 > attendeeStatus) {
1751 LogError("Cannot read attendee status. Setting the default value.");
1753 switch (attendeeStatus) {
1754 case EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS:
1755 attendeePtr->setStatus(EventAttendee::PENDING_AT_STATUS);
1757 case EVENT_ATTENDEE_ACCEPTED_AT_STATUS:
1758 attendeePtr->setStatus(EventAttendee::ACCEPTED_AT_STATUS);
1760 case EVENT_ATTENDEE_DECLINED_AT_STATUS:
1761 attendeePtr->setStatus(EventAttendee::DECLINED_AT_STATUS);
1763 case EVENT_ATTENDEE_TENTATIVE_AT_STATUS:
1764 attendeePtr->setStatus(EventAttendee::TENTATIVE_AT_STATUS);
1766 case EVENT_ATTENDEE_DELEGATED_AT_STATUS:
1767 attendeePtr->setStatus(EventAttendee::DELEGATED_AT_STATUS);
1769 case EVENT_ATTENDEE_COMPLETED_AT_STATUS:
1770 attendeePtr->setStatus(EventAttendee::COMPLETED_AT_STATUS);
1772 case EVENT_ATTENDEE_IN_PROCESS_AT_STATUS:
1773 attendeePtr->setStatus(EventAttendee::IN_PROCESS_AT_STATUS);
1776 attendeePtr->setStatus(EventAttendee::PENDING_AT_STATUS);
1781 int attendeeRSVP = calendar_svc_value_get_int(attendee, CAL_VALUE_INT_ATTENDEE_RSVP);
1782 if (0 > attendeeRSVP) {
1783 LogError("Cannot read attendee RSVP. Setting the default value.");
1785 attendeePtr->setRSVP(attendeeRSVP>0 ? true : false);
1788 cal_event_attendee_type_t attendeeType =
1789 static_cast<cal_event_attendee_type_t>(calendar_svc_value_get_int(
1791 CAL_VALUE_INT_ATTENDEE_DETAIL_TYPE));
1792 if (0 > attendeeType) {
1793 LogError("Cannot read attendee type. Setting the default value.");
1795 switch (attendeeType) {
1796 case EVENT_ATTENDEE_INDIVIDUAL_TYPE:
1797 attendeePtr->setType(EventAttendee::INDIVIDUAL_TYPE);
1799 case EVENT_ATTENDEE_GROUP_TYPE:
1800 attendeePtr->setType(EventAttendee::GROUP_TYPE);
1802 case EVENT_ATTENDEE_RESOURCE_TYPE:
1803 attendeePtr->setType(EventAttendee::RESOURCE_TYPE);
1805 case EVENT_ATTENDEE_ROOM_TYPE:
1806 attendeePtr->setType(EventAttendee::ROOM_TYPE);
1808 case EVENT_ATTENDEE_UNKNOWN_TYPE:
1809 attendeePtr->setType(EventAttendee::UNKNOWN_TYPE);
1812 attendeePtr->setType(EventAttendee::INDIVIDUAL_TYPE);
1817 char* attendeeGroup = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_GROUP);
1818 if (NULL == attendeeGroup) {
1819 LogError("Cannot read attendee group. Setting an empty string.");
1820 attendeePtr->setGroup("");
1822 attendeePtr->setGroup(attendeeGroup);
1825 // load delegatorURI
1826 char* attendeeDelegatorURI = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_DELEGATOR_URI);
1827 if (NULL == attendeeDelegatorURI) {
1828 LogError("Cannot read attendee delegatorURI. Setting an empty string.");
1829 attendeePtr->setDelegatorURI("");
1831 attendeePtr->setDelegatorURI(attendeeDelegatorURI);
1835 char* attendeeDelegateURI = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_DELEGATE_URI);
1836 if (NULL == attendeeDelegateURI) {
1837 LogError("Cannot read attendee delegateURI. Setting an empty string.");
1838 attendeePtr->setDelegateURI("");
1840 attendeePtr->setDelegateURI(attendeeDelegateURI);
1844 char* attendeeContactId = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_UID);
1845 if (NULL == attendeeContactId) {
1846 LogError("Cannot read attendee UId. Setting an empty string.");
1847 attendeePtr->setContactId("");
1849 attendeePtr->setContactId(attendeeContactId);
1852 // load addressBookId
1853 int attendeeAddressBookId = calendar_svc_value_get_int(attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX);
1854 if ( 0>attendeeAddressBookId) {
1855 LogError("Cannot read attendee address book id. Setting an empty string.");
1856 attendeeAddressBookId = -1;
1858 std::stringstream ss;
1859 if (attendeeAddressBookId>=0) {
1860 ss<<attendeeAddressBookId;
1864 attendeePtr->setAddressBookId(ss.str());
1866 m_abstractEvent->getAttendees()->push_back(attendeePtr);
1870 void EventWrapper::setPositionFromPlatformEvent()
1872 if (!m_platformEvent) {
1873 ThrowMsg(UnknownException, "Null platform pointer.");
1876 double value = calendar_svc_struct_get_double(
1878 CAL_VALUE_DBL_LATITUDE);
1879 m_abstractEvent->setLatitude(value);
1881 value = calendar_svc_struct_get_double(
1883 CAL_VALUE_DBL_LONGITUDE);
1884 m_abstractEvent->setLongitude(value);
1887 void EventWrapper::setPriorityFromPlatformEvent()
1889 if (!m_platformEvent) {
1890 ThrowMsg(UnknownException, "Null platform pointer.");
1893 cal_priority_type_t priority = static_cast<cal_priority_type_t>(calendar_svc_struct_get_int(m_platformEvent,
1894 CAL_VALUE_INT_PRIORITY));
1896 case EVENT_PRIORITY_LOW:
1897 m_abstractEvent->setPriority(CalendarEvent::LOW_PRIORITY);
1899 case EVENT_PRIORITY_NORMAL:
1900 m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
1902 case EVENT_PRIORITY_HIGH:
1903 m_abstractEvent->setPriority(CalendarEvent::HIGH_PRIORITY);
1906 m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
1911 void EventWrapper::setCreatedDateFromPlatformEvent()
1913 if (!m_platformEvent) {
1914 ThrowMsg(UnknownException, "Null platform pointer.");
1917 long long int createdDate = 0;
1918 createdDate = calendar_svc_struct_get_lli(m_platformEvent,
1919 CALS_VALUE_LLI_LASTMOD);
1921 m_abstractEvent->setCreatedDate(createdDate);
1924 void EventWrapper::setCompletedDateFromPlatformEvent()
1926 if (!m_platformEvent) {
1927 ThrowMsg(UnknownException, "Null platform pointer.");
1930 long long int completedDate = 0;
1931 completedDate = calendar_svc_struct_get_lli(m_platformEvent,
1932 CAL_VALUE_LLI_COMPLETED_TIME);
1934 LogInfo("completedDate: "<<completedDate);
1935 m_abstractEvent->setCompletedDate(completedDate);
1938 void EventWrapper::setProgressFromPlatformEvent()
1940 if (!m_platformEvent) {
1941 ThrowMsg(UnknownException, "Null platform pointer.");
1945 progress = calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_PROGRESS);
1947 LogInfo("progress: "<<progress);
1948 m_abstractEvent->setProgress(progress);
1951 void EventWrapper::setIsDetachedFromPlatformEvent()
1953 if (!m_platformEvent) {
1954 ThrowMsg(UnknownException, "Null platform pointer.");
1957 int isDetached = calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_ORIGINAL_EVENT_ID);
1959 m_abstractEvent->setIsDetached(true);
1960 LogInfo("This is a detached event.");
1962 m_abstractEvent->setIsDetached(false);
1966 void EventWrapper::displayAbstractEvent()
1968 m_abstractEvent->display();
1971 void EventWrapper::displayPlatformEvent()
1973 LogDebug("event id: " << calendar_svc_struct_get_int(m_platformEvent,
1974 CAL_VALUE_INT_INDEX));
1976 long long int startTime = calendar_svc_struct_get_lli(
1977 m_platformEvent, CALS_VALUE_LLI_DTSTART_UTIME);
1978 LogDebug("event start time: " << startTime);
1980 LogDebug("event end time: " << calendar_svc_struct_get_lli(m_platformEvent, CALS_VALUE_LLI_DTEND_UTIME));
1981 LogDebug("event location: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_LOCATION));
1982 LogDebug("event summary: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_SUMMARY));
1983 LogDebug("event description: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_DESCRIPTION));
1984 LogDebug("event isAllDay: " << calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_DTSTART_TYPE));
1985 LogDebug("event organizer: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_ORGANIZER_NAME));
1986 LogDebug("event lastModifiedDate: " << calendar_svc_struct_get_lli(m_platformEvent, CALS_VALUE_LLI_LASTMOD));
1987 LogDebug("event visibility: " << calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_SENSITIVITY));
1988 LogDebug("event availability: " << calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_BUSY_STATUS));
1989 LogDebug("event categories: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_CATEGORIES));
1990 LogDebug("event uid: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_UID));
1992 GList *attendees = NULL;
1993 if (CAL_SUCCESS != calendar_svc_struct_get_list(m_platformEvent, CAL_VALUE_LST_ATTENDEE_LIST, &attendees)) {
1994 LogError("cannot read attendee list");
1997 cal_value* attendee = NULL;
1998 for (; attendees; attendees = g_list_next(attendees)) {
1999 attendee = static_cast<cal_value*>(attendees->data);
2000 char* attendeeName = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME);
2001 if (NULL == attendeeName) {
2002 LogError("cannot read attendee name");
2005 LogDebug("event attendees: " << attendeeName);
2008 LogDebug("event repeat frequency: " << calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ));
2009 LogDebug("event repeat interval: " << calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_INTERVAL));
2010 LogDebug("event repeat occurrence count: " << calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_COUNT));
2011 LogDebug("event repeat end date: " << calendar_svc_struct_get_lli(m_platformEvent, CALS_VALUE_LLI_RRULE_UNTIL_UTIME));
2012 LogDebug("event exceptions: " << calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_EXDATE));
2015 CalendarEvent::CalendarType EventWrapper::getType()
2017 return m_calendarType;