2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
16 * Author: Nick Dedekind <nick.dedekind@canonical.com>
20#include "fake_scopes.h"
21#include "fake_scopesoverview.h"
23// TODO: Implement remaining pieces, like Categories (i.e. LensView now gives warnings)
28Scopes::Scopes(QObject *parent)
29 : unity::shell::scopes::ScopesInterface(parent)
30 , m_scopesOverview(nullptr)
34 timer.setSingleShot(true);
35 timer.setInterval(100);
36 QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateScopes()));
38 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
39 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
40 QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
49void Scopes::updateScopes()
52 addScope(new Scope("MockScope1", "People", true, this));
53 addScope(new Scope("MockScope2", "Music", false, this));
54 addScope(new Scope("clickscope", "Apps", true, this));
55 addScope(new Scope("MockScope5", "Videos", true, this));
56 addScope(new Scope("SingleCategoryScope", "Single", true, this, 1));
57 addScope(new Scope("MockScope4", "MS4", true, this));
58 addScope(new Scope("MockScope6", "MS6", true, this));
59 addScope(new Scope("MockScope7", "MS7", false, this));
60 addScope(new Scope("MockScope8", "MS8", false, this));
61 addScope(new Scope("MockScope9", "MS9", false, this));
62 addScope(new Scope("NullPreviewScope", "NPS", false, this, 1, true));
63 m_scopesOverview = new ScopesOverview(this);
67 Q_EMIT loadedChanged();
68 Q_EMIT overviewScopeChanged();
75 if (m_scopes.size() > 0) {
76 beginRemoveRows(QModelIndex(), 0, m_scopes.count()-1);
77 qDeleteAll(m_allScopes);
82 delete m_scopesOverview;
83 m_scopesOverview = nullptr;
87 Q_EMIT loadedChanged();
96int Scopes::rowCount(const QModelIndex&) const
98 return m_scopes.count();
101QVariant Scopes::data(const QModelIndex& index, int role) const
103 if (!index.isValid() || index.row() >= m_scopes.size()) {
107 Scope* scope = m_scopes.at(index.row());
109 if (role == Scopes::RoleScope) {
110 return QVariant::fromValue(scope);
111 } else if (role == Scopes::RoleId) {
112 return QVariant::fromValue(scope->id());
113 } else if (role == Scopes::RoleTitle) {
114 return QVariant::fromValue(scope->name());
120unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
122 if (row < 0 || row >= m_scopes.size()) {
126 return m_scopes[row];
129unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
131 // According to mh3 Scopes::getScope should only return favorite scopes (i.e the ones in the model)
132 for (Scope *scope : m_scopes) {
133 if (scope->id() == scope_id)
139Scope* Scopes::getScopeFromAll(const QString& scope_id) const
141 for (Scope *scope : m_allScopes) {
142 if (scope->id() == scope_id)
148QModelIndex Scopes::parent(const QModelIndex&) const
150 return QModelIndex();
153bool Scopes::loaded() const
158int Scopes::count() const
163unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
165 return m_scopesOverview;
168void Scopes::setFavorite(const QString& scopeId, bool favorite)
171 for (Scope *scope : m_scopes) {
172 // Check it's not already there
173 Q_ASSERT(scope->id() != scopeId);
175 for (Scope *scope : m_allScopes) {
176 if (scope->id() == scopeId) {
177 const int index = rowCount();
178 beginInsertRows(QModelIndex(), index, index);
181 m_scopesOverview->setFavorite(scope, true);
185 Q_ASSERT(false && "Unknown scopeId");
187 for (Scope *scope : m_scopes) {
188 if (scope->id() == scopeId) {
189 const int index = m_scopes.indexOf(scope);
190 beginRemoveRows(QModelIndex(), index, index);
191 m_scopes.removeAt(index);
193 m_scopesOverview->setFavorite(scope, false);
197 Q_ASSERT(false && "Unknown scopeId");
201void Scopes::moveFavoriteTo(const QString& scopeId, int to)
204 for (int i = 0; i < m_scopes.count(); ++i) {
205 if (m_scopes[i]->id() == scopeId) {
210 Q_ASSERT(from != -1);
211 beginMoveRows(QModelIndex(), from, from, QModelIndex(), to + (to > from ? 1 : 0));
212 m_scopes.move(from, to);
214 m_scopesOverview->moveFavoriteTo(m_scopes[to], to);
217QList<Scope*> Scopes::favScopes() const
222QList<Scope*> Scopes::nonFavScopes() const
225 for (Scope *scope : m_allScopes) {
226 if (!m_scopes.contains(scope))
232void Scopes::addScope(Scope* scope)
234 int index = rowCount();
235 if (scope->favorite()) {
236 beginInsertRows(QModelIndex(), index, index);
237 m_scopes.append(scope);
240 m_allScopes.append(scope);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list