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 _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_MONTH = 5;
82 static const double _MIN_LATITUDE = -90.0;
83 static const double _MAX_LATITUDE = 90.0;
84 static const double _MIN_LONGITUDE = -180.0;
85 static const double _MAX_LONGITUDE = 180.0;
87 _CalEventImpl::_CalEventImpl(void)
88 : __originalEventId(INVALID_RECORD_ID)
90 , __reminderListUpdated(false)
92 // Set default start and end time
95 SystemTime::GetCurrentTime(startTime);
96 if (IsFailed(GetLastResult()))
98 startTime = _CalendarbookImpl::GetMinDateTime();
102 DateTime endTime(startTime);
103 r = endTime.AddHours(_DEFAULT_ADDED_HOUR);
104 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
106 calendar_time_s startCalendarTime;
107 calendar_time_s endCalendarTime;
108 startCalendarTime.type = CALENDAR_TIME_UTIME;
109 endCalendarTime.type = CALENDAR_TIME_UTIME;
110 startCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(startTime);
111 endCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(endTime);
113 int errorCode = CALENDAR_ERROR_NONE;
114 calendar_record_h eventHandle = null;
116 r = _CalendarbookDbConnector::Connect();
117 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
119 errorCode = calendar_record_create(_calendar_event._uri, &eventHandle);
120 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
122 __eventRecord.ResetHandle(eventHandle);
124 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
125 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
128 errorCode = calendar_record_set_int(eventHandle, _calendar_event.event_status, CALENDAR_EVENT_STATUS_NONE);
129 errorCode = calendar_record_set_int(eventHandle, _calendar_event.busy_status, CALENDAR_EVENT_BUSY_STATUS_FREE);
130 errorCode = calendar_record_set_int(eventHandle, _calendar_event.priority, CALENDAR_EVENT_PRIORITY_NORMAL);
131 errorCode = calendar_record_set_int(eventHandle, _calendar_event.sensitivity, CALENDAR_SENSITIVITY_PUBLIC);
133 r = __reminderList.Construct();
134 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
137 _CalEventImpl::_CalEventImpl(const _CalEventImpl& rhs)
138 : __originalEventId(rhs.__originalEventId)
139 , __isInstance(rhs.__isInstance)
140 , __reminderListUpdated(false)
142 int errorCode = CALENDAR_ERROR_NONE;
143 calendar_record_h eventHandle = null;
145 result r = _CalendarbookDbConnector::Connect();
146 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
148 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
149 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
151 __eventRecord.ResetHandle(eventHandle);
153 r = __reminderList.Construct();
154 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
157 _CalEventImpl::~_CalEventImpl(void)
159 int errorCode = CALENDAR_ERROR_NONE;
160 errorCode = calendar_record_destroy(__eventRecord.ReleaseHandle(), true);
162 __reminderList.RemoveAll(true);
164 result r = _CalendarbookDbConnector::Disconnect();
165 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
169 _CalEventImpl::operator =(const _CalEventImpl& rhs)
176 __originalEventId = rhs.__originalEventId;
177 __isInstance = rhs.__isInstance;
178 __reminderList.RemoveAll(true);
179 __reminderListUpdated = false;
181 int errorCode = CALENDAR_ERROR_NONE;
182 calendar_record_h eventHandle = null;
184 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
185 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
187 __eventRecord.ResetHandle(eventHandle);
193 _CalEventImpl::IsInstance(void) const
199 _CalEventImpl::IsRecurring(void) const
201 int errorCode = CALENDAR_ERROR_NONE;
202 int recurrenceFreq = CALENDAR_RECURRENCE_NONE;
204 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFreq);
206 if (recurrenceFreq == CALENDAR_RECURRENCE_NONE)
215 _CalEventImpl::GetOriginalCalEventId(void) const
217 return __originalEventId;
221 _CalEventImpl::IsAllDayEvent(void) const
223 int errorCode = CALENDAR_ERROR_NONE;
224 calendar_time_s startCalendarTime;
226 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
227 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
236 _CalEventImpl::SetAllDayEvent(bool isAllDayEvent)
238 if (GetCategory() == EVENT_CATEGORY_ANNIVERSARY)
243 int errorCode = CALENDAR_ERROR_NONE;
244 calendar_time_s startCalendarTime;
245 calendar_time_s tmpStartCalendarTime;
246 calendar_time_s endCalendarTime;
247 calendar_time_s tmpEndCalendarTime;
249 bool isChanged = false;
251 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
252 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
254 if (isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_UTIME)
256 tmpStartCalendarTime.type = CALENDAR_TIME_LOCALTIME;
257 DateTime tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
258 tmpStartCalendarTime.time.date.year = tmpStartTime.GetYear();
259 tmpStartCalendarTime.time.date.month = tmpStartTime.GetMonth();
260 tmpStartCalendarTime.time.date.mday = tmpStartTime.GetDay();
262 tmpEndCalendarTime.type = CALENDAR_TIME_LOCALTIME;
263 DateTime tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
264 tmpEndCalendarTime.time.date.year = tmpEndTime.GetYear();
265 tmpEndCalendarTime.time.date.month = tmpEndTime.GetMonth();
266 tmpEndCalendarTime.time.date.mday = tmpEndTime.GetDay();
268 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
269 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
273 else if (!isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
275 tmpStartCalendarTime.type = CALENDAR_TIME_UTIME;
276 DateTime tmpStartTime;
277 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
278 tmpStartCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpStartTime);
280 tmpEndCalendarTime.type = CALENDAR_TIME_UTIME;
282 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
283 tmpEndCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpEndTime);
285 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
286 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
293 int rangeType = CALENDAR_RANGE_NONE;
294 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.range_type, &rangeType);
296 if (rangeType == CALENDAR_RANGE_UNTIL)
298 calendar_time_s untilCalendarTime;
299 calendar_time_s tmpUntilCalendarTime;
301 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, &untilCalendarTime);
302 if (isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_UTIME)
304 tmpUntilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
305 DateTime tmpUntilTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
306 tmpUntilCalendarTime.time.date.year = tmpUntilTime.GetYear();
307 tmpUntilCalendarTime.time.date.month = tmpUntilTime.GetMonth();
308 tmpUntilCalendarTime.time.date.mday = tmpUntilTime.GetDay();
310 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
312 else if (!isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
314 tmpUntilCalendarTime.type = CALENDAR_TIME_UTIME;
315 DateTime tmpUntilTime;
316 tmpUntilTime.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
317 tmpUntilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpUntilTime);
319 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
325 if (__pRecurrence == null)
327 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
330 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*__pRecurrence.get(), isAllDayEvent)));
331 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
337 _CalEventImpl::GetUIDN(void) const
341 int errorCode = CALENDAR_ERROR_NONE;
342 char* pStrUid = null;
343 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
345 if (pStrUid == null || strlen(pStrUid) == 0)
350 ByteBuffer* pConvertedUidBuffer = _CalendarbookUtil::ConvertCharArrayToByteBufferN(pStrUid);
351 SysTryReturn(NID_SCL, pConvertedUidBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
353 return pConvertedUidBuffer;
357 _CalEventImpl::SetUID(const ByteBuffer* pUid)
359 int errorCode = CALENDAR_ERROR_NONE;
363 std::unique_ptr<char[]> pConvertedUidArray(_CalendarbookUtil::ConvertByteBufferToCharArrayN(*pUid));
364 SysTryReturn(NID_SCL, pConvertedUidArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
366 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pConvertedUidArray.get());
370 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, null);
377 _CalEventImpl::GetUid(void) const
379 int errorCode = CALENDAR_ERROR_NONE;
380 char* pStrUid = null;
381 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
383 return String(pStrUid);
387 _CalEventImpl::SetUid(const Tizen::Base::String& uid)
389 int errorCode = CALENDAR_ERROR_NONE;
391 std::unique_ptr<char[]> pStrUid(_StringConverter::CopyToCharArrayN(uid));
392 SysTryReturnVoidResult(NID_SCL, pStrUid != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
394 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pStrUid.get());
398 _CalEventImpl::GetStatus(void) const
400 int errorCode = CALENDAR_ERROR_NONE;
401 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
403 EventStatus eventStatus = EVENT_STATUS_NONE;
405 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.event_status, &srcEventStatus);
407 switch (srcEventStatus)
409 case CALENDAR_EVENT_STATUS_NONE:
410 eventStatus = EVENT_STATUS_NONE;
412 case CALENDAR_EVENT_STATUS_TENTATIVE:
413 eventStatus = EVENT_STATUS_TENTATIVE;
415 case CALENDAR_EVENT_STATUS_CONFIRMED:
416 eventStatus = EVENT_STATUS_CONFIRMED;
418 case CALENDAR_EVENT_STATUS_CANCELLED:
419 eventStatus = EVENT_STATUS_CANCELLED;
422 SysLog(NID_SCL, "The status value is invalid.");
423 return EVENT_STATUS_NONE;
430 _CalEventImpl::SetStatus(EventStatus status)
432 int errorCode = CALENDAR_ERROR_NONE;
433 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.event_status, _CalendarbookUtil::ConvertEventStatusToCSEventStatus(status));
437 _CalEventImpl::GetBusyStatus(void) const
439 int errorCode = CALENDAR_ERROR_NONE;
440 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
442 BusyStatus busyStatus = BUSY_STATUS_FREE;
444 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.busy_status, &srcEventBusyStatus);
446 switch (srcEventBusyStatus)
448 case CALENDAR_EVENT_BUSY_STATUS_FREE:
449 busyStatus = BUSY_STATUS_FREE;
451 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
452 busyStatus = BUSY_STATUS_BUSY;
454 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
455 busyStatus = BUSY_STATUS_UNAVAILABLE;
457 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
458 busyStatus = BUSY_STATUS_TENTATIVE;
461 SysLog(NID_SCL, "The busy status value is invalid.");
462 busyStatus = BUSY_STATUS_FREE;
470 _CalEventImpl::SetBusyStatus(BusyStatus busyStatus)
472 int errorCode = CALENDAR_ERROR_NONE;
473 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.busy_status, _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(busyStatus));
477 _CalEventImpl::GetPriority(void) const
479 int errorCode = CALENDAR_ERROR_NONE;
480 int srcPriority = CALENDAR_EVENT_PRIORITY_LOW;
482 EventPriority priority = EVENT_PRIORITY_NORMAL;
484 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.priority, &srcPriority);
488 case CALENDAR_EVENT_PRIORITY_LOW:
489 priority = EVENT_PRIORITY_LOW;
491 case CALENDAR_EVENT_PRIORITY_NONE:
493 case CALENDAR_EVENT_PRIORITY_NORMAL:
494 priority = EVENT_PRIORITY_NORMAL;
496 case CALENDAR_EVENT_PRIORITY_HIGH:
497 priority = EVENT_PRIORITY_HIGH;
500 SysLog(NID_SCL, "The priority value is invalid.");
501 priority = EVENT_PRIORITY_NORMAL;
508 _CalEventImpl::SetPriority(EventPriority priority)
510 int errorCode = CALENDAR_ERROR_NONE;
511 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.priority, _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(priority));
515 _CalEventImpl::AddAttendee(const Attendee& attendee)
517 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0)
519 SysTryReturnResult(NID_SCL, !attendee.GetEmail().IsEmpty(), E_OBJ_ALREADY_EXIST
520 , "The attendee's email string is empty.");
524 SysTryReturnResult(NID_SCL, !attendee.GetEmail().IsEmpty(), E_INVALID_ARG
525 , "The attendee's email string is empty.");
528 std::unique_ptr<char[]> pConvertedEmail(_StringConverter::CopyToCharArrayN(attendee.GetEmail()));
529 SysTryReturnResult(NID_SCL, pConvertedEmail != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
531 SysTryReturnResult(NID_SCL, GetAttendeeIndex(pConvertedEmail.get()) == _INVALID_ATTENDEE_INDEX, E_OBJ_ALREADY_EXIST
532 , "The specified attendee already exists as this email is already registered.");
534 int errorCode = CALENDAR_ERROR_NONE;
536 std::unique_ptr<char[]> pConvertedName(_StringConverter::CopyToCharArrayN(attendee.GetName()));
537 SysTryReturnResult(NID_SCL, pConvertedName != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
539 std::unique_ptr<char[]> pConvertedPhoneNumber(_StringConverter::CopyToCharArrayN(attendee.GetPhoneNumber()));
540 SysTryReturnResult(NID_SCL, pConvertedPhoneNumber != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
542 calendar_attendee_status_e convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
543 switch (attendee.GetStatus())
545 case ATTENDEE_STATUS_NONE:
546 convertedStatus = CALENDAR_ATTENDEE_STATUS_COMPLETED;
548 case ATTENDEE_STATUS_NOT_RESPONDED:
549 convertedStatus = CALENDAR_ATTENDEE_STATUS_PENDING;
551 case ATTENDEE_STATUS_ACCEPTED:
552 convertedStatus = CALENDAR_ATTENDEE_STATUS_ACCEPTED;
554 case ATTENDEE_STATUS_DECLINED:
555 convertedStatus = CALENDAR_ATTENDEE_STATUS_DECLINED;
557 case ATTENDEE_STATUS_TENTATIVE:
558 convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
561 SysLog(NID_SCL, "The attendee status value is invalid. attendee status = %d", attendee.GetStatus());
562 convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
566 calendar_attendee_role_e convertedRole = CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT;
567 switch (attendee.GetRole())
569 case ATTENDEE_ROLE_ATTENDEE:
570 convertedRole = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
572 case ATTENDEE_ROLE_REQUIRED_ATTENDEE:
573 convertedRole = CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT;
575 case ATTENDEE_ROLE_ORGANIZER:
576 convertedRole = CALENDAR_ATTENDEE_ROLE_CHAIR;
579 SysLog(NID_SCL, "The attendee role value is invalid. attendee role = %d", attendee.GetRole());
580 convertedRole = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
584 calendar_record_h attendeeHandle = null;
585 errorCode = calendar_record_create(_calendar_attendee._uri, &attendeeHandle);
586 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
588 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.name, pConvertedName.get());
589 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.email, pConvertedEmail.get());
590 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.number, pConvertedPhoneNumber.get());
591 errorCode = calendar_record_set_int(attendeeHandle, _calendar_attendee.status, convertedStatus);
592 errorCode = calendar_record_set_int(attendeeHandle, _calendar_attendee.role, convertedRole);
593 errorCode = calendar_record_set_int(attendeeHandle, _calendar_attendee.person_id, attendee.GetPersonId());
595 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, attendeeHandle);
601 _CalEventImpl::RemoveAttendee(const Attendee& attendee)
603 int errorCode = CALENDAR_ERROR_NONE;
604 int index = _INVALID_ATTENDEE_INDEX;
606 std::unique_ptr<char[]> pConvertedEmail(_StringConverter::CopyToCharArrayN(attendee.GetEmail()));
607 SysTryReturnResult(NID_SCL, pConvertedEmail != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
609 index = GetAttendeeIndex(pConvertedEmail.get());
610 SysTryReturnResult(NID_SCL, index != _INVALID_ATTENDEE_INDEX, E_OBJ_NOT_FOUND, "The specified attendee does not exist.")
612 calendar_record_h tmpAttendeeHandle = null;
613 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, index, &tmpAttendeeHandle);
614 errorCode = calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, tmpAttendeeHandle);
620 _CalEventImpl::GetAllAttendeesN(void) const
624 int errorCode = CALENDAR_ERROR_NONE;
626 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
627 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
628 result r = pList->Construct();
629 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
631 unsigned int attendeeCount = 0;
632 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
634 for (int i = 0; i < attendeeCount; i++)
636 calendar_record_h tmpAttendeeHandle = null;
637 char* pTmpEmail = null;
638 char* pTmpName = null;
639 char* pTmpPhoneNumber = null;
642 int tmpPersonId = -1;
643 AttendeeStatus attendeeStatus = ATTENDEE_STATUS_NONE;
644 AttendeeRole attendeeRole = ATTENDEE_ROLE_ATTENDEE;
646 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
647 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpEmail);
648 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.name, &pTmpName);
649 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.number, &pTmpPhoneNumber);
650 errorCode = calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.status, &tmpStatus);
651 errorCode = calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.role, &tmpRole);
652 errorCode = calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.person_id, &tmpPersonId);
656 case CALENDAR_ATTENDEE_STATUS_PENDING:
657 attendeeStatus = ATTENDEE_STATUS_NOT_RESPONDED;
659 case CALENDAR_ATTENDEE_STATUS_ACCEPTED:
660 attendeeStatus = ATTENDEE_STATUS_ACCEPTED;
662 case CALENDAR_ATTENDEE_STATUS_DECLINED:
663 attendeeStatus = ATTENDEE_STATUS_DECLINED;
665 case CALENDAR_ATTENDEE_STATUS_TENTATIVE:
666 attendeeStatus = ATTENDEE_STATUS_TENTATIVE;
668 case CALENDAR_ATTENDEE_STATUS_DELEGATED:
669 attendeeStatus = ATTENDEE_STATUS_NONE;
671 case CALENDAR_ATTENDEE_STATUS_COMPLETED:
672 attendeeStatus = ATTENDEE_STATUS_NONE;
674 case CALENDAR_ATTENDEE_STATUS_IN_PROCESS:
675 attendeeStatus = ATTENDEE_STATUS_NOT_RESPONDED;
678 SysLog(NID_SCL, "The attendee status value is invalid. attendee status = %d", tmpStatus);
679 attendeeStatus = ATTENDEE_STATUS_NONE;
685 case CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT:
686 attendeeRole = ATTENDEE_ROLE_REQUIRED_ATTENDEE;
688 case CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT:
689 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
691 case CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT:
692 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
694 case CALENDAR_ATTENDEE_ROLE_CHAIR:
695 attendeeRole = ATTENDEE_ROLE_ORGANIZER;
698 SysLog(NID_SCL, "The attendee role value is invalid. attendee role = %d", tmpRole);
699 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
703 Attendee* pTmpAttendee = new (std::nothrow) Attendee(pTmpEmail);
704 SysTryReturn(NID_SCL, pTmpAttendee != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
706 if (pTmpName != null && strlen(pTmpName) > 0)
708 pTmpAttendee->SetName(pTmpName);
711 if (pTmpPhoneNumber != null && strlen(pTmpPhoneNumber) > 0)
713 pTmpAttendee->SetPhoneNumber(pTmpPhoneNumber);
716 pTmpAttendee->SetStatus(attendeeStatus);
717 pTmpAttendee->SetRole(attendeeRole);
718 pTmpAttendee->SetPersonId(tmpPersonId);
720 pList->Add(*pTmpAttendee);
723 return pList.release();
726 Tizen::Locales::TimeZone
727 _CalEventImpl::GetTimeZone(void) const
729 int errorCode = CALENDAR_ERROR_NONE;
730 char* pTimeZoneId = null;
733 result r = E_SUCCESS;
734 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.start_tzid, &pTimeZoneId);
735 if (pTimeZoneId != null && strlen(pTimeZoneId) > 0)
737 r = TimeZone::GetTimeZone(pTimeZoneId, timeZone);
744 _CalEventImpl::SetTimeZone(const Tizen::Locales::TimeZone& timeZone)
746 int errorCode = CALENDAR_ERROR_NONE;
748 std::unique_ptr<char[]> pConvertedTimeZoneId(_StringConverter::CopyToCharArrayN(timeZone.GetId()));
749 SysTryReturnResult(NID_SCL, pConvertedTimeZoneId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
751 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.start_tzid, pConvertedTimeZoneId.get());
752 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.end_tzid, pConvertedTimeZoneId.get());
758 _CalEventImpl::GetRecurrenceId(void) const
761 SysTryReturn(NID_SCL, __isInstance, DateTime(), E_INVALID_STATE,
762 "[E_INVALID_STATE] The instance does not have a recurrence or is not a CalEvent instance which doesn't have a RecurrenceId.");
764 return GetStartTime();
768 _CalEventImpl::GetSubject(void) const
770 int errorCode = CALENDAR_ERROR_NONE;
771 char* pSubject = null;
773 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.summary, &pSubject);
775 return String(pSubject);
779 _CalEventImpl::GetDescription(void) const
781 int errorCode = CALENDAR_ERROR_NONE;
782 char* pDescription = null;
784 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.description, &pDescription);
786 return String(pDescription);
789 _CalEventImpl::GetStartTime(void) const
791 int errorCode = CALENDAR_ERROR_NONE;
792 calendar_time_s startCalendarTime;
793 DateTime tmpStartTime;
795 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
797 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
799 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
803 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
810 _CalEventImpl::GetEndTime(void) const
812 int errorCode = CALENDAR_ERROR_NONE;
813 calendar_time_s endCalendarTime;
816 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
818 if (endCalendarTime.type == CALENDAR_TIME_UTIME)
820 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
822 else if (endCalendarTime.type == CALENDAR_TIME_LOCALTIME)
824 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
831 _CalEventImpl::GetLocation(void) const
833 int errorCode = CALENDAR_ERROR_NONE;
834 char* pLocation = null;
836 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.location, &pLocation);
838 return String(pLocation);
842 _CalEventImpl::GetCategory(void) const
845 int errorCode = CALENDAR_ERROR_NONE;
846 char* pCategories = null;
848 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.categories, &pCategories);
850 return _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
854 _CalEventImpl::GetSensitivity(void) const
856 int errorCode = CALENDAR_ERROR_NONE;
857 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
858 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
860 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.sensitivity, &srcSensitivity);
862 switch (srcSensitivity)
864 case CALENDAR_SENSITIVITY_PUBLIC:
865 sensitivity = SENSITIVITY_PUBLIC;
867 case CALENDAR_SENSITIVITY_PRIVATE:
868 sensitivity = SENSITIVITY_PRIVATE;
870 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
871 sensitivity = SENSITIVITY_CONFIDENTIAL;
874 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
875 sensitivity = SENSITIVITY_PUBLIC;
882 _CalEventImpl::GetReminder(void) const
884 if (__reminderListUpdated == false)
886 result r = _CalendarbookUtil::ConvertEventAlarmsToReminderList(__eventRecord.GetHandle(), __reminderList);
887 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
889 __reminderListUpdated = true;
892 if (__reminderList.GetCount() > 0)
894 return static_cast<const Reminder*>(__reminderList.GetAt(0));
901 _CalEventImpl::GetRecurrence(void) const
903 if (__pRecurrence == null)
905 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
908 return __pRecurrence.get();
912 _CalEventImpl::ConvertEventHandleToRecurrenceN(calendar_record_h eventHandle) const
914 int errorCode = CALENDAR_ERROR_NONE;
915 int srcFrequency = CALENDAR_RECURRENCE_NONE;
916 calendar_time_s untilCalendarTime;
917 int rangeType = CALENDAR_RANGE_NONE;
921 char* pByMonthDay = null;
922 char* pByMonth = null;
924 char* pExDates = null;
926 result r = E_SUCCESS;
931 CalDayOfWeek convertedWeekStart = CAL_SUNDAY;
933 std::unique_ptr<Recurrence> pRecurrence(new (std::nothrow) Recurrence());
935 errorCode = calendar_record_get_int(eventHandle, _calendar_event.freq, &srcFrequency);
937 if (srcFrequency == CALENDAR_RECURRENCE_NONE)
942 errorCode = calendar_record_get_int(eventHandle, _calendar_event.range_type, &rangeType);
943 errorCode = calendar_record_get_int(eventHandle, _calendar_event.count, &count);
944 errorCode = calendar_record_get_int(eventHandle, _calendar_event.interval, &interval);
945 errorCode = calendar_record_get_caltime(eventHandle, _calendar_event.until_time, &untilCalendarTime);
946 errorCode = calendar_record_get_int(eventHandle, _calendar_event.wkst, &weekStart);
948 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.byday, &pByDay);
949 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.bymonthday, &pByMonthDay);
950 if (pByMonthDay != null)
952 r = Integer::Parse(pByMonthDay, dayOfMonth);
953 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
955 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.bymonth, &pByMonth);
956 if (pByMonth != null)
958 r = Integer::Parse(pByMonth, monthOfYear);
959 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
962 switch (srcFrequency)
964 case CALENDAR_RECURRENCE_DAILY:
965 pRecurrence->SetFrequency(FREQ_DAILY);
967 case CALENDAR_RECURRENCE_WEEKLY:
968 pRecurrence->SetFrequency(FREQ_WEEKLY);
970 dayOfWeek = ConvertRRuleByDayStringToDayOfWeek(pByDay);
971 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %s", pByDay);
973 r = pRecurrence->SetDayOfWeek(dayOfWeek);
976 case CALENDAR_RECURRENCE_MONTHLY:
977 pRecurrence->SetFrequency(FREQ_MONTHLY);
983 int maxDaysOfMonth = _CalendarbookUtil::GetMaxDaysOfMonth(untilCalendarTime.time.date.year, monthOfYear);
984 r = pRecurrence->SetDayOfMonth(maxDaysOfMonth + dayOfMonth);
988 r = pRecurrence->SetDayOfMonth(dayOfMonth);
993 r = ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(pByDay, weekOfMonth, dayOfWeek);
994 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %s", pByDay);
996 r = pRecurrence->SetWeekOfMonth(weekOfMonth);
997 r = pRecurrence->SetDayOfWeek(dayOfWeek);
1001 case CALENDAR_RECURRENCE_YEARLY:
1002 pRecurrence->SetFrequency(FREQ_YEARLY);
1004 if (dayOfMonth != 0)
1008 int maxDaysOfMonth = _CalendarbookUtil::GetMaxDaysOfMonth(untilCalendarTime.time.date.year, monthOfYear);
1009 r = pRecurrence->SetDayOfMonth(maxDaysOfMonth + dayOfMonth);
1013 r = pRecurrence->SetDayOfMonth(dayOfMonth);
1018 r = ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(pByDay, weekOfMonth, dayOfWeek);
1019 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %s", pByDay);
1021 r = pRecurrence->SetWeekOfMonth(weekOfMonth);
1022 r = pRecurrence->SetDayOfWeek(dayOfWeek);
1024 r = pRecurrence->SetMonthOfYear(monthOfYear);
1028 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. frequency = %d", srcFrequency);
1032 if (rangeType == CALENDAR_RANGE_NONE)
1034 r = pRecurrence->SetUntil(&DateTime::GetMaxValue());
1036 else if (rangeType == CALENDAR_RANGE_UNTIL)
1040 if (untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1042 until.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
1046 until = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
1049 r = pRecurrence->SetUntil(&until);
1053 r = pRecurrence->SetCounts(count);
1055 r = pRecurrence->SetInterval(interval);
1059 case CALENDAR_SUNDAY:
1060 convertedWeekStart = CAL_SUNDAY;
1062 case CALENDAR_MONDAY:
1063 convertedWeekStart = CAL_MONDAY;
1066 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. week start = %d", weekStart);
1069 r = pRecurrence->SetWeekStart(convertedWeekStart);
1071 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExDates);
1072 if (pExDates != null && strlen(pExDates) != 0)
1074 r = ConvertRRuleExDateStringToRecurrence(pExDates, *pRecurrence.get());
1075 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. exdate = %s", pExDates);
1078 return pRecurrence.release();
1082 _CalEventImpl::GetLastRevisedTime(void) const
1084 int errorCode = CALENDAR_ERROR_NONE;
1085 long long lastModifiedTime = 0;
1086 DateTime tmpLastRevisedTime;
1088 errorCode = calendar_record_get_lli(__eventRecord.GetHandle(), _calendar_event.last_modified_time, &lastModifiedTime);
1090 tmpLastRevisedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(lastModifiedTime);
1092 return tmpLastRevisedTime;
1096 _CalEventImpl::SetSubject(const String& subject)
1098 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1100 SysTryReturnResult(NID_SCL, subject.GetLength() <= MAX_EVENT_SUBJECT_LENGTH, E_INVALID_ARG
1101 , "The length of the value exceeds MAX_EVENT_SUBJECT_LENGTH.");
1104 std::unique_ptr<char[]> pConvertedSubject(_StringConverter::CopyToCharArrayN(subject));
1105 SysTryReturnResult(NID_SCL, pConvertedSubject != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1107 int errorCode = CALENDAR_ERROR_NONE;
1108 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.summary, pConvertedSubject.get());
1114 _CalEventImpl::SetDescription(const String& description)
1116 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1118 SysTryReturnResult(NID_SCL, description.GetLength() <= MAX_EVENT_DESCRIPTION_LENGTH, E_INVALID_ARG
1119 , "The length of the value exceeds MAX_EVENT_DESCRIPTION_LENGTH.");
1122 std::unique_ptr<char[]> pConvertedDescription(_StringConverter::CopyToCharArrayN(description));
1123 SysTryReturnResult(NID_SCL, pConvertedDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1125 int errorCode = CALENDAR_ERROR_NONE;
1126 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.description, pConvertedDescription.get());
1132 _CalEventImpl::SetLocation(const String& location)
1134 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1136 SysTryReturnResult(NID_SCL, location.GetLength() <= MAX_EVENT_LOCATION_LENGTH, E_INVALID_ARG
1137 , "The length of the value exceeds MAX_EVENT_LOCATION_LENGTH.");
1140 std::unique_ptr<char[]> pConvertedLocation(_StringConverter::CopyToCharArrayN(location));
1141 SysTryReturnResult(NID_SCL, pConvertedLocation != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1143 int errorCode = CALENDAR_ERROR_NONE;
1144 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.location, pConvertedLocation.get());
1150 _CalEventImpl::SetStartAndEndTime(const DateTime& start, const DateTime& end)
1152 int errorCode = CALENDAR_ERROR_NONE;
1153 int recurrenceFrequency = 0;
1155 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFrequency);
1157 SysTryReturnResult(NID_SCL, recurrenceFrequency == CALENDAR_RECURRENCE_NONE, E_INVALID_CONDITION
1158 , "The recurrence date is already set. Cannot modify the start and end date/time.");
1159 SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, "Invalid argument is used. start = %S", start.ToString().GetPointer());
1160 SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, "Invalid argument is used. end = %S", end.ToString().GetPointer());
1161 SysTryReturnResult(NID_SCL, start <= end, E_INVALID_ARG, "Invalid argument is used. The end date is earlier than the start date.");
1163 return SetStartAndEndTimeCommon(start, end);
1167 _CalEventImpl::SetStartAndEndTimeCommon(const DateTime& start, const DateTime& end)
1169 int errorCode = CALENDAR_ERROR_NONE;
1170 calendar_time_s startCalendarTime;
1171 calendar_time_s endCalendarTime;
1173 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
1175 if (startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1177 startCalendarTime.time.date.year = start.GetYear();
1178 startCalendarTime.time.date.month = start.GetMonth();
1179 startCalendarTime.time.date.mday = start.GetDay();
1181 endCalendarTime.type = CALENDAR_TIME_LOCALTIME;
1182 endCalendarTime.time.date.year = end.GetYear();
1183 endCalendarTime.time.date.month = end.GetMonth();
1184 endCalendarTime.time.date.mday = end.GetDay();
1188 startCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(start);
1190 endCalendarTime.type = CALENDAR_TIME_UTIME;
1191 endCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(end);
1194 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, startCalendarTime);
1195 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, endCalendarTime);
1201 _CalEventImpl::SetCategory(EventCategory category)
1203 int errorCode = CALENDAR_ERROR_NONE;
1204 std::unique_ptr<char[]> pConvertedCategory;
1206 if (category == EVENT_CATEGORY_ANNIVERSARY)
1208 SetAllDayEvent(true);
1210 pConvertedCategory.reset(_StringConverter::CopyToCharArrayN(_EVENT_CATEGORY_ANNIVERSARY_STRING));
1211 SysTryReturnVoidResult(NID_SCL, pConvertedCategory != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1215 pConvertedCategory.reset(_StringConverter::CopyToCharArrayN(_EVENT_CATEGORY_APPOINTMENT_STRING));
1216 SysTryReturnVoidResult(NID_SCL, pConvertedCategory != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1219 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.categories, pConvertedCategory.get());
1223 _CalEventImpl::SetSensitivity(RecordSensitivity sensitivity)
1225 int errorCode = CALENDAR_ERROR_NONE;
1226 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.sensitivity, _CalendarbookUtil::ConvertSensitivityToCSSensitivity(sensitivity));
1230 _CalEventImpl::SetCoordinates(double latitude, double longitude)
1232 SysTryReturnResult(NID_SCL, latitude >= _MIN_LATITUDE && latitude <= _MAX_LATITUDE, E_INVALID_ARG, "Invalid argument is used. The latitude is out of range.");
1233 SysTryReturnResult(NID_SCL, longitude >= _MIN_LONGITUDE && longitude <= _MAX_LONGITUDE, E_INVALID_ARG, "Invalid argument is used. The longitude is out of range.");
1235 int errorCode = CALENDAR_ERROR_NONE;
1237 errorCode = calendar_record_set_double(__eventRecord.GetHandle(), _calendar_event.latitude, latitude);
1238 errorCode = calendar_record_set_double(__eventRecord.GetHandle(), _calendar_event.longitude, longitude);
1244 _CalEventImpl::GetCoordinates(double& latitude, double& longitude) const
1246 int errorCode = CALENDAR_ERROR_NONE;
1248 errorCode = calendar_record_get_double(__eventRecord.GetHandle(), _calendar_event.latitude, &latitude);
1249 errorCode = calendar_record_get_double(__eventRecord.GetHandle(), _calendar_event.longitude, &longitude);
1253 _CalEventImpl::SetReminder(const Reminder* pReminder)
1255 int errorCode = CALENDAR_ERROR_NONE;
1257 unsigned int reminderCount = 0;
1258 calendar_record_h tmpAlarmHandle = null;
1260 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, &reminderCount);
1262 if (pReminder != null)
1264 int convertedTimeUnit = 0;
1265 switch (pReminder->GetTimeUnit())
1267 case REMINDER_TIME_UNIT_MINUTE:
1268 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1270 case REMINDER_TIME_UNIT_HOUR:
1271 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
1273 case REMINDER_TIME_UNIT_DAY:
1274 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
1276 case REMINDER_TIME_UNIT_WEEK:
1277 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
1283 calendar_record_h tmpAlarmHandle = null;
1285 if (reminderCount > 0)
1287 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, 0, &tmpAlarmHandle);
1288 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1289 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, pReminder->GetTimeOffset());
1291 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(pReminder->GetSoundFile()));
1292 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1294 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1298 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(pReminder->GetSoundFile()));
1299 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1301 errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
1302 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1304 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1305 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, pReminder->GetTimeOffset());
1306 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1308 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1313 if (reminderCount > 0)
1315 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, 0, &tmpAlarmHandle);
1316 errorCode = calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1320 __reminderList.RemoveAll(true);
1321 __reminderListUpdated = false;
1327 _CalEventImpl::SetRecurrence(const Recurrence* pRecurrence)
1329 result r = E_SUCCESS;
1330 int errorCode = CALENDAR_ERROR_NONE;
1332 if (pRecurrence != null)
1334 r = VerifyRecurrence(*pRecurrence);
1335 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1337 r = ResetStartAndEndTimeByRecurrence(*pRecurrence);
1338 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1340 r = ConvertRecurrenceToEventHandle(*pRecurrence, __eventRecord.GetHandle());
1341 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1343 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*pRecurrence, IsAllDayEvent())));
1344 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
1346 __pRecurrence.reset(new (std::nothrow) Recurrence(*pRecurrence));
1347 SysTryReturnResult(NID_SCL, __pRecurrence != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1351 int errorCode = CALENDAR_ERROR_NONE;
1352 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.freq, CALENDAR_RECURRENCE_NONE);
1354 __pRecurrence.reset(null);
1361 _CalEventImpl::AddReminder(const Reminder& reminder)
1363 int errorCode = CALENDAR_ERROR_NONE;
1364 calendar_record_h tmpAlarmHandle = null;
1366 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(reminder.GetSoundFile()));
1367 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1369 errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
1370 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1372 int convertedTimeUnit = 0;
1374 ReminderTimeUnit timeUnit = reminder.GetTimeUnit();
1377 case REMINDER_TIME_UNIT_MINUTE:
1378 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1380 case REMINDER_TIME_UNIT_HOUR:
1381 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
1383 case REMINDER_TIME_UNIT_DAY:
1384 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
1386 case REMINDER_TIME_UNIT_WEEK:
1387 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
1389 case REMINDER_TIME_UNIT_NONE:
1390 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
1396 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1397 errorCode = calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, reminder.GetTimeOffset());
1398 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1400 if (convertedTimeUnit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
1402 errorCode = calendar_record_set_lli(tmpAlarmHandle, _calendar_alarm.time, _CalendarbookUtil::ConvertDateTimeToEpochTime(reminder.GetAbsoluteTime()));
1405 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1407 __reminderList.RemoveAll(true);
1408 __reminderListUpdated = false;
1414 _CalEventImpl::RemoveReminderAt(int index)
1416 int errorCode = CALENDAR_ERROR_NONE;
1417 calendar_record_h tmpAlarmHandle = null;
1419 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, index, &tmpAlarmHandle);
1420 SysTryReturnResult(NID_SCL, tmpAlarmHandle != null, E_OUT_OF_RANGE, "The index is out of range. index = %d", index);
1422 errorCode = calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1424 __reminderList.RemoveAll(true);
1425 __reminderListUpdated = false;
1431 _CalEventImpl::GetAllReminders(void) const
1435 if (__reminderListUpdated == false)
1437 result r = _CalendarbookUtil::ConvertEventAlarmsToReminderList(__eventRecord.GetHandle(), __reminderList);
1438 SysTryReturn(NID_SCL, r == E_SUCCESS, __reminderList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1440 __reminderListUpdated = true;
1443 return __reminderList;
1447 _CalEventImpl::ConvertRecurrenceToEventHandle(const Recurrence& recurrence, calendar_record_h eventHandle) const
1449 result r = E_SUCCESS;
1451 int errorCode = CALENDAR_ERROR_NONE;
1452 int weekStart = CALENDAR_SUNDAY;
1453 std::unique_ptr<char[]> pByDay;
1454 std::unique_ptr<char[]> pByMonth;
1455 std::unique_ptr<char[]> pByMonthDay;
1458 String dayOfWeekString;
1459 String exDateString;
1461 switch (recurrence.GetWeekStart())
1464 weekStart = CALENDAR_SUNDAY;
1467 weekStart = CALENDAR_MONDAY;
1470 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. week start = %d", recurrence.GetWeekStart());
1471 return E_INVALID_ARG;
1473 errorCode = calendar_record_set_int(eventHandle, _calendar_event.wkst, weekStart);
1474 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_INVALID_ARG, "Invalid argument is passed. week start = %d", weekStart);
1476 if (recurrence.GetUntil() != null)
1478 if (*recurrence.GetUntil() == DateTime::GetMaxValue())
1480 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_NONE);
1484 calendar_time_s startCalendarTime;
1485 calendar_time_s untilCalendarTime;
1487 errorCode = calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &startCalendarTime);
1488 if (startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1490 untilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
1491 untilCalendarTime.time.date.year = recurrence.GetUntil()->GetYear();
1492 untilCalendarTime.time.date.month = recurrence.GetUntil()->GetMonth();
1493 untilCalendarTime.time.date.mday = recurrence.GetUntil()->GetDay();
1497 untilCalendarTime.type = CALENDAR_TIME_UTIME;
1498 untilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(*recurrence.GetUntil());
1501 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
1502 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.until_time, untilCalendarTime);
1507 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
1508 errorCode = calendar_record_set_int(eventHandle, _calendar_event.count, recurrence.GetCounts());
1511 errorCode = calendar_record_set_int(eventHandle, _calendar_event.interval, recurrence.GetInterval());
1513 switch (recurrence.GetFrequency())
1516 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_DAILY);
1519 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_WEEKLY);
1521 dayOfWeek = recurrence.GetDayOfWeek();
1522 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, 0, dayOfWeekString);
1523 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1525 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
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())));
1537 dayOfWeek = recurrence.GetDayOfWeek();
1538 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1539 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1541 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1546 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY);
1548 pByMonth.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetMonthOfYear())));
1550 if (recurrence.GetDayOfMonth() != 0)
1552 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1556 dayOfWeek = recurrence.GetDayOfWeek();
1557 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1558 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1560 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1565 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. frequency = %d", recurrence.GetFrequency());
1566 return E_INVALID_ARG;
1569 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, pByDay.get());
1570 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, pByMonth.get());
1571 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, pByMonthDay.get());
1577 _CalEventImpl::ConvertDayOfWeekToRRuleByDayString(int dayOfWeek, int weekOfMonth, String& byDayString) const
1579 int tmpDayOfWeek = CAL_SUNDAY;
1581 byDayString.Clear();
1582 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
1584 if (dayOfWeek & tmpDayOfWeek)
1586 if (weekOfMonth != 0)
1588 byDayString.Append(weekOfMonth);
1591 switch (tmpDayOfWeek)
1594 byDayString.Append(_RECURRENCE_KEYWORD_SUNDAY);
1597 byDayString.Append(_RECURRENCE_KEYWORD_MONDAY);
1600 byDayString.Append(_RECURRENCE_KEYWORD_TUESDAY);
1603 byDayString.Append(_RECURRENCE_KEYWORD_WEDNESDAY);
1606 byDayString.Append(_RECURRENCE_KEYWORD_THURSDAY);
1609 byDayString.Append(_RECURRENCE_KEYWORD_FRIDAY);
1612 byDayString.Append(_RECURRENCE_KEYWORD_SATURDAY);
1615 byDayString.Append(_RECURRENCE_DELIMITER);
1621 byDayString.Remove(byDayString.GetLength() - 1, _RECURRENCE_DELIMITER_LENGTH);
1627 _CalEventImpl::GetCalendarId(void) const
1629 int errorCode = CALENDAR_ERROR_NONE;
1630 int srcCalendarbookId = 0;
1632 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.calendar_book_id, &srcCalendarbookId);
1634 return srcCalendarbookId;
1638 _CalEventImpl::GetBaseEventId(void) const
1640 int errorCode = CALENDAR_ERROR_NONE;
1641 int srcBaseEventId = INVALID_RECORD_ID;
1643 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.original_event_id, &srcBaseEventId);
1645 return srcBaseEventId;
1649 _CalEventImpl::SetOriginalCalEventId(RecordId originalEventId)
1651 __originalEventId = originalEventId;
1652 __isInstance = true;
1656 _CalEventImpl::GetAttendeeIndex(const char* pAttendeeEmail)
1658 int index = _INVALID_ATTENDEE_INDEX;
1659 unsigned int attendeeCount = 0;
1661 int errorCode = CALENDAR_ERROR_NONE;
1662 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
1664 calendar_record_h tmpAttendeeHandle = null;
1665 char* pTmpAttendeeEmail = null;
1666 for (int i = 0; i < attendeeCount; i++)
1668 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
1669 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpAttendeeEmail);
1671 if (strcmp(pAttendeeEmail, pTmpAttendeeEmail) == 0)
1682 _CalEventImpl::VerifyRecurrence(const Recurrence& recurrence)
1684 const DateTime* pUntil = recurrence.GetUntil();
1685 RecurFrequency frequency = recurrence.GetFrequency();
1686 int durationLimit = 0;
1687 int interval = recurrence.GetInterval();
1689 DateTime startTime = GetStartTime();
1690 DateTime endTime = GetEndTime();
1691 EventCategory category = GetCategory();
1695 SysTryReturnResult(NID_SCL, startTime <= *pUntil, E_INVALID_CONDITION, "The until date of recurrence is earlier than start date.");
1698 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1700 if (category == EVENT_CATEGORY_ANNIVERSARY)
1702 SysTryReturnResult(NID_SCL, frequency == FREQ_YEARLY, E_TYPE_MISMATCH
1703 , "The recurrence pattern is not a yearly pattern in case of the event being an Anniversary.");
1707 if (frequency == FREQ_DAILY)
1709 durationLimit = _TERM_LIMIT_DAILY * interval;
1711 else if (frequency == FREQ_WEEKLY)
1713 SysTryReturnResult(NID_SCL, recurrence.GetDayOfWeek() != 0, E_INVALID_ARG, "Invalid argument is used. The day of week is not set.");
1714 durationLimit = _TERM_LIMIT_WEEKLY * interval;
1716 else if (frequency == FREQ_MONTHLY)
1718 SysTryReturnResult(NID_SCL, recurrence.GetDayOfMonth() != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1719 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1720 durationLimit = _TERM_LIMIT_MONTHLY * interval;
1722 else if (frequency == FREQ_YEARLY)
1724 int dayOfMonth = recurrence.GetDayOfMonth();
1725 int monthOfYear = recurrence.GetMonthOfYear();
1726 SysTryReturnResult(NID_SCL, monthOfYear != 0, E_INVALID_ARG, "Invalid argument is used. The month of year is not set.");
1727 SysTryReturnResult(NID_SCL, dayOfMonth != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1728 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1730 SysTryReturnResult(NID_SCL, monthOfYear != 2 || dayOfMonth < 30
1731 , E_INVALID_ARG, "Invalid argument is used. If the frequency is yearly, the max days of the February is less than 30.");
1732 if (dayOfMonth > 30)
1734 SysTryReturnResult(NID_SCL, monthOfYear != 4 && monthOfYear != 6 && monthOfYear != 9 && monthOfYear != 11
1735 , 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.");
1738 durationLimit = _TERM_LIMIT_YEARLY * interval;
1741 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1742 SysTryReturnResult(NID_SCL, duration.GetDays() <= durationLimit, E_INVALID_CONDITION
1743 , "The duration of the event is greater than (interval x frequency) days. duration days = %d", duration.GetDays());
1749 _CalEventImpl::ResetStartAndEndTimeByRecurrence(const Recurrence& recurrence)
1751 result r = E_SUCCESS;
1755 bool isAllDay = IsAllDayEvent();
1756 Locales::TimeZone timeZone;
1760 timeZone = GetTimeZone();
1761 startTime = timeZone.UtcTimeToWallTime(GetStartTime());
1762 endTime = timeZone.UtcTimeToWallTime(GetEndTime());
1766 startTime = GetStartTime();
1767 endTime = GetEndTime();
1770 DateTime calculatedStartTime(startTime);
1771 DateTime calculatedEndTime(endTime);
1772 RecurFrequency frequency = recurrence.GetFrequency();
1773 int interval = recurrence.GetInterval();
1774 int dayOfMonth = recurrence.GetDayOfMonth();
1775 int dayOfWeek = recurrence.GetDayOfWeek();
1776 int weekOfMonth = recurrence.GetWeekOfMonth();
1777 int monthOfYear = recurrence.GetMonthOfYear();
1778 CalDayOfWeek weekStart = recurrence.GetWeekStart();
1779 CalDayOfWeek weekEnd = CAL_SATURDAY;
1781 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1783 if (weekStart == CAL_MONDAY)
1785 weekEnd = CAL_SUNDAY;
1788 if (recurrence.GetUntil() != null)
1790 until = *(recurrence.GetUntil());
1793 until = timeZone.UtcTimeToWallTime(until);
1798 until = _CalendarbookImpl::GetMaxDateTime();
1801 CalDayOfWeek dayOfStartTime = GetDayOfWeek(startTime, timeZone);
1803 if (frequency == FREQ_WEEKLY)
1807 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
1809 if ((dayOfStartTime & dayOfWeek) != 0)
1814 if ((dayOfStartTime & weekEnd) != 0)
1816 count += (interval - 1) * _NUMBER_OF_DAYS_OF_WEEK;
1819 dayOfStartTime = GetNextDayOfWeek(dayOfStartTime);
1823 r = calculatedStartTime.AddDays(count);
1824 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1825 r = calculatedEndTime.AddDays(count);
1826 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1829 else if (frequency == FREQ_MONTHLY)
1831 if (dayOfMonth != 0)
1833 bool isDone = false;
1834 while (calculatedStartTime <= until)
1836 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1838 if (calculatedStartTime >= startTime)
1844 calculatedStartTime.AddMonths(interval);
1846 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1847 calculatedEndTime = calculatedStartTime;
1848 calculatedEndTime.Add(duration);
1852 bool isDone = false;
1854 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1855 while (calculatedStartTime <= until)
1857 for (int i = 0; i < dayCount; i++)
1859 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1860 if (calculatedStartTime >= startTime)
1865 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1871 calculatedStartTime.AddMonths(interval);
1874 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1875 calculatedEndTime = calculatedStartTime;
1876 calculatedEndTime.Add(duration);
1879 else if (frequency == FREQ_YEARLY)
1881 if (dayOfMonth != 0)
1883 bool isDone = false;
1884 while (calculatedStartTime <= until)
1886 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), monthOfYear, dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1888 if (calculatedStartTime >= startTime)
1894 calculatedStartTime.AddYears(interval);
1896 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1897 calculatedEndTime = calculatedStartTime;
1898 calculatedEndTime.Add(duration);
1902 bool isDone = false;
1904 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1905 while (calculatedStartTime <= until)
1907 for (int i = 0; i < dayCount; i++)
1909 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), monthOfYear, weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1910 if (calculatedStartTime >= startTime)
1915 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1921 calculatedStartTime.AddYears(interval);
1924 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1925 calculatedEndTime = calculatedStartTime;
1926 calculatedEndTime.Add(duration);
1932 calculatedStartTime = timeZone.WallTimeToUtcTime(calculatedStartTime);
1933 calculatedEndTime = timeZone.WallTimeToUtcTime(calculatedEndTime);
1936 SysTryReturnResult(NID_SCL, calculatedStartTime <= until, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1937 SysTryReturnResult(NID_SCL, calculatedEndTime <= _CalendarbookImpl::GetMaxDateTime(), E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1939 SysLog(NID_SCL, "Reset start time : %S", calculatedStartTime.ToString().GetPointer());
1940 SetStartAndEndTimeCommon(calculatedStartTime, calculatedEndTime);
1946 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeek(const String& byDay) const
1948 result r = E_SUCCESS;
1952 SysTryReturn(NID_SCL, !byDay.IsEmpty(), 0, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The byDay is empty.");
1954 String delim(_RECURRENCE_DELIMITER);
1957 StringTokenizer strTok(byDay, delim);
1958 while (strTok.HasMoreTokens())
1960 r = strTok.GetNextToken(token);
1961 SysTryReturn(NID_SCL, r == E_SUCCESS, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1963 if (token == String(_RECURRENCE_KEYWORD_SUNDAY))
1965 dayOfWeek |= CAL_SUNDAY;
1967 else if (token == String(_RECURRENCE_KEYWORD_MONDAY))
1969 dayOfWeek |= CAL_MONDAY;
1971 else if (token == String(_RECURRENCE_KEYWORD_TUESDAY))
1973 dayOfWeek |= CAL_TUESDAY;
1975 else if (token == String(_RECURRENCE_KEYWORD_WEDNESDAY))
1977 dayOfWeek |= CAL_WEDNESDAY;
1979 else if (token == String(_RECURRENCE_KEYWORD_THURSDAY))
1981 dayOfWeek |= CAL_THURSDAY;
1983 else if (token == String(_RECURRENCE_KEYWORD_FRIDAY))
1985 dayOfWeek |= CAL_FRIDAY;
1987 else if (token == String(_RECURRENCE_KEYWORD_SATURDAY))
1989 dayOfWeek |= CAL_SATURDAY;
1993 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %S", byDay.GetPointer());
2002 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(const String& byDay, int& weekOfMonth, int& dayOfWeek) const
2004 result r = E_SUCCESS;
2005 String delim(_RECURRENCE_DELIMITER);
2007 wchar_t tmpChar = 0;
2008 int tmpWeekOfMonth = 0;
2009 int weekStringStartIndex = 0;
2015 SysTryReturnResult(NID_SCL, !byDay.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The byDay is empty.");
2017 StringTokenizer strTok(byDay, delim);
2019 while (strTok.HasMoreTokens())
2021 r = strTok.GetNextToken(token);
2022 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2024 r = token.GetCharAt(_RECURRENCE_BY_DAY_FIRST_INDEX, tmpChar);
2025 if (tmpChar == _RECURRENCE_BY_DAY_CHAR_MINUS)
2027 SysTryReturnResult(NID_SCL, weekOfMonth == 0 || weekOfMonth == _MAX_WEEK_OF_MONTH
2028 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2030 if (weekOfMonth == 0)
2033 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2034 SysTryReturnResult(NID_SCL, tmpChar == _RECURRENCE_BY_DAY_CHAR_ONE
2035 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2037 weekOfMonth = _MAX_WEEK_OF_MONTH;
2039 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2041 else if (tmpChar == _RECURRENCE_BY_DAY_CHAR_PLUS)
2043 if (weekOfMonth == 0)
2046 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2047 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2048 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_MONTH
2049 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2051 weekOfMonth = tmpWeekOfMonth;
2055 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2056 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2059 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2063 if (weekOfMonth == 0)
2065 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2066 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_MONTH
2067 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2069 weekOfMonth = tmpWeekOfMonth;
2073 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2074 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2077 weekStringStartIndex = _RECURRENCE_BY_DAY_FIRST_INDEX + 1;
2080 token.SubString(weekStringStartIndex, tmpString);
2082 if (tmpString == String(_RECURRENCE_KEYWORD_SUNDAY))
2084 dayOfWeek |= CAL_SUNDAY;
2086 else if (tmpString == String(_RECURRENCE_KEYWORD_MONDAY))
2088 dayOfWeek |= CAL_MONDAY;
2090 else if (tmpString == String(_RECURRENCE_KEYWORD_TUESDAY))
2092 dayOfWeek |= CAL_TUESDAY;
2094 else if (tmpString == String(_RECURRENCE_KEYWORD_WEDNESDAY))
2096 dayOfWeek |= CAL_WEDNESDAY;
2098 else if (tmpString == String(_RECURRENCE_KEYWORD_THURSDAY))
2100 dayOfWeek |= CAL_THURSDAY;
2102 else if (tmpString == String(_RECURRENCE_KEYWORD_FRIDAY))
2104 dayOfWeek |= CAL_FRIDAY;
2106 else if (tmpString == String(_RECURRENCE_KEYWORD_SATURDAY))
2108 dayOfWeek |= CAL_SATURDAY;
2112 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %S", byDay.GetPointer());
2120 _CalEventImpl::ConvertRRuleExDateStringToRecurrence(const String& exdate, Recurrence& recurrence) const
2122 result r = E_SUCCESS;
2124 String delim(_RECURRENCE_DELIMITER);
2126 DateTime tmpDateTime;
2127 TimeZone tmpTimeZone;
2128 TimeZone utcTimeZone = TimeZone::GetGmtTimeZone();
2129 bool isDate = false;
2131 SysTryReturnResult(NID_SCL, !exdate.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The exdate is empty.");
2133 StringTokenizer strTok(exdate, delim);
2134 while (strTok.HasMoreTokens())
2136 r = strTok.GetNextToken(token);
2137 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2139 r = _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(token, tmpDateTime, tmpTimeZone, isDate);
2140 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. exdate = %S", exdate.GetPointer());
2142 if (!isDate && tmpTimeZone != utcTimeZone)
2144 tmpDateTime = tmpTimeZone.WallTimeToUtcTime(tmpDateTime);
2147 r = recurrence.AddExceptionDate(tmpDateTime);
2148 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. exdate = %S", exdate.GetPointer());
2155 _CalEventImpl::ConvertRecurrenceToRRuleExDateString(const Recurrence& recurrence, bool isDate) const
2157 result r = E_SUCCESS;
2159 bool isNotFirst = false;
2160 String exdateString;
2162 std::unique_ptr<IList, AllElementsDeleter> pExDateList(recurrence.GetExceptionDatesN());
2164 IEnumerator* pEnum = pExDateList->GetEnumeratorN();
2165 while (pEnum->MoveNext() == E_SUCCESS)
2167 DateTime* pDateTime = static_cast<DateTime*>(pEnum->GetCurrent());
2171 r = exdateString.Append(_RECURRENCE_DELIMITER);
2174 r = exdateString.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(*pDateTime, isDate));
2180 return exdateString;
2184 _CalEventImpl::GetNextDayOfWeek(CalDayOfWeek currentDay)
2186 int tmpDay = currentDay;
2189 if (tmpDay > CAL_SATURDAY)
2191 tmpDay = CAL_SUNDAY;
2194 return static_cast<CalDayOfWeek>(tmpDay);
2198 _CalEventImpl::GetDate(int year, int month, int weekOfMonth, CalDayOfWeek dayOfWeek, const DateTime& time, const Locales::TimeZone& timeZone)
2200 Tizen::Locales::DayOfWeek dayOfWeekByGregorianCalendar = Tizen::Locales::DAY_OF_WEEK_UNDEFINED;
2205 dayOfWeekByGregorianCalendar = Tizen::Locales::SUNDAY;
2208 dayOfWeekByGregorianCalendar = Tizen::Locales::MONDAY;
2211 dayOfWeekByGregorianCalendar = Tizen::Locales::TUESDAY;
2214 dayOfWeekByGregorianCalendar = Tizen::Locales::WEDNESDAY;
2217 dayOfWeekByGregorianCalendar = Tizen::Locales::THURSDAY;
2220 dayOfWeekByGregorianCalendar = Tizen::Locales::FRIDAY;
2223 dayOfWeekByGregorianCalendar = Tizen::Locales::SATURDAY;
2229 Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN);
2231 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
2232 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
2233 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH, 1);
2235 Tizen::Locales::DayOfWeek tmpDayOfWeek = static_cast<Tizen::Locales::DayOfWeek>(pGregorianCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK));
2236 int maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(TIME_FIELD_DAY_OF_MONTH);
2237 int tmpDayOfMonth = ((_NUMBER_OF_DAYS_OF_WEEK + dayOfWeekByGregorianCalendar) - tmpDayOfWeek) % _NUMBER_OF_DAYS_OF_WEEK + 1;
2239 tmpDayOfMonth += ((weekOfMonth - 1) * _NUMBER_OF_DAYS_OF_WEEK);
2240 if (tmpDayOfMonth > maxDaysOfMonth)
2242 tmpDayOfMonth -= _NUMBER_OF_DAYS_OF_WEEK;
2245 DateTime resultTime;
2246 resultTime.SetValue(year, month, tmpDayOfMonth, time.GetHour(), time.GetMinute(), time.GetSecond());
2248 delete pGregorianCalendar;
2254 _CalEventImpl::GetDayOfWeek(const DateTime& date, const Locales::TimeZone& timeZone)
2256 CalDayOfWeek dayOfWeek = CAL_SUNDAY;
2258 std::unique_ptr<Tizen::Locales::Calendar> pGregorianCalendar(Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN));
2260 pGregorianCalendar->SetTime(date);
2261 int dayOfWeekByGregorianCalendar = pGregorianCalendar->GetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_WEEK);
2263 switch (dayOfWeekByGregorianCalendar)
2265 case Tizen::Locales::SUNDAY:
2266 dayOfWeek = CAL_SUNDAY;
2268 case Tizen::Locales::MONDAY:
2269 dayOfWeek = CAL_MONDAY;
2271 case Tizen::Locales::TUESDAY:
2272 dayOfWeek = CAL_TUESDAY;
2274 case Tizen::Locales::WEDNESDAY:
2275 dayOfWeek = CAL_WEDNESDAY;
2277 case Tizen::Locales::THURSDAY:
2278 dayOfWeek = CAL_THURSDAY;
2280 case Tizen::Locales::FRIDAY:
2281 dayOfWeek = CAL_FRIDAY;
2283 case Tizen::Locales::SATURDAY:
2284 dayOfWeek = CAL_SATURDAY;
2294 _CalEventImpl::GetFirstDay(CalDayOfWeek weekStart, int dayOfWeek, int& count)
2297 int tmpDay = weekStart;
2300 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
2302 if ((tmpDay & dayOfWeek) != 0)
2312 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2315 return static_cast<CalDayOfWeek>(firstDay);
2319 _CalEventImpl::GetNextDay(int dayOfWeek, CalDayOfWeek currentDay)
2321 int tmpDay = currentDay;
2323 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
2325 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2327 if ((tmpDay & dayOfWeek) != 0)
2333 return static_cast<CalDayOfWeek>(tmpDay);
2337 _CalEventImpl::SetRecordHandle(calendar_record_h eventHandle)
2339 __eventRecord.ResetHandle(eventHandle);
2343 _CalEventImpl::GetRecordHandle(void) const
2345 return __eventRecord.GetHandle();
2349 _CalEventImpl::CreateDefaultInstanceN(void)
2351 return new (std::nothrow) CalEvent();
2355 _CalEventImpl::GetInstance(CalEvent& event)
2357 return event.__pCalEventImpl;
2360 const _CalEventImpl*
2361 _CalEventImpl::GetInstance(const CalEvent& event)
2363 return event.__pCalEventImpl;