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 <FBaseColArrayList.h>
26 #include <FBaseColHashMapT.h>
27 #include <FBaseDateTime.h>
28 #include <FBaseSysLog.h>
29 #include <FBase_StringConverter.h>
30 #include <FBaseUtilStringUtil.h>
32 #include <FLclTimeZone.h>
33 #include <FSclCalendar.h>
34 #include <FSclCalendarbook.h>
35 #include <FSclCalEvent.h>
36 #include <FSclCalEventChangeInfo.h>
37 #include <FSclCalEventInstance.h>
38 #include <FSclCalTodo.h>
39 #include <FSclCalTodoChangeInfo.h>
40 #include <FSclICalendarbookEventListener.h>
41 #include <FSclIRecordEventListener.h>
42 #include <FSclIRecordListener.h>
43 #include "FScl_CalendarbookImpl.h"
44 #include "FScl_CalendarbookFilterImpl.h"
45 #include "FScl_CalendarbookDbConnector.h"
46 #include "FScl_CalendarbookDbMonitor.h"
47 #include "FScl_CalendarbookRecordRetrivalEvent.h"
48 #include "FScl_CalendarbookRecordRetrivalThread.h"
49 #include "FScl_CalendarbookUtil.h"
50 #include "FScl_CalEventChangeInfoImpl.h"
51 #include "FScl_CalendarImpl.h"
52 #include "FScl_CalEventImpl.h"
53 #include "FScl_CalEventInstanceImpl.h"
54 #include "FScl_CalTodoChangeInfoImpl.h"
55 #include "FScl_CalTodoImpl.h"
56 #include "FScl_RecordImpl.h"
58 using namespace Tizen::Base;
59 using namespace Tizen::Base::Collection;
60 using namespace Tizen::Base::Utility;
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)
296 _CalendarbookDbMonitor* pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
297 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
299 result r = E_SUCCESS;
301 int dbVersion = GetLatestVersion();
302 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
304 r = pCalendarbookDbMonitor->AddListener(*this);
305 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
307 __pICalendarbookEventListener = &listener;
308 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
310 __dbVersionForEvent = dbVersion;
311 __dbVersionForTodo = dbVersion;
316 pCalendarbookDbMonitor->Release();
322 _CalendarbookImpl::AddEvent(CalEvent& event)
324 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
325 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
326 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
327 , "Invalid argument is used. The event is not an entry type instance.");
329 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
331 int errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, _DEFAULT_EVENT_CALENDAR_DB_ID);
332 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
335 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
336 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
337 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
338 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
340 calendar_record_h tmpEventHandle = null;
341 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
342 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
343 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
349 _CalendarbookImpl::AddEvent(CalEvent& event, RecordId calendarId)
351 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
352 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
353 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
354 , "Invalid argument is used. The event is not an entry type instance.");
355 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
356 , "Invalid argument is used. calendarId = %d", calendarId);
357 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
358 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
359 SysTryReturnResult(NID_SCL,(itemType == CALENDAR_ITEM_TYPE_EVENT_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
360 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_TODO_ONLY");
362 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
364 int errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, calendarId);
365 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
368 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
369 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
370 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
371 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
373 calendar_record_h tmpEventHandle = null;
374 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
375 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
376 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
382 _CalendarbookImpl::AddTodo(CalTodo& todo)
384 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
385 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
387 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
389 int errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, _DEFAULT_TODO_CALENDAR_DB_ID);
390 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
393 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
394 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
395 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
396 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
398 calendar_record_h tmpTodoHandle = null;
399 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
400 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
401 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
407 _CalendarbookImpl::AddTodo(CalTodo& todo, RecordId calendarId)
409 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
410 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
411 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
412 , "Invalid argument is used. calendarId = %d", calendarId);
413 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
414 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
415 SysTryReturnResult(NID_SCL, (itemType == CALENDAR_ITEM_TYPE_TODO_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
416 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_EVENT_ONLY");
418 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
420 int errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, calendarId);
423 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
424 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
425 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
426 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
428 calendar_record_h tmpTodoHandle = null;
429 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
430 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
431 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
437 _CalendarbookImpl::AddCalendar(Calendar& calendar)
439 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
440 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
442 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
445 int errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
446 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
447 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
448 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
450 calendar_record_h tmpCalendarHandle = null;
451 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
452 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
453 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
459 _CalendarbookImpl::AddCalendar(Calendar& calendar, AccountId accountId)
461 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
462 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
463 SysTryReturnResult(NID_SCL, accountId >= 0, E_INVALID_ARG, "Invalid argument is used.");
465 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
467 int errorCode = calendar_record_set_int(calendarHandle, _calendar_book.account_id, accountId);
468 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
471 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
472 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
473 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
474 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
476 calendar_record_h tmpCalendarHandle = null;
477 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
478 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
479 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
485 _CalendarbookImpl::RemoveEvent(CalEvent& event)
487 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
488 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
490 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
492 int baseEventId = _INVALID_EVENT_DB_ID;
493 int errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
494 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
495 , "Invalid argument is used. The event has the base event id.");
497 errorCode = calendar_db_delete_record(_calendar_event._uri, event.GetRecordId());
498 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
499 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
501 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(event);
502 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
508 _CalendarbookImpl::RemoveEvent(RecordId eventId)
510 SysTryReturnResult(NID_SCL, eventId != INVALID_RECORD_ID, E_INVALID_ARG
511 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
513 calendar_record_h eventHandle = null;
515 int errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
516 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
518 int baseEventId = _INVALID_EVENT_DB_ID;
519 calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
521 calendar_record_destroy(eventHandle, true);
523 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
524 , "Invalid argument is used. The event of eventId has the base event id.");
526 errorCode = calendar_db_delete_record(_calendar_event._uri, eventId);
527 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
533 _CalendarbookImpl::RemoveTodo(CalTodo& todo)
535 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(todo);
537 result r = RemoveTodo(todo.GetRecordId());
538 SysTryReturnResult(NID_SCL, !IsFailed(r), r, "Failed to remove the todo.");
539 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
545 _CalendarbookImpl::RemoveTodo(RecordId todoId)
547 SysTryReturnResult(NID_SCL, todoId != INVALID_RECORD_ID, E_INVALID_ARG
548 , "Invalid argument is used. The specified todoId is INVALID_RECORD_ID.");
550 int errorCode = calendar_db_delete_record(_calendar_todo._uri, todoId);
551 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
552 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
558 _CalendarbookImpl::RemoveCalendar(RecordId calendarId)
560 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
561 , "The specified calendarId is INVALID_RECORD_ID.");
562 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_EVENT_CALENDAR_DB_ID
563 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
564 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_TODO_CALENDAR_DB_ID
565 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
566 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendarId), E_OBJ_NOT_FOUND, "The specified record is not found.");
568 int errorCode = calendar_db_delete_record(_calendar_book._uri, calendarId);
569 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
575 _CalendarbookImpl::UpdateEvent(const CalEvent& event)
577 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
578 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
579 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
580 , "Invalid argument is used. The event is not an entry type instance.");
582 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
584 int baseEventId = _INVALID_EVENT_DB_ID;
585 int errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
586 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
587 , "Invalid argument is used. The event has the base event id.");
589 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
591 errorCode = calendar_db_update_record(eventHandle);
592 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
593 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
599 _CalendarbookImpl::UpdateTodo(const CalTodo& todo)
601 SysTryReturnResult(NID_SCL, todo.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
602 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
603 SysTryReturnResult(NID_SCL, CheckTodoExistance(todo.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
605 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
606 int errorCode = calendar_db_update_record(todoHandle);
607 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
613 _CalendarbookImpl::UpdateCalendar(const Calendar& calendar)
615 SysTryReturnResult(NID_SCL, calendar.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
616 , "The specified recordId is INVALID_RECORD_ID.");
617 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendar.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
619 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
620 int errorCode = calendar_db_update_record(calendarHandle);
621 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
627 _CalendarbookImpl::GetEventN(RecordId eventId) const
631 SysTryReturn(NID_SCL, eventId != INVALID_RECORD_ID, null, E_INVALID_ARG
632 , "[%s] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
634 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
635 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
637 calendar_record_h eventHandle = null;
638 int errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
639 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
640 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The specified record is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
642 _CalEventImpl::GetInstance(*pEvent.get())->SetRecordHandle(eventHandle);
643 _RecordImpl::GetInstance(*pEvent.get())->SetRecordId(eventId);
645 return pEvent.release();
649 _CalendarbookImpl::GetTodoN(RecordId todoId) const
653 SysTryReturn(NID_SCL, todoId != INVALID_RECORD_ID, null, E_INVALID_ARG
654 , "[%s] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
656 std::unique_ptr<CalTodo> pTodo(new (std::nothrow) CalTodo());
657 SysTryReturn(NID_SCL, pTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
659 calendar_record_h todoHandle = null;
660 int errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
661 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
662 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The specified record is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
664 _CalTodoImpl::GetInstance(*pTodo.get())->SetRecordHandle(todoHandle);
665 _RecordImpl::GetInstance(*pTodo.get())->SetRecordId(todoId);
667 return pTodo.release();
671 _CalendarbookImpl::GetCalendarN(RecordId calendarId) const
675 SysTryReturn(NID_SCL, calendarId != INVALID_RECORD_ID, null, E_INVALID_ARG
676 , "[%s] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
678 std::unique_ptr<Calendar> pCalendar(new (std::nothrow) Calendar(CALENDAR_ITEM_TYPE_EVENT_AND_TODO));
679 SysTryReturn(NID_SCL, pCalendar != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
681 calendar_record_h calendarHandle = null;
682 int errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
683 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
684 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The specified record is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
686 _CalendarImpl::GetInstance(*pCalendar.get())->SetRecordHandle(calendarHandle);
687 _RecordImpl::GetInstance(*pCalendar.get())->SetRecordId(calendarId);
689 return pCalendar.release();
693 _CalendarbookImpl::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status,
694 unsigned long priority) const
698 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The pageNo or countPerPage is less than 1.", GetErrorMessage(E_INVALID_ARG));
699 SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG));
700 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer());
701 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer());
702 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), null, E_INVALID_ARG, "[%s] Invalid argument is used. status = %ld", GetErrorMessage(E_INVALID_ARG), status);
703 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), null, E_INVALID_ARG, "[%s] Invalid argument is used. priority = %ld", GetErrorMessage(E_INVALID_ARG), priority);
707 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
708 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
709 calendar_time_s convertedStartTime;
710 calendar_time_s convertedEndTime;
711 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
712 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
714 calendar_filter_h mainFilterHandle = null;
715 int errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
716 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
717 _CalendarFilter mainFilter(mainFilterHandle);
719 // Condition : Due time of the item >= start time of filter
720 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
721 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
723 // Condition : Due time of the item <= end time of filter
724 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
725 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
726 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
727 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
729 // Condition : status
730 calendar_filter_h subFilterHandle = null;
731 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
732 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
733 _CalendarFilter subFilter(subFilterHandle);
734 subFilterHandle = null;
736 int tmpStatus = TODO_STATUS_NONE;
737 bool alreadyAdded = false;
738 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
740 if (status & tmpStatus)
744 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
745 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
748 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
749 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
757 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
758 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
759 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
760 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
762 // Condition : priority
763 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
764 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
765 subFilter.ResetHandle(subFilterHandle);
766 subFilterHandle = null;
768 int tmpPriority = TODO_PRIORITY_LOW;
769 alreadyAdded = false;
770 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
772 if (priority & tmpPriority)
776 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
777 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
780 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
781 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
788 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
789 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
790 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
791 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
794 calendar_query_h queryHandle = null;
795 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
796 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
797 _CalendarQuery query(queryHandle);
799 calendar_query_set_sort(queryHandle, _calendar_todo.due_time, true);
800 calendar_query_set_filter(queryHandle, mainFilterHandle);
802 calendar_list_h calendarListHandle = null;
803 errorCode = calendar_db_get_records_with_query(queryHandle, (pageNo - 1) * countPerPage, countPerPage, &calendarListHandle);
804 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
805 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
806 _CalendarList calendarList(calendarListHandle);
808 // TODO:- Should we use SingleObjectDeleter instead ?
809 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
810 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
811 result r = pList->Construct();
812 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
815 calendar_list_get_count(calendarListHandle, &count);
817 for (int i = 0; i < count; i++)
819 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
820 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
822 r = pList->Add(pTmpTodo.get());
823 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
827 calendar_list_first(calendarListHandle);
828 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
829 while (pEnum->MoveNext() == E_SUCCESS)
831 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
833 calendar_record_h tmpRecordHandle = null;
834 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
835 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
837 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
840 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
841 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
842 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
844 calendar_list_next(calendarListHandle);
847 calendar_list_destroy(calendarList.ReleaseHandle(), false);
849 return pList.release();
853 _CalendarbookImpl::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const
857 SysTryReturn(NID_SCL, start <= end, _INVALID_COUNT
858 , E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG));
859 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), _INVALID_COUNT
860 , E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer());
861 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), _INVALID_COUNT
862 , E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer());
863 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), _INVALID_COUNT
864 , E_INVALID_ARG, "[%s] Invalid argument is used. status = %ld", GetErrorMessage(E_INVALID_ARG), status);
865 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), _INVALID_COUNT
866 , E_INVALID_ARG, "[%s] Invalid argument is used. priority = %ld", GetErrorMessage(E_INVALID_ARG), priority);
870 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
871 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
872 calendar_time_s convertedStartTime;
873 calendar_time_s convertedEndTime;
874 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
875 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
877 calendar_filter_h mainFilterHandle = null;
878 int errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
879 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
880 _CalendarFilter mainFilter(mainFilterHandle);
882 // Condition : Due time of the item => start time of filter
883 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
884 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
886 // Condition : Due time of the item <= end time of filter
887 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
888 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
889 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
890 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
892 // Condition : status
893 calendar_filter_h subFilterHandle = null;
894 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
895 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
896 _CalendarFilter subFilter(subFilterHandle);
897 subFilterHandle = null;
899 int tmpStatus = TODO_STATUS_NONE;
900 bool alreadyAdded = false;
901 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
903 if (status & tmpStatus)
907 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
908 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
911 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
912 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
919 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
920 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
921 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
922 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
924 // Condition : priority
925 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
926 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
927 subFilter.ResetHandle(subFilterHandle);
928 subFilterHandle = null;
930 int tmpPriority = TODO_PRIORITY_LOW;
931 alreadyAdded = false;
932 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
934 if (priority & tmpPriority)
938 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
939 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
942 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
943 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
950 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
951 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
952 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
953 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
956 calendar_query_h queryHandle = null;
957 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
958 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
959 _CalendarQuery query(queryHandle);
961 calendar_query_set_filter(queryHandle, mainFilterHandle);
963 int count = _INVALID_COUNT;
965 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
966 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
972 _CalendarbookImpl::GetEventInstancesN(const DateTime& start, const DateTime& end,
973 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage,
974 unsigned long category) const
978 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The pageNo or countPerPage is less than 1.", GetErrorMessage(E_INVALID_ARG));
979 SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG));
980 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer());
981 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer());
982 SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), null, E_INVALID_ARG, "[%s] Invalid argument is used. category = %ld", GetErrorMessage(E_INVALID_ARG), category);
984 std::unique_ptr<IList, AllElementsDeleter> pList(GetEventInstancesCommonN(start, end, timeZone, pageNo, countPerPage, category));
985 result r = GetLastResult();
986 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
988 return pList.release();
992 _CalendarbookImpl::GetEventInstances(const DateTime& start, const DateTime& end,
993 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category,
994 RequestId& reqId, const IRecordListener& listener) const
999 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The pageNo or countPerPage is less than 1.", GetErrorMessage(E_INVALID_ARG));
1000 SysTryReturn(NID_SCL, start <= end, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG));
1001 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer());
1002 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer());
1003 SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. category = %ld", GetErrorMessage(E_INVALID_ARG), category);
1005 std::unique_ptr<_CalendarbookRecordRetrivalEvent> pEvent(new (std::nothrow) _CalendarbookRecordRetrivalEvent());
1006 SysTryReturnResult(NID_SCL, pEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1007 result r = pEvent->Construct();
1008 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1009 r = pEvent->AddListener(listener);
1010 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1012 if (__pRecordRetrivalThread != null)
1014 __pRecordRetrivalThread->Join();
1015 delete __pRecordRetrivalThread;
1016 __pRecordRetrivalThread = null;
1019 std::unique_ptr<_CalendarbookRecordRetrivalThread> pRecordRetrivalThread(new (std::nothrow) _CalendarbookRecordRetrivalThread());
1020 SysTryReturnResult(NID_SCL, pRecordRetrivalThread != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1021 r = pRecordRetrivalThread->Construct(__requestId, *pEvent.release(), start, end, timeZone, pageNo, countPerPage, category);
1022 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1024 r = pRecordRetrivalThread->Start();
1025 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1027 __pRecordRetrivalThread = pRecordRetrivalThread.release();
1033 _CalendarbookImpl::GetAllEventsN(void) const
1035 calendar_list_h calendarListHandle = null;
1036 int errorCode = calendar_db_get_all_records(_calendar_event._uri, 0, 0, &calendarListHandle);
1037 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1038 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1039 _CalendarList calendarList(calendarListHandle);
1041 result r = E_SUCCESS;
1042 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1043 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1044 r = pList->Construct();
1045 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1048 calendar_list_get_count(calendarListHandle, &count);
1050 for (int i = 0; i < count; i++)
1052 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1053 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1055 r = pList->Add(pTmpEvent.get());
1056 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1057 pTmpEvent.release();
1060 calendar_list_first(calendarListHandle);
1061 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1062 while (pEnum->MoveNext() == E_SUCCESS)
1064 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1066 calendar_record_h tmpRecordHandle = null;
1067 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1068 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1070 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1073 calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &dbIndex);
1074 _RecordImpl::GetInstance(*pTmpEvent)->SetRecordId(dbIndex);
1076 calendar_list_next(calendarListHandle);
1079 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1081 return pList.release();
1085 _CalendarbookImpl::GetAllTodosN(void) const
1087 calendar_list_h calendarListHandle = null;
1088 int errorCode = calendar_db_get_all_records(_calendar_todo._uri, 0, 0, &calendarListHandle);
1089 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1090 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1091 _CalendarList calendarList(calendarListHandle);
1093 result r = E_SUCCESS;
1094 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1095 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1096 r = pList->Construct();
1097 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1100 calendar_list_get_count(calendarListHandle, &count);
1102 for (int i = 0; i < count; i++)
1104 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1105 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1107 r = pList->Add(pTmpTodo.get());
1108 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1112 calendar_list_first(calendarListHandle);
1113 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1114 while (pEnum->MoveNext() == E_SUCCESS)
1116 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1118 calendar_record_h tmpRecordHandle = null;
1119 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1120 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1122 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1125 calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
1126 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
1128 calendar_list_next(calendarListHandle);
1131 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1133 return pList.release();
1137 _CalendarbookImpl::GetAllCalendarsN(void) const
1139 calendar_list_h calendarListHandle = null;
1140 int errorCode = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &calendarListHandle);
1141 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1142 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1143 _CalendarList calendarList(calendarListHandle);
1145 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1146 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1147 result r = pList->Construct();
1148 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1151 calendar_list_get_count(calendarListHandle, &count);
1153 for (int i = 0; i < count; i++)
1155 std::unique_ptr<Calendar> pTmpCalendar(_CalendarImpl::CreateDefaultInstanceN());
1156 SysTryReturn(NID_SCL, pTmpCalendar != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1158 r = pList->Add(pTmpCalendar.get());
1159 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1160 pTmpCalendar.release();
1163 calendar_list_first(calendarListHandle);
1164 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1165 while (pEnum->MoveNext() == E_SUCCESS)
1167 Calendar* pTmpCalendar = static_cast<Calendar*>(pEnum->GetCurrent());
1169 calendar_record_h tmpRecordHandle = null;
1170 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1171 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1172 _CalendarImpl::GetInstance(*pTmpCalendar)->SetRecordHandle(tmpRecordHandle);
1175 calendar_record_get_int(tmpRecordHandle, _calendar_book.id, &dbIndex);
1176 _RecordImpl::GetInstance(*pTmpCalendar)->SetRecordId(dbIndex);
1178 calendar_list_next(calendarListHandle);
1181 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1183 return pList.release();
1187 _CalendarbookImpl::GetChangedEventsAfterN(int version, int& latestVersion) const
1191 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1193 calendar_list_h calendarListHandle = null;
1194 int tmpLatestVersion = 0;
1195 int errorCode = calendar_db_get_changes_by_version(_calendar_event._uri, CALENDAR_BOOK_FILTER_ALL, version
1196 , &calendarListHandle, &tmpLatestVersion);
1197 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1198 , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1199 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1201 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1202 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1203 result r = pList->Construct();
1204 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1207 calendar_list_get_count(calendarListHandle, &count);
1209 calendar_list_first(calendarListHandle);
1210 for (int i = 0; i < count; i++)
1212 calendar_record_h tmpRecordHandle = null;
1213 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1214 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1216 std::unique_ptr<CalEventChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(tmpRecordHandle));
1217 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1219 r = pList->Add(pChangedInfo.get());
1220 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1221 pChangedInfo.release();
1223 calendar_list_next(calendarListHandle);
1226 latestVersion = tmpLatestVersion;
1228 return pList.release();
1232 _CalendarbookImpl::GetChangedTodosAfterN(int version, int& latestVersion) const
1236 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version = %d", GetErrorMessage(E_INVALID_ARG), version);
1238 calendar_list_h calendarListHandle = null;
1239 int tmpLatestVersion = 0;
1240 int errorCode = calendar_db_get_changes_by_version(_calendar_todo._uri, CALENDAR_BOOK_FILTER_ALL, version
1241 , &calendarListHandle, &tmpLatestVersion);
1242 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1243 , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1244 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1245 _CalendarList calendarList(calendarListHandle);
1247 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1248 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1249 result r = pList->Construct();
1250 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1253 calendar_list_get_count(calendarListHandle, &count);
1255 calendar_list_first(calendarListHandle);
1256 for (int i = 0; i < count; i++)
1258 calendar_record_h tmpRecordHandle = null;
1259 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1260 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1262 std::unique_ptr<CalTodoChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(tmpRecordHandle));
1263 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1265 r = pList->Add(pChangedInfo.get());
1266 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1267 pChangedInfo.release();
1269 calendar_list_next(calendarListHandle);
1272 latestVersion = tmpLatestVersion;
1274 return pList.release();
1278 _CalendarbookImpl::RemoveEventInstance(const CalEventInstance& eventInstance)
1280 calendar_record_h eventHandle = null;
1282 // Get event handle from DB
1283 int errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &eventHandle);
1284 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1285 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
1286 _CalendarRecord eventRecord(eventHandle);
1288 int baseEventId = _INVALID_EVENT_DB_ID;
1289 calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1291 if (baseEventId != _INVALID_EVENT_DB_ID)
1293 errorCode = calendar_db_delete_record(_calendar_event._uri, eventInstance.GetOriginalEventId());
1294 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1298 char* pExdate = null;
1301 calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExdate);
1304 if (pExdate != null && strlen(pExdate) > 0)
1306 exdate.Append(pExdate);
1307 exdate.Append(_RECURRENCE_DELIMITER);
1310 exdate.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent()));
1312 std::unique_ptr<char[]> pAppendedExdate(_StringConverter::CopyToCharArrayN(exdate));
1313 SysTryReturnResult(NID_SCL, pAppendedExdate != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1315 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, pAppendedExdate.get());
1316 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1318 // Update event handle
1319 errorCode = calendar_db_update_record(eventHandle);
1320 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1327 _CalendarbookImpl::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event)
1329 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
1330 , "Invalid argument is used. The event's recordId is INVALID_RECORD_ID.");
1331 SysTryReturnResult(NID_SCL, eventInstance.GetOriginalEventId() == event.GetRecordId(), E_INVALID_ARG
1332 , "[%s] Invalid argument is used. The event's recordId is not equal to eventInstance's original event ID.", GetErrorMessage(E_INVALID_ARG));
1333 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified event is not found.");
1335 calendar_record_h eventHandle = null;
1336 int errorCode = calendar_record_clone(_CalEventImpl::GetInstance(event)->GetRecordHandle(), &eventHandle);
1337 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1338 _CalendarRecord eventRecord(eventHandle);
1340 int baseEventId = _INVALID_EVENT_DB_ID;
1341 calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1343 calendar_record_h baseEventHandle = null;
1344 if (baseEventId == _INVALID_EVENT_DB_ID)
1346 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &baseEventHandle);
1350 errorCode = calendar_db_get_record(_calendar_event._uri, baseEventId, &baseEventHandle);
1352 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1353 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The base event is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1354 _CalendarRecord baseEventRecord(baseEventHandle);
1356 int tmpIntValue = 0;
1357 calendar_record_get_int(baseEventHandle, _calendar_event.freq, &tmpIntValue);
1358 calendar_record_set_int(eventHandle, _calendar_event.freq, tmpIntValue);
1359 calendar_record_get_int(baseEventHandle, _calendar_event.range_type, &tmpIntValue);
1360 calendar_record_set_int(eventHandle, _calendar_event.range_type, tmpIntValue);
1361 calendar_record_get_int(baseEventHandle, _calendar_event.count, &tmpIntValue);
1362 calendar_record_set_int(eventHandle, _calendar_event.count, tmpIntValue);
1363 calendar_record_get_int(baseEventHandle, _calendar_event.interval, &tmpIntValue);
1364 calendar_record_set_int(eventHandle, _calendar_event.interval, tmpIntValue);
1365 calendar_record_get_int(baseEventHandle, _calendar_event.wkst, &tmpIntValue);
1366 calendar_record_set_int(eventHandle, _calendar_event.wkst, tmpIntValue);
1368 calendar_time_s tmpTimeValue;
1369 calendar_record_get_caltime(baseEventHandle, _calendar_event.until_time, &tmpTimeValue);
1371 calendar_time_s tmpStartTimeValue;
1372 DateTime convertedTime;
1373 calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &tmpStartTimeValue);
1375 if (tmpTimeValue.type != tmpStartTimeValue.type)
1377 if (tmpStartTimeValue.type == CALENDAR_TIME_UTIME)
1379 convertedTime.SetValue(tmpTimeValue.time.date.year, tmpTimeValue.time.date.month, tmpTimeValue.time.date.mday);
1380 tmpTimeValue.type = CALENDAR_TIME_UTIME;
1381 tmpTimeValue.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(convertedTime);
1385 convertedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpTimeValue.time.utime);
1386 tmpTimeValue.type = CALENDAR_TIME_LOCALTIME;
1387 tmpTimeValue.time.date.year = convertedTime.GetYear();
1388 tmpTimeValue.time.date.month = convertedTime.GetMonth();
1389 tmpTimeValue.time.date.mday = convertedTime.GetDay();
1392 calendar_record_set_caltime(eventHandle, _calendar_event.until_time, tmpTimeValue);
1394 char* tmpStrValue = null;
1395 calendar_record_get_str_p(baseEventHandle, _calendar_event.byday, &tmpStrValue);
1396 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, tmpStrValue);
1397 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1399 calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonthday, &tmpStrValue);
1400 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, tmpStrValue);
1401 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1403 calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonth, &tmpStrValue);
1404 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, tmpStrValue);
1405 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1407 calendar_record_get_str_p(baseEventHandle, _calendar_event.exdate, &tmpStrValue);
1408 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, tmpStrValue);
1409 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1411 if (baseEventId == _INVALID_EVENT_DB_ID)
1413 calendar_record_set_int(eventHandle, _calendar_event.original_event_id, eventInstance.GetOriginalEventId());
1415 std::unique_ptr<char[]> pConvertedRecurrenceId(_StringConverter::CopyToCharArrayN(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent())));
1416 errorCode = calendar_record_set_str(eventHandle, _calendar_event.recurrence_id, pConvertedRecurrenceId.get());
1417 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1420 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
1421 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1422 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
1426 errorCode = calendar_db_update_record(eventHandle);
1427 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1428 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The base event of the event is not found.");
1431 calendar_record_h tmpEventHandle = null;
1432 errorCode = calendar_db_get_record(_calendar_event._uri, event.GetRecordId(), &tmpEventHandle);
1433 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1434 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
1440 _CalendarbookImpl::GetLatestVersion(void) const
1445 int errorCode = calendar_db_get_current_version(&dbVersion);
1446 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, 0, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1452 _CalendarbookImpl::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const
1454 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1455 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1457 SysTryReturn(NID_SCL, offset >= 0 && maxCount >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified offset or maxCount is less than 0.", GetErrorMessage(E_INVALID_ARG));
1458 SysTryReturn(NID_SCL, propertySortedBy == 0 || _CalendarbookFilterImpl::IsValidProperty(type, propertySortedBy), null, E_INVALID_ARG
1459 , "[%s] Invalid argument is used. propertySortedBy = %d", GetErrorMessage(E_INVALID_ARG), propertySortedBy);
1461 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1464 calendar_query_h queryHandle = null;
1465 int errorCode = calendar_query_create(pViewUri, &queryHandle);
1466 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1467 _CalendarQuery query(queryHandle);
1469 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1471 unsigned int viewSortPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1472 bool ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1474 calendar_query_set_sort(queryHandle, viewSortPropertyId, ascending);
1479 calendar_query_set_filter(queryHandle, filterHandle);
1482 calendar_list_h resultListHandle = null;
1483 errorCode = calendar_db_get_records_with_query(queryHandle, offset, maxCount, &resultListHandle);
1484 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1485 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1486 _CalendarList calendarList(resultListHandle);
1488 std::unique_ptr<IList, AllElementsDeleter> pList(null);
1492 case CB_FI_TYPE_EVENT:
1494 pList.reset(ConvertRecordListN<CalEvent, _CalEventImpl, _calendar_event_property_ids>(resultListHandle, _calendar_event));
1495 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1496 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1499 case CB_FI_TYPE_TODO:
1501 pList.reset(ConvertRecordListN<CalTodo, _CalTodoImpl, _calendar_todo_property_ids>(resultListHandle, _calendar_todo));
1502 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1503 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1506 case CB_FI_TYPE_CALENDAR:
1508 pList.reset(ConvertRecordListN<Calendar, _CalendarImpl, _calendar_book_property_ids>(resultListHandle, _calendar_book));
1509 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1510 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1513 case CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE:
1515 pList.reset(ConvertEventInstanceListN(resultListHandle, true));
1516 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1519 case CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE:
1521 pList.reset(ConvertEventInstanceListN(resultListHandle, false));
1522 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1526 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of filter is (%d)", GetErrorMessage(E_INVALID_ARG), type);
1530 return pList.release();
1534 _CalendarbookImpl::GetMatchedItemCount(const CalendarbookFilter& filter) const
1536 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1537 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1539 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1542 calendar_query_h queryHandle = null;
1543 int errorCode = calendar_query_create(pViewUri, &queryHandle);
1544 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1545 _CalendarQuery query(queryHandle);
1549 calendar_query_set_filter(queryHandle, filterHandle);
1552 int count = _INVALID_COUNT;
1554 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
1555 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1561 _CalendarbookImpl::ParseEventsFromVcalendarN(const String& vCalFilePath)
1566 result r = vCalFile.Construct(vCalFilePath, L"r");
1567 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1568 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1569 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1571 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1572 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1573 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1575 int fileLength = vCalFile.Tell();
1576 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is empty.", GetErrorMessage(E_INVALID_ARG));
1578 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1579 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1580 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1582 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1583 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1584 r = pBuffer->Construct(fileLength);
1585 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1587 r = vCalFile.Read(*pBuffer);
1588 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1589 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1591 _CalendarConnector connector;
1592 r = connector.GetResult();
1593 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s]A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1596 calendar_list_h calendarListHandle = null;
1597 int errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1598 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1599 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is invalid.", GetErrorMessage(E_INVALID_ARG));
1600 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE || errorCode == CALENDAR_ERROR_NO_DATA, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1601 _CalendarList calendarList(calendarListHandle);
1603 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1604 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1605 r = pList->Construct();
1606 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1609 calendar_list_get_count(calendarListHandle, &count);
1611 calendar_list_first(calendarListHandle);
1612 for (int i = 0; i < count; i++)
1614 calendar_record_h tmpRecordHandle = null;
1615 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1616 calendar_list_next(calendarListHandle);
1619 calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1621 if (strcmp(pUri, _calendar_event._uri) == 0)
1623 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1624 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1626 r = pList->Add(pTmpEvent.get());
1627 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1628 pTmpEvent.release();
1632 calendar_list_remove(calendarListHandle, tmpRecordHandle);
1633 calendar_record_destroy(tmpRecordHandle, true);
1637 calendar_list_first(calendarListHandle);
1638 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1639 while (pEnum->MoveNext() == E_SUCCESS)
1641 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1643 calendar_record_h tmpRecordHandle = null;
1644 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1645 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1647 calendar_list_next(calendarListHandle);
1650 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1652 return pList.release();
1656 _CalendarbookImpl::ParseTodosFromVcalendarN(const String& vCalFilePath)
1661 result r = vCalFile.Construct(vCalFilePath, L"r");
1662 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1663 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1664 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1666 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1667 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1668 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1670 int fileLength = vCalFile.Tell();
1671 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is empty.", GetErrorMessage(E_INVALID_ARG));
1673 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1674 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1675 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1677 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1678 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1679 r = pBuffer->Construct(fileLength);
1680 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1682 r = vCalFile.Read(*pBuffer);
1683 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1684 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1686 _CalendarConnector connector;
1687 r = connector.GetResult();
1688 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1691 calendar_list_h calendarListHandle = null;
1692 int errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1693 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1694 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is invalid.", GetErrorMessage(E_INVALID_ARG));
1695 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE || errorCode == CALENDAR_ERROR_NO_DATA, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1696 _CalendarList calendarList(calendarListHandle);
1698 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1699 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1700 r = pList->Construct();
1701 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1704 calendar_list_get_count(calendarListHandle, &count);
1706 calendar_list_first(calendarListHandle);
1707 for (int i = 0; i < count; i++)
1709 calendar_record_h tmpRecordHandle = null;
1710 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1711 calendar_list_next(calendarListHandle);
1714 calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1716 if (strcmp(pUri, _calendar_todo._uri) == 0)
1718 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1719 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1721 r = pList->Add(pTmpTodo.get());
1722 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1727 calendar_list_remove(calendarListHandle, tmpRecordHandle);
1728 calendar_record_destroy(tmpRecordHandle, true);
1732 calendar_list_first(calendarListHandle);
1733 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1734 while (pEnum->MoveNext() == E_SUCCESS)
1736 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1738 calendar_record_h tmpRecordHandle = null;
1739 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1740 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1742 calendar_list_next(calendarListHandle);
1745 calendar_list_destroy(calendarList.ReleaseHandle(), false);
1747 return pList.release();
1751 _CalendarbookImpl::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath)
1753 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1754 result r = GetLastResult();
1755 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1757 _CalendarConnector connector;
1758 r = connector.GetResult();
1759 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1761 calendar_list_h calendarListHandle = null;
1762 int errorCode = calendar_list_create(&calendarListHandle);
1763 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1764 _CalendarList calendarList(calendarListHandle, false);
1766 std::unique_ptr<IEnumerator> pEnum(eventList.GetEnumeratorN());
1767 while (pEnum->MoveNext() == E_SUCCESS)
1769 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1770 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_EVENT, E_INVALID_ARG, "Invalid argument is used. The eventList contains invalid record.");
1772 CalEvent* pTmpEvent = static_cast<CalEvent*>(pTmpRecord);
1773 errorCode = calendar_list_add(calendarListHandle, _CalEventImpl::GetInstance(*pTmpEvent)->GetRecordHandle());
1774 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1777 char* pVCalBuffer = null;
1778 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1779 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1780 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1781 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1784 r = vCalFile.Construct(vCalFilePath, L"w");
1785 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
1786 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1787 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1789 int pVCalBufferLength = strlen(pVCalBuffer);
1790 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1791 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1792 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1798 _CalendarbookImpl::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath)
1800 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1801 result 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, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1808 calendar_list_h calendarListHandle = null;
1809 int 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(todoList.GetEnumeratorN());
1814 while (pEnum->MoveNext() == E_SUCCESS)
1816 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1817 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_TODO, E_INVALID_ARG, "Invalid argument is used. The todoList contains invalid record.");
1819 CalTodo* pTmpTodo = static_cast<CalTodo*>(pTmpRecord);
1820 errorCode = calendar_list_add(calendarListHandle, _CalTodoImpl::GetInstance(*pTmpTodo)->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, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
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, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1845 _CalendarbookImpl::GetMaxDateTime(void)
1847 DateTime maxDateTime;
1848 maxDateTime.SetValue(2100, 12, 31, 23, 59, 59);
1854 _CalendarbookImpl::GetMinDateTime(void)
1856 DateTime minDateTime;
1857 minDateTime.SetValue(1900, 1, 1, 0, 0, 0);
1863 _CalendarbookImpl::GetEventInstancesCommonN(const DateTime& start, const DateTime& end,
1864 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category) const
1868 calendar_time_s convertedStartTime;
1869 calendar_time_s convertedEndTime;
1870 _CalendarbookUtil::ConvertDateTimeToCalTime(start, convertedStartTime);
1871 _CalendarbookUtil::ConvertDateTimeToCalTime(end, convertedEndTime);
1873 Tizen::Locales::TimeZone tmpTimeZone(timeZone);
1874 DateTime localStartTime = tmpTimeZone.UtcTimeToWallTime(start);
1875 DateTime localEndTime = tmpTimeZone.UtcTimeToWallTime(end);
1877 calendar_time_s convertedLocalStartTime;
1878 calendar_time_s convertedLocalEndTime;
1879 _CalendarbookUtil::ConvertDateToCalTime(localStartTime, convertedLocalStartTime);
1880 _CalendarbookUtil::ConvertDateToCalTime(localEndTime, convertedLocalEndTime);
1882 std::unique_ptr<IList, AllElementsDeleter> pList;
1884 if (category == EVENT_CATEGORY_ALL)
1886 pList.reset(GetEventInstancesOfAllCategoriesN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage));
1890 pList.reset(GetEventInstancesOfCategoryN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage, category));
1893 return pList.release();
1897 _CalendarbookImpl::GetEventInstancesOfAllCategoriesN(const calendar_time_s& startTime, const calendar_time_s& endTime,
1898 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage) const
1902 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
1903 int errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
1904 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1905 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
1907 // Condition : End time of the item > start time of filter
1908 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
1909 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1911 // Condition : Start time of the item < end time of filter
1912 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
1913 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1914 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
1915 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1918 calendar_query_h allDayEventInstanceQueryHandle = null;
1919 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
1920 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1921 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
1923 calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
1924 calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
1926 int startIndex = (pageNo - 1) * countPerPage;
1928 calendar_list_h allDayEventInstanceListHandle = null;
1929 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, startIndex, countPerPage, &allDayEventInstanceListHandle);
1930 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1931 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1932 _CalendarList allDayEventList(allDayEventInstanceListHandle);
1934 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1935 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1936 result r = pList->Construct();
1937 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1939 int allDayEventInstanceCount = 0;
1940 errorCode = calendar_db_get_count_with_query(allDayEventInstanceQueryHandle, &allDayEventInstanceCount);
1941 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1944 calendar_list_get_count(allDayEventInstanceListHandle, &count);
1946 int pageCount = allDayEventInstanceCount / countPerPage;
1947 int remainingCount = countPerPage - count;
1949 calendar_list_first(allDayEventInstanceListHandle);
1950 for (int i = 0; i < count; i++)
1952 calendar_record_h tmpRecordHandle = null;
1953 calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
1955 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
1956 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1958 r = pList->Add(*pTmpEventInstance.release());
1959 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1961 calendar_list_next(allDayEventInstanceListHandle);
1964 if (remainingCount > 0)
1966 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
1967 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
1968 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1969 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
1971 calendar_filter_h subFilterHandle = null;
1972 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
1973 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1974 _CalendarFilter subFilter(subFilterHandle);
1975 subFilterHandle = null;
1977 // Condition : End time of the item > start time of filter
1978 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
1979 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1981 // Condition : Start time of the item < end time of filter
1982 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
1983 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1984 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
1985 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1987 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
1988 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1990 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
1991 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
1992 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1993 subFilter.ResetHandle(subFilterHandle);
1994 subFilterHandle = null;
1996 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
1997 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1998 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
1999 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2000 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2001 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2003 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2004 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2005 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2006 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2009 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2010 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2011 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2012 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2014 calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2015 calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2017 if (remainingCount == countPerPage)
2019 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (allDayEventInstanceCount % countPerPage);
2026 calendar_list_h nonAllDayEventInstanceListHandle = null;
2027 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, startIndex, remainingCount, &nonAllDayEventInstanceListHandle);
2028 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2029 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2030 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2033 calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2034 calendar_list_first(nonAllDayEventInstanceListHandle);
2035 for (int i = 0; i < count; i++)
2037 calendar_record_h tmpRecordHandle = null;
2038 calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2040 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2041 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2043 r = pList->Add(pTmpEventInstance.get());
2044 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2046 pTmpEventInstance.release();
2048 calendar_list_next(nonAllDayEventInstanceListHandle);
2052 return pList.release();
2056 _CalendarbookImpl::GetEventInstancesOfCategoryN(const calendar_time_s& startTime, const calendar_time_s& endTime,
2057 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage, unsigned long category) const
2061 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
2062 int errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
2063 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2064 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
2066 // Condition : End time of the item > start time of filter
2067 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
2068 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2070 // Condition : Start time of the item < end time of filter
2071 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
2072 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2073 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
2074 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2077 calendar_query_h allDayEventInstanceQueryHandle = null;
2078 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
2079 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2080 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
2082 calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
2083 calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
2085 // Generate event : category map
2086 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(GenerateEventCategoryMapN());
2087 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2089 int startIndex = (pageNo - 1) * countPerPage;
2091 calendar_list_h allDayEventInstanceListHandle = null;
2092 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, 0, 0, &allDayEventInstanceListHandle);
2093 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2094 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2095 _CalendarList allDayEventList(allDayEventInstanceListHandle);
2097 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2098 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2099 result r = pList->Construct();
2100 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2102 int remainingCount = countPerPage;
2103 int candidateCount = 0;
2105 calendar_list_get_count(allDayEventInstanceListHandle, &count);
2106 calendar_list_first(allDayEventInstanceListHandle);
2107 for (int i = 0; i < count && remainingCount > 0; i++)
2109 calendar_record_h tmpRecordHandle = null;
2110 calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
2112 int tmpCategory = (int) EVENT_CATEGORY_ALL;
2114 calendar_record_get_int(tmpRecordHandle, _calendar_instance_allday_calendar_book.event_id, &eventId);
2115 pEventCategoryMap->GetValue(eventId, tmpCategory);
2117 if (tmpCategory == (int) category)
2119 if (candidateCount >= startIndex)
2121 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2122 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2124 r = pList->Add(pTmpEventInstance.get());
2125 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2126 pTmpEventInstance.release();
2134 calendar_list_next(allDayEventInstanceListHandle);
2137 if (remainingCount > 0)
2139 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
2140 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
2141 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2142 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
2144 calendar_filter_h subFilterHandle = null;
2145 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2146 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2147 _CalendarFilter subFilter(subFilterHandle);
2148 subFilterHandle = null;
2150 // Condition : End time of the item > start time of filter
2151 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2152 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2154 // Condition : Start time of the item < end time of filter
2155 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2156 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2157 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2158 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2160 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2161 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2163 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2164 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2165 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2166 subFilter.ResetHandle(subFilterHandle);
2167 subFilterHandle = null;
2169 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2170 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2171 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2172 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2173 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2174 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2176 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2177 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2178 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2179 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2182 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2183 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2184 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2185 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2187 calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2188 calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2190 if (remainingCount == countPerPage)
2192 int pageCount = candidateCount / countPerPage;
2193 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (candidateCount % countPerPage);
2200 calendar_list_h nonAllDayEventInstanceListHandle = null;
2201 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, 0, 0, &nonAllDayEventInstanceListHandle);
2202 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2203 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2204 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2209 calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2210 calendar_list_first(nonAllDayEventInstanceListHandle);
2211 for (int i = 0; i < count && remainingCount > 0; i++)
2213 calendar_record_h tmpRecordHandle = null;
2214 calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2216 int tmpCategory = (int) EVENT_CATEGORY_ALL;
2218 calendar_record_get_int(tmpRecordHandle, _calendar_instance_normal_calendar_book.event_id, &eventId);
2219 pEventCategoryMap->GetValue(eventId, tmpCategory);
2221 if (tmpCategory == (int) category)
2223 if (candidateCount >= startIndex)
2225 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2226 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2228 r = pList->Add(*pTmpEventInstance.release());
2229 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2237 calendar_list_next(nonAllDayEventInstanceListHandle);
2241 return pList.release();
2245 _CalendarbookImpl::GenerateEventCategoryMapN(void) const
2247 result r = E_SUCCESS;
2248 int errorCode = CALENDAR_ERROR_NONE;
2250 unsigned int projectionList[_NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION] = {_calendar_event.id, _calendar_event.categories};
2253 calendar_query_h queryHandle = null;
2254 errorCode = calendar_query_create(_calendar_event._uri, &queryHandle);
2255 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2256 _CalendarQuery query(queryHandle);
2258 calendar_query_set_projection(queryHandle, projectionList, _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION);
2259 calendar_query_set_sort(queryHandle, _calendar_event.id, true);
2261 calendar_list_h calendarListHandle = null;
2262 errorCode = calendar_db_get_records_with_query(queryHandle, 0, 0, &calendarListHandle);
2263 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2264 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2265 _CalendarList calendarList(calendarListHandle);
2267 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(new HashMapT<int, int>());
2268 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2269 r = pEventCategoryMap->Construct();
2270 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2273 calendar_list_get_count(calendarListHandle, &count);
2274 calendar_list_first(calendarListHandle);
2275 for (int i = 0; i < count; i++)
2277 calendar_record_h tmpRecordHandle = null;
2278 calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
2281 char* pCategories = null;
2283 calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &eventId);
2284 calendar_record_get_str_p(tmpRecordHandle, _calendar_event.categories, &pCategories);
2286 int category = _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
2288 pEventCategoryMap->Add(eventId, category);
2290 calendar_list_next(calendarListHandle);
2293 return pEventCategoryMap.release();
2297 _CalendarbookImpl::GetCalendarItemTypeByCalendarId(RecordId calendarId) const
2299 CalendarItemType calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2301 calendar_record_h calendarHandle = null;
2302 int storeType = CALENDAR_BOOK_TYPE_NONE;
2304 int errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2305 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, CALENDAR_ITEM_TYPE_EVENT_AND_TODO, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2307 calendar_record_get_int(calendarHandle, _calendar_book.store_type, &storeType);
2309 if (storeType == (CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO))
2311 calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2313 else if (storeType == CALENDAR_BOOK_TYPE_EVENT)
2315 calendarItemType = CALENDAR_ITEM_TYPE_EVENT_ONLY;
2317 else if (storeType == CALENDAR_BOOK_TYPE_TODO)
2319 calendarItemType = CALENDAR_ITEM_TYPE_TODO_ONLY;
2323 SetLastResult(E_SYSTEM);
2324 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2325 calendar_record_destroy(calendarHandle, true);
2326 return CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2329 calendar_record_destroy(calendarHandle, true);
2331 return calendarItemType;
2335 _CalendarbookImpl::CheckEventExistance(RecordId eventId) const
2337 calendar_record_h eventHandle = null;
2339 int errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
2340 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2342 calendar_record_destroy(eventHandle, true);
2348 _CalendarbookImpl::CheckTodoExistance(RecordId todoId) const
2350 calendar_record_h todoHandle = null;
2352 int errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
2353 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2355 calendar_record_destroy(todoHandle, true);
2361 _CalendarbookImpl::CheckCalendarExistance(RecordId calendarId) const
2363 calendar_record_h calendarHandle = null;
2365 int errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2366 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2368 calendar_record_destroy(calendarHandle, true);
2374 _CalendarbookImpl::CheckValidTodoPriority(unsigned long priority) const
2376 if ((priority & TODO_PRIORITY_LOW) || (priority & TODO_PRIORITY_NORMAL) || (priority & TODO_PRIORITY_HIGH))
2385 _CalendarbookImpl::CheckValidTodoStatus(unsigned long status) const
2387 if ((status & TODO_STATUS_NONE) || (status & TODO_STATUS_NEEDS_ACTION) || (status & TODO_STATUS_COMPLETED)
2388 || (status & TODO_STATUS_IN_PROCESS) || (status & TODO_STATUS_CANCELLED))
2397 _CalendarbookImpl::ConvertTodoStatusToCalendarTodoStatus(unsigned long todoStatus) const
2399 return todoStatus << 8;
2403 _CalendarbookImpl::ConvertTodoPriorityToCalendarTodoPriority(unsigned long todoPriority) const
2405 int calendarTodoPriority = CALENDAR_TODO_PRIORITY_NONE;
2407 if (todoPriority == TODO_PRIORITY_LOW)
2409 calendarTodoPriority = CALENDAR_TODO_PRIORITY_LOW;
2411 else if (todoPriority == TODO_PRIORITY_NORMAL)
2413 calendarTodoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
2415 else if (todoPriority == TODO_PRIORITY_HIGH)
2417 calendarTodoPriority = CALENDAR_TODO_PRIORITY_HIGH;
2420 return calendarTodoPriority;
2424 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2426 int originalEventDBId = _INVALID_EVENT_DB_ID;
2427 calendar_record_h eventHandle = null;
2429 int errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2430 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2432 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2433 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2434 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2436 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2437 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2439 calendar_time_s startCalendarTime;
2440 calendar_time_s endCalendarTime;
2441 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2442 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2443 calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2444 calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2446 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2447 pEventImpl->SetRecordHandle(eventHandle);
2449 return pEvent.release();
2453 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2455 int originalEventDBId = _INVALID_EVENT_DB_ID;
2456 calendar_record_h eventHandle = null;
2458 int errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2459 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[%s] Invalid argument is used. The instanceHandle is invalid record.", GetErrorMessage(E_INVALID_ARG));
2461 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2462 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2463 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2465 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2466 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2468 calendar_time_s startCalendarTime;
2469 calendar_time_s endCalendarTime;
2470 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2471 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2472 calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2473 calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2475 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2476 pEventImpl->SetRecordHandle(eventHandle);
2478 return pEvent.release();
2482 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2486 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2487 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2488 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2490 int originalEventDBId = _INVALID_EVENT_DB_ID;
2491 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2492 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2494 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2495 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.calendar_book_id, &calendarDBId);
2496 pEventInstanceImpl->SetCalendarId(calendarDBId);
2498 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2499 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.busy_status, &srcEventBusyStatus);
2500 BusyStatus busyStatus = BUSY_STATUS_FREE;
2501 switch (srcEventBusyStatus)
2503 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2504 busyStatus = BUSY_STATUS_FREE;
2506 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2507 busyStatus = BUSY_STATUS_BUSY;
2509 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2510 busyStatus = BUSY_STATUS_UNAVAILABLE;
2512 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2513 busyStatus = BUSY_STATUS_TENTATIVE;
2516 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. busy status = %d", GetErrorMessage(E_INVALID_ARG), srcEventBusyStatus);
2517 busyStatus = BUSY_STATUS_FREE;
2520 pEventInstanceImpl->SetBusyStatus(busyStatus);
2522 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2523 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_status, &srcEventStatus);
2524 EventStatus eventStatus = EVENT_STATUS_NONE;
2525 switch (srcEventStatus)
2527 case CALENDAR_EVENT_STATUS_NONE:
2528 eventStatus = EVENT_STATUS_NONE;
2530 case CALENDAR_EVENT_STATUS_TENTATIVE:
2531 eventStatus = EVENT_STATUS_TENTATIVE;
2533 case CALENDAR_EVENT_STATUS_CONFIRMED:
2534 eventStatus = EVENT_STATUS_CONFIRMED;
2536 case CALENDAR_EVENT_STATUS_CANCELLED:
2537 eventStatus = EVENT_STATUS_CANCELLED;
2540 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. status = %d", GetErrorMessage(E_INVALID_ARG), srcEventStatus);
2541 eventStatus = EVENT_STATUS_NONE;
2543 pEventInstanceImpl->SetStatus(eventStatus);
2545 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2546 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.priority, &srcPriority);
2547 EventPriority priority = EVENT_PRIORITY_NORMAL;
2548 switch (srcPriority)
2550 case CALENDAR_EVENT_PRIORITY_LOW:
2551 priority = EVENT_PRIORITY_LOW;
2553 case CALENDAR_EVENT_PRIORITY_NONE:
2555 case CALENDAR_EVENT_PRIORITY_NORMAL:
2556 priority = EVENT_PRIORITY_NORMAL;
2558 case CALENDAR_EVENT_PRIORITY_HIGH:
2559 priority = EVENT_PRIORITY_HIGH;
2562 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. priority = %d", GetErrorMessage(E_INVALID_ARG), srcPriority);
2563 priority = EVENT_PRIORITY_NORMAL;
2565 pEventInstanceImpl->SetPriority(priority);
2567 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2568 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.sensitivity, &srcSensitivity);
2569 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2570 switch (srcSensitivity)
2572 case CALENDAR_SENSITIVITY_PUBLIC:
2573 sensitivity = SENSITIVITY_PUBLIC;
2575 case CALENDAR_SENSITIVITY_PRIVATE:
2576 sensitivity = SENSITIVITY_PRIVATE;
2578 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2579 sensitivity = SENSITIVITY_CONFIDENTIAL;
2582 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. sensitivity = %d", GetErrorMessage(E_INVALID_ARG), srcSensitivity);
2583 sensitivity = SENSITIVITY_PUBLIC;
2585 pEventInstanceImpl->SetSensitivity(sensitivity);
2587 calendar_time_s startCalendarTime;
2588 DateTime tmpStartTime;
2589 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2590 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
2591 pEventInstanceImpl->SetStartTime(tmpStartTime);
2593 calendar_time_s endCalendarTime;
2594 DateTime tmpEndTime;
2595 calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2596 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
2597 pEventInstanceImpl->SetEndTime(tmpEndTime);
2599 pEventInstanceImpl->SetAllDayEvent(true);
2601 int isRecurring = 0;
2602 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_rrule, &isRecurring);
2603 pEventInstanceImpl->SetRecurring(isRecurring);
2605 int hasReminder = 0;
2606 calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_alarm, &hasReminder);
2607 pEventInstanceImpl->SetHasReminder(hasReminder);
2609 char* pSubject = null;
2610 calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.summary, &pSubject);
2611 pEventInstanceImpl->SetSubject(pSubject);
2613 char* pDescription = null;
2614 calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.description, &pDescription);
2615 pEventInstanceImpl->SetDescription(pDescription);
2617 char* pLocation = null;
2618 calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.location, &pLocation);
2619 pEventInstanceImpl->SetLocation(pLocation);
2621 return pEventInstance.release();
2625 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2629 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2630 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2631 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2633 int originalEventDBId = _INVALID_EVENT_DB_ID;
2634 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2635 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2637 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2638 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.calendar_book_id, &calendarDBId);
2639 pEventInstanceImpl->SetCalendarId(calendarDBId);
2641 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2642 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.busy_status, &srcEventBusyStatus);
2643 BusyStatus busyStatus = BUSY_STATUS_FREE;
2644 switch (srcEventBusyStatus)
2646 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2647 busyStatus = BUSY_STATUS_FREE;
2649 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2650 busyStatus = BUSY_STATUS_BUSY;
2652 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2653 busyStatus = BUSY_STATUS_UNAVAILABLE;
2655 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2656 busyStatus = BUSY_STATUS_TENTATIVE;
2659 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. busy status = %d", GetErrorMessage(E_INVALID_ARG), srcEventBusyStatus);
2660 busyStatus = BUSY_STATUS_FREE;
2663 pEventInstanceImpl->SetBusyStatus(busyStatus);
2665 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2666 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_status, &srcEventStatus);
2668 EventStatus eventStatus = EVENT_STATUS_NONE;
2669 switch (srcEventStatus)
2671 case CALENDAR_EVENT_STATUS_NONE:
2672 eventStatus = EVENT_STATUS_NONE;
2674 case CALENDAR_EVENT_STATUS_TENTATIVE:
2675 eventStatus = EVENT_STATUS_TENTATIVE;
2677 case CALENDAR_EVENT_STATUS_CONFIRMED:
2678 eventStatus = EVENT_STATUS_CONFIRMED;
2680 case CALENDAR_EVENT_STATUS_CANCELLED:
2681 eventStatus = EVENT_STATUS_CANCELLED;
2684 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. status = %d", GetErrorMessage(E_INVALID_ARG), srcEventStatus);
2685 eventStatus = EVENT_STATUS_NONE;
2687 pEventInstanceImpl->SetStatus(eventStatus);
2689 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2690 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.priority, &srcPriority);
2691 EventPriority priority = EVENT_PRIORITY_NORMAL;
2692 switch (srcPriority)
2694 case CALENDAR_EVENT_PRIORITY_LOW:
2695 priority = EVENT_PRIORITY_LOW;
2697 case CALENDAR_EVENT_PRIORITY_NONE:
2699 case CALENDAR_EVENT_PRIORITY_NORMAL:
2700 priority = EVENT_PRIORITY_NORMAL;
2702 case CALENDAR_EVENT_PRIORITY_HIGH:
2703 priority = EVENT_PRIORITY_HIGH;
2706 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. priority = %d", GetErrorMessage(E_INVALID_ARG), srcPriority);
2707 priority = EVENT_PRIORITY_NORMAL;
2709 pEventInstanceImpl->SetPriority(priority);
2711 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2712 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.sensitivity, &srcSensitivity);
2713 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2714 switch (srcSensitivity)
2716 case CALENDAR_SENSITIVITY_PUBLIC:
2717 sensitivity = SENSITIVITY_PUBLIC;
2719 case CALENDAR_SENSITIVITY_PRIVATE:
2720 sensitivity = SENSITIVITY_PRIVATE;
2722 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2723 sensitivity = SENSITIVITY_CONFIDENTIAL;
2726 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. sensitivity = %d", GetErrorMessage(E_INVALID_ARG), srcSensitivity);
2727 sensitivity = SENSITIVITY_PUBLIC;
2729 pEventInstanceImpl->SetSensitivity(sensitivity);
2731 calendar_time_s startCalendarTime;
2732 DateTime tmpStartTime;
2733 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2734 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
2735 pEventInstanceImpl->SetStartTime(tmpStartTime);
2737 calendar_time_s endCalendarTime;
2738 DateTime tmpEndTime;
2739 calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2740 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
2741 pEventInstanceImpl->SetEndTime(tmpEndTime);
2743 pEventInstanceImpl->SetAllDayEvent(false);
2745 int isRecurring = 0;
2746 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_rrule, &isRecurring);
2747 pEventInstanceImpl->SetRecurring(isRecurring);
2749 int hasReminder = 0;
2750 calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_alarm, &hasReminder);
2751 pEventInstanceImpl->SetHasReminder(hasReminder);
2753 char* pSubject = null;
2754 calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.summary, &pSubject);
2755 pEventInstanceImpl->SetSubject(pSubject);
2757 char* pDescription = null;
2758 calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.description, &pDescription);
2759 pEventInstanceImpl->SetDescription(pDescription);
2761 char* pLocation = null;
2762 calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.location, &pLocation);
2763 pEventInstanceImpl->SetLocation(pLocation);
2765 return pEventInstance.release();
2769 _CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(calendar_record_h modifiedEventHandle)
2773 std::unique_ptr<CalEventChangeInfo> pEventChangeInfo(new (std::nothrow) CalEventChangeInfo());
2774 SysTryReturn(NID_SCL, pEventChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2775 _CalEventChangeInfoImpl* pEventChangeInfoImpl = _CalEventChangeInfoImpl::GetInstance(*pEventChangeInfo.get());
2778 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.id, &eventId);
2779 pEventChangeInfoImpl->SetEventId(eventId);
2781 int calendarbookId = 0;
2782 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2783 pEventChangeInfoImpl->SetCalendarId(calendarbookId);
2785 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2786 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2787 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2788 switch (modifiedStatus)
2790 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2791 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2793 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2794 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2796 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2797 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2800 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. modified status = %d", GetErrorMessage(E_INVALID_ARG), modifiedStatus);
2803 pEventChangeInfoImpl->SetChangeType(recordChangeType);
2806 calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.version, &version);
2807 pEventChangeInfoImpl->SetVersion(version);
2809 return pEventChangeInfo.release();
2813 _CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(calendar_record_h modifiedTodoHandle)
2817 std::unique_ptr<CalTodoChangeInfo> pTodoChangeInfo(new (std::nothrow) CalTodoChangeInfo());
2818 SysTryReturn(NID_SCL, pTodoChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2819 _CalTodoChangeInfoImpl* pTodoChangeInfoImpl = _CalTodoChangeInfoImpl::GetInstance(*pTodoChangeInfo.get());
2822 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.id, &todoId);
2823 pTodoChangeInfoImpl->SetTodoId(todoId);
2825 int calendarbookId = 0;
2826 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2827 pTodoChangeInfoImpl->SetCalendarId(calendarbookId);
2829 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2830 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2831 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2833 switch (modifiedStatus)
2835 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2836 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2838 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2839 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2841 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2842 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2845 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. modified status = %d", GetErrorMessage(E_INVALID_ARG), modifiedStatus);
2848 pTodoChangeInfoImpl->SetChangeType(recordChangeType);
2851 calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.version, &version);
2852 pTodoChangeInfoImpl->SetVersion(version);
2854 return pTodoChangeInfo.release();
2857 template<typename RecordType, typename RecordTypeImpl, typename RecordView>
2859 _CalendarbookImpl::ConvertRecordListN(calendar_list_h resultListHandle, RecordView recordView)
2861 result r = E_SUCCESS;
2863 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2864 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2865 r = pList->Construct();
2866 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2869 calendar_list_get_count(resultListHandle, &count);
2871 for (int i = 0; i < count; i++)
2873 std::unique_ptr<RecordType> pTmpRecord(RecordTypeImpl::CreateDefaultInstanceN());
2874 SysTryReturn(NID_SCL, pTmpRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2876 r = pList->Add(pTmpRecord.get());
2877 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2878 pTmpRecord.release();
2881 calendar_list_first(resultListHandle);
2882 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2883 while (pEnum->MoveNext() == E_SUCCESS)
2885 RecordType* pTmpRecord = static_cast<RecordType*>(pEnum->GetCurrent());
2887 calendar_record_h tmpRecordHandle = null;
2888 calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2889 RecordTypeImpl::GetInstance(*pTmpRecord)->SetRecordHandle(tmpRecordHandle);
2892 calendar_record_get_int(tmpRecordHandle, recordView.id, &dbIndex);
2893 _RecordImpl::GetInstance(*pTmpRecord)->SetRecordId(dbIndex);
2895 calendar_list_next(resultListHandle);
2898 return pList.release();
2902 _CalendarbookImpl::ConvertEventInstanceListN(calendar_list_h resultListHandle, bool isAllDay)
2904 result r = E_SUCCESS;
2906 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2907 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2908 r = pList->Construct();
2909 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2912 calendar_list_get_count(resultListHandle, &count);
2913 calendar_list_first(resultListHandle);
2914 for (int i = 0; i < count; i++)
2916 calendar_record_h tmpRecordHandle = null;
2917 calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2919 std::unique_ptr<CalEventInstance> pTmpEventInstance;
2923 pTmpEventInstance.reset(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2924 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2928 pTmpEventInstance.reset(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2929 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2932 r = pList->Add(pTmpEventInstance.get());
2933 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2934 pTmpEventInstance.release();
2936 calendar_list_next(resultListHandle);
2939 return pList.release();
2943 _CalendarbookImpl::OnCalEventChanged(void)
2945 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
2950 _CalendarConnector connector;
2951 result r = connector.GetResult();
2952 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2954 std::unique_ptr<IList, AllElementsDeleter> pChangedEventList(GetChangedEventsAfterN(__dbVersionForEvent, __dbVersionForEvent));
2955 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2956 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2958 if (pChangedEventList->GetCount() > 0)
2960 if (__pICalendarbookEventListener != null)
2962 __pICalendarbookEventListener->OnCalendarEventsChanged(*pChangedEventList.get());
2966 RecordEventType recordEventType = RECORD_ADDED;
2967 IEnumerator* pEnum = pChangedEventList->GetEnumeratorN();
2968 CalEvent* pEvent = null;
2970 while (pEnum->MoveNext() == E_SUCCESS)
2972 CalEventChangeInfo* pEventChagneInfo = static_cast<CalEventChangeInfo*>(pEnum->GetCurrent());
2974 if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2976 recordEventType = RECORD_ADDED;
2977 pEvent = GetEventN(pEventChagneInfo->GetEventId());
2980 if (GetLastResult() == E_OBJ_NOT_FOUND)
2990 else if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
2992 recordEventType = RECORD_UPDATED;
2993 pEvent = GetEventN(pEventChagneInfo->GetEventId());
2996 if (GetLastResult() == E_OBJ_NOT_FOUND)
3008 recordEventType = RECORD_REMOVED;
3009 pEvent = new (std::nothrow) CalEvent();
3012 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3016 _RecordImpl::GetInstance(*pEvent)->SetRecordId(pEventChagneInfo->GetEventId());
3019 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_EVENT, *pEvent, null, null);
3030 _CalendarbookImpl::OnCalTodoChanged(void)
3032 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
3037 _CalendarConnector connector;
3038 result r = connector.GetResult();
3039 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
3041 std::unique_ptr<IList, AllElementsDeleter> pChangedTodoList(GetChangedTodosAfterN(__dbVersionForTodo, __dbVersionForTodo));
3042 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3043 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
3045 if (pChangedTodoList->GetCount() > 0)
3047 if (__pICalendarbookEventListener != null)
3049 __pICalendarbookEventListener->OnCalendarTodosChanged(*pChangedTodoList.get());
3053 RecordEventType recordEventType = RECORD_ADDED;
3054 IEnumerator* pEnum = pChangedTodoList->GetEnumeratorN();
3055 CalTodo* pTodo = null;
3057 while (pEnum->MoveNext() == E_SUCCESS)
3059 CalTodoChangeInfo* pTodoChagneInfo = static_cast<CalTodoChangeInfo*>(pEnum->GetCurrent());
3061 if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
3063 recordEventType = RECORD_ADDED;
3064 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3067 if (GetLastResult() == E_OBJ_NOT_FOUND)
3077 else if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3079 recordEventType = RECORD_UPDATED;
3080 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3083 if (GetLastResult() == E_OBJ_NOT_FOUND)
3095 recordEventType = RECORD_REMOVED;
3096 pTodo = new (std::nothrow) CalTodo();
3099 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3103 _RecordImpl::GetInstance(*pTodo)->SetRecordId(pTodoChagneInfo->GetTodoId());
3106 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_TODO, *pTodo, null, null);
3117 _CalendarbookImpl::GetInstance(Calendarbook& calendarbook)
3119 return calendarbook.__pCalendarbookImpl;
3122 const _CalendarbookImpl*
3123 _CalendarbookImpl::GetInstance(const Calendarbook& calendarbook)
3125 return calendarbook.__pCalendarbookImpl;