2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <Commons/Exception.h>
22 #include "EventWrapper.h"
24 #include "CalendarUtility.h"
27 using namespace WrtDeviceApis::Commons;
32 EventWrapper::EventWrapper(CalendarEvent::CalendarType type) :
33 m_platformEvent(NULL),
34 m_abstractEvent(NULL),
37 m_abstractEvent = CalendarEventPtr(new CalendarEvent());
38 if (!m_abstractEvent) {
39 ThrowMsg(UnknownException, "Abstract object is not created.");
43 EventWrapper::EventWrapper(const CalendarEventPtr &event, CalendarEvent::CalendarType type) :
44 m_platformEvent(NULL),
45 m_abstractEvent(event),
50 EventWrapper::EventWrapper(calendar_record_h event, CalendarEvent::CalendarType type) :
51 m_platformEvent(event),
52 m_abstractEvent(NULL),
55 m_abstractEvent = CalendarEventPtr(new CalendarEvent());
56 if (!m_abstractEvent) {
57 ThrowMsg(UnknownException, "Abstract object is not created.");
61 EventWrapper::~EventWrapper()
66 void EventWrapper::saveEvent()
68 if (m_platformEvent == NULL) {
69 ThrowMsg(NullPointerException, "m_platformEvent is not set");
72 int itemId = m_abstractEvent->getId();
73 LoggerD("Before saving/update eventId: " << itemId);
75 //displayPlatformEvent();
78 if (itemId <= UNDEFINED_ITEM_ID) {
79 ret = calendar_db_insert_record(m_platformEvent, &itemId);
80 if (CALENDAR_ERROR_NONE!=ret) {
81 ThrowMsg(PlatformException, "Can't insert new item: "<<ret);
83 m_abstractEvent->setId(itemId);
84 LoggerD("New calendar item inserted with id: "<<itemId);
86 ret = calendar_db_update_record(m_platformEvent);
87 if (CALENDAR_ERROR_NONE != ret) {
88 ThrowMsg(PlatformException, "Can't update new item: "<<ret);
90 LoggerD("Calendar item updated.");
94 void EventWrapper::loadEvent(int id)
96 LoggerD("Item id to load: " << id);
100 if(getType() == CalendarEvent::TASK_TYPE) {
101 dataType = _calendar_todo._uri;
103 dataType = _calendar_event._uri;
106 int ret = calendar_db_get_record(dataType, id, &m_platformEvent);
107 if (CALENDAR_ERROR_NONE!=ret) {
108 m_platformEvent = NULL;
109 ThrowMsg(NotFoundException, "Can't get item with id: "<<id<<", error code: "<<ret);
113 if(getType() == CalendarEvent::TASK_TYPE) {
114 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.is_deleted, &isDeleted);
116 ret = calendar_record_get_int(m_platformEvent, _calendar_event.is_deleted, &isDeleted);
118 if (CALENDAR_ERROR_NONE!=ret) {
119 ThrowMsg(NotFoundException, "Item already deleted.");
122 convertPlatformEventToAbstractEvent();
124 m_abstractEvent->setCalendarType(getType());
126 //displayAbstractEvent();
129 void EventWrapper::deleteEvent()
131 if (m_platformEvent == NULL) {
132 ThrowMsg(NullPointerException, "Platform event is null.");
135 // If the recurrenceId is set, delete the instance of recurring event only.
136 int itemId = m_abstractEvent->getId();
137 long long int recurrenceId = m_abstractEvent->getRecurrenceId();
138 LoggerD("itemId to delete: " << itemId << ", recurrenceId: " << recurrenceId << ", type: " << getType());
140 calendar_record_h item = NULL;
141 const char *dataType;
142 if(getType() == CalendarEvent::TASK_TYPE) {
143 dataType = _calendar_todo._uri;
145 dataType = _calendar_event._uri;
148 int ret = calendar_db_get_record(dataType, itemId, &item);
149 if (CALENDAR_ERROR_NONE != ret) {
150 ThrowMsg(NotFoundException, "Can't get calendar item: "<<ret);
154 if(CalendarEvent::TASK_TYPE==getType()) {
155 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.is_deleted, &isDeleted);
157 ret = calendar_record_get_int(m_platformEvent, _calendar_event.is_deleted, &isDeleted);
159 if (CALENDAR_ERROR_NONE!=ret) {
161 calendar_record_destroy(item, true);
163 ThrowMsg(NotFoundException, "Item already deleted.");
167 calendar_record_destroy(item, true);
170 if ( 0>=recurrenceId || true==getAbstractEvent()->getIsDetached()) {
171 // Platform detects the detached events and uptates all instances.
172 ret = calendar_db_delete_record(dataType, itemId);
173 if (CALENDAR_ERROR_NONE != ret) {
174 if(CALENDAR_ERROR_DB_RECORD_NOT_FOUND==ret) {
175 ThrowMsg(NotFoundException, "Item not found.");
177 ThrowMsg(PlatformException, "Can't delete calendar item: "<<ret);
180 m_abstractEvent->resetId();
182 EventRecurrenceRulePtr rrule = m_abstractEvent->getRecurrenceRule();
183 (*rrule->getExceptions()).push_back(recurrenceId);
185 std::string exdate = "";
186 for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ ) {
187 std::stringstream ss;
188 ss<<rrule->getExceptions()->at(i);
189 exdate.append(ss.str());
190 if(i!=rrule->getExceptions()->size()-1) {
194 ret = calendar_record_set_str(m_platformEvent, _calendar_event.exdate, exdate.c_str());
195 if(ret!=CALENDAR_ERROR_NONE) {
196 ThrowMsg(PlatformException, "Can't delete the instance: "<<ret);
198 LoggerD("Set the exdate: "<<exdate);
201 ret = calendar_db_update_record(m_platformEvent);
202 if (CALENDAR_ERROR_NONE != ret) {
203 ThrowMsg(PlatformException, "Can't update the exdate "<<ret);
205 LoggerD("Calendar item instance deleted.");
209 void EventWrapper::createEventFromString(std::string value)
212 ThrowMsg(NullPointerException, "Failed to create an item from string.");
214 LoggerD("string to convert: "<<value);
217 calendar_list_h list = NULL;
220 ret = calendar_vcalendar_parse_to_calendar(value.c_str(), &list);
221 if (CALENDAR_ERROR_NONE != ret) {
222 ThrowMsg(PlatformException, "Can't convert string: "<<ret);
225 ThrowMsg(PlatformException, "No items converted.");
229 if(CALENDAR_ERROR_NONE!=calendar_list_get_count(list, &count)){
230 LoggerW("Getting list count failed.");
232 LoggerD("List count: "<<count);
235 calendar_record_h currentItem = NULL;
237 calendar_list_first(list);
240 // We cover only one item per string.
243 ret = calendar_list_get_current_record_p(list, ¤tItem);
244 if(CALENDAR_ERROR_NONE!=ret) {
245 LoggerW("Getting current record failed: "<<ret);
248 // Filter out the extended features.
250 ret = calendar_record_get_uri_p(currentItem, &uri);
251 if(CALENDAR_ERROR_NONE!=ret) {
252 LoggerW("Getting uri failed: "<<ret);
255 if ( 0==strcmp(uri, _calendar_event._uri) && CalendarEvent::EVENT_TYPE==getType()) {
256 LoggerD("Found an event.");
257 } else if ( 0==strcmp(uri, _calendar_todo._uri) && CalendarEvent::TASK_TYPE==getType()) {
258 LoggerD("Found a task.");
260 LoggerD("Skip an extended feature.");
261 calendar_list_next(list);
265 ret = calendar_record_clone(currentItem, &m_platformEvent);
266 if(CALENDAR_ERROR_NONE!=ret) {
267 LoggerW("Clonning failed: "<<ret);
272 calendar_list_destroy(list, true);
275 //displayPlatformEvent();
278 std::string EventWrapper::exportEventToString()
280 char *vStrings = NULL;
281 calendar_list_h list = NULL;
283 std::string returnString;
285 ret = calendar_list_create(&list);
286 if (CALENDAR_ERROR_NONE != ret) {
287 ThrowMsg(PlatformException, "Can't create a list: "<<ret);
290 ret = calendar_list_add(list, m_platformEvent);
291 if (CALENDAR_ERROR_NONE != ret) {
292 ThrowMsg(PlatformException, "Can't add list item: "<<ret);
295 ret = calendar_vcalendar_make_from_records(list, &vStrings);
296 if (CALENDAR_ERROR_NONE != ret) {
297 ThrowMsg(PlatformException, "Can't convert item to string: "<<ret);
299 if (NULL==vStrings) {
300 ThrowMsg(PlatformException, "No items converted.");
303 returnString = std::string(vStrings);
309 // Don't destroy the record itself.
310 calendar_list_destroy(list, false);
316 calendar_record_h EventWrapper::getPlatformEvent() const
318 return m_platformEvent;
321 CalendarEventPtr EventWrapper::getAbstractEvent() const
323 return m_abstractEvent;
326 void EventWrapper::freePlatformEvent()
328 if (m_platformEvent != NULL) {
329 if (CALENDAR_ERROR_NONE != calendar_record_destroy(m_platformEvent, true)) {
330 LoggerW("Can't destroy calendar record.");
332 m_platformEvent = NULL;
334 LoggerD("Null platform event.");
338 calendar_record_h EventWrapper::convertAbstractEventToPlatformEvent(bool loadBeforeConvert)
341 const char *dataType;
344 if(getType() == CalendarEvent::TASK_TYPE) {
345 dataType = _calendar_todo._uri;
347 dataType = _calendar_event._uri;
350 if(loadBeforeConvert) {
351 // Load the item for update operation to include the id.
352 ret = calendar_db_get_record(dataType, m_abstractEvent->getId(), &m_platformEvent);
353 if (CALENDAR_ERROR_NONE!=ret) {
354 ThrowMsg(NotFoundException, "Can't load the item with id: "<<m_abstractEvent->getId()<<", error code: "<<ret);
356 LoggerD("Item loaded with id: "<<m_abstractEvent->getId());
359 ret = calendar_record_create(dataType, &m_platformEvent);
360 if (CALENDAR_ERROR_NONE != ret) {
361 ThrowMsg(PlatformException, "Can't create platform record: "<<ret);
363 LoggerD("Platform item created with dataType: "<<dataType);
367 setCalendarIdToPlatformEvent();
368 setDescriptionToPlatformEvent();
369 setSummaryToPlatformEvent();
370 setStartTimeToPlatformEvent();
371 setEndTimeToPlatformEvent(); // replacement for duration
372 setLocationToPlatformEvent();
373 setCategoriesToPlatformEvent();
374 setStatusToPlatformEvent();
375 setAlarmsToPlatformEvent();
376 setIsAllDayToPlatformEvent();
377 setOrganizerToPlatformEvent();
378 setAttendeesToPlatformEvent();
379 setPositionToPlatformEvent();
380 setVisibilityToPlatformEvent();
381 setAvailabilityToPlatformEvent();
382 setRecurrenceRuleToPlatformEvent();
383 //setUIdToPlatformEvent(); // We don't set uid but use id field instead.
384 setRecurrenceIdToPlatformEvent();
385 setParentIdToPlatformEvent();
386 setPriorityToPlatformEvent();
387 setCreatedDateToPlatformEvent();
388 setCompletedDateToPlatformEvent();
389 setProgressToPlatformEvent();
391 return getPlatformEvent();
394 void EventWrapper::setCalendarIdToPlatformEvent()
398 if(CalendarEvent::TASK_TYPE==getType()) {
399 ret = calendar_record_set_int(m_platformEvent, _calendar_todo.calendar_book_id, m_abstractEvent->getCalendarId());
401 ret = calendar_record_set_int(m_platformEvent, _calendar_event.calendar_book_id, m_abstractEvent->getCalendarId());
403 if (CALENDAR_ERROR_NONE!=ret) {
404 LoggerW("Can't set calendarId.");
408 void EventWrapper::setDescriptionToPlatformEvent()
411 if(CalendarEvent::TASK_TYPE==getType()) {
412 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.description, m_abstractEvent->getDescription().c_str());
414 ret = calendar_record_set_str(m_platformEvent, _calendar_event.description, m_abstractEvent->getDescription().c_str());
416 if (CALENDAR_ERROR_NONE!=ret) {
417 LoggerW("Can't set item description.");
421 void EventWrapper::setSummaryToPlatformEvent()
424 if(CalendarEvent::TASK_TYPE==getType()) {
425 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.summary, m_abstractEvent->getSubject().c_str());
427 ret = calendar_record_set_str(m_platformEvent, _calendar_event.summary, m_abstractEvent->getSubject().c_str());
429 if (CALENDAR_ERROR_NONE != ret) {
430 LoggerW("Can't set item subject.");
434 void EventWrapper::setStartTimeToPlatformEvent()
437 long long int time = m_abstractEvent->getStartTime();
438 if (time == UNDEFINED_TIME) {
439 time = m_abstractEvent->getEndTime();
442 std::string timeZone = m_abstractEvent->getTimeZone();
445 if(m_abstractEvent->getIsAllDay()) {
446 cal.type = CALENDAR_TIME_LOCALTIME;
447 cal.time.date = CalendarUtility::LLIToCalTime(timeZone.c_str(), time).time.date;
449 cal.type = CALENDAR_TIME_UTIME;
450 cal.time.utime = time;
453 if(CalendarEvent::TASK_TYPE==getType()) {
454 ret = calendar_record_set_caltime(m_platformEvent, _calendar_todo.start_time, cal);
456 ret = calendar_record_set_caltime(m_platformEvent, _calendar_event.start_time, cal);
458 if (CALENDAR_ERROR_NONE != ret) {
459 ThrowMsg(PlatformException, "Can't set start time: "<<ret);
461 LoggerD("Set start time.");
464 if(CalendarEvent::TASK_TYPE==getType()) {
465 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.start_tzid, timeZone.c_str());
467 ret = calendar_record_set_str(m_platformEvent, _calendar_event.start_tzid, timeZone.c_str());
469 if (CALENDAR_ERROR_NONE != ret) {
470 ThrowMsg(PlatformException, "Can't set start time zone: "<<ret);
472 LoggerD("Set time zone: "<<timeZone);
476 void EventWrapper::setEndTimeToPlatformEvent()
479 long long int time = m_abstractEvent->getEndTime();
480 if (time == UNDEFINED_TIME) {
481 time = m_abstractEvent->getStartTime();
485 if(m_abstractEvent->getIsAllDay()) {
486 cal.type = CALENDAR_TIME_LOCALTIME;
487 cal.time.date = CalendarUtility::LLIToCalTime(m_abstractEvent->getTimeZone().c_str(), time).time.date;
489 cal.type = CALENDAR_TIME_UTIME;
490 cal.time.utime = time;
493 if(CalendarEvent::TASK_TYPE==getType()) {
494 ret = calendar_record_set_caltime(m_platformEvent, _calendar_todo.due_time, cal);
496 ret = calendar_record_set_caltime(m_platformEvent, _calendar_event.end_time, cal);
498 if (CALENDAR_ERROR_NONE != ret) {
499 LoggerW("Can't set end/due time: "<<ret);
503 void EventWrapper::setLocationToPlatformEvent()
506 if(CalendarEvent::TASK_TYPE==getType()) {
507 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.location, m_abstractEvent->getLocation().c_str());
509 ret = calendar_record_set_str(m_platformEvent, _calendar_event.location, m_abstractEvent->getLocation().c_str());
511 if (CALENDAR_ERROR_NONE != ret) {
512 LoggerW("Can't set location.");
516 void EventWrapper::setRecurrenceRuleToPlatformEvent()
518 if (CalendarEvent::TASK_TYPE==getType()) {
519 LoggerD("No need to set rrule for a task.");
523 EventRecurrenceRulePtr rrule = m_abstractEvent->getRecurrenceRule();
525 LoggerW("No way! Rrule is not set!");
527 } else if(EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
528 LoggerD("No recurrence frequency.");
529 } else if(EventRecurrenceRule::UNDEFINED_RECURRENCE==rrule->getFrequency()) {
530 LoggerD("Undefined recurrence frequency.");
532 LoggerD("frequency "<<rrule->getFrequency());
536 switch (rrule->getFrequency()) {
537 case EventRecurrenceRule::NO_RECURRENCE:
538 case EventRecurrenceRule::UNDEFINED_RECURRENCE:
539 if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_NONE)) {
540 LoggerW("Failed setting frequency.");
543 case EventRecurrenceRule::DAILY_RECURRENCE:
544 if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_DAILY)) {
545 LoggerW("Failed setting frequency.");
548 case EventRecurrenceRule::WEEKLY_RECURRENCE:
550 if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_WEEKLY)) {
551 LoggerW("Failed setting frequency.");
555 case EventRecurrenceRule::MONTHLY_RECURRENCE:
557 if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_MONTHLY)) {
558 LoggerW("Failed setting frequency.");
562 case EventRecurrenceRule::YEARLY_RECURRENCE:
564 if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY)) {
565 LoggerW("Failed setting frequency.");
570 LoggerW("Invalid reccurence rule frequency "<<rrule->getFrequency());
575 StringArrayPtr daysOfTheWeek = rrule->getDaysOfTheWeek();
576 if( 0 != daysOfTheWeek->size() ) {
577 std::string byday = "";
578 for(unsigned int i=0; i<daysOfTheWeek->size(); i++) {
579 byday.append(daysOfTheWeek->at(i));
580 if(i!=daysOfTheWeek->size()-1) {
585 LoggerD("byday: "<<byday);
586 if (CALENDAR_ERROR_NONE!=calendar_record_set_str(m_platformEvent, _calendar_event.byday, byday.c_str())) {
587 LoggerW("Can't set byday.");
591 // set the ocurrence count
592 if (-1 != rrule->getOccurrenceCount()) {
593 LoggerD("Set the occurrence count: "<<rrule->getOccurrenceCount());
595 if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent, _calendar_event.range_type, CALENDAR_RANGE_COUNT)) {
596 LoggerW("Can't set rrule range type.");
599 if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent, _calendar_event.count, rrule->getOccurrenceCount())) {
600 LoggerW("Can't set occurrence count.");
604 // set the exceptions
605 if ( !rrule->getExceptions()->empty() )
607 LoggerD("Set the exceptions of length: "<<rrule->getExceptions()->size());
609 std::string exdate = "";
610 for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ )
612 std::stringstream ss;
613 ss<<rrule->getExceptions()->at(i);
614 exdate.append(ss.str());
615 if(i!=rrule->getExceptions()->size()-1) {
619 LoggerD("exdate: "<<exdate);
620 if (CALENDAR_ERROR_NONE!=calendar_record_set_str(m_platformEvent, _calendar_event.exdate, exdate.c_str())) {
621 LoggerW("Can't save exceptions.");
625 // set the setPositions
626 if ( !rrule->getSetPositions()->empty() )
628 LoggerD("Set the setPositions of length: "<<rrule->getSetPositions()->size());
630 std::string bysetpos = "";
631 for( unsigned int i=0; i<rrule->getSetPositions()->size(); i++ )
633 std::stringstream ss;
634 ss<<rrule->getSetPositions()->at(i);
635 bysetpos.append(ss.str());
636 if(i!=rrule->getSetPositions()->size()-1) {
637 bysetpos.append(",");
640 LoggerD("bysetpos: "<<bysetpos);
641 if (CALENDAR_ERROR_NONE!=calendar_record_set_str(m_platformEvent, _calendar_event.bysetpos, bysetpos.c_str())) {
642 LoggerW("Can't save setPositions.");
646 // set the recurrence interval
647 if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent,
648 _calendar_event.interval,
649 rrule->getInterval()))
651 LoggerW("Can't set interval.");
654 // set the recurrence end date. This is automatically calculated by platform if empty.
655 if (UNDEFINED_TIME!=rrule->getEndDate()) {
656 LoggerD("Setting the end date: "<<rrule->getEndDate());
658 if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent, _calendar_event.range_type, CALENDAR_RANGE_UNTIL)) {
659 LoggerW("Can't set rrule range type.");
663 calendar_time_s cal = {CALENDAR_TIME_UTIME, {0}};
664 cal.type = CALENDAR_TIME_UTIME;
665 cal.time.utime = m_abstractEvent->getRecurrenceRule()->getEndDate();
666 ret = calendar_record_set_caltime(m_platformEvent, _calendar_event.until_time, cal);
667 if (CALENDAR_ERROR_NONE != ret) {
668 LoggerW("Can't set rrule until time: "<<ret);
673 void EventWrapper::setAlarmsToPlatformEvent()
675 // Remove the preset child alarms before adding new ones.
677 unsigned int count = 0, i;
679 if(CalendarEvent::TASK_TYPE==getType()) {
680 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_todo.calendar_alarm, &count);
682 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_event.calendar_alarm, &count);
684 if (CALENDAR_ERROR_NONE != ret) {
685 LoggerW("Can't get alarms count: "<<ret);
689 LoggerD("No alarms to remove.");
691 LoggerD("Number of alarms to remove: "<<count);
694 calendar_record_h alarm = NULL;
695 for(i=0; i<count; i++) {
697 // Be careful about the index. We always insert 0 cause the child list is updated every time we remove one.
698 if(CalendarEvent::TASK_TYPE==getType()) {
699 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_alarm, 0, &alarm);
701 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_alarm, 0, &alarm);
703 if (CALENDAR_ERROR_NONE != ret) {
704 LoggerW("Can't get the alarm: "<<ret);
708 if(CalendarEvent::TASK_TYPE==getType()) {
709 ret = calendar_record_remove_child_record(m_platformEvent, _calendar_todo.calendar_alarm, alarm);
711 ret = calendar_record_remove_child_record(m_platformEvent, _calendar_event.calendar_alarm, alarm);
713 if (CALENDAR_ERROR_NONE != ret) {
714 LoggerW("Can't remove the alarm: "<<ret);
719 // Now add the new alarms.
720 if( 0 != m_abstractEvent->getAlarms()->size() ) {
721 for( i=0; i<m_abstractEvent->getAlarms()->size(); i++ )
723 LoggerD("Set the alarms #"<<i);
726 ret = calendar_record_create(_calendar_alarm._uri, &alarm);
727 if(CALENDAR_ERROR_NONE!=ret) {
728 LoggerW("Alarm creation failed: "<<ret);
732 EventAlarmPtr theAlarm = m_abstractEvent->getAlarms()->at(i);
734 calendar_alarm_time_unit_type_e tickUnit = CALENDAR_ALARM_NONE;
736 if( UNDEFINED_TIME!=theAlarm->getAbsoluteDate() ) {
737 tickUnit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
739 if( Time::MSECS_UNIT==theAlarm->getDuration().unit ) {
740 tickUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE; // minimum calendar time unit.
741 tick = theAlarm->getDuration().length / 60000;
742 } else if( Time::SECONDS_UNIT==theAlarm->getDuration().unit ) {
743 tickUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
744 tick = theAlarm->getDuration().length / 1000;
745 } else if( Time::MINUTES_UNIT==theAlarm->getDuration().unit ) {
746 tickUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
747 tick = theAlarm->getDuration().length;
748 } else if( Time::HOURS_UNIT==theAlarm->getDuration().unit ) {
749 tickUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
750 tick = theAlarm->getDuration().length;
751 } else if( Time::DAYS_UNIT==theAlarm->getDuration().unit ) {
752 tickUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
753 tick = theAlarm->getDuration().length;
755 LoggerW("Wrong alarm time unit: "<<theAlarm->getDuration().unit);
759 if( CALENDAR_ALARM_TIME_UNIT_SPECIFIC==tickUnit ) {
760 long long int time = theAlarm->getAbsoluteDate();
761 LoggerD("Save absolute date: "<<time);
762 ret = calendar_record_set_lli(alarm, _calendar_alarm.time, time);
763 if (CALENDAR_ERROR_NONE != ret) {
764 LoggerW("Can't set alarm time: "<<ret);
767 ret = calendar_record_set_int(alarm, _calendar_alarm.tick, tick);
768 if (CALENDAR_ERROR_NONE != ret) {
769 LoggerW("Can't set alarm tick: "<<ret);
773 ret = calendar_record_set_int(alarm, _calendar_alarm.tick_unit, tickUnit);
774 if (CALENDAR_ERROR_NONE != ret) {
775 LoggerW("Can't set alarm tick unit: "<<ret);
778 // Set the alarm type.
779 ret = calendar_record_set_int(alarm, _calendar_alarm.type, theAlarm->getMethod());
780 if (CALENDAR_ERROR_NONE != ret) {
781 LoggerW("Can't set alarm type: "<<ret);
784 // Set the display text
785 ret = calendar_record_set_str(alarm, _calendar_alarm.description, theAlarm->getDescription().c_str());
786 if (CALENDAR_ERROR_NONE != ret) {
787 LoggerW("Can't set alarm description: "<<ret);
790 if(CalendarEvent::TASK_TYPE==getType()) {
791 ret = calendar_record_add_child_record(m_platformEvent, _calendar_todo.calendar_alarm, alarm);
793 ret = calendar_record_add_child_record(m_platformEvent, _calendar_event.calendar_alarm, alarm);
795 if(CALENDAR_ERROR_NONE!=ret) {
796 LoggerW("Cannot add alarm child record: "<<ret);
798 calendar_record_destroy(alarm, true);
803 LoggerD("No alarms to save.");
807 void EventWrapper::setStatusToPlatformEvent()
810 if(CalendarEvent::TASK_TYPE==getType()) {
811 calendar_todo_status_e taskStatus = CALENDAR_TODO_STATUS_NONE;
813 switch (m_abstractEvent->getStatus()) {
814 case CalendarEvent::NEEDS_ACTION_STATUS:
815 taskStatus = CALENDAR_TODO_STATUS_NEEDS_ACTION;
817 case CalendarEvent::COMPLETED_STATUS:
818 taskStatus = CALENDAR_TODO_STATUS_COMPLETED;
820 case CalendarEvent::IN_PROCESS_STATUS:
821 taskStatus = CALENDAR_TODO_STATUS_IN_PROCESS;
823 case CalendarEvent::CANCELLED_STATUS:
824 taskStatus = CALENDAR_TODO_STATUS_CANCELED;
830 ret = calendar_record_set_int(m_platformEvent, _calendar_todo.todo_status, taskStatus);
832 calendar_event_status_e eventStatus = CALENDAR_EVENT_STATUS_NONE;
834 switch (m_abstractEvent->getStatus()) {
835 case CalendarEvent::TENTATIVE_STATUS:
836 eventStatus = CALENDAR_EVENT_STATUS_TENTATIVE;
838 case CalendarEvent::CONFIRMED_STATUS:
839 eventStatus = CALENDAR_EVENT_STATUS_CONFIRMED;
841 case CalendarEvent::CANCELLED_STATUS:
842 eventStatus = CALENDAR_EVENT_STATUS_CANCELLED;
848 ret = calendar_record_set_int(m_platformEvent, _calendar_event.event_status, eventStatus);
851 if (CALENDAR_ERROR_NONE != ret) {
852 LoggerW("Can't set item status.");
856 void EventWrapper::setCategoriesToPlatformEvent()
859 std::string categories = "";
861 // Need to concatenate all categories into one string separated by a comma.
862 for (size_t i = 0; i < m_abstractEvent->getCategories()->size(); ++i) {
864 categories.append(m_abstractEvent->getCategories()->at(i));
866 categories.append("," + m_abstractEvent->getCategories()->at(i));
870 LoggerD("Saving categories: "<<categories);
872 if(CalendarEvent::TASK_TYPE==getType()) {
873 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.categories, categories.c_str());
875 ret = calendar_record_set_str(m_platformEvent, _calendar_event.categories, categories.c_str());
877 if (CALENDAR_ERROR_NONE !=ret) {
878 LoggerW("Cannot save categories.");
882 void EventWrapper::setRecurrenceIdToPlatformEvent()
885 if (CalendarEvent::TASK_TYPE==getType()) {
886 LoggerD("No need to set recurrence id for a task.");
890 if(UNDEFINED_TIME!=m_abstractEvent->getRecurrenceId()) {
891 std::stringstream ss;
892 ss<<m_abstractEvent->getRecurrenceId();
893 ret = calendar_record_set_str(m_platformEvent, _calendar_event.recurrence_id, ss.str().c_str());
894 if (CALENDAR_ERROR_NONE != ret) {
895 LoggerW("Can't set recurrence id.");
897 LoggerD("Set the recurrence id: "<<ss.str());
900 LoggerD("Recurrence id not defined.");
904 void EventWrapper::setParentIdToPlatformEvent()
907 if (CalendarEvent::TASK_TYPE==getType()) {
908 LoggerD("No need to set parent id for a task.");
912 if(UNDEFINED_ITEM_ID!=m_abstractEvent->getParentId()) {
913 ret = calendar_record_set_int(m_platformEvent, _calendar_event.original_event_id, m_abstractEvent->getParentId());
914 if (CALENDAR_ERROR_NONE != ret) {
915 LoggerW("Can't set parent Id.");
917 LoggerD("Set the parent id: "<<m_abstractEvent->getParentId());
920 LoggerD("Parent id not defined.");
924 void EventWrapper::setIsAllDayToPlatformEvent()
926 LoggerD("All day flag is set in the start time struct: "<<m_abstractEvent->getIsAllDay());
929 void EventWrapper::setOrganizerToPlatformEvent()
932 if(CalendarEvent::TASK_TYPE==getType()) {
933 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.organizer_name, m_abstractEvent->getOrganizer().c_str());
935 ret = calendar_record_set_str(m_platformEvent, _calendar_event.organizer_name, m_abstractEvent->getOrganizer().c_str());
937 if (CALENDAR_ERROR_NONE != ret) {
938 LoggerW("Can't set item organizer.");
942 void EventWrapper::setVisibilityToPlatformEvent()
945 calendar_sensitivity_e visibility = CALENDAR_SENSITIVITY_PUBLIC;
947 switch (m_abstractEvent->getVisibility()) {
948 case CalendarEvent::PUBLIC_VISIBILITY:
949 visibility = CALENDAR_SENSITIVITY_PUBLIC;
951 case CalendarEvent::PRIVATE_VISIBILITY:
952 visibility = CALENDAR_SENSITIVITY_PRIVATE;
954 case CalendarEvent::CONFIDENTIAL_VISIBILITY:
955 visibility = CALENDAR_SENSITIVITY_CONFIDENTIAL;
958 LoggerD("Use the default visibility");
962 if(CalendarEvent::TASK_TYPE==getType()) {
963 ret = calendar_record_set_int(m_platformEvent, _calendar_todo.sensitivity, visibility);
965 ret = calendar_record_set_int(m_platformEvent, _calendar_event.sensitivity, visibility);
967 if (CALENDAR_ERROR_NONE != ret) {
968 LoggerW("Can't set visibility.");
972 void EventWrapper::setAvailabilityToPlatformEvent()
974 if(CalendarEvent::TASK_TYPE==getType()) {
975 LoggerD("No need to set availability for a task.");
979 calendar_event_busy_status_e availability = CALENDAR_EVENT_BUSY_STATUS_FREE;
980 switch (m_abstractEvent->getAvailability()) {
981 case CalendarEvent::BUSY_FB:
982 availability = CALENDAR_EVENT_BUSY_STATUS_BUSY;
984 case CalendarEvent::BUSY_UNAVAILABLE_FB:
985 availability = CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE;
987 case CalendarEvent::FREE_FB:
988 availability = CALENDAR_EVENT_BUSY_STATUS_FREE;
990 case CalendarEvent::BUSY_TENTATIVE_FB:
991 availability = CALENDAR_EVENT_BUSY_STATUS_TENTATIVE;
994 LoggerD("Use the default availability");
998 int ret = calendar_record_set_int(m_platformEvent, _calendar_event.busy_status, availability);
999 if (CALENDAR_ERROR_NONE != ret) {
1000 LoggerW("Can't set availability.");
1004 void EventWrapper::setUIdToPlatformEvent()
1007 if(CalendarEvent::TASK_TYPE==getType()) {
1008 ret = calendar_record_set_str(m_platformEvent, _calendar_todo.uid, m_abstractEvent->getUId().c_str());
1010 ret = calendar_record_set_str(m_platformEvent, _calendar_event.uid, m_abstractEvent->getUId().c_str());
1012 if (CALENDAR_ERROR_NONE != ret) {
1013 LoggerW("Can't set item uid.");
1017 void EventWrapper::setAttendeesToPlatformEvent()
1019 // Remove the preset child attendees before adding new ones.
1021 unsigned int count = 0, i;
1023 if(CalendarEvent::TASK_TYPE==getType()) {
1024 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_todo.calendar_attendee, &count);
1026 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_event.calendar_attendee, &count);
1028 if (CALENDAR_ERROR_NONE != ret) {
1029 LoggerW("Can't get attendees count: "<<ret);
1033 LoggerD("No attendees to remove.");
1035 LoggerD("Number of attendees to remove: "<<count);
1038 calendar_record_h attendee = NULL;
1039 for(i=0; i<count; i++) {
1041 // Be careful about the index. We always insert 0 cause the child list is updated every time we remove one.
1042 if(CalendarEvent::TASK_TYPE==getType()) {
1043 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_attendee, 0, &attendee);
1045 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_attendee, 0, &attendee);
1047 if (CALENDAR_ERROR_NONE != ret) {
1048 LoggerW("Can't get the attendee: "<<ret);
1052 if(CalendarEvent::TASK_TYPE==getType()) {
1053 ret = calendar_record_remove_child_record(m_platformEvent, _calendar_todo.calendar_attendee, attendee);
1055 ret = calendar_record_remove_child_record(m_platformEvent, _calendar_event.calendar_attendee, attendee);
1057 if (CALENDAR_ERROR_NONE != ret) {
1058 LoggerW("Can't remove the attendee: "<<ret);
1063 // Now add the new attendees.
1064 EventAttendeeListPtr attendeeList = m_abstractEvent->getAttendees();
1066 if( 0!=attendeeList->size() ) {
1067 for (i = 0; i < attendeeList->size(); ++i) {
1068 LoggerD("Adding attendee "<<i+1<<" over "<<attendeeList->size());
1071 ret = calendar_record_create(_calendar_attendee._uri, &attendee);
1072 if(CALENDAR_ERROR_NONE!=ret) {
1073 LoggerW("Attendee creation failed: "<<ret);
1077 EventAttendeePtr theAttendee = attendeeList->at(i);
1080 ret = calendar_record_set_str(attendee, _calendar_attendee.name, theAttendee->getName().c_str());
1081 if (CALENDAR_ERROR_NONE!=ret) {
1082 LoggerW("Cannot set attendee name: "<<ret);
1086 ret = calendar_record_set_str(attendee, _calendar_attendee.email, theAttendee->getURI().c_str());
1087 if (CALENDAR_ERROR_NONE!=ret) {
1088 LoggerW("Cannot set attendee URI: "<<ret);
1092 calendar_attendee_role_e role = CALENDAR_ATTENDEE_ROLE_CHAIR;
1093 switch (theAttendee->getRole()) {
1094 case EventAttendee::REQ_PARTICIPANT_ROLE:
1095 role = CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT;
1097 case EventAttendee::OPT_PARTICIPANT_ROLE:
1098 role = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
1100 case EventAttendee::NON_PARTICIPANT_ROLE:
1101 role = CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT;
1103 case EventAttendee::CHAIR_ROLE:
1104 role = CALENDAR_ATTENDEE_ROLE_CHAIR;
1107 LoggerD("Use the default role");
1110 ret = calendar_record_set_int(attendee, _calendar_attendee.role, role);
1111 if (CALENDAR_ERROR_NONE != ret) {
1112 LoggerW("Cannot set attendee role: "<<ret);
1116 calendar_attendee_status_e status = CALENDAR_ATTENDEE_STATUS_PENDING;
1117 switch (theAttendee->getStatus()) {
1118 case EventAttendee::PENDING_AT_STATUS:
1119 status = CALENDAR_ATTENDEE_STATUS_PENDING;
1121 case EventAttendee::ACCEPTED_AT_STATUS:
1122 status = CALENDAR_ATTENDEE_STATUS_ACCEPTED;
1124 case EventAttendee::DECLINED_AT_STATUS:
1125 status = CALENDAR_ATTENDEE_STATUS_DECLINED;
1127 case EventAttendee::TENTATIVE_AT_STATUS:
1128 status = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
1130 case EventAttendee::DELEGATED_AT_STATUS:
1131 status = CALENDAR_ATTENDEE_STATUS_DELEGATED;
1133 case EventAttendee::COMPLETED_AT_STATUS:
1134 status = CALENDAR_ATTENDEE_STATUS_COMPLETED;
1136 case EventAttendee::IN_PROCESS_AT_STATUS:
1137 status = CALENDAR_ATTENDEE_STATUS_IN_PROCESS;
1140 LoggerD("Use the default status");
1143 ret = calendar_record_set_int(attendee, _calendar_attendee.status, status);
1144 if (CALENDAR_ERROR_NONE != ret) {
1145 LoggerW("Cannot set attendee status: "<<ret);
1149 ret = calendar_record_set_int(attendee, _calendar_attendee.rsvp, theAttendee->getRSVP());
1150 if (CALENDAR_ERROR_NONE != ret) {
1151 LoggerW("Cannot set attendee RSVP: "<<ret);
1155 ret = calendar_record_set_int(attendee, _calendar_attendee.type, theAttendee->getType());
1156 if (CALENDAR_ERROR_NONE != ret) {
1157 LoggerW("Cannot set attendee type: "<<ret);
1161 ret = calendar_record_set_str(attendee, _calendar_attendee.group, theAttendee->getGroup().c_str());
1162 if (CALENDAR_ERROR_NONE != ret) {
1163 LoggerW("Cannot set attendee group: "<<ret);
1166 // save delegatorURI
1167 ret = calendar_record_set_str(attendee, _calendar_attendee.delegator_uri, theAttendee->getDelegatorURI().c_str());
1168 if (CALENDAR_ERROR_NONE != ret ) {
1169 LoggerW("Cannot set attendee delegator uri "<<ret);
1173 ret = calendar_record_set_str(attendee, _calendar_attendee.delegate_uri, theAttendee->getDelegateURI().c_str());
1174 if (CALENDAR_ERROR_NONE != ret) {
1175 LoggerW("Cannot set attendee delegate uri: "<<ret);
1179 ret = calendar_record_set_str(attendee, _calendar_attendee.uid, theAttendee->getContactId().c_str());
1180 if (CALENDAR_ERROR_NONE != ret) {
1181 LoggerW("Cannot set attendee uid: "<<ret);
1184 // save addressBookId
1185 std::stringstream ss(attendeeList->at(i)->getAddressBookId());
1188 LoggerD("addressBookId: "<<addressBookId);
1189 ret = calendar_record_set_int(attendee, _calendar_attendee.person_id, addressBookId);
1190 if (CALENDAR_ERROR_NONE != ret) {
1191 LoggerW("Cannot set attendee address book id "<<ret);
1194 if(CalendarEvent::TASK_TYPE==getType()) {
1195 ret = calendar_record_add_child_record(m_platformEvent, _calendar_todo.calendar_attendee, attendee);
1198 ret = calendar_record_add_child_record(m_platformEvent, _calendar_event.calendar_attendee, attendee);
1200 if(CALENDAR_ERROR_NONE!=ret) {
1201 LoggerW("Cannot add attendee child record: "<<ret);
1203 calendar_record_destroy(attendee, true);
1208 LoggerD("No attendee to save.");
1212 void EventWrapper::setPositionToPlatformEvent()
1215 if(CalendarEvent::TASK_TYPE==getType()) {
1216 ret = calendar_record_set_double(m_platformEvent, _calendar_todo.latitude, m_abstractEvent->getGeolocation()->getLatitude());
1218 ret = calendar_record_set_double(m_platformEvent, _calendar_event.latitude, m_abstractEvent->getGeolocation()->getLatitude());
1220 if (CALENDAR_ERROR_NONE != ret) {
1221 LoggerW("Can't set latitude: "<<ret);
1224 if(CalendarEvent::TASK_TYPE==getType()) {
1225 ret = calendar_record_set_double(m_platformEvent, _calendar_todo.longitude, m_abstractEvent->getGeolocation()->getLongitude());
1227 ret = calendar_record_set_double(m_platformEvent, _calendar_event.longitude, m_abstractEvent->getGeolocation()->getLongitude());
1230 if (CALENDAR_ERROR_NONE != ret) {
1231 LoggerW("Can't set longitude: "<<ret);
1235 void EventWrapper::setPriorityToPlatformEvent()
1238 if(CalendarEvent::TASK_TYPE==getType()) {
1239 calendar_todo_priority_e todoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
1241 switch (m_abstractEvent->getPriority()) {
1242 case CalendarEvent::HIGH_PRIORITY:
1243 todoPriority = CALENDAR_TODO_PRIORITY_HIGH;
1245 case CalendarEvent::MEDIUM_PRIORITY:
1246 todoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
1248 case CalendarEvent::LOW_PRIORITY:
1249 todoPriority = CALENDAR_TODO_PRIORITY_LOW;
1255 ret = calendar_record_set_int(m_platformEvent, _calendar_todo.priority, todoPriority);
1256 if (CALENDAR_ERROR_NONE != ret) {
1257 LoggerW("Can't set task priority: "<<ret);
1260 calendar_event_priority_e eventPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
1262 switch (m_abstractEvent->getPriority()) {
1263 case CalendarEvent::HIGH_PRIORITY:
1264 eventPriority = CALENDAR_EVENT_PRIORITY_HIGH;
1266 case CalendarEvent::MEDIUM_PRIORITY:
1267 eventPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
1269 case CalendarEvent::LOW_PRIORITY:
1270 eventPriority = CALENDAR_EVENT_PRIORITY_LOW;
1276 ret = calendar_record_set_int(m_platformEvent, _calendar_event.priority, eventPriority);
1277 if (CALENDAR_ERROR_NONE != ret) {
1278 LoggerW("Can't set event priority: "<<ret);
1283 void EventWrapper::setCreatedDateToPlatformEvent()
1287 if(CalendarEvent::TASK_TYPE==getType()) {
1288 ret = calendar_record_set_lli(m_platformEvent, _calendar_todo.created_time, m_abstractEvent->getCreatedDate());
1290 ret = calendar_record_set_lli(m_platformEvent, _calendar_event.created_time, m_abstractEvent->getCreatedDate());
1292 if (CALENDAR_ERROR_NONE != ret) {
1293 LoggerW("Can't set createde time: "<<ret);
1297 void EventWrapper::setCompletedDateToPlatformEvent()
1299 if(CalendarEvent::EVENT_TYPE==getType()) {
1300 LoggerD("No need to set the completed date for an event.");
1304 int ret = calendar_record_set_lli(m_platformEvent, _calendar_todo.completed_time, m_abstractEvent->getCompletedDate());
1305 if (CALENDAR_ERROR_NONE != ret) {
1306 LoggerW( "Can't set createde time: "<<ret);
1310 void EventWrapper::setProgressToPlatformEvent()
1312 if(CalendarEvent::EVENT_TYPE==getType()) {
1313 LoggerD("No need to set the progress for an event.");
1317 int ret = calendar_record_set_int(m_platformEvent, _calendar_todo.progress, m_abstractEvent->getProgress());
1318 if (CALENDAR_ERROR_NONE != ret) {
1319 LoggerW("Can't set progress: "<<ret);
1323 CalendarEventPtr EventWrapper::convertPlatformEventToAbstractEvent()
1325 LoggerD("Convert to abstract item.");
1327 setCalendarIdFromPlatformEvent();
1328 setDescriptionFromPlatformEvent();
1329 setSummaryFromPlatformEvent();
1330 setStartTimeFromPlatformEvent();
1331 setEndTimeFromPlatformEvent(); // replace for duration
1332 setLocationFromPlatformEvent();
1333 setCategoriesFromPlatformEvent();
1334 setStatusFromPlatformEvent();
1335 setAlarmsFromPlatformEvent();
1336 setIsAllDayFromPlatformEvent();
1337 setOrganizerFromPlatformEvent();
1338 setAttendeesFromPlatformEvent();
1339 setPositionFromPlatformEvent();
1340 setVisibilityFromPlatformEvent();
1341 setLastModifiedDateFromPlatformEvent();
1342 setAvailabilityFromPlatformEvent();
1343 setRecurrenceRuleFromPlatformEvent();
1344 setIdFromPlatformEvent();
1345 setRecurrenceIdFromPlatformEvent();
1346 setParentIdFromPlatformEvent();
1347 //setUIdFromPlatformEvent(); // We set the uid value as the same with id.
1348 setPriorityFromPlatformEvent();
1349 setCreatedDateFromPlatformEvent();
1350 setCompletedDateFromPlatformEvent();
1351 setProgressFromPlatformEvent();
1352 setIsDetachedFromPlatformEvent();
1354 return getAbstractEvent();
1357 void EventWrapper::setCalendarIdFromPlatformEvent()
1359 int ret, calendarId;
1361 if(CalendarEvent::TASK_TYPE==getType()) {
1362 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.calendar_book_id, &calendarId);
1364 ret = calendar_record_get_int(m_platformEvent, _calendar_event.calendar_book_id, &calendarId);
1366 if (CALENDAR_ERROR_NONE != ret) {
1367 LoggerW("Can't get calenadrId: "<<ret);
1370 m_abstractEvent->setCalendarId(calendarId);
1373 void EventWrapper::setDescriptionFromPlatformEvent()
1376 char *description = NULL;
1377 if(CalendarEvent::TASK_TYPE==getType()) {
1378 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.description, &description);
1380 ret = calendar_record_get_str(m_platformEvent, _calendar_event.description, &description);
1382 if (CALENDAR_ERROR_NONE != ret) {
1383 LoggerW("Can't get description: "<<ret);
1387 m_abstractEvent->setDescription(description);
1392 void EventWrapper::setSummaryFromPlatformEvent()
1395 char *summary = NULL;
1396 if(CalendarEvent::TASK_TYPE==getType()) {
1397 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.summary, &summary);
1399 ret = calendar_record_get_str(m_platformEvent, _calendar_event.summary, &summary);
1401 if (CALENDAR_ERROR_NONE != ret) {
1402 LoggerW("Can't get summary: "<<ret);
1406 m_abstractEvent->setSubject(summary);
1411 void EventWrapper::setStartTimeFromPlatformEvent()
1414 calendar_time_s cal;
1416 // Retrive the time zone info only when the start time is loaded.
1417 char *timeZone = NULL;
1418 if(CalendarEvent::TASK_TYPE==getType()) {
1419 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.start_tzid, &timeZone);
1421 ret = calendar_record_get_str(m_platformEvent, _calendar_event.start_tzid, &timeZone);
1423 if (CALENDAR_ERROR_NONE != ret) {
1424 LoggerW("Can't get time zone: "<<ret);
1428 LoggerD("timeZone: "<<timeZone);
1429 m_abstractEvent->setTimeZone(std::string(timeZone));
1432 if(CalendarEvent::TASK_TYPE==getType()) {
1433 ret = calendar_record_get_caltime(m_platformEvent, _calendar_todo.start_time, &cal);
1435 ret = calendar_record_get_caltime(m_platformEvent, _calendar_event.start_time, &cal);
1437 if (CALENDAR_ERROR_NONE != ret) {
1438 LoggerW("Can't get start time: "<<ret);
1441 // Set the isAllDay flag also.
1442 if(CALENDAR_TIME_LOCALTIME==cal.type) {
1443 m_abstractEvent->setStartTime(CalendarUtility::calTimeToLLI(timeZone, cal));
1444 m_abstractEvent->setIsAllDay(true);
1446 m_abstractEvent->setStartTime(cal.time.utime);
1447 m_abstractEvent->setIsAllDay(false);
1455 void EventWrapper::setEndTimeFromPlatformEvent()
1458 calendar_time_s cal;
1460 if(CalendarEvent::TASK_TYPE==getType()) {
1461 ret = calendar_record_get_caltime(m_platformEvent, _calendar_todo.due_time, &cal);
1463 ret = calendar_record_get_caltime(m_platformEvent, _calendar_event.end_time, &cal);
1465 if (CALENDAR_ERROR_NONE != ret) {
1466 LoggerW("Can't get due/end time: "<<ret);
1470 // Set the isAllDay flag also.
1471 if(CALENDAR_TIME_LOCALTIME==cal.type) {
1472 m_abstractEvent->setEndTime(CalendarUtility::calTimeToLLI(m_abstractEvent->getTimeZone().c_str(), cal));
1474 m_abstractEvent->setEndTime(cal.time.utime);
1478 void EventWrapper::setLocationFromPlatformEvent()
1481 char *location = NULL;
1482 if(CalendarEvent::TASK_TYPE==getType()) {
1483 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.location, &location);
1485 ret = calendar_record_get_str(m_platformEvent, _calendar_event.location, &location);
1487 if (CALENDAR_ERROR_NONE != ret) {
1488 LoggerW("Can't get location: "<<ret);
1492 m_abstractEvent->setLocation(location);
1497 void EventWrapper::setRecurrenceRuleFromPlatformEvent()
1499 if (CalendarEvent::TASK_TYPE==getType()) {
1500 LoggerD("No need to set rrule for a task.");
1505 EventRecurrenceRulePtr rrule(new EventRecurrenceRule());
1507 // load the recurrence frequency
1509 ret = calendar_record_get_int(m_platformEvent, _calendar_event.freq, &frequency);
1510 if (CALENDAR_ERROR_NONE != ret) {
1511 LoggerW("Can't get frequency: "<<ret);
1514 LoggerD("frequency "<<frequency);
1515 switch (frequency) {
1516 case CALENDAR_RECURRENCE_NONE:
1517 rrule->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
1520 case CALENDAR_RECURRENCE_DAILY:
1521 rrule->setFrequency(EventRecurrenceRule::DAILY_RECURRENCE);
1523 case CALENDAR_RECURRENCE_WEEKLY:
1524 rrule->setFrequency(EventRecurrenceRule::WEEKLY_RECURRENCE);
1526 case CALENDAR_RECURRENCE_MONTHLY:
1527 rrule->setFrequency(EventRecurrenceRule::MONTHLY_RECURRENCE);
1529 case CALENDAR_RECURRENCE_YEARLY:
1530 rrule->setFrequency(EventRecurrenceRule::YEARLY_RECURRENCE);
1533 LoggerW("Unknown recurrence frequency.");
1534 rrule->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
1540 StringArrayPtr daysOfTheWeek(new StringArray());
1542 ret = calendar_record_get_str(m_platformEvent, _calendar_event.byday, &byday);
1543 if (CALENDAR_ERROR_NONE != ret) {
1544 LoggerW("Can't get byday: "<<ret);
1547 LoggerD("Loaded byday: "<<byday);
1548 char *saveptr = NULL;
1549 char* pch = strtok_r(byday, ",", &saveptr);
1550 while (NULL != pch) {
1551 (*daysOfTheWeek).push_back(pch);
1552 pch = strtok_r(NULL, ",", &saveptr);
1556 rrule->setDaysOfTheWeek(daysOfTheWeek);
1557 LoggerD("Number of daysOfTheWeek: "<<rrule->getDaysOfTheWeek()->size());
1559 // load the recurrence interval
1561 ret = calendar_record_get_int(m_platformEvent, _calendar_event.interval, &interval);
1562 if (CALENDAR_ERROR_NONE != ret) {
1563 LoggerW("Can't get interval: "<<ret);
1565 rrule->setInterval(interval);
1567 // load the ocurrence count
1568 int occurrrenceCount;
1569 ret = calendar_record_get_int(m_platformEvent, _calendar_event.count, &occurrrenceCount);
1570 if (CALENDAR_ERROR_NONE != ret) {
1571 LoggerW("Can't get occurrrence count: "<<ret);
1573 rrule->setOccurrenceCount(occurrrenceCount);
1575 // load the recurrence end date
1576 calendar_time_s cal = {CALENDAR_TIME_UTIME, {0}};
1577 ret = calendar_record_get_caltime(m_platformEvent, _calendar_event.until_time, &cal);
1578 if (CALENDAR_ERROR_NONE != ret) {
1579 LoggerW("Can't get recurrence end date: "<<ret);
1581 if(cal.time.utime>0) {
1582 if(CALENDAR_RECORD_NO_UNTIL==cal.time.utime) {
1583 rrule->setEndDate(UNDEFINED_TIME);
1585 rrule->setEndDate(cal.time.utime);
1588 rrule->setEndDate(UNDEFINED_TIME);
1590 LoggerD("endDate from platform = "<<rrule->getEndDate());
1592 // load the exceptions
1593 NumberArrayPtr exceptions(new NumberArray());
1594 char* exdate = NULL;
1595 ret = calendar_record_get_str(m_platformEvent, _calendar_event.exdate, &exdate);
1596 if (CALENDAR_ERROR_NONE != ret) {
1597 LoggerW("Can't get exdate: "<<ret);
1600 LoggerD("Loaded exdate: "<<exdate);
1601 char *saveptr = NULL;
1602 char *pch = strtok_r(exdate, ",", &saveptr);
1603 while (NULL != pch) {
1604 std::stringstream ss(pch);
1605 long long int oneException;
1607 (*exceptions).push_back(oneException);
1608 pch = strtok_r(NULL, ",", &saveptr);
1612 rrule->setExceptions(exceptions);
1613 LoggerD("Number of exceptions: "<<rrule->getExceptions()->size());
1615 // load the setPositions
1616 NumberArrayPtr setPositions(new NumberArray());
1617 char* bysetpos = NULL;
1618 ret = calendar_record_get_str(m_platformEvent, _calendar_event.bysetpos, &bysetpos);
1619 if (CALENDAR_ERROR_NONE != ret) {
1620 LoggerW("Can't get bysetpos: "<<ret);
1623 LoggerD("Loaded bysetpos: "<<bysetpos);
1624 char *saveptr = NULL;
1625 char *pch = strtok_r(bysetpos, ",", &saveptr);
1626 while (NULL != pch) {
1627 std::stringstream ss(pch);
1630 (*setPositions).push_back(setPos);
1631 pch = strtok_r(NULL, ",", &saveptr);
1635 rrule->setSetPositions(setPositions);
1636 LoggerD("Number of setPositions: "<<rrule->getSetPositions()->size());
1638 // set the loaded recurrence rule
1639 m_abstractEvent->setRecurrenceRule(rrule);
1642 void EventWrapper::setAlarmsFromPlatformEvent()
1645 unsigned int count = 0, i;
1646 calendar_list_h list = NULL;
1648 if(CalendarEvent::TASK_TYPE==getType()) {
1649 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_todo.calendar_alarm, &count);
1651 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_event.calendar_alarm, &count);
1653 if (CALENDAR_ERROR_NONE != ret) {
1654 LoggerW("Can't get alarms count: "<<ret);
1658 LoggerD("No alarms to set.");
1661 LoggerD("Number of alarms: "<<count);
1664 if(CalendarEvent::TASK_TYPE==getType()) {
1665 ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_todo.calendar_alarm, &list);
1667 ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_event.calendar_alarm, &list);
1669 if (CALENDAR_ERROR_NONE != ret) {
1670 LoggerW("Can't get alarms list: "<<ret);
1675 calendar_record_h alarm = NULL;
1676 for(i=0; i<count; i++)
1678 LoggerD("Processing the alarm #"<<i);
1680 if(CalendarEvent::TASK_TYPE==getType()) {
1681 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_alarm, i, &alarm);
1683 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_alarm, i, &alarm);
1685 if (CALENDAR_ERROR_NONE != ret) {
1686 LoggerW("Can't get the alarm: "<<ret);
1690 EventAlarmPtr theAlarm( new EventAlarm() );
1692 ret = calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &tickUnit);
1693 if (CALENDAR_ERROR_NONE != ret) {
1694 LoggerW("Cannot read alarm tick unit: "<<ret);
1698 if( CALENDAR_ALARM_TIME_UNIT_SPECIFIC==tickUnit ) {
1700 ret = calendar_record_get_lli(alarm, _calendar_alarm.time, &time);
1701 if (CALENDAR_ERROR_NONE != ret) {
1702 LoggerW("Can't get alarm tick: "<<ret);
1705 theAlarm->setAbsoluteDate(time);
1706 LoggerD("Loaded absolute date: "<<theAlarm->getAbsoluteDate());
1708 ret = calendar_record_get_int(alarm, _calendar_alarm.tick, &tick);
1709 if (CALENDAR_ERROR_NONE != ret) {
1710 LoggerW("Cannot read alarm tick. Stop processing alarms.");
1714 Time::DurationProperties duration;
1715 if( CALENDAR_ALARM_TIME_UNIT_MINUTE==tickUnit ) {
1716 duration.unit = Time::MINUTES_UNIT;
1717 duration.length = tick;
1718 } else if( CALENDAR_ALARM_TIME_UNIT_HOUR==tickUnit ) {
1719 duration.unit = Time::HOURS_UNIT;
1720 duration.length = tick;
1721 } else if( CALENDAR_ALARM_TIME_UNIT_DAY==tickUnit ) {
1722 duration.unit = Time::DAYS_UNIT;
1723 duration.length = tick;
1724 } else if( CALENDAR_ALARM_TIME_UNIT_WEEK==tickUnit) {
1725 duration.unit = Time::DAYS_UNIT;
1726 duration.length = tick*7;
1727 } else if( CALENDAR_ALARM_TIME_UNIT_MONTH==tickUnit) {
1728 // Not supportd correctly.
1729 duration.unit = Time::DAYS_UNIT;
1730 duration.length = tick*30;
1732 LoggerW("Wrong tick unit: "<<tickUnit);
1735 theAlarm->setDuration(duration);
1739 ret = calendar_record_get_int(alarm, _calendar_alarm.type, &type);
1740 if (CALENDAR_ERROR_NONE != ret) {
1741 LoggerW("Cannot read alarm type: "<<ret);
1744 theAlarm->setMethod((EventAlarm::EventAlarmType)type);
1746 char* description = NULL;
1747 ret = calendar_record_get_str(alarm, _calendar_alarm.description, &description);
1748 if (CALENDAR_ERROR_NONE != ret) {
1749 LoggerW("Cannot read alarm description: "<<ret);
1750 theAlarm->setDescription("");
1754 LoggerD("Alarm description: "<<description);
1755 theAlarm->setDescription(description);
1760 m_abstractEvent->getAlarms()->push_back(theAlarm);
1764 calendar_list_destroy(list, true);
1766 LoggerD("Number of alarms: "<<m_abstractEvent->getAlarms()->size());
1769 void EventWrapper::setStatusFromPlatformEvent()
1773 if(CalendarEvent::TASK_TYPE==getType()) {
1774 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.todo_status, &status);
1776 ret = calendar_record_get_int(m_platformEvent, _calendar_event.event_status, &status);
1778 if (CALENDAR_ERROR_NONE != ret) {
1779 LoggerW("Can't get status: "<<ret);
1784 case CALENDAR_EVENT_STATUS_TENTATIVE:
1785 m_abstractEvent->setStatus(CalendarEvent::TENTATIVE_STATUS);
1787 case CALENDAR_EVENT_STATUS_CONFIRMED:
1788 m_abstractEvent->setStatus(CalendarEvent::CONFIRMED_STATUS);
1790 case CALENDAR_EVENT_STATUS_CANCELLED:
1791 case CALENDAR_TODO_STATUS_CANCELED:
1792 m_abstractEvent->setStatus(CalendarEvent::CANCELLED_STATUS);
1794 case CALENDAR_TODO_STATUS_NEEDS_ACTION:
1795 m_abstractEvent->setStatus(CalendarEvent::NEEDS_ACTION_STATUS);
1797 case CALENDAR_TODO_STATUS_COMPLETED:
1798 m_abstractEvent->setStatus(CalendarEvent::COMPLETED_STATUS);
1800 case CALENDAR_TODO_STATUS_IN_PROCESS:
1801 m_abstractEvent->setStatus(CalendarEvent::IN_PROCESS_STATUS);
1804 m_abstractEvent->setStatus(CalendarEvent::UNDEFINED_STATUS);
1809 void EventWrapper::setCategoriesFromPlatformEvent()
1811 m_abstractEvent->getCategories()->clear();
1814 char *categories = NULL;
1815 if(CalendarEvent::TASK_TYPE==getType()) {
1816 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.categories, &categories);
1818 ret = calendar_record_get_str(m_platformEvent, _calendar_event.categories, &categories);
1820 if (CALENDAR_ERROR_NONE != ret) {
1821 LoggerW("Can't get categories: "<<ret);
1825 LoggerD("Loaded categories: "<<categories);
1827 char *saveptr = NULL;
1828 char* pch = strtok_r(categories, ",", &saveptr);
1829 while (NULL != pch) {
1830 m_abstractEvent->getCategories()->push_back(pch);
1831 pch = strtok_r(NULL, ",", &saveptr);
1836 LoggerD("Number of categories: "<<m_abstractEvent->getCategories()->size());
1839 void EventWrapper::setIdFromPlatformEvent()
1841 if (m_platformEvent == NULL) {
1842 ThrowMsg(NullPointerException, "m_platformEvent is not set");
1846 if(CalendarEvent::TASK_TYPE==getType()) {
1847 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.id, &id);
1849 ret = calendar_record_get_int(m_platformEvent, _calendar_event.id, &id);
1851 if (CALENDAR_ERROR_NONE!=ret) {
1852 ThrowMsg(PlatformException, "Can't get id: "<<ret);
1855 m_abstractEvent->setId(id);
1857 // Set the uid also.
1858 std::stringstream ss;
1860 m_abstractEvent->setUId(ss.str());
1863 void EventWrapper::setRecurrenceIdFromPlatformEvent()
1865 if(CalendarEvent::TASK_TYPE==getType()) {
1866 LoggerD("No need to set the recurrence id for a task.");
1871 char* recurrenceId = NULL;
1872 ret = calendar_record_get_str(m_platformEvent, _calendar_event.recurrence_id, &recurrenceId);
1873 if (CALENDAR_ERROR_NONE != ret) {
1874 LoggerW("Can't get recurrence id: "<<ret);
1878 if( recurrenceId ) {
1880 std::stringstream ss(recurrenceId);
1882 m_abstractEvent->setRecurrenceId(rid);
1883 LoggerD("Set the recurrence id: "<<rid);
1885 m_abstractEvent->setRecurrenceId(UNDEFINED_TIME);
1889 void EventWrapper::setParentIdFromPlatformEvent()
1891 if(CalendarEvent::TASK_TYPE==getType()) {
1892 LoggerD("No need to set the parent id for a task.");
1897 ret = calendar_record_get_int(m_platformEvent, _calendar_event.original_event_id, &parentId);
1898 if (CALENDAR_ERROR_NONE != ret) {
1899 LoggerW("Can't get parent id: "<<ret);
1904 m_abstractEvent->setParentId(parentId);
1906 m_abstractEvent->setParentId(UNDEFINED_ITEM_ID);
1910 void EventWrapper::setIsAllDayFromPlatformEvent()
1912 LoggerD("All day flag is set when getting the start time: "<<m_abstractEvent->getIsAllDay());
1915 void EventWrapper::setOrganizerFromPlatformEvent()
1918 char* organizer = NULL;
1919 if(CalendarEvent::TASK_TYPE==getType()) {
1920 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.organizer_name, &organizer);
1922 ret = calendar_record_get_str(m_platformEvent, _calendar_event.organizer_name, &organizer);
1924 if (CALENDAR_ERROR_NONE != ret) {
1925 LoggerW("Can't get organizer: "<<ret);
1929 m_abstractEvent->setOrganizer(organizer);
1934 void EventWrapper::setLastModifiedDateFromPlatformEvent()
1937 long long int lastModifiedDate;
1939 if(CalendarEvent::TASK_TYPE==getType()) {
1940 ret = calendar_record_get_lli(m_platformEvent, _calendar_todo.last_modified_time, &lastModifiedDate);
1942 ret = calendar_record_get_lli(m_platformEvent, _calendar_event.last_modified_time, &lastModifiedDate);
1944 if (CALENDAR_ERROR_NONE != ret) {
1945 LoggerW("Can't get last modification time: "<<ret);
1949 m_abstractEvent->setLastModifiedDate(lastModifiedDate);
1952 void EventWrapper::setVisibilityFromPlatformEvent()
1954 int ret, visibility;
1956 if(CalendarEvent::TASK_TYPE==getType()) {
1957 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.sensitivity, &visibility);
1959 ret = calendar_record_get_int(m_platformEvent, _calendar_event.sensitivity, &visibility);
1961 if (CALENDAR_ERROR_NONE != ret) {
1962 LoggerW("Can't get visibility: "<<ret);
1966 switch (visibility) {
1967 case CALENDAR_SENSITIVITY_PUBLIC:
1968 m_abstractEvent->setVisibility(CalendarEvent::PUBLIC_VISIBILITY);
1970 case CALENDAR_SENSITIVITY_PRIVATE:
1971 m_abstractEvent->setVisibility(CalendarEvent::PRIVATE_VISIBILITY);
1973 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
1974 m_abstractEvent->setVisibility(CalendarEvent::CONFIDENTIAL_VISIBILITY);
1977 m_abstractEvent->setVisibility(CalendarEvent::PUBLIC_VISIBILITY);
1982 void EventWrapper::setAvailabilityFromPlatformEvent()
1984 if(CalendarEvent::TASK_TYPE==getType()) {
1985 LoggerD("No need to set availability for a task.");
1989 int ret, availability;
1990 ret = calendar_record_get_int(m_platformEvent, _calendar_event.busy_status, &availability);
1991 if (CALENDAR_ERROR_NONE != ret) {
1992 LoggerW("Can't get visibility: "<<ret);
1996 switch (availability) {
1997 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
1998 m_abstractEvent->setAvailability(CalendarEvent::BUSY_FB);
2000 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2001 m_abstractEvent->setAvailability(CalendarEvent::BUSY_UNAVAILABLE_FB);
2003 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2004 m_abstractEvent->setAvailability(CalendarEvent::FREE_FB);
2006 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2007 m_abstractEvent->setAvailability(CalendarEvent::BUSY_TENTATIVE_FB);
2010 m_abstractEvent->setAvailability(CalendarEvent::FREE_FB);
2015 void EventWrapper::setUIdFromPlatformEvent()
2020 if(CalendarEvent::TASK_TYPE==getType()) {
2021 ret = calendar_record_get_str(m_platformEvent, _calendar_todo.uid, &uid);
2023 ret = calendar_record_get_str(m_platformEvent, _calendar_event.uid, &uid);
2025 if (CALENDAR_ERROR_NONE != ret) {
2026 LoggerW("Can't get uid: "<<ret);
2030 m_abstractEvent->setUId(uid);
2035 void EventWrapper::setAttendeesFromPlatformEvent()
2037 if ( NULL != m_abstractEvent->getAttendees() ) {
2038 m_abstractEvent->getAttendees()->clear();
2042 unsigned int count = 0, i;
2043 calendar_record_h attendee = NULL;
2044 calendar_list_h list = NULL;
2046 if(CalendarEvent::TASK_TYPE==getType()) {
2047 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_todo.calendar_attendee, &count);
2049 ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_event.calendar_attendee, &count);
2051 if (CALENDAR_ERROR_NONE != ret) {
2052 LoggerW("Can't get attendee count: "<<ret);
2057 LoggerD("No attendees to set.");
2061 if(CalendarEvent::TASK_TYPE==getType()) {
2062 ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_todo.calendar_attendee, &list);
2064 ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_event.calendar_attendee, &list);
2066 if (CALENDAR_ERROR_NONE != ret) {
2067 LoggerW("Can't get attendee list: "<<ret);
2071 for (i=0; i<count; i++)
2073 LoggerD("Processing the attendee #"<<i);
2075 if(CalendarEvent::TASK_TYPE==getType()) {
2076 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_attendee, i, &attendee);
2078 ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_attendee, i, &attendee);
2080 if (CALENDAR_ERROR_NONE != ret) {
2081 LoggerW("Can't get attendee record: "<<ret);
2085 EventAttendeePtr attendeePtr(new EventAttendee());
2088 char* attendeeName = NULL;
2089 ret = calendar_record_get_str(attendee, _calendar_attendee.name, &attendeeName);
2090 if (CALENDAR_ERROR_NONE != ret) {
2091 LoggerW("Cannot read attendee name. Setting an empty string.");
2092 attendeePtr->setName("");
2095 attendeePtr->setName(attendeeName);
2101 char* attendeeURI = NULL;
2102 ret = calendar_record_get_str(attendee, _calendar_attendee.email, &attendeeURI);
2103 if (CALENDAR_ERROR_NONE != ret) {
2104 LoggerW("Cannot read attendee URI. Setting an empty string.");
2105 attendeePtr->setURI("");
2108 attendeePtr->setURI(attendeeURI);
2115 ret = calendar_record_get_int(attendee, _calendar_attendee.role, &attendeeRole);
2116 if (CALENDAR_ERROR_NONE != ret) {
2117 LoggerW("Cannot read attendee role. Setting the default value.");
2119 switch (attendeeRole) {
2120 case CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT:
2121 attendeePtr->setRole(EventAttendee::REQ_PARTICIPANT_ROLE);
2123 case CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT:
2124 attendeePtr->setRole(EventAttendee::OPT_PARTICIPANT_ROLE);
2126 case CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT:
2127 attendeePtr->setRole(EventAttendee::NON_PARTICIPANT_ROLE);
2129 case CALENDAR_ATTENDEE_ROLE_CHAIR:
2130 attendeePtr->setRole(EventAttendee::CHAIR_ROLE);
2133 attendeePtr->setRole(EventAttendee::REQ_PARTICIPANT_ROLE);
2139 ret = calendar_record_get_int(attendee, _calendar_attendee.status, &attendeeStatus);
2140 if (CALENDAR_ERROR_NONE != ret) {
2141 LoggerW("Cannot read attendee status. Setting the default value.");
2143 switch (attendeeStatus) {
2144 case CALENDAR_ATTENDEE_STATUS_PENDING:
2145 attendeePtr->setStatus(EventAttendee::PENDING_AT_STATUS);
2147 case CALENDAR_ATTENDEE_STATUS_ACCEPTED:
2148 attendeePtr->setStatus(EventAttendee::ACCEPTED_AT_STATUS);
2150 case CALENDAR_ATTENDEE_STATUS_DECLINED:
2151 attendeePtr->setStatus(EventAttendee::DECLINED_AT_STATUS);
2153 case CALENDAR_ATTENDEE_STATUS_TENTATIVE:
2154 attendeePtr->setStatus(EventAttendee::TENTATIVE_AT_STATUS);
2156 case CALENDAR_ATTENDEE_STATUS_DELEGATED:
2157 attendeePtr->setStatus(EventAttendee::DELEGATED_AT_STATUS);
2159 case CALENDAR_ATTENDEE_STATUS_COMPLETED:
2160 attendeePtr->setStatus(EventAttendee::COMPLETED_AT_STATUS);
2162 case CALENDAR_ATTENDEE_STATUS_IN_PROCESS:
2163 attendeePtr->setStatus(EventAttendee::IN_PROCESS_AT_STATUS);
2166 attendeePtr->setStatus(EventAttendee::PENDING_AT_STATUS);
2172 ret = calendar_record_get_int(attendee, _calendar_attendee.rsvp, &attendeeRSVP);
2173 if (CALENDAR_ERROR_NONE != ret) {
2174 LoggerW("Cannot read attendee RSVP. Setting the default value.");
2176 attendeePtr->setRSVP(attendeeRSVP>0 ? true : false);
2180 ret = calendar_record_get_int(attendee, _calendar_attendee.type, &attendeeType);
2181 if (CALENDAR_ERROR_NONE != ret) {
2182 LoggerW("Cannot read attendee type. Setting the default value.");
2184 attendeePtr->setType((EventAttendee::EventAttendeeType)attendeeType);
2187 char* attendeeGroup = NULL;
2188 ret = calendar_record_get_str(attendee, _calendar_attendee.group, &attendeeGroup);
2189 if (CALENDAR_ERROR_NONE != ret) {
2190 LoggerW("Cannot read attendee group. Setting an empty string.");
2191 attendeePtr->setGroup("");
2194 attendeePtr->setGroup(attendeeGroup);
2195 free(attendeeGroup);
2199 // load delegatorURI
2200 char* attendeeDelegatorURI = NULL;
2201 ret = calendar_record_get_str(attendee, _calendar_attendee.delegator_uri, &attendeeDelegatorURI);
2202 if (CALENDAR_ERROR_NONE != ret) {
2203 LoggerW("Cannot read attendee delegatorURI. Setting an empty string.");
2204 attendeePtr->setDelegatorURI("");
2206 if(attendeeDelegatorURI) {
2207 attendeePtr->setDelegatorURI(attendeeDelegatorURI);
2208 free(attendeeDelegatorURI);
2213 char* attendeeDelegateURI = NULL;
2214 ret = calendar_record_get_str(attendee, _calendar_attendee.delegate_uri, &attendeeDelegateURI);
2215 if (CALENDAR_ERROR_NONE != ret) {
2216 LoggerW("Cannot read attendee delegateURI. Setting an empty string.");
2217 attendeePtr->setDelegateURI("");
2219 if(attendeeDelegateURI) {
2220 attendeePtr->setDelegateURI(attendeeDelegateURI);
2221 free(attendeeDelegateURI);
2226 char* attendeeContactId = NULL;
2227 ret = calendar_record_get_str(attendee, _calendar_attendee.uid, &attendeeContactId);
2228 if (CALENDAR_ERROR_NONE != ret) {
2229 LoggerW("Cannot read attendee UId. Setting an empty string.");
2230 attendeePtr->setContactId("");
2232 if(attendeeContactId) {
2233 attendeePtr->setContactId(attendeeContactId);
2234 free(attendeeContactId);
2238 // load addressBookId
2239 int attendeeAddressBookId;
2240 ret = calendar_record_get_int(attendee, _calendar_attendee.person_id, &attendeeAddressBookId);
2241 LoggerD("attendeeAddressBookId: "<<attendeeAddressBookId);
2242 if (CALENDAR_ERROR_NONE != ret) {
2243 LoggerW("Cannot read attendee address book id. Setting an empty string.");
2244 attendeeAddressBookId = -1;
2246 std::stringstream ss;
2247 if (attendeeAddressBookId>=0) {
2248 ss<<attendeeAddressBookId;
2252 attendeePtr->setAddressBookId(ss.str());
2254 m_abstractEvent->getAttendees()->push_back(attendeePtr);
2258 calendar_list_destroy(list, true);
2262 void EventWrapper::setPositionFromPlatformEvent()
2267 if(CalendarEvent::TASK_TYPE==getType()) {
2268 ret = calendar_record_get_double(m_platformEvent, _calendar_todo.latitude, &value);
2270 ret = calendar_record_get_double(m_platformEvent, _calendar_event.latitude, &value);
2272 if (CALENDAR_ERROR_NONE != ret) {
2273 LoggerW("Can't get item latitude.");
2276 m_abstractEvent->getGeolocation()->setLatitude(value);
2278 if(CalendarEvent::TASK_TYPE==getType()) {
2279 ret = calendar_record_get_double(m_platformEvent, _calendar_todo.longitude, &value);
2281 ret = calendar_record_get_double(m_platformEvent, _calendar_event.longitude, &value);
2283 if (CALENDAR_ERROR_NONE != ret) {
2284 LoggerW("Can't get item longitude.");
2287 m_abstractEvent->getGeolocation()->setLongitude(value);
2290 void EventWrapper::setPriorityFromPlatformEvent()
2295 if(CalendarEvent::TASK_TYPE==getType()) {
2296 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.priority, &priority);
2297 if (CALENDAR_ERROR_NONE != ret) {
2298 LoggerW("Can't get task priority: "<<ret);
2303 case CALENDAR_TODO_PRIORITY_LOW:
2304 m_abstractEvent->setPriority(CalendarEvent::LOW_PRIORITY);
2306 case CALENDAR_TODO_PRIORITY_NORMAL:
2307 m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
2309 case CALENDAR_TODO_PRIORITY_HIGH:
2310 m_abstractEvent->setPriority(CalendarEvent::HIGH_PRIORITY);
2313 m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
2317 ret = calendar_record_get_int(m_platformEvent, _calendar_event.priority, &priority);
2318 if (CALENDAR_ERROR_NONE != ret) {
2319 LoggerW("Can't get event priority: "<<ret);
2324 case CALENDAR_EVENT_PRIORITY_LOW:
2325 m_abstractEvent->setPriority(CalendarEvent::LOW_PRIORITY);
2327 case CALENDAR_EVENT_PRIORITY_NORMAL:
2328 m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
2330 case CALENDAR_EVENT_PRIORITY_HIGH:
2331 m_abstractEvent->setPriority(CalendarEvent::HIGH_PRIORITY);
2334 m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
2340 void EventWrapper::setCreatedDateFromPlatformEvent()
2343 long long int createdDate;
2345 if(CalendarEvent::TASK_TYPE==getType()) {
2346 ret = calendar_record_get_lli(m_platformEvent, _calendar_todo.created_time, &createdDate);
2348 ret = calendar_record_get_lli(m_platformEvent, _calendar_event.created_time, &createdDate);
2350 if (CALENDAR_ERROR_NONE != ret) {
2351 LoggerW("Can't get created date: "<<ret);
2355 m_abstractEvent->setCreatedDate(createdDate);
2358 void EventWrapper::setCompletedDateFromPlatformEvent()
2360 if(CalendarEvent::EVENT_TYPE==getType()) {
2361 LoggerD("No need to set completedDate for an event.");
2366 long long int completedDate;
2368 ret = calendar_record_get_lli(m_platformEvent, _calendar_todo.completed_time, &completedDate);
2369 if (CALENDAR_ERROR_NONE != ret) {
2370 LoggerW("Can't get completed date: "<<ret);
2374 m_abstractEvent->setCompletedDate(completedDate);
2377 void EventWrapper::setProgressFromPlatformEvent()
2379 if(CalendarEvent::EVENT_TYPE==getType()) {
2380 LoggerD("No need to set progress for an event.");
2386 ret = calendar_record_get_int(m_platformEvent, _calendar_todo.progress, &progress);
2387 if (CALENDAR_ERROR_NONE != ret) {
2388 LoggerW("Can't get progress: "<<ret);
2392 m_abstractEvent->setProgress(progress);
2395 void EventWrapper::setIsDetachedFromPlatformEvent()
2397 if(CalendarEvent::TASK_TYPE==getType()) {
2398 LoggerD("No need to set isDetached flag for a task.");
2404 ret = calendar_record_get_int(m_platformEvent, _calendar_event.original_event_id, &isDetached);
2405 if (CALENDAR_ERROR_NONE != ret) {
2406 LoggerW("Can't get isDetached: "<<ret);
2411 m_abstractEvent->setIsDetached(true);
2412 LoggerD("This is a detached event.");
2414 m_abstractEvent->setIsDetached(false);
2418 void EventWrapper::displayAbstractEvent()
2420 m_abstractEvent->display();
2423 void EventWrapper::displayPlatformEvent()
2425 LoggerD("Displaying platform itemt disabled.");
2428 CalendarEvent::CalendarType EventWrapper::getType()
2430 return m_calendarType;