on 558fc05 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
329 lines 7.3 kB history raw
1/*
2 * Copyright (C) 2013, 2014, 2015 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_filters.h"
23#include "fake_navigation.h"
24#include "fake_resultsmodel.h"
25#include "fake_scopes.h"
26#include "fake_settingsmodel.h"
28#include <paths.h> // from unity8/include
30Scope::Scope(Scopes* parent) : Scope("MockScope5", "Mock Scope", false, parent)
34Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview)
35 : unity::shell::scopes::ScopeInterface(parent)
36 , m_id(id)
37 , m_name(name)
38 , m_searching(false)
39 , m_favorite(favorite)
40 , m_isActive(false)
41 , m_currentNavigationId("root")
42 , m_previewRendererName("preview-generic")
43 , m_categories(new Categories(categories, this))
44 , m_openScope(nullptr)
45 , m_settings(new SettingsModel(this))
46 , m_filters(new Filters(this))
47 , m_returnNullPreview(returnNullPreview)
51QString Scope::id() const
53 return m_id;
56QString Scope::name() const
58 return m_name;
61QString Scope::searchQuery() const
63 return m_searchQuery;
66QString Scope::iconHint() const
68 return m_iconHint;
71QString Scope::description() const
73 return m_description;
76QString Scope::searchHint() const
78 return QString("Search %1").arg(m_name);
81QString Scope::shortcut() const
83 return QString("");
86bool Scope::searchInProgress() const
88 return m_searching;
91bool Scope::favorite() const
93 return m_favorite;
96unity::shell::scopes::CategoriesInterface* Scope::categories() const
98 return m_categories;
101unity::shell::scopes::SettingsModelInterface* Scope::settings() const
103 return m_settings;
106QString Scope::noResultsHint() const
108 return m_noResultsHint;
111QString Scope::formFactor() const
113 return m_formFactor;
116bool Scope::isActive() const
118 return m_isActive;
121void Scope::setSearchQuery(const QString &str)
123 if (str != m_searchQuery) {
124 m_searchQuery = str;
125 Q_EMIT searchQueryChanged();
126 }
129void Scope::setFormFactor(const QString &str)
131 if (str != m_formFactor) {
132 m_formFactor = str;
133 Q_EMIT formFactorChanged();
134 }
137void Scope::setActive(const bool active)
139 if (active != m_isActive) {
140 m_isActive = active;
141 Q_EMIT isActiveChanged();
142 }
145void Scope::setFavorite(const bool favorite)
147 if (favorite != m_favorite) {
148 m_favorite = favorite;
149 Q_EMIT favoriteChanged();
150 }
153void Scope::setId(const QString &id)
155 if (id != m_id) {
156 m_id = id;
157 Q_EMIT idChanged();
158 }
161void Scope::setName(const QString &name)
163 if (name != m_name) {
164 m_name = name;
165 Q_EMIT nameChanged();
166 }
169void Scope::setSearchInProgress(const bool inProg)
171 if (inProg != m_searching) {
172 m_searching = inProg;
173 Q_EMIT searchInProgressChanged();
174 }
177void Scope::setNoResultsHint(const QString& str)
179 if (str != m_noResultsHint) {
180 m_noResultsHint = str;
181 Q_EMIT noResultsHintChanged();
182 }
185void Scope::activate(QVariant const& result, QString const& categoryId)
187 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
188 if (result.toString() == "Result.2.2") {
189 Scopes *scopes = dynamic_cast<Scopes*>(parent());
190 m_openScope = scopes->getScopeFromAll("MockScope9");
191 scopes->addTempScope(m_openScope);
192 Q_EMIT openScope(m_openScope);
193 } else {
194 Q_EMIT previewRequested(result);
195 }
198PreviewStack* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
200 Q_UNUSED(result);
202 if (m_returnNullPreview) {
203 return nullptr;
204 } else {
205 // This probably leaks, do we don't care
206 // it's a test after all
207 return new PreviewStack(this, this);
208 }
211void Scope::cancelActivation()
215void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
217 Scopes *scopes = dynamic_cast<Scopes*>(parent());
218 if (scopes) {
219 return scopes->closeScope(scope);
220 }
223QString Scope::currentNavigationId() const
225 return m_currentNavigationId;
228bool Scope::hasNavigation() 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(sourceDirectory() + "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(sourceDirectory() + "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 Q_EMIT refreshed();
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);
284void Scope::setNavigationState(const QString &navigationId)
286 m_currentNavigationId = navigationId;
287 Q_EMIT currentNavigationIdChanged();
288 Q_EMIT primaryNavigationTagChanged();
291unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() const
293 return nullptr;
296unity::shell::scopes::FiltersInterface* Scope::filters() const
298 return m_filters;
301QString Scope::primaryNavigationTag() const
303 if (m_currentNavigationId == "root")
304 return QString();
305 else
306 return const_cast<Scope*>(this)->getNavigation(m_currentNavigationId)->label();
309int Scope::activeFiltersCount() const
311 // TODO
312 return 0;
315void Scope::resetPrimaryNavigationTag()
317 if (m_currentNavigationId != "root") {
318 setNavigationState("root");
319 }
322void Scope::performQuery(const QString& query)
324 Q_EMIT queryPerformed(query);
325 if (query.startsWith("scopes://")) {
326 QString scopeId = query.mid(9);
327 Q_EMIT gotoScope(scopeId);
328 }