summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp
diff options
context:
space:
mode:
authorKevin Krammer <kevin.krammer.qnx@kdab.com>2012-04-10 11:26:12 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-12 15:00:33 +0200
commit4fac40f8b0e7b2a6f5f41eb82196e8b197bc851a (patch)
tree756147e942b5cf20c45cdeb2ad62ec0b63e618e1 /src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp
parent28675642f3445e41434b004c2a1a1d96ec0145a2 (diff)
Refactor navigator event handling
Separate PPS based navigator event notification handling and implementation of the actual event handling. Like the similar refactoring for screen events, this will allow to reuse the same event handler class for BPS driven event processing. Change-Id: I29d4a082cb01ff7943b7822ea9aa8ad622fda593 Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp')
-rw-r--r--src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp210
1 files changed, 26 insertions, 184 deletions
diff --git a/src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp b/src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp
index 9527a57ca3..72227c6089 100644
--- a/src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp
+++ b/src/plugins/platforms/qnx/qqnxnavigatoreventhandler.cpp
@@ -1,6 +1,6 @@
/***************************************************************************
**
-** Copyright (C) 2011 - 2012 Research In Motion
+** Copyright (C) 2012 Research In Motion
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
@@ -41,216 +41,58 @@
#include "qqnxnavigatoreventhandler.h"
-#include <QtGui/QGuiApplication>
-#include <QtGui/QWindow>
-#include <QtGui/QWindowSystemInterface>
+#include <QDebug>
+#include <QGuiApplication>
+#include <QWindowSystemInterface>
-#include <QtCore/QByteArray>
-#include <QtCore/QDebug>
-#include <QtCore/QList>
-#include <QtCore/QSocketNotifier>
-#include <QtCore/private/qcore_unix_p.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-static const char *navigatorControlPath = "/pps/services/navigator/control";
-static const int ppsBufferSize = 4096;
+QT_BEGIN_NAMESPACE
QQnxNavigatorEventHandler::QQnxNavigatorEventHandler(QObject *parent)
- : QObject(parent),
- m_fd(-1),
- m_readNotifier(0)
-{
-}
-
-QQnxNavigatorEventHandler::~QQnxNavigatorEventHandler()
+ : QObject(parent)
{
- delete m_readNotifier;
-
- // close connection to navigator
- if (m_fd != -1)
- close(m_fd);
-
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "QQNX: navigator event handler stopped";
-#endif
}
-void QQnxNavigatorEventHandler::start()
+bool QQnxNavigatorEventHandler::handleOrientationCheck(int angle)
{
+ // reply to navigator that (any) orientation is acceptable
#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "QQNX: navigator event handler started";
+ qDebug() << Q_FUNC_INFO << "angle=" << angle;
#endif
- // open connection to navigator
- errno = 0;
- m_fd = open(navigatorControlPath, O_RDWR);
- if (m_fd == -1) {
- qWarning("QQNX: failed to open navigator pps, errno=%d", errno);
- return;
- }
-
- m_readNotifier = new QSocketNotifier(m_fd, QSocketNotifier::Read);
- connect(m_readNotifier, SIGNAL(activated(int)), this, SLOT(readData()));
+ // TODO: check if top window flags prohibit orientation change
+ return true;
}
-void QQnxNavigatorEventHandler::parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id)
+void QQnxNavigatorEventHandler::handleOrientationChange(int angle)
{
+ // update screen geometry and reply to navigator that we're ready
#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: data=" << ppsData;
-#endif
-
- // tokenize pps data into lines
- QList<QByteArray> lines = ppsData.split('\n');
-
- // validate pps object
- if (lines.size() == 0 || lines.at(0) != "@control") {
- qFatal("QQNX: unrecognized pps object, data=%s", ppsData.constData());
- }
-
- // parse pps object attributes and extract values
- for (int i = 1; i < lines.size(); i++) {
-
- // tokenize current attribute
- const QByteArray &attr = lines.at(i);
-
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: attr=" << attr;
-#endif
-
- int firstColon = attr.indexOf(':');
- if (firstColon == -1) {
- // abort - malformed attribute
- continue;
- }
-
- int secondColon = attr.indexOf(':', firstColon + 1);
- if (secondColon == -1) {
- // abort - malformed attribute
- continue;
- }
-
- QByteArray key = attr.left(firstColon);
- QByteArray value = attr.mid(secondColon + 1);
-
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: key=" << key;
- qDebug() << "PPS: val=" << value;
+ qDebug() << Q_FUNC_INFO << "angle=" << angle;
#endif
- // save attribute value
- if (key == "msg") {
- msg = value;
- } else if (key == "dat") {
- dat = value;
- } else if (key == "id") {
- id = value;
- } else {
- qFatal("QQNX: unrecognized pps attribute, attr=%s", key.constData());
- }
- }
+ emit rotationChanged(angle);
}
-void QQnxNavigatorEventHandler::replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat)
+void QQnxNavigatorEventHandler::handleSwipeDown()
{
- // construct pps message
- QByteArray ppsData = "res::";
- ppsData += res;
- ppsData += "\nid::";
- ppsData += id;
- if (!dat.isEmpty()) {
- ppsData += "\ndat::";
- ppsData += dat;
- }
- ppsData += "\n";
-
+ // simulate menu key press
#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS reply=" << ppsData;
+ qDebug() << Q_FUNC_INFO;
#endif
- // send pps message to navigator
- errno = 0;
- int bytes = write(m_fd, ppsData.constData(), ppsData.size());
- if (bytes == -1) {
- qFatal("QQNX: failed to write navigator pps, errno=%d", errno);
- }
+ QWindow *w = QGuiApplication::focusWindow();
+ QWindowSystemInterface::handleKeyEvent(w, QEvent::KeyPress, Qt::Key_Menu, Qt::NoModifier);
+ QWindowSystemInterface::handleKeyEvent(w, QEvent::KeyRelease, Qt::Key_Menu, Qt::NoModifier);
}
-void QQnxNavigatorEventHandler::handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id)
+void QQnxNavigatorEventHandler::handleExit()
{
+ // shutdown everything
#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: msg=" << msg << ", dat=" << dat << ", id=" << id;
+ qDebug() << Q_FUNC_INFO;
#endif
- // check message type
- if (msg == "orientationCheck") {
-
- // reply to navigator that (any) orientation is acceptable
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: orientation check, o=" << dat;
-#endif
- replyPPS(msg, id, "true");
-
- } else if (msg == "orientation") {
-
- // update screen geometry and reply to navigator that we're ready
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: orientation, o=" << dat;
-#endif
- Q_EMIT rotationChanged(dat.toInt());
- replyPPS(msg, id, "");
-
- } else if (msg == "SWIPE_DOWN") {
-
- // simulate menu key press
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: menu";
-#endif
- QWindow *w = QGuiApplication::focusWindow();
- QWindowSystemInterface::handleKeyEvent(w, QEvent::KeyPress, Qt::Key_Menu, Qt::NoModifier);
- QWindowSystemInterface::handleKeyEvent(w, QEvent::KeyRelease, Qt::Key_Menu, Qt::NoModifier);
-
- } else if (msg == "exit") {
-
- // shutdown everything
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "PPS: exit";
-#endif
- QCoreApplication::quit();
- }
+ QCoreApplication::quit();
}
-void QQnxNavigatorEventHandler::readData()
-{
-#if defined(QQNXNAVIGATOREVENTHANDLER_DEBUG)
- qDebug() << "QQNX: reading navigator data";
-#endif
- // allocate buffer for pps data
- char buffer[ppsBufferSize];
-
- // attempt to read pps data
- errno = 0;
- int bytes = qt_safe_read(m_fd, buffer, ppsBufferSize - 1);
- if (bytes == -1) {
- qFatal("QQNX: failed to read navigator pps, errno=%d", errno);
- }
-
- // check if pps data was received
- if (bytes > 0) {
-
- // ensure data is null terminated
- buffer[bytes] = '\0';
-
- // process received message
- QByteArray ppsData(buffer);
- QByteArray msg;
- QByteArray dat;
- QByteArray id;
- parsePPS(ppsData, msg, dat, id);
- handleMessage(msg, dat, id);
- }
-}
+QT_END_NAMESPACE