2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Michael Zanetti <michael.zanetti@canonical.com>
20#include "launchermodel.h"
21#include "launcheritem.h"
22#include "backend/launcherbackend.h"
24LauncherModel::LauncherModel(QObject *parent):
25 LauncherModelInterface(parent),
26 m_backend(new LauncherBackend(this))
28 Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
29 LauncherItem *item = new LauncherItem(entry,
30 m_backend->desktopFile(entry),
31 m_backend->displayName(entry),
32 m_backend->icon(entry),
34 if (m_backend->isPinned(entry)) {
35 item->setPinned(true);
37 item->setRecent(true);
43LauncherModel::~LauncherModel()
45 while (!m_list.empty()) {
46 m_list.takeFirst()->deleteLater();
50int LauncherModel::rowCount(const QModelIndex &parent) const
53 return m_list.count();
56QVariant LauncherModel::data(const QModelIndex &index, int role) const
58 LauncherItem *item = m_list.at(index.row());
61 return item->desktopFile();
63 return item->desktopFile();
69 return item->pinned();
75unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
77 if (index < 0 || index >= m_list.count()) {
80 return m_list.at(index);
83void LauncherModel::move(int oldIndex, int newIndex)
85 // Make sure its not moved outside the lists
89 if (newIndex >= m_list.count()) {
90 newIndex = m_list.count()-1;
94 if (oldIndex == newIndex) {
98 // QList's and QAbstractItemModel's move implementation differ when moving an item up the list :/
99 // While QList needs the index in the resulting list, beginMoveRows expects it to be in the current list
100 // adjust the model's index by +1 in case we're moving upwards
101 int newModelIndex = newIndex > oldIndex ? newIndex+1 : newIndex;
103 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newModelIndex);
104 m_list.move(oldIndex, newIndex);
109 pin(m_list.at(newIndex)->appId());
112void LauncherModel::pin(const QString &appId, int index)
114 int currentIndex = findApplication(appId);
116 if (currentIndex >= 0) {
117 if (index == -1 || index == currentIndex) {
118 m_list.at(currentIndex)->setPinned(true);
119 QModelIndex modelIndex = this->index(currentIndex);
120 Q_EMIT dataChanged(modelIndex, modelIndex);
122 move(currentIndex, index);
126 index = m_list.count();
128 beginInsertRows(QModelIndex(), index, index);
129 LauncherItem *item = new LauncherItem(appId,
130 m_backend->desktopFile(appId),
131 m_backend->displayName(appId),
132 m_backend->icon(appId));
133 item->setPinned(true);
134 m_list.insert(index, item);
139void LauncherModel::requestRemove(const QString &appId)
141 int index = findApplication(appId);
146 beginRemoveRows(QModelIndex(), index, index);
147 m_list.takeAt(index)->deleteLater();
153void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
155 int index = findApplication(appId);
160 LauncherItem *item = m_list.at(index);
161 QuickListModel *model = qobject_cast<QuickListModel*>(item->quickList());
163 QString actionId = model->get(actionIndex).actionId();
165 // Check if this is one of the launcher actions we handle ourselves
166 if (actionId == "pin_item") {
167 if (item->pinned()) {
168 requestRemove(appId);
173 // Nope, we don't know this action, let the backend forward it to the application
175 m_backend->triggerQuickListAction(appId, actionId);
180void LauncherModel::storeAppList()
183 Q_FOREACH(LauncherItem *item, m_list) {
184 if (item->pinned() || item->recent()) {
185 appIds << item->appId();
188 m_backend->setStoredApplications(appIds);
191int LauncherModel::findApplication(const QString &appId)
193 for (int i = 0; i < m_list.count(); ++i) {
194 LauncherItem *item = m_list.at(i);
195 if (item->appId() == appId) {
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