From 2a345c6af2201d02b5685187f9db0911969bbf2e Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 23 Nov 2011 13:49:15 +1000 Subject: add simulator plugin for sensorgestures. Change-Id: I7ec82ef7ee7795f6d8528f9ebd9d70b80435b7ea Sanity-Review: Qt Sanity Bot Reviewed-by: Lincoln Ramsay --- src/plugins/sensorgestures/sensorgestures.pro | 3 +- .../simulator/qsimulatorrecognizer.cpp | 107 +++++++++++++++++++++ .../simulator/qsimulatorrecognizer.h | 78 +++++++++++++++ .../simulator/qsimulatorsensorgestureplugin.cpp | 80 +++++++++++++++ .../simulator/qsimulatorsensorgestureplugin.h | 66 +++++++++++++ src/plugins/sensorgestures/simulator/simulator.pro | 24 +++++ .../simulator/simulatorgesturescommon.cpp | 100 +++++++++++++++++++ .../simulator/simulatorgesturescommon.h | 79 +++++++++++++++ 8 files changed, 536 insertions(+), 1 deletion(-) create mode 100644 src/plugins/sensorgestures/simulator/qsimulatorrecognizer.cpp create mode 100644 src/plugins/sensorgestures/simulator/qsimulatorrecognizer.h create mode 100644 src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.cpp create mode 100644 src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.h create mode 100644 src/plugins/sensorgestures/simulator/simulator.pro create mode 100644 src/plugins/sensorgestures/simulator/simulatorgesturescommon.cpp create mode 100644 src/plugins/sensorgestures/simulator/simulatorgesturescommon.h (limited to 'src/plugins') diff --git a/src/plugins/sensorgestures/sensorgestures.pro b/src/plugins/sensorgestures/sensorgestures.pro index e300fa77..18898807 100644 --- a/src/plugins/sensorgestures/sensorgestures.pro +++ b/src/plugins/sensorgestures/sensorgestures.pro @@ -1,2 +1,3 @@ TEMPLATE = subdirs -SUBDIRS += shake +!simulator:SUBDIRS += shake +simulator:SUBDIRS += simulator diff --git a/src/plugins/sensorgestures/simulator/qsimulatorrecognizer.cpp b/src/plugins/sensorgestures/simulator/qsimulatorrecognizer.cpp new file mode 100644 index 00000000..904cd88e --- /dev/null +++ b/src/plugins/sensorgestures/simulator/qsimulatorrecognizer.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "qsimulatorrecognizer.h" +#include "simulatorgesturescommon.h" + +QSimulatorSensorGestureRecognizer::QSimulatorSensorGestureRecognizer(QObject *parent) + : QSensorGestureRecognizer(parent) +{ + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); + + timer->setInterval(1000); +} + +QSimulatorSensorGestureRecognizer::~QSimulatorSensorGestureRecognizer() +{ + if (timer->isActive()) + timer->stop(); +} + +void QSimulatorSensorGestureRecognizer::create() +{ + SensorGesturesConnection *connection = new SensorGesturesConnection(this); + connect(connection,SIGNAL(sensorGestureDetected()),this,SLOT(sensorGestureDetected())); +} + +void QSimulatorSensorGestureRecognizer::sensorGestureDetected() +{ + detectingState = true; +} + + +bool QSimulatorSensorGestureRecognizer::start() +{ + timer->start(); + timeout(); + return timer->isActive(); +} + +bool QSimulatorSensorGestureRecognizer::stop() +{ + timer->stop(); + return timer->isActive(); +} + + +bool QSimulatorSensorGestureRecognizer::isActive() +{ + return timer->isActive(); +} + +QString QSimulatorSensorGestureRecognizer::id() const +{ + return QString("QtSensors.simulator"); +} + +void QSimulatorSensorGestureRecognizer::timeout() +{ + if (detectingState) { + QString str = get_qtSensorGestureData(); + emit detected(str); + detectingState = false; + } +} diff --git a/src/plugins/sensorgestures/simulator/qsimulatorrecognizer.h b/src/plugins/sensorgestures/simulator/qsimulatorrecognizer.h new file mode 100644 index 00000000..2c62ffc0 --- /dev/null +++ b/src/plugins/sensorgestures/simulator/qsimulatorrecognizer.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSIMULATORRECOGNIZER_H +#define QSIMULATORRECOGNIZER_H + +#include +#include + +#include + +class QSimulatorSensorGestureRecognizer : public QSensorGestureRecognizer +{ + Q_OBJECT + +public: + + QSimulatorSensorGestureRecognizer(QObject *parent = 0); + ~QSimulatorSensorGestureRecognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + +Q_SIGNALS: + void simulator(); + +private slots: + void timeout(); + void sensorGestureDetected(); +private: + bool detectingState; + QTimer *timer; + +}; + +#endif // QSHAKERECOGNIZER_H diff --git a/src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.cpp b/src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.cpp new file mode 100644 index 00000000..285079e3 --- /dev/null +++ b/src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "qsimulatorsensorgestureplugin.h" + +#include +#include + +#include "qsimulatorrecognizer.h" + + +QSimulatorSensorGesturePlugin::QSimulatorSensorGesturePlugin() +{ +} + +QSimulatorSensorGesturePlugin::~QSimulatorSensorGesturePlugin() +{ +} + +QStringList QSimulatorSensorGesturePlugin::supportedIds() const +{ + QStringList list; + list << "shake"; + return list; +} + +QList QSimulatorSensorGesturePlugin::createRecognizers() +{ + QList recognizers; + + QSensorGestureRecognizer *sRec = new QSimulatorSensorGestureRecognizer(this); + recognizers.append(sRec); + + return recognizers; +} + +Q_EXPORT_PLUGIN2(QSimulatorSensorGestureRecognizer, QSimulatorSensorGesturePlugin) + diff --git a/src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.h b/src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.h new file mode 100644 index 00000000..d075e897 --- /dev/null +++ b/src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSIMULATORSENSORGESTUREPLUGIN_H +#define QSIMULATORSENSORGESTUREPLUGIN_H + +#include +#include + +#include + +class QSimulatorSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface) + +public: + explicit QSimulatorSensorGesturePlugin(); + ~QSimulatorSensorGesturePlugin(); + + QList createRecognizers(); + + QStringList gestureSignals() const; + QStringList supportedIds() const; + QString name() const { return "SimulatorGestures"; } +}; + +#endif // QSIMULATORSENSORGESTUREPLUGIN_H diff --git a/src/plugins/sensorgestures/simulator/simulator.pro b/src/plugins/sensorgestures/simulator/simulator.pro new file mode 100644 index 00000000..015d01f0 --- /dev/null +++ b/src/plugins/sensorgestures/simulator/simulator.pro @@ -0,0 +1,24 @@ +load(qt_module) + +TARGET = qtsensorgestures_simulator +load(qt_plugin) + +DESTDIR = $$QT.sensors.plugins/sensorgestures + +QT=core gui network sensors simulator + +target.path += $$[QT_INSTALL_PLUGINS]/sensorgestures +INSTALLS += target + +HEADERS += \ + simulatorgesturescommon.h\ + qsimulatorrecognizer.h\ + qsimulatorsensorgestureplugin.h + + +SOURCES += \ + simulatorgesturescommon.cpp\ + qsimulatorrecognizer.cpp\ + qsimulatorsensorgestureplugin.cpp + + diff --git a/src/plugins/sensorgestures/simulator/simulatorgesturescommon.cpp b/src/plugins/sensorgestures/simulator/simulatorgesturescommon.cpp new file mode 100644 index 00000000..0f377f9d --- /dev/null +++ b/src/plugins/sensorgestures/simulator/simulatorgesturescommon.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "simulatorgesturescommon.h" + +#include +#include +#include + +using namespace Simulator; + + +Q_GLOBAL_STATIC(QString, qtSensorGestureData) + +SensorGesturesConnection::SensorGesturesConnection(QObject *parent) + : QObject(parent) +{ + mConnection = new Connection(Connection::Client, "QtSimulator_Mobility_ServerName1.3.0.0", 0xbeef+1, Version(1,0,0,0), this); + mWorker = mConnection->connectToServer(Connection::simulatorHostName(true), 0xbeef+1); + + if (!mWorker) { + qWarning() << "Could not connect to server"; + return; + } + newSensorGestures(); + + mWorker->addReceiver(this); + mWorker->call("setRequestsSensorGestures"); +} + +SensorGesturesConnection::~SensorGesturesConnection() +{ + delete mWorker; +} + +void SensorGesturesConnection::setSensorGestureData(const QString &data) +{ + QString gesture = data; + if (data.contains("detected")) { + gesture.remove("detected("); + gesture.remove(")"); + } + *qtSensorGestureData() = gesture; +} + +void SensorGesturesConnection::newSensorGestureDetected() +{ + emit sensorGestureDetected(); +} + +void SensorGesturesConnection::newSensorGestures() +{ + QStringList allGestures; + allGestures << "shake"; + mWorker->call("setSensorGestures", allGestures); +} + +QString get_qtSensorGestureData() +{ + return *qtSensorGestureData(); +} + diff --git a/src/plugins/sensorgestures/simulator/simulatorgesturescommon.h b/src/plugins/sensorgestures/simulator/simulatorgesturescommon.h new file mode 100644 index 00000000..c7d85adb --- /dev/null +++ b/src/plugins/sensorgestures/simulator/simulatorgesturescommon.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SIMULATORGESTURESCOMMON_H +#define SIMULATORGESTURESCOMMON_H + +#include +#include + +class QTimer; + +namespace Simulator +{ + class Connection; + class ConnectionWorker; +} + +class SensorGesturesConnection : public QObject +{ + Q_OBJECT +public: + explicit SensorGesturesConnection(QObject *parent = 0); + virtual ~SensorGesturesConnection(); + +Q_SIGNALS: + void sensorGestureDetected(); + +public slots: + void setSensorGestureData(const QString &); + void newSensorGestureDetected(); + void newSensorGestures(); + +private: + Simulator::Connection *mConnection; + Simulator::ConnectionWorker *mWorker; +}; + +QString get_qtSensorGestureData(); + +#endif //SIMULATORGESTURESCOMMON_H + -- cgit v1.2.3