on dd024c8 help sign in
unity8/plugins/Unity/categoryresults.cpp
96 lines 2.8 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Michal Hruby <michal.hruby@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
20// self
21#include "categoryresults.h"
23// TODO: use something from libunity once it's public
24enum ResultsColumn {
25 URI,
26 ICON_HINT,
27 CATEGORY,
28 RESULT_TYPE,
29 MIMETYPE,
30 TITLE,
31 COMMENT,
32 DND_URI,
33 METADATA
34};
36CategoryResults::CategoryResults(QObject* parent)
37 : DeeListModel(parent)
38 , m_categoryIndex(-1)
40 m_roles[CategoryResults::RoleUri] = "uri";
41 m_roles[CategoryResults::RoleIconHint] = "icon";
42 m_roles[CategoryResults::RoleCategory] = "category";
43 m_roles[CategoryResults::RoleMimetype] = "mimetype";
44 m_roles[CategoryResults::RoleTitle] = "title";
45 m_roles[CategoryResults::RoleComment] = "comment";
46 m_roles[CategoryResults::RoleDndUri] = "dndUri";
47 m_roles[CategoryResults::RoleMetadata] = "metadata";
50int CategoryResults::categoryIndex() const
52 return m_categoryIndex;
55void CategoryResults::setCategoryIndex(int index)
57 if (m_categoryIndex != index) {
58 m_categoryIndex = index;
59 Q_EMIT categoryIndexChanged(m_categoryIndex);
60 }
63QHash<int, QByteArray>
64CategoryResults::roleNames() const
66 return m_roles;
69QVariant
70CategoryResults::data(const QModelIndex& index, int role) const
72 if (!index.isValid()) {
73 return QVariant();
74 }
76 switch (role) {
77 case RoleUri:
78 return DeeListModel::data(index, ResultsColumn::URI);
79 case RoleIconHint:
80 return DeeListModel::data(index, ResultsColumn::ICON_HINT);
81 case RoleCategory:
82 return DeeListModel::data(index, ResultsColumn::CATEGORY);
83 case RoleMimetype:
84 return DeeListModel::data(index, ResultsColumn::MIMETYPE);
85 case RoleTitle:
86 return DeeListModel::data(index, ResultsColumn::TITLE);
87 case RoleComment:
88 return DeeListModel::data(index, ResultsColumn::COMMENT);
89 case RoleDndUri:
90 return DeeListModel::data(index, ResultsColumn::DND_URI);
91 case RoleMetadata:
92 return DeeListModel::data(index, ResultsColumn::METADATA);
93 default:
94 return QVariant();
95 }