diff options
Diffstat (limited to 'homescreen/src')
-rw-r--r-- | homescreen/src/homescreenhandler.cpp | 53 | ||||
-rw-r--r-- | homescreen/src/homescreenhandler.h | 10 | ||||
-rw-r--r-- | homescreen/src/main.cpp | 20 | ||||
-rw-r--r-- | homescreen/src/toucharea.cpp | 36 | ||||
-rw-r--r-- | homescreen/src/toucharea.h | 30 |
5 files changed, 142 insertions, 7 deletions
diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp index daf1b90..2d51099 100644 --- a/homescreen/src/homescreenhandler.cpp +++ b/homescreen/src/homescreenhandler.cpp @@ -49,12 +49,61 @@ void HomescreenHandler::init(int port, const char *token) HMI_DEBUG("HomeScreen","set_event_handler Event_OnScreenMessage display_message = %s", display_message); }); + mp_hs->set_event_handler(LibHomeScreen::Event_ShowNotification,[this](json_object *object){ + const char *application_id = json_object_get_string( + json_object_object_get(object, "application_id")); + + json_object *p_obj = json_object_object_get(object, "parameter"); + const char *icon = json_object_get_string( + json_object_object_get(p_obj, "icon")); + const char *text = json_object_get_string( + json_object_object_get(p_obj, "text")); + QFileInfo icon_file(icon); + QString icon_path; + if (icon_file.exists()) { + icon_path = QString(QLatin1String(icon)); + } else { + icon_path = "./images/Utility_Logo_Grey-01.svg"; + } + + emit showNotification(QString(QLatin1String(application_id)), icon_path, QString(QLatin1String(text))); + }); + + mp_hs->set_event_handler(LibHomeScreen::Event_ShowInformation,[this](json_object *object){ + json_object *p_obj = json_object_object_get(object, "parameter"); + const char *info = json_object_get_string( + json_object_object_get(p_obj, "info")); + + emit showInformation(QString(QLatin1String(info))); + }); } -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()); - mp_hs->tapShortcut(application_id.toStdString().c_str()); + struct json_object* j_json = json_object_new_object(); + struct json_object* value; + if(is_full) { + value = json_object_new_string("fullscreen"); + HMI_DEBUG("HomeScreen","tapShortcut fullscreen"); + } else { + value = json_object_new_string("normal"); + HMI_DEBUG("HomeScreen","tapShortcut normal"); + } + json_object_object_add(j_json, "area", value); + mp_hs->showWindow(application_id.toStdString().c_str(), j_json); +} + +void HomescreenHandler::setCurrentApplication(QString application_id) +{ + HMI_DEBUG("HomeScreen","setCurrentApplication %s", application_id.toStdString().c_str()); + current_applciation = application_id; +} + +QString HomescreenHandler::getCurrentApplication() +{ + HMI_DEBUG("HomeScreen","getCurrentApplication %s", current_applciation.toStdString().c_str()); + return current_applciation; } void HomescreenHandler::onRep_static(struct json_object* reply_contents) diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h index 1a9a2b5..d31d6af 100644 --- a/homescreen/src/homescreenhandler.h +++ b/homescreen/src/homescreenhandler.h @@ -20,6 +20,7 @@ #include <QObject> #include <libhomescreen.hpp> #include <string> +#include <QFileInfo> using namespace std; @@ -32,7 +33,9 @@ public: void init(int port, const char* token); - Q_INVOKABLE void tapShortcut(QString application_id); + Q_INVOKABLE void tapShortcut(QString application_id, bool is_full); + Q_INVOKABLE QString getCurrentApplication(); + void setCurrentApplication(QString application_id); void onRep(struct json_object* reply_contents); void onEv(const string& event, struct json_object* event_contents); @@ -40,8 +43,13 @@ public: static void* myThis; static void onRep_static(struct json_object* reply_contents); static void onEv_static(const string& event, struct json_object* event_contents); + +signals: + void showNotification(QString application_id, QString icon_path, QString text); + void showInformation(QString info); private: LibHomeScreen *mp_hs; + QString current_applciation; }; #endif // HOMESCREENHANDLER_H diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index 620c869..7a7aa71 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -22,6 +22,7 @@ #include <QtQml/QQmlContext> #include <QtQml/qqml.h> #include <QQuickWindow> +#include <QThread> #include <qlibwindowmanager.h> #include <weather.h> @@ -32,6 +33,7 @@ #include "mastervolume.h" #include "homescreenhandler.h" #include "hmi-debug.h" +#include "toucharea.h" // XXX: We want this DBus connection to be shared across the different // QML objects, is there another way to do this, a nice way, perhaps? @@ -93,6 +95,9 @@ int main(int argc, char *argv[]) ApplicationLauncher *launcher = new ApplicationLauncher(); QLibWindowmanager* layoutHandler = new QLibWindowmanager(); + TouchArea* touchArea = new TouchArea(); + HomescreenHandler* homescreenHandler = new HomescreenHandler(); + homescreenHandler->init(port, token.toStdString().c_str()); if(layoutHandler->init(port,token) != 0){ exit(EXIT_FAILURE); } @@ -107,20 +112,18 @@ int main(int argc, char *argv[]) layoutHandler->endDraw(QString("HomeScreen")); }); - layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher](json_object *object) { + layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher, homescreenHandler](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()); + homescreenHandler->setCurrentApplication(label); QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label)); } }); - HomescreenHandler* homescreenHandler = new HomescreenHandler(); - homescreenHandler->init(port, token.toStdString().c_str()); - QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); bindingAddress.setHost(QStringLiteral("localhost")); @@ -139,10 +142,19 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("weather", new Weather(bindingAddress)); engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress)); engine.rootContext()->setContextProperty("screenInfo", &screenInfo); + engine.rootContext()->setContextProperty("touchArea", touchArea); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *root = engine.rootObjects().first(); QQuickWindow *window = qobject_cast<QQuickWindow *>(root); + + touchArea->setWindow(window); + QThread* thread = new QThread; + touchArea->moveToThread(thread); + QObject::connect(thread, &QThread::started, touchArea, &TouchArea::init); + + thread->start(); + QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface())); QList<QObject *> sobjs = engine.rootObjects(); 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 <QBitmap> +#include <QQuickWindow> + +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 |