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 fprintf(stderr, "OnScreenModel::setModel: setModel start!\n");
33 struct json_object *j_title = nullptr, *j_type = nullptr, *j_contents = nullptr, *j_buttons = nullptr;
34 struct json_object *j_param = json_tokener_parse(data.toString().toStdString().c_str());
36 fprintf(stderr, "OnScreenModel::setModel receiving end: %s\n", data.toString().toStdString().c_str());
38 if(json_object_object_get_ex(j_param, _title, &j_title)) {
39 m_title = json_object_get_string(j_title);
42 fprintf(stderr, "OnScreenModel::setModel: title input is null\n");
45 if(json_object_object_get_ex(j_param, _type, &j_type)) {
46 m_type = json_object_get_string(j_type);
49 fprintf(stderr, "OnScreenModel::setModel: type input is null\n");
52 if(json_object_object_get_ex(j_param, _contents, &j_contents)) {
53 m_contents = json_object_get_string(j_contents);
56 fprintf(stderr, "OnScreenModel::setModel: contents input is null\n");
59 if(json_object_object_get_ex(j_param, _buttons, &j_buttons)) {
60 if(json_object_get_type(j_buttons) != json_type_array) {
61 fprintf(stderr, "OnScreenModel::setModel buttons josn type isn't array!\n");
65 int len = json_object_array_length(j_buttons);
66 struct json_object *json_tmp = nullptr;
67 for (int i = 0; i < len; i++) {
68 json_tmp = json_object_array_get_idx(j_buttons, i);
69 m_buttons << QString(json_object_get_string(json_tmp));
74 fprintf(stderr, "OnScreenModel::setModel: buttons input is null\n");
77 fprintf(stderr, "OnScreenModel::setModel setModel end!titile=%s,type=%s,contents=%s,btnNum=%d\n",
78 m_title.toStdString().c_str(), m_type.toStdString().c_str(), m_contents.toStdString().c_str(), m_buttons.size());
81 QString OnScreenModel::buttonName(int index) const
83 if(index >= m_buttons.size())
86 return m_buttons[index];
89 void OnScreenModel::clearModel(void)