on 6fe90db help sign in
unity8/tests/mocks/Unity/fake_scopesoverview.cpp
180 lines 5.4 kB history raw
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 */
17#include "fake_scopesoverview.h"
19#include "fake_scopes.h"
21#include <paths.h>
23ScopesOverview::ScopesOverview(Scopes* parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
26 delete m_categories;
27 m_categories = new ScopesOverviewCategories(parent, this);
30void ScopesOverview::activate(QVariant const& result)
32 Scopes *scopes = dynamic_cast<Scopes*>(parent());
33 Q_EMIT openScope(scopes->getScope(result.toString()));
38ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
39 : unity::shell::scopes::CategoriesInterface(parent)
40 , m_scopes(scopes)
44int ScopesOverviewCategories::rowCount(const QModelIndex& /*parent*/) const
46 return 2;
49void ScopesOverviewCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
51 qFatal("Using un-implemented ScopesOverviewCategories::addSpecialCategory");
54bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
56 qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
59QVariant
60ScopesOverviewCategories::data(const QModelIndex& index, int role) const
62 if (!index.isValid()) {
63 return QVariant();
64 }
66 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
67 if (!resultsModel) {
68 QObject *that = const_cast<ScopesOverviewCategories*>(this);
69 resultsModel = new ScopesOverviewResultsModel(m_scopes, index.row() == 0, that);
70 m_resultsModels[index.row()] = resultsModel;
71 }
72 switch (role) {
73 case RoleCategoryId:
74 return index.row() == 0 ? "favourites" : "all";
75 case RoleName:
76 return index.row() == 0 ? "Favourites" : "All";
77 case RoleIcon:
78 return QVariant();
79 case RoleRawRendererTemplate:
80 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
81 return QVariant();
82 case RoleRenderer:
83 {
84 QVariantMap map;
85 map["category-layout"] = "grid";
86 map["card-size"] = "small";
87 map["overlay"] = true;
88 return map;
89 }
90 case RoleComponents:
91 {
92 QVariantMap map, artMap;
93 artMap["aspect-ratio"] = "0.5";
94 artMap["field"] = "art";
95 map["art"] = artMap;
96 map["title"] = "HOLA";
97 return map;
98 }
99 case RoleResults:
100 return QVariant::fromValue(resultsModel);
101 case RoleCount:
102 return resultsModel->rowCount();
103 default:
104 qFatal("Using un-implemented Categories role");
105 return QVariant();
106 }
111ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
112 : unity::shell::scopes::ResultsModelInterface(parent)
113 , m_scopes(scopes)
114 , m_isFavoriteCategory(isFavoriteCategory)
118QString ScopesOverviewResultsModel::categoryId() const
120 return m_isFavoriteCategory ? "favourites" : "all";
123void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
125 qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
128int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
130 const int scopeCount = count();
131 for (int i = 0; i < scopeCount; ++i) {
132 if (m_scopes->scopeAt(i, m_isFavoriteCategory)->id() == id)
133 return i;
134 }
135 return -1;
138QHash<int, QByteArray> ScopesOverviewResultsModel::roleNames() const
140 QHash<int, QByteArray> roles = unity::shell::scopes::ResultsModelInterface::roleNames();
141 roles[RoleBackground + 1] = "scopeId";
142 return roles;
145int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
147 Q_UNUSED(parent);
149 return m_scopes->count(m_isFavoriteCategory);
152int ScopesOverviewResultsModel::count() const
154 return rowCount();
157QVariant
158ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
160 switch (role) {
161 case RoleUri:
162 case RoleCategoryId:
163 case RoleDndUri:
164 return QString();
165 case RoleResult:
166 return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
167 case RoleTitle:
168 return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->name();
169 case RoleArt:
170 return qmlDirectory() + "graphics/applicationIcons/dash.png";
171 case RoleMascot:
172 case RoleEmblem:
173 case RoleSummary:
174 case RoleBackground + 1: // scopeId
175 return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
176 break;
177 default:
178 return QVariant();
179 }