@@ -23,8 +23,9 @@
2323ScopesOverview::ScopesOverview(Scopes* parent)
2424 : Scope("scopesOverview", "Scopes Overview", false, parent)
2525{
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
2727 m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
28+ m_searchCategories = new ScopesOverviewSearchCategories(parent, this);
2829 m_categories = m_scopesOverviewCategories;
2930}
3031
@@ -69,15 +70,17 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
6970 return QVariant();
7071 }
7172
73+ const QString categoryId = index.row() == 0 ? "favorites" : "all";
74+
7275 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
7376 if (!resultsModel) {
7477 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);
7679 m_resultsModels[index.row()] = resultsModel;
7780 }
7881 switch (role) {
7982 case RoleCategoryId:
80− return index.row() == 0 ? "favorites" : "all";
83+ return categoryId;
8184 case RoleName:
8285 return index.row() == 0 ? "Favorites" : "All";
8386 case RoleIcon:
@@ -114,16 +117,96 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
114117
115118
116119
117−ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
120+ScopesOverviewSearchCategories::ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent)
121+ : unity::shell::scopes::CategoriesInterface(parent)
122+ , m_scopes(scopes)
123+{
124+}
125+
126+int ScopesOverviewSearchCategories::rowCount(const QModelIndex& /*parent*/) const
127+{
128+ return 2;
129+}
130+
131+void ScopesOverviewSearchCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
132+{
133+ qFatal("Using un-implemented ScopesOverviewSearchCategories::addSpecialCategory");
134+}
135+
136+bool ScopesOverviewSearchCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
137+{
138+ qFatal("Using un-implemented ScopesOverviewSearchCategories::overrideCategoryJson");
139+}
140+
141+QVariant
142+ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
143+{
144+ if (!index.isValid()) {
145+ return QVariant();
146+ }
147+
148+ const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
149+
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");
156+ } else {
157+ scopes << nullptr << m_scopes->getScope("MockScope7") << nullptr << m_scopes->getScope("MockScope1");
158+ }
159+ resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
160+ m_resultsModels[index.row()] = resultsModel;
161+ }
162+ switch (role) {
163+ case RoleCategoryId:
164+ return categoryId;
165+ case RoleName:
166+ return index.row() == 0 ? "SearchA" : "SearchB";
167+ case RoleIcon:
168+ return QVariant();
169+ case RoleRawRendererTemplate:
170+ qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
171+ return QVariant();
172+ case RoleRenderer:
173+ {
174+ QVariantMap map;
175+ map["category-layout"] = "grid";
176+ map["card-size"] = "small";
177+ map["overlay"] = true;
178+ return map;
179+ }
180+ case RoleComponents:
181+ {
182+ QVariantMap map, artMap;
183+ artMap["aspect-ratio"] = "1";
184+ artMap["field"] = "art";
185+ map["art"] = artMap;
186+ map["title"] = "HOLA";
187+ return map;
188+ }
189+ case RoleResults:
190+ return QVariant::fromValue(resultsModel);
191+ case RoleCount:
192+ return resultsModel->rowCount();
193+ default:
194+ qFatal("Using un-implemented Categories role");
195+ return QVariant();
196+ }
197+}
198+
199+
200+ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent)
118201 : unity::shell::scopes::ResultsModelInterface(parent)
119202 , m_scopes(scopes)
120− , m_isFavoriteCategory(isFavoriteCategory)
203+ , m_categoryId(categoryId)
121204{
122205}
123206
124207QString ScopesOverviewResultsModel::categoryId() const
125208{
126− return m_isFavoriteCategory ? "favorites" : "all";
209+ return m_categoryId;
127210}
128211
129212void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
@@ -135,7 +218,7 @@ int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
135218{
136219 const int scopeCount = count();
137220 for (int i = 0; i < scopeCount; ++i) {
138− if (m_scopes->scopeAt(i, m_isFavoriteCategory)->id() == id)
221+ if (m_scopes[i]->id() == id)
139222 return i;
140223 }
141224 return -1;
@@ -152,7 +235,7 @@ int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
152235{
153236 Q_UNUSED(parent);
154237
155− return m_scopes->count(m_isFavoriteCategory);
238+ return m_scopes.count();
156239}
157240
158241int ScopesOverviewResultsModel::count() const
@@ -163,22 +246,23 @@ int ScopesOverviewResultsModel::count() const
163246QVariant
164247ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
165248{
249+ unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
166250 switch (role) {
167251 case RoleUri:
168252 case RoleCategoryId:
169253 case RoleDndUri:
170254 return QString();
171255 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());
173257 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());
175259 case RoleArt:
176260 return qmlDirectory() + "graphics/applicationIcons/dash.png";
177261 case RoleMascot:
178262 case RoleEmblem:
179263 case RoleSummary:
180264 case RoleBackground + 1: // scopeId
181− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
265+ return scope ? scope->id() : nullptr;
182266 break;
183267 default:
184268 return QVariant();