summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@gmail.com>2012-09-12 13:51:23 +1000
committerLorn Potter <lorn.potter@gmail.com>2012-11-07 22:15:49 +0100
commit182969371548eb3c17f7fe605898cdb2588b9226 (patch)
tree5fd304b6bdbba5c9402abe86d51976bdf7aa16ee /src
parentcfe9f4be6f2c5529d42686fa67650bae43395e38 (diff)
backport sensor gestures from qt 5
Change-Id: I0ce06c6859d471b4cada6e7ea908f62d32879ca2 Reviewed-by: Lorn Potter <lorn.potter@gmail.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/sensors/gestures/qsensorgesture.cpp226
-rw-r--r--src/sensors/gestures/qsensorgesture.h87
-rw-r--r--src/sensors/gestures/qsensorgesture_p.h82
-rw-r--r--src/sensors/gestures/qsensorgesturemanager.cpp142
-rw-r--r--src/sensors/gestures/qsensorgesturemanager.h80
-rw-r--r--src/sensors/gestures/qsensorgesturemanagerprivate.cpp252
-rw-r--r--src/sensors/gestures/qsensorgesturemanagerprivate_p.h103
-rw-r--r--src/sensors/gestures/qsensorgestureplugininterface.cpp99
-rw-r--r--src/sensors/gestures/qsensorgestureplugininterface.h73
-rw-r--r--src/sensors/gestures/qsensorgesturerecognizer.cpp221
-rw-r--r--src/sensors/gestures/qsensorgesturerecognizer.h84
-rw-r--r--src/sensors/gestures/simulatorgesturescommon.cpp123
-rw-r--r--src/sensors/gestures/simulatorgesturescommon_p.h94
-rw-r--r--src/sensors/sensors.pro17
14 files changed, 1683 insertions, 0 deletions
diff --git a/src/sensors/gestures/qsensorgesture.cpp b/src/sensors/gestures/qsensorgesture.cpp
new file mode 100644
index 0000000000..467b3a5daf
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesture.cpp
@@ -0,0 +1,226 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDir>
+#include <QPluginLoader>
+#include <QDebug>
+
+#include "qsensorgesture.h"
+#include "qsensorgesture_p.h"
+#include "qsensorgesturemanager.h"
+
+QTM_BEGIN_NAMESPACE
+
+/*!
+ \class QSensorGesture
+ \ingroup sensorgestures_main
+ \inmodule QtSensors
+
+ \brief The QSensorGesture class represents one or more sensor gesture recognizers.
+
+
+ \sa QSensorGestureRecognizer
+
+ You may use QSensorGestureManager to obtain the systems known sensor gesture ids.
+
+ \sa QSensorGestureManager
+ */
+
+/*!
+ \fn QSensorGesture::detected(QString gestureId)
+ Signals when the \a gestureId gesture has been recognized.
+ */
+
+/*!
+ Constructs the sensor gesture, and initializes the \a ids list of recognizers,
+ with parent \a parent
+ */
+QSensorGesture::QSensorGesture(const QStringList &ids, QObject *parent) :
+ QObject(parent)
+{
+ d_ptr = new QSensorGesturePrivate();
+ Q_FOREACH (const QString &id, ids) {
+ QSensorGestureRecognizer * rec = QSensorGestureManager::sensorGestureRecognizer(id);
+ if (rec != 0) {
+ d_ptr->m_sensorRecognizers.append(rec);
+ d_ptr->availableIds.append(id);
+ } else {
+ d_ptr->invalidIds.append(id);
+ //add to not available things
+ }
+ }
+
+// d_ptr->meta = 0;
+
+// QMetaObjectBuilder builder;
+// builder.setSuperClass(&QObject::staticMetaObject);
+// builder.setClassName("QSensorGesture");
+
+// Q_FOREACH (QSensorGestureRecognizer *recognizer, d_ptr->m_sensorRecognizers) {
+// Q_FOREACH (const QString &gesture, recognizer->gestureSignals()) {
+// QMetaMethodBuilder b = builder.addSignal(gesture.toLatin1());
+// if (!d_ptr->localGestureSignals.contains(QLatin1String(b.signature())))
+// d_ptr->localGestureSignals.append(QLatin1String(b.signature()));
+// }
+// recognizer->createBackend();
+// }
+// d_ptr->meta = builder.toMetaObject();
+
+ if (d_ptr->m_sensorRecognizers.count() > 0) {
+ d_ptr->valid = true;
+ }
+}
+
+/*!
+ Destroy the QSensorGesture
+ */
+QSensorGesture::~QSensorGesture()
+{
+ stopDetection();
+// if (d_ptr->meta)
+// free(d_ptr->meta);
+// delete d_ptr;
+}
+
+/*!
+ Returns the gesture recognizer ids that were found.
+ */
+QStringList QSensorGesture::validIds() const
+{
+ return d_ptr->availableIds;
+}
+
+/*!
+ Returns the gesture recognizer ids that were not found.
+ */
+QStringList QSensorGesture::invalidIds() const
+{
+ return d_ptr->invalidIds;
+}
+
+/*!
+ Starts the gesture detection routines in the recognizer.
+ */
+void QSensorGesture::startDetection()
+{
+ if (d_ptr->m_sensorRecognizers.count() < 1)
+ return;
+ if (d_ptr->isActive)
+ return;
+
+ Q_FOREACH (QSensorGestureRecognizer *recognizer, d_ptr->m_sensorRecognizers) {
+
+ Q_ASSERT(recognizer !=0);
+
+ connect(recognizer,SIGNAL(detected(QString)),
+ this,SIGNAL(detected(QString)),Qt::UniqueConnection);
+
+ //connect recognizer signals
+// Q_FOREACH (QString method, recognizer->gestureSignals()) {
+// method.prepend(QLatin1String("2"));
+// connect(recognizer, method.toLatin1(),
+// this, method.toLatin1(), Qt::UniqueConnection);
+// }
+
+ recognizer->startBackend();
+ }
+ d_ptr->isActive = true;
+}
+
+/*!
+ Stops the gesture detection routines.
+ */
+void QSensorGesture::stopDetection()
+{
+ if (d_ptr->m_sensorRecognizers.count() < 1)
+ return;
+
+ if (!d_ptr->isActive)
+ return;
+
+ Q_FOREACH (QSensorGestureRecognizer *recognizer, d_ptr->m_sensorRecognizers) {
+ disconnect(recognizer,SIGNAL(detected(QString)),
+ this,SIGNAL(detected(QString)));
+ //disconnect recognizer signals
+// Q_FOREACH (QString method,recognizer->gestureSignals()) {
+// method.prepend(QLatin1String("2"));
+// disconnect(recognizer, method.toLatin1(),
+// this, method.toLatin1());
+// }
+
+ recognizer->stopBackend();
+ }
+ d_ptr->isActive = false;
+}
+
+/*!
+ Returns all the possible gestures signals that may be emitted.
+ */
+QStringList QSensorGesture::gestureSignals() const
+{
+ if (d_ptr->m_sensorRecognizers.count() > 0) {
+ return d_ptr->localGestureSignals;
+ }
+ return QStringList();
+}
+
+/*!
+ Returns whether this gesture is active or not.
+ */
+
+bool QSensorGesture::isActive()
+{
+ return d_ptr->isActive;
+}
+
+QSensorGesturePrivate::QSensorGesturePrivate(QObject *parent)
+ : QObject(parent),isActive(0), valid(0)
+{
+}
+
+QSensorGesturePrivate::~QSensorGesturePrivate()
+{
+
+}
+
+#include "moc_qsensorgesture.cpp"
+
+QTM_END_NAMESPACE
diff --git a/src/sensors/gestures/qsensorgesture.h b/src/sensors/gestures/qsensorgesture.h
new file mode 100644
index 0000000000..0ee93c3ee7
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesture.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORGESTURE_H
+#define QSENSORGESTURE_H
+
+#include <qmobilityglobal.h>
+#include <QtCore/QObject>
+#include <QStringList>
+#include <QtCore/QMetaType>
+
+#include <QList>
+#include <QMap>
+#include <QVector>
+
+QTM_BEGIN_NAMESPACE
+
+class QSensorGesturePrivate;
+
+class Q_SENSORS_EXPORT QSensorGesture : public QObject
+{
+ Q_OBJECT
+public:
+ QSensorGesture(const QStringList &ids, QObject *parent = 0);
+ ~QSensorGesture();
+
+ bool isActive();
+
+ QStringList validIds() const;
+ QStringList invalidIds() const;
+
+ QStringList gestureSignals() const;
+
+ void startDetection();
+ void stopDetection();
+
+private:
+ QSensorGesturePrivate * d_ptr;
+
+private:
+
+Q_SIGNALS:
+ void detected(QString);
+};
+
+QTM_END_NAMESPACE
+
+
+#endif // QSENSORGESTURE_H
diff --git a/src/sensors/gestures/qsensorgesture_p.h b/src/sensors/gestures/qsensorgesture_p.h
new file mode 100644
index 0000000000..ed846e4768
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesture_p.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORGESTURE_P_H
+#define QSENSORGESTURE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include <qsensor.h>
+#include <QTimer>
+
+#include "qsensorgesture.h"
+#include "qsensorgesturemanager.h"
+
+QTM_BEGIN_NAMESPACE
+
+class QSensorGesturePrivate : public QObject
+{
+
+public:
+ QSensorGesturePrivate(QObject *parent = 0);
+ ~QSensorGesturePrivate();
+
+ QList<QSensorGestureRecognizer *> m_sensorRecognizers;
+
+ QByteArray metadata;
+ bool isActive;
+ QStringList localGestureSignals;
+ QStringList availableIds;
+ QStringList invalidIds;
+ bool valid;
+};
+
+QTM_END_NAMESPACE
+
+#endif // QSENSORGESTURE_P_H
diff --git a/src/sensors/gestures/qsensorgesturemanager.cpp b/src/sensors/gestures/qsensorgesturemanager.cpp
new file mode 100644
index 0000000000..77c6e15882
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesturemanager.cpp
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensorgesturemanager.h"
+#include "qsensorgesturemanagerprivate_p.h"
+
+QTM_BEGIN_NAMESPACE
+
+/*!
+ \class QSensorGestureManager
+ \ingroup sensorgestures_main
+ \inmodule QtSensors
+
+ \brief The QSensorGestureManager class manages sensor gestures, registers and creates sensor gesture plugins.
+
+ Sensor Gesture plugins register their recognizers using the registerSensorGestureRecognizer() function.
+
+ \snippet snippets/sensorgestures/creating.cpp Receiving sensor gesture signals
+
+ */
+
+/*!
+ \fn QSensorGestureManager::newSensorGestureAvailable()
+ Signals when a new sensor gesture becomes available for use.
+ */
+
+/*!
+ Constructs the QSensorGestureManager as a child of \a parent
+ */
+QSensorGestureManager::QSensorGestureManager(QObject *parent)
+ : QObject(parent)
+{
+ QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance();
+ if (!d) return; // hardly likely but just in case...
+ connect(d,SIGNAL(newSensorGestureAvailable()),
+ this,SIGNAL(newSensorGestureAvailable()));
+}
+
+/*!
+ Destroy the QSensorGestureManager
+*/
+QSensorGestureManager::~QSensorGestureManager()
+{
+}
+
+/*!
+ Registers the sensor recognizer \a recognizer for use.
+ QSensorGestureManager retains ownership of the recognizer object.
+ Returns true unless the gesture has already been registered, in
+ which case the object is deleted.
+
+ */
+
+ bool QSensorGestureManager::registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer)
+ {
+ QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance();
+ if (!d) { // hardly likely but just in case...
+ delete recognizer;
+ return false;
+ }
+ bool ok = d->registerSensorGestureRecognizer(recognizer);
+ if (!ok)
+ delete recognizer;
+
+ return ok;
+ }
+
+
+ /*!
+ Returns the list of the currently registered gestures.
+ Includes all the standard built-ins as well as available plugins.
+ */
+ QStringList QSensorGestureManager::gestureIds() const
+ {
+ QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance();
+ if (!d) return QStringList(); // hardly likely but just in case...
+ return d->gestureIds();
+ }
+
+ /*!
+ Returns the list of all the gesture signals for the registered \a gestureId gesture recognizer id.
+ */
+ QStringList QSensorGestureManager::recognizerSignals(const QString &gestureId) const
+ {
+ QSensorGestureRecognizer *recognizer = sensorGestureRecognizer(gestureId);
+ if (recognizer != 0)
+ return recognizer->gestureSignals();
+ else
+ return QStringList();
+ }
+
+/*!
+ Returns the sensor gesture object for the recognizer \a id.
+ */
+QSensorGestureRecognizer *QSensorGestureManager::sensorGestureRecognizer(const QString &id)
+{
+ QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance();
+ if (!d) return 0; // hardly likely but just in case...
+ return d->sensorGestureRecognizer(id);
+}
+
+#include "moc_qsensorgesturemanager.cpp"
+
+QTM_END_NAMESPACE
diff --git a/src/sensors/gestures/qsensorgesturemanager.h b/src/sensors/gestures/qsensorgesturemanager.h
new file mode 100644
index 0000000000..0b24c8458e
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesturemanager.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORGESTUREMANAGER_P_H
+#define QSENSORGESTUREMANAGER_P_H
+
+#include <QObject>
+#include <QStringList>
+
+#include "qsensorgesturerecognizer.h"
+#include "qsensorgesture.h"
+
+QTM_BEGIN_NAMESPACE
+
+class QSensorGestureManagerPrivate;
+class Q_SENSORS_EXPORT QSensorGestureManager : public QObject
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QSensorGestureManager)
+
+public:
+ explicit QSensorGestureManager(QObject *parent = 0);
+
+ ~QSensorGestureManager();
+
+ bool registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer);
+
+ QStringList gestureIds() const;
+ QStringList recognizerSignals(const QString &recognizerId) const;
+
+ static QSensorGestureRecognizer *sensorGestureRecognizer(const QString &id);
+
+Q_SIGNALS:
+ void newSensorGestureAvailable();
+
+};
+
+
+
+QTM_END_NAMESPACE
+
+#endif // QSENSORGESTUREMANAGER_P_H
diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp
new file mode 100644
index 0000000000..6e4782850c
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp
@@ -0,0 +1,252 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDir>
+#include <QLibraryInfo>
+
+#include "qsensorgesturemanagerprivate_p.h"
+#include "qsensorgesturerecognizer.h"
+#include "qsensorgestureplugininterface.h"
+
+#include <qmobilitypluginsearch.h>
+
+#ifdef SIMULATOR_BUILD
+#include "simulatorgesturescommon_p.h"
+#endif
+
+
+QTM_BEGIN_NAMESPACE
+Q_GLOBAL_STATIC(QSensorGestureManagerPrivate, sensorGestureManagerPrivate)
+
+QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) :
+ QObject(parent)
+{
+#ifdef SIMULATOR_BUILD
+ SensorGesturesConnection *connection = new SensorGesturesConnection(this);
+ connect(connection,SIGNAL(sensorGestureDetected()),
+ this,SLOT(sensorGestureDetected()));
+
+ connect(this,SIGNAL(newSensorGestures(QStringList)),
+ connection,SLOT(newSensorGestures(QStringList)));
+
+ connect(this,SIGNAL(removeSensorGestures(QStringList)),
+ connection,SLOT(removeSensorGestures(QStringList)));
+#endif
+
+// loader = new QFactoryLoader("com.Nokia.QSensorGesturePluginInterface", QLatin1String("/sensorgestures"));
+ loadPlugins();
+}
+
+QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate()
+{
+// qDeleteAll(registeredSensorGestures);
+// delete loader;
+}
+
+
+ void QSensorGestureManagerPrivate::initPlugin(QObject *plugin)
+{
+ if (QSensorGesturePluginInterface *pInterface
+ = qobject_cast<QSensorGesturePluginInterface *>(plugin)) {
+
+ Q_FOREACH (const QString &id, pInterface->supportedIds()) {
+
+ if (!knownIds.contains(id))
+ knownIds.append(id);
+ else
+ qWarning() << id <<"from the plugin"
+ << pInterface->name()
+ << "is already known.";
+
+ }
+ plugins << plugin;
+ } else {
+ qWarning() << "Could not load "<< plugin;
+ }
+}
+
+
+/*!
+ Internal
+ Loads the sensorgesture plugins.
+ */
+void QSensorGestureManagerPrivate::loadPlugins()
+{
+ // Qt-style static plugins
+ Q_FOREACH (QObject *plugin, QPluginLoader::staticInstances()) {
+ initPlugin(plugin);
+ }
+
+ QStringList gestureplugins = mobilityPlugins(QLatin1String("sensorgestures"));
+ for (int i = 0; i < gestureplugins.count(); i++) {
+
+ QPluginLoader *loader = new QPluginLoader(gestureplugins.at(i), this);
+ QObject *plugin = loader->instance();
+ if (plugin) {
+ initPlugin(plugin);
+ }
+ }
+}
+
+/*!
+ Internal
+ creates the requested recognizer.
+ */
+
+bool QSensorGestureManagerPrivate::loadRecognizer(const QString &recognizerId)
+{
+ //if no plugin is used return true if this is a registered recognizer
+
+ if (registeredSensorGestures.contains(recognizerId))
+ return true;
+
+ for (int i= 0; i < plugins.count(); i++) {
+
+ if (QSensorGesturePluginInterface *pInterface
+ = qobject_cast<QSensorGesturePluginInterface *>(plugins.at(i))) {
+
+ if (pInterface->supportedIds().contains(recognizerId)) {
+
+ if (!registeredSensorGestures.contains(recognizerId)) {
+ //create these recognizers
+ QList <QSensorGestureRecognizer *> recognizers = pInterface->createRecognizers();
+
+ Q_FOREACH (QSensorGestureRecognizer *recognizer, recognizers) {
+
+ if (registeredSensorGestures.contains(recognizer->id())) {
+ qWarning() << "Ignoring recognizer " << recognizer->id() << "from plugin" << pInterface->name() << "because it is already registered";
+ delete recognizer;
+ } else {
+ registeredSensorGestures.insert(recognizer->id(),recognizer);
+ }
+ }
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool QSensorGestureManagerPrivate::registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer)
+{
+ if (!knownIds.contains(recognizer->id())) {
+ knownIds.append(recognizer->id());
+ Q_ASSERT (!registeredSensorGestures.contains(recognizer->id()));
+ recognizer->setParent(0);
+ registeredSensorGestures.insert(recognizer->id(),recognizer);
+ Q_EMIT newSensorGestureAvailable();
+
+ return true;
+ }
+ return false;
+}
+
+QSensorGestureRecognizer *QSensorGestureManagerPrivate::sensorGestureRecognizer(const QString &id)
+{
+ QSensorGestureRecognizer *recognizer = 0;
+
+ if (loadRecognizer(id)) {
+ recognizer= registeredSensorGestures.value(id);
+ }
+
+ return recognizer;
+}
+
+QStringList QSensorGestureManagerPrivate::gestureIds()
+{
+ return knownIds;
+}
+
+#ifdef SIMULATOR_BUILD
+void QSensorGestureManagerPrivate::sensorGestureDetected()
+{
+ QString str = get_qtSensorGestureData();
+
+ Q_FOREACH (const QString &id, gestureIds()) {
+ QSensorGestureRecognizer *recognizer = sensorGestureRecognizer(id);
+ if (recognizer != 0) {
+ Q_FOREACH (const QString &sig, recognizer->gestureSignals()) {
+ if (!sig.contains(QLatin1String("detected"))) { //weed out detected signals
+ QString tmp;
+ tmp = sig.left(sig.length() - 2);
+ if (str == tmp) {
+ // named signal for c++
+ QMetaObject::invokeMethod(recognizer, str.toLocal8Bit(), Qt::DirectConnection);
+ // detected signal for qml and c++
+ QMetaObject::invokeMethod(recognizer, "detected", Qt::DirectConnection,
+ Q_ARG(QString, str));
+ break;
+
+ }
+ }
+ }
+ }
+ }
+}
+
+void QSensorGestureManagerPrivate::recognizerStarted(const QSensorGestureRecognizer *recognizer)
+{
+ QStringList list = recognizer->gestureSignals();
+ list.removeOne(QLatin1String("detected(QString)"));
+ Q_EMIT newSensorGestures(list);
+}
+
+void QSensorGestureManagerPrivate::recognizerStopped(const QSensorGestureRecognizer *recognizer)
+{
+ QStringList list = recognizer->gestureSignals();
+ list.removeOne(QLatin1String("detected(QString)"));
+ Q_EMIT removeSensorGestures(list);
+}
+
+#endif
+
+QSensorGestureManagerPrivate * QSensorGestureManagerPrivate::instance()
+{
+ QSensorGestureManagerPrivate *priv = sensorGestureManagerPrivate();
+ // It's safe to return 0 because this is checked when used
+ //if (!priv) qFatal("Cannot return from QSensorGestureManagerPrivate::instance() because sensorGestureManagerPrivate() returned 0.");
+ return priv;
+}
+
+#include "moc_qsensorgesturemanagerprivate_p.cpp"
+
+QTM_END_NAMESPACE
diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate_p.h b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h
new file mode 100644
index 0000000000..80c4639863
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORGESTUREMANAGERPRIVATE_P_H
+#define QSENSORGESTUREMANAGERPRIVATE_P_H
+
+#include <QObject>
+#include <QMap>
+#include <QStringList>
+#include <QDebug>
+#include <QSharedPointer>
+#include <QPluginLoader>
+#include <qmobilityglobal.h>
+
+#include "qsensorgesture.h"
+#include "qsensorgesturerecognizer.h"
+
+QTM_BEGIN_NAMESPACE
+
+class QFactoryLoader;
+
+class QSensorGestureManagerPrivate : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QSensorGestureManagerPrivate(QObject *parent = 0);
+ ~QSensorGestureManagerPrivate();
+
+ QMap<QString, QSensorGestureRecognizer *> registeredSensorGestures;
+
+ QList <QObject *> plugins;
+
+ QFactoryLoader *loader;
+ void loadPlugins();
+ bool loadRecognizer(const QString &id);
+
+ QSensorGestureRecognizer *sensorGestureRecognizer(const QString &id);
+
+ bool registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer);
+ QStringList gestureIds();
+ QStringList knownIds;
+ void initPlugin(QObject *o);
+#ifdef SIMULATOR_BUILD
+ void recognizerStarted(const QSensorGestureRecognizer *);
+ void recognizerStopped(const QSensorGestureRecognizer *);
+#endif
+
+ static QSensorGestureManagerPrivate * instance();
+Q_SIGNALS:
+ void newSensorGestureAvailable();
+
+#ifdef SIMULATOR_BUILD
+Q_SIGNALS:
+ void newSensorGestures(QStringList);
+ void removeSensorGestures(QStringList);
+
+private slots:
+ void sensorGestureDetected();
+
+#endif
+};
+
+QTM_END_NAMESPACE
+
+#endif // QSENSORGESTUREMANAGERPRIVATE_P_H
diff --git a/src/sensors/gestures/qsensorgestureplugininterface.cpp b/src/sensors/gestures/qsensorgestureplugininterface.cpp
new file mode 100644
index 0000000000..95d4af6187
--- /dev/null
+++ b/src/sensors/gestures/qsensorgestureplugininterface.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensorgestureplugininterface.h"
+
+QTM_BEGIN_NAMESPACE
+
+/*!
+ \class QSensorGesturePluginInterface
+ \ingroup sensorgestures_recognizer
+ \inmodule QtSensors
+
+ \brief The QSensorGesturePluginInterface class is the pure virtual interface to sensor gesture
+ plugins.
+
+ \since QtSensors 5.0
+
+ The QSensorGesturePluginInterface class is implemented in sensor gesture plugins to register
+ sensor gesture recognizers with QSensorGestureManager.
+
+ \sa {QtSensorGestures Plugins}
+*/
+
+/*!
+ \fn QSensorGesturePluginInterface::createRecognizers()
+
+ Called by the manager to create the recognizers.
+ Plugins should initialize and register their recognizers using
+ QSensorGestureManager::registerSensorGestureRecognizer() here.
+
+ \sa QSensorGestureManager
+*/
+
+/*!
+ \fn QSensorGesturePluginInterface::supportedIds() const
+
+ Returns a list of the recognizer Id's that this plugin supports.
+ */
+
+
+/*!
+ \fn QSensorGesturePluginInterface::name() const
+
+ Returns this plugins name.
+ */
+
+/*!
+ Construct the QSensorGesturePluginInterface.
+*/
+QSensorGesturePluginInterface::QSensorGesturePluginInterface()
+{
+}
+
+/*!
+ Destroy the QSensorGesturePluginInterface.
+*/
+QSensorGesturePluginInterface::~QSensorGesturePluginInterface()
+{
+}
+
+QTM_END_NAMESPACE
diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h
new file mode 100644
index 0000000000..d13c1dea6b
--- /dev/null
+++ b/src/sensors/gestures/qsensorgestureplugininterface.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORGESTUREPLUGININTERFACE_H
+#define QSENSORGESTUREPLUGININTERFACE_H
+
+#include <QObject>
+#include <QtGlobal>
+#include <QtCore/qplugin.h>
+#include "qsensorgesture.h"
+#include "qsensorgesturerecognizer.h"
+
+
+QTM_BEGIN_NAMESPACE
+
+class QSensorGestureRecognizer;
+
+class Q_SENSORS_EXPORT QSensorGesturePluginInterface
+{
+public:
+ QSensorGesturePluginInterface();
+ virtual ~QSensorGesturePluginInterface();
+ virtual QList <QSensorGestureRecognizer *> createRecognizers() = 0;
+ virtual QStringList supportedIds() const = 0;
+ virtual QString name() const = 0;
+};
+
+QTM_END_NAMESPACE
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_INTERFACE(QtMobility::QSensorGesturePluginInterface, "com.Nokia.Qt.QSensorGesturePluginInterface/1.0");
+QT_END_NAMESPACE
+
+
+#endif // QSENSORGESTUREPLUGININTERFACE_H
diff --git a/src/sensors/gestures/qsensorgesturerecognizer.cpp b/src/sensors/gestures/qsensorgesturerecognizer.cpp
new file mode 100644
index 0000000000..9ec9edeac7
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesturerecognizer.cpp
@@ -0,0 +1,221 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensorgesture_p.h"
+#include "qsensorgesturerecognizer.h"
+
+//#include "qsensorgesturemanager.h"
+#ifdef SIMULATOR_BUILD
+#include "qsensorgesturemanagerprivate_p.h"
+#endif
+
+QTM_BEGIN_NAMESPACE
+
+
+/*!
+ \class QSensorGestureRecognizer
+ \ingroup sensorgestures_recognizer
+ \inmodule QtSensors
+
+ \brief The QSensorGestureRecognizer class is the base class for a sensor gesture
+ recognizer.
+
+ QSensorGesture recognizer developers should sub-class this to implement their own recognizer.
+
+ All sensor gesture recognizers have a detected(QString) signal. Implementors can use this
+ and send recognizer specific gestures, such as detected("shake_left") or implement custom signals
+ such as shakeLeft().
+
+ These custom signals will be available in the QSensorGesture object at runtime.
+
+ \sa QSensorGestureRecognizer::gestureSignals()
+
+ */
+
+/*!
+ \fn void QSensorGestureRecognizer::create()
+
+ Called by QSensorGesture object constructor to create the recognizers backend.
+
+ Implementors would use this to instantiate QSensors and connect signals.
+
+ */
+
+/*!
+ \fn QString QSensorGestureRecognizer::id() const
+ Returns the identifier for this recognizer.
+ */
+/*!
+ \fn bool QSensorGestureRecognizer::start()
+
+ Called by QSensorGesture::startDetection() to start this recognizer.
+ Implementors should start the sensors.
+ Returns true if the operation is successful.
+
+ */
+/*!
+ \fn bool QSensorGestureRecognizer::stop()
+
+ Called by QSensorGesture::stopDetection() to stop this recognizer.
+ Returns true if the call succeeds, otherwise false.
+
+ Implementors should stop the sensors.
+
+ */
+/*!
+ \fn bool QSensorGestureRecognizer::isActive()
+
+ Returns true if this recognizer is active, otherwise false.
+ */
+
+/*!
+ \fn QSensorGestureRecognizer::detected(const QString &gestureId)
+ Signals when the \a gestureId gesture has been recognized.
+ */
+
+class QSensorGestureRecognizerPrivate
+{
+public:
+ bool initialized;
+ int count;
+};
+
+
+/*!
+ Constructs the QSensorGestureRecognizer with \a parent as parent.
+ */
+QSensorGestureRecognizer::QSensorGestureRecognizer(QObject *parent)
+ :QObject(parent),
+ d_ptr(new QSensorGestureRecognizerPrivate())
+{
+}
+
+/*!
+ Destroy the QSensorGestureRecognizer
+*/
+QSensorGestureRecognizer::~QSensorGestureRecognizer()
+{
+ delete d_ptr;
+}
+
+/*!
+ Returns a list of signals that this recognizer supports.
+
+ Note that all signals declared will be exported to the QSensorGesture
+ object. If you need to use signals that are not exported, you should use a private class
+ to do so.
+
+ */
+QStringList QSensorGestureRecognizer::gestureSignals() const
+{
+ QStringList list;
+ //bool ok = false;
+ list.append(QString::fromLatin1("detected(QString)"))
+ ;
+ // for (int i = 0; i < this->metaObject()->methodCount(); i++) {
+// //weed out objectsignals and slots
+// const QByteArray sig(this->metaObject()->method(i).methodSignature());
+// if (this->metaObject()->indexOfSignal(sig) != -1) {
+// if (sig.contains("detected"))
+// ok = true;
+// if (ok)
+// list.append(QString::fromLatin1(sig));
+// }
+// }
+ return list;
+}
+
+/*!
+ Calls QSensorGestureRecognizer::create() if the recognizer is valid.
+*/
+void QSensorGestureRecognizer::createBackend()
+{
+ if (d_ptr->initialized) {
+ return;
+ }
+ d_ptr->initialized = true;
+ create();
+}
+
+/*!
+ Calls QSensorGestureRecognizer::start() if the recognizer isn't already initialized.
+ This is called by the QSensorGesture object, so please use that instead.
+
+\sa QSensorGesture::startDetection()
+
+*/
+void QSensorGestureRecognizer::startBackend()
+{
+ if (!d_ptr->initialized) {
+ qWarning() << "Not starting. Gesture Recognizer not initialized";
+ return;
+ }
+ if (d_ptr->count++ == 0) {
+ start();
+#ifdef SIMULATOR_BUILD
+ QSensorGestureManagerPrivate::instance()->recognizerStarted(this);
+#endif
+ }
+}
+
+/*!
+ Calls QSensorGestureRecognizer::stop() if no other clients are using it.
+ This is called by the QSensorGesture object, so please use that instead.
+
+\sa QSensorGesture::stopDetection()
+*/
+void QSensorGestureRecognizer::stopBackend()
+{
+ if (!d_ptr->initialized) {
+ qWarning() << "Not stopping. Gesture Recognizer not initialized";
+ return;
+ }
+ if (--d_ptr->count == 0) {
+ stop();
+#ifdef SIMULATOR_BUILD
+ QSensorGestureManagerPrivate::instance()->recognizerStopped(this);
+#endif
+ }
+}
+
+#include "moc_qsensorgesturerecognizer.cpp"
+
+QTM_END_NAMESPACE
diff --git a/src/sensors/gestures/qsensorgesturerecognizer.h b/src/sensors/gestures/qsensorgesturerecognizer.h
new file mode 100644
index 0000000000..d2391f447a
--- /dev/null
+++ b/src/sensors/gestures/qsensorgesturerecognizer.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORGESTURERECOGNIZER_H
+#define QSENSORGESTURERECOGNIZER_H
+
+#include <qmobilityglobal.h>
+#include <QDebug>
+#include <QTimer>
+#include <QStringList>
+
+
+QTM_BEGIN_NAMESPACE
+
+class QSensorGestureRecognizerPrivate;
+class Q_SENSORS_EXPORT QSensorGestureRecognizer : public QObject
+{
+ Q_OBJECT
+public:
+ QSensorGestureRecognizer(QObject *parent = 0);
+ virtual ~QSensorGestureRecognizer();
+
+ virtual QString id() const = 0;
+
+ virtual bool isActive() = 0;
+
+ void startBackend();
+ void stopBackend();
+ void createBackend();
+
+ QStringList gestureSignals() const;
+
+Q_SIGNALS:
+ void detected(const QString &);
+
+protected:
+ virtual void create() = 0;
+ virtual bool start() = 0;
+ virtual bool stop() = 0;
+
+private:
+ QSensorGestureRecognizerPrivate * d_ptr;
+};
+
+QTM_END_NAMESPACE
+#endif // QSENSORGESTURERECOGNIZER_H
diff --git a/src/sensors/gestures/simulatorgesturescommon.cpp b/src/sensors/gestures/simulatorgesturescommon.cpp
new file mode 100644
index 0000000000..02e62e7e4f
--- /dev/null
+++ b/src/sensors/gestures/simulatorgesturescommon.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "simulatorgesturescommon_p.h"
+
+#include <QtSimulator/version.h>
+#include <QtSimulator/QtSimulator>
+
+#include <QDebug>
+#include <QStringList>
+
+using namespace Simulator;
+
+
+Q_GLOBAL_STATIC(QString, qtSensorGestureData)
+
+SensorGesturesConnection::SensorGesturesConnection(QObject *parent)
+ : QObject(parent)
+{
+ mConnection = new Connection(Connection::Client, QLatin1String("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;
+ }
+
+ mWorker->addReceiver(this);
+ mWorker->call("setRequestsSensorGestures");
+}
+
+SensorGesturesConnection::~SensorGesturesConnection()
+{
+ mWorker->call("setSensorGestures", QStringList());
+ delete mWorker;
+}
+
+void SensorGesturesConnection::setSensorGestureData(const QString &data)
+{
+ QString gesture = data;
+ if (data.contains(QLatin1String("detected"))) {
+ gesture.remove(QLatin1String("detected("));
+ gesture.remove(QLatin1String(")"));
+ }
+ *qtSensorGestureData() = gesture;
+}
+
+void SensorGesturesConnection::newSensorGestureDetected()
+{
+ emit sensorGestureDetected();
+}
+
+void SensorGesturesConnection::newSensorGestures(const QStringList &gestures)
+{
+ if (!mWorker) return;
+
+ Q_FOREACH (const QString &gest, gestures) {
+ if (!gest.contains(QLatin1String("detected"))) {
+ QString tmp = gest.left(gest.length()-2);
+ if (!allGestures.contains(tmp)) {
+ allGestures.append(tmp);
+ }
+ }
+ }
+
+ mWorker->call("setSensorGestures", allGestures);
+}
+
+void SensorGesturesConnection::removeSensorGestures(const QStringList &gestures)
+{
+ Q_FOREACH (const QString &gest, gestures) {
+ QString tmp = gest.left(gest.length()-2);
+ if (allGestures.contains(tmp)) {
+ allGestures.removeOne(tmp);
+ }
+ }
+ mWorker->call("setSensorGestures", allGestures);
+}
+
+QString get_qtSensorGestureData()
+{
+ return *qtSensorGestureData();
+}
+
diff --git a/src/sensors/gestures/simulatorgesturescommon_p.h b/src/sensors/gestures/simulatorgesturescommon_p.h
new file mode 100644
index 0000000000..20c26b39eb
--- /dev/null
+++ b/src/sensors/gestures/simulatorgesturescommon_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SIMULATORGESTURESCOMMON_H
+#define SIMULATORGESTURESCOMMON_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtSimulator/connection.h>
+#include <QtSimulator/connectionworker.h>
+#include <QStringList>
+
+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(const QStringList &gestures);
+ void removeSensorGestures(const QStringList &gestures);
+
+private:
+ Simulator::Connection *mConnection;
+ Simulator::ConnectionWorker *mWorker;
+ QStringList allGestures;
+
+};
+
+QString get_qtSensorGestureData();
+
+#endif //SIMULATORGESTURESCOMMON_H
+
diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro
index 0c111b45b0..fe5b59fc64 100644
--- a/src/sensors/sensors.pro
+++ b/src/sensors/sensors.pro
@@ -67,6 +67,23 @@ for(s,SENSORS) {
PRIVATE_HEADERS += $${s}_p.h
}
+SOURCES += \
+ gestures/qsensorgesture.cpp \
+ gestures/qsensorgesturerecognizer.cpp \
+ gestures/qsensorgesturemanager.cpp \
+ gestures/qsensorgesturemanagerprivate.cpp \
+ gestures/qsensorgestureplugininterface.cpp
+
+PUBLIC_HEADERS += \
+ gestures/qsensorgesture.h\
+ gestures/qsensorgesturerecognizer.h \
+ gestures/qsensorgesturemanager.h \
+ gestures/qsensorgestureplugininterface.h
+
+PRIVATE_HEADERS += \
+ gestures/qsensorgesturemanagerprivate_p.h \
+ gestures/qsensorgesture_p.h
+
HEADERS = $$PUBLIC_HEADERS $$PRIVATE_HEADERS
include(../../features/deploy.pri)