on a7ea6aa help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
200 lines 5.4 kB history raw
1/*
2 * Copyright (C) 2013 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// Self
18#include "fake_scope.h"
20#include <dee.h>
21#include "paths.h"
23static DeeModel* create_categories_model(unsigned category_count);
24static DeeModel* create_results_model(unsigned category_count, unsigned result_count);
26// TODO: Implement remaining pieces
28Scope::Scope(QObject* parent)
29 : QObject(parent)
30 , m_visible(false)
31 , m_categories(new Categories(this))
32 , m_results(new DeeListModel(this))
34 DeeModel* results_model = create_results_model(4, 30);
35 m_categories->setResultModel(results_model);
36 m_categories->setModel(create_categories_model(4));
37 m_results->setModel(results_model);
40Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent)
41 : QObject(parent)
42 , m_id(id)
43 , m_name(name)
44 , m_visible(visible)
45 , m_categories(new Categories(this))
46 , m_results(new DeeListModel(this))
48 DeeModel* results_model = create_results_model(4, 30);
49 m_categories->setResultModel(results_model);
50 m_categories->setModel(create_categories_model(4));
51 m_results->setModel(results_model);
54QString Scope::id() const {
55 return m_id;
58QString Scope::name() const {
59 return m_name;
62QString Scope::searchQuery() const {
63 return m_searchQuery;
66QString Scope::iconHint() const {
67 return m_iconHint;
70QString Scope::description() const {
71 return m_description;
74QString Scope::searchHint() const {
75 return QString("");
78QString Scope::shortcut() const {
79 return QString("");
82bool Scope::connected() const {
83 return true;
86Categories* Scope::categories() const {
87 return m_categories;
90QString Scope::noResultsHint() const {
91 return m_noResultsHint;
94QString Scope::formFactor() const {
95 return m_formFactor;
98bool Scope::visible() const {
99 return m_visible;
102void Scope::setName(const QString &str) {
103 if (str != m_name) {
104 m_name = str;
105 Q_EMIT nameChanged(m_name);
106 }
109void Scope::setSearchQuery(const QString &str) {
110 if (str != m_searchQuery) {
111 m_searchQuery = str;
112 Q_EMIT searchQueryChanged();
113 }
116void Scope::setFormFactor(const QString &str) {
117 if (str != m_formFactor) {
118 m_formFactor = str;
119 Q_EMIT formFactorChanged();
120 }
123void Scope::setNoResultsHint(const QString& str) {
124 if (str != m_noResultsHint) {
125 m_noResultsHint = str;
126 Q_EMIT noResultsHintChanged();
127 }
130static const gchar * categories_model_schema[] = {
131 "s", //ID
132 "s", // DISPLAY_NAME
133 "s", // ICON_HINT
134 "s", // RENDERER_NAME
135 "a{sv}" // HINTS
136};
139DeeModel* create_categories_model(unsigned category_count) {
140 DeeModel* category_model = dee_sequence_model_new();
141 dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
142 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
144 for(unsigned i = 0; i < category_count; ++i)
145 {
146 dee_model_append(category_model,
147 std::to_string(i).c_str(),
148 ("Category "+std::to_string(i)).c_str(),
149 "gtk-apply",
150 "grid",
151 hints);
152 }
153 return category_model;
157/* Schema that is used in the DeeModel representing
158 the results */
159static const gchar * results_model_schema[] = {
160 "s", // URI
161 "s", // ICON_HINT
162 "u", // CATEGORY
163 "u", // RESULT_TYPE
164 "s", // MIMETYPE
165 "s", // TITLE
166 "s", // COMMENT
167 "s", // DND_URI
168 "a{sv}" // METADATA
169};
171static const gchar * icons[] = {
172 "Applications.png",
173 "Home.png",
174 "Music.png",
175 "People.png",
176 "Videos.png",
177};
179DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
180 DeeModel* results_model = dee_sequence_model_new();
181 dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
182 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
184 for(unsigned i = 0; i < result_count; ++i)
185 {
186 unsigned category = i % category_count;
188 dee_model_append(results_model,
189 ("uri://result."+std::to_string(i)).c_str(),
190 (shellAppDirectory() + "Dash/graphics/scopeIcons/" + (icons[i%G_N_ELEMENTS(icons)])).toLatin1().data(),
191 category,
192 0,
193 "application/x-desktop",
194 ("Title."+std::to_string(i)).c_str(),
195 ("Comment."+std::to_string(i)).c_str(),
196 ("uri://result."+std::to_string(i)).c_str(),
197 hints);
198 }
199 return results_model;