on daa5708 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
312 lines 6.9 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"
25#include "fake_settingsmodel.h"
27Scope::Scope(Scopes* parent) : Scope("MockScope5", "Mock Scope", false, parent)
31Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview)
32 : unity::shell::scopes::ScopeInterface(parent)
33 , m_id(id)
34 , m_name(name)
35 , m_searching(false)
36 , m_favorite(favorite)
37 , m_isActive(false)
38 , m_currentNavigationId("root")
39 , m_currentAltNavigationId("altrootChild1")
40 , m_previewRendererName("preview-generic")
41 , m_categories(new Categories(categories, this))
42 , m_openScope(nullptr)
43 , m_settings(new SettingsModel(this))
44 , m_returnNullPreview(returnNullPreview)
48QString Scope::id() const
50 return m_id;
53QString Scope::name() const
55 return m_name;
58QString Scope::searchQuery() const
60 return m_searchQuery;
63QString Scope::iconHint() const
65 return m_iconHint;
68QString Scope::description() const
70 return m_description;
73QString Scope::searchHint() const
75 return QString("Search %1").arg(m_name);
78QString Scope::shortcut() const
80 return QString("");
83bool Scope::searchInProgress() const
85 return m_searching;
88bool Scope::favorite() const
90 return m_favorite;
93unity::shell::scopes::CategoriesInterface* Scope::categories() const
95 return m_categories;
98unity::shell::scopes::SettingsModelInterface* Scope::settings() const
100 return m_settings;
103QString Scope::noResultsHint() const
105 return m_noResultsHint;
108QString Scope::formFactor() const
110 return m_formFactor;
113bool Scope::isActive() const
115 return m_isActive;
118void Scope::setSearchQuery(const QString &str)
120 if (str != m_searchQuery) {
121 m_searchQuery = str;
122 Q_EMIT searchQueryChanged();
123 }
126void Scope::setFormFactor(const QString &str)
128 if (str != m_formFactor) {
129 m_formFactor = str;
130 Q_EMIT formFactorChanged();
131 }
134void Scope::setActive(const bool active)
136 if (active != m_isActive) {
137 m_isActive = active;
138 Q_EMIT isActiveChanged();
139 }
142void Scope::setFavorite(const bool favorite)
144 if (favorite != m_favorite) {
145 m_favorite = favorite;
146 Q_EMIT favoriteChanged();
147 }
150void Scope::setId(const QString &id)
152 if (id != m_id) {
153 m_id = id;
154 Q_EMIT idChanged();
155 }
158void Scope::setName(const QString &name)
160 if (name != m_name) {
161 m_name = name;
162 Q_EMIT nameChanged();
163 }
166void Scope::setSearchInProgress(const bool inProg)
168 if (inProg != m_searching) {
169 m_searching = inProg;
170 Q_EMIT searchInProgressChanged();
171 }
174void Scope::setNoResultsHint(const QString& str)
176 if (str != m_noResultsHint) {
177 m_noResultsHint = str;
178 Q_EMIT noResultsHintChanged();
179 }
182void Scope::activate(QVariant const& result)
184 qDebug() << "Called activate on scope" << m_id << "with result" << result;
185 if (result.toString() == "Result.2.2") {
186 Scopes *scopes = dynamic_cast<Scopes*>(parent());
187 m_openScope = scopes->getScopeFromAll("MockScope9");
188 scopes->addTempScope(m_openScope);
189 Q_EMIT openScope(m_openScope);
190 }
193PreviewStack* Scope::preview(QVariant const& result)
195 Q_UNUSED(result);
197 if (m_returnNullPreview) {
198 return nullptr;
199 } else {
200 // This probably leaks, do we don't care
201 // it's a test after all
202 return new PreviewStack(this, this);
203 }
206void Scope::cancelActivation()
210void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
212 Scopes *scopes = dynamic_cast<Scopes*>(parent());
213 if (scopes) {
214 return scopes->closeScope(scope);
215 }
218QString Scope::currentNavigationId() const
220 return m_currentNavigationId;
223bool Scope::hasNavigation() const
225 return true;
228QString Scope::currentAltNavigationId() const
230 return m_currentAltNavigationId;
233bool Scope::hasAltNavigation() const
235 return true;
238Scope::Status Scope::status() const
240 return Status::Okay;
243QVariantMap Scope::customizations() const
245 QVariantMap m, h;
246 if (m_id == "clickscope") {
247 h["foreground-color"] = "yellow";
248 m["background-color"] = "red";
249 m["foreground-color"] = "blue";
250 m["page-header"] = h;
251 } else if (m_id == "MockScope4") {
252 h["navigation-background"] = QUrl("../../../tests/qmltests/Dash/artwork/background.png");
253 m["page-header"] = h;
254 } else if (m_id == "MockScope5") {
255 h["background"] = "gradient:///lightgrey/grey";
256 h["logo"] = QUrl("../../../tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
257 h["divider-color"] = "red";
258 h["navigation-background"] = "color:///black";
259 m["page-header"] = h;
260 } else if (m_id == "MockScope6") {
261 h["navigation-background"] = "gradient:///blue/red";
262 m["page-header"] = h;
263 }
264 return m;
267void Scope::refresh()
269 Q_EMIT refreshed();
272unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
274 if (id.isEmpty())
275 return nullptr;
277 QString parentId;
278 QString parentLabel;
279 if (id.startsWith("middle")) {
280 parentId = "root";
281 parentLabel = "root";
282 } else if (id.startsWith("child")) {
283 parentId = id.mid(5, 7);
284 parentLabel = parentId;
285 }
286 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
289unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
291 if (id.isEmpty())
292 return nullptr;
294 QString parentId;
295 QString parentLabel;
296 if (id != "altroot") {
297 parentId = "altroot";
298 parentLabel = "altroot";
299 }
300 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
303void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
305 if (isAltNavigation) {
306 m_currentAltNavigationId = navigationId;
307 Q_EMIT currentAltNavigationIdChanged();
308 } else {
309 m_currentNavigationId = navigationId;
310 Q_EMIT currentNavigationIdChanged();
311 }