@@ -0,0 +1,149 @@
1+/*
2+ * Copyright (C) 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+ */
16+
17+#include "fake_scopesoverview.h"
18+
19+#include "fake_scopes.h"
20+
21+#include <paths.h>
22+
23+ScopesOverview::ScopesOverview(Scopes* parent)
24+ : Scope("scopesOverview", "Scopes Overview", false, parent)
25+{
26+ delete m_categories;
27+ m_categories = new ScopesOverviewCategories(this);
28+}
29+
30+ScopesOverviewCategories::ScopesOverviewCategories(QObject* parent)
31+ : unity::shell::scopes::CategoriesInterface(parent)
32+{
33+}
34+
35+int ScopesOverviewCategories::rowCount(const QModelIndex& /*parent*/) const
36+{
37+ return 2;
38+}
39+
40+void ScopesOverviewCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
41+{
42+ qFatal("Using un-implemented ScopesOverviewCategories::addSpecialCategory");
43+}
44+
45+bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
46+{
47+ qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
48+}
49+
50+QVariant
51+ScopesOverviewCategories::data(const QModelIndex& index, int role) const
52+{
53+ if (!index.isValid()) {
54+ return QVariant();
55+ }
56+
57+ return QVariant();
58+ unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
59+ if (!resultsModel) {
60+ QObject *that = const_cast<ScopesOverviewCategories*>(this);
61+ resultsModel = new ScopesOverviewResultsModel(static_cast<Scopes*>(parent()), index.row() == 0, that);
62+ m_resultsModels[index.row()] = resultsModel;
63+ }
64+ switch (role) {
65+ case RoleCategoryId:
66+ return index.row() == 0 ? "favourites" : "all";
67+ case RoleName:
68+ return index.row() == 0 ? "Favourites" : "All";
69+ case RoleIcon:
70+ return QVariant();
71+ case RoleRawRendererTemplate:
72+ qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
73+ return QVariant();
74+ case RoleRenderer:
75+ {
76+ QVariantMap map;
77+ map["category-layout"] = "grid";
78+ map["card-size"] = "medium";
79+ map["overlay"] = true;
80+ return map;
81+ }
82+ case RoleComponents:
83+ {
84+ QVariantMap map, artMap;
85+ artMap["aspect-ratio"] = "1.0";
86+ artMap["field"] = "art";
87+ map["art"] = artMap;
88+ map["title"] = "HOLA";
89+ return map;
90+ }
91+ case RoleResults:
92+ return QVariant::fromValue(resultsModel);
93+ case RoleCount:
94+ return resultsModel->rowCount();
95+ default:
96+ qFatal("Using un-implemented Categories role");
97+ return QVariant();
98+ }
99+}
100+
101+ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
102+ : unity::shell::scopes::ResultsModelInterface(parent)
103+ , m_scopes(scopes)
104+ , m_isFavoriteCategory(isFavoriteCategory)
105+{
106+}
107+
108+QString ScopesOverviewResultsModel::categoryId() const
109+{
110+ return m_isFavoriteCategory ? "favourites" : "all";
111+}
112+
113+void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
114+{
115+ qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
116+}
117+
118+int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
119+{
120+ Q_UNUSED(parent);
121+
122+ return m_scopes->count(m_isFavoriteCategory);
123+}
124+
125+int ScopesOverviewResultsModel::count() const
126+{
127+ return rowCount();
128+}
129+
130+QVariant
131+ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
132+{
133+ switch (role) {
134+ case RoleUri:
135+ case RoleCategoryId:
136+ case RoleDndUri:
137+ case RoleResult:
138+ return QString();
139+ case RoleTitle:
140+ return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->name();
141+ case RoleArt:
142+ return qmlDirectory() + "graphics/applicationIcons/dash.png";
143+ case RoleMascot:
144+ case RoleEmblem:
145+ case RoleSummary:
146+ default:
147+ return QVariant();
148+ }
149+}