on d996949 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
358 lines 8.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_optionselectorfilter.h"
25#include "fake_resultsmodel.h"
26#include "fake_scopes.h"
27#include "fake_settingsmodel.h"
29#include <paths.h> // from unity8/include
31Scope::Scope(Scopes* parent) : Scope("MockScope5", "Mock Scope", false, parent)
35Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview)
36 : unity::shell::scopes::ScopeInterface(parent)
37 , m_id(id)
38 , m_name(name)
39 , m_searching(false)
40 , m_favorite(favorite)
41 , m_isActive(false)
42 , m_hasNavigation(true)
43 , m_hasPrimaryFilter(true)
44 , m_currentNavigationId("root")
45 , m_previewRendererName("preview-generic")
46 , m_categories(new Categories(categories, this))
47 , m_openScope(nullptr)
48 , m_settings(new SettingsModel(this))
49 , m_filters(new Filters(this))
50 , m_returnNullPreview(returnNullPreview)
52 m_primaryNavigationFilter = new FakeOptionSelectorFilter("OSF3", "PFTag", "Which food you like More", false, QStringList() << "meat" << "vegetables", this);
53 connect(m_filters, &Filters::activeFiltersCountChanged, this, &Scope::activeFiltersCountChanged);
56QString Scope::id() const
58 return m_id;
61QString Scope::name() const
63 return m_name;
66QString Scope::searchQuery() const
68 return m_searchQuery;
71QString Scope::iconHint() const
73 return m_iconHint;
76QString Scope::description() const
78 return m_description;
81QString Scope::searchHint() const
83 return QString("Search %1").arg(m_name);
86QString Scope::shortcut() const
88 return QString("");
91bool Scope::searchInProgress() const
93 return m_searching;
96bool Scope::activationInProgress() const
98 return false;
101bool Scope::favorite() const
103 return m_favorite;
106unity::shell::scopes::CategoriesInterface* Scope::categories() const
108 return m_categories;
111unity::shell::scopes::SettingsModelInterface* Scope::settings() const
113 return m_settings;
116QString Scope::noResultsHint() const
118 return m_noResultsHint;
121QString Scope::formFactor() const
123 return m_formFactor;
126bool Scope::isActive() const
128 return m_isActive;
131void Scope::setSearchQuery(const QString &str)
133 if (str != m_searchQuery) {
134 m_searchQuery = str;
135 Q_EMIT searchQueryChanged();
136 }
139void Scope::setFormFactor(const QString &str)
141 if (str != m_formFactor) {
142 m_formFactor = str;
143 Q_EMIT formFactorChanged();
144 }
147void Scope::setActive(const bool active)
149 if (active != m_isActive) {
150 m_isActive = active;
151 Q_EMIT isActiveChanged();
152 }
155void Scope::setFavorite(const bool favorite)
157 if (favorite != m_favorite) {
158 m_favorite = favorite;
159 Q_EMIT favoriteChanged();
160 }
163void Scope::setId(const QString &id)
165 if (id != m_id) {
166 m_id = id;
167 Q_EMIT idChanged();
168 }
171void Scope::setName(const QString &name)
173 if (name != m_name) {
174 m_name = name;
175 Q_EMIT nameChanged();
176 }
179void Scope::setSearchInProgress(const bool inProg)
181 if (inProg != m_searching) {
182 m_searching = inProg;
183 Q_EMIT searchInProgressChanged();
184 }
187void Scope::setNoResultsHint(const QString& str)
189 if (str != m_noResultsHint) {
190 m_noResultsHint = str;
191 Q_EMIT noResultsHintChanged();
192 }
195void Scope::activate(QVariant const& result, QString const& categoryId)
197 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
198 if (result.toString() == "Result.2.2") {
199 Scopes *scopes = dynamic_cast<Scopes*>(parent());
200 m_openScope = scopes->getScopeFromAll("MockScope9");
201 scopes->addTempScope(m_openScope);
202 Q_EMIT openScope(m_openScope);
203 } else {
204 Q_EMIT previewRequested(result);
205 }
208PreviewModel* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
210 Q_UNUSED(result);
212 if (m_returnNullPreview) {
213 return nullptr;
214 } else {
215 return new PreviewModel(this, this);
216 }
219void Scope::cancelActivation()
223void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
225 Scopes *scopes = dynamic_cast<Scopes*>(parent());
226 if (scopes) {
227 return scopes->closeScope(scope);
228 }
231QString Scope::currentNavigationId() const
233 return m_currentNavigationId;
236bool Scope::hasNavigation() const
238 return m_hasNavigation;
241void Scope::setHasNavigation(bool hasNavigation)
243 m_hasNavigation = hasNavigation;
244 Q_EMIT hasNavigationChanged();
247Scope::Status Scope::status() const
249 return Status::Okay;
252QVariantMap Scope::customizations() const
254 QVariantMap m, h;
255 if (m_id == "clickscope") {
256 h["foreground-color"] = "yellow";
257 m["background-color"] = "red";
258 m["foreground-color"] = "blue";
259 m["page-header"] = h;
260 } else if (m_id == "MockScope4") {
261 h["navigation-background"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/artwork/background.png");
262 m["page-header"] = h;
263 } else if (m_id == "MockScope5") {
264 h["background"] = "gradient:///lightgrey/grey";
265 h["logo"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
266 h["divider-color"] = "red";
267 h["navigation-background"] = "color:///black";
268 m["page-header"] = h;
269 } else if (m_id == "MockScope6") {
270 h["navigation-background"] = "gradient:///blue/red";
271 m["page-header"] = h;
272 }
273 return m;
276void Scope::refresh()
278 Q_EMIT refreshed();
281void Scope::resetFilters()
283 qWarning() << "Scope::resetFilters is unimplemented";
286void Scope::activateAction(QVariant const& /*result*/, QString const& /*categoryId*/, QString const& /*actionId*/)
288 qFatal("Using Scope::activateAction");
291unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
293 if (id.isEmpty())
294 return nullptr;
296 QString parentId;
297 QString parentLabel;
298 if (id.startsWith("middle")) {
299 parentId = "root";
300 parentLabel = "root";
301 } else if (id.startsWith("child")) {
302 parentId = id.mid(5, 7);
303 parentLabel = parentId;
304 }
305 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
308void Scope::setNavigationState(const QString &navigationId)
310 m_currentNavigationId = navigationId;
311 Q_EMIT currentNavigationIdChanged();
312 Q_EMIT primaryNavigationTagChanged();
315unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() const
317 return m_hasPrimaryFilter ? m_primaryNavigationFilter : nullptr;
320unity::shell::scopes::FiltersInterface* Scope::filters() const
322 return m_filters;
325QString Scope::primaryNavigationTag() const
327 if (m_currentNavigationId == "root")
328 return QString();
329 else
330 return const_cast<Scope*>(this)->getNavigation(m_currentNavigationId)->label();
333int Scope::activeFiltersCount() const
335 return m_filters->activeFiltersCount();
338void Scope::resetPrimaryNavigationTag()
340 if (m_currentNavigationId != "root") {
341 setNavigationState("root");
342 }
345void Scope::setHasPrimaryFilter(bool hasPrimaryFilter)
347 m_hasPrimaryFilter = hasPrimaryFilter;
348 Q_EMIT primaryNavigationFilterChanged();
351void Scope::performQuery(const QString& query)
353 Q_EMIT queryPerformed(query);
354 if (query.startsWith("scopes://")) {
355 QString scopeId = query.mid(9);
356 Q_EMIT gotoScope(scopeId);
357 }