From: wang_zhiqiang Date: Sat, 25 May 2019 03:28:39 +0000 (+0800) Subject: add register/update shortcut X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Flibqthomescreen.git;a=commitdiff_plain;h=37f697decb02159b068fb8805d5d2a48644ce0e0 add register/update shortcut Change-Id: I50ebc14839a465508c74aadd7b3f3d9dab3465a6 --- diff --git a/src/qlibhomescreen.cpp b/src/qlibhomescreen.cpp index e76a6d8..b173e33 100644 --- a/src/qlibhomescreen.cpp +++ b/src/qlibhomescreen.cpp @@ -27,6 +27,10 @@ using namespace std; #define _KEY_APPLICATION_DATA "application_id" #define _KEY_REPLY_MESSAGE "reply_message" #define _KEY_REQUEST_MESSAGE "display_message" +#define _KEY_SHORTCUT "shortcut" +#define _KEY_SHORTCUT_ID "shortcut_id" +#define _KEY_SHORTCUT_NAME "shortcut_name" +#define _KEY_POSITION "position" static QLibHomeScreen* myThis; @@ -379,4 +383,43 @@ void QLibHomeScreen::setQuickWindow(QQuickWindow *qw) HMI_NOTICE("qlibhomescreen", "connect frameSwapped signal."); m_loading = QObject::connect(mp_window, SIGNAL(frameSwapped()), this, SLOT(slotPublishSubscription())); } +} + +void QLibHomeScreen::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, _KEY_SHORTCUT_ID, val_id); + json_object_object_add(j_obj, _KEY_SHORTCUT_NAME, val_name); + json_object_object_add(j_obj, _KEY_POSITION, val_position); + + mp_hs->registerShortcut(j_obj); +} + +/** + * shortcut_id pattern: "shocut_id1,shocut_id2,shocut_id3" + * shortcut_name pattern: "shortcut_name1,shortcut_name2,shortcut_name3" + */ +void QLibHomeScreen::updateShortcut(QString shortcut_id, QString shortcut_name) +{ + QStringList id = shortcut_id.split(','); + QStringList name = shortcut_name.split(','); + if(id.size() == 0 || id.size() != name.size()) { + HMI_NOTICE("qlibhomescreen","input parameters error."); + return; + } + + // make json contents + struct json_object* arr_obj = json_object_new_array(); + for(int i = 0; i < id.size(); ++i) { + struct json_object *j_obj = json_object_new_object(); + json_object_object_add(j_obj, _KEY_SHORTCUT_ID, json_object_new_string(id[i].toStdString().c_str())); + json_object_object_add(j_obj, _KEY_SHORTCUT_NAME, json_object_new_string(name[i].toStdString().c_str())); + json_object_array_add(arr_obj, j_obj); + } + struct json_object* push_obj = json_object_new_object(); + json_object_object_add(push_obj, _KEY_SHORTCUT, arr_obj); + mp_hs->updateShortcut(push_obj); } \ No newline at end of file diff --git a/src/qlibhomescreen.h b/src/qlibhomescreen.h index 306983c..11970e2 100644 --- a/src/qlibhomescreen.h +++ b/src/qlibhomescreen.h @@ -42,7 +42,9 @@ public: Event_ReplyShowWindow = LibHomeScreen::Event_ReplyShowWindow, Event_ShowNotification = LibHomeScreen::Event_ShowNotification, Event_ShowInformation = LibHomeScreen::Event_ShowInformation, - Event_AppListChanged = LibHomeScreen::Event_AppListChanged + Event_AppListChanged = LibHomeScreen::Event_AppListChanged, + Event_RegisterShortcut = LibHomeScreen::Event_RegisterShortcut, + Event_UpdateShortcut = LibHomeScreen::Event_UpdateShortcut }; using handler_fun = std::function; @@ -61,6 +63,8 @@ public: Q_INVOKABLE void hideWindow(QString application_id); Q_INVOKABLE void replyShowWindow(QString application_id, QString reply); Q_INVOKABLE void getRunnables(void); + Q_INVOKABLE void registerShortcut(QString shortcut_id, QString shortcut_name, QString position); + Q_INVOKABLE void updateShortcut(QString shortcut_id, QString shortcut_name); void registerCallback( void (*event_cb)(const std::string& event, struct json_object* event_contents), void (*reply_cb)(struct json_object* reply_contents),