on 366698d help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
230 lines 6.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"
23#include "fake_preview.h"
25static DeeModel* create_categories_model(unsigned category_count);
26static DeeModel* create_results_model(unsigned category_count, unsigned result_count);
28// TODO: Implement remaining pieces
30Scope::Scope(QObject* parent)
31 : QObject(parent)
32 , m_visible(false)
33 , m_searching(false)
34 , m_categories(new Categories(this))
35 , m_results(new DeeListModel(this))
37 DeeModel* results_model = create_results_model(4, 30);
38 m_categories->setResultModel(results_model);
39 m_categories->setModel(create_categories_model(4));
40 m_results->setModel(results_model);
43Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent)
44 : QObject(parent)
45 , m_id(id)
46 , m_name(name)
47 , m_visible(visible)
48 , m_searching(false)
49 , m_categories(new Categories(this))
50 , m_results(new DeeListModel(this))
52 DeeModel* results_model = create_results_model(4, 30);
53 m_categories->setResultModel(results_model);
54 m_categories->setModel(create_categories_model(4));
55 m_results->setModel(results_model);
58QString Scope::id() const {
59 return m_id;
62QString Scope::name() const {
63 return m_name;
66QString Scope::searchQuery() const {
67 return m_searchQuery;
70QString Scope::iconHint() const {
71 return m_iconHint;
74QString Scope::description() const {
75 return m_description;
78QString Scope::searchHint() const {
79 return QString("");
82QString Scope::shortcut() const {
83 return QString("");
86bool Scope::connected() const {
87 return true;
90bool Scope::searchInProgress() const {
91 return m_searching;
94Categories* Scope::categories() const {
95 return m_categories;
98QString Scope::noResultsHint() const {
99 return m_noResultsHint;
102QString Scope::formFactor() const {
103 return m_formFactor;
106bool Scope::visible() const {
107 return m_visible;
110void Scope::setName(const QString &str) {
111 if (str != m_name) {
112 m_name = str;
113 Q_EMIT nameChanged(m_name);
114 }
117void Scope::setSearchQuery(const QString &str) {
118 if (str != m_searchQuery) {
119 m_searchQuery = str;
120 Q_EMIT searchQueryChanged();
121 }
124void Scope::setFormFactor(const QString &str) {
125 if (str != m_formFactor) {
126 m_formFactor = str;
127 Q_EMIT formFactorChanged();
128 }
131void Scope::setNoResultsHint(const QString& str) {
132 if (str != m_noResultsHint) {
133 m_noResultsHint = str;
134 Q_EMIT noResultsHintChanged();
135 }
138void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
139 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
140 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
142 Q_UNUSED(uri);
143 Q_UNUSED(icon_hint);
144 Q_UNUSED(category);
145 Q_UNUSED(result_type);
146 Q_UNUSED(mimetype);
147 Q_UNUSED(title);
148 Q_UNUSED(comment);
149 Q_UNUSED(dnd_uri);
150 Q_UNUSED(metadata);
153void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
154 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
155 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
157 Q_UNUSED(uri);
158 Q_UNUSED(icon_hint);
159 Q_UNUSED(category);
160 Q_UNUSED(result_type);
161 Q_UNUSED(mimetype);
162 Q_UNUSED(title);
163 Q_UNUSED(comment);
164 Q_UNUSED(dnd_uri);
165 Q_UNUSED(metadata);
168static const gchar * categories_model_schema[] = {
169 "s", //ID
170 "s", // DISPLAY_NAME
171 "s", // ICON_HINT
172 "s", // RENDERER_NAME
173 "a{sv}" // HINTS
174};
177DeeModel* create_categories_model(unsigned category_count) {
178 DeeModel* category_model = dee_sequence_model_new();
179 dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
180 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
182 for(unsigned i = 0; i < category_count; ++i)
183 {
184 dee_model_append(category_model,
185 std::to_string(i).c_str(),
186 ("Category "+std::to_string(i)).c_str(),
187 "gtk-apply",
188 "grid",
189 hints);
190 }
191 return category_model;
195/* Schema that is used in the DeeModel representing
196 the results */
197static const gchar * results_model_schema[] = {
198 "s", // URI
199 "s", // ICON_HINT
200 "u", // CATEGORY
201 "u", // RESULT_TYPE
202 "s", // MIMETYPE
203 "s", // TITLE
204 "s", // COMMENT
205 "s", // DND_URI
206 "a{sv}" // METADATA
207};
209DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
210 DeeModel* results_model = dee_sequence_model_new();
211 dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
212 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
214 for(unsigned i = 0; i < result_count; ++i)
215 {
216 unsigned category = i % category_count;
218 dee_model_append(results_model,
219 ("uri://result."+std::to_string(i)).c_str(),
220 (shellAppDirectory() + "graphics/applicationIcons/dash.png").toLatin1().data(),
221 category,
222 0,
223 "application/x-desktop",
224 ("Title."+std::to_string(i)).c_str(),
225 ("Comment."+std::to_string(i)).c_str(),
226 ("uri://result."+std::to_string(i)).c_str(),
227 hints);
228 }
229 return results_model;