on 5ef5f08 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
312 lines 7.0 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(QString(), QString(), false, parent)
31Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories)
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))
47QString Scope::id() const
49 return m_id;
52QString Scope::name() const
54 return m_name;
57QString Scope::searchQuery() const
59 return m_searchQuery;
62QString Scope::iconHint() const
64 return m_iconHint;
67QString Scope::description() const
69 return m_description;
72QString Scope::searchHint() const
74 return QString("Search %1").arg(m_name);
77QString Scope::shortcut() const
79 return QString("");
82bool Scope::searchInProgress() const
84 return m_searching;
87bool Scope::favorite() const
89 return m_favorite;
92unity::shell::scopes::CategoriesInterface* Scope::categories() const
94 return m_categories;
97unity::shell::scopes::SettingsModelInterface* Scope::settings() const
99 return m_settings;
102QString Scope::noResultsHint() const
104 return m_noResultsHint;
107QString Scope::formFactor() const
109 return m_formFactor;
112bool Scope::isActive() const
114 return m_isActive;
117void Scope::setSearchQuery(const QString &str)
119 if (str != m_searchQuery) {
120 m_searchQuery = str;
121 Q_EMIT searchQueryChanged();
122 }
125void Scope::setFormFactor(const QString &str)
127 if (str != m_formFactor) {
128 m_formFactor = str;
129 Q_EMIT formFactorChanged();
130 }
133void Scope::setActive(const bool active)
135 if (active != m_isActive) {
136 m_isActive = active;
137 Q_EMIT isActiveChanged();
138 }
141void Scope::setFavorite(const bool favorite)
143 if (favorite != m_favorite) {
144 m_favorite = favorite;
145 Q_EMIT favoriteChanged();
146 }
149void Scope::setId(const QString &id)
151 if (id != m_id) {
152 m_id = id;
153 Q_EMIT idChanged();
154 }
157void Scope::setName(const QString &name)
159 if (name != m_name) {
160 m_name = name;
161 Q_EMIT nameChanged();
162 }
165void Scope::setSearchInProgress(const bool inProg)
167 if (inProg != m_searching) {
168 m_searching = inProg;
169 Q_EMIT searchInProgressChanged();
170 }
173void Scope::setNoResultsHint(const QString& str)
175 if (str != m_noResultsHint) {
176 m_noResultsHint = str;
177 Q_EMIT noResultsHintChanged();
178 }
181void Scope::activate(QVariant const& result)
183 qDebug() << "Called activate on scope" << m_id << "with result" << result;
184 if (result.toString() == "Result.2.2") {
185 Scopes *scopes = dynamic_cast<Scopes*>(parent());
186 m_openScope = scopes->getScopeFromAll("MockScope9");
187 Q_EMIT openScope(m_openScope);
188 }
191PreviewStack* Scope::preview(QVariant const& result)
193 Q_UNUSED(result);
195 // This probably leaks, do we don't care
196 // it's a test after all
197 return new PreviewStack;
200void Scope::cancelActivation()
204void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
206 if (scope != m_openScope) {
207 qDebug() << scope << m_openScope;
208 qFatal("Scope::closeScope got wrong scope in closeScope");
209 }
210 m_openScope = nullptr;
213QString Scope::currentNavigationId() const
215 return m_currentNavigationId;
218bool Scope::hasNavigation() const
220 return true;
223QString Scope::currentAltNavigationId() const
225 return m_currentAltNavigationId;
228bool Scope::hasAltNavigation() const
230 return true;
233Scope::Status Scope::status() const
235 return Status::Okay;
238QVariantMap Scope::customizations() const
240 QVariantMap m, h;
241 if (m_id == "clickscope") {
242 h["foreground-color"] = "yellow";
243 m["background-color"] = "red";
244 m["foreground-color"] = "blue";
245 m["page-header"] = h;
246 } else if (m_id == "MockScope4") {
247 h["navigation-background"] = QUrl("../../../tests/qmltests/Dash/artwork/background.png");
248 m["page-header"] = h;
249 } else if (m_id == "MockScope5") {
250 h["background"] = "gradient:///lightgrey/grey";
251 h["logo"] = QUrl("../../../tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
252 h["divider-color"] = "red";
253 h["navigation-background"] = "color:///black";
254 m["page-header"] = h;
255 } else if (m_id == "MockScope6") {
256 h["navigation-background"] = "gradient:///blue/red";
257 m["page-header"] = h;
258 }
259 return m;
262void Scope::refresh()
264 qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
267unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
269 if (id.isEmpty())
270 return nullptr;
272 QString parentId;
273 QString parentLabel;
274 if (id.startsWith("middle")) {
275 parentId = "root";
276 parentLabel = "root";
277 } else if (id.startsWith("child")) {
278 parentId = id.mid(5, 7);
279 parentLabel = parentId;
280 }
281 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
284unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
286 if (id.isEmpty())
287 return nullptr;
289 QString parentId;
290 QString parentLabel;
291 if (id != "altroot") {
292 parentId = "altroot";
293 parentLabel = "altroot";
294 }
295 auto result = new Navigation(id, id, "all"+id, parentId, parentLabel, this);
296 if (id == "altroot") {
297 m_currentAltNavigationId = "altrootChild1";
298 Q_EMIT currentAltNavigationIdChanged();
299 }
300 return result;
303void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
305 if (isAltNavigation) {
306 m_currentAltNavigationId = navigationId;
307 Q_EMIT currentAltNavigationIdChanged();
308 } else {
309 m_currentNavigationId = navigationId;
310 Q_EMIT currentNavigationIdChanged();
311 }