on 0aef820 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
195 lines 4.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 <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 nCategories)
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(nCategories, this))
40QString Scope::id() const {
41 return m_id;
44QString Scope::name() const {
45 return m_name;
48QString Scope::searchQuery() const {
49 return m_searchQuery;
52QString Scope::iconHint() const {
53 return m_iconHint;
56QString Scope::description() const {
57 return m_description;
60QString Scope::searchHint() const {
61 return QString("");
64QString Scope::shortcut() const {
65 return QString("");
68bool Scope::searchInProgress() const {
69 return m_searching;
72unity::shell::scopes::CategoriesInterface* Scope::categories() const {
73 return m_categories;
76QString Scope::noResultsHint() const {
77 return m_noResultsHint;
80QString Scope::formFactor() const {
81 return m_formFactor;
84bool Scope::visible() const {
85 return m_visible;
88bool Scope::isActive() const {
89 return m_isActive;
92void Scope::setSearchQuery(const QString &str) {
93 if (str != m_searchQuery) {
94 m_searchQuery = str;
95 Q_EMIT searchQueryChanged();
96 }
99void Scope::setFormFactor(const QString &str) {
100 if (str != m_formFactor) {
101 m_formFactor = str;
102 Q_EMIT formFactorChanged();
103 }
106void Scope::setActive(const bool active) {
107 if (active != m_isActive) {
108 m_isActive = active;
109 Q_EMIT isActiveChanged();
110 }
113void Scope::setSearchInProgress(const bool inProg) {
114 if (inProg != m_searching) {
115 m_searching = inProg;
116 Q_EMIT searchInProgressChanged();
117 }
120void Scope::setNoResultsHint(const QString& str) {
121 if (str != m_noResultsHint) {
122 m_noResultsHint = str;
123 Q_EMIT noResultsHintChanged();
124 }
127void Scope::activate(QVariant const& result)
129 Q_UNUSED(result);
132PreviewStack* Scope::preview(QVariant const& result)
134 Q_UNUSED(result);
136 // This probably leaks, do we don't care
137 // it's a test after all
138 return new PreviewStack;
141void Scope::cancelActivation()
145void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
147 qFatal("Scope::closeScope is not implemented");
150QString Scope::currentDepartmentId() const
152 return m_currentDeparment;
155bool Scope::hasDepartments() const
157 return true;
160QVariantMap Scope::customizations() const
162 QVariantMap m;
163 if (m_id == "clickscope") {
164 m["background-color"] = "red";
165 m["foreground-color"] = "blue";
166 } else if (m_id == "MockScope5") {
167 QVariantMap pageHeader;
168 pageHeader["logo"] = QUrl("../../../tests/qmltests/Components/tst_PageHeader/logo-ubuntu-orange.svg");
169 m["page-header"] = pageHeader;
170 }
171 return m;
174unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
176 if (id.isEmpty())
177 return nullptr;
179 QString parentId;
180 QString parentLabel;
181 if (id.startsWith("middle")) {
182 parentId = "root";
183 parentLabel = "root";
184 } else if (id.startsWith("child")) {
185 parentId = id.mid(5, 7);
186 parentLabel = parentId;
187 }
188 return new Department(id, id, "all"+id, parentId, parentLabel, this);
191void Scope::loadDepartment(const QString& id)
193 m_currentDeparment = id;
194 Q_EMIT currentDepartmentIdChanged();