on 8afbe69 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
169 lines 4.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"
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 m_categories->setModel(create_categories_model(4));
35 m_results->setModel(create_results_model(4, 30));
37 m_categories->setResultModel(m_results);
40Scope::Scope(QString const& id,
41 QString const& name,
42 bool visible,
43 QObject* parent)
44: QObject(parent),
45 m_id(id),
46 m_name(name),
47 m_visible(visible),
48 m_categories(new Categories(this)),
49 m_results(new DeeListModel(this))
51 m_categories->setModel(create_categories_model(4));
52 m_results->setModel(create_results_model(4, 30));
54 m_categories->setResultModel(m_results);
57QString Scope::id() const {
58 return m_id;
61QString Scope::name() const {
62 return m_name;
65QString Scope::searchQuery() const {
66 return m_searchQuery;
69void Scope::setName(const QString &str) {
70 if (str != m_name) {
71 m_name = str;
72 Q_EMIT nameChanged(m_name);
73 }
76void Scope::setSearchQuery(const QString &str) {
77 if (str != m_searchQuery) {
78 m_searchQuery = str;
79 Q_EMIT searchQueryChanged(m_searchQuery);
80 }
83bool Scope::visible() const {
84 return m_visible;
87Categories* Scope::categories() const {
88 return m_categories;
91static const gchar * categories_model_schema[] = {
92 "s", //ID
93 "s", // DISPLAY_NAME
94 "s", // ICON_HINT
95 "s", // RENDERER_NAME
96 "a{sv}" // HINTS
97};
100DeeModel* create_categories_model(unsigned category_count) {
101 DeeModel* category_model = dee_sequence_model_new();
102 dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
104 GVariantBuilder b;
105 g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
106 GVariant *hints = g_variant_builder_end(&b);
108 for(unsigned i = 0; i < category_count; ++i)
109 {
110 dee_model_append(category_model,
111 std::to_string(i).c_str(),
112 ("Category "+std::to_string(i)).c_str(),
113 "gtk-apply",
114 "grid",
115 hints);
116 }
117 g_variant_unref(hints);
118 return category_model;
122/* Schema that is used in the DeeModel representing
123 the results */
124static const gchar * results_model_schema[] = {
125 "s", // URI
126 "s", // ICON_HINT
127 "u", // CATEGORY
128 "u", // RESULT_TYPE
129 "s", // MIMETYPE
130 "s", // TITLE
131 "s", // COMMENT
132 "s", // DND_URI
133 "a{sv}" // METADATA
134};
136static const gchar * icons[] = {
137 "Applications.png",
138 "Home.png",
139 "Music.png",
140 "People.png",
141 "Videos.png",
142};
144DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
145 DeeModel* results_model = dee_sequence_model_new();
146 dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
148 GVariantBuilder b;
149 g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
150 GVariant *hints = g_variant_builder_end(&b);
152 for(unsigned i = 0; i < result_count; ++i)
153 {
154 unsigned category = i % category_count;
156 dee_model_append(results_model,
157 ("uri://result."+std::to_string(i)).c_str(),
158 (shellAppDirectory() + "Dash/graphics/scopeIcons/" + (icons[i%G_N_ELEMENTS(icons)])).toLatin1().data(),
159 category,
160 0,
161 "application/x-desktop",
162 ("Title."+std::to_string(i)).c_str(),
163 ("Comment."+std::to_string(i)).c_str(),
164 ("uri://result."+std::to_string(i)).c_str(),
165 hints);
166 }
167 g_variant_unref(hints);
168 return results_model;
169 }