From 7fb7793d78ad3803e3140c9dfa0f76a9978f417a Mon Sep 17 00:00:00 2001 From: Maciek Blim Date: Sun, 21 Dec 2014 10:51:56 +0100 Subject: [PATCH] [Messaging] moved MessageFolder class Change-Id: I0a40ecf65c5b4973cf058064de81f2ae7a250a88 Signed-off-by: Maciek Blim --- src/messaging/message_folder.cc | 182 ++++++++++++++++++++++++++++ src/messaging/message_folder.h | 89 ++++++++++++++ src/messaging/messaging.gyp | 4 +- src/messaging/messaging_util.cc | 2 + src/messaging/messaging_util.h | 3 +- src/messaging/old/MessageFolder.cpp | 12 +- 6 files changed, 284 insertions(+), 8 deletions(-) create mode 100644 src/messaging/message_folder.cc create mode 100644 src/messaging/message_folder.h diff --git a/src/messaging/message_folder.cc b/src/messaging/message_folder.cc new file mode 100644 index 00000000..22f03934 --- /dev/null +++ b/src/messaging/message_folder.cc @@ -0,0 +1,182 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "messaging_util.h" +#include "message_folder.h" + +namespace extension { +namespace messaging { + +using namespace tizen; + +MessageFolder::MessageFolder( + std::string id, + std::string parent_id, + std::string service_id, + std::string content_type, + std::string name, + std::string path, + MessageFolderType type, + bool synchronizable): + m_id(id), + m_parent_id(parent_id), + m_parent_id_set(true), + m_service_id(service_id), + m_content_type(content_type), + m_name(name), + m_path(path), + m_type(type), + m_synchronizable(synchronizable) +{ +} + +MessageFolder::MessageFolder(email_mailbox_t mailbox) +{ + m_id = std::to_string(mailbox.mailbox_id); + m_parent_id_set = false; + m_service_id = std::to_string(mailbox.account_id); + m_content_type = MessagingUtil::messageTypeToString(EMAIL); + m_name = mailbox.alias; + m_path = mailbox.mailbox_name; + m_type = convertPlatformFolderType(mailbox.mailbox_type); + if (0 == mailbox.local) { + m_synchronizable = true; + } + else { + m_synchronizable = false; + } +} + +std::string MessageFolder::getId() const +{ + return m_id; +} + +std::string MessageFolder::getParentId() const +{ + return m_parent_id; +} + +bool MessageFolder::isParentIdSet() const +{ + return m_parent_id_set; +} + +void MessageFolder::setParentId(const std::string& parentId) +{ + m_parent_id = parentId; + m_parent_id_set = true; +} + +std::string MessageFolder::getServiceId() const +{ + return m_service_id; +} + +std::string MessageFolder::getContentType() const +{ + return m_content_type; +} + +std::string MessageFolder::getName() const +{ + return m_name; +} + +std::string MessageFolder::getPath() const +{ + return m_path; +} + +MessageFolderType MessageFolder::getType() const +{ + return m_type; +} + +bool MessageFolder::getSynchronizable() const +{ + return m_synchronizable; +} + +void MessageFolder::setName(const std::string &value) +{ + m_name = value; +} + +void MessageFolder::setSynchronizable(const bool &value) +{ + m_synchronizable = value; +} + +MessageFolderType MessageFolder::convertPlatformFolderType( + email_mailbox_type_e folderType) +{ + switch (folderType) { + case email_mailbox_type_e::EMAIL_MAILBOX_TYPE_INBOX: + return MessageFolderType::MESSAGE_FOLDER_TYPE_INBOX; + case email_mailbox_type_e::EMAIL_MAILBOX_TYPE_SENTBOX: + return MessageFolderType::MESSAGE_FOLDER_TYPE_SENTBOX; + case email_mailbox_type_e::EMAIL_MAILBOX_TYPE_DRAFT: + return MessageFolderType::MESSAGE_FOLDER_TYPE_DRAFTS; + case email_mailbox_type_e::EMAIL_MAILBOX_TYPE_OUTBOX: + return MessageFolderType::MESSAGE_FOLDER_TYPE_OUTBOX; + case email_mailbox_type_e::EMAIL_MAILBOX_TYPE_ALL_EMAILS: + return MessageFolderType::MESSAGE_FOLDER_TYPE_NOTSTANDARD; + default: + return MessageFolderType::MESSAGE_FOLDER_TYPE_NOTSTANDARD; + } +} + +/** + * + * Attribute | Attribute filter| Attribute range filter + * | supported | supported + * ----------------+-----------------+------------------------ + * id | No | No + * parentId | No | No + * serviceId | Yes | No + * contentType | No | No + * name | No | No + * path | No | No + * type | No | No + * synchronizable | No | No + */ + +namespace FOLDER_FILTER_ATTRIBUTE { +const std::string SERVICE_ID = "serviceId"; +} //namespace FOLDER_FILTER_ATTRIBUTE + +bool MessageFolder::isMatchingAttribute(const std::string& attribute_name, + const FilterMatchFlag match_flag, + AnyPtr match_value) const +{ + LoggerD("Entered"); + auto key = match_value->toString(); + LoggerD("attribute_name: %s match_flag:%d match_value:%s", attribute_name.c_str(), + match_flag, key.c_str()); + + using namespace FOLDER_FILTER_ATTRIBUTE; + + if (SERVICE_ID == attribute_name) { + return FilterUtils::isStringMatching(key, getServiceId() , match_flag); + } + else { + LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str()); + } + + return false; +} + + +bool MessageFolder::isMatchingAttributeRange(const std::string& attribute_name, + AnyPtr initial_value, + AnyPtr end_value) const +{ + LoggerD("Entered"); + LoggerD("attribute_name: %s NOT SUPPORTED", attribute_name.c_str()); + return false; +} + +} //messaging +} //extension diff --git a/src/messaging/message_folder.h b/src/messaging/message_folder.h new file mode 100644 index 00000000..87f9be19 --- /dev/null +++ b/src/messaging/message_folder.h @@ -0,0 +1,89 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef __TIZEN_MESSAGING_MESSAGE_FOLDER_H__ +#define __TIZEN_MESSAGING_MESSAGE_FOLDER_H__ + +#include +#include +#include + +#include +#include "MsgCommon/AbstractFilter.h" + +namespace extension { +namespace messaging { + +enum MessageFolderType { + MESSAGE_FOLDER_TYPE_INBOX, + MESSAGE_FOLDER_TYPE_OUTBOX, + MESSAGE_FOLDER_TYPE_DRAFTS, + MESSAGE_FOLDER_TYPE_SENTBOX, + MESSAGE_FOLDER_TYPE_NOTSTANDARD +}; + +class MessageFolder; + +struct MessageFolderHolder { + std::shared_ptr ptr; +}; + +typedef std::shared_ptr FolderPtr; + +typedef std::vector FolderPtrVector; + +class MessageFolder : public tizen::FilterableObject{ + +public: + MessageFolder( + std::string id, + std::string parent_id, + std::string service_id, + std::string content_type, + std::string name, + std::string path, + MessageFolderType type, + bool synchronizable); + MessageFolder(email_mailbox_t mailbox); + + std::string getId() const; + std::string getParentId() const; + bool isParentIdSet() const; + void setParentId(const std::string& parentId); + std::string getServiceId() const; + std::string getContentType() const; + std::string getName() const; + void setName(const std::string &value); + std::string getPath() const; + MessageFolderType getType() const; + bool getSynchronizable() const; + void setSynchronizable(const bool &value); + + // tizen::FilterableObject + virtual bool isMatchingAttribute(const std::string& attribute_name, + const tizen::FilterMatchFlag match_flag, + tizen::AnyPtr match_value) const; + + virtual bool isMatchingAttributeRange(const std::string& attribute_name, + tizen::AnyPtr initial_value, + tizen::AnyPtr end_value) const; +private: + MessageFolderType convertPlatformFolderType( + email_mailbox_type_e folderType); + + std::string m_id; + std::string m_parent_id; + bool m_parent_id_set; + std::string m_service_id; + std::string m_content_type; + std::string m_name; + std::string m_path; + MessageFolderType m_type; + bool m_synchronizable; +}; + +} //messaging +} //extension + +#endif // __TIZEN_MESSAGING_MESSAGE_FOLDER_H__ diff --git a/src/messaging/messaging.gyp b/src/messaging/messaging.gyp index 563951f0..2309cfe4 100644 --- a/src/messaging/messaging.gyp +++ b/src/messaging/messaging.gyp @@ -91,7 +91,9 @@ 'change_listener_container.cc', 'change_listener_container.h', 'messages_change_callback.cc', - 'messages_change_callback.h' + 'messages_change_callback.h', + 'message_folder.cc', + 'message_folder.h' ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc index e1b5470f..62b8f99f 100644 --- a/src/messaging/messaging_util.cc +++ b/src/messaging/messaging_util.cc @@ -61,6 +61,8 @@ const char* MESSAGE_ATTACHMENT_ATTRIBUTE_MESSAGE_ID = "messageId"; const char* MESSAGE_ATTACHMENT_ATTRIBUTE_MIME_TYPE = "mimeType"; const char* MESSAGE_ATTACHMENT_ATTRIBUTE_FILE_PATH = "filePath"; +const char* MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID = "serviceId"; + namespace { const std::string TYPE_SMS = "messaging.sms"; const std::string TYPE_MMS = "messaging.mms"; diff --git a/src/messaging/messaging_util.h b/src/messaging/messaging_util.h index 9f251f42..11f31c59 100644 --- a/src/messaging/messaging_util.h +++ b/src/messaging/messaging_util.h @@ -44,18 +44,19 @@ extern const char* MESSAGE_ATTRIBUTE_MESSAGE_STATUS; extern const char* MESSAGE_ATTRIBUTE_ATTACHMENTS; extern const char* MESSAGE_ATTRIBUTE_HAS_ATTACHMENT; extern const char* MESSAGE_ATTRIBUTE_MESSAGE_BODY; +extern const char* MESSAGE_ATTRIBUTE_MESSAGE_ATTACHMENT; extern const char* MESSAGE_BODY_ATTRIBUTE_MESSAGE_ID; extern const char* MESSAGE_BODY_ATTRIBUTE_LOADED; extern const char* MESSAGE_BODY_ATTRIBUTE_PLAIN_BODY; extern const char* MESSAGE_BODY_ATTRIBUTE_HTML_BODY; -extern const char* MESSAGE_ATTRIBUTE_MESSAGE_ATTACHMENT; extern const char* MESSAGE_ATTACHMENT_ATTRIBUTE_ID; extern const char* MESSAGE_ATTACHMENT_ATTRIBUTE_MESSAGE_ID; extern const char* MESSAGE_ATTACHMENT_ATTRIBUTE_MIME_TYPE; extern const char* MESSAGE_ATTACHMENT_ATTRIBUTE_FILE_PATH; +extern const char* MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID; enum MessageType { UNDEFINED = 0, diff --git a/src/messaging/old/MessageFolder.cpp b/src/messaging/old/MessageFolder.cpp index 420006fa..3c952b42 100644 --- a/src/messaging/old/MessageFolder.cpp +++ b/src/messaging/old/MessageFolder.cpp @@ -162,16 +162,16 @@ MessageFolderType MessageFolder::convertPlatformFolderType( */ namespace FOLDER_FILTER_ATTRIBUTE { -const std::string SERVICE_ID = "serviceId"; +const std::string SERVICE_ID = MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID; } //namespace FOLDER_FILTER_ATTRIBUTE bool MessageFolder::isMatchingAttribute(const std::string& attribute_name, const FilterMatchFlag match_flag, AnyPtr match_value) const { - LOGD("Entered"); + LoggerD("Entered"); auto key = match_value->toString(); - LOGD("attribute_name: %s match_flag:%d match_value:%s", attribute_name.c_str(), + LoggerD("attribute_name: %s match_flag:%d match_value:%s", attribute_name.c_str(), match_flag, key.c_str()); using namespace FOLDER_FILTER_ATTRIBUTE; @@ -180,7 +180,7 @@ bool MessageFolder::isMatchingAttribute(const std::string& attribute_name, return FilterUtils::isStringMatching(key, getServiceId() , match_flag); } else { - LOGD("attribute:%s is NOT SUPPORTED", attribute_name.c_str()); + LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str()); } return false; @@ -191,8 +191,8 @@ bool MessageFolder::isMatchingAttributeRange(const std::string& attribute_name, AnyPtr initial_value, AnyPtr end_value) const { - LOGD("Entered"); - LOGD("attribute_name: %s NOT SUPPORTED", attribute_name.c_str()); + LoggerD("Entered"); + LoggerD("attribute_name: %s NOT SUPPORTED", attribute_name.c_str()); return false; } -- 2.34.1