TizenRefApp-7104 Extend ContactPicker to make it work with contacts with no phone... 92/88492/2
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 19 Sep 2016 09:54:35 +0000 (12:54 +0300)
committerAndrey Klimenko <and.klimenko@samsung.com>
Mon, 19 Sep 2016 10:24:09 +0000 (03:24 -0700)
Change-Id: I6e06b20d247a8073c149e6e57dffdb71690715c3
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/ContactManager/inc/ContactManager.h
src/Common/ContactManager/src/ContactManager.cpp
src/Conversation/AppControl/inc/ContactPicker.h
src/Conversation/AppControl/src/ContactPicker.cpp
src/Conversation/Recipients/Controller/inc/ConvRecipientsPanel.h
src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp

index 1fc48d2..53a4077 100644 (file)
@@ -80,6 +80,13 @@ namespace Msg
             ContactPersonNumberRef getContactPersonNumber(int phoneId);
 
             /**
+             *@brief        Search for email-id, name, email and thumbnail path
+             *@param[in]    emailId - identifier of email in contacts-database
+             *@return       Reference to ContactPersonEmail
+             */
+            ContactPersonEmailRef getContactPersonEmail(int emailId);
+
+            /**
              *@brief        Search by email address ContactPersonEmail record
              *@param[in]    email - email address
              *@return       Reference to ContactPersonEmail
index 646df7e..61c61a1 100644 (file)
         return filter ? getContactPersonNumber(filter) : nullptr;
     }
 
+    ContactPersonEmailRef ContactManager::getContactPersonEmail(int emailId)
+    {
+        contacts_filter_h filter = nullptr;
+        contacts_filter_create(_contacts_contact_email._uri, &filter);
+        contacts_filter_add_int(filter, _contacts_person_email.email_id, CONTACTS_MATCH_EQUAL, emailId);
+        return filter ? getContactPersonEmail(filter) : nullptr;
+    }
+
     ContactPersonNumberRef ContactManager::getContactPersonNumber(const std::string &number)
     {
         contacts_filter_h filter = nullptr;
index 35393e1..c355777 100644 (file)
@@ -29,35 +29,47 @@ namespace Msg
      */
     class ContactPicker
     {
-    public:
-        ContactPicker();
+        public:
+            ContactPicker();
 
-        /**
-         * @brief Sets a listener-object to be notified when pick-operation succeeds.
-         */
-        void setListener(IContactPickerListener *pListener);
+            /**
+             * @brief Sets a listener-object to be notified when pick-operation succeeds.
+             */
+            void setListener(IContactPickerListener *pListener);
 
-        /**
-         * @brief Launches pick-operation.
-         * @param howManyToPick defines a maximum count of contacts allowed to be picked.
-         * @return true in case of success, otherwise returns false.
-         */
-        bool launch(size_t howManyToPick);
+            /**
+             * @brief Launches pick-operation.
+             * @param howManyToPick defines a maximum count of contacts allowed to be picked.
+             * @return true in case of success, otherwise returns false.
+             */
+            bool launch(size_t howManyToPick);
 
-    private:
-        ContactPicker(const ContactPicker&) = delete;
-        ContactPicker& operator=(const ContactPicker&) = delete;
-        void onAppControlRes(app_control_h request, app_control_h reply, app_control_result_e result);
+        private:
+            ContactPicker(const ContactPicker&) = delete;
+            ContactPicker& operator=(const ContactPicker&) = delete;
+            void onAppControlRes(app_control_h request, app_control_h reply, app_control_result_e result);
 
-    private:
-        IContactPickerListener *m_pListener;
+        private:
+            IContactPickerListener *m_pListener;
     };
 
     class IContactPickerListener
     {
-    public:
-        virtual ~IContactPickerListener() {}
-        virtual void onContactsPicked(const std::list<int> &numberIdList) = 0;
+        public:
+            enum AddressType
+            {
+                PhoneType,
+                EmailType
+            };
+            struct ResultData
+            {
+                AddressType type;
+                int id;
+            };
+
+        public:
+            virtual ~IContactPickerListener() {}
+            virtual void onContactsPicked(const std::list<ResultData> &numberIdList) {};
     };
 }
 
index 064e372..c670e4b 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include "ContactPicker.h"
-#include <app_control.h>
 #include "Logger.h"
 
 using namespace Msg;
@@ -26,7 +25,8 @@ namespace
     const char* mimeContact = "application/vnd.tizen.contact";
     const char* single  = "single";
     const char* multiple  = "multiple";
-    const char* resultTypePhone  = "phone";
+    const std::string typePhone  = "phone";
+    const std::string typeEmail  = "email";
 }
 
 ContactPicker::ContactPicker()
@@ -58,13 +58,13 @@ bool ContactPicker::launch(size_t howManyToPick)
             app_control_add_extra_data(svc_handle, APP_CONTROL_DATA_SELECTION_MODE, single);
         }
 
-        //TODO: We have to request a possibility to acquire phone numbers and emails at the same time
-        app_control_add_extra_data(svc_handle, APP_CONTROL_DATA_TYPE, resultTypePhone);
+        static const char *addressesTypes[] = {typePhone.c_str(), typeEmail.c_str()};
+        size_t len = sizeof(addressesTypes) / sizeof(addressesTypes[0]);
+        app_control_add_extra_data_array(svc_handle, APP_CONTROL_DATA_TYPE, addressesTypes, len);
         app_control_set_launch_mode(svc_handle, APP_CONTROL_LAUNCH_MODE_GROUP);
         int ret = app_control_send_launch_request(svc_handle, APP_CONTROL_RES_CALLBACK(ContactPicker, onAppControlRes), this);
         MSG_LOG("launching contacts, result-code: ", ret);
         res = (ret == APP_CONTROL_ERROR_NONE);
-
         app_control_destroy(svc_handle);
     }
 
@@ -75,11 +75,29 @@ void ContactPicker::onAppControlRes(app_control_h request, app_control_h reply,
 {
     if(result == APP_CONTROL_RESULT_SUCCEEDED)
     {
-        std::list<int> phoneNumIds;
-        AppControlUtils::getExtraDataIntArray(reply, APP_CONTROL_DATA_SELECTED, phoneNumIds);
-        if(m_pListener)
+        std::list<int> addressIds;
+        std::list<std::string> types;
+        std::list<IContactPickerListener::ResultData> result;
+
+        AppControlUtils::getExtraDataIntArray(reply, APP_CONTROL_DATA_SELECTED, addressIds);
+        AppControlUtils::getExtraDataArray(reply, APP_CONTROL_DATA_TYPE, types);
+
+        int minLen = std::min(addressIds.size(), types.size());
+        auto itId = addressIds.begin();
+        auto itType = types.begin();
+        for(int i = 0; i < minLen; ++i, ++itId, ++itType)
         {
-            m_pListener->onContactsPicked(phoneNumIds);
+            if(*itType == typePhone)
+                result.push_back({IContactPickerListener::PhoneType, *itId});
+            else if(*itType == typeEmail)
+                result.push_back({IContactPickerListener::EmailType, *itId});
+            else
+            {
+                MSG_LOG_WARN("Unknown type: ", *itType);
+            }
         }
+
+        if(m_pListener)
+            m_pListener->onContactsPicked(result);
     }
 }
index ee968a2..7231495 100644 (file)
@@ -80,7 +80,7 @@ namespace Msg
                               MsgAddress::AddressType addressType = MsgAddress::UnknownAddressType);
 
             // IContactPickerListener
-            virtual void onContactsPicked(const std::list<int> &numberIdList);
+            virtual void onContactsPicked(const std::list<ResultData> &addressIdList);
 
             // IContactManagerListener:
             virtual void onContactChanged();
index 307a288..c53efe3 100644 (file)
@@ -271,25 +271,30 @@ void ConvRecipientsPanel::onPlusButtonClicked()
     addRecipientsFromEntry(true);
 }
 
-void ConvRecipientsPanel::onContactsPicked(const std::list<int> &numberIdList)
+void ConvRecipientsPanel::onContactsPicked(const std::list<ResultData> &addressIdList)
 {
-    int numberOfInvalids = 0;
+    int addressOfInvalids = 0;
     int duplicateRecip = 0;
-    int sizeOfList = numberIdList.size();
-    for(auto phoneNumId : numberIdList)
+    int sizeOfList = addressIdList.size();
+    for(auto &addressData : addressIdList)
     {
-        ContactPersonNumberRef num = m_App.getContactManager().getContactPersonNumber(phoneNumId);
-        if(num)
+        ContactAddressRef address;
+        if(addressData.type == IContactPickerListener::PhoneType)
+            address = m_App.getContactManager().getContactPersonNumber(addressData.id);
+        else if(addressData.type == IContactPickerListener::EmailType)
+            address = m_App.getContactManager().getContactPersonEmail(addressData.id);
+
+        if(address)
         {
-            auto apendStatus = appendItem(num->getAddress(), num->getDispName(), MsgAddress::UnknownAddressType);
+            auto apendStatus = appendItem(address->getAddress(), address->getDispName(), MsgAddress::UnknownAddressType);
             if(apendStatus == MbeRecipients::InvalidRecipStatus)
-                ++numberOfInvalids;
+                ++addressOfInvalids;
             if(apendStatus == MbeRecipients::DuplicatedStatus)
                 ++duplicateRecip;
         }
     }
-    if(numberOfInvalids != 0)
-        appendStatusHandler((numberOfInvalids == sizeOfList) ? MbeRecipients::InvalidAllRecipStatus : MbeRecipients::InvalidSomeRecipStatus);
+    if(addressOfInvalids != 0)
+        appendStatusHandler((addressOfInvalids == sizeOfList) ? MbeRecipients::InvalidAllRecipStatus : MbeRecipients::InvalidSomeRecipStatus);
     else if(duplicateRecip != 0)
         appendStatusHandler(MbeRecipients::DuplicatedStatus);