Lomiri
Loading...
Searching...
No Matches
applicationsfiltermodel.cpp
1/*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17// lomiri-api
18#include <lomiri/shell/application/ApplicationManagerInterface.h>
19#include <lomiri/shell/application/ApplicationInfoInterface.h>
20
21#include "applicationsfiltermodel.h"
22
23using namespace lomiri::shell::application;
24
25ApplicationsFilterModel::ApplicationsFilterModel(QObject *parent):
26 QSortFilterProxyModel(parent),
27 m_appModel(nullptr),
28 m_filterTouchApps(false),
29 m_filterLegacyApps(false)
30{
31}
32
33ApplicationManagerInterface *ApplicationsFilterModel::applicationsModel() const
34{
35 return m_appModel;
36}
37
38void ApplicationsFilterModel::setApplicationsModel(ApplicationManagerInterface *applicationsModel)
39{
40 if (m_appModel != applicationsModel) {
41 if (m_appModel) {
42 disconnect(m_appModel, &ApplicationManagerInterface::countChanged, this, &ApplicationsFilterModel::countChanged);
43 }
44 m_appModel = applicationsModel;
45 setSourceModel(m_appModel);
46 Q_EMIT applicationsModelChanged();
47 connect(m_appModel, &ApplicationManagerInterface::countChanged, this, &ApplicationsFilterModel::countChanged);
48 }
49}
50
51bool ApplicationsFilterModel::filterTouchApps() const
52{
53 return m_filterTouchApps;
54}
55
56void ApplicationsFilterModel::setFilterTouchApps(bool filterTouchApps)
57{
58 if (m_filterTouchApps != filterTouchApps) {
59 m_filterTouchApps = filterTouchApps;
60 Q_EMIT filterTouchAppsChanged();
61
62 invalidateFilter();
63 Q_EMIT countChanged();
64 }
65}
66
67bool ApplicationsFilterModel::filterLegacyApps() const
68{
69 return m_filterLegacyApps;
70}
71
72void ApplicationsFilterModel::setFilterLegacyApps(bool filterLegacyApps)
73{
74 if (m_filterLegacyApps != filterLegacyApps) {
75 m_filterLegacyApps = filterLegacyApps;
76 Q_EMIT filterLegacyAppsChanged();
77
78 invalidateFilter();
79 Q_EMIT countChanged();
80 }
81}
82
83bool ApplicationsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
84{
85 Q_UNUSED(source_parent);
86
87 ApplicationInfoInterface *app = m_appModel->get(source_row);
88 Q_ASSERT(app);
89 if (m_filterLegacyApps && !app->isTouchApp()) {
90 return false;
91 }
92 if (m_filterTouchApps && app->isTouchApp()) {
93 return false;
94 }
95 return true;
96}
97
98ApplicationInfoInterface *ApplicationsFilterModel::get(int index) const
99{
100 return m_appModel->get(mapToSource(this->index(index, 0)).row());
101}