on 770ffe6 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
224 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 <QDebug>
18#include <QUrl>
20#include "fake_scope.h"
21#include "fake_department.h"
22#include "fake_resultsmodel.h"
24Scope::Scope(QObject* parent) : Scope(QString(), QString(), false, parent)
28Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent)
29 : unity::shell::scopes::ScopeInterface(parent)
30 , m_id(id)
31 , m_name(name)
32 , m_visible(visible)
33 , m_searching(false)
34 , m_isActive(false)
35 , m_currentDeparment("root")
36 , m_previewRendererName("preview-generic")
37 , m_categories(new Categories(20, this))
41QString Scope::id() const
43 return m_id;
46QString Scope::name() const
48 return m_name;
51QString Scope::searchQuery() const
53 return m_searchQuery;
56QString Scope::iconHint() const
58 return m_iconHint;
61QString Scope::description() const
63 return m_description;
66QString Scope::searchHint() const
68 return QString("");
71QString Scope::shortcut() const
73 return QString("");
76bool Scope::searchInProgress() const
78 return m_searching;
81unity::shell::scopes::CategoriesInterface* Scope::categories() const
83 return m_categories;
86unity::shell::scopes::SettingsModelInterface* Scope::settings() const
88 return nullptr;
91QString Scope::noResultsHint() const
93 return m_noResultsHint;
96QString Scope::formFactor() const
98 return m_formFactor;
101bool Scope::visible() const
103 return m_visible;
106bool Scope::isActive() const
108 return m_isActive;
111void Scope::setSearchQuery(const QString &str)
113 if (str != m_searchQuery) {
114 m_searchQuery = str;
115 Q_EMIT searchQueryChanged();
116 }
119void Scope::setFormFactor(const QString &str)
121 if (str != m_formFactor) {
122 m_formFactor = str;
123 Q_EMIT formFactorChanged();
124 }
127void Scope::setActive(const bool active)
129 if (active != m_isActive) {
130 m_isActive = active;
131 Q_EMIT isActiveChanged();
132 }
135void Scope::setSearchInProgress(const bool inProg)
137 if (inProg != m_searching) {
138 m_searching = inProg;
139 Q_EMIT searchInProgressChanged();
140 }
143void Scope::setNoResultsHint(const QString& str)
145 if (str != m_noResultsHint) {
146 m_noResultsHint = str;
147 Q_EMIT noResultsHintChanged();
148 }
151void Scope::activate(QVariant const& result)
153 qDebug() << "Called activate on scope" << m_id << "with result" << result;;
156PreviewStack* Scope::preview(QVariant const& result)
158 Q_UNUSED(result);
160 // This probably leaks, do we don't care
161 // it's a test after all
162 return new PreviewStack;
165void Scope::cancelActivation()
169void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
171 qFatal("Scope::closeScope is not implemented");
174QString Scope::currentDepartmentId() const
176 return m_currentDeparment;
179bool Scope::hasDepartments() const
181 return true;
184QVariantMap Scope::customizations() const
186 QVariantMap m;
187 if (m_id == "clickscope") {
188 m["background-color"] = "red";
189 m["foreground-color"] = "blue";
190 } else if (m_id == "MockScope5") {
191 QVariantMap pageHeader;
192 pageHeader["logo"] = QUrl("../../../tests/qmltests/Components/tst_PageHeader/logo-ubuntu-orange.svg");
193 m["page-header"] = pageHeader;
194 }
195 return m;
198unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
200 if (id.isEmpty())
201 return nullptr;
203 QString parentId;
204 QString parentLabel;
205 if (id.startsWith("middle")) {
206 parentId = "root";
207 parentLabel = "root";
208 } else if (id.startsWith("child")) {
209 parentId = id.mid(5, 7);
210 parentLabel = parentId;
211 }
212 return new Department(id, id, "all"+id, parentId, parentLabel, this);
215void Scope::loadDepartment(const QString& id)
217 m_currentDeparment = id;
218 Q_EMIT currentDepartmentIdChanged();
221void Scope::performQuery(const QString& query)
223 Q_UNUSED(query);