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::RoleLens] = "scope";
37 m_roles[Scopes::RoleId] = "id";
38 m_roles[Scopes::RoleVisible] = "visible";
40 m_unityScopes->scope_added.connect(sigc::mem_fun(this, &Scopes::onScopeAdded));
41 m_unityScopes->scope_removed.connect(sigc::mem_fun(this, &Scopes::onScopeRemoved));
42 m_unityScopes->scopes_reordered.connect(sigc::mem_fun(this, &Scopes::onScopesReordered));
43 m_unityScopes->LoadScopes();
46QHash<int, QByteArray> Scopes::roleNames() const
51int Scopes::rowCount(const QModelIndex& parent) const
55 return m_scopes.count();
58QVariant Scopes::data(const QModelIndex& index, int role) const
62 if (!index.isValid()) {
66 Scope* scope = m_scopes.at(index.row());
68 if (role == Scopes::RoleLens) {
69 return QVariant::fromValue(scope);
70 } else if (role == Scopes::RoleId) {
71 return QVariant::fromValue(scope->id());
72 } else if (role == Scopes::RoleVisible) {
73 return QVariant::fromValue(scope->visible());
79QVariant Scopes::get(int row) const
81 return data(QAbstractListModel::index(row), 0);
84QVariant Scopes::get(const QString& scope_id) const
86 Q_FOREACH(Scope* scope, m_scopes) {
87 if (scope->id() == scope_id) {
88 return QVariant::fromValue(scope);
95bool Scopes::loaded() const
100void Scopes::onScopeAdded(const unity::dash::Scope::Ptr& scope, int position)
102 int index = m_scopes.count();
103 beginInsertRows(QModelIndex(), index, index);
104 addUnityScope(scope);
107 // FIXME: do only once after all loaded?
109 Q_EMIT loadedChanged(m_loaded);
112void Scopes::onScopesLoaded()
114 qWarning() << "Scopes Loaded!!!";
117void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
122void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
127void Scopes::onScopePropertyChanged()
129 QModelIndex scopeIndex = index(m_scopes.indexOf(qobject_cast<Scope*>(sender())));
130 Q_EMIT dataChanged(scopeIndex, scopeIndex);
133void Scopes::addUnityScope(const unity::dash::Scope::Ptr& unity_scope)
135 qDebug() << "Scope added:" << QString::fromStdString(unity_scope->id);
136 Scope* scope = new Scope(this);
137 scope->setUnityScope(unity_scope);
139 QObject::connect(scope, SIGNAL(visibleChanged(bool)), this, SLOT(onScopePropertyChanged()));
140 m_scopes.append(scope);
143void Scopes::removeUnityScope(int index)
145 Scope* scope = m_scopes.takeAt(index);
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