#include "applicationmodel.h"
#include "appinfo.h"
+#include <QtCore/QDebug>
+
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
+#include "afm_user_daemon_proxy.h"
+
+extern org::AGL::afm::user *afm_user_daemon_proxy;
+
class ApplicationModel::Private
{
public:
- Private(ApplicationModel *parent);
+ Private();
-private:
- ApplicationModel *q;
-public:
- QDBusInterface proxy;
QList<AppInfo> data;
};
-ApplicationModel::Private::Private(ApplicationModel *parent)
- : q(parent)
- , proxy(QStringLiteral("org.agl.homescreenappframeworkbinder"), QStringLiteral("/AppFramework"), QStringLiteral("org.agl.appframework"), QDBusConnection::sessionBus())
+namespace {
+ QString get_icon_name(QJsonObject const &i)
+ {
+ QString icon = i["id"].toString().split("@").front();
+ if (icon == "hvac" || icon == "poi") {
+ icon = icon.toUpper();
+ } else if (icon == "mediaplayer") {
+ icon = "Multimedia";
+ } else {
+ icon[0] = icon[0].toUpper();
+ }
+ return icon;
+ }
+}
+
+ApplicationModel::Private::Private()
{
- QDBusReply<QList<AppInfo>> reply = proxy.call("getAvailableApps");
- if (false)/*reply.isValid()) TODO: test for CES! */ {
- data = reply.value();
- } else {
- data.append(AppInfo(QStringLiteral("HVAC"), QStringLiteral("HVAC"), QStringLiteral("hvac@0.1")));
- data.append(AppInfo(QStringLiteral("Navigation"), QStringLiteral("NAVIGATION"), QStringLiteral("navigation@0.1")));
- data.append(AppInfo(QStringLiteral("Phone"), QStringLiteral("PHONE"), QStringLiteral("phone@0.1")));
- data.append(AppInfo(QStringLiteral("Radio"), QStringLiteral("RADIO"), QStringLiteral("radio@0.1")));
- data.append(AppInfo(QStringLiteral("Multimedia"), QStringLiteral("MULTIMEDIA"), QStringLiteral("mediaplayer@0.1")));
- data.append(AppInfo(QStringLiteral("Mixer"), QStringLiteral("MIXER"), QStringLiteral("mixer@0.1")));
- data.append(AppInfo(QStringLiteral("Dashboard"), QStringLiteral("DASHBOARD"), QStringLiteral("dashboard@0.1")));
- data.append(AppInfo(QStringLiteral("Settings"), QStringLiteral("SETTINGS"), QStringLiteral("settings@0.1")));
- data.append(AppInfo(QStringLiteral("POI"), QStringLiteral("POINT OF\nINTEREST"), QStringLiteral("poi@0.1")));
+ QString apps = afm_user_daemon_proxy->runnables(QStringLiteral(""));
+ QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8());
+ for (auto const &app : japps.array()) {
+ QJsonObject const &jso = app.toObject();
+ auto const name = jso["name"].toString();
+ auto const id = jso["id"].toString();
+ auto const icon = get_icon_name(jso);
+ this->data.append(AppInfo(icon, name, id));
+ qDebug() << "name:" << name << "icon:" << icon << "id:" << id;
}
}
ApplicationModel::ApplicationModel(QObject *parent)
: QAbstractListModel(parent)
- , d(new Private(this))
+ , d(new Private())
{
}
ApplicationModel::~ApplicationModel()
{
- delete d;
+ delete this->d;
}
int ApplicationModel::rowCount(const QModelIndex &parent) const
if (parent.isValid())
return 0;
- return d->data.count();
+ return this->d->data.count();
}
QVariant ApplicationModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::DecorationRole:
- ret = d->data[index.row()].iconPath();
+ ret = this->d->data[index.row()].iconPath();
break;
case Qt::DisplayRole:
- ret = d->data[index.row()].name();
+ ret = this->d->data[index.row()].name();
break;
case Qt::UserRole:
- ret = d->data[index.row()].id();
+ ret = this->d->data[index.row()].id();
break;
default:
break;
roles[Qt::UserRole] = "id";
return roles;
}
+
+QString ApplicationModel::id(int i) const
+{
+ return data(index(i), Qt::UserRole).toString();
+}
+
+void ApplicationModel::move(int from, int to)
+{
+ QModelIndex parent;
+ if (to < 0 || to > rowCount()) return;
+ if (from < to) {
+ if (!beginMoveRows(parent, from, from, parent, to + 1)) {
+ qDebug() << from << to << false;
+ return;
+ }
+ d->data.move(from, to);
+ endMoveRows();
+ } else if (from > to) {
+ if (!beginMoveRows(parent, from, from, parent, to)) {
+ qDebug() << from << to << false;
+ return;
+ }
+ d->data.move(from, to);
+ endMoveRows();
+ } else {
+ qDebug() << from << to << false;
+ }
+}