aboutsummaryrefslogtreecommitdiffstats
path: root/launcher/src
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-05-28 14:02:08 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-05-28 14:02:08 +0800
commit3508d025b0046fffb337ffceb912947ef1dcf47d (patch)
treec2665aa357bda0132a6134621c9cacd0b2795200 /launcher/src
parent353da85004c72efb2bd6f117a15713b58e0df866 (diff)
registerShortcut
Change-Id: Ia05d26a3e14f6b35e53f70c116e5b422518883a4
Diffstat (limited to 'launcher/src')
-rw-r--r--launcher/src/homescreenhandler.cpp66
-rw-r--r--launcher/src/homescreenhandler.h5
-rw-r--r--launcher/src/main.cpp9
-rw-r--r--launcher/src/shortcutappmodel.cpp169
-rw-r--r--launcher/src/shortcutappmodel.h53
5 files changed, 300 insertions, 2 deletions
diff --git a/launcher/src/homescreenhandler.cpp b/launcher/src/homescreenhandler.cpp
index 240f5c8..2da71c8 100644
--- a/launcher/src/homescreenhandler.cpp
+++ b/launcher/src/homescreenhandler.cpp
@@ -18,8 +18,15 @@
#include <QFileInfo>
#include "homescreenhandler.h"
#include <functional>
+#include <QProcess>
+#include <dirent.h>
+#include <stdio.h>
#include "hmi-debug.h"
+#include "afm_user_daemon_proxy.h"
+extern org::AGL::afm::user *afm_user_daemon_proxy;
+
+#define BUF_SIZE 1024
void* HomescreenHandler::myThis = 0;
HomescreenHandler::HomescreenHandler(QObject *parent) :
@@ -110,6 +117,20 @@ void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm
}
}
});
+
+ mp_qhs->set_event_handler(QLibHomeScreen::Event_UpdateShortcut,[this](json_object *object){
+ HMI_DEBUG("Launcher","Surface launcher got Event_UpdateShortcut\n");
+ json_object *obj_p = json_object_object_get(object, "parameter");
+ json_object *obj_array = json_object_object_get(obj_p, "shortcut");
+ QStringList shortcut_list;
+ for(int i = 0; i < 3; i++)
+ {
+ shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_id"))));
+ shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_name"))));
+ }
+ HMI_DEBUG("Launcher","SEvent_UpdateShortcut id1 = %s", shortcut_list.at(2).toStdString().c_str());
+ emit updateShortcutList(shortcut_list);
+ });
}
void HomescreenHandler::tapShortcut(QString application_id)
@@ -144,6 +165,51 @@ void HomescreenHandler::onRep(struct json_object* reply_contents)
}
}
+void HomescreenHandler::hideWindow(QString application_id)
+{
+ mp_qhs->hideWindow(application_id.section('@', 0, 0).toStdString().c_str());
+}
+
+void HomescreenHandler::registerShortcut(QString shortcut_id, QString shortcut_name, QString position)
+{
+// struct json_object* j_obj = json_object_new_object();
+// struct json_object* val_id = json_object_new_string(shortcut_id.toStdString().c_str());
+// struct json_object* val_name = json_object_new_string(shortcut_name.toStdString().c_str());
+// struct json_object* val_position = json_object_new_string(position.toStdString().c_str());
+// json_object_object_add(j_obj, "shortcut_id", val_id);
+// json_object_object_add(j_obj, "shortcut_name", val_name);
+// json_object_object_add(j_obj, "position", val_position);
+
+ mp_qhs->registerShortcut(shortcut_id, shortcut_name, position);
+}
+
+int HomescreenHandler::uninstallApplication(QString application_id)
+{
+ int result = -1;
+ HMI_DEBUG("launcher","Application uninstall %s.", application_id.toStdString().c_str());
+
+ result = afm_user_daemon_proxy->uninstall(application_id).value().toInt();
+ HMI_DEBUG("launcher","ApplicationUninstall pid: %d.", result);
+
+// QProcess *process = new QProcess();
+// QString command = "/usr/bin/pkill " + application_id.section('@', 0, 0);
+// HMI_DEBUG("launcher", "command is %s", command.toStdString().c_str());
+// process->start(command);
+
+ return result;
+}
+
+void HomescreenHandler::sendAppToMeter(QString application_id)
+{
+ HMI_DEBUG("Launcher","sendAppToMeter %s", application_id.toStdString().c_str());
+ struct json_object* j_json = json_object_new_object();
+ struct json_object* value;
+ value = json_object_new_string("master.split.sub");
+ json_object_object_add(j_json, "area", value);
+
+ mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json);
+}
+
void HomescreenHandler::getRunnables(void)
{
mp_qhs->getRunnables();
diff --git a/launcher/src/homescreenhandler.h b/launcher/src/homescreenhandler.h
index 6f0602d..e612331 100644
--- a/launcher/src/homescreenhandler.h
+++ b/launcher/src/homescreenhandler.h
@@ -37,6 +37,10 @@ public:
Q_INVOKABLE void tapShortcut(QString application_id);
Q_INVOKABLE void getRunnables(void);
+ Q_INVOKABLE void hideWindow(QString application_id);
+ Q_INVOKABLE void registerShortcut(QString shortcut_id, QString shortcut_name, QString position);
+ Q_INVOKABLE int uninstallApplication(QString application_id);
+ Q_INVOKABLE void sendAppToMeter(QString application_id);
void onRep(struct json_object* reply_contents);
@@ -47,6 +51,7 @@ public:
signals:
void initAppList(QString data);
void appListUpdate(QStringList info);
+ void updateShortcutList(QStringList shortcut_list);
private:
QLibHomeScreen *mp_qhs;
diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp
index 15ce0f6..7181a78 100644
--- a/launcher/src/main.cpp
+++ b/launcher/src/main.cpp
@@ -30,6 +30,7 @@
#include "appinfo.h"
#include "afm_user_daemon_proxy.h"
#include "homescreenhandler.h"
+#include "shortcutappmodel.h"
#include "hmi-debug.h"
// XXX: We want this DBus connection to be shared across the different
@@ -88,6 +89,7 @@ int main(int argc, char *argv[])
// import C++ class to QML
qmlRegisterType<ApplicationModel>("AppModel", 1, 0, "ApplicationModel");
+ qmlRegisterType<ShortcutAppModel>("ShortcutAppModel", 1, 0, "ShortcutAppModel");
// DBus
qDBusRegisterMetaType<AppInfo>();
@@ -95,11 +97,12 @@ int main(int argc, char *argv[])
ApplicationLauncher *launcher = new ApplicationLauncher();
QLibWindowmanager* layoutHandler = new QLibWindowmanager();
+ ShortcutAppModel* shortcutAppModel = new ShortcutAppModel();
if(layoutHandler->init(port,token) != 0){
exit(EXIT_FAILURE);
}
- AGLScreenInfo screenInfo(layoutHandler->get_scale_factor());
+// AGLScreenInfo screenInfo(layoutHandler->get_scale_factor());
if (layoutHandler->requestSurface(myname) != 0) {
exit(EXIT_FAILURE);
@@ -121,6 +124,7 @@ int main(int argc, char *argv[])
});
HomescreenHandler* homescreenHandler = new HomescreenHandler();
+ QObject::connect(homescreenHandler, SIGNAL(updateShortcutList(QStringList)), shortcutAppModel, SLOT(shortcutUpdate(QStringList)));
homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, myname);
QUrl bindingAddress;
@@ -148,7 +152,8 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty(QStringLiteral("layoutHandler"), layoutHandler);
engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler);
engine.rootContext()->setContextProperty(QStringLiteral("launcher"), launcher);
- engine.rootContext()->setContextProperty(QStringLiteral("screenInfo"), &screenInfo);
+// engine.rootContext()->setContextProperty(QStringLiteral("screenInfo"), &screenInfo);
+ engine.rootContext()->setContextProperty(QStringLiteral("shortcutAppModel"), shortcutAppModel);
engine.load(QUrl(QStringLiteral("qrc:/Launcher.qml")));
homescreenHandler->getRunnables();
diff --git a/launcher/src/shortcutappmodel.cpp b/launcher/src/shortcutappmodel.cpp
new file mode 100644
index 0000000..0fd76b6
--- /dev/null
+++ b/launcher/src/shortcutappmodel.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "shortcutappmodel.h"
+#include "hmi-debug.h"
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonParseError>
+
+#define SHORTCUTKEY_PATH "/var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json"
+
+class ShortcutAppModel::Private
+{
+public:
+ Private();
+
+ QList<RegisterApp> data;
+};
+
+ShortcutAppModel::Private::Private()
+{
+}
+
+
+ShortcutAppModel::ShortcutAppModel(QObject *parent)
+ : QAbstractListModel(parent)
+ , d(new Private())
+{
+ init();
+// getAppQueue();
+}
+
+ShortcutAppModel::~ShortcutAppModel()
+{
+ delete this->d;
+}
+void ShortcutAppModel::init()
+{
+ RegisterApp temp;
+ for(int i = 0; i < 3; i++) {
+ temp.id = "video@0.1";
+ temp.name = "video";
+ temp.icon = getIconPath(temp.id);
+ if (temp.icon == "") {
+ temp.isBlank = true;
+ } else {
+ temp.isBlank = false;
+ }
+ d->data.append(temp);
+ }
+}
+
+int ShortcutAppModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+
+ return this->d->data.count();
+}
+
+QVariant ShortcutAppModel::data(const QModelIndex &index, int role) const
+{
+ QVariant ret;
+ if (!index.isValid())
+ return ret;
+
+ switch (role) {
+ case Qt::DecorationRole:
+ ret = this->d->data[index.row()].icon;
+ break;
+ case Qt::DisplayRole:
+ ret = this->d->data[index.row()].name;
+ break;
+ case Qt::UserRole:
+ ret = this->d->data[index.row()].id;
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+QHash<int, QByteArray> ShortcutAppModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[Qt::DecorationRole] = "icon";
+ roles[Qt::DisplayRole] = "name";
+ roles[Qt::UserRole] = "id";
+ return roles;
+}
+
+void ShortcutAppModel::shortcutUpdate(QStringList shortcut_list)
+{
+ HMI_DEBUG("Launcher", "ShortcutAppModel::shortcutUpdate id1=%s", shortcut_list.at(1).toStdString().c_str());
+ RegisterApp temp;
+ for(int i = 0; i < d->data.size(); i++) {
+ temp.id = shortcut_list.at(2 * i);
+ temp.name = shortcut_list.at(2 * i + 1);
+ temp.icon = getIconPath(temp.id);
+ if (temp.icon == "") {
+ temp.isBlank = true;
+ } else {
+ temp.isBlank = false;
+ }
+ d->data.replace(i, temp);
+ }
+ emit updateShortcut();
+}
+
+QString ShortcutAppModel::getId(int index) const
+{
+ return d->data.at(index).id;
+}
+
+QString ShortcutAppModel::getName(int index) const
+{
+ return d->data.at(index).name;
+}
+
+QString ShortcutAppModel::getIcon(int index) const
+{
+ return d->data.at(index).icon;
+}
+
+bool ShortcutAppModel::isBlank(int index) const
+{
+ return d->data.at(index).isBlank;
+}
+
+QString ShortcutAppModel::getIconPath(QString id)
+{
+ QString name = id.section('@', 0, 0);
+ QString version = id.section('@', 1, 1);
+ QString boardIconPath = "/var/local/lib/afm/applications/" + name + "/" + version + "/icon.svg";
+ QString appIconPath = ":/images/TopShortcut/" + name + ".svg";
+ if (QFile::exists(boardIconPath)) {
+ return "file://" + boardIconPath;
+ } else if (QFile::exists(appIconPath)) {
+ return appIconPath.section('/', 1, -1);
+ }
+ return "";
+}
+
+void ShortcutAppModel::setAppQueuePoint(QString id, QString name)
+{
+ app.id = id;
+ app.icon = getIconPath(app.id);
+ if (app.icon == "") {
+ app.isBlank = true;
+ } else {
+ app.isBlank = false;
+ }
+ app.name = name;
+ d->data.append(app);
+}
diff --git a/launcher/src/shortcutappmodel.h b/launcher/src/shortcutappmodel.h
new file mode 100644
index 0000000..e11e121
--- /dev/null
+++ b/launcher/src/shortcutappmodel.h
@@ -0,0 +1,53 @@
+#ifndef SHORTCUTAPPMODEL_H
+#define SHORTCUTAPPMODEL_H
+
+#include <QtCore/QAbstractListModel>
+#include <QXmlStreamReader>
+#include <QXmlStreamWriter>
+#include <QFile>
+#include <QProcess>
+#include <QThread>
+
+struct RegisterApp {
+ QString id;
+ QString name;
+ QString icon;
+ bool isBlank;
+};
+
+class ShortcutAppModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ explicit ShortcutAppModel(QObject *parent = nullptr);
+ ~ShortcutAppModel();
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ QHash<int, QByteArray> roleNames() const override;
+
+ Q_INVOKABLE QString getId(int index) const;
+ Q_INVOKABLE QString getName(int index) const;
+ Q_INVOKABLE QString getIcon(int index) const;
+ Q_INVOKABLE bool isBlank(int index) const;
+
+public slots:
+ void shortcutUpdate(QStringList shortcut_list);
+
+signals:
+ void updateShortcut();
+
+private:
+ void init();
+ void getAppQueue();
+ void setAppQueuePoint(QString id, QString name);
+ QString getIconPath(QString id);
+
+ class Private;
+ Private *d;
+ RegisterApp app;
+
+};
+
+#endif // SHORTCUTAPPMODEL_H