on dd0f9ca help sign in
unity8/tests/mocks/Unity/fake_scopesoverview.cpp
160 lines 4.8 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::rowCount(const QModelIndex& parent) const
130 Q_UNUSED(parent);
132 return m_scopes->count(m_isFavoriteCategory);
135int ScopesOverviewResultsModel::count() const
137 return rowCount();
140QVariant
141ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
143 switch (role) {
144 case RoleUri:
145 case RoleCategoryId:
146 case RoleDndUri:
147 return QString();
148 case RoleResult:
149 return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
150 case RoleTitle:
151 return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->name();
152 case RoleArt:
153 return qmlDirectory() + "graphics/applicationIcons/dash.png";
154 case RoleMascot:
155 case RoleEmblem:
156 case RoleSummary:
157 default:
158 return QVariant();
159 }