Modify the spec file for secure log
[framework/osp/social.git] / src / FScl_CalTodoImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 /**
17  * @file                FScl_CalTodoImpl.cpp
18  * @brief               This is the implementation for _CalTodoImpl class.
19  *
20  * This file contains definitions of @e CalTodoImpl class.
21  */
22
23 #include <FApp_AppInfo.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseSysLog.h>
27 #include <FBase_StringConverter.h>
28 #include <FSclCalTodo.h>
29 #include <FSclRecord.h>
30 #include <FSclReminder.h>
31 #include <FSclRecurrence.h>
32 #include <FSysSystemTime.h>
33 #include <FSclTypes.h>
34 #include "FScl_CalendarbookDbConnector.h"
35 #include "FScl_CalendarbookImpl.h"
36 #include "FScl_CalTodoImpl.h"
37 #include "FScl_RecordImpl.h"
38
39 using namespace Tizen::App;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42
43 namespace Tizen { namespace Social
44 {
45 static const double _MIN_LATITUDE = -90.0;
46 static const double _MAX_LATITUDE = 90.0;
47 static const double _MIN_LONGITUDE = -180.0;
48 static const double _MAX_LONGITUDE = 180.0;
49
50 static const long long _CALENDAR_TODO_NO_START_DATE = -0x7fffffffffffffffLL;
51 static const long long _CALENDAR_TODO_NO_DUE_DATE = 0x7fffffffffffffffLL;
52
53 _CalTodoImpl::_CalTodoImpl(void)
54         : __reminderListUpdated(false)
55 {
56         calendar_record_h todoHandle = null;
57
58         result r = _CalendarbookDbConnector::Connect();
59         SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
60
61         int errorCode = calendar_record_create(_calendar_todo._uri, &todoHandle);
62         SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
63
64         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
65         {
66                 DateTime tmpDateTime;
67
68                 // Set start date to current date
69                 Tizen::System::SystemTime::GetCurrentTime(tmpDateTime);
70                 if (IsFailed(GetLastResult()))
71                 {
72                         tmpDateTime = _CalendarbookImpl::GetMinDateTime();
73                         ClearLastResult();
74                 }
75                 tmpDateTime.SetValue(tmpDateTime.GetYear(), tmpDateTime.GetMonth(), tmpDateTime.GetDay(), 0, 0, 0);
76
77                 calendar_time_s convertedCalendarTime;
78
79                 convertedCalendarTime.type = CALENDAR_TIME_UTIME;
80                 convertedCalendarTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(tmpDateTime);
81
82                 calendar_record_set_caltime(todoHandle, _calendar_todo.start_time, convertedCalendarTime);
83                 calendar_record_set_caltime(todoHandle, _calendar_todo.due_time, convertedCalendarTime);
84         }
85         else
86         {
87                 calendar_time_s convertedStartTime;
88                 convertedStartTime.type = CALENDAR_TIME_UTIME;
89                 convertedStartTime.time.utime = _CALENDAR_TODO_NO_START_DATE;
90
91                 calendar_time_s convertedDueTime;
92                 convertedDueTime.type = CALENDAR_TIME_UTIME;
93                 convertedDueTime.time.utime = _CALENDAR_TODO_NO_DUE_DATE;
94
95                 calendar_record_set_caltime(todoHandle, _calendar_todo.start_time, convertedStartTime);
96                 calendar_record_set_caltime(todoHandle, _calendar_todo.due_time, convertedDueTime);
97         }
98
99         // default value
100         calendar_record_set_int(todoHandle, _calendar_todo.todo_status, CALENDAR_TODO_STATUS_NONE);
101         calendar_record_set_int(todoHandle, _calendar_todo.priority, CALENDAR_TODO_PRIORITY_NORMAL);
102         calendar_record_set_int(todoHandle, _calendar_todo.sensitivity, CALENDAR_SENSITIVITY_PUBLIC);
103         calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, INVALID_RECORD_ID);
104
105         __todoRecord.ResetHandle(todoHandle);
106
107         r = __reminderList.Construct();
108         SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
109 }
110
111 _CalTodoImpl::_CalTodoImpl(const _CalTodoImpl& rhs)
112         : __reminderListUpdated(false)
113 {
114         calendar_record_h todoHandle = null;
115
116         result r = _CalendarbookDbConnector::Connect();
117         SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
118
119         int errorCode = calendar_record_clone(rhs.__todoRecord.GetHandle(), &todoHandle);
120         SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
121
122         __todoRecord.ResetHandle(todoHandle);
123
124         r = __reminderList.Construct();
125         SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
126 }
127
128 _CalTodoImpl::~_CalTodoImpl(void)
129 {
130         __reminderList.RemoveAll(true);
131
132         result r = _CalendarbookDbConnector::Disconnect();
133         SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
134 }
135
136 _CalTodoImpl&
137 _CalTodoImpl::operator =(const _CalTodoImpl& rhs)
138 {
139         if (this == &rhs)
140         {
141                 return *this;
142         }
143
144         __reminderList.RemoveAll(true);
145         __reminderListUpdated = false;
146
147         calendar_record_h todoHandle = null;
148
149         int errorCode = calendar_record_clone(rhs.__todoRecord.GetHandle(), &todoHandle);
150         SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
151
152         __todoRecord.ResetHandle(todoHandle);
153
154         return *this;
155 }
156
157 String
158 _CalTodoImpl::GetSubject(void) const
159 {
160         char* pSubject = null;
161
162         calendar_record_get_str_p(__todoRecord.GetHandle(), _calendar_todo.summary, &pSubject);
163
164         return String(pSubject);
165 }
166
167 String
168 _CalTodoImpl::GetDescription(void) const
169 {
170         char* pDescription = null;
171
172         calendar_record_get_str_p(__todoRecord.GetHandle(), _calendar_todo.description, &pDescription);
173
174         return String(pDescription);
175 }
176
177 DateTime
178 _CalTodoImpl::GetStartDate(void) const
179 {
180         ClearLastResult();
181
182         calendar_time_s tmpCalendarTime;
183
184         calendar_record_get_caltime(__todoRecord.GetHandle(), _calendar_todo.start_time, &tmpCalendarTime);
185
186         if (tmpCalendarTime.time.utime == _CALENDAR_TODO_NO_START_DATE)
187         {
188                 SetLastResult(E_DATA_NOT_FOUND);
189                 return DateTime::GetMinValue();
190         }
191
192         DateTime tmpDateTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpCalendarTime.time.utime);
193
194         return tmpDateTime;
195 }
196
197 DateTime
198 _CalTodoImpl::GetDueDate(void) const
199 {
200         ClearLastResult();
201
202         calendar_time_s tmpCalendarTime;
203
204         calendar_record_get_caltime(__todoRecord.GetHandle(), _calendar_todo.due_time, &tmpCalendarTime);
205
206         if (tmpCalendarTime.time.utime == _CALENDAR_TODO_NO_DUE_DATE)
207         {
208                 SetLastResult(E_DATA_NOT_FOUND);
209                 return DateTime::GetMinValue();
210         }
211
212         DateTime tmpDateTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpCalendarTime.time.utime);
213
214         return tmpDateTime;
215 }
216
217 TodoPriority
218 _CalTodoImpl::GetPriority(void) const
219 {
220         int srcPriority = CALENDAR_EVENT_PRIORITY_LOW;
221
222         TodoPriority priority = TODO_PRIORITY_NORMAL;
223
224         calendar_record_get_int(__todoRecord.GetHandle(), _calendar_todo.priority, &srcPriority);
225
226         switch (srcPriority)
227         {
228         case CALENDAR_TODO_PRIORITY_LOW:
229                 priority = TODO_PRIORITY_LOW;
230                 break;
231
232         case CALENDAR_TODO_PRIORITY_NONE:
233                 // fall through
234         case CALENDAR_TODO_PRIORITY_NORMAL:
235                 priority = TODO_PRIORITY_NORMAL;
236                 break;
237
238         case CALENDAR_TODO_PRIORITY_HIGH:
239                 priority = TODO_PRIORITY_HIGH;
240                 break;
241
242         default:
243                 SysLog(NID_SCL, "The priority value is invalid. priority = %d", srcPriority);
244                 priority = TODO_PRIORITY_NORMAL;
245                 break;
246         }
247
248         return priority;
249 }
250
251 TodoStatus
252 _CalTodoImpl::GetStatus(void) const
253 {
254         int srcStatus = CALENDAR_EVENT_STATUS_NONE;
255
256         TodoStatus status = TODO_STATUS_NONE;
257
258         calendar_record_get_int(__todoRecord.GetHandle(), _calendar_todo.todo_status, &srcStatus);
259
260         switch (srcStatus)
261         {
262         case CALENDAR_TODO_STATUS_NONE:
263                 status = TODO_STATUS_NONE;
264                 break;
265
266         case CALENDAR_TODO_STATUS_NEEDS_ACTION:
267                 status = TODO_STATUS_NEEDS_ACTION;
268                 break;
269
270         case CALENDAR_TODO_STATUS_COMPLETED:
271                 status = TODO_STATUS_COMPLETED;
272                 break;
273
274         case CALENDAR_TODO_STATUS_IN_PROCESS:
275                 status = TODO_STATUS_IN_PROCESS;
276                 break;
277
278         case CALENDAR_TODO_STATUS_CANCELED:
279                 status = TODO_STATUS_CANCELLED;
280                 break;
281
282         default:
283                 SysLog(NID_SCL, "The status value is invalid. status = %d", srcStatus);
284                 status = TODO_STATUS_NONE;
285                 break;
286         }
287
288         return status;
289 }
290
291 RecordSensitivity
292 _CalTodoImpl::GetSensitivity(void) const
293 {
294         int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
295         RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
296
297         calendar_record_get_int(__todoRecord.GetHandle(), _calendar_todo.sensitivity, &srcSensitivity);
298
299         switch (srcSensitivity)
300         {
301         case CALENDAR_SENSITIVITY_PUBLIC:
302                 sensitivity = SENSITIVITY_PUBLIC;
303                 break;
304
305         case CALENDAR_SENSITIVITY_PRIVATE:
306                 sensitivity = SENSITIVITY_PRIVATE;
307                 break;
308
309         case CALENDAR_SENSITIVITY_CONFIDENTIAL:
310                 sensitivity = SENSITIVITY_CONFIDENTIAL;
311                 break;
312
313         default:
314                 SysLog(NID_SCL, "The sensitivity value is invalid. sensitivity = %d", srcSensitivity);
315                 sensitivity = SENSITIVITY_PUBLIC;
316                 break;
317         }
318
319         return sensitivity;
320 }
321
322 DateTime
323 _CalTodoImpl::GetLastRevisedTime(void) const
324 {
325         long long lastModifiedTime = 0;
326
327         calendar_record_get_lli(__todoRecord.GetHandle(), _calendar_todo.last_modified_time, &lastModifiedTime);
328
329         return _CalendarbookUtil::ConvertEpochTimeToDateTime(lastModifiedTime);
330 }
331
332 result
333 _CalTodoImpl::SetSubject(const String& subject)
334 {
335         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
336         {
337                 SysTryReturnResult(NID_SCL, subject.GetLength() <= MAX_TODO_SUBJECT_LENGTH,
338                                         E_INVALID_ARG, "Invalid argument is used. The length of the subject exceeds MAX_TODO_SUBJECT_LENGTH.");
339         }
340
341         std::unique_ptr<char[]> pConvertedSubject(_StringConverter::CopyToCharArrayN(subject));
342         SysTryReturnResult(NID_SCL, pConvertedSubject != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
343
344         int errorCode = calendar_record_set_str(__todoRecord.GetHandle(), _calendar_todo.summary, pConvertedSubject.get());
345         SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
346
347         return E_SUCCESS;
348 }
349
350 result
351 _CalTodoImpl::SetDescription(const String& description)
352 {
353         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
354         {
355                 SysTryReturnResult(NID_SCL, description.GetLength() <= MAX_TODO_DESCRIPTION_LENGTH,
356                                         E_INVALID_ARG, "Invalid argument is used. The length of the description exceeds MAX_TODO_SUBJECT_LENGTH.");
357         }
358
359         std::unique_ptr<char[]> pConvertedDescription(_StringConverter::CopyToCharArrayN(description));
360         SysTryReturnResult(NID_SCL, pConvertedDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
361
362         int errorCode = calendar_record_set_str(__todoRecord.GetHandle(), _calendar_todo.description, pConvertedDescription.get());
363         SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
364
365         return E_SUCCESS;
366 }
367
368 result
369 _CalTodoImpl::SetStartAndDueDate(const DateTime& startDate, const DateTime& dueDate)
370 {
371         SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(startDate), E_INVALID_ARG, "Invalid argument is used. The start date is invalid.");
372         SysTryReturnResult(NID_SCL, _CalendarbookUtil::CheckValidDateTime(dueDate), E_INVALID_ARG, "Invalid argument is used. The end date is invalid.");
373         SysTryReturnResult(NID_SCL, startDate <= dueDate, E_INVALID_ARG, "Invalid argument is used. The end date is earlier than the start date.");
374
375         calendar_time_s convertedStartTime;
376         calendar_time_s convertedDueTime;
377
378         convertedStartTime.type = CALENDAR_TIME_UTIME;
379         convertedStartTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(startDate);
380         convertedDueTime.type = CALENDAR_TIME_UTIME;
381         convertedDueTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(dueDate);
382
383         calendar_record_set_caltime(__todoRecord.GetHandle(), _calendar_todo.start_time, convertedStartTime);
384         calendar_record_set_caltime(__todoRecord.GetHandle(), _calendar_todo.due_time, convertedDueTime);
385
386         return E_SUCCESS;
387 }
388
389 result
390 _CalTodoImpl::SetStartDate(const DateTime& startDate)
391 {
392         calendar_time_s convertedStartTime;
393         convertedStartTime.type = CALENDAR_TIME_UTIME;
394
395         if (startDate == DateTime::GetMinValue())
396         {
397                 convertedStartTime.time.utime = _CALENDAR_TODO_NO_START_DATE;
398         }
399         else if (startDate < _CalendarbookImpl::GetMinDateTime() || startDate > _CalendarbookImpl::GetMaxDateTime())
400         {
401                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used.  The startDate is invalid.", GetErrorMessage(E_INVALID_ARG));
402                 return E_INVALID_ARG;
403         }
404         else
405         {
406                 calendar_time_s convertedDueTime;
407                 calendar_record_get_caltime(__todoRecord.GetHandle(), _calendar_todo.due_time, &convertedDueTime);
408
409                 convertedStartTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(startDate);
410
411                 if (convertedStartTime.time.utime > convertedDueTime.time.utime)
412                 {
413                         convertedDueTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(DateTime::GetMinValue());
414                         calendar_record_set_caltime(__todoRecord.GetHandle(), _calendar_todo.due_time, convertedDueTime);
415                 }
416         }
417
418         calendar_record_set_caltime(__todoRecord.GetHandle(), _calendar_todo.start_time, convertedStartTime);
419
420         return E_SUCCESS;
421 }
422
423 result
424 _CalTodoImpl::SetDueDate(const DateTime& dueDate)
425 {
426         calendar_time_s convertedDueTime;
427         convertedDueTime.type = CALENDAR_TIME_UTIME;
428
429         if (dueDate == DateTime::GetMinValue())
430         {
431                 convertedDueTime.time.utime = _CALENDAR_TODO_NO_DUE_DATE;
432         }
433         else if (dueDate < _CalendarbookImpl::GetMinDateTime() || dueDate > _CalendarbookImpl::GetMaxDateTime())
434         {
435                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used.  The dueDate is invalid.", GetErrorMessage(E_INVALID_ARG));
436                 return E_INVALID_ARG;
437         }
438         else
439         {
440                 calendar_time_s convertedStartTime;
441                 calendar_record_get_caltime(__todoRecord.GetHandle(), _calendar_todo.start_time, &convertedStartTime);
442
443                 convertedDueTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(dueDate);
444
445                 if (convertedStartTime.time.utime > convertedDueTime.time.utime)
446                 {
447                         convertedStartTime.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(DateTime::GetMinValue());
448                         calendar_record_set_caltime(__todoRecord.GetHandle(), _calendar_todo.start_time, convertedStartTime);
449                 }
450         }
451
452         calendar_record_set_caltime(__todoRecord.GetHandle(), _calendar_todo.due_time, convertedDueTime);
453
454         return E_SUCCESS;
455 }
456
457 void
458 _CalTodoImpl::SetPriority(TodoPriority priority)
459 {
460         calendar_record_set_int(__todoRecord.GetHandle(), _calendar_todo.priority, _CalendarbookUtil::ConvertTodoPriorityToCSTodoPriority(priority));
461 }
462
463 void
464 _CalTodoImpl::SetStatus(TodoStatus status)
465 {
466         calendar_record_set_int(__todoRecord.GetHandle(), _calendar_todo.todo_status, _CalendarbookUtil::ConvertTodoStatusToCSTodoStatus(status));
467 }
468
469 void
470 _CalTodoImpl::SetSensitivity(RecordSensitivity sensitivity)
471 {
472         calendar_record_set_int(__todoRecord.GetHandle(), _calendar_todo.sensitivity, _CalendarbookUtil::ConvertSensitivityToCSSensitivity(sensitivity));
473 }
474
475 void
476 _CalTodoImpl::SetLocation(const String& location)
477 {
478         std::unique_ptr<char[]> pConvertedLocation(_StringConverter::CopyToCharArrayN(location));
479         SysTryReturnVoidResult(NID_SCL, pConvertedLocation != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
480
481         int errorCode = calendar_record_set_str(__todoRecord.GetHandle(), _calendar_todo.location, pConvertedLocation.get());
482         SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
483 }
484
485 String
486 _CalTodoImpl::GetLocation(void) const
487 {
488         char* pLocation = null;
489
490         calendar_record_get_str_p(__todoRecord.GetHandle(), _calendar_todo.location, &pLocation);
491
492         return String(pLocation);
493 }
494
495 result
496 _CalTodoImpl::SetCoordinates(double latitude, double longitude)
497 {
498         SysTryReturnResult(NID_SCL, latitude >= _MIN_LATITUDE && latitude <= _MAX_LATITUDE, E_INVALID_ARG, "Invalid argument is used. The latitude is out of range.");
499         SysTryReturnResult(NID_SCL, longitude >= _MIN_LONGITUDE && longitude <= _MAX_LONGITUDE, E_INVALID_ARG, "Invalid argument is used. The longitude is out of range.");
500
501         calendar_record_set_double(__todoRecord.GetHandle(), _calendar_todo.latitude, latitude);
502         calendar_record_set_double(__todoRecord.GetHandle(), _calendar_todo.longitude, longitude);
503
504         return E_SUCCESS;
505 }
506
507 void
508 _CalTodoImpl::GetCoordinates(double& latitude, double& longitude) const
509 {
510         calendar_record_get_double(__todoRecord.GetHandle(), _calendar_todo.latitude, &latitude);
511         calendar_record_get_double(__todoRecord.GetHandle(), _calendar_todo.longitude, &longitude);
512 }
513
514 result
515 _CalTodoImpl::AddReminder(const Reminder& reminder)
516 {
517         calendar_record_h tmpAlarmHandle = null;
518
519         std::unique_ptr<char[]> pTmpAlarmTone(_StringConverter::CopyToCharArrayN(reminder.GetSoundFile()));
520         SysTryReturnResult(NID_SCL, pTmpAlarmTone != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
521
522         int errorCode = calendar_record_create(_calendar_alarm._uri, &tmpAlarmHandle);
523         SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
524
525         int convertedTimeUnit = 0;
526
527         ReminderTimeUnit timeUnit = reminder.GetTimeUnit();
528         switch (timeUnit)
529         {
530         case REMINDER_TIME_UNIT_MINUTE:
531                 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
532                 break;
533
534         case REMINDER_TIME_UNIT_HOUR:
535                 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
536                 break;
537
538         case REMINDER_TIME_UNIT_DAY:
539                 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
540                 break;
541
542         case REMINDER_TIME_UNIT_WEEK:
543                 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_WEEK;
544                 break;
545
546         case REMINDER_TIME_UNIT_NONE:
547                 convertedTimeUnit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
548                 break;
549
550         default:
551                 break;
552         }
553
554         calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick_unit, convertedTimeUnit);
555         calendar_record_set_int(tmpAlarmHandle, _calendar_alarm.tick, reminder.GetTimeOffset());
556         errorCode = calendar_record_set_str(tmpAlarmHandle, _calendar_alarm.tone, pTmpAlarmTone.get());
557         SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
558
559         if (convertedTimeUnit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC)
560         {
561                 calendar_record_set_lli(tmpAlarmHandle, _calendar_alarm.time, _CalendarbookUtil::ConvertDateTimeToEpochTime(reminder.GetAbsoluteTime()));
562         }
563
564         errorCode = calendar_record_add_child_record(__todoRecord.GetHandle(), _calendar_todo.calendar_alarm, tmpAlarmHandle);
565         SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
566
567         __reminderList.RemoveAll(true);
568         __reminderListUpdated = false;
569
570         return E_SUCCESS;
571 }
572
573 result
574 _CalTodoImpl::RemoveReminderAt(int index)
575 {
576         calendar_record_h tmpAlarmHandle = null;
577
578         calendar_record_get_child_record_at_p(__todoRecord.GetHandle(), _calendar_todo.calendar_alarm, index, &tmpAlarmHandle);
579         SysTryReturnResult(NID_SCL, tmpAlarmHandle != null, E_OUT_OF_RANGE, "The index is either equal to or greater than the number of reminders or less than 0.");
580
581         calendar_record_remove_child_record(__todoRecord.GetHandle(), _calendar_todo.calendar_alarm, tmpAlarmHandle);
582
583         __reminderList.RemoveAll(true);
584         __reminderListUpdated = false;
585
586         return E_SUCCESS;
587 }
588
589 const IList&
590 _CalTodoImpl::GetAllReminders(void) const
591 {
592         ClearLastResult();
593
594         if (__reminderListUpdated == false)
595         {
596                 result r = _CalendarbookUtil::ConvertTodoAlarmsToReminderList(__todoRecord.GetHandle(), __reminderList);
597                 SysTryReturn(NID_SCL, r == E_SUCCESS, __reminderList, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
598
599                 __reminderListUpdated = true;
600         }
601
602         return __reminderList;
603 }
604
605 RecordId
606 _CalTodoImpl::GetCalendarId(void) const
607 {
608         int srcCalendarbookId = 0;
609
610         calendar_record_get_int(__todoRecord.GetHandle(), _calendar_todo.calendar_book_id, &srcCalendarbookId);
611
612         return srcCalendarbookId;
613 }
614
615 void
616 _CalTodoImpl::SetRecordHandle(calendar_record_h todoHandle)
617 {
618         __todoRecord.ResetHandle(todoHandle);
619 }
620
621 calendar_record_h
622 _CalTodoImpl::GetRecordHandle(void) const
623 {
624         return __todoRecord.GetHandle();
625 }
626
627 CalTodo*
628 _CalTodoImpl::CreateDefaultInstanceN(void)
629 {
630         return new (std::nothrow) CalTodo();
631 }
632
633 _CalTodoImpl*
634 _CalTodoImpl::GetInstance(CalTodo& todo)
635 {
636         return todo.__pCalTodoImpl;
637 }
638
639 const _CalTodoImpl*
640 _CalTodoImpl::GetInstance(const CalTodo& todo)
641 {
642         return todo.__pCalTodoImpl;
643 }
644
645 }}      // Tizen::Social