on f7d2979 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
297 lines 6.4 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 }
147void Scope::setId(const QString &id)
149 if (id != m_id) {
150 m_id = id;
151 Q_EMIT idChanged();
152 }
155void Scope::setName(const QString &name)
157 if (name != m_name) {
158 m_name = name;
159 Q_EMIT nameChanged();
160 }
163void Scope::setSearchInProgress(const bool inProg)
165 if (inProg != m_searching) {
166 m_searching = inProg;
167 Q_EMIT searchInProgressChanged();
168 }
171void Scope::setNoResultsHint(const QString& str)
173 if (str != m_noResultsHint) {
174 m_noResultsHint = str;
175 Q_EMIT noResultsHintChanged();
176 }
179void Scope::activate(QVariant const& result)
181 qDebug() << "Called activate on scope" << m_id << "with result" << result;
182 if (result.toString() == "Result.2.2") {
183 Scopes *scopes = dynamic_cast<Scopes*>(parent());
184 m_openScope = scopes->getScopeFromAll("MockScope9");
185 Q_EMIT openScope(m_openScope);
186 }
189PreviewStack* Scope::preview(QVariant const& result)
191 Q_UNUSED(result);
193 // This probably leaks, do we don't care
194 // it's a test after all
195 return new PreviewStack;
198void Scope::cancelActivation()
202void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
204 if (scope != m_openScope) {
205 qDebug() << scope << m_openScope;
206 qFatal("Scope::closeScope got wrong scope in closeScope");
207 }
208 m_openScope = nullptr;
211QString Scope::currentNavigationId() const
213 return m_currentNavigationId;
216bool Scope::hasNavigation() const
218 return true;
221QString Scope::currentAltNavigationId() const
223 return m_currentAltNavigationId;
226bool Scope::hasAltNavigation() const
228 return true;
231Scope::Status Scope::status() const
233 return Status::Okay;
236QVariantMap Scope::customizations() const
238 QVariantMap m, h;
239 if (m_id == "clickscope") {
240 h["foreground-color"] = "yellow";
241 m["background-color"] = "red";
242 m["foreground-color"] = "blue";
243 m["page-header"] = h;
244 } else if (m_id == "MockScope5") {
245 h["background"] = "gradient:///lightgrey/grey";
246 h["logo"] = QUrl("../../../tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
247 m["page-header"] = h;
248 }
249 return m;
252void Scope::refresh()
254 qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
257unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
259 if (id.isEmpty())
260 return nullptr;
262 QString parentId;
263 QString parentLabel;
264 if (id.startsWith("middle")) {
265 parentId = "root";
266 parentLabel = "root";
267 } else if (id.startsWith("child")) {
268 parentId = id.mid(5, 7);
269 parentLabel = parentId;
270 }
271 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
274unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
276 if (id.isEmpty())
277 return nullptr;
279 QString parentId;
280 QString parentLabel;
281 if (id.startsWith("altmiddle")) {
282 parentId = "altroot";
283 parentLabel = "altroot";
284 }
285 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
288void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
290 if (isAltNavigation) {
291 m_currentAltNavigationId = navigationId;
292 Q_EMIT currentAltNavigationIdChanged();
293 } else {
294 m_currentNavigationId = navigationId;
295 Q_EMIT currentNavigationIdChanged();
296 }