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);
51void ScopesOverview::setFavorite(Scope *scope, bool favorite)
53 m_scopesOverviewCategories->setFavorite(scope, favorite);
56ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
57 : unity::shell::scopes::CategoriesInterface(parent)
62int ScopesOverviewCategories::rowCount(const QModelIndex& /*parent*/) const
67void ScopesOverviewCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
69 qFatal("Using un-implemented ScopesOverviewCategories::addSpecialCategory");
72bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
74 qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
77void ScopesOverviewCategories::setFavorite(Scope *scope, bool favorite)
79 if (m_resultsModels.value(0)) {
81 m_resultsModels[0]->appendScope(scope);
83 m_resultsModels[0]->removeScope(scope);
86 if (m_resultsModels.value(1)) {
88 m_resultsModels[1]->removeScope(scope);
90 m_resultsModels[1]->appendScope(scope);
96ScopesOverviewCategories::data(const QModelIndex& index, int role) const
98 if (!index.isValid()) {
102 const QString categoryId = index.row() == 0 ? "favorites" : "nonfavorites";
104 ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
106 QObject *that = const_cast<ScopesOverviewCategories*>(this);
107 QList<Scope*> scopes = index.row() == 0 ? m_scopes->favScopes() : m_scopes->nonFavScopes();
108 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
109 m_resultsModels[index.row()] = resultsModel;
115 return index.row() == 0 ? "Favorites" : "Non Favorites";
118 case RoleRawRendererTemplate:
119 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
124 map["category-layout"] = "grid";
125 map["card-size"] = "small";
126 map["overlay"] = true;
131 QVariantMap map, artMap, attributesMap;
132 artMap["aspect-ratio"] = "0.5";
133 artMap["field"] = "art";
135 map["title"] = "HOLA";
136 map["attributes"] = attributesMap;
140 return QVariant::fromValue(resultsModel);
142 return resultsModel->rowCount();
146 qFatal("Using un-implemented Categories role");
153ScopesOverviewSearchCategories::ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent)
154 : unity::shell::scopes::CategoriesInterface(parent)
159int ScopesOverviewSearchCategories::rowCount(const QModelIndex& /*parent*/) const
164void ScopesOverviewSearchCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
166 qFatal("Using un-implemented ScopesOverviewSearchCategories::addSpecialCategory");
169bool ScopesOverviewSearchCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
171 qFatal("Using un-implemented ScopesOverviewSearchCategories::overrideCategoryJson");
175ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
177 if (!index.isValid()) {
181 const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
183 ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
185 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
186 QList<Scope *> scopes;
187 if (index.row() == 0) {
188 scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
190 scopes << nullptr << m_scopes->getScopeFromAll("MockScope7") << nullptr << m_scopes->getScopeFromAll("MockScope1");
192 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
193 m_resultsModels[index.row()] = resultsModel;
199 return index.row() == 0 ? "SearchA" : "SearchB";
202 case RoleRawRendererTemplate:
203 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
208 map["category-layout"] = "grid";
209 map["card-size"] = "small";
210 map["overlay"] = true;
215 QVariantMap map, artMap, attributesMap;
216 artMap["aspect-ratio"] = "1";
217 artMap["field"] = "art";
219 map["title"] = "HOLA";
220 map["attributes"] = attributesMap;
224 return QVariant::fromValue(resultsModel);
226 return resultsModel->rowCount();
230 qFatal("Using un-implemented Categories role");
236ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<Scope *> &scopes, const QString &categoryId, QObject* parent)
237 : unity::shell::scopes::ResultsModelInterface(parent)
239 , m_categoryId(categoryId)
243QString ScopesOverviewResultsModel::categoryId() const
248void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
250 qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
253int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
255 const int scopeCount = count();
256 for (int i = 0; i < scopeCount; ++i) {
257 if (m_scopes[i]->id() == id)
263QHash<int, QByteArray> ScopesOverviewResultsModel::roleNames() const
265 QHash<int, QByteArray> roles = unity::shell::scopes::ResultsModelInterface::roleNames();
266 roles[RoleBackground + 1] = "scopeId";
270int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
274 return m_scopes.count();
277int ScopesOverviewResultsModel::count() const
282QVariant ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
284 unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
291 return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
293 return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
295 return qmlDirectory() + "graphics/applicationIcons/dash.png";
299 case RoleBackground + 1: // scopeId
300 return scope ? scope->id() : nullptr;
307void ScopesOverviewResultsModel::appendScope(Scope *scope)
309 Q_ASSERT(!m_scopes.contains(scope));
310 const int index = rowCount();
311 beginInsertRows(QModelIndex(), index, index);
316void ScopesOverviewResultsModel::removeScope(Scope *scope)
318 const int index = m_scopes.indexOf(scope);
319 Q_ASSERT(index != -1);
320 beginRemoveRows(QModelIndex(), index, index);
321 m_scopes.removeAt(index);
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