Implemented FavoriteProvider with basic functionality. 97/66397/5
authorAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Mon, 18 Apr 2016 14:21:08 +0000 (17:21 +0300)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Tue, 19 Apr 2016 11:48:40 +0000 (14:48 +0300)
Change-Id: Iae8d1dd650f5db04396b7e5460ebd9e574096195
Signed-off-by: Aleksandr Sapozhnik <a.sapozhnik@samsung.com>
lib-contacts/inc/Contacts/List/Model/FavoritesProvider.h [new file with mode: 0644]
lib-contacts/inc/Contacts/List/Model/PersonProvider.h
lib-contacts/src/Contacts/List/Model/FavoritesProvider.cpp [new file with mode: 0644]
lib-contacts/src/Contacts/List/Model/PersonProvider.cpp

diff --git a/lib-contacts/inc/Contacts/List/Model/FavoritesProvider.h b/lib-contacts/inc/Contacts/List/Model/FavoritesProvider.h
new file mode 100644 (file)
index 0000000..07c8477
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015-2016 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_MODEL_FAVORITES_PROVIDER_H
+#define CONTACTS_LIST_MODEL_FAVORITES_PROVIDER_H
+
+#include "Contacts/List/Model/PersonProvider.h"
+
+namespace Contacts
+{
+       namespace List
+       {
+               namespace Model
+               {
+                       /**
+                        * @brief Provides list of favorite persons
+                        */
+                       class FavoritesProvider : public PersonProvider
+                       {
+                       public:
+                               /**
+                            * @brief Determines which items are displayed.
+                                */
+                               enum Mode
+                               {
+                                       ModeOnly,                   /**< Only favorites are displayed */
+                                       ModeExclude                 /**< Displayed all contacts without favorites */
+                               };
+
+                               /**
+                                * @brief Constructor
+                                * @param[in]    mode          The mode
+                                * @param[in]    filterType    The filter
+                                */
+                               explicit FavoritesProvider(Mode mode = ModeOnly, int filterType = FilterNone);
+
+                               /**
+                                * @brief Destructor
+                                */
+                               virtual ~FavoritesProvider() override;
+
+                       protected:
+                               /**
+                                * @see ContactRecordProvider::createContactData
+                                */
+                               virtual Contacts::Model::ContactData *createContactData(contacts_record_h record) override;
+
+                               /**
+                                * @see PersonProvider::getFilter
+                                */
+                               virtual contacts_filter_h getFilter() const override;
+
+                               /**
+                                * @see PersonProvider::getQuery
+                                */
+                               virtual contacts_query_h getQuery() const override;
+
+                       private:
+
+                               Mode m_Mode;
+                       };
+               }
+       }
+}
+
+#endif /* CONTACTS_LIST_MODEL_FAVORITES_PROVIDER_H */
index 43dde70..beb25b5 100644 (file)
@@ -62,8 +62,21 @@ namespace Contacts
                                 */
                                virtual contacts_record_h getRecord(int id) override;
 
+                               /**
+                                * @brief Fills the filter for query
+                                * @return The filter
+                                */
+                               virtual contacts_filter_h getFilter() const;
+
+                               /**
+                                * @brief Fills the query to get list of persons
+                                * @return The query
+                                */
+                               virtual contacts_query_h getQuery() const;
+
                        private:
                                virtual bool shouldUpdateChangedCallback() override;
+                               contacts_list_h getPersonList();
                                void onNameFormatChanged(contacts_name_display_order_e order);
 
                                int m_FilterType;
diff --git a/lib-contacts/src/Contacts/List/Model/FavoritesProvider.cpp b/lib-contacts/src/Contacts/List/Model/FavoritesProvider.cpp
new file mode 100644 (file)
index 0000000..6f2c959
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2015-2016 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/Model/FavoritesProvider.h"
+#include "Contacts/List/Model/Person.h"
+#include "Contacts/Utils.h"
+
+using namespace Contacts;
+using namespace Contacts::Model;
+using namespace Contacts::List::Model;
+
+namespace
+{
+       unsigned projection[] = {
+               _contacts_person.id,
+               _contacts_person.display_name,
+               _contacts_person.display_name_index,
+               _contacts_person.display_contact_id,
+               _contacts_person.image_thumbnail_path,
+               _contacts_person.is_favorite,
+               _contacts_person.favorite_priority
+       };
+}
+
+FavoritesProvider::FavoritesProvider(Mode mode, int filterType)
+       : PersonProvider(filterType), m_Mode(mode)
+{
+}
+
+FavoritesProvider::~FavoritesProvider()
+{
+}
+
+ContactData *FavoritesProvider::createContactData(contacts_record_h record)
+{
+       Person *person = nullptr;
+       if (m_Mode == ModeOnly) {
+               //TODO FavPerson should be created here
+               person = new Person(record);
+       } else {
+               person = new Person(record);
+       }
+
+       return person;
+}
+
+contacts_filter_h FavoritesProvider::getFilter() const
+{
+       contacts_filter_h filter = PersonProvider::getFilter();
+       if (filter) {
+               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+       } else {
+               contacts_filter_create(_contacts_person._uri, &filter);
+       }
+
+       contacts_filter_add_bool(filter, _contacts_person.is_favorite, m_Mode == ModeOnly);
+
+       return filter;
+}
+
+contacts_query_h FavoritesProvider::getQuery() const
+{
+       contacts_query_h query = PersonProvider::getQuery();
+       if (query && m_Mode == ModeOnly) {
+               contacts_query_set_projection(query, projection, Utils::count(projection));
+               contacts_query_set_sort(query, _contacts_person.favorite_priority, true);
+       }
+       return query;
+}
+
index 267a8e4..06a54a1 100644 (file)
@@ -36,51 +36,6 @@ namespace
                _contacts_person.is_favorite,
                _contacts_person.favorite_priority
        };
-
-       contacts_filter_h getProviderFilter(int filterType)
-       {
-               contacts_filter_h filter = nullptr;
-
-               if (filterType != FilterNone) {
-                       contacts_filter_create(_contacts_person._uri, &filter);
-                       bool emptyFilter = true;
-
-                       if (filterType & FilterNumber) {
-                               contacts_filter_add_bool(filter, _contacts_person.has_phonenumber, true);
-                               emptyFilter = false;
-                       }
-
-                       if (filterType & FilterEmail) {
-                               if (!emptyFilter) {
-                                       contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
-                               }
-                               contacts_filter_add_bool(filter, _contacts_person.has_email, true);
-                       }
-               }
-
-               return filter;
-       }
-
-       contacts_list_h getPersonList(int filterType)
-       {
-               contacts_query_h query = nullptr;
-               contacts_query_create(_contacts_person._uri, &query);
-
-               contacts_filter_h filter = getProviderFilter(filterType);
-               if (filter) {
-                       contacts_query_set_filter(query, filter);
-               }
-
-               contacts_query_set_projection(query, projection, Utils::count(projection));
-
-               contacts_list_h list = nullptr;
-               contacts_db_get_records_with_query(query, 0, 0, &list);
-
-               contacts_query_destroy(query);
-               contacts_filter_destroy(filter);
-
-               return list;
-       }
 }
 
 PersonProvider::PersonProvider(int filterType)
@@ -103,7 +58,7 @@ const ContactDataList &PersonProvider::getContactDataList()
                return contactList;
        }
 
-       contacts_list_h list = ::getPersonList(m_FilterType);
+       contacts_list_h list = getPersonList();
 
        contacts_record_h record = nullptr;
        CONTACTS_LIST_FOREACH(list, record) {
@@ -125,7 +80,7 @@ contacts_record_h PersonProvider::getRecord(int contactId)
        contacts_query_h query = nullptr;
        contacts_query_create(_contacts_person._uri, &query);
 
-       contacts_filter_h filter = getProviderFilter(m_FilterType);
+       contacts_filter_h filter = getFilter();
        if (filter) {
                contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
        } else {
@@ -149,6 +104,56 @@ contacts_record_h PersonProvider::getRecord(int contactId)
        return record;
 }
 
+contacts_filter_h PersonProvider::getFilter() const
+{
+       contacts_filter_h filter = nullptr;
+
+       if (m_FilterType != FilterNone) {
+               contacts_filter_create(_contacts_person._uri, &filter);
+               bool emptyFilter = true;
+
+               if (m_FilterType & FilterNumber) {
+                       contacts_filter_add_bool(filter, _contacts_person.has_phonenumber, true);
+                       emptyFilter = false;
+               }
+
+               if (m_FilterType & FilterEmail) {
+                       if (!emptyFilter) {
+                               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+                       }
+                       contacts_filter_add_bool(filter, _contacts_person.has_email, true);
+               }
+       }
+
+       return filter;
+}
+
+contacts_query_h PersonProvider::getQuery() const
+{
+       contacts_query_h query = nullptr;
+       contacts_query_create(_contacts_person._uri, &query);
+       contacts_query_set_projection(query, projection, Utils::count(projection));
+
+       return query;
+}
+
+contacts_list_h PersonProvider::getPersonList()
+{
+       contacts_list_h list = nullptr;
+       contacts_query_h query = getQuery();
+       if (query) {
+               contacts_filter_h filter = getFilter();
+               if (filter) {
+                       contacts_query_set_filter(query, filter);
+               }
+
+               contacts_db_get_records_with_query(query, 0, 0, &list);
+               contacts_query_destroy(query);
+               contacts_filter_destroy(filter);
+       }
+       return list;
+}
+
 bool PersonProvider::shouldUpdateChangedCallback()
 {
        return true;