--- /dev/null
+/*
+ * 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 */
*/
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;
--- /dev/null
+/*
+ * 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;
+}
+
_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)
return contactList;
}
- contacts_list_h list = ::getPersonList(m_FilterType);
+ contacts_list_h list = getPersonList();
contacts_record_h record = nullptr;
CONTACTS_LIST_FOREACH(list, record) {
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 {
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;