(no commit message)
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 19:53:25 +0000 (19:53 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 19:53:25 +0000 (19:53 +0000)
mainwindow.cpp
mainwindow.h
nnokia.pro
nshooter.h
smshandler.cpp [new file with mode: 0644]
smshandler.h [new file with mode: 0644]

index c3ef62f..cac84a4 100644 (file)
@@ -9,10 +9,8 @@
 
 #include <QtDebug>
 #include <QtCore/QCoreApplication>
-#include <QMessageService>
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
-#include "nshooter.h"
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent), ui(new Ui::MainWindow)
@@ -20,24 +18,6 @@ MainWindow::MainWindow(QWidget *parent)
     ui->setupUi(this);
 //    QPushButton *goButton;
 //    connect(goButton, SIGNAL(clicked()), this, SLOT(go_slot()));
-    nshooter = new NShooter(this);
-
-    msgManager = new QMessageManager(this);
-    QObject::connect(msgManager, SIGNAL(messageAdded(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)),
-                     this, SLOT(slot_message_received(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)));
-
-    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(nshooter, SIGNAL(fileReady(const QString &)),
-                     this, SLOT(slot_imageReady(const QString &)));
 }
 
 MainWindow::~MainWindow()
@@ -100,48 +80,9 @@ void MainWindow::showExpanded()
 }
 
 void MainWindow::on_gobutton_clicked() {
-    qDebug() << "go clicked";
+    qDebug() << "go clicked (not active)";
     //timer->start();
-    nshooter->go();
+    //nshooter->go();
 }
 
 
-void MainWindow::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();
-
-
-    QString content = msg.textContent();
-    qDebug() << "content" << content;
-
-    if (!content.compare("go", Qt::CaseInsensitive)) {
-        nshooter->go();
-    }
-}
-
-void MainWindow::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";
-    QMessageService *m_service = new QMessageService(this);
-    m_service->send(response);
-}
-/*
-void MainWindow::slot_timer_activation() {
-    // cam_shoot();
-    nshooter->go();
-}
-*/
index 709a202..785de56 100644 (file)
 #define MAINWINDOW_H
 
 #include <QtGui/QMainWindow>
-#include <QTimer>
-//#include <QMessageId>
-#include <QMessageManager>
 #include <mainwindow.h>
-#include "nshooter.h"
+#include "smshandler.h"
 
 namespace Ui {
     class MainWindow;
 }
-using namespace QtMobility;
 
 class MainWindow : public QMainWindow
 {
@@ -41,16 +37,10 @@ public:
 public slots:
     void on_gobutton_clicked();
 private slots:
-//    void slot_timer_activation();
-    void slot_message_received(const QMessageId&, const QMessageManager::NotificationFilterIdSet&);
-    void slot_imageReady(const QString &);
 
 private:
     Ui::MainWindow *ui;
-    QtMobility::QMessageManager *msgManager;
-    NShooter *nshooter;
-//    QTimer *timer;
-    QMessageAddress remoteAddr;
+    SmsHandler smsHandler;
 };
 
 #endif // MAINWINDOW_H
index 3f342ff..d59b52f 100644 (file)
@@ -16,9 +16,11 @@ CONFIG += mobility
 MOBILITY += multimedia messaging
 
 SOURCES += main.cpp mainwindow.cpp \
-    nshooter.cpp
+    nshooter.cpp \
+    smshandler.cpp
 HEADERS += mainwindow.h \
-    nshooter.h
+    nshooter.h \
+    smshandler.h
 FORMS += mainwindow.ui
 
 # Please do not modify the following two lines. Required for deployment.
index 77afd93..23f8566 100644 (file)
@@ -12,7 +12,6 @@ public:
     NShooter(QObject *parent=NULL);
     virtual ~NShooter();
     void go();
-
 signals:
     void fileReady(const QString &);
 
@@ -26,7 +25,6 @@ private slots:
 protected:
     void debug_dump(const char *);
 
-private:
     QCamera *camera;
     QCameraImageCapture *imageCapture;
     QImageEncoderSettings encoderSettings;
diff --git a/smshandler.cpp b/smshandler.cpp
new file mode 100644 (file)
index 0000000..420012a
--- /dev/null
@@ -0,0 +1,78 @@
+#include <QtDebug>
+#include <QMessageService>
+#include "smshandler.h"
+#include "nshooter.h"
+
+SmsHandler::SmsHandler(QObject *parent) :
+    QObject(parent)
+{
+  nshooter = new NShooter(this);
+
+  msgManager = new QMessageManager(this);
+  QObject::connect(msgManager, SIGNAL(messageAdded(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)),
+                   this, SLOT(slot_message_received(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)));
+
+  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(nshooter, 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();
+
+    QString content = msg.textContent();
+    qDebug() << "content" << content;
+
+    if (!content.compare("go", Qt::CaseInsensitive)) {
+        qDebug() << "receive mms snapshoot request";
+
+        qDebug() << "deleting original message";
+        msgManager->removeMessage(id);
+
+        qDebug() << "starting shooter";
+        nshooter->go();
+    }
+
+
+}
+
+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";
+}
+
+/*
+void SmsHandler::slot_timer_activation() {
+    // cam_shoot();
+    nshooter->go();
+}
+*/
diff --git a/smshandler.h b/smshandler.h
new file mode 100644 (file)
index 0000000..163ff74
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef SMSHANDLER_H
+#define SMSHANDLER_H
+
+#include <QObject>
+#include <QMessageManager>
+#include "nshooter.h"
+
+using namespace QtMobility;
+
+class SmsHandler : public QObject
+{
+    Q_OBJECT
+public:
+    explicit SmsHandler(QObject *parent = 0);
+
+signals:
+
+public slots:
+    void slot_message_received(const QMessageId&, const QMessageManager::NotificationFilterIdSet&);
+    void slot_imageReady(const QString &);
+
+protected:
+    QtMobility::QMessageManager *msgManager;
+    NShooter *nshooter;
+//    QTimer *timer;
+    QMessageAddress remoteAddr;
+
+};
+
+#endif // SMSHANDLER_H