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_CalendarbookImpl.cpp
18 * @brief This is the implementation for _CalendarbookImpl class.
20 * This file contains definitions of @e _CalendarbookImpl class.
24 #include <unique_ptr.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColHashMapT.h>
28 #include <FBaseUtilStringUtil.h>
29 #include <FLclTimeZone.h>
31 #include <FSclCalendarbook.h>
32 #include <FSclCalEvent.h>
33 #include <FSclCalTodo.h>
34 #include <FSclCalendar.h>
35 #include <FSclCalEventInstance.h>
36 #include <FSclCalEventChangeInfo.h>
37 #include <FSclCalTodoChangeInfo.h>
38 #include <FSclIRecordEventListener.h>
39 #include <FSclIRecordListener.h>
40 #include <FSclICalendarbookEventListener.h>
41 #include <FBaseSysLog.h>
42 #include <FBase_StringConverter.h>
43 #include "FScl_CalendarbookImpl.h"
44 #include "FScl_RecordImpl.h"
45 #include "FScl_CalEventImpl.h"
46 #include "FScl_CalTodoImpl.h"
47 #include "FScl_CalendarImpl.h"
48 #include "FScl_CalEventInstanceImpl.h"
49 #include "FScl_CalEventChangeInfoImpl.h"
50 #include "FScl_CalTodoChangeInfoImpl.h"
51 #include "FScl_CalendarbookFilterImpl.h"
52 #include "FScl_CalendarbookUtil.h"
53 #include "FScl_CalendarbookDbMonitor.h"
54 #include "FScl_CalendarbookDbConnector.h"
55 #include "FScl_CalendarbookRecordRetrivalThread.h"
56 #include "FScl_CalendarbookRecordRetrivalEvent.h"
58 using namespace Tizen::Base;
59 using namespace Tizen::Base::Utility;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Io;
63 namespace Tizen { namespace Social
66 RequestId _CalendarbookImpl::__requestId = 0;
67 _CalendarbookRecordRetrivalThread* _CalendarbookImpl::__pRecordRetrivalThread = null;
69 static const int _DEFAULT_EVENT_CALENDAR_DB_ID = 1;
70 static const int _DEFAULT_TODO_CALENDAR_DB_ID = 2;
71 static const wchar_t* _RECURRENCE_DELIMITER = L",";
72 static const int _NUMBER_OF_TODO_STATUS = 5;
73 static const int _NUMBER_OF_TODO_PRIORITY = 3;
74 static const int _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION = 2;
76 static const int _INVALID_CALENDARBOOK_DB_ID = -1; // TODO : This value should be checked.
77 static const int _INVALID_EVENT_DB_ID = -1;
82 _CalendarList(calendar_list_h calendarListHandle, bool deleteRecord = true)
83 : __calendarListHandle(calendarListHandle)
84 , __deleteRecord(deleteRecord)
90 if (__calendarListHandle)
92 calendar_list_destroy(__calendarListHandle, __deleteRecord);
96 calendar_list_h GetHandle(void)
98 return __calendarListHandle;
101 calendar_list_h ReleaseHandle(void)
103 calendar_list_h calendarListHandle = __calendarListHandle;
104 __calendarListHandle = null;
105 return calendarListHandle;
109 calendar_list_h __calendarListHandle;
113 class _CalendarFilter
116 _CalendarFilter(calendar_filter_h calendarFilterHandle)
117 : __calendarFilterHandle(calendarFilterHandle)
121 ~_CalendarFilter(void)
123 if (__calendarFilterHandle)
125 calendar_filter_destroy(__calendarFilterHandle);
129 calendar_filter_h GetHandle(void)
131 return __calendarFilterHandle;
134 calendar_filter_h ReleaseHandle(void)
136 calendar_filter_h calendarFilterHandle = __calendarFilterHandle;
137 __calendarFilterHandle = null;
138 return calendarFilterHandle;
141 void ResetHandle(calendar_filter_h calendarFilterHandle)
143 if (__calendarFilterHandle)
145 calendar_filter_destroy(__calendarFilterHandle);
147 __calendarFilterHandle = calendarFilterHandle;
151 calendar_filter_h __calendarFilterHandle;
154 class _CalendarConnector
160 __r = _CalendarbookDbConnector::Connect();
163 ~_CalendarConnector(void)
165 if (__r == E_SUCCESS)
167 _CalendarbookDbConnector::Disconnect();
171 result GetResult(void)
183 _CalendarQuery(calendar_query_h calendarQueryHandle)
184 : __calendarQueryHandle(calendarQueryHandle)
188 ~_CalendarQuery(void)
190 if (__calendarQueryHandle)
192 calendar_query_destroy(__calendarQueryHandle);
196 calendar_query_h GetHandle(void)
198 return __calendarQueryHandle;
201 calendar_query_h ReleaseHandle(void)
203 calendar_query_h calendarQueryHandle = __calendarQueryHandle;
204 __calendarQueryHandle = null;
205 return calendarQueryHandle;
208 void ResetHandle(calendar_query_h calendarQueryHandle)
210 if (__calendarQueryHandle)
212 calendar_query_destroy(__calendarQueryHandle);
214 __calendarQueryHandle = calendarQueryHandle;
218 calendar_query_h __calendarQueryHandle;
221 _CalendarbookImpl::_CalendarbookImpl(void)
222 : __pIRecordEventListener(null)
223 , __pICalendarbookEventListener(null)
224 , __dbVersionForEvent(0)
225 , __dbVersionForTodo(0)
226 , __pCalendarbookDbMonitor(null)
230 _CalendarbookImpl::~_CalendarbookImpl(void)
232 if (__pCalendarbookDbMonitor != null)
234 if (__pIRecordEventListener != null || __pICalendarbookEventListener != null)
236 __pCalendarbookDbMonitor->RemoveListener(*this);
239 __pCalendarbookDbMonitor->Release();
243 _CalendarbookDbConnector::Disconnect();
248 _CalendarbookImpl::Construct(void)
250 result r = _CalendarbookDbConnector::Connect();
251 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
257 _CalendarbookImpl::Construct(IRecordEventListener* pListener)
259 result r = E_SUCCESS;
264 _CalendarbookDbMonitor* pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
265 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
267 if (pListener != null)
269 dbVersion = GetLatestVersion();
270 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
272 r = pCalendarbookDbMonitor->AddListener(*this);
273 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
275 __pIRecordEventListener = pListener;
278 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
280 __dbVersionForEvent = dbVersion;
281 __dbVersionForTodo = dbVersion;
286 pCalendarbookDbMonitor->Release();
292 _CalendarbookImpl::Construct(ICalendarbookEventListener& listener)
294 result r = E_SUCCESS;
295 _CalendarbookDbMonitor* pCalendarbookDbMonitor = null;
300 pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
301 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
303 dbVersion = GetLatestVersion();
304 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
306 r = pCalendarbookDbMonitor->AddListener(*this);
307 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
309 __pICalendarbookEventListener = &listener;
310 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
312 __dbVersionForEvent = dbVersion;
313 __dbVersionForTodo = dbVersion;
318 pCalendarbookDbMonitor->Release();
324 _CalendarbookImpl::AddEvent(CalEvent& event)
326 int errorCode = CALENDAR_ERROR_NONE;
329 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
330 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
331 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
332 , "Invalid argument is used. The event is not an entry type instance.");
334 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
336 calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, _DEFAULT_EVENT_CALENDAR_DB_ID);
337 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
338 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
339 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
340 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
342 calendar_record_h tmpEventHandle = null;
343 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
344 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
345 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
351 _CalendarbookImpl::AddEvent(CalEvent& event, RecordId calendarId)
353 int errorCode = CALENDAR_ERROR_NONE;
356 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
357 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
358 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
359 , "Invalid argument is used. The event is not an entry type instance.");
360 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
361 , "Invalid argument is used. calendarId = %d", calendarId);
362 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
363 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
364 SysTryReturnResult(NID_SCL,(itemType == CALENDAR_ITEM_TYPE_EVENT_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
365 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_TODO_ONLY");
367 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
369 calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, calendarId);
370 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
371 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
372 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
373 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
375 calendar_record_h tmpEventHandle = null;
376 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
377 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
378 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
384 _CalendarbookImpl::AddTodo(CalTodo& todo)
386 int errorCode = CALENDAR_ERROR_NONE;
389 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
390 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
392 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
394 calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, _DEFAULT_TODO_CALENDAR_DB_ID);
395 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
396 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
397 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
398 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
400 calendar_record_h tmpTodoHandle = null;
401 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
402 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
403 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
409 _CalendarbookImpl::AddTodo(CalTodo& todo, RecordId calendarId)
411 int errorCode = CALENDAR_ERROR_NONE;
414 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
415 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
416 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
417 , "Invalid argument is used. calendarId = %d", calendarId);
418 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
419 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
420 SysTryReturnResult(NID_SCL, (itemType == CALENDAR_ITEM_TYPE_TODO_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
421 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_EVENT_ONLY");
423 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
425 calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, calendarId);
426 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
427 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
428 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
429 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
431 calendar_record_h tmpTodoHandle = null;
432 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
433 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
434 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
440 _CalendarbookImpl::AddCalendar(Calendar& calendar)
442 int errorCode = CALENDAR_ERROR_NONE;
445 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
446 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
448 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
450 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
451 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
452 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
453 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
455 calendar_record_h tmpCalendarHandle = null;
456 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
457 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
458 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
464 _CalendarbookImpl::AddCalendar(Calendar& calendar, AccountId accountId)
466 int errorCode = CALENDAR_ERROR_NONE;
469 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
470 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
471 SysTryReturnResult(NID_SCL, accountId >= 0, E_INVALID_ARG, "Invalid argument is used.");
473 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
475 calendar_record_set_int(calendarHandle, _calendar_book.account_id, accountId);
477 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
478 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
479 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
480 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
482 calendar_record_h tmpCalendarHandle = null;
483 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
484 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
485 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
491 _CalendarbookImpl::RemoveEvent(CalEvent& event)
493 int errorCode = CALENDAR_ERROR_NONE;
495 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
496 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
498 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
500 int baseEventId = _INVALID_EVENT_DB_ID;
501 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
502 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
503 , "Invalid argument is used. The event has the base event id.");
505 errorCode = calendar_db_delete_record(_calendar_event._uri, event.GetRecordId());
506 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
507 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
509 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(event);
510 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
516 _CalendarbookImpl::RemoveEvent(RecordId eventId)
518 int errorCode = CALENDAR_ERROR_NONE;
520 SysTryReturnResult(NID_SCL, eventId != INVALID_RECORD_ID, E_INVALID_ARG
521 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
523 calendar_record_h eventHandle = null;
525 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
526 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
528 int baseEventId = _INVALID_EVENT_DB_ID;
529 calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
531 calendar_record_destroy(eventHandle, true);
533 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
534 , "Invalid argument is used. The event of eventId has the base event id.");
536 errorCode = calendar_db_delete_record(_calendar_event._uri, eventId);
537 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
543 _CalendarbookImpl::RemoveTodo(CalTodo& todo)
545 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(todo);
547 result r = RemoveTodo(todo.GetRecordId());
548 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
554 _CalendarbookImpl::RemoveTodo(RecordId todoId)
556 int errorCode = CALENDAR_ERROR_NONE;
558 SysTryReturnResult(NID_SCL, todoId != INVALID_RECORD_ID, E_INVALID_ARG
559 , "Invalid argument is used. The specified todoId is INVALID_RECORD_ID.");
561 errorCode = calendar_db_delete_record(_calendar_todo._uri, todoId);
562 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
563 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
569 _CalendarbookImpl::RemoveCalendar(RecordId calendarId)
571 int errorCode = CALENDAR_ERROR_NONE;
573 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
574 , "The specified calendarId is INVALID_RECORD_ID.");
575 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_EVENT_CALENDAR_DB_ID
576 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
577 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_TODO_CALENDAR_DB_ID
578 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
579 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendarId), E_OBJ_NOT_FOUND, "The specified record is not found.");
581 errorCode = calendar_db_delete_record(_calendar_book._uri, calendarId);
582 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
588 _CalendarbookImpl::UpdateEvent(const CalEvent& event)
590 int errorCode = CALENDAR_ERROR_NONE;
592 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
593 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
594 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
595 , "Invalid argument is used. The event is not an entry type instance.");
597 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
599 int baseEventId = _INVALID_EVENT_DB_ID;
600 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
601 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
602 , "Invalid argument is used. The event has the base event id.");
604 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
606 errorCode = calendar_db_update_record(eventHandle);
607 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
608 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
614 _CalendarbookImpl::UpdateTodo(const CalTodo& todo)
616 int errorCode = CALENDAR_ERROR_NONE;
618 SysTryReturnResult(NID_SCL, todo.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
619 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
620 SysTryReturnResult(NID_SCL, CheckTodoExistance(todo.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
622 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
623 errorCode = calendar_db_update_record(todoHandle);
624 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
630 _CalendarbookImpl::UpdateCalendar(const Calendar& calendar)
632 int errorCode = CALENDAR_ERROR_NONE;
634 SysTryReturnResult(NID_SCL, calendar.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
635 , "The specified recordId is INVALID_RECORD_ID.");
636 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendar.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
638 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
639 errorCode = calendar_db_update_record(calendarHandle);
640 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
646 _CalendarbookImpl::GetEventN(RecordId eventId) const
648 int errorCode = CALENDAR_ERROR_NONE;
649 calendar_record_h eventHandle = null;
653 SysTryReturn(NID_SCL, eventId != INVALID_RECORD_ID, null, E_INVALID_ARG
654 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
656 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
657 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
659 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
660 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
661 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
663 _CalEventImpl::GetInstance(*pEvent.get())->SetRecordHandle(eventHandle);
664 _RecordImpl::GetInstance(*pEvent.get())->SetRecordId(eventId);
666 return pEvent.release();
670 _CalendarbookImpl::GetTodoN(RecordId todoId) const
672 int errorCode = CALENDAR_ERROR_NONE;
673 calendar_record_h todoHandle = null;
677 SysTryReturn(NID_SCL, todoId != INVALID_RECORD_ID, null, E_INVALID_ARG
678 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
680 std::unique_ptr<CalTodo> pTodo(new (std::nothrow) CalTodo());
681 SysTryReturn(NID_SCL, pTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
683 errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
684 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
685 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
687 _CalTodoImpl::GetInstance(*pTodo.get())->SetRecordHandle(todoHandle);
688 _RecordImpl::GetInstance(*pTodo.get())->SetRecordId(todoId);
690 return pTodo.release();
694 _CalendarbookImpl::GetCalendarN(RecordId calendarId) const
696 int errorCode = CALENDAR_ERROR_NONE;
697 calendar_record_h calendarHandle = null;
701 SysTryReturn(NID_SCL, calendarId != INVALID_RECORD_ID, null, E_INVALID_ARG
702 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
704 std::unique_ptr<Calendar> pCalendar(new (std::nothrow) Calendar(CALENDAR_ITEM_TYPE_EVENT_AND_TODO));
705 SysTryReturn(NID_SCL, pCalendar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
707 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
708 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
709 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
711 _CalendarImpl::GetInstance(*pCalendar.get())->SetRecordHandle(calendarHandle);
712 _RecordImpl::GetInstance(*pCalendar.get())->SetRecordId(calendarId);
714 return pCalendar.release();
718 _CalendarbookImpl::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status,
719 unsigned long priority) const
721 int errorCode = CALENDAR_ERROR_NONE;
725 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The pageNo or countPerPage is less than 1.");
726 SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
727 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
728 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
729 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %ld", status);
730 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %ld", priority);
734 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
735 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
736 calendar_time_s convertedStartTime;
737 calendar_time_s convertedEndTime;
738 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
739 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
741 calendar_filter_h mainFilterHandle = null;
742 errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
743 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
744 _CalendarFilter mainFilter(mainFilterHandle);
746 // Condition : Due time of the item >= start time of filter
747 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
748 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
750 // Condition : Due time of the item <= end time of filter
751 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
752 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
753 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
754 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
756 // Condition : status
757 calendar_filter_h subFilterHandle = null;
758 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
759 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
760 _CalendarFilter subFilter(subFilterHandle);
761 subFilterHandle = null;
763 int tmpStatus = TODO_STATUS_NONE;
764 bool alreadyAdded = false;
765 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
767 if (status & tmpStatus)
771 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
772 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
775 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
776 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
784 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
785 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
786 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
787 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
789 // Condition : priority
790 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
791 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
792 subFilter.ResetHandle(subFilterHandle);
793 subFilterHandle = null;
795 int tmpPriority = TODO_PRIORITY_LOW;
796 alreadyAdded = false;
797 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
799 if (priority & tmpPriority)
803 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
804 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
807 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
808 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
815 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
816 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
817 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
818 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
821 calendar_query_h queryHandle = null;
822 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
823 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
824 _CalendarQuery query(queryHandle);
826 calendar_query_set_sort(queryHandle, _calendar_todo.due_time, true);
827 calendar_query_set_filter(queryHandle, mainFilterHandle);
829 calendar_list_h calendarListHandle = null;
830 errorCode = calendar_db_get_records_with_query(queryHandle, (pageNo - 1) * countPerPage, countPerPage, &calendarListHandle);
831 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
832 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
833 _CalendarList calendarList(calendarListHandle);
835 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
836 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
837 result r = pList->Construct();
838 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
841 calendar_list_get_count(calendarListHandle, &count);
843 for (int i = 0; i < count; i++)
845 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
846 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
848 r = pList->Add(*pTmpTodo.release());
849 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
852 calendar_list_first(calendarListHandle);
853 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
854 while (pEnum->MoveNext() == E_SUCCESS)
856 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
858 calendar_record_h tmpRecordHandle = null;
859 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
861 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
864 calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
865 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
867 calendar_list_next(calendarListHandle);
870 calendar_list_destroy(calendarList.ReleaseHandle(), false);
872 return pList.release();
876 _CalendarbookImpl::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const
878 int errorCode = CALENDAR_ERROR_NONE;
882 SysTryReturn(NID_SCL, start <= end, _INVALID_COUNT
883 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
884 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), _INVALID_COUNT
885 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
886 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), _INVALID_COUNT
887 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
888 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), _INVALID_COUNT
889 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %ld", status);
890 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), _INVALID_COUNT
891 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %ld", priority);
895 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
896 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
897 calendar_time_s convertedStartTime;
898 calendar_time_s convertedEndTime;
899 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
900 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
902 calendar_filter_h mainFilterHandle = null;
903 errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
904 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
905 _CalendarFilter mainFilter(mainFilterHandle);
907 // Condition : Due time of the item => start time of filter
908 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
909 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
911 // Condition : Due time of the item <= end time of filter
912 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
913 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
914 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
915 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
917 // Condition : status
918 calendar_filter_h subFilterHandle = null;
919 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
920 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
921 _CalendarFilter subFilter(subFilterHandle);
922 subFilterHandle = null;
924 int tmpStatus = TODO_STATUS_NONE;
925 bool alreadyAdded = false;
926 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
928 if (status & tmpStatus)
932 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
933 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
936 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
937 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
944 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
945 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
946 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
947 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
949 // Condition : priority
950 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
951 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
952 subFilter.ResetHandle(subFilterHandle);
953 subFilterHandle = null;
955 int tmpPriority = TODO_PRIORITY_LOW;
956 alreadyAdded = false;
957 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
959 if (priority & tmpPriority)
963 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
964 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
967 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
968 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
975 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
976 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
977 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
978 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
981 calendar_query_h queryHandle = null;
982 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
983 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
984 _CalendarQuery query(queryHandle);
986 calendar_query_set_filter(queryHandle, mainFilterHandle);
988 int count = _INVALID_COUNT;
990 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
991 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
997 _CalendarbookImpl::GetEventInstancesN(const DateTime& start, const DateTime& end,
998 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage,
999 unsigned long category) const
1001 result r = E_SUCCESS;
1005 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The pageNo or countPerPage is less than 1.");
1006 SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
1007 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
1008 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
1009 SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. category = %ld", category);
1011 std::unique_ptr<IList, AllElementsDeleter> pList(GetEventInstancesCommonN(start, end, timeZone, pageNo, countPerPage, category));
1012 r = GetLastResult();
1013 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1015 return pList.release();
1019 _CalendarbookImpl::GetEventInstances(const DateTime& start, const DateTime& end,
1020 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category,
1021 RequestId& reqId, const IRecordListener& listener) const
1024 reqId = __requestId;
1026 result r = E_SUCCESS;
1028 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The pageNo or countPerPage is less than 1.");
1029 SysTryReturn(NID_SCL, start <= end, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
1030 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
1031 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
1032 SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. category = %ld", category);
1034 std::unique_ptr<_CalendarbookRecordRetrivalEvent> pEvent(new (std::nothrow) _CalendarbookRecordRetrivalEvent());
1035 SysTryReturnResult(NID_SCL, pEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1036 r = pEvent->Construct();
1037 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1038 r = pEvent->AddListener(listener);
1039 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1041 if (__pRecordRetrivalThread != null)
1043 __pRecordRetrivalThread->Join();
1044 delete __pRecordRetrivalThread;
1045 __pRecordRetrivalThread = null;
1048 std::unique_ptr<_CalendarbookRecordRetrivalThread> pRecordRetrivalThread(new (std::nothrow) _CalendarbookRecordRetrivalThread());
1049 SysTryReturnResult(NID_SCL, pRecordRetrivalThread != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1050 r = pRecordRetrivalThread->Construct(__requestId, *pEvent.release(), start, end, timeZone, pageNo, countPerPage, category);
1051 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1053 r = pRecordRetrivalThread->Start();
1054 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1056 __pRecordRetrivalThread = pRecordRetrivalThread.release();
1062 _CalendarbookImpl::GetAllEventsN(void) const
1064 int errorCode = CALENDAR_ERROR_NONE;
1066 calendar_list_h calendarListHandle = null;
1067 errorCode = calendar_db_get_all_records(_calendar_event._uri, 0, 0, &calendarListHandle);
1068 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1069 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1070 _CalendarList calendarList(calendarListHandle);
1072 result r = E_SUCCESS;
1073 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1074 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1075 r = pList->Construct();
1076 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1079 calendar_list_get_count(calendarListHandle, &count);
1081 for (int i = 0; i < count; i++)
1083 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1084 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1086 r = pList->Add(*pTmpEvent.release());
1087 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1090 calendar_list_first(calendarListHandle);
1091 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1092 while (pEnum->MoveNext() == E_SUCCESS)
1094 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1096 calendar_record_h tmpRecordHandle = null;
1097 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1098 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1101 calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &dbIndex);
1102 _RecordImpl::GetInstance(*pTmpEvent)->SetRecordId(dbIndex);
1104 calendar_list_next(calendarListHandle);
1107 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1109 return pList.release();
1113 _CalendarbookImpl::GetAllTodosN(void) const
1115 int errorCode = CALENDAR_ERROR_NONE;
1117 calendar_list_h calendarListHandle = null;
1118 errorCode = calendar_db_get_all_records(_calendar_todo._uri, 0, 0, &calendarListHandle);
1119 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1120 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1121 _CalendarList calendarList(calendarListHandle);
1123 result r = E_SUCCESS;
1124 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1125 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1126 r = pList->Construct();
1127 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1130 calendar_list_get_count(calendarListHandle, &count);
1132 for (int i = 0; i < count; i++)
1134 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1135 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1137 r = pList->Add(*pTmpTodo.release());
1138 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1141 calendar_list_first(calendarListHandle);
1142 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1143 while (pEnum->MoveNext() == E_SUCCESS)
1145 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1147 calendar_record_h tmpRecordHandle = null;
1148 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1149 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1152 calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
1153 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
1155 calendar_list_next(calendarListHandle);
1158 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1160 return pList.release();
1164 _CalendarbookImpl::GetAllCalendarsN(void) const
1166 int errorCode = CALENDAR_ERROR_NONE;
1168 calendar_list_h calendarListHandle = null;
1169 errorCode = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &calendarListHandle);
1170 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1171 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1172 _CalendarList calendarList(calendarListHandle);
1174 result r = E_SUCCESS;
1175 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1176 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1177 r = pList->Construct();
1178 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1181 calendar_list_get_count(calendarListHandle, &count);
1183 for (int i = 0; i < count; i++)
1185 std::unique_ptr<Calendar> pTmpCalendar(_CalendarImpl::CreateDefaultInstanceN());
1186 SysTryReturn(NID_SCL, pTmpCalendar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1188 r = pList->Add(*pTmpCalendar.release());
1189 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1192 calendar_list_first(calendarListHandle);
1193 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1194 while (pEnum->MoveNext() == E_SUCCESS)
1196 Calendar* pTmpCalendar = static_cast<Calendar*>(pEnum->GetCurrent());
1198 calendar_record_h tmpRecordHandle = null;
1199 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1200 _CalendarImpl::GetInstance(*pTmpCalendar)->SetRecordHandle(tmpRecordHandle);
1203 calendar_record_get_int(tmpRecordHandle, _calendar_book.id, &dbIndex);
1204 _RecordImpl::GetInstance(*pTmpCalendar)->SetRecordId(dbIndex);
1206 calendar_list_next(calendarListHandle);
1209 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1211 return pList.release();
1215 _CalendarbookImpl::GetChangedEventsAfterN(int version, int& latestVersion) const
1217 int errorCode = CALENDAR_ERROR_NONE;
1221 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1223 calendar_list_h calendarListHandle = null;
1224 int tmpLatestVersion = 0;
1225 errorCode = calendar_db_get_changes_by_version(_calendar_event._uri, CALENDAR_BOOK_FILTER_ALL, version
1226 , &calendarListHandle, &tmpLatestVersion);
1227 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1228 , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1229 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1231 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1232 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1233 result r = pList->Construct();
1234 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1237 calendar_list_get_count(calendarListHandle, &count);
1239 calendar_list_first(calendarListHandle);
1240 for (int i = 0; i < count; i++)
1242 calendar_record_h tmpRecordHandle = null;
1243 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1245 std::unique_ptr<CalEventChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(tmpRecordHandle));
1246 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1248 r = pList->Add(*pChangedInfo.release());
1249 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1251 calendar_list_next(calendarListHandle);
1254 latestVersion = tmpLatestVersion;
1256 return pList.release();
1260 _CalendarbookImpl::GetChangedTodosAfterN(int version, int& latestVersion) const
1262 int errorCode = CALENDAR_ERROR_NONE;
1266 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1268 calendar_list_h calendarListHandle = null;
1269 int tmpLatestVersion = 0;
1270 errorCode = calendar_db_get_changes_by_version(_calendar_todo._uri, CALENDAR_BOOK_FILTER_ALL, version
1271 , &calendarListHandle, &tmpLatestVersion);
1272 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1273 , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1274 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1275 _CalendarList calendarList(calendarListHandle);
1277 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1278 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1279 result r = pList->Construct();
1280 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1283 calendar_list_get_count(calendarListHandle, &count);
1285 calendar_list_first(calendarListHandle);
1286 for (int i = 0; i < count; i++)
1288 calendar_record_h tmpRecordHandle = null;
1289 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1291 std::unique_ptr<CalTodoChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(tmpRecordHandle));
1292 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1294 r = pList->Add(*pChangedInfo.release());
1295 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1297 calendar_list_next(calendarListHandle);
1300 latestVersion = tmpLatestVersion;
1302 return pList.release();
1306 _CalendarbookImpl::RemoveEventInstance(const CalEventInstance& eventInstance)
1308 int errorCode = CALENDAR_ERROR_NONE;
1310 calendar_record_h eventHandle = null;
1311 char* pExdate = null;
1313 // Get event handle from DB
1314 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &eventHandle);
1315 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1316 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
1317 _CalendarRecord eventRecord(eventHandle);
1319 int baseEventId = _INVALID_EVENT_DB_ID;
1320 calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1322 if (baseEventId != _INVALID_EVENT_DB_ID)
1324 errorCode = calendar_db_delete_record(_calendar_event._uri, eventInstance.GetOriginalEventId());
1325 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1330 calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExdate);
1333 if (pExdate != null && strlen(pExdate) > 0)
1335 exdate.Append(pExdate);
1336 exdate.Append(_RECURRENCE_DELIMITER);
1339 exdate.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent()));
1341 std::unique_ptr<char[]> pAppendedExdate(_StringConverter::CopyToCharArrayN(exdate));
1342 SysTryReturnResult(NID_SCL, pAppendedExdate != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1344 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, pAppendedExdate.get());
1345 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1347 // Update event handle
1348 errorCode = calendar_db_update_record(eventHandle);
1349 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1356 _CalendarbookImpl::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event)
1358 int errorCode = CALENDAR_ERROR_NONE;
1360 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
1361 , "Invalid argument is used. The event's recordId is INVALID_RECORD_ID.");
1362 SysTryReturnResult(NID_SCL, eventInstance.GetOriginalEventId() == event.GetRecordId(), E_INVALID_ARG
1363 , "Invalid argument is used. The event's recordId is not equal to eventInstance's original event ID.");
1364 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified event is not found.");
1366 calendar_record_h eventHandle = null;
1367 errorCode = calendar_record_clone(_CalEventImpl::GetInstance(event)->GetRecordHandle(), &eventHandle);
1368 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1369 _CalendarRecord eventRecord(eventHandle);
1371 int baseEventId = _INVALID_EVENT_DB_ID;
1372 calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1374 calendar_record_h baseEventHandle = null;
1375 if (baseEventId == _INVALID_EVENT_DB_ID)
1377 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &baseEventHandle);
1381 errorCode = calendar_db_get_record(_calendar_event._uri, baseEventId, &baseEventHandle);
1383 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1384 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The base event is not found.");
1385 _CalendarRecord baseEventRecord(baseEventHandle);
1387 int tmpIntValue = 0;
1388 calendar_record_get_int(baseEventHandle, _calendar_event.freq, &tmpIntValue);
1389 calendar_record_set_int(eventHandle, _calendar_event.freq, tmpIntValue);
1390 calendar_record_get_int(baseEventHandle, _calendar_event.range_type, &tmpIntValue);
1391 calendar_record_set_int(eventHandle, _calendar_event.range_type, tmpIntValue);
1392 calendar_record_get_int(baseEventHandle, _calendar_event.count, &tmpIntValue);
1393 calendar_record_set_int(eventHandle, _calendar_event.count, tmpIntValue);
1394 calendar_record_get_int(baseEventHandle, _calendar_event.interval, &tmpIntValue);
1395 calendar_record_set_int(eventHandle, _calendar_event.interval, tmpIntValue);
1396 calendar_record_get_int(baseEventHandle, _calendar_event.wkst, &tmpIntValue);
1397 calendar_record_set_int(eventHandle, _calendar_event.wkst, tmpIntValue);
1399 calendar_time_s tmpTimeValue;
1400 calendar_record_get_caltime(baseEventHandle, _calendar_event.until_time, &tmpTimeValue);
1402 calendar_time_s tmpStartTimeValue;
1403 DateTime convertedTime;
1404 calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &tmpStartTimeValue);
1406 if (tmpTimeValue.type != tmpStartTimeValue.type)
1408 if (tmpStartTimeValue.type == CALENDAR_TIME_UTIME)
1410 convertedTime.SetValue(tmpTimeValue.time.date.year, tmpTimeValue.time.date.month, tmpTimeValue.time.date.mday);
1411 tmpTimeValue.type = CALENDAR_TIME_UTIME;
1412 tmpTimeValue.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(convertedTime);
1416 convertedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpTimeValue.time.utime);
1417 tmpTimeValue.type = CALENDAR_TIME_LOCALTIME;
1418 tmpTimeValue.time.date.year = convertedTime.GetYear();
1419 tmpTimeValue.time.date.month = convertedTime.GetMonth();
1420 tmpTimeValue.time.date.mday = convertedTime.GetDay();
1423 calendar_record_set_caltime(eventHandle, _calendar_event.until_time, tmpTimeValue);
1425 char* tmpStrValue = null;
1426 calendar_record_get_str_p(baseEventHandle, _calendar_event.byday, &tmpStrValue);
1427 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, tmpStrValue);
1428 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1430 calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonthday, &tmpStrValue);
1431 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, tmpStrValue);
1432 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1434 calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonth, &tmpStrValue);
1435 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, tmpStrValue);
1436 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1438 calendar_record_get_str_p(baseEventHandle, _calendar_event.exdate, &tmpStrValue);
1439 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, tmpStrValue);
1440 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1442 if (baseEventId == _INVALID_EVENT_DB_ID)
1444 calendar_record_set_int(eventHandle, _calendar_event.original_event_id, eventInstance.GetOriginalEventId());
1446 std::unique_ptr<char[]> pConvertedRecurrenceId(_StringConverter::CopyToCharArrayN(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent())));
1447 errorCode = calendar_record_set_str(eventHandle, _calendar_event.recurrence_id, pConvertedRecurrenceId.get());
1448 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1451 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
1452 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1453 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
1457 errorCode = calendar_db_update_record(eventHandle);
1458 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1459 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The base event of the event is not found.");
1462 calendar_record_h tmpEventHandle = null;
1463 errorCode = calendar_db_get_record(_calendar_event._uri, event.GetRecordId(), &tmpEventHandle);
1464 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1465 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
1471 _CalendarbookImpl::GetLatestVersion(void) const
1473 int errorCode = CALENDAR_ERROR_NONE;
1478 errorCode = calendar_db_get_current_version(&dbVersion);
1479 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, 0, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1485 _CalendarbookImpl::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const
1487 int errorCode = CALENDAR_ERROR_NONE;
1489 bool ascending = false;
1490 unsigned int viewSortPropertyId = 0;
1492 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1493 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1495 SysTryReturn(NID_SCL, offset >= 0 && maxCount >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The specified offset or maxCount is less than 0.");
1496 SysTryReturn(NID_SCL, propertySortedBy == 0 || _CalendarbookFilterImpl::IsValidProperty(type, propertySortedBy), null, E_INVALID_ARG
1497 , "[%s] Invalid argument is used. propertySortedBy = %d", GetErrorMessage(E_INVALID_ARG), propertySortedBy);
1499 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1502 calendar_query_h queryHandle = null;
1503 errorCode = calendar_query_create(pViewUri, &queryHandle);
1504 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1505 _CalendarQuery query(queryHandle);
1507 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1509 viewSortPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1510 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1512 calendar_query_set_sort(queryHandle, viewSortPropertyId, ascending);
1517 calendar_query_set_filter(queryHandle, filterHandle);
1520 calendar_list_h resultListHandle = null;
1521 errorCode = calendar_db_get_records_with_query(queryHandle, offset, maxCount, &resultListHandle);
1522 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1523 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1524 _CalendarList calendarList(resultListHandle);
1526 std::unique_ptr<IList, AllElementsDeleter> pList;
1530 case CB_FI_TYPE_EVENT:
1532 pList.reset(ConvertRecordListN<CalEvent, _CalEventImpl, _calendar_event_property_ids>(resultListHandle, _calendar_event));
1533 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1534 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1537 case CB_FI_TYPE_TODO:
1539 pList.reset(ConvertRecordListN<CalTodo, _CalTodoImpl, _calendar_todo_property_ids>(resultListHandle, _calendar_todo));
1540 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1541 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1544 case CB_FI_TYPE_CALENDAR:
1546 pList.reset(ConvertRecordListN<Calendar, _CalendarImpl, _calendar_book_property_ids>(resultListHandle, _calendar_book));
1547 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1548 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1551 case CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE:
1553 pList.reset(ConvertEventInstanceListN(resultListHandle, true));
1554 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1557 case CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE:
1559 pList.reset(ConvertEventInstanceListN(resultListHandle, false));
1560 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1564 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of filter is (%d)", GetErrorMessage(E_INVALID_ARG), type);
1568 return pList.release();
1572 _CalendarbookImpl::GetMatchedItemCount(const CalendarbookFilter& filter) const
1574 int errorCode = CALENDAR_ERROR_NONE;
1576 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1577 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1579 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1582 calendar_query_h queryHandle = null;
1583 errorCode = calendar_query_create(pViewUri, &queryHandle);
1584 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1585 _CalendarQuery query(queryHandle);
1589 calendar_query_set_filter(queryHandle, filterHandle);
1592 int count = _INVALID_COUNT;
1594 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
1595 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1601 _CalendarbookImpl::ParseEventsFromVcalendarN(const String& vCalFilePath)
1603 result r = E_SUCCESS;
1604 int errorCode = CALENDAR_ERROR_NONE;
1609 r = vCalFile.Construct(vCalFilePath, L"r");
1610 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1611 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1612 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1614 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1615 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1616 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1618 int fileLength = vCalFile.Tell();
1619 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is empty.");
1621 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1622 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1623 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1625 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1626 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1627 r = pBuffer->Construct(fileLength);
1628 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1630 r = vCalFile.Read(*pBuffer);
1631 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1632 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1634 _CalendarConnector connector;
1635 r = connector.GetResult();
1636 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1639 calendar_list_h calendarListHandle = null;
1640 errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1641 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1642 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is invalid.");
1643 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1644 _CalendarList calendarList(calendarListHandle);
1646 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1647 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1648 r = pList->Construct();
1649 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1652 calendar_list_get_count(calendarListHandle, &count);
1654 calendar_list_first(calendarListHandle);
1655 for (int i = 0; i < count; i++)
1657 calendar_record_h tmpRecordHandle = null;
1658 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1659 calendar_list_next(calendarListHandle);
1662 calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1664 if (strcmp(pUri, _calendar_event._uri) == 0)
1666 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1667 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1669 r = pList->Add(*pTmpEvent.release());
1670 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1674 calendar_list_remove(calendarListHandle, tmpRecordHandle);
1675 calendar_record_destroy(tmpRecordHandle, true);
1679 calendar_list_first(calendarListHandle);
1680 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1681 while (pEnum->MoveNext() == E_SUCCESS)
1683 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1685 calendar_record_h tmpRecordHandle = null;
1686 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1687 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1689 calendar_list_next(calendarListHandle);
1692 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1694 return pList.release();
1698 _CalendarbookImpl::ParseTodosFromVcalendarN(const String& vCalFilePath)
1700 result r = E_SUCCESS;
1701 int errorCode = CALENDAR_ERROR_NONE;
1706 r = vCalFile.Construct(vCalFilePath, L"r");
1707 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1708 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1709 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1711 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1712 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1713 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1715 int fileLength = vCalFile.Tell();
1716 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is empty.");
1718 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1719 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1720 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1722 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1723 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1724 r = pBuffer->Construct(fileLength);
1725 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1727 r = vCalFile.Read(*pBuffer);
1728 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1729 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1731 _CalendarConnector connector;
1732 r = connector.GetResult();
1733 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1736 calendar_list_h calendarListHandle = null;
1737 errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1738 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1739 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is invalid.");
1740 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1741 _CalendarList calendarList(calendarListHandle);
1743 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1744 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1745 r = pList->Construct();
1746 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1749 calendar_list_get_count(calendarListHandle, &count);
1751 calendar_list_first(calendarListHandle);
1752 for (int i = 0; i < count; i++)
1754 calendar_record_h tmpRecordHandle = null;
1755 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1756 calendar_list_next(calendarListHandle);
1759 calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1761 if (strcmp(pUri, _calendar_todo._uri) == 0)
1763 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1764 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1766 r = pList->Add(*pTmpTodo.release());
1767 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1771 calendar_list_remove(calendarListHandle, tmpRecordHandle);
1772 calendar_record_destroy(tmpRecordHandle, true);
1776 calendar_list_first(calendarListHandle);
1777 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1778 while (pEnum->MoveNext() == E_SUCCESS)
1780 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1782 calendar_record_h tmpRecordHandle = null;
1783 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1784 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1786 calendar_list_next(calendarListHandle);
1789 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1791 return pList.release();
1795 _CalendarbookImpl::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath)
1797 result r = E_SUCCESS;
1798 int errorCode = CALENDAR_ERROR_NONE;
1800 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1801 r = GetLastResult();
1802 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1804 _CalendarConnector connector;
1805 r = connector.GetResult();
1806 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1808 calendar_list_h calendarListHandle = null;
1809 errorCode = calendar_list_create(&calendarListHandle);
1810 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1811 _CalendarList calendarList(calendarListHandle, false);
1813 std::unique_ptr<IEnumerator> pEnum(eventList.GetEnumeratorN());
1814 while (pEnum->MoveNext() == E_SUCCESS)
1816 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1817 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_EVENT, E_INVALID_ARG, "Invalid argument is used. The eventList contains invalid record.");
1819 CalEvent* pTmpEvent = static_cast<CalEvent*>(pTmpRecord);
1820 errorCode = calendar_list_add(calendarListHandle, _CalEventImpl::GetInstance(*pTmpEvent)->GetRecordHandle());
1821 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1824 char* pVCalBuffer = null;
1825 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1826 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1827 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1828 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1831 r = vCalFile.Construct(vCalFilePath, L"w");
1832 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1833 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1834 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1836 int pVCalBufferLength = strlen(pVCalBuffer);
1837 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1838 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1839 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1845 _CalendarbookImpl::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath)
1847 result r = E_SUCCESS;
1848 int errorCode = CALENDAR_ERROR_NONE;
1850 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1851 r = GetLastResult();
1852 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1854 _CalendarConnector connector;
1855 r = connector.GetResult();
1856 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1858 calendar_list_h calendarListHandle = null;
1859 errorCode = calendar_list_create(&calendarListHandle);
1860 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1861 _CalendarList calendarList(calendarListHandle, false);
1863 std::unique_ptr<IEnumerator> pEnum(todoList.GetEnumeratorN());
1864 while (pEnum->MoveNext() == E_SUCCESS)
1866 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1867 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_TODO, E_INVALID_ARG, "Invalid argument is used. The todoList contains invalid record.");
1869 CalTodo* pTmpTodo = static_cast<CalTodo*>(pTmpRecord);
1870 errorCode = calendar_list_add(calendarListHandle, _CalTodoImpl::GetInstance(*pTmpTodo)->GetRecordHandle());
1871 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1874 char* pVCalBuffer = null;
1875 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1876 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1877 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1878 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1881 r = vCalFile.Construct(vCalFilePath, L"w");
1882 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1883 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1884 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1886 int pVCalBufferLength = strlen(pVCalBuffer);
1887 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1888 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1889 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1895 _CalendarbookImpl::GetMaxDateTime(void)
1897 DateTime maxDateTime;
1898 maxDateTime.SetValue(2100, 12, 31, 23, 59, 59);
1904 _CalendarbookImpl::GetMinDateTime(void)
1906 DateTime minDateTime;
1907 minDateTime.SetValue(1900, 1, 1, 0, 0, 0);
1913 _CalendarbookImpl::GetEventInstancesCommonN(const DateTime& start, const DateTime& end,
1914 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category) const
1918 calendar_time_s convertedStartTime;
1919 calendar_time_s convertedEndTime;
1920 _CalendarbookUtil::ConvertDateTimeToCalTime(start, convertedStartTime);
1921 _CalendarbookUtil::ConvertDateTimeToCalTime(end, convertedEndTime);
1923 Tizen::Locales::TimeZone tmpTimeZone(timeZone);
1924 DateTime localStartTime = tmpTimeZone.UtcTimeToWallTime(start);
1925 DateTime localEndTime = tmpTimeZone.UtcTimeToWallTime(end);
1927 calendar_time_s convertedLocalStartTime;
1928 calendar_time_s convertedLocalEndTime;
1929 _CalendarbookUtil::ConvertDateToCalTime(localStartTime, convertedLocalStartTime);
1930 _CalendarbookUtil::ConvertDateToCalTime(localEndTime, convertedLocalEndTime);
1932 std::unique_ptr<IList, AllElementsDeleter> pList;
1934 if (category == EVENT_CATEGORY_ALL)
1936 pList.reset(GetEventInstancesOfAllCategoriesN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage));
1940 pList.reset(GetEventInstancesOfCategoryN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage, category));
1943 return pList.release();
1947 _CalendarbookImpl::GetEventInstancesOfAllCategoriesN(const calendar_time_s& startTime, const calendar_time_s& endTime,
1948 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage) const
1950 int errorCode = CALENDAR_ERROR_NONE;
1954 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
1955 errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
1956 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1957 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
1959 // Condition : End time of the item > start time of filter
1960 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
1961 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1963 // Condition : Start time of the item < end time of filter
1964 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
1965 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1966 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
1967 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1970 calendar_query_h allDayEventInstanceQueryHandle = null;
1971 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
1972 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1973 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
1975 calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
1976 calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
1978 int startIndex = (pageNo - 1) * countPerPage;
1980 calendar_list_h allDayEventInstanceListHandle = null;
1981 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, startIndex, countPerPage, &allDayEventInstanceListHandle);
1982 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1983 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1984 _CalendarList allDayEventList(allDayEventInstanceListHandle);
1986 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1987 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1988 result r = pList->Construct();
1989 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1991 int allDayEventInstanceCount = 0;
1992 errorCode = calendar_db_get_count_with_query(allDayEventInstanceQueryHandle, &allDayEventInstanceCount);
1993 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1996 calendar_list_get_count(allDayEventInstanceListHandle, &count);
1998 int pageCount = allDayEventInstanceCount / countPerPage;
1999 int remainingCount = countPerPage - count;
2001 calendar_list_first(allDayEventInstanceListHandle);
2002 for (int i = 0; i < count; i++)
2004 calendar_record_h tmpRecordHandle = null;
2005 calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
2007 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2008 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2010 r = pList->Add(*pTmpEventInstance.release());
2011 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2013 calendar_list_next(allDayEventInstanceListHandle);
2016 if (remainingCount > 0)
2018 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
2019 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
2020 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2021 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
2023 calendar_filter_h subFilterHandle = null;
2024 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2025 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2026 _CalendarFilter subFilter(subFilterHandle);
2027 subFilterHandle = null;
2029 // Condition : End time of the item > start time of filter
2030 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2031 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2033 // Condition : Start time of the item < end time of filter
2034 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2035 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2036 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2037 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2039 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2040 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2042 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2043 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2044 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2045 subFilter.ResetHandle(subFilterHandle);
2046 subFilterHandle = null;
2048 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2049 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2050 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2051 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2052 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2053 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2055 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2056 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2057 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2058 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2061 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2062 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2063 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2064 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2066 calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2067 calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2069 if (remainingCount == countPerPage)
2071 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (allDayEventInstanceCount % countPerPage);
2078 calendar_list_h nonAllDayEventInstanceListHandle = null;
2079 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, startIndex, remainingCount, &nonAllDayEventInstanceListHandle);
2080 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2081 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2082 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2085 calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2086 calendar_list_first(nonAllDayEventInstanceListHandle);
2087 for (int i = 0; i < count; i++)
2089 calendar_record_h tmpRecordHandle = null;
2090 calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2092 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2093 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2095 r = pList->Add(*pTmpEventInstance.release());
2096 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2098 calendar_list_next(nonAllDayEventInstanceListHandle);
2102 return pList.release();
2106 _CalendarbookImpl::GetEventInstancesOfCategoryN(const calendar_time_s& startTime, const calendar_time_s& endTime,
2107 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage, unsigned long category) const
2109 int errorCode = CALENDAR_ERROR_NONE;
2113 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
2114 errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
2115 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2116 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
2118 // Condition : End time of the item > start time of filter
2119 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
2120 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2122 // Condition : Start time of the item < end time of filter
2123 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
2124 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2125 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
2126 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2129 calendar_query_h allDayEventInstanceQueryHandle = null;
2130 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
2131 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2132 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
2134 calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
2135 calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
2137 // Generate event : category map
2138 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(GenerateEventCategoryMapN());
2139 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2141 int startIndex = (pageNo - 1) * countPerPage;
2143 calendar_list_h allDayEventInstanceListHandle = null;
2144 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, 0, 0, &allDayEventInstanceListHandle);
2145 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2146 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2147 _CalendarList allDayEventList(allDayEventInstanceListHandle);
2149 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2150 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2151 result r = pList->Construct();
2152 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2154 int remainingCount = countPerPage;
2155 int candidateCount = 0;
2157 calendar_list_get_count(allDayEventInstanceListHandle, &count);
2158 calendar_list_first(allDayEventInstanceListHandle);
2159 for (int i = 0; i < count && remainingCount > 0; i++)
2161 calendar_record_h tmpRecordHandle = null;
2162 calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
2164 int tmpCategory = (int) EVENT_CATEGORY_ALL;
2166 calendar_record_get_int(tmpRecordHandle, _calendar_instance_allday_calendar_book.event_id, &eventId);
2167 pEventCategoryMap->GetValue(eventId, tmpCategory);
2169 if (tmpCategory == (int) category)
2171 if (candidateCount >= startIndex)
2173 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2174 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2176 r = pList->Add(*pTmpEventInstance.release());
2177 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2185 calendar_list_next(allDayEventInstanceListHandle);
2188 if (remainingCount > 0)
2190 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
2191 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
2192 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2193 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
2195 calendar_filter_h subFilterHandle = null;
2196 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2197 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2198 _CalendarFilter subFilter(subFilterHandle);
2199 subFilterHandle = null;
2201 // Condition : End time of the item > start time of filter
2202 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2203 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2205 // Condition : Start time of the item < end time of filter
2206 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2207 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2208 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2209 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2211 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2212 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2214 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2215 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2216 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2217 subFilter.ResetHandle(subFilterHandle);
2218 subFilterHandle = null;
2220 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2221 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2222 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2223 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2224 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2225 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2227 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2228 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2229 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2230 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2233 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2234 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2235 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2236 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2238 calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2239 calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2241 if (remainingCount == countPerPage)
2243 int pageCount = candidateCount / countPerPage;
2244 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (candidateCount % countPerPage);
2251 calendar_list_h nonAllDayEventInstanceListHandle = null;
2252 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, 0, 0, &nonAllDayEventInstanceListHandle);
2253 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2254 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2255 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2260 calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2261 calendar_list_first(nonAllDayEventInstanceListHandle);
2262 for (int i = 0; i < count && remainingCount > 0; i++)
2264 calendar_record_h tmpRecordHandle = null;
2265 calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2267 int tmpCategory = (int) EVENT_CATEGORY_ALL;
2269 calendar_record_get_int(tmpRecordHandle, _calendar_instance_normal_calendar_book.event_id, &eventId);
2270 pEventCategoryMap->GetValue(eventId, tmpCategory);
2272 if (tmpCategory == (int) category)
2274 if (candidateCount >= startIndex)
2276 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2277 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2279 r = pList->Add(*pTmpEventInstance.release());
2280 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2288 calendar_list_next(nonAllDayEventInstanceListHandle);
2292 return pList.release();
2296 _CalendarbookImpl::GenerateEventCategoryMapN(void) const
2298 result r = E_SUCCESS;
2299 int errorCode = CALENDAR_ERROR_NONE;
2301 unsigned int projectionList[_NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION] = {_calendar_event.id, _calendar_event.categories};
2304 calendar_query_h queryHandle = null;
2305 errorCode = calendar_query_create(_calendar_event._uri, &queryHandle);
2306 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2307 _CalendarQuery query(queryHandle);
2309 calendar_query_set_projection(queryHandle, projectionList, _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION);
2310 calendar_query_set_sort(queryHandle, _calendar_event.id, true);
2312 calendar_list_h calendarListHandle = null;
2313 errorCode = calendar_db_get_records_with_query(queryHandle, 0, 0, &calendarListHandle);
2314 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2315 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2316 _CalendarList calendarList(calendarListHandle);
2318 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(new HashMapT<int, int>());
2319 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2320 r = pEventCategoryMap->Construct();
2321 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2324 calendar_list_get_count(calendarListHandle, &count);
2325 calendar_list_first(calendarListHandle);
2326 for (int i = 0; i < count; i++)
2328 calendar_record_h tmpRecordHandle = null;
2329 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
2332 char* pCategories = null;
2334 calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &eventId);
2335 calendar_record_get_str_p(tmpRecordHandle, _calendar_event.categories, &pCategories);
2337 int category = _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
2339 pEventCategoryMap->Add(eventId, category);
2341 calendar_list_next(calendarListHandle);
2344 return pEventCategoryMap.release();
2348 _CalendarbookImpl::GetCalendarItemTypeByCalendarId(RecordId calendarId) const
2350 CalendarItemType calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2352 int errorCode = CALENDAR_ERROR_NONE;
2353 calendar_record_h calendarHandle = null;
2354 int storeType = CALENDAR_BOOK_TYPE_NONE;
2356 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2357 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, CALENDAR_ITEM_TYPE_EVENT_AND_TODO, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2359 calendar_record_get_int(calendarHandle, _calendar_book.store_type, &storeType);
2361 if (storeType == (CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO))
2363 calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2365 else if (storeType == CALENDAR_BOOK_TYPE_EVENT)
2367 calendarItemType = CALENDAR_ITEM_TYPE_EVENT_ONLY;
2369 else if (storeType == CALENDAR_BOOK_TYPE_TODO)
2371 calendarItemType = CALENDAR_ITEM_TYPE_TODO_ONLY;
2375 SetLastResult(E_SYSTEM);
2376 SysLogException(NID_SCL, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2377 calendar_record_destroy(calendarHandle, true);
2378 return CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2381 calendar_record_destroy(calendarHandle, true);
2383 return calendarItemType;
2387 _CalendarbookImpl::CheckEventExistance(RecordId eventId) const
2389 int errorCode = CALENDAR_ERROR_NONE;
2390 calendar_record_h eventHandle = null;
2392 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
2393 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2395 calendar_record_destroy(eventHandle, true);
2401 _CalendarbookImpl::CheckTodoExistance(RecordId todoId) const
2403 int errorCode = CALENDAR_ERROR_NONE;
2404 calendar_record_h todoHandle = null;
2406 errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
2407 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2409 calendar_record_destroy(todoHandle, true);
2415 _CalendarbookImpl::CheckCalendarExistance(RecordId calendarId) const
2417 int errorCode = CALENDAR_ERROR_NONE;
2418 calendar_record_h calendarHandle = null;
2420 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2421 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2423 calendar_record_destroy(calendarHandle, true);
2429 _CalendarbookImpl::CheckValidTodoPriority(unsigned long priority) const
2431 if ((priority & TODO_PRIORITY_LOW) || (priority & TODO_PRIORITY_NORMAL) || (priority & TODO_PRIORITY_HIGH))
2440 _CalendarbookImpl::CheckValidTodoStatus(unsigned long status) const
2442 if ((status & TODO_STATUS_NONE) || (status & TODO_STATUS_NEEDS_ACTION) || (status & TODO_STATUS_COMPLETED)
2443 || (status & TODO_STATUS_IN_PROCESS) || (status & TODO_STATUS_CANCELLED))
2452 _CalendarbookImpl::ConvertTodoStatusToCalendarTodoStatus(unsigned long todoStatus) const
2454 return todoStatus << 8;
2458 _CalendarbookImpl::ConvertTodoPriorityToCalendarTodoPriority(unsigned long todoPriority) const
2460 int calendarTodoPriority = CALENDAR_TODO_PRIORITY_NONE;
2462 if (todoPriority == TODO_PRIORITY_LOW)
2464 calendarTodoPriority = CALENDAR_TODO_PRIORITY_LOW;
2466 else if (todoPriority == TODO_PRIORITY_NORMAL)
2468 calendarTodoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
2470 else if (todoPriority == TODO_PRIORITY_HIGH)
2472 calendarTodoPriority = CALENDAR_TODO_PRIORITY_HIGH;
2475 return calendarTodoPriority;
2479 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2481 int errorCode = CALENDAR_ERROR_NONE;
2482 int originalEventDBId = _INVALID_EVENT_DB_ID;
2483 calendar_record_h eventHandle = null;
2485 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2486 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2488 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2489 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2490 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2492 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2493 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2495 calendar_time_s startCalendarTime;
2496 calendar_time_s endCalendarTime;
2497 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2498 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2499 calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2500 calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2502 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2503 pEventImpl->SetRecordHandle(eventHandle);
2505 return pEvent.release();
2509 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2511 int errorCode = CALENDAR_ERROR_NONE;
2512 int originalEventDBId = _INVALID_EVENT_DB_ID;
2513 calendar_record_h eventHandle = null;
2515 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2516 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2518 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2519 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2520 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2522 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2523 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2525 calendar_time_s startCalendarTime;
2526 calendar_time_s endCalendarTime;
2527 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2528 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2529 calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2530 calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2532 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2533 pEventImpl->SetRecordHandle(eventHandle);
2535 return pEvent.release();
2539 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2543 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2544 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2545 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2547 int originalEventDBId = _INVALID_EVENT_DB_ID;
2548 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2549 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2551 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2552 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.calendar_book_id, &calendarDBId);
2553 pEventInstanceImpl->SetCalendarId(calendarDBId);
2555 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2556 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.busy_status, &srcEventBusyStatus);
2557 BusyStatus busyStatus = BUSY_STATUS_FREE;
2558 switch (srcEventBusyStatus)
2560 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2561 busyStatus = BUSY_STATUS_FREE;
2563 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2564 busyStatus = BUSY_STATUS_BUSY;
2566 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2567 busyStatus = BUSY_STATUS_UNAVAILABLE;
2569 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2570 busyStatus = BUSY_STATUS_TENTATIVE;
2573 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busy status = %d", srcEventBusyStatus);
2574 busyStatus = BUSY_STATUS_FREE;
2577 pEventInstanceImpl->SetBusyStatus(busyStatus);
2579 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2580 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_status, &srcEventStatus);
2581 EventStatus eventStatus = EVENT_STATUS_NONE;
2582 switch (srcEventStatus)
2584 case CALENDAR_EVENT_STATUS_NONE:
2585 eventStatus = EVENT_STATUS_NONE;
2587 case CALENDAR_EVENT_STATUS_TENTATIVE:
2588 eventStatus = EVENT_STATUS_TENTATIVE;
2590 case CALENDAR_EVENT_STATUS_CONFIRMED:
2591 eventStatus = EVENT_STATUS_CONFIRMED;
2593 case CALENDAR_EVENT_STATUS_CANCELLED:
2594 eventStatus = EVENT_STATUS_CANCELLED;
2597 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", srcEventStatus);
2598 eventStatus = EVENT_STATUS_NONE;
2600 pEventInstanceImpl->SetStatus(eventStatus);
2602 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2603 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.priority, &srcPriority);
2604 EventPriority priority = EVENT_PRIORITY_NORMAL;
2605 switch (srcPriority)
2607 case CALENDAR_EVENT_PRIORITY_LOW:
2608 priority = EVENT_PRIORITY_LOW;
2610 case CALENDAR_EVENT_PRIORITY_NONE:
2612 case CALENDAR_EVENT_PRIORITY_NORMAL:
2613 priority = EVENT_PRIORITY_NORMAL;
2615 case CALENDAR_EVENT_PRIORITY_HIGH:
2616 priority = EVENT_PRIORITY_HIGH;
2619 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", srcPriority);
2620 priority = EVENT_PRIORITY_NORMAL;
2622 pEventInstanceImpl->SetPriority(priority);
2624 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2625 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.sensitivity, &srcSensitivity);
2626 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2627 switch (srcSensitivity)
2629 case CALENDAR_SENSITIVITY_PUBLIC:
2630 sensitivity = SENSITIVITY_PUBLIC;
2632 case CALENDAR_SENSITIVITY_PRIVATE:
2633 sensitivity = SENSITIVITY_PRIVATE;
2635 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2636 sensitivity = SENSITIVITY_CONFIDENTIAL;
2639 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
2640 sensitivity = SENSITIVITY_PUBLIC;
2642 pEventInstanceImpl->SetSensitivity(sensitivity);
2644 calendar_time_s startCalendarTime;
2645 DateTime tmpStartTime;
2646 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2647 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
2648 pEventInstanceImpl->SetStartTime(tmpStartTime);
2650 calendar_time_s endCalendarTime;
2651 DateTime tmpEndTime;
2652 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2653 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
2654 pEventInstanceImpl->SetEndTime(tmpEndTime);
2656 pEventInstanceImpl->SetAllDayEvent(true);
2658 int isRecurring = 0;
2659 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_rrule, &isRecurring);
2660 pEventInstanceImpl->SetRecurring(isRecurring);
2662 int hasReminder = 0;
2663 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_alarm, &hasReminder);
2664 pEventInstanceImpl->SetHasReminder(hasReminder);
2666 char* pSubject = null;
2667 calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.summary, &pSubject);
2668 pEventInstanceImpl->SetSubject(pSubject);
2670 char* pDescription = null;
2671 calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.description, &pDescription);
2672 pEventInstanceImpl->SetDescription(pDescription);
2674 char* pLocation = null;
2675 calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.location, &pLocation);
2676 pEventInstanceImpl->SetLocation(pLocation);
2678 return pEventInstance.release();
2682 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2686 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2687 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2688 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2690 int originalEventDBId = _INVALID_EVENT_DB_ID;
2691 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2692 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2694 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2695 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.calendar_book_id, &calendarDBId);
2696 pEventInstanceImpl->SetCalendarId(calendarDBId);
2698 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2699 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.busy_status, &srcEventBusyStatus);
2700 BusyStatus busyStatus = BUSY_STATUS_FREE;
2701 switch (srcEventBusyStatus)
2703 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2704 busyStatus = BUSY_STATUS_FREE;
2706 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2707 busyStatus = BUSY_STATUS_BUSY;
2709 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2710 busyStatus = BUSY_STATUS_UNAVAILABLE;
2712 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2713 busyStatus = BUSY_STATUS_TENTATIVE;
2716 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busy status = %d", srcEventBusyStatus);
2717 busyStatus = BUSY_STATUS_FREE;
2720 pEventInstanceImpl->SetBusyStatus(busyStatus);
2722 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2723 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_status, &srcEventStatus);
2725 EventStatus eventStatus = EVENT_STATUS_NONE;
2726 switch (srcEventStatus)
2728 case CALENDAR_EVENT_STATUS_NONE:
2729 eventStatus = EVENT_STATUS_NONE;
2731 case CALENDAR_EVENT_STATUS_TENTATIVE:
2732 eventStatus = EVENT_STATUS_TENTATIVE;
2734 case CALENDAR_EVENT_STATUS_CONFIRMED:
2735 eventStatus = EVENT_STATUS_CONFIRMED;
2737 case CALENDAR_EVENT_STATUS_CANCELLED:
2738 eventStatus = EVENT_STATUS_CANCELLED;
2741 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", srcEventStatus);
2742 eventStatus = EVENT_STATUS_NONE;
2744 pEventInstanceImpl->SetStatus(eventStatus);
2746 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2747 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.priority, &srcPriority);
2748 EventPriority priority = EVENT_PRIORITY_NORMAL;
2749 switch (srcPriority)
2751 case CALENDAR_EVENT_PRIORITY_LOW:
2752 priority = EVENT_PRIORITY_LOW;
2754 case CALENDAR_EVENT_PRIORITY_NONE:
2756 case CALENDAR_EVENT_PRIORITY_NORMAL:
2757 priority = EVENT_PRIORITY_NORMAL;
2759 case CALENDAR_EVENT_PRIORITY_HIGH:
2760 priority = EVENT_PRIORITY_HIGH;
2763 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", srcPriority);
2764 priority = EVENT_PRIORITY_NORMAL;
2766 pEventInstanceImpl->SetPriority(priority);
2768 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2769 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.sensitivity, &srcSensitivity);
2770 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2771 switch (srcSensitivity)
2773 case CALENDAR_SENSITIVITY_PUBLIC:
2774 sensitivity = SENSITIVITY_PUBLIC;
2776 case CALENDAR_SENSITIVITY_PRIVATE:
2777 sensitivity = SENSITIVITY_PRIVATE;
2779 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2780 sensitivity = SENSITIVITY_CONFIDENTIAL;
2783 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
2784 sensitivity = SENSITIVITY_PUBLIC;
2786 pEventInstanceImpl->SetSensitivity(sensitivity);
2788 calendar_time_s startCalendarTime;
2789 DateTime tmpStartTime;
2790 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2791 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
2792 pEventInstanceImpl->SetStartTime(tmpStartTime);
2794 calendar_time_s endCalendarTime;
2795 DateTime tmpEndTime;
2796 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2797 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
2798 pEventInstanceImpl->SetEndTime(tmpEndTime);
2800 pEventInstanceImpl->SetAllDayEvent(false);
2802 int isRecurring = 0;
2803 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_rrule, &isRecurring);
2804 pEventInstanceImpl->SetRecurring(isRecurring);
2806 int hasReminder = 0;
2807 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_alarm, &hasReminder);
2808 pEventInstanceImpl->SetHasReminder(hasReminder);
2810 char* pSubject = null;
2811 calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.summary, &pSubject);
2812 pEventInstanceImpl->SetSubject(pSubject);
2814 char* pDescription = null;
2815 calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.description, &pDescription);
2816 pEventInstanceImpl->SetDescription(pDescription);
2818 char* pLocation = null;
2819 calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.location, &pLocation);
2820 pEventInstanceImpl->SetLocation(pLocation);
2822 return pEventInstance.release();
2826 _CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(calendar_record_h modifiedEventHandle)
2830 std::unique_ptr<CalEventChangeInfo> pEventChangeInfo(new (std::nothrow) CalEventChangeInfo());
2831 SysTryReturn(NID_SCL, pEventChangeInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2832 _CalEventChangeInfoImpl* pEventChangeInfoImpl = _CalEventChangeInfoImpl::GetInstance(*pEventChangeInfo.get());
2835 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.id, &eventId);
2836 pEventChangeInfoImpl->SetEventId(eventId);
2838 int calendarbookId = 0;
2839 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2840 pEventChangeInfoImpl->SetCalendarId(calendarbookId);
2842 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2843 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2844 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2845 switch (modifiedStatus)
2847 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2848 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2850 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2851 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2853 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2854 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2857 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. modified status = %d", modifiedStatus);
2860 pEventChangeInfoImpl->SetChangeType(recordChangeType);
2863 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.version, &version);
2864 pEventChangeInfoImpl->SetVersion(version);
2866 return pEventChangeInfo.release();
2870 _CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(calendar_record_h modifiedTodoHandle)
2874 std::unique_ptr<CalTodoChangeInfo> pTodoChangeInfo(new (std::nothrow) CalTodoChangeInfo());
2875 SysTryReturn(NID_SCL, pTodoChangeInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2876 _CalTodoChangeInfoImpl* pTodoChangeInfoImpl = _CalTodoChangeInfoImpl::GetInstance(*pTodoChangeInfo.get());
2879 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.id, &todoId);
2880 pTodoChangeInfoImpl->SetTodoId(todoId);
2882 int calendarbookId = 0;
2883 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2884 pTodoChangeInfoImpl->SetCalendarId(calendarbookId);
2886 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2887 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2888 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2890 switch (modifiedStatus)
2892 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2893 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2895 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2896 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2898 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2899 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2902 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. modified status = %d", modifiedStatus);
2905 pTodoChangeInfoImpl->SetChangeType(recordChangeType);
2908 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.version, &version);
2909 pTodoChangeInfoImpl->SetVersion(version);
2911 return pTodoChangeInfo.release();
2914 template<typename RecordType, typename RecordTypeImpl, typename RecordView>
2916 _CalendarbookImpl::ConvertRecordListN(calendar_list_h resultListHandle, RecordView recordView)
2918 result r = E_SUCCESS;
2920 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2921 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2922 r = pList->Construct();
2923 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2926 calendar_list_get_count(resultListHandle, &count);
2928 for (int i = 0; i < count; i++)
2930 std::unique_ptr<RecordType> pTmpRecord(RecordTypeImpl::CreateDefaultInstanceN());
2931 SysTryReturn(NID_SCL, pTmpRecord != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2933 r = pList->Add(*pTmpRecord.release());
2934 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2937 calendar_list_first(resultListHandle);
2938 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2939 while (pEnum->MoveNext() == E_SUCCESS)
2941 RecordType* pTmpRecord = static_cast<RecordType*>(pEnum->GetCurrent());
2943 calendar_record_h tmpRecordHandle = null;
2944 calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2945 RecordTypeImpl::GetInstance(*pTmpRecord)->SetRecordHandle(tmpRecordHandle);
2948 calendar_record_get_int(tmpRecordHandle, recordView.id, &dbIndex);
2949 _RecordImpl::GetInstance(*pTmpRecord)->SetRecordId(dbIndex);
2951 calendar_list_next(resultListHandle);
2954 return pList.release();
2958 _CalendarbookImpl::ConvertEventInstanceListN(calendar_list_h resultListHandle, bool isAllDay)
2960 result r = E_SUCCESS;
2962 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2963 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2964 r = pList->Construct();
2965 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2968 calendar_list_get_count(resultListHandle, &count);
2969 calendar_list_first(resultListHandle);
2970 for (int i = 0; i < count; i++)
2972 calendar_record_h tmpRecordHandle = null;
2973 calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2975 std::unique_ptr<CalEventInstance> pTmpEventInstance;
2979 pTmpEventInstance.reset(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2980 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2984 pTmpEventInstance.reset(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2985 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2988 r = pList->Add(*pTmpEventInstance.release());
2989 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2991 calendar_list_next(resultListHandle);
2994 return pList.release();
2998 _CalendarbookImpl::OnCalEventChanged(void)
3000 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
3005 _CalendarConnector connector;
3006 result r = connector.GetResult();
3007 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3009 std::unique_ptr<IList, AllElementsDeleter> pChangedEventList(GetChangedEventsAfterN(__dbVersionForEvent, __dbVersionForEvent));
3010 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Propagating.");
3011 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3013 if (pChangedEventList->GetCount() > 0)
3015 if (__pICalendarbookEventListener != null)
3017 __pICalendarbookEventListener->OnCalendarEventsChanged(*pChangedEventList.get());
3021 RecordEventType recordEventType = RECORD_ADDED;
3022 IEnumerator* pEnum = pChangedEventList->GetEnumeratorN();
3023 CalEvent* pEvent = null;
3025 while (pEnum->MoveNext() == E_SUCCESS)
3027 CalEventChangeInfo* pEventChagneInfo = static_cast<CalEventChangeInfo*>(pEnum->GetCurrent());
3029 if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
3031 recordEventType = RECORD_ADDED;
3032 pEvent = GetEventN(pEventChagneInfo->GetEventId());
3035 if (GetLastResult() == E_OBJ_NOT_FOUND)
3045 else if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3047 recordEventType = RECORD_UPDATED;
3048 pEvent = GetEventN(pEventChagneInfo->GetEventId());
3051 if (GetLastResult() == E_OBJ_NOT_FOUND)
3063 recordEventType = RECORD_REMOVED;
3064 pEvent = new (std::nothrow) CalEvent();
3067 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3071 _RecordImpl::GetInstance(*pEvent)->SetRecordId(pEventChagneInfo->GetEventId());
3074 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_EVENT, *pEvent, null, null);
3085 _CalendarbookImpl::OnCalTodoChanged(void)
3087 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
3092 _CalendarConnector connector;
3093 result r = connector.GetResult();
3094 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3096 std::unique_ptr<IList, AllElementsDeleter> pChangedTodoList(GetChangedTodosAfterN(__dbVersionForTodo, __dbVersionForTodo));
3097 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Propagating.");
3098 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3100 if (pChangedTodoList->GetCount() > 0)
3102 if (__pICalendarbookEventListener != null)
3104 __pICalendarbookEventListener->OnCalendarTodosChanged(*pChangedTodoList.get());
3108 RecordEventType recordEventType = RECORD_ADDED;
3109 IEnumerator* pEnum = pChangedTodoList->GetEnumeratorN();
3110 CalTodo* pTodo = null;
3112 while (pEnum->MoveNext() == E_SUCCESS)
3114 CalTodoChangeInfo* pTodoChagneInfo = static_cast<CalTodoChangeInfo*>(pEnum->GetCurrent());
3116 if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
3118 recordEventType = RECORD_ADDED;
3119 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3122 if (GetLastResult() == E_OBJ_NOT_FOUND)
3132 else if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3134 recordEventType = RECORD_UPDATED;
3135 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3138 if (GetLastResult() == E_OBJ_NOT_FOUND)
3150 recordEventType = RECORD_REMOVED;
3151 pTodo = new (std::nothrow) CalTodo();
3154 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3158 _RecordImpl::GetInstance(*pTodo)->SetRecordId(pTodoChagneInfo->GetTodoId());
3161 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_TODO, *pTodo, null, null);
3172 _CalendarbookImpl::GetInstance(Calendarbook& calendarbook)
3174 return calendarbook.__pCalendarbookImpl;
3177 const _CalendarbookImpl*
3178 _CalendarbookImpl::GetInstance(const Calendarbook& calendarbook)
3180 return calendarbook.__pCalendarbookImpl;