~mzanetti/unity8/modeswitchwarning

« back to all changes in this revision

Viewing changes to plugins/Utils/applicationsfiltermodel.cpp

  • Committer: Michael Zanetti
  • Date: 2015-10-09 09:57:09 UTC
  • Revision ID: michael.zanetti@canonical.com-20151009095709-ys1oyiur58m5locd
added a filter model for apps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// unity-api
 
2
#include <unity/shell/application/ApplicationManagerInterface.h>
 
3
#include <unity/shell/application/ApplicationInfoInterface.h>
 
4
 
 
5
#include "applicationsfiltermodel.h"
 
6
 
 
7
using namespace unity::shell::application;
 
8
 
 
9
ApplicationsFilterModel::ApplicationsFilterModel(QObject *parent):
 
10
    QSortFilterProxyModel(parent),
 
11
    m_appModel(nullptr),
 
12
    m_filterTouchApps(false),
 
13
    m_filterLegacyApps(false)
 
14
{
 
15
 
 
16
}
 
17
 
 
18
ApplicationManagerInterface *ApplicationsFilterModel::applicationsModel() const
 
19
{
 
20
    return m_appModel;
 
21
}
 
22
 
 
23
void ApplicationsFilterModel::setApplicationsModel(ApplicationManagerInterface *applicationsModel)
 
24
{
 
25
    if (m_appModel != applicationsModel) {
 
26
        m_appModel = applicationsModel;
 
27
        Q_EMIT applicationsModelChanged();
 
28
    }
 
29
}
 
30
 
 
31
bool ApplicationsFilterModel::filterTouchApps() const
 
32
{
 
33
    return m_filterTouchApps;
 
34
}
 
35
 
 
36
void ApplicationsFilterModel::setFilterTouchApps(bool filterTouchApps)
 
37
{
 
38
    if (m_filterTouchApps != filterTouchApps) {
 
39
        m_filterTouchApps = filterTouchApps;
 
40
        Q_EMIT filterTouchAppsChanged();
 
41
 
 
42
        invalidateFilter();
 
43
    }
 
44
}
 
45
 
 
46
bool ApplicationsFilterModel::filterLegacyApps() const
 
47
{
 
48
    return m_filterLegacyApps;
 
49
}
 
50
 
 
51
void ApplicationsFilterModel::setFilterLegacyApps(bool filterLegacyApps)
 
52
{
 
53
    if (m_filterLegacyApps != filterLegacyApps) {
 
54
        m_filterLegacyApps = filterLegacyApps;
 
55
        Q_EMIT filterLegacyAppsChanged();
 
56
 
 
57
        invalidateFilter();
 
58
    }
 
59
}
 
60
 
 
61
bool ApplicationsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
 
62
{
 
63
    Q_UNUSED(source_parent);
 
64
 
 
65
    ApplicationInfoInterface *app = m_appModel->get(source_row);
 
66
    Q_ASSERT(app);
 
67
    if (m_filterLegacyApps && !app->isTouchApp()) {
 
68
        return false;
 
69
    }
 
70
    if (m_filterTouchApps && app->isTouchApp()) {
 
71
        return false;
 
72
    }
 
73
    return true;
 
74
}