~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to plugins/Unity/launchermodel.cpp

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    // FIXME: Dummy data... Aggregate real data from backends
 
25
 
 
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);
 
47
}
 
48
 
 
49
LauncherModel::~LauncherModel()
 
50
{
 
51
    while (!m_list.empty()) {
 
52
        m_list.takeFirst()->deleteLater();
 
53
    }
 
54
}
 
55
 
 
56
int LauncherModel::rowCount(const QModelIndex &parent) const
 
57
{
 
58
    Q_UNUSED(parent)
 
59
    return m_list.count();
 
60
}
 
61
 
 
62
QVariant LauncherModel::data(const QModelIndex &index, int role) const
 
63
{
 
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
    }
 
73
 
 
74
    return QVariant();
 
75
}
 
76
 
 
77
LauncherItem *LauncherModel::get(int index) const
 
78
{
 
79
    if (index < 0 || index >= m_list.count()) {
 
80
        return 0;
 
81
    }
 
82
    return m_list.at(index);
 
83
}
 
84
 
 
85
void LauncherModel::move(int oldIndex, int newIndex)
 
86
{
 
87
    beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
 
88
    m_list.move(oldIndex, newIndex);
 
89
    endMoveRows();
 
90
}
 
91
 
 
92
QHash<int, QByteArray> LauncherModel::roleNames() const
 
93
{
 
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;
 
101
}
 
102
 
 
103
 
 
104
LauncherItem::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)
 
110
{
 
111
 
 
112
}
 
113
 
 
114
QString LauncherItem::desktopFile() const
 
115
{
 
116
    return m_desktopFile;
 
117
}
 
118
 
 
119
QString LauncherItem::name() const
 
120
{
 
121
    return m_name;
 
122
}
 
123
 
 
124
QString LauncherItem::icon() const
 
125
{
 
126
    return m_icon;
 
127
}
 
128
 
 
129
bool LauncherItem::favorite() const
 
130
{
 
131
    return m_favorite;
 
132
}
 
133
 
 
134
void LauncherItem::setFavorite(bool favorite)
 
135
{
 
136
    if (m_favorite != favorite) {
 
137
        m_favorite = favorite;
 
138
        Q_EMIT favoriteChanged(m_favorite);
 
139
    }
 
140
}
 
141
 
 
142
bool LauncherItem::running() const
 
143
{
 
144
    return m_running;
 
145
}
 
146
 
 
147
void LauncherItem::setRunning(bool running)
 
148
{
 
149
    if (m_running != running) {
 
150
        m_running = running;
 
151
        Q_EMIT runningChanged(running);
 
152
    }
 
153
}