--- /dev/null
+/*
+ * Copyright 2016 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ContactPicker_h_
+#define ContactPicker_h_
+
+#include "AppControlUtils.h"
+#include "AppControlLauncher.h"
+
+namespace Msg {
+ class IContactPickerListener;
+
+ /**
+ * @brief An utility-class aimed to launch contacts-application with pick-operation passed via app-control.
+ */
+ class ContactPicker
+ : public AppControlHandle {
+ public:
+ ContactPicker();
+
+ /**
+ * @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);
+
+ private:
+ virtual void onReply(app_control_h request, app_control_h reply, app_control_result_e result);
+
+ private:
+ IContactPickerListener *m_pListener;
+ };
+
+ class IContactPickerListener {
+ public:
+ enum AddressType {
+ PhoneType,
+ EmailType
+ };
+ struct ResultData {
+ AddressType type;
+ int id;
+ };
+
+ public:
+ virtual ~IContactPickerListener() {}
+ virtual void onContactsPicked(const std::list<ResultData> &numberIdList) {};
+ };
+}
+
+#endif /* ContactPicker_h_ */
*/
bool launch(const ContactAddress &address);
+ /**
+ * @brief Launches view-operation.
+ * @return true in case of success, otherwise returns false.
+ */
+ bool launch();
+
private:
const char *toStr(ContactAddress::OwnerType type);
};
--- /dev/null
+/*
+ * Copyright 2016 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ContactPicker.h"
+#include "Logger.h"
+
+using namespace Msg;
+
+namespace {
+ const char* mimeContact = "application/vnd.tizen.contact";
+ const char* single = "single";
+ const char* multiple = "multiple";
+ const std::string typePhone = "phone";
+ const std::string typeEmail = "email";
+}
+
+ContactPicker::ContactPicker()
+ : m_pListener(nullptr)
+{
+ app_control_set_operation(m_Handle, APP_CONTROL_OPERATION_PICK);
+ app_control_set_mime(m_Handle, mimeContact);
+}
+
+void ContactPicker::setListener(IContactPickerListener *pListener)
+{
+ m_pListener = pListener;
+}
+
+bool ContactPicker::launch(size_t howManyToPick)
+{
+ bool res = false;
+ if (m_Handle) {
+ if (howManyToPick > 1) {
+ app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_SELECTION_MODE, multiple);
+ app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_TOTAL_COUNT, std::to_string(howManyToPick).c_str());
+ } else {
+ app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_SELECTION_MODE, single);
+ }
+
+ // Email:
+ #if (0)
+ static const char *addressesTypes[] = {typePhone.c_str(), typeEmail.c_str()};
+ size_t len = sizeof(addressesTypes) / sizeof(addressesTypes[0]);
+ app_control_add_extra_data_array(m_Handle, APP_CONTROL_DATA_TYPE, addressesTypes, len);
+ #endif
+
+ res = AppControlLauncher::getInst().launch(*this);
+ }
+
+ return res;
+}
+
+void ContactPicker::onReply(app_control_h request, app_control_h reply, app_control_result_e result)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+ 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) {
+ 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);
+ }
+}
using namespace Msg;
-namespace
-{
+namespace {
const char *mimeContact = "application/vnd.tizen.contact";
const char *personContactTypeStr = "person";
const char *myProfileTypeStr = "my_profile";
{
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 AppControlLauncher::getInst().launch(*this);
+ return launch();
}
bool ContactViewer::launch(const ContactAddress &address)
return launch(address.getOwnerId(), address.getOwnerType());
}
+bool ContactViewer::launch()
+{
+ return AppControlLauncher::getInst().launch(*this);
+}
+
const char *ContactViewer::toStr(ContactAddress::OwnerType type)
{
switch (type)
* @param id valid thread id
* @return recipient
*/
-
static Recipient getByThreadId(ThreadId id);
+ /**
+ * @brief Get recipient by contact person number id
+ * @param id valid contact id
+ * @return recipient
+ */
+ static Recipient getByContactPresonNmberId(int id);
+
private:
std::string m_Address;
std::string m_DispName;
}
return res;
}
+
+Recipient Recipient::getByContactPresonNmberId(int id)
+{
+ Recipient res;
+ auto rec = App::getInst().getContactManager().getContactPersonNumber(id);
+ if (rec) {
+ res.setDispName(rec->getDispName());
+ res.setAddress(rec->getAddress());
+
+ if (res.getDispName().empty())
+ res.setDispName(res.getAddress());
+ }
+ return res;
+}
#include "RecipFieldView.h"
#include "FrameController.h"
#include "Recipient.h"
+#include "ContactPicker.h"
namespace Msg {
class RecipFrame
: public FrameController
- , private IRecipFieldViewListener {
+ , private IRecipFieldViewListener
+ , private IContactPickerListener {
public:
RecipFrame(NaviFrameController &parent);
// Entry(RecipField):
void onEntryChanged(Evas_Object *obj, void *event);
+ // IContactPickerListener:
+ void onContactsPicked(const std::list<ResultData> &numberIdList) override;
+
void onInputFramePop(NaviFrameItem &item);
private:
RecipFieldView *m_pRecipField;
RecipInputFrame *m_pInputFrame;
Recipient m_Recip;
+ ContactPicker m_ContactPicker;
};
}
updateRecipFieldButton();
updateNextButton();
+
+ m_ContactPicker.setListener(this);
}
RecipFrame::~RecipFrame()
void RecipFrame::onContactButtonClicked(RecipFieldView &obj)
{
MSG_LOG("");
- // TODO: impl.
+ m_ContactPicker.launch(1); // How many to pick
}
void RecipFrame::onInputFramePop(NaviFrameItem &item)
updateNextButton();
updateRecipFieldButton();
}
+
+void RecipFrame::onContactsPicked(const std::list<ResultData> &numberIdList)
+{
+ MSG_LOG("");
+ if (!numberIdList.empty() && numberIdList.front().type == IContactPickerListener::PhoneType) {
+ m_Recip = Recipient::getByContactPresonNmberId(numberIdList.front().id);
+ if (m_Recip.isValid())
+ m_pRecipField->getEntry().setText(m_Recip.getDispName());
+ }
+}
#include "CtxPopup.h"
#include "ThreadList.h"
#include "MsgTypes.h"
+#include "ContactViewer.h"
namespace Msg {
class MsgThreadFrame
BottomButton *m_pDeleteButton;
SelectButton *m_pSelectButton;
ThreadList *m_pThreadList;
+ ContactViewer m_ContactViewer;
Mode m_Mode;
};
}
void MsgThreadFrame::navigateToComposeFrame()
{
- auto *recipFrame = new RecipFrame(getParent());
- getParent().push(*recipFrame);
+ auto *frame = new RecipFrame(getParent());
+ getParent().push(*frame);
}
void MsgThreadFrame::onAttached(ViewItem &item)
void MsgThreadFrame::onContactsButtonClicked(ThreadList &list)
{
MSG_LOG("");
+ m_ContactViewer.launch();
}