136161a282a039b60a62df4b481cb249120251f4
[staging/HomeScreen.git] / HomeScreen / src2 / applicationmodel.cpp
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "applicationmodel.h"
19 #include "appinfo.h"
20
21 #include <QtDBus/QDBusInterface>
22 #include <QtDBus/QDBusReply>
23
24 class ApplicationModel::Private
25 {
26 public:
27     Private(ApplicationModel *parent);
28
29 private:
30     ApplicationModel *q;
31 public:
32     QDBusInterface proxy;
33     QList<AppInfo> data;
34 };
35
36 ApplicationModel::Private::Private(ApplicationModel *parent)
37     : q(parent)
38     , proxy(QStringLiteral("org.agl.homescreenappframeworkbinder"), QStringLiteral("/AppFramework"), QStringLiteral("org.agl.appframework"), QDBusConnection::sessionBus())
39 {
40     QDBusReply<QList<AppInfo>> reply = proxy.call("getAvailableApps");
41     if (false)/*reply.isValid()) TODO: test for CES!  */ {
42         data = reply.value();
43     } else {
44         data.append(AppInfo(QStringLiteral("HVAC"), QStringLiteral("HVAC"), QStringLiteral("hvac@0.1")));
45         data.append(AppInfo(QStringLiteral("Navigation"), QStringLiteral("NAVIGATION"), QStringLiteral("navigation@0.1")));
46         data.append(AppInfo(QStringLiteral("Phone"), QStringLiteral("PHONE"), QStringLiteral("phone@0.1")));
47         data.append(AppInfo(QStringLiteral("Radio"), QStringLiteral("RADIO"), QStringLiteral("radio@0.1")));
48         data.append(AppInfo(QStringLiteral("Multimedia"), QStringLiteral("MULTIMEDIA"), QStringLiteral("mediaplayer@0.1")));
49         data.append(AppInfo(QStringLiteral("Connectivity"), QStringLiteral("CONNECTIVITY"), QStringLiteral("connectivity@0.1")));
50         data.append(AppInfo(QStringLiteral("Dashboard"), QStringLiteral("DASHBOARD"), QStringLiteral("dashboard@0.1")));
51         data.append(AppInfo(QStringLiteral("Settings"), QStringLiteral("SETTINGS"), QStringLiteral("settings@0.1")));
52         data.append(AppInfo(QStringLiteral("POI"), QStringLiteral("POINT OF\nINTEREST"), QStringLiteral("poi@0.1")));
53     }
54 }
55 void ApplicationModel::changeLanguage(const QString &lang)
56 { //todo: use QT translator instead of hardcoded strings.
57     if(lang == "fr") {
58         d->data[0].setName("CLIMATISATION");
59         d->data[1].setName("NAVIGATION");
60         d->data[2].setName("TÉLÉPHONE");
61         d->data[3].setName("RADIO");
62         d->data[4].setName("MULTIMÉDIA");
63         d->data[5].setName("CONNEXIONS");
64         d->data[6].setName("TABLEAU DE\nBORD");
65         d->data[7].setName("PARAMÈTRES");
66         d->data[8].setName("POINT D'INTÉRÊT");
67     } else {
68         d->data[0].setName("HVAC");
69         d->data[1].setName("NAVIGATION");
70         d->data[2].setName("PHONE");
71         d->data[3].setName("RADIO");
72         d->data[4].setName("MULTIMEDIA");
73         d->data[5].setName("CONNECTIVITY");
74         d->data[6].setName("DASHBOARD");
75         d->data[7].setName("SETTINGS");
76         d->data[8].setName("POINT OF\nINTEREST");
77     }
78 }
79
80 ApplicationModel::ApplicationModel(QObject *parent)
81     : QAbstractListModel(parent)
82     , d(new Private(this))
83 {
84     setObjectName("ApplicationModel");
85 }
86
87 ApplicationModel::~ApplicationModel()
88 {
89     delete d;
90 }
91
92 int ApplicationModel::rowCount(const QModelIndex &parent) const
93 {
94     if (parent.isValid())
95         return 0;
96
97     return d->data.count();
98 }
99
100 QVariant ApplicationModel::data(const QModelIndex &index, int role) const
101 {
102     QVariant ret;
103     if (!index.isValid())
104         return ret;
105
106     switch (role) {
107     case Qt::DecorationRole:
108         ret = d->data[index.row()].iconPath();
109         break;
110     case Qt::DisplayRole:
111         ret = d->data[index.row()].name();
112         break;
113     case Qt::UserRole:
114         ret = d->data[index.row()].id();
115         break;
116     default:
117         break;
118     }
119
120     return ret;
121 }
122
123 QHash<int, QByteArray> ApplicationModel::roleNames() const
124 {
125     QHash<int, QByteArray> roles;
126     roles[Qt::DecorationRole] = "icon";
127     roles[Qt::DisplayRole] = "name";
128     roles[Qt::UserRole] = "id";
129     return roles;
130 }