2
* Copyright (C) 2011 Canonical, Ltd.
5
* Michael Zanetti <michael.zanetti@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/>.
20
#include "launchermodel.h"
22
LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
24
// FIXME: Dummy data... Aggregate real data from backends
27
LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
29
item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
31
item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
33
item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
35
item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
37
item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
39
item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
41
item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
43
item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
45
item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
49
LauncherModel::~LauncherModel()
51
while (!m_list.empty()) {
52
m_list.takeFirst()->deleteLater();
56
int LauncherModel::rowCount(const QModelIndex &parent) const
59
return m_list.count();
62
QVariant LauncherModel::data(const QModelIndex &index, int role) const
64
LauncherItem *item = m_list.at(index.row());
71
return item->favorite();
77
LauncherItem *LauncherModel::get(int index) const
79
if (index < 0 || index >= m_list.count()) {
82
return m_list.at(index);
85
void LauncherModel::move(int oldIndex, int newIndex)
87
beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
88
m_list.move(oldIndex, newIndex);
92
QHash<int, QByteArray> LauncherModel::roleNames() const
94
QHash<int, QByteArray> roles;
95
roles.insert(RoleDesktopFile, "desktopFile");
96
roles.insert(RoleName, "name");
97
roles.insert(RoleIcon, "icon");
98
roles.insert(RoleFavorite, "favorite");
99
roles.insert(RoleRunning, "runnng");
104
LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
106
m_desktopFile(desktopFile),
114
QString LauncherItem::desktopFile() const
116
return m_desktopFile;
119
QString LauncherItem::name() const
124
QString LauncherItem::icon() const
129
bool LauncherItem::favorite() const
134
void LauncherItem::setFavorite(bool favorite)
136
if (m_favorite != favorite) {
137
m_favorite = favorite;
138
Q_EMIT favoriteChanged(m_favorite);
142
bool LauncherItem::running() const
147
void LauncherItem::setRunning(bool running)
149
if (m_running != running) {
151
Q_EMIT runningChanged(running);