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 QList<Scope*> scopes = index.row() == 0 ? m_scopes->scopes() : m_scopes->allScopes();
85 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
86 m_resultsModels[index.row()] = resultsModel;
92 return index.row() == 0 ? "Favorites" : "All";
95 case RoleRawRendererTemplate:
96 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
101 map["category-layout"] = "grid";
102 map["card-size"] = "small";
103 map["overlay"] = true;
108 QVariantMap map, artMap, attributesMap;
109 artMap["aspect-ratio"] = "0.5";
110 artMap["field"] = "art";
112 map["title"] = "HOLA";
113 map["attributes"] = attributesMap;
117 return QVariant::fromValue(resultsModel);
119 return resultsModel->rowCount();
123 qFatal("Using un-implemented Categories role");
130ScopesOverviewSearchCategories::ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent)
131 : unity::shell::scopes::CategoriesInterface(parent)
136int ScopesOverviewSearchCategories::rowCount(const QModelIndex& /*parent*/) const
141void ScopesOverviewSearchCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
143 qFatal("Using un-implemented ScopesOverviewSearchCategories::addSpecialCategory");
146bool ScopesOverviewSearchCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
148 qFatal("Using un-implemented ScopesOverviewSearchCategories::overrideCategoryJson");
152ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
154 if (!index.isValid()) {
158 const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
160 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
162 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
163 QList<Scope *> scopes;
164 if (index.row() == 0) {
165 scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
167 scopes << nullptr << m_scopes->getScopeFromAll("MockScope7") << nullptr << m_scopes->getScopeFromAll("MockScope1");
169 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
170 m_resultsModels[index.row()] = resultsModel;
176 return index.row() == 0 ? "SearchA" : "SearchB";
179 case RoleRawRendererTemplate:
180 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
185 map["category-layout"] = "grid";
186 map["card-size"] = "small";
187 map["overlay"] = true;
192 QVariantMap map, artMap, attributesMap;
193 artMap["aspect-ratio"] = "1";
194 artMap["field"] = "art";
196 map["title"] = "HOLA";
197 map["attributes"] = attributesMap;
201 return QVariant::fromValue(resultsModel);
203 return resultsModel->rowCount();
207 qFatal("Using un-implemented Categories role");
213ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<Scope *> &scopes, const QString &categoryId, QObject* parent)
214 : unity::shell::scopes::ResultsModelInterface(parent)
216 , m_categoryId(categoryId)
220QString ScopesOverviewResultsModel::categoryId() const
225void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
227 qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
230int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
232 const int scopeCount = count();
233 for (int i = 0; i < scopeCount; ++i) {
234 if (m_scopes[i]->id() == id)
240QHash<int, QByteArray> ScopesOverviewResultsModel::roleNames() const
242 QHash<int, QByteArray> roles = unity::shell::scopes::ResultsModelInterface::roleNames();
243 roles[RoleBackground + 1] = "scopeId";
247int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
251 return m_scopes.count();
254int ScopesOverviewResultsModel::count() const
260ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
262 unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
269 return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
271 return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
273 return qmlDirectory() + "graphics/applicationIcons/dash.png";
277 case RoleBackground + 1: // scopeId
278 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