Init Tizen 2.2.1
[framework/osp/social.git] / src / FScl_CalendarImpl.cpp
index ff4863e..b719498 100644 (file)
  * This file contains definitions of @e _CalendarImpl class.
  */
 
+#include <FBaseInteger.h>
 #include <FBaseString.h>
 #include <FBaseSysLog.h>
 #include <FBaseUtilStringTokenizer.h>
-#include <FBaseInteger.h>
-#include <FSclCalendar.h>
 #include <FBase_StringConverter.h>
+#include <FSclCalendar.h>
+#include "FScl_CalendarbookDbConnector.h"
 #include "FScl_CalendarImpl.h"
 #include "FScl_RecordImpl.h"
-#include "FScl_CalendarbookDbConnector.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Utility;
@@ -42,16 +42,14 @@ static const int _NUM_OF_COLOR_FACTOR = 3;
 
 _CalendarImpl::_CalendarImpl(CalendarItemType itemType)
 {
-       int errorCode = CALENDAR_ERROR_NONE;
-       calendar_record_h calendarHandle = null;
-
        result r = _CalendarbookDbConnector::Connect();
-       SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
+       SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       errorCode = calendar_record_create(_calendar_book._uri, &calendarHandle);
-       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+       calendar_record_h calendarHandle = null;
+       int errorCode = calendar_record_create(_calendar_book._uri, &calendarHandle);
+       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       errorCode = calendar_record_set_int(calendarHandle, _calendar_book.store_type, _CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(itemType));
+       calendar_record_set_int(calendarHandle, _calendar_book.store_type, _CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(itemType));
 
        __calendarRecord.ResetHandle(calendarHandle);
 
@@ -59,26 +57,22 @@ _CalendarImpl::_CalendarImpl(CalendarItemType itemType)
 
 _CalendarImpl::_CalendarImpl(const _CalendarImpl& rhs)
 {
-       int errorCode = CALENDAR_ERROR_NONE;
-       calendar_record_h calendarHandle = null;
-
        result r = _CalendarbookDbConnector::Connect();
-       SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
+       SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       errorCode = calendar_record_clone(rhs.__calendarRecord.GetHandle(), &calendarHandle);
-       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+       calendar_record_h calendarHandle = null;
+       int errorCode = calendar_record_clone(rhs.__calendarRecord.GetHandle(), &calendarHandle);
+       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        __calendarRecord.ResetHandle(calendarHandle);
 }
 
 _CalendarImpl::~_CalendarImpl(void)
 {
-       int errorCode = CALENDAR_ERROR_NONE;
-
-       errorCode = calendar_record_destroy(__calendarRecord.ReleaseHandle(), true);
+       calendar_record_destroy(__calendarRecord.ReleaseHandle(), true);
 
        result r = _CalendarbookDbConnector::Disconnect();
-       SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
+       SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 }
 
 _CalendarImpl&
@@ -89,11 +83,10 @@ _CalendarImpl::operator =(const _CalendarImpl& rhs)
                return *this;
        }
 
-       int errorCode = CALENDAR_ERROR_NONE;
        calendar_record_h calendarHandle = null;
 
-       errorCode = calendar_record_clone(rhs.__calendarRecord.GetHandle(), &calendarHandle);
-       SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+       int errorCode = calendar_record_clone(rhs.__calendarRecord.GetHandle(), &calendarHandle);
+       SysTryReturn(NID_SCL, errorCode == CALENDAR_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        __calendarRecord.ResetHandle(calendarHandle);
 
@@ -103,10 +96,9 @@ _CalendarImpl::operator =(const _CalendarImpl& rhs)
 String
 _CalendarImpl::GetName(void) const
 {
-       int errorCode = CALENDAR_ERROR_NONE;
        char* pName = null;
 
-       errorCode = calendar_record_get_str_p(__calendarRecord.GetHandle(), _calendar_book.name, &pName);
+       calendar_record_get_str_p(__calendarRecord.GetHandle(), _calendar_book.name, &pName);
 
        return String(pName);
 }
@@ -114,11 +106,10 @@ _CalendarImpl::GetName(void) const
 CalendarItemType
 _CalendarImpl::GetItemType(void) const
 {
-       int errorCode = CALENDAR_ERROR_NONE;
        int storeType = 0;
        CalendarItemType calendarItemType = CALENDAR_ITEM_TYPE_EVENT_AND_TODO;
 
-       errorCode = calendar_record_get_int(__calendarRecord.GetHandle(), _calendar_book.store_type, &storeType);
+       calendar_record_get_int(__calendarRecord.GetHandle(), _calendar_book.store_type, &storeType);
        switch (storeType)
        {
 
@@ -142,9 +133,8 @@ _CalendarImpl::GetItemType(void) const
 AccountId
 _CalendarImpl::GetAccountId(void) const
 {
-       int errorCode = CALENDAR_ERROR_NONE;
        int accountId = 0;
-       errorCode = calendar_record_get_int(__calendarRecord.GetHandle(), _calendar_book.account_id, &accountId);
+       calendar_record_get_int(__calendarRecord.GetHandle(), _calendar_book.account_id, &accountId);
 
        return accountId;
 }
@@ -152,9 +142,8 @@ _CalendarImpl::GetAccountId(void) const
 result
 _CalendarImpl::GetColor(byte& red, byte& green, byte& blue) const
 {
-       int errorCode = CALENDAR_ERROR_NONE;
        char* pColor = null;
-       errorCode = calendar_record_get_str_p(__calendarRecord.GetHandle(), _calendar_book.color, &pColor);
+       calendar_record_get_str_p(__calendarRecord.GetHandle(), _calendar_book.color, &pColor);
 
        if (pColor == null || strlen(pColor) == 0)
        {
@@ -165,8 +154,6 @@ _CalendarImpl::GetColor(byte& red, byte& green, byte& blue) const
                return E_DATA_NOT_FOUND;
        }
 
-       result r = E_SUCCESS;
-
        int tmpRed = 0;
        int tmpGreen = 0;
        int tmpBlue = 0;
@@ -177,12 +164,12 @@ _CalendarImpl::GetColor(byte& red, byte& green, byte& blue) const
 
        StringTokenizer strTok(tmpString, delim);
 
-       r = strTok.GetNextToken(token);
-       r = Integer::Parse(token, tmpRed);
-       r = strTok.GetNextToken(token);
-       r = Integer::Parse(token, tmpGreen);
-       r = strTok.GetNextToken(token);
-       r = Integer::Parse(token, tmpBlue);
+       strTok.GetNextToken(token);
+       Integer::Parse(token, tmpRed);
+       strTok.GetNextToken(token);
+       Integer::Parse(token, tmpGreen);
+       strTok.GetNextToken(token);
+       Integer::Parse(token, tmpBlue);
 
        red = tmpRed;
        green = tmpGreen;
@@ -195,10 +182,10 @@ void
 _CalendarImpl::SetName(const String& name)
 {
        std::unique_ptr<char[]> pConvertedName(_StringConverter::CopyToCharArrayN(name));
-       SysTryReturnVoidResult(NID_SCL, pConvertedName != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+       SysTryReturnVoidResult(NID_SCL, pConvertedName != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       int errorCode = CALENDAR_ERROR_NONE;
-       errorCode = calendar_record_set_str(__calendarRecord.GetHandle(), _calendar_book.name, pConvertedName.get());
+       int errorCode = calendar_record_set_str(__calendarRecord.GetHandle(), _calendar_book.name, pConvertedName.get());
+       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 }
 
 void
@@ -214,29 +201,23 @@ _CalendarImpl::SetColor(byte red, byte green, byte blue)
        color.Append(255);      // alpha
 
        std::unique_ptr<char[]> pConvertedColor(_StringConverter::CopyToCharArrayN(color));
-       SysTryReturnVoidResult(NID_SCL, pConvertedColor != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+       SysTryReturnVoidResult(NID_SCL, pConvertedColor != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       int errorCode = CALENDAR_ERROR_NONE;
-       errorCode = calendar_record_set_str(__calendarRecord.GetHandle(), _calendar_book.color, pConvertedColor.get());
+       int errorCode = calendar_record_set_str(__calendarRecord.GetHandle(), _calendar_book.color, pConvertedColor.get());
+       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 }
 
 void
 _CalendarImpl::ClearColor(void)
 {
-       String color;
-
-       std::unique_ptr<char[]> pConvertedColor(_StringConverter::CopyToCharArrayN(color));
-       SysTryReturnVoidResult(NID_SCL, pConvertedColor != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
-
-       int errorCode = CALENDAR_ERROR_NONE;
-       errorCode = calendar_record_set_str(__calendarRecord.GetHandle(), _calendar_book.color, pConvertedColor.get());
+       int errorCode = calendar_record_set_str(__calendarRecord.GetHandle(), _calendar_book.color, null);
+       SysTryReturnVoidResult(NID_SCL, errorCode == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 }
 
 void
 _CalendarImpl::SetAccountId(AccountId accountId)
 {
-       int errorCode = CALENDAR_ERROR_NONE;
-       errorCode = calendar_record_set_int(__calendarRecord.GetHandle(), _calendar_book.account_id, accountId);
+       calendar_record_set_int(__calendarRecord.GetHandle(), _calendar_book.account_id, accountId);
 }
 
 void