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->setFocused(true);
30 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
31 item->setProgress(10);
32 item->setPinned(true);
34 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
35 item->setProgress(50);
36 item->setCountVisible(true);
38 item = new MockLauncherItem("music-app", "/usr/share/applications/music-app.desktop", "Music", "soundcloud", this);
40 item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook", this);
41 item->setProgress(150);
43 item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser", this);
45 item->setCountVisible(true);
47 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
49 item->setCountVisible(true);
50 item->setPinned(true);
52 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
54 item->setCountVisible(true);
56 item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather", this);
57 item->setCount(1234567890);
58 item->setCountVisible(true);
59 item->setPinned(true);
61 item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad", this);
62 item->setProgress(50);
64 item->setCountVisible(true);
65 item->setFocused(true);
66 item->setPinned(true);
68 item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
69 item->setPinned(true);
73MockLauncherModel::~MockLauncherModel()
77int MockLauncherModel::rowCount(const QModelIndex& parent) const
80 return m_list.count();
83QVariant MockLauncherModel::data(const QModelIndex& index, int role) const
85 LauncherItemInterface *item = m_list.at(index.row());
95 return item->pinned();
97 return item->running();
99 return item->recent();
101 return item->progress();
103 return item->count();
104 case RoleCountVisible:
105 return item->countVisible();
107 return item->focused();
113unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index) const
115 if (index < 0 || index >= m_list.count())
119 return m_list.at(index);
122void MockLauncherModel::move(int oldIndex, int newIndex)
124 // Make sure its not moved outside the lists
128 if (newIndex >= m_list.count()) {
129 newIndex = m_list.count()-1;
133 if (oldIndex == newIndex) {
137 // QList's and QAbstractItemModel's move implementation differ when moving an item up the list :/
138 // While QList needs the index in the resulting list, beginMoveRows expects it to be in the current list
139 // adjust the model's index by +1 in case we're moving upwards
140 int newModelIndex = newIndex > oldIndex ? newIndex+1 : newIndex;
142 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newModelIndex);
143 m_list.move(oldIndex, newIndex);
146 pin(m_list.at(newIndex)->appId());
149void MockLauncherModel::pin(const QString &appId, int index)
151 int currentIndex = findApp(appId);
153 if (currentIndex >= 0) {
154 if (index == -1 || index == currentIndex) {
155 m_list.at(currentIndex)->setPinned(true);
156 QModelIndex modelIndex = this->index(currentIndex);
157 Q_EMIT dataChanged(modelIndex, modelIndex);
159 move(currentIndex, index);
162 beginInsertRows(QModelIndex(), index, index);
163 m_list.insert(index, new MockLauncherItem(appId,
167 m_list.at(index)->setPinned(true);
172void MockLauncherModel::requestRemove(const QString &appId)
174 int index = findApp(appId);
176 beginRemoveRows(QModelIndex(), index, 0);
177 m_list.takeAt(index)->deleteLater();
182void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
184 Q_EMIT quickListTriggered(appId, actionIndex);
187int MockLauncherModel::findApp(const QString &appId)
189 for (int i = 0; i < m_list.count(); ++i) {
190 MockLauncherItem *item = m_list.at(i);
191 if (item->appId() == appId) {
198void MockLauncherModel::setUser(const QString &username)
201 // TODO: implement this...
204QString MockLauncherModel::getUrlForAppId(const QString &appId) const
206 return "application:///" + appId + ".desktop";
209void MockLauncherModel::setApplicationManager(unity::shell::application::ApplicationManagerInterface *applicationManager)
211 Q_UNUSED(applicationManager)
214bool MockLauncherModel::onlyPinned() const
219void MockLauncherModel::setOnlyPinned(bool onlyPinned)
224void MockLauncherModel::emitHint()
229unity::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