2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FScl_CalEventImpl.cpp
18 * @brief This is the implementation for _CalEventImpl class.
20 * This file contains definitions of @e _CalEventImpl class.
25 #include <FBaseColArrayList.h>
26 #include <FSysSystemTime.h>
27 #include <FLclTimeZone.h>
28 #include <FLclGregorianCalendar.h>
29 #include <FLclCalendar.h>
30 #include <FSclAttendee.h>
31 #include <FSclRecord.h>
32 #include <FSclCalEvent.h>
33 #include <FBaseSysLog.h>
34 #include <FApp_AppInfo.h>
35 #include <FBase_StringConverter.h>
36 #include "FScl_RecordImpl.h"
37 #include "FScl_CalEventImpl.h"
38 #include "FScl_RecurrenceImpl.h"
39 #include "FScl_CalendarbookImpl.h"
40 #include "FScl_CalendarbookDbConnector.h"
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Base::Utility;
45 using namespace Tizen::App;
46 using namespace Tizen::System;
47 using namespace Tizen::Locales;
49 namespace Tizen { namespace Social
52 static const int _DEFAULT_ADDED_HOUR = 1;
53 static const int _INVALID_ATTENDEE_INDEX = -1;
55 static const int _TERM_LIMIT_DAILY = 1;
56 static const int _TERM_LIMIT_WEEKLY = 7;
57 static const int _TERM_LIMIT_MONTHLY = 31;
58 static const int _TERM_LIMIT_YEARLY = 366;
59 static const int _NUMBER_OF_DAYS_OF_WEEK = 7;
61 static const wchar_t* _EVENT_CATEGORY_APPOINTMENT_STRING = L"Appointment";
62 static const wchar_t* _EVENT_CATEGORY_ANNIVERSARY_STRING = L"Anniversary";
64 static const wchar_t* _RECURRENCE_KEYWORD_SUNDAY = L"SU";
65 static const wchar_t* _RECURRENCE_KEYWORD_MONDAY = L"MO";
66 static const wchar_t* _RECURRENCE_KEYWORD_TUESDAY = L"TU";
67 static const wchar_t* _RECURRENCE_KEYWORD_WEDNESDAY = L"WE";
68 static const wchar_t* _RECURRENCE_KEYWORD_THURSDAY = L"TH";
69 static const wchar_t* _RECURRENCE_KEYWORD_FRIDAY = L"FR";
70 static const wchar_t* _RECURRENCE_KEYWORD_SATURDAY = L"SA";
72 static const wchar_t* _RECURRENCE_DELIMITER = L",";
73 static const int _RECURRENCE_DELIMITER_LENGTH = 1;
74 static const wchar_t _RECURRENCE_BY_DAY_CHAR_PLUS = L'+';
75 static const wchar_t _RECURRENCE_BY_DAY_CHAR_MINUS = L'-';
76 static const wchar_t _RECURRENCE_BY_DAY_CHAR_ONE = L'1';
77 static const int _RECURRENCE_BY_DAY_FIRST_INDEX = 0;
78 static const int _RECURRENCE_BY_DAY_SECOND_INDEX = 1;
79 static const int _MAX_WEEK_OF_MONTH = 5;
81 static const double _MIN_LATITUDE = -90.0;
82 static const double _MAX_LATITUDE = 90.0;
83 static const double _MIN_LONGITUDE = -180.0;
84 static const double _MAX_LONGITUDE = 180.0;
86 _CalEventImpl::_CalEventImpl(void)
87 : __originalEventId(INVALID_RECORD_ID)
89 , __reminderListUpdated(false)
91 // Set default start and end time
94 SystemTime::GetCurrentTime(startTime);
95 if (IsFailed(GetLastResult()))
97 startTime = _CalendarbookImpl::GetMinDateTime();
101 DateTime endTime(startTime);
102 r = endTime.AddHours(_DEFAULT_ADDED_HOUR);
103 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
105 calendar_time_s startCalendarTime;
106 calendar_time_s endCalendarTime;
107 startCalendarTime.type = CALENDAR_TIME_UTIME;
108 endCalendarTime.type = CALENDAR_TIME_UTIME;
109 startCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(startTime);
110 endCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(endTime);
112 int errorCode = CALENDAR_ERROR_NONE;
113 calendar_record_h eventHandle = null;
115 r = _CalendarbookDbConnector::Connect();
116 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
118 errorCode = calendar_record_create(_calendar_event._uri, &eventHandle);
119 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
121 __eventRecord.ResetHandle(eventHandle);
123 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
124 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
127 errorCode = calendar_record_set_int(eventHandle, _calendar_event.event_status, CALENDAR_EVENT_STATUS_NONE);
128 errorCode = calendar_record_set_int(eventHandle, _calendar_event.busy_status, CALENDAR_EVENT_BUSY_STATUS_FREE);
129 errorCode = calendar_record_set_int(eventHandle, _calendar_event.priority, CALENDAR_EVENT_PRIORITY_NORMAL);
130 errorCode = calendar_record_set_int(eventHandle, _calendar_event.sensitivity, CALENDAR_SENSITIVITY_PUBLIC);
132 r = __reminderList.Construct();
133 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
136 _CalEventImpl::_CalEventImpl(const _CalEventImpl& rhs)
137 : __originalEventId(rhs.__originalEventId)
138 , __isInstance(rhs.__isInstance)
139 , __reminderListUpdated(false)
141 int errorCode = CALENDAR_ERROR_NONE;
142 calendar_record_h eventHandle = null;
144 result r = _CalendarbookDbConnector::Connect();
145 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
147 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
148 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
150 __eventRecord.ResetHandle(eventHandle);
152 r = __reminderList.Construct();
153 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
156 _CalEventImpl::~_CalEventImpl(void)
158 int errorCode = CALENDAR_ERROR_NONE;
159 errorCode = calendar_record_destroy(__eventRecord.ReleaseHandle(), true);
161 __reminderList.RemoveAll(true);
163 result r = _CalendarbookDbConnector::Disconnect();
164 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
168 _CalEventImpl::operator =(const _CalEventImpl& rhs)
175 __originalEventId = rhs.__originalEventId;
176 __isInstance = rhs.__isInstance;
177 __reminderList.RemoveAll(true);
178 __reminderListUpdated = false;
180 int errorCode = CALENDAR_ERROR_NONE;
181 calendar_record_h eventHandle = null;
183 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
184 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
186 __eventRecord.ResetHandle(eventHandle);
192 _CalEventImpl::IsInstance(void) const
198 _CalEventImpl::IsRecurring(void) const
200 int errorCode = CALENDAR_ERROR_NONE;
201 int recurrenceFreq = CALENDAR_RECURRENCE_NONE;
203 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFreq);
205 if (recurrenceFreq == CALENDAR_RECURRENCE_NONE)
214 _CalEventImpl::GetOriginalCalEventId(void) const
216 return __originalEventId;
220 _CalEventImpl::IsAllDayEvent(void) const
222 int errorCode = CALENDAR_ERROR_NONE;
223 calendar_time_s startCalendarTime;
225 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
226 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
235 _CalEventImpl::SetAllDayEvent(bool isAllDayEvent)
237 if (GetCategory() == EVENT_CATEGORY_ANNIVERSARY)
242 int errorCode = CALENDAR_ERROR_NONE;
243 calendar_time_s startCalendarTime;
244 calendar_time_s tmpStartCalendarTime;
245 calendar_time_s endCalendarTime;
246 calendar_time_s tmpEndCalendarTime;
248 bool isChanged = false;
250 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
251 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
253 if (isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_UTIME)
255 tmpStartCalendarTime.type = CALENDAR_TIME_LOCALTIME;
256 DateTime tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
257 tmpStartCalendarTime.time.date.year = tmpStartTime.GetYear();
258 tmpStartCalendarTime.time.date.month = tmpStartTime.GetMonth();
259 tmpStartCalendarTime.time.date.mday = tmpStartTime.GetDay();
261 tmpEndCalendarTime.type = CALENDAR_TIME_LOCALTIME;
262 DateTime tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
263 tmpEndCalendarTime.time.date.year = tmpEndTime.GetYear();
264 tmpEndCalendarTime.time.date.month = tmpEndTime.GetMonth();
265 tmpEndCalendarTime.time.date.mday = tmpEndTime.GetDay();
267 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
268 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
272 else if (!isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
274 tmpStartCalendarTime.type = CALENDAR_TIME_UTIME;
275 DateTime tmpStartTime;
276 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
277 tmpStartCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpStartTime);
279 tmpEndCalendarTime.type = CALENDAR_TIME_UTIME;
281 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
282 tmpEndCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpEndTime);
284 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
285 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
292 int rangeType = CALENDAR_RANGE_NONE;
293 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.range_type, &rangeType);
295 if (rangeType == CALENDAR_RANGE_UNTIL)
297 calendar_time_s untilCalendarTime;
298 calendar_time_s tmpUntilCalendarTime;
300 errorCode = calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, &untilCalendarTime);
301 if (isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_UTIME)
303 tmpUntilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
304 DateTime tmpUntilTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
305 tmpUntilCalendarTime.time.date.year = tmpUntilTime.GetYear();
306 tmpUntilCalendarTime.time.date.month = tmpUntilTime.GetMonth();
307 tmpUntilCalendarTime.time.date.mday = tmpUntilTime.GetDay();
309 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
311 else if (!isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
313 tmpUntilCalendarTime.type = CALENDAR_TIME_UTIME;
314 DateTime tmpUntilTime;
315 tmpUntilTime.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
316 tmpUntilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpUntilTime);
318 errorCode = calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
324 if (__pRecurrence == null)
326 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
329 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*__pRecurrence.get(), isAllDayEvent)));
330 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
336 _CalEventImpl::GetUIDN(void) const
340 int errorCode = CALENDAR_ERROR_NONE;
341 char* pStrUid = null;
342 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
344 if (pStrUid == null || strlen(pStrUid) == 0)
349 ByteBuffer* pConvertedUidBuffer = _CalendarbookUtil::ConvertCharArrayToByteBufferN(pStrUid);
350 SysTryReturn(NID_SCL, pConvertedUidBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
352 return pConvertedUidBuffer;
356 _CalEventImpl::SetUID(const ByteBuffer* pUid)
358 int errorCode = CALENDAR_ERROR_NONE;
362 std::unique_ptr<char[]> pConvertedUidArray(_CalendarbookUtil::ConvertByteBufferToCharArrayN(*pUid));
363 SysTryReturn(NID_SCL, pConvertedUidArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
365 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pConvertedUidArray.get());
369 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, null);
376 _CalEventImpl::GetUid(void) const
378 int errorCode = CALENDAR_ERROR_NONE;
379 char* pStrUid = null;
380 errorCode = calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
382 return String(pStrUid);
386 _CalEventImpl::SetUid(const Tizen::Base::String& uid)
388 int errorCode = CALENDAR_ERROR_NONE;
390 std::unique_ptr<char[]> pStrUid(_StringConverter::CopyToCharArrayN(uid));
391 SysTryReturnVoidResult(NID_SCL, pStrUid != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
393 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pStrUid.get());
397 _CalEventImpl::GetStatus(void) const
399 int errorCode = CALENDAR_ERROR_NONE;
400 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
402 EventStatus eventStatus = EVENT_STATUS_NONE;
404 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.event_status, &srcEventStatus);
406 switch (srcEventStatus)
408 case CALENDAR_EVENT_STATUS_NONE:
409 eventStatus = EVENT_STATUS_NONE;
411 case CALENDAR_EVENT_STATUS_TENTATIVE:
412 eventStatus = EVENT_STATUS_TENTATIVE;
414 case CALENDAR_EVENT_STATUS_CONFIRMED:
415 eventStatus = EVENT_STATUS_CONFIRMED;
417 case CALENDAR_EVENT_STATUS_CANCELLED:
418 eventStatus = EVENT_STATUS_CANCELLED;
421 SysLog(NID_SCL, "The status value is invalid.");
422 return EVENT_STATUS_NONE;
429 _CalEventImpl::SetStatus(EventStatus status)
431 int errorCode = CALENDAR_ERROR_NONE;
432 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.event_status, _CalendarbookUtil::ConvertEventStatusToCSEventStatus(status));
436 _CalEventImpl::GetBusyStatus(void) const
438 int errorCode = CALENDAR_ERROR_NONE;
439 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
441 BusyStatus busyStatus = BUSY_STATUS_FREE;
443 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.busy_status, &srcEventBusyStatus);
445 switch (srcEventBusyStatus)
447 case CALENDAR_EVENT_BUSY_STATUS_FREE:
448 busyStatus = BUSY_STATUS_FREE;
450 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
451 busyStatus = BUSY_STATUS_BUSY;
453 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
454 busyStatus = BUSY_STATUS_UNAVAILABLE;
456 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
457 busyStatus = BUSY_STATUS_TENTATIVE;
460 SysLog(NID_SCL, "The busy status value is invalid.");
461 busyStatus = BUSY_STATUS_FREE;
469 _CalEventImpl::SetBusyStatus(BusyStatus busyStatus)
471 int errorCode = CALENDAR_ERROR_NONE;
472 errorCode = calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.busy_status, _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(busyStatus));
476 _CalEventImpl::GetPriority(void) const
478 int errorCode = CALENDAR_ERROR_NONE;
479 int srcPriority = CALENDAR_EVENT_PRIORITY_LOW;
481 EventPriority priority = EVENT_PRIORITY_NORMAL;
483 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.priority, &srcPriority);
487 case CALENDAR_EVENT_PRIORITY_LOW:
488 priority = EVENT_PRIORITY_LOW;
490 case CALENDAR_EVENT_PRIORITY_NONE:
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));
1528 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_MONTHLY);
1530 if (recurrence.GetDayOfMonth() != 0)
1532 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1536 dayOfWeek = recurrence.GetDayOfWeek();
1537 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1538 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1540 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1545 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY);
1547 pByMonth.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetMonthOfYear())));
1549 if (recurrence.GetDayOfMonth() != 0)
1551 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1555 dayOfWeek = recurrence.GetDayOfWeek();
1556 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1557 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1559 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1564 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. frequency = %d", recurrence.GetFrequency());
1565 return E_INVALID_ARG;
1568 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, pByDay.get());
1569 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, pByMonth.get());
1570 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, pByMonthDay.get());
1576 _CalEventImpl::ConvertDayOfWeekToRRuleByDayString(int dayOfWeek, int weekOfMonth, String& byDayString) const
1578 int tmpDayOfWeek = CAL_SUNDAY;
1580 byDayString.Clear();
1581 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
1583 if (dayOfWeek & tmpDayOfWeek)
1585 if (weekOfMonth != 0)
1587 byDayString.Append(weekOfMonth);
1590 switch (tmpDayOfWeek)
1593 byDayString.Append(_RECURRENCE_KEYWORD_SUNDAY);
1596 byDayString.Append(_RECURRENCE_KEYWORD_MONDAY);
1599 byDayString.Append(_RECURRENCE_KEYWORD_TUESDAY);
1602 byDayString.Append(_RECURRENCE_KEYWORD_WEDNESDAY);
1605 byDayString.Append(_RECURRENCE_KEYWORD_THURSDAY);
1608 byDayString.Append(_RECURRENCE_KEYWORD_FRIDAY);
1611 byDayString.Append(_RECURRENCE_KEYWORD_SATURDAY);
1614 byDayString.Append(_RECURRENCE_DELIMITER);
1620 byDayString.Remove(byDayString.GetLength() - 1, _RECURRENCE_DELIMITER_LENGTH);
1626 _CalEventImpl::GetCalendarId(void) const
1628 int errorCode = CALENDAR_ERROR_NONE;
1629 int srcCalendarbookId = 0;
1631 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.calendar_book_id, &srcCalendarbookId);
1633 return srcCalendarbookId;
1637 _CalEventImpl::GetBaseEventId(void) const
1639 int errorCode = CALENDAR_ERROR_NONE;
1640 int srcBaseEventId = INVALID_RECORD_ID;
1642 errorCode = calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.original_event_id, &srcBaseEventId);
1644 return srcBaseEventId;
1648 _CalEventImpl::SetOriginalCalEventId(RecordId originalEventId)
1650 __originalEventId = originalEventId;
1651 __isInstance = true;
1655 _CalEventImpl::GetAttendeeIndex(const char* pAttendeeEmail)
1657 int index = _INVALID_ATTENDEE_INDEX;
1658 unsigned int attendeeCount = 0;
1660 int errorCode = CALENDAR_ERROR_NONE;
1661 errorCode = calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
1663 calendar_record_h tmpAttendeeHandle = null;
1664 char* pTmpAttendeeEmail = null;
1665 for (int i = 0; i < attendeeCount; i++)
1667 errorCode = calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
1668 errorCode = calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpAttendeeEmail);
1670 if (strcmp(pAttendeeEmail, pTmpAttendeeEmail) == 0)
1681 _CalEventImpl::VerifyRecurrence(const Recurrence& recurrence)
1683 const DateTime* pUntil = recurrence.GetUntil();
1684 RecurFrequency frequency = recurrence.GetFrequency();
1685 int durationLimit = 0;
1686 int interval = recurrence.GetInterval();
1688 DateTime startTime = GetStartTime();
1689 DateTime endTime = GetEndTime();
1690 EventCategory category = GetCategory();
1694 SysTryReturnResult(NID_SCL, startTime <= *pUntil, E_INVALID_CONDITION, "The until date of recurrence is earlier than start date.");
1697 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1699 if (category == EVENT_CATEGORY_ANNIVERSARY)
1701 SysTryReturnResult(NID_SCL, frequency == FREQ_YEARLY, E_TYPE_MISMATCH
1702 , "The recurrence pattern is not a yearly pattern in case of the event being an Anniversary.");
1706 if (frequency == FREQ_DAILY)
1708 durationLimit = _TERM_LIMIT_DAILY * interval;
1710 else if (frequency == FREQ_WEEKLY)
1712 SysTryReturnResult(NID_SCL, recurrence.GetDayOfWeek() != 0, E_INVALID_ARG, "Invalid argument is used. The day of week is not set.");
1713 durationLimit = _TERM_LIMIT_WEEKLY * interval;
1715 else if (frequency == FREQ_MONTHLY)
1717 SysTryReturnResult(NID_SCL, recurrence.GetDayOfMonth() != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1718 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1719 durationLimit = _TERM_LIMIT_MONTHLY * interval;
1721 else if (frequency == FREQ_YEARLY)
1723 int dayOfMonth = recurrence.GetDayOfMonth();
1724 int monthOfYear = recurrence.GetMonthOfYear();
1725 SysTryReturnResult(NID_SCL, monthOfYear != 0, E_INVALID_ARG, "Invalid argument is used. The month of year is not set.");
1726 SysTryReturnResult(NID_SCL, dayOfMonth != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1727 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1729 SysTryReturnResult(NID_SCL, monthOfYear != 2 || dayOfMonth < 30
1730 , E_INVALID_ARG, "Invalid argument is used. If the frequency is yearly, the max days of the February is less than 30.");
1731 if (dayOfMonth > 30)
1733 SysTryReturnResult(NID_SCL, monthOfYear != 4 && monthOfYear != 6 && monthOfYear != 9 && monthOfYear != 11
1734 , 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.");
1737 durationLimit = _TERM_LIMIT_YEARLY * interval;
1740 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1741 SysTryReturnResult(NID_SCL, duration.GetDays() <= durationLimit, E_INVALID_CONDITION
1742 , "The duration of the event is greater than (interval x frequency) days. duration days = %d", duration.GetDays());
1748 _CalEventImpl::ResetStartAndEndTimeByRecurrence(const Recurrence& recurrence)
1750 result r = E_SUCCESS;
1754 bool isAllDay = IsAllDayEvent();
1755 Locales::TimeZone timeZone;
1759 timeZone = GetTimeZone();
1760 startTime = timeZone.UtcTimeToWallTime(GetStartTime());
1761 endTime = timeZone.UtcTimeToWallTime(GetEndTime());
1765 startTime = GetStartTime();
1766 endTime = GetEndTime();
1769 DateTime calculatedStartTime(startTime);
1770 DateTime calculatedEndTime(endTime);
1771 RecurFrequency frequency = recurrence.GetFrequency();
1772 int interval = recurrence.GetInterval();
1773 int dayOfMonth = recurrence.GetDayOfMonth();
1774 int dayOfWeek = recurrence.GetDayOfWeek();
1775 int weekOfMonth = recurrence.GetWeekOfMonth();
1776 int monthOfYear = recurrence.GetMonthOfYear();
1777 CalDayOfWeek weekStart = recurrence.GetWeekStart();
1778 CalDayOfWeek weekEnd = CAL_SATURDAY;
1780 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1782 if (weekStart == CAL_MONDAY)
1784 weekEnd = CAL_SUNDAY;
1787 if (recurrence.GetUntil() != null)
1789 until = *(recurrence.GetUntil());
1792 until = timeZone.UtcTimeToWallTime(until);
1797 until = _CalendarbookImpl::GetMaxDateTime();
1800 CalDayOfWeek dayOfStartTime = GetDayOfWeek(startTime, timeZone);
1802 if (frequency == FREQ_WEEKLY)
1806 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
1808 if ((dayOfStartTime & dayOfWeek) != 0)
1813 if ((dayOfStartTime & weekEnd) != 0)
1815 count += (interval - 1) * _NUMBER_OF_DAYS_OF_WEEK;
1818 dayOfStartTime = GetNextDayOfWeek(dayOfStartTime);
1822 r = calculatedStartTime.AddDays(count);
1823 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1824 r = calculatedEndTime.AddDays(count);
1825 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1828 else if (frequency == FREQ_MONTHLY)
1830 if (dayOfMonth != 0)
1832 bool isDone = false;
1833 while (calculatedStartTime <= until)
1835 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1837 if (calculatedStartTime >= startTime)
1843 calculatedStartTime.AddMonths(interval);
1845 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1846 calculatedEndTime = calculatedStartTime;
1847 calculatedEndTime.Add(duration);
1851 bool isDone = false;
1853 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1854 while (calculatedStartTime <= until)
1856 for (int i = 0; i < dayCount; i++)
1858 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1859 if (calculatedStartTime >= startTime)
1864 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1870 calculatedStartTime.AddMonths(interval);
1873 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1874 calculatedEndTime = calculatedStartTime;
1875 calculatedEndTime.Add(duration);
1878 else if (frequency == FREQ_YEARLY)
1880 if (dayOfMonth != 0)
1882 bool isDone = false;
1883 while (calculatedStartTime <= until)
1885 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), monthOfYear, dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1887 if (calculatedStartTime >= startTime)
1893 calculatedStartTime.AddYears(interval);
1895 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1896 calculatedEndTime = calculatedStartTime;
1897 calculatedEndTime.Add(duration);
1901 bool isDone = false;
1903 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1904 while (calculatedStartTime <= until)
1906 for (int i = 0; i < dayCount; i++)
1908 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), monthOfYear, weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1909 if (calculatedStartTime >= startTime)
1914 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1920 calculatedStartTime.AddYears(interval);
1923 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1924 calculatedEndTime = calculatedStartTime;
1925 calculatedEndTime.Add(duration);
1931 calculatedStartTime = timeZone.WallTimeToUtcTime(calculatedStartTime);
1932 calculatedEndTime = timeZone.WallTimeToUtcTime(calculatedEndTime);
1935 SysTryReturnResult(NID_SCL, calculatedStartTime <= until, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1936 SysTryReturnResult(NID_SCL, calculatedEndTime <= _CalendarbookImpl::GetMaxDateTime(), E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1938 SysLog(NID_SCL, "Reset start time : %S", calculatedStartTime.ToString().GetPointer());
1939 SetStartAndEndTimeCommon(calculatedStartTime, calculatedEndTime);
1945 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeek(const String& byDay) const
1947 result r = E_SUCCESS;
1951 SysTryReturn(NID_SCL, !byDay.IsEmpty(), 0, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The byDay is empty.");
1953 String delim(_RECURRENCE_DELIMITER);
1956 StringTokenizer strTok(byDay, delim);
1957 while (strTok.HasMoreTokens())
1959 r = strTok.GetNextToken(token);
1960 SysTryReturn(NID_SCL, r == E_SUCCESS, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1962 if (token == String(_RECURRENCE_KEYWORD_SUNDAY))
1964 dayOfWeek |= CAL_SUNDAY;
1966 else if (token == String(_RECURRENCE_KEYWORD_MONDAY))
1968 dayOfWeek |= CAL_MONDAY;
1970 else if (token == String(_RECURRENCE_KEYWORD_TUESDAY))
1972 dayOfWeek |= CAL_TUESDAY;
1974 else if (token == String(_RECURRENCE_KEYWORD_WEDNESDAY))
1976 dayOfWeek |= CAL_WEDNESDAY;
1978 else if (token == String(_RECURRENCE_KEYWORD_THURSDAY))
1980 dayOfWeek |= CAL_THURSDAY;
1982 else if (token == String(_RECURRENCE_KEYWORD_FRIDAY))
1984 dayOfWeek |= CAL_FRIDAY;
1986 else if (token == String(_RECURRENCE_KEYWORD_SATURDAY))
1988 dayOfWeek |= CAL_SATURDAY;
1992 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %S", byDay.GetPointer());
2001 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(const String& byDay, int& weekOfMonth, int& dayOfWeek) const
2003 result r = E_SUCCESS;
2004 String delim(_RECURRENCE_DELIMITER);
2006 wchar_t tmpChar = 0;
2007 int tmpWeekOfMonth = 0;
2008 int weekStringStartIndex = 0;
2014 SysTryReturnResult(NID_SCL, !byDay.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The byDay is empty.");
2016 StringTokenizer strTok(byDay, delim);
2018 while (strTok.HasMoreTokens())
2020 r = strTok.GetNextToken(token);
2021 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2023 r = token.GetCharAt(_RECURRENCE_BY_DAY_FIRST_INDEX, tmpChar);
2024 if (tmpChar == _RECURRENCE_BY_DAY_CHAR_MINUS)
2026 SysTryReturnResult(NID_SCL, weekOfMonth == 0 || weekOfMonth == _MAX_WEEK_OF_MONTH
2027 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2029 if (weekOfMonth == 0)
2032 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2033 SysTryReturnResult(NID_SCL, tmpChar == _RECURRENCE_BY_DAY_CHAR_ONE
2034 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2036 weekOfMonth = _MAX_WEEK_OF_MONTH;
2038 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2040 else if (tmpChar == _RECURRENCE_BY_DAY_CHAR_PLUS)
2042 if (weekOfMonth == 0)
2045 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2046 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2047 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_MONTH
2048 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2050 weekOfMonth = tmpWeekOfMonth;
2054 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2055 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2058 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2062 if (weekOfMonth == 0)
2064 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2065 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_MONTH
2066 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2068 weekOfMonth = tmpWeekOfMonth;
2072 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2073 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2076 weekStringStartIndex = _RECURRENCE_BY_DAY_FIRST_INDEX + 1;
2079 token.SubString(weekStringStartIndex, tmpString);
2081 if (tmpString == String(_RECURRENCE_KEYWORD_SUNDAY))
2083 dayOfWeek |= CAL_SUNDAY;
2085 else if (tmpString == String(_RECURRENCE_KEYWORD_MONDAY))
2087 dayOfWeek |= CAL_MONDAY;
2089 else if (tmpString == String(_RECURRENCE_KEYWORD_TUESDAY))
2091 dayOfWeek |= CAL_TUESDAY;
2093 else if (tmpString == String(_RECURRENCE_KEYWORD_WEDNESDAY))
2095 dayOfWeek |= CAL_WEDNESDAY;
2097 else if (tmpString == String(_RECURRENCE_KEYWORD_THURSDAY))
2099 dayOfWeek |= CAL_THURSDAY;
2101 else if (tmpString == String(_RECURRENCE_KEYWORD_FRIDAY))
2103 dayOfWeek |= CAL_FRIDAY;
2105 else if (tmpString == String(_RECURRENCE_KEYWORD_SATURDAY))
2107 dayOfWeek |= CAL_SATURDAY;
2111 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. byday = %S", byDay.GetPointer());
2119 _CalEventImpl::ConvertRRuleExDateStringToRecurrence(const String& exdate, Recurrence& recurrence) const
2121 result r = E_SUCCESS;
2123 String delim(_RECURRENCE_DELIMITER);
2125 DateTime tmpDateTime;
2126 TimeZone tmpTimeZone;
2127 TimeZone utcTimeZone = TimeZone::GetGmtTimeZone();
2128 bool isDate = false;
2130 SysTryReturnResult(NID_SCL, !exdate.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The exdate is empty.");
2132 StringTokenizer strTok(exdate, delim);
2133 while (strTok.HasMoreTokens())
2135 r = strTok.GetNextToken(token);
2136 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2138 r = _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(token, tmpDateTime, tmpTimeZone, isDate);
2139 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. exdate = %S", exdate.GetPointer());
2141 if (!isDate && tmpTimeZone != utcTimeZone)
2143 tmpDateTime = tmpTimeZone.WallTimeToUtcTime(tmpDateTime);
2146 r = recurrence.AddExceptionDate(tmpDateTime);
2147 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. exdate = %S", exdate.GetPointer());
2154 _CalEventImpl::ConvertRecurrenceToRRuleExDateString(const Recurrence& recurrence, bool isDate) const
2156 result r = E_SUCCESS;
2158 bool isNotFirst = false;
2159 String exdateString;
2161 std::unique_ptr<IList, AllElementsDeleter> pExDateList(recurrence.GetExceptionDatesN());
2163 IEnumerator* pEnum = pExDateList->GetEnumeratorN();
2164 while (pEnum->MoveNext() == E_SUCCESS)
2166 DateTime* pDateTime = static_cast<DateTime*>(pEnum->GetCurrent());
2170 r = exdateString.Append(_RECURRENCE_DELIMITER);
2173 r = exdateString.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(*pDateTime, isDate));
2179 return exdateString;
2183 _CalEventImpl::GetNextDayOfWeek(CalDayOfWeek currentDay)
2185 int tmpDay = currentDay;
2188 if (tmpDay > CAL_SATURDAY)
2190 tmpDay = CAL_SUNDAY;
2193 return static_cast<CalDayOfWeek>(tmpDay);
2197 _CalEventImpl::GetDate(int year, int month, int weekOfMonth, CalDayOfWeek dayOfWeek, const DateTime& time, const Locales::TimeZone& timeZone)
2199 Tizen::Locales::DayOfWeek dayOfWeekByGregorianCalendar = Tizen::Locales::DAY_OF_WEEK_UNDEFINED;
2204 dayOfWeekByGregorianCalendar = Tizen::Locales::SUNDAY;
2207 dayOfWeekByGregorianCalendar = Tizen::Locales::MONDAY;
2210 dayOfWeekByGregorianCalendar = Tizen::Locales::TUESDAY;
2213 dayOfWeekByGregorianCalendar = Tizen::Locales::WEDNESDAY;
2216 dayOfWeekByGregorianCalendar = Tizen::Locales::THURSDAY;
2219 dayOfWeekByGregorianCalendar = Tizen::Locales::FRIDAY;
2222 dayOfWeekByGregorianCalendar = Tizen::Locales::SATURDAY;
2228 Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN);
2230 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
2231 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
2232 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH, 1);
2234 Tizen::Locales::DayOfWeek tmpDayOfWeek = static_cast<Tizen::Locales::DayOfWeek>(pGregorianCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK));
2235 int maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(TIME_FIELD_DAY_OF_MONTH);
2236 int tmpDayOfMonth = ((_NUMBER_OF_DAYS_OF_WEEK + dayOfWeekByGregorianCalendar) - tmpDayOfWeek) % _NUMBER_OF_DAYS_OF_WEEK + 1;
2238 tmpDayOfMonth += ((weekOfMonth - 1) * _NUMBER_OF_DAYS_OF_WEEK);
2239 if (tmpDayOfMonth > maxDaysOfMonth)
2241 tmpDayOfMonth -= _NUMBER_OF_DAYS_OF_WEEK;
2244 DateTime resultTime;
2245 resultTime.SetValue(year, month, tmpDayOfMonth, time.GetHour(), time.GetMinute(), time.GetSecond());
2247 delete pGregorianCalendar;
2253 _CalEventImpl::GetDayOfWeek(const DateTime& date, const Locales::TimeZone& timeZone)
2255 CalDayOfWeek dayOfWeek = CAL_SUNDAY;
2257 std::unique_ptr<Tizen::Locales::Calendar> pGregorianCalendar(Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN));
2259 pGregorianCalendar->SetTime(date);
2260 int dayOfWeekByGregorianCalendar = pGregorianCalendar->GetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_WEEK);
2262 switch (dayOfWeekByGregorianCalendar)
2264 case Tizen::Locales::SUNDAY:
2265 dayOfWeek = CAL_SUNDAY;
2267 case Tizen::Locales::MONDAY:
2268 dayOfWeek = CAL_MONDAY;
2270 case Tizen::Locales::TUESDAY:
2271 dayOfWeek = CAL_TUESDAY;
2273 case Tizen::Locales::WEDNESDAY:
2274 dayOfWeek = CAL_WEDNESDAY;
2276 case Tizen::Locales::THURSDAY:
2277 dayOfWeek = CAL_THURSDAY;
2279 case Tizen::Locales::FRIDAY:
2280 dayOfWeek = CAL_FRIDAY;
2282 case Tizen::Locales::SATURDAY:
2283 dayOfWeek = CAL_SATURDAY;
2293 _CalEventImpl::GetFirstDay(CalDayOfWeek weekStart, int dayOfWeek, int& count)
2296 int tmpDay = weekStart;
2299 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
2301 if ((tmpDay & dayOfWeek) != 0)
2311 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2314 return static_cast<CalDayOfWeek>(firstDay);
2318 _CalEventImpl::GetNextDay(int dayOfWeek, CalDayOfWeek currentDay)
2320 int tmpDay = currentDay;
2322 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
2324 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2326 if ((tmpDay & dayOfWeek) != 0)
2332 return static_cast<CalDayOfWeek>(tmpDay);
2336 _CalEventImpl::SetRecordHandle(calendar_record_h eventHandle)
2338 __eventRecord.ResetHandle(eventHandle);
2342 _CalEventImpl::GetRecordHandle(void) const
2344 return __eventRecord.GetHandle();
2348 _CalEventImpl::CreateDefaultInstanceN(void)
2350 return new (std::nothrow) CalEvent();
2354 _CalEventImpl::GetInstance(CalEvent& event)
2356 return event.__pCalEventImpl;
2359 const _CalEventImpl*
2360 _CalEventImpl::GetInstance(const CalEvent& event)
2362 return event.__pCalEventImpl;