on 455d32d help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
353 lines 8.2 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::favorite() const
98 return m_favorite;
101unity::shell::scopes::CategoriesInterface* Scope::categories() const
103 return m_categories;
106unity::shell::scopes::SettingsModelInterface* Scope::settings() const
108 return m_settings;
111QString Scope::noResultsHint() const
113 return m_noResultsHint;
116QString Scope::formFactor() const
118 return m_formFactor;
121bool Scope::isActive() const
123 return m_isActive;
126void Scope::setSearchQuery(const QString &str)
128 if (str != m_searchQuery) {
129 m_searchQuery = str;
130 Q_EMIT searchQueryChanged();
131 }
134void Scope::setFormFactor(const QString &str)
136 if (str != m_formFactor) {
137 m_formFactor = str;
138 Q_EMIT formFactorChanged();
139 }
142void Scope::setActive(const bool active)
144 if (active != m_isActive) {
145 m_isActive = active;
146 Q_EMIT isActiveChanged();
147 }
150void Scope::setFavorite(const bool favorite)
152 if (favorite != m_favorite) {
153 m_favorite = favorite;
154 Q_EMIT favoriteChanged();
155 }
158void Scope::setId(const QString &id)
160 if (id != m_id) {
161 m_id = id;
162 Q_EMIT idChanged();
163 }
166void Scope::setName(const QString &name)
168 if (name != m_name) {
169 m_name = name;
170 Q_EMIT nameChanged();
171 }
174void Scope::setSearchInProgress(const bool inProg)
176 if (inProg != m_searching) {
177 m_searching = inProg;
178 Q_EMIT searchInProgressChanged();
179 }
182void Scope::setNoResultsHint(const QString& str)
184 if (str != m_noResultsHint) {
185 m_noResultsHint = str;
186 Q_EMIT noResultsHintChanged();
187 }
190void Scope::activate(QVariant const& result, QString const& categoryId)
192 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
193 if (result.toString() == "Result.2.2") {
194 Scopes *scopes = dynamic_cast<Scopes*>(parent());
195 m_openScope = scopes->getScopeFromAll("MockScope9");
196 scopes->addTempScope(m_openScope);
197 Q_EMIT openScope(m_openScope);
198 } else {
199 Q_EMIT previewRequested(result);
200 }
203PreviewStack* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
205 Q_UNUSED(result);
207 if (m_returnNullPreview) {
208 return nullptr;
209 } else {
210 return new PreviewStack(this);
211 }
214void Scope::cancelActivation()
218void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
220 Scopes *scopes = dynamic_cast<Scopes*>(parent());
221 if (scopes) {
222 return scopes->closeScope(scope);
223 }
226QString Scope::currentNavigationId() const
228 return m_currentNavigationId;
231bool Scope::hasNavigation() const
233 return m_hasNavigation;
236void Scope::setHasNavigation(bool hasNavigation)
238 m_hasNavigation = hasNavigation;
239 Q_EMIT hasNavigationChanged();
242Scope::Status Scope::status() const
244 return Status::Okay;
247QVariantMap Scope::customizations() const
249 QVariantMap m, h;
250 if (m_id == "clickscope") {
251 h["foreground-color"] = "yellow";
252 m["background-color"] = "red";
253 m["foreground-color"] = "blue";
254 m["page-header"] = h;
255 } else if (m_id == "MockScope4") {
256 h["navigation-background"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/artwork/background.png");
257 m["page-header"] = h;
258 } else if (m_id == "MockScope5") {
259 h["background"] = "gradient:///lightgrey/grey";
260 h["logo"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
261 h["divider-color"] = "red";
262 h["navigation-background"] = "color:///black";
263 m["page-header"] = h;
264 } else if (m_id == "MockScope6") {
265 h["navigation-background"] = "gradient:///blue/red";
266 m["page-header"] = h;
267 }
268 return m;
271void Scope::refresh()
273 Q_EMIT refreshed();
276void Scope::resetFilters()
278 qWarning() << "Scope::resetFilters is unimplemented";
281void Scope::activateAction(QVariant const& /*result*/, QString const& /*categoryId*/, QString const& /*actionId*/)
283 qFatal("Using Scope::activateAction");
286unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
288 if (id.isEmpty())
289 return nullptr;
291 QString parentId;
292 QString parentLabel;
293 if (id.startsWith("middle")) {
294 parentId = "root";
295 parentLabel = "root";
296 } else if (id.startsWith("child")) {
297 parentId = id.mid(5, 7);
298 parentLabel = parentId;
299 }
300 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
303void Scope::setNavigationState(const QString &navigationId)
305 m_currentNavigationId = navigationId;
306 Q_EMIT currentNavigationIdChanged();
307 Q_EMIT primaryNavigationTagChanged();
310unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() const
312 return m_hasPrimaryFilter ? m_primaryNavigationFilter : nullptr;
315unity::shell::scopes::FiltersInterface* Scope::filters() const
317 return m_filters;
320QString Scope::primaryNavigationTag() const
322 if (m_currentNavigationId == "root")
323 return QString();
324 else
325 return const_cast<Scope*>(this)->getNavigation(m_currentNavigationId)->label();
328int Scope::activeFiltersCount() const
330 return m_filters->activeFiltersCount();
333void Scope::resetPrimaryNavigationTag()
335 if (m_currentNavigationId != "root") {
336 setNavigationState("root");
337 }
340void Scope::setHasPrimaryFilter(bool hasPrimaryFilter)
342 m_hasPrimaryFilter = hasPrimaryFilter;
343 Q_EMIT primaryNavigationFilterChanged();
346void Scope::performQuery(const QString& query)
348 Q_EMIT queryPerformed(query);
349 if (query.startsWith("scopes://")) {
350 QString scopeId = query.mid(9);
351 Q_EMIT gotoScope(scopeId);
352 }