// // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file FScl_CalendarbookImpl.cpp * @brief This is the implementation for _CalendarbookImpl class. * * This file contains definitions of @e _CalendarbookImpl class. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "FScl_CalendarbookImpl.h" #include "FScl_CalendarbookFilterImpl.h" #include "FScl_CalendarbookDbConnector.h" #include "FScl_CalendarbookDbMonitor.h" #include "FScl_CalendarbookRecordRetrivalEvent.h" #include "FScl_CalendarbookRecordRetrivalThread.h" #include "FScl_CalendarbookUtil.h" #include "FScl_CalEventChangeInfoImpl.h" #include "FScl_CalendarImpl.h" #include "FScl_CalEventImpl.h" #include "FScl_CalEventInstanceImpl.h" #include "FScl_CalTodoChangeInfoImpl.h" #include "FScl_CalTodoImpl.h" #include "FScl_RecordImpl.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Base::Utility; using namespace Tizen::Io; namespace Tizen { namespace Social { RequestId _CalendarbookImpl::__requestId = 0; _CalendarbookRecordRetrivalThread* _CalendarbookImpl::__pRecordRetrivalThread = null; static const int _DEFAULT_EVENT_CALENDAR_DB_ID = 1; static const int _DEFAULT_TODO_CALENDAR_DB_ID = 2; static const wchar_t* _RECURRENCE_DELIMITER = L","; static const int _NUMBER_OF_TODO_STATUS = 5; static const int _NUMBER_OF_TODO_PRIORITY = 3; static const int _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION = 2; static const int _INVALID_CALENDARBOOK_DB_ID = -1; // TODO : This value should be checked. static const int _INVALID_EVENT_DB_ID = -1; class _CalendarList { public : _CalendarList(calendar_list_h calendarListHandle, bool deleteRecord = true) : __calendarListHandle(calendarListHandle) , __deleteRecord(deleteRecord) { } ~_CalendarList(void) { if (__calendarListHandle) { calendar_list_destroy(__calendarListHandle, __deleteRecord); } } calendar_list_h GetHandle(void) { return __calendarListHandle; } calendar_list_h ReleaseHandle(void) { calendar_list_h calendarListHandle = __calendarListHandle; __calendarListHandle = null; return calendarListHandle; } private : calendar_list_h __calendarListHandle; bool __deleteRecord; }; class _CalendarFilter { public : _CalendarFilter(calendar_filter_h calendarFilterHandle) : __calendarFilterHandle(calendarFilterHandle) { } ~_CalendarFilter(void) { if (__calendarFilterHandle) { calendar_filter_destroy(__calendarFilterHandle); } } calendar_filter_h GetHandle(void) { return __calendarFilterHandle; } calendar_filter_h ReleaseHandle(void) { calendar_filter_h calendarFilterHandle = __calendarFilterHandle; __calendarFilterHandle = null; return calendarFilterHandle; } void ResetHandle(calendar_filter_h calendarFilterHandle) { if (__calendarFilterHandle) { calendar_filter_destroy(__calendarFilterHandle); } __calendarFilterHandle = calendarFilterHandle; } private : calendar_filter_h __calendarFilterHandle; }; class _CalendarConnector { public : _CalendarConnector() : __r(E_SUCCESS) { __r = _CalendarbookDbConnector::Connect(); } ~_CalendarConnector(void) { if (__r == E_SUCCESS) { _CalendarbookDbConnector::Disconnect(); } } result GetResult(void) { return __r; } private : result __r; }; class _CalendarQuery { public : _CalendarQuery(calendar_query_h calendarQueryHandle) : __calendarQueryHandle(calendarQueryHandle) { } ~_CalendarQuery(void) { if (__calendarQueryHandle) { calendar_query_destroy(__calendarQueryHandle); } } calendar_query_h GetHandle(void) { return __calendarQueryHandle; } calendar_query_h ReleaseHandle(void) { calendar_query_h calendarQueryHandle = __calendarQueryHandle; __calendarQueryHandle = null; return calendarQueryHandle; } void ResetHandle(calendar_query_h calendarQueryHandle) { if (__calendarQueryHandle) { calendar_query_destroy(__calendarQueryHandle); } __calendarQueryHandle = calendarQueryHandle; } private : calendar_query_h __calendarQueryHandle; }; _CalendarbookImpl::_CalendarbookImpl(void) : __pIRecordEventListener(null) , __pICalendarbookEventListener(null) , __dbVersionForEvent(0) , __dbVersionForTodo(0) , __pCalendarbookDbMonitor(null) { } _CalendarbookImpl::~_CalendarbookImpl(void) { if (__pCalendarbookDbMonitor != null) { if (__pIRecordEventListener != null || __pICalendarbookEventListener != null) { __pCalendarbookDbMonitor->RemoveListener(*this); } __pCalendarbookDbMonitor->Release(); } else { _CalendarbookDbConnector::Disconnect(); } } result _CalendarbookImpl::Construct(void) { result r = _CalendarbookDbConnector::Connect(); SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred."); return E_SUCCESS; } result _CalendarbookImpl::Construct(IRecordEventListener* pListener) { result r = E_SUCCESS; int dbVersion = -1; ClearLastResult(); _CalendarbookDbMonitor* pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance(); SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred."); if (pListener != null) { dbVersion = GetLatestVersion(); SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); r = pCalendarbookDbMonitor->AddListener(*this); SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); __pIRecordEventListener = pListener; } __pCalendarbookDbMonitor = pCalendarbookDbMonitor; __dbVersionForEvent = dbVersion; __dbVersionForTodo = dbVersion; return E_SUCCESS; CATCH: pCalendarbookDbMonitor->Release(); return r; } result _CalendarbookImpl::Construct(ICalendarbookEventListener& listener) { ClearLastResult(); _CalendarbookDbMonitor* pCalendarbookDbMonitor = _CalendarbookDbMonitor::GetInstance(); SysTryReturnResult(NID_SCL, pCalendarbookDbMonitor != null, E_SYSTEM, "A system error has been occurred."); result r = E_SUCCESS; int dbVersion = GetLatestVersion(); SysTryCatch(NID_SCL, dbVersion != -1, r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); r = pCalendarbookDbMonitor->AddListener(*this); SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); __pICalendarbookEventListener = &listener; __pCalendarbookDbMonitor = pCalendarbookDbMonitor; __dbVersionForEvent = dbVersion; __dbVersionForTodo = dbVersion; return E_SUCCESS; CATCH: pCalendarbookDbMonitor->Release(); return r; } result _CalendarbookImpl::AddEvent(CalEvent& event) { SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG , "Invalid argument is used. The event is not an entry type instance."); calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle(); int errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, _DEFAULT_EVENT_CALENDAR_DB_ID); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); int dbIndex = -1; errorCode = calendar_db_insert_record(eventHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(event)->SetRecordId(dbIndex); calendar_record_h tmpEventHandle = null; errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle); return E_SUCCESS; } result _CalendarbookImpl::AddEvent(CalEvent& event, RecordId calendarId) { SysTryReturnResult(NID_SCL, event.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG , "Invalid argument is used. The event is not an entry type instance."); SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. calendarId = %d", calendarId); CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId); SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found."); SysTryReturnResult(NID_SCL,(itemType == CALENDAR_ITEM_TYPE_EVENT_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO) , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_TODO_ONLY"); calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle(); int errorCode = calendar_record_set_int(eventHandle, _calendar_event.calendar_book_id, calendarId); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); int dbIndex = -1; errorCode = calendar_db_insert_record(eventHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(event)->SetRecordId(dbIndex); calendar_record_h tmpEventHandle = null; errorCode = calendar_db_get_record(_calendar_event._uri, dbIndex, &tmpEventHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle); return E_SUCCESS; } result _CalendarbookImpl::AddTodo(CalTodo& todo) { SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID."); calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle(); int errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, _DEFAULT_TODO_CALENDAR_DB_ID); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); int dbIndex = -1; errorCode = calendar_db_insert_record(todoHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex); calendar_record_h tmpTodoHandle = null; errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle); return E_SUCCESS; } result _CalendarbookImpl::AddTodo(CalTodo& todo, RecordId calendarId) { SysTryReturnResult(NID_SCL, todo.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. calendarId = %d", calendarId); CalendarItemType itemType = GetCalendarItemTypeByCalendarId(calendarId); SysTryReturnResult(NID_SCL, GetLastResult() == E_SUCCESS, E_OBJ_NOT_FOUND, "The specified calendarId is not found."); SysTryReturnResult(NID_SCL, (itemType == CALENDAR_ITEM_TYPE_TODO_ONLY || itemType == CALENDAR_ITEM_TYPE_EVENT_AND_TODO) , E_INVALID_ARG, "Invalid argument is used. The calendar is created for CALENDAR_ITEM_TYPE_EVENT_ONLY"); calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle(); int errorCode = calendar_record_set_int(todoHandle, _calendar_todo.calendar_book_id, calendarId); int dbIndex = -1; errorCode = calendar_db_insert_record(todoHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(todo)->SetRecordId(dbIndex); calendar_record_h tmpTodoHandle = null; errorCode = calendar_db_get_record(_calendar_todo._uri, dbIndex, &tmpTodoHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalTodoImpl::GetInstance(todo)->SetRecordHandle(tmpTodoHandle); return E_SUCCESS; } result _CalendarbookImpl::AddCalendar(Calendar& calendar) { SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID."); calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle(); int dbIndex = -1; int errorCode = calendar_db_insert_record(calendarHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex); calendar_record_h tmpCalendarHandle = null; errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle); return E_SUCCESS; } result _CalendarbookImpl::AddCalendar(Calendar& calendar, AccountId accountId) { SysTryReturnResult(NID_SCL, calendar.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is not INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, accountId >= 0, E_INVALID_ARG, "Invalid argument is used."); calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle(); int errorCode = calendar_record_set_int(calendarHandle, _calendar_book.account_id, accountId); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); int dbIndex = -1; errorCode = calendar_db_insert_record(calendarHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, "The storage is insufficient."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(calendar)->SetRecordId(dbIndex); calendar_record_h tmpCalendarHandle = null; errorCode = calendar_db_get_record(_calendar_book._uri, dbIndex, &tmpCalendarHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalendarImpl::GetInstance(calendar)->SetRecordHandle(tmpCalendarHandle); return E_SUCCESS; } result _CalendarbookImpl::RemoveEvent(CalEvent& event) { SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID."); calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle(); int baseEventId = _INVALID_EVENT_DB_ID; int errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId); SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION , "Invalid argument is used. The event has the base event id."); errorCode = calendar_db_delete_record(_calendar_event._uri, event.GetRecordId()); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(event); pRecordImpl->SetRecordId(INVALID_RECORD_ID); return E_SUCCESS; } result _CalendarbookImpl::RemoveEvent(RecordId eventId) { SysTryReturnResult(NID_SCL, eventId != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified eventId is INVALID_RECORD_ID."); calendar_record_h eventHandle = null; int errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found."); int baseEventId = _INVALID_EVENT_DB_ID; calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId); calendar_record_destroy(eventHandle, true); SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION , "Invalid argument is used. The event of eventId has the base event id."); errorCode = calendar_db_delete_record(_calendar_event._uri, eventId); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); return E_SUCCESS; } result _CalendarbookImpl::RemoveTodo(CalTodo& todo) { _RecordImpl* pRecordImpl = _RecordImpl::GetInstance(todo); result r = RemoveTodo(todo.GetRecordId()); SysTryReturnResult(NID_SCL, !IsFailed(r), r, "Failed to remove the todo."); pRecordImpl->SetRecordId(INVALID_RECORD_ID); return r; } result _CalendarbookImpl::RemoveTodo(RecordId todoId) { SysTryReturnResult(NID_SCL, todoId != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified todoId is INVALID_RECORD_ID."); int errorCode = calendar_db_delete_record(_calendar_todo._uri, todoId); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_RECORD_NOT_FOUND, E_OBJ_NOT_FOUND, "The specified record is not found."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); return E_SUCCESS; } result _CalendarbookImpl::RemoveCalendar(RecordId calendarId) { SysTryReturnResult(NID_SCL, calendarId != INVALID_RECORD_ID, E_INVALID_ARG , "The specified calendarId is INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_EVENT_CALENDAR_DB_ID , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar."); SysTryReturnResult(NID_SCL, calendarId != _DEFAULT_TODO_CALENDAR_DB_ID , E_INVALID_ARG, "Invalid argument is used. The calendar represents default calendar."); SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendarId), E_OBJ_NOT_FOUND, "The specified record is not found."); int errorCode = calendar_db_delete_record(_calendar_book._uri, calendarId); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); return E_SUCCESS; } result _CalendarbookImpl::UpdateEvent(const CalEvent& event) { SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, !event.IsInstance(), E_INVALID_ARG , "Invalid argument is used. The event is not an entry type instance."); calendar_record_h eventHandle = _CalEventImpl::GetInstance(event)->GetRecordHandle(); int baseEventId = _INVALID_EVENT_DB_ID; int errorCode = calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId); SysTryReturnResult(NID_SCL, baseEventId == _INVALID_EVENT_DB_ID, E_INVALID_OPERATION , "Invalid argument is used. The event has the base event id."); SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found."); errorCode = calendar_db_update_record(eventHandle); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found."); return E_SUCCESS; } result _CalendarbookImpl::UpdateTodo(const CalTodo& todo) { SysTryReturnResult(NID_SCL, todo.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The specified recordId is INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, CheckTodoExistance(todo.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found."); calendar_record_h todoHandle = _CalTodoImpl::GetInstance(todo)->GetRecordHandle(); int errorCode = calendar_db_update_record(todoHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); return E_SUCCESS; } result _CalendarbookImpl::UpdateCalendar(const Calendar& calendar) { SysTryReturnResult(NID_SCL, calendar.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG , "The specified recordId is INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, CheckCalendarExistance(calendar.GetRecordId()), E_OBJ_NOT_FOUND, "The specified record is not found."); calendar_record_h calendarHandle = _CalendarImpl::GetInstance(calendar)->GetRecordHandle(); int errorCode = calendar_db_update_record(calendarHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); return E_SUCCESS; } CalEvent* _CalendarbookImpl::GetEventN(RecordId eventId) const { ClearLastResult(); SysTryReturn(NID_SCL, eventId != INVALID_RECORD_ID, null, E_INVALID_ARG , "[%s] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); std::unique_ptr pEvent(new (std::nothrow) CalEvent()); SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); calendar_record_h eventHandle = null; int errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The specified record is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); _CalEventImpl::GetInstance(*pEvent.get())->SetRecordHandle(eventHandle); _RecordImpl::GetInstance(*pEvent.get())->SetRecordId(eventId); return pEvent.release(); } CalTodo* _CalendarbookImpl::GetTodoN(RecordId todoId) const { ClearLastResult(); SysTryReturn(NID_SCL, todoId != INVALID_RECORD_ID, null, E_INVALID_ARG , "[%s] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); std::unique_ptr pTodo(new (std::nothrow) CalTodo()); SysTryReturn(NID_SCL, pTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); calendar_record_h todoHandle = null; int errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The specified record is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); _CalTodoImpl::GetInstance(*pTodo.get())->SetRecordHandle(todoHandle); _RecordImpl::GetInstance(*pTodo.get())->SetRecordId(todoId); return pTodo.release(); } Calendar* _CalendarbookImpl::GetCalendarN(RecordId calendarId) const { ClearLastResult(); SysTryReturn(NID_SCL, calendarId != INVALID_RECORD_ID, null, E_INVALID_ARG , "[%s] Invalid argument is used. The specified recordId is INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); std::unique_ptr pCalendar(new (std::nothrow) Calendar(CALENDAR_ITEM_TYPE_EVENT_AND_TODO)); SysTryReturn(NID_SCL, pCalendar != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); calendar_record_h calendarHandle = null; int errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The specified record is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); _CalendarImpl::GetInstance(*pCalendar.get())->SetRecordHandle(calendarHandle); _RecordImpl::GetInstance(*pCalendar.get())->SetRecordId(calendarId); return pCalendar.release(); } IList* _CalendarbookImpl::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status, unsigned long priority) const { ClearLastResult(); SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The pageNo or countPerPage is less than 1.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer()); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer()); SysTryReturn(NID_SCL, CheckValidTodoStatus(status), null, E_INVALID_ARG, "[%s] Invalid argument is used. status = %ld", GetErrorMessage(E_INVALID_ARG), status); SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), null, E_INVALID_ARG, "[%s] Invalid argument is used. priority = %ld", GetErrorMessage(E_INVALID_ARG), priority); DateTime tmpStart; DateTime tmpEnd; tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay()); tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59); calendar_time_s convertedStartTime; calendar_time_s convertedEndTime; _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime); _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime); calendar_filter_h mainFilterHandle = null; int errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter mainFilter(mainFilterHandle); // Condition : Due time of the item >= start time of filter errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Due time of the item <= end time of filter errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : status calendar_filter_h subFilterHandle = null; errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter subFilter(subFilterHandle); subFilterHandle = null; int tmpStatus = TODO_STATUS_NONE; bool alreadyAdded = false; for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++) { if (status & tmpStatus) { if (alreadyAdded) { errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); alreadyAdded = true; } tmpStatus <<= 1; } errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : priority errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); subFilter.ResetHandle(subFilterHandle); subFilterHandle = null; int tmpPriority = TODO_PRIORITY_LOW; alreadyAdded = false; for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++) { if (priority & tmpPriority) { if (alreadyAdded) { errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); alreadyAdded = true; } tmpPriority <<= 1; } errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Create query calendar_query_h queryHandle = null; errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery query(queryHandle); calendar_query_set_sort(queryHandle, _calendar_todo.due_time, true); calendar_query_set_filter(queryHandle, mainFilterHandle); calendar_list_h calendarListHandle = null; errorCode = calendar_db_get_records_with_query(queryHandle, (pageNo - 1) * countPerPage, countPerPage, &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); // TODO:- Should we use SingleObjectDeleter instead ? std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); for (int i = 0; i < count; i++) { std::unique_ptr pTmpTodo(new (std::nothrow) CalTodo()); SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpTodo.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpTodo.release(); } calendar_list_first(calendarListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { CalTodo* pTmpTodo = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle); int dbIndex = -1; errorCode = calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex); calendar_list_next(calendarListHandle); } calendar_list_destroy(calendarList.ReleaseHandle(), false); return pList.release(); } int _CalendarbookImpl::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const { ClearLastResult(); SysTryReturn(NID_SCL, start <= end, _INVALID_COUNT , E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), _INVALID_COUNT , E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer()); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), _INVALID_COUNT , E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer()); SysTryReturn(NID_SCL, CheckValidTodoStatus(status), _INVALID_COUNT , E_INVALID_ARG, "[%s] Invalid argument is used. status = %ld", GetErrorMessage(E_INVALID_ARG), status); SysTryReturn(NID_SCL, CheckValidTodoPriority(priority), _INVALID_COUNT , E_INVALID_ARG, "[%s] Invalid argument is used. priority = %ld", GetErrorMessage(E_INVALID_ARG), priority); DateTime tmpStart; DateTime tmpEnd; tmpStart.SetValue(start.GetYear(), start.GetMonth(), start.GetDay()); tmpEnd.SetValue(end.GetYear(), end.GetMonth(), end.GetDay(), 23, 59, 59); calendar_time_s convertedStartTime; calendar_time_s convertedEndTime; _CalendarbookUtil::ConvertDateTimeToCalTime(tmpStart, convertedStartTime); _CalendarbookUtil::ConvertDateTimeToCalTime(tmpEnd, convertedEndTime); calendar_filter_h mainFilterHandle = null; int errorCode = calendar_filter_create(_calendar_todo._uri, &mainFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter mainFilter(mainFilterHandle); // Condition : Due time of the item => start time of filter errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, convertedStartTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Due time of the item <= end time of filter errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(mainFilterHandle, _calendar_todo.due_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, convertedEndTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : status calendar_filter_h subFilterHandle = null; errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter subFilter(subFilterHandle); subFilterHandle = null; int tmpStatus = TODO_STATUS_NONE; bool alreadyAdded = false; for (int i = 0; i < _NUMBER_OF_TODO_STATUS; i++) { if (status & tmpStatus) { if (alreadyAdded) { errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.todo_status, CALENDAR_MATCH_EQUAL, ConvertTodoStatusToCalendarTodoStatus(tmpStatus)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); alreadyAdded = true; } tmpStatus <<= 1; } errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : priority errorCode = calendar_filter_create(_calendar_todo._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); subFilter.ResetHandle(subFilterHandle); subFilterHandle = null; int tmpPriority = TODO_PRIORITY_LOW; alreadyAdded = false; for (int i = 0; i < _NUMBER_OF_TODO_PRIORITY; i++) { if (priority & tmpPriority) { if (alreadyAdded) { errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_OR); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } errorCode = calendar_filter_add_int(subFilter.GetHandle(), _calendar_todo.priority, CALENDAR_MATCH_EQUAL, ConvertTodoPriorityToCalendarTodoPriority(tmpPriority)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); alreadyAdded = true; } tmpPriority <<= 1; } errorCode = calendar_filter_add_operator(mainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(mainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Create query calendar_query_h queryHandle = null; errorCode = calendar_query_create(_calendar_todo._uri, &queryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, _INVALID_COUNT, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery query(queryHandle); calendar_query_set_filter(queryHandle, mainFilterHandle); int count = _INVALID_COUNT; errorCode = calendar_db_get_count_with_query(queryHandle, &count); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return count; } IList* _CalendarbookImpl::GetEventInstancesN(const DateTime& start, const DateTime& end, const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category) const { ClearLastResult(); SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The pageNo or countPerPage is less than 1.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, start <= end, null, E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), null, E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer()); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), null, E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer()); SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), null, E_INVALID_ARG, "[%s] Invalid argument is used. category = %ld", GetErrorMessage(E_INVALID_ARG), category); std::unique_ptr pList(GetEventInstancesCommonN(start, end, timeZone, pageNo, countPerPage, category)); result r = GetLastResult(); SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); return pList.release(); } result _CalendarbookImpl::GetEventInstances(const DateTime& start, const DateTime& end, const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category, RequestId& reqId, const IRecordListener& listener) const { __requestId++; reqId = __requestId; SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The pageNo or countPerPage is less than 1.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, start <= end, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The start time is later than the end date.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(start), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. start = %S", GetErrorMessage(E_INVALID_ARG), start.ToString().GetPointer()); SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(end), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. end = %S", GetErrorMessage(E_INVALID_ARG), end.ToString().GetPointer()); SysTryReturn(NID_SCL, (category & EVENT_CATEGORY_APPOINTMENT) || (category & EVENT_CATEGORY_ANNIVERSARY), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. category = %ld", GetErrorMessage(E_INVALID_ARG), category); std::unique_ptr<_CalendarbookRecordRetrivalEvent> pEvent(new (std::nothrow) _CalendarbookRecordRetrivalEvent()); SysTryReturnResult(NID_SCL, pEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); result r = pEvent->Construct(); SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred."); r = pEvent->AddListener(listener); SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred."); if (__pRecordRetrivalThread != null) { __pRecordRetrivalThread->Join(); delete __pRecordRetrivalThread; __pRecordRetrivalThread = null; } std::unique_ptr<_CalendarbookRecordRetrivalThread> pRecordRetrivalThread(new (std::nothrow) _CalendarbookRecordRetrivalThread()); SysTryReturnResult(NID_SCL, pRecordRetrivalThread != null, E_OUT_OF_MEMORY, "Memory allocation failed."); r = pRecordRetrivalThread->Construct(__requestId, *pEvent.release(), start, end, timeZone, pageNo, countPerPage, category); SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred."); r = pRecordRetrivalThread->Start(); SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred."); __pRecordRetrivalThread = pRecordRetrivalThread.release(); return E_SUCCESS; } IList* _CalendarbookImpl::GetAllEventsN(void) const { calendar_list_h calendarListHandle = null; int errorCode = calendar_db_get_all_records(_calendar_event._uri, 0, 0, &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); result r = E_SUCCESS; std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); for (int i = 0; i < count; i++) { std::unique_ptr pTmpEvent(new (std::nothrow) CalEvent()); SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpEvent.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpEvent.release(); } calendar_list_first(calendarListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { CalEvent* pTmpEvent = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle); int dbIndex = -1; calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &dbIndex); _RecordImpl::GetInstance(*pTmpEvent)->SetRecordId(dbIndex); calendar_list_next(calendarListHandle); } calendar_list_destroy(calendarList.ReleaseHandle(), false); return pList.release(); } IList* _CalendarbookImpl::GetAllTodosN(void) const { calendar_list_h calendarListHandle = null; int errorCode = calendar_db_get_all_records(_calendar_todo._uri, 0, 0, &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); result r = E_SUCCESS; std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); for (int i = 0; i < count; i++) { std::unique_ptr pTmpTodo(new (std::nothrow) CalTodo()); SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpTodo.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpTodo.release(); } calendar_list_first(calendarListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { CalTodo* pTmpTodo = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle); int dbIndex = -1; calendar_record_get_int(tmpRecordHandle, _calendar_todo.id, &dbIndex); _RecordImpl::GetInstance(*pTmpTodo)->SetRecordId(dbIndex); calendar_list_next(calendarListHandle); } calendar_list_destroy(calendarList.ReleaseHandle(), false); return pList.release(); } IList* _CalendarbookImpl::GetAllCalendarsN(void) const { calendar_list_h calendarListHandle = null; int errorCode = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); for (int i = 0; i < count; i++) { std::unique_ptr pTmpCalendar(_CalendarImpl::CreateDefaultInstanceN()); SysTryReturn(NID_SCL, pTmpCalendar != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpCalendar.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpCalendar.release(); } calendar_list_first(calendarListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { Calendar* pTmpCalendar = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarImpl::GetInstance(*pTmpCalendar)->SetRecordHandle(tmpRecordHandle); int dbIndex = -1; calendar_record_get_int(tmpRecordHandle, _calendar_book.id, &dbIndex); _RecordImpl::GetInstance(*pTmpCalendar)->SetRecordId(dbIndex); calendar_list_next(calendarListHandle); } calendar_list_destroy(calendarList.ReleaseHandle(), false); return pList.release(); } IList* _CalendarbookImpl::GetChangedEventsAfterN(int version, int& latestVersion) const { ClearLastResult(); SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. version = %d", version); calendar_list_h calendarListHandle = null; int tmpLatestVersion = 0; int errorCode = calendar_db_get_changes_by_version(_calendar_event._uri, CALENDAR_BOOK_FILTER_ALL, version , &calendarListHandle, &tmpLatestVersion); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); calendar_list_first(calendarListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pChangedInfo(_CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(tmpRecordHandle)); SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pChangedInfo.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pChangedInfo.release(); calendar_list_next(calendarListHandle); } latestVersion = tmpLatestVersion; return pList.release(); } IList* _CalendarbookImpl::GetChangedTodosAfterN(int version, int& latestVersion) const { ClearLastResult(); SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version = %d", GetErrorMessage(E_INVALID_ARG), version); calendar_list_h calendarListHandle = null; int tmpLatestVersion = 0; int errorCode = calendar_db_get_changes_by_version(_calendar_todo._uri, CALENDAR_BOOK_FILTER_ALL, version , &calendarListHandle, &tmpLatestVersion); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); calendar_list_first(calendarListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; errorCode = calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pChangedInfo(_CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(tmpRecordHandle)); SysTryReturn(NID_SCL, pChangedInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pChangedInfo.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pChangedInfo.release(); calendar_list_next(calendarListHandle); } latestVersion = tmpLatestVersion; return pList.release(); } result _CalendarbookImpl::RemoveEventInstance(const CalEventInstance& eventInstance) { calendar_record_h eventHandle = null; // Get event handle from DB int errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &eventHandle); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The specified record is not found."); _CalendarRecord eventRecord(eventHandle); int baseEventId = _INVALID_EVENT_DB_ID; calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId); if (baseEventId != _INVALID_EVENT_DB_ID) { errorCode = calendar_db_delete_record(_calendar_event._uri, eventInstance.GetOriginalEventId()); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); } else { char* pExdate = null; // Append exdate calendar_record_get_str_p(eventHandle, _calendar_event.exdate, &pExdate); String exdate; if (pExdate != null && strlen(pExdate) > 0) { exdate.Append(pExdate); exdate.Append(_RECURRENCE_DELIMITER); } exdate.Append(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent())); std::unique_ptr pAppendedExdate(_StringConverter::CopyToCharArrayN(exdate)); SysTryReturnResult(NID_SCL, pAppendedExdate != null, E_OUT_OF_MEMORY, "Memory allocation failed."); errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, pAppendedExdate.get()); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); // Update event handle errorCode = calendar_db_update_record(eventHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); } return E_SUCCESS; } result _CalendarbookImpl::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event) { SysTryReturnResult(NID_SCL, event.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG , "Invalid argument is used. The event's recordId is INVALID_RECORD_ID."); SysTryReturnResult(NID_SCL, eventInstance.GetOriginalEventId() == event.GetRecordId(), E_INVALID_ARG , "[%s] Invalid argument is used. The event's recordId is not equal to eventInstance's original event ID.", GetErrorMessage(E_INVALID_ARG)); SysTryReturnResult(NID_SCL, CheckEventExistance(event.GetRecordId()), E_OBJ_NOT_FOUND, "The specified event is not found."); calendar_record_h eventHandle = null; int errorCode = calendar_record_clone(_CalEventImpl::GetInstance(event)->GetRecordHandle(), &eventHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); _CalendarRecord eventRecord(eventHandle); int baseEventId = _INVALID_EVENT_DB_ID; calendar_record_get_int(eventHandle, _calendar_event.original_event_id, &baseEventId); calendar_record_h baseEventHandle = null; if (baseEventId == _INVALID_EVENT_DB_ID) { errorCode = calendar_db_get_record(_calendar_event._uri, eventInstance.GetOriginalEventId(), &baseEventHandle); } else { errorCode = calendar_db_get_record(_calendar_event._uri, baseEventId, &baseEventHandle); } SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OBJ_NOT_FOUND, "[%s] The base event is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); _CalendarRecord baseEventRecord(baseEventHandle); int tmpIntValue = 0; calendar_record_get_int(baseEventHandle, _calendar_event.freq, &tmpIntValue); calendar_record_set_int(eventHandle, _calendar_event.freq, tmpIntValue); calendar_record_get_int(baseEventHandle, _calendar_event.range_type, &tmpIntValue); calendar_record_set_int(eventHandle, _calendar_event.range_type, tmpIntValue); calendar_record_get_int(baseEventHandle, _calendar_event.count, &tmpIntValue); calendar_record_set_int(eventHandle, _calendar_event.count, tmpIntValue); calendar_record_get_int(baseEventHandle, _calendar_event.interval, &tmpIntValue); calendar_record_set_int(eventHandle, _calendar_event.interval, tmpIntValue); calendar_record_get_int(baseEventHandle, _calendar_event.wkst, &tmpIntValue); calendar_record_set_int(eventHandle, _calendar_event.wkst, tmpIntValue); calendar_time_s tmpTimeValue; calendar_record_get_caltime(baseEventHandle, _calendar_event.until_time, &tmpTimeValue); calendar_time_s tmpStartTimeValue; DateTime convertedTime; calendar_record_get_caltime(eventHandle, _calendar_event.start_time, &tmpStartTimeValue); if (tmpTimeValue.type != tmpStartTimeValue.type) { if (tmpStartTimeValue.type == CALENDAR_TIME_UTIME) { convertedTime.SetValue(tmpTimeValue.time.date.year, tmpTimeValue.time.date.month, tmpTimeValue.time.date.mday); tmpTimeValue.type = CALENDAR_TIME_UTIME; tmpTimeValue.time.utime = _CalendarbookUtil::ConvertDateTimeToEpochTime(convertedTime); } else { convertedTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(tmpTimeValue.time.utime); tmpTimeValue.type = CALENDAR_TIME_LOCALTIME; tmpTimeValue.time.date.year = convertedTime.GetYear(); tmpTimeValue.time.date.month = convertedTime.GetMonth(); tmpTimeValue.time.date.mday = convertedTime.GetDay(); } } calendar_record_set_caltime(eventHandle, _calendar_event.until_time, tmpTimeValue); char* tmpStrValue = null; calendar_record_get_str_p(baseEventHandle, _calendar_event.byday, &tmpStrValue); errorCode = calendar_record_set_str(eventHandle, _calendar_event.byday, tmpStrValue); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonthday, &tmpStrValue); errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonthday, tmpStrValue); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); calendar_record_get_str_p(baseEventHandle, _calendar_event.bymonth, &tmpStrValue); errorCode = calendar_record_set_str(eventHandle, _calendar_event.bymonth, tmpStrValue); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); calendar_record_get_str_p(baseEventHandle, _calendar_event.exdate, &tmpStrValue); errorCode = calendar_record_set_str(eventHandle, _calendar_event.exdate, tmpStrValue); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); if (baseEventId == _INVALID_EVENT_DB_ID) { calendar_record_set_int(eventHandle, _calendar_event.original_event_id, eventInstance.GetOriginalEventId()); std::unique_ptr pConvertedRecurrenceId(_StringConverter::CopyToCharArrayN(_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(eventInstance.GetStartTime(), eventInstance.IsAllDayEvent()))); errorCode = calendar_record_set_str(eventHandle, _calendar_event.recurrence_id, pConvertedRecurrenceId.get()); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); int dbIndex = -1; errorCode = calendar_db_insert_record(eventHandle, &dbIndex); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _RecordImpl::GetInstance(event)->SetRecordId(dbIndex); } else { errorCode = calendar_db_update_record(eventHandle); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_DB_FAILED, E_SYSTEM, "A system error has been occurred."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OBJ_NOT_FOUND, "The base event of the event is not found."); } calendar_record_h tmpEventHandle = null; errorCode = calendar_db_get_record(_calendar_event._uri, event.GetRecordId(), &tmpEventHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); _CalEventImpl::GetInstance(event)->SetRecordHandle(tmpEventHandle); return E_SUCCESS; } int _CalendarbookImpl::GetLatestVersion(void) const { ClearLastResult(); int dbVersion = 0; int errorCode = calendar_db_get_current_version(&dbVersion); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, 0, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return dbVersion; } IList* _CalendarbookImpl::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const { CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType(); calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle(); SysTryReturn(NID_SCL, offset >= 0 && maxCount >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified offset or maxCount is less than 0.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, propertySortedBy == 0 || _CalendarbookFilterImpl::IsValidProperty(type, propertySortedBy), null, E_INVALID_ARG , "[%s] Invalid argument is used. propertySortedBy = %d", GetErrorMessage(E_INVALID_ARG), propertySortedBy); const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type); // Create query calendar_query_h queryHandle = null; int errorCode = calendar_query_create(pViewUri, &queryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery query(queryHandle); if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE) { unsigned int viewSortPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(type, propertySortedBy); bool ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false; calendar_query_set_sort(queryHandle, viewSortPropertyId, ascending); } if (filterHandle) { calendar_query_set_filter(queryHandle, filterHandle); } calendar_list_h resultListHandle = null; errorCode = calendar_db_get_records_with_query(queryHandle, offset, maxCount, &resultListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(resultListHandle); std::unique_ptr pList(null); switch(type) { case CB_FI_TYPE_EVENT: { pList.reset(ConvertRecordListN(resultListHandle, _calendar_event)); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); calendar_list_destroy(calendarList.ReleaseHandle(), false); } break; case CB_FI_TYPE_TODO: { pList.reset(ConvertRecordListN(resultListHandle, _calendar_todo)); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); calendar_list_destroy(calendarList.ReleaseHandle(), false); } break; case CB_FI_TYPE_CALENDAR: { pList.reset(ConvertRecordListN(resultListHandle, _calendar_book)); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); calendar_list_destroy(calendarList.ReleaseHandle(), false); } break; case CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE: { pList.reset(ConvertEventInstanceListN(resultListHandle, true)); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); } break; case CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE: { pList.reset(ConvertEventInstanceListN(resultListHandle, false)); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); } break; default: SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of filter is (%d)", GetErrorMessage(E_INVALID_ARG), type); break; }; return pList.release(); } int _CalendarbookImpl::GetMatchedItemCount(const CalendarbookFilter& filter) const { CalendarbookFilterType type = _CalendarbookFilterImpl::GetInstance(filter)->GetType(); calendar_filter_h filterHandle = _CalendarbookFilterImpl::GetInstance(filter)->GetFilterHandle(); const char* pViewUri = _CalendarbookFilterImpl::GetUriFromType(type); // Create query calendar_query_h queryHandle = null; int errorCode = calendar_query_create(pViewUri, &queryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery query(queryHandle); if (filterHandle) { calendar_query_set_filter(queryHandle, filterHandle); } int count = _INVALID_COUNT; errorCode = calendar_db_get_count_with_query(queryHandle, &count); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return count; } IList* _CalendarbookImpl::ParseEventsFromVcalendarN(const String& vCalFilePath) { ClearLastResult(); File vCalFile; result r = vCalFile.Construct(vCalFilePath, L"r"); SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY , null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); r = vCalFile.Seek(FILESEEKPOSITION_END, 0); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); int fileLength = vCalFile.Tell(); SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is empty.", GetErrorMessage(E_INVALID_ARG)); r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pBuffer(new (std::nothrow) ByteBuffer()); SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pBuffer->Construct(fileLength); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = vCalFile.Read(*pBuffer); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarConnector connector; r = connector.GetResult(); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s]A system error has been occurred.", GetErrorMessage(E_SYSTEM)); pBuffer->Rewind(); calendar_list_h calendarListHandle = null; int errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast(const_cast(pBuffer->GetPointer())), &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is invalid.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE || errorCode == CALENDAR_ERROR_NO_DATA, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); calendar_list_first(calendarListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); calendar_list_next(calendarListHandle); char* pUri = null; calendar_record_get_uri_p(tmpRecordHandle, &pUri); if (strcmp(pUri, _calendar_event._uri) == 0) { std::unique_ptr pTmpEvent(new (std::nothrow) CalEvent()); SysTryReturn(NID_SCL, pTmpEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); r = pList->Add(pTmpEvent.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); pTmpEvent.release(); } else { calendar_list_remove(calendarListHandle, tmpRecordHandle); calendar_record_destroy(tmpRecordHandle, true); } } calendar_list_first(calendarListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { CalEvent* pTmpEvent = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); _CalEventImpl::GetInstance(*pTmpEvent)->SetRecordHandle(tmpRecordHandle); calendar_list_next(calendarListHandle); } calendar_list_destroy(calendarList.ReleaseHandle(), false); return pList.release(); } IList* _CalendarbookImpl::ParseTodosFromVcalendarN(const String& vCalFilePath) { ClearLastResult(); File vCalFile; result r = vCalFile.Construct(vCalFilePath, L"r"); SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS && r != E_FILE_NOT_FOUND && r != E_OUT_OF_MEMORY , null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); r = vCalFile.Seek(FILESEEKPOSITION_END, 0); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); int fileLength = vCalFile.Tell(); SysTryReturn(NID_SCL, fileLength > 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is empty.", GetErrorMessage(E_INVALID_ARG)); r = vCalFile.Seek(FILESEEKPOSITION_BEGIN, 0); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pBuffer(new (std::nothrow) ByteBuffer()); SysTryReturn(NID_SCL, pBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pBuffer->Construct(fileLength); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = vCalFile.Read(*pBuffer); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarConnector connector; r = connector.GetResult(); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); pBuffer->Rewind(); calendar_list_h calendarListHandle = null; int errorCode = calendar_vcalendar_parse_to_calendar(reinterpret_cast(const_cast(pBuffer->GetPointer())), &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used. The vCal file is invalid.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE || errorCode == CALENDAR_ERROR_NO_DATA, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(calendarListHandle, &count); calendar_list_first(calendarListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); calendar_list_next(calendarListHandle); char* pUri = null; calendar_record_get_uri_p(tmpRecordHandle, &pUri); if (strcmp(pUri, _calendar_todo._uri) == 0) { std::unique_ptr pTmpTodo(new (std::nothrow) CalTodo()); SysTryReturn(NID_SCL, pTmpTodo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpTodo.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpTodo.release(); } else { calendar_list_remove(calendarListHandle, tmpRecordHandle); calendar_record_destroy(tmpRecordHandle, true); } } calendar_list_first(calendarListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { CalTodo* pTmpTodo = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); _CalTodoImpl::GetInstance(*pTmpTodo)->SetRecordHandle(tmpRecordHandle); calendar_list_next(calendarListHandle); } calendar_list_destroy(calendarList.ReleaseHandle(), false); return pList.release(); } result _CalendarbookImpl::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath) { SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists."); result r = GetLastResult(); SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); _CalendarConnector connector; r = connector.GetResult(); SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_list_h calendarListHandle = null; int errorCode = calendar_list_create(&calendarListHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); _CalendarList calendarList(calendarListHandle, false); std::unique_ptr pEnum(eventList.GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { Record* pTmpRecord = static_cast(pEnum->GetCurrent()); SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_EVENT, E_INVALID_ARG, "Invalid argument is used. The eventList contains invalid record."); CalEvent* pTmpEvent = static_cast(pTmpRecord); errorCode = calendar_list_add(calendarListHandle, _CalEventImpl::GetInstance(*pTmpEvent)->GetRecordHandle()); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); } char* pVCalBuffer = null; errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); std::unique_ptr pVCal(pVCalBuffer); File vCalFile; r = vCalFile.Construct(vCalFilePath, L"w"); 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 , r, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); int pVCalBufferLength = strlen(pVCalBuffer); r = vCalFile.Write(static_cast(pVCalBuffer), pVCalBufferLength); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return E_SUCCESS; } result _CalendarbookImpl::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath) { SysTryReturnResult(NID_SCL, !File::IsFileExist(vCalFilePath), E_FILE_ALREADY_EXIST, "The vCalendar file already exists."); result r = GetLastResult(); SysTryReturn(NID_SCL, r != E_INVALID_ARG && r != E_ILLEGAL_ACCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); _CalendarConnector connector; r = connector.GetResult(); SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_list_h calendarListHandle = null; int errorCode = calendar_list_create(&calendarListHandle); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); _CalendarList calendarList(calendarListHandle, false); std::unique_ptr pEnum(todoList.GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { Record* pTmpRecord = static_cast(pEnum->GetCurrent()); SysTryReturnResult(NID_SCL, pTmpRecord->GetRecordType() == RECORD_TYPE_TODO, E_INVALID_ARG, "Invalid argument is used. The todoList contains invalid record."); CalTodo* pTmpTodo = static_cast(pTmpRecord); errorCode = calendar_list_add(calendarListHandle, _CalTodoImpl::GetInstance(*pTmpTodo)->GetRecordHandle()); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "Memory allocation failed."); } char* pVCalBuffer = null; errorCode = calendar_vcalendar_make_from_records(calendarListHandle, &pVCalBuffer); SysTryReturnResult(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed."); SysTryReturnResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred."); std::unique_ptr pVCal(pVCalBuffer); File vCalFile; r = vCalFile.Construct(vCalFilePath, L"w"); 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 , r, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); int pVCalBufferLength = strlen(pVCalBuffer); r = vCalFile.Write(static_cast(pVCalBuffer), pVCalBufferLength); SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS && r != E_STORAGE_FULL, r, r, "[%s] Propagating.", GetErrorMessage(r)); SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return E_SUCCESS; } DateTime _CalendarbookImpl::GetMaxDateTime(void) { DateTime maxDateTime; maxDateTime.SetValue(2100, 12, 31, 23, 59, 59); return maxDateTime; } DateTime _CalendarbookImpl::GetMinDateTime(void) { DateTime minDateTime; minDateTime.SetValue(1900, 1, 1, 0, 0, 0); return minDateTime; } IList* _CalendarbookImpl::GetEventInstancesCommonN(const DateTime& start, const DateTime& end, const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category) const { ClearLastResult(); calendar_time_s convertedStartTime; calendar_time_s convertedEndTime; _CalendarbookUtil::ConvertDateTimeToCalTime(start, convertedStartTime); _CalendarbookUtil::ConvertDateTimeToCalTime(end, convertedEndTime); Tizen::Locales::TimeZone tmpTimeZone(timeZone); DateTime localStartTime = tmpTimeZone.UtcTimeToWallTime(start); DateTime localEndTime = tmpTimeZone.UtcTimeToWallTime(end); calendar_time_s convertedLocalStartTime; calendar_time_s convertedLocalEndTime; _CalendarbookUtil::ConvertDateToCalTime(localStartTime, convertedLocalStartTime); _CalendarbookUtil::ConvertDateToCalTime(localEndTime, convertedLocalEndTime); std::unique_ptr pList; if (category == EVENT_CATEGORY_ALL) { pList.reset(GetEventInstancesOfAllCategoriesN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage)); } else { pList.reset(GetEventInstancesOfCategoryN(convertedStartTime, convertedEndTime, convertedLocalStartTime, convertedLocalEndTime, pageNo, countPerPage, category)); } return pList.release(); } IList* _CalendarbookImpl::GetEventInstancesOfAllCategoriesN(const calendar_time_s& startTime, const calendar_time_s& endTime, const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage) const { ClearLastResult(); calendar_filter_h allDayEventInstanceMainFilterHandle = null; int errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle); // Condition : End time of the item > start time of filter errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Start time of the item < end time of filter errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Create query calendar_query_h allDayEventInstanceQueryHandle = null; errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle); calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true); calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle); int startIndex = (pageNo - 1) * countPerPage; calendar_list_h allDayEventInstanceListHandle = null; errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, startIndex, countPerPage, &allDayEventInstanceListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList allDayEventList(allDayEventInstanceListHandle); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int allDayEventInstanceCount = 0; errorCode = calendar_db_get_count_with_query(allDayEventInstanceQueryHandle, &allDayEventInstanceCount); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); int count = 0; calendar_list_get_count(allDayEventInstanceListHandle, &count); int pageCount = allDayEventInstanceCount / countPerPage; int remainingCount = countPerPage - count; calendar_list_first(allDayEventInstanceListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle); std::unique_ptr pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle)); SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(*pTmpEventInstance.release()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); calendar_list_next(allDayEventInstanceListHandle); } if (remainingCount > 0) { calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null; errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle); calendar_filter_h subFilterHandle = null; errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter subFilter(subFilterHandle); subFilterHandle = null; // Condition : End time of the item > start time of filter errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Start time of the item < end time of filter errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); subFilter.ResetHandle(subFilterHandle); subFilterHandle = null; errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Create query calendar_query_h nonAllDayEventInstanceQueryHandle = null; errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle); calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true); calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle); if (remainingCount == countPerPage) { startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (allDayEventInstanceCount % countPerPage); } else { startIndex = 0; } calendar_list_h nonAllDayEventInstanceListHandle = null; errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, startIndex, remainingCount, &nonAllDayEventInstanceListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle); count = 0; calendar_list_get_count(nonAllDayEventInstanceListHandle, &count); calendar_list_first(nonAllDayEventInstanceListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle); std::unique_ptr pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle)); SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpEventInstance.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpEventInstance.release(); calendar_list_next(nonAllDayEventInstanceListHandle); } } return pList.release(); } IList* _CalendarbookImpl::GetEventInstancesOfCategoryN(const calendar_time_s& startTime, const calendar_time_s& endTime, const calendar_time_s& localStartTime, const calendar_time_s& localEndTime, int pageNo, int countPerPage, unsigned long category) const { ClearLastResult(); calendar_filter_h allDayEventInstanceMainFilterHandle = null; int errorCode = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceMainFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter allDayEventInstanceMainFilter(allDayEventInstanceMainFilterHandle); // Condition : End time of the item > start time of filter errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, localStartTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Start time of the item < end time of filter errorCode = calendar_filter_add_operator(allDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(allDayEventInstanceMainFilterHandle, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, localEndTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Create query calendar_query_h allDayEventInstanceQueryHandle = null; errorCode = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &allDayEventInstanceQueryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery allDayEventInstanceQuery(allDayEventInstanceQueryHandle); calendar_query_set_sort(allDayEventInstanceQueryHandle, _calendar_instance_allday_calendar_book.start_time, true); calendar_query_set_filter(allDayEventInstanceQueryHandle, allDayEventInstanceMainFilterHandle); // Generate event : category map std::unique_ptr< HashMapT > pEventCategoryMap(GenerateEventCategoryMapN()); SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); int startIndex = (pageNo - 1) * countPerPage; calendar_list_h allDayEventInstanceListHandle = null; errorCode = calendar_db_get_records_with_query(allDayEventInstanceQueryHandle, 0, 0, &allDayEventInstanceListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList allDayEventList(allDayEventInstanceListHandle); std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int remainingCount = countPerPage; int candidateCount = 0; int count = 0; calendar_list_get_count(allDayEventInstanceListHandle, &count); calendar_list_first(allDayEventInstanceListHandle); for (int i = 0; i < count && remainingCount > 0; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(allDayEventInstanceListHandle, &tmpRecordHandle); int tmpCategory = (int) EVENT_CATEGORY_ALL; int eventId = -1; calendar_record_get_int(tmpRecordHandle, _calendar_instance_allday_calendar_book.event_id, &eventId); pEventCategoryMap->GetValue(eventId, tmpCategory); if (tmpCategory == (int) category) { if (candidateCount >= startIndex) { std::unique_ptr pTmpEventInstance(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(tmpRecordHandle)); SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpEventInstance.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpEventInstance.release(); remainingCount--; } candidateCount++; } calendar_list_next(allDayEventInstanceListHandle); } if (remainingCount > 0) { calendar_filter_h nonAllDayEventInstanceMainFilterHandle = null; errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceMainFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter nonAllDayEventInstanceMainFilter(nonAllDayEventInstanceMainFilterHandle); calendar_filter_h subFilterHandle = null; errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarFilter subFilter(subFilterHandle); subFilterHandle = null; // Condition : End time of the item > start time of filter errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, startTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Start time of the item < end time of filter errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN, endTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Condition : Start time of the item = start time of filter AND Start time of the item = end time of filter errorCode = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &subFilterHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); subFilter.ResetHandle(subFilterHandle); subFilterHandle = null; errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, startTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_operator(subFilter.GetHandle(), CALENDAR_FILTER_OPERATOR_AND); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_caltime(subFilter.GetHandle(), _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_EQUAL, endTime); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_operator(nonAllDayEventInstanceMainFilterHandle, CALENDAR_FILTER_OPERATOR_OR); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); errorCode = calendar_filter_add_filter(nonAllDayEventInstanceMainFilterHandle, subFilter.GetHandle()); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); // Create query calendar_query_h nonAllDayEventInstanceQueryHandle = null; errorCode = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &nonAllDayEventInstanceQueryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery nonAllDayEventInstanceQuery(nonAllDayEventInstanceQueryHandle); calendar_query_set_sort(nonAllDayEventInstanceQueryHandle, _calendar_instance_normal_calendar_book.start_time, true); calendar_query_set_filter(nonAllDayEventInstanceQueryHandle, nonAllDayEventInstanceMainFilterHandle); if (remainingCount == countPerPage) { int pageCount = candidateCount / countPerPage; startIndex = (((pageNo - pageCount) - 1) * countPerPage) - (candidateCount % countPerPage); } else { startIndex = 0; } calendar_list_h nonAllDayEventInstanceListHandle = null; errorCode = calendar_db_get_records_with_query(nonAllDayEventInstanceQueryHandle, 0, 0, &nonAllDayEventInstanceListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList nonAllDayEventList(nonAllDayEventInstanceListHandle); candidateCount = 0; count = 0; calendar_list_get_count(nonAllDayEventInstanceListHandle, &count); calendar_list_first(nonAllDayEventInstanceListHandle); for (int i = 0; i < count && remainingCount > 0; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(nonAllDayEventInstanceListHandle, &tmpRecordHandle); int tmpCategory = (int) EVENT_CATEGORY_ALL; int eventId = -1; calendar_record_get_int(tmpRecordHandle, _calendar_instance_normal_calendar_book.event_id, &eventId); pEventCategoryMap->GetValue(eventId, tmpCategory); if (tmpCategory == (int) category) { if (candidateCount >= startIndex) { std::unique_ptr pTmpEventInstance(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(tmpRecordHandle)); SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(*pTmpEventInstance.release()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); remainingCount--; } candidateCount++; } calendar_list_next(nonAllDayEventInstanceListHandle); } } return pList.release(); } HashMapT* _CalendarbookImpl::GenerateEventCategoryMapN(void) const { result r = E_SUCCESS; int errorCode = CALENDAR_ERROR_NONE; unsigned int projectionList[_NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION] = {_calendar_event.id, _calendar_event.categories}; // Create query calendar_query_h queryHandle = null; errorCode = calendar_query_create(_calendar_event._uri, &queryHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalendarQuery query(queryHandle); calendar_query_set_projection(queryHandle, projectionList, _NUMBER_OF_EVENT_CATEGORY_MAP_PROJECTION); calendar_query_set_sort(queryHandle, _calendar_event.id, true); calendar_list_h calendarListHandle = null; errorCode = calendar_db_get_records_with_query(queryHandle, 0, 0, &calendarListHandle); SysTryReturn(NID_SCL, errorCode != CALENDAR_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CalendarList calendarList(calendarListHandle); std::unique_ptr< HashMapT > pEventCategoryMap(new HashMapT()); SysTryReturn(NID_SCL, pEventCategoryMap != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pEventCategoryMap->Construct(); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); int count = 0; calendar_list_get_count(calendarListHandle, &count); calendar_list_first(calendarListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(calendarListHandle, &tmpRecordHandle); int eventId = -1; char* pCategories = null; calendar_record_get_int(tmpRecordHandle, _calendar_event.id, &eventId); calendar_record_get_str_p(tmpRecordHandle, _calendar_event.categories, &pCategories); int category = _CalendarbookUtil::ConvertCSCategoriesToEventCategory(pCategories); pEventCategoryMap->Add(eventId, category); calendar_list_next(calendarListHandle); } return pEventCategoryMap.release(); } CalendarItemType _CalendarbookImpl::GetCalendarItemTypeByCalendarId(RecordId calendarId) const { CalendarItemType calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO; calendar_record_h calendarHandle = null; int storeType = CALENDAR_BOOK_TYPE_NONE; int errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, CALENDAR_ITEM_TYPE_EVENT_AND_TODO, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_record_get_int(calendarHandle, _calendar_book.store_type, &storeType); if (storeType == (CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO)) { calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO; } else if (storeType == CALENDAR_BOOK_TYPE_EVENT) { calendarItemType = CALENDAR_ITEM_TYPE_EVENT_ONLY; } else if (storeType == CALENDAR_BOOK_TYPE_TODO) { calendarItemType = CALENDAR_ITEM_TYPE_TODO_ONLY; } else { SetLastResult(E_SYSTEM); SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_record_destroy(calendarHandle, true); return CALENDAR_ITEM_TYPE_EVENT_AND_TODO; } calendar_record_destroy(calendarHandle, true); return calendarItemType; } bool _CalendarbookImpl::CheckEventExistance(RecordId eventId) const { calendar_record_h eventHandle = null; int errorCode = calendar_db_get_record(_calendar_event._uri, eventId, &eventHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_record_destroy(eventHandle, true); return true; } bool _CalendarbookImpl::CheckTodoExistance(RecordId todoId) const { calendar_record_h todoHandle = null; int errorCode = calendar_db_get_record(_calendar_todo._uri, todoId, &todoHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_record_destroy(todoHandle, true); return true; } bool _CalendarbookImpl::CheckCalendarExistance(RecordId calendarId) const { calendar_record_h calendarHandle = null; int errorCode = calendar_db_get_record(_calendar_book._uri, calendarId, &calendarHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_record_destroy(calendarHandle, true); return true; } bool _CalendarbookImpl::CheckValidTodoPriority(unsigned long priority) const { if ((priority & TODO_PRIORITY_LOW) || (priority & TODO_PRIORITY_NORMAL) || (priority & TODO_PRIORITY_HIGH)) { return true; } return false; } bool _CalendarbookImpl::CheckValidTodoStatus(unsigned long status) const { if ((status & TODO_STATUS_NONE) || (status & TODO_STATUS_NEEDS_ACTION) || (status & TODO_STATUS_COMPLETED) || (status & TODO_STATUS_IN_PROCESS) || (status & TODO_STATUS_CANCELLED)) { return true; } return false; } int _CalendarbookImpl::ConvertTodoStatusToCalendarTodoStatus(unsigned long todoStatus) const { return todoStatus << 8; } int _CalendarbookImpl::ConvertTodoPriorityToCalendarTodoPriority(unsigned long todoPriority) const { int calendarTodoPriority = CALENDAR_TODO_PRIORITY_NONE; if (todoPriority == TODO_PRIORITY_LOW) { calendarTodoPriority = CALENDAR_TODO_PRIORITY_LOW; } else if (todoPriority == TODO_PRIORITY_NORMAL) { calendarTodoPriority = CALENDAR_TODO_PRIORITY_NORMAL; } else if (todoPriority == TODO_PRIORITY_HIGH) { calendarTodoPriority = CALENDAR_TODO_PRIORITY_HIGH; } return calendarTodoPriority; } CalEvent* _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle) { int originalEventDBId = _INVALID_EVENT_DB_ID; calendar_record_h eventHandle = null; int errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The instanceHandle is invalid record."); std::unique_ptr pEvent(new (std::nothrow) CalEvent()); SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get()); errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_time_s startCalendarTime; calendar_time_s endCalendarTime; calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime); calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime); calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime); calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime); pEventImpl->SetOriginalCalEventId(originalEventDBId); pEventImpl->SetRecordHandle(eventHandle); return pEvent.release(); } CalEvent* _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventN(calendar_record_h instanceHandle) { int originalEventDBId = _INVALID_EVENT_DB_ID; calendar_record_h eventHandle = null; int errorCode = calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_INVALID_ARG, "[%s] Invalid argument is used. The instanceHandle is invalid record.", GetErrorMessage(E_INVALID_ARG)); std::unique_ptr pEvent(new (std::nothrow) CalEvent()); SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalEventImpl* pEventImpl = _CalEventImpl::GetInstance(*pEvent.get()); errorCode = calendar_db_get_record(_calendar_event._uri, originalEventDBId, &eventHandle); SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); calendar_time_s startCalendarTime; calendar_time_s endCalendarTime; calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime); calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime); calendar_record_set_caltime(eventHandle, _calendar_event.start_time, startCalendarTime); calendar_record_set_caltime(eventHandle, _calendar_event.end_time, endCalendarTime); pEventImpl->SetOriginalCalEventId(originalEventDBId); pEventImpl->SetRecordHandle(eventHandle); return pEvent.release(); } CalEventInstance* _CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle) { ClearLastResult(); std::unique_ptr pEventInstance(new (std::nothrow) CalEventInstance()); SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get()); int originalEventDBId = _INVALID_EVENT_DB_ID; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_id, &originalEventDBId); pEventInstanceImpl->SetOriginalEventId(originalEventDBId); int calendarDBId = _INVALID_CALENDARBOOK_DB_ID; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.calendar_book_id, &calendarDBId); pEventInstanceImpl->SetCalendarId(calendarDBId); int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.busy_status, &srcEventBusyStatus); BusyStatus busyStatus = BUSY_STATUS_FREE; switch (srcEventBusyStatus) { case CALENDAR_EVENT_BUSY_STATUS_FREE: busyStatus = BUSY_STATUS_FREE; break; case CALENDAR_EVENT_BUSY_STATUS_BUSY: busyStatus = BUSY_STATUS_BUSY; break; case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE: busyStatus = BUSY_STATUS_UNAVAILABLE; break; case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE: busyStatus = BUSY_STATUS_TENTATIVE; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. busy status = %d", GetErrorMessage(E_INVALID_ARG), srcEventBusyStatus); busyStatus = BUSY_STATUS_FREE; break; } pEventInstanceImpl->SetBusyStatus(busyStatus); int srcEventStatus = CALENDAR_EVENT_STATUS_NONE; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.event_status, &srcEventStatus); EventStatus eventStatus = EVENT_STATUS_NONE; switch (srcEventStatus) { case CALENDAR_EVENT_STATUS_NONE: eventStatus = EVENT_STATUS_NONE; break; case CALENDAR_EVENT_STATUS_TENTATIVE: eventStatus = EVENT_STATUS_TENTATIVE; break; case CALENDAR_EVENT_STATUS_CONFIRMED: eventStatus = EVENT_STATUS_CONFIRMED; break; case CALENDAR_EVENT_STATUS_CANCELLED: eventStatus = EVENT_STATUS_CANCELLED; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. status = %d", GetErrorMessage(E_INVALID_ARG), srcEventStatus); eventStatus = EVENT_STATUS_NONE; } pEventInstanceImpl->SetStatus(eventStatus); int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.priority, &srcPriority); EventPriority priority = EVENT_PRIORITY_NORMAL; switch (srcPriority) { case CALENDAR_EVENT_PRIORITY_LOW: priority = EVENT_PRIORITY_LOW; break; case CALENDAR_EVENT_PRIORITY_NONE: // fall through case CALENDAR_EVENT_PRIORITY_NORMAL: priority = EVENT_PRIORITY_NORMAL; break; case CALENDAR_EVENT_PRIORITY_HIGH: priority = EVENT_PRIORITY_HIGH; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. priority = %d", GetErrorMessage(E_INVALID_ARG), srcPriority); priority = EVENT_PRIORITY_NORMAL; } pEventInstanceImpl->SetPriority(priority); int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.sensitivity, &srcSensitivity); RecordSensitivity sensitivity = SENSITIVITY_PUBLIC; switch (srcSensitivity) { case CALENDAR_SENSITIVITY_PUBLIC: sensitivity = SENSITIVITY_PUBLIC; break; case CALENDAR_SENSITIVITY_PRIVATE: sensitivity = SENSITIVITY_PRIVATE; break; case CALENDAR_SENSITIVITY_CONFIDENTIAL: sensitivity = SENSITIVITY_CONFIDENTIAL; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. sensitivity = %d", GetErrorMessage(E_INVALID_ARG), srcSensitivity); sensitivity = SENSITIVITY_PUBLIC; } pEventInstanceImpl->SetSensitivity(sensitivity); calendar_time_s startCalendarTime; DateTime tmpStartTime; calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.start_time, &startCalendarTime); tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday); pEventInstanceImpl->SetStartTime(tmpStartTime); calendar_time_s endCalendarTime; DateTime tmpEndTime; calendar_record_get_caltime(instanceHandle, _calendar_instance_allday_calendar_book.end_time, &endCalendarTime); tmpEndTime.SetValue(endCalendarTime.time.date.year, endCalendarTime.time.date.month, endCalendarTime.time.date.mday); pEventInstanceImpl->SetEndTime(tmpEndTime); pEventInstanceImpl->SetAllDayEvent(true); int isRecurring = 0; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_rrule, &isRecurring); pEventInstanceImpl->SetRecurring(isRecurring); int hasReminder = 0; calendar_record_get_int(instanceHandle, _calendar_instance_allday_calendar_book.has_alarm, &hasReminder); pEventInstanceImpl->SetHasReminder(hasReminder); char* pSubject = null; calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.summary, &pSubject); pEventInstanceImpl->SetSubject(pSubject); char* pDescription = null; calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.description, &pDescription); pEventInstanceImpl->SetDescription(pDescription); char* pLocation = null; calendar_record_get_str_p(instanceHandle, _calendar_instance_allday_calendar_book.location, &pLocation); pEventInstanceImpl->SetLocation(pLocation); return pEventInstance.release(); } CalEventInstance* _CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(calendar_record_h instanceHandle) { ClearLastResult(); std::unique_ptr pEventInstance(new (std::nothrow) CalEventInstance()); SysTryReturn(NID_SCL, pEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalEventInstanceImpl* pEventInstanceImpl = _CalEventInstanceImpl::GetInstance(*pEventInstance.get()); int originalEventDBId = _INVALID_EVENT_DB_ID; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_id, &originalEventDBId); pEventInstanceImpl->SetOriginalEventId(originalEventDBId); int calendarDBId = _INVALID_CALENDARBOOK_DB_ID; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.calendar_book_id, &calendarDBId); pEventInstanceImpl->SetCalendarId(calendarDBId); int srcEventBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.busy_status, &srcEventBusyStatus); BusyStatus busyStatus = BUSY_STATUS_FREE; switch (srcEventBusyStatus) { case CALENDAR_EVENT_BUSY_STATUS_FREE: busyStatus = BUSY_STATUS_FREE; break; case CALENDAR_EVENT_BUSY_STATUS_BUSY: busyStatus = BUSY_STATUS_BUSY; break; case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE: busyStatus = BUSY_STATUS_UNAVAILABLE; break; case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE: busyStatus = BUSY_STATUS_TENTATIVE; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. busy status = %d", GetErrorMessage(E_INVALID_ARG), srcEventBusyStatus); busyStatus = BUSY_STATUS_FREE; break; } pEventInstanceImpl->SetBusyStatus(busyStatus); int srcEventStatus = CALENDAR_EVENT_STATUS_NONE; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.event_status, &srcEventStatus); EventStatus eventStatus = EVENT_STATUS_NONE; switch (srcEventStatus) { case CALENDAR_EVENT_STATUS_NONE: eventStatus = EVENT_STATUS_NONE; break; case CALENDAR_EVENT_STATUS_TENTATIVE: eventStatus = EVENT_STATUS_TENTATIVE; break; case CALENDAR_EVENT_STATUS_CONFIRMED: eventStatus = EVENT_STATUS_CONFIRMED; break; case CALENDAR_EVENT_STATUS_CANCELLED: eventStatus = EVENT_STATUS_CANCELLED; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. status = %d", GetErrorMessage(E_INVALID_ARG), srcEventStatus); eventStatus = EVENT_STATUS_NONE; } pEventInstanceImpl->SetStatus(eventStatus); int srcPriority = CALENDAR_EVENT_PRIORITY_NORMAL; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.priority, &srcPriority); EventPriority priority = EVENT_PRIORITY_NORMAL; switch (srcPriority) { case CALENDAR_EVENT_PRIORITY_LOW: priority = EVENT_PRIORITY_LOW; break; case CALENDAR_EVENT_PRIORITY_NONE: // fall through case CALENDAR_EVENT_PRIORITY_NORMAL: priority = EVENT_PRIORITY_NORMAL; break; case CALENDAR_EVENT_PRIORITY_HIGH: priority = EVENT_PRIORITY_HIGH; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. priority = %d", GetErrorMessage(E_INVALID_ARG), srcPriority); priority = EVENT_PRIORITY_NORMAL; } pEventInstanceImpl->SetPriority(priority); int srcSensitivity = CALENDAR_SENSITIVITY_PUBLIC; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.sensitivity, &srcSensitivity); RecordSensitivity sensitivity = SENSITIVITY_PUBLIC; switch (srcSensitivity) { case CALENDAR_SENSITIVITY_PUBLIC: sensitivity = SENSITIVITY_PUBLIC; break; case CALENDAR_SENSITIVITY_PRIVATE: sensitivity = SENSITIVITY_PRIVATE; break; case CALENDAR_SENSITIVITY_CONFIDENTIAL: sensitivity = SENSITIVITY_CONFIDENTIAL; break; default : SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. sensitivity = %d", GetErrorMessage(E_INVALID_ARG), srcSensitivity); sensitivity = SENSITIVITY_PUBLIC; } pEventInstanceImpl->SetSensitivity(sensitivity); calendar_time_s startCalendarTime; DateTime tmpStartTime; calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.start_time, &startCalendarTime); tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime); pEventInstanceImpl->SetStartTime(tmpStartTime); calendar_time_s endCalendarTime; DateTime tmpEndTime; calendar_record_get_caltime(instanceHandle, _calendar_instance_normal_calendar_book.end_time, &endCalendarTime); tmpEndTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(endCalendarTime.time.utime); pEventInstanceImpl->SetEndTime(tmpEndTime); pEventInstanceImpl->SetAllDayEvent(false); int isRecurring = 0; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_rrule, &isRecurring); pEventInstanceImpl->SetRecurring(isRecurring); int hasReminder = 0; calendar_record_get_int(instanceHandle, _calendar_instance_normal_calendar_book.has_alarm, &hasReminder); pEventInstanceImpl->SetHasReminder(hasReminder); char* pSubject = null; calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.summary, &pSubject); pEventInstanceImpl->SetSubject(pSubject); char* pDescription = null; calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.description, &pDescription); pEventInstanceImpl->SetDescription(pDescription); char* pLocation = null; calendar_record_get_str_p(instanceHandle, _calendar_instance_normal_calendar_book.location, &pLocation); pEventInstanceImpl->SetLocation(pLocation); return pEventInstance.release(); } CalEventChangeInfo* _CalendarbookImpl::ConvertModifiedEventToCalEventChangeInfoN(calendar_record_h modifiedEventHandle) { ClearLastResult(); std::unique_ptr pEventChangeInfo(new (std::nothrow) CalEventChangeInfo()); SysTryReturn(NID_SCL, pEventChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalEventChangeInfoImpl* pEventChangeInfoImpl = _CalEventChangeInfoImpl::GetInstance(*pEventChangeInfo.get()); int eventId = 0; calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.id, &eventId); pEventChangeInfoImpl->SetEventId(eventId); int calendarbookId = 0; calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.calendar_book_id, &calendarbookId); pEventChangeInfoImpl->SetCalendarId(calendarbookId); int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED; calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.modified_status, &modifiedStatus); RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED; switch (modifiedStatus) { case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED: recordChangeType = RECORD_CHANGE_TYPE_ADDED; break; case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED: recordChangeType = RECORD_CHANGE_TYPE_UPDATED; break; case CALENDAR_RECORD_MODIFIED_STATUS_DELETED: recordChangeType = RECORD_CHANGE_TYPE_REMOVED; break; default: SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. modified status = %d", GetErrorMessage(E_INVALID_ARG), modifiedStatus); return null; } pEventChangeInfoImpl->SetChangeType(recordChangeType); int version = 0; calendar_record_get_int(modifiedEventHandle, _calendar_updated_info.version, &version); pEventChangeInfoImpl->SetVersion(version); return pEventChangeInfo.release(); } CalTodoChangeInfo* _CalendarbookImpl::ConvertModifiedTodoToCalTodoChangeInfoN(calendar_record_h modifiedTodoHandle) { ClearLastResult(); std::unique_ptr pTodoChangeInfo(new (std::nothrow) CalTodoChangeInfo()); SysTryReturn(NID_SCL, pTodoChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); _CalTodoChangeInfoImpl* pTodoChangeInfoImpl = _CalTodoChangeInfoImpl::GetInstance(*pTodoChangeInfo.get()); int todoId = 0; calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.id, &todoId); pTodoChangeInfoImpl->SetTodoId(todoId); int calendarbookId = 0; calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.calendar_book_id, &calendarbookId); pTodoChangeInfoImpl->SetCalendarId(calendarbookId); int modifiedStatus = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED; calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.modified_status, &modifiedStatus); RecordChangeType recordChangeType = RECORD_CHANGE_TYPE_ADDED; switch (modifiedStatus) { case CALENDAR_RECORD_MODIFIED_STATUS_INSERTED: recordChangeType = RECORD_CHANGE_TYPE_ADDED; break; case CALENDAR_RECORD_MODIFIED_STATUS_UPDATED: recordChangeType = RECORD_CHANGE_TYPE_UPDATED; break; case CALENDAR_RECORD_MODIFIED_STATUS_DELETED: recordChangeType = RECORD_CHANGE_TYPE_REMOVED; break; default: SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. modified status = %d", GetErrorMessage(E_INVALID_ARG), modifiedStatus); return null; } pTodoChangeInfoImpl->SetChangeType(recordChangeType); int version = 0; calendar_record_get_int(modifiedTodoHandle, _calendar_updated_info.version, &version); pTodoChangeInfoImpl->SetVersion(version); return pTodoChangeInfo.release(); } template IList* _CalendarbookImpl::ConvertRecordListN(calendar_list_h resultListHandle, RecordView recordView) { result r = E_SUCCESS; std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(resultListHandle, &count); for (int i = 0; i < count; i++) { std::unique_ptr pTmpRecord(RecordTypeImpl::CreateDefaultInstanceN()); SysTryReturn(NID_SCL, pTmpRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Add(pTmpRecord.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpRecord.release(); } calendar_list_first(resultListHandle); std::unique_ptr pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { RecordType* pTmpRecord = static_cast(pEnum->GetCurrent()); calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle); RecordTypeImpl::GetInstance(*pTmpRecord)->SetRecordHandle(tmpRecordHandle); int dbIndex = -1; calendar_record_get_int(tmpRecordHandle, recordView.id, &dbIndex); _RecordImpl::GetInstance(*pTmpRecord)->SetRecordId(dbIndex); calendar_list_next(resultListHandle); } return pList.release(); } IList* _CalendarbookImpl::ConvertEventInstanceListN(calendar_list_h resultListHandle, bool isAllDay) { result r = E_SUCCESS; std::unique_ptr pList(new (std::nothrow) ArrayList()); SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pList->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); int count = 0; calendar_list_get_count(resultListHandle, &count); calendar_list_first(resultListHandle); for (int i = 0; i < count; i++) { calendar_record_h tmpRecordHandle = null; calendar_list_get_current_record_p(resultListHandle, &tmpRecordHandle); std::unique_ptr pTmpEventInstance; if (isAllDay) { pTmpEventInstance.reset(_CalendarbookImpl::ConvertAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle)); SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } else { pTmpEventInstance.reset(_CalendarbookImpl::ConvertNonAllDayEventInstanceHandleToCalEventInstanceN(tmpRecordHandle)); SysTryReturn(NID_SCL, pTmpEventInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } r = pList->Add(pTmpEventInstance.get()); SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pTmpEventInstance.release(); calendar_list_next(resultListHandle); } return pList.release(); } void _CalendarbookImpl::OnCalEventChanged(void) { if (__pICalendarbookEventListener == null && __pIRecordEventListener == null) { return; } _CalendarConnector connector; result r = connector.GetResult(); SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pChangedEventList(GetChangedEventsAfterN(__dbVersionForEvent, __dbVersionForEvent)); SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); if (pChangedEventList->GetCount() > 0) { if (__pICalendarbookEventListener != null) { __pICalendarbookEventListener->OnCalendarEventsChanged(*pChangedEventList.get()); } else { RecordEventType recordEventType = RECORD_ADDED; IEnumerator* pEnum = pChangedEventList->GetEnumeratorN(); CalEvent* pEvent = null; while (pEnum->MoveNext() == E_SUCCESS) { CalEventChangeInfo* pEventChagneInfo = static_cast(pEnum->GetCurrent()); if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED) { recordEventType = RECORD_ADDED; pEvent = GetEventN(pEventChagneInfo->GetEventId()); if (pEvent == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else if (pEventChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED) { recordEventType = RECORD_UPDATED; pEvent = GetEventN(pEventChagneInfo->GetEventId()); if (pEvent == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else { recordEventType = RECORD_REMOVED; pEvent = new (std::nothrow) CalEvent(); if (pEvent == null) { SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); break; } _RecordImpl::GetInstance(*pEvent)->SetRecordId(pEventChagneInfo->GetEventId()); } __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_EVENT, *pEvent, null, null); delete pEvent; } delete pEnum; } } } void _CalendarbookImpl::OnCalTodoChanged(void) { if (__pICalendarbookEventListener == null && __pIRecordEventListener == null) { return; } _CalendarConnector connector; result r = connector.GetResult(); SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pChangedTodoList(GetChangedTodosAfterN(__dbVersionForTodo, __dbVersionForTodo)); SysTryReturnVoidResult(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturnVoidResult(NID_SCL, GetLastResult() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); if (pChangedTodoList->GetCount() > 0) { if (__pICalendarbookEventListener != null) { __pICalendarbookEventListener->OnCalendarTodosChanged(*pChangedTodoList.get()); } else { RecordEventType recordEventType = RECORD_ADDED; IEnumerator* pEnum = pChangedTodoList->GetEnumeratorN(); CalTodo* pTodo = null; while (pEnum->MoveNext() == E_SUCCESS) { CalTodoChangeInfo* pTodoChagneInfo = static_cast(pEnum->GetCurrent()); if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED) { recordEventType = RECORD_ADDED; pTodo = GetTodoN(pTodoChagneInfo->GetTodoId()); if (pTodo == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else if (pTodoChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED) { recordEventType = RECORD_UPDATED; pTodo = GetTodoN(pTodoChagneInfo->GetTodoId()); if (pTodo == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else { recordEventType = RECORD_REMOVED; pTodo = new (std::nothrow) CalTodo(); if (pTodo == null) { SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); break; } _RecordImpl::GetInstance(*pTodo)->SetRecordId(pTodoChagneInfo->GetTodoId()); } __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_TODO, *pTodo, null, null); delete pTodo; } delete pEnum; } } } _CalendarbookImpl* _CalendarbookImpl::GetInstance(Calendarbook& calendarbook) { return calendarbook.__pCalendarbookImpl; } const _CalendarbookImpl* _CalendarbookImpl::GetInstance(const Calendarbook& calendarbook) { return calendarbook.__pCalendarbookImpl; } }} //OSP::Social