@@ -23,8 +23,9 @@
23ScopesOverview::ScopesOverview(Scopes* parent)
23ScopesOverview::ScopesOverview(Scopes* parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
26− m_searchCategories = m_categories; // save the usual categories as search result
26+ delete m_categories; // delete the usual categories, we're not going to use it
27 m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
27 m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
28+ m_searchCategories = new ScopesOverviewSearchCategories(parent, this);
28 m_categories = m_scopesOverviewCategories;
29 m_categories = m_scopesOverviewCategories;
@@ -69,15 +70,17 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
69 return QVariant();
70 return QVariant();
73+ const QString categoryId = index.row() == 0 ? "favorites" : "all";
72 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
75 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
73 if (!resultsModel) {
76 if (!resultsModel) {
74 QObject *that = const_cast<ScopesOverviewCategories*>(this);
77 QObject *that = const_cast<ScopesOverviewCategories*>(this);
75− resultsModel = new ScopesOverviewResultsModel(m_scopes, index.row() == 0, that);
78+ resultsModel = new ScopesOverviewResultsModel(m_scopes->scopes(index.row() == 0), categoryId, that);
76 m_resultsModels[index.row()] = resultsModel;
79 m_resultsModels[index.row()] = resultsModel;
78 switch (role) {
81 switch (role) {
79 case RoleCategoryId:
82 case RoleCategoryId:
80− return index.row() == 0 ? "favorites" : "all";
83+ return categoryId;
81 case RoleName:
84 case RoleName:
82 return index.row() == 0 ? "Favorites" : "All";
85 return index.row() == 0 ? "Favorites" : "All";
83 case RoleIcon:
86 case RoleIcon:
@@ -114,16 +117,96 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
117−ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
120+ScopesOverviewSearchCategories::ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent)
121+ : unity::shell::scopes::CategoriesInterface(parent)
126+int ScopesOverviewSearchCategories::rowCount(const QModelIndex& /*parent*/) const
131+void ScopesOverviewSearchCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
133+ qFatal("Using un-implemented ScopesOverviewSearchCategories::addSpecialCategory");
136+bool ScopesOverviewSearchCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
138+ qFatal("Using un-implemented ScopesOverviewSearchCategories::overrideCategoryJson");
142+ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
144+ if (!index.isValid()) {
148+ const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
150+ unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
151+ if (!resultsModel) {
152+ QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
153+ QList<unity::shell::scopes::ScopeInterface *> scopes;
154+ if (index.row() == 0) {
155+ scopes << m_scopes->getScope("clickscope") << nullptr << m_scopes->getScope("MockScope2");
157+ scopes << nullptr << m_scopes->getScope("MockScope7") << nullptr << m_scopes->getScope("MockScope1");
159+ resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
160+ m_resultsModels[index.row()] = resultsModel;
163+ case RoleCategoryId:
166+ return index.row() == 0 ? "SearchA" : "SearchB";
169+ case RoleRawRendererTemplate:
170+ qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
175+ map["category-layout"] = "grid";
176+ map["card-size"] = "small";
177+ map["overlay"] = true;
180+ case RoleComponents:
182+ QVariantMap map, artMap;
183+ artMap["aspect-ratio"] = "1";
184+ artMap["field"] = "art";
185+ map["art"] = artMap;
186+ map["title"] = "HOLA";
190+ return QVariant::fromValue(resultsModel);
192+ return resultsModel->rowCount();
194+ qFatal("Using un-implemented Categories role");
200+ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent)
118 : unity::shell::scopes::ResultsModelInterface(parent)
201 : unity::shell::scopes::ResultsModelInterface(parent)
119 , m_scopes(scopes)
202 , m_scopes(scopes)
120− , m_isFavoriteCategory(isFavoriteCategory)
203+ , m_categoryId(categoryId)
124QString ScopesOverviewResultsModel::categoryId() const
207QString ScopesOverviewResultsModel::categoryId() const
126− return m_isFavoriteCategory ? "favorites" : "all";
209+ return m_categoryId;
129void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
212void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
@@ -135,7 +218,7 @@ int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
136 const int scopeCount = count();
219 const int scopeCount = count();
137 for (int i = 0; i < scopeCount; ++i) {
220 for (int i = 0; i < scopeCount; ++i) {
138− if (m_scopes->scopeAt(i, m_isFavoriteCategory)->id() == id)
221+ if (m_scopes[i]->id() == id)
139 return i;
222 return i;
141 return -1;
224 return -1;
@@ -152,7 +235,7 @@ int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
153 Q_UNUSED(parent);
236 Q_UNUSED(parent);
155− return m_scopes->count(m_isFavoriteCategory);
238+ return m_scopes.count();
158int ScopesOverviewResultsModel::count() const
241int ScopesOverviewResultsModel::count() const
@@ -163,22 +246,23 @@ int ScopesOverviewResultsModel::count() const
164ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
247ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
249+ unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
166 switch (role) {
250 switch (role) {
167 case RoleUri:
251 case RoleUri:
168 case RoleCategoryId:
252 case RoleCategoryId:
169 case RoleDndUri:
253 case RoleDndUri:
170 return QString();
254 return QString();
171 case RoleResult:
255 case RoleResult:
172− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
256+ return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
173 case RoleTitle:
257 case RoleTitle:
174− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->name();
258+ return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
175 case RoleArt:
259 case RoleArt:
176 return qmlDirectory() + "graphics/applicationIcons/dash.png";
260 return qmlDirectory() + "graphics/applicationIcons/dash.png";
177 case RoleMascot:
261 case RoleMascot:
178 case RoleEmblem:
262 case RoleEmblem:
179 case RoleSummary:
263 case RoleSummary:
180 case RoleBackground + 1: // scopeId
264 case RoleBackground + 1: // scopeId
181− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
265+ return scope ? scope->id() : nullptr;
184 return QVariant();
268 return QVariant();