on ee5863a help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
237 lines 6.6 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::setSearchInProgress(const bool inProg) {
132 if (inProg != m_searching) {
133 m_searching = inProg;
134 Q_EMIT searchInProgressChanged();
135 }
138void Scope::setNoResultsHint(const QString& str) {
139 if (str != m_noResultsHint) {
140 m_noResultsHint = str;
141 Q_EMIT noResultsHintChanged();
142 }
145void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
146 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
147 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
149 Q_UNUSED(uri);
150 Q_UNUSED(icon_hint);
151 Q_UNUSED(category);
152 Q_UNUSED(result_type);
153 Q_UNUSED(mimetype);
154 Q_UNUSED(title);
155 Q_UNUSED(comment);
156 Q_UNUSED(dnd_uri);
157 Q_UNUSED(metadata);
160void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
161 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
162 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
164 Q_UNUSED(uri);
165 Q_UNUSED(icon_hint);
166 Q_UNUSED(category);
167 Q_UNUSED(result_type);
168 Q_UNUSED(mimetype);
169 Q_UNUSED(title);
170 Q_UNUSED(comment);
171 Q_UNUSED(dnd_uri);
172 Q_UNUSED(metadata);
175static const gchar * categories_model_schema[] = {
176 "s", //ID
177 "s", // DISPLAY_NAME
178 "s", // ICON_HINT
179 "s", // RENDERER_NAME
180 "a{sv}" // HINTS
181};
184DeeModel* create_categories_model(unsigned category_count) {
185 DeeModel* category_model = dee_sequence_model_new();
186 dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
187 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
189 for(unsigned i = 0; i < category_count; ++i)
190 {
191 dee_model_append(category_model,
192 std::to_string(i).c_str(),
193 ("Category "+std::to_string(i)).c_str(),
194 "gtk-apply",
195 "grid",
196 hints);
197 }
198 return category_model;
202/* Schema that is used in the DeeModel representing
203 the results */
204static const gchar * results_model_schema[] = {
205 "s", // URI
206 "s", // ICON_HINT
207 "u", // CATEGORY
208 "u", // RESULT_TYPE
209 "s", // MIMETYPE
210 "s", // TITLE
211 "s", // COMMENT
212 "s", // DND_URI
213 "a{sv}" // METADATA
214};
216DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
217 DeeModel* results_model = dee_sequence_model_new();
218 dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
219 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
221 for(unsigned i = 0; i < result_count; ++i)
222 {
223 unsigned category = i % category_count;
225 dee_model_append(results_model,
226 ("uri://result."+std::to_string(i)).c_str(),
227 (shellAppDirectory() + "graphics/applicationIcons/dash.png").toLatin1().data(),
228 category,
229 0,
230 "application/x-desktop",
231 ("Title."+std::to_string(i)).c_str(),
232 ("Comment."+std::to_string(i)).c_str(),
233 ("uri://result."+std::to_string(i)).c_str(),
234 hints);
235 }
236 return results_model;