Clean received & sent messages
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 22:48:57 +0000 (22:48 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 22:48:57 +0000 (22:48 +0000)
camshooter.cpp
camshooter.h
nnokia.pro
shootquery.cpp [new file with mode: 0644]
shootquery.h [new file with mode: 0644]
smshandler.cpp
smshandler.h

index 3973712ef42492a559728967110c945c8b0e6c0e..413763b37cd7bf03cfdf082ab8d19e67bc4c4f81 100644 (file)
@@ -27,7 +27,7 @@ CamShooter::~CamShooter() {
 
 void CamShooter::debug_dump(const char *msg) {
     qDebug() << msg;
-
+/*
     qDebug() << "\t------------------";
     if (camera) {
         if (camera->error())
@@ -47,6 +47,7 @@ void CamShooter::debug_dump(const char *msg) {
             qDebug() << "\tImageCapture no error";
     }
     qDebug() << "\t------------------";
+*/
 }
 
 
index 41b65d5b87d407e0ecae6bea65aba6c1e5d022c1..8506b17b2e4cf9c595242c0031a7ddf43e50b6ec 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef NSHOOTER_H
-#define NSHOOTER_H
+#ifndef CAMSHOOTER_H
+#define CAMSHOOTER_H
 
 #include <QObject>
 #include <QCamera>
@@ -31,4 +31,4 @@ protected:
 };
 
 
-#endif // NSHOOTER_H
+#endif // CAMSHOOTER_H
index 693bf2f271ad41aab88a435a7bd4c414d97b4b48..3f793b483c5afb274e28161eae6bbe2dba2dfe02 100644 (file)
@@ -17,10 +17,12 @@ MOBILITY += multimedia messaging
 
 SOURCES += main.cpp mainwindow.cpp \
     smshandler.cpp \
-    camshooter.cpp
+    camshooter.cpp \
+    shootquery.cpp
 HEADERS += mainwindow.h \
     smshandler.h \
-    camshooter.h
+    camshooter.h \
+    shootquery.h
 FORMS += mainwindow.ui
 
 # Please do not modify the following two lines. Required for deployment.
diff --git a/shootquery.cpp b/shootquery.cpp
new file mode 100644 (file)
index 0000000..1da3967
--- /dev/null
@@ -0,0 +1,66 @@
+#include <QtDebug>
+#include "shootquery.h"
+#include "camshooter.h"
+
+ShootQuery::ShootQuery(QObject *parent, CamShooter *camShooterSingleton, QMessageAddress remoteAddr) :
+    QObject(parent)
+{
+    msgManager = new QMessageManager(this);
+    msgService = new QMessageService(this);
+    filterId = 0;
+
+    this->camShooter = camShooterSingleton;
+    this->remoteAddr = remoteAddr;
+    QObject::connect(camShooter, SIGNAL(fileReady(const QString &)),
+                     this, SLOT(slot_imageReady(const QString &)));
+    QObject::connect(msgManager, SIGNAL(messageUpdated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)),
+                     this, SLOT(slot_message_updated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)));
+    camShooter->go();
+}
+
+ShootQuery::~ShootQuery() {
+    qDebug() << "deleting ShotQuery";
+    if (filterId)
+        msgManager->unregisterNotificationFilter(filterId);
+    QObject::disconnect(this, 0, 0, 0);
+    delete msgManager;
+    delete msgService;
+}
+
+void ShootQuery::slot_imageReady(const QString &filename) {
+    qDebug() << "In slot imageReady";
+
+    qDebug() << "building mms";
+    QMessage response;
+    response.setType(QMessage::Mms);
+    response.setTo(remoteAddr);
+    qDebug() << "attaching image";
+    QStringList paths;
+    paths << filename;
+    response.appendAttachments(paths);
+    qDebug() << "response status is" << response.status();
+
+    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 ShootQuery::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/shootquery.h b/shootquery.h
new file mode 100644 (file)
index 0000000..2b78078
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef SHOOTQUERY_H
+#define SHOOTQUERY_H
+
+#include <QObject>
+#include <QCamera>
+#include <QMessageManager>
+#include <QMessageService>
+#include "camshooter.h"
+
+using namespace QtMobility;
+
+class ShootQuery : public QObject
+{
+    Q_OBJECT
+public:
+    explicit ShootQuery(QObject *parent,
+                        CamShooter *camShooterSingleton,
+                        QMessageAddress remoteAddr);
+    virtual ~ShootQuery();
+
+signals:
+
+public slots:
+    void slot_imageReady(const QString &);
+    void slot_message_updated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&);
+
+protected:
+    QMessageManager *msgManager;
+    QMessageService *msgService;
+    CamShooter *camShooter;
+    QMessageAddress remoteAddr;
+    QMessageManager::NotificationFilterId filterId;
+};
+
+#endif // SHOOTQUERY_H
index 527ea38d93df966a8c08e2b6598746acf86de8ff..40f6452f47fb4c61065bea6ccf84cc542ac58aec 100644 (file)
@@ -1,7 +1,7 @@
 #include <QtDebug>
-#include <QMessageService>
 #include "smshandler.h"
 #include "camshooter.h"
+#include "shootquery.h"
 
 SmsHandler::SmsHandler(QObject *parent) :
     QObject(parent)
@@ -15,24 +15,15 @@ SmsHandler::SmsHandler(QObject *parent) :
   msgManager->registerNotificationFilter(
       QMessageFilter::byType(QMessage::Sms) &
       QMessageFilter::byStandardFolder(QMessage::InboxFolder));
-
-  /*
-  timer = new QTimer(this);
-  timer->setInterval(20000);
-  timer->setSingleShot(false);
-  QObject::connect(timer, SIGNAL(timeout()), this, SLOT(slot_timer_activation()));
-  */
-  QObject::connect(camShooter, SIGNAL(fileReady(const QString &)),
-                   this, SLOT(slot_imageReady(const QString &)));
 }
 
+
 void SmsHandler::slot_message_received(const QMessageId & id, const QMessageManager::NotificationFilterIdSet & /*matchingFilterIds*/) {
     qDebug() << "message received";
 
     QMessage msg = msgManager->message(id);
 
-    remoteAddr = msg.from();
-    qDebug() << "from" << remoteAddr.addressee();
+    qDebug() << "from" << msg.from().addressee();
 
     QString content = msg.textContent();
     qDebug() << "content" << content;
@@ -43,27 +34,7 @@ void SmsHandler::slot_message_received(const QMessageId & id, const QMessageMana
         qDebug() << "deleting original message";
         msgManager->removeMessage(id);
 
-        qDebug() << "starting shooter";
-        camShooter->go();
+        new ShootQuery(this, this->camShooter, msg.from());
     }
 }
 
-void SmsHandler::slot_imageReady(const QString &filename) {
-    qDebug() << "In slot imageReady";
-
-    qDebug() << "building mms";
-    QMessage response;
-    response.setType(QMessage::Mms);
-    response.setTo(remoteAddr);
-    qDebug() << "attaching image";
-    QStringList paths;
-    paths << filename;
-    response.appendAttachments(paths);
-
-    qDebug() << "sending message";
-    QMessageService *m_service = new QMessageService(this);
-    if (!m_service->send(response)) {
-        qDebug() << "send() failed.";
-    }
-    qDebug() << "message" << response.id().toString() << "queued";
-}
index b421c02f186b0b9f98b475c84865ca3ad295d4ee..13df2f1faca4674c79b9cde4413026fad82bf7df 100644 (file)
@@ -17,13 +17,11 @@ signals:
 
 public slots:
     void slot_message_received(const QMessageId&, const QMessageManager::NotificationFilterIdSet&);
-    void slot_imageReady(const QString &);
 
 protected:
-    QtMobility::QMessageManager *msgManager;
     CamShooter *camShooter;
+    QMessageManager *msgManager;
 //    QTimer *timer;
-    QMessageAddress remoteAddr;
 
 };