on 32f07dd help sign in
unity8/plugins/Unity/launchermodel.cpp
153 lines 4.2 kB history raw
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 */
20#include "launchermodel.h"
22LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
24 // FIXME: Dummy data... Aggregate real data from backends
26 // Fake favorites
27 LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
28 m_list.append(item);
29 item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
30 m_list.append(item);
31 item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
32 m_list.append(item);
33 item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
34 m_list.append(item);
35 item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
36 m_list.append(item);
37 item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
38 m_list.append(item);
39 item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
40 m_list.append(item);
41 item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
42 m_list.append(item);
43 item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
44 m_list.append(item);
45 item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
46 m_list.append(item);
49LauncherModel::~LauncherModel()
51 while (!m_list.empty()) {
52 m_list.takeFirst()->deleteLater();
53 }
56int LauncherModel::rowCount(const QModelIndex &parent) const
58 Q_UNUSED(parent)
59 return m_list.count();
62QVariant LauncherModel::data(const QModelIndex &index, int role) const
64 LauncherItem *item = m_list.at(index.row());
65 switch(role) {
66 case RoleName:
67 return item->name();
68 case RoleIcon:
69 return item->icon();
70 case RoleFavorite:
71 return item->favorite();
72 }
74 return QVariant();
77LauncherItem *LauncherModel::get(int index) const
79 if (index < 0 || index >= m_list.count()) {
80 return 0;
81 }
82 return m_list.at(index);
85void LauncherModel::move(int oldIndex, int newIndex)
87 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
88 m_list.move(oldIndex, newIndex);
89 endMoveRows();
92QHash<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");
100 return roles;
104LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
105 QObject(parent),
106 m_desktopFile(desktopFile),
107 m_name(name),
108 m_icon(icon),
109 m_favorite(false)
114QString LauncherItem::desktopFile() const
116 return m_desktopFile;
119QString LauncherItem::name() const
121 return m_name;
124QString LauncherItem::icon() const
126 return m_icon;
129bool LauncherItem::favorite() const
131 return m_favorite;
134void LauncherItem::setFavorite(bool favorite)
136 if (m_favorite != favorite) {
137 m_favorite = favorite;
138 Q_EMIT favoriteChanged(m_favorite);
139 }
142bool LauncherItem::running() const
144 return m_running;
147void LauncherItem::setRunning(bool running)
149 if (m_running != running) {
150 m_running = running;
151 Q_EMIT runningChanged(running);
152 }