Rework to use launcher wrapper from libqtappfw
[apps/launcher.git] / launcher / src / applicationmodel.cpp
index 261e43e..d54d171 100644 (file)
@@ -1,32 +1,20 @@
+// SPDX-License-Identifier: Apache-2.0
 /*
  * Copyright (C) 2016 The Qt Company Ltd.
  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
  * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright (C) 2022 Konsulko Group
  */
 
 #include "applicationmodel.h"
 #include "appinfo.h"
 
-#include "hmi-debug.h"
-
-#include <QtDBus/QDBusInterface>
-#include <QtDBus/QDBusReply>
-
-#include "afm_user_daemon_proxy.h"
+#include <QtCore/QFile>
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonArray>
 
-extern org::AGL::afm::user *afm_user_daemon_proxy;
+#include "hmi-debug.h"
 
 class ApplicationModel::Private
 {
@@ -42,13 +30,10 @@ public:
 namespace {
     QString get_icon_name(QJsonObject const &i)
     {
-        QString icon = i["name"].toString().toLower();
-
-        if ( !QFile::exists(QString(":/images/%1_active.svg").arg(icon)) ||
-             !QFile::exists(QString(":/images/%1_inactive.svg").arg(icon)) )
-        {
+        QString icon = i["icon"].toString();
+        fprintf(stderr, "Looking for icon %s\n", icon.toLocal8Bit().data());
+        if ( !QFile::exists(icon) )
             icon = "blank";
-        }
         return icon;
     }
 }
@@ -65,9 +50,13 @@ void ApplicationModel::Private::addApp(QString icon, QString name, QString id)
             return;
     }
 
-    QString _icon = name.toLower();
-    if ( !QFile::exists(QString(":/images/%1_active.svg").arg(_icon)) ||
-         !QFile::exists(QString(":/images/%1_inactive.svg").arg(_icon)) )
+    QString _icon;
+    if ( QFile::exists(icon) )
+    {
+        _icon = QString("file:%1").arg(icon);
+        fprintf(stderr, "using icon '%s'\n", _icon.toLocal8Bit().data());
+    }
+    else
     {
         _icon = "blank";
     }
@@ -198,18 +187,13 @@ void ApplicationModel::updateApplist(QStringList info)
     endResetModel();
 }
 
-void ApplicationModel::initAppList(QString data)
+void ApplicationModel::initAppList(QList<QMap<QString, QString>> &apps)
 {
     HMI_DEBUG("launcher","init application list.");
     beginResetModel();
-    QJsonDocument japps = QJsonDocument::fromJson(data.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);
-
-        d->addApp(icon, name, id);
+    qDebug() << "ApplicationModel::initAppList: got " << apps.size() << " apps";
+    for (int i = 0; i < apps.size(); i++) {
+        d->addApp(apps[i]["icon_path"], apps[i]["name"], apps[i]["id"]);
     }
     endResetModel();
 }