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 <FApp_AppInfo.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
29 #include <FLclCalendar.h>
30 #include <FLclGregorianCalendar.h>
31 #include <FLclTimeZone.h>
32 #include <FSclAttendee.h>
33 #include <FSclCalEvent.h>
34 #include <FSclRecord.h>
35 #include <FSysSystemTime.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::App;
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Base::Utility;
46 using namespace Tizen::Locales;
47 using namespace Tizen::System;
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
93 SystemTime::GetCurrentTime(startTime);
94 if (IsFailed(GetLastResult()))
96 startTime = _CalendarbookImpl::GetMinDateTime();
100 DateTime endTime(startTime);
101 result r = endTime.AddHours(_DEFAULT_ADDED_HOUR);
102 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
104 calendar_time_s startCalendarTime;
105 calendar_time_s endCalendarTime;
106 startCalendarTime.type = CALENDAR_TIME_UTIME;
107 endCalendarTime.type = CALENDAR_TIME_UTIME;
108 startCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(startTime);
109 endCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(endTime);
111 r = _CalendarbookDbConnector::Connect();
112 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
114 calendar_record_h eventHandle = null;
115 int errorCode = calendar_record_create(_calendar_event._uri, &eventHandle);
116 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
118 __eventRecord.ResetHandle(eventHandle);
120 calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
121 calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
124 calendar_record_set_int(eventHandle, _calendar_event.event_status, CALENDAR_EVENT_STATUS_NONE);
125 calendar_record_set_int(eventHandle, _calendar_event.busy_status, CALENDAR_EVENT_BUSY_STATUS_FREE);
126 calendar_record_set_int(eventHandle, _calendar_event.priority, CALENDAR_EVENT_PRIORITY_NORMAL);
127 calendar_record_set_int(eventHandle, _calendar_event.sensitivity, CALENDAR_SENSITIVITY_PUBLIC);
128 calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, INVALID_RECORD_ID);
130 r = __reminderList.Construct();
131 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
134 _CalEventImpl::_CalEventImpl(const _CalEventImpl& rhs)
135 : __originalEventId(rhs.__originalEventId)
136 , __isInstance(rhs.__isInstance)
137 , __reminderListUpdated(false)
139 result r = _CalendarbookDbConnector::Connect();
140 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
142 calendar_record_h eventHandle = null;
143 int errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
144 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
146 __eventRecord.ResetHandle(eventHandle);
148 r = __reminderList.Construct();
149 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
152 _CalEventImpl::~_CalEventImpl(void)
154 calendar_record_destroy(__eventRecord.ReleaseHandle(), true);
156 __reminderList.RemoveAll(true);
158 result r = _CalendarbookDbConnector::Disconnect();
159 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
163 _CalEventImpl::operator =(const _CalEventImpl& rhs)
170 __originalEventId = rhs.__originalEventId;
171 __isInstance = rhs.__isInstance;
172 __reminderList.RemoveAll(true);
173 __reminderListUpdated = false;
175 int errorCode = CALENDAR_ERROR_NONE;
176 calendar_record_h eventHandle = null;
178 errorCode = calendar_record_clone(rhs.__eventRecord.GetHandle(), &eventHandle);
179 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
181 __eventRecord.ResetHandle(eventHandle);
187 _CalEventImpl::IsInstance(void) const
193 _CalEventImpl::IsRecurring(void) const
195 int recurrenceFreq = CALENDAR_RECURRENCE_NONE;
197 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFreq);
199 if (recurrenceFreq == CALENDAR_RECURRENCE_NONE)
208 _CalEventImpl::GetOriginalCalEventId(void) const
210 return __originalEventId;
214 _CalEventImpl::IsAllDayEvent(void) const
216 calendar_time_s startCalendarTime;
218 calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
219 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
228 _CalEventImpl::SetAllDayEvent(bool isAllDayEvent)
230 if (GetCategory() == EVENT_CATEGORY_ANNIVERSARY)
235 calendar_time_s startCalendarTime;
236 calendar_time_s tmpStartCalendarTime;
237 calendar_time_s endCalendarTime;
238 calendar_time_s tmpEndCalendarTime;
240 bool isChanged = false;
242 calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
243 calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
245 if (isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_UTIME)
247 tmpStartCalendarTime.type = CALENDAR_TIME_LOCALTIME;
248 DateTime tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
249 tmpStartCalendarTime.time.date.year = tmpStartTime.GetYear();
250 tmpStartCalendarTime.time.date.month = tmpStartTime.GetMonth();
251 tmpStartCalendarTime.time.date.mday = tmpStartTime.GetDay();
253 tmpEndCalendarTime.type = CALENDAR_TIME_LOCALTIME;
254 DateTime tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
255 tmpEndCalendarTime.time.date.year = tmpEndTime.GetYear();
256 tmpEndCalendarTime.time.date.month = tmpEndTime.GetMonth();
257 tmpEndCalendarTime.time.date.mday = tmpEndTime.GetDay();
259 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
260 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
264 else if (!isAllDayEvent && startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
266 tmpStartCalendarTime.type = CALENDAR_TIME_UTIME;
267 DateTime tmpStartTime;
268 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
269 tmpStartCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpStartTime);
271 tmpEndCalendarTime.type = CALENDAR_TIME_UTIME;
273 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
274 tmpEndCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpEndTime);
276 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, tmpStartCalendarTime);
277 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, tmpEndCalendarTime);
284 int rangeType = CALENDAR_RANGE_NONE;
285 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.range_type, &rangeType);
287 if (rangeType == CALENDAR_RANGE_UNTIL)
289 calendar_time_s untilCalendarTime;
290 calendar_time_s tmpUntilCalendarTime;
292 calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, &untilCalendarTime);
293 if (isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_UTIME)
295 tmpUntilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
296 DateTime tmpUntilTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
297 tmpUntilCalendarTime.time.date.year = tmpUntilTime.GetYear();
298 tmpUntilCalendarTime.time.date.month = tmpUntilTime.GetMonth();
299 tmpUntilCalendarTime.time.date.mday = tmpUntilTime.GetDay();
301 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
303 else if (!isAllDayEvent && untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
305 tmpUntilCalendarTime.type = CALENDAR_TIME_UTIME;
306 DateTime tmpUntilTime;
307 tmpUntilTime.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
308 tmpUntilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpUntilTime);
310 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.until_time, tmpUntilCalendarTime);
316 if (__pRecurrence == null)
318 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
321 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*__pRecurrence.get(), isAllDayEvent)));
322 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
323 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
329 _CalEventImpl::GetUIDN(void) const
333 char* pStrUid = null;
334 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
336 if (pStrUid == null || strlen(pStrUid) == 0)
341 ByteBuffer* pConvertedUidBuffer = _CalendarbookUtil::ConvertCharArrayToByteBufferN(pStrUid);
342 SysTryReturn(NID_SCL, pConvertedUidBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
344 return pConvertedUidBuffer;
348 _CalEventImpl::SetUID(const ByteBuffer* pUid)
350 int errorCode = CALENDAR_ERROR_NONE;
354 std::unique_ptr<char[]> pConvertedUidArray(_CalendarbookUtil::ConvertByteBufferToCharArrayN(*pUid));
355 SysTryReturn(NID_SCL, pConvertedUidArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
357 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pConvertedUidArray.get());
358 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
362 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, null);
363 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
370 _CalEventImpl::GetUid(void) const
372 char* pStrUid = null;
373 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.uid, &pStrUid);
375 return String(pStrUid);
379 _CalEventImpl::SetUid(const String& uid)
381 std::unique_ptr<char[]> pStrUid(_StringConverter::CopyToCharArrayN(uid));
382 SysTryReturnVoidResult(NID_SCL, pStrUid != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
384 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.uid, pStrUid.get());
385 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
389 _CalEventImpl::GetStatus(void) const
391 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
393 EventStatus eventStatus = EVENT_STATUS_NONE;
395 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.event_status, &srcEventStatus);
397 switch (srcEventStatus)
399 case CALENDAR_EVENT_STATUS_NONE:
400 eventStatus = EVENT_STATUS_NONE;
402 case CALENDAR_EVENT_STATUS_TENTATIVE:
403 eventStatus = EVENT_STATUS_TENTATIVE;
405 case CALENDAR_EVENT_STATUS_CONFIRMED:
406 eventStatus = EVENT_STATUS_CONFIRMED;
408 case CALENDAR_EVENT_STATUS_CANCELLED:
409 eventStatus = EVENT_STATUS_CANCELLED;
412 SysLog(NID_SCL, "The status value is invalid.");
413 return EVENT_STATUS_NONE;
420 _CalEventImpl::SetStatus(EventStatus status)
422 calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.event_status, _CalendarbookUtil::ConvertEventStatusToCSEventStatus(status));
426 _CalEventImpl::GetBusyStatus(void) const
428 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
430 BusyStatus busyStatus = BUSY_STATUS_FREE;
432 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.busy_status, &srcEventBusyStatus);
434 switch (srcEventBusyStatus)
436 case CALENDAR_EVENT_BUSY_STATUS_FREE:
437 busyStatus = BUSY_STATUS_FREE;
439 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
440 busyStatus = BUSY_STATUS_BUSY;
442 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
443 busyStatus = BUSY_STATUS_UNAVAILABLE;
445 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
446 busyStatus = BUSY_STATUS_TENTATIVE;
449 SysLog(NID_SCL, "The busy status value is invalid.");
450 busyStatus = BUSY_STATUS_FREE;
458 _CalEventImpl::SetBusyStatus(BusyStatus busyStatus)
460 calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.busy_status, _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(busyStatus));
464 _CalEventImpl::GetPriority(void) const
466 int srcPriority = CALENDAR_EVENT_PRIORITY_LOW;
468 EventPriority priority = EVENT_PRIORITY_NORMAL;
470 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.priority, &srcPriority);
474 case CALENDAR_EVENT_PRIORITY_LOW:
475 priority = EVENT_PRIORITY_LOW;
477 case CALENDAR_EVENT_PRIORITY_NONE:
479 case CALENDAR_EVENT_PRIORITY_NORMAL:
480 priority = EVENT_PRIORITY_NORMAL;
482 case CALENDAR_EVENT_PRIORITY_HIGH:
483 priority = EVENT_PRIORITY_HIGH;
486 SysLog(NID_SCL, "The priority value is invalid.");
487 priority = EVENT_PRIORITY_NORMAL;
494 _CalEventImpl::SetPriority(EventPriority priority)
496 calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.priority, _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(priority));
500 _CalEventImpl::AddAttendee(const Attendee& attendee)
502 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0)
504 SysTryReturnResult(NID_SCL, !attendee.GetEmail().IsEmpty(), E_OBJ_ALREADY_EXIST
505 , "The attendee's email string is empty.");
509 SysTryReturnResult(NID_SCL, !attendee.GetEmail().IsEmpty(), E_INVALID_ARG
510 , "The attendee's email string is empty.");
513 std::unique_ptr<char[]> pConvertedEmail(_StringConverter::CopyToCharArrayN(attendee.GetEmail()));
514 SysTryReturnResult(NID_SCL, pConvertedEmail != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
516 SysTryReturnResult(NID_SCL, GetAttendeeIndex(pConvertedEmail.get()) == _INVALID_ATTENDEE_INDEX, E_OBJ_ALREADY_EXIST
517 , "The specified attendee already exists as this email is already registered.");
519 std::unique_ptr<char[]> pConvertedName(_StringConverter::CopyToCharArrayN(attendee.GetName()));
520 SysTryReturnResult(NID_SCL, pConvertedName != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
522 std::unique_ptr<char[]> pConvertedPhoneNumber(_StringConverter::CopyToCharArrayN(attendee.GetPhoneNumber()));
523 SysTryReturnResult(NID_SCL, pConvertedPhoneNumber != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
525 calendar_attendee_status_e convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
526 switch (attendee.GetStatus())
528 case ATTENDEE_STATUS_NONE:
529 convertedStatus = CALENDAR_ATTENDEE_STATUS_COMPLETED;
531 case ATTENDEE_STATUS_NOT_RESPONDED:
532 convertedStatus = CALENDAR_ATTENDEE_STATUS_PENDING;
534 case ATTENDEE_STATUS_ACCEPTED:
535 convertedStatus = CALENDAR_ATTENDEE_STATUS_ACCEPTED;
537 case ATTENDEE_STATUS_DECLINED:
538 convertedStatus = CALENDAR_ATTENDEE_STATUS_DECLINED;
540 case ATTENDEE_STATUS_TENTATIVE:
541 convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
544 SysLog(NID_SCL, "The attendee status value is invalid. attendee status = %d", attendee.GetStatus());
545 convertedStatus = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
549 calendar_attendee_role_e convertedRole = CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT;
550 switch (attendee.GetRole())
552 case ATTENDEE_ROLE_ATTENDEE:
553 convertedRole = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
555 case ATTENDEE_ROLE_REQUIRED_ATTENDEE:
556 convertedRole = CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT;
558 case ATTENDEE_ROLE_ORGANIZER:
559 convertedRole = CALENDAR_ATTENDEE_ROLE_CHAIR;
562 SysLog(NID_SCL, "The attendee role value is invalid. attendee role = %d", attendee.GetRole());
563 convertedRole = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
567 calendar_record_h attendeeHandle = null;
568 int errorCode = calendar_record_create(_calendar_attendee._uri, &attendeeHandle);
569 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
571 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.name, pConvertedName.get());
572 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
573 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.email, pConvertedEmail.get());
574 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
575 errorCode = calendar_record_set_str(attendeeHandle, _calendar_attendee.number, pConvertedPhoneNumber.get());
576 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
577 calendar_record_set_int(attendeeHandle, _calendar_attendee.status, convertedStatus);
578 calendar_record_set_int(attendeeHandle, _calendar_attendee.role, convertedRole);
579 calendar_record_set_int(attendeeHandle, _calendar_attendee.person_id, attendee.GetPersonId());
581 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, attendeeHandle);
582 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
588 _CalEventImpl::RemoveAttendee(const Attendee& attendee)
590 std::unique_ptr<char[]> pConvertedEmail(_StringConverter::CopyToCharArrayN(attendee.GetEmail()));
591 SysTryReturnResult(NID_SCL, pConvertedEmail != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
593 int index = GetAttendeeIndex(pConvertedEmail.get());
594 SysTryReturnResult(NID_SCL, index != _INVALID_ATTENDEE_INDEX, E_OBJ_NOT_FOUND, "The specified attendee does not exist.");
596 calendar_record_h tmpAttendeeHandle = null;
597 calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, index, &tmpAttendeeHandle);
598 calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, tmpAttendeeHandle);
604 _CalEventImpl::GetAllAttendeesN(void) const
608 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
609 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
610 result r = pList->Construct();
611 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
613 unsigned int attendeeCount = 0;
614 calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
616 for (unsigned int i = 0; i < attendeeCount; i++)
618 calendar_record_h tmpAttendeeHandle = null;
619 char* pTmpEmail = null;
620 char* pTmpName = null;
621 char* pTmpPhoneNumber = null;
624 int tmpPersonId = -1;
625 AttendeeStatus attendeeStatus = ATTENDEE_STATUS_NONE;
626 AttendeeRole attendeeRole = ATTENDEE_ROLE_ATTENDEE;
628 calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
629 calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpEmail);
630 calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.name, &pTmpName);
631 calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.number, &pTmpPhoneNumber);
632 calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.status, &tmpStatus);
633 calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.role, &tmpRole);
634 calendar_record_get_int(tmpAttendeeHandle, _calendar_attendee.person_id, &tmpPersonId);
638 case CALENDAR_ATTENDEE_STATUS_PENDING:
639 attendeeStatus = ATTENDEE_STATUS_NOT_RESPONDED;
641 case CALENDAR_ATTENDEE_STATUS_ACCEPTED:
642 attendeeStatus = ATTENDEE_STATUS_ACCEPTED;
644 case CALENDAR_ATTENDEE_STATUS_DECLINED:
645 attendeeStatus = ATTENDEE_STATUS_DECLINED;
647 case CALENDAR_ATTENDEE_STATUS_TENTATIVE:
648 attendeeStatus = ATTENDEE_STATUS_TENTATIVE;
650 case CALENDAR_ATTENDEE_STATUS_DELEGATED:
651 attendeeStatus = ATTENDEE_STATUS_NONE;
653 case CALENDAR_ATTENDEE_STATUS_COMPLETED:
654 attendeeStatus = ATTENDEE_STATUS_NONE;
656 case CALENDAR_ATTENDEE_STATUS_IN_PROCESS:
657 attendeeStatus = ATTENDEE_STATUS_NOT_RESPONDED;
660 SysLog(NID_SCL, "The attendee status value is invalid. attendee status = %d", tmpStatus);
661 attendeeStatus = ATTENDEE_STATUS_NONE;
667 case CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT:
668 attendeeRole = ATTENDEE_ROLE_REQUIRED_ATTENDEE;
670 case CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT:
671 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
673 case CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT:
674 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
676 case CALENDAR_ATTENDEE_ROLE_CHAIR:
677 attendeeRole = ATTENDEE_ROLE_ORGANIZER;
680 SysLog(NID_SCL, "The attendee role value is invalid. attendee role = %d", tmpRole);
681 attendeeRole = ATTENDEE_ROLE_ATTENDEE;
685 std::unique_ptr<Attendee> pTmpAttendee(new (std::nothrow) Attendee(pTmpEmail));
686 SysTryReturn(NID_SCL, pTmpAttendee != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
688 if (pTmpName != null && strlen(pTmpName) > 0)
690 pTmpAttendee->SetName(pTmpName);
693 if (pTmpPhoneNumber != null && strlen(pTmpPhoneNumber) > 0)
695 pTmpAttendee->SetPhoneNumber(pTmpPhoneNumber);
698 pTmpAttendee->SetStatus(attendeeStatus);
699 pTmpAttendee->SetRole(attendeeRole);
700 pTmpAttendee->SetPersonId(tmpPersonId);
702 r = pList->Add(pTmpAttendee.get());
703 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
705 pTmpAttendee.release();
708 return pList.release();
712 _CalEventImpl::GetTimeZone(void) const
714 char* pTimeZoneId = null;
717 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.start_tzid, &pTimeZoneId);
718 if (pTimeZoneId != null && strlen(pTimeZoneId) > 0)
720 DateTime startTime = GetStartTime();
722 TimeZone::GetTimeZone(pTimeZoneId, startTime, timeZone);
729 _CalEventImpl::SetTimeZone(const TimeZone& timeZone)
731 std::unique_ptr<char[]> pConvertedTimeZoneId(_StringConverter::CopyToCharArrayN(timeZone.GetId()));
732 SysTryReturnResult(NID_SCL, pConvertedTimeZoneId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
734 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.start_tzid, pConvertedTimeZoneId.get());
735 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
736 errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.end_tzid, pConvertedTimeZoneId.get());
737 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
743 _CalEventImpl::GetRecurrenceId(void) const
746 SysTryReturn(NID_SCL, __isInstance, DateTime(), E_INVALID_STATE,
747 "[%s] The instance does not have a recurrence or is not a CalEvent instance which doesn't have a RecurrenceId.", GetErrorMessage(E_INVALID_STATE));
749 return GetStartTime();
753 _CalEventImpl::GetSubject(void) const
755 char* pSubject = null;
757 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.summary, &pSubject);
759 return String(pSubject);
763 _CalEventImpl::GetDescription(void) const
765 char* pDescription = null;
767 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.description, &pDescription);
769 return String(pDescription);
772 _CalEventImpl::GetStartTime(void) const
774 calendar_time_s startCalendarTime;
775 DateTime tmpStartTime;
777 calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, &startCalendarTime);
779 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
781 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
785 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
792 _CalEventImpl::GetEndTime(void) const
794 calendar_time_s endCalendarTime;
797 calendar_record_get_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, &endCalendarTime);
799 if (endCalendarTime.type == CALENDAR_TIME_UTIME)
801 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
803 else if (endCalendarTime.type == CALENDAR_TIME_LOCALTIME)
805 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
812 _CalEventImpl::GetLocation(void) const
814 char* pLocation = null;
816 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.location, &pLocation);
818 return String(pLocation);
822 _CalEventImpl::GetCategory(void) const
824 char* pCategories = null;
826 calendar_record_get_str_p(__eventRecord.GetHandle(), _calendar_event.categories, &pCategories);
828 return _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
832 _CalEventImpl::GetSensitivity(void) const
834 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
835 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
837 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.sensitivity, &srcSensitivity);
839 switch (srcSensitivity)
841 case CALENDAR_SENSITIVITY_PUBLIC:
842 sensitivity = SENSITIVITY_PUBLIC;
844 case CALENDAR_SENSITIVITY_PRIVATE:
845 sensitivity = SENSITIVITY_PRIVATE;
847 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
848 sensitivity = SENSITIVITY_CONFIDENTIAL;
851 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. sensitivity = %d", GetErrorMessage(E_INVALID_ARG), srcSensitivity);
852 sensitivity = SENSITIVITY_PUBLIC;
859 _CalEventImpl::GetReminder(void) const
861 if (__reminderListUpdated == false)
863 result r = _CalendarbookUtil::ConvertEventAlarmsToReminderList(__eventRecord.GetHandle(), __reminderList);
864 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
866 __reminderListUpdated = true;
869 if (__reminderList.GetCount() > 0)
871 return static_cast<const Reminder*>(__reminderList.GetAt(0));
878 _CalEventImpl::GetRecurrence(void) const
880 if (__pRecurrence == null)
882 __pRecurrence.reset(ConvertEventHandleToRecurrenceN(__eventRecord.GetHandle()));
885 return __pRecurrence.get();
889 _CalEventImpl::ConvertEventHandleToRecurrenceN(calendar_record_h eventHandle) const
891 int srcFrequency = CALENDAR_RECURRENCE_NONE;
892 calendar_time_s untilCalendarTime;
893 int rangeType = CALENDAR_RANGE_NONE;
897 char* pByMonthDay = null;
898 char* pByMonth = null;
900 char* pExDates = null;
902 result r = E_SUCCESS;
907 CalDayOfWeek convertedWeekStart = CAL_SUNDAY;
909 std::unique_ptr<Recurrence> pRecurrence(new (std::nothrow) Recurrence());
911 calendar_record_get_int(eventHandle, _calendar_event.freq, &srcFrequency);
913 if (srcFrequency == CALENDAR_RECURRENCE_NONE)
918 calendar_record_get_int(eventHandle, _calendar_event.range_type, &rangeType);
919 calendar_record_get_int(eventHandle, _calendar_event.count, &count);
920 calendar_record_get_int(eventHandle, _calendar_event.interval, &interval);
921 calendar_record_get_caltime(eventHandle, _calendar_event.until_time, &untilCalendarTime);
922 calendar_record_get_int(eventHandle, _calendar_event.wkst, &weekStart);
924 calendar_record_get_str_p(eventHandle, _calendar_event.byday, &pByDay);
925 calendar_record_get_str_p(eventHandle, _calendar_event.bymonthday, &pByMonthDay);
926 if (pByMonthDay != null)
928 r = Integer::Parse(pByMonthDay, dayOfMonth);
929 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
931 calendar_record_get_str_p(eventHandle, _calendar_event.bymonth, &pByMonth);
932 if (pByMonth != null)
934 r = Integer::Parse(pByMonth, monthOfYear);
935 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
938 switch (srcFrequency)
940 case CALENDAR_RECURRENCE_DAILY:
941 pRecurrence->SetFrequency(FREQ_DAILY);
944 case CALENDAR_RECURRENCE_WEEKLY:
945 pRecurrence->SetFrequency(FREQ_WEEKLY);
947 dayOfWeek = ConvertRRuleByDayStringToDayOfWeek(pByDay);
948 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Invalid argument is used. byday = %s", GetErrorMessage(E_INVALID_ARG), pByDay);
950 pRecurrence->SetDayOfWeek(dayOfWeek);
953 case CALENDAR_RECURRENCE_MONTHLY:
954 pRecurrence->SetFrequency(FREQ_MONTHLY);
960 int maxDaysOfMonth = _CalendarbookUtil::GetMaxDaysOfMonth(untilCalendarTime.time.date.year, monthOfYear);
961 pRecurrence->SetDayOfMonth(maxDaysOfMonth + dayOfMonth);
965 pRecurrence->SetDayOfMonth(dayOfMonth);
972 r = ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(pByDay, weekOfMonth, dayOfWeek);
973 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[%s] Invalid argument is used. byday = %s", GetErrorMessage(E_INVALID_ARG), pByDay);
975 pRecurrence->SetWeekOfMonth(weekOfMonth);
976 pRecurrence->SetDayOfWeek(dayOfWeek);
980 DateTime startTime = GetStartTime();
982 dayOfMonth = startTime.GetDay();
983 pRecurrence->SetDayOfMonth(dayOfMonth);
989 case CALENDAR_RECURRENCE_YEARLY:
990 pRecurrence->SetFrequency(FREQ_YEARLY);
996 int maxDaysOfMonth = _CalendarbookUtil::GetMaxDaysOfMonth(untilCalendarTime.time.date.year, monthOfYear);
997 pRecurrence->SetDayOfMonth(maxDaysOfMonth + dayOfMonth);
1001 pRecurrence->SetDayOfMonth(dayOfMonth);
1008 r = ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(pByDay, weekOfMonth, dayOfWeek);
1009 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[%s] Invalid argument is used. byday = %s", GetErrorMessage(E_INVALID_ARG), pByDay);
1011 pRecurrence->SetWeekOfMonth(weekOfMonth);
1012 pRecurrence->SetDayOfWeek(dayOfWeek);
1016 DateTime startTime = GetStartTime();
1018 dayOfMonth = startTime.GetDay();
1019 monthOfYear = startTime.GetMonth();
1021 pRecurrence->SetDayOfMonth(dayOfMonth);
1024 pRecurrence->SetMonthOfYear(monthOfYear);
1029 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. frequency = %d", srcFrequency);
1033 if (rangeType == CALENDAR_RANGE_NONE)
1035 pRecurrence->SetUntil(&DateTime::GetMaxValue());
1037 else if (rangeType == CALENDAR_RANGE_UNTIL)
1041 if (untilCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1043 until.SetValue(untilCalendarTime.time.date.year, untilCalendarTime.time.date.month, untilCalendarTime.time.date.mday);
1047 until = _CalendarbookUtil::ConvertEpochTimeToDateTime(untilCalendarTime.time.utime);
1050 pRecurrence->SetUntil(&until);
1054 pRecurrence->SetCounts(count);
1056 pRecurrence->SetInterval(interval);
1060 case CALENDAR_SUNDAY:
1061 convertedWeekStart = CAL_SUNDAY;
1064 case CALENDAR_MONDAY:
1065 convertedWeekStart = CAL_MONDAY;
1069 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. week start = %d", weekStart);
1072 pRecurrence->SetWeekStart(convertedWeekStart);
1074 calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExDates);
1075 if (pExDates != null && strlen(pExDates) != 0)
1077 r = ConvertRRuleExDateStringToRecurrence(pExDates, *pRecurrence.get());
1078 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_INVALID_ARG, "[%s] Invalid argument is used. exdate = %s", GetErrorMessage(E_INVALID_ARG), pExDates);
1081 return pRecurrence.release();
1085 _CalEventImpl::GetLastRevisedTime(void) const
1087 long long lastModifiedTime = 0;
1088 DateTime tmpLastRevisedTime;
1090 calendar_record_get_lli(__eventRecord.GetHandle(), _calendar_event.last_modified_time, &lastModifiedTime);
1092 tmpLastRevisedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(lastModifiedTime);
1094 return tmpLastRevisedTime;
1098 _CalEventImpl::SetSubject(const String& subject)
1100 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1102 SysTryReturnResult(NID_SCL, subject.GetLength() <= MAX_EVENT_SUBJECT_LENGTH, E_INVALID_ARG
1103 , "The length of the value exceeds MAX_EVENT_SUBJECT_LENGTH.");
1106 std::unique_ptr<char[]> pConvertedSubject(_StringConverter::CopyToCharArrayN(subject));
1107 SysTryReturnResult(NID_SCL, pConvertedSubject != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1109 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.summary, pConvertedSubject.get());
1110 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1116 _CalEventImpl::SetDescription(const String& description)
1118 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1120 SysTryReturnResult(NID_SCL, description.GetLength() <= MAX_EVENT_DESCRIPTION_LENGTH, E_INVALID_ARG
1121 , "The length of the value exceeds MAX_EVENT_DESCRIPTION_LENGTH.");
1124 std::unique_ptr<char[]> pConvertedDescription(_StringConverter::CopyToCharArrayN(description));
1125 SysTryReturnResult(NID_SCL, pConvertedDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1127 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.description, pConvertedDescription.get());
1128 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1134 _CalEventImpl::SetLocation(const String& location)
1136 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1138 SysTryReturnResult(NID_SCL, location.GetLength() <= MAX_EVENT_LOCATION_LENGTH, E_INVALID_ARG
1139 , "The length of the value exceeds MAX_EVENT_LOCATION_LENGTH.");
1142 std::unique_ptr<char[]> pConvertedLocation(_StringConverter::CopyToCharArrayN(location));
1143 SysTryReturnResult(NID_SCL, pConvertedLocation != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1145 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.location, pConvertedLocation.get());
1146 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1152 _CalEventImpl::SetStartAndEndTime(const DateTime& start, const DateTime& end)
1154 int recurrenceFrequency = 0;
1156 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.freq, &recurrenceFrequency);
1158 SysTryReturnResult(NID_SCL, recurrenceFrequency == CALENDAR_RECURRENCE_NONE, E_INVALID_CONDITION
1159 , "The recurrence date is already set. Cannot modify the start and end date/time.");
1160 SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, "Invalid argument is used. start = %S", start.ToString().GetPointer());
1161 SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, "Invalid argument is used. end = %S", end.ToString().GetPointer());
1162 SysTryReturnResult(NID_SCL, start <= end, E_INVALID_ARG, "Invalid argument is used. The end date is earlier than the start date.");
1164 return SetStartAndEndTimeCommon(start, end);
1168 _CalEventImpl::SetStartAndEndTimeCommon(const DateTime& start, const DateTime& end)
1170 calendar_time_s startCalendarTime;
1171 calendar_time_s endCalendarTime;
1173 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 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.start_time, startCalendarTime);
1195 calendar_record_set_caltime(__eventRecord.GetHandle(), _calendar_event.end_time, endCalendarTime);
1201 _CalEventImpl::SetCategory(EventCategory category)
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, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1214 pConvertedCategory.reset(_StringConverter::CopyToCharArrayN(_EVENT_CATEGORY_APPOINTMENT_STRING));
1215 SysTryReturnVoidResult(NID_SCL, pConvertedCategory != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1218 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.categories, pConvertedCategory.get());
1219 SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1223 _CalEventImpl::SetSensitivity(RecordSensitivity sensitivity)
1225 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 calendar_record_set_double(__eventRecord.GetHandle(), _calendar_event.latitude, latitude);
1235 calendar_record_set_double(__eventRecord.GetHandle(), _calendar_event.longitude, longitude);
1241 _CalEventImpl::GetCoordinates(double& latitude, double& longitude) const
1243 calendar_record_get_double(__eventRecord.GetHandle(), _calendar_event.latitude, &latitude);
1244 calendar_record_get_double(__eventRecord.GetHandle(), _calendar_event.longitude, &longitude);
1248 _CalEventImpl::SetReminder(const Reminder* pReminder)
1250 unsigned int reminderCount = 0;
1251 calendar_record_h tmpAlarmHandle = null;
1253 calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, &reminderCount);
1255 if (pReminder != null)
1257 int convertedTimeUnit = 0;
1258 switch (pReminder->GetTimeUnit())
1260 case REMINDER_TIME_UNIT_MINUTE:
1261 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1263 case REMINDER_TIME_UNIT_HOUR:
1264 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
1266 case REMINDER_TIME_UNIT_DAY:
1267 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
1269 case REMINDER_TIME_UNIT_WEEK:
1270 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
1276 calendar_record_h tmpAlarmHandle = null;
1277 int errorCode = CALENDAR_ERROR_NONE;
1279 if (reminderCount > 0)
1281 calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, 0, &tmpAlarmHandle);
1282 calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1283 calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, pReminder->GetTimeOffset());
1285 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(pReminder->GetSoundFile()));
1286 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1288 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1289 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1293 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(pReminder->GetSoundFile()));
1294 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1296 errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
1297 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1299 calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1300 calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, pReminder->GetTimeOffset());
1301 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1302 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1304 errorCode = calendar_record_add_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1305 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1310 if (reminderCount > 0)
1312 calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, 0, &tmpAlarmHandle);
1313 calendar_record_remove_child_record(__eventRecord.GetHandle(), _calendar_event.calendar_alarm, tmpAlarmHandle);
1317 __reminderList.RemoveAll(true);
1318 __reminderListUpdated = false;
1324 _CalEventImpl::SetRecurrence(const Recurrence* pRecurrence)
1326 if (pRecurrence != null)
1328 result r = VerifyRecurrence(*pRecurrence);
1329 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1331 r = ResetStartAndEndTimeByRecurrence(*pRecurrence);
1332 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1334 r = ConvertRecurrenceToEventHandle(*pRecurrence, __eventRecord.GetHandle());
1335 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1337 std::unique_ptr<char[]> pExDates(_StringConverter::CopyToCharArrayN(ConvertRecurrenceToRRuleExDateString(*pRecurrence, IsAllDayEvent())));
1338 int errorCode = calendar_record_set_str(__eventRecord.GetHandle(), _calendar_event.exdate, pExDates.get());
1339 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1341 __pRecurrence.reset(new (std::nothrow) Recurrence(*pRecurrence));
1342 SysTryReturnResult(NID_SCL, __pRecurrence != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1346 calendar_record_set_int(__eventRecord.GetHandle(), _calendar_event.freq, CALENDAR_RECURRENCE_NONE);
1348 __pRecurrence.reset(null);
1355 _CalEventImpl::AddReminder(const Reminder& reminder)
1357 calendar_record_h tmpAlarmHandle = null;
1359 std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(reminder.GetSoundFile()));
1360 SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1362 int errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
1363 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1365 int convertedTimeUnit = 0;
1367 ReminderTimeUnit timeUnit = reminder.GetTimeUnit();
1370 case REMINDER_TIME_UNIT_MINUTE:
1371 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
1374 case REMINDER_TIME_UNIT_HOUR:
1375 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
1378 case REMINDER_TIME_UNIT_DAY:
1379 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
1382 case REMINDER_TIME_UNIT_WEEK:
1383 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
1386 case REMINDER_TIME_UNIT_NONE:
1387 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
1394 calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
1395 calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, reminder.GetTimeOffset());
1396 errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
1397 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1399 if (convertedTimeUnit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
1401 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);
1405 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1407 __reminderList.RemoveAll(true);
1408 __reminderListUpdated = false;
1414 _CalEventImpl::RemoveReminderAt(int index)
1416 calendar_record_h tmpAlarmHandle = null;
1418 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 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, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1439 __reminderListUpdated = true;
1442 return __reminderList;
1446 _CalEventImpl::ConvertRecurrenceToEventHandle(const Recurrence& recurrence, calendar_record_h eventHandle) const
1448 result r = E_SUCCESS;
1450 int weekStart = CALENDAR_SUNDAY;
1451 std::unique_ptr<char[]> pByDay;
1452 std::unique_ptr<char[]> pByMonth;
1453 std::unique_ptr<char[]> pByMonthDay;
1456 String dayOfWeekString;
1457 String exDateString;
1459 switch (recurrence.GetWeekStart())
1462 weekStart = CALENDAR_SUNDAY;
1466 weekStart = CALENDAR_MONDAY;
1470 SysLogException(NID_SCL, E_INVALID_ARG, "Invalid argument is passed. week start = %d", recurrence.GetWeekStart());
1471 return E_INVALID_ARG;
1474 int errorCode = calendar_record_set_int(eventHandle, _calendar_event.wkst, weekStart);
1475 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_INVALID_ARG, "Invalid argument is passed. week start = %d", weekStart);
1477 if (recurrence.GetUntil() != null)
1479 if (*recurrence.GetUntil() == DateTime::GetMaxValue())
1481 calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_NONE);
1485 calendar_time_s startCalendarTime;
1486 calendar_time_s untilCalendarTime;
1488 calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &startCalendarTime);
1489 if (startCalendarTime.type == CALENDAR_TIME_LOCALTIME)
1491 untilCalendarTime.type = CALENDAR_TIME_LOCALTIME;
1492 untilCalendarTime.time.date.year = recurrence.GetUntil()->GetYear();
1493 untilCalendarTime.time.date.month = recurrence.GetUntil()->GetMonth();
1494 untilCalendarTime.time.date.mday = recurrence.GetUntil()->GetDay();
1498 untilCalendarTime.type = CALENDAR_TIME_UTIME;
1499 untilCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(*recurrence.GetUntil());
1502 calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
1503 calendar_record_set_caltime(eventHandle, _calendar_event.until_time, untilCalendarTime);
1508 calendar_record_set_int(eventHandle, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
1509 calendar_record_set_int(eventHandle, _calendar_event.count, recurrence.GetCounts());
1512 calendar_record_set_int(eventHandle, _calendar_event.interval, recurrence.GetInterval());
1514 switch (recurrence.GetFrequency())
1517 calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_DAILY);
1521 calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_WEEKLY);
1523 dayOfWeek = recurrence.GetDayOfWeek();
1524 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, 0, dayOfWeekString);
1525 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1527 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1532 calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_MONTHLY);
1534 if (recurrence.GetDayOfMonth() != 0)
1536 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1540 dayOfWeek = recurrence.GetDayOfWeek();
1541 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1542 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1544 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1550 calendar_record_set_int(eventHandle, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY);
1552 pByMonth.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetMonthOfYear())));
1554 if (recurrence.GetDayOfMonth() != 0)
1556 pByMonthDay.reset(_StringConverter::CopyToCharArrayN(Integer::ToString(recurrence.GetDayOfMonth())));
1560 dayOfWeek = recurrence.GetDayOfWeek();
1561 r = ConvertDayOfWeekToRRuleByDayString(dayOfWeek, recurrence.GetWeekOfMonth(), dayOfWeekString);
1562 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. day of week = %d", dayOfWeek);
1564 pByDay.reset(_StringConverter::CopyToCharArrayN(dayOfWeekString));
1570 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. frequency = %d", GetErrorMessage(E_INVALID_ARG), recurrence.GetFrequency());
1571 return E_INVALID_ARG;
1574 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, pByDay.get());
1575 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1576 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, pByMonth.get());
1577 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1578 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, pByMonthDay.get());
1579 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1585 _CalEventImpl::ConvertDayOfWeekToRRuleByDayString(int dayOfWeek, int weekOfMonth, String& byDayString) const
1587 int tmpDayOfWeek = CAL_SUNDAY;
1589 byDayString.Clear();
1590 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
1592 if (dayOfWeek & tmpDayOfWeek)
1594 if (weekOfMonth != 0)
1596 byDayString.Append(weekOfMonth);
1599 switch (tmpDayOfWeek)
1602 byDayString.Append(_RECURRENCE_KEYWORD_SUNDAY);
1605 byDayString.Append(_RECURRENCE_KEYWORD_MONDAY);
1608 byDayString.Append(_RECURRENCE_KEYWORD_TUESDAY);
1611 byDayString.Append(_RECURRENCE_KEYWORD_WEDNESDAY);
1614 byDayString.Append(_RECURRENCE_KEYWORD_THURSDAY);
1617 byDayString.Append(_RECURRENCE_KEYWORD_FRIDAY);
1620 byDayString.Append(_RECURRENCE_KEYWORD_SATURDAY);
1623 byDayString.Append(_RECURRENCE_DELIMITER);
1629 byDayString.Remove(byDayString.GetLength() - 1, _RECURRENCE_DELIMITER_LENGTH);
1635 _CalEventImpl::GetCalendarId(void) const
1637 int srcCalendarbookId = 0;
1639 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.calendar_book_id, &srcCalendarbookId);
1641 return srcCalendarbookId;
1645 _CalEventImpl::GetBaseEventId(void) const
1647 int srcBaseEventId = INVALID_RECORD_ID;
1649 calendar_record_get_int(__eventRecord.GetHandle(), _calendar_event.original_event_id, &srcBaseEventId);
1651 return srcBaseEventId;
1655 _CalEventImpl::SetOriginalCalEventId(RecordId originalEventId)
1657 __originalEventId = originalEventId;
1658 __isInstance = true;
1662 _CalEventImpl::GetAttendeeIndex(const char* pAttendeeEmail)
1664 int index = _INVALID_ATTENDEE_INDEX;
1665 unsigned int attendeeCount = 0;
1667 calendar_record_get_child_record_count(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, &attendeeCount);
1669 calendar_record_h tmpAttendeeHandle = null;
1670 char* pTmpAttendeeEmail = null;
1671 for (unsigned int i = 0; i < attendeeCount; i++)
1673 calendar_record_get_child_record_at_p(__eventRecord.GetHandle(), _calendar_event.calendar_attendee, i, &tmpAttendeeHandle);
1674 calendar_record_get_str_p(tmpAttendeeHandle, _calendar_attendee.email, &pTmpAttendeeEmail);
1676 if (strcmp(pAttendeeEmail, pTmpAttendeeEmail) == 0)
1687 _CalEventImpl::VerifyRecurrence(const Recurrence& recurrence)
1689 const DateTime* pUntil = recurrence.GetUntil();
1690 RecurFrequency frequency = recurrence.GetFrequency();
1691 int durationLimit = 0;
1692 int interval = recurrence.GetInterval();
1694 DateTime startTime = GetStartTime();
1695 DateTime endTime = GetEndTime();
1696 EventCategory category = GetCategory();
1700 SysTryReturnResult(NID_SCL, startTime <= *pUntil, E_INVALID_CONDITION, "The until date of recurrence is earlier than start date.");
1703 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1705 if (category == EVENT_CATEGORY_ANNIVERSARY)
1707 SysTryReturnResult(NID_SCL, frequency == FREQ_YEARLY, E_TYPE_MISMATCH
1708 , "The recurrence pattern is not a yearly pattern in case of the event being an Anniversary.");
1712 if (frequency == FREQ_DAILY)
1714 durationLimit = _TERM_LIMIT_DAILY * interval;
1716 else if (frequency == FREQ_WEEKLY)
1718 SysTryReturnResult(NID_SCL, recurrence.GetDayOfWeek() != 0, E_INVALID_ARG, "Invalid argument is used. The day of week is not set.");
1719 durationLimit = _TERM_LIMIT_WEEKLY * interval;
1721 else if (frequency == FREQ_MONTHLY)
1723 SysTryReturnResult(NID_SCL, recurrence.GetDayOfMonth() != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1724 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1725 durationLimit = _TERM_LIMIT_MONTHLY * interval;
1727 else if (frequency == FREQ_YEARLY)
1729 int dayOfMonth = recurrence.GetDayOfMonth();
1730 int monthOfYear = recurrence.GetMonthOfYear();
1731 SysTryReturnResult(NID_SCL, monthOfYear != 0, E_INVALID_ARG, "Invalid argument is used. The month of year is not set.");
1732 SysTryReturnResult(NID_SCL, dayOfMonth != 0 || (recurrence.GetDayOfWeek() != 0 && recurrence.GetWeekOfMonth() != 0)
1733 , E_INVALID_ARG, "Invalid argument is used. The day of month or day of week/week of month is not set.");
1735 SysTryReturnResult(NID_SCL, monthOfYear != 2 || dayOfMonth < 30
1736 , E_INVALID_ARG, "Invalid argument is used. If the frequency is yearly, the max days of the February is less than 30.");
1737 if (dayOfMonth > 30)
1739 SysTryReturnResult(NID_SCL, monthOfYear != 4 && monthOfYear != 6 && monthOfYear != 9 && monthOfYear != 11
1740 , 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.");
1743 durationLimit = _TERM_LIMIT_YEARLY * interval;
1746 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1747 SysTryReturnResult(NID_SCL, duration.GetDays() <= durationLimit, E_INVALID_CONDITION
1748 , "The duration of the event is greater than (interval x frequency) days. duration days = %d", duration.GetDays());
1754 _CalEventImpl::ResetStartAndEndTimeByRecurrence(const Recurrence& recurrence)
1759 bool isAllDay = IsAllDayEvent();
1760 Locales::TimeZone timeZone;
1764 timeZone = GetTimeZone();
1765 startTime = timeZone.UtcTimeToWallTime(GetStartTime());
1766 endTime = timeZone.UtcTimeToWallTime(GetEndTime());
1770 startTime = GetStartTime();
1771 endTime = GetEndTime();
1774 DateTime calculatedStartTime(startTime);
1775 DateTime calculatedEndTime(endTime);
1776 RecurFrequency frequency = recurrence.GetFrequency();
1777 int interval = recurrence.GetInterval();
1778 int dayOfMonth = recurrence.GetDayOfMonth();
1779 int dayOfWeek = recurrence.GetDayOfWeek();
1780 int weekOfMonth = recurrence.GetWeekOfMonth();
1781 int monthOfYear = recurrence.GetMonthOfYear();
1782 CalDayOfWeek weekStart = recurrence.GetWeekStart();
1783 CalDayOfWeek weekEnd = CAL_SATURDAY;
1785 TimeSpan duration = endTime.GetTime() - startTime.GetTime();
1787 if (weekStart == CAL_MONDAY)
1789 weekEnd = CAL_SUNDAY;
1792 if (recurrence.GetUntil() != null)
1794 until = *(recurrence.GetUntil());
1797 until = timeZone.UtcTimeToWallTime(until);
1802 until = _CalendarbookImpl::GetMaxDateTime();
1805 CalDayOfWeek dayOfStartTime = GetDayOfWeek(startTime, timeZone);
1807 if (frequency == FREQ_WEEKLY)
1811 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
1813 if ((dayOfStartTime & dayOfWeek) != 0)
1818 if ((dayOfStartTime & weekEnd) != 0)
1820 count += (interval - 1) * _NUMBER_OF_DAYS_OF_WEEK;
1823 dayOfStartTime = GetNextDayOfWeek(dayOfStartTime);
1827 result r = calculatedStartTime.AddDays(count);
1828 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1829 r = calculatedEndTime.AddDays(count);
1830 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "[%s][Propagating]", GetErrorMessage(r));
1833 else if (frequency == FREQ_MONTHLY)
1835 if (dayOfMonth != 0)
1837 bool isDone = false;
1838 while (calculatedStartTime <= until)
1840 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1842 if (calculatedStartTime >= startTime)
1848 calculatedStartTime.AddMonths(interval);
1850 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1851 calculatedEndTime = calculatedStartTime;
1852 calculatedEndTime.Add(duration);
1856 bool isDone = false;
1858 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1859 while (calculatedStartTime <= until)
1861 for (int i = 0; i < dayCount; i++)
1863 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), calculatedStartTime.GetMonth(), weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1864 if (calculatedStartTime >= startTime)
1869 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1875 calculatedStartTime.AddMonths(interval);
1878 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1879 calculatedEndTime = calculatedStartTime;
1880 calculatedEndTime.Add(duration);
1883 else if (frequency == FREQ_YEARLY)
1885 if (dayOfMonth != 0)
1887 bool isDone = false;
1888 while (calculatedStartTime <= until)
1890 if (calculatedStartTime.SetValue(calculatedStartTime.GetYear(), monthOfYear, dayOfMonth, calculatedStartTime.GetHour(), calculatedStartTime.GetMinute(), calculatedStartTime.GetSecond()) == E_SUCCESS)
1892 if (calculatedStartTime >= startTime)
1898 calculatedStartTime.AddYears(interval);
1900 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1901 calculatedEndTime = calculatedStartTime;
1902 calculatedEndTime.Add(duration);
1906 bool isDone = false;
1908 CalDayOfWeek tmpDayOfWeek = GetFirstDay(weekStart, dayOfWeek, dayCount);
1909 while (calculatedStartTime <= until)
1911 for (int i = 0; i < dayCount; i++)
1913 calculatedStartTime = GetDate(calculatedStartTime.GetYear(), monthOfYear, weekOfMonth, tmpDayOfWeek, calculatedStartTime, timeZone);
1914 if (calculatedStartTime >= startTime)
1919 tmpDayOfWeek = GetNextDay(dayOfWeek, tmpDayOfWeek);
1925 calculatedStartTime.AddYears(interval);
1928 SysTryReturnResult(NID_SCL, isDone, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1929 calculatedEndTime = calculatedStartTime;
1930 calculatedEndTime.Add(duration);
1936 calculatedStartTime = timeZone.WallTimeToUtcTime(calculatedStartTime);
1937 calculatedEndTime = timeZone.WallTimeToUtcTime(calculatedEndTime);
1940 SysTryReturnResult(NID_SCL, calculatedStartTime <= until, E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1941 SysTryReturnResult(NID_SCL, calculatedEndTime <= _CalendarbookImpl::GetMaxDateTime(), E_INVALID_ARG, "Invalid argument is used. There is no instance of the recurrence.");
1943 SysLog(NID_SCL, "Reset start time : %S", calculatedStartTime.ToString().GetPointer());
1944 SetStartAndEndTimeCommon(calculatedStartTime, calculatedEndTime);
1950 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeek(const String& byDay) const
1955 SysTryReturn(NID_SCL, !byDay.IsEmpty(), 0, E_INVALID_ARG, "[%s] Invalid argument is used. The byDay is empty.", GetErrorMessage(E_INVALID_ARG));
1957 String delim(_RECURRENCE_DELIMITER);
1960 StringTokenizer strTok(byDay, delim);
1961 while (strTok.HasMoreTokens())
1963 result r = strTok.GetNextToken(token);
1964 SysTryReturn(NID_SCL, r == E_SUCCESS, 0, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1966 if (token == String(_RECURRENCE_KEYWORD_SUNDAY))
1968 dayOfWeek |= CAL_SUNDAY;
1970 else if (token == String(_RECURRENCE_KEYWORD_MONDAY))
1972 dayOfWeek |= CAL_MONDAY;
1974 else if (token == String(_RECURRENCE_KEYWORD_TUESDAY))
1976 dayOfWeek |= CAL_TUESDAY;
1978 else if (token == String(_RECURRENCE_KEYWORD_WEDNESDAY))
1980 dayOfWeek |= CAL_WEDNESDAY;
1982 else if (token == String(_RECURRENCE_KEYWORD_THURSDAY))
1984 dayOfWeek |= CAL_THURSDAY;
1986 else if (token == String(_RECURRENCE_KEYWORD_FRIDAY))
1988 dayOfWeek |= CAL_FRIDAY;
1990 else if (token == String(_RECURRENCE_KEYWORD_SATURDAY))
1992 dayOfWeek |= CAL_SATURDAY;
1996 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. byday = %S", GetErrorMessage(E_INVALID_ARG), byDay.GetPointer());
2005 _CalEventImpl::ConvertRRuleByDayStringToDayOfWeekAndWeekOfMonth(const String& byDay, int& weekOfMonth, int& dayOfWeek) const
2007 String delim(_RECURRENCE_DELIMITER);
2009 wchar_t tmpChar = 0;
2010 int tmpWeekOfMonth = 0;
2011 int weekStringStartIndex = 0;
2017 SysTryReturnResult(NID_SCL, !byDay.IsEmpty(), E_INVALID_ARG, "Invalid argument is passed. The byDay is empty.");
2019 StringTokenizer strTok(byDay, delim);
2021 while (strTok.HasMoreTokens())
2023 result r = strTok.GetNextToken(token);
2024 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
2026 r = token.GetCharAt(_RECURRENCE_BY_DAY_FIRST_INDEX, tmpChar);
2027 if (tmpChar == _RECURRENCE_BY_DAY_CHAR_MINUS)
2029 SysTryReturnResult(NID_SCL, weekOfMonth == 0 || weekOfMonth == _MAX_WEEK_OF_MONTH
2030 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2032 if (weekOfMonth == 0)
2035 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2036 SysTryReturnResult(NID_SCL, tmpChar == _RECURRENCE_BY_DAY_CHAR_ONE
2037 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2039 weekOfMonth = _MAX_WEEK_OF_MONTH;
2041 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2043 else if (tmpChar == _RECURRENCE_BY_DAY_CHAR_PLUS)
2045 if (weekOfMonth == 0)
2048 r = token.GetCharAt(_RECURRENCE_BY_DAY_SECOND_INDEX, tmpChar);
2049 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2050 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_MONTH
2051 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2053 weekOfMonth = tmpWeekOfMonth;
2057 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2058 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2061 weekStringStartIndex = _RECURRENCE_BY_DAY_SECOND_INDEX + 1;
2065 if (weekOfMonth == 0)
2067 tmpWeekOfMonth = Character::ToDigit(tmpChar, Character::RADIX_DECIMAL);
2068 SysTryReturnResult(NID_SCL, tmpWeekOfMonth > 0 && tmpWeekOfMonth <= _MAX_WEEK_OF_MONTH
2069 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2071 weekOfMonth = tmpWeekOfMonth;
2075 SysTryReturnResult(NID_SCL, weekOfMonth == tmpWeekOfMonth
2076 , E_INVALID_ARG, "Invalid argument is passed. byday = %S", byDay.GetPointer());
2079 weekStringStartIndex = _RECURRENCE_BY_DAY_FIRST_INDEX + 1;
2082 token.SubString(weekStringStartIndex, tmpString);
2084 if (tmpString == String(_RECURRENCE_KEYWORD_SUNDAY))
2086 dayOfWeek |= CAL_SUNDAY;
2088 else if (tmpString == String(_RECURRENCE_KEYWORD_MONDAY))
2090 dayOfWeek |= CAL_MONDAY;
2092 else if (tmpString == String(_RECURRENCE_KEYWORD_TUESDAY))
2094 dayOfWeek |= CAL_TUESDAY;
2096 else if (tmpString == String(_RECURRENCE_KEYWORD_WEDNESDAY))
2098 dayOfWeek |= CAL_WEDNESDAY;
2100 else if (tmpString == String(_RECURRENCE_KEYWORD_THURSDAY))
2102 dayOfWeek |= CAL_THURSDAY;
2104 else if (tmpString == String(_RECURRENCE_KEYWORD_FRIDAY))
2106 dayOfWeek |= CAL_FRIDAY;
2108 else if (tmpString == String(_RECURRENCE_KEYWORD_SATURDAY))
2110 dayOfWeek |= CAL_SATURDAY;
2114 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. byday = %S", GetErrorMessage(E_INVALID_ARG), byDay.GetPointer());
2122 _CalEventImpl::ConvertRRuleExDateStringToRecurrence(const String& exdate, Recurrence& recurrence) const
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 result 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 bool isNotFirst = false;
2158 String exdateString;
2160 std::unique_ptr<IList, AllElementsDeleter> pExDateList(recurrence.GetExceptionDatesN());
2162 std::unique_ptr<IEnumerator> pEnum(pExDateList->GetEnumeratorN());
2163 while (pEnum->MoveNext() == E_SUCCESS)
2165 DateTime* pDateTime = static_cast<DateTime*>(pEnum->GetCurrent());
2169 exdateString.Append(_RECURRENCE_DELIMITER);
2172 exdateString.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(*pDateTime, isDate));
2177 return exdateString;
2181 _CalEventImpl::GetNextDayOfWeek(CalDayOfWeek currentDay)
2183 int tmpDay = currentDay;
2186 if (tmpDay > CAL_SATURDAY)
2188 tmpDay = CAL_SUNDAY;
2191 return static_cast<CalDayOfWeek>(tmpDay);
2195 _CalEventImpl::GetDate(int year, int month, int weekOfMonth, CalDayOfWeek dayOfWeek, const DateTime& time, const TimeZone& timeZone)
2199 Tizen::Locales::DayOfWeek dayOfWeekByGregorianCalendar = Tizen::Locales::DAY_OF_WEEK_UNDEFINED;
2204 dayOfWeekByGregorianCalendar = Tizen::Locales::SUNDAY;
2208 dayOfWeekByGregorianCalendar = Tizen::Locales::MONDAY;
2212 dayOfWeekByGregorianCalendar = Tizen::Locales::TUESDAY;
2216 dayOfWeekByGregorianCalendar = Tizen::Locales::WEDNESDAY;
2220 dayOfWeekByGregorianCalendar = Tizen::Locales::THURSDAY;
2224 dayOfWeekByGregorianCalendar = Tizen::Locales::FRIDAY;
2228 dayOfWeekByGregorianCalendar = Tizen::Locales::SATURDAY;
2235 std::unique_ptr<Tizen::Locales::Calendar> pGregorianCalendar(Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN));
2236 SysTryReturn(NID_SCL, pGregorianCalendar != null, DateTime(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2238 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
2239 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
2240 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH, 1);
2242 Tizen::Locales::DayOfWeek tmpDayOfWeek = static_cast<Tizen::Locales::DayOfWeek>(pGregorianCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK));
2243 int maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(TIME_FIELD_DAY_OF_MONTH);
2244 int tmpDayOfMonth = ((_NUMBER_OF_DAYS_OF_WEEK + dayOfWeekByGregorianCalendar) - tmpDayOfWeek) % _NUMBER_OF_DAYS_OF_WEEK + 1;
2246 tmpDayOfMonth += ((weekOfMonth - 1) * _NUMBER_OF_DAYS_OF_WEEK);
2247 if (tmpDayOfMonth > maxDaysOfMonth)
2249 tmpDayOfMonth -= _NUMBER_OF_DAYS_OF_WEEK;
2252 DateTime resultTime;
2253 resultTime.SetValue(year, month, tmpDayOfMonth, time.GetHour(), time.GetMinute(), time.GetSecond());
2259 _CalEventImpl::GetDayOfWeek(const DateTime& date, const Locales::TimeZone& timeZone)
2263 CalDayOfWeek dayOfWeek = CAL_SUNDAY;
2265 std::unique_ptr<Tizen::Locales::Calendar> pGregorianCalendar(Tizen::Locales::Calendar::CreateInstanceN(timeZone, Tizen::Locales::CALENDAR_GREGORIAN));
2266 SysTryReturn(NID_SCL, pGregorianCalendar != null, dayOfWeek, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2268 pGregorianCalendar->SetTime(date);
2269 int dayOfWeekByGregorianCalendar = pGregorianCalendar->GetTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_WEEK);
2271 switch (dayOfWeekByGregorianCalendar)
2273 case Tizen::Locales::SUNDAY:
2274 dayOfWeek = CAL_SUNDAY;
2277 case Tizen::Locales::MONDAY:
2278 dayOfWeek = CAL_MONDAY;
2281 case Tizen::Locales::TUESDAY:
2282 dayOfWeek = CAL_TUESDAY;
2285 case Tizen::Locales::WEDNESDAY:
2286 dayOfWeek = CAL_WEDNESDAY;
2289 case Tizen::Locales::THURSDAY:
2290 dayOfWeek = CAL_THURSDAY;
2293 case Tizen::Locales::FRIDAY:
2294 dayOfWeek = CAL_FRIDAY;
2297 case Tizen::Locales::SATURDAY:
2298 dayOfWeek = CAL_SATURDAY;
2309 _CalEventImpl::GetFirstDay(CalDayOfWeek weekStart, int dayOfWeek, int& count)
2312 int tmpDay = weekStart;
2315 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
2317 if ((tmpDay & dayOfWeek) != 0)
2327 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2330 return static_cast<CalDayOfWeek>(firstDay);
2334 _CalEventImpl::GetNextDay(int dayOfWeek, CalDayOfWeek currentDay)
2336 int tmpDay = currentDay;
2338 for (int i = 0; i < _NUMBER_OF_DAYS_OF_WEEK; i++)
2340 tmpDay = GetNextDayOfWeek(static_cast<CalDayOfWeek>(tmpDay));
2342 if ((tmpDay & dayOfWeek) != 0)
2348 return static_cast<CalDayOfWeek>(tmpDay);
2352 _CalEventImpl::SetRecordHandle(calendar_record_h eventHandle)
2354 __eventRecord.ResetHandle(eventHandle);
2358 _CalEventImpl::GetRecordHandle(void) const
2360 return __eventRecord.GetHandle();
2364 _CalEventImpl::CreateDefaultInstanceN(void)
2366 return new (std::nothrow) CalEvent();
2370 _CalEventImpl::GetInstance(CalEvent& event)
2372 return event.__pCalEventImpl;
2375 const _CalEventImpl*
2376 _CalEventImpl::GetInstance(const CalEvent& event)
2378 return event.__pCalEventImpl;