44
44
Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
46
46
Scopes *scopes = dynamic_cast<Scopes*>(parent());
47
m_openScope = scopes->getScopeFromAll(result.toString());
48
Q_EMIT openScope(m_openScope);
47
if (scopes->getScope(result.toString())) {
48
Q_EMIT gotoScope(result.toString());
50
m_openScope = scopes->getScopeFromAll(result.toString());
51
Q_EMIT openScope(m_openScope);
55
void ScopesOverview::setFavorite(Scope *scope, bool favorite)
57
m_scopesOverviewCategories->setFavorite(scope, favorite);
60
void ScopesOverview::moveFavoriteTo(Scope *scope, int index)
62
m_scopesOverviewCategories->moveFavoriteTo(scope, index);
51
65
ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
69
83
qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
73
ScopesOverviewCategories::data(const QModelIndex& index, int role) const
86
void ScopesOverviewCategories::setFavorite(Scope *scope, bool favorite)
88
if (m_resultsModels.value(0)) {
90
m_resultsModels[0]->appendScope(scope);
92
m_resultsModels[0]->removeScope(scope);
95
if (m_resultsModels.value(1)) {
97
m_resultsModels[1]->removeScope(scope);
99
m_resultsModels[1]->appendScope(scope);
104
void ScopesOverviewCategories::moveFavoriteTo(Scope *scope, int index)
106
m_resultsModels[0]->moveScopeTo(scope, index);
109
QVariant ScopesOverviewCategories::data(const QModelIndex& index, int role) const
75
111
if (!index.isValid()) {
76
112
return QVariant();
79
const QString categoryId = index.row() == 0 ? "favorites" : "all";
115
const QString categoryId = index.row() == 0 ? "favorites" : "other";
81
unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
117
ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
82
118
if (!resultsModel) {
83
119
QObject *that = const_cast<ScopesOverviewCategories*>(this);
84
QList<Scope*> scopes = index.row() == 0 ? m_scopes->scopes() : m_scopes->allScopes();
120
QList<Scope*> scopes = index.row() == 0 ? m_scopes->favScopes() : m_scopes->nonFavScopes();
85
121
resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
86
122
m_resultsModels[index.row()] = resultsModel;
158
194
const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
160
unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
196
ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
161
197
if (!resultsModel) {
162
198
QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
163
199
QList<Scope *> scopes;
256
292
return rowCount();
260
ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
295
QVariant ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
262
297
unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
269
304
return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
271
306
return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
308
return scope && scope->name() == "Videos" ? "tube, movies, cinema" : QString();
273
310
return qmlDirectory() + "graphics/applicationIcons/dash.png";
281
318
return QVariant();
322
void ScopesOverviewResultsModel::appendScope(Scope *scope)
324
Q_ASSERT(!m_scopes.contains(scope));
325
const int index = rowCount();
326
beginInsertRows(QModelIndex(), index, index);
329
Q_EMIT countChanged();
332
void ScopesOverviewResultsModel::removeScope(Scope *scope)
334
const int index = m_scopes.indexOf(scope);
335
Q_ASSERT(index != -1);
336
beginRemoveRows(QModelIndex(), index, index);
337
m_scopes.removeAt(index);
339
Q_EMIT countChanged();
342
void ScopesOverviewResultsModel::moveScopeTo(Scope *scope, int to)
344
const int from = m_scopes.indexOf(scope);
346
beginMoveRows(QModelIndex(), from, from, QModelIndex(), to + (to > from ? 1 : 0));
347
m_scopes.move(from, to);