2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3 * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION
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.
19 #include "homescreenhandler.h"
24 #include "hmi-debug.h"
25 #include "afm_user_daemon_proxy.h"
27 extern org::AGL::afm::user *afm_user_daemon_proxy;
30 void* HomescreenHandler::myThis = 0;
32 HomescreenHandler::HomescreenHandler(QObject *parent) :
38 HomescreenHandler::~HomescreenHandler()
45 void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname)
51 mp_qhs = new QLibHomeScreen();
52 mp_qhs->init(port, token);
53 mp_qhs->registerCallback(nullptr, HomescreenHandler::onRep_static);
55 mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowWindow,[this](json_object *object){
56 HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n");
57 mp_qwm->activateWindow(m_myname);
60 mp_qhs->set_event_handler(QLibHomeScreen::Event_AppListChanged,[this](json_object *object){
61 HMI_DEBUG("Launcher","laucher: appListChanged [%s]\n", json_object_to_json_string(object));
63 struct json_object *obj_param, *obj_oper, *obj_data;
64 if(json_object_object_get_ex(object, "parameter", &obj_param)
65 && json_object_object_get_ex(obj_param, "operation", &obj_oper)
66 && json_object_object_get_ex(obj_param, "data", &obj_data)) {
67 QString oper = json_object_get_string(obj_oper);
68 if(oper == "uninstall") {
69 /* { "application_id": "launcher",
70 * "type": "application-list-changed",
72 * "operation": "uninstall",
73 * "data": "onstestapp@0.1"
76 QString id = json_object_get_string(obj_data);
79 info << "" << "" << id;
80 emit appListUpdate(info);
82 else if(oper == "install") {
83 /* { "application_id": "launcher",
84 * "type": "application-list-changed",
86 * "operation": "install",
88 * "description":"This is a demo onstestapp application",
89 * "name": "onstestapp",
91 * "id": "onstestapp@0.1",
97 * "icon": "\/var\/local\/lib\/afm\/applications\/onstestapp\/0.1\/icon.svg",
102 struct json_object *obj_icon, *obj_name, *obj_id;
103 if(json_object_object_get_ex(obj_data, "icon", &obj_icon)
104 && json_object_object_get_ex(obj_data, "name", &obj_name)
105 && json_object_object_get_ex(obj_data, "id", &obj_id)) {
106 QString icon = json_object_get_string(obj_icon);
107 QString name = json_object_get_string(obj_name);
108 QString id = json_object_get_string(obj_id);
111 info << icon << name << id;
112 emit appListUpdate(info);
116 HMI_ERROR("Launcher","error operation.\n");
121 mp_qhs->set_event_handler(QLibHomeScreen::Event_UpdateShortcut,[this](json_object *object){
122 HMI_DEBUG("Launcher","Surface launcher got Event_UpdateShortcut\n");
123 json_object *obj_p = json_object_object_get(object, "parameter");
124 json_object *obj_array = json_object_object_get(obj_p, "shortcut");
125 QStringList shortcut_list;
126 for(int i = 0; i < 3; i++)
128 shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_id"))));
129 shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_name"))));
131 HMI_DEBUG("Launcher","SEvent_UpdateShortcut id1 = %s", shortcut_list.at(2).toStdString().c_str());
132 emit updateShortcutList(shortcut_list);
136 void HomescreenHandler::tapShortcut(QString application_id)
138 HMI_DEBUG("Launcher","tapShortcut %s", application_id.toStdString().c_str());
139 struct json_object* j_json = json_object_new_object();
140 struct json_object* value;
141 value = json_object_new_string("normal.full");
142 json_object_object_add(j_json, "area", value);
144 mp_qhs->showWindow(application_id.toStdString().c_str(), j_json);
147 void HomescreenHandler::onRep_static(struct json_object* reply_contents)
149 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents);
152 void HomescreenHandler::onRep(struct json_object* reply_contents)
154 HMI_DEBUG("launcher","HomeScreen onReply %s", json_object_to_json_string(reply_contents));
155 struct json_object *obj_res, *obj_verb;
156 if(json_object_object_get_ex(reply_contents, "response", &obj_res)
157 && json_object_object_get_ex(obj_res, "verb", &obj_verb)
158 && !strcasecmp("getRunnables", json_object_get_string(obj_verb))) {
159 struct json_object *obj_data;
160 if(json_object_object_get_ex(obj_res, "data", &obj_data)) {
161 HMI_DEBUG("launcher","HomescreenHandler emit initAppList");
162 QString data = json_object_to_json_string(obj_data);
163 emit initAppList(data);
168 void HomescreenHandler::hideWindow(QString application_id)
170 mp_qhs->hideWindow(application_id.section('@', 0, 0).toStdString().c_str());
173 void HomescreenHandler::registerShortcut(QString shortcut_id, QString shortcut_name, QString position)
175 // struct json_object* j_obj = json_object_new_object();
176 // struct json_object* val_id = json_object_new_string(shortcut_id.toStdString().c_str());
177 // struct json_object* val_name = json_object_new_string(shortcut_name.toStdString().c_str());
178 // struct json_object* val_position = json_object_new_string(position.toStdString().c_str());
179 // json_object_object_add(j_obj, "shortcut_id", val_id);
180 // json_object_object_add(j_obj, "shortcut_name", val_name);
181 // json_object_object_add(j_obj, "position", val_position);
183 mp_qhs->registerShortcut(shortcut_id, shortcut_name, position);
186 int HomescreenHandler::uninstallApplication(QString application_id)
189 HMI_DEBUG("launcher","Application uninstall %s.", application_id.toStdString().c_str());
191 result = afm_user_daemon_proxy->uninstall(application_id).value().toInt();
192 HMI_DEBUG("launcher","ApplicationUninstall pid: %d.", result);
194 // QProcess *process = new QProcess();
195 // QString command = "/usr/bin/pkill " + application_id.section('@', 0, 0);
196 // HMI_DEBUG("launcher", "command is %s", command.toStdString().c_str());
197 // process->start(command);
202 void HomescreenHandler::sendAppToMeter(QString application_id)
204 HMI_DEBUG("Launcher","sendAppToMeter %s", application_id.toStdString().c_str());
205 struct json_object* j_json = json_object_new_object();
206 struct json_object* value;
207 value = json_object_new_string("master.split.sub");
208 json_object_object_add(j_json, "area", value);
210 mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json);
213 void HomescreenHandler::getRunnables(void)
215 mp_qhs->getRunnables();
218 void HomescreenHandler::setQuickWindow(QQuickWindow *qw)
220 mp_qhs->setQuickWindow(qw);