2 // Open Service Platform
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.
18 * @file FScl_CalEventImpl.cpp
19 * @brief This is the implementation for _CalEventImpl class.
21 * This file contains definitions of @e _CalEventImpl class.
26 #include <FBaseColArrayList.h>
27 #include <FSysSystemTime.h>
28 #include <FLclTimeZone.h>
29 #include <FLclGregorianCalendar.h>
30 #include <FLclCalendar.h>
31 #include <FSclAttendee.h>
32 #include <FSclRecord.h>
33 #include <FSclCalEvent.h>
34 #include <FBaseSysLog.h>
35 #include <FApp_AppInfo.h>
36 #include <FBase_StringConverter.h>
37 #include "FScl_RecordImpl.h"
38 #include "FScl_CalEventImpl.h"
39 #include "FScl_RecurrenceImpl.h"
40 #include "FScl_CalendarbookImpl.h"
41 #include "FScl_CalendarbookDbConnector.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Base::Utility;
46 using namespace Tizen::App;
47 using namespace Tizen::System;
48 using namespace Tizen::Locales;
50 namespace Tizen { namespace Social
53 static const int _DEFAULT_ADDED_HOUR = 1;
54 static const int _INVALID_ATTENDEE_INDEX = -1;
56 static const int _TERM_LIMIT_DAILY = 1;
57 static const int _TERM_LIMIT_WEEKLY = 7;
58 static const int _TERM_LIMIT_MONTHLY = 31;
59 static const int _TERM_LIMIT_YEARLY = 366;
60 static const int _CALENDARBOOK_NUMBER_OF_DAYS_OF_WEEK = 7;
62 static const wchar_t* _EVENT_CATEGORY_APPOINTMENT_STRING = L"Appointment";
63 static const wchar_t* _EVENT_CATEGORY_ANNIVERSARY_STRING = L"Anniversary";
65 static const wchar_t* _RECURRENCE_KEYWORD_SUNDAY = L"SU";
66 static const wchar_t* _RECURRENCE_KEYWORD_MONDAY = L"MO";
67 static const wchar_t* _RECURRENCE_KEYWORD_TUESDAY = L"TU";
68 static const wchar_t* _RECURRENCE_KEYWORD_WEDNESDAY = L"WE";
69 static const wchar_t* _RECURRENCE_KEYWORD_THURSDAY = L"TH";
70 static const wchar_t* _RECURRENCE_KEYWORD_FRIDAY = L"FR";
71 static const wchar_t* _RECURRENCE_KEYWORD_SATURDAY = L"SA";
73 static const wchar_t* _RECURRENCE_DELIMITER = L",";
74 static const int _RECURRENCE_DELIMITER_LENGTH = 1;
75 static const wchar_t _RECURRENCE_BY_DAY_CHAR_PLUS = L'+';
76 static const wchar_t _RECURRENCE_BY_DAY_CHAR_MINUS = L'-';
77 static const wchar_t _RECURRENCE_BY_DAY_CHAR_ONE = L'1';
78 static const int _RECURRENCE_BY_DAY_FIRST_INDEX = 0;
79 static const int _RECURRENCE_BY_DAY_SECOND_INDEX = 1;
80 static const int _MAX_WEEK_OF_RECURRENCE_BY_DAY = 5;
81 static const int _RECURRENCE_NUMBER_OF_WEEK_DAY = 7;
83 static const double _MIN_LATITUDE = -90.0;
84 static const double _MAX_LATITUDE = 90.0;
85 static const double _MIN_LONGITUDE = -180.0;
86 static const double _MAX_LONGITUDE = 180.0;
88 _CalEventImpl::_CalEventImpl(void)
89 : __originalEventId(INVALID_RECORD_ID)
91 , __reminderListUpdated(false)
93 // Set default start and end time
96 SystemTime::GetCurrentTime(startTime);
97 if (IsFailed(GetLastResult()))
99 startTime = _CalendarbookImpl::GetMinDateTime();
103 DateTime endTime(startTime);
104 r = endTime.AddHours(_DEFAULT_ADDED_HOUR);
105 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
107 calendar_time_s startCalendarTime;
108 calendar_time_s endCalendarTime;
109 startCalendarTime.type = CALENDAR_TIME_UTIME;
110 endCalendarTime.type = CALENDAR_TIME_UTIME;
111 startCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(startTime);
112 endCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(endTime);
114 int errorCode = CALENDAR_ERROR_NONE;
115 calendar_record_h eventHandle = null;
117 r = _CalendarbookDbConnector::Connect();
118 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
120 errorCode = calendar_record_create(_calendar_event._uri, &eventHandle);
121 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
123 __eventRecord.ResetHandle(eventHandle);
125 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
126 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
129 errorCode = calendar_record_set_int(eventHandle, _calendar_event.event_status, CALENDAR_EVENT_STATUS_NONE);
130 errorCode = calendar_record_set_int(eventHandle, _calendar_event.busy_status, CALENDAR_EVENT_BUSY_STATUS_FREE);
131 errorCode = calendar_record_set_int(eventHandle, _calendar_event.priority, CALENDAR_EVENT_PRIORITY_NORMAL);
132 errorCode = calendar_record_set_int(eventHandle, _calendar_event.sensitivity, CALENDAR_SENSITIVITY_PUBLIC);
134 r = __reminderList.Construct();
135 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138 _CalEventImpl::_CalEventImpl(const _CalEventImpl& rhs)
139 : __originalEventId(rhs.__originalEventId)
140 , __isInstance(rhs.__isInstance)
141 , __reminderListUpdated(false)
143 int errorCode = CALENDAR_ERROR_NONE;
144 calendar_record_h eventHandle = null;
146 result r = _CalendarbookDbConnector::Connect();
147 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
149 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
150 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
152 __eventRecord.ResetHandle(eventHandle);
154 r = __reminderList.Construct();
155 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
158 _CalEventImpl::~_CalEventImpl(void)
160 int errorCode = CALENDAR_ERROR_NONE;
161 errorCode = calendar_record_destroy(__eventRecord.ReleaseHandle(), true);
163 __reminderList.RemoveAll(true);
165 result r = _CalendarbookDbConnector::Disconnect();
166 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
170 _CalEventImpl::operator =(const _CalEventImpl& rhs)
177 __originalEventId = rhs.__originalEventId;
178 __isInstance = rhs.__isInstance;
179 __reminderList.RemoveAll(true);
180 __reminderListUpdated = false;
182 int errorCode = CALENDAR_ERROR_NONE;
183 calendar_record_h eventHandle = null;
185 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
186 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
188 __eventRecord.ResetHandle(eventHandle);
194 _CalEventImpl::IsInstance(void) const
200 _CalEventImpl::IsRecurring(void) const
202 int errorCode = CALENDAR_ERROR_NONE;
203 int recurrenceFreq = CALENDAR_RECURRENCE_NONE;
205 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFreq);
207 if (recurrenceFreq == CALENDAR_RECURRENCE_NONE)
216 _CalEventImpl::GetOriginalCalEventId(void) const
218 return __originalEventId;
222 _CalEventImpl::IsAllDayEvent(void) const
224 int errorCode = CALENDAR_ERROR_NONE;
225 calendar_time_s startCalendarTime;
227 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
228 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
237 _CalEventImpl::SetAllDayEvent(bool isAllDayEvent)
239 if (GetCategory() == EVENT_CATEGORY_ANNIVERSARY)
244 int errorCode = CALENDAR_ERROR_NONE;
245 calendar_time_s startCalendarTime;
246 calendar_time_s tmpStartCalendarTime;
247 calendar_time_s endCalendarTime;
248 calendar_time_s tmpEndCalendarTime;
250 bool isChanged = false;
252 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
253 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
255 if (isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_UTIME)
257 tmpStartCalendarTime.type = CALENDAR_TIME_LOCALTIME;
258 DateTime tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
259 tmpStartCalendarTime.time.date.year = tmpStartTime.GetYear();
260 tmpStartCalendarTime.time.date.month = tmpStartTime.GetMonth();
261 tmpStartCalendarTime.time.date.mday = tmpStartTime.GetDay();
263 tmpEndCalendarTime.type = CALENDAR_TIME_LOCALTIME;
264 DateTime tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
265 tmpEndCalendarTime.time.date.year = tmpEndTime.GetYear();
266 tmpEndCalendarTime.time.date.month = tmpEndTime.GetMonth();
267 tmpEndCalendarTime.time.date.mday = tmpEndTime.GetDay();
269 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
270 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
274 else if (!isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
276 tmpStartCalendarTime.type = CALENDAR_TIME_UTIME;
277 DateTime tmpStartTime;
278 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
279 tmpStartCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpStartTime);
281 tmpEndCalendarTime.type = CALENDAR_TIME_UTIME;
283 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
284 tmpEndCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpEndTime);
286 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
287 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
294 int rangeType = CALENDAR_RANGE_NONE;
295 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.range_type, &rangeType);
297 if (rangeType == CALENDAR_RANGE_UNTIL)
299 calendar_time_s untilCalendarTime;
300 calendar_time_s tmpUntilCalendarTime;
302 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, &untilCalendarTime);
303 if (isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_UTIME)
305 tmpUntilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
306 DateTime tmpUntilTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
307 tmpUntilCalendarTime.time.date.year = tmpUntilTime.GetYear();
308 tmpUntilCalendarTime.time.date.month = tmpUntilTime.GetMonth();
309 tmpUntilCalendarTime.time.date.mday = tmpUntilTime.GetDay();
311 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
313 else if (!isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
315 tmpUntilCalendarTime.type = CALENDAR_TIME_UTIME;
316 DateTime tmpUntilTime;
317 tmpUntilTime.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
318 tmpUntilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpUntilTime);
320 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
326 if (__pRecurrence == null)
328 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
331 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*__pRecurrence.get(), isAllDayEvent)));
332 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
338 _CalEventImpl::GetUIDN(void) const
342 int errorCode = CALENDAR_ERROR_NONE;
343 char* pStrUid = null;
344 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
346 if (pStrUid == null || strlen(pStrUid) == 0)
351 ByteBuffer* pConvertedUidBuffer = _CalendarbookUtil::ConvertCharArrayToByteBufferN(pStrUid);
352 SysTryReturn(NID_SCL, pConvertedUidBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
354 return pConvertedUidBuffer;
358 _CalEventImpl::SetUID(const ByteBuffer* pUid)
360 int errorCode = CALENDAR_ERROR_NONE;
364 std::unique_ptr<char[]> pConvertedUidArray(_CalendarbookUtil::ConvertByteBufferToCharArrayN(*pUid));
365 SysTryReturn(NID_SCL, pConvertedUidArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
367 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pConvertedUidArray.get());
371 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, null);
378 _CalEventImpl::GetUid(void) const
380 int errorCode = CALENDAR_ERROR_NONE;
381 char* pStrUid = null;
382 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
384 return String(pStrUid);
388 _CalEventImpl::SetUid(const Tizen::Base::String& uid)
390 int errorCode = CALENDAR_ERROR_NONE;
392 std::unique_ptr<char[]> pStrUid(_StringConverter::CopyToCharArrayN(uid));
393 SysTryReturnVoidResult(NID_SCL, pStrUid != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
395 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pStrUid.get());
399 _CalEventImpl::GetStatus(void) const
401 int errorCode = CALENDAR_ERROR_NONE;
402 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
404 EventStatus eventStatus = EVENT_STATUS_NONE;
406 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.event_status, &srcEventStatus);
408 switch (srcEventStatus)
410 case CALENDAR_EVENT_STATUS_NONE:
411 eventStatus = EVENT_STATUS_NONE;
413 case CALENDAR_EVENT_STATUS_TENTATIVE:
414 eventStatus = EVENT_STATUS_TENTATIVE;
416 case CALENDAR_EVENT_STATUS_CONFIRMED:
417 eventStatus = EVENT_STATUS_CONFIRMED;
419 case CALENDAR_EVENT_STATUS_CANCELLED:
420 eventStatus = EVENT_STATUS_CANCELLED;
423 SysLog(NID_SCL, "The status value is invalid.");
424 return EVENT_STATUS_NONE;
431 _CalEventImpl::SetStatus(EventStatus status)
433 int errorCode = CALENDAR_ERROR_NONE;
434 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.event_status, _CalendarbookUtil::ConvertEventStatusToCSEventStatus(status));
438 _CalEventImpl::GetBusyStatus(void) const
440 int errorCode = CALENDAR_ERROR_NONE;
441 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
443 BusyStatus busyStatus = BUSY_STATUS_FREE;
445 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.busy_status, &srcEventBusyStatus);
447 switch (srcEventBusyStatus)
449 case CALENDAR_EVENT_BUSY_STATUS_FREE:
450 busyStatus = BUSY_STATUS_FREE;
452 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
453 busyStatus = BUSY_STATUS_BUSY;
455 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
456 busyStatus = BUSY_STATUS_UNAVAILABLE;
458 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
459 busyStatus = BUSY_STATUS_TENTATIVE;
462 SysLog(NID_SCL, "The busy status value is invalid.");
463 busyStatus = BUSY_STATUS_FREE;
471 _CalEventImpl::SetBusyStatus(BusyStatus busyStatus)
473 int errorCode = CALENDAR_ERROR_NONE;
474 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.busy_status, _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(busyStatus));
478 _CalEventImpl::GetPriority(void) const
480 int errorCode = CALENDAR_ERROR_NONE;
481 int srcPriority = CALENDAR_EVENT_PRIORITY_LOW;
483 EventPriority priority = EVENT_PRIORITY_NORMAL;
485 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.priority, &srcPriority);
489 case CALENDAR_EVENT_PRIORITY_LOW:
490 priority = EVENT_PRIORITY_LOW;
492 case CALENDAR_EVENT_PRIORITY_NORMAL:
493 priority = EVENT_PRIORITY_NORMAL;
495 case CALENDAR_EVENT_PRIORITY_HIGH:
496 priority = EVENT_PRIORITY_HIGH;
499 SysLog(NID_SCL, "The priority value is invalid.");
500 priority = EVENT_PRIORITY_NORMAL;
507 _CalEventImpl::SetPriority(EventPriority priority)
509 int errorCode = CALENDAR_ERROR_NONE;
510 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.priority, _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(priority));
514 _CalEventImpl::AddAttendee(const Attendee& attendee)
516 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0)
518 SysTryReturnResult(NID_SCL, !attendee.GetEmail().IsEmpty(), E_OBJ_ALREADY_EXIST
519 , "The attendee's email string is empty.");
523 SysTryReturnResult(NID_SCL, !attendee.GetEmail().IsEmpty(), E_INVALID_ARG
524 , "The attendee's email string is empty.");
527 std::unique_ptr<char[]> pConvertedEmail(_StringConverter::CopyToCharArrayN(attendee.GetEmail()));
528 SysTryReturnResult(NID_SCL, pConvertedEmail != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
530 SysTryReturnResult(NID_SCL, GetAttendeeIndex(pConvertedEmail.get()) == _INVALID_ATTENDEE_INDEX, E_OBJ_ALREADY_EXIST
531 , "The specified attendee already exists as this email is already registered.");
533 int errorCode = CALENDAR_ERROR_NONE;
535 std::unique_ptr<char[]> pConvertedName(_StringConverter::CopyToCharArrayN(attendee.GetName()));
536 SysTryReturnResult(NID_SCL, pConvertedName != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
538 std::unique_ptr<char[]> pConvertedPhoneNumber(_StringConverter::CopyToCharArrayN(attendee.GetPhoneNumber()));
539 SysTryReturnResult(NID_SCL, pConvertedPhoneNumber != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
541 calendar_attendee_status_e convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
542 switch (attendee.GetStatus())
544 case ATTENDEE_STATUS_NONE:
545 convertedStatus = CALENDAR_ATTENDEE_STATUS_COMPLETED;
547 case ATTENDEE_STATUS_NOT_RESPONDED:
548 convertedStatus = CALENDAR_ATTENDEE_STATUS_PENDING;
550 case ATTENDEE_STATUS_ACCEPTED:
551 convertedStatus = CALENDAR_ATTENDEE_STATUS_ACCEPTED;
553 case ATTENDEE_STATUS_DECLINED:
554 convertedStatus = CALENDAR_ATTENDEE_STATUS_DECLINED;
556 case ATTENDEE_STATUS_TENTATIVE:
557 convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
560 SysLog(NID_SCL, "The attendee status value is invalid. attendee status = %d", attendee.GetStatus());
561 convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
565 calendar_attendee_role_e convertedRole = CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT;
566 switch (attendee.GetRole())
568 case ATTENDEE_ROLE_ATTENDEE:
569 convertedRole = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
571 case ATTENDEE_ROLE_REQUIRED_ATTENDEE:
572 convertedRole = CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT;
574 case ATTENDEE_ROLE_ORGANIZER:
575 convertedRole = CALENDAR_ATTENDEE_ROLE_CHAIR;
578 SysLog(NID_SCL, "The attendee role value is invalid. attendee role = %d", attendee.GetRole());
579 convertedRole = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
583 calendar_record_h attendeeHandle = null;
584 errorCode = calendar_record_create(_calendar_attendee._uri, &attendeeHandle);
585 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
587 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.name, pConvertedName.get());
588 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.email, pConvertedEmail.get());
589 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.number, pConvertedPhoneNumber.get());
590 errorCode = calendar_record_set_int(attendeeHandle, _calendar_attendee.status, convertedStatus);
591 errorCode = calendar_record_set_int(attendeeHandle, _calendar_attendee.role, convertedRole);
592 errorCode = calendar_record_set_int(attendeeHandle, _calendar_attendee.person_id, attendee.GetPersonId());
594 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, attendeeHandle);
600 _CalEventImpl::RemoveAttendee(const Attendee& attendee)
602 int errorCode = CALENDAR_ERROR_NONE;
603 int index = _INVALID_ATTENDEE_INDEX;
605 std::unique_ptr<char[]> pConvertedEmail(_StringConverter::CopyToCharArrayN(attendee.GetEmail()));
606 SysTryReturnResult(NID_SCL, pConvertedEmail != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
608 index = GetAttendeeIndex(pConvertedEmail.get());
609 SysTryReturnResult(NID_SCL, index != _INVALID_ATTENDEE_INDEX, E_OBJ_NOT_FOUND, "The specified attendee does not exist.")
611 calendar_record_h tmpAttendeeHandle = null;
612 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, index, &tmpAttendeeHandle);
613 errorCode = calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, tmpAttendeeHandle);
619 _CalEventImpl::GetAllAttendeesN(void) const
623 int errorCode = CALENDAR_ERROR_NONE;
625 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
626 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
627 result r = pList->Construct();
628 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
630 unsigned int attendeeCount = 0;
631 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
633 for (int i = 0; i < attendeeCount; i++)
635 calendar_record_h tmpAttendeeHandle = null;
636 char* pTmpEmail = null;
637 char* pTmpName = null;
638 char* pTmpPhoneNumber = null;
641 int tmpPersonId = -1;
642 AttendeeStatus attendeeStatus = ATTENDEE_STATUS_NONE;
643 AttendeeRole attendeeRole = ATTENDEE_ROLE_ATTENDEE;
645 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
646 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpEmail);
647 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.name, &pTmpName);
648 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.number, &pTmpPhoneNumber);
649 errorCode = calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.status, &tmpStatus);
650 errorCode = calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.role, &tmpRole);
651 errorCode = calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.person_id, &tmpPersonId);
655 case CALENDAR_ATTENDEE_STATUS_PENDING:
656 attendeeStatus = ATTENDEE_STATUS_NOT_RESPONDED;
658 case CALENDAR_ATTENDEE_STATUS_ACCEPTED:
659 attendeeStatus = ATTENDEE_STATUS_ACCEPTED;
661 case CALENDAR_ATTENDEE_STATUS_DECLINED:
662 attendeeStatus = ATTENDEE_STATUS_DECLINED;
664 case CALENDAR_ATTENDEE_STATUS_TENTATIVE:
665 attendeeStatus = ATTENDEE_STATUS_TENTATIVE;
667 case CALENDAR_ATTENDEE_STATUS_DELEGATED:
668 attendeeStatus = ATTENDEE_STATUS_NONE;
670 case CALENDAR_ATTENDEE_STATUS_COMPLETED:
671 attendeeStatus = ATTENDEE_STATUS_NONE;
673 case CALENDAR_ATTENDEE_STATUS_IN_PROCESS:
674 attendeeStatus = ATTENDEE_STATUS_NOT_RESPONDED;
677 SysLog(NID_SCL, "The attendee status value is invalid. attendee status = %d", tmpStatus);
678 attendeeStatus = ATTENDEE_STATUS_NONE;
684 case CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT:
685 attendeeRole = ATTENDEE_ROLE_REQUIRED_ATTENDEE;
687 case CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT:
688 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
690 case CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT:
691 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
693 case CALENDAR_ATTENDEE_ROLE_CHAIR:
694 attendeeRole = ATTENDEE_ROLE_ORGANIZER;
697 SysLog(NID_SCL, "The attendee role value is invalid. attendee role = %d", tmpRole);
698 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
702 Attendee* pTmpAttendee = new (std::nothrow) Attendee(pTmpEmail);
703 SysTryReturn(NID_SCL, pTmpAttendee != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
705 if (pTmpName != null && strlen(pTmpName) > 0)
707 pTmpAttendee->SetName(pTmpName);
710 if (pTmpPhoneNumber != null && strlen(pTmpPhoneNumber) > 0)
712 pTmpAttendee->SetPhoneNumber(pTmpPhoneNumber);
715 pTmpAttendee->SetStatus(attendeeStatus);
716 pTmpAttendee->SetRole(attendeeRole);
717 pTmpAttendee->SetPersonId(tmpPersonId);
719 pList->Add(*pTmpAttendee);
722 return pList.release();
725 Tizen::Locales::TimeZone
726 _CalEventImpl::GetTimeZone(void) const
728 int errorCode = CALENDAR_ERROR_NONE;
729 char* pTimeZoneId = null;
732 result r = E_SUCCESS;
733 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.start_tzid, &pTimeZoneId);
734 if (pTimeZoneId != null && strlen(pTimeZoneId) > 0)
736 r = TimeZone::GetTimeZone(pTimeZoneId, timeZone);
743 _CalEventImpl::SetTimeZone(const Tizen::Locales::TimeZone& timeZone)
745 int errorCode = CALENDAR_ERROR_NONE;
747 std::unique_ptr<char[]> pConvertedTimeZoneId(_StringConverter::CopyToCharArrayN(timeZone.GetId()));
748 SysTryReturnResult(NID_SCL, pConvertedTimeZoneId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
750 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.start_tzid, pConvertedTimeZoneId.get());
751 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.end_tzid, pConvertedTimeZoneId.get());
757 _CalEventImpl::GetRecurrenceId(void) const
760 SysTryReturn(NID_SCL, __isInstance, DateTime(), E_INVALID_STATE,
761 "[E_INVALID_STATE] The instance does not have a recurrence or is not a CalEvent instance which doesn't have a RecurrenceId.");
763 return GetStartTime();
767 _CalEventImpl::GetSubject(void) const
769 int errorCode = CALENDAR_ERROR_NONE;
770 char* pSubject = null;
772 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.summary, &pSubject);
774 return String(pSubject);
778 _CalEventImpl::GetDescription(void) const
780 int errorCode = CALENDAR_ERROR_NONE;
781 char* pDescription = null;
783 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.description, &pDescription);
785 return String(pDescription);
788 _CalEventImpl::GetStartTime(void) const
790 int errorCode = CALENDAR_ERROR_NONE;
791 calendar_time_s startCalendarTime;
792 DateTime tmpStartTime;
794 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
796 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
798 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
802 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
809 _CalEventImpl::GetEndTime(void) const
811 int errorCode = CALENDAR_ERROR_NONE;
812 calendar_time_s endCalendarTime;
815 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
817 if (endCalendarTime.type == CALENDAR_TIME_UTIME)
819 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
821 else if (endCalendarTime.type == CALENDAR_TIME_LOCALTIME)
823 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
830 _CalEventImpl::GetLocation(void) const
832 int errorCode = CALENDAR_ERROR_NONE;
833 char* pLocation = null;
835 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.location, &pLocation);
837 return String(pLocation);
841 _CalEventImpl::GetCategory(void) const
844 int errorCode = CALENDAR_ERROR_NONE;
845 char* pCategories = null;
847 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.categories, &pCategories);
849 return _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
853 _CalEventImpl::GetSensitivity(void) const
855 int errorCode = CALENDAR_ERROR_NONE;
856 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
857 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
859 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.sensitivity, &srcSensitivity);
861 switch (srcSensitivity)
863 case CALENDAR_SENSITIVITY_PUBLIC:
864 sensitivity = SENSITIVITY_PUBLIC;
866 case CALENDAR_SENSITIVITY_PRIVATE:
867 sensitivity = SENSITIVITY_PRIVATE;
869 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
870 sensitivity = SENSITIVITY_CONFIDENTIAL;
873 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
874 sensitivity = SENSITIVITY_PUBLIC;
881 _CalEventImpl::GetReminder(void) const
883 if (__reminderListUpdated == false)
885 result r = _CalendarbookUtil::ConvertEventAlarmsToReminderList(__eventRecord.GetHandle(), __reminderList);
886 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
888 __reminderListUpdated = true;
891 if (__reminderList.GetCount() > 0)
893 return static_cast<const Reminder*>(__reminderList.GetAt(0));
900 _CalEventImpl::GetRecurrence(void) const
902 if (__pRecurrence == null)
904 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
907 return __pRecurrence.get();
911 _CalEventImpl::ConvertEventHandleToRecurrenceN(calendar_record_h eventHandle) const
913 int errorCode = CALENDAR_ERROR_NONE;
914 int srcFrequency = CALENDAR_RECURRENCE_NONE;
915 calendar_time_s untilCalendarTime;
916 int rangeType = CALENDAR_RANGE_NONE;
920 char* pByMonthDay = null;
921 char* pByMonth = null;
923 char* pExDates = null;
925 result r = E_SUCCESS;
930 CalDayOfWeek convertedWeekStart = CAL_SUNDAY;
932 std::unique_ptr<Recurrence> pRecurrence(new (std::nothrow) Recurrence());
934 errorCode = calendar_record_get_int(eventHandle, _calendar_event.freq, &srcFrequency);
936 if (srcFrequency == CALENDAR_RECURRENCE_NONE)
941 errorCode = calendar_record_get_int(eventHandle, _calendar_event.range_type, &rangeType);
942 errorCode = calendar_record_get_int(eventHandle, _calendar_event.count, &count);
943 errorCode = calendar_record_get_int(eventHandle, _calendar_event.interval, &interval);
944 errorCode = calendar_record_get_caltime(eventHandle, _calendar_event.until_time, &untilCalendarTime);
945 errorCode = calendar_record_get_int(eventHandle, _calendar_event.wkst, &weekStart);
947 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.byday, &pByDay);
948 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.bymonthday, &pByMonthDay);
949 if (pByMonthDay != null)
951 r = Integer::Parse(pByMonthDay, dayOfMonth);
952 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
954 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.bymonth, &pByMonth);
955 if (pByMonth != null)
957 r = Integer::Parse(pByMonth, monthOfYear);
958 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
961 switch (srcFrequency)
963 case CALENDAR_RECURRENCE_DAILY:
964 pRecurrence->SetFrequency(FREQ_DAILY);
966 case CALENDAR_RECURRENCE_WEEKLY:
967 pRecurrence->SetFrequency(FREQ_WEEKLY);
969 dayOfWeek = ConvertRRuleByDayStringToDayOfWeek(pByDay);
970 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %s", pByDay);
972 r = pRecurrence->SetDayOfWeek(dayOfWeek);
975 case CALENDAR_RECURRENCE_MONTHLY:
976 pRecurrence->SetFrequency(FREQ_MONTHLY);
982 int maxDaysOfMonth = _CalendarbookUtil::GetMaxDaysOfMonth(untilCalendarTime.time.date.year, monthOfYear);
983 r = pRecurrence->SetDayOfMonth(maxDaysOfMonth + dayOfMonth);
987 r = pRecurrence->SetDayOfMonth(dayOfMonth);
992 r = ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(pByDay, weekOfMonth, dayOfWeek);
993 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %s", pByDay);
995 r = pRecurrence->SetWeekOfMonth(weekOfMonth);
996 r = pRecurrence->SetDayOfWeek(dayOfWeek);
1000 case CALENDAR_RECURRENCE_YEARLY:
1001 pRecurrence->SetFrequency(FREQ_YEARLY);
1003 if (dayOfMonth != 0)
1007 int maxDaysOfMonth = _CalendarbookUtil::GetMaxDaysOfMonth(untilCalendarTime.time.date.year, monthOfYear);
1008 r = pRecurrence->SetDayOfMonth(maxDaysOfMonth + dayOfMonth);
1012 r = pRecurrence->SetDayOfMonth(dayOfMonth);
1017 r = ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(pByDay, weekOfMonth, dayOfWeek);
1018 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %s", pByDay);
1020 r = pRecurrence->SetWeekOfMonth(weekOfMonth);
1021 r = pRecurrence->SetDayOfWeek(dayOfWeek);
1023 r = pRecurrence->SetMonthOfYear(monthOfYear);
1027 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. frequency = %d", srcFrequency);
1031 if (rangeType == CALENDAR_RANGE_NONE)
1033 r = pRecurrence->SetUntil(&DateTime::GetMaxValue());
1035 else if (rangeType == CALENDAR_RANGE_UNTIL)
1039 if (untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1041 until.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
1045 until = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
1048 r = pRecurrence->SetUntil(&until);
1052 r = pRecurrence->SetCounts(count);
1054 r = pRecurrence->SetInterval(interval);
1058 case CALENDAR_SUNDAY:
1059 convertedWeekStart = CAL_SUNDAY;
1061 case CALENDAR_MONDAY:
1062 convertedWeekStart = CAL_MONDAY;
1065 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. week start = %d", weekStart);
1068 r = pRecurrence->SetWeekStart(convertedWeekStart);
1070 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExDates);
1071 if (pExDates != null && strlen(pExDates) != 0)
1073 r = ConvertRRuleExDateStringToRecurrence(pExDates, *pRecurrence.get());
1074 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. exdate = %s", pExDates);
1077 return pRecurrence.release();
1081 _CalEventImpl::GetLastRevisedTime(void) const
1083 int errorCode = CALENDAR_ERROR_NONE;
1084 long long lastModifiedTime = 0;
1085 DateTime tmpLastRevisedTime;
1087 errorCode = calendar_record_get_lli(__eventRecord.GetHandle(), _calendar_event.last_modified_time, &lastModifiedTime);
1089 tmpLastRevisedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(lastModifiedTime);
1091 return tmpLastRevisedTime;
1095 _CalEventImpl::SetSubject(const String& subject)
1097 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1099 SysTryReturnResult(NID_SCL, subject.GetLength() <= MAX_EVENT_SUBJECT_LENGTH, E_INVALID_ARG
1100 , "The length of the value exceeds MAX_EVENT_SUBJECT_LENGTH.");
1103 std::unique_ptr<char[]> pConvertedSubject(_StringConverter::CopyToCharArrayN(subject));
1104 SysTryReturnResult(NID_SCL, pConvertedSubject != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1106 int errorCode = CALENDAR_ERROR_NONE;
1107 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.summary, pConvertedSubject.get());
1113 _CalEventImpl::SetDescription(const String& description)
1115 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1117 SysTryReturnResult(NID_SCL, description.GetLength() <= MAX_EVENT_DESCRIPTION_LENGTH, E_INVALID_ARG
1118 , "The length of the value exceeds MAX_EVENT_DESCRIPTION_LENGTH.");
1121 std::unique_ptr<char[]> pConvertedDescription(_StringConverter::CopyToCharArrayN(description));
1122 SysTryReturnResult(NID_SCL, pConvertedDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1124 int errorCode = CALENDAR_ERROR_NONE;
1125 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.description, pConvertedDescription.get());
1131 _CalEventImpl::SetLocation(const String& location)
1133 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1135 SysTryReturnResult(NID_SCL, location.GetLength() <= MAX_EVENT_LOCATION_LENGTH, E_INVALID_ARG
1136 , "The length of the value exceeds MAX_EVENT_LOCATION_LENGTH.");
1139 std::unique_ptr<char[]> pConvertedLocation(_StringConverter::CopyToCharArrayN(location));
1140 SysTryReturnResult(NID_SCL, pConvertedLocation != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1142 int errorCode = CALENDAR_ERROR_NONE;
1143 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.location, pConvertedLocation.get());
1149 _CalEventImpl::SetStartAndEndTime(const DateTime& start, const DateTime& end)
1151 int errorCode = CALENDAR_ERROR_NONE;
1152 int recurrenceFrequency = 0;
1154 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFrequency);
1156 SysTryReturnResult(NID_SCL, recurrenceFrequency == CALENDAR_RECURRENCE_NONE, E_INVALID_CONDITION
1157 , "The recurrence date is already set. Cannot modify the start and end date/time.");
1158 SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, "Invalid argument is used. start = %S", start.ToString().GetPointer());
1159 SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, "Invalid argument is used. end = %S", end.ToString().GetPointer());
1160 SysTryReturnResult(NID_SCL, start <= end, E_INVALID_ARG, "Invalid argument is used. The end date is earlier than the start date.");
1162 return SetStartAndEndTimeCommon(start, end);
1166 _CalEventImpl::SetStartAndEndTimeCommon(const DateTime& start, const DateTime& end)
1168 int errorCode = CALENDAR_ERROR_NONE;
1169 calendar_time_s startCalendarTime;
1170 calendar_time_s endCalendarTime;
1172 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
1174 if (startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1176 startCalendarTime.time.date.year = start.GetYear();
1177 startCalendarTime.time.date.month = start.GetMonth();
1178 startCalendarTime.time.date.mday = start.GetDay();
1180 endCalendarTime.type = CALENDAR_TIME_LOCALTIME;
1181 endCalendarTime.time.date.year = end.GetYear();
1182 endCalendarTime.time.date.month = end.GetMonth();
1183 endCalendarTime.time.date.mday = end.GetDay();
1187 startCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(start);
1189 endCalendarTime.type = CALENDAR_TIME_UTIME;
1190 endCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(end);
1193 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, startCalendarTime);
1194 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, endCalendarTime);
1200 _CalEventImpl::SetCategory(EventCategory category)
1202 int errorCode = CALENDAR_ERROR_NONE;
1203 std::unique_ptr<char[]> pConvertedCategory;
1205 if (category == EVENT_CATEGORY_ANNIVERSARY)
1207 SetAllDayEvent(true);
1209 pConvertedCategory.reset(_StringConverter::CopyToCharArrayN(_EVENT_CATEGORY_ANNIVERSARY_STRING));
1210 SysTryReturnVoidResult(NID_SCL, pConvertedCategory != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1214 pConvertedCategory.reset(_StringConverter::CopyToCharArrayN(_EVENT_CATEGORY_APPOINTMENT_STRING));
1215 SysTryReturnVoidResult(NID_SCL, pConvertedCategory != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1218 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.categories, pConvertedCategory.get());
1222 _CalEventImpl::SetSensitivity(RecordSensitivity sensitivity)
1224 int errorCode = CALENDAR_ERROR_NONE;
1225 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.sensitivity, _CalendarbookUtil::ConvertSensitivityToCSSensitivity(sensitivity));
1229 _CalEventImpl::SetCoordinates(double latitude, double longitude)
1231 SysTryReturnResult(NID_SCL, latitude >= _MIN_LATITUDE && latitude <= _MAX_LATITUDE, E_INVALID_ARG, "Invalid argument is used. The latitude is out of range.");
1232 SysTryReturnResult(NID_SCL, longitude >= _MIN_LONGITUDE && longitude <= _MAX_LONGITUDE, E_INVALID_ARG, "Invalid argument is used. The longitude is out of range.");
1234 int errorCode = CALENDAR_ERROR_NONE;
1236 errorCode = calendar_record_set_double(__eventRecord.GetHandle(), _calendar_event.latitude, latitude);
1237 errorCode = calendar_record_set_double(__eventRecord.GetHandle(), _calendar_event.longitude, longitude);
1243 _CalEventImpl::GetCoordinates(double& latitude, double& longitude) const
1245 int errorCode = CALENDAR_ERROR_NONE;
1247 errorCode = calendar_record_get_double(__eventRecord.GetHandle(), _calendar_event.latitude, &latitude);
1248 errorCode = calendar_record_get_double(__eventRecord.GetHandle(), _calendar_event.longitude, &longitude);
1252 _CalEventImpl::SetReminder(const Reminder* pReminder)
1254 int errorCode = CALENDAR_ERROR_NONE;
1256 unsigned int reminderCount = 0;
1257 calendar_record_h tmpAlarmHandle = null;
1259 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, &reminderCount);
1261 if (pReminder != null)
1263 int convertedTimeUnit = 0;
1264 switch (pReminder->GetTimeUnit())
1266 case REMINDER_TIME_UNIT_MINUTE:
1267 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1269 case REMINDER_TIME_UNIT_HOUR:
1270 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
1272 case REMINDER_TIME_UNIT_DAY:
1273 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
1275 case REMINDER_TIME_UNIT_WEEK:
1276 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
1282 calendar_record_h tmpAlarmHandle = null;
1284 if (reminderCount > 0)
1286 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, 0, &tmpAlarmHandle);
1287 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1288 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, pReminder->GetTimeOffset());
1290 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(pReminder->GetSoundFile()));
1291 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1293 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1297 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(pReminder->GetSoundFile()));
1298 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1300 errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
1301 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1303 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1304 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, pReminder->GetTimeOffset());
1305 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1307 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1312 if (reminderCount > 0)
1314 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, 0, &tmpAlarmHandle);
1315 errorCode = calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1319 __reminderList.RemoveAll(true);
1320 __reminderListUpdated = false;
1326 _CalEventImpl::SetRecurrence(const Recurrence* pRecurrence)
1328 result r = E_SUCCESS;
1329 int errorCode = CALENDAR_ERROR_NONE;
1331 if (pRecurrence != null)
1333 r = VerifyRecurrence(*pRecurrence);
1334 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1336 r = ResetStartAndEndTimeByRecurrence(*pRecurrence);
1337 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1339 r = ConvertRecurrenceToEventHandle(*pRecurrence, __eventRecord.GetHandle());
1340 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1342 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*pRecurrence, IsAllDayEvent())));
1343 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
1345 __pRecurrence.reset(new (std::nothrow) Recurrence(*pRecurrence));
1346 SysTryReturnResult(NID_SCL, __pRecurrence != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1350 int errorCode = CALENDAR_ERROR_NONE;
1351 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.freq, CALENDAR_RECURRENCE_NONE);
1353 __pRecurrence.reset(null);
1360 _CalEventImpl::AddReminder(const Reminder& reminder)
1362 int errorCode = CALENDAR_ERROR_NONE;
1363 calendar_record_h tmpAlarmHandle = null;
1365 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(reminder.GetSoundFile()));
1366 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1368 errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
1369 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1371 int convertedTimeUnit = 0;
1373 ReminderTimeUnit timeUnit = reminder.GetTimeUnit();
1376 case REMINDER_TIME_UNIT_MINUTE:
1377 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1379 case REMINDER_TIME_UNIT_HOUR:
1380 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
1382 case REMINDER_TIME_UNIT_DAY:
1383 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
1385 case REMINDER_TIME_UNIT_WEEK:
1386 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
1388 case REMINDER_TIME_UNIT_NONE:
1389 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
1395 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1396 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, reminder.GetTimeOffset());
1397 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1399 if (convertedTimeUnit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
1401 errorCode = calendar_record_set_lli(tmpAlarmHandle, _calendar_alarm.time, _CalendarbookUtil::ConvertDateTimeToEpochTime(reminder.GetAbsoluteTime()));
1404 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1406 __reminderList.RemoveAll(true);
1407 __reminderListUpdated = false;
1413 _CalEventImpl::RemoveReminderAt(int index)
1415 int errorCode = CALENDAR_ERROR_NONE;
1416 calendar_record_h tmpAlarmHandle = null;
1418 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, index, &tmpAlarmHandle);
1419 SysTryReturnResult(NID_SCL, tmpAlarmHandle != null, E_OUT_OF_RANGE, "The index is out of range. index = %d", index);
1421 errorCode = calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1423 __reminderList.RemoveAll(true);
1424 __reminderListUpdated = false;
1430 _CalEventImpl::GetAllReminders(void) const
1434 if (__reminderListUpdated == false)
1436 result r = _CalendarbookUtil::ConvertEventAlarmsToReminderList(__eventRecord.GetHandle(), __reminderList);
1437 SysTryReturn(NID_SCL, r == E_SUCCESS, __reminderList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1439 __reminderListUpdated = true;
1442 return __reminderList;
1446 _CalEventImpl::ConvertRecurrenceToEventHandle(const Recurrence& recurrence, calendar_record_h eventHandle) const
1448 result r = E_SUCCESS;
1450 int errorCode = CALENDAR_ERROR_NONE;
1451 int weekStart = CALENDAR_SUNDAY;
1452 std::unique_ptr<char[]> pByDay;
1453 std::unique_ptr<char[]> pByMonth;
1454 std::unique_ptr<char[]> pByMonthDay;
1457 String dayOfWeekString;
1458 String exDateString;
1460 switch (recurrence.GetWeekStart())
1463 weekStart = CALENDAR_SUNDAY;
1466 weekStart = CALENDAR_MONDAY;
1469 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. week start = %d", recurrence.GetWeekStart());
1470 return E_INVALID_ARG;
1472 errorCode = calendar_record_set_int(eventHandle, _calendar_event.wkst, weekStart);
1473 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_INVALID_ARG, "Invalid argument is passed. week start = %d", weekStart);
1475 if (recurrence.GetUntil() != null)
1477 if (*recurrence.GetUntil() == DateTime::GetMaxValue())
1479 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_NONE);
1483 calendar_time_s startCalendarTime;
1484 calendar_time_s untilCalendarTime;
1486 errorCode = calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &startCalendarTime);
1487 if (startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1489 untilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
1490 untilCalendarTime.time.date.year = recurrence.GetUntil()->GetYear();
1491 untilCalendarTime.time.date.month = recurrence.GetUntil()->GetMonth();
1492 untilCalendarTime.time.date.mday = recurrence.GetUntil()->GetDay();
1496 untilCalendarTime.type = CALENDAR_TIME_UTIME;
1497 untilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(*recurrence.GetUntil());
1500 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
1501 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.until_time, untilCalendarTime);
1506 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
1507 errorCode = calendar_record_set_int(eventHandle, _calendar_event.count, recurrence.GetCounts());
1510 errorCode = calendar_record_set_int(eventHandle, _calendar_event.interval, recurrence.GetInterval());
1512 switch (recurrence.GetFrequency())
1515 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_DAILY);
1518 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_WEEKLY);
1520 dayOfWeek = recurrence.GetDayOfWeek();
1521 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, 0, dayOfWeekString);
1522 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1524 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1525 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, pByDay.get());
1529 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_MONTHLY);
1531 if (recurrence.GetDayOfMonth() != 0)
1533 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1534 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, pByMonthDay.get());
1538 dayOfWeek = recurrence.GetDayOfWeek();
1539 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1540 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1542 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1543 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, pByDay.get());
1548 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY);
1550 pByMonth.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetMonthOfYear())));
1551 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, pByMonth.get());
1553 if (recurrence.GetDayOfMonth() != 0)
1555 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1556 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, pByMonthDay.get());
1560 dayOfWeek = recurrence.GetDayOfWeek();
1561 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1562 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1564 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1565 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, pByDay.get());
1570 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. frequency = %d", recurrence.GetFrequency());
1571 return E_INVALID_ARG;
1578 _CalEventImpl::ConvertDayOfWeekToRRuleByDayString(int dayOfWeek, int weekOfMonth, String& byDayString) const
1580 int tmpDayOfWeek = CAL_SUNDAY;
1582 byDayString.Clear();
1583 for (int i = 0; i < _RECURRENCE_NUMBER_OF_WEEK_DAY; i++)
1585 if (dayOfWeek & tmpDayOfWeek)
1587 if (weekOfMonth != 0)
1589 byDayString.Append(weekOfMonth);
1592 switch (tmpDayOfWeek)
1595 byDayString.Append(_RECURRENCE_KEYWORD_SUNDAY);
1598 byDayString.Append(_RECURRENCE_KEYWORD_MONDAY);
1601 byDayString.Append(_RECURRENCE_KEYWORD_TUESDAY);
1604 byDayString.Append(_RECURRENCE_KEYWORD_WEDNESDAY);
1607 byDayString.Append(_RECURRENCE_KEYWORD_THURSDAY);
1610 byDayString.Append(_RECURRENCE_KEYWORD_FRIDAY);
1613 byDayString.Append(_RECURRENCE_KEYWORD_SATURDAY);
1616 byDayString.Append(_RECURRENCE_DELIMITER);
1622 byDayString.Remove(byDayString.GetLength() - 1, _RECURRENCE_DELIMITER_LENGTH);
1628 _CalEventImpl::GetCalendarId(void) const
1630 int errorCode = CALENDAR_ERROR_NONE;
1631 int srcCalendarbookId = 0;
1633 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.calendar_book_id, &srcCalendarbookId);
1635 return srcCalendarbookId;
1639 _CalEventImpl::GetBaseEventId(void) const
1641 int errorCode = CALENDAR_ERROR_NONE;
1642 int srcBaseEventId = INVALID_RECORD_ID;
1644 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.original_event_id, &srcBaseEventId);
1646 return srcBaseEventId;
1650 _CalEventImpl::SetOriginalCalEventId(RecordId originalEventId)
1652 __originalEventId = originalEventId;
1653 __isInstance = true;
1657 _CalEventImpl::GetAttendeeIndex(const char* pAttendeeEmail)
1659 int index = _INVALID_ATTENDEE_INDEX;
1660 unsigned int attendeeCount = 0;
1662 int errorCode = CALENDAR_ERROR_NONE;
1663 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
1665 calendar_record_h tmpAttendeeHandle = null;
1666 char* pTmpAttendeeEmail = null;
1667 for (int i = 0; i < attendeeCount; i++)
1669 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
1670 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpAttendeeEmail);
1672 if (strcmp(pAttendeeEmail, pTmpAttendeeEmail) == 0)
1683 _CalEventImpl::VerifyRecurrence(const Recurrence& recurrence)
1685 const DateTime* pUntil = recurrence.GetUntil();
1686 RecurFrequency frequency = recurrence.GetFrequency();
1687 int durationLimit = 0;
1688 int interval = recurrence.GetInterval();
1690 DateTime startTime = GetStartTime();
1691 DateTime endTime = GetEndTime();
1692 EventCategory category = GetCategory();
1696 SysTryReturnResult(NID_SCL, startTime <= *pUntil, E_INVALID_CONDITION, "The until date of recurrence is earlier than start date.");
1699 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1701 if (category == EVENT_CATEGORY_ANNIVERSARY)
1703 SysTryReturnResult(NID_SCL, frequency == FREQ_YEARLY, E_TYPE_MISMATCH
1704 , "The recurrence pattern is not a yearly pattern in case of the event being an Anniversary.");
1708 if (frequency == FREQ_DAILY)
1710 durationLimit = _TERM_LIMIT_DAILY * interval;
1712 else if (frequency == FREQ_WEEKLY)
1714 SysTryReturnResult(NID_SCL, recurrence.GetDayOfWeek() != 0, E_INVALID_ARG, "Invalid argument is used. The day of week is not set.");
1715 durationLimit = _TERM_LIMIT_WEEKLY * interval;
1717 else if (frequency == FREQ_MONTHLY)
1719 SysTryReturnResult(NID_SCL, recurrence.GetDayOfMonth() != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1720 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1721 durationLimit = _TERM_LIMIT_MONTHLY * interval;
1723 else if (frequency == FREQ_YEARLY)
1725 int dayOfMonth = recurrence.GetDayOfMonth();
1726 int monthOfYear = recurrence.GetMonthOfYear();
1727 SysTryReturnResult(NID_SCL, monthOfYear != 0, E_INVALID_ARG, "Invalid argument is used. The month of year is not set.");
1728 SysTryReturnResult(NID_SCL, dayOfMonth != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1729 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1731 SysTryReturnResult(NID_SCL, monthOfYear != 2 || dayOfMonth < 30
1732 , E_INVALID_ARG, "Invalid argument is used. If the frequency is yearly, the max days of the February is less than 30.");
1733 if (dayOfMonth > 30)
1735 SysTryReturnResult(NID_SCL, monthOfYear != 4 && monthOfYear != 6 && monthOfYear != 9 && monthOfYear != 11
1736 , E_INVALID_ARG, "Invalid argument is used. If the frequency is yearly, the max days of the April, June, September and November is less than 31.");
1739 durationLimit = _TERM_LIMIT_YEARLY * interval;
1742 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1743 SysTryReturnResult(NID_SCL, duration.GetDays() <= durationLimit, E_INVALID_CONDITION
1744 , "The duration of the event is greater than (interval x frequency) days. duration days = %d", duration.GetDays());
1750 _CalEventImpl::ResetStartAndEndTimeByRecurrence(const Recurrence& recurrence)
1752 result r = E_SUCCESS;
1756 bool isAllDay = IsAllDayEvent();
1757 Locales::TimeZone timeZone;
1761 timeZone = GetTimeZone();
1762 startTime = timeZone.UtcTimeToWallTime(GetStartTime());
1763 endTime = timeZone.UtcTimeToWallTime(GetEndTime());
1767 startTime = GetStartTime();
1768 endTime = GetEndTime();
1771 DateTime calculatedStartTime(startTime);
1772 DateTime calculatedEndTime(endTime);
1773 RecurFrequency frequency = recurrence.GetFrequency();
1774 int interval = recurrence.GetInterval();
1775 int dayOfMonth = recurrence.GetDayOfMonth();
1776 int dayOfWeek = recurrence.GetDayOfWeek();
1777 int weekOfMonth = recurrence.GetWeekOfMonth();
1778 int monthOfYear = recurrence.GetMonthOfYear();
1779 CalDayOfWeek weekStart = recurrence.GetWeekStart();
1780 CalDayOfWeek weekEnd = CAL_SATURDAY;
1782 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1784 if (weekStart == CAL_MONDAY)
1786 weekEnd = CAL_SUNDAY;
1789 if (recurrence.GetUntil() != null)
1791 until = *(recurrence.GetUntil());
1794 until = timeZone.UtcTimeToWallTime(until);
1799 until = _CalendarbookImpl::GetMaxDateTime();
1802 CalDayOfWeek dayOfStartTime = GetDayOfWeek(startTime, timeZone);
1804 if (frequency == FREQ_WEEKLY)
1808 for (int i = 0; i < _CALENDARBOOK_NUMBER_OF_DAYS_OF_WEEK; i++)
1810 if ((dayOfStartTime & dayOfWeek) != 0)
1815 if ((dayOfStartTime & weekEnd) != 0)
1817 count += (interval - 1) * _CALENDARBOOK_NUMBER_OF_DAYS_OF_WEEK;
1820 dayOfStartTime = GetNextDayOfWeek(dayOfStartTime);
1824 r = calculatedStartTime.AddDays(count);
1825 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1826 r = calculatedEndTime.AddDays(count);
1827 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1830 else if (frequency == FREQ_MONTHLY)
1832 if (dayOfMonth != 0)
1834 bool isDone = false;
1835 while (calculatedStartTime <= until)
1837 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1839 if (calculatedStartTime >= startTime)
1845 calculatedStartTime.AddMonths(interval);
1847 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1848 calculatedEndTime = calculatedStartTime;
1849 calculatedEndTime.Add(duration);
1853 bool isDone = false;
1855 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1856 while (calculatedStartTime <= until)
1858 for (int i = 0; i < dayCount; i++)
1860 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1861 if (calculatedStartTime >= startTime)
1866 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1872 calculatedStartTime.AddMonths(interval);
1875 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1876 calculatedEndTime = calculatedStartTime;
1877 calculatedEndTime.Add(duration);
1880 else if (frequency == FREQ_YEARLY)
1882 if (dayOfMonth != 0)
1884 bool isDone = false;
1885 while (calculatedStartTime <= until)
1887 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), monthOfYear, dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1889 if (calculatedStartTime >= startTime)
1895 calculatedStartTime.AddYears(interval);
1897 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1898 calculatedEndTime = calculatedStartTime;
1899 calculatedEndTime.Add(duration);
1903 bool isDone = false;
1905 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1906 while (calculatedStartTime <= until)
1908 for (int i = 0; i < dayCount; i++)
1910 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), monthOfYear, weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1911 if (calculatedStartTime >= startTime)
1916 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1922 calculatedStartTime.AddYears(interval);
1925 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1926 calculatedEndTime = calculatedStartTime;
1927 calculatedEndTime.Add(duration);
1933 calculatedStartTime = timeZone.WallTimeToUtcTime(calculatedStartTime);
1934 calculatedEndTime = timeZone.WallTimeToUtcTime(calculatedEndTime);
1937 SysTryReturnResult(NID_SCL, calculatedStartTime <= until, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1938 SysTryReturnResult(NID_SCL, calculatedEndTime <= _CalendarbookImpl::GetMaxDateTime(), E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1940 SysLog(NID_SCL, "Reset start time : %S", calculatedStartTime.ToString().GetPointer());
1941 SetStartAndEndTimeCommon(calculatedStartTime, calculatedEndTime);
1947 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeek(const String& byDay) const
1949 result r = E_SUCCESS;
1953 SysTryReturn(NID_SCL, !byDay.IsEmpty(), 0, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The byDay is empty.");
1955 String delim(_RECURRENCE_DELIMITER);
1958 StringTokenizer strTok(byDay, delim);
1959 while (strTok.HasMoreTokens())
1961 r = strTok.GetNextToken(token);
1962 SysTryReturn(NID_SCL, r == E_SUCCESS, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1964 if (token == String(_RECURRENCE_KEYWORD_SUNDAY))
1966 dayOfWeek |= CAL_SUNDAY;
1968 else if (token == String(_RECURRENCE_KEYWORD_MONDAY))
1970 dayOfWeek |= CAL_MONDAY;
1972 else if (token == String(_RECURRENCE_KEYWORD_TUESDAY))
1974 dayOfWeek |= CAL_TUESDAY;
1976 else if (token == String(_RECURRENCE_KEYWORD_WEDNESDAY))
1978 dayOfWeek |= CAL_WEDNESDAY;
1980 else if (token == String(_RECURRENCE_KEYWORD_THURSDAY))
1982 dayOfWeek |= CAL_THURSDAY;
1984 else if (token == String(_RECURRENCE_KEYWORD_FRIDAY))
1986 dayOfWeek |= CAL_FRIDAY;
1988 else if (token == String(_RECURRENCE_KEYWORD_SATURDAY))
1990 dayOfWeek |= CAL_SATURDAY;
1994 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %S", byDay.GetPointer());
2003 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(const String& byDay, int& weekOfMonth, int& dayOfWeek) const
2005 result r = E_SUCCESS;
2006 String delim(_RECURRENCE_DELIMITER);
2008 wchar_t tmpChar = 0;
2009 int tmpWeekOfMonth = 0;
2010 int weekStringStartIndex = 0;
2016 SysTryReturnResult(NID_SCL, !byDay.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The byDay is empty.");
2018 StringTokenizer strTok(byDay, delim);
2020 while (strTok.HasMoreTokens())
2022 r = strTok.GetNextToken(token);
2023 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2025 r = token.GetCharAt(_RECURRENCE_BY_DAY_FIRST_INDEX, tmpChar);
2026 if (tmpChar == _RECURRENCE_BY_DAY_CHAR_MINUS)
2028 SysTryReturnResult(NID_SCL, weekOfMonth == 0 || weekOfMonth == _MAX_WEEK_OF_RECURRENCE_BY_DAY
2029 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2031 if (weekOfMonth == 0)
2034 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2035 SysTryReturnResult(NID_SCL, tmpChar == _RECURRENCE_BY_DAY_CHAR_ONE
2036 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2038 weekOfMonth = _MAX_WEEK_OF_RECURRENCE_BY_DAY;
2040 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2042 else if (tmpChar == _RECURRENCE_BY_DAY_CHAR_PLUS)
2044 if (weekOfMonth == 0)
2047 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2048 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2049 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_RECURRENCE_BY_DAY
2050 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2052 weekOfMonth = tmpWeekOfMonth;
2056 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2057 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2060 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2064 if (weekOfMonth == 0)
2066 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2067 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_RECURRENCE_BY_DAY
2068 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2070 weekOfMonth = tmpWeekOfMonth;
2074 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2075 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2078 weekStringStartIndex = _RECURRENCE_BY_DAY_FIRST_INDEX + 1;
2081 token.SubString(weekStringStartIndex, tmpString);
2083 if (tmpString == String(_RECURRENCE_KEYWORD_SUNDAY))
2085 dayOfWeek |= CAL_SUNDAY;
2087 else if (tmpString == String(_RECURRENCE_KEYWORD_MONDAY))
2089 dayOfWeek |= CAL_MONDAY;
2091 else if (tmpString == String(_RECURRENCE_KEYWORD_TUESDAY))
2093 dayOfWeek |= CAL_TUESDAY;
2095 else if (tmpString == String(_RECURRENCE_KEYWORD_WEDNESDAY))
2097 dayOfWeek |= CAL_WEDNESDAY;
2099 else if (tmpString == String(_RECURRENCE_KEYWORD_THURSDAY))
2101 dayOfWeek |= CAL_THURSDAY;
2103 else if (tmpString == String(_RECURRENCE_KEYWORD_FRIDAY))
2105 dayOfWeek |= CAL_FRIDAY;
2107 else if (tmpString == String(_RECURRENCE_KEYWORD_SATURDAY))
2109 dayOfWeek |= CAL_SATURDAY;
2113 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %S", byDay.GetPointer());
2121 _CalEventImpl::ConvertRRuleExDateStringToRecurrence(const String& exdate, Recurrence& recurrence) const
2123 result r = E_SUCCESS;
2125 String delim(_RECURRENCE_DELIMITER);
2127 DateTime tmpDateTime;
2128 TimeZone tmpTimeZone;
2129 TimeZone utcTimeZone = TimeZone::GetGmtTimeZone();
2130 bool isDate = false;
2132 SysTryReturnResult(NID_SCL, !exdate.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The exdate is empty.");
2134 StringTokenizer strTok(exdate, delim);
2135 while (strTok.HasMoreTokens())
2137 r = strTok.GetNextToken(token);
2138 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2140 r = _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(token, tmpDateTime, tmpTimeZone, isDate);
2141 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. exdate = %S", exdate.GetPointer());
2143 if (!isDate && tmpTimeZone != utcTimeZone)
2145 tmpDateTime = tmpTimeZone.WallTimeToUtcTime(tmpDateTime);
2148 r = recurrence.AddExceptionDate(tmpDateTime);
2149 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. exdate = %S", exdate.GetPointer());
2156 _CalEventImpl::ConvertRecurrenceToRRuleExDateString(const Recurrence& recurrence, bool isDate) const
2158 result r = E_SUCCESS;
2160 bool isNotFirst = false;
2161 String exdateString;
2163 std::unique_ptr<IList, AllElementsDeleter> pExDateList(recurrence.GetExceptionDatesN());
2165 IEnumerator* pEnum = pExDateList->GetEnumeratorN();
2166 while (pEnum->MoveNext() == E_SUCCESS)
2168 DateTime* pDateTime = static_cast<DateTime*>(pEnum->GetCurrent());
2172 r = exdateString.Append(_RECURRENCE_DELIMITER);
2175 r = exdateString.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(*pDateTime, isDate));
2181 return exdateString;
2185 _CalEventImpl::GetNextDayOfWeek(CalDayOfWeek currentDay)
2187 int tmpDay = currentDay;
2190 if (tmpDay > CAL_SATURDAY)
2192 tmpDay = CAL_SUNDAY;
2195 return static_cast<CalDayOfWeek>(tmpDay);
2199 _CalEventImpl::GetDate(int year, int month, int weekOfMonth, CalDayOfWeek dayOfWeek, const DateTime& time, const Locales::TimeZone& timeZone)
2201 DateTime resultTime;
2203 Tizen::Locales::DayOfWeek dayOfWeekByGregorianCalendar = Tizen::Locales::DAY_OF_WEEK_UNDEFINED;
2208 dayOfWeekByGregorianCalendar = Tizen::Locales::SUNDAY;
2211 dayOfWeekByGregorianCalendar = Tizen::Locales::MONDAY;
2214 dayOfWeekByGregorianCalendar = Tizen::Locales::TUESDAY;
2217 dayOfWeekByGregorianCalendar = Tizen::Locales::WEDNESDAY;
2220 dayOfWeekByGregorianCalendar = Tizen::Locales::THURSDAY;
2223 dayOfWeekByGregorianCalendar = Tizen::Locales::FRIDAY;
2226 dayOfWeekByGregorianCalendar = Tizen::Locales::SATURDAY;
2232 Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN);
2234 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
2235 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
2236 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_WEEK, dayOfWeekByGregorianCalendar);
2237 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_WEEK_OF_MONTH, weekOfMonth);
2239 resultTime = pGregorianCalendar->GetTime();
2241 if (month != resultTime.GetMonth())
2243 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
2244 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
2245 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_WEEK_OF_MONTH, _MAX_WEEK_OF_RECURRENCE_BY_DAY - 1);
2246 resultTime = pGregorianCalendar->GetTime();
2249 resultTime.SetValue(resultTime.GetYear(), resultTime.GetMonth(), resultTime.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
2251 delete pGregorianCalendar;
2257 _CalEventImpl::GetDayOfWeek(const DateTime& date, const Locales::TimeZone& timeZone)
2259 CalDayOfWeek dayOfWeek = CAL_SUNDAY;
2261 std::unique_ptr<Tizen::Locales::Calendar> pGregorianCalendar(Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN));
2263 pGregorianCalendar->SetTime(date);
2264 int dayOfWeekByGregorianCalendar = pGregorianCalendar->GetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_WEEK);
2266 switch (dayOfWeekByGregorianCalendar)
2268 case Tizen::Locales::SUNDAY:
2269 dayOfWeek = CAL_SUNDAY;
2271 case Tizen::Locales::MONDAY:
2272 dayOfWeek = CAL_MONDAY;
2274 case Tizen::Locales::TUESDAY:
2275 dayOfWeek = CAL_TUESDAY;
2277 case Tizen::Locales::WEDNESDAY:
2278 dayOfWeek = CAL_WEDNESDAY;
2280 case Tizen::Locales::THURSDAY:
2281 dayOfWeek = CAL_THURSDAY;
2283 case Tizen::Locales::FRIDAY:
2284 dayOfWeek = CAL_FRIDAY;
2286 case Tizen::Locales::SATURDAY:
2287 dayOfWeek = CAL_SATURDAY;
2297 _CalEventImpl::GetFirstDay(CalDayOfWeek weekStart, int dayOfWeek, int& count)
2300 int tmpDay = weekStart;
2303 for (int i = 0; i < _CALENDARBOOK_NUMBER_OF_DAYS_OF_WEEK; i++)
2305 if ((tmpDay & dayOfWeek) != 0)
2315 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2318 return static_cast<CalDayOfWeek>(firstDay);
2322 _CalEventImpl::GetNextDay(int dayOfWeek, CalDayOfWeek currentDay)
2324 int tmpDay = currentDay;
2326 for (int i = 0; i < _CALENDARBOOK_NUMBER_OF_DAYS_OF_WEEK; i++)
2328 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2330 if ((tmpDay & dayOfWeek) != 0)
2336 return static_cast<CalDayOfWeek>(tmpDay);
2340 _CalEventImpl::SetRecordHandle(calendar_record_h eventHandle)
2342 __eventRecord.ResetHandle(eventHandle);
2346 _CalEventImpl::GetRecordHandle(void) const
2348 return __eventRecord.GetHandle();
2352 _CalEventImpl::CreateDefaultInstanceN(void)
2354 return new (std::nothrow) CalEvent();
2358 _CalEventImpl::GetInstance(CalEvent& event)
2360 return event.__pCalEventImpl;
2363 const _CalEventImpl*
2364 _CalEventImpl::GetInstance(const CalEvent& event)
2366 return event.__pCalEventImpl;