TizenRefApp-6080 Create a separate view for "View vCard" operation 71/65271/4
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 8 Apr 2016 07:09:54 +0000 (10:09 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 11 Apr 2016 12:30:38 +0000 (15:30 +0300)
Change-Id: I12de34c7ac9a581927ec39da80dd1de62eb9a74e
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
20 files changed:
contacts-app/inc/OperationController.h
contacts-app/inc/OperationDefaultController.h
contacts-app/inc/OperationViewController.h
contacts-app/src/OperationController.cpp
contacts-app/src/OperationDefaultController.cpp
contacts-app/src/OperationViewController.cpp
lib-common/inc/Contacts/Model/ContactData.h
lib-common/src/Contacts/Model/ContactData.cpp
lib-contacts/inc/Contacts/List/ContactItem.h [new file with mode: 0644]
lib-contacts/inc/Contacts/List/ListView.h
lib-contacts/inc/Contacts/List/Model/Person.h
lib-contacts/inc/Contacts/List/Model/VcardProvider.h
lib-contacts/inc/Contacts/List/PersonItem.h
lib-contacts/inc/Contacts/List/VcardView.h [new file with mode: 0644]
lib-contacts/src/Contacts/List/ContactItem.cpp [new file with mode: 0644]
lib-contacts/src/Contacts/List/ListView.cpp
lib-contacts/src/Contacts/List/Model/Person.cpp
lib-contacts/src/Contacts/List/Model/VcardProvider.cpp
lib-contacts/src/Contacts/List/PersonItem.cpp
lib-contacts/src/Contacts/List/VcardView.cpp [new file with mode: 0644]

index 7a86238..7ff18b3 100644 (file)
@@ -18,8 +18,9 @@
 #ifndef OPERATION_CONTROLLER_H
 #define OPERATION_CONTROLLER_H
 
-#include <app_control.h>
+#include <app.h>
 #include <Evas.h>
+#include <string>
 
 namespace Ui
 {
@@ -104,6 +105,13 @@ protected:
        app_control_h getRequest() const;
 
        /**
+        * @brief Get URI without prefix (if present).
+        * @param[in]   scheme  Scheme prefix to remove (e.g. tel: or file://)
+        * @return URI without scheme.
+        */
+       std::string getUrn(const char *scheme) const;
+
+       /**
         * @brief Send failure reply to the last request
         */
        void replyFailure();
index b59ec93..904265d 100644 (file)
@@ -46,9 +46,7 @@ private:
        virtual void onCreate() override;
        virtual void onRequest(Operation operation, app_control_h request) override;
 
-       static std::string getPhoneNumber(app_control_h appControl);
        static unsigned getBadgeCount(const char *package);
-
        void saveLastTab();
        static TabId getLastTab();
 
index a18133a..0680d7c 100644 (file)
 #define OPERATION_VIEW_CONTROLLER_H
 
 #include "OperationController.h"
-#include "Ux/SelectTypes.h"
-
-namespace Contacts
-{
-       namespace List
-       {
-               class ListView;
-       }
-       namespace Settings
-       {
-               class ImportController;
-       }
-}
 
 class OperationViewController : public OperationController
 {
@@ -40,10 +27,6 @@ public:
 
 private:
        virtual void onRequest(Operation operation, app_control_h request);
-       bool onSelectResult(Ux::SelectResults results,
-                       Contacts::List::ListView *view, std::string uri);
-       void onImportFinish(Contacts::Settings::ImportController *importer,
-                       Contacts::List::ListView *view);
 };
 
-#endif /* _OPERATION_VIEW_CONTROLLER_H_ */
+#endif /* OPERATION_VIEW_CONTROLLER_H */
index 5a54f63..89ec982 100644 (file)
@@ -119,6 +119,30 @@ app_control_h OperationController::getRequest() const
        return m_Request;
 }
 
+std::string OperationController::getUrn(const char *scheme) const
+{
+       char *uri = nullptr;
+       app_control_get_uri(m_Request, &uri);
+       if (!uri) {
+               return "";
+       }
+
+       std::string path;
+       if (scheme) {
+               size_t length = strlen(scheme);
+               if (strncmp(uri, scheme, length) == 0) {
+                       path = uri + length;
+               }
+       }
+
+       if (path.empty()) {
+               path = uri;
+       }
+
+       free(uri);
+       return path;
+}
+
 void OperationController::replyFailure()
 {
        app_control_h reply;
index c89e2f3..cc305f1 100644 (file)
@@ -64,7 +64,7 @@ void OperationDefaultController::onRequest(Operation operation, app_control_h re
        TabId selectedTab = TabContacts;
        if (operation == OperationDial) {
                auto dialer = static_cast<Phone::Dialer::DialerView *>(m_Tabs[TabDialer]);
-               dialer->setNumber(getPhoneNumber(request));
+               dialer->setNumber(getUrn(APP_CONTROL_URI_DIAL));
                selectedTab = TabDialer;
        } else if (appId && strcmp(appId, APP_CONTROL_PHONE_APPID) == 0) {
                if (getBadgeCount(APP_CONTROL_PHONE_APPID) > 0) {
@@ -79,22 +79,6 @@ void OperationDefaultController::onRequest(Operation operation, app_control_h re
        free(appId);
 }
 
-std::string OperationDefaultController::getPhoneNumber(app_control_h appControl)
-{
-       std::string number;
-
-       char *uri = nullptr;
-       app_control_get_uri(appControl, &uri);
-
-       size_t length = sizeof(APP_CONTROL_URI_DIAL) - 1;
-       if (uri && strncmp(uri, APP_CONTROL_URI_DIAL, length) == 0) {
-               number = uri + length;
-       }
-
-       free(uri);
-       return number;
-}
-
 unsigned OperationDefaultController::getBadgeCount(const char *package)
 {
        unsigned count = 0;
index 0508ee2..cca1397 100644 (file)
 
 #include "OperationViewController.h"
 
-#include "MainApp.h"
 #include "Contacts/Details/DetailsView.h"
-#include "Contacts/List/ListView.h"
-#include "Contacts/Settings/ImportController.h"
+#include "Contacts/List/VcardView.h"
 #include "Contacts/Utils.h"
-#include "Utils/Logger.h"
 
 #include "App/AppControlRequest.h"
 #include "Ui/Navigator.h"
+#include "Utils/Logger.h"
 
-#include <notification.h>
 #include <string.h>
+#include <sys/stat.h>
+
+#define APP_CONTROL_URI_PATH "file://"
 
 using namespace Contacts;
 using namespace Contacts::Details;
 using namespace Contacts::List;
 
-#define BUFFER_SIZE        1024
-
 OperationViewController::OperationViewController()
        : OperationController(OperationView)
 {
@@ -53,16 +51,12 @@ void OperationViewController::onRequest(Operation operation, app_control_h reque
                        view = new DetailsView(getDisplayContactId(personId));
                }
        } else {
-               char *uri = NULL;
-               app_control_get_uri(request, &uri);
-               if (uri) {
-                       view = new ListView(uri);
-                       ListView *listView = (ListView *)view;
-                       listView->setSelectMode(Ux::SelectMulti);
-                       listView->setSelectCallback(std::bind(&OperationViewController::onSelectResult, this,
-                                       std::placeholders::_1, listView, std::string(uri)));
-
-                       free(uri);
+               std::string path = getUrn(APP_CONTROL_URI_PATH);
+               struct stat buffer;
+               if (stat(path.c_str(), &buffer) == 0) {
+                       view = new VcardView(path);
+               } else {
+                       ERR("Failed to open file: \"%s\". %s", path.c_str(), strerror(errno));
                }
        }
 
@@ -74,40 +68,3 @@ void OperationViewController::onRequest(Operation operation, app_control_h reque
                ui_app_exit();
        }
 }
-
-bool OperationViewController::onSelectResult(Ux::SelectResults results, ListView *view, std::string uri)
-{
-       std::vector<contacts_record_h> records;
-       for (auto &&result : results) {
-               records.push_back((contacts_record_h)result.value.data);
-       }
-       int count = records.size();
-       if (count) {
-               std::vector<std::string> vcards;
-               vcards.push_back(uri);
-               Settings::ImportController *importer = new Settings::ImportController(view->getEvasObject(),
-                               "IDS_PB_HEADER_IMPORT_CONTACTS_ABB2", count, std::move(vcards), std::move(records));
-               importer->setFinishCallback(std::bind(&OperationViewController::onImportFinish, this, importer, view));
-               importer->run();
-       }
-
-       return false;
-}
-
-void OperationViewController::onImportFinish(Settings::ImportController *importer, ListView *view)
-{
-       int count = importer->getTotalCount();
-       RETM_IF(count <= 0, "invalid count");
-       int err = NOTIFICATION_ERROR_NONE;
-
-       if (count == 1) {
-               err = notification_status_message_post(_("IDS_PB_TPOP_1_CONTACT_IMPORTED"));
-       } else {
-               char text[BUFFER_SIZE] = { 0, };
-               snprintf(text, sizeof(text), _("IDS_PB_TPOP_PD_CONTACTS_IMPORTED"), count);
-               err = notification_status_message_post(text);
-       }
-       WARN_IF_ERR(err, "notification_status_message_post() failed.");
-
-       view->getPage()->close();
-}
index e6c7b1c..ef4dd1a 100644 (file)
 #include <tizen.h>
 #include <list>
 
-namespace Utils
-{
-       class UniString;
-}
-
 namespace Contacts
 {
        namespace Model
@@ -147,11 +142,6 @@ namespace Contacts
                         */
                        void unsetDeleteCallback();
 
-                       /**
-                        * @return First letter from formatted person name
-                        */
-                       virtual const Utils::UniString *getIndexLetter() const;
-
                protected:
                        /**
                         * @brief ContactData updated callback
index b69ee9e..34ffa63 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include "Contacts/Model/ContactData.h"
-#include "Utils/UniString.h"
 
 using namespace Contacts::Model;
 
@@ -50,11 +49,6 @@ void ContactData::unsetDeleteCallback()
        m_OnDeleted = nullptr;
 }
 
-const Utils::UniString *ContactData::getIndexLetter() const
-{
-       return nullptr;
-}
-
 void ContactData::onUpdated(int changes)
 {
        if (m_OnUpdated) {
diff --git a/lib-contacts/inc/Contacts/List/ContactItem.h b/lib-contacts/inc/Contacts/List/ContactItem.h
new file mode 100644 (file)
index 0000000..01e3eaa
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_LIST_CONTACT_ITEM_H
+#define CONTACTS_LIST_CONTACT_ITEM_H
+
+#include "Ux/SelectItem.h"
+
+#define PART_CONTACT_NAME      "elm.text"
+#define PART_CONTACT_THUMBNAIL "elm.swallow.icon"
+#define PART_CONTACT_CHECK     "elm.swallow.end"
+
+namespace Contacts
+{
+       namespace Model
+       {
+               class ContactRecordData;
+       }
+
+       namespace List
+       {
+               /**
+                * @brief Contact genlist item
+                */
+               class ContactItem : public Ux::SelectItem
+               {
+               public:
+                       /**
+                        * @brief Create contact item
+                        * @param[in]   contact     Contact object
+                        */
+                       explicit ContactItem(Contacts::Model::ContactRecordData &contact);
+
+                       /**
+                        * @return Contact object.
+                        */
+                       Contacts::Model::ContactRecordData &getContact();
+
+               private:
+                       virtual char *getText(Evas_Object *parent, const char *part) override;
+                       virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
+                       virtual Ux::SelectResult getDefaultResult() const override;
+
+                       Contacts::Model::ContactRecordData &m_Contact;
+               };
+       }
+}
+
+#endif /* CONTACTS_LIST_CONTACT_ITEM_H */
index b54249e..6aaedc9 100644 (file)
@@ -19,6 +19,8 @@
 #define CONTACTS_LIST_LIST_VIEW_H
 
 #include "Contacts/Common/ContactSelectTypes.h"
+#include "Contacts/List/Model/PersonProvider.h"
+
 #include "Ux/SelectView.h"
 #include "Utils/UniString.h"
 
 namespace Ui
 {
        class Genlist;
-       class GenlistItem;
        class GenlistGroupItem;
 }
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactData;
-               class ContactDataProvider;
-       }
-
        namespace List
        {
-               class GroupItem;
-               class SelectAllItem;
-               class PersonGroupItem;
                class PersonItem;
-
-               namespace Model
-               {
-                       class Person;
-               }
+               class PersonGroupItem;
 
                /**
                 * @brief Contacts list view
@@ -61,14 +49,7 @@ namespace Contacts
                         * @brief Create new person list view
                         * @param[in]   filterType  Defines how to filter person list
                         */
-                       ListView(int filterType = FilterNone);
-
-                       /**
-                        * @brief Create new vcard contact list view
-                        * @param[in]   vcardPath   Path of the vcard file
-                        */
-                       explicit ListView(const char *vcardPath);
-
+                       explicit ListView(int filterType = FilterNone);
                        virtual ~ListView() override;
 
                private:
@@ -87,7 +68,8 @@ namespace Contacts
                        virtual void onCreated() override;
                        virtual void onMenuPressed() override;
 
-                       void onSharePressed();
+                       void onDeleteSelected();
+                       void onShareSelected();
 
                        virtual void onSelectAllInsert(Ui::GenlistItem *item) override;
                        virtual void onSelectModeChanged(Ux::SelectMode selectMode) override;
@@ -129,7 +111,7 @@ namespace Contacts
                        void deletePersonGroupItem(PersonGroupItem *group);
                        PersonGroupItem *getNextPersonGroupItem(const Utils::UniString &indexLetter);
 
-                       PersonItem *createPersonItem(Contacts::Model::ContactData &person);
+                       PersonItem *createPersonItem(Model::Person &person);
                        void insertPersonItem(PersonItem *item);
                        void updatePersonItem(PersonItem *item, int changes);
                        void deletePersonItem(PersonItem *item);
@@ -146,17 +128,15 @@ namespace Contacts
                        void onPersonDeleted(PersonItem *item);
 
                        Evas_Object *m_Box;
+                       Evas_Object *m_NoContent;
                        Ui::Genlist *m_Genlist;
                        Evas_Object *m_Index;
                        Evas_Object *m_AddButton;
-                       Evas_Object *m_NoContent;
 
                        Ui::GenlistGroupItem *m_Sections[SectionMax];
-                       std::map<Utils::UniString, PersonGroupItem *> m_PersonGroups;
 
-                       Contacts::Model::ContactDataProvider *m_Provider;
-
-                       bool m_HasIndex;
+                       std::map<Utils::UniString, PersonGroupItem *> m_PersonGroups;
+                       Model::PersonProvider m_Provider;
                };
        }
 }
index 7ac9ef9..20663a4 100644 (file)
@@ -71,7 +71,7 @@ namespace Contacts
                                /**
                                 * @return First letter from formatted person name
                                 */
-                               virtual const Utils::UniString *getIndexLetter() const override;
+                               const Utils::UniString &getIndexLetter() const;
 
                                /**
                                 * @return _contacts_person record
index 83e0556..7c4482d 100644 (file)
@@ -19,6 +19,7 @@
 #define CONTACTS_LIST_MODEL_VCARD_PROVIDER_H
 
 #include "Contacts/Model/ContactDataProvider.h"
+#include <string>
 
 namespace Contacts
 {
@@ -34,9 +35,9 @@ namespace Contacts
                        public:
                                /**
                                 * @brief Create list of vcard contacts
-                                * @param[in]   path    Vcard path
+                                * @param[in]   vcardPath   Vcard path
                                 */
-                               VcardProvider(const char *path);
+                               VcardProvider(std::string vcardPath);
                                VcardProvider(const VcardProvider &contact) = delete;
                                virtual ~VcardProvider() override;
 
index 9b5e358..082a8f8 100644 (file)
 #ifndef CONTACTS_LIST_PERSON_ITEM_H
 #define CONTACTS_LIST_PERSON_ITEM_H
 
-#include "Ux/SelectItem.h"
-
-#define PART_PERSON_NAME        "elm.text"
-#define PART_PERSON_THUMBNAIL   "elm.swallow.icon"
-#define PART_CHECK              "elm.swallow.end"
+#include "Contacts/List/ContactItem.h"
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactData;
-       }
-
        namespace List
        {
+               namespace Model
+               {
+                       class Person;
+               }
+
                /**
-                * @brief Person list item
+                * @brief Person genlist item
                 */
-               class PersonItem : public Ux::SelectItem
+               class PersonItem : public ContactItem
                {
                public:
                        /**
                         * @brief Create person item
                         * @param[in]   person      Person object
                         */
-                       explicit PersonItem(Contacts::Model::ContactData &person);
+                       explicit PersonItem(Model::Person &person);
 
                        /**
-                        * @return Person object
+                        * @return Person object.
                         */
-                       Contacts::Model::ContactData &getPerson();
+                       Model::Person &getPerson();
 
                private:
-                       virtual char *getText(Evas_Object *parent, const char *part) override;
-                       virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
                        virtual Ux::SelectResult getDefaultResult() const override;
 
-                       Contacts::Model::ContactData &m_Person;
+                       Model::Person &m_Person;
                };
        }
 }
diff --git a/lib-contacts/inc/Contacts/List/VcardView.h b/lib-contacts/inc/Contacts/List/VcardView.h
new file mode 100644 (file)
index 0000000..6e9a187
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_LIST_VCARD_VIEW_H
+#define CONTACTS_LIST_VCARD_VIEW_H
+
+#include "Ux/SelectView.h"
+#include "Contacts/List/Model/VcardProvider.h"
+
+namespace Ui
+{
+       class Genlist;
+}
+
+namespace Contacts
+{
+       namespace Settings
+       {
+               class ImportController;
+       }
+
+       namespace List
+       {
+               class EXPORT_API VcardView : public Ux::SelectView
+               {
+               public:
+                       /**
+                        * @brief Create new vcard contact list view
+                        * @param[in]   vcardPath   Path of the vcard file
+                        */
+                       explicit VcardView(std::string vcardPath);
+
+               private:
+                       virtual Evas_Object *onCreate(Evas_Object *parent) override;
+                       virtual void onSelectAllInsert(Ui::GenlistItem *item) override;
+
+                       bool onSelectResult(Ux::SelectResults results);
+                       void onImportFinished(Settings::ImportController *importer);
+
+                       Ui::Genlist *m_Genlist;
+                       std::string m_VcardPath;
+                       Model::VcardProvider m_Provider;
+               };
+       }
+}
+
+#endif /* CONTACTS_LIST_VCARD_VIEW_H */
diff --git a/lib-contacts/src/Contacts/List/ContactItem.cpp b/lib-contacts/src/Contacts/List/ContactItem.cpp
new file mode 100644 (file)
index 0000000..42c5604
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/List/ContactItem.h"
+#include "Contacts/Model/ContactRecordData.h"
+
+#include "Ui/Thumbnail.h"
+#include <app_i18n.h>
+
+using namespace Contacts::List;
+using namespace Contacts::Model;
+
+ContactItem::ContactItem(ContactRecordData &contact)
+       : m_Contact(contact)
+{
+}
+
+ContactRecordData &ContactItem::getContact()
+{
+       return m_Contact;
+}
+
+char *ContactItem::getText(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, PART_CONTACT_NAME) == 0) {
+               const char *name = m_Contact.getName();
+               return strdup(name ? name : _("IDS_LOGS_MBODY_UNKNOWN"));
+       }
+
+       return nullptr;
+}
+
+Evas_Object *ContactItem::getContent(Evas_Object *parent, const char *part)
+{
+       using Ui::Thumbnail;
+
+       if (strcmp(part, PART_CONTACT_THUMBNAIL) == 0) {
+               Thumbnail *thumbnail = Thumbnail::create(parent, Thumbnail::SizeSmall,
+                               m_Contact.getImagePath());
+               thumbnail->setSizeHint(true);
+               return thumbnail->getEvasObject();
+       } else if (strcmp(part, PART_CONTACT_CHECK) == 0) {
+               return SelectItem::getContent(parent, part);
+       }
+
+       return nullptr;
+}
+
+Ux::SelectResult ContactItem::getDefaultResult() const
+{
+       return { 0, (void *) m_Contact.getContactRecord() };
+}
index 87d1f60..6b1d5f8 100644 (file)
@@ -48,32 +48,18 @@ using namespace Ux;
 using namespace std::placeholders;
 
 ListView::ListView(int filterType)
-       : m_Genlist(nullptr), m_Index(nullptr), m_AddButton(nullptr),
-         m_Sections{ nullptr }, m_HasIndex(true)
+       : m_Box(nullptr), m_NoContent(nullptr), m_Genlist(nullptr),
+         m_Index(nullptr), m_AddButton(nullptr),
+         m_Sections{ nullptr }, m_Provider(filterType)
 {
        auto strings = Common::getSelectViewStrings();
        strings.titleDefault = "IDS_PB_TAB_CONTACTS";
        strings.titleSingle = "IDS_PB_HEADER_SELECT_CONTACT_ABB2";
        setStrings(strings);
-
-       m_Provider = new PersonProvider(filterType);
-}
-
-ListView::ListView(const char *vcardPath)
-       : m_Genlist(nullptr), m_Index(nullptr), m_AddButton(nullptr),
-         m_Sections{ nullptr }, m_HasIndex(false)
-{
-       auto strings = Common::getSelectViewStrings();
-       strings.buttonDone = "IDS_PB_HEADER_IMPORT";
-       setStrings(strings);
-
-       m_Provider = new VcardProvider(vcardPath);
 }
 
 ListView::~ListView()
 {
-       m_Provider->unsetInsertCallback();
-       delete m_Provider;
        contacts_db_remove_changed_cb(_contacts_my_profile._uri,
                        makeCallbackWithLastParam(&ListView::updateMyProfileItem), this);
 }
@@ -84,17 +70,13 @@ Evas_Object *ListView::onCreate(Evas_Object *parent)
        elm_layout_theme_set(layout, "layout", "application", "fastscroll");
 
        m_Box = elm_box_add(layout);
-
+       m_NoContent = createNoContentLayout(m_Box);
        m_Genlist = createGenlist(m_Box);
        elm_box_pack_end(m_Box, m_Genlist->getEvasObject());
 
-       m_NoContent = createNoContentLayout(m_Box);
-
        elm_object_part_content_set(layout, "elm.swallow.content", m_Box);
        elm_object_part_content_set(layout, "elm.swallow.fastscroll", createIndex(layout));
 
-       setIndexState(layout, m_HasIndex);
-
        return layout;
 }
 
@@ -108,7 +90,7 @@ void ListView::onCreated()
 {
        updateSectionsMode();
 
-       m_Provider->setInsertCallback(std::bind(&ListView::onPersonInserted, this, _1));
+       m_Provider.setInsertCallback(std::bind(&ListView::onPersonInserted, this, _1));
        contacts_db_add_changed_cb(_contacts_my_profile._uri,
                        makeCallbackWithLastParam(&ListView::updateMyProfileItem), this);
 }
@@ -121,28 +103,8 @@ void ListView::onMenuPressed()
 
        Ui::Menu *menu = new Ui::Menu();
        menu->create(getEvasObject());
-
-       menu->addItem("IDS_LOGS_OPT_DELETE", [this] {
-               auto strings = Common::getSelectViewStrings();
-               strings.buttonDone = "IDS_LOGS_OPT_DELETE";
-
-               ListView *view = new ListView();
-               view->setStrings(strings);
-               view->setSelectMode(SelectMulti);
-               view->setSelectCallback([](SelectResults results) {
-                       std::vector<int> ids;
-                       for (auto &&result : results) {
-                               ids.push_back(result.value.id);
-                       }
-
-                       contacts_db_delete_records(_contacts_person._uri, ids.data(), ids.size());
-                       return true;
-               });
-               getNavigator()->navigateTo(view);
-       });
-
-       menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onSharePressed, this));
-
+       menu->addItem("IDS_LOGS_OPT_DELETE", std::bind(&ListView::onDeleteSelected, this));
+       menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onShareSelected, this));
        menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB", [this] {
                auto manageFavPopup = new ManageFavoritesPopup(getNavigator());
                manageFavPopup->create(getEvasObject());
@@ -155,7 +117,29 @@ void ListView::onMenuPressed()
        menu->show();
 }
 
-void ListView::onSharePressed()
+void ListView::onDeleteSelected()
+{
+       auto strings = Common::getSelectViewStrings();
+       strings.buttonDone = "IDS_LOGS_OPT_DELETE";
+
+       ListView *view = new ListView();
+       view->setStrings(strings);
+       view->setSelectMode(SelectMulti);
+       view->setSelectCallback([](SelectResults results) {
+               std::vector<int> ids;
+               ids.reserve(results.count());
+
+               for (auto &&result : results) {
+                       ids.push_back(result.value.id);
+               }
+
+               contacts_db_delete_records(_contacts_person._uri, ids.data(), ids.size());
+               return true;
+       });
+       getNavigator()->navigateTo(view);
+}
+
+void ListView::onShareSelected()
 {
        auto strings = Common::getSelectViewStrings();
        strings.buttonDone = "IDS_PB_OPT_SHARE";
@@ -165,19 +149,17 @@ void ListView::onSharePressed()
        view->setSelectMode(SelectMulti);
        view->setSelectCallback([](SelectResults results) {
                size_t count = results.count();
-
                std::vector<std::string> idString(count);
-               idString.reserve(count);
                std::vector<const char *> ids(count);
-               ids.reserve(count);
 
                for (size_t i = 0; i < count; ++i) {
                        idString[i] = std::to_string(results[i].value.id);
                        ids[i] = idString[i].c_str();
                }
-               App::AppControl control = App::requestMultiShareContacts(ids.data(), count);
-               control.launch();
-               control.detach();
+
+               App::AppControl request = App::requestMultiShareContacts(ids.data(), count);
+               request.launch();
+               request.detach();
 
                return true;
        });
@@ -220,18 +202,18 @@ void ListView::fillMfc()
 void ListView::fillPersonList()
 {
        if (m_PersonGroups.empty()) {
-               ContactDataList list = m_Provider->getContactDataList();
+               ContactDataList list = m_Provider.getContactDataList();
                PersonGroupItem *group = nullptr;
 
                for (auto &&contactData : list) {
-                       const UniString *nextLetter = contactData->getIndexLetter();
-                       if (nextLetter) {
-                               if (!group || group->getTitle() != *nextLetter) {
-                                       group = insertPersonGroupItem(*nextLetter);
-                               }
+                       Person &person = static_cast<Person &>(*contactData);
+
+                       const UniString &nextLetter = person.getIndexLetter();
+                       if (!group || group->getTitle() != nextLetter) {
+                               group = insertPersonGroupItem(nextLetter);
                        }
 
-                       auto item = createPersonItem(*contactData);
+                       auto item = createPersonItem(person);
                        m_Genlist->insert(item, group);
                        onItemInserted(item);
                }
@@ -291,7 +273,7 @@ void ListView::showNoContentLayout()
 void ListView::hideNoContentLayout()
 {
        if (evas_object_visible_get(m_NoContent)) {
-               setIndexState(getEvasObject(), m_HasIndex);
+               setIndexState(getEvasObject(), true);
 
                elm_scroller_content_min_limit(m_Genlist->getEvasObject(), EINA_FALSE, EINA_FALSE);
                evas_object_size_hint_weight_set(m_Genlist->getEvasObject(), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -304,7 +286,7 @@ void ListView::hideNoContentLayout()
 
 void ListView::updateNoContentLayout()
 {
-       ContactDataList list = m_Provider->getContactDataList();
+       ContactDataList list = m_Provider.getContactDataList();
        list.size() > 0 ? hideNoContentLayout() : showNoContentLayout();
 }
 
@@ -385,10 +367,6 @@ void ListView::updatePageMode()
                        break;
 
                case SelectSingle:
-                       deleteAddButton();
-                       page->setContent("toolbar", nullptr);
-                       break;
-
                case SelectMulti:
                        deleteAddButton();
                        page->setContent("toolbar", nullptr);
@@ -517,7 +495,7 @@ PersonGroupItem *ListView::getNextPersonGroupItem(const Utils::UniString &indexL
        return nullptr;
 }
 
-PersonItem *ListView::createPersonItem(ContactData &person)
+PersonItem *ListView::createPersonItem(Person &person)
 {
        PersonItem *item = new PersonItem(person);
        person.setUpdateCallback(std::bind(&ListView::onPersonUpdated, this, item, _1));
@@ -531,16 +509,14 @@ void ListView::insertPersonItem(PersonItem *item)
        PersonGroupItem *group = nullptr;
        PersonItem *nextItem = nullptr;
 
-       const UniString *indexLetter = item->getPerson().getIndexLetter();
-       if (indexLetter) {
-               auto it = m_PersonGroups.find(*indexLetter);
-               if (it != m_PersonGroups.end()) {
-                       group = it->second;
-                       nextItem = getNextPersonItem(it->second, static_cast<Person &>(item->getPerson()));
-               } else {
-                       PersonGroupItem *nextGroup = getNextPersonGroupItem(*indexLetter);
-                       group = insertPersonGroupItem(*indexLetter, nextGroup);
-               }
+       const UniString &indexLetter = item->getPerson().getIndexLetter();
+       auto it = m_PersonGroups.find(indexLetter);
+       if (it != m_PersonGroups.end()) {
+               group = it->second;
+               nextItem = getNextPersonItem(it->second, item->getPerson());
+       } else {
+               PersonGroupItem *nextGroup = getNextPersonGroupItem(indexLetter);
+               group = insertPersonGroupItem(indexLetter, nextGroup);
        }
 
        m_Genlist->insert(item, group, nextItem);
@@ -560,7 +536,7 @@ void ListView::updatePersonItem(PersonItem *item, int changes)
                }
        } else if (changes & ContactData::ChangedImage) {
                elm_genlist_item_fields_update(item->getObjectItem(),
-                               PART_PERSON_THUMBNAIL, ELM_GENLIST_ITEM_FIELD_CONTENT);
+                               PART_CONTACT_THUMBNAIL, ELM_GENLIST_ITEM_FIELD_CONTENT);
        }
 }
 
@@ -594,7 +570,7 @@ PersonItem *ListView::getNextPersonItem(PersonGroupItem *group, const Person &pe
 void ListView::onItemPressed(SelectItem *item)
 {
        PersonItem *personItem = static_cast<PersonItem *>(item);
-       int id = static_cast<Person &>(personItem->getPerson()).getDisplayContactId();
+       int id = personItem->getPerson().getDisplayContactId();
        getNavigator()->navigateTo(new Details::DetailsView(id));
 }
 
@@ -617,7 +593,7 @@ void ListView::onIndexSelected(Evas_Object *index, Elm_Object_Item *indexItem)
 
 void ListView::onPersonInserted(ContactData &person)
 {
-       auto item = createPersonItem(person);
+       auto item = createPersonItem(static_cast<Person &>(person));
        insertPersonItem(item);
        onItemInserted(item);
 }
index 6ade1c1..84cc446 100644 (file)
@@ -94,9 +94,9 @@ const Person::ContactIds &Person::getContactIds() const
        return m_ContactIds;
 }
 
-const UniString *Person::getIndexLetter() const
+const UniString &Person::getIndexLetter() const
 {
-       return &m_IndexLetter;
+       return m_IndexLetter;
 }
 
 const contacts_record_h Person::getRecord() const
index d4420c4..e0ac52a 100644 (file)
@@ -23,9 +23,9 @@ using namespace Contacts;
 using namespace Contacts::Model;
 using namespace Contacts::List::Model;
 
-VcardProvider::VcardProvider(const char *path)
+VcardProvider::VcardProvider(std::string vcardPath)
 {
-       int err = contacts_vcard_parse_to_contact_foreach(path, [](contacts_record_h record, void *data)->bool {
+       int err = contacts_vcard_parse_to_contact_foreach(vcardPath.c_str(), [](contacts_record_h record, void *data)->bool {
                RETVM_IF(!record || !data, true, "invalid data");
                ContactDataList *list = (ContactDataList *)data;
 
index 66e6ba4..9f12e1b 100644 (file)
  *
  */
 
-#include "Contacts/Model/ContactRecordData.h"
 #include "Contacts/List/PersonItem.h"
+#include "Contacts/List/Model/Person.h"
 #include "Contacts/Common/ContactSelectTypes.h"
-#include "Ui/Thumbnail.h"
-#include <app_i18n.h>
 
-using namespace Contacts;
 using namespace Contacts::List;
-using namespace Contacts::Model;
+using namespace Contacts::List::Model;
 
-PersonItem::PersonItem(ContactData &person)
-       : m_Person(person)
+PersonItem::PersonItem(Person &person)
+       : ContactItem(person), m_Person(person)
 {
 }
 
-ContactData &PersonItem::getPerson()
+Person &PersonItem::getPerson()
 {
        return m_Person;
 }
 
-char *PersonItem::getText(Evas_Object *parent, const char *part)
-{
-       if (strcmp(part, PART_PERSON_NAME) == 0) {
-               const char *name = m_Person.getName();
-               return strdup(name ? name : _("IDS_LOGS_MBODY_UNKNOWN"));
-       }
-
-       return nullptr;
-}
-
-Evas_Object *PersonItem::getContent(Evas_Object *parent, const char *part)
-{
-       using Ui::Thumbnail;
-
-       if (strcmp(part, PART_PERSON_THUMBNAIL) == 0) {
-               Thumbnail *thumbnail = Thumbnail::create(parent, Thumbnail::SizeSmall,
-                               m_Person.getImagePath());
-               thumbnail->setSizeHint(true);
-               return thumbnail->getEvasObject();
-       } else if (strcmp(part, PART_CHECK) == 0) {
-               return SelectItem::getContent(parent, part);
-       }
-
-       return nullptr;
-}
-
 Ux::SelectResult PersonItem::getDefaultResult() const
 {
-       if (m_Person.getType() == ContactData::TypeContact) {
-               return { ResultPerson, (void *)static_cast<ContactRecordData &>(m_Person).getContactRecord() };
-       } else {
-               return { ResultPerson, m_Person.getId() };
-       }
+       return { ResultPerson, m_Person.getId() };
 }
diff --git a/lib-contacts/src/Contacts/List/VcardView.cpp b/lib-contacts/src/Contacts/List/VcardView.cpp
new file mode 100644 (file)
index 0000000..8bbce91
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/List/VcardView.h"
+#include "Contacts/List/ContactItem.h"
+#include "Contacts/Model/ContactRecordData.h"
+#include "Contacts/Settings/ImportController.h"
+#include "Common/Strings.h"
+
+#include "Ui/Genlist.h"
+#include "Utils/Logger.h"
+
+#include <app_i18n.h>
+#include <notification.h>
+
+#define NOTI_BUFFER_SIZE 1024
+
+using namespace Contacts::Model;
+using namespace Contacts::List;
+using namespace Contacts::List::Model;
+using namespace std::placeholders;
+
+VcardView::VcardView(std::string vcardPath)
+       : m_Genlist(nullptr), m_VcardPath(std::move(vcardPath)), m_Provider(m_VcardPath)
+{
+       auto strings = Common::getSelectViewStrings();
+       strings.buttonDone = "IDS_PB_HEADER_IMPORT";
+
+       setStrings(strings);
+       setSelectMode(Ux::SelectMulti);
+       setSelectCallback(std::bind(&VcardView::onSelectResult, this, _1));
+}
+
+Evas_Object *VcardView::onCreate(Evas_Object *parent)
+{
+       m_Genlist = new Ui::Genlist();
+       m_Genlist->create(parent);
+
+       for (auto &&contact : m_Provider.getContactDataList()) {
+               ContactItem *item = new ContactItem(static_cast<ContactRecordData &>(*contact));
+               m_Genlist->insert(item);
+               onItemInserted(item);
+       }
+
+       return m_Genlist->getEvasObject();
+}
+
+void VcardView::onSelectAllInsert(Ui::GenlistItem *item)
+{
+       m_Genlist->insert(item, nullptr, nullptr, Ui::Genlist::After);
+}
+
+bool VcardView::onSelectResult(Ux::SelectResults results)
+{
+       std::vector<contacts_record_h> records;
+       for (auto &&result : results) {
+               records.push_back((contacts_record_h) result.value.data);
+       }
+
+       Settings::ImportController *importer = new Settings::ImportController(getEvasObject(),
+                       "IDS_PB_HEADER_IMPORT_CONTACTS_ABB2", records.size(), { m_VcardPath }, std::move(records));
+       importer->setFinishCallback(std::bind(&VcardView::onImportFinished, this, importer));
+       importer->run();
+
+       return false;
+}
+
+void VcardView::onImportFinished(Settings::ImportController *importer)
+{
+       size_t count = importer->getTotalCount();
+       int err = NOTIFICATION_ERROR_NONE;
+
+       if (count > 1) {
+               char buffer[NOTI_BUFFER_SIZE] = { 0, };
+               snprintf(buffer, sizeof(buffer), _("IDS_PB_TPOP_PD_CONTACTS_IMPORTED"), count);
+               err = notification_status_message_post(buffer);
+       } else if (count == 1){
+               err = notification_status_message_post(_("IDS_PB_TPOP_1_CONTACT_IMPORTED"));
+       }
+       WARN_IF_ERR(err, "notification_status_message_post() failed.");
+
+       getPage()->close();
+}