on f621663 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
295 lines 6.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"
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 }
148void Scope::setSearchInProgress(const bool inProg)
150 if (inProg != m_searching) {
151 m_searching = inProg;
152 Q_EMIT searchInProgressChanged();
153 }
156void Scope::setNoResultsHint(const QString& str)
158 if (str != m_noResultsHint) {
159 m_noResultsHint = str;
160 Q_EMIT noResultsHintChanged();
161 }
164void Scope::activate(QVariant const& result)
166 qDebug() << "Called activate on scope" << m_id << "with result" << result;
167 if (result.toString() == "Result.2.2") {
168 Scopes *scopes = dynamic_cast<Scopes*>(parent());
169 m_openScope = scopes->getScopeFromAll("MockScope9");
170 Q_EMIT openScope(m_openScope);
171 }
174PreviewStack* Scope::preview(QVariant const& result)
176 Q_UNUSED(result);
178 // This probably leaks, do we don't care
179 // it's a test after all
180 return new PreviewStack;
183void Scope::cancelActivation()
187void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
189 if (scope != m_openScope) {
190 qDebug() << scope << m_openScope;
191 qFatal("Scope::closeScope got wrong scope in closeScope");
192 }
193 m_openScope = nullptr;
196QString Scope::currentNavigationId() const
198 return m_currentNavigationId;
201bool Scope::hasNavigation() const
203 return true;
206QString Scope::currentAltNavigationId() const
208 return m_currentAltNavigationId;
211bool Scope::hasAltNavigation() const
213 return true;
216Scope::Status Scope::status() const
218 return Status::Okay;
221QVariantMap Scope::customizations() const
223 QVariantMap m, h;
224 if (m_id == "clickscope") {
225 h["foreground-color"] = "yellow";
226 m["background-color"] = "red";
227 m["foreground-color"] = "blue";
228 m["page-header"] = h;
229 } else if (m_id == "MockScope4") {
230 h["navigation-background"] = QUrl("../../../tests/qmltests/Dash/artwork/background.png");
231 m["page-header"] = h;
232 } else if (m_id == "MockScope5") {
233 h["background"] = "gradient:///lightgrey/grey";
234 h["logo"] = QUrl("../../../tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
235 h["divider-color"] = "red";
236 h["navigation-background"] = "color:///black";
237 m["page-header"] = h;
238 } else if (m_id == "MockScope6") {
239 h["navigation-background"] = "gradient:///blue/red";
240 m["page-header"] = h;
241 }
242 return m;
245void Scope::refresh()
247 qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
250unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
252 if (id.isEmpty())
253 return nullptr;
255 QString parentId;
256 QString parentLabel;
257 if (id.startsWith("middle")) {
258 parentId = "root";
259 parentLabel = "root";
260 } else if (id.startsWith("child")) {
261 parentId = id.mid(5, 7);
262 parentLabel = parentId;
263 }
264 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
267unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
269 if (id.isEmpty())
270 return nullptr;
272 QString parentId;
273 QString parentLabel;
274 if (id != "altroot") {
275 parentId = "altroot";
276 parentLabel = "altroot";
277 }
278 auto result = new Navigation(id, id, "all"+id, parentId, parentLabel, this);
279 if (id == "altroot") {
280 m_currentAltNavigationId = "altrootChild1";
281 Q_EMIT currentAltNavigationIdChanged();
282 }
283 return result;
286void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
288 if (isAltNavigation) {
289 m_currentAltNavigationId = navigationId;
290 Q_EMIT currentAltNavigationIdChanged();
291 } else {
292 m_currentNavigationId = navigationId;
293 Q_EMIT currentNavigationIdChanged();
294 }