2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FScl_CalendarbookImpl.cpp
19 * @brief This is the implementation for _CalendarbookImpl class.
21 * This file contains definitions of @e _CalendarbookImpl class.
25 #include <unique_ptr.h>
26 #include <FBaseDateTime.h>
27 #include <FBaseColArrayList.h>
28 #include <FBaseColHashMapT.h>
29 #include <FBaseUtilStringUtil.h>
30 #include <FLclTimeZone.h>
32 #include <FSclCalendarbook.h>
33 #include <FSclCalEvent.h>
34 #include <FSclCalTodo.h>
35 #include <FSclCalendar.h>
36 #include <FSclCalEventInstance.h>
37 #include <FSclCalEventChangeInfo.h>
38 #include <FSclCalTodoChangeInfo.h>
39 #include <FSclIRecordEventListener.h>
40 #include <FSclIRecordListener.h>
41 #include <FSclICalendarbookEventListener.h>
42 #include <FBaseSysLog.h>
43 #include <FBase_StringConverter.h>
44 #include "FScl_CalendarbookImpl.h"
45 #include "FScl_RecordImpl.h"
46 #include "FScl_CalEventImpl.h"
47 #include "FScl_CalTodoImpl.h"
48 #include "FScl_CalendarImpl.h"
49 #include "FScl_CalEventInstanceImpl.h"
50 #include "FScl_CalEventChangeInfoImpl.h"
51 #include "FScl_CalTodoChangeInfoImpl.h"
52 #include "FScl_CalendarbookFilterImpl.h"
53 #include "FScl_CalendarbookUtil.h"
54 #include "FScl_CalendarbookDbMonitor.h"
55 #include "FScl_CalendarbookDbConnector.h"
56 #include "FScl_CalendarbookRecordRetrivalThread.h"
57 #include "FScl_CalendarbookRecordRetrivalEvent.h"
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Utility;
61 using namespace Tizen::Base::Collection;
62 using namespace Tizen::Io;
64 namespace Tizen { namespace Social
67 RequestId _CalendarbookImpl::__requestId = 0;
68 _CalendarbookRecordRetrivalThread* _CalendarbookImpl::__pRecordRetrivalThread = null;
70 static const int _DEFAULT_EVENT_CALENDAR_DB_ID = 1;
71 static const int _DEFAULT_TODO_CALENDAR_DB_ID = 2;
72 static const wchar_t* _RECURRENCE_DELIMITER = L",";
73 static const int _NUMBER_OF_TODO_STATUS = 5;
74 static const int _NUMBER_OF_TODO_PRIORITY = 3;
75 static const int _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION = 2;
77 static const int _INVALID_CALENDARBOOK_DB_ID = -1; // TODO : This value should be checked.
78 static const int _INVALID_EVENT_DB_ID = -1;
83 _CalendarList(calendar_list_h calendarListHandle, bool deleteRecord = true)
84 : __calendarListHandle(calendarListHandle)
85 , __deleteRecord(deleteRecord)
91 if (__calendarListHandle)
93 calendar_list_destroy(__calendarListHandle, __deleteRecord);
97 calendar_list_h GetHandle(void)
99 return __calendarListHandle;
102 calendar_list_h ReleaseHandle(void)
104 calendar_list_h calendarListHandle = __calendarListHandle;
105 __calendarListHandle = null;
106 return calendarListHandle;
110 calendar_list_h __calendarListHandle;
114 class _CalendarFilter
117 _CalendarFilter(calendar_filter_h calendarFilterHandle)
118 : __calendarFilterHandle(calendarFilterHandle)
122 ~_CalendarFilter(void)
124 if (__calendarFilterHandle)
126 calendar_filter_destroy(__calendarFilterHandle);
130 calendar_filter_h GetHandle(void)
132 return __calendarFilterHandle;
135 calendar_filter_h ReleaseHandle(void)
137 calendar_filter_h calendarFilterHandle = __calendarFilterHandle;
138 __calendarFilterHandle = null;
139 return calendarFilterHandle;
142 void ResetHandle(calendar_filter_h calendarFilterHandle)
144 if (__calendarFilterHandle)
146 calendar_filter_destroy(__calendarFilterHandle);
148 __calendarFilterHandle = calendarFilterHandle;
152 calendar_filter_h __calendarFilterHandle;
155 class _CalendarConnector
161 __r = _CalendarbookDbConnector::Connect();
164 ~_CalendarConnector(void)
166 if (__r == E_SUCCESS)
168 _CalendarbookDbConnector::Disconnect();
172 result GetResult(void)
184 _CalendarQuery(calendar_query_h calendarQueryHandle)
185 : __calendarQueryHandle(calendarQueryHandle)
189 ~_CalendarQuery(void)
191 if (__calendarQueryHandle)
193 calendar_query_destroy(__calendarQueryHandle);
197 calendar_query_h GetHandle(void)
199 return __calendarQueryHandle;
202 calendar_query_h ReleaseHandle(void)
204 calendar_query_h calendarQueryHandle = __calendarQueryHandle;
205 __calendarQueryHandle = null;
206 return calendarQueryHandle;
209 void ResetHandle(calendar_query_h calendarQueryHandle)
211 if (__calendarQueryHandle)
213 calendar_query_destroy(__calendarQueryHandle);
215 __calendarQueryHandle = calendarQueryHandle;
219 calendar_query_h __calendarQueryHandle;
222 _CalendarbookImpl::_CalendarbookImpl(void)
223 : __pIRecordEventListener(null)
224 , __pICalendarbookEventListener(null)
225 , __dbVersionForEvent(0)
226 , __dbVersionForTodo(0)
227 , __pCalendarbookDbMonitor(null)
231 _CalendarbookImpl::~_CalendarbookImpl(void)
233 if (__pCalendarbookDbMonitor != null)
235 if (__pIRecordEventListener != null || __pICalendarbookEventListener != null)
237 __pCalendarbookDbMonitor->RemoveListener(*this);
240 __pCalendarbookDbMonitor->Release();
244 _CalendarbookDbConnector::Disconnect();
249 _CalendarbookImpl::Construct(void)
251 result r = _CalendarbookDbConnector::Connect();
252 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
258 _CalendarbookImpl::Construct(IRecordEventListener* pListener)
260 result r = E_SUCCESS;
265 _CalendarbookDbMonitor* pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
266 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
268 if (pListener != null)
270 dbVersion = GetLatestVersion();
271 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
273 r = pCalendarbookDbMonitor->AddListener(*this);
274 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
276 __pIRecordEventListener = pListener;
279 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
281 __dbVersionForEvent = dbVersion;
282 __dbVersionForTodo = dbVersion;
287 pCalendarbookDbMonitor->Release();
293 _CalendarbookImpl::Construct(ICalendarbookEventListener& listener)
295 result r = E_SUCCESS;
296 _CalendarbookDbMonitor* pCalendarbookDbMonitor = null;
301 pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance();
302 SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred.");
304 dbVersion = GetLatestVersion();
305 SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
307 r = pCalendarbookDbMonitor->AddListener(*this);
308 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
310 __pICalendarbookEventListener = &listener;
311 __pCalendarbookDbMonitor = pCalendarbookDbMonitor;
313 __dbVersionForEvent = dbVersion;
314 __dbVersionForTodo = dbVersion;
319 pCalendarbookDbMonitor->Release();
325 _CalendarbookImpl::AddEvent(CalEvent& event)
327 int errorCode = CALENDAR_ERROR_NONE;
330 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
331 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
332 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
333 , "Invalid argument is used. The event is not an entry type instance.");
335 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
337 errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, _DEFAULT_EVENT_CALENDAR_DB_ID);
338 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
339 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
340 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
341 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
343 calendar_record_h tmpEventHandle = null;
344 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
345 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
346 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
352 _CalendarbookImpl::AddEvent(CalEvent& event, RecordId calendarId)
354 int errorCode = CALENDAR_ERROR_NONE;
357 SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
358 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
359 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
360 , "Invalid argument is used. The event is not an entry type instance.");
361 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
362 , "Invalid argument is used. calendarId = %d", calendarId);
363 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
364 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
365 SysTryReturnResult(NID_SCL,(itemType == CALENDAR_ITEM_TYPE_EVENT_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
366 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_TODO_ONLY");
368 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
370 errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, calendarId);
371 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
372 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
373 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
374 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
376 calendar_record_h tmpEventHandle = null;
377 errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle);
378 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
379 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
385 _CalendarbookImpl::AddTodo(CalTodo& todo)
387 int errorCode = CALENDAR_ERROR_NONE;
390 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
391 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
393 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
395 errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, _DEFAULT_TODO_CALENDAR_DB_ID);
396 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
397 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
398 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
399 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
401 calendar_record_h tmpTodoHandle = null;
402 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
403 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
404 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
410 _CalendarbookImpl::AddTodo(CalTodo& todo, RecordId calendarId)
412 int errorCode = CALENDAR_ERROR_NONE;
415 SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
416 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
417 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
418 , "Invalid argument is used. calendarId = %d", calendarId);
419 CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId);
420 SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found.");
421 SysTryReturnResult(NID_SCL, (itemType == CALENDAR_ITEM_TYPE_TODO_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO)
422 , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_EVENT_ONLY");
424 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
426 errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, calendarId);
427 errorCode = calendar_db_insert_record(todoHandle, &dbIndex);
428 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
429 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
430 _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex);
432 calendar_record_h tmpTodoHandle = null;
433 errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle);
434 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
435 _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle);
441 _CalendarbookImpl::AddCalendar(Calendar& calendar)
443 int errorCode = CALENDAR_ERROR_NONE;
446 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
447 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
449 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
451 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
452 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
453 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
454 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
456 calendar_record_h tmpCalendarHandle = null;
457 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
458 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
459 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
465 _CalendarbookImpl::AddCalendar(Calendar& calendar, AccountId accountId)
467 int errorCode = CALENDAR_ERROR_NONE;
470 SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG
471 , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID.");
472 SysTryReturnResult(NID_SCL, accountId >= 0, E_INVALID_ARG, "Invalid argument is used.");
474 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
476 errorCode = calendar_record_set_int(calendarHandle, _calendar_book.account_id, accountId);
478 errorCode = calendar_db_insert_record(calendarHandle, &dbIndex);
479 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient.");
480 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
481 _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex);
483 calendar_record_h tmpCalendarHandle = null;
484 errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle);
485 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
486 _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle);
492 _CalendarbookImpl::RemoveEvent(CalEvent& event)
494 int errorCode = CALENDAR_ERROR_NONE;
496 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
497 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
499 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
501 int baseEventId = _INVALID_EVENT_DB_ID;
502 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
503 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
504 , "Invalid argument is used. The event has the base event id.");
506 errorCode = calendar_db_delete_record(_calendar_event._uri, event.GetRecordId());
507 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
508 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
510 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(event);
511 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
517 _CalendarbookImpl::RemoveEvent(RecordId eventId)
519 int errorCode = CALENDAR_ERROR_NONE;
521 SysTryReturnResult(NID_SCL, eventId != INVALID_RECORD_ID, E_INVALID_ARG
522 , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID.");
524 calendar_record_h eventHandle = null;
526 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
527 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
529 int baseEventId = _INVALID_EVENT_DB_ID;
530 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
532 calendar_record_destroy(eventHandle, true);
534 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
535 , "Invalid argument is used. The event of eventId has the base event id.");
537 errorCode = calendar_db_delete_record(_calendar_event._uri, eventId);
538 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
544 _CalendarbookImpl::RemoveTodo(CalTodo& todo)
546 _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(todo);
548 result r = RemoveTodo(todo.GetRecordId());
549 pRecordImpl->SetRecordId(INVALID_RECORD_ID);
555 _CalendarbookImpl::RemoveTodo(RecordId todoId)
557 int errorCode = CALENDAR_ERROR_NONE;
559 SysTryReturnResult(NID_SCL, todoId != INVALID_RECORD_ID, E_INVALID_ARG
560 , "Invalid argument is used. The specified todoId is INVALID_RECORD_ID.");
562 errorCode = calendar_db_delete_record(_calendar_todo._uri, todoId);
563 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found.");
564 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
570 _CalendarbookImpl::RemoveCalendar(RecordId calendarId)
572 int errorCode = CALENDAR_ERROR_NONE;
574 SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG
575 , "The specified calendarId is INVALID_RECORD_ID.");
576 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_EVENT_CALENDAR_DB_ID
577 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
578 SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_TODO_CALENDAR_DB_ID
579 , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar.");
580 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendarId), E_OBJ_NOT_FOUND, "The specified record is not found.");
582 errorCode = calendar_db_delete_record(_calendar_book._uri, calendarId);
583 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
589 _CalendarbookImpl::UpdateEvent(const CalEvent& event)
591 int errorCode = CALENDAR_ERROR_NONE;
593 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
594 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
595 SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG
596 , "Invalid argument is used. The event is not an entry type instance.");
598 calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle();
600 int baseEventId = _INVALID_EVENT_DB_ID;
601 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
602 SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION
603 , "Invalid argument is used. The event has the base event id.");
605 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
607 errorCode = calendar_db_update_record(eventHandle);
608 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
609 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
615 _CalendarbookImpl::UpdateTodo(const CalTodo& todo)
617 int errorCode = CALENDAR_ERROR_NONE;
619 SysTryReturnResult(NID_SCL, todo.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
620 , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
621 SysTryReturnResult(NID_SCL, CheckTodoExistance(todo.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
623 calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle();
624 errorCode = calendar_db_update_record(todoHandle);
625 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
631 _CalendarbookImpl::UpdateCalendar(const Calendar& calendar)
633 int errorCode = CALENDAR_ERROR_NONE;
635 SysTryReturnResult(NID_SCL, calendar.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
636 , "The specified recordId is INVALID_RECORD_ID.");
637 SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendar.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found.");
639 calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle();
640 errorCode = calendar_db_update_record(calendarHandle);
641 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
647 _CalendarbookImpl::GetEventN(RecordId eventId) const
649 int errorCode = CALENDAR_ERROR_NONE;
650 calendar_record_h eventHandle = null;
654 SysTryReturn(NID_SCL, eventId != INVALID_RECORD_ID, null, E_INVALID_ARG
655 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
657 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
658 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
660 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
661 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
662 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
664 _CalEventImpl::GetInstance(*pEvent.get())->SetRecordHandle(eventHandle);
665 _RecordImpl::GetInstance(*pEvent.get())->SetRecordId(eventId);
667 return pEvent.release();
671 _CalendarbookImpl::GetTodoN(RecordId todoId) const
673 int errorCode = CALENDAR_ERROR_NONE;
674 calendar_record_h todoHandle = null;
678 SysTryReturn(NID_SCL, todoId != INVALID_RECORD_ID, null, E_INVALID_ARG
679 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
681 std::unique_ptr<CalTodo> pTodo(new (std::nothrow) CalTodo());
682 SysTryReturn(NID_SCL, pTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
684 errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
686 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
687 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
689 _CalTodoImpl::GetInstance(*pTodo.get())->SetRecordHandle(todoHandle);
690 _RecordImpl::GetInstance(*pTodo.get())->SetRecordId(todoId);
692 return pTodo.release();
696 _CalendarbookImpl::GetCalendarN(RecordId calendarId) const
698 int errorCode = CALENDAR_ERROR_NONE;
699 calendar_record_h calendarHandle = null;
703 SysTryReturn(NID_SCL, calendarId != INVALID_RECORD_ID, null, E_INVALID_ARG
704 , "[E_INVALID_ARG] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.");
706 std::unique_ptr<Calendar> pCalendar(new (std::nothrow) Calendar(CALENDAR_ITEM_TYPE_EVENT_AND_TODO));
707 SysTryReturn(NID_SCL, pCalendar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
709 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
710 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
711 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The specified record is not found.");
713 _CalendarImpl::GetInstance(*pCalendar.get())->SetRecordHandle(calendarHandle);
714 _RecordImpl::GetInstance(*pCalendar.get())->SetRecordId(calendarId);
716 return pCalendar.release();
720 _CalendarbookImpl::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status,
721 unsigned long priority) const
723 int errorCode = CALENDAR_ERROR_NONE;
727 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.");
728 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.");
729 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
730 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
731 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %ld", status);
732 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %ld", priority);
736 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
737 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
738 calendar_time_s convertedStartTime;
739 calendar_time_s convertedEndTime;
740 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
741 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
743 calendar_filter_h mainFilterHandle = null;
744 errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
745 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
746 _CalendarFilter mainFilter(mainFilterHandle);
748 // Condition : Due time of the item >= start time of filter
749 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
751 // Condition : Due time of the item <= end time of filter
752 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
753 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
755 // Condition : status
756 calendar_filter_h subFilterHandle = null;
757 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
758 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
759 _CalendarFilter subFilter(subFilterHandle);
760 subFilterHandle = null;
762 int tmpStatus = TODO_STATUS_NONE;
763 bool alreadyAdded = false;
764 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
766 if (status & tmpStatus)
770 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
773 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
781 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
782 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
784 // Condition : priority
785 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
786 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
787 subFilter.ResetHandle(subFilterHandle);
788 subFilterHandle = null;
790 int tmpPriority = TODO_PRIORITY_LOW;
791 alreadyAdded = false;
792 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
794 if (priority & tmpPriority)
798 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
801 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
808 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
809 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
812 calendar_query_h queryHandle = null;
813 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
814 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
815 _CalendarQuery query(queryHandle);
817 errorCode = calendar_query_set_sort(queryHandle, _calendar_todo.due_time, true);
818 errorCode = calendar_query_set_filter(queryHandle, mainFilterHandle);
820 calendar_list_h calendarListHandle = null;
821 errorCode = calendar_db_get_records_with_query(queryHandle, (pageNo - 1) * countPerPage, countPerPage, &calendarListHandle);
822 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
823 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
824 _CalendarList calendarList(calendarListHandle);
826 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
827 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
828 result r = pList->Construct();
829 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
832 errorCode = calendar_list_get_count(calendarListHandle, &count);
834 for (int i = 0; i < count; i++)
836 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
837 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
839 r = pList->Add(*pTmpTodo.release());
840 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
843 errorCode = calendar_list_first(calendarListHandle);
844 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
845 while (pEnum->MoveNext() == E_SUCCESS)
847 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
849 calendar_record_h tmpRecordHandle = null;
850 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
852 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
855 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
856 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
858 errorCode = calendar_list_next(calendarListHandle);
861 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
863 return pList.release();
867 _CalendarbookImpl::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const
869 int errorCode = CALENDAR_ERROR_NONE;
873 SysTryReturn(NID_SCL, start <= end, _INVALID_COUNT
874 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The start time is later than the end date.");
875 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), _INVALID_COUNT
876 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
877 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), _INVALID_COUNT
878 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
879 SysTryReturn(NID_SCL, CheckValidTodoStatus(status), _INVALID_COUNT
880 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %ld", status);
881 SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), _INVALID_COUNT
882 , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %ld", priority);
886 tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay());
887 tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59);
888 calendar_time_s convertedStartTime;
889 calendar_time_s convertedEndTime;
890 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime);
891 _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime);
893 calendar_filter_h mainFilterHandle = null;
894 errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle);
895 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
896 _CalendarFilter mainFilter(mainFilterHandle);
898 // Condition : Due time of the item => start time of filter
899 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime);
901 // Condition : Due time of the item <= end time of filter
902 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
903 errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime);
905 // Condition : status
906 calendar_filter_h subFilterHandle = null;
907 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
908 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
909 _CalendarFilter subFilter(subFilterHandle);
910 subFilterHandle = null;
912 int tmpStatus = TODO_STATUS_NONE;
913 bool alreadyAdded = false;
914 for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++)
916 if (status & tmpStatus)
920 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
923 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus));
930 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
931 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
933 // Condition : priority
934 errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle);
935 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
936 subFilter.ResetHandle(subFilterHandle);
937 subFilterHandle = null;
939 int tmpPriority = TODO_PRIORITY_LOW;
940 alreadyAdded = false;
941 for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++)
943 if (priority & tmpPriority)
947 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR);
950 errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority));
957 errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
958 errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle());
961 calendar_query_h queryHandle = null;
962 errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle);
963 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
964 _CalendarQuery query(queryHandle);
966 errorCode = calendar_query_set_filter(queryHandle, mainFilterHandle);
968 int count = _INVALID_COUNT;
970 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
971 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
977 _CalendarbookImpl::GetEventInstancesN(const DateTime& start, const DateTime& end,
978 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage,
979 unsigned long category) const
981 result r = E_SUCCESS;
985 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.");
986 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.");
987 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
988 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
989 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);
991 std::unique_ptr<IList, AllElementsDeleter> pList(GetEventInstancesCommonN(start, end, timeZone, pageNo, countPerPage, category));
993 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
995 return pList.release();
999 _CalendarbookImpl::GetEventInstances(const DateTime& start, const DateTime& end,
1000 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category,
1001 RequestId& reqId, const IRecordListener& listener) const
1004 reqId = __requestId;
1006 result r = E_SUCCESS;
1008 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.");
1009 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.");
1010 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. start = %S", start.ToString().GetPointer());
1011 SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. end = %S", end.ToString().GetPointer());
1012 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);
1014 std::unique_ptr<_CalendarbookRecordRetrivalEvent> pEvent(new (std::nothrow) _CalendarbookRecordRetrivalEvent());
1015 SysTryReturnResult(NID_SCL, pEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1016 r = pEvent->Construct();
1017 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1018 r = pEvent->AddListener(listener);
1019 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1021 if (__pRecordRetrivalThread != null)
1023 __pRecordRetrivalThread->Join();
1024 delete __pRecordRetrivalThread;
1025 __pRecordRetrivalThread = null;
1028 std::unique_ptr<_CalendarbookRecordRetrivalThread> pRecordRetrivalThread(new (std::nothrow) _CalendarbookRecordRetrivalThread());
1029 SysTryReturnResult(NID_SCL, pRecordRetrivalThread != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1030 r = pRecordRetrivalThread->Construct(__requestId, *pEvent.release(), start, end, timeZone, pageNo, countPerPage, category);
1031 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1033 r = pRecordRetrivalThread->Start();
1034 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
1036 __pRecordRetrivalThread = pRecordRetrivalThread.release();
1042 _CalendarbookImpl::GetAllEventsN(void) const
1044 int errorCode = CALENDAR_ERROR_NONE;
1046 calendar_list_h calendarListHandle = null;
1047 errorCode = calendar_db_get_all_records(_calendar_event._uri, 0, 0, &calendarListHandle);
1048 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1049 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1050 _CalendarList calendarList(calendarListHandle);
1052 result r = E_SUCCESS;
1053 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1054 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1055 r = pList->Construct();
1056 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1059 errorCode = calendar_list_get_count(calendarListHandle, &count);
1061 for (int i = 0; i < count; i++)
1063 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1064 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1066 r = pList->Add(*pTmpEvent.release());
1067 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1070 errorCode = calendar_list_first(calendarListHandle);
1071 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1072 while (pEnum->MoveNext() == E_SUCCESS)
1074 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1076 calendar_record_h tmpRecordHandle = null;
1077 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1078 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1081 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &dbIndex);
1082 _RecordImpl::GetInstance(*pTmpEvent)->SetRecordId(dbIndex);
1084 errorCode = calendar_list_next(calendarListHandle);
1087 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1089 return pList.release();
1093 _CalendarbookImpl::GetAllTodosN(void) const
1095 int errorCode = CALENDAR_ERROR_NONE;
1097 calendar_list_h calendarListHandle = null;
1098 errorCode = calendar_db_get_all_records(_calendar_todo._uri, 0, 0, &calendarListHandle);
1099 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1100 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1101 _CalendarList calendarList(calendarListHandle);
1103 result r = E_SUCCESS;
1104 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1105 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1106 r = pList->Construct();
1107 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1110 errorCode = calendar_list_get_count(calendarListHandle, &count);
1112 for (int i = 0; i < count; i++)
1114 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1115 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1117 r = pList->Add(*pTmpTodo.release());
1118 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1121 errorCode = calendar_list_first(calendarListHandle);
1122 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1123 while (pEnum->MoveNext() == E_SUCCESS)
1125 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1127 calendar_record_h tmpRecordHandle = null;
1128 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1129 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1132 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex);
1133 _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex);
1135 errorCode = calendar_list_next(calendarListHandle);
1138 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1140 return pList.release();
1144 _CalendarbookImpl::GetAllCalendarsN(void) const
1146 int errorCode = CALENDAR_ERROR_NONE;
1148 calendar_list_h calendarListHandle = null;
1149 errorCode = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &calendarListHandle);
1150 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1151 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1152 _CalendarList calendarList(calendarListHandle);
1154 result r = E_SUCCESS;
1155 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1156 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1157 r = pList->Construct();
1158 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1161 errorCode = calendar_list_get_count(calendarListHandle, &count);
1163 for (int i = 0; i < count; i++)
1165 std::unique_ptr<Calendar> pTmpCalendar(_CalendarImpl::CreateDefaultInstanceN());
1166 SysTryReturn(NID_SCL, pTmpCalendar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1168 r = pList->Add(*pTmpCalendar.release());
1169 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1172 errorCode = calendar_list_first(calendarListHandle);
1173 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1174 while (pEnum->MoveNext() == E_SUCCESS)
1176 Calendar* pTmpCalendar = static_cast<Calendar*>(pEnum->GetCurrent());
1178 calendar_record_h tmpRecordHandle = null;
1179 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1180 _CalendarImpl::GetInstance(*pTmpCalendar)->SetRecordHandle(tmpRecordHandle);
1183 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_book.id, &dbIndex);
1184 _RecordImpl::GetInstance(*pTmpCalendar)->SetRecordId(dbIndex);
1186 errorCode = calendar_list_next(calendarListHandle);
1189 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1191 return pList.release();
1195 _CalendarbookImpl::GetChangedEventsAfterN(int version, int& latestVersion) const
1197 int errorCode = CALENDAR_ERROR_NONE;
1201 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1203 calendar_list_h calendarListHandle = null;
1204 int tmpLatestVersion = 0;
1205 errorCode = calendar_db_get_changes_by_version(_calendar_event._uri, CALENDAR_BOOK_FILTER_ALL, version
1206 , &calendarListHandle, &tmpLatestVersion);
1207 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1208 , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1209 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1211 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1212 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1213 result r = pList->Construct();
1214 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1217 errorCode = calendar_list_get_count(calendarListHandle, &count);
1219 errorCode = calendar_list_first(calendarListHandle);
1220 for (int i = 0; i < count; i++)
1222 calendar_record_h tmpRecordHandle = null;
1223 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1225 std::unique_ptr<CalEventChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(tmpRecordHandle));
1226 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1228 r = pList->Add(*pChangedInfo.release());
1229 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1231 errorCode = calendar_list_next(calendarListHandle);
1234 latestVersion = tmpLatestVersion;
1236 return pList.release();
1240 _CalendarbookImpl::GetChangedTodosAfterN(int version, int& latestVersion) const
1242 int errorCode = CALENDAR_ERROR_NONE;
1246 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version);
1248 calendar_list_h calendarListHandle = null;
1249 int tmpLatestVersion = 0;
1250 errorCode = calendar_db_get_changes_by_version(_calendar_todo._uri, CALENDAR_BOOK_FILTER_ALL, version
1251 , &calendarListHandle, &tmpLatestVersion);
1252 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null
1253 , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1254 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1255 _CalendarList calendarList(calendarListHandle);
1257 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1258 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1259 result r = pList->Construct();
1260 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1263 errorCode = calendar_list_get_count(calendarListHandle, &count);
1265 errorCode = calendar_list_first(calendarListHandle);
1266 for (int i = 0; i < count; i++)
1268 calendar_record_h tmpRecordHandle = null;
1269 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1271 std::unique_ptr<CalTodoChangeInfo> pChangedInfo(_CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(tmpRecordHandle));
1272 SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1274 r = pList->Add(*pChangedInfo.release());
1275 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1277 errorCode = calendar_list_next(calendarListHandle);
1280 latestVersion = tmpLatestVersion;
1282 return pList.release();
1286 _CalendarbookImpl::RemoveEventInstance(const CalEventInstance& eventInstance)
1288 result r = E_SUCCESS;
1289 int errorCode = CALENDAR_ERROR_NONE;
1291 calendar_record_h eventHandle = null;
1292 char* pExdate = null;
1294 // Get event handle from DB
1295 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &eventHandle);
1296 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1297 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found.");
1298 _CalendarRecord eventRecord(eventHandle);
1300 int baseEventId = _INVALID_EVENT_DB_ID;
1301 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1303 if (baseEventId != _INVALID_EVENT_DB_ID)
1305 errorCode = calendar_db_delete_record(_calendar_event._uri, eventInstance.GetOriginalEventId());
1306 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1311 errorCode = calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExdate);
1314 if (pExdate != null && strlen(pExdate) > 0)
1316 exdate.Append(pExdate);
1317 r = exdate.Append(_RECURRENCE_DELIMITER);
1320 r = exdate.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent()));
1322 std::unique_ptr<char[]> pAppendedExdate(_StringConverter::CopyToCharArrayN(exdate));
1323 SysTryReturnResult(NID_SCL, pAppendedExdate != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1325 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, pAppendedExdate.get());
1327 // Update event handle
1328 errorCode = calendar_db_update_record(eventHandle);
1329 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1336 _CalendarbookImpl::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event)
1338 result r = E_SUCCESS;
1339 int errorCode = CALENDAR_ERROR_NONE;
1341 SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG
1342 , "Invalid argument is used. The event's recordId is INVALID_RECORD_ID.");
1343 SysTryReturnResult(NID_SCL, eventInstance.GetOriginalEventId() == event.GetRecordId(), E_INVALID_ARG
1344 , "Invalid argument is used. The event's recordId is not equal to eventInstance's original event ID.");
1345 SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified event is not found.");
1347 calendar_record_h eventHandle = null;
1348 errorCode = calendar_record_clone(_CalEventImpl::GetInstance(event)->GetRecordHandle(), &eventHandle);
1349 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1350 _CalendarRecord eventRecord(eventHandle);
1352 int baseEventId = _INVALID_EVENT_DB_ID;
1353 errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId);
1355 calendar_record_h baseEventHandle = null;
1356 if (baseEventId == _INVALID_EVENT_DB_ID)
1358 errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &baseEventHandle);
1362 errorCode = calendar_db_get_record(_calendar_event._uri, baseEventId, &baseEventHandle);
1364 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1365 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The base event is not found.");
1366 _CalendarRecord baseEventRecord(baseEventHandle);
1368 int tmpIntValue = 0;
1369 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.freq, &tmpIntValue);
1370 errorCode = calendar_record_set_int(eventHandle, _calendar_event.freq, tmpIntValue);
1371 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.range_type, &tmpIntValue);
1372 errorCode = calendar_record_set_int(eventHandle, _calendar_event.range_type, tmpIntValue);
1373 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.count, &tmpIntValue);
1374 errorCode = calendar_record_set_int(eventHandle, _calendar_event.count, tmpIntValue);
1375 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.interval, &tmpIntValue);
1376 errorCode = calendar_record_set_int(eventHandle, _calendar_event.interval, tmpIntValue);
1377 errorCode = calendar_record_get_int(baseEventHandle, _calendar_event.wkst, &tmpIntValue);
1378 errorCode = calendar_record_set_int(eventHandle, _calendar_event.wkst, tmpIntValue);
1380 calendar_time_s tmpTimeValue;
1381 errorCode = calendar_record_get_caltime(baseEventHandle, _calendar_event.until_time, &tmpTimeValue);
1382 bool tmpIsAllDay = 0;
1383 calendar_time_s tmpStartTimeValue;
1384 DateTime convertedTime;
1385 errorCode = calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &tmpStartTimeValue);
1387 if (tmpTimeValue.type != tmpStartTimeValue.type)
1389 if (tmpStartTimeValue.type == CALENDAR_TIME_UTIME)
1391 convertedTime.SetValue(tmpTimeValue.time.date.year, tmpTimeValue.time.date.month, tmpTimeValue.time.date.mday);
1392 tmpTimeValue.type = CALENDAR_TIME_UTIME;
1393 tmpTimeValue.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(convertedTime);
1397 convertedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpTimeValue.time.utime);
1398 tmpTimeValue.type = CALENDAR_TIME_LOCALTIME;
1399 tmpTimeValue.time.date.year = convertedTime.GetYear();
1400 tmpTimeValue.time.date.month = convertedTime.GetMonth();
1401 tmpTimeValue.time.date.mday = convertedTime.GetDay();
1404 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.until_time, tmpTimeValue);
1406 char* tmpStrValue = null;
1407 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.byday, &tmpStrValue);
1408 errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, tmpStrValue);
1409 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonthday, &tmpStrValue);
1410 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, tmpStrValue);
1411 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonth, &tmpStrValue);
1412 errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, tmpStrValue);
1413 errorCode = calendar_record_get_str_p(baseEventHandle, _calendar_event.exdate, &tmpStrValue);
1414 errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, tmpStrValue);
1416 if (baseEventId == _INVALID_EVENT_DB_ID)
1418 errorCode = calendar_record_set_int(eventHandle, _calendar_event.original_event_id, eventInstance.GetOriginalEventId());
1420 std::unique_ptr<char[]> pConvertedRecurrenceId(_StringConverter::CopyToCharArrayN(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent())));
1421 errorCode = calendar_record_set_str(eventHandle, _calendar_event.recurrence_id, pConvertedRecurrenceId.get());
1424 errorCode = calendar_db_insert_record(eventHandle, &dbIndex);
1425 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1426 _RecordImpl::GetInstance(event)->SetRecordId(dbIndex);
1430 errorCode = calendar_db_update_record(eventHandle);
1431 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred.");
1432 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The base event of the event is not found.");
1435 calendar_record_h tmpEventHandle = null;
1436 errorCode = calendar_db_get_record(_calendar_event._uri, event.GetRecordId(), &tmpEventHandle);
1437 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1438 _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle);
1444 _CalendarbookImpl::GetLatestVersion(void) const
1446 int errorCode = CALENDAR_ERROR_NONE;
1451 errorCode = calendar_db_get_current_version(&dbVersion);
1452 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, 0, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1458 _CalendarbookImpl::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const
1460 int errorCode = CALENDAR_ERROR_NONE;
1462 bool ascending = false;
1463 unsigned int viewSortPropertyId = 0;
1465 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1466 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1468 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.");
1469 SysTryReturn(NID_SCL, propertySortedBy == 0 || _CalendarbookFilterImpl::IsValidProperty(type, propertySortedBy), null, E_INVALID_ARG
1470 , "[%s] Invalid argument is used. propertySortedBy = %d", GetErrorMessage(E_INVALID_ARG), propertySortedBy);
1472 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1475 calendar_query_h queryHandle = null;
1476 errorCode = calendar_query_create(pViewUri, &queryHandle);
1477 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1478 _CalendarQuery query(queryHandle);
1480 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1482 viewSortPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1483 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1485 errorCode = calendar_query_set_sort(queryHandle, viewSortPropertyId, ascending);
1490 errorCode = calendar_query_set_filter(queryHandle, filterHandle);
1493 calendar_list_h resultListHandle = null;
1494 errorCode = calendar_db_get_records_with_query(queryHandle, offset, maxCount, &resultListHandle);
1495 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1496 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1497 _CalendarList calendarList(resultListHandle);
1499 std::unique_ptr<IList, AllElementsDeleter> pList;
1503 case CB_FI_TYPE_EVENT:
1505 pList.reset(ConvertRecordListN<CalEvent, _CalEventImpl, _calendar_event_property_ids>(resultListHandle, _calendar_event));
1506 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1507 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1510 case CB_FI_TYPE_TODO:
1512 pList.reset(ConvertRecordListN<CalTodo, _CalTodoImpl, _calendar_todo_property_ids>(resultListHandle, _calendar_todo));
1513 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1514 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1517 case CB_FI_TYPE_CALENDAR:
1519 pList.reset(ConvertRecordListN<Calendar, _CalendarImpl, _calendar_book_property_ids>(resultListHandle, _calendar_book));
1520 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1521 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1524 case CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE:
1526 pList.reset(ConvertEventInstanceListN(resultListHandle, true));
1527 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1530 case CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE:
1532 pList.reset(ConvertEventInstanceListN(resultListHandle, false));
1533 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1537 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of filter is (%d)", GetErrorMessage(E_INVALID_ARG), type);
1541 return pList.release();
1545 _CalendarbookImpl::GetMatchedItemCount(const CalendarbookFilter& filter) const
1547 int errorCode = CALENDAR_ERROR_NONE;
1549 CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType();
1550 calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1552 const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type);
1555 calendar_query_h queryHandle = null;
1556 errorCode = calendar_query_create(pViewUri, &queryHandle);
1557 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1558 _CalendarQuery query(queryHandle);
1562 errorCode = calendar_query_set_filter(queryHandle, filterHandle);
1565 int count = _INVALID_COUNT;
1567 errorCode = calendar_db_get_count_with_query(queryHandle, &count);
1568 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1574 _CalendarbookImpl::ParseEventsFromVcalendarN(const String& vCalFilePath)
1576 result r = E_SUCCESS;
1577 int errorCode = CALENDAR_ERROR_NONE;
1582 r = vCalFile.Construct(vCalFilePath, L"r");
1583 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1584 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1585 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1587 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1588 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1589 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1591 int fileLength = vCalFile.Tell();
1592 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is empty.");
1594 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1595 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1596 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1598 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1599 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1600 r = pBuffer->Construct(fileLength);
1601 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1603 r = vCalFile.Read(*pBuffer);
1604 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1605 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1607 _CalendarConnector connector;
1608 r = connector.GetResult();
1609 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1612 calendar_list_h calendarListHandle = null;
1613 errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1614 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1615 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is invalid.");
1616 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1617 _CalendarList calendarList(calendarListHandle);
1619 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1620 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1621 r = pList->Construct();
1622 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1625 errorCode = calendar_list_get_count(calendarListHandle, &count);
1627 errorCode = calendar_list_first(calendarListHandle);
1628 for (int i = 0; i < count; i++)
1630 calendar_record_h tmpRecordHandle = null;
1631 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1632 errorCode = calendar_list_next(calendarListHandle);
1635 errorCode = calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1637 if (strcmp(pUri, _calendar_event._uri) == 0)
1639 std::unique_ptr<CalEvent> pTmpEvent(new (std::nothrow) CalEvent());
1640 SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1642 r = pList->Add(*pTmpEvent.release());
1643 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1647 errorCode = calendar_list_remove(calendarListHandle, tmpRecordHandle);
1648 errorCode = calendar_record_destroy(tmpRecordHandle, true);
1652 errorCode = calendar_list_first(calendarListHandle);
1653 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1654 while (pEnum->MoveNext() == E_SUCCESS)
1656 CalEvent* pTmpEvent = static_cast<CalEvent*>(pEnum->GetCurrent());
1658 calendar_record_h tmpRecordHandle = null;
1659 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1660 _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle);
1662 errorCode = calendar_list_next(calendarListHandle);
1665 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1667 return pList.release();
1671 _CalendarbookImpl::ParseTodosFromVcalendarN(const String& vCalFilePath)
1673 result r = E_SUCCESS;
1674 int errorCode = CALENDAR_ERROR_NONE;
1679 r = vCalFile.Construct(vCalFilePath, L"r");
1680 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY
1681 , null, r, "[%s] Propagating.", GetErrorMessage(r));
1682 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1684 r = vCalFile.Seek(FILESEEKPOSITION_END, 0);
1685 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1686 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1688 int fileLength = vCalFile.Tell();
1689 SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is empty.");
1691 r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0);
1692 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1693 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1695 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
1696 SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1697 r = pBuffer->Construct(fileLength);
1698 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1700 r = vCalFile.Read(*pBuffer);
1701 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1702 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1704 _CalendarConnector connector;
1705 r = connector.GetResult();
1706 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1709 calendar_list_h calendarListHandle = null;
1710 errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast<char*>(const_cast<byte*>(pBuffer->GetPointer())), &calendarListHandle);
1711 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1712 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The vCal file is invalid.");
1713 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1714 _CalendarList calendarList(calendarListHandle);
1716 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1717 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1718 r = pList->Construct();
1719 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1722 errorCode = calendar_list_get_count(calendarListHandle, &count);
1724 errorCode = calendar_list_first(calendarListHandle);
1725 for (int i = 0; i < count; i++)
1727 calendar_record_h tmpRecordHandle = null;
1728 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1729 errorCode = calendar_list_next(calendarListHandle);
1732 errorCode = calendar_record_get_uri_p(tmpRecordHandle, &pUri);
1734 if (strcmp(pUri, _calendar_todo._uri) == 0)
1736 std::unique_ptr<CalTodo> pTmpTodo(new (std::nothrow) CalTodo());
1737 SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1739 r = pList->Add(*pTmpTodo.release());
1740 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1744 errorCode = calendar_list_remove(calendarListHandle, tmpRecordHandle);
1745 errorCode = calendar_record_destroy(tmpRecordHandle, true);
1749 errorCode = calendar_list_first(calendarListHandle);
1750 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
1751 while (pEnum->MoveNext() == E_SUCCESS)
1753 CalTodo* pTmpTodo = static_cast<CalTodo*>(pEnum->GetCurrent());
1755 calendar_record_h tmpRecordHandle = null;
1756 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
1757 _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle);
1759 errorCode = calendar_list_next(calendarListHandle);
1762 errorCode = calendar_list_destroy(calendarList.ReleaseHandle(), false);
1764 return pList.release();
1768 _CalendarbookImpl::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath)
1770 result r = E_SUCCESS;
1771 int errorCode = CALENDAR_ERROR_NONE;
1773 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1774 r = GetLastResult();
1775 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1777 _CalendarConnector connector;
1778 r = connector.GetResult();
1779 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1781 calendar_list_h calendarListHandle = null;
1782 errorCode = calendar_list_create(&calendarListHandle);
1783 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1784 _CalendarList calendarList(calendarListHandle, false);
1786 std::unique_ptr<IEnumerator> pEnum(eventList.GetEnumeratorN());
1787 while (pEnum->MoveNext() == E_SUCCESS)
1789 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1790 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_EVENT, E_INVALID_ARG, "Invalid argument is used. The eventList contains invalid record.");
1792 CalEvent* pTmpEvent = static_cast<CalEvent*>(pTmpRecord);
1793 errorCode = calendar_list_add(calendarListHandle, _CalEventImpl::GetInstance(*pTmpEvent)->GetRecordHandle());
1794 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1797 char* pVCalBuffer = null;
1798 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1799 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1800 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1801 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1804 r = vCalFile.Construct(vCalFilePath, L"w");
1805 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
1806 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1807 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1809 int pVCalBufferLength = strlen(pVCalBuffer);
1810 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1811 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1812 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1818 _CalendarbookImpl::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath)
1820 result r = E_SUCCESS;
1821 int errorCode = CALENDAR_ERROR_NONE;
1823 SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists.");
1824 r = GetLastResult();
1825 SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1827 _CalendarConnector connector;
1828 r = connector.GetResult();
1829 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM]A system error has been occurred.");
1831 calendar_list_h calendarListHandle = null;
1832 errorCode = calendar_list_create(&calendarListHandle);
1833 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1834 _CalendarList calendarList(calendarListHandle, false);
1836 std::unique_ptr<IEnumerator> pEnum(todoList.GetEnumeratorN());
1837 while (pEnum->MoveNext() == E_SUCCESS)
1839 Record* pTmpRecord = static_cast<Record*>(pEnum->GetCurrent());
1840 SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_TODO, E_INVALID_ARG, "Invalid argument is used. The todoList contains invalid record.");
1842 CalTodo* pTmpTodo = static_cast<CalTodo*>(pTmpRecord);
1843 errorCode = calendar_list_add(calendarListHandle, _CalTodoImpl::GetInstance(*pTmpTodo)->GetRecordHandle());
1844 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed.");
1847 char* pVCalBuffer = null;
1848 errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer);
1849 SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
1850 SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
1851 std::unique_ptr<char[]> pVCal(pVCalBuffer);
1854 r = vCalFile.Construct(vCalFilePath, L"w");
1855 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
1856 , r, r, "[%s] Propagating.", GetErrorMessage(r));
1857 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1859 int pVCalBufferLength = strlen(pVCalBuffer);
1860 r = vCalFile.Write(static_cast<void*>(pVCalBuffer), pVCalBufferLength);
1861 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r));
1862 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1868 _CalendarbookImpl::GetMaxDateTime(void)
1870 DateTime maxDateTime;
1871 maxDateTime.SetValue(2100, 12, 31, 23, 59, 59);
1877 _CalendarbookImpl::GetMinDateTime(void)
1879 DateTime minDateTime;
1880 minDateTime.SetValue(1900, 1, 1, 0, 0, 0);
1886 _CalendarbookImpl::GetEventInstancesCommonN(const DateTime& start, const DateTime& end,
1887 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category) const
1891 calendar_time_s convertedStartTime;
1892 calendar_time_s convertedEndTime;
1893 _CalendarbookUtil::ConvertDateTimeToCalTime(start, convertedStartTime);
1894 _CalendarbookUtil::ConvertDateTimeToCalTime(end, convertedEndTime);
1896 Tizen::Locales::TimeZone tmpTimeZone(timeZone);
1897 DateTime localStartTime = tmpTimeZone.UtcTimeToWallTime(start);
1898 DateTime localEndTime = tmpTimeZone.UtcTimeToWallTime(end);
1900 calendar_time_s convertedLocalStartTime;
1901 calendar_time_s convertedLocalEndTime;
1902 _CalendarbookUtil::ConvertDateToCalTime(localStartTime, convertedLocalStartTime);
1903 _CalendarbookUtil::ConvertDateToCalTime(localEndTime, convertedLocalEndTime);
1905 std::unique_ptr<IList, AllElementsDeleter> pList;
1907 if (category == EVENT_CATEGORY_ALL)
1909 pList.reset(GetEventInstancesOfAllCategoriesN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage));
1913 pList.reset(GetEventInstancesOfCategoryN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage, category));
1916 return pList.release();
1920 _CalendarbookImpl::GetEventInstancesOfAllCategoriesN(const calendar_time_s& startTime, const calendar_time_s& endTime,
1921 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage) const
1923 int errorCode = CALENDAR_ERROR_NONE;
1927 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
1928 errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
1929 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1930 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
1932 // Condition : End time of the item > start time of filter
1933 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
1935 // Condition : Start time of the item < end time of filter
1936 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
1937 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
1940 calendar_query_h allDayEventInstanceQueryHandle = null;
1941 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
1942 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1943 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
1945 errorCode = calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
1946 errorCode = calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
1948 int startIndex = (pageNo - 1) * countPerPage;
1950 calendar_list_h allDayEventInstanceListHandle = null;
1951 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, startIndex, countPerPage, &allDayEventInstanceListHandle);
1952 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1953 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1954 _CalendarList allDayEventList(allDayEventInstanceListHandle);
1956 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1957 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1958 result r = pList->Construct();
1959 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1961 int allDayEventInstanceCount = 0;
1962 errorCode = calendar_db_get_count_with_query(allDayEventInstanceQueryHandle, &allDayEventInstanceCount);
1963 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
1966 errorCode = calendar_list_get_count(allDayEventInstanceListHandle, &count);
1968 int pageCount = allDayEventInstanceCount / countPerPage;
1969 int remainingCount = countPerPage - count;
1971 errorCode = calendar_list_first(allDayEventInstanceListHandle);
1972 for (int i = 0; i < count; i++)
1974 calendar_record_h tmpRecordHandle = null;
1975 errorCode = calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
1977 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
1978 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1980 r = pList->Add(*pTmpEventInstance.release());
1981 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1983 errorCode = calendar_list_next(allDayEventInstanceListHandle);
1986 if (remainingCount > 0)
1988 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
1989 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
1990 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1991 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
1993 calendar_filter_h subFilterHandle = null;
1994 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
1995 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1996 _CalendarFilter subFilter(subFilterHandle);
1997 subFilterHandle = null;
1999 // Condition : End time of the item > start time of filter
2000 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2002 // Condition : Start time of the item < end time of filter
2003 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2004 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2006 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2008 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2009 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2010 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2011 subFilter.ResetHandle(subFilterHandle);
2012 subFilterHandle = null;
2014 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2015 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2016 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2018 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2019 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2022 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2023 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2024 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2025 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2027 errorCode = calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2028 errorCode = calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2030 if (remainingCount == countPerPage)
2032 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (allDayEventInstanceCount % countPerPage);
2039 calendar_list_h nonAllDayEventInstanceListHandle = null;
2040 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, startIndex, remainingCount, &nonAllDayEventInstanceListHandle);
2041 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2042 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2043 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2046 errorCode = calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2047 errorCode = calendar_list_first(nonAllDayEventInstanceListHandle);
2048 for (int i = 0; i < count; i++)
2050 calendar_record_h tmpRecordHandle = null;
2051 errorCode = calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2053 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2054 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2056 r = pList->Add(*pTmpEventInstance.release());
2057 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2059 errorCode = calendar_list_next(nonAllDayEventInstanceListHandle);
2063 return pList.release();
2067 _CalendarbookImpl::GetEventInstancesOfCategoryN(const calendar_time_s& startTime, const calendar_time_s& endTime,
2068 const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage, unsigned long category) const
2070 int errorCode = CALENDAR_ERROR_NONE;
2074 calendar_filter_h allDayEventInstanceMainFilterHandle = null;
2075 errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle);
2076 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2077 _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle);
2079 // Condition : End time of the item > start time of filter
2080 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime);
2082 // Condition : Start time of the item < end time of filter
2083 errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND);
2084 errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime);
2087 calendar_query_h allDayEventInstanceQueryHandle = null;
2088 errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle);
2089 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2090 _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle);
2092 errorCode = calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true);
2093 errorCode = calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle);
2095 // Generate event : category map
2096 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(GenerateEventCategoryMapN());
2097 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2099 int startIndex = (pageNo - 1) * countPerPage;
2101 calendar_list_h allDayEventInstanceListHandle = null;
2102 errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, 0, 0, &allDayEventInstanceListHandle);
2103 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2104 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2105 _CalendarList allDayEventList(allDayEventInstanceListHandle);
2107 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2108 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2109 result r = pList->Construct();
2110 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2112 int remainingCount = countPerPage;
2113 int candidateCount = 0;
2115 errorCode = calendar_list_get_count(allDayEventInstanceListHandle, &count);
2116 errorCode = calendar_list_first(allDayEventInstanceListHandle);
2117 for (int i = 0; i < count && remainingCount > 0; i++)
2119 calendar_record_h tmpRecordHandle = null;
2120 errorCode = calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle);
2122 int tmpCategory = EVENT_CATEGORY_ALL;
2124 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_instance_allday_calendar_book.event_id, &eventId);
2125 pEventCategoryMap->GetValue(eventId, tmpCategory);
2127 if (tmpCategory == category)
2129 if (candidateCount >= startIndex)
2131 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2132 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2134 r = pList->Add(*pTmpEventInstance.release());
2135 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2143 errorCode = calendar_list_next(allDayEventInstanceListHandle);
2146 if (remainingCount > 0)
2148 calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null;
2149 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle);
2150 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2151 _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle);
2153 calendar_filter_h subFilterHandle = null;
2154 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2155 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2156 _CalendarFilter subFilter(subFilterHandle);
2157 subFilterHandle = null;
2159 // Condition : End time of the item > start time of filter
2160 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime);
2162 // Condition : Start time of the item < end time of filter
2163 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2164 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime);
2166 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2168 // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter
2169 errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle);
2170 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2171 subFilter.ResetHandle(subFilterHandle);
2172 subFilterHandle = null;
2174 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime);
2175 errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND);
2176 errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime);
2178 errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR);
2179 errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle());
2182 calendar_query_h nonAllDayEventInstanceQueryHandle = null;
2183 errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle);
2184 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2185 _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle);
2187 errorCode = calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true);
2188 errorCode = calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle);
2190 if (remainingCount == countPerPage)
2192 int pageCount = candidateCount / countPerPage;
2193 startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (candidateCount % countPerPage);
2200 calendar_list_h nonAllDayEventInstanceListHandle = null;
2201 errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, 0, 0, &nonAllDayEventInstanceListHandle);
2202 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2203 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2204 _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle);
2209 errorCode = calendar_list_get_count(nonAllDayEventInstanceListHandle, &count);
2210 errorCode = calendar_list_first(nonAllDayEventInstanceListHandle);
2211 for (int i = 0; i < count && remainingCount > 0; i++)
2213 calendar_record_h tmpRecordHandle = null;
2214 errorCode = calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle);
2216 int tmpCategory = EVENT_CATEGORY_ALL;
2218 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_instance_normal_calendar_book.event_id, &eventId);
2219 pEventCategoryMap->GetValue(eventId, tmpCategory);
2221 if (tmpCategory == category)
2223 if (candidateCount >= startIndex)
2225 std::unique_ptr<CalEvent> pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle));
2226 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2228 r = pList->Add(*pTmpEventInstance.release());
2229 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2237 errorCode = calendar_list_next(nonAllDayEventInstanceListHandle);
2241 return pList.release();
2245 _CalendarbookImpl::GenerateEventCategoryMapN(void) const
2247 result r = E_SUCCESS;
2248 int errorCode = CALENDAR_ERROR_NONE;
2250 unsigned int projectionList[_NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION] = {_calendar_event.id, _calendar_event.categories};
2253 calendar_query_h queryHandle = null;
2254 errorCode = calendar_query_create(_calendar_event._uri, &queryHandle);
2255 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2256 _CalendarQuery query(queryHandle);
2258 errorCode = calendar_query_set_projection(queryHandle, projectionList, _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION);
2259 errorCode = calendar_query_set_sort(queryHandle, _calendar_event.id, true);
2261 calendar_list_h calendarListHandle = null;
2262 errorCode = calendar_db_get_records_with_query(queryHandle, 0, 0, &calendarListHandle);
2263 SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2264 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2265 _CalendarList calendarList(calendarListHandle);
2267 std::unique_ptr< HashMapT<int, int> > pEventCategoryMap(new HashMapT<int, int>());
2268 SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2269 r = pEventCategoryMap->Construct();
2270 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2273 errorCode = calendar_list_get_count(calendarListHandle, &count);
2274 errorCode = calendar_list_first(calendarListHandle);
2275 for (int i = 0; i < count; i++)
2277 calendar_record_h tmpRecordHandle = null;
2278 errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle);
2281 char* pCategories = null;
2283 errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &eventId);
2284 errorCode = calendar_record_get_str_p(tmpRecordHandle, _calendar_event.categories, &pCategories);
2286 int category = _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories);
2288 pEventCategoryMap->Add(eventId, category);
2290 errorCode = calendar_list_next(calendarListHandle);
2293 return pEventCategoryMap.release();
2297 _CalendarbookImpl::GetCalendarItemTypeByCalendarId(RecordId calendarId) const
2299 CalendarItemType calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2301 int errorCode = CALENDAR_ERROR_NONE;
2302 calendar_record_h calendarHandle = null;
2303 int storeType = CALENDAR_BOOK_TYPE_NONE;
2305 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2306 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, CALENDAR_ITEM_TYPE_EVENT_AND_TODO, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2308 errorCode = calendar_record_get_int(calendarHandle, _calendar_book.store_type, &storeType);
2310 if (storeType == (CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO))
2312 calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2314 else if (storeType == CALENDAR_BOOK_TYPE_EVENT)
2316 calendarItemType = CALENDAR_ITEM_TYPE_EVENT_ONLY;
2318 else if (storeType == CALENDAR_BOOK_TYPE_TODO)
2320 calendarItemType = CALENDAR_ITEM_TYPE_TODO_ONLY;
2324 SetLastResult(E_SYSTEM);
2325 SysLogException(NID_SCL, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2326 calendar_record_destroy(calendarHandle, true);
2327 return CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
2330 calendar_record_destroy(calendarHandle, true);
2332 return calendarItemType;
2336 _CalendarbookImpl::CheckEventExistance(RecordId eventId) const
2338 int errorCode = CALENDAR_ERROR_NONE;
2339 calendar_record_h eventHandle = null;
2341 errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle);
2342 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2344 calendar_record_destroy(eventHandle, true);
2350 _CalendarbookImpl::CheckTodoExistance(RecordId todoId) const
2352 int errorCode = CALENDAR_ERROR_NONE;
2353 calendar_record_h todoHandle = null;
2355 errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle);
2356 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2358 calendar_record_destroy(todoHandle, true);
2364 _CalendarbookImpl::CheckCalendarExistance(RecordId calendarId) const
2366 int errorCode = CALENDAR_ERROR_NONE;
2367 calendar_record_h calendarHandle = null;
2369 errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle);
2370 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2372 calendar_record_destroy(calendarHandle, true);
2378 _CalendarbookImpl::CheckValidTodoPriority(unsigned long priority) const
2380 if ((priority & TODO_PRIORITY_LOW) || (priority & TODO_PRIORITY_NORMAL) || (priority & TODO_PRIORITY_HIGH))
2389 _CalendarbookImpl::CheckValidTodoStatus(unsigned long status) const
2391 if ((status & TODO_STATUS_NONE) || (status & TODO_STATUS_NEEDS_ACTION) || (status & TODO_STATUS_COMPLETED)
2392 || (status & TODO_STATUS_IN_PROCESS) || (status & TODO_STATUS_CANCELLED))
2401 _CalendarbookImpl::ConvertTodoStatusToCalendarTodoStatus(unsigned long todoStatus) const
2403 return todoStatus << 8;
2407 _CalendarbookImpl::ConvertTodoPriorityToCalendarTodoPriority(unsigned long todoPriority) const
2409 int calendarTodoPriority = CALENDAR_TODO_PRIORITY_NONE;
2411 if (todoPriority == TODO_PRIORITY_LOW)
2413 calendarTodoPriority = CALENDAR_TODO_PRIORITY_LOW;
2415 else if (todoPriority == TODO_PRIORITY_NORMAL)
2417 calendarTodoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
2419 else if (todoPriority == TODO_PRIORITY_HIGH)
2421 calendarTodoPriority = CALENDAR_TODO_PRIORITY_HIGH;
2424 return calendarTodoPriority;
2428 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2430 int errorCode = CALENDAR_ERROR_NONE;
2431 int originalEventDBId = _INVALID_EVENT_DB_ID;
2432 calendar_record_h eventHandle = null;
2434 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2435 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2437 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2438 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2439 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2441 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2442 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2444 calendar_time_s startCalendarTime;
2445 calendar_time_s endCalendarTime;
2446 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2447 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2448 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2449 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2451 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2452 pEventImpl->SetRecordHandle(eventHandle);
2454 return pEvent.release();
2458 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle)
2460 int errorCode = CALENDAR_ERROR_NONE;
2461 int originalEventDBId = _INVALID_EVENT_DB_ID;
2462 calendar_record_h eventHandle = null;
2464 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2465 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record.");
2467 std::unique_ptr<CalEvent> pEvent(new (std::nothrow) CalEvent());
2468 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2469 _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get());
2471 errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle);
2472 SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2474 calendar_time_s startCalendarTime;
2475 calendar_time_s endCalendarTime;
2476 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2477 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2478 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime);
2479 errorCode = calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime);
2481 pEventImpl->SetOriginalCalEventId(originalEventDBId);
2482 pEventImpl->SetRecordHandle(eventHandle);
2484 return pEvent.release();
2488 _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2490 int errorCode = CALENDAR_ERROR_NONE;
2494 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2495 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2496 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2498 int originalEventDBId = _INVALID_EVENT_DB_ID;
2499 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId);
2500 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2502 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2503 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.calendar_book_id, &calendarDBId);
2504 pEventInstanceImpl->SetCalendarId(calendarDBId);
2506 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2507 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.busy_status, &srcEventBusyStatus);
2508 BusyStatus busyStatus = BUSY_STATUS_FREE;
2509 switch (srcEventBusyStatus)
2511 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2512 busyStatus = BUSY_STATUS_FREE;
2514 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2515 busyStatus = BUSY_STATUS_BUSY;
2517 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2518 busyStatus = BUSY_STATUS_UNAVAILABLE;
2520 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2521 busyStatus = BUSY_STATUS_TENTATIVE;
2524 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busy status = %d", srcEventBusyStatus);
2525 busyStatus = BUSY_STATUS_FREE;
2528 pEventInstanceImpl->SetBusyStatus(busyStatus);
2530 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2531 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_status, &srcEventStatus);
2532 EventStatus eventStatus = EVENT_STATUS_NONE;
2533 switch (srcEventStatus)
2535 case CALENDAR_EVENT_STATUS_NONE:
2536 eventStatus = EVENT_STATUS_NONE;
2538 case CALENDAR_EVENT_STATUS_TENTATIVE:
2539 eventStatus = EVENT_STATUS_TENTATIVE;
2541 case CALENDAR_EVENT_STATUS_CONFIRMED:
2542 eventStatus = EVENT_STATUS_CONFIRMED;
2544 case CALENDAR_EVENT_STATUS_CANCELLED:
2545 eventStatus = EVENT_STATUS_CANCELLED;
2548 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", srcEventStatus);
2549 eventStatus = EVENT_STATUS_NONE;
2551 pEventInstanceImpl->SetStatus(eventStatus);
2553 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2554 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.priority, &srcPriority);
2555 EventPriority priority = EVENT_PRIORITY_NORMAL;
2556 switch (srcPriority)
2558 case CALENDAR_EVENT_PRIORITY_LOW:
2559 priority = EVENT_PRIORITY_LOW;
2561 case CALENDAR_EVENT_PRIORITY_NORMAL:
2562 priority = EVENT_PRIORITY_NORMAL;
2564 case CALENDAR_EVENT_PRIORITY_HIGH:
2565 priority = EVENT_PRIORITY_HIGH;
2568 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", srcPriority);
2569 priority = EVENT_PRIORITY_NORMAL;
2571 pEventInstanceImpl->SetPriority(priority);
2573 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2574 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.sensitivity, &srcSensitivity);
2575 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2576 switch (srcSensitivity)
2578 case CALENDAR_SENSITIVITY_PUBLIC:
2579 sensitivity = SENSITIVITY_PUBLIC;
2581 case CALENDAR_SENSITIVITY_PRIVATE:
2582 sensitivity = SENSITIVITY_PRIVATE;
2584 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2585 sensitivity = SENSITIVITY_CONFIDENTIAL;
2588 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
2589 sensitivity = SENSITIVITY_PUBLIC;
2591 pEventInstanceImpl->SetSensitivity(sensitivity);
2593 calendar_time_s startCalendarTime;
2594 DateTime tmpStartTime;
2595 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime);
2596 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
2597 pEventInstanceImpl->SetStartTime(tmpStartTime);
2599 calendar_time_s endCalendarTime;
2600 DateTime tmpEndTime;
2601 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime);
2602 tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday);
2603 pEventInstanceImpl->SetEndTime(tmpEndTime);
2605 pEventInstanceImpl->SetAllDayEvent(true);
2607 int isRecurring = 0;
2608 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_rrule, &isRecurring);
2609 pEventInstanceImpl->SetRecurring(isRecurring);
2611 int hasReminder = 0;
2612 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_alarm, &hasReminder);
2613 pEventInstanceImpl->SetHasReminder(hasReminder);
2615 char* pSubject = null;
2616 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.summary, &pSubject);
2617 pEventInstanceImpl->SetSubject(pSubject);
2619 char* pDescription = null;
2620 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.description, &pDescription);
2621 pEventInstanceImpl->SetDescription(pDescription);
2623 char* pLocation = null;
2624 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.location, &pLocation);
2625 pEventInstanceImpl->SetLocation(pLocation);
2627 return pEventInstance.release();
2631 _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle)
2633 int errorCode = CALENDAR_ERROR_NONE;
2637 std::unique_ptr<CalEventInstance> pEventInstance(new (std::nothrow) CalEventInstance());
2638 SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2639 _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get());
2641 int originalEventDBId = _INVALID_EVENT_DB_ID;
2642 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId);
2643 pEventInstanceImpl->SetOriginalEventId(originalEventDBId);
2645 int calendarDBId = _INVALID_CALENDARBOOK_DB_ID;
2646 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.calendar_book_id, &calendarDBId);
2647 pEventInstanceImpl->SetCalendarId(calendarDBId);
2649 int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
2650 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.busy_status, &srcEventBusyStatus);
2651 BusyStatus busyStatus = BUSY_STATUS_FREE;
2652 switch (srcEventBusyStatus)
2654 case CALENDAR_EVENT_BUSY_STATUS_FREE:
2655 busyStatus = BUSY_STATUS_FREE;
2657 case CALENDAR_EVENT_BUSY_STATUS_BUSY:
2658 busyStatus = BUSY_STATUS_BUSY;
2660 case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
2661 busyStatus = BUSY_STATUS_UNAVAILABLE;
2663 case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
2664 busyStatus = BUSY_STATUS_TENTATIVE;
2667 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busy status = %d", srcEventBusyStatus);
2668 busyStatus = BUSY_STATUS_FREE;
2671 pEventInstanceImpl->SetBusyStatus(busyStatus);
2673 int srcEventStatus = CALENDAR_EVENT_STATUS_NONE;
2674 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_status, &srcEventStatus);
2676 EventStatus eventStatus = EVENT_STATUS_NONE;
2677 switch (srcEventStatus)
2679 case CALENDAR_EVENT_STATUS_NONE:
2680 eventStatus = EVENT_STATUS_NONE;
2682 case CALENDAR_EVENT_STATUS_TENTATIVE:
2683 eventStatus = EVENT_STATUS_TENTATIVE;
2685 case CALENDAR_EVENT_STATUS_CONFIRMED:
2686 eventStatus = EVENT_STATUS_CONFIRMED;
2688 case CALENDAR_EVENT_STATUS_CANCELLED:
2689 eventStatus = EVENT_STATUS_CANCELLED;
2692 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", srcEventStatus);
2693 eventStatus = EVENT_STATUS_NONE;
2695 pEventInstanceImpl->SetStatus(eventStatus);
2697 int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
2698 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.priority, &srcPriority);
2699 EventPriority priority = EVENT_PRIORITY_NORMAL;
2700 switch (srcPriority)
2702 case CALENDAR_EVENT_PRIORITY_LOW:
2703 priority = EVENT_PRIORITY_LOW;
2705 case CALENDAR_EVENT_PRIORITY_NORMAL:
2706 priority = EVENT_PRIORITY_NORMAL;
2708 case CALENDAR_EVENT_PRIORITY_HIGH:
2709 priority = EVENT_PRIORITY_HIGH;
2712 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", srcPriority);
2713 priority = EVENT_PRIORITY_NORMAL;
2715 pEventInstanceImpl->SetPriority(priority);
2717 int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
2718 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.sensitivity, &srcSensitivity);
2719 RecordSensitivity sensitivity = SENSITIVITY_PUBLIC;
2720 switch (srcSensitivity)
2722 case CALENDAR_SENSITIVITY_PUBLIC:
2723 sensitivity = SENSITIVITY_PUBLIC;
2725 case CALENDAR_SENSITIVITY_PRIVATE:
2726 sensitivity = SENSITIVITY_PRIVATE;
2728 case CALENDAR_SENSITIVITY_CONFIDENTIAL:
2729 sensitivity = SENSITIVITY_CONFIDENTIAL;
2732 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", srcSensitivity);
2733 sensitivity = SENSITIVITY_PUBLIC;
2735 pEventInstanceImpl->SetSensitivity(sensitivity);
2737 calendar_time_s startCalendarTime;
2738 DateTime tmpStartTime;
2739 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime);
2740 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
2741 pEventInstanceImpl->SetStartTime(tmpStartTime);
2743 calendar_time_s endCalendarTime;
2744 DateTime tmpEndTime;
2745 errorCode = calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime);
2746 tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime);
2747 pEventInstanceImpl->SetEndTime(tmpEndTime);
2749 pEventInstanceImpl->SetAllDayEvent(false);
2751 int isRecurring = 0;
2752 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_rrule, &isRecurring);
2753 pEventInstanceImpl->SetRecurring(isRecurring);
2755 int hasReminder = 0;
2756 errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_alarm, &hasReminder);
2757 pEventInstanceImpl->SetHasReminder(hasReminder);
2759 char* pSubject = null;
2760 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.summary, &pSubject);
2761 pEventInstanceImpl->SetSubject(pSubject);
2763 char* pDescription = null;
2764 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.description, &pDescription);
2765 pEventInstanceImpl->SetDescription(pDescription);
2767 char* pLocation = null;
2768 errorCode = calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.location, &pLocation);
2769 pEventInstanceImpl->SetLocation(pLocation);
2771 return pEventInstance.release();
2775 _CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(calendar_record_h modifiedEventHandle)
2777 int errorCode = CALENDAR_ERROR_NONE;
2781 std::unique_ptr<CalEventChangeInfo> pEventChangeInfo(new (std::nothrow) CalEventChangeInfo());
2782 SysTryReturn(NID_SCL, pEventChangeInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2783 _CalEventChangeInfoImpl* pEventChangeInfoImpl = _CalEventChangeInfoImpl::GetInstance(*pEventChangeInfo.get());
2786 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.id, &eventId);
2787 pEventChangeInfoImpl->SetEventId(eventId);
2789 int calendarbookId = 0;
2790 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2791 pEventChangeInfoImpl->SetCalendarId(calendarbookId);
2793 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2794 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2795 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2796 switch (modifiedStatus)
2798 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2799 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2801 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2802 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2804 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2805 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2808 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. modified status = %d", modifiedStatus);
2811 pEventChangeInfoImpl->SetChangeType(recordChangeType);
2814 errorCode = calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.version, &version);
2815 pEventChangeInfoImpl->SetVersion(version);
2817 return pEventChangeInfo.release();
2821 _CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(calendar_record_h modifiedTodoHandle)
2823 int errorCode = CALENDAR_ERROR_NONE;
2827 std::unique_ptr<CalTodoChangeInfo> pTodoChangeInfo(new (std::nothrow) CalTodoChangeInfo());
2828 SysTryReturn(NID_SCL, pTodoChangeInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2829 _CalTodoChangeInfoImpl* pTodoChangeInfoImpl = _CalTodoChangeInfoImpl::GetInstance(*pTodoChangeInfo.get());
2832 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.id, &todoId);
2833 pTodoChangeInfoImpl->SetTodoId(todoId);
2835 int calendarbookId = 0;
2836 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.calendar_book_id, &calendarbookId);
2837 pTodoChangeInfoImpl->SetCalendarId(calendarbookId);
2839 int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
2840 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.modified_status, &modifiedStatus);
2841 RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2843 switch (modifiedStatus)
2845 case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED:
2846 recordChangeType = RECORD_CHANGE_TYPE_ADDED;
2848 case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED:
2849 recordChangeType = RECORD_CHANGE_TYPE_UPDATED;
2851 case CALENDAR_RECORD_MODIFIED_STATUS_DELETED:
2852 recordChangeType = RECORD_CHANGE_TYPE_REMOVED;
2855 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. modified status = %d", modifiedStatus);
2858 pTodoChangeInfoImpl->SetChangeType(recordChangeType);
2861 errorCode = calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.version, &version);
2862 pTodoChangeInfoImpl->SetVersion(version);
2864 return pTodoChangeInfo.release();
2867 template<typename RecordType, typename RecordTypeImpl, typename RecordView>
2869 _CalendarbookImpl::ConvertRecordListN(calendar_list_h resultListHandle, RecordView recordView)
2871 int errorCode = CALENDAR_ERROR_NONE;
2872 result r = E_SUCCESS;
2874 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2875 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2876 r = pList->Construct();
2877 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2880 errorCode = calendar_list_get_count(resultListHandle, &count);
2882 for (int i = 0; i < count; i++)
2884 std::unique_ptr<RecordType> pTmpRecord(RecordTypeImpl::CreateDefaultInstanceN());
2885 SysTryReturn(NID_SCL, pTmpRecord != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2887 r = pList->Add(*pTmpRecord.release());
2888 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2891 errorCode = calendar_list_first(resultListHandle);
2892 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2893 while (pEnum->MoveNext() == E_SUCCESS)
2895 RecordType* pTmpRecord = static_cast<RecordType*>(pEnum->GetCurrent());
2897 calendar_record_h tmpRecordHandle = null;
2898 errorCode = calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2899 RecordTypeImpl::GetInstance(*pTmpRecord)->SetRecordHandle(tmpRecordHandle);
2902 errorCode = calendar_record_get_int(tmpRecordHandle, recordView.id, &dbIndex);
2903 _RecordImpl::GetInstance(*pTmpRecord)->SetRecordId(dbIndex);
2905 errorCode = calendar_list_next(resultListHandle);
2908 return pList.release();
2912 _CalendarbookImpl::ConvertEventInstanceListN(calendar_list_h resultListHandle, bool isAllDay)
2914 int errorCode = CALENDAR_ERROR_NONE;
2915 result r = E_SUCCESS;
2917 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2918 SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2919 r = pList->Construct();
2920 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
2923 errorCode = calendar_list_get_count(resultListHandle, &count);
2924 errorCode = calendar_list_first(resultListHandle);
2925 for (int i = 0; i < count; i++)
2927 calendar_record_h tmpRecordHandle = null;
2928 errorCode = calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle);
2930 std::unique_ptr<CalEventInstance> pTmpEventInstance;
2934 pTmpEventInstance.reset(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2935 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2939 pTmpEventInstance.reset(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle));
2940 SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2943 r = pList->Add(*pTmpEventInstance.release());
2944 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2946 errorCode = calendar_list_next(resultListHandle);
2949 return pList.release();
2953 _CalendarbookImpl::OnCalEventChanged(void)
2955 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
2960 _CalendarConnector connector;
2961 result r = connector.GetResult();
2962 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2964 std::unique_ptr<IList, AllElementsDeleter> pChangedEventList(GetChangedEventsAfterN(__dbVersionForEvent, __dbVersionForEvent));
2965 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Propagating.");
2966 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
2968 if (pChangedEventList->GetCount() > 0)
2970 if (__pICalendarbookEventListener != null)
2972 __pICalendarbookEventListener->OnCalendarEventsChanged(*pChangedEventList.get());
2976 RecordEventType recordEventType = RECORD_ADDED;
2977 IEnumerator* pEnum = pChangedEventList->GetEnumeratorN();
2978 CalEvent* pEvent = null;
2980 while (pEnum->MoveNext() == E_SUCCESS)
2982 CalEventChangeInfo* pEventChagneInfo = static_cast<CalEventChangeInfo*>(pEnum->GetCurrent());
2984 if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2986 recordEventType = RECORD_ADDED;
2987 pEvent = GetEventN(pEventChagneInfo->GetEventId());
2990 if (GetLastResult() == E_OBJ_NOT_FOUND)
3000 else if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3002 recordEventType = RECORD_UPDATED;
3003 pEvent = GetEventN(pEventChagneInfo->GetEventId());
3006 if (GetLastResult() == E_OBJ_NOT_FOUND)
3018 recordEventType = RECORD_REMOVED;
3019 pEvent = new (std::nothrow) CalEvent();
3022 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3026 _RecordImpl::GetInstance(*pEvent)->SetRecordId(pEventChagneInfo->GetEventId());
3029 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_EVENT, *pEvent, null, null);
3040 _CalendarbookImpl::OnCalTodoChanged(void)
3042 if (__pICalendarbookEventListener == null && __pIRecordEventListener == null)
3047 _CalendarConnector connector;
3048 result r = connector.GetResult();
3049 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3051 std::unique_ptr<IList, AllElementsDeleter> pChangedTodoList(GetChangedTodosAfterN(__dbVersionForTodo, __dbVersionForTodo));
3052 SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Propagating.");
3053 SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
3055 if (pChangedTodoList->GetCount() > 0)
3057 if (__pICalendarbookEventListener != null)
3059 __pICalendarbookEventListener->OnCalendarTodosChanged(*pChangedTodoList.get());
3063 RecordEventType recordEventType = RECORD_ADDED;
3064 IEnumerator* pEnum = pChangedTodoList->GetEnumeratorN();
3065 CalTodo* pTodo = null;
3067 while (pEnum->MoveNext() == E_SUCCESS)
3069 CalTodoChangeInfo* pTodoChagneInfo = static_cast<CalTodoChangeInfo*>(pEnum->GetCurrent());
3071 if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
3073 recordEventType = RECORD_ADDED;
3074 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3077 if (GetLastResult() == E_OBJ_NOT_FOUND)
3087 else if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
3089 recordEventType = RECORD_UPDATED;
3090 pTodo = GetTodoN(pTodoChagneInfo->GetTodoId());
3093 if (GetLastResult() == E_OBJ_NOT_FOUND)
3105 recordEventType = RECORD_REMOVED;
3106 pTodo = new (std::nothrow) CalTodo();
3109 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3113 _RecordImpl::GetInstance(*pTodo)->SetRecordId(pTodoChagneInfo->GetTodoId());
3116 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_TODO, *pTodo, null, null);
3127 _CalendarbookImpl::GetInstance(Calendarbook& calendarbook)
3129 return calendarbook.__pCalendarbookImpl;
3132 const _CalendarbookImpl*
3133 _CalendarbookImpl::GetInstance(const Calendarbook& calendarbook)
3135 return calendarbook.__pCalendarbookImpl;