on ed593dc help sign in
unity8/plugins/Utils/applicationsfiltermodel.cpp
101 lines 3.0 kB history raw
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 */
17// unity-api
18#include <unity/shell/application/ApplicationManagerInterface.h>
19#include <unity/shell/application/ApplicationInfoInterface.h>
21#include "applicationsfiltermodel.h"
23using namespace unity::shell::application;
25ApplicationsFilterModel::ApplicationsFilterModel(QObject *parent):
26 QSortFilterProxyModel(parent),
27 m_appModel(nullptr),
28 m_filterTouchApps(false),
29 m_filterLegacyApps(false)
33ApplicationManagerInterface *ApplicationsFilterModel::applicationsModel() const
35 return m_appModel;
38void ApplicationsFilterModel::setApplicationsModel(ApplicationManagerInterface *applicationsModel)
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 }
51bool ApplicationsFilterModel::filterTouchApps() const
53 return m_filterTouchApps;
56void ApplicationsFilterModel::setFilterTouchApps(bool filterTouchApps)
58 if (m_filterTouchApps != filterTouchApps) {
59 m_filterTouchApps = filterTouchApps;
60 Q_EMIT filterTouchAppsChanged();
62 invalidateFilter();
63 Q_EMIT countChanged();
64 }
67bool ApplicationsFilterModel::filterLegacyApps() const
69 return m_filterLegacyApps;
72void ApplicationsFilterModel::setFilterLegacyApps(bool filterLegacyApps)
74 if (m_filterLegacyApps != filterLegacyApps) {
75 m_filterLegacyApps = filterLegacyApps;
76 Q_EMIT filterLegacyAppsChanged();
78 invalidateFilter();
79 Q_EMIT countChanged();
80 }
83bool ApplicationsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
85 Q_UNUSED(source_parent);
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;
98ApplicationInfoInterface *ApplicationsFilterModel::get(int index) const
100 return m_appModel->get(mapToSource(this->index(index, 0)).row());