on 00a39ec help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
224 lines 6.3 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_categories(new Categories(this))
34 , m_results(new DeeListModel(this))
36 DeeModel* results_model = create_results_model(4, 30);
37 m_categories->setResultModel(results_model);
38 m_categories->setModel(create_categories_model(4));
39 m_results->setModel(results_model);
42Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent)
43 : QObject(parent)
44 , m_id(id)
45 , m_name(name)
46 , m_visible(visible)
47 , m_categories(new Categories(this))
48 , m_results(new DeeListModel(this))
50 DeeModel* results_model = create_results_model(4, 30);
51 m_categories->setResultModel(results_model);
52 m_categories->setModel(create_categories_model(4));
53 m_results->setModel(results_model);
56QString Scope::id() const {
57 return m_id;
60QString Scope::name() const {
61 return m_name;
64QString Scope::searchQuery() const {
65 return m_searchQuery;
68QString Scope::iconHint() const {
69 return m_iconHint;
72QString Scope::description() const {
73 return m_description;
76QString Scope::searchHint() const {
77 return QString("");
80QString Scope::shortcut() const {
81 return QString("");
84bool Scope::connected() const {
85 return true;
88Categories* Scope::categories() const {
89 return m_categories;
92QString Scope::noResultsHint() const {
93 return m_noResultsHint;
96QString Scope::formFactor() const {
97 return m_formFactor;
100bool Scope::visible() const {
101 return m_visible;
104void Scope::setName(const QString &str) {
105 if (str != m_name) {
106 m_name = str;
107 Q_EMIT nameChanged(m_name);
108 }
111void Scope::setSearchQuery(const QString &str) {
112 if (str != m_searchQuery) {
113 m_searchQuery = str;
114 Q_EMIT searchQueryChanged();
115 }
118void Scope::setFormFactor(const QString &str) {
119 if (str != m_formFactor) {
120 m_formFactor = str;
121 Q_EMIT formFactorChanged();
122 }
125void Scope::setNoResultsHint(const QString& str) {
126 if (str != m_noResultsHint) {
127 m_noResultsHint = str;
128 Q_EMIT noResultsHintChanged();
129 }
132void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
133 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
134 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
136 Q_UNUSED(uri);
137 Q_UNUSED(icon_hint);
138 Q_UNUSED(category);
139 Q_UNUSED(result_type);
140 Q_UNUSED(mimetype);
141 Q_UNUSED(title);
142 Q_UNUSED(comment);
143 Q_UNUSED(dnd_uri);
144 Q_UNUSED(metadata);
147void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
148 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
149 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
151 Q_UNUSED(uri);
152 Q_UNUSED(icon_hint);
153 Q_UNUSED(category);
154 Q_UNUSED(result_type);
155 Q_UNUSED(mimetype);
156 Q_UNUSED(title);
157 Q_UNUSED(comment);
158 Q_UNUSED(dnd_uri);
159 Q_UNUSED(metadata);
162static const gchar * categories_model_schema[] = {
163 "s", //ID
164 "s", // DISPLAY_NAME
165 "s", // ICON_HINT
166 "s", // RENDERER_NAME
167 "a{sv}" // HINTS
168};
171DeeModel* create_categories_model(unsigned category_count) {
172 DeeModel* category_model = dee_sequence_model_new();
173 dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
174 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
176 for(unsigned i = 0; i < category_count; ++i)
177 {
178 dee_model_append(category_model,
179 std::to_string(i).c_str(),
180 ("Category "+std::to_string(i)).c_str(),
181 "gtk-apply",
182 "grid",
183 hints);
184 }
185 return category_model;
189/* Schema that is used in the DeeModel representing
190 the results */
191static const gchar * results_model_schema[] = {
192 "s", // URI
193 "s", // ICON_HINT
194 "u", // CATEGORY
195 "u", // RESULT_TYPE
196 "s", // MIMETYPE
197 "s", // TITLE
198 "s", // COMMENT
199 "s", // DND_URI
200 "a{sv}" // METADATA
201};
203DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
204 DeeModel* results_model = dee_sequence_model_new();
205 dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
206 GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
208 for(unsigned i = 0; i < result_count; ++i)
209 {
210 unsigned category = i % category_count;
212 dee_model_append(results_model,
213 ("uri://result."+std::to_string(i)).c_str(),
214 (shellAppDirectory() + "graphics/applicationIcons/dash.png").toLatin1().data(),
215 category,
216 0,
217 "application/x-desktop",
218 ("Title."+std::to_string(i)).c_str(),
219 ("Comment."+std::to_string(i)).c_str(),
220 ("uri://result."+std::to_string(i)).c_str(),
221 hints);
222 }
223 return results_model;