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] = "lens";
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::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
117void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
122void Scopes::loadMocks()
124 /* FIXME: this is temporary code that is required on mobile to order
125 the lenses according to the design.
127 QStringList staticScopes;
128 staticScopes << "mockmusic.lens" << "people.lens" << "home.lens" << "applications.lens" << "mockvideos.lens";
130 // not all the lenses are guaranteed to go into the model (only if their UnitCore counterparts exist);
131 // so build up a list of the valid ones, then add them later.
132 QList<unity::dash::Scope::Ptr> added_scopes;
134 // add statically ordered lenses
135 Q_FOREACH(QString lensId, staticScopes) {
136 unity::dash::Scope::Ptr lens = m_unityScopes->GetScope(lensId.toStdString());
138 added_scopes << lens;
142 // add remaining lenses
143 unity::dash::Scopes::ScopeList scopesList = m_unityScopes->GetScopes();
144 for(auto it = scopesList.begin(); it != scopesList.end(); ++it) {
145 unity::dash::Scope::Ptr scope = (*it);
146 if (!staticScopes.contains(QString::fromStdString(scope->id))) {
147 added_scopes << scope;
151 if (added_scopes.count() > 0) {
152 int index = rowCount();
153 beginInsertRows(QModelIndex(), index, index+added_scopes.count()-1);
154 Q_FOREACH(unity::dash::Scope::Ptr scope, added_scopes) {
155 addUnityScope(scope);
161 Q_EMIT loadedChanged(m_loaded);
164void Scopes::onScopePropertyChanged()
166 QModelIndex scopeIndex = index(m_scopes.indexOf(qobject_cast<Scope*>(sender())));
167 Q_EMIT dataChanged(scopeIndex, scopeIndex);
170void Scopes::addUnityScope(const unity::dash::Scope::Ptr& unity_scope)
172 Scope* scope = new Scope(this);
173 scope->setUnityScope(unity_scope);
175 QObject::connect(scope, SIGNAL(visibleChanged(bool)), this, SLOT(onLensPropertyChanged()));
176 m_scopes.append(scope);
179void Scopes::removeUnityScope(int index)
181 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