Moved SelectView to lib-common. Separated contact-specific selection types. 35/60835/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Wed, 2 Mar 2016 11:10:49 +0000 (13:10 +0200)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Wed, 2 Mar 2016 13:32:34 +0000 (05:32 -0800)
Made SelectResult more generic.

Change-Id: I31939bf812911c651f827aac0613b7e68ff8fd22
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
20 files changed:
lib-common/inc/Contacts/SelectAllItem.h [moved from lib-contact/inc/Contacts/Common/SelectAllItem.h with 100% similarity]
lib-common/inc/Contacts/SelectItem.h [moved from lib-contact/inc/Contacts/Common/SelectItem.h with 94% similarity]
lib-common/inc/Contacts/SelectTypes.h [new file with mode: 0644]
lib-common/inc/Contacts/SelectView.h [moved from lib-contact/inc/Contacts/Common/SelectView.h with 96% similarity]
lib-common/src/Contacts/SelectAllItem.cpp [moved from lib-contact/src/Contacts/Common/SelectAllItem.cpp with 96% similarity]
lib-common/src/Contacts/SelectItem.cpp [moved from lib-contact/src/Contacts/Common/SelectItem.cpp with 96% similarity]
lib-common/src/Contacts/SelectView.cpp [moved from lib-contact/src/Contacts/Common/SelectView.cpp with 98% similarity]
lib-contact/inc/Contacts/Common/Chooser.h
lib-contact/inc/Contacts/Common/ContactSelectTypes.h [moved from lib-contact/inc/Contacts/Common/SelectMode.h with 59% similarity]
lib-contact/inc/Contacts/Details/BasicInfoItem.h
lib-contact/inc/Contacts/Details/DetailsView.h
lib-contact/inc/Contacts/Details/FieldItem.h
lib-contact/inc/Contacts/List/ListView.h
lib-contact/inc/Contacts/List/Model/PersonProvider.h
lib-contact/inc/Contacts/List/PersonItem.h
lib-contact/src/Contacts/Common/Chooser.cpp
lib-contact/src/Contacts/List/ListView.cpp
lib-contact/src/Contacts/List/PersonItem.cpp
main-app/inc/OperationPickController.h
main-app/src/OperationPickController.cpp

similarity index 94%
rename from lib-contact/inc/Contacts/Common/SelectItem.h
rename to lib-common/inc/Contacts/SelectItem.h
index f126a6a..ec8d332 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_SELECT_ITEM_H
 #define CONTACTS_SELECT_ITEM_H
 
-#include "Contacts/Common/SelectMode.h"
+#include "Contacts/SelectTypes.h"
 #include "Ui/GenlistCheckItem.h"
 
 namespace Contacts
@@ -26,7 +26,7 @@ namespace Contacts
        /**
         * @brief Genlist item for SelectView that supports selection mode switching.
         */
-       class SelectItem : public Ui::GenlistCheckItem
+       class EXPORT_API SelectItem : public Ui::GenlistCheckItem
        {
        public:
                SelectItem();
diff --git a/lib-common/inc/Contacts/SelectTypes.h b/lib-common/inc/Contacts/SelectTypes.h
new file mode 100644 (file)
index 0000000..caeabc7
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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_SELECT_TYPES_H
+#define CONTACTS_SELECT_TYPES_H
+
+#include "Utils/Range.h"
+#include <functional>
+
+namespace Contacts
+{
+       /**
+        * @brief Determines how items can be selected.
+        */
+       enum SelectMode
+       {
+               SelectNone,     /**< Selection is disabled */
+               SelectSingle,   /**< Only one item can be selected */
+               SelectMulti     /**< Multiple items can be selected */
+       };
+
+       /**
+        * @brief Selection result.
+        */
+       struct SelectResult
+       {
+               unsigned type;  /**< Result type (depends on result source) */
+               union Value
+               {
+                       Value(void *data) : data(data) { }
+                       Value(int id) : id(id) { }
+                       void *data; /**< Result data */
+                       int id;     /**< Result data ID */
+               } value;        /**< Result value (depends on type) */
+       };
+
+       /**
+        * @brief Range of consecutive selection results.
+        */
+       typedef Utils::Range<const SelectResult *> SelectResults;
+
+       /**
+        * @brief Callback to be called when selection is done.
+        * @param[in]   Selection results
+        * @return Whether the component that provided the selection should be destroyed.
+        */
+       typedef std::function<bool(SelectResults)> SelectCallback;
+}
+
+#endif /* CONTACTS_SELECT_TYPES_H */
similarity index 96%
rename from lib-contact/inc/Contacts/Common/SelectView.h
rename to lib-common/inc/Contacts/SelectView.h
index 87a3f65..35e9b08 100644 (file)
@@ -18,8 +18,8 @@
 #ifndef CONTACTS_SELECT_VIEW_H
 #define CONTACTS_SELECT_VIEW_H
 
-#include "Contacts/Common/SelectAllItem.h"
-#include "Contacts/Common/SelectMode.h"
+#include "Contacts/SelectAllItem.h"
+#include "Contacts/SelectTypes.h"
 #include "Ui/View.h"
 
 #include <memory>
@@ -37,7 +37,7 @@ namespace Contacts
        /**
         * @brief Base class for a view that support single and multiple selection modes.
         */
-       class SelectView : public Ui::View
+       class EXPORT_API SelectView : public Ui::View
        {
        public:
                SelectView();
@@ -15,7 +15,7 @@
  *
  */
 
-#include "Contacts/Common/SelectAllItem.h"
+#include "Contacts/SelectAllItem.h"
 #include <app_i18n.h>
 
 using namespace Contacts;
similarity index 96%
rename from lib-contact/src/Contacts/Common/SelectItem.cpp
rename to lib-common/src/Contacts/SelectItem.cpp
index dad76fe..70a25ec 100644 (file)
@@ -15,7 +15,7 @@
  *
  */
 
-#include "Contacts/Common/SelectItem.h"
+#include "Contacts/SelectItem.h"
 
 using namespace Contacts;
 
similarity index 98%
rename from lib-contact/src/Contacts/Common/SelectView.cpp
rename to lib-common/src/Contacts/SelectView.cpp
index d006d53..fa17374 100644 (file)
@@ -15,8 +15,8 @@
  *
  */
 
-#include "Contacts/Common/SelectView.h"
-#include "Contacts/Common/SelectItem.h"
+#include "Contacts/SelectView.h"
+#include "Contacts/SelectItem.h"
 
 #include "Ui/Genlist.h"
 #include "Utils/Callback.h"
index 2ad25a2..da6e4f1 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_COMMON_CHOOSER_H
 #define CONTACTS_COMMON_CHOOSER_H
 
-#include "Contacts/Common/SelectMode.h"
+#include "Contacts/Common/ContactSelectTypes.h"
 #include "Ui/Naviframe.h"
 
 namespace Contacts
  *
  */
 
-#ifndef CONTACTS_COMMON_SELECT_MODE_H
-#define CONTACTS_COMMON_SELECT_MODE_H
+#ifndef CONTACTS_COMMON_CONTACT_SELECT_TYPES_H
+#define CONTACTS_COMMON_CONTACT_SELECT_TYPES_H
 
+#include "Contacts/SelectTypes.h"
 #include "Contacts/Model/ContactField.h"
 #include "Contacts/Model/ContactTypes.h"
-#include "Utils/Range.h"
-
-#include <functional>
 
 namespace Contacts
 {
        /**
-        * @brief Determines how items can be selected.
-        */
-       enum SelectMode
-       {
-               SelectNone,     /**< Selection is disabled */
-               SelectSingle,   /**< Only one item can be selected */
-               SelectMulti     /**< Multiple items can be selected */
-       };
-
-       /**
         * @brief Determines which items are displayed.
         */
        enum FilterType
@@ -56,27 +44,6 @@ namespace Contacts
                ResultNumber    = Model::ObjectTypeNumber,    /**< Number ID is the result */
                ResultEmail     = Model::ObjectTypeEmail      /**< Email ID is the result */
        };
-
-       /**
-        * @brief Selection result.
-        */
-       struct SelectResult
-       {
-               unsigned type;  /**< @ref ResultType. */
-               int itemId;     /**< Item database ID (for _contacts_person, _contacts_number or _contacts_email). */
-       };
-
-       /**
-        * @brief Range of consecutive selection results.
-        */
-       typedef Utils::Range<const SelectResult *> SelectResults;
-
-       /**
-        * @brief Callback to be called when selection is done.
-        * @param[in]   Selection results
-        * @return Whether the component that provided the selection should be destroyed.
-        */
-       typedef std::function<bool(SelectResults)> SelectCallback;
 }
 
-#endif /* CONTACTS_COMMON_SELECT_MODE_H */
+#endif /* CONTACTS_COMMON_CONTACT_SELECT_TYPES_H */
index 5747f16..e198195 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_DETAILS_BASIC_INFO_ITEM_H
 #define CONTACTS_DETAILS_BASIC_INFO_ITEM_H
 
-#include "Contacts/Common/SelectMode.h"
+#include "Contacts/SelectTypes.h"
 #include "Ui/GenlistItem.h"
 
 #include <contacts.h>
index e252e73..40ce4eb 100644 (file)
@@ -19,9 +19,9 @@
 #define CONTACTS_DETAILS_DETAILS_VIEW_H
 
 #include "App/AppControl.h"
-#include "Contacts/Common/SelectView.h"
+#include "Contacts/Common/ContactSelectTypes.h"
 #include "Contacts/Model/Contact.h"
-#include "Ui/View.h"
+#include "Contacts/SelectView.h"
 
 namespace Ui
 {
index 1fd6631..8c3153b 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_DETAILS_FIELD_ITEM_H
 #define CONTACTS_DETAILS_FIELD_ITEM_H
 
-#include "Contacts/Common/SelectItem.h"
+#include "Contacts/SelectItem.h"
 #include <contacts.h>
 
 namespace Contacts
index 7bd3273..dc062ed 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "Contacts/List/Model/PersonProvider.h"
 #include "Contacts/List/PersonItem.h"
-#include "Contacts/Common/SelectView.h"
+#include "Contacts/SelectView.h"
 
 #include "Utils/UniString.h"
 
index b0e74e1..bd8e71d 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_LIST_MODEL_PERSON_PROVIDER_H
 #define CONTACTS_LIST_MODEL_PERSON_PROVIDER_H
 
-#include "Contacts/Common/SelectMode.h"
+#include "Contacts/Common/ContactSelectTypes.h"
 #include "Contacts/DbChangeObserver.h"
 #include "Contacts/List/Model/Person.h"
 
index d5646f1..47d022c 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_LIST_PERSON_ITEM_H
 #define CONTACTS_LIST_PERSON_ITEM_H
 
-#include "Contacts/Common/SelectItem.h"
+#include "Contacts/SelectItem.h"
 #include "Contacts/List/Model/Person.h"
 #include <functional>
 
index 9e254e6..dbf9104 100644 (file)
@@ -71,7 +71,7 @@ void Chooser::onPageAttached()
 bool Chooser::onSinglePersonSelected(SelectResults personResults)
 {
        const SelectResult &person = *personResults.begin();
-       int resultId = getSingleResultId(person.itemId, m_ResultType);
+       int resultId = getSingleResultId(person.value.id, m_ResultType);
 
        if (resultId > 0) {
                SelectResult result = { m_ResultType, resultId };
@@ -79,7 +79,7 @@ bool Chooser::onSinglePersonSelected(SelectResults personResults)
        }
 
        /* FIXME: Implement person support in DetailsView */
-       DetailsView *view = new DetailsView(getContactId(person.itemId),
+       DetailsView *view = new DetailsView(getContactId(person.value.id),
                        DetailsView::Type(person.type), m_FilterType);
        view->setSelectMode(m_SelectMode);
        view->setSelectCallback(std::bind(&Chooser::onSelected, this, _1));
@@ -99,7 +99,7 @@ bool Chooser::onMultiPersonSelected(SelectResults personResults)
        results.reserve(personResults.count());
 
        for (auto &&result : personResults) {
-               contacts_person_get_default_property(property, result.itemId, &id);
+               contacts_person_get_default_property(property, result.value.id, &id);
                results.push_back({ m_ResultType, id });
        }
 
index 07bd47f..48b985b 100644 (file)
@@ -93,7 +93,7 @@ void ListView::onMenuPressed()
                view->setSelectCallback([](SelectResults results) {
                        std::vector<int> ids;
                        for (auto &&result : results) {
-                               ids.push_back(result.itemId);
+                               ids.push_back(result.value.id);
                        }
 
                        contacts_db_delete_records(_contacts_person._uri, ids.data(), ids.size());
index e6895c1..56bcbe9 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "Contacts/List/PersonItem.h"
+#include "Contacts/Common/ContactSelectTypes.h"
 #include "Ui/Thumbnail.h"
 #include <app_i18n.h>
 
index 0d6aa79..9890373 100644 (file)
@@ -19,7 +19,7 @@
 #define OPERATION_PICK_CONTROLLER_H
 
 #include "OperationController.h"
-#include "Contacts/Common/SelectMode.h"
+#include "Contacts/Common/ContactSelectTypes.h"
 
 #include <Evas.h>
 
index c14a056..0742faa 100644 (file)
@@ -71,7 +71,7 @@ bool OperationPickController::onSelected(SelectResults results)
        std::vector<const char *> ids(count);
 
        for (size_t i = 0; i < count; ++i) {
-               snprintf(buffers[i], sizeof(buffers[i]), "%d", results[i].itemId);
+               snprintf(buffers[i], sizeof(buffers[i]), "%d", results[i].value.id);
                ids[i] = buffers[i];
        }