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
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;
*/
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) {};
};
}
*/
#include "ContactPicker.h"
-#include <app_control.h>
#include "Logger.h"
using namespace Msg;
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()
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);
}
{
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);
}
}
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();
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);