on f395e40 help sign in
unity8/tests/mocks/Unity/fake_scope.cpp
190 lines 4.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 "fake_scope.h"
18#include "fake_department.h"
19#include "fake_resultsmodel.h"
21Scope::Scope(QObject* parent) : Scope(QString(), QString(), false, parent)
25Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent)
26 : QObject(parent)
27 , m_id(id)
28 , m_name(name)
29 , m_visible(visible)
30 , m_searching(false)
31 , m_isActive(false)
32 , m_currentDeparment("root")
33 , m_previewRendererName("preview-generic")
34 , m_categories(new Categories(20, this))
38QString Scope::id() const {
39 return m_id;
42QString Scope::name() const {
43 return m_name;
46QString Scope::searchQuery() const {
47 return m_searchQuery;
50QString Scope::iconHint() const {
51 return m_iconHint;
54QString Scope::description() const {
55 return m_description;
58QString Scope::searchHint() const {
59 return QString("");
62QString Scope::shortcut() const {
63 return QString("");
66bool Scope::connected() const {
67 return true;
70bool Scope::searchInProgress() const {
71 return m_searching;
74Categories* Scope::categories() const {
75 return m_categories;
78QString Scope::noResultsHint() const {
79 return m_noResultsHint;
82QString Scope::formFactor() const {
83 return m_formFactor;
86bool Scope::visible() const {
87 return m_visible;
90bool Scope::isActive() const {
91 return m_isActive;
94void Scope::setName(const QString &str) {
95 if (str != m_name) {
96 m_name = str;
97 Q_EMIT nameChanged(m_name);
98 }
101void Scope::setSearchQuery(const QString &str) {
102 if (str != m_searchQuery) {
103 m_searchQuery = str;
104 Q_EMIT searchQueryChanged();
105 }
108void Scope::setFormFactor(const QString &str) {
109 if (str != m_formFactor) {
110 m_formFactor = str;
111 Q_EMIT formFactorChanged();
112 }
115void Scope::setActive(const bool active) {
116 if (active != m_isActive) {
117 m_isActive = active;
118 Q_EMIT isActiveChanged(active);
119 }
122void Scope::setSearchInProgress(const bool inProg) {
123 if (inProg != m_searching) {
124 m_searching = inProg;
125 Q_EMIT searchInProgressChanged();
126 }
129void Scope::setNoResultsHint(const QString& str) {
130 if (str != m_noResultsHint) {
131 m_noResultsHint = str;
132 Q_EMIT noResultsHintChanged();
133 }
136void Scope::activate(QVariant const& result)
138 Q_UNUSED(result);
141PreviewStack* Scope::preview(QVariant const& result)
143 Q_UNUSED(result);
145 // This probably leaks, do we don't care
146 // it's a test after all
147 return new PreviewStack;
150void Scope::cancelActivation()
154void Scope::closeScope(Scope* /*scope*/)
156 qFatal("Scope::closeScope is not implemented");
159QString Scope::currentDepartment() const
161 return m_currentDeparment;
164bool Scope::hasDepartments() const
166 return true;
169Department *Scope::getDepartment(const QString& id)
171 if (id.isEmpty())
172 return nullptr;
174 QString parentId;
175 QString parentLabel;
176 if (id.startsWith("middle")) {
177 parentId = "root";
178 parentLabel = "root";
179 } else if (id.startsWith("child")) {
180 parentId = "middle";
181 parentLabel = "middle";
182 }
183 return new Department(id, id, "all"+id, parentId, parentLabel, this);
186void Scope::loadDepartment(const QString& id)
188 m_currentDeparment = id;
189 currentDepartmentChanged(m_currentDeparment);