From: Denis Dolzhenko Date: Mon, 19 Sep 2016 09:54:35 +0000 (+0300) Subject: TizenRefApp-7104 Extend ContactPicker to make it work with contacts with no phone... X-Git-Tag: submit/tizen/20160926.072415^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F92%2F88492%2F2;p=profile%2Fmobile%2Fapps%2Fnative%2Fmessage.git TizenRefApp-7104 Extend ContactPicker to make it work with contacts with no phone number but with email Change-Id: I6e06b20d247a8073c149e6e57dffdb71690715c3 Signed-off-by: Denis Dolzhenko --- diff --git a/src/Common/ContactManager/inc/ContactManager.h b/src/Common/ContactManager/inc/ContactManager.h index 1fc48d2..53a4077 100644 --- a/src/Common/ContactManager/inc/ContactManager.h +++ b/src/Common/ContactManager/inc/ContactManager.h @@ -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 diff --git a/src/Common/ContactManager/src/ContactManager.cpp b/src/Common/ContactManager/src/ContactManager.cpp index 646df7e..61c61a1 100644 --- a/src/Common/ContactManager/src/ContactManager.cpp +++ b/src/Common/ContactManager/src/ContactManager.cpp @@ -146,6 +146,14 @@ 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; diff --git a/src/Conversation/AppControl/inc/ContactPicker.h b/src/Conversation/AppControl/inc/ContactPicker.h index 35393e1..c355777 100644 --- a/src/Conversation/AppControl/inc/ContactPicker.h +++ b/src/Conversation/AppControl/inc/ContactPicker.h @@ -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 &numberIdList) = 0; + public: + enum AddressType + { + PhoneType, + EmailType + }; + struct ResultData + { + AddressType type; + int id; + }; + + public: + virtual ~IContactPickerListener() {} + virtual void onContactsPicked(const std::list &numberIdList) {}; }; } diff --git a/src/Conversation/AppControl/src/ContactPicker.cpp b/src/Conversation/AppControl/src/ContactPicker.cpp index 064e372..c670e4b 100644 --- a/src/Conversation/AppControl/src/ContactPicker.cpp +++ b/src/Conversation/AppControl/src/ContactPicker.cpp @@ -16,7 +16,6 @@ */ #include "ContactPicker.h" -#include #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 phoneNumIds; - AppControlUtils::getExtraDataIntArray(reply, APP_CONTROL_DATA_SELECTED, phoneNumIds); - if(m_pListener) + std::list addressIds; + std::list types; + std::list 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); } } diff --git a/src/Conversation/Recipients/Controller/inc/ConvRecipientsPanel.h b/src/Conversation/Recipients/Controller/inc/ConvRecipientsPanel.h index ee968a2..7231495 100644 --- a/src/Conversation/Recipients/Controller/inc/ConvRecipientsPanel.h +++ b/src/Conversation/Recipients/Controller/inc/ConvRecipientsPanel.h @@ -80,7 +80,7 @@ namespace Msg MsgAddress::AddressType addressType = MsgAddress::UnknownAddressType); // IContactPickerListener - virtual void onContactsPicked(const std::list &numberIdList); + virtual void onContactsPicked(const std::list &addressIdList); // IContactManagerListener: virtual void onContactChanged(); diff --git a/src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp b/src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp index 307a288..c53efe3 100644 --- a/src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp +++ b/src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp @@ -271,25 +271,30 @@ void ConvRecipientsPanel::onPlusButtonClicked() addRecipientsFromEntry(true); } -void ConvRecipientsPanel::onContactsPicked(const std::list &numberIdList) +void ConvRecipientsPanel::onContactsPicked(const std::list &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);