TizenRefApp-5907 Implement support of vcard result type in the Pick operation 48/62348/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 15 Mar 2016 11:49:44 +0000 (13:49 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Thu, 17 Mar 2016 07:30:58 +0000 (00:30 -0700)
Change-Id: I73fa3b573ff47e9065f6f69ce38e568a878f29cf
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-contact/inc/Contacts/Common/Chooser.h
lib-contact/inc/Contacts/Common/ContactSelectTypes.h
lib-contact/src/Contacts/Common/Chooser.cpp
lib-contact/src/Contacts/List/ListView.cpp
main-app/inc/OperationPickController.h
main-app/src/OperationPickController.cpp

index 28d6387..a7bc9d3 100644 (file)
@@ -53,6 +53,7 @@ namespace Contacts
                        bool onSinglePersonSelected(SelectResults personResults);
                        bool onMultiPersonSelected(SelectResults personResults);
                        bool onSelected(SelectResults results);
+                       bool onSelectedForVcard(SelectResults results);
 
                        static int getSingleResultId(int personId, ResultType resultType);
                        static int getFilterType(ResultType resultType);
index fe378e4..d89e800 100644 (file)
@@ -42,7 +42,8 @@ namespace Contacts
                ResultMyProfile = Model::ObjectTypeMyProfile, /**< My Profile ID is the result */
                ResultPerson    = Model::ObjectTypeContact,   /**< Person ID is the result */
                ResultNumber    = Model::ObjectTypeNumber,    /**< Number ID is the result */
-               ResultEmail     = Model::ObjectTypeEmail      /**< Email ID is the result */
+               ResultEmail     = Model::ObjectTypeEmail,     /**< Email ID is the result */
+               ResultVcard
        };
 }
 
index 319d752..c899e4c 100644 (file)
@@ -18,6 +18,7 @@
 #include "Contacts/Common/Chooser.h"
 #include "Contacts/Details/DetailsView.h"
 #include "Contacts/List/ListView.h"
+#include "Contacts/Settings/ExportController.h"
 #include "Contacts/Utils.h"
 #include "Utils/Logger.h"
 
@@ -56,6 +57,9 @@ void Chooser::onCreated()
                                view->setSelectCallback(std::bind(&Chooser::onMultiPersonSelected, this, _1));
                        }
                        break;
+               case ResultVcard:
+                       view->setSelectCallback(std::bind(&Chooser::onSelectedForVcard, this, _1));
+                       break;
                default:
                        break;
        }
@@ -116,6 +120,29 @@ bool Chooser::onSelected(SelectResults results)
        return false;
 }
 
+bool Chooser::onSelectedForVcard(SelectResults results)
+{
+       using namespace Settings;
+
+       std::vector<int> ids;
+       ids.reserve(results.count());
+       for (auto &&result : results) {
+               ids.push_back(result.value.id);
+       }
+
+       auto exporter = new ExportController(getEvasObject(), "IDS_PB_HEADER_EXPORT_CONTACTS_ABB",
+                       std::move(ids), StorageInternalOther);
+       exporter->setFinishCallback([this, exporter] {
+               SelectResult result = { ResultVcard, (void *) exporter->getVcardPath().c_str() };
+               if (!m_OnSelected || m_OnSelected({ &result, 1 })) {
+                       getPage()->close();
+               }
+       });
+       exporter->run();
+
+       return false;
+}
+
 int Chooser::getSingleResultId(int personId, ResultType resultType)
 {
        int resultId = 0;
index 545de0c..69c1f39 100644 (file)
@@ -112,11 +112,14 @@ void ListView::onMenuPressed()
 
 const char *ListView::getPageTitle() const
 {
-       if (getSelectMode() == SelectNone) {
-               return "IDS_PB_TAB_CONTACTS";
+       switch (getSelectMode()) {
+               case SelectNone:
+                       return "IDS_PB_TAB_CONTACTS";
+               case SelectSingle:
+                       return "IDS_PB_HEADER_SELECT_CONTACT_ABB2";
+               default:
+                       return SelectView::getPageTitle();
        }
-
-       return SelectView::getPageTitle();
 }
 
 void ListView::onSelectAllInsert(Ui::GenlistItem *item)
index 6e6f8ee..c42138b 100644 (file)
@@ -37,6 +37,10 @@ private:
        virtual void onRequest(Operation operation, app_control_h request) override;
        bool onSelected(Contacts::SelectResults results);
 
+       void replyIds(Contacts::SelectResults results);
+       void replyPath(Contacts::SelectResults results);
+       void replyResults(const char **results, size_t count);
+
        static Contacts::SelectMode getSelectMode(app_control_h request);
        static Contacts::ResultType getResultType(app_control_h request);
        static const char *getResultTypeString(Contacts::ResultType resultType);
index a84a181..da3bc49 100644 (file)
@@ -50,6 +50,17 @@ void OperationPickController::onRequest(Operation operation, app_control_h reque
 
 bool OperationPickController::onSelected(SelectResults results)
 {
+       if (m_ResultType == ResultVcard) {
+               replyPath(results);
+       } else {
+               replyIds(results);
+       }
+
+       return true;
+}
+
+void OperationPickController::replyIds(Contacts::SelectResults results)
+{
        size_t count = results.count();
        std::vector<char[ID_BUFFER_SIZE]> buffers(count);
        std::vector<const char *> ids(count);
@@ -59,16 +70,25 @@ bool OperationPickController::onSelected(SelectResults results)
                ids[i] = buffers[i];
        }
 
+       replyResults(ids.data(), ids.size());
+}
+
+void OperationPickController::replyPath(Contacts::SelectResults results)
+{
+       auto &result = *results.begin();
+       replyResults((const char **) &result.value.data, 1);
+}
+
+void OperationPickController::replyResults(const char **results, size_t count)
+{
        app_control_h reply = nullptr;
        app_control_create(&reply);
 
        app_control_add_extra_data(reply, APP_CONTROL_DATA_TYPE, getResultTypeString(m_ResultType));
-       app_control_add_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, ids.data(), ids.size());
+       app_control_add_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, results, count);
 
        app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
        app_control_destroy(reply);
-
-       return true;
 }
 
 SelectMode OperationPickController::getSelectMode(app_control_h request)
@@ -101,6 +121,8 @@ ResultType OperationPickController::getResultType(app_control_h request)
                        return ResultNumber;
                } else if (strcmp(resultType, APP_CONTROL_RESULT_EMAIL) == 0) {
                        return ResultEmail;
+               } else if (strcmp(resultType, APP_CONTROL_RESULT_VCARD) == 0) {
+                       return ResultVcard;
                }
 
                free(resultType);
@@ -119,6 +141,8 @@ const char *OperationPickController::getResultTypeString(ResultType resultType)
                        return APP_CONTROL_RESULT_PHONE;
                case ResultEmail:
                        return APP_CONTROL_RESULT_EMAIL;
+               case ResultVcard:
+                       return APP_CONTROL_RESULT_VCARD;
        }
 
        return APP_CONTROL_RESULT_ID;