2 * Copyright (c) 2019 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 "onscreenmodel.h"
18 #include "hmi-debug.h"
19 #include <json-c/json.h>
21 const char _modelName[] = "OnScreenModel";
22 const char _title[] = "title";
23 const char _type[] = "type";
24 const char _contents[] = "contents";
25 const char _buttons[] = "buttons";
28 void OnScreenModel::setModel(QVariant data)
30 HMI_DEBUG(_modelName, "setModel start!");
32 struct json_object *j_title = nullptr, *j_type = nullptr, *j_contents = nullptr, *j_buttons = nullptr;
33 struct json_object *j_param = json_tokener_parse(data.toString().toStdString().c_str());
34 if(json_object_object_get_ex(j_param, _title, &j_title)) {
35 m_title = json_object_get_string(j_title);
38 HMI_DEBUG(_modelName, "title input is null");
41 if(json_object_object_get_ex(j_param, _type, &j_type)) {
42 m_type = json_object_get_string(j_type);
45 HMI_DEBUG(_modelName, "type input is null");
48 if(json_object_object_get_ex(j_param, _contents, &j_contents)) {
49 m_contents = json_object_get_string(j_contents);
52 HMI_DEBUG(_modelName, "contents input is null");
55 if(json_object_object_get_ex(j_param, _buttons, &j_buttons)) {
56 if(json_object_get_type(j_buttons) != json_type_array) {
57 HMI_DEBUG(_modelName, "buttons josn type isn't array!");
61 int len = json_object_array_length(j_buttons);
62 struct json_object *json_tmp = nullptr;
63 for (int i = 0; i < len; i++) {
64 json_tmp = json_object_array_get_idx(j_buttons, i);
65 m_buttons << QString(json_object_get_string(json_tmp));
70 HMI_DEBUG("OnScreenModel", "buttons input is null");
72 HMI_DEBUG(_modelName, "setModel end!titile=%s,type=%s,contents=%s,btnNum=%d",
73 m_title.toStdString().c_str(), m_type.toStdString().c_str(), m_contents.toStdString().c_str(), m_buttons.size());
76 QString OnScreenModel::buttonName(int index) const
78 if(index >= m_buttons.size())
81 return m_buttons[index];
84 void OnScreenModel::clearModel(void)