on 2f2b341 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
282 lines 6.2 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"
26Scope::Scope(Scopes* parent) : Scope(QString(), QString(), false, parent)
30Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories)
31 : unity::shell::scopes::ScopeInterface(parent)
32 , m_id(id)
33 , m_name(name)
34 , m_searching(false)
35 , m_favorite(favorite)
36 , m_isActive(false)
37 , m_currentNavigationId("root")
38 , m_currentAltNavigationId("altroot")
39 , m_previewRendererName("preview-generic")
40 , m_categories(new Categories(categories, this))
41 , m_openScope(nullptr)
45QString Scope::id() const
47 return m_id;
50QString Scope::name() const
52 return m_name;
55QString Scope::searchQuery() const
57 return m_searchQuery;
60QString Scope::iconHint() const
62 return m_iconHint;
65QString Scope::description() const
67 return m_description;
70QString Scope::searchHint() const
72 return QString("Search %1").arg(m_name);
75QString Scope::shortcut() const
77 return QString("");
80bool Scope::searchInProgress() const
82 return m_searching;
85bool Scope::favorite() const
87 return m_favorite;
90unity::shell::scopes::CategoriesInterface* Scope::categories() const
92 return m_categories;
95unity::shell::scopes::SettingsModelInterface* Scope::settings() const
97 return nullptr;
100QString Scope::noResultsHint() const
102 return m_noResultsHint;
105QString Scope::formFactor() const
107 return m_formFactor;
110bool Scope::isActive() const
112 return m_isActive;
115void Scope::setSearchQuery(const QString &str)
117 if (str != m_searchQuery) {
118 m_searchQuery = str;
119 Q_EMIT searchQueryChanged();
120 }
123void Scope::setFormFactor(const QString &str)
125 if (str != m_formFactor) {
126 m_formFactor = str;
127 Q_EMIT formFactorChanged();
128 }
131void Scope::setActive(const bool active)
133 if (active != m_isActive) {
134 m_isActive = active;
135 Q_EMIT isActiveChanged();
136 }
139void Scope::setFavorite(const bool favorite)
141 if (favorite != m_favorite) {
142 m_favorite = favorite;
143 Q_EMIT favoriteChanged();
144 }
146void Scope::setSearchInProgress(const bool inProg)
148 if (inProg != m_searching) {
149 m_searching = inProg;
150 Q_EMIT searchInProgressChanged();
151 }
154void Scope::setNoResultsHint(const QString& str)
156 if (str != m_noResultsHint) {
157 m_noResultsHint = str;
158 Q_EMIT noResultsHintChanged();
159 }
162void Scope::activate(QVariant const& result)
164 qDebug() << "Called activate on scope" << m_id << "with result" << result;
165 if (result.toString() == "Result.2.2") {
166 Scopes *scopes = dynamic_cast<Scopes*>(parent());
167 m_openScope = scopes->getScopeFromAll("MockScope9");
168 Q_EMIT openScope(m_openScope);
169 }
172PreviewStack* Scope::preview(QVariant const& result)
174 Q_UNUSED(result);
176 // This probably leaks, do we don't care
177 // it's a test after all
178 return new PreviewStack;
181void Scope::cancelActivation()
185void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
187 if (scope != m_openScope) {
188 qDebug() << scope << m_openScope;
189 qFatal("Scope::closeScope got wrong scope in closeScope");
190 }
191 m_openScope = nullptr;
194QString Scope::currentNavigationId() const
196 return m_currentNavigationId;
199bool Scope::hasNavigation() const
201 return true;
204QString Scope::currentAltNavigationId() const
206 return m_currentAltNavigationId;
209bool Scope::hasAltNavigation() const
211 return true;
214Scope::Status Scope::status() const
216 return Status::Okay;
219QVariantMap Scope::customizations() const
221 QVariantMap m, h;
222 if (m_id == "clickscope") {
223 h["foreground-color"] = "yellow";
224 m["background-color"] = "red";
225 m["foreground-color"] = "blue";
226 m["page-header"] = h;
227 } else if (m_id == "MockScope5") {
228 h["background"] = "gradient:///lightgrey/grey";
229 h["logo"] = QUrl("../../../tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
230 h["divider-color"] = "red";
231 h["navigation-background"] = "color:///black";
232 m["page-header"] = h;
233 }
234 return m;
237void Scope::refresh()
239 qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
242unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
244 if (id.isEmpty())
245 return nullptr;
247 QString parentId;
248 QString parentLabel;
249 if (id.startsWith("middle")) {
250 parentId = "root";
251 parentLabel = "root";
252 } else if (id.startsWith("child")) {
253 parentId = id.mid(5, 7);
254 parentLabel = parentId;
255 }
256 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
259unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
261 if (id.isEmpty())
262 return nullptr;
264 QString parentId;
265 QString parentLabel;
266 if (id.startsWith("altmiddle")) {
267 parentId = "altroot";
268 parentLabel = "altroot";
269 }
270 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
273void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
275 if (isAltNavigation) {
276 m_currentAltNavigationId = navigationId;
277 Q_EMIT currentAltNavigationIdChanged();
278 } else {
279 m_currentNavigationId = navigationId;
280 Q_EMIT currentNavigationIdChanged();
281 }