@@ -48,6 +48,11 @@ Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
4848 Q_EMIT openScope(m_openScope);
4949}
5050
51+void ScopesOverview::setFavorite(Scope *scope, bool favorite)
52+{
53+ m_scopesOverviewCategories->setFavorite(scope, favorite);
54+}
55+
5156ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
5257 : unity::shell::scopes::CategoriesInterface(parent)
5358 , m_scopes(scopes)
@@ -69,6 +74,24 @@ bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId
6974 qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
7075}
7176
77+void ScopesOverviewCategories::setFavorite(Scope *scope, bool favorite)
78+{
79+ if (m_resultsModels.value(0)) {
80+ if (favorite) {
81+ m_resultsModels[0]->appendScope(scope);
82+ } else {
83+ m_resultsModels[0]->removeScope(scope);
84+ }
85+ }
86+ if (m_resultsModels.value(1)) {
87+ if (favorite) {
88+ m_resultsModels[1]->removeScope(scope);
89+ } else {
90+ m_resultsModels[1]->appendScope(scope);
91+ }
92+ }
93+}
94+
7295QVariant
7396ScopesOverviewCategories::data(const QModelIndex& index, int role) const
7497{
@@ -78,7 +101,7 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
78101
79102 const QString categoryId = index.row() == 0 ? "favorites" : "nonfavorites";
80103
81− unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
104+ ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
82105 if (!resultsModel) {
83106 QObject *that = const_cast<ScopesOverviewCategories*>(this);
84107 QList<Scope*> scopes = index.row() == 0 ? m_scopes->favScopes() : m_scopes->nonFavScopes();
@@ -157,7 +180,7 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
157180
158181 const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
159182
160− unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
183+ ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
161184 if (!resultsModel) {
162185 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
163186 QList<Scope *> scopes;
@@ -256,8 +279,7 @@ int ScopesOverviewResultsModel::count() const
256279 return rowCount();
257280}
258281
259−QVariant
260−ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
282+QVariant ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
261283{
262284 unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
263285 switch (role) {
@@ -281,3 +303,21 @@ ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
281303 return QVariant();
282304 }
283305}
306+
307+void ScopesOverviewResultsModel::appendScope(Scope *scope)
308+{
309+ Q_ASSERT(!m_scopes.contains(scope));
310+ const int index = rowCount();
311+ beginInsertRows(QModelIndex(), index, index);
312+ m_scopes << scope;
313+ endInsertRows();
314+}
315+
316+void ScopesOverviewResultsModel::removeScope(Scope *scope)
317+{
318+ const int index = m_scopes.indexOf(scope);
319+ Q_ASSERT(index != -1);
320+ beginRemoveRows(QModelIndex(), index, index);
321+ m_scopes.removeAt(index);
322+ endRemoveRows();
323+}