TizenRefApp-6916 Implement group members count calculation according to the filter... 69/87769/4
authorNataliia Sydorchuk <n.sydorchuk@samsung.com>
Tue, 13 Sep 2016 08:18:15 +0000 (11:18 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 13 Sep 2016 09:48:27 +0000 (02:48 -0700)
Change-Id: If47a87af50145bbd7c4c68a4e78c34c21f152181
Signed-off-by: Nataliia Sydorchuk <n.sydorchuk@samsung.com>
lib-contacts/inc/Contacts/Groups/GroupsView.h
lib-contacts/inc/Contacts/Groups/Model/Group.h
lib-contacts/inc/Contacts/Groups/Model/GroupsProvider.h
lib-contacts/inc/Contacts/Groups/Model/Queries.h
lib-contacts/src/Contacts/Chooser/ChooserView.cpp
lib-contacts/src/Contacts/Groups/GroupsView.cpp
lib-contacts/src/Contacts/Groups/Model/Group.cpp
lib-contacts/src/Contacts/Groups/Model/GroupsProvider.cpp
lib-contacts/src/Contacts/Groups/Model/Queries.cpp

index c6901d1..247f36b 100644 (file)
@@ -49,7 +49,12 @@ namespace Contacts
                class GroupsView : public Ux::SelectView
                {
                public:
-                       GroupsView();
+                       /**
+                        * @brief Create groups main view.
+                        * @param[in]   filterType  Bitmask filter
+                        * @see FilterType
+                        */
+                       GroupsView(int filterType = FilterNone);
 
                        /**
                         * @brief Set whether the view is used for assigning contacts to groups.
index 1f4028b..5cf58b1 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "Model2/DataItem.h"
 
+#include "Contacts/Common/ContactSelectTypes.h"
 #include "Common/DataTypes.h"
 #include "Utils/UniString.h"
 
@@ -46,15 +47,19 @@ namespace Contacts
 
                                /**
                                 * @brief Create group object
-                                * @param[in]   id  _contacts_group id
+                                * @param[in]   id          _contacts_group id
+                                * @param[in]   filterType  Filter to use to count group's members
+                                * @see FilterType
                                 */
-                               explicit Group(int id = 0);
+                               explicit Group(int id = 0, int filterType = FilterNone);
 
                                /**
                                 * @brief Create group object
-                                * @param[in]   record  _contacts_group record
+                                * @param[in]   record      _contacts_group record
+                                * @param[in]   filterType  Filter to use to count group's members
+                                * @see FilterType
                                 */
-                               explicit Group(contacts_record_h record);
+                               explicit Group(contacts_record_h record, int filterType = FilterNone);
 
                                /**
                                 * @brief Create group object
@@ -135,6 +140,7 @@ namespace Contacts
                                Common::GroupType m_Type;
                                mutable Utils::UniString m_SortValue;
                                int m_MembersCount;
+                               int m_FilterType;
                        };
                }
        }
index f8e78d2..cc8c9db 100644 (file)
@@ -19,6 +19,7 @@
 #define CONTACTS_GROUPS_MODEL_GROUPS_PROVIDER_H
 
 #include "Model2/DataProvider.h"
+#include "Contacts/Common/ContactSelectTypes.h"
 
 #include <contacts.h>
 
@@ -33,7 +34,12 @@ namespace Contacts
                        class GroupsProvider : public ::Model2::DataProvider
                        {
                        public:
-                               GroupsProvider();
+                               /**
+                                * @brief Create groups provider.
+                                * @param[in]   filterType  Bitmask filter
+                                * @see FilterType
+                                */
+                               GroupsProvider(int filterType = FilterNone);
                                virtual ~GroupsProvider() override;
 
                        private:
@@ -62,6 +68,7 @@ namespace Contacts
                                int m_DbVersion;
                                int m_MembersDbVersion;
                                int m_UpdateType;
+                               int m_FilterType;
                        };
                }
        }
index 89cb13c..9e85f80 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef CONTACTS_GROUPS_MODEL_QUERIES_H
 #define CONTACTS_GROUPS_MODEL_QUERIES_H
 
+#include "Contacts/Common/ContactSelectTypes.h"
+
 #include <contacts.h>
 
 namespace Contacts
@@ -30,16 +32,20 @@ namespace Contacts
                         * @brief Get query for group's members filtered by group name.
                         * @remark Return value MUST be destroyed with contacts_query_destroy by you
                         * @param[in]   groupId     _contacts_group ID.
+                        * @param[in]   filterType  Filter type
                         * @return filtered query.
+                        * @see FilterType
                         */
-                       EXPORT_API contacts_query_h getMembersQuery(int groupId);
+                       EXPORT_API contacts_query_h getMembersQuery(int groupId, int filterType = FilterNone);
 
                        /**
                         * @brief Get members count of specified group.
                         * @param[in]   groupId     _contacts_group ID.
+                        * @param[in]   filterType  Filter type
                         * @return members count.
+                        * @see FilterType
                         */
-                       EXPORT_API int getMembersCount(int groupId);
+                       EXPORT_API int getMembersCount(int groupId, int filterType = FilterNone);
                }
        }
 }
index 51f71f2..6cb8bb1 100644 (file)
@@ -127,7 +127,7 @@ SelectView *ChooserView::createContactsView()
 
 SelectView *ChooserView::createGroupsView()
 {
-       auto view = new GroupsView();
+       auto view = new GroupsView(m_FilterType);
        view->setSelectMode(SelectSingle);
        view->setSelectCallback([this](SelectResults results) {
                auto group = static_cast<Group *>(results.front().value.data);
index 3319afe..593ffda 100644 (file)
@@ -44,10 +44,10 @@ using namespace Ui;
 using namespace Utils;
 using namespace Ux;
 
-GroupsView::GroupsView()
+GroupsView::GroupsView(int filterType)
        : m_Genlist(nullptr), m_GroupsItem(nullptr),
          m_NotAssignedItem(nullptr), m_CreateItem(nullptr),
-         m_IsAssignMode(false), m_NewGroupId(0)
+         m_IsAssignMode(false), m_NewGroupId(0), m_Provider(filterType)
 {
        auto strings = getSelectViewStrings();
        strings.titleDefault = "IDS_PB_HEADER_GROUPS_ABB";
index 9e0aa0c..edf5e2a 100644 (file)
@@ -41,21 +41,21 @@ namespace
        }
 }
 
-Group::Group(int id)
-       : Group(fetchGroupRecord(id))
+Group::Group(int id, int filterType)
+       : Group(fetchGroupRecord(id), filterType)
 {
 }
 
-Group::Group(contacts_record_h record)
-       : m_Record(record), m_DbVersion(0)
+Group::Group(contacts_record_h record, int filterType)
+       : m_Record(record), m_DbVersion(0), m_FilterType(filterType)
 {
        m_Type = Common::getGroupType(getName());
-       m_MembersCount = Model::getMembersCount(getId());
+       m_MembersCount = Model::getMembersCount(getId(), m_FilterType);
 }
 
 Group::Group(const Group &that)
        : m_DbVersion(0), m_Type(that.m_Type), m_SortValue(that.m_SortValue),
-         m_MembersCount(that.m_MembersCount)
+         m_MembersCount(that.m_MembersCount), m_FilterType(that.m_FilterType)
 {
        contacts_record_clone(that.m_Record, &m_Record);
 }
@@ -162,7 +162,7 @@ const Utils::UniString &Group::getSortValue() const
 
 void Group::updateMembersCount()
 {
-       m_MembersCount = Model::getMembersCount(getId());
+       m_MembersCount = Model::getMembersCount(getId(), m_FilterType);
        setChanged(Model2::ChangeUpdate, ChangedMembersCount);
 }
 
index 15bcabc..6ac66e9 100644 (file)
@@ -27,8 +27,8 @@ using namespace Contacts::Groups::Model;
 using namespace Common::Database;
 using namespace Model2;
 
-GroupsProvider::GroupsProvider()
-       : m_DbVersion(0), m_MembersDbVersion(0), m_UpdateType(UpdateNone)
+GroupsProvider::GroupsProvider(int filterType)
+       : m_DbVersion(0), m_MembersDbVersion(0), m_UpdateType(UpdateNone), m_FilterType(filterType)
 {
 }
 
@@ -54,7 +54,7 @@ void GroupsProvider::onInitialize()
 
        DataList dataList;
        for (auto &&record : makeRange(list)) {
-               dataList.push_back(DataItemPtr(new Group(record)));
+               dataList.push_back(DataItemPtr(new Group(record, m_FilterType)));
        }
        contacts_list_destroy(list, false);
 
@@ -145,7 +145,7 @@ void GroupsProvider::onMembersChanged(const char *uri)
 
 void GroupsProvider::insertGroup(int id)
 {
-       insertDataItem(DataItemPtr(new Group(id)));
+       insertDataItem(DataItemPtr(new Group(id, m_FilterType)));
 }
 
 void GroupsProvider::updateGroup(DataList::const_iterator groupIt)
index 3527b89..1d1b7cc 100644 (file)
 
 using namespace Contacts::Groups;
 
-contacts_query_h Model::getMembersQuery(int groupId)
+contacts_query_h Model::getMembersQuery(int groupId, int filterType)
 {
        contacts_filter_h filter = nullptr;
        contacts_filter_create(_contacts_person_group_assigned._uri, &filter);
        contacts_filter_add_int(filter, _contacts_person_group_assigned.group_id,
                        CONTACTS_MATCH_EQUAL, groupId);
 
+       if (filterType != FilterNone) {
+               contacts_filter_h subFilter = nullptr;
+               contacts_filter_create(_contacts_person_group_assigned._uri, &subFilter);
+               if (filterType & FilterNumber) {
+                       contacts_filter_add_bool(subFilter, _contacts_person_group_assigned.has_phonenumber, true);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+               }
+               if (filterType & FilterEmail) {
+                       contacts_filter_add_bool(subFilter, _contacts_person_group_assigned.has_email, true);
+               }
+               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+               contacts_filter_add_filter(filter, subFilter);
+               contacts_filter_destroy(subFilter);
+       }
+
        contacts_query_h query = nullptr;
        contacts_query_create(_contacts_person_group_assigned._uri, &query);
        contacts_query_set_filter(query, filter);
@@ -34,13 +49,13 @@ contacts_query_h Model::getMembersQuery(int groupId)
        return query;
 }
 
-int Model::getMembersCount(int groupId)
+int Model::getMembersCount(int groupId, int filterType)
 {
        if (!groupId) {
                return 0;
        }
 
-       contacts_query_h query = getMembersQuery(groupId);
+       contacts_query_h query = getMembersQuery(groupId, filterType);
        int count = 0;
        contacts_db_get_count_with_query(query, &count);
        contacts_query_destroy(query);