TizenRefApp-8428 Implement call of external contacts app. by app_control 37/126937/1
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 25 Apr 2017 09:52:38 +0000 (12:52 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 25 Apr 2017 09:52:38 +0000 (12:52 +0300)
Change-Id: I367d91209f5a6b265d45c19c9fd9ec4096258b99
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/AppControl/inc/ContactPicker.h [new file with mode: 0644]
src/Common/AppControl/inc/ContactViewer.h
src/Common/AppControl/src/ContactPicker.cpp [new file with mode: 0644]
src/Common/AppControl/src/ContactViewer.cpp
src/Common/Recipient/inc/Recipient.h
src/Common/Recipient/src/Recipient.cpp
src/Composer/Controller/inc/RecipFrame.h
src/Composer/Controller/src/RecipFrame.cpp
src/MsgThread/Controller/inc/MsgThreadFrame.h
src/MsgThread/Controller/src/MsgThreadFrame.cpp

diff --git a/src/Common/AppControl/inc/ContactPicker.h b/src/Common/AppControl/inc/ContactPicker.h
new file mode 100644 (file)
index 0000000..033dd40
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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_ */
index 83d166fcab7c271ad4779e057e6d8398444f42ba..906316c7cd40a254a2bef675e054313c15b29c9b 100644 (file)
@@ -45,6 +45,12 @@ namespace Msg {
              */
             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);
     };
diff --git a/src/Common/AppControl/src/ContactPicker.cpp b/src/Common/AppControl/src/ContactPicker.cpp
new file mode 100644 (file)
index 0000000..329364b
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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);
+    }
+}
index 40d41f29a9d544e7641dad5eae011ada5002d6c2..b214acae9c1b8528065f8bee69aa3cdefbd6b7a7 100644 (file)
@@ -22,8 +22,7 @@
 
 using namespace Msg;
 
-namespace
-{
+namespace {
     const char *mimeContact = "application/vnd.tizen.contact";
     const char *personContactTypeStr = "person";
     const char *myProfileTypeStr = "my_profile";
@@ -43,7 +42,7 @@ 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 AppControlLauncher::getInst().launch(*this);
+    return launch();
 }
 
 bool ContactViewer::launch(const ContactAddress &address)
@@ -51,6 +50,11 @@ 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)
index 47fe9ebef8ef715e1934b000b5199e23ae920501..bd8b46bc5e8730c4d1b06e5810e770d00dfe5b00 100644 (file)
@@ -57,9 +57,15 @@ namespace Msg {
              * @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;
index 77cd2d68060dbd872585865277642c08bcc074af..d8eaccc0690b1bde5a64403cf778a8af9a1b82de 100644 (file)
@@ -163,3 +163,17 @@ Recipient Recipient::getByThreadId(ThreadId id)
     }
     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;
+}
index 4a9cc5bad5f55d0e32a1ba3747ef5e25d10b1a3f..42b074daf359e5d927ec3488985ee97911ed6f4c 100644 (file)
@@ -20,6 +20,7 @@
 #include "RecipFieldView.h"
 #include "FrameController.h"
 #include "Recipient.h"
+#include "ContactPicker.h"
 
 namespace Msg {
 
@@ -30,7 +31,8 @@ namespace Msg {
 
     class RecipFrame
         : public FrameController
-        , private IRecipFieldViewListener {
+        , private IRecipFieldViewListener
+        , private IContactPickerListener {
 
         public:
             RecipFrame(NaviFrameController &parent);
@@ -54,6 +56,9 @@ namespace Msg {
             // Entry(RecipField):
             void onEntryChanged(Evas_Object *obj, void *event);
 
+            // IContactPickerListener:
+            void onContactsPicked(const std::list<ResultData> &numberIdList) override;
+
             void onInputFramePop(NaviFrameItem &item);
 
         private:
@@ -71,6 +76,7 @@ namespace Msg {
             RecipFieldView *m_pRecipField;
             RecipInputFrame *m_pInputFrame;
             Recipient m_Recip;
+            ContactPicker m_ContactPicker;
     };
 }
 
index b27a22fc05da0785ec183ddd1f1968264750ce57..7982285f536e765d29ba052b9e932f9e7a9fa4ae 100644 (file)
@@ -41,6 +41,8 @@ RecipFrame::RecipFrame(NaviFrameController &parent)
 
     updateRecipFieldButton();
     updateNextButton();
+
+    m_ContactPicker.setListener(this);
 }
 
 RecipFrame::~RecipFrame()
@@ -146,7 +148,7 @@ void RecipFrame::onClearButtonClicked(RecipFieldView &obj)
 void RecipFrame::onContactButtonClicked(RecipFieldView &obj)
 {
     MSG_LOG("");
-    // TODO: impl.
+    m_ContactPicker.launch(1); // How many to pick
 }
 
 void RecipFrame::onInputFramePop(NaviFrameItem &item)
@@ -163,3 +165,13 @@ void RecipFrame::onEntryChanged(Evas_Object *obj, void *event)
     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());
+    }
+}
index 02c75085f3cf6b1773bf0620cfc40fbfa4dd844b..1c98224d383030e4cfeddac1fc317a63cbc89241 100644 (file)
@@ -25,6 +25,7 @@
 #include "CtxPopup.h"
 #include "ThreadList.h"
 #include "MsgTypes.h"
+#include "ContactViewer.h"
 
 namespace Msg {
     class MsgThreadFrame
@@ -89,6 +90,7 @@ namespace Msg {
             BottomButton *m_pDeleteButton;
             SelectButton *m_pSelectButton;
             ThreadList *m_pThreadList;
+            ContactViewer m_ContactViewer;
             Mode m_Mode;
     };
 }
index c87132aed423e1931b4805b2deae65894f05d60e..f9e2bdbf0e876bdb0786f18ec2878b2ed403f34d 100644 (file)
@@ -180,8 +180,8 @@ void MsgThreadFrame::navigateToConvFrame(ThreadId id)
 
 void MsgThreadFrame::navigateToComposeFrame()
 {
-    auto *recipFrame = new RecipFrame(getParent());
-    getParent().push(*recipFrame);
+    auto *frame = new RecipFrame(getParent());
+    getParent().push(*frame);
 }
 
 void MsgThreadFrame::onAttached(ViewItem &item)
@@ -285,4 +285,5 @@ void MsgThreadFrame::onComposeButtonClicked(ThreadList &list)
 void MsgThreadFrame::onContactsButtonClicked(ThreadList &list)
 {
     MSG_LOG("");
+    m_ContactViewer.launch();
 }