summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJae-Hwa Shin <jaehwa.shin@samsung.com>2013-06-17 00:35:31 +0000
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>2013-06-17 00:35:31 +0000
commit9280813c083c86411abcb200f234962b2b01761a (patch)
treebab96497eded6dad85bd364c995b46e4d03390af /src
parent4a636f7e76c3e06734f9543b0e22dad3e626a1bd (diff)
parentbda2e0ab01fcd4719c3e4bbd957073375b1c54da (diff)
downloadsocial-9280813c083c86411abcb200f234962b2b01761a.tar.gz
social-9280813c083c86411abcb200f234962b2b01761a.tar.bz2
social-9280813c083c86411abcb200f234962b2b01761a.zip
Merge "add method for getting extra data of a category" into tizen_2.2
Diffstat (limited to 'src')
-rw-r--r--src/FSclCategory.cpp12
-rw-r--r--src/FScl_CategoryImpl.cpp113
-rw-r--r--src/inc/FScl_CategoryImpl.h4
3 files changed, 127 insertions, 2 deletions
diff --git a/src/FSclCategory.cpp b/src/FSclCategory.cpp
index 70a40df..1309df3 100644
--- a/src/FSclCategory.cpp
+++ b/src/FSclCategory.cpp
@@ -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
diff --git a/src/FScl_CategoryImpl.cpp b/src/FScl_CategoryImpl.cpp
index 6c4f822..53976cf 100644
--- a/src/FScl_CategoryImpl.cpp
+++ b/src/FScl_CategoryImpl.cpp
@@ -22,7 +22,10 @@
#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>
@@ -37,9 +40,12 @@
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));
diff --git a/src/inc/FScl_CategoryImpl.h b/src/inc/FScl_CategoryImpl.h
index 82c1bd3..1cfde87 100644
--- a/src/inc/FScl_CategoryImpl.h
+++ b/src/inc/FScl_CategoryImpl.h
@@ -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);