on 451cbdb help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
220 lines 4.6 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 <QUrl>
19#include "fake_scope.h"
20#include "fake_department.h"
21#include "fake_resultsmodel.h"
23Scope::Scope(QObject* parent) : Scope(QString(), QString(), false, parent)
27Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent, int categories)
28 : unity::shell::scopes::ScopeInterface(parent)
29 , m_id(id)
30 , m_name(name)
31 , m_visible(visible)
32 , m_searching(false)
33 , m_isActive(false)
34 , m_currentDeparment("root")
35 , m_previewRendererName("preview-generic")
36 , m_categories(new Categories(categories, this))
40QString Scope::id() const
42 return m_id;
45QString Scope::name() const
47 return m_name;
50QString Scope::searchQuery() const
52 return m_searchQuery;
55QString Scope::iconHint() const
57 return m_iconHint;
60QString Scope::description() const
62 return m_description;
65QString Scope::searchHint() const
67 return QString("");
70QString Scope::shortcut() const
72 return QString("");
75bool Scope::searchInProgress() const
77 return m_searching;
80unity::shell::scopes::CategoriesInterface* Scope::categories() const
82 return m_categories;
85unity::shell::scopes::SettingsModelInterface* Scope::settings() const
87 return nullptr;
90QString Scope::noResultsHint() const
92 return m_noResultsHint;
95QString Scope::formFactor() const
97 return m_formFactor;
100bool Scope::visible() const
102 return m_visible;
105bool Scope::isActive() const
107 return m_isActive;
110void Scope::setSearchQuery(const QString &str)
112 if (str != m_searchQuery) {
113 m_searchQuery = str;
114 Q_EMIT searchQueryChanged();
115 }
118void Scope::setFormFactor(const QString &str)
120 if (str != m_formFactor) {
121 m_formFactor = str;
122 Q_EMIT formFactorChanged();
123 }
126void Scope::setActive(const bool active)
128 if (active != m_isActive) {
129 m_isActive = active;
130 Q_EMIT isActiveChanged();
131 }
134void Scope::setSearchInProgress(const bool inProg)
136 if (inProg != m_searching) {
137 m_searching = inProg;
138 Q_EMIT searchInProgressChanged();
139 }
142void Scope::setNoResultsHint(const QString& str)
144 if (str != m_noResultsHint) {
145 m_noResultsHint = str;
146 Q_EMIT noResultsHintChanged();
147 }
150void Scope::activate(QVariant const& result)
152 Q_UNUSED(result);
155PreviewStack* Scope::preview(QVariant const& result)
157 Q_UNUSED(result);
159 // This probably leaks, do we don't care
160 // it's a test after all
161 return new PreviewStack;
164void Scope::cancelActivation()
168void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
170 qFatal("Scope::closeScope is not implemented");
173QString Scope::currentDepartmentId() const
175 return m_currentDeparment;
178bool Scope::hasDepartments() const
180 return true;
183QVariantMap Scope::customizations() const
185 QVariantMap m, h;
186 if (m_id == "clickscope") {
187 h["foreground-color"] = "yellow";
188 m["background-color"] = "red";
189 m["foreground-color"] = "blue";
190 m["page-header"] = h;
191 } else if (m_id == "MockScope5") {
192 h["background"] = "gradient:///lightgrey/grey";
193 h["logo"] = QUrl("../../../tests/qmltests/Components/tst_PageHeader/logo-ubuntu-orange.svg");
194 m["page-header"] = h;
195 }
196 return m;
199unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
201 if (id.isEmpty())
202 return nullptr;
204 QString parentId;
205 QString parentLabel;
206 if (id.startsWith("middle")) {
207 parentId = "root";
208 parentLabel = "root";
209 } else if (id.startsWith("child")) {
210 parentId = id.mid(5, 7);
211 parentLabel = parentId;
212 }
213 return new Department(id, id, "all"+id, parentId, parentLabel, this);
216void Scope::loadDepartment(const QString& id)
218 m_currentDeparment = id;
219 Q_EMIT currentDepartmentIdChanged();