2 * Copyright (C) 2011 Canonical, Ltd.
5 * Florian Boucault <florian.boucault@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28#include <QtCore/QStringList>
29#include <QtGui/QKeySequence>
31Scopes::Scopes(QObject *parent)
32 : QAbstractListModel(parent)
33 , m_unityScopes(std::make_shared<unity::dash::GSettingsScopes>())
36 m_roles[Scopes::RoleScope] = "scope";
37 m_roles[Scopes::RoleId] = "id";
38 m_roles[Scopes::RoleVisible] = "visible";
39 m_roles[Scopes::RoleTitle] = "title";
41 m_unityScopes->scope_added.connect(sigc::mem_fun(this, &Scopes::onScopeAdded));
42 m_unityScopes->scope_removed.connect(sigc::mem_fun(this, &Scopes::onScopeRemoved));
43 m_unityScopes->scopes_reordered.connect(sigc::mem_fun(this, &Scopes::onScopesReordered));
44 m_unityScopes->LoadScopes();
47QHash<int, QByteArray> Scopes::roleNames() const
52int Scopes::rowCount(const QModelIndex& parent) const
56 return m_scopes.count();
59QVariant Scopes::data(const QModelIndex& index, int role) const
63 if (!index.isValid()) {
67 Scope* scope = m_scopes.at(index.row());
69 if (role == Scopes::RoleScope) {
70 return QVariant::fromValue(scope);
71 } else if (role == Scopes::RoleId) {
72 return QVariant::fromValue(scope->id());
73 } else if (role == Scopes::RoleVisible) {
74 return QVariant::fromValue(scope->visible());
75 } else if (role == Scopes::RoleTitle) {
82QVariant Scopes::get(int row) const
84 return data(QAbstractListModel::index(row), 0);
87QVariant Scopes::get(const QString& scope_id) const
89 Q_FOREACH(Scope* scope, m_scopes) {
90 if (scope->id() == scope_id) {
91 return QVariant::fromValue(scope);
98bool Scopes::loaded() const
103void Scopes::onScopeAdded(const unity::dash::Scope::Ptr& scope, int /*position*/)
105 int index = m_scopes.count();
106 beginInsertRows(QModelIndex(), index, index);
107 addUnityScope(scope);
110 // FIXME: do only once after all loaded?
112 Q_EMIT loadedChanged(m_loaded);
115void Scopes::onScopesLoaded()
119void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
121 auto id = QString::fromStdString(scope->id);
122 auto index = findScopeById(id);
124 beginRemoveRows(QModelIndex(), index, index);
125 removeUnityScope(index);
128 Q_EMIT scopeRemoved(id, index);
132void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
134 // FIXME Should use beginMoveRows()/endMoveRows() to not recreate the UI for every scope.
137 // remove existing scopes
138 for (auto i=m_scopes.count()-1; i>=0; i--) {
143 for (uint i=0; i<scopes.size(); i++) {
144 addUnityScope(scopes[i]);
149void Scopes::onScopePropertyChanged()
151 QModelIndex scopeIndex = index(m_scopes.indexOf(qobject_cast<Scope*>(sender())));
152 Q_EMIT dataChanged(scopeIndex, scopeIndex);
155void Scopes::addUnityScope(const unity::dash::Scope::Ptr& unity_scope)
157 Scope* scope = new Scope(this);
158 scope->setUnityScope(unity_scope);
160 QObject::connect(scope, SIGNAL(visibleChanged(bool)), this, SLOT(onScopePropertyChanged()));
161 m_scopes.append(scope);
164void Scopes::removeUnityScope(int index)
166 Scope* scope = m_scopes.takeAt(index);
171int Scopes::findScopeById(const QString& scope_id)
173 for (int i=0; i<m_scopes.count(); i++) {
174 if (m_scopes[i]->id() == scope_id) {
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