2 * Copyright (C) 2014 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/>.
17#include "fake_scopesoverview.h"
19#include "fake_scopes.h"
23ScopesOverview::ScopesOverview(Scopes* parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
26 delete m_categories; // delete the usual categories, we're not going to use it
27 m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
28 m_searchCategories = new ScopesOverviewSearchCategories(parent, this);
29 m_categories = m_scopesOverviewCategories;
32void ScopesOverview::setSearchQuery(const QString& search_query)
34 Scope::setSearchQuery(search_query);
36 auto origCategories = m_categories;
37 if (search_query.isEmpty()) m_categories = m_scopesOverviewCategories;
38 else m_categories = m_searchCategories;
40 if (m_categories != origCategories)
41 Q_EMIT categoriesChanged();
44Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
46 Scopes *scopes = dynamic_cast<Scopes*>(parent());
47 m_openScope = scopes->getScopeFromAll(result.toString());
48 Q_EMIT openScope(m_openScope);
51ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
52 : unity::shell::scopes::CategoriesInterface(parent)
57int ScopesOverviewCategories::rowCount(const QModelIndex& /*parent*/) const
62void ScopesOverviewCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
64 qFatal("Using un-implemented ScopesOverviewCategories::addSpecialCategory");
67bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
69 qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
73ScopesOverviewCategories::data(const QModelIndex& index, int role) const
75 if (!index.isValid()) {
79 const QString categoryId = index.row() == 0 ? "favorites" : "all";
81 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
83 QObject *that = const_cast<ScopesOverviewCategories*>(this);
84 resultsModel = new ScopesOverviewResultsModel(m_scopes->scopes(index.row() == 0), categoryId, that);
85 m_resultsModels[index.row()] = resultsModel;
91 return index.row() == 0 ? "Favorites" : "All";
94 case RoleRawRendererTemplate:
95 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
100 map["category-layout"] = "grid";
101 map["card-size"] = "small";
102 map["overlay"] = true;
107 QVariantMap map, artMap;
108 artMap["aspect-ratio"] = "0.5";
109 artMap["field"] = "art";
111 map["title"] = "HOLA";
115 return QVariant::fromValue(resultsModel);
117 return resultsModel->rowCount();
119 qFatal("Using un-implemented Categories role");
126ScopesOverviewSearchCategories::ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent)
127 : unity::shell::scopes::CategoriesInterface(parent)
132int ScopesOverviewSearchCategories::rowCount(const QModelIndex& /*parent*/) const
137void ScopesOverviewSearchCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
139 qFatal("Using un-implemented ScopesOverviewSearchCategories::addSpecialCategory");
142bool ScopesOverviewSearchCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
144 qFatal("Using un-implemented ScopesOverviewSearchCategories::overrideCategoryJson");
148ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
150 if (!index.isValid()) {
154 const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
156 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
158 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
159 QList<unity::shell::scopes::ScopeInterface *> scopes;
160 if (index.row() == 0) {
161 scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
163 scopes << nullptr << m_scopes->getScopeFromAll("MockScope7") << nullptr << m_scopes->getScopeFromAll("MockScope1");
165 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
166 m_resultsModels[index.row()] = resultsModel;
172 return index.row() == 0 ? "SearchA" : "SearchB";
175 case RoleRawRendererTemplate:
176 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
181 map["category-layout"] = "grid";
182 map["card-size"] = "small";
183 map["overlay"] = true;
188 QVariantMap map, artMap;
189 artMap["aspect-ratio"] = "1";
190 artMap["field"] = "art";
192 map["title"] = "HOLA";
196 return QVariant::fromValue(resultsModel);
198 return resultsModel->rowCount();
200 qFatal("Using un-implemented Categories role");
206ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent)
207 : unity::shell::scopes::ResultsModelInterface(parent)
209 , m_categoryId(categoryId)
213QString ScopesOverviewResultsModel::categoryId() const
218void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
220 qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
223int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
225 const int scopeCount = count();
226 for (int i = 0; i < scopeCount; ++i) {
227 if (m_scopes[i]->id() == id)
233QHash<int, QByteArray> ScopesOverviewResultsModel::roleNames() const
235 QHash<int, QByteArray> roles = unity::shell::scopes::ResultsModelInterface::roleNames();
236 roles[RoleBackground + 1] = "scopeId";
240int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
244 return m_scopes.count();
247int ScopesOverviewResultsModel::count() const
253ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
255 unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
262 return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
264 return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
266 return qmlDirectory() + "graphics/applicationIcons/dash.png";
270 case RoleBackground + 1: // scopeId
271 return scope ? scope->id() : nullptr;
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