Implement view of recipients by app_control 06/133306/3
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 9 Jun 2017 14:45:25 +0000 (17:45 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 12 Jun 2017 07:14:38 +0000 (10:14 +0300)
Change-Id: I4fd1882d92e3262dfad60618d452a00b406cae7a
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/AppControl/inc/ContactViewer.h
src/Common/AppControl/src/ContactViewer.cpp
src/Common/ContactManager/inc/ContactAddress.h
src/Common/ContactManager/inc/ContactManager.h
src/Common/ContactManager/inc/ContactMyProfileEmail.h
src/Common/ContactManager/inc/ContactMyProfileNumber.h
src/Common/ContactManager/inc/ContactPersonEmail.h
src/Common/ContactManager/inc/ContactPersonNumber.h
src/Common/ContactManager/inc/ContactPersonPhoneLog.h
src/Common/ContactManager/src/ContactManager.cpp
src/Common/Controller/src/NaviFrameController.cpp

index 79840982ddd8e43c497a3bfdd5d3efc18d59443d..b79626b2d5022979b1cf8f2fb4f01231387667eb 100644 (file)
@@ -30,14 +30,6 @@ namespace Msg {
             ContactViewer();
             virtual ~ContactViewer();
 
-            /**
-             * @brief Launches view-operation.
-             * @param[in] id Contact person id or MyProfile id
-             * @param[in] ownerType PersonType or MyProfileType
-             * @return true in case of success, otherwise returns false.
-             */
-            bool launch(int id, ContactAddress::OwnerType ownerType);
-
             /**
              * @brief Launches view-operation.
              * @param[in] address reference to ContactAddress object.
@@ -59,6 +51,7 @@ namespace Msg {
             bool launch();
 
         private:
+            void clear();
             const char *toStr(ContactAddress::OwnerType type);
     };
 }
index 25b0d524769fefd07eb36ed250d46f6c0bb1638f..7d63070e0f58bd557306e70f6669cb6ec1afc55f 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "ContactViewer.h"
 #include "Logger.h"
+#include "ContactManager.h"
+#include "App.h"
+#include "ContactPersonPhoneLog.h"
 
 #include <app_control.h>
 #include <string>
@@ -24,43 +27,69 @@ using namespace Msg;
 
 namespace {
     const char *mimeContact = "application/vnd.tizen.contact";
+    const char *mimeLog = "application/vnd.tizen.log";
     const char *personContactTypeStr = "person";
     const char *myProfileTypeStr = "my_profile";
+    const char *contactsAppId = "org.tizen.w-contacts";
 }
 
 ContactViewer::ContactViewer()
 {
     app_control_set_operation(m_Handle, APP_CONTROL_OPERATION_VIEW);
-    app_control_set_mime(m_Handle, mimeContact);
 }
 
 ContactViewer::~ContactViewer()
 {
 }
 
-bool ContactViewer::launch(int id, ContactAddress::OwnerType ownerType)
-{
-    app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_TYPE, toStr(ownerType));
-    app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_ID, std::to_string(id).c_str());
-    return launch();
-}
-
 bool ContactViewer::launch(const ContactAddress &address)
 {
-    return launch(address.getOwnerId(), address.getOwnerType());
+    clear();
+    bool isLog = dynamic_cast<const ContactPersonPhoneLog*>(&address);
+    std::string mime = isLog ? mimeLog : mimeContact;
+    int id = isLog ? address.getId() : address.getOwnerId();
+    app_control_set_mime(m_Handle, mime.c_str());
+    app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_TYPE, toStr(address.getOwnerType()));
+    app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_ID, std::to_string(id).c_str());
+    return AppControlLauncher::getInst().launch(*this);
 }
 
 bool ContactViewer::launch()
 {
+    clear();
+    app_control_set_app_id(m_Handle, contactsAppId);
     return AppControlLauncher::getInst().launch(*this);
 }
 
 bool ContactViewer::launch(const std::string &address)
 {
-    app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_PHONE, address.c_str());
+    clear();
+
+    auto rec = App::getInst().getContactManager().getContactAddress(address);
+    if (rec)
+        return launch(*rec);
+
+    app_control_set_mime(m_Handle, mimeLog);
+    if (MsgUtils::isValidNumber(address))
+        app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_PHONE, address.c_str());
+    else if (MsgUtils::isValidEmail(address))
+        app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_EMAIL, address.c_str());
+    else
+        return false;
+
     return launch();
 }
 
+void ContactViewer::clear()
+{
+    app_control_set_app_id(m_Handle, nullptr);
+    app_control_set_mime(m_Handle, nullptr);
+    app_control_remove_extra_data(m_Handle, APP_CONTROL_DATA_PHONE);
+    app_control_remove_extra_data(m_Handle, APP_CONTROL_DATA_EMAIL);
+    app_control_remove_extra_data(m_Handle, APP_CONTROL_DATA_TYPE);
+    app_control_remove_extra_data(m_Handle, APP_CONTROL_DATA_ID);
+}
+
 const char *ContactViewer::toStr(ContactAddress::OwnerType type)
 {
     switch (type)
index b53a612573ac110c2af901ed9548119170815944..50b7f4ca61dfd6942c1494c12ded9302b5c06349 100644 (file)
@@ -28,23 +28,18 @@ namespace Msg {
         : public ContactRecord {
 
         public:
-            enum AddressType {
-                EmailType,
-                NumberType
-            };
-
             enum OwnerType {
                 PersonType,
-                MyProfileType
+                MyProfileType,
             };
 
         public:
             ContactAddress();
             ContactAddress(bool release, contacts_record_h record = nullptr);
             virtual ~ContactAddress() {};
-            virtual AddressType getAddressType() const = 0;
             virtual OwnerType getOwnerType() const = 0;
             virtual int getOwnerId() const = 0;
+            virtual int getId() const = 0;
             virtual std::string getDispName() const = 0;
             virtual std::string getAddress() const = 0; // Email or Number
             virtual std::string getThumbnailPath() const = 0;
index daf1b33833ad3b3c85b83f38f08477e4d49745ed..dc685ad46241afced581a9f1b81782b5b408a8f7 100644 (file)
@@ -91,6 +91,13 @@ namespace Msg {
              */
             ContactPersonEmailRef getContactPersonEmail(const std::string &email);
 
+            /**
+             *@brief        Search by number or email ContactPersonPhoneLog record
+             *@param[in]    address - number or email address
+             *@return       Reference to ContactPersonPhoneLog
+             */
+            ContactPersonPhoneLogRef getContactPersonPhoneLog(const std::string &address);
+
             /**
              *@brief        Search by number address ContactMyProfileNumber record
              *@param[in]    number - phone number
@@ -164,6 +171,7 @@ namespace Msg {
              */
             ContactPersonNumberRef getContactPersonNumber(contacts_filter_h filter);
             ContactPersonEmailRef getContactPersonEmail(contacts_filter_h filter);
+            ContactPersonPhoneLogRef getContactPersonPhoneLog(contacts_filter_h filter);
 
             /**
              *@brief        Search by phone number ContactPersonNumber record
index 9b2366efdc8a9f9107d5407dba600d42a1fbcba2..90b86aa711537e7022b04495a3ff9a239557b3f7 100644 (file)
@@ -30,12 +30,11 @@ namespace Msg {
         public:
             ContactMyProfileEmail(bool release, const ContactMyProfile &myProfile, contacts_record_h record = nullptr);
             static const char *getUri();
-            int getId() const;
 
             // ContactAddress:
-            AddressType getAddressType() const override;
             OwnerType getOwnerType() const override;
             int getOwnerId() const override;
+            int getId() const override;
             std::string getDispName() const override;
             std::string getAddress() const override;
             std::string getThumbnailPath() const override;
@@ -90,11 +89,6 @@ namespace Msg {
         return MyProfileType;
     }
 
-    inline ContactMyProfileNumber::AddressType ContactMyProfileEmail::getAddressType() const
-    {
-        return EmailType;
-    }
-
     inline ContactRecordRef ContactMyProfileEmail::clone() const
     {
         return cloneInternal<ContactMyProfileEmail>();
index b9ac7849634400b673281ede9ea42e49eb65ead9..79a51f54da92309679694e405f481c4ae7fad963 100644 (file)
@@ -31,12 +31,11 @@ namespace Msg {
         public:
             ContactMyProfileNumber(bool release, const ContactMyProfile &myProfile, contacts_record_h record = nullptr);
             static const char *getUri();
-            int getId() const;
 
             // ContactAddress:
-            AddressType getAddressType() const override;
             OwnerType getOwnerType() const override;
             int getOwnerId() const override;
+            int getId() const override;
             std::string getDispName() const override;
             std::string getAddress() const override;
             std::string getThumbnailPath() const override;
@@ -91,11 +90,6 @@ namespace Msg {
         return MyProfileType;
     }
 
-    inline ContactMyProfileNumber::AddressType ContactMyProfileNumber::getAddressType() const
-    {
-        return NumberType;
-    }
-
     inline ContactRecordRef ContactMyProfileNumber::clone() const
     {
         return cloneInternal<ContactMyProfileNumber>();
index 0a7bda46295cc1deed364d05a5cf79e926470931..447a68daef8137d1f4f3edee32289831c67bddf9 100644 (file)
@@ -30,12 +30,11 @@ namespace Msg {
         public:
             ContactPersonEmail(bool release, contacts_record_h record = nullptr);
             static const char *getUri();
-            int getEmailId() const;
 
             // ContactAddress:
             OwnerType getOwnerType() const override;
-            AddressType getAddressType() const override;
             int getOwnerId() const override;
+            int getId() const override;
             std::string getDispName() const override;
             std::string getAddress() const override;
             std::string getThumbnailPath() const override;
@@ -47,7 +46,7 @@ namespace Msg {
     {
     }
 
-    inline int ContactPersonEmail::getEmailId() const
+    inline int ContactPersonEmail::getId() const
     {
         return getInt(_contacts_person_email.email_id);
     }
@@ -82,11 +81,6 @@ namespace Msg {
         return PersonType;
     }
 
-    inline ContactPersonEmail::AddressType ContactPersonEmail::getAddressType() const
-    {
-        return EmailType;
-    }
-
     inline ContactRecordRef ContactPersonEmail::clone() const
     {
         return cloneInternal<ContactPersonEmail>();
index 950021d7911e28ba5844210f352665d36e839c11..55b3237447aa2022dbacbab4827cc78b6228b2cd 100644 (file)
@@ -30,12 +30,11 @@ namespace Msg {
         public:
             ContactPersonNumber(bool release, contacts_record_h record = nullptr);
             static const char *getUri();
-            int getNumberId() const;
 
             // ContactAddress:
             OwnerType getOwnerType() const override;
-            AddressType getAddressType() const override;
             int getOwnerId() const override;
+            int getId() const override;
             std::string getDispName() const override;
             std::string getAddress() const override;
             std::string getThumbnailPath() const override;
@@ -47,7 +46,7 @@ namespace Msg {
     {
     }
 
-    inline int ContactPersonNumber::getNumberId() const
+    inline int ContactPersonNumber::getId() const
     {
         return getInt(_contacts_person_number.number_id);
     }
@@ -82,11 +81,6 @@ namespace Msg {
         return PersonType;
     }
 
-    inline ContactPersonNumber::AddressType ContactPersonNumber::getAddressType() const
-    {
-        return NumberType;
-    }
-
     inline ContactRecordRef ContactPersonNumber::clone() const
     {
         return cloneInternal<ContactPersonNumber>();
index a6932cb465460767f377ff7d06488877722f318b..58e254bed8b0f48ec8add86fc86808499bec5f5c 100644 (file)
 #define __ContactPersonPhoneLog_h__
 
 #include "ContactRecord.h"
+#include "ContactAddress.h"
 
 namespace Msg {
     class ContactPersonPhoneLog;
     typedef std::shared_ptr<ContactPersonPhoneLog> ContactPersonPhoneLogRef;
 
     class ContactPersonPhoneLog
-        : public ContactRecord {
+        : public ContactAddress {
+
         public:
             ContactPersonPhoneLog(bool release, contacts_record_h record = nullptr);
             static const char *getUri();
-            int getId() const;
-            int getPersonId() const;
-            std::string getAddress() const;
-            std::string getDispName() const;
+
+            // ContactAddress:
+            OwnerType getOwnerType() const override;
+            int getOwnerId() const override;
+            int getId() const override;
+            std::string getDispName() const override;
+            std::string getAddress() const override;
             ContactRecordRef clone() const override;
+            std::string getThumbnailPath() const override;
     };
 
     inline ContactPersonPhoneLog::ContactPersonPhoneLog(bool release, contacts_record_h record)
-        : ContactRecord(release, record)
+        : ContactAddress(release, record)
     {
     }
 
@@ -45,7 +51,7 @@ namespace Msg {
         return getInt(_contacts_person_phone_log.log_id);
     }
 
-    inline int ContactPersonPhoneLog::getPersonId() const
+    inline int ContactPersonPhoneLog::getOwnerId() const
     {
         return getInt(_contacts_person_phone_log.person_id);
     }
@@ -60,6 +66,11 @@ namespace Msg {
         return getStr(_contacts_person_phone_log.address);
     }
 
+    inline std::string ContactPersonPhoneLog::getThumbnailPath() const
+    {
+        return getStr(_contacts_person_phone_log.image_thumbnail_path);
+    }
+
     inline const char *ContactPersonPhoneLog::getUri()
     {
         return _contacts_person_phone_log._uri;
@@ -69,6 +80,11 @@ namespace Msg {
     {
         return cloneInternal<ContactPersonPhoneLog>();
     }
+
+    inline ContactPersonPhoneLog::OwnerType ContactPersonPhoneLog::getOwnerType() const
+    {
+        return PersonType;
+    }
 }
 
 
index 5c0befdbc28a6c00b2716eff3ec79b68f3e97f33..4115bd7ebe835ce189a74559ce533d30b1c75d0d 100644 (file)
     ContactPersonEmailRef ContactManager::getContactPersonEmail(const std::string &email)
     {
         contacts_filter_h filter = nullptr;
-        contacts_filter_create(_contacts_person_email._uri, &filter);
-        contacts_filter_add_str(filter, _contacts_person_email.email, CONTACTS_MATCH_EXACTLY, email.c_str());
+        contacts_filter_create(_contacts_contact_email._uri, &filter);
+        contacts_filter_add_str(filter, _contacts_person_email.email, CONTACTS_MATCH_FULLSTRING, email.c_str());
         return filter ? getContactPersonEmail(filter) : nullptr;
     }
 
+    ContactPersonPhoneLogRef ContactManager::getContactPersonPhoneLog(const std::string &address)
+    {
+        contacts_filter_h filter = nullptr;
+        contacts_filter_create(_contacts_person_phone_log._uri, &filter);
+        contacts_filter_add_str(filter, _contacts_person_email.email, CONTACTS_MATCH_FULLSTRING, address.c_str());
+        return filter ? getContactPersonPhoneLog(filter) : nullptr;
+    }
+
     ContactMyProfileNumberRef ContactManager::getContactMyProfileNumber(const std::string &number)
     {
         auto myProfile = getOwnerProfile();
         return cResValue ? std::make_shared<ContactPersonEmail>(true, cResValue) : nullptr;
     }
 
+    ContactPersonPhoneLogRef ContactManager::getContactPersonPhoneLog(contacts_filter_h filter)
+    {
+        contacts_query_h query = nullptr;
+        contacts_list_h list = nullptr;
+        contacts_record_h crValue = nullptr;
+        contacts_record_h cResValue = nullptr;
+
+        contacts_query_create(_contacts_person_phone_log._uri, &query);
+        contacts_query_set_filter(query, filter);
+
+        unsigned int projection[] = {
+            _contacts_person_phone_log.person_id,
+            _contacts_person_phone_log.address,
+            _contacts_person_phone_log.display_name,
+            _contacts_person_phone_log.image_thumbnail_path
+        };
+
+        int ctRrr = contacts_query_set_projection(query, projection, sizeof(projection) / sizeof(unsigned int));
+        if (ctRrr == CONTACTS_ERROR_NONE)
+            ctRrr = contacts_db_get_records_with_query(query, 0, 0, &list);
+
+        contacts_filter_destroy(filter);
+        contacts_query_destroy(query);
+
+        while (ctRrr == CONTACTS_ERROR_NONE) {
+            int logId = 0;
+
+            contacts_list_get_current_record_p(list, &crValue);
+            if (crValue) {
+                contacts_record_get_int(crValue, _contacts_person_phone_log.log_id, &logId);
+                if (logId > 0)
+                    cResValue = crValue;
+                else
+                    contacts_record_destroy(crValue, true);
+            }
+            ctRrr = contacts_list_next(list);
+        }
+
+        contacts_list_destroy(list, false);
+        return cResValue ? std::make_shared<ContactPersonPhoneLog>(true, cResValue) : nullptr;
+    }
+
     ContactAddressRef ContactManager::getAddress(const std::string &address)
     {
         auto it = m_AddressMap.find(address);
             else
                 contactAddress = getContactPersonEmail(address);
 
+
             // MyProfile:
             #if (0)
             if (!contactAddress)
             }
             #endif
 
+            if (!contactAddress)
+                contactAddress = getContactPersonPhoneLog(address);
+
             m_AddressMap[address] = contactAddress;
             return contactAddress;
         }
index fd705691e74e6124c5ce4c1e7db35fe76d331414..b3f163d5bfae0a5c74e40ec7e2bad8610cebe2f6 100644 (file)
@@ -91,7 +91,6 @@ bool NaviFrameController::prepare(const AppControlCommand &cmd)
 void NaviFrameController::execCmd(const AppControlDefaultRef &cmd)
 {
     if (prepare(*cmd)) {
-        AppControlLauncher::getInst().terminate();
         AppControlDefault::DefaultType type = cmd->getDefaultType();
         auto *thread = findTopFrame<MsgThreadFrame>(); // Check if thread is open
         if (!thread)
@@ -102,9 +101,11 @@ void NaviFrameController::execCmd(const AppControlDefaultRef &cmd)
             if (msg) {
                 auto *conv = findTopFrame<ConvFrame>(); // Check if conversation is open
                 if (conv) {
+                    AppControlLauncher::getInst().terminate();
                     promote(*conv);
                     conv->execCmd(cmd);
                 } else if (type == AppControlDefault::ViewType || type == AppControlDefault::ReplyType || isUnreadNotificationSingle(type)) {
+                    AppControlLauncher::getInst().terminate();
                     conv = new ConvFrame(*this);
                     push(*conv);
                     conv->execCmd(cmd);