aboutsummaryrefslogtreecommitdiffstats
path: root/launcher/src
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-05-20 16:16:18 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-05-20 16:16:18 +0900
commit39de6fae412ddb327d7ba0c3545a2445e94fbd9e (patch)
tree5c5d78e462655aa73196ac9b07cdd009ab9543ce /launcher/src
parent1046e52b2936b64d7b112e1408136ad0bec0464b (diff)
add als2019 source codesandbox/zheng_wenlong/als2019
Diffstat (limited to 'launcher/src')
-rw-r--r--launcher/src/applicationmodel.cpp3
-rw-r--r--launcher/src/homescreenhandler.cpp52
-rw-r--r--launcher/src/homescreenhandler.h4
-rw-r--r--launcher/src/main.cpp4
-rw-r--r--launcher/src/shortcutappmodel.cpp187
-rw-r--r--launcher/src/shortcutappmodel.h52
6 files changed, 300 insertions, 2 deletions
diff --git a/launcher/src/applicationmodel.cpp b/launcher/src/applicationmodel.cpp
index 261e43e..cf67617 100644
--- a/launcher/src/applicationmodel.cpp
+++ b/launcher/src/applicationmodel.cpp
@@ -190,8 +190,7 @@ void ApplicationModel::updateApplist(QStringList info)
beginResetModel();
if(icon == "") { // uninstall
d->removeApp(id);
- }
- else {
+ } else {
// new app
d->addApp(icon, name, id);
}
diff --git a/launcher/src/homescreenhandler.cpp b/launcher/src/homescreenhandler.cpp
index 9f15b6a..99ced2e 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) :
@@ -145,6 +152,51 @@ void HomescreenHandler::onRep(struct json_object* reply_contents)
}
}
+void HomescreenHandler::hideWindow(QString application_id)
+{
+ mp_hs->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_hs->registerShortcut(j_obj);
+}
+
+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_hs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json);
+}
+
void HomescreenHandler::getRunnables(void)
{
mp_hs->getRunnables();
diff --git a/launcher/src/homescreenhandler.h b/launcher/src/homescreenhandler.h
index 09b6848..8e5bbd1 100644
--- a/launcher/src/homescreenhandler.h
+++ b/launcher/src/homescreenhandler.h
@@ -36,6 +36,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);
diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp
index e56ff5a..fc28468 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,6 +97,7 @@ 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);
}
@@ -149,6 +152,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler);
engine.rootContext()->setContextProperty(QStringLiteral("launcher"), launcher);
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..bbfb74c
--- /dev/null
+++ b/launcher/src/shortcutappmodel.cpp
@@ -0,0 +1,187 @@
+/*
+ * 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"
+
+class ShortcutAppModel::Private
+{
+public:
+ Private();
+
+ QList<RegisterApp> data;
+};
+
+ShortcutAppModel::Private::Private()
+{
+}
+
+
+ShortcutAppModel::ShortcutAppModel(QObject *parent)
+ : QAbstractListModel(parent)
+ , d(new Private())
+{
+ getAppQueue();
+}
+
+ShortcutAppModel::~ShortcutAppModel()
+{
+ delete this->d;
+}
+
+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::changeShortcut(QString id, QString name, QString position)
+{
+ for(int i = 0; i < d->data.size(); i++) {
+ if(id == d->data.at(i).id) {
+ return;
+ }
+ }
+ d->data.removeAt(position.toInt());
+ HMI_DEBUG("launcher","parameter.id========%s", id.toStdString().c_str());
+ HMI_DEBUG("launcher","parameter.name========%s", name.toStdString().c_str());
+ HMI_DEBUG("launcher","parameter.position========%s", position.toStdString().c_str());
+
+ RegisterApp temp;
+ temp.id = id;
+ temp.name = name;
+ temp.icon = temp.icon = getIconPath(temp.id);
+ if (temp.icon == "") {
+ temp.isBlank = true;
+ } else {
+ temp.isBlank = false;
+ }
+
+ d->data.insert(position.toInt(), 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)) {
+ HMI_DEBUG("launcher", "boardIconPath===%s", boardIconPath.toStdString().c_str());
+ return "file://" + boardIconPath;
+ } else if (QFile::exists(appIconPath)) {
+ HMI_DEBUG("launcher", "appIconPath===%s", appIconPath.toStdString().c_str());
+ return appIconPath.section('/', 1, -1);
+ }
+ return "";
+}
+
+void ShortcutAppModel::getAppQueue()
+{
+ QFile file("/home/0/app-data/homescreen/registeredApp.xml");
+ if(file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ QByteArray line = file.readLine();
+ QString str(line);
+ if(str == "") {
+ file.close();
+
+ }
+ QXmlStreamReader reader(&file);
+ bool is_first = true;
+ while(!reader.atEnd()) {
+ if(reader.isStartElement())
+ {
+ if(reader.name() == "id")
+ {
+ app.id = reader.readElementText();
+ app.icon = getIconPath(app.id);
+ if (app.icon == "") {
+ app.isBlank = true;
+ } else {
+ app.isBlank = false;
+ }
+ } else if(reader.name() == "name") {
+ app.name = reader.readElementText();
+ }
+ } else if(reader.isEndElement() && reader.name() == "app") {
+ if(is_first) {
+ is_first = false;
+ } else {
+ d->data.append(app);
+ }
+ }
+ reader.readNext();
+ }
+ } else {
+ HMI_ERROR("HomeScreen", "registeredApp.xml file open failed");
+ }
+ file.close();
+}
diff --git a/launcher/src/shortcutappmodel.h b/launcher/src/shortcutappmodel.h
new file mode 100644
index 0000000..3a2c313
--- /dev/null
+++ b/launcher/src/shortcutappmodel.h
@@ -0,0 +1,52 @@
+#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 changeShortcut(QString id, QString name, QString position);
+
+signals:
+ void updateShortcut();
+
+private:
+ void getAppQueue();
+// bool confirmIconImage(QString id);
+ QString getIconPath(QString id);
+
+ class Private;
+ Private *d;
+ RegisterApp app;
+
+};
+
+#endif // SHORTCUTAPPMODEL_H