on e700c19 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
268 lines 5.7 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"
21#include "fake_navigation.h"
22#include "fake_resultsmodel.h"
24Scope::Scope(QObject* parent) : Scope(QString(), QString(), false, parent)
28Scope::Scope(QString const& id, QString const& name, bool favorite, QObject* parent, int categories)
29 : unity::shell::scopes::ScopeInterface(parent)
30 , m_id(id)
31 , m_name(name)
32 , m_searching(false)
33 , m_favorite(favorite)
34 , m_isActive(false)
35 , m_currentNavigationId("root")
36 , m_currentAltNavigationId("altroot")
37 , m_previewRendererName("preview-generic")
38 , m_categories(new Categories(categories, this))
42QString Scope::id() const
44 return m_id;
47QString Scope::name() const
49 return m_name;
52QString Scope::searchQuery() const
54 return m_searchQuery;
57QString Scope::iconHint() const
59 return m_iconHint;
62QString Scope::description() const
64 return m_description;
67QString Scope::searchHint() const
69 return QString("");
72QString Scope::shortcut() const
74 return QString("");
77bool Scope::searchInProgress() const
79 return m_searching;
82bool Scope::favorite() const
84 return m_favorite;
87unity::shell::scopes::CategoriesInterface* Scope::categories() const
89 return m_categories;
92unity::shell::scopes::SettingsModelInterface* Scope::settings() const
94 return nullptr;
97QString Scope::noResultsHint() const
99 return m_noResultsHint;
102QString Scope::formFactor() const
104 return m_formFactor;
107bool Scope::isActive() const
109 return m_isActive;
112void Scope::setSearchQuery(const QString &str)
114 if (str != m_searchQuery) {
115 m_searchQuery = str;
116 Q_EMIT searchQueryChanged();
117 }
120void Scope::setFormFactor(const QString &str)
122 if (str != m_formFactor) {
123 m_formFactor = str;
124 Q_EMIT formFactorChanged();
125 }
128void Scope::setActive(const bool active)
130 if (active != m_isActive) {
131 m_isActive = active;
132 Q_EMIT isActiveChanged();
133 }
136void Scope::setFavorite(const bool favorite)
138 if (favorite != m_favorite) {
139 m_favorite = favorite;
140 Q_EMIT favoriteChanged();
141 }
143void Scope::setSearchInProgress(const bool inProg)
145 if (inProg != m_searching) {
146 m_searching = inProg;
147 Q_EMIT searchInProgressChanged();
148 }
151void Scope::setNoResultsHint(const QString& str)
153 if (str != m_noResultsHint) {
154 m_noResultsHint = str;
155 Q_EMIT noResultsHintChanged();
156 }
159void Scope::activate(QVariant const& result)
161 Q_UNUSED(result);
164PreviewStack* Scope::preview(QVariant const& result)
166 Q_UNUSED(result);
168 // This probably leaks, do we don't care
169 // it's a test after all
170 return new PreviewStack;
173void Scope::cancelActivation()
177void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
179 qFatal("Scope::closeScope is not implemented");
182QString Scope::currentNavigationId() const
184 return m_currentNavigationId;
187bool Scope::hasNavigation() const
189 return true;
192QString Scope::currentAltNavigationId() const
194 return m_currentAltNavigationId;
197bool Scope::hasAltNavigation() const
199 return true;
202Scope::Status Scope::status() const
204 return Status::Okay;
207QVariantMap Scope::customizations() const
209 QVariantMap m, h;
210 if (m_id == "clickscope") {
211 h["foreground-color"] = "yellow";
212 m["background-color"] = "red";
213 m["foreground-color"] = "blue";
214 m["page-header"] = h;
215 } else if (m_id == "MockScope5") {
216 h["background"] = "gradient:///lightgrey/grey";
217 h["logo"] = QUrl("../../../tests/qmltests/Components/tst_PageHeader/logo-ubuntu-orange.svg");
218 m["page-header"] = h;
219 }
220 return m;
223void Scope::refresh()
225 qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
228unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
230 if (id.isEmpty())
231 return nullptr;
233 QString parentId;
234 QString parentLabel;
235 if (id.startsWith("middle")) {
236 parentId = "root";
237 parentLabel = "root";
238 } else if (id.startsWith("child")) {
239 parentId = id.mid(5, 7);
240 parentLabel = parentId;
241 }
242 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
245unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
247 if (id.isEmpty())
248 return nullptr;
250 QString parentId;
251 QString parentLabel;
252 if (id.startsWith("altmiddle")) {
253 parentId = "altroot";
254 parentLabel = "altroot";
255 }
256 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
259void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
261 if (isAltNavigation) {
262 m_currentAltNavigationId = navigationId;
263 Q_EMIT currentAltNavigationIdChanged();
264 } else {
265 m_currentNavigationId = navigationId;
266 Q_EMIT currentNavigationIdChanged();
267 }