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>
31Lenses::Lenses(QObject *parent)
32 : QAbstractListModel(parent)
33 , m_unityLenses(std::make_shared<unity::dash::GSettingsScopes>())
34/* , m_homeLens(std::make_shared<unity::dash::HomeLens>(QString::fromUtf8(dgettext("unity", "Home")).toStdString(),
35 QString::fromUtf8(dgettext("unity", "Home screen")).toStdString(),
36 QString::fromUtf8(dgettext("unity", "Search")).toStdString()))*/
39 m_roles[Lenses::RoleLens] = "lens";
40 m_roles[Lenses::RoleId] = "id";
41 m_roles[Lenses::RoleVisible] = "visible";
43 m_unityLenses->scope_added.connect(sigc::mem_fun(this, &Lenses::onScopeAdded));
44 m_unityLenses->scope_removed.connect(sigc::mem_fun(this, &Lenses::onScopeRemoved));
45 m_unityLenses->scopes_reordered.connect(sigc::mem_fun(this, &Lenses::onScopesReordered));
46 m_unityLenses->LoadScopes();
49QHash<int, QByteArray> Lenses::roleNames() const
54int Lenses::rowCount(const QModelIndex& parent) const
58 return m_lenses.count();
61QVariant Lenses::data(const QModelIndex& index, int role) const
65 if (!index.isValid()) {
69 Lens* lens = m_lenses.at(index.row());
71 if (role == Lenses::RoleLens) {
72 return QVariant::fromValue(lens);
73 } else if (role == Lenses::RoleId) {
74 return QVariant::fromValue(lens->id());
75 } else if (role == Lenses::RoleVisible) {
76 return QVariant::fromValue(lens->visible());
82QVariant Lenses::get(int row) const
84 return data(QAbstractListModel::index(row), 0);
87QVariant Lenses::get(const QString& lens_id) const
89 Q_FOREACH(Lens* lens, m_lenses) {
90 if (lens->id() == lens_id) {
91 return QVariant::fromValue(lens);
98bool Lenses::loaded() const
103void Lenses::onScopeAdded(const unity::dash::Scope::Ptr& scope, int position)
105 int index = m_lenses.count();
106 beginInsertRows(QModelIndex(), index, index);
110 // FIXME: do only once after all loaded?
112 Q_EMIT loadedChanged(m_loaded);
115void Lenses::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
120void Lenses::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
125void Lenses::loadMocks()
127 /* FIXME: this is temporary code that is required on mobile to order
128 the lenses according to the design.
130 QStringList staticLenses;
131 staticLenses << "mockmusic.lens" << "people.lens" << "home.lens" << "applications.lens" << "mockvideos.lens";
133 // not all the lenses are guaranteed to go into the model (only if their UnitCore counterparts exist);
134 // so build up a list of the valid ones, then add them later.
135 QList<unity::dash::Scope::Ptr> added_lenses;
137 // add statically ordered lenses
138 Q_FOREACH(QString lensId, staticLenses) {
139 unity::dash::Scope::Ptr lens = m_unityLenses->GetScope(lensId.toStdString());
141 added_lenses << lens;
145 // add remaining lenses
146 unity::dash::Scopes::ScopeList lensesList = m_unityLenses->GetScopes();
147 for(auto it = lensesList.begin(); it != lensesList.end(); ++it) {
148 unity::dash::Scope::Ptr lens = (*it);
149 if (!staticLenses.contains(QString::fromStdString(lens->id))) {
150 added_lenses << lens;
154 if (added_lenses.count() > 0) {
155 int index = rowCount();
156 beginInsertRows(QModelIndex(), index, index+added_lenses.count()-1);
157 Q_FOREACH(unity::dash::Scope::Ptr lens, added_lenses) {
164 Q_EMIT loadedChanged(m_loaded);
166 // listen to dynamically added lenses
167 //m_homeLens->lens_added.connect(sigc::mem_fun(this, &Lenses::onLensAdded)); //FIXME
170void Lenses::onLensPropertyChanged()
172 QModelIndex lensIndex = index(m_lenses.indexOf(qobject_cast<Lens*>(sender())));
173 Q_EMIT dataChanged(lensIndex, lensIndex);
176void Lenses::addUnityLens(const unity::dash::Scope::Ptr& unity_lens)
178 Lens* lens = new Lens(this);
179 lens->setUnityLens(unity_lens);
181 QObject::connect(lens, SIGNAL(visibleChanged(bool)), this, SLOT(onLensPropertyChanged()));
182 m_lenses.append(lens);
185void Lenses::removeUnityLens(int index)
187 Lens* lens = m_lenses.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