on 6743bb3 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
233 lines 5.0 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_department.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 visible, Scopes* parent, int categories)
31 : unity::shell::scopes::ScopeInterface(parent)
32 , m_id(id)
33 , m_name(name)
34 , m_visible(visible)
35 , m_searching(false)
36 , m_isActive(false)
37 , m_currentDeparment("root")
38 , m_previewRendererName("preview-generic")
39 , m_categories(new Categories(categories, this))
40 , m_openScope(nullptr)
44QString Scope::id() const
46 return m_id;
49QString Scope::name() const
51 return m_name;
54QString Scope::searchQuery() const
56 return m_searchQuery;
59QString Scope::iconHint() const
61 return m_iconHint;
64QString Scope::description() const
66 return m_description;
69QString Scope::searchHint() const
71 return QString("");
74QString Scope::shortcut() const
76 return QString("");
79bool Scope::searchInProgress() const
81 return m_searching;
84unity::shell::scopes::CategoriesInterface* Scope::categories() const
86 return m_categories;
89unity::shell::scopes::SettingsModelInterface* Scope::settings() const
91 return nullptr;
94QString Scope::noResultsHint() const
96 return m_noResultsHint;
99QString Scope::formFactor() const
101 return m_formFactor;
104bool Scope::visible() const
106 return m_visible;
109bool Scope::isActive() const
111 return m_isActive;
114void Scope::setSearchQuery(const QString &str)
116 if (str != m_searchQuery) {
117 m_searchQuery = str;
118 Q_EMIT searchQueryChanged();
119 }
122void Scope::setFormFactor(const QString &str)
124 if (str != m_formFactor) {
125 m_formFactor = str;
126 Q_EMIT formFactorChanged();
127 }
130void Scope::setActive(const bool active)
132 if (active != m_isActive) {
133 m_isActive = active;
134 Q_EMIT isActiveChanged();
135 }
138void Scope::setSearchInProgress(const bool inProg)
140 if (inProg != m_searching) {
141 m_searching = inProg;
142 Q_EMIT searchInProgressChanged();
143 }
146void Scope::setNoResultsHint(const QString& str)
148 if (str != m_noResultsHint) {
149 m_noResultsHint = str;
150 Q_EMIT noResultsHintChanged();
151 }
154void Scope::activate(QVariant const& result)
156 qDebug() << "Called activate on scope" << m_id << "with result" << result;
157 if (result.toString() == "Result.2.2") {
158 Scopes *scopes = dynamic_cast<Scopes*>(parent());
159 m_openScope = scopes->getScopeFromAll("MockScope9");
160 Q_EMIT openScope(m_openScope);
161 }
164PreviewStack* Scope::preview(QVariant const& result)
166 Q_UNUSED(result);
168 // This probably leaks, do we don't care
169 // it's a test after all
170 return new PreviewStack;
173void Scope::cancelActivation()
177void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
179 if (scope != m_openScope) {
180 qDebug() << scope << m_openScope;
181 qFatal("Scope::closeScope got wrong scope in closeScope");
182 }
183 m_openScope = nullptr;
186QString Scope::currentDepartmentId() const
188 return m_currentDeparment;
191bool Scope::hasDepartments() const
193 return true;
196QVariantMap Scope::customizations() const
198 QVariantMap m, h;
199 if (m_id == "clickscope") {
200 h["foreground-color"] = "yellow";
201 m["background-color"] = "red";
202 m["foreground-color"] = "blue";
203 m["page-header"] = h;
204 } else if (m_id == "MockScope5") {
205 h["background"] = "gradient:///lightgrey/grey";
206 h["logo"] = QUrl("../../../tests/qmltests/Components/tst_PageHeader/logo-ubuntu-orange.svg");
207 m["page-header"] = h;
208 }
209 return m;
212unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
214 if (id.isEmpty())
215 return nullptr;
217 QString parentId;
218 QString parentLabel;
219 if (id.startsWith("middle")) {
220 parentId = "root";
221 parentLabel = "root";
222 } else if (id.startsWith("child")) {
223 parentId = id.mid(5, 7);
224 parentLabel = parentId;
225 }
226 return new Department(id, id, "all"+id, parentId, parentLabel, this);
229void Scope::loadDepartment(const QString& id)
231 m_currentDeparment = id;
232 Q_EMIT currentDepartmentIdChanged();