#include <FSclRecord.h>
#include <FSclTypes.h>
+namespace Tizen { namespace Base { namespace Collection
+{
+class IMap;
+}}};
+
namespace Tizen { namespace Social
{
* @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);
/**
* 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
#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)
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)
{
{
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));