on aae6256 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
359 lines 8.4 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, const QStringList primaryNavigationFilterOptionLabels)
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, primaryNavigationFilterOptionLabels, this);
53 m_filters->addFakeFilters();
54 connect(m_filters, &Filters::activeFiltersCountChanged, this, &Scope::activeFiltersCountChanged);
57QString Scope::id() const
59 return m_id;
62QString Scope::name() const
64 return m_name;
67QString Scope::searchQuery() const
69 return m_searchQuery;
72QString Scope::iconHint() const
74 return m_iconHint;
77QString Scope::description() const
79 return m_description;
82QString Scope::searchHint() const
84 return QString("Search %1").arg(m_name);
87QString Scope::shortcut() const
89 return QString("");
92bool Scope::searchInProgress() const
94 return m_searching;
97bool Scope::activationInProgress() const
99 return false;
102bool Scope::favorite() const
104 return m_favorite;
107unity::shell::scopes::CategoriesInterface* Scope::categories() const
109 return m_categories;
112unity::shell::scopes::SettingsModelInterface* Scope::settings() const
114 return m_settings;
117QString Scope::noResultsHint() const
119 return m_noResultsHint;
122QString Scope::formFactor() const
124 return m_formFactor;
127bool Scope::isActive() const
129 return m_isActive;
132void Scope::setSearchQuery(const QString &str)
134 if (str != m_searchQuery) {
135 m_searchQuery = str;
136 Q_EMIT searchQueryChanged();
137 }
140void Scope::setFormFactor(const QString &str)
142 if (str != m_formFactor) {
143 m_formFactor = str;
144 Q_EMIT formFactorChanged();
145 }
148void Scope::setActive(const bool active)
150 if (active != m_isActive) {
151 m_isActive = active;
152 Q_EMIT isActiveChanged();
153 }
156void Scope::setFavorite(const bool favorite)
158 if (favorite != m_favorite) {
159 m_favorite = favorite;
160 Q_EMIT favoriteChanged();
161 }
164void Scope::setId(const QString &id)
166 if (id != m_id) {
167 m_id = id;
168 Q_EMIT idChanged();
169 }
172void Scope::setName(const QString &name)
174 if (name != m_name) {
175 m_name = name;
176 Q_EMIT nameChanged();
177 }
180void Scope::setSearchInProgress(const bool inProg)
182 if (inProg != m_searching) {
183 m_searching = inProg;
184 Q_EMIT searchInProgressChanged();
185 }
188void Scope::setNoResultsHint(const QString& str)
190 if (str != m_noResultsHint) {
191 m_noResultsHint = str;
192 Q_EMIT noResultsHintChanged();
193 }
196void Scope::activate(QVariant const& result, QString const& categoryId)
198 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
199 if (result.toString() == "Result.2.2") {
200 Scopes *scopes = dynamic_cast<Scopes*>(parent());
201 m_openScope = scopes->getScopeFromAll("MockScope9");
202 scopes->addTempScope(m_openScope);
203 Q_EMIT openScope(m_openScope);
204 } else {
205 Q_EMIT previewRequested(result);
206 }
209PreviewModel* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
211 Q_UNUSED(result);
213 if (m_returnNullPreview) {
214 return nullptr;
215 } else {
216 return new PreviewModel(this, this);
217 }
220void Scope::cancelActivation()
224void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
226 Scopes *scopes = dynamic_cast<Scopes*>(parent());
227 if (scopes) {
228 return scopes->closeScope(scope);
229 }
232QString Scope::currentNavigationId() const
234 return m_currentNavigationId;
237bool Scope::hasNavigation() const
239 return m_hasNavigation;
242void Scope::setHasNavigation(bool hasNavigation)
244 m_hasNavigation = hasNavigation;
245 Q_EMIT hasNavigationChanged();
248Scope::Status Scope::status() const
250 return Status::Okay;
253QVariantMap Scope::customizations() const
255 QVariantMap m, h;
256 if (m_id == "clickscope") {
257 h["foreground-color"] = "yellow";
258 m["background-color"] = "red";
259 m["foreground-color"] = "blue";
260 m["page-header"] = h;
261 } else if (m_id == "MockScope4") {
262 h["navigation-background"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/artwork/background.png");
263 m["page-header"] = h;
264 } else if (m_id == "MockScope5") {
265 h["background"] = "gradient:///lightgrey/grey";
266 h["logo"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
267 h["divider-color"] = "red";
268 h["navigation-background"] = "color:///black";
269 m["page-header"] = h;
270 } else if (m_id == "MockScope6") {
271 h["navigation-background"] = "gradient:///blue/red";
272 m["page-header"] = h;
273 }
274 return m;
277void Scope::refresh()
279 Q_EMIT refreshed();
282void Scope::resetFilters()
284 qWarning() << "Scope::resetFilters is unimplemented";
287void Scope::activateAction(QVariant const& /*result*/, QString const& /*categoryId*/, QString const& /*actionId*/)
289 qFatal("Using Scope::activateAction");
292unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
294 if (id.isEmpty())
295 return nullptr;
297 QString parentId;
298 QString parentLabel;
299 if (id.startsWith("middle")) {
300 parentId = "root";
301 parentLabel = "root";
302 } else if (id.startsWith("child")) {
303 parentId = id.mid(5, 7);
304 parentLabel = parentId;
305 }
306 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
309void Scope::setNavigationState(const QString &navigationId)
311 m_currentNavigationId = navigationId;
312 Q_EMIT currentNavigationIdChanged();
313 Q_EMIT primaryNavigationTagChanged();
316unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() const
318 return m_hasPrimaryFilter ? m_primaryNavigationFilter : nullptr;
321unity::shell::scopes::FiltersInterface* Scope::filters() const
323 return m_filters;
326QString Scope::primaryNavigationTag() const
328 if (m_currentNavigationId == "root")
329 return QString();
330 else
331 return const_cast<Scope*>(this)->getNavigation(m_currentNavigationId)->label();
334int Scope::activeFiltersCount() const
336 return m_filters->activeFiltersCount();
339void Scope::resetPrimaryNavigationTag()
341 if (m_currentNavigationId != "root") {
342 setNavigationState("root");
343 }
346void Scope::setHasPrimaryFilter(bool hasPrimaryFilter)
348 m_hasPrimaryFilter = hasPrimaryFilter;
349 Q_EMIT primaryNavigationFilterChanged();
352void Scope::performQuery(const QString& query)
354 Q_EMIT queryPerformed(query);
355 if (query.startsWith("scopes://")) {
356 QString scopeId = query.mid(9);
357 Q_EMIT gotoScope(scopeId);
358 }