-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainview.cpp
94 lines (80 loc) · 2.74 KB
/
mainview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*************************************************************************
**
** (C) Copyright 2013 Reach Technology Inc.
**
** This code is protected by international copyright laws. This file may
** only be used in accordance with a license and cannot be used on
** hardware other than supplied by Reach Technology Inc. We appreciate
** your understanding and fairness.
**
*************************************************************************/
#include "mainview.h"
MainView::MainView(QWidget *parent) :
QDeclarativeView(parent)
,m_connection(new Connection(this))
,m_messageHandler(new MessageHandler)
,m_settings(new Settings(this))
,m_screen(new Screen(this))
,m_enableAck(false)
{
this->rootContext()->setContextProperty("connection", m_connection);
this->rootContext()->setContextProperty("settings", m_settings);
this->rootContext()->setContextProperty("screen", m_screen);
connect(m_connection,SIGNAL(readyToSend()),this,SLOT(onConnectionReady()));
connect(m_connection,SIGNAL(notReadyToSend()),this,SLOT(onConnectionClosed()));
connect(m_connection,SIGNAL(messageAvailable(QByteArray)),m_messageHandler,SLOT(onMessageAvailable(QByteArray)));
connect(m_connection,SIGNAL(lookupAckChanged(bool)),this,SLOT(enableLookupAck(bool)));
connect(m_messageHandler,SIGNAL(messageAvailable(QString,QString,QVariant)),this,SLOT(onMessageAvailable(QString,QString,QVariant)));
connect(m_messageHandler,SIGNAL(messageSyntaxError(QByteArray)),this,SLOT(onMessageSyntaxError(QByteArray)));
}
MainView::~MainView()
{
}
void MainView::onMessageAvailable(const QString &item, const QString &property, const QVariant &value)
{
QDeclarativeItem *obj = this->rootObject()->findChild<QDeclarativeItem*>(item);
if(!obj) {
qDebug() << "[QML] no item with objectName: " << item;
if(m_enableAck) {
m_connection->sendMessage("LUNO");
}
return;
}
bool found = obj->setProperty(property.toLatin1(),value);
if (!found) {
qDebug() << "[QML] no property on objectName: " << property;
if(m_enableAck) {
m_connection->sendMessage("LUNP");
}
return;
}
if(m_enableAck) {
m_connection->sendMessage("LUOK");
}
}
void MainView::onMessageSyntaxError(const QByteArray &msg)
{
if(m_enableAck) {
m_connection->sendMessage("SYNERR");
}
}
void MainView::enableLookupAck(bool enable)
{
m_enableAck = enable;
if (m_enableAck)
{
qDebug() << "[QML] Ack enabled";
}
else
{
qDebug() << "[QML] Ack disabled";
}
}
void MainView::onConnectionReady()
{
qDebug() << "[QML] connection open";
}
void MainView::onConnectionClosed()
{
qDebug() << "[QML] connection closed";
}