@@ -1,150 +0,0 @@
1−/*
2− * Copyright (C) 2011 Canonical, Ltd.
3− *
4− * Authors:
5− * Michael Zanetti <michael.zanetti@canonical.com>
6− *
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.
10− *
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.
15− *
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/>.
18− */
19−
20−#include "launchermodel.h"
21−
22−LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
23−{
24− LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
25− m_list.append(item);
26− item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
27− m_list.append(item);
28− item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
29− m_list.append(item);
30− item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
31− m_list.append(item);
32− item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
33− m_list.append(item);
34− item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
35− m_list.append(item);
36− item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
37− m_list.append(item);
38− item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
39− m_list.append(item);
40− item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
41− m_list.append(item);
42− item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
43− m_list.append(item);
44−}
45−
46−LauncherModel::~LauncherModel()
47−{
48− while (!m_list.empty()) {
49− m_list.takeFirst()->deleteLater();
50− }
51−}
52−
53−int LauncherModel::rowCount(const QModelIndex &parent) const
54−{
55− Q_UNUSED(parent)
56− return m_list.count();
57−}
58−
59−QVariant LauncherModel::data(const QModelIndex &index, int role) const
60−{
61− LauncherItem *item = m_list.at(index.row());
62− switch(role) {
63− case RoleName:
64− return item->name();
65− case RoleIcon:
66− return item->icon();
67− case RoleFavorite:
68− return item->favorite();
69− }
70−
71− return QVariant();
72−}
73−
74−LauncherItem *LauncherModel::get(int index) const
75−{
76− if (index < 0 || index >= m_list.count()) {
77− return 0;
78− }
79− return m_list.at(index);
80−}
81−
82−void LauncherModel::move(int oldIndex, int newIndex)
83−{
84− beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
85− m_list.move(oldIndex, newIndex);
86− endMoveRows();
87−}
88−
89−QHash<int, QByteArray> LauncherModel::roleNames() const
90−{
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");
97− return roles;
98−}
99−
100−
101−LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
102− QObject(parent),
103− m_desktopFile(desktopFile),
104− m_name(name),
105− m_icon(icon),
106− m_favorite(false)
107−{
108−
109−}
110−
111−QString LauncherItem::desktopFile() const
112−{
113− return m_desktopFile;
114−}
115−
116−QString LauncherItem::name() const
117−{
118− return m_name;
119−}
120−
121−QString LauncherItem::icon() const
122−{
123− return m_icon;
124−}
125−
126−bool LauncherItem::favorite() const
127−{
128− return m_favorite;
129−}
130−
131−void LauncherItem::setFavorite(bool favorite)
132−{
133− if (m_favorite != favorite) {
134− m_favorite = favorite;
135− Q_EMIT favoriteChanged(m_favorite);
136− }
137−}
138−
139−bool LauncherItem::running() const
140−{
141− return m_running;
142−}
143−
144−void LauncherItem::setRunning(bool running)
145−{
146− if (m_running != running) {
147− m_running = running;
148− Q_EMIT runningChanged(running);
149− }
150−}