2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FScl_CalendarbookImpl.cpp
18 * @brief This is the implementation for _CalendarbookImpl class.
20 * This file contains definitions of @e _CalendarbookImpl class.
24 #include <unique_ptr.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColHashMapT.h>
28 #include <FBaseUtilStringUtil.h>
29 #include <FLclTimeZone.h>
31 #include <FSclCalendarbook.h>
32 #include <FSclCalEvent.h>
33 #include <FSclCalTodo.h>
34 #include <FSclCalendar.h>
35 #include <FSclCalEventInstance.h>
36 #include <FSclCalEventChangeInfo.h>
37 #include <FSclCalTodoChangeInfo.h>
38 #include <FSclIRecordEventListener.h>
39 #include <FSclIRecordListener.h>
40 #include <FSclICalendarbookEventListener.h>
41 #include <FBaseSysLog.h>
42 #include <FBase_StringConverter.h>
43 #include "FScl_CalendarbookImpl.h"
44 #include "FScl_RecordImpl.h"
45 #include "FScl_CalEventImpl.h"
46 #include "FScl_CalTodoImpl.h"
47 #include "FScl_CalendarImpl.h"
48 #include "FScl_CalEventInstanceImpl.h"
49 #include "FScl_CalEventChangeInfoImpl.h"
50 #include "FScl_CalTodoChangeInfoImpl.h"
51 #include "FScl_CalendarbookFilterImpl.h"
52 #include "FScl_CalendarbookUtil.h"
53 #include "FScl_CalendarbookDbMonitor.h"
54 #include "FScl_CalendarbookDbConnector.h"
55 #include "FScl_CalendarbookRecordRetrivalThread.h"
56 #include "FScl_CalendarbookRecordRetrivalEvent.h"
58 using namespace Tizen::Base;
59 using namespace Tizen::Base::Utility;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Io;
63 namespace Tizen { namespace Social
66 RequestId _CalendarbookImpl::__requestId = 0;
67 _CalendarbookRecordRetrivalThread* _CalendarbookImpl::__pRecordRetrivalThread = null;
69 static const int _DEFAULT_EVENT_CALENDAR_DB_ID = 1;
70 static const int _DEFAULT_TODO_CALENDAR_DB_ID = 2;
71 static const wchar_t* _RECURRENCE_DELIMITER = L",";
72 static const int _NUMBER_OF_TODO_STATUS = 5;
73 static const int _NUMBER_OF_TODO_PRIORITY = 3;
74 static const int _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION = 2;
76 static const int _INVALID_CALENDARBOOK_DB_ID = -1; // TODO : This value should be checked.
77 static const int _INVALID_EVENT_DB_ID = -1;
82 _CalendarList(calendar_list_h calendarListHandle, bool deleteRecord = true)
83 : __calendarListHandle(calendarListHandle)
84 , __deleteRecord(deleteRecord)
90 if (__calendarListHandle)
92 calendar_list_destroy(__calendarListHandle, __deleteRecord);
96 calendar_list_h GetHandle(void)
98 return __calendarListHandle;
101 calendar_list_h ReleaseHandle(void)
103 calendar_list_h calendarListHandle = __calendarListHandle;
104 __calendarListHandle = null;
105 return calendarListHandle;
109 calendar_list_h __calendarListHandle;
113 class _CalendarFilter
116 _CalendarFilter(calendar_filter_h calendarFilterHandle)
117 : __calendarFilterHandle(calendarFilterHandle)
121 ~_CalendarFilter(void)
123 if (__calendarFilterHandle)
125 calendar_filter_destroy(__calendarFilterHandle);
129 calendar_filter_h GetHandle(void)
131 return __calendarFilterHandle;
134 calendar_filter_h ReleaseHandle(void)
136 calendar_filter_h calendarFilterHandle = __calendarFilterHandle;
137 __calendarFilterHandle = null;
138 return calendarFilterHandle;
141 void ResetHandle(calendar_filter_h calendarFilterHandle)
143 if (__calendarFilterHandle)
145 calendar_filter_destroy(__calendarFilterHandle);
147 __calendarFilterHandle = calendarFilterHandle;
151 calendar_filter_h __calendarFilterHandle;
154 class _CalendarConnector
160 __r = _CalendarbookDbConnector::Connect();
163 ~_CalendarConnector(void)
165 if (__r == E_SUCCESS)
167 _CalendarbookDbConnector::Disconnect();
171 result GetResult(void)
183 _CalendarQuery(calendar_query_h calendarQueryHandle)
184 : __calendarQueryHandle(calendarQueryHandle)
188 ~_CalendarQuery(void)
190 if (__calendarQueryHandle)
192 calendar_query_destroy(__calendarQueryHandle);
196 calendar_query_h GetHandle(void)
198 return __calendarQueryHandle;
201 calendar_query_h ReleaseHandle(void)
203 calendar_query_h calendarQueryHandle = __calendarQueryHandle;
204 __calendarQueryHandle = null;
205 return calendarQueryHandle;
208 void ResetHandle(calendar_query_h calendarQueryHandle)
210 if (__calendarQueryHandle)
212 calendar_query_destroy(__calendarQueryHandle);
214 __calendarQueryHandle = calendarQueryHandle;
218 calendar_query_h __calendarQueryHandle;
221 _CalendarbookImpl::_CalendarbookImpl(void)
222 : __pIRecordEventListener(null)
223 , __pICalendarbookEventListener(null)
224 , __dbVersionForEvent(0)
225 , __dbVersionForTodo(0)
226 , __pCalendarbookDbMonitor(null)
230 _CalendarbookImpl::~_CalendarbookImpl(void)
232 if (__pCalendarbookDbMonitor != null)
234 if (__pIRecordEventListener != null || __pICalendarbookEventListener != null)
236 __pCalendarbookDbMonitor->RemoveListener(*this);
239 __pCalendarbookDbMonitor->Release();
243 _CalendarbookDbConnector::Disconnect();
248 _CalendarbookImpl::Construct(void)
250 result r = _CalendarbookDbConnector::Connect();
251 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
257 _CalendarbookImpl::Construct(IRecordEventListener* pListener)
259 result r = E_SUCCESS;
264 _CalendarbookDbMonitor* pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
265 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
267 if (pListener != null)
269 dbVersion = GetLatestVersion();
270 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
272 r = pCalendarbookDbMonitor->AddListener(*this);
273 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
275 __pIRecordEventListener = pListener;
278 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
280 __dbVersionForEvent = dbVersion;
281 __dbVersionForTodo = dbVersion;
286 pCalendarbookDbMonitor->Release();
292 _CalendarbookImpl::Construct(ICalendarbookEventListener& listener)
294 result r = E_SUCCESS;
295 _CalendarbookDbMonitor* pCalendarbookDbMonitor = null;
300 pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
301 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
303 dbVersion = GetLatestVersion();
304 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
306 r = pCalendarbookDbMonitor->AddListener(*this);
307 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
309 __pICalendarbookEventListener = &listener;
310 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
312 __dbVersionForEvent = dbVersion;
313 __dbVersionForTodo = dbVersion;
318 pCalendarbookDbMonitor->Release();
324 _CalendarbookImpl::AddEvent(CalEvent& event)
326 int errorCode = CALENDAR_ERROR_NONE;
329 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
330 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
331 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
332 , "Invalid argument is used. The event is not an entry type instance.");
334 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
336 errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, _DEFAULT_EVENT_CALENDAR_DB_ID);
337 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
338 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
339 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
340 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
342 calendar_record_h tmpEventHandle = null;
343 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
344 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
345 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
351 _CalendarbookImpl::AddEvent(CalEvent& event, RecordId calendarId)
353 int errorCode = CALENDAR_ERROR_NONE;
356 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
357 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
358 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
359 , "Invalid argument is used. The event is not an entry type instance.");
360 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
361 , "Invalid argument is used. calendarId = %d", calendarId);
362 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
363 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
364 SysTryReturnResult(NID_SCL,(itemType == CALENDAR_ITEM_TYPE_EVENT_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
365 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_TODO_ONLY");
367 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
369 errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, calendarId);
370 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
371 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
372 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
373 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
375 calendar_record_h tmpEventHandle = null;
376 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
377 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
378 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
384 _CalendarbookImpl::AddTodo(CalTodo& todo)
386 int errorCode = CALENDAR_ERROR_NONE;
389 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
390 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
392 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
394 errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, _DEFAULT_TODO_CALENDAR_DB_ID);
395 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
396 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
397 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
398 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
400 calendar_record_h tmpTodoHandle = null;
401 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
402 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
403 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
409 _CalendarbookImpl::AddTodo(CalTodo& todo, RecordId calendarId)
411 int errorCode = CALENDAR_ERROR_NONE;
414 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
415 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
416 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
417 , "Invalid argument is used. calendarId = %d", calendarId);
418 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
419 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
420 SysTryReturnResult(NID_SCL, (itemType == CALENDAR_ITEM_TYPE_TODO_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
421 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_EVENT_ONLY");
423 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
425 errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, calendarId);
426 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
427 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
428 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
429 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
431 calendar_record_h tmpTodoHandle = null;
432 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
433 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
434 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
440 _CalendarbookImpl::AddCalendar(Calendar& calendar)
442 int errorCode = CALENDAR_ERROR_NONE;
445 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
446 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
448 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
450 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
451 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
452 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
453 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
455 calendar_record_h tmpCalendarHandle = null;
456 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
457 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
458 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
464 _CalendarbookImpl::AddCalendar(Calendar& calendar, AccountId accountId)
466 int errorCode = CALENDAR_ERROR_NONE;
469 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
470 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
471 SysTryReturnResult(NID_SCL, accountId >= 0, E_INVALID_ARG, "Invalid argument is used.");
473 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
475 errorCode = calendar_record_set_int(calendarHandle, _calendar_book.account_id, accountId);
477 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
478 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
479 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
480 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
482 calendar_record_h tmpCalendarHandle = null;
483 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
484 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
485 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
491 _CalendarbookImpl::RemoveEvent(CalEvent& event)
493 int errorCode = CALENDAR_ERROR_NONE;
495 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
496 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
498 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
500 int baseEventId = _INVALID_EVENT_DB_ID;
501 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
502 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
503 , "Invalid argument is used. The event has the base event id.");
505 errorCode = calendar_db_delete_record(_calendar_event._uri, event.GetRecordId());
506 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
507 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
509 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(event);
510 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
516 _CalendarbookImpl::RemoveEvent(RecordId eventId)
518 int errorCode = CALENDAR_ERROR_NONE;
520 SysTryReturnResult(NID_SCL, eventId != INVALID_RECORD_ID, E_INVALID_ARG
521 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
523 calendar_record_h eventHandle = null;
525 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
526 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
528 int baseEventId = _INVALID_EVENT_DB_ID;
529 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
531 calendar_record_destroy(eventHandle, true);
533 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
534 , "Invalid argument is used. The event of eventId has the base event id.");
536 errorCode = calendar_db_delete_record(_calendar_event._uri, eventId);
537 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
543 _CalendarbookImpl::RemoveTodo(CalTodo& todo)
545 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(todo);
547 result r = RemoveTodo(todo.GetRecordId());
548 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
554 _CalendarbookImpl::RemoveTodo(RecordId todoId)
556 int errorCode = CALENDAR_ERROR_NONE;
558 SysTryReturnResult(NID_SCL, todoId != INVALID_RECORD_ID, E_INVALID_ARG
559 , "Invalid argument is used. The specified todoId is INVALID_RECORD_ID.");
561 errorCode = calendar_db_delete_record(_calendar_todo._uri, todoId);
562 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
563 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
569 _CalendarbookImpl::RemoveCalendar(RecordId calendarId)
571 int errorCode = CALENDAR_ERROR_NONE;
573 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
574 , "The specified calendarId is INVALID_RECORD_ID.");
575 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_EVENT_CALENDAR_DB_ID
576 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
577 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_TODO_CALENDAR_DB_ID
578 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
579 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendarId), E_OBJ_NOT_FOUND, "The specified record is not found.");
581 errorCode = calendar_db_delete_record(_calendar_book._uri, calendarId);
582 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
588 _CalendarbookImpl::UpdateEvent(const CalEvent& event)
590 int errorCode = CALENDAR_ERROR_NONE;
592 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
593 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
594 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
595 , "Invalid argument is used. The event is not an entry type instance.");
597 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
599 int baseEventId = _INVALID_EVENT_DB_ID;
600 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
601 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
602 , "Invalid argument is used. The event has the base event id.");
604 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
606 errorCode = calendar_db_update_record(eventHandle);
607 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
608 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
614 _CalendarbookImpl::UpdateTodo(const CalTodo& todo)
616 int errorCode = CALENDAR_ERROR_NONE;
618 SysTryReturnResult(NID_SCL, todo.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
619 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
620 SysTryReturnResult(NID_SCL, CheckTodoExistance(todo.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
622 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
623 errorCode = calendar_db_update_record(todoHandle);
624 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
630 _CalendarbookImpl::UpdateCalendar(const Calendar& calendar)
632 int errorCode = CALENDAR_ERROR_NONE;
634 SysTryReturnResult(NID_SCL, calendar.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
635 , "The specified recordId is INVALID_RECORD_ID.");
636 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendar.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
638 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
639 errorCode = calendar_db_update_record(calendarHandle);
640 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
646 _CalendarbookImpl::GetEventN(RecordId eventId) const
648 int errorCode = CALENDAR_ERROR_NONE;
649 calendar_record_h eventHandle = null;
653 SysTryReturn(NID_SCL, eventId != INVALID_RECORD_ID, null, E_INVALID_ARG
654 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
656 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
657 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
659 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
660 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
661 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
663 _CalEventImpl::GetInstance(*pEvent.get())->SetRecordHandle(eventHandle);
664 _RecordImpl::GetInstance(*pEvent.get())->SetRecordId(eventId);
666 return pEvent.release();
670 _CalendarbookImpl::GetTodoN(RecordId todoId) const
672 int errorCode = CALENDAR_ERROR_NONE;
673 calendar_record_h todoHandle = null;
677 SysTryReturn(NID_SCL, todoId != INVALID_RECORD_ID, null, E_INVALID_ARG
678 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
680 std::unique_ptr<CalTodo> pTodo(new (std::nothrow) CalTodo());
681 SysTryReturn(NID_SCL, pTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
683 errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
685 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
686 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
688 _CalTodoImpl::GetInstance(*pTodo.get())->SetRecordHandle(todoHandle);
689 _RecordImpl::GetInstance(*pTodo.get())->SetRecordId(todoId);
691 return pTodo.release();
695 _CalendarbookImpl::GetCalendarN(RecordId calendarId) const
697 int errorCode = CALENDAR_ERROR_NONE;
698 calendar_record_h calendarHandle = null;
702 SysTryReturn(NID_SCL, calendarId != INVALID_RECORD_ID, null, E_INVALID_ARG
703 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
705 std::unique_ptr<Calendar> pCalendar(new (std::nothrow) Calendar(CALENDAR_ITEM_TYPE_EVENT_AND_TODO));
706 SysTryReturn(NID_SCL, pCalendar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
708 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
709 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
710 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
712 _CalendarImpl::GetInstance(*pCalendar.get())->SetRecordHandle(calendarHandle);
713 _RecordImpl::GetInstance(*pCalendar.get())->SetRecordId(calendarId);
715 return pCalendar.release();
719 _CalendarbookImpl::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status,
720 unsigned long priority) const
722 int errorCode = CALENDAR_ERROR_NONE;
726 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The pageNo or countPerPage is less than 1.");
727 SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
728 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
729 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
730 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %ld", status);
731 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %ld", priority);
735 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
736 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
737 calendar_time_s convertedStartTime;
738 calendar_time_s convertedEndTime;
739 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
740 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
742 calendar_filter_h mainFilterHandle = null;
743 errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
744 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
745 _CalendarFilter mainFilter(mainFilterHandle);
747 // Condition : Due time of the item >= start time of filter
748 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
750 // Condition : Due time of the item <= end time of filter
751 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
752 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
754 // Condition : status
755 calendar_filter_h subFilterHandle = null;
756 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
757 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
758 _CalendarFilter subFilter(subFilterHandle);
759 subFilterHandle = null;
761 int tmpStatus = TODO_STATUS_NONE;
762 bool alreadyAdded = false;
763 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
765 if (status & tmpStatus)
769 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
772 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
780 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
781 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
783 // Condition : priority
784 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
785 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
786 subFilter.ResetHandle(subFilterHandle);
787 subFilterHandle = null;
789 int tmpPriority = TODO_PRIORITY_LOW;
790 alreadyAdded = false;
791 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
793 if (priority & tmpPriority)
797 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
800 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
807 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
808 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
811 calendar_query_h queryHandle = null;
812 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
813 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
814 _CalendarQuery query(queryHandle);
816 errorCode = calendar_query_set_sort(queryHandle, _calendar_todo.due_time, true);
817 errorCode = calendar_query_set_filter(queryHandle, mainFilterHandle);
819 calendar_list_h calendarListHandle = null;
820 errorCode = calendar_db_get_records_with_query(queryHandle, (pageNo - 1) * countPerPage, countPerPage, &calendarListHandle);
821 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
822 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
823 _CalendarList calendarList(calendarListHandle);
825 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
826 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
827 result r = pList->Construct();
828 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
831 errorCode = calendar_list_get_count(calendarListHandle, &count);
833 for (int i = 0; i < count; i++)
835 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
836 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
838 r = pList->Add(*pTmpTodo.release());
839 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
842 errorCode = calendar_list_first(calendarListHandle);
843 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
844 while (pEnum->MoveNext() == E_SUCCESS)
846 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
848 calendar_record_h tmpRecordHandle = null;
849 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
851 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
854 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
855 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
857 errorCode = calendar_list_next(calendarListHandle);
860 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
862 return pList.release();
866 _CalendarbookImpl::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const
868 int errorCode = CALENDAR_ERROR_NONE;
872 SysTryReturn(NID_SCL, start <= end, _INVALID_COUNT
873 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
874 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), _INVALID_COUNT
875 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
876 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), _INVALID_COUNT
877 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
878 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), _INVALID_COUNT
879 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %ld", status);
880 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), _INVALID_COUNT
881 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %ld", priority);
885 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
886 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
887 calendar_time_s convertedStartTime;
888 calendar_time_s convertedEndTime;
889 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
890 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
892 calendar_filter_h mainFilterHandle = null;
893 errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
894 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
895 _CalendarFilter mainFilter(mainFilterHandle);
897 // Condition : Due time of the item => start time of filter
898 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
900 // Condition : Due time of the item <= end time of filter
901 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
902 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
904 // Condition : status
905 calendar_filter_h subFilterHandle = null;
906 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
907 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
908 _CalendarFilter subFilter(subFilterHandle);
909 subFilterHandle = null;
911 int tmpStatus = TODO_STATUS_NONE;
912 bool alreadyAdded = false;
913 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
915 if (status & tmpStatus)
919 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
922 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
929 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
930 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
932 // Condition : priority
933 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
934 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
935 subFilter.ResetHandle(subFilterHandle);
936 subFilterHandle = null;
938 int tmpPriority = TODO_PRIORITY_LOW;
939 alreadyAdded = false;
940 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
942 if (priority & tmpPriority)
946 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
949 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
956 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
957 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
960 calendar_query_h queryHandle = null;
961 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
962 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
963 _CalendarQuery query(queryHandle);
965 errorCode = calendar_query_set_filter(queryHandle, mainFilterHandle);
967 int count = _INVALID_COUNT;
969 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
970 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
976 _CalendarbookImpl::GetEventInstancesN(const DateTime& start, const DateTime& end,
977 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage,
978 unsigned long category) const
980 result r = E_SUCCESS;
984 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The pageNo or countPerPage is less than 1.");
985 SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
986 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
987 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
988 SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. category = %ld", category);
990 std::unique_ptr<IList, AllElementsDeleter> pList(GetEventInstancesCommonN(start, end, timeZone, pageNo, countPerPage, category));
992 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
994 return pList.release();
998 _CalendarbookImpl::GetEventInstances(const DateTime& start, const DateTime& end,
999 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category,
1000 RequestId& reqId, const IRecordListener& listener) const
1003 reqId = __requestId;
1005 result r = E_SUCCESS;
1007 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The pageNo or countPerPage is less than 1.");
1008 SysTryReturn(NID_SCL, start <= end, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
1009 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
1010 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
1011 SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. category = %ld", category);
1013 std::unique_ptr<_CalendarbookRecordRetrivalEvent> pEvent(new (std::nothrow) _CalendarbookRecordRetrivalEvent());
1014 SysTryReturnResult(NID_SCL, pEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1015 r = pEvent->Construct();
1016 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1017 r = pEvent->AddListener(listener);
1018 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1020 if (__pRecordRetrivalThread != null)
1022 __pRecordRetrivalThread->Join();
1023 delete __pRecordRetrivalThread;
1024 __pRecordRetrivalThread = null;
1027 std::unique_ptr<_CalendarbookRecordRetrivalThread> pRecordRetrivalThread(new (std::nothrow) _CalendarbookRecordRetrivalThread());
1028 SysTryReturnResult(NID_SCL, pRecordRetrivalThread != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1029 r = pRecordRetrivalThread->Construct(__requestId, *pEvent.release(), start, end, timeZone, pageNo, countPerPage, category);
1030 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1032 r = pRecordRetrivalThread->Start();
1033 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1035 __pRecordRetrivalThread = pRecordRetrivalThread.release();
1041 _CalendarbookImpl::GetAllEventsN(void) const
1043 int errorCode = CALENDAR_ERROR_NONE;
1045 calendar_list_h calendarListHandle = null;
1046 errorCode = calendar_db_get_all_records(_calendar_event._uri, 0, 0, &calendarListHandle);
1047 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1048 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1049 _CalendarList calendarList(calendarListHandle);
1051 result r = E_SUCCESS;
1052 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1053 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1054 r = pList->Construct();
1055 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1058 errorCode = calendar_list_get_count(calendarListHandle, &count);
1060 for (int i = 0; i < count; i++)
1062 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1063 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1065 r = pList->Add(*pTmpEvent.release());
1066 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1069 errorCode = calendar_list_first(calendarListHandle);
1070 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1071 while (pEnum->MoveNext() == E_SUCCESS)
1073 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1075 calendar_record_h tmpRecordHandle = null;
1076 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1077 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1080 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &dbIndex);
1081 _RecordImpl::GetInstance(*pTmpEvent)->SetRecordId(dbIndex);
1083 errorCode = calendar_list_next(calendarListHandle);
1086 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1088 return pList.release();
1092 _CalendarbookImpl::GetAllTodosN(void) const
1094 int errorCode = CALENDAR_ERROR_NONE;
1096 calendar_list_h calendarListHandle = null;
1097 errorCode = calendar_db_get_all_records(_calendar_todo._uri, 0, 0, &calendarListHandle);
1098 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1099 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1100 _CalendarList calendarList(calendarListHandle);
1102 result r = E_SUCCESS;
1103 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1104 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1105 r = pList->Construct();
1106 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1109 errorCode = calendar_list_get_count(calendarListHandle, &count);
1111 for (int i = 0; i < count; i++)
1113 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1114 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1116 r = pList->Add(*pTmpTodo.release());
1117 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1120 errorCode = calendar_list_first(calendarListHandle);
1121 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1122 while (pEnum->MoveNext() == E_SUCCESS)
1124 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1126 calendar_record_h tmpRecordHandle = null;
1127 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1128 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1131 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
1132 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
1134 errorCode = calendar_list_next(calendarListHandle);
1137 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1139 return pList.release();
1143 _CalendarbookImpl::GetAllCalendarsN(void) const
1145 int errorCode = CALENDAR_ERROR_NONE;
1147 calendar_list_h calendarListHandle = null;
1148 errorCode = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &calendarListHandle);
1149 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1150 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1151 _CalendarList calendarList(calendarListHandle);
1153 result r = E_SUCCESS;
1154 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1155 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1156 r = pList->Construct();
1157 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1160 errorCode = calendar_list_get_count(calendarListHandle, &count);
1162 for (int i = 0; i < count; i++)
1164 std::unique_ptr<Calendar> pTmpCalendar(_CalendarImpl::CreateDefaultInstanceN());
1165 SysTryReturn(NID_SCL, pTmpCalendar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1167 r = pList->Add(*pTmpCalendar.release());
1168 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1171 errorCode = calendar_list_first(calendarListHandle);
1172 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1173 while (pEnum->MoveNext() == E_SUCCESS)
1175 Calendar* pTmpCalendar = static_cast<Calendar*>(pEnum->GetCurrent());
1177 calendar_record_h tmpRecordHandle = null;
1178 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1179 _CalendarImpl::GetInstance(*pTmpCalendar)->SetRecordHandle(tmpRecordHandle);
1182 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_book.id, &dbIndex);
1183 _RecordImpl::GetInstance(*pTmpCalendar)->SetRecordId(dbIndex);
1185 errorCode = calendar_list_next(calendarListHandle);
1188 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1190 return pList.release();
1194 _CalendarbookImpl::GetChangedEventsAfterN(int version, int& latestVersion) const
1196 int errorCode = CALENDAR_ERROR_NONE;
1200 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1202 calendar_list_h calendarListHandle = null;
1203 int tmpLatestVersion = 0;
1204 errorCode = calendar_db_get_changes_by_version(_calendar_event._uri, CALENDAR_BOOK_FILTER_ALL, version
1205 , &calendarListHandle, &tmpLatestVersion);
1206 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1207 , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1208 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1210 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1211 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1212 result r = pList->Construct();
1213 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1216 errorCode = calendar_list_get_count(calendarListHandle, &count);
1218 errorCode = calendar_list_first(calendarListHandle);
1219 for (int i = 0; i < count; i++)
1221 calendar_record_h tmpRecordHandle = null;
1222 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1224 std::unique_ptr<CalEventChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(tmpRecordHandle));
1225 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1227 r = pList->Add(*pChangedInfo.release());
1228 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1230 errorCode = calendar_list_next(calendarListHandle);
1233 latestVersion = tmpLatestVersion;
1235 return pList.release();
1239 _CalendarbookImpl::GetChangedTodosAfterN(int version, int& latestVersion) const
1241 int errorCode = CALENDAR_ERROR_NONE;
1245 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1247 calendar_list_h calendarListHandle = null;
1248 int tmpLatestVersion = 0;
1249 errorCode = calendar_db_get_changes_by_version(_calendar_todo._uri, CALENDAR_BOOK_FILTER_ALL, version
1250 , &calendarListHandle, &tmpLatestVersion);
1251 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1252 , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1253 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1254 _CalendarList calendarList(calendarListHandle);
1256 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1257 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1258 result r = pList->Construct();
1259 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1262 errorCode = calendar_list_get_count(calendarListHandle, &count);
1264 errorCode = calendar_list_first(calendarListHandle);
1265 for (int i = 0; i < count; i++)
1267 calendar_record_h tmpRecordHandle = null;
1268 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1270 std::unique_ptr<CalTodoChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(tmpRecordHandle));
1271 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1273 r = pList->Add(*pChangedInfo.release());
1274 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1276 errorCode = calendar_list_next(calendarListHandle);
1279 latestVersion = tmpLatestVersion;
1281 return pList.release();
1285 _CalendarbookImpl::RemoveEventInstance(const CalEventInstance& eventInstance)
1287 result r = E_SUCCESS;
1288 int errorCode = CALENDAR_ERROR_NONE;
1290 calendar_record_h eventHandle = null;
1291 char* pExdate = null;
1293 // Get event handle from DB
1294 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &eventHandle);
1295 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1296 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
1297 _CalendarRecord eventRecord(eventHandle);
1299 int baseEventId = _INVALID_EVENT_DB_ID;
1300 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1302 if (baseEventId != _INVALID_EVENT_DB_ID)
1304 errorCode = calendar_db_delete_record(_calendar_event._uri, eventInstance.GetOriginalEventId());
1305 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1310 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExdate);
1313 if (pExdate != null && strlen(pExdate) > 0)
1315 exdate.Append(pExdate);
1316 r = exdate.Append(_RECURRENCE_DELIMITER);
1319 r = exdate.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent()));
1321 std::unique_ptr<char[]> pAppendedExdate(_StringConverter::CopyToCharArrayN(exdate));
1322 SysTryReturnResult(NID_SCL, pAppendedExdate != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1324 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, pAppendedExdate.get());
1326 // Update event handle
1327 errorCode = calendar_db_update_record(eventHandle);
1328 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1335 _CalendarbookImpl::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event)
1337 result r = E_SUCCESS;
1338 int errorCode = CALENDAR_ERROR_NONE;
1340 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
1341 , "Invalid argument is used. The event's recordId is INVALID_RECORD_ID.");
1342 SysTryReturnResult(NID_SCL, eventInstance.GetOriginalEventId() == event.GetRecordId(), E_INVALID_ARG
1343 , "Invalid argument is used. The event's recordId is not equal to eventInstance's original event ID.");
1344 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified event is not found.");
1346 calendar_record_h eventHandle = null;
1347 errorCode = calendar_record_clone(_CalEventImpl::GetInstance(event)->GetRecordHandle(), &eventHandle);
1348 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1349 _CalendarRecord eventRecord(eventHandle);
1351 int baseEventId = _INVALID_EVENT_DB_ID;
1352 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1354 calendar_record_h baseEventHandle = null;
1355 if (baseEventId == _INVALID_EVENT_DB_ID)
1357 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &baseEventHandle);
1361 errorCode = calendar_db_get_record(_calendar_event._uri, baseEventId, &baseEventHandle);
1363 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1364 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The base event is not found.");
1365 _CalendarRecord baseEventRecord(baseEventHandle);
1367 int tmpIntValue = 0;
1368 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.freq, &tmpIntValue);
1369 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, tmpIntValue);
1370 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.range_type, &tmpIntValue);
1371 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, tmpIntValue);
1372 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.count, &tmpIntValue);
1373 errorCode = calendar_record_set_int(eventHandle, _calendar_event.count, tmpIntValue);
1374 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.interval, &tmpIntValue);
1375 errorCode = calendar_record_set_int(eventHandle, _calendar_event.interval, tmpIntValue);
1376 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.wkst, &tmpIntValue);
1377 errorCode = calendar_record_set_int(eventHandle, _calendar_event.wkst, tmpIntValue);
1379 calendar_time_s tmpTimeValue;
1380 errorCode = calendar_record_get_caltime(baseEventHandle, _calendar_event.until_time, &tmpTimeValue);
1381 bool tmpIsAllDay = 0;
1382 calendar_time_s tmpStartTimeValue;
1383 DateTime convertedTime;
1384 errorCode = calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &tmpStartTimeValue);
1386 if (tmpTimeValue.type != tmpStartTimeValue.type)
1388 if (tmpStartTimeValue.type == CALENDAR_TIME_UTIME)
1390 convertedTime.SetValue(tmpTimeValue.time.date.year, tmpTimeValue.time.date.month, tmpTimeValue.time.date.mday);
1391 tmpTimeValue.type = CALENDAR_TIME_UTIME;
1392 tmpTimeValue.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(convertedTime);
1396 convertedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpTimeValue.time.utime);
1397 tmpTimeValue.type = CALENDAR_TIME_LOCALTIME;
1398 tmpTimeValue.time.date.year = convertedTime.GetYear();
1399 tmpTimeValue.time.date.month = convertedTime.GetMonth();
1400 tmpTimeValue.time.date.mday = convertedTime.GetDay();
1403 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.until_time, tmpTimeValue);
1405 char* tmpStrValue = null;
1406 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.byday, &tmpStrValue);
1407 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, tmpStrValue);
1408 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonthday, &tmpStrValue);
1409 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, tmpStrValue);
1410 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonth, &tmpStrValue);
1411 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, tmpStrValue);
1412 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.exdate, &tmpStrValue);
1413 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, tmpStrValue);
1415 if (baseEventId == _INVALID_EVENT_DB_ID)
1417 errorCode = calendar_record_set_int(eventHandle, _calendar_event.original_event_id, eventInstance.GetOriginalEventId());
1419 std::unique_ptr<char[]> pConvertedRecurrenceId(_StringConverter::CopyToCharArrayN(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent())));
1420 errorCode = calendar_record_set_str(eventHandle, _calendar_event.recurrence_id, pConvertedRecurrenceId.get());
1423 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
1424 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1425 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
1429 errorCode = calendar_db_update_record(eventHandle);
1430 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1431 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The base event of the event is not found.");
1434 calendar_record_h tmpEventHandle = null;
1435 errorCode = calendar_db_get_record(_calendar_event._uri, event.GetRecordId(), &tmpEventHandle);
1436 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1437 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
1443 _CalendarbookImpl::GetLatestVersion(void) const
1445 int errorCode = CALENDAR_ERROR_NONE;
1450 errorCode = calendar_db_get_current_version(&dbVersion);
1451 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, 0, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1457 _CalendarbookImpl::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const
1459 int errorCode = CALENDAR_ERROR_NONE;
1461 bool ascending = false;
1462 unsigned int viewSortPropertyId = 0;
1464 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1465 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1467 SysTryReturn(NID_SCL, offset >= 0 && maxCount >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The specified offset or maxCount is less than 0.");
1468 SysTryReturn(NID_SCL, propertySortedBy == 0 || _CalendarbookFilterImpl::IsValidProperty(type, propertySortedBy), null, E_INVALID_ARG
1469 , "[%s] Invalid argument is used. propertySortedBy = %d", GetErrorMessage(E_INVALID_ARG), propertySortedBy);
1471 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1474 calendar_query_h queryHandle = null;
1475 errorCode = calendar_query_create(pViewUri, &queryHandle);
1476 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1477 _CalendarQuery query(queryHandle);
1479 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1481 viewSortPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1482 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1484 errorCode = calendar_query_set_sort(queryHandle, viewSortPropertyId, ascending);
1489 errorCode = calendar_query_set_filter(queryHandle, filterHandle);
1492 calendar_list_h resultListHandle = null;
1493 errorCode = calendar_db_get_records_with_query(queryHandle, offset, maxCount, &resultListHandle);
1494 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1495 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1496 _CalendarList calendarList(resultListHandle);
1498 std::unique_ptr<IList, AllElementsDeleter> pList;
1502 case CB_FI_TYPE_EVENT:
1504 pList.reset(ConvertRecordListN<CalEvent, _CalEventImpl, _calendar_event_property_ids>(resultListHandle, _calendar_event));
1505 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1506 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1509 case CB_FI_TYPE_TODO:
1511 pList.reset(ConvertRecordListN<CalTodo, _CalTodoImpl, _calendar_todo_property_ids>(resultListHandle, _calendar_todo));
1512 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1513 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1516 case CB_FI_TYPE_CALENDAR:
1518 pList.reset(ConvertRecordListN<Calendar, _CalendarImpl, _calendar_book_property_ids>(resultListHandle, _calendar_book));
1519 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1520 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1523 case CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE:
1525 pList.reset(ConvertEventInstanceListN(resultListHandle, true));
1526 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1529 case CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE:
1531 pList.reset(ConvertEventInstanceListN(resultListHandle, false));
1532 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1536 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of filter is (%d)", GetErrorMessage(E_INVALID_ARG), type);
1540 return pList.release();
1544 _CalendarbookImpl::GetMatchedItemCount(const CalendarbookFilter& filter) const
1546 int errorCode = CALENDAR_ERROR_NONE;
1548 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1549 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1551 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1554 calendar_query_h queryHandle = null;
1555 errorCode = calendar_query_create(pViewUri, &queryHandle);
1556 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1557 _CalendarQuery query(queryHandle);
1561 errorCode = calendar_query_set_filter(queryHandle, filterHandle);
1564 int count = _INVALID_COUNT;
1566 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
1567 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1573 _CalendarbookImpl::ParseEventsFromVcalendarN(const String& vCalFilePath)
1575 result r = E_SUCCESS;
1576 int errorCode = CALENDAR_ERROR_NONE;
1581 r = vCalFile.Construct(vCalFilePath, L"r");
1582 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1583 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1584 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1586 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1587 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1588 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1590 int fileLength = vCalFile.Tell();
1591 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is empty.");
1593 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1594 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1595 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1597 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1598 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1599 r = pBuffer->Construct(fileLength);
1600 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1602 r = vCalFile.Read(*pBuffer);
1603 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1604 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1606 _CalendarConnector connector;
1607 r = connector.GetResult();
1608 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1611 calendar_list_h calendarListHandle = null;
1612 errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1613 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1614 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is invalid.");
1615 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1616 _CalendarList calendarList(calendarListHandle);
1618 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1619 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1620 r = pList->Construct();
1621 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1624 errorCode = calendar_list_get_count(calendarListHandle, &count);
1626 errorCode = calendar_list_first(calendarListHandle);
1627 for (int i = 0; i < count; i++)
1629 calendar_record_h tmpRecordHandle = null;
1630 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1631 errorCode = calendar_list_next(calendarListHandle);
1634 errorCode = calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1636 if (strcmp(pUri, _calendar_event._uri) == 0)
1638 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1639 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1641 r = pList->Add(*pTmpEvent.release());
1642 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1646 errorCode = calendar_list_remove(calendarListHandle, tmpRecordHandle);
1647 errorCode = calendar_record_destroy(tmpRecordHandle, true);
1651 errorCode = calendar_list_first(calendarListHandle);
1652 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1653 while (pEnum->MoveNext() == E_SUCCESS)
1655 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1657 calendar_record_h tmpRecordHandle = null;
1658 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1659 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1661 errorCode = calendar_list_next(calendarListHandle);
1664 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1666 return pList.release();
1670 _CalendarbookImpl::ParseTodosFromVcalendarN(const String& vCalFilePath)
1672 result r = E_SUCCESS;
1673 int errorCode = CALENDAR_ERROR_NONE;
1678 r = vCalFile.Construct(vCalFilePath, L"r");
1679 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1680 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1681 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1683 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1684 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1685 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1687 int fileLength = vCalFile.Tell();
1688 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is empty.");
1690 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1691 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1692 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1694 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1695 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1696 r = pBuffer->Construct(fileLength);
1697 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1699 r = vCalFile.Read(*pBuffer);
1700 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1701 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1703 _CalendarConnector connector;
1704 r = connector.GetResult();
1705 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1708 calendar_list_h calendarListHandle = null;
1709 errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1710 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1711 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is invalid.");
1712 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1713 _CalendarList calendarList(calendarListHandle);
1715 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1716 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1717 r = pList->Construct();
1718 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1721 errorCode = calendar_list_get_count(calendarListHandle, &count);
1723 errorCode = calendar_list_first(calendarListHandle);
1724 for (int i = 0; i < count; i++)
1726 calendar_record_h tmpRecordHandle = null;
1727 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1728 errorCode = calendar_list_next(calendarListHandle);
1731 errorCode = calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1733 if (strcmp(pUri, _calendar_todo._uri) == 0)
1735 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1736 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1738 r = pList->Add(*pTmpTodo.release());
1739 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1743 errorCode = calendar_list_remove(calendarListHandle, tmpRecordHandle);
1744 errorCode = calendar_record_destroy(tmpRecordHandle, true);
1748 errorCode = calendar_list_first(calendarListHandle);
1749 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1750 while (pEnum->MoveNext() == E_SUCCESS)
1752 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1754 calendar_record_h tmpRecordHandle = null;
1755 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1756 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1758 errorCode = calendar_list_next(calendarListHandle);
1761 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1763 return pList.release();
1767 _CalendarbookImpl::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath)
1769 result r = E_SUCCESS;
1770 int errorCode = CALENDAR_ERROR_NONE;
1772 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1773 r = GetLastResult();
1774 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1776 _CalendarConnector connector;
1777 r = connector.GetResult();
1778 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1780 calendar_list_h calendarListHandle = null;
1781 errorCode = calendar_list_create(&calendarListHandle);
1782 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1783 _CalendarList calendarList(calendarListHandle, false);
1785 std::unique_ptr<IEnumerator> pEnum(eventList.GetEnumeratorN());
1786 while (pEnum->MoveNext() == E_SUCCESS)
1788 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1789 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_EVENT, E_INVALID_ARG, "Invalid argument is used. The eventList contains invalid record.");
1791 CalEvent* pTmpEvent = static_cast<CalEvent*>(pTmpRecord);
1792 errorCode = calendar_list_add(calendarListHandle, _CalEventImpl::GetInstance(*pTmpEvent)->GetRecordHandle());
1793 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1796 char* pVCalBuffer = null;
1797 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1798 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1799 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1800 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1803 r = vCalFile.Construct(vCalFilePath, L"w");
1804 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
1805 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1806 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1808 int pVCalBufferLength = strlen(pVCalBuffer);
1809 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1810 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1811 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1817 _CalendarbookImpl::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath)
1819 result r = E_SUCCESS;
1820 int errorCode = CALENDAR_ERROR_NONE;
1822 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1823 r = GetLastResult();
1824 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1826 _CalendarConnector connector;
1827 r = connector.GetResult();
1828 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1830 calendar_list_h calendarListHandle = null;
1831 errorCode = calendar_list_create(&calendarListHandle);
1832 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1833 _CalendarList calendarList(calendarListHandle, false);
1835 std::unique_ptr<IEnumerator> pEnum(todoList.GetEnumeratorN());
1836 while (pEnum->MoveNext() == E_SUCCESS)
1838 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1839 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_TODO, E_INVALID_ARG, "Invalid argument is used. The todoList contains invalid record.");
1841 CalTodo* pTmpTodo = static_cast<CalTodo*>(pTmpRecord);
1842 errorCode = calendar_list_add(calendarListHandle, _CalTodoImpl::GetInstance(*pTmpTodo)->GetRecordHandle());
1843 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1846 char* pVCalBuffer = null;
1847 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1848 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1849 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1850 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1853 r = vCalFile.Construct(vCalFilePath, L"w");
1854 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
1855 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1856 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1858 int pVCalBufferLength = strlen(pVCalBuffer);
1859 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1860 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1861 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1867 _CalendarbookImpl::GetMaxDateTime(void)
1869 DateTime maxDateTime;
1870 maxDateTime.SetValue(2100, 12, 31, 23, 59, 59);
1876 _CalendarbookImpl::GetMinDateTime(void)
1878 DateTime minDateTime;
1879 minDateTime.SetValue(1900, 1, 1, 0, 0, 0);
1885 _CalendarbookImpl::GetEventInstancesCommonN(const DateTime& start, const DateTime& end,
1886 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category) const
1890 calendar_time_s convertedStartTime;
1891 calendar_time_s convertedEndTime;
1892 _CalendarbookUtil::ConvertDateTimeToCalTime(start, convertedStartTime);
1893 _CalendarbookUtil::ConvertDateTimeToCalTime(end, convertedEndTime);
1895 Tizen::Locales::TimeZone tmpTimeZone(timeZone);
1896 DateTime localStartTime = tmpTimeZone.UtcTimeToWallTime(start);
1897 DateTime localEndTime = tmpTimeZone.UtcTimeToWallTime(end);
1899 calendar_time_s convertedLocalStartTime;
1900 calendar_time_s convertedLocalEndTime;
1901 _CalendarbookUtil::ConvertDateToCalTime(localStartTime, convertedLocalStartTime);
1902 _CalendarbookUtil::ConvertDateToCalTime(localEndTime, convertedLocalEndTime);
1904 std::unique_ptr<IList, AllElementsDeleter> pList;
1906 if (category == EVENT_CATEGORY_ALL)
1908 pList.reset(GetEventInstancesOfAllCategoriesN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage));
1912 pList.reset(GetEventInstancesOfCategoryN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage, category));
1915 return pList.release();
1919 _CalendarbookImpl::GetEventInstancesOfAllCategoriesN(const calendar_time_s& startTime, const calendar_time_s& endTime,
1920 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage) const
1922 int errorCode = CALENDAR_ERROR_NONE;
1926 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
1927 errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
1928 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1929 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
1931 // Condition : End time of the item > start time of filter
1932 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
1934 // Condition : Start time of the item < end time of filter
1935 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
1936 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
1939 calendar_query_h allDayEventInstanceQueryHandle = null;
1940 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
1941 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1942 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
1944 errorCode = calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
1945 errorCode = calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
1947 int startIndex = (pageNo - 1) * countPerPage;
1949 calendar_list_h allDayEventInstanceListHandle = null;
1950 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, startIndex, countPerPage, &allDayEventInstanceListHandle);
1951 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1952 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1953 _CalendarList allDayEventList(allDayEventInstanceListHandle);
1955 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1956 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1957 result r = pList->Construct();
1958 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1960 int allDayEventInstanceCount = 0;
1961 errorCode = calendar_db_get_count_with_query(allDayEventInstanceQueryHandle, &allDayEventInstanceCount);
1962 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1965 errorCode = calendar_list_get_count(allDayEventInstanceListHandle, &count);
1967 int pageCount = allDayEventInstanceCount / countPerPage;
1968 int remainingCount = countPerPage - count;
1970 errorCode = calendar_list_first(allDayEventInstanceListHandle);
1971 for (int i = 0; i < count; i++)
1973 calendar_record_h tmpRecordHandle = null;
1974 errorCode = calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
1976 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
1977 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1979 r = pList->Add(*pTmpEventInstance.release());
1980 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1982 errorCode = calendar_list_next(allDayEventInstanceListHandle);
1985 if (remainingCount > 0)
1987 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
1988 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
1989 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1990 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
1992 calendar_filter_h subFilterHandle = null;
1993 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
1994 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1995 _CalendarFilter subFilter(subFilterHandle);
1996 subFilterHandle = null;
1998 // Condition : End time of the item > start time of filter
1999 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2001 // Condition : Start time of the item < end time of filter
2002 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2003 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2005 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2007 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2008 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2009 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2010 subFilter.ResetHandle(subFilterHandle);
2011 subFilterHandle = null;
2013 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2014 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2015 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2017 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2018 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2021 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2022 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2023 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2024 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2026 errorCode = calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2027 errorCode = calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2029 if (remainingCount == countPerPage)
2031 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (allDayEventInstanceCount % countPerPage);
2038 calendar_list_h nonAllDayEventInstanceListHandle = null;
2039 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, startIndex, remainingCount, &nonAllDayEventInstanceListHandle);
2040 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2041 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2042 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2045 errorCode = calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2046 errorCode = calendar_list_first(nonAllDayEventInstanceListHandle);
2047 for (int i = 0; i < count; i++)
2049 calendar_record_h tmpRecordHandle = null;
2050 errorCode = calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2052 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2053 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2055 r = pList->Add(*pTmpEventInstance.release());
2056 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2058 errorCode = calendar_list_next(nonAllDayEventInstanceListHandle);
2062 return pList.release();
2066 _CalendarbookImpl::GetEventInstancesOfCategoryN(const calendar_time_s& startTime, const calendar_time_s& endTime,
2067 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage, unsigned long category) const
2069 int errorCode = CALENDAR_ERROR_NONE;
2073 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
2074 errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
2075 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2076 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
2078 // Condition : End time of the item > start time of filter
2079 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
2081 // Condition : Start time of the item < end time of filter
2082 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
2083 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
2086 calendar_query_h allDayEventInstanceQueryHandle = null;
2087 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
2088 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2089 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
2091 errorCode = calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
2092 errorCode = calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
2094 // Generate event : category map
2095 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(GenerateEventCategoryMapN());
2096 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2098 int startIndex = (pageNo - 1) * countPerPage;
2100 calendar_list_h allDayEventInstanceListHandle = null;
2101 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, 0, 0, &allDayEventInstanceListHandle);
2102 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2103 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2104 _CalendarList allDayEventList(allDayEventInstanceListHandle);
2106 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2107 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2108 result r = pList->Construct();
2109 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2111 int remainingCount = countPerPage;
2112 int candidateCount = 0;
2114 errorCode = calendar_list_get_count(allDayEventInstanceListHandle, &count);
2115 errorCode = calendar_list_first(allDayEventInstanceListHandle);
2116 for (int i = 0; i < count && remainingCount > 0; i++)
2118 calendar_record_h tmpRecordHandle = null;
2119 errorCode = calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
2121 int tmpCategory = EVENT_CATEGORY_ALL;
2123 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_instance_allday_calendar_book.event_id, &eventId);
2124 pEventCategoryMap->GetValue(eventId, tmpCategory);
2126 if (tmpCategory == category)
2128 if (candidateCount >= startIndex)
2130 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2131 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2133 r = pList->Add(*pTmpEventInstance.release());
2134 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2142 errorCode = calendar_list_next(allDayEventInstanceListHandle);
2145 if (remainingCount > 0)
2147 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
2148 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
2149 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2150 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
2152 calendar_filter_h subFilterHandle = null;
2153 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2154 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2155 _CalendarFilter subFilter(subFilterHandle);
2156 subFilterHandle = null;
2158 // Condition : End time of the item > start time of filter
2159 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2161 // Condition : Start time of the item < end time of filter
2162 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2163 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2165 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2167 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2168 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2169 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2170 subFilter.ResetHandle(subFilterHandle);
2171 subFilterHandle = null;
2173 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2174 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2175 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2177 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2178 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2181 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2182 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2183 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2184 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2186 errorCode = calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2187 errorCode = calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2189 if (remainingCount == countPerPage)
2191 int pageCount = candidateCount / countPerPage;
2192 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (candidateCount % countPerPage);
2199 calendar_list_h nonAllDayEventInstanceListHandle = null;
2200 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, 0, 0, &nonAllDayEventInstanceListHandle);
2201 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2202 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2203 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2208 errorCode = calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2209 errorCode = calendar_list_first(nonAllDayEventInstanceListHandle);
2210 for (int i = 0; i < count && remainingCount > 0; i++)
2212 calendar_record_h tmpRecordHandle = null;
2213 errorCode = calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2215 int tmpCategory = EVENT_CATEGORY_ALL;
2217 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_instance_normal_calendar_book.event_id, &eventId);
2218 pEventCategoryMap->GetValue(eventId, tmpCategory);
2220 if (tmpCategory == category)
2222 if (candidateCount >= startIndex)
2224 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2225 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2227 r = pList->Add(*pTmpEventInstance.release());
2228 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2236 errorCode = calendar_list_next(nonAllDayEventInstanceListHandle);
2240 return pList.release();
2244 _CalendarbookImpl::GenerateEventCategoryMapN(void) const
2246 result r = E_SUCCESS;
2247 int errorCode = CALENDAR_ERROR_NONE;
2249 unsigned int projectionList[_NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION] = {_calendar_event.id, _calendar_event.categories};
2252 calendar_query_h queryHandle = null;
2253 errorCode = calendar_query_create(_calendar_event._uri, &queryHandle);
2254 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2255 _CalendarQuery query(queryHandle);
2257 errorCode = calendar_query_set_projection(queryHandle, projectionList, _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION);
2258 errorCode = calendar_query_set_sort(queryHandle, _calendar_event.id, true);
2260 calendar_list_h calendarListHandle = null;
2261 errorCode = calendar_db_get_records_with_query(queryHandle, 0, 0, &calendarListHandle);
2262 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2263 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2264 _CalendarList calendarList(calendarListHandle);
2266 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(new HashMapT<int, int>());
2267 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2268 r = pEventCategoryMap->Construct();
2269 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2272 errorCode = calendar_list_get_count(calendarListHandle, &count);
2273 errorCode = calendar_list_first(calendarListHandle);
2274 for (int i = 0; i < count; i++)
2276 calendar_record_h tmpRecordHandle = null;
2277 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
2280 char* pCategories = null;
2282 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &eventId);
2283 errorCode = calendar_record_get_str_p(tmpRecordHandle, _calendar_event.categories, &pCategories);
2285 int category = _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
2287 pEventCategoryMap->Add(eventId, category);
2289 errorCode = calendar_list_next(calendarListHandle);
2292 return pEventCategoryMap.release();
2296 _CalendarbookImpl::GetCalendarItemTypeByCalendarId(RecordId calendarId) const
2298 CalendarItemType calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2300 int errorCode = CALENDAR_ERROR_NONE;
2301 calendar_record_h calendarHandle = null;
2302 int storeType = CALENDAR_BOOK_TYPE_NONE;
2304 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, "[E_SYSTEM] A system error has been occurred.");
2307 errorCode = 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, "[E_SYSTEM] A system error has been occurred.");
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 int errorCode = CALENDAR_ERROR_NONE;
2338 calendar_record_h eventHandle = null;
2340 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
2341 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2343 calendar_record_destroy(eventHandle, true);
2349 _CalendarbookImpl::CheckTodoExistance(RecordId todoId) const
2351 int errorCode = CALENDAR_ERROR_NONE;
2352 calendar_record_h todoHandle = null;
2354 errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
2355 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2357 calendar_record_destroy(todoHandle, true);
2363 _CalendarbookImpl::CheckCalendarExistance(RecordId calendarId) const
2365 int errorCode = CALENDAR_ERROR_NONE;
2366 calendar_record_h calendarHandle = null;
2368 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2369 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2371 calendar_record_destroy(calendarHandle, true);
2377 _CalendarbookImpl::CheckValidTodoPriority(unsigned long priority) const
2379 if ((priority & TODO_PRIORITY_LOW) || (priority & TODO_PRIORITY_NORMAL) || (priority & TODO_PRIORITY_HIGH))
2388 _CalendarbookImpl::CheckValidTodoStatus(unsigned long status) const
2390 if ((status & TODO_STATUS_NONE) || (status & TODO_STATUS_NEEDS_ACTION) || (status & TODO_STATUS_COMPLETED)
2391 || (status & TODO_STATUS_IN_PROCESS) || (status & TODO_STATUS_CANCELLED))
2400 _CalendarbookImpl::ConvertTodoStatusToCalendarTodoStatus(unsigned long todoStatus) const
2402 return todoStatus << 8;
2406 _CalendarbookImpl::ConvertTodoPriorityToCalendarTodoPriority(unsigned long todoPriority) const
2408 int calendarTodoPriority = CALENDAR_TODO_PRIORITY_NONE;
2410 if (todoPriority == TODO_PRIORITY_LOW)
2412 calendarTodoPriority = CALENDAR_TODO_PRIORITY_LOW;
2414 else if (todoPriority == TODO_PRIORITY_NORMAL)
2416 calendarTodoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
2418 else if (todoPriority == TODO_PRIORITY_HIGH)
2420 calendarTodoPriority = CALENDAR_TODO_PRIORITY_HIGH;
2423 return calendarTodoPriority;
2427 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2429 int errorCode = CALENDAR_ERROR_NONE;
2430 int originalEventDBId = _INVALID_EVENT_DB_ID;
2431 calendar_record_h eventHandle = null;
2433 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2434 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2436 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2437 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2438 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2440 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2441 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2443 calendar_time_s startCalendarTime;
2444 calendar_time_s endCalendarTime;
2445 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2446 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2447 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2448 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2450 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2451 pEventImpl->SetRecordHandle(eventHandle);
2453 return pEvent.release();
2457 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2459 int errorCode = CALENDAR_ERROR_NONE;
2460 int originalEventDBId = _INVALID_EVENT_DB_ID;
2461 calendar_record_h eventHandle = null;
2463 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2464 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2466 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2467 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2468 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2470 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2471 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2473 calendar_time_s startCalendarTime;
2474 calendar_time_s endCalendarTime;
2475 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2476 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2477 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2478 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2480 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2481 pEventImpl->SetRecordHandle(eventHandle);
2483 return pEvent.release();
2487 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2489 int errorCode = CALENDAR_ERROR_NONE;
2493 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2494 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2495 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2497 int originalEventDBId = _INVALID_EVENT_DB_ID;
2498 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2499 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2501 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2502 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.calendar_book_id, &calendarDBId);
2503 pEventInstanceImpl->SetCalendarId(calendarDBId);
2505 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2506 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.busy_status, &srcEventBusyStatus);
2507 BusyStatus busyStatus = BUSY_STATUS_FREE;
2508 switch (srcEventBusyStatus)
2510 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2511 busyStatus = BUSY_STATUS_FREE;
2513 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2514 busyStatus = BUSY_STATUS_BUSY;
2516 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2517 busyStatus = BUSY_STATUS_UNAVAILABLE;
2519 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2520 busyStatus = BUSY_STATUS_TENTATIVE;
2523 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busy status = %d", srcEventBusyStatus);
2524 busyStatus = BUSY_STATUS_FREE;
2527 pEventInstanceImpl->SetBusyStatus(busyStatus);
2529 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2530 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_status, &srcEventStatus);
2531 EventStatus eventStatus = EVENT_STATUS_NONE;
2532 switch (srcEventStatus)
2534 case CALENDAR_EVENT_STATUS_NONE:
2535 eventStatus = EVENT_STATUS_NONE;
2537 case CALENDAR_EVENT_STATUS_TENTATIVE:
2538 eventStatus = EVENT_STATUS_TENTATIVE;
2540 case CALENDAR_EVENT_STATUS_CONFIRMED:
2541 eventStatus = EVENT_STATUS_CONFIRMED;
2543 case CALENDAR_EVENT_STATUS_CANCELLED:
2544 eventStatus = EVENT_STATUS_CANCELLED;
2547 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", srcEventStatus);
2548 eventStatus = EVENT_STATUS_NONE;
2550 pEventInstanceImpl->SetStatus(eventStatus);
2552 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2553 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.priority, &srcPriority);
2554 EventPriority priority = EVENT_PRIORITY_NORMAL;
2555 switch (srcPriority)
2557 case CALENDAR_EVENT_PRIORITY_LOW:
2558 priority = EVENT_PRIORITY_LOW;
2560 case CALENDAR_EVENT_PRIORITY_NONE:
2562 case CALENDAR_EVENT_PRIORITY_NORMAL:
2563 priority = EVENT_PRIORITY_NORMAL;
2565 case CALENDAR_EVENT_PRIORITY_HIGH:
2566 priority = EVENT_PRIORITY_HIGH;
2569 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", srcPriority);
2570 priority = EVENT_PRIORITY_NORMAL;
2572 pEventInstanceImpl->SetPriority(priority);
2574 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2575 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.sensitivity, &srcSensitivity);
2576 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2577 switch (srcSensitivity)
2579 case CALENDAR_SENSITIVITY_PUBLIC:
2580 sensitivity = SENSITIVITY_PUBLIC;
2582 case CALENDAR_SENSITIVITY_PRIVATE:
2583 sensitivity = SENSITIVITY_PRIVATE;
2585 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2586 sensitivity = SENSITIVITY_CONFIDENTIAL;
2589 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
2590 sensitivity = SENSITIVITY_PUBLIC;
2592 pEventInstanceImpl->SetSensitivity(sensitivity);
2594 calendar_time_s startCalendarTime;
2595 DateTime tmpStartTime;
2596 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2597 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
2598 pEventInstanceImpl->SetStartTime(tmpStartTime);
2600 calendar_time_s endCalendarTime;
2601 DateTime tmpEndTime;
2602 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2603 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
2604 pEventInstanceImpl->SetEndTime(tmpEndTime);
2606 pEventInstanceImpl->SetAllDayEvent(true);
2608 int isRecurring = 0;
2609 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_rrule, &isRecurring);
2610 pEventInstanceImpl->SetRecurring(isRecurring);
2612 int hasReminder = 0;
2613 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_alarm, &hasReminder);
2614 pEventInstanceImpl->SetHasReminder(hasReminder);
2616 char* pSubject = null;
2617 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.summary, &pSubject);
2618 pEventInstanceImpl->SetSubject(pSubject);
2620 char* pDescription = null;
2621 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.description, &pDescription);
2622 pEventInstanceImpl->SetDescription(pDescription);
2624 char* pLocation = null;
2625 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.location, &pLocation);
2626 pEventInstanceImpl->SetLocation(pLocation);
2628 return pEventInstance.release();
2632 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2634 int errorCode = CALENDAR_ERROR_NONE;
2638 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2639 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2640 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2642 int originalEventDBId = _INVALID_EVENT_DB_ID;
2643 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2644 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2646 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2647 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.calendar_book_id, &calendarDBId);
2648 pEventInstanceImpl->SetCalendarId(calendarDBId);
2650 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2651 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.busy_status, &srcEventBusyStatus);
2652 BusyStatus busyStatus = BUSY_STATUS_FREE;
2653 switch (srcEventBusyStatus)
2655 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2656 busyStatus = BUSY_STATUS_FREE;
2658 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2659 busyStatus = BUSY_STATUS_BUSY;
2661 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2662 busyStatus = BUSY_STATUS_UNAVAILABLE;
2664 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2665 busyStatus = BUSY_STATUS_TENTATIVE;
2668 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busy status = %d", srcEventBusyStatus);
2669 busyStatus = BUSY_STATUS_FREE;
2672 pEventInstanceImpl->SetBusyStatus(busyStatus);
2674 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2675 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_status, &srcEventStatus);
2677 EventStatus eventStatus = EVENT_STATUS_NONE;
2678 switch (srcEventStatus)
2680 case CALENDAR_EVENT_STATUS_NONE:
2681 eventStatus = EVENT_STATUS_NONE;
2683 case CALENDAR_EVENT_STATUS_TENTATIVE:
2684 eventStatus = EVENT_STATUS_TENTATIVE;
2686 case CALENDAR_EVENT_STATUS_CONFIRMED:
2687 eventStatus = EVENT_STATUS_CONFIRMED;
2689 case CALENDAR_EVENT_STATUS_CANCELLED:
2690 eventStatus = EVENT_STATUS_CANCELLED;
2693 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", srcEventStatus);
2694 eventStatus = EVENT_STATUS_NONE;
2696 pEventInstanceImpl->SetStatus(eventStatus);
2698 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2699 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.priority, &srcPriority);
2700 EventPriority priority = EVENT_PRIORITY_NORMAL;
2701 switch (srcPriority)
2703 case CALENDAR_EVENT_PRIORITY_LOW:
2704 priority = EVENT_PRIORITY_LOW;
2706 case CALENDAR_EVENT_PRIORITY_NONE:
2708 case CALENDAR_EVENT_PRIORITY_NORMAL:
2709 priority = EVENT_PRIORITY_NORMAL;
2711 case CALENDAR_EVENT_PRIORITY_HIGH:
2712 priority = EVENT_PRIORITY_HIGH;
2715 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", srcPriority);
2716 priority = EVENT_PRIORITY_NORMAL;
2718 pEventInstanceImpl->SetPriority(priority);
2720 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2721 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.sensitivity, &srcSensitivity);
2722 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2723 switch (srcSensitivity)
2725 case CALENDAR_SENSITIVITY_PUBLIC:
2726 sensitivity = SENSITIVITY_PUBLIC;
2728 case CALENDAR_SENSITIVITY_PRIVATE:
2729 sensitivity = SENSITIVITY_PRIVATE;
2731 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2732 sensitivity = SENSITIVITY_CONFIDENTIAL;
2735 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
2736 sensitivity = SENSITIVITY_PUBLIC;
2738 pEventInstanceImpl->SetSensitivity(sensitivity);
2740 calendar_time_s startCalendarTime;
2741 DateTime tmpStartTime;
2742 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2743 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
2744 pEventInstanceImpl->SetStartTime(tmpStartTime);
2746 calendar_time_s endCalendarTime;
2747 DateTime tmpEndTime;
2748 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2749 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
2750 pEventInstanceImpl->SetEndTime(tmpEndTime);
2752 pEventInstanceImpl->SetAllDayEvent(false);
2754 int isRecurring = 0;
2755 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_rrule, &isRecurring);
2756 pEventInstanceImpl->SetRecurring(isRecurring);
2758 int hasReminder = 0;
2759 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_alarm, &hasReminder);
2760 pEventInstanceImpl->SetHasReminder(hasReminder);
2762 char* pSubject = null;
2763 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.summary, &pSubject);
2764 pEventInstanceImpl->SetSubject(pSubject);
2766 char* pDescription = null;
2767 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.description, &pDescription);
2768 pEventInstanceImpl->SetDescription(pDescription);
2770 char* pLocation = null;
2771 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.location, &pLocation);
2772 pEventInstanceImpl->SetLocation(pLocation);
2774 return pEventInstance.release();
2778 _CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(calendar_record_h modifiedEventHandle)
2780 int errorCode = CALENDAR_ERROR_NONE;
2784 std::unique_ptr<CalEventChangeInfo> pEventChangeInfo(new (std::nothrow) CalEventChangeInfo());
2785 SysTryReturn(NID_SCL, pEventChangeInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2786 _CalEventChangeInfoImpl* pEventChangeInfoImpl = _CalEventChangeInfoImpl::GetInstance(*pEventChangeInfo.get());
2789 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.id, &eventId);
2790 pEventChangeInfoImpl->SetEventId(eventId);
2792 int calendarbookId = 0;
2793 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2794 pEventChangeInfoImpl->SetCalendarId(calendarbookId);
2796 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2797 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2798 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2799 switch (modifiedStatus)
2801 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2802 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2804 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2805 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2807 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2808 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2811 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. modified status = %d", modifiedStatus);
2814 pEventChangeInfoImpl->SetChangeType(recordChangeType);
2817 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.version, &version);
2818 pEventChangeInfoImpl->SetVersion(version);
2820 return pEventChangeInfo.release();
2824 _CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(calendar_record_h modifiedTodoHandle)
2826 int errorCode = CALENDAR_ERROR_NONE;
2830 std::unique_ptr<CalTodoChangeInfo> pTodoChangeInfo(new (std::nothrow) CalTodoChangeInfo());
2831 SysTryReturn(NID_SCL, pTodoChangeInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2832 _CalTodoChangeInfoImpl* pTodoChangeInfoImpl = _CalTodoChangeInfoImpl::GetInstance(*pTodoChangeInfo.get());
2835 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.id, &todoId);
2836 pTodoChangeInfoImpl->SetTodoId(todoId);
2838 int calendarbookId = 0;
2839 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2840 pTodoChangeInfoImpl->SetCalendarId(calendarbookId);
2842 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2843 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2844 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2846 switch (modifiedStatus)
2848 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2849 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2851 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2852 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2854 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2855 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2858 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. modified status = %d", modifiedStatus);
2861 pTodoChangeInfoImpl->SetChangeType(recordChangeType);
2864 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.version, &version);
2865 pTodoChangeInfoImpl->SetVersion(version);
2867 return pTodoChangeInfo.release();
2870 template<typename RecordType, typename RecordTypeImpl, typename RecordView>
2872 _CalendarbookImpl::ConvertRecordListN(calendar_list_h resultListHandle, RecordView recordView)
2874 int errorCode = CALENDAR_ERROR_NONE;
2875 result r = E_SUCCESS;
2877 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2878 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2879 r = pList->Construct();
2880 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2883 errorCode = calendar_list_get_count(resultListHandle, &count);
2885 for (int i = 0; i < count; i++)
2887 std::unique_ptr<RecordType> pTmpRecord(RecordTypeImpl::CreateDefaultInstanceN());
2888 SysTryReturn(NID_SCL, pTmpRecord != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2890 r = pList->Add(*pTmpRecord.release());
2891 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2894 errorCode = calendar_list_first(resultListHandle);
2895 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2896 while (pEnum->MoveNext() == E_SUCCESS)
2898 RecordType* pTmpRecord = static_cast<RecordType*>(pEnum->GetCurrent());
2900 calendar_record_h tmpRecordHandle = null;
2901 errorCode = calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2902 RecordTypeImpl::GetInstance(*pTmpRecord)->SetRecordHandle(tmpRecordHandle);
2905 errorCode = calendar_record_get_int(tmpRecordHandle, recordView.id, &dbIndex);
2906 _RecordImpl::GetInstance(*pTmpRecord)->SetRecordId(dbIndex);
2908 errorCode = calendar_list_next(resultListHandle);
2911 return pList.release();
2915 _CalendarbookImpl::ConvertEventInstanceListN(calendar_list_h resultListHandle, bool isAllDay)
2917 int errorCode = CALENDAR_ERROR_NONE;
2918 result r = E_SUCCESS;
2920 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2921 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2922 r = pList->Construct();
2923 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2926 errorCode = calendar_list_get_count(resultListHandle, &count);
2927 errorCode = calendar_list_first(resultListHandle);
2928 for (int i = 0; i < count; i++)
2930 calendar_record_h tmpRecordHandle = null;
2931 errorCode = calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2933 std::unique_ptr<CalEventInstance> pTmpEventInstance;
2937 pTmpEventInstance.reset(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2938 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2942 pTmpEventInstance.reset(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2943 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2946 r = pList->Add(*pTmpEventInstance.release());
2947 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2949 errorCode = calendar_list_next(resultListHandle);
2952 return pList.release();
2956 _CalendarbookImpl::OnCalEventChanged(void)
2958 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
2963 _CalendarConnector connector;
2964 result r = connector.GetResult();
2965 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2967 std::unique_ptr<IList, AllElementsDeleter> pChangedEventList(GetChangedEventsAfterN(__dbVersionForEvent, __dbVersionForEvent));
2968 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Propagating.");
2969 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2971 if (pChangedEventList->GetCount() > 0)
2973 if (__pICalendarbookEventListener != null)
2975 __pICalendarbookEventListener->OnCalendarEventsChanged(*pChangedEventList.get());
2979 RecordEventType recordEventType = RECORD_ADDED;
2980 IEnumerator* pEnum = pChangedEventList->GetEnumeratorN();
2981 CalEvent* pEvent = null;
2983 while (pEnum->MoveNext() == E_SUCCESS)
2985 CalEventChangeInfo* pEventChagneInfo = static_cast<CalEventChangeInfo*>(pEnum->GetCurrent());
2987 if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2989 recordEventType = RECORD_ADDED;
2990 pEvent = GetEventN(pEventChagneInfo->GetEventId());
2993 if (GetLastResult() == E_OBJ_NOT_FOUND)
3003 else if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3005 recordEventType = RECORD_UPDATED;
3006 pEvent = GetEventN(pEventChagneInfo->GetEventId());
3009 if (GetLastResult() == E_OBJ_NOT_FOUND)
3021 recordEventType = RECORD_REMOVED;
3022 pEvent = new (std::nothrow) CalEvent();
3025 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3029 _RecordImpl::GetInstance(*pEvent)->SetRecordId(pEventChagneInfo->GetEventId());
3032 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_EVENT, *pEvent, null, null);
3043 _CalendarbookImpl::OnCalTodoChanged(void)
3045 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
3050 _CalendarConnector connector;
3051 result r = connector.GetResult();
3052 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3054 std::unique_ptr<IList, AllElementsDeleter> pChangedTodoList(GetChangedTodosAfterN(__dbVersionForTodo, __dbVersionForTodo));
3055 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Propagating.");
3056 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3058 if (pChangedTodoList->GetCount() > 0)
3060 if (__pICalendarbookEventListener != null)
3062 __pICalendarbookEventListener->OnCalendarTodosChanged(*pChangedTodoList.get());
3066 RecordEventType recordEventType = RECORD_ADDED;
3067 IEnumerator* pEnum = pChangedTodoList->GetEnumeratorN();
3068 CalTodo* pTodo = null;
3070 while (pEnum->MoveNext() == E_SUCCESS)
3072 CalTodoChangeInfo* pTodoChagneInfo = static_cast<CalTodoChangeInfo*>(pEnum->GetCurrent());
3074 if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
3076 recordEventType = RECORD_ADDED;
3077 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3080 if (GetLastResult() == E_OBJ_NOT_FOUND)
3090 else if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3092 recordEventType = RECORD_UPDATED;
3093 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3096 if (GetLastResult() == E_OBJ_NOT_FOUND)
3108 recordEventType = RECORD_REMOVED;
3109 pTodo = new (std::nothrow) CalTodo();
3112 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3116 _RecordImpl::GetInstance(*pTodo)->SetRecordId(pTodoChagneInfo->GetTodoId());
3119 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_TODO, *pTodo, null, null);
3130 _CalendarbookImpl::GetInstance(Calendarbook& calendarbook)
3132 return calendarbook.__pCalendarbookImpl;
3135 const _CalendarbookImpl*
3136 _CalendarbookImpl::GetInstance(const Calendarbook& calendarbook)
3138 return calendarbook.__pCalendarbookImpl;