summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2011-11-23 13:49:15 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-08 06:20:47 +0100
commit2a345c6af2201d02b5685187f9db0911969bbf2e (patch)
tree71d3c41b7216a415936cab896e932717945d8ca6 /src/plugins
parent19cd6c6744c5886da37de83b79b58ee3059e5998 (diff)
add simulator plugin for sensorgestures.
Change-Id: I7ec82ef7ee7795f6d8528f9ebd9d70b80435b7ea Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/sensorgestures/sensorgestures.pro3
-rw-r--r--src/plugins/sensorgestures/simulator/qsimulatorrecognizer.cpp107
-rw-r--r--src/plugins/sensorgestures/simulator/qsimulatorrecognizer.h78
-rw-r--r--src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.cpp80
-rw-r--r--src/plugins/sensorgestures/simulator/qsimulatorsensorgestureplugin.h66
-rw-r--r--src/plugins/sensorgestures/simulator/simulator.pro24
-rw-r--r--src/plugins/sensorgestures/simulator/simulatorgesturescommon.cpp100
-rw-r--r--src/plugins/sensorgestures/simulator/simulatorgesturescommon.h79
8 files changed, 536 insertions, 1 deletions
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 <QDebug>
+#include <QTimer>
+#include <QFile>
+
+#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 <QDebug>
+#include <QTimer>
+
+#include <qsensorgesturerecognizer.h>
+
+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 <QtPlugin>
+#include <QStringList>
+#include <QObject>
+
+#include "qsimulatorsensorgestureplugin.h"
+
+#include <qsensorgestureplugininterface.h>
+#include <qsensorgesturemanager.h>
+
+#include "qsimulatorrecognizer.h"
+
+
+QSimulatorSensorGesturePlugin::QSimulatorSensorGesturePlugin()
+{
+}
+
+QSimulatorSensorGesturePlugin::~QSimulatorSensorGesturePlugin()
+{
+}
+
+QStringList QSimulatorSensorGesturePlugin::supportedIds() const
+{
+ QStringList list;
+ list << "shake";
+ return list;
+}
+
+QList <QSensorGestureRecognizer *> QSimulatorSensorGesturePlugin::createRecognizers()
+{
+ QList <QSensorGestureRecognizer *> 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 <QObject>
+#include <QStringList>
+
+#include <qsensorgestureplugininterface.h>
+
+class QSimulatorSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
+
+public:
+ explicit QSimulatorSensorGesturePlugin();
+ ~QSimulatorSensorGesturePlugin();
+
+ QList <QSensorGestureRecognizer *> 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 <QtSimulator/version.h>
+#include <QDebug>
+#include <QStringList>
+
+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 <QtSimulator/connection.h>
+#include <QtSimulator/connectionworker.h>
+
+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
+