2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "applicationmodel.h"
21 #include <QtDBus/QDBusInterface>
22 #include <QtDBus/QDBusReply>
24 class ApplicationModel::Private
27 Private(ApplicationModel *parent);
28 QList<QList<int> > orders;
29 QList<AppInfo> originalData;
37 ApplicationModel::Private::Private(ApplicationModel *parent)
39 , proxy(QStringLiteral("org.agl.homescreenappframeworkbinder"), QStringLiteral("/AppFramework"), QStringLiteral("org.agl.appframework"), QDBusConnection::sessionBus())
41 QDBusReply<QList<AppInfo>> reply = proxy.call("getAvailableApps");
42 if (false)/*reply.isValid()) TODO: test for CES! */ {
45 data.append(AppInfo(QStringLiteral("HVAC"), QStringLiteral("HVAC"), QStringLiteral("hvac@0.1")));
46 data.append(AppInfo(QStringLiteral("Navigation"), QStringLiteral("NAVIGATION"), QStringLiteral("navigation@0.1")));
47 data.append(AppInfo(QStringLiteral("Phone"), QStringLiteral("PHONE"), QStringLiteral("phone@0.1")));
48 data.append(AppInfo(QStringLiteral("Radio"), QStringLiteral("RADIO"), QStringLiteral("radio@0.1")));
49 data.append(AppInfo(QStringLiteral("Multimedia"), QStringLiteral("MULTIMEDIA"), QStringLiteral("mediaplayer@0.1")));
50 data.append(AppInfo(QStringLiteral("Mixer"), QStringLiteral("MIXER"), QStringLiteral("mixer@0.1")));
51 data.append(AppInfo(QStringLiteral("Dashboard"), QStringLiteral("DASHBOARD"), QStringLiteral("dashboard@0.1")));
52 data.append(AppInfo(QStringLiteral("Settings"), QStringLiteral("SETTINGS"), QStringLiteral("settings@0.1")));
53 data.append(AppInfo(QStringLiteral("POI"), QStringLiteral("POINT OF\nINTEREST"), QStringLiteral("poi@0.1")));
57 o << 5 << 4 << 3 << 7 << 8 << 0 << 2 << 1 << 6;
60 o << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 ;
63 o << 3 << 8 << 1 << 0 << 2 << 7 << 5 << 4 << 6;
66 o << 2 << 7 << 3 << 8 << 4 << 0 << 1 << 5 << 6;
69 o << 2 << 7 << 3 << 8 << 4 << 0 << 1 << 5 << 6;
72 o << 6 << 0 << 2 << 1 << 7 << 3 << 5 << 4 << 8;
75 void ApplicationModel::changeOrder(const int &hash)
78 d->data = d->originalData;
81 int order = qAbs(hash) % 7;
82 QList<int> o = d->orders.at(order);
83 QList<AppInfo> newData;
84 for(int i = 0; i < o.size(); ++i) {
85 newData.append(d->originalData.at(o.at(i)));
90 void ApplicationModel::changeLanguage(const QString &lang)
91 { //todo: use QT translator instead of hardcoded strings.
93 d->originalData[0].setName("CLIMATISATION");
94 d->originalData[1].setName("NAVIGATION");
95 d->originalData[2].setName("TÉLÉPHONE");
96 d->originalData[3].setName("RADIO");
97 d->originalData[4].setName("MULTIMÉDIA");
98 d->originalData[5].setName("MIXER");
99 d->originalData[6].setName("TABLEAU DE\nBORD");
100 d->originalData[7].setName("PARAMÈTRES");
101 d->originalData[8].setName("POINT D'INTÉRÊT");
103 d->originalData[0].setName("HVAC");
104 d->originalData[1].setName("NAVIGATION");
105 d->originalData[2].setName("PHONE");
106 d->originalData[3].setName("RADIO");
107 d->originalData[4].setName("MULTIMEDIA");
108 d->originalData[5].setName("MIXER");
109 d->originalData[6].setName("DASHBOARD");
110 d->originalData[7].setName("SETTINGS");
111 d->originalData[8].setName("POINT OF\nINTEREST");
115 ApplicationModel::ApplicationModel(QObject *parent)
116 : QAbstractListModel(parent)
117 , d(new Private(this))
119 setObjectName("ApplicationModel");
122 ApplicationModel::~ApplicationModel()
127 int ApplicationModel::rowCount(const QModelIndex &parent) const
129 if (parent.isValid())
132 return d->data.count();
135 QVariant ApplicationModel::data(const QModelIndex &index, int role) const
138 if (!index.isValid())
142 case Qt::DecorationRole:
143 ret = d->data[index.row()].iconPath();
145 case Qt::DisplayRole:
146 ret = d->data[index.row()].name();
149 ret = d->data[index.row()].id();
158 QHash<int, QByteArray> ApplicationModel::roleNames() const
160 QHash<int, QByteArray> roles;
161 roles[Qt::DecorationRole] = "icon";
162 roles[Qt::DisplayRole] = "name";
163 roles[Qt::UserRole] = "id";