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 "MockLauncherModel.h"
21#include "MockLauncherItem.h"
23MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
25 MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app", this);
28 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
29 item->setProgress(10);
31 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
32 item->setProgress(50);
34 item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook", this);
35 item->setProgress(150);
37 item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser", this);
40 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
43 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
46 item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather", this);
47 item->setCount(1234567890);
49 item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad", this);
50 item->setProgress(50);
53 item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
57MockLauncherModel::~MockLauncherModel()
61int MockLauncherModel::rowCount(const QModelIndex& parent) const
64 return m_list.count();
67QVariant MockLauncherModel::data(const QModelIndex& index, int role) const
69 LauncherItemInterface *item = m_list.at(index.row());
73 return item->desktopFile();
79 return item->pinned();
81 return item->running();
83 return item->recent();
85 return item->progress();
93unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index) const
95 if (index < 0 || index >= m_list.count())
99 return m_list.at(index);
102void MockLauncherModel::move(int oldIndex, int newIndex)
104 // Make sure its not moved outside the lists
108 if (newIndex >= m_list.count()) {
109 newIndex = m_list.count()-1;
113 if (oldIndex == newIndex) {
117 // QList's and QAbstractItemModel's move implementation differ when moving an item up the list :/
118 // While QList needs the index in the resulting list, beginMoveRows expects it to be in the current list
119 // adjust the model's index by +1 in case we're moving upwards
120 int newModelIndex = newIndex > oldIndex ? newIndex+1 : newIndex;
122 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newModelIndex);
123 m_list.move(oldIndex, newIndex);
126 pin(m_list.at(newIndex)->appId());
129void MockLauncherModel::pin(const QString &appId, int index)
131 int currentIndex = findApp(appId);
133 if (currentIndex >= 0) {
134 if (index == -1 || index == currentIndex) {
135 m_list.at(currentIndex)->setPinned(true);
136 QModelIndex modelIndex = this->index(currentIndex);
137 Q_EMIT dataChanged(modelIndex, modelIndex);
139 move(currentIndex, index);
142 beginInsertRows(QModelIndex(), index, index);
143 m_list.insert(index, new MockLauncherItem(appId,
147 m_list.at(index)->setPinned(true);
152void MockLauncherModel::requestRemove(const QString &appId)
154 int index = findApp(appId);
156 beginRemoveRows(QModelIndex(), index, 0);
157 m_list.takeAt(index)->deleteLater();
162void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
165 Q_UNUSED(actionIndex)
166 // Nothing to mock yet...
169int MockLauncherModel::findApp(const QString &appId)
171 for (int i = 0; i < m_list.count(); ++i) {
172 MockLauncherItem *item = m_list.at(i);
173 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