From: wang_zhiqiang Date: Tue, 28 May 2019 06:00:55 +0000 (+0800) Subject: registerShortcut X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=7d29d877baafe52cc0e0bbdf7d86deff61073651;p=apps%2Fhomescreen.git registerShortcut Change-Id: I66dbf6f12a890e67908594ed238556f5456b7ed7 --- diff --git a/homescreen/homescreen.pro b/homescreen/homescreen.pro index 4fcfb31..0de8e03 100644 --- a/homescreen/homescreen.pro +++ b/homescreen/homescreen.pro @@ -28,14 +28,18 @@ SOURCES += \ src/statusbarserver.cpp \ src/applicationlauncher.cpp \ src/mastervolume.cpp \ - src/homescreenhandler.cpp + src/homescreenhandler.cpp \ + src/toucharea.cpp \ + src/shortcutappmodel.cpp HEADERS += \ src/statusbarmodel.h \ src/statusbarserver.h \ src/applicationlauncher.h \ src/mastervolume.h \ - src/homescreenhandler.h + src/homescreenhandler.h \ + src/toucharea.h \ + src/shortcutappmodel.h OTHER_FILES += \ README.md diff --git a/homescreen/qml/ShortcutArea.qml b/homescreen/qml/ShortcutArea.qml index a8ce127..217aa9f 100644 --- a/homescreen/qml/ShortcutArea.qml +++ b/homescreen/qml/ShortcutArea.qml @@ -24,47 +24,41 @@ Item { width: 785 height: 218 - - ListModel { - id: applicationModel - ListElement { - appid: 'launcher' - name: 'launcher' - application: 'launcher@0.1' - } - ListElement { - appid: 'mediaplayer' - name: 'MediaPlayer' - application: 'mediaplayer@0.1' - } - ListElement { - appid: 'hvac' - name: 'HVAC' - application: 'hvac@0.1' - } - ListElement { - appid: 'navigation' - name: 'Navigation' - application: 'navigation@0.1' - } - } - property int pid: -1 RowLayout { anchors.fill: parent spacing: 2 Repeater { - model: applicationModel + id: repeater + model: shortcutAppModel delegate: ShortcutIcon { Layout.fillWidth: true Layout.fillHeight: true - name: model.name - active: model.name === launcher.current + name: shortcutAppModel.getName(model.index) + icon: shortcutAppModel.getIcon(model.index) + isBlank: shortcutAppModel.isBlank(model.index) + active: shortcutAppModel.getName(model.index).toLowerCase() === launcher.current onClicked: { - homescreenHandler.tapShortcut(model.appid) + console.log("launcher.current====="+homescreenHandler.getCurrentApplication()) + if(launcher.current === shortcutAppModel.getName(model.index)) { + return + } + homescreenHandler.tapShortcut(shortcutAppModel.getId(model.index), false) } } } } + + Connections { + target: shortcutAppModel + onUpdateShortcut: { + for(var i = 0; i < 4; i++) { + var item = repeater.itemAt(i) + item.name = shortcutAppModel.getName(i) + item.icon = shortcutAppModel.getIcon(i) + item.isBlank = shortcutAppModel.isBlank(i) + } + } + } } diff --git a/homescreen/qml/ShortcutIcon.qml b/homescreen/qml/ShortcutIcon.qml index 1100a7c..e891c99 100644 --- a/homescreen/qml/ShortcutIcon.qml +++ b/homescreen/qml/ShortcutIcon.qml @@ -24,7 +24,10 @@ MouseArea { width: 195 height: 216.8 property string name: 'Home' + property string icon:'./images/Shortcut/' property bool active: false + property bool isBlank: false + Item { id: icon property real desaturation: 0 @@ -32,14 +35,42 @@ MouseArea { Image { id: inactiveIcon anchors.fill: parent - source: './images/Shortcut/%1.svg'.arg(root.name.toLowerCase()) + source: './images/Shortcut/blank.svg' +// source: isBlank ? './images/Shortcut/blank.svg' : root.icon + property string initial: root.name.substring(0,1).toUpperCase() + Label { + style: Text.Outline + styleColor: '#00FFFF' + color: 'transparent' + font.pixelSize: 75 + anchors.centerIn: parent + text: inactiveIcon.initial + visible: root.isBlank + } } Image { id: activeIcon anchors.fill: parent - source: './images/Shortcut/%1_active.svg'.arg(root.name.toLowerCase()) + source: './images/Shortcut/blank_active.svg' +// source: isBlank ? './images/Shortcut/blank_active.svg' : root.icon + property string initial: root.name.substring(0,1).toUpperCase() + Label { + style: Text.Outline + styleColor: '#00FFFF' + color: 'transparent' + font.pixelSize: 75 + anchors.centerIn: parent + text: activeIcon.initial + visible: root.isBlank + } opacity: 0.0 } + Image { + id: sourceIcon + anchors.fill: parent + source: isBlank ? null : root.icon + } + layer.enabled: true layer.effect: Desaturate { id: desaturate @@ -47,6 +78,7 @@ MouseArea { cached: true } } + Label { id: name y: 160 @@ -57,20 +89,10 @@ MouseArea { anchors.horizontalCenter: parent.horizontalCenter horizontalAlignment: Text.AlignHCenter color: "white" - text: qsTr(model.name.toUpperCase()) + text: qsTr((root.name === "launcher" ? "home" : root.name).toUpperCase()) } + states: [ - State { - when: launcher.launching - PropertyChanges { - target: root - enabled: false - } - PropertyChanges { - target: icon - desaturation: 1.0 - } - }, State { when: root.active PropertyChanges { @@ -83,18 +105,4 @@ MouseArea { } } ] - - transitions: [ - Transition { - NumberAnimation { - properties: 'opacity' - duration: 500 - easing.type: Easing.OutExpo - } - NumberAnimation { - properties: 'desaturation' - duration: 250 - } - } - ] } diff --git a/homescreen/qml/StatusArea.qml b/homescreen/qml/StatusArea.qml index d2e0930..961cd88 100644 --- a/homescreen/qml/StatusArea.qml +++ b/homescreen/qml/StatusArea.qml @@ -109,6 +109,12 @@ Item { font.pixelSize: 32 } } + MouseArea { + anchors.fill: parent + onClicked: { + homescreenHandler.killRunningApplications() + } + } } } ColumnLayout { @@ -117,11 +123,16 @@ Item { Layout.fillHeight: true Layout.preferredWidth: 76 spacing: -10 + Rectangle { + Layout.preferredWidth: 77 + Layout.preferredHeight: 55 + opacity: 0 + } Image { id: bt_icon Layout.preferredWidth: 77 - Layout.preferredHeight: 73 + Layout.preferredHeight: 55 source: connStatus ? './images/Status/HMI_Status_Bluetooth_On-01.png' : './images/Status/HMI_Status_Bluetooth_Inactive-01.png' fillMode: Image.PreserveAspectFit property string deviceName: "none" @@ -138,7 +149,7 @@ Item { model: StatusBarModel { objectName: "statusBar" } delegate: Image { Layout.preferredWidth: 77 - Layout.preferredHeight: 73 + Layout.preferredHeight: 55 source: model.modelData fillMode: Image.PreserveAspectFit } diff --git a/homescreen/qml/images/AGL_HMI_Blue_Background_NoCar-01.png b/homescreen/qml/images/AGL_HMI_Blue_Background_NoCar-01.png index 357c204..a4e026c 100644 Binary files a/homescreen/qml/images/AGL_HMI_Blue_Background_NoCar-01.png and b/homescreen/qml/images/AGL_HMI_Blue_Background_NoCar-01.png differ diff --git a/homescreen/qml/images/AGL_HMI_Full_Background.png b/homescreen/qml/images/AGL_HMI_Full_Background.png new file mode 100644 index 0000000..9631ca0 Binary files /dev/null and b/homescreen/qml/images/AGL_HMI_Full_Background.png differ diff --git a/homescreen/qml/images/AGL_HMI_Normal_Background.png b/homescreen/qml/images/AGL_HMI_Normal_Background.png new file mode 100644 index 0000000..c686067 Binary files /dev/null and b/homescreen/qml/images/AGL_HMI_Normal_Background.png differ diff --git a/homescreen/qml/images/Shortcut/blank.svg b/homescreen/qml/images/Shortcut/blank.svg new file mode 100644 index 0000000..3bccdca --- /dev/null +++ b/homescreen/qml/images/Shortcut/blank.svg @@ -0,0 +1,81 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/homescreen/qml/images/Shortcut/blank_active.svg b/homescreen/qml/images/Shortcut/blank_active.svg new file mode 100644 index 0000000..0b63bc9 --- /dev/null +++ b/homescreen/qml/images/Shortcut/blank_active.svg @@ -0,0 +1,100 @@ + + + +image/svg+xml + + + + + + + + + + + + + + \ No newline at end of file diff --git a/homescreen/qml/images/Shortcut/sdl_usb.svg b/homescreen/qml/images/Shortcut/sdl_usb.svg new file mode 100644 index 0000000..3b6a7e9 --- /dev/null +++ b/homescreen/qml/images/Shortcut/sdl_usb.svg @@ -0,0 +1,311 @@ + + + +image/svg+xml diff --git a/homescreen/qml/images/Shortcut/sdl_usb_active.svg b/homescreen/qml/images/Shortcut/sdl_usb_active.svg new file mode 100644 index 0000000..9584885 --- /dev/null +++ b/homescreen/qml/images/Shortcut/sdl_usb_active.svg @@ -0,0 +1,278 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + diff --git a/homescreen/qml/images/Shortcut/shortcut.qrc b/homescreen/qml/images/Shortcut/shortcut.qrc index 5d67341..54df1ad 100644 --- a/homescreen/qml/images/Shortcut/shortcut.qrc +++ b/homescreen/qml/images/Shortcut/shortcut.qrc @@ -8,5 +8,11 @@ mediaplayer_active.svg navigation.svg navigation_active.svg + video.svg + video_active.svg + sdl_usb.svg + sdl_usb_active.svg + blank.svg + blank_active.svg diff --git a/homescreen/qml/images/Shortcut/video.svg b/homescreen/qml/images/Shortcut/video.svg new file mode 100644 index 0000000..e368922 --- /dev/null +++ b/homescreen/qml/images/Shortcut/video.svg @@ -0,0 +1,109 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/homescreen/qml/images/Shortcut/video_active.svg b/homescreen/qml/images/Shortcut/video_active.svg new file mode 100644 index 0000000..344385f --- /dev/null +++ b/homescreen/qml/images/Shortcut/video_active.svg @@ -0,0 +1,126 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/homescreen/qml/images/fullscreen.png b/homescreen/qml/images/fullscreen.png new file mode 100644 index 0000000..f56a13c Binary files /dev/null and b/homescreen/qml/images/fullscreen.png differ diff --git a/homescreen/qml/images/images.qrc b/homescreen/qml/images/images.qrc index 37ad676..39f7eb6 100644 --- a/homescreen/qml/images/images.qrc +++ b/homescreen/qml/images/images.qrc @@ -6,5 +6,10 @@ Utility_Music_Background-01.png Utility_Radio_Background-01.png AGL_HMI_Blue_Background_NoCar-01.png + AGL_HMI_Full_Background.png + AGL_HMI_Normal_Background.png + fullscreen.png + normal.png + normal_disable.png diff --git a/homescreen/qml/images/normal.png b/homescreen/qml/images/normal.png new file mode 100644 index 0000000..92dee7a Binary files /dev/null and b/homescreen/qml/images/normal.png differ diff --git a/homescreen/qml/images/normal_disable.png b/homescreen/qml/images/normal_disable.png new file mode 100644 index 0000000..f191241 Binary files /dev/null and b/homescreen/qml/images/normal_disable.png differ diff --git a/homescreen/qml/main.qml b/homescreen/qml/main.qml index 7d40276..a8d095b 100644 --- a/homescreen/qml/main.qml +++ b/homescreen/qml/main.qml @@ -26,6 +26,7 @@ Window { width: container.width * container.scale height: container.height * container.scale title: 'HomeScreen' + color: "#00000000" Image { id: container @@ -60,6 +61,145 @@ Window { Layout.preferredHeight: 215 } } + + + state: "normal" + + states: [ + State { + name: "normal" + PropertyChanges { + target: topArea + y: 0 + } + PropertyChanges { + target: applicationArea + y: 218 + } + PropertyChanges { + target: mediaArea + y: 1705 + } + }, + State { + name: "fullscreen" + PropertyChanges { + target: topArea + y: -220 + } + PropertyChanges { + target: applicationArea + y: -1490 + } + PropertyChanges { + target: mediaArea + y: 2135 + } + } + ] + transitions: Transition { + NumberAnimation { + target: topArea + property: "y" + easing.type: "OutQuad" + duration: 250 + } + NumberAnimation { + target: mediaArea + property: "y" + easing.type: "OutQuad" + duration: 250 + } + } + + } + Item { + id: switchBtn + width: 70 + height: 70 + anchors.right: parent.right + anchors.top: parent.top + z: 1 + property bool enableSwitchBtn: true + Image { + anchors.right: parent.right + anchors.rightMargin: 20 + anchors.top: parent.top + anchors.topMargin: 25 + width: 35 + height: 35 + id: image + source: './images/normal.png' + } + + MouseArea { + anchors.fill: parent + onClicked: { + if(switchBtn.enableSwitchBtn) { + var appName = homescreenHandler.getCurrentApplication() + if (container.state === 'normal') { + image.source = './images/fullscreen.png' + container.state = 'fullscreen' + touchArea.switchArea(1) + homescreenHandler.tapShortcut(appName, true) + container.opacity = 0.0 + } else { + image.source = './images/normal.png' + container.state = 'normal' + touchArea.switchArea(0) + homescreenHandler.tapShortcut(appName, false) + container.opacity = 1.0 + } + } + } + } + } + + Item { + id: rebootBtn + width: 70 + height: 70 + anchors.left: parent.left + anchors.top: parent.top + z: 1 + MouseArea { + anchors.fill: parent + onClicked: { + homescreenHandler.reboot(); + } + } + } + + function changeSwitchState(is_navigation) { + if(container.state === 'normal') { + if(is_navigation) { + switchBtn.enableSwitchBtn = true + image.source = './images/normal.png' + } else { + switchBtn.enableSwitchBtn = false + image.source = './images/normal_disable.png' + } + } + } + + Connections { + target: homescreenHandler + onShowWindow: { + container.state = 'normal' + image.visible = true + touchArea.switchArea(0) + container.opacity = 1.0 + } + } + + Connections { + target: homescreenHandler + onHideWindow: { + container.state = 'fullscreen' + image.visible = false + touchArea.switchArea(1) + container.opacity = 0.0 + } } Timer { diff --git a/homescreen/src/applicationlauncher.cpp b/homescreen/src/applicationlauncher.cpp index 5a1e2d6..a72ea9f 100644 --- a/homescreen/src/applicationlauncher.cpp +++ b/homescreen/src/applicationlauncher.cpp @@ -81,5 +81,6 @@ void ApplicationLauncher::setCurrent(const QString ¤t) { if (m_current == current) return; m_current = current; + qDebug() << "setCurrent" << m_current; emit currentChanged(current); } diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp index 865f6a5..a06fa7e 100644 --- a/homescreen/src/homescreenhandler.cpp +++ b/homescreen/src/homescreenhandler.cpp @@ -17,13 +17,18 @@ #include #include "homescreenhandler.h" #include +#include +#include +#include #include "hmi-debug.h" +#define BUF_SIZE 1024 void* HomescreenHandler::myThis = 0; HomescreenHandler::HomescreenHandler(QObject *parent) : QObject(parent), - mp_qhs(NULL) + mp_qhs(NULL), + current_application("launcher") { } @@ -48,6 +53,7 @@ void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowWindow,[this](json_object *object){ HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n"); mp_qwm->activateWindow(m_myname); + emit showWindow(); }); mp_qhs->set_event_handler(QLibHomeScreen::Event_OnScreenMessage, [this](json_object *object){ @@ -83,17 +89,112 @@ void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm emit showInformation(QString(QLatin1String(info))); }); + + mp_qhs->set_event_handler(QLibHomeScreen::Event_HideWindow, [this](json_object *object) { + emit hideWindow(); + HMI_DEBUG("HomeScreen","set_event_handler Event_HideWindow"); + }); + + mp_qhs->set_event_handler(QLibHomeScreen::Event_RegisterShortcut,[this](json_object *object){ + HMI_DEBUG("HomeScreen","set_event_handler Event_RegisterShortcut"); + json_object *p_obj = json_object_object_get(object, "parameter"); + const char *shortcut_id = json_object_get_string( + json_object_object_get(p_obj, "shortcut_id")); + const char *shortcut_name = json_object_get_string( + json_object_object_get(p_obj, "shortcut_name")); + const char *position = json_object_get_string( + json_object_object_get(p_obj, "position")); + HMI_DEBUG("HomeScreen", "Event_RegisterShortcut id==%s, name==%s, position ==%s", shortcut_id, shortcut_name, position); + emit shortcutChanged(QString(QLatin1String(shortcut_id)), QString(QLatin1String(shortcut_name)), QString(QLatin1String(position))); + }); } -void HomescreenHandler::tapShortcut(QString application_id) +void HomescreenHandler::tapShortcut(QString application_id, bool is_full) { HMI_DEBUG("HomeScreen","tapShortcut %s", application_id.toStdString().c_str()); struct json_object* j_json = json_object_new_object(); struct json_object* value; - value = json_object_new_string("normal.full"); + if(is_full) { + value = json_object_new_string("fullscreen"); + HMI_DEBUG("HomeScreen","fullscreen"); + } else { + value = json_object_new_string("normal.full"); + HMI_DEBUG("HomeScreen","normal"); + } json_object_object_add(j_json, "area", value); + mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json); +} + +void HomescreenHandler::updateShortcut(QString id, struct json_object* object) +{ + mp_qhs->updateShortcut(id.toStdString().c_str(), object); +} + + +void HomescreenHandler::setCurrentApplication(QString application_name) +{ + HMI_DEBUG("HomeScreen","setCurrentApplication %s", application_name.toStdString().c_str()); + current_application = application_name; +} + +QString HomescreenHandler::getCurrentApplication() +{ + HMI_DEBUG("HomeScreen","getCurrentApplication %s", current_application.toStdString().c_str()); + return current_application; +} + +int HomescreenHandler::getPidOfApplication(QString application_name) { + DIR *dir = NULL; + struct dirent *dir_ent_ptr = NULL; + FILE *fp = NULL; + char file_path[50] = {0}; + char cur_task_ame[50] = {0}; + char buf[BUF_SIZE] = {0}; + int pid = -1; + + dir = opendir("/proc"); + if (dir) { + while((dir_ent_ptr = readdir(dir)) != NULL) { + if ((strcmp(dir_ent_ptr->d_name, ".") == 0) || (strcmp(dir_ent_ptr->d_name, "..") == 0) + || (DT_DIR != dir_ent_ptr->d_type)) + continue; + sprintf(file_path, "/proc/%s/status", dir_ent_ptr->d_name); + fp = fopen(file_path, "r"); + if (fp) { + if (fgets(buf, BUF_SIZE - 1, fp) == NULL) { + fclose(fp); + continue; + } + sscanf(buf, "%*s %s", cur_task_ame); + if (0 == strcmp(application_name.toStdString().c_str(), cur_task_ame)) { + pid = atoi(dir_ent_ptr->d_name); + break; + } + } + } + } - mp_qhs->showWindow(application_id.toStdString().c_str(), j_json); + return pid; +} + +void HomescreenHandler::killRunningApplications() +{ + QProcess *proc = new QProcess; + QProcess *proc2 = new QProcess; +// int num = getPidOfApplication("afbd-video@0.1"); +// QString procNum = QString::number(num); + QString command = "/usr/bin/pkill videoplayer"; + QString command2 = "/usr/bin/pkill navigation"; + proc->start(command); + proc2->start(command2); + HMI_DEBUG("homescreen", command.toStdString().c_str()); + HMI_DEBUG("homescreen", command2.toStdString().c_str()); +} + +void HomescreenHandler::reboot() +{ + QProcess::execute("sync"); + QProcess::execute("reboot -f"); } void HomescreenHandler::onRep_static(struct json_object* reply_contents) diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h index d617737..4afbac4 100644 --- a/homescreen/src/homescreenhandler.h +++ b/homescreen/src/homescreenhandler.h @@ -34,7 +34,12 @@ public: void init(int port, const char* token, QLibWindowmanager *qwm, QString myname); - Q_INVOKABLE void tapShortcut(QString application_id); + Q_INVOKABLE void tapShortcut(QString application_name, bool is_full); + Q_INVOKABLE QString getCurrentApplication(); + Q_INVOKABLE void killRunningApplications(); + Q_INVOKABLE void reboot(); + void setCurrentApplication(QString application_name); + int getPidOfApplication(QString application_name); void onRep(struct json_object* reply_contents); void onEv(const string& event, struct json_object* event_contents); @@ -47,10 +52,18 @@ public: signals: void showNotification(QString application_id, QString icon_path, QString text); void showInformation(QString info); + void shortcutChanged(QString shortcut_id, QString shortcut_name, QString position); + void showWindow(); + void hideWindow(); + +public slots: + void updateShortcut(QString id, struct json_object* object); + private: QLibHomeScreen *mp_qhs; QLibWindowmanager *mp_qwm; QString m_myname; + QString current_application; }; #endif // HOMESCREENHANDLER_H diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index ec0a76b..0c477fd 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,8 @@ #include "afm_user_daemon_proxy.h" #include "mastervolume.h" #include "homescreenhandler.h" +#include "toucharea.h" +#include "shortcutappmodel.h" #include "hmi-debug.h" // XXX: We want this DBus connection to be shared across the different @@ -91,9 +94,12 @@ int main(int argc, char *argv[]) // qmlRegisterType("HomeScreen", 1, 0, "ApplicationLauncher"); qmlRegisterType("HomeScreen", 1, 0, "StatusBarModel"); qmlRegisterType("MasterVolume", 1, 0, "MasterVolume"); + qmlRegisterType("ShortcutAppModel", 1, 0, "ShortcutAppModel"); ApplicationLauncher *launcher = new ApplicationLauncher(); QLibWindowmanager* layoutHandler = new QLibWindowmanager(); + HomescreenHandler* homescreenHandler = new HomescreenHandler(); + ShortcutAppModel* shortcutAppModel = new ShortcutAppModel(); if(layoutHandler->init(port,token) != 0){ exit(EXIT_FAILURE); } @@ -104,24 +110,6 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler, &graphic_role](json_object *object) { - layoutHandler->endDraw(graphic_role); - }); - - layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher](json_object *object) { - json_object *jarray = json_object_object_get(object, "ids"); - int arrLen = json_object_array_length(jarray); - for( int idx = 0; idx < arrLen; idx++) - { - QString label = QString(json_object_get_string( json_object_array_get_idx(jarray, idx) )); - HMI_DEBUG("HomeScreen","Event_ScreenUpdated application: %s.", label.toStdString().c_str()); - QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label)); - } - }); - - HomescreenHandler* homescreenHandler = new HomescreenHandler(); - homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, graphic_role); - QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); bindingAddress.setHost(QStringLiteral("localhost")); @@ -132,11 +120,16 @@ int main(int argc, char *argv[]) query.addQueryItem(QStringLiteral("token"), token); bindingAddress.setQuery(query); + TouchArea* touchArea = new TouchArea(); + homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, graphic_role); + // mail.qml loading QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("bindingAddress", bindingAddress); engine.rootContext()->setContextProperty("layoutHandler", layoutHandler); engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler); + engine.rootContext()->setContextProperty("touchArea", touchArea); + engine.rootContext()->setContextProperty("shortcutAppModel", shortcutAppModel); engine.rootContext()->setContextProperty("launcher", launcher); engine.rootContext()->setContextProperty("weather", new Weather(bindingAddress)); engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress, engine.rootContext())); @@ -147,9 +140,44 @@ int main(int argc, char *argv[]) QQuickWindow *window = qobject_cast(root); homescreenHandler->setQuickWindow(window); + layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler, &graphic_role](json_object *object) { + layoutHandler->endDraw(graphic_role); + }); + + layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher, homescreenHandler, root](json_object *object) { + json_object *jarray = json_object_object_get(object, "ids"); + HMI_DEBUG("HomeScreen","ids=%s", json_object_to_json_string(object)); + int arrLen = json_object_array_length(jarray); + QString label = QString(""); + for( int idx = 0; idx < arrLen; idx++) + { + label = QString(json_object_get_string( json_object_array_get_idx(jarray, idx) )); + HMI_DEBUG("HomeScreen","Event_ScreenUpdated application11: %s.", label.toStdString().c_str()); + homescreenHandler->setCurrentApplication(label); + QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label)); + } + if((arrLen == 1) && (QString("navigation") == label)){ + QMetaObject::invokeMethod(root, "changeSwitchState", Q_ARG(QVariant, true)); + }else{ + QMetaObject::invokeMethod(root, "changeSwitchState", Q_ARG(QVariant, false)); + } + }); + + touchArea->setWindow(window); + QThread* thread = new QThread; + touchArea->moveToThread(thread); + QObject::connect(thread, &QThread::started, touchArea, &TouchArea::init); + + thread->start(); + QList sobjs = engine.rootObjects(); StatusBarModel *statusBar = sobjs.first()->findChild("statusBar"); statusBar->init(bindingAddress, engine.rootContext()); + QObject::connect(homescreenHandler, SIGNAL(shortcutChanged(QString, QString, QString)), shortcutAppModel, SLOT(changeShortcut(QString, QString, QString))); + QObject::connect(shortcutAppModel, SIGNAL(shortcutUpdated(QString, struct json_object*)), homescreenHandler, SLOT(updateShortcut(QString, struct json_object*))); + + shortcutAppModel->screenUpdated(); + return a.exec(); } diff --git a/homescreen/src/shortcutappmodel.cpp b/homescreen/src/shortcutappmodel.cpp new file mode 100644 index 0000000..76078da --- /dev/null +++ b/homescreen/src/shortcutappmodel.cpp @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "shortcutappmodel.h" +#include "hmi-debug.h" +#include +#define SHORTCUTKEY_PATH "/var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json" + +class ShortcutAppModel::Private +{ +public: + Private(); + + QList data; +}; + +ShortcutAppModel::Private::Private() +{ +} + + +ShortcutAppModel::ShortcutAppModel(QObject *parent) + : QAbstractListModel(parent) + , d(new Private()) +{ + getAppQueue(); +} + +ShortcutAppModel::~ShortcutAppModel() +{ + delete this->d; +} + +int ShortcutAppModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return this->d->data.count(); +} + +QVariant ShortcutAppModel::data(const QModelIndex &index, int role) const +{ + QVariant ret; + if (!index.isValid()) + return ret; + + switch (role) { + case Qt::DecorationRole: + ret = this->d->data[index.row()].icon; + break; + case Qt::DisplayRole: + ret = this->d->data[index.row()].name; + break; + case Qt::UserRole: + ret = this->d->data[index.row()].id; + break; + default: + break; + } + + return ret; +} + +QHash ShortcutAppModel::roleNames() const +{ + QHash roles; + roles[Qt::DecorationRole] = "icon"; + roles[Qt::DisplayRole] = "name"; + roles[Qt::UserRole] = "id"; + return roles; +} + +void ShortcutAppModel::changeShortcut(QString id, QString name, QString position) +{ + for(int i = 1; i < d->data.size(); i++) { + if(id == d->data.at(i).id) { + return; + } + } + d->data.removeAt(position.toInt() + 1); + + RegisterApp temp; + temp.id = id; + temp.name = name; + temp.icon = temp.icon = getIconPath(temp.id); + if (temp.icon == "") { + temp.isBlank = true; + } else { + temp.isBlank = false; + } + + d->data.insert(position.toInt() + 1, temp); + setAppQueue(); + emit updateShortcut(); + struct json_object* obj = makeAppListJson(); + emit shortcutUpdated(QString("launcher"), obj); +} + +struct json_object* ShortcutAppModel::makeAppListJson() +{ + struct json_object* obj = json_object_new_object(); + struct json_object* obj_array = json_object_new_array(); + for(int i = 1; i < d->data.size(); i++) + { + struct json_object* obj_shortcut = json_object_new_object(); + json_object_object_add(obj_shortcut, "shortcut_id", json_object_new_string(d->data.at(i).id.toStdString().c_str())); + json_object_object_add(obj_shortcut, "shortcut_name", json_object_new_string(d->data.at(i).name.toStdString().c_str())); + json_object_array_add(obj_array, obj_shortcut); + } + json_object_object_add(obj, "shortcut", obj_array); + HMI_DEBUG("Homescreen", "makeAppListJson id1=%s",json_object_new_string(d->data.at(1).name.toStdString().c_str())); + return obj; +} + +QString ShortcutAppModel::getId(int index) const +{ + return d->data.at(index).id; +} + +QString ShortcutAppModel::getName(int index) const +{ + return d->data.at(index).name; +} + +QString ShortcutAppModel::getIcon(int index) const +{ + return d->data.at(index).icon; +} + +bool ShortcutAppModel::isBlank(int index) const +{ + return d->data.at(index).isBlank; +} + +QString ShortcutAppModel::getIconPath(QString id) +{ + QString name = id.section('@', 0, 0); + QString version = id.section('@', 1, 1); + QString boardIconPath = "/var/local/lib/afm/applications/" + name + "/" + version + "/icon.svg"; + QString appIconPath = ":/images/Shortcut/" + name + ".svg"; + if (QFile::exists(boardIconPath)) { + return "file://" + boardIconPath; + } else if (QFile::exists(appIconPath)) { + return appIconPath.section('/', 1, -1); + } + return ""; +} + +void ShortcutAppModel::getAppQueue() +{ + QProcess *process = new QProcess(this); + if(checkAppFile()) { + process->start("cp /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.aaa.json /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json"); + } else { + process->start("cp /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.aaa.json"); + } + QThread::msleep(300); + + QFile file(SHORTCUTKEY_PATH); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QByteArray allData = file.readAll(); + QString str(allData); + if(str == "") { + file.close(); + + } + QJsonParseError json_error; + QJsonDocument jsonDoc(QJsonDocument::fromJson(allData, &json_error)); + + if(json_error.error != QJsonParseError::NoError) + { + HMI_ERROR("HomeScreen", "registeredApp.json error"); + return; + } + + QJsonObject rootObj = jsonDoc.object(); + + QJsonObject subObj = rootObj.value("1st shortcut key").toObject(); + setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); + subObj = rootObj.value("2nd shortcut key").toObject(); + setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); + subObj = rootObj.value("3rd shortcut key").toObject(); + setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); + subObj = rootObj.value("4th shortcut key").toObject(); + setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); + } + file.close(); +} + +void ShortcutAppModel::setAppQueuePoint(QString id, QString name) +{ + app.id = id; + app.icon = getIconPath(app.id); + if (app.icon == "") { + app.isBlank = true; + } else { + app.isBlank = false; + } + app.name = name; + d->data.append(app); +} + +void ShortcutAppModel::screenUpdated() +{ + struct json_object* obj = makeAppListJson(); + emit shortcutUpdated(QString("launcher"), obj); +} + +void ShortcutAppModel::setAppQueue() +{ + QFile file(SHORTCUTKEY_PATH); + if(file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QJsonObject rootObj, subObj1, subObj2, subObj3, subObj4; + subObj1.insert("id", d->data.at(0).id); + subObj1.insert("name", d->data.at(0).name); + subObj2.insert("id", d->data.at(1).id); + subObj2.insert("name", d->data.at(1).name); + subObj3.insert("id", d->data.at(2).id); + subObj3.insert("name", d->data.at(2).name); + subObj4.insert("id", d->data.at(3).id); + subObj4.insert("name", d->data.at(3).name); + rootObj.insert("1st shortcut key", subObj1); + rootObj.insert("2nd shortcut key", subObj2); + rootObj.insert("3rd shortcut key", subObj3); + rootObj.insert("4th shortcut key", subObj4); + + QJsonDocument jsonDoc; + jsonDoc.setObject(rootObj); + + file.write(jsonDoc.toJson()); + } else { + HMI_ERROR("HomeScreen", "write to registeredApp.json file failed"); + } + file.flush(); + fsync(file.handle()); + file.close(); +} + +bool ShortcutAppModel::checkAppFile() +{ + bool fileError = false; + QFile file(SHORTCUTKEY_PATH); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QByteArray line = file.readLine(); + if(line == "\n" || line.isEmpty()) { + fileError = true; + } + } else { + fileError = true; + HMI_ERROR("HomeScreen", "registeredApp.json file open failed"); + } + file.close(); + return fileError; +} diff --git a/homescreen/src/shortcutappmodel.h b/homescreen/src/shortcutappmodel.h new file mode 100644 index 0000000..f177a95 --- /dev/null +++ b/homescreen/src/shortcutappmodel.h @@ -0,0 +1,62 @@ +#ifndef SHORTCUTAPPMODEL_H +#define SHORTCUTAPPMODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct RegisterApp { + QString id; + QString name; + QString icon; + bool isBlank; +}; + +class ShortcutAppModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit ShortcutAppModel(QObject *parent = nullptr); + ~ShortcutAppModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + + Q_INVOKABLE QString getId(int index) const; + Q_INVOKABLE QString getName(int index) const; + Q_INVOKABLE QString getIcon(int index) const; + Q_INVOKABLE bool isBlank(int index) const; + + void screenUpdated(); + +public slots: + void changeShortcut(QString id, QString name, QString position); + +signals: + void updateShortcut(); + void shortcutUpdated(QString id, struct json_object* object); + +private: + void getAppQueue(); + void setAppQueue(); + bool checkAppFile(); + void setAppQueuePoint(QString id, QString name); + QString getIconPath(QString id); + struct json_object* makeAppListJson(); + + class Private; + Private *d; + RegisterApp app; + +}; + +#endif // SHORTCUTAPPMODEL_H diff --git a/homescreen/src/toucharea.cpp b/homescreen/src/toucharea.cpp new file mode 100644 index 0000000..1cf4384 --- /dev/null +++ b/homescreen/src/toucharea.cpp @@ -0,0 +1,36 @@ +#include "toucharea.h" +#include "hmi-debug.h" + +TouchArea::TouchArea() +{ +} + +TouchArea::~TouchArea() +{ + +} + +void TouchArea::setWindow(QQuickWindow *window) +{ + myWindow = window; +} + +void TouchArea::init() +{ + bitmapNormal = QPixmap(":/images/AGL_HMI_Normal_Background.png").createHeuristicMask(); + bitmapFullscreen = QPixmap(":/images/AGL_HMI_Full_Background.png").createHeuristicMask(); + myWindow->setMask(QRegion(bitmapNormal)); +} + +void TouchArea::switchArea(int areaType) +{ + if(areaType == NORMAL) { + myWindow->setMask(QRegion(bitmapNormal)); + HMI_DEBUG("HomeScreen","TouchArea switchArea: %d.", areaType); + } else if (areaType == FULLSCREEN) { + HMI_DEBUG("HomeScreen","TouchArea switchArea: %d.", areaType); + myWindow->setMask(QRegion(bitmapFullscreen)); + } +} + + diff --git a/homescreen/src/toucharea.h b/homescreen/src/toucharea.h new file mode 100644 index 0000000..69c6872 --- /dev/null +++ b/homescreen/src/toucharea.h @@ -0,0 +1,30 @@ +#ifndef TOUCHAREA_H +#define TOUCHAREA_H + +#include +#include + +enum { + NORMAL=0, + FULLSCREEN +}; + +class TouchArea : public QObject +{ + Q_OBJECT +public: + explicit TouchArea(); + ~TouchArea(); + + Q_INVOKABLE void switchArea(int areaType); + void setWindow(QQuickWindow* window); + +public slots: + void init(); + +private: + QBitmap bitmapNormal, bitmapFullscreen; + QQuickWindow* myWindow; +}; + +#endif // TOUCHAREA_H diff --git a/package/etc/registeredApp.aaa.json b/package/etc/registeredApp.aaa.json new file mode 100644 index 0000000..490b33c --- /dev/null +++ b/package/etc/registeredApp.aaa.json @@ -0,0 +1,18 @@ +{ + "1st shortcut key": { + "id": "launcher@0.1", + "name": "launcher" + }, + "2nd shortcut key": { + "id": "sdl_usb@5.0", + "name": "sdl_usb" + }, + "3rd shortcut key": { + "id": "video@0.1", + "name": "video" + }, + "4th shortcut key": { + "id": "navigation@0.1", + "name": "navigation" + } +} diff --git a/package/etc/registeredApp.json b/package/etc/registeredApp.json new file mode 100644 index 0000000..490b33c --- /dev/null +++ b/package/etc/registeredApp.json @@ -0,0 +1,18 @@ +{ + "1st shortcut key": { + "id": "launcher@0.1", + "name": "launcher" + }, + "2nd shortcut key": { + "id": "sdl_usb@5.0", + "name": "sdl_usb" + }, + "3rd shortcut key": { + "id": "video@0.1", + "name": "video" + }, + "4th shortcut key": { + "id": "navigation@0.1", + "name": "navigation" + } +} diff --git a/package/package.pro b/package/package.pro index 09c7a01..1f175d3 100644 --- a/package/package.pro +++ b/package/package.pro @@ -12,6 +12,12 @@ copy_config.commands = $(COPY_FILE) \"$$replace(copy_config.depends, /, $$QMAKE_ QMAKE_EXTRA_TARGETS += copy_config PRE_TARGETDEPS += $$copy_config.target +copy_json.target = $$OUT_PWD/root/etc +copy_json.depends = $$_PRO_FILE_PWD_/etc +copy_json.commands = $(COPY_DIR) \"$$replace(copy_json.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_json.target, /, $$QMAKE_DIR_SEP)\" +QMAKE_EXTRA_TARGETS += copy_json +PRE_TARGETDEPS += $$copy_json.target + wgt.target = package wgt.commands = wgtpkg-pack -f -o homescreen.wgt root