2 * Copyright 2013,2015 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 "MockLauncherModel.h"
21#include "MockLauncherItem.h"
23MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
25 MockLauncherItem *item = new MockLauncherItem("dialer-app", "/usr/share/applications/dialer-app.desktop", "Dialer", "dialer-app", this);
27 item->setPinned(true);
28 item->setRunning(true);
29 item->setFocused(true);
31 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
32 item->setProgress(10);
33 item->setPinned(true);
35 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
36 item->setProgress(50);
37 item->setCountVisible(true);
38 item->setRunning(true);
39 item->setAlerting(false);
41 item = new MockLauncherItem("music-app", "/usr/share/applications/music-app.desktop", "Music", "soundcloud", this);
43 item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook", this);
44 item->setProgress(150);
46 item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser", this);
48 item->setCountVisible(true);
49 item->setRunning(true);
50 item->setAlerting(false);
52 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
54 item->setCountVisible(true);
55 item->setAlerting(false);
56 item->setPinned(true);
58 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
60 item->setCountVisible(true);
61 item->setAlerting(false);
63 item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather", this);
64 item->setCount(1234567890);
65 item->setCountVisible(true);
66 item->setAlerting(false);
67 item->setPinned(true);
69 item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad", this);
70 item->setProgress(50);
72 item->setCountVisible(true);
73 item->setAlerting(false);
74 item->setFocused(true);
75 item->setPinned(true);
77 item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
78 item->setPinned(true);
82MockLauncherModel::~MockLauncherModel()
86int MockLauncherModel::rowCount(const QModelIndex& parent) const
89 return m_list.count();
92QVariant MockLauncherModel::data(const QModelIndex& index, int role) const
94 LauncherItemInterface *item = m_list.at(index.row());
104 return item->pinned();
106 return item->running();
108 return item->recent();
110 return item->progress();
112 return item->count();
113 case RoleCountVisible:
114 return item->countVisible();
116 return item->focused();
118 return item->alerting();
124unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index) const
126 if (index < 0 || index >= m_list.count())
130 return m_list.at(index);
133void MockLauncherModel::setAlerting(const QString &appId, bool alerting) {
134 int index = findApp(appId);
136 QModelIndex modelIndex = this->index(index);
137 MockLauncherItem *item = m_list.at(index);
138 if (!item->focused()) {
139 item->setAlerting(alerting);
140 Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RoleAlerting);
145void MockLauncherModel::move(int oldIndex, int newIndex)
147 // Make sure its not moved outside the lists
151 if (newIndex >= m_list.count()) {
152 newIndex = m_list.count()-1;
156 if (oldIndex == newIndex) {
160 // QList's and QAbstractItemModel's move implementation differ when moving an item up the list :/
161 // While QList needs the index in the resulting list, beginMoveRows expects it to be in the current list
162 // adjust the model's index by +1 in case we're moving upwards
163 int newModelIndex = newIndex > oldIndex ? newIndex+1 : newIndex;
165 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newModelIndex);
166 m_list.move(oldIndex, newIndex);
169 pin(m_list.at(newIndex)->appId());
172void MockLauncherModel::pin(const QString &appId, int index)
174 int currentIndex = findApp(appId);
176 if (currentIndex >= 0) {
177 if (index == -1 || index == currentIndex) {
178 m_list.at(currentIndex)->setPinned(true);
179 QModelIndex modelIndex = this->index(currentIndex);
180 Q_EMIT dataChanged(modelIndex, modelIndex);
182 move(currentIndex, index);
185 beginInsertRows(QModelIndex(), index, index);
186 m_list.insert(index, new MockLauncherItem(appId,
190 m_list.at(index)->setPinned(true);
195void MockLauncherModel::requestRemove(const QString &appId)
197 int index = findApp(appId);
199 beginRemoveRows(QModelIndex(), index, 0);
200 MockLauncherItem * item = m_list.takeAt(index);
201 item->setRunning(false);
207void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
209 Q_EMIT quickListTriggered(appId, actionIndex);
212int MockLauncherModel::findApp(const QString &appId)
214 for (int i = 0; i < m_list.count(); ++i) {
215 MockLauncherItem *item = m_list.at(i);
216 if (item->appId() == appId) {
223void MockLauncherModel::setProgress(const QString &appId, int progress)
225 int index = findApp(appId);
227 m_list.at(index)->setProgress(progress);
228 QModelIndex modelIndex = this->index(index);
229 Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RoleProgress);
233void MockLauncherModel::setUser(const QString &username)
236 // TODO: implement this...
239QString MockLauncherModel::getUrlForAppId(const QString &appId) const
241 return "application:///" + appId + ".desktop";
244void MockLauncherModel::setApplicationManager(unity::shell::application::ApplicationManagerInterface *applicationManager)
246 Q_UNUSED(applicationManager)
249bool MockLauncherModel::onlyPinned() const
254void MockLauncherModel::setOnlyPinned(bool onlyPinned)
259void MockLauncherModel::emitHint()
264void MockLauncherModel::setCount(const QString &appId, int count)
266 int index = findApp(appId);
268 m_list.at(index)->setCount(count);
269 QModelIndex modelIndex = this->index(index);
270 Q_EMIT dataChanged(modelIndex, modelIndex);
274void MockLauncherModel::setCountVisible(const QString &appId, bool countVisible)
276 int index = findApp(appId);
278 m_list.at(index)->setCountVisible(countVisible);
279 QModelIndex modelIndex = this->index(index);
280 Q_EMIT dataChanged(modelIndex, modelIndex);
284unity::shell::application::ApplicationManagerInterface *MockLauncherModel::applicationManager() const
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