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