2 * Copyright (C) 2013, 2014, 2015 Canonical, Ltd.
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.
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.
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/>.
20#include "fake_scope.h"
22#include "fake_filters.h"
23#include "fake_navigation.h"
24#include "fake_optionselectorfilter.h"
25#include "fake_resultsmodel.h"
26#include "fake_scopes.h"
27#include "fake_settingsmodel.h"
29#include <paths.h> // from unity8/include
31Scope::Scope(Scopes* parent) : Scope("MockScope5", "Mock Scope", false, parent)
35Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview, const QStringList primaryNavigationFilterOptionLabels)
36 : unity::shell::scopes::ScopeInterface(parent)
40 , m_favorite(favorite)
42 , m_hasNavigation(true)
43 , m_hasPrimaryFilter(true)
44 , m_currentNavigationId("root")
45 , m_previewRendererName("preview-generic")
46 , m_categories(new Categories(categories, this))
47 , m_openScope(nullptr)
48 , m_settings(new SettingsModel(this))
49 , m_filters(new Filters(this))
50 , m_returnNullPreview(returnNullPreview)
52 m_primaryNavigationFilter = new FakeOptionSelectorFilter("OSF3", "PFTag", "Which food you like More", false, primaryNavigationFilterOptionLabels, this);
53 m_filters->addFakeFilters();
54 connect(m_filters, &Filters::activeFiltersCountChanged, this, &Scope::activeFiltersCountChanged);
55 connect(m_primaryNavigationFilter, &FakeOptionSelectorFilter::isActiveChanged,
56 this, &unity::shell::scopes::ScopeInterface::primaryNavigationTagChanged);
59QString Scope::id() const
64QString Scope::name() const
69QString Scope::searchQuery() const
74QString Scope::iconHint() const
79QString Scope::description() const
84QString Scope::searchHint() const
86 return QString("Search %1").arg(m_name);
89QString Scope::shortcut() const
94bool Scope::searchInProgress() const
99bool Scope::activationInProgress() const
104bool Scope::favorite() const
109unity::shell::scopes::CategoriesInterface* Scope::categories() const
114unity::shell::scopes::SettingsModelInterface* Scope::settings() const
119QString Scope::noResultsHint() const
121 return m_noResultsHint;
124QString Scope::formFactor() const
129bool Scope::isActive() const
134void Scope::setSearchQuery(const QString &str)
136 if (str != m_searchQuery) {
138 Q_EMIT searchQueryChanged();
142void Scope::setFormFactor(const QString &str)
144 if (str != m_formFactor) {
146 Q_EMIT formFactorChanged();
150void Scope::setActive(const bool active)
152 if (active != m_isActive) {
154 Q_EMIT isActiveChanged();
158void Scope::setFavorite(const bool favorite)
160 if (favorite != m_favorite) {
161 m_favorite = favorite;
162 Q_EMIT favoriteChanged();
166void Scope::setId(const QString &id)
174void Scope::setName(const QString &name)
176 if (name != m_name) {
178 Q_EMIT nameChanged();
182void Scope::setSearchInProgress(const bool inProg)
184 if (inProg != m_searching) {
185 m_searching = inProg;
186 Q_EMIT searchInProgressChanged();
190void Scope::setNoResultsHint(const QString& str)
192 if (str != m_noResultsHint) {
193 m_noResultsHint = str;
194 Q_EMIT noResultsHintChanged();
198void Scope::activate(QVariant const& result, QString const& categoryId)
200 qDebug() << "Called activate on scope" << m_id << "with result" << result << "and category" << categoryId;
201 if (result.toString() == "Result.2.2") {
202 Scopes *scopes = dynamic_cast<Scopes*>(parent());
203 m_openScope = scopes->getScopeFromAll("MockScope9");
204 scopes->addTempScope(m_openScope);
205 Q_EMIT openScope(m_openScope);
207 Q_EMIT previewRequested(result);
211PreviewModel* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
215 if (m_returnNullPreview) {
218 return new PreviewModel(this, this);
222void Scope::cancelActivation()
226void Scope::closeScope(unity::shell::scopes::ScopeInterface* scope)
228 Scopes *scopes = dynamic_cast<Scopes*>(parent());
230 return scopes->closeScope(scope);
234QString Scope::currentNavigationId() const
236 return m_currentNavigationId;
239bool Scope::hasNavigation() const
241 return m_hasNavigation;
244void Scope::setHasNavigation(bool hasNavigation)
246 m_hasNavigation = hasNavigation;
247 Q_EMIT hasNavigationChanged();
250Scope::Status Scope::status() const
255QVariantMap Scope::customizations() const
258 if (m_id == "clickscope") {
259 h["foreground-color"] = "yellow";
260 m["background-color"] = "red";
261 m["foreground-color"] = "blue";
262 m["page-header"] = h;
263 } else if (m_id == "MockScope4") {
264 h["navigation-background"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/artwork/background.png");
265 m["page-header"] = h;
266 } else if (m_id == "MockScope5") {
267 h["background"] = "gradient:///lightgrey/grey";
268 h["logo"] = QUrl(sourceDirectory() + "/tests/qmltests/Dash/tst_PageHeader/logo-ubuntu-orange.svg");
269 h["divider-color"] = "red";
270 h["navigation-background"] = "color:///black";
271 m["page-header"] = h;
272 } else if (m_id == "MockScope6") {
273 h["navigation-background"] = "gradient:///blue/red";
274 m["page-header"] = h;
284void Scope::resetFilters()
286 qWarning() << "Scope::resetFilters is unimplemented";
289void Scope::activateAction(QVariant const& /*result*/, QString const& /*categoryId*/, QString const& /*actionId*/)
291 qFatal("Using Scope::activateAction");
294unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
301 if (id.startsWith("middle")) {
303 parentLabel = "root";
304 } else if (id.startsWith("child")) {
305 parentId = id.mid(5, 7);
306 parentLabel = parentId;
308 return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
311void Scope::setNavigationState(const QString &navigationId)
313 m_currentNavigationId = navigationId;
314 Q_EMIT currentNavigationIdChanged();
315 Q_EMIT primaryNavigationTagChanged();
318unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() const
320 return m_hasPrimaryFilter ? m_primaryNavigationFilter : nullptr;
323unity::shell::scopes::FiltersInterface* Scope::filters() const
328QString Scope::primaryNavigationTag() const
330 if (m_hasPrimaryFilter && m_primaryNavigationFilter->isActive())
331 return m_primaryNavigationFilter->filterTag();
332 if (m_currentNavigationId == "root")
335 return const_cast<Scope*>(this)->getNavigation(m_currentNavigationId)->label();
338int Scope::activeFiltersCount() const
340 return m_filters->activeFiltersCount();
343void Scope::resetPrimaryNavigationTag()
345 if (m_currentNavigationId != "root") {
346 setNavigationState("root");
350void Scope::setHasPrimaryFilter(bool hasPrimaryFilter)
352 m_hasPrimaryFilter = hasPrimaryFilter;
353 Q_EMIT primaryNavigationFilterChanged();
356void Scope::performQuery(const QString& query)
358 Q_EMIT queryPerformed(query);
359 if (query.startsWith("scopes://")) {
360 QString scopeId = query.mid(9);
361 Q_EMIT gotoScope(scopeId);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list