on 00a2ef4 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
328 lines 7.4 kB history raw
1/*
2 * Copyright (C) 2013, 2014 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#include <QDebug>
18#include <QUrl>
20#include "fake_scope.h"
22#include "fake_navigation.h"
23#include "fake_resultsmodel.h"
24#include "fake_scopes.h"
25#include "fake_settingsmodel.h"
27#include <paths.h> // from unity8/include
29Scope::Scope(Scopes* parent) : Scope("MockScope5", "Mock Scope", false, parent)
33Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview)
34 : unity::shell::scopes::ScopeInterface(parent)
35 , m_id(id)
36 , m_name(name)
37 , m_searching(false)
38 , m_favorite(favorite)
39 , m_isActive(false)
40 , m_currentNavigationId("root")
41 , m_currentAltNavigationId("altrootChild1")
42 , m_previewRendererName("preview-generic")
43 , m_categories(new Categories(categories, this))
44 , m_openScope(nullptr)
45 , m_settings(new SettingsModel(this))
46 , m_returnNullPreview(returnNullPreview)
50QString Scope::id() const
52 return m_id;
55QString Scope::name() const
57 return m_name;
60QString Scope::searchQuery() const
62 return m_searchQuery;
65QString Scope::iconHint() const
67 return m_iconHint;
70QString Scope::description() const
72 return m_description;
75QString Scope::searchHint() const
77 return QString("Search %1").arg(m_name);
80QString Scope::shortcut() const
82 return QString("");
85bool Scope::searchInProgress() const
87 return m_searching;
90bool Scope::favorite() const
92 return m_favorite;
95unity::shell::scopes::CategoriesInterface* Scope::categories() const
97 return m_categories;
100unity::shell::scopes::SettingsModelInterface* Scope::settings() const
102 return m_settings;
105QString Scope::noResultsHint() const
107 return m_noResultsHint;
110QString Scope::formFactor() const
112 return m_formFactor;
115bool Scope::isActive() const
117 return m_isActive;
120void Scope::setSearchQuery(const QString &str)
122 if (str != m_searchQuery) {
123 m_searchQuery = str;
124 Q_EMIT searchQueryChanged();
125 }
128void Scope::setFormFactor(const QString &str)
130 if (str != m_formFactor) {
131 m_formFactor = str;
132 Q_EMIT formFactorChanged();
133 }
136void Scope::setActive(const bool active)
138 if (active != m_isActive) {
139 m_isActive = active;
140 Q_EMIT isActiveChanged();
141 }
144void Scope::setFavorite(const bool favorite)
146 if (favorite != m_favorite) {
147 m_favorite = favorite;
148 Q_EMIT favoriteChanged();
149 }
152void Scope::setId(const QString &id)
154 if (id != m_id) {
155 m_id = id;
156 Q_EMIT idChanged();
157 }
160void Scope::setName(const QString &name)
162 if (name != m_name) {
163 m_name = name;
164 Q_EMIT nameChanged();
165 }
168void Scope::setSearchInProgress(const bool inProg)
170 if (inProg != m_searching) {
171 m_searching = inProg;
172 Q_EMIT searchInProgressChanged();
173 }
176void Scope::setNoResultsHint(const QString& str)
178 if (str != m_noResultsHint) {
179 m_noResultsHint = str;
180 Q_EMIT noResultsHintChanged();
181 }
184void Scope::activate(QVariant const& result, QString const& categoryId)
186 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
187 if (result.toString() == "Result.2.2") {
188 Scopes *scopes = dynamic_cast<Scopes*>(parent());
189 m_openScope = scopes->getScopeFromAll("MockScope9");
190 scopes->addTempScope(m_openScope);
191 Q_EMIT openScope(m_openScope);
192 } else {
193 Q_EMIT previewRequested(result);
194 }
197PreviewStack* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
199 Q_UNUSED(result);
201 if (m_returnNullPreview) {
202 return nullptr;
203 } else {
204 return new PreviewStack(this);
205 }
208void Scope::cancelActivation()
212void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
214 Scopes *scopes = dynamic_cast<Scopes*>(parent());
215 if (scopes) {
216 return scopes->closeScope(scope);
217 }
220QString Scope::currentNavigationId() const
222 return m_currentNavigationId;
225bool Scope::hasNavigation() const
227 return true;
230QString Scope::currentAltNavigationId() const
232 return m_currentAltNavigationId;
235bool Scope::hasAltNavigation() const
237 return true;
240Scope::Status Scope::status() const
242 return Status::Okay;
245QVariantMap Scope::customizations() const
247 QVariantMap m, h;
248 if (m_id == "clickscope") {
249 h["foreground-color"] = "yellow";
250 m["background-color"] = "red";
251 m["foreground-color"] = "blue";
252 m["page-header"] = h;
253 } else if (m_id == "MockScope4") {
254 h["navigation-background"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/artwork/background.png");
255 m["page-header"] = h;
256 } else if (m_id == "MockScope5") {
257 h["background"] = "gradient:///lightgrey/grey";
258 h["logo"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
259 h["divider-color"] = "red";
260 h["navigation-background"] = "color:///black";
261 m["page-header"] = h;
262 } else if (m_id == "MockScope6") {
263 h["navigation-background"] = "gradient:///blue/red";
264 m["page-header"] = h;
265 }
266 return m;
269void Scope::refresh()
271 Q_EMIT refreshed();
274void Scope::activateAction(QVariant const& /*result*/, QString const& /*categoryId*/, QString const& /*actionId*/)
276 qFatal("Using Scope::activateAction");
279unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
281 if (id.isEmpty())
282 return nullptr;
284 QString parentId;
285 QString parentLabel;
286 if (id.startsWith("middle")) {
287 parentId = "root";
288 parentLabel = "root";
289 } else if (id.startsWith("child")) {
290 parentId = id.mid(5, 7);
291 parentLabel = parentId;
292 }
293 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
296unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
298 if (id.isEmpty())
299 return nullptr;
301 QString parentId;
302 QString parentLabel;
303 if (id != "altroot") {
304 parentId = "altroot";
305 parentLabel = "altroot";
306 }
307 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
310void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
312 if (isAltNavigation) {
313 m_currentAltNavigationId = navigationId;
314 Q_EMIT currentAltNavigationIdChanged();
315 } else {
316 m_currentNavigationId = navigationId;
317 Q_EMIT currentNavigationIdChanged();
318 }
321void Scope::performQuery(const QString& query)
323 Q_EMIT queryPerformed(query);
324 if (query.startsWith("scopes://")) {
325 QString scopeId = query.mid(9);
326 Q_EMIT gotoScope(scopeId);
327 }