add method for getting extra data of a category
authorGwangbok Kim <gwangbok.kim@samsung.com>
Wed, 12 Jun 2013 02:26:47 +0000 (11:26 +0900)
committerGwangbok Kim <gwangbok.kim@samsung.com>
Fri, 14 Jun 2013 08:06:25 +0000 (17:06 +0900)
Change-Id: Icb0696ab54e0cadb86d5a0140750b458f94658ba
Signed-off-by: Gwangbok Kim <gwangbok.kim@samsung.com>
inc/FSclCategory.h
src/FSclCategory.cpp
src/FScl_CategoryImpl.cpp
src/inc/FScl_CategoryImpl.h

index 99d2bb3..9bb3f6a 100644 (file)
 #include <FSclRecord.h>
 #include <FSclTypes.h>
 
+namespace Tizen { namespace Base { namespace Collection
+{
+class IMap;
+}}};
+
 namespace Tizen { namespace Social
 {
 
@@ -191,10 +196,10 @@ public:
         * @param [in]  name                    The category name
         * @exception   E_SUCCESS               The method is successful.
         * @exception   E_INVALID_ARG   The specified @c name is an empty string.
-        * @exception   E_INVALID_OPERATION     This category is a default category.
-        * @remarks     It is not allowed to change the name of a default category.
+        * @exception   E_INVALID_OPERATION     This category is a read-only category.
+        * @remarks     It is not allowed to change the name of a read-only category.
         * @see GetName()
-        * @see IsDefault()
+        * @see IsReadOnly()
         */
        result SetName(const Tizen::Base::String& name);
 
@@ -237,15 +242,36 @@ public:
 
        /**
         * Checks whether this category is a default category or not. @n
-        * If a category is default, it is not possible to update the category’s name and delete the category.
-        * However it is still possible to add or remove contacts and change thumbnail and ringtone.
-        *  
-        * @since       2.0
+        *
+        * @since       2.0
         *
         * @return     @c true if this is a default category, @n
         *             else @c false
         */
-       bool IsDefault(void) const;   
+       bool IsDefault(void) const;
+
+       /**
+        * Checks whether this category is read-only or not. @n
+        * If a category is default, it is not possible to update the category name and delete the category.
+        * However it is possible to add or remove contacts and change thumbnail and ringtone.
+        *
+        * @since       2.1
+        *
+        * @return     @c true if this is a default category, @n
+        *             else @c false
+        */
+       bool IsReadOnly(void) const;
+
+       /*
+        * Gets the extra data.
+        *
+        * @since       2.2
+        *
+        * @return      The key-value map of the extended data where the key and value are of type Tizen::Base::String, @n
+        *                      else and empty map if there is no extra data, or null if an exception occurs.
+        * @remarks     The specific error code can be accessed using the GetlastResult() method.
+        */
+       Tizen::Base::Collection::IMap* GetExtraDataN(void) const;
 
        /**
         * Sets the thumbnail image. @n
index 70a40df..1309df3 100644 (file)
@@ -184,4 +184,16 @@ Category::IsDefault(void) const
        return __pCategoryImpl->IsDefault();
 }
 
+bool
+Category::IsReadOnly(void) const
+{
+       return __pCategoryImpl->IsReadOnly();
+}
+
+IMap*
+Category::GetExtraDataN(void) const
+{
+       return __pCategoryImpl->GetExtraDataN();
+}
+
 }} // Tizen::Social
index 6c4f822..53976cf 100644 (file)
 
 #include <new>
 #include <FBaseString.h>
+#include <FBaseColHashMap.h>
 #include <FBaseColArrayListT.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseUtilStringTokenizer.h>
 #include <FSclAddressbook.h>
 #include <FSclCategory.h>
 #include <FBaseSysLog.h>
 
 using namespace Tizen::App;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Io;
 
+static const wchar_t CATEGORY_EXT_DATA_GROUP_NAME_ID_KEY[] = L"group_name_id";
+
 namespace Tizen { namespace Social
 {
 _CategoryImpl::_CategoryImpl(void)
@@ -207,6 +213,109 @@ _CategoryImpl::IsDefault(void) const
        return false;
 }
 
+bool
+_CategoryImpl::IsReadOnly(void) const
+{
+       bool isReadOnly = false;
+
+       contacts_record_get_bool(__recordHandle, _contacts_group.is_read_only, &isReadOnly);
+       if (isReadOnly)
+       {
+               return true;
+       }
+
+       return false;
+}
+
+IMap*
+_CategoryImpl::GetExtraDataN(void) const
+{
+       std::unique_ptr<HashMap, AllElementsDeleter> pExtraData(new (std::nothrow) HashMap());
+       SysTryReturn(NID_SCL, pExtraData != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       result r = pExtraData->Construct();
+       SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       char* pCharValue = null;
+       contacts_record_get_str_p(__recordHandle, _contacts_group.extra_data, &pCharValue);
+
+       if (pCharValue == null)
+       {
+               return pExtraData.release();
+       }
+
+       String delim(L":,");
+       String extraData(pCharValue);
+       String decodedString(L"");
+       std::unique_ptr<ByteBuffer> pByteBuffer(null);
+
+       StringTokenizer tokerizer(extraData, delim);
+       String token(L"");
+
+       if (tokerizer.GetTokenCount() == 1) // utf8
+       {
+               if (GetAddressbookId() == DEFAULT_ADDRESSBOOK_ID)
+               {
+                       if (tokerizer.GetNextToken(token) == E_SUCCESS)
+                       {
+                               std::unique_ptr<String> pKey(new (std::nothrow) String(CATEGORY_EXT_DATA_GROUP_NAME_ID_KEY));
+                               SysTryReturn(NID_SCL, pKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                               std::unique_ptr<String> pValue(new (std::nothrow) String(token));
+                               SysTryReturn(NID_SCL, pValue != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                               r = pExtraData->Add(pKey.get(), pValue.get());
+                               SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                               pKey.release();
+                               pValue.release();
+                       }
+               }
+       }
+       else // base64
+       {
+               while (tokerizer.HasMoreTokens())
+               {
+                       // key
+                       r = tokerizer.GetNextToken(token);
+                       if (r != E_SUCCESS)
+                       {
+                               break;
+                       }
+
+                       pByteBuffer.reset(StringUtil::DecodeBase64StringN(token));
+                       SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       std::unique_ptr<String> pKey(new (std::nothrow) String());
+                       SysTryReturn(NID_SCL, pKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       StringUtil::Utf8ToString((const char*)pByteBuffer->GetPointer(), *pKey);
+
+                       // value
+                       r = tokerizer.GetNextToken(token);
+                       if (r != E_SUCCESS)
+                       {
+                               break;
+                       }
+
+                       pByteBuffer.reset(StringUtil::DecodeBase64StringN(token));
+                       SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       std::unique_ptr<String> pValue(new (std::nothrow) String());
+                       SysTryReturn(NID_SCL, pValue != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+                       StringUtil::Utf8ToString((const char*)pByteBuffer->GetPointer(), *pValue);
+
+                       r = pExtraData->Add(pKey.get(), pValue.get());
+                       SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       pKey.release();
+                       pValue.release();
+               }
+       }
+
+       return pExtraData.release();
+}
+
 void
 _CategoryImpl::SetRecordHandle(contacts_record_h recordHandle)
 {
@@ -361,12 +470,12 @@ _CategoryImpl::SetName(const String& name)
 {
        if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
        {
-               SysTryReturn(NID_SCL, !IsDefault(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. This category is a default category.", GetErrorMessage(E_INVALID_ARG));
+               SysTryReturn(NID_SCL, !IsReadOnly(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. This category is a default category.", GetErrorMessage(E_INVALID_ARG));
                SysTryReturn(NID_SCL, name.GetLength() <= 100, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified name exceeds the max length.", GetErrorMessage(E_INVALID_ARG));
        }
        else
        {
-               SysTryReturn(NID_SCL, !IsDefault(), E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] This category is a default category.", GetErrorMessage(E_INVALID_OPERATION));
+               SysTryReturn(NID_SCL, !IsReadOnly(), E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] This category is a default category.", GetErrorMessage(E_INVALID_OPERATION));
        }
 
        SysTryReturn(NID_SCL, !name.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified file path is an empty string", GetErrorMessage(E_INVALID_ARG));
index 82c1bd3..1cfde87 100644 (file)
@@ -106,6 +106,10 @@ public:
 
        bool IsDefault(void) const;
 
+       bool IsReadOnly(void) const;
+
+       Tizen::Base::Collection::IMap* GetExtraDataN(void) const;
+
        void SetMemberCount(int memberCount);
 
        void SetRecord(const Record& record);