Added "tou" command master
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 11 Mar 2011 00:03:06 +0000 (00:03 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 11 Mar 2011 00:03:06 +0000 (00:03 +0000)
locationquery.cpp [new file with mode: 0644]
locationquery.h [new file with mode: 0644]
nnokia.pro
shootquery.cpp
smshandler.cpp

diff --git a/locationquery.cpp b/locationquery.cpp
new file mode 100644 (file)
index 0000000..84db277
--- /dev/null
@@ -0,0 +1,92 @@
+#include <QtDebug>
+#include "locationquery.h"
+
+LocationQuery::LocationQuery(QObject *parent, QMessageAddress remoteAddr) :
+    QObject(parent)
+{
+    msgManager = new QMessageManager(this);
+    msgService = new QMessageService(this);
+    posSource = QGeoPositionInfoSource::createDefaultSource(this);
+    qDebug() << posSource;
+    filterId = 0;
+    this->remoteAddr = remoteAddr;
+
+    QObject::connect(posSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)),
+                     this, SLOT(slot_positionUpdated(const QGeoPositionInfo &)));
+    QObject::connect(posSource, SIGNAL(updateTimeout()),
+                     this, SLOT(slot_updateTimeout()));
+    QObject::connect(msgManager, SIGNAL(messageUpdated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)),
+                     this, SLOT(slot_message_updated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)));
+
+    qDebug() << "requesting position";
+    posSource->requestUpdate(60000);
+}
+
+LocationQuery::~LocationQuery() {
+    qDebug() << "deleting LocationQuery";
+    if (filterId)
+        msgManager->unregisterNotificationFilter(filterId);
+    QObject::disconnect(this, 0, 0, 0);
+    delete msgManager;
+    delete msgService;
+}
+
+
+void LocationQuery::slot_positionUpdated(const QGeoPositionInfo & posInfo) {
+    qDebug() << "positioning ok:" << posInfo.coordinate();
+    posSource->stopUpdates();
+
+    qDebug() << "building sms";
+    QMessage response;
+    response.setType(QMessage::Mms);
+    response.setTo(remoteAddr);
+    response.setBody(QString("lat %1 lon %2")
+                     .arg(posInfo.coordinate().latitude())
+                     .arg(posInfo.coordinate().longitude()));
+
+    qDebug() << "sending message";
+    if (!msgService->send(response)) {
+        qDebug() << "send() failed.";
+    }
+    else {
+        qDebug() << "message" << response.id().toString() << "queued";
+        qDebug() << "response status is" << response.status();
+        filterId = msgManager->registerNotificationFilter(
+                            QMessageFilter::byId(response.id()));
+    }
+}
+
+void LocationQuery::slot_updateTimeout() {
+    qDebug() << "positioning failed";
+    posSource->stopUpdates();
+
+    qDebug() << "building sms";
+    QMessage response;
+    response.setType(QMessage::Mms);
+    response.setTo(remoteAddr);
+    response.setBody("Positioning failed.");
+
+    qDebug() << "sending message";
+    if (!msgService->send(response)) {
+        qDebug() << "send() failed.";
+    }
+    else {
+        qDebug() << "message" << response.id().toString() << "queued";
+        qDebug() << "response status is" << response.status();
+        filterId = msgManager->registerNotificationFilter(
+                            QMessageFilter::byId(response.id()));
+    }
+}
+
+
+void LocationQuery::slot_message_updated(const QMessageId &id, const QMessageManager::NotificationFilterIdSet&) {
+    qDebug() << "Message" << id.toString() << "was updated.";
+    QMessage msg = msgManager->message(id);
+    qDebug() << "msg status is" << msg.status();
+    if (msg.standardFolder() == QMessage::SentFolder) {
+        qDebug() << "Message was sent. deleting.";
+        msgManager->removeMessage(msg.id());
+        qDebug() << "Message deleted.";
+        delete this;
+    }
+}
diff --git a/locationquery.h b/locationquery.h
new file mode 100644 (file)
index 0000000..2ec83a6
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef LOCATIONQUERY_H
+#define LOCATIONQUERY_H
+
+#include <QMessageManager>
+#include <QMessageService>
+#include <QGeoPositionInfoSource>
+
+using namespace QtMobility;
+
+class LocationQuery : public QObject
+{
+    Q_OBJECT
+public:
+    explicit LocationQuery(QObject *parent, QMessageAddress remoteAddr);
+    virtual ~LocationQuery();
+
+signals:
+
+public slots:
+    void slot_message_updated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&);
+    void slot_positionUpdated(const QGeoPositionInfo &);
+    void slot_updateTimeout();
+
+protected:
+    QMessageManager *msgManager;
+    QMessageService *msgService;
+    QMessageAddress remoteAddr;
+    QMessageManager::NotificationFilterId filterId;
+    QGeoPositionInfoSource * posSource;
+};
+
+#endif // LOCATIONQUERY_H
index 3f793b4..3aa93c7 100644 (file)
@@ -7,22 +7,24 @@ DEPLOYMENTFOLDERS = # file1 dir1
 symbian:TARGET.UID3 = 0xE0B4133F
 
 # Allow network access on Symbian
-symbian:TARGET.CAPABILITY += NetworkServices UserEnvironment ReadUserData WriteUserData ReadDeviceData WriteDeviceData
+symbian:TARGET.CAPABILITY += NetworkServices UserEnvironment ReadUserData WriteUserData ReadDeviceData WriteDeviceData Location
 
 # If your application uses the Qt Mobility libraries, uncomment
 # the following lines and add the respective components to the 
 # MOBILITY variable. 
 CONFIG += mobility
-MOBILITY += multimedia messaging
+MOBILITY += multimedia messaging location
 
 SOURCES += main.cpp mainwindow.cpp \
     smshandler.cpp \
     camshooter.cpp \
-    shootquery.cpp
+    shootquery.cpp \
+    locationquery.cpp
 HEADERS += mainwindow.h \
     smshandler.h \
     camshooter.h \
-    shootquery.h
+    shootquery.h \
+    locationquery.h
 FORMS += mainwindow.ui
 
 # Please do not modify the following two lines. Required for deployment.
index 1da3967..2649e6d 100644 (file)
@@ -38,7 +38,6 @@ void ShootQuery::slot_imageReady(const QString &filename) {
     QStringList paths;
     paths << filename;
     response.appendAttachments(paths);
-    qDebug() << "response status is" << response.status();
 
     qDebug() << "sending message";
     if (!msgService->send(response)) {
index 40f6452..9a17ee3 100644 (file)
@@ -2,6 +2,7 @@
 #include "smshandler.h"
 #include "camshooter.h"
 #include "shootquery.h"
+#include "locationquery.h"
 
 SmsHandler::SmsHandler(QObject *parent) :
     QObject(parent)
@@ -28,13 +29,20 @@ void SmsHandler::slot_message_received(const QMessageId & id, const QMessageMana
     QString content = msg.textContent();
     qDebug() << "content" << content;
 
-    if (!content.compare("go", Qt::CaseInsensitive)) {
-        qDebug() << "receive mms snapshoot request";
+    if (!content.compare("snap", Qt::CaseInsensitive)) {
+        qDebug() << "received mms snapshoot request";
 
         qDebug() << "deleting original message";
         msgManager->removeMessage(id);
 
         new ShootQuery(this, this->camShooter, msg.from());
+    } else if (!content.compare("tou", Qt::CaseInsensitive)) {
+        qDebug() << "received localisation request";
+
+        qDebug() << "deleting original message";
+        msgManager->removeMessage(id);
+
+        new LocationQuery(this, msg.from());
     }
 }