on 8237bc2 help sign in
unity8/plugins/Unity/Launcher/launchermodel.cpp
102 lines 3.4 kB history raw
1/*
2 * Copyright (C) 2013 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"
21#include "launcheritem.h"
23LauncherModel::LauncherModel(QObject *parent): LauncherModelInterface(parent)
25 // FIXME: Dummy data... Aggregate real data from backends
27 // Fake favorites
28 LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
29 m_list.append(item);
30 item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
31 m_list.append(item);
32 item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
33 m_list.append(item);
34 item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
35 m_list.append(item);
36 item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
37 m_list.append(item);
38 item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
39 m_list.append(item);
40 item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
41 m_list.append(item);
42 item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
43 m_list.append(item);
44 item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
45 m_list.append(item);
46 item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
47 m_list.append(item);
50LauncherModel::~LauncherModel()
52 while (!m_list.empty()) {
53 m_list.takeFirst()->deleteLater();
54 }
57int LauncherModel::rowCount(const QModelIndex &parent) const
59 Q_UNUSED(parent)
60 return m_list.count();
63QVariant LauncherModel::data(const QModelIndex &index, int role) const
65 LauncherItem *item = m_list.at(index.row());
66 switch(role) {
67 case RoleName:
68 return item->name();
69 case RoleIcon:
70 return item->icon();
71 case RoleFavorite:
72 return item->favorite();
73 }
75 return QVariant();
78unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
80 if (index < 0 || index >= m_list.count()) {
81 return 0;
82 }
83 return m_list.at(index);
86void LauncherModel::move(int oldIndex, int newIndex)
88 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
89 m_list.move(oldIndex, newIndex);
90 endMoveRows();
93QHash<int, QByteArray> LauncherModel::roleNames() const
95 QHash<int, QByteArray> roles;
96 roles.insert(RoleDesktopFile, "desktopFile");
97 roles.insert(RoleName, "name");
98 roles.insert(RoleIcon, "icon");
99 roles.insert(RoleFavorite, "favorite");
100 roles.insert(RoleRunning, "runnng");
101 return roles;