on 2764051 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
301 lines 6.9 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"
27Scope::Scope(Scopes* parent) : Scope("MockScope5", "Mock Scope", false, parent)
31Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview)
32 : unity::shell::scopes::ScopeInterface(parent)
33 , m_id(id)
34 , m_name(name)
35 , m_searching(false)
36 , m_favorite(favorite)
37 , m_isActive(false)
38 , m_currentNavigationId("root")
39 , m_currentAltNavigationId("altroot")
40 , m_previewRendererName("preview-generic")
41 , m_categories(new Categories(categories, this))
42 , m_openScope(nullptr)
43 , m_settings(new SettingsModel(this))
44 , m_returnNullPreview(returnNullPreview)
48QString Scope::id() const
50 return m_id;
53QString Scope::name() const
55 return m_name;
58QString Scope::searchQuery() const
60 return m_searchQuery;
63QString Scope::iconHint() const
65 return m_iconHint;
68QString Scope::description() const
70 return m_description;
73QString Scope::searchHint() const
75 return QString("Search %1").arg(m_name);
78QString Scope::shortcut() const
80 return QString("");
83bool Scope::searchInProgress() const
85 return m_searching;
88bool Scope::favorite() const
90 return m_favorite;
93unity::shell::scopes::CategoriesInterface* Scope::categories() const
95 return m_categories;
98unity::shell::scopes::SettingsModelInterface* Scope::settings() const
100 return m_settings;
103QString Scope::noResultsHint() const
105 return m_noResultsHint;
108QString Scope::formFactor() const
110 return m_formFactor;
113bool Scope::isActive() const
115 return m_isActive;
118void Scope::setSearchQuery(const QString &str)
120 if (str != m_searchQuery) {
121 m_searchQuery = str;
122 Q_EMIT searchQueryChanged();
123 }
126void Scope::setFormFactor(const QString &str)
128 if (str != m_formFactor) {
129 m_formFactor = str;
130 Q_EMIT formFactorChanged();
131 }
134void Scope::setActive(const bool active)
136 if (active != m_isActive) {
137 m_isActive = active;
138 Q_EMIT isActiveChanged();
139 }
142void Scope::setFavorite(const bool favorite)
144 if (favorite != m_favorite) {
145 m_favorite = favorite;
146 Q_EMIT favoriteChanged();
147 }
149void Scope::setSearchInProgress(const bool inProg)
151 if (inProg != m_searching) {
152 m_searching = inProg;
153 Q_EMIT searchInProgressChanged();
154 }
157void Scope::setNoResultsHint(const QString& str)
159 if (str != m_noResultsHint) {
160 m_noResultsHint = str;
161 Q_EMIT noResultsHintChanged();
162 }
165void Scope::activate(QVariant const& result)
167 qDebug() << "Called activate on scope" << m_id << "with result" << result;
168 if (result.toString() == "Result.2.2") {
169 Scopes *scopes = dynamic_cast<Scopes*>(parent());
170 m_openScope = scopes->getScopeFromAll("MockScope9");
171 Q_EMIT openScope(m_openScope);
172 }
175PreviewStack* Scope::preview(QVariant const& result)
177 Q_UNUSED(result);
179 if (m_returnNullPreview) {
180 return nullptr;
181 }
182 else {
183 // This probably leaks, do we don't care
184 // it's a test after all
185 return new PreviewStack;
186 }
189void Scope::cancelActivation()
193void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
195 if (scope != m_openScope) {
196 qDebug() << scope << m_openScope;
197 qFatal("Scope::closeScope got wrong scope in closeScope");
198 }
199 m_openScope = nullptr;
202QString Scope::currentNavigationId() const
204 return m_currentNavigationId;
207bool Scope::hasNavigation() const
209 return true;
212QString Scope::currentAltNavigationId() const
214 return m_currentAltNavigationId;
217bool Scope::hasAltNavigation() const
219 return true;
222Scope::Status Scope::status() const
224 return Status::Okay;
227QVariantMap Scope::customizations() const
229 QVariantMap m, h;
230 if (m_id == "clickscope") {
231 h["foreground-color"] = "yellow";
232 m["background-color"] = "red";
233 m["foreground-color"] = "blue";
234 m["page-header"] = h;
235 } else if (m_id == "MockScope4") {
236 h["navigation-background"] = QUrl("../../../tests/qmltests/Dash/artwork/background.png");
237 m["page-header"] = h;
238 } else if (m_id == "MockScope5") {
239 h["background"] = "gradient:///lightgrey/grey";
240 h["logo"] = QUrl("../../../tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
241 h["divider-color"] = "red";
242 h["navigation-background"] = "color:///black";
243 m["page-header"] = h;
244 } else if (m_id == "MockScope6") {
245 h["navigation-background"] = "gradient:///blue/red";
246 m["page-header"] = h;
247 }
248 return m;
251void Scope::refresh()
253 qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
256unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
258 if (id.isEmpty())
259 return nullptr;
261 QString parentId;
262 QString parentLabel;
263 if (id.startsWith("middle")) {
264 parentId = "root";
265 parentLabel = "root";
266 } else if (id.startsWith("child")) {
267 parentId = id.mid(5, 7);
268 parentLabel = parentId;
269 }
270 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
273unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
275 if (id.isEmpty())
276 return nullptr;
278 QString parentId;
279 QString parentLabel;
280 if (id != "altroot") {
281 parentId = "altroot";
282 parentLabel = "altroot";
283 }
284 auto result = new Navigation(id, id, "all"+id, parentId, parentLabel, this);
285 if (id == "altroot") {
286 m_currentAltNavigationId = "altrootChild1";
287 Q_EMIT currentAltNavigationIdChanged();
288 }
289 return result;
292void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
294 if (isAltNavigation) {
295 m_currentAltNavigationId = navigationId;
296 Q_EMIT currentAltNavigationIdChanged();
297 } else {
298 m_currentNavigationId = navigationId;
299 Q_EMIT currentNavigationIdChanged();
300 }