2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "qlibhomescreen.h"
18 #include <QJsonDocument>
19 #include <QJsonObject>
20 #include "hmi-debug.h"
23 #define _POPUPREPLY "on_screen_reply"
24 #define _REQ_POPUP_MESSAGE "on_screen_message"
25 #define _TAPSHORTCUT "tap_shortcut"
26 #define _KEY_DATA "data"
27 #define _KEY_APPLICATION_DATA "application_id"
28 #define _KEY_REPLY_MESSAGE "reply_message"
29 #define _KEY_REQUEST_MESSAGE "display_message"
31 static QLibHomeScreen* myThis;
33 // Note: qlibhomescreen will be integrated to libqtappfw
35 * QLibHomeScreen construction function
38 * - parent [in] : object parent.
44 QLibHomeScreen::QLibHomeScreen(QObject *parent) :
48 HMI_DEBUG("qlibhomescreen", "called.");
52 * QLibHomeScreen destruction function
61 QLibHomeScreen::~QLibHomeScreen()
63 HMI_DEBUG("qlibhomescreen", "called.");
72 * call libhomescreen init function to connect to binder by websocket
75 * - prot : port from application
76 * - token : token from application
82 void QLibHomeScreen::init(int port, const QString &token)
84 HMI_DEBUG("qlibhomescreen", "called.");
85 string ctoken = token.toStdString();
86 mp_hs = new LibHomeScreen();
87 mp_hs->init(port, ctoken.c_str());
94 * call on screen message
96 * use libhomescreen api to call onscreen message
99 * - message : message contents
102 * - Returns 0 on success or -1 in case of error.
105 int QLibHomeScreen::onScreenMessage(const QString &message)
107 HMI_DEBUG("qlibhomescreen", "called.");
108 string str = message.toStdString();
109 return mp_hs->onScreenMessage(str.c_str());
115 * use libhomescreen api to subscribe homescreen event
118 * - evetNave : homescreen event name
121 * - Returns 0 on success or -1 in case of error.
124 int QLibHomeScreen::subscribe(const QString &evetName)
126 HMI_DEBUG("qlibhomescreen", "called.");
127 string str = evetName.toStdString();
128 return mp_hs->subscribe(str);
134 * use libhomescreen api to unsubscribe homescreen event
137 * - evetNave : homescreen event name
140 * - Returns 0 on success or -1 in case of error.
143 int QLibHomeScreen::unsubscribe(const QString &evetName)
145 HMI_DEBUG("qlibhomescreen", "called.");
146 string str = evetName.toStdString();
147 return mp_hs->unsubscribe(str);
151 * set homescreen event handler function
154 * - et : homescreen event name
155 * - f : event handler function
161 void QLibHomeScreen::set_event_handler(enum QEventType et, handler_fun f)
163 HMI_DEBUG("qlibhomescreen", "called.");
164 LibHomeScreen::EventType hs_et = (LibHomeScreen::EventType)et;
165 return this->mp_hs->set_event_handler(hs_et, std::move(f));
169 * tapShortcut function
172 * - application_id : tapped application id
178 void QLibHomeScreen::tapShortcut(QString application_id)
180 HMI_DEBUG("qlibhomescreen","tapShortcut %s", application_id.toStdString().c_str());
181 mp_hs->showWindow(application_id.toStdString().c_str(), nullptr);
185 * show application by application id
188 * - application_id : application id
189 * - json : json parameters
195 void QLibHomeScreen::showWindow(QString application_id, json_object* json)
197 mp_hs->showWindow(application_id.toStdString().c_str(), json);
201 * show application by application id, json string
204 * - application_id : application id
205 * - json : json parameters
211 void QLibHomeScreen::showWindow(QString application_id, QString json)
214 mp_hs->showWindow(application_id.toStdString().c_str(), nullptr);
216 mp_hs->showWindow(application_id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str()));
220 * hide application by application id
223 * - application_id : application id
229 void QLibHomeScreen::hideWindow(QString application_id)
231 mp_hs->hideWindow(application_id.toStdString().c_str());
235 * send onscreen or software keyboard message to application
238 * - application_id : application id
239 * - json : json parameters
245 void QLibHomeScreen::replyShowWindow(QString application_id, json_object* json)
247 mp_hs->replyShowWindow(application_id.toStdString().c_str(), json);
251 * send onscreen or software keyboard message to application
254 * - application_id : application id
255 * - json : json parameters
261 void QLibHomeScreen::replyShowWindow(QString application_id, QString json)
264 mp_hs->replyShowWindow(application_id.toStdString().c_str(), nullptr);
266 mp_hs->replyShowWindow(application_id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str()));
272 * use libhomescreen api to push information to menubarApp
275 * - params : json parameters
281 void QLibHomeScreen::showInformation(QString info)
283 struct json_object* j_obj = json_object_new_object();
284 struct json_object* val = json_object_new_string(info.toStdString().c_str());
285 json_object_object_add(j_obj, "info", val);
287 mp_hs->showInformation(j_obj);
293 * use libhomescreen api to push notification to menubarApp
296 * - params : json parameters
302 void QLibHomeScreen::showNotification(QString icon, QString text)
304 struct json_object* j_obj = json_object_new_object();
305 struct json_object* val_icon = json_object_new_string(icon.toStdString().c_str());
306 struct json_object* val_text = json_object_new_string(text.toStdString().c_str());
307 json_object_object_add(j_obj, "icon", val_icon);
308 json_object_object_add(j_obj, "text", val_text);
310 mp_hs->showNotification(j_obj);