aboutsummaryrefslogtreecommitdiffstats
path: root/homescreen/src
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-11-30 19:20:22 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-11-30 19:20:22 +0900
commit9e12877a80b90a1921a8e8714c0c5464779a6ba6 (patch)
tree7704ded0a8b755bbb619f2ad4f990720ea5afb82 /homescreen/src
parentfabcb8148b8032f4f8d04523e2f24cf8debe477f (diff)
Add feature : changeAreaSize
Diffstat (limited to 'homescreen/src')
-rw-r--r--homescreen/src/homescreenhandler.cpp71
-rw-r--r--homescreen/src/homescreenhandler.h19
-rw-r--r--homescreen/src/main.cpp43
3 files changed, 105 insertions, 28 deletions
diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp
index a655a5e..9125ecf 100644
--- a/homescreen/src/homescreenhandler.cpp
+++ b/homescreen/src/homescreenhandler.cpp
@@ -16,13 +16,15 @@
#include "homescreenhandler.h"
#include <functional>
+#include <QQmlApplicationEngine>
+#include <QtQuick/QQuickWindow>
#include "hmi-debug.h"
void* HomescreenHandler::myThis = 0;
HomescreenHandler::HomescreenHandler(QObject *parent) :
QObject(parent),
- mp_hs(NULL)
+ mp_hs(NULL), mp_wm(NULL), m_role()
{
}
@@ -32,10 +34,29 @@ HomescreenHandler::~HomescreenHandler()
if (mp_hs != NULL) {
delete mp_hs;
}
+ if (mp_wm != NULL) {
+ delete mp_wm;
+ }
}
-void HomescreenHandler::init(int port, const char *token)
+void HomescreenHandler::init(const char* role, int port, const char *token)
{
+ this->m_role = role;
+
+ // LibWindowManager initialize
+ mp_wm = new LibWindowmanager();
+ if(mp_wm->init(port,token) != 0){
+ exit(EXIT_FAILURE);
+ }
+
+ int surface = mp_wm->requestSurface(m_role.c_str());
+ if (surface < 0) {
+ exit(EXIT_FAILURE);
+ }
+ std::string ivi_id = std::to_string(surface);
+ setenv("QT_IVI_SURFACE_ID", ivi_id.c_str(), true);
+
+ // LibHomeScreen initialize
mp_hs = new LibHomeScreen();
mp_hs->init(port, token);
@@ -50,6 +71,52 @@ void HomescreenHandler::init(int port, const char *token)
});
}
+void HomescreenHandler::setWMHandler(WMHandler& h) {
+ h.on_sync_draw = [&](const char* role, const char* area, Rect r) {
+ this->mp_wm->endDraw(this->m_role.c_str());
+ };
+ mp_wm->setEventHandler(h);
+}
+
+void HomescreenHandler::disconnect_frame_swapped(void)
+{
+ qDebug("Let's start homescreen");
+ QObject::disconnect(this->loading);
+ mp_wm->activateWindow(m_role.c_str(), "fullscreen");
+}
+
+void HomescreenHandler::attach(QQmlApplicationEngine* engine)
+{
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(engine->rootObjects().first());
+ this->loading = QObject::connect(window, SIGNAL(frameSwapped()), this, SLOT(disconnect_frame_swapped()));
+}
+
+void HomescreenHandler::changeLayout(int pattern)
+{
+ HMI_NOTICE("HomeScreen", "Pressed %d, %s", pattern,
+ (pattern == P_LEFT_METER_RIGHT_MAP) ? "left:meter, right:map": "left:map, right:meter");
+ ChangeAreaReq req;
+ std::unordered_map<std::string, Rect> map_list;
+ switch(pattern) {
+ case P_LEFT_METER_RIGHT_MAP:
+ map_list["split.main"] = Rect(0, 0, 1280, 720);
+ map_list["split.sub"] = Rect(1280, 0, 640, 720);
+ break;
+ case P_LEFT_MAP_RIGHT_METER:
+ map_list["split.main"] = Rect(640, 0, 1280, 720);
+ map_list["split.sub"] = Rect(0, 0, 640, 720);
+ break;
+ default:
+ break;
+ }
+ if(map_list.size() != 0)
+ {
+ req.setAreaReq(map_list);
+ HMI_NOTICE("Homescreen", "Change layout");
+ mp_wm->changeAreaSize(req);
+ }
+}
+
void HomescreenHandler::tapShortcut(QString application_name)
{
HMI_DEBUG("HomeScreen","tapShortcut %s", application_name.toStdString().c_str());
diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h
index 99367d5..c32e6cc 100644
--- a/homescreen/src/homescreenhandler.h
+++ b/homescreen/src/homescreenhandler.h
@@ -19,20 +19,31 @@
#include <QObject>
#include <libhomescreen.hpp>
+#include <libwindowmanager.h>
#include <string>
using namespace std;
+class QQmlApplicationEngine;
+
class HomescreenHandler : public QObject
{
Q_OBJECT
public:
+ enum CHANGE_LAYOUT_PATTERN {
+ P_LEFT_METER_RIGHT_MAP = 0,
+ P_LEFT_MAP_RIGHT_METER
+ };
+ Q_ENUMS(CHANGE_LAYOUT_PATTERN)
explicit HomescreenHandler(QObject *parent = 0);
~HomescreenHandler();
- void init(int port, const char* token);
+ void init(const char* role, int port, const char* token);
+ void attach(QQmlApplicationEngine* engine);
+ void setWMHandler(WMHandler &handler);
Q_INVOKABLE void tapShortcut(QString application_name);
+ Q_INVOKABLE void changeLayout(int pattern);
void onRep(struct json_object* reply_contents);
void onEv(const string& event, struct json_object* event_contents);
@@ -45,8 +56,14 @@ signals:
void notification(QString id, QString icon, QString text);
void information(QString text);
+private Q_SLOTS:
+ void disconnect_frame_swapped(void);
+
private:
LibHomeScreen *mp_hs;
+ LibWindowmanager *mp_wm;
+ std::string m_role;
+ QMetaObject::Connection loading;
};
#endif // HOMESCREENHANDLER_H
diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp
index 08f83a8..6479cd9 100644
--- a/homescreen/src/main.cpp
+++ b/homescreen/src/main.cpp
@@ -24,7 +24,6 @@
#include <QQuickWindow>
#include <QThread>
-#include <qlibwindowmanager.h>
#include <weather.h>
#include <bluetooth.h>
#include "applicationlauncher.h"
@@ -57,6 +56,7 @@ void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
+ const char* graphic_role = "homescreen";
// use launch process
QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
@@ -94,16 +94,7 @@ int main(int argc, char *argv[])
ApplicationLauncher *launcher = new ApplicationLauncher();
HomescreenHandler* homescreenHandler = new HomescreenHandler();
- homescreenHandler->init(port, token.toStdString().c_str());
-
- QLibWindowmanager* layoutHandler = new QLibWindowmanager();
- if(layoutHandler->init(port,token) != 0){
- exit(EXIT_FAILURE);
- }
-
- if (layoutHandler->requestSurface(QString("homescreen")) != 0) {
- exit(EXIT_FAILURE);
- }
+ homescreenHandler->init(graphic_role, port, token.toStdString().c_str());
QUrl bindingAddress;
bindingAddress.setScheme(QStringLiteral("ws"));
@@ -119,7 +110,6 @@ int main(int argc, char *argv[])
// mail.qml loading
QQmlApplicationEngine engine;
-// engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler);
engine.rootContext()->setContextProperty("touchArea", touchArea);
engine.rootContext()->setContextProperty("launcher", launcher);
@@ -129,27 +119,32 @@ int main(int argc, char *argv[])
QObject *root = engine.rootObjects().first();
- layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler](json_object *object) {
- layoutHandler->endDraw(QString("homescreen"));
- });
-
- layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher, root](json_object *object) {
- json_object *jarray = json_object_object_get(object, "ids");
- int arrLen = json_object_array_length(jarray);
+ WMHandler wmh;
+ wmh.on_screen_updated = [launcher, root](std::vector<std::string> list) {
+ for(const auto& i : list) {
+ HMI_DEBUG("HomeScreen", "ids=%s", i.c_str());
+ }
+ int arrLen = list.size();
+ QString label = QString("");
for( int idx = 0; idx < arrLen; idx++)
{
- QString label = QString(json_object_get_string( json_object_array_get_idx(jarray, idx) ));
+ label = list[idx].c_str();
HMI_DEBUG("HomeScreen","Event_ScreenUpdated application: %s.", label.toStdString().c_str());
QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label));
if(label == "launcher") {
QMetaObject::invokeMethod(root, "turnToNormal");
-// homescreenHandler->emitTurnToFullscreen(false);
} else {
QMetaObject::invokeMethod(root, "turnToFullscreen");
-// homescreenHandler->emitTurnToFullscreen(true);
+ }
+ if((arrLen == 1) && (QString("restriction") != label)) {
+ QMetaObject::invokeMethod(root, "disableSplitSwitchBtn");
+ } else {
+ QMetaObject::invokeMethod(root, "enableSplitSwitchBtn");
}
}
- });
+ };
+ homescreenHandler->setWMHandler(wmh);
+ homescreenHandler->attach(&engine);
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
@@ -164,7 +159,5 @@ int main(int argc, char *argv[])
StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar");
statusBar->init(bindingAddress, engine.rootContext());
- QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface()));
-
return a.exec();
}