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
LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
26
item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
28
item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
30
item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
32
item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
34
item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
36
item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
38
item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
40
item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
42
item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
46
LauncherModel::~LauncherModel()
48
while (!m_list.empty()) {
49
m_list.takeFirst()->deleteLater();
53
int LauncherModel::rowCount(const QModelIndex &parent) const
56
return m_list.count();
59
QVariant LauncherModel::data(const QModelIndex &index, int role) const
61
LauncherItem *item = m_list.at(index.row());
68
return item->favorite();
74
LauncherItem *LauncherModel::get(int index) const
76
if (index < 0 || index >= m_list.count()) {
79
return m_list.at(index);
82
void LauncherModel::move(int oldIndex, int newIndex)
84
beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
85
m_list.move(oldIndex, newIndex);
89
QHash<int, QByteArray> LauncherModel::roleNames() const
91
QHash<int, QByteArray> roles;
92
roles.insert(RoleDesktopFile, "desktopFile");
93
roles.insert(RoleName, "name");
94
roles.insert(RoleIcon, "icon");
95
roles.insert(RoleFavorite, "favorite");
96
roles.insert(RoleRunning, "runnng");
101
LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
103
m_desktopFile(desktopFile),
111
QString LauncherItem::desktopFile() const
113
return m_desktopFile;
116
QString LauncherItem::name() const
121
QString LauncherItem::icon() const
126
bool LauncherItem::favorite() const
131
void LauncherItem::setFavorite(bool favorite)
133
if (m_favorite != favorite) {
134
m_favorite = favorite;
135
Q_EMIT favoriteChanged(m_favorite);
139
bool LauncherItem::running() const
144
void LauncherItem::setRunning(bool running)
146
if (m_running != running) {
148
Q_EMIT runningChanged(running);