on 8755192 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
333 lines 7.5 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::activationInProgress() const
92 return false;
95bool Scope::favorite() const
97 return m_favorite;
100unity::shell::scopes::CategoriesInterface* Scope::categories() const
102 return m_categories;
105unity::shell::scopes::SettingsModelInterface* Scope::settings() const
107 return m_settings;
110QString Scope::noResultsHint() const
112 return m_noResultsHint;
115QString Scope::formFactor() const
117 return m_formFactor;
120bool Scope::isActive() const
122 return m_isActive;
125void Scope::setSearchQuery(const QString &str)
127 if (str != m_searchQuery) {
128 m_searchQuery = str;
129 Q_EMIT searchQueryChanged();
130 }
133void Scope::setFormFactor(const QString &str)
135 if (str != m_formFactor) {
136 m_formFactor = str;
137 Q_EMIT formFactorChanged();
138 }
141void Scope::setActive(const bool active)
143 if (active != m_isActive) {
144 m_isActive = active;
145 Q_EMIT isActiveChanged();
146 }
149void Scope::setFavorite(const bool favorite)
151 if (favorite != m_favorite) {
152 m_favorite = favorite;
153 Q_EMIT favoriteChanged();
154 }
157void Scope::setId(const QString &id)
159 if (id != m_id) {
160 m_id = id;
161 Q_EMIT idChanged();
162 }
165void Scope::setName(const QString &name)
167 if (name != m_name) {
168 m_name = name;
169 Q_EMIT nameChanged();
170 }
173void Scope::setSearchInProgress(const bool inProg)
175 if (inProg != m_searching) {
176 m_searching = inProg;
177 Q_EMIT searchInProgressChanged();
178 }
181void Scope::setNoResultsHint(const QString& str)
183 if (str != m_noResultsHint) {
184 m_noResultsHint = str;
185 Q_EMIT noResultsHintChanged();
186 }
189void Scope::activate(QVariant const& result, QString const& categoryId)
191 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
192 if (result.toString() == "Result.2.2") {
193 Scopes *scopes = dynamic_cast<Scopes*>(parent());
194 m_openScope = scopes->getScopeFromAll("MockScope9");
195 scopes->addTempScope(m_openScope);
196 Q_EMIT openScope(m_openScope);
197 } else {
198 Q_EMIT previewRequested(result);
199 }
202PreviewModel* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
204 Q_UNUSED(result);
206 if (m_returnNullPreview) {
207 return nullptr;
208 } else {
209 return new PreviewModel(this, this);
210 }
213void Scope::cancelActivation()
217void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
219 Scopes *scopes = dynamic_cast<Scopes*>(parent());
220 if (scopes) {
221 return scopes->closeScope(scope);
222 }
225QString Scope::currentNavigationId() const
227 return m_currentNavigationId;
230bool Scope::hasNavigation() const
232 return true;
235QString Scope::currentAltNavigationId() const
237 return m_currentAltNavigationId;
240bool Scope::hasAltNavigation() const
242 return true;
245Scope::Status Scope::status() const
247 return Status::Okay;
250QVariantMap Scope::customizations() const
252 QVariantMap m, h;
253 if (m_id == "clickscope") {
254 h["foreground-color"] = "yellow";
255 m["background-color"] = "red";
256 m["foreground-color"] = "blue";
257 m["page-header"] = h;
258 } else if (m_id == "MockScope4") {
259 h["navigation-background"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/artwork/background.png");
260 m["page-header"] = h;
261 } else if (m_id == "MockScope5") {
262 h["background"] = "gradient:///lightgrey/grey";
263 h["logo"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
264 h["divider-color"] = "red";
265 h["navigation-background"] = "color:///black";
266 m["page-header"] = h;
267 } else if (m_id == "MockScope6") {
268 h["navigation-background"] = "gradient:///blue/red";
269 m["page-header"] = h;
270 }
271 return m;
274void Scope::refresh()
276 Q_EMIT refreshed();
279void Scope::activateAction(QVariant const& /*result*/, QString const& /*categoryId*/, QString const& /*actionId*/)
281 qFatal("Using Scope::activateAction");
284unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
286 if (id.isEmpty())
287 return nullptr;
289 QString parentId;
290 QString parentLabel;
291 if (id.startsWith("middle")) {
292 parentId = "root";
293 parentLabel = "root";
294 } else if (id.startsWith("child")) {
295 parentId = id.mid(5, 7);
296 parentLabel = parentId;
297 }
298 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
301unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
303 if (id.isEmpty())
304 return nullptr;
306 QString parentId;
307 QString parentLabel;
308 if (id != "altroot") {
309 parentId = "altroot";
310 parentLabel = "altroot";
311 }
312 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
315void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
317 if (isAltNavigation) {
318 m_currentAltNavigationId = navigationId;
319 Q_EMIT currentAltNavigationIdChanged();
320 } else {
321 m_currentNavigationId = navigationId;
322 Q_EMIT currentNavigationIdChanged();
323 }
326void Scope::performQuery(const QString& query)
328 Q_EMIT queryPerformed(query);
329 if (query.startsWith("scopes://")) {
330 QString scopeId = query.mid(9);
331 Q_EMIT gotoScope(scopeId);
332 }