on bb7eaf1 help sign in
unity8/tests/mocks/Unity/fake_launchermodel.cpp
150 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 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);
46LauncherModel::~LauncherModel()
48 while (!m_list.empty()) {
49 m_list.takeFirst()->deleteLater();
50 }
53int LauncherModel::rowCount(const QModelIndex &parent) const
55 Q_UNUSED(parent)
56 return m_list.count();
59QVariant LauncherModel::data(const QModelIndex &index, int role) const
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 }
71 return QVariant();
74LauncherItem *LauncherModel::get(int index) const
76 if (index < 0 || index >= m_list.count()) {
77 return 0;
78 }
79 return m_list.at(index);
82void LauncherModel::move(int oldIndex, int newIndex)
84 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
85 m_list.move(oldIndex, newIndex);
86 endMoveRows();
89QHash<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");
97 return roles;
101LauncherItem::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)
111QString LauncherItem::desktopFile() const
113 return m_desktopFile;
116QString LauncherItem::name() const
118 return m_name;
121QString LauncherItem::icon() const
123 return m_icon;
126bool LauncherItem::favorite() const
128 return m_favorite;
131void LauncherItem::setFavorite(bool favorite)
133 if (m_favorite != favorite) {
134 m_favorite = favorite;
135 Q_EMIT favoriteChanged(m_favorite);
136 }
139bool LauncherItem::running() const
141 return m_running;
144void LauncherItem::setRunning(bool running)
146 if (m_running != running) {
147 m_running = running;
148 Q_EMIT runningChanged(running);
149 }