Renames nshooter into camshooter
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 20:00:56 +0000 (20:00 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 20:00:56 +0000 (20:00 +0000)
camshooter.cpp [new file with mode: 0644]
camshooter.h [new file with mode: 0644]
nnokia.pro
nshooter.cpp [deleted file]
nshooter.h [deleted file]
smshandler.cpp
smshandler.h

diff --git a/camshooter.cpp b/camshooter.cpp
new file mode 100644 (file)
index 0000000..3973712
--- /dev/null
@@ -0,0 +1,160 @@
+#include <QtDebug>
+#include <QCameraFocusControl>
+
+#include "camshooter.h"
+
+
+CamShooter::CamShooter(QObject *parent) : QObject(parent) {
+    camera = NULL;
+    imageCapture = NULL;
+    encoderSettings.setCodec("image/jpeg");
+    encoderSettings.setQuality(QtMultimediaKit::LowQuality);
+    //encoderSettings.setQuality(QtMultimediaKit::VeryLowQuality);
+}
+
+
+CamShooter::~CamShooter() {
+    if (imageCapture) {
+        delete imageCapture;
+        imageCapture = NULL;
+    }
+    if (camera) {
+        delete camera;
+        camera = NULL;
+    }
+}
+
+
+void CamShooter::debug_dump(const char *msg) {
+    qDebug() << msg;
+
+    qDebug() << "\t------------------";
+    if (camera) {
+        if (camera->error())
+            qDebug() << "\tCamera error" << camera->errorString();
+        else
+            qDebug() << "\tCamera no error";
+
+        qDebug() << "\tCamera state" << camera->state();
+        qDebug() << "\tCamera status" << camera->status();
+        qDebug() << "\tCamera lockstatus" << camera->lockStatus();
+    }
+
+    if (imageCapture) {
+        if (imageCapture->error())
+            qDebug() << "\tImageCapture error" << imageCapture->errorString();
+        else
+            qDebug() << "\tImageCapture no error";
+    }
+    qDebug() << "\t------------------";
+}
+
+
+void CamShooter::slot_cam_state(QCamera::State state) {
+    if (state == QCamera::LoadedState)
+        debug_dump("camera->state changed to LoadedState");
+    else
+        qDebug() << "camera->state changed to" << state;
+}
+
+void CamShooter::slot_cam_status(QCamera::Status status) {
+    if (status == QCamera::ActiveStatus) {
+
+        // set manual focus on infinity
+        qDebug() << "focus mode is now " << camera->focus()->focusMode();
+        camera->focus()->setFocusMode(QCameraFocus::InfinityFocus);
+        debug_dump("focus set to infinity");
+        qDebug() << "focus mode is now " << camera->focus()->focusMode();
+
+        // deactivating flash
+        QCameraExposure *camExposure = camera->exposure();
+        qDebug() << "Flash mode is now" << camExposure->flashMode();
+        qDebug() << "Setting flash mode to off";
+        camExposure->setFlashMode(QCameraExposure::FlashOff);
+        qDebug() << "Flash mode is now" << camExposure->flashMode();
+
+        debug_dump("Camera state is ActiveStatus. Calling searchAndLock.");
+        // disable autofocus
+        QCamera::LockTypes wantedlocks = camera->supportedLocks() & ~QCamera::LockFocus;
+        if (wantedlocks) {
+            camera->searchAndLock(wantedlocks);
+            debug_dump("after camera->searchAndLock");
+        } else {
+            qDebug() << "wantedlocks is 0. Calling slot_cam_lockstatus directly";
+            slot_cam_lockstatus(QCamera::Locked, QCamera::UserRequest);
+        }
+    }
+    else
+        qDebug() << "camera->status changed to" << status;
+}
+
+void CamShooter::slot_cam_lockstatus(QCamera::LockStatus status, QCamera::LockChangeReason reason) {
+    if (status == QCamera::Locked) {
+        qDebug() << "Lock acquired. Shooting.";
+        imageCapture->capture(); //QString("c:\Data\Images\image.jpg"));
+        debug_dump("after imageCapture->capture");
+    }
+    qDebug() << "camera->lockstatus changed to" << status << "because" << reason;
+}
+
+
+void CamShooter::slot_cap_captured(int id, const QImage&) {
+    qDebug() << "imageCaptured" << id;
+    qDebug() << "unlocking camera";
+    camera->unlock();
+    this->debug_dump("after camera->unlock");
+    qDebug() << "stoping camera";
+    camera->stop();
+    this->debug_dump("after camera->stop");
+    qDebug() << "unloading camera";
+    camera->unload();
+    this->debug_dump("after camera->unload");
+}
+
+void CamShooter::slot_cap_imageSaved(int id, const QString &fileName) {
+    qDebug() << "imageSaved" << id << fileName;
+    emit fileReady(fileName);
+}
+
+void CamShooter::go() {
+    if (!camera) {
+        camera = new QCamera(this);
+        if (!camera) {
+            qDebug() << "new QCamera failed";
+            return;
+        }
+        QObject::connect(camera, SIGNAL(stateChanged (QCamera::State)),
+                         this, SLOT(slot_cam_state(QCamera::State)));
+        QObject::connect(camera, SIGNAL(statusChanged (QCamera::Status)),
+                         this, SLOT(slot_cam_status(QCamera::Status)));
+        QObject::connect(camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason)),
+                         this, SLOT(slot_cam_lockstatus(QCamera::LockStatus, QCamera::LockChangeReason)));
+
+        camera->setCaptureMode(QCamera::CaptureStillImage);
+        debug_dump("after camera->setCaptureMode");
+    }
+
+    if (!imageCapture) {
+        imageCapture = new QCameraImageCapture(camera, this);
+        if (!imageCapture) {
+            qDebug() << "new QCameraImageCapture failed";
+            return;
+        }
+        QObject::connect(imageCapture, SIGNAL(imageCaptured(int, const QImage&)),
+                         this, SLOT(slot_cap_captured(int, const QImage&)));
+        QObject::connect(imageCapture, SIGNAL(imageSaved(int, const QString&)),
+                         this, SLOT(slot_cap_imageSaved(int, const QString&)));
+        imageCapture->setEncodingSettings(encoderSettings);
+    }
+
+    QCamera::Status curstatus = camera->status();
+    if (curstatus != QCamera::ActiveStatus) {
+        qDebug() << "camera status is" << curstatus << "Starting cameara...";
+        camera->start();
+        debug_dump("after camera->start");
+    } else {
+        // direct call to slot
+        slot_cam_status(QCamera::ActiveStatus);
+    }
+}
+
diff --git a/camshooter.h b/camshooter.h
new file mode 100644 (file)
index 0000000..41b65d5
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef NSHOOTER_H
+#define NSHOOTER_H
+
+#include <QObject>
+#include <QCamera>
+#include <QCameraImageCapture>
+
+class CamShooter : public QObject {
+    Q_OBJECT
+
+public:
+    CamShooter(QObject *parent=NULL);
+    virtual ~CamShooter();
+    void go();
+signals:
+    void fileReady(const QString &);
+
+private slots:
+    void slot_cam_state(QCamera::State state);
+    void slot_cam_status(QCamera::Status status);
+    void slot_cam_lockstatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
+    void slot_cap_captured(int id, const QImage &preview);
+    void slot_cap_imageSaved(int id, const QString &fileName);
+
+protected:
+    void debug_dump(const char *);
+
+    QCamera *camera;
+    QCameraImageCapture *imageCapture;
+    QImageEncoderSettings encoderSettings;
+};
+
+
+#endif // NSHOOTER_H
index d59b52f1a7f63844f1f25019a04324285de9285d..693bf2f271ad41aab88a435a7bd4c414d97b4b48 100644 (file)
@@ -16,11 +16,11 @@ CONFIG += mobility
 MOBILITY += multimedia messaging
 
 SOURCES += main.cpp mainwindow.cpp \
-    nshooter.cpp \
-    smshandler.cpp
+    smshandler.cpp \
+    camshooter.cpp
 HEADERS += mainwindow.h \
-    nshooter.h \
-    smshandler.h
+    smshandler.h \
+    camshooter.h
 FORMS += mainwindow.ui
 
 # Please do not modify the following two lines. Required for deployment.
diff --git a/nshooter.cpp b/nshooter.cpp
deleted file mode 100644 (file)
index f87eea0..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-#include <QtDebug>
-#include <QCameraFocusControl>
-
-#include "nshooter.h"
-
-
-
-NShooter::NShooter(QObject *parent) : QObject(parent) {
-    camera = NULL;
-    imageCapture = NULL;
-    encoderSettings.setCodec("image/jpeg");
-    encoderSettings.setQuality(QtMultimediaKit::LowQuality);
-    //encoderSettings.setQuality(QtMultimediaKit::VeryLowQuality);
-}
-
-
-NShooter::~NShooter() {
-    if (imageCapture) {
-        delete imageCapture;
-        imageCapture = NULL;
-    }
-    if (camera) {
-        delete camera;
-        camera = NULL;
-    }
-}
-
-
-void NShooter::debug_dump(const char *msg) {
-    qDebug() << msg;
-
-    qDebug() << "\t------------------";
-    if (camera) {
-        if (camera->error())
-            qDebug() << "\tCamera error" << camera->errorString();
-        else
-            qDebug() << "\tCamera no error";
-
-        qDebug() << "\tCamera state" << camera->state();
-        qDebug() << "\tCamera status" << camera->status();
-        qDebug() << "\tCamera lockstatus" << camera->lockStatus();
-    }
-
-    if (imageCapture) {
-        if (imageCapture->error())
-            qDebug() << "\tImageCapture error" << imageCapture->errorString();
-        else
-            qDebug() << "\tImageCapture no error";
-    }
-    qDebug() << "\t------------------";
-}
-
-
-void NShooter::slot_cam_state(QCamera::State state) {
-    if (state == QCamera::LoadedState)
-        debug_dump("camera->state changed to LoadedState");
-    else
-        qDebug() << "camera->state changed to" << state;
-}
-
-void NShooter::slot_cam_status(QCamera::Status status) {
-    if (status == QCamera::ActiveStatus) {
-
-        // set manual focus on infinity
-        qDebug() << "focus mode is now " << camera->focus()->focusMode();
-        camera->focus()->setFocusMode(QCameraFocus::InfinityFocus);
-        debug_dump("focus set to infinity");
-        qDebug() << "focus mode is now " << camera->focus()->focusMode();
-
-        // deactivating flash
-        QCameraExposure *camExposure = camera->exposure();
-        qDebug() << "Flash mode is now" << camExposure->flashMode();
-        qDebug() << "Setting flash mode to off";
-        camExposure->setFlashMode(QCameraExposure::FlashOff);
-        qDebug() << "Flash mode is now" << camExposure->flashMode();
-
-        debug_dump("Camera state is ActiveStatus. Calling searchAndLock.");
-        // disable autofocus
-        QCamera::LockTypes wantedlocks = camera->supportedLocks() & ~QCamera::LockFocus;
-        if (wantedlocks) {
-            camera->searchAndLock(wantedlocks);
-            debug_dump("after camera->searchAndLock");
-        } else {
-            qDebug() << "wantedlocks is 0. Calling slot_cam_lockstatus directly";
-            slot_cam_lockstatus(QCamera::Locked, QCamera::UserRequest);
-        }
-    }
-    else
-        qDebug() << "camera->status changed to" << status;
-}
-
-void NShooter::slot_cam_lockstatus(QCamera::LockStatus status, QCamera::LockChangeReason reason) {
-    if (status == QCamera::Locked) {
-        qDebug() << "Lock acquired. Shooting.";
-        imageCapture->capture(); //QString("c:\Data\Images\image.jpg"));
-        debug_dump("after imageCapture->capture");
-    }
-    qDebug() << "camera->lockstatus changed to" << status << "because" << reason;
-}
-
-
-void NShooter::slot_cap_captured(int id, const QImage&) {
-    qDebug() << "imageCaptured" << id;
-    qDebug() << "unlocking camera";
-    camera->unlock();
-    this->debug_dump("after camera->unlock");
-    qDebug() << "stoping camera";
-    camera->stop();
-    this->debug_dump("after camera->stop");
-    qDebug() << "unloading camera";
-    camera->unload();
-    this->debug_dump("after camera->unload");
-}
-
-void NShooter::slot_cap_imageSaved(int id, const QString &fileName) {
-    qDebug() << "imageSaved" << id << fileName;
-    emit fileReady(fileName);
-}
-
-void NShooter::go() {
-    if (!camera) {
-        camera = new QCamera(this);
-        if (!camera) {
-            qDebug() << "new QCamera failed";
-            return;
-        }
-        QObject::connect(camera, SIGNAL(stateChanged (QCamera::State)),
-                         this, SLOT(slot_cam_state(QCamera::State)));
-        QObject::connect(camera, SIGNAL(statusChanged (QCamera::Status)),
-                         this, SLOT(slot_cam_status(QCamera::Status)));
-        QObject::connect(camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason)),
-                         this, SLOT(slot_cam_lockstatus(QCamera::LockStatus, QCamera::LockChangeReason)));
-
-        camera->setCaptureMode(QCamera::CaptureStillImage);
-        debug_dump("after camera->setCaptureMode");
-    }
-
-    if (!imageCapture) {
-        imageCapture = new QCameraImageCapture(camera, this);
-        if (!imageCapture) {
-            qDebug() << "new QCameraImageCapture failed";
-            return;
-        }
-        QObject::connect(imageCapture, SIGNAL(imageCaptured(int, const QImage&)),
-                         this, SLOT(slot_cap_captured(int, const QImage&)));
-        QObject::connect(imageCapture, SIGNAL(imageSaved(int, const QString&)),
-                         this, SLOT(slot_cap_imageSaved(int, const QString&)));
-        imageCapture->setEncodingSettings(encoderSettings);
-    }
-
-    QCamera::Status curstatus = camera->status();
-    if (curstatus != QCamera::ActiveStatus) {
-        qDebug() << "camera status is" << curstatus << "Starting cameara...";
-        camera->start();
-        debug_dump("after camera->start");
-    } else {
-        // direct call to slot
-        slot_cam_status(QCamera::ActiveStatus);
-    }
-}
-
diff --git a/nshooter.h b/nshooter.h
deleted file mode 100644 (file)
index 23f8566..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef NSHOOTER_H
-#define NSHOOTER_H
-
-#include <QObject>
-#include <QCamera>
-#include <QCameraImageCapture>
-
-class NShooter : public QObject {
-    Q_OBJECT
-
-public:
-    NShooter(QObject *parent=NULL);
-    virtual ~NShooter();
-    void go();
-signals:
-    void fileReady(const QString &);
-
-private slots:
-    void slot_cam_state(QCamera::State state);
-    void slot_cam_status(QCamera::Status status);
-    void slot_cam_lockstatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
-    void slot_cap_captured(int id, const QImage &preview);
-    void slot_cap_imageSaved(int id, const QString &fileName);
-
-protected:
-    void debug_dump(const char *);
-
-    QCamera *camera;
-    QCameraImageCapture *imageCapture;
-    QImageEncoderSettings encoderSettings;
-};
-
-
-#endif // NSHOOTER_H
index 420012a68435fc0c81b929cc028de219446555ce..527ea38d93df966a8c08e2b6598746acf86de8ff 100644 (file)
@@ -1,12 +1,12 @@
 #include <QtDebug>
 #include <QMessageService>
 #include "smshandler.h"
-#include "nshooter.h"
+#include "camshooter.h"
 
 SmsHandler::SmsHandler(QObject *parent) :
     QObject(parent)
 {
-  nshooter = new NShooter(this);
+  camShooter = new CamShooter(this);
 
   msgManager = new QMessageManager(this);
   QObject::connect(msgManager, SIGNAL(messageAdded(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)),
@@ -22,7 +22,7 @@ SmsHandler::SmsHandler(QObject *parent) :
   timer->setSingleShot(false);
   QObject::connect(timer, SIGNAL(timeout()), this, SLOT(slot_timer_activation()));
   */
-  QObject::connect(nshooter, SIGNAL(fileReady(const QString &)),
+  QObject::connect(camShooter, SIGNAL(fileReady(const QString &)),
                    this, SLOT(slot_imageReady(const QString &)));
 }
 
@@ -44,10 +44,8 @@ void SmsHandler::slot_message_received(const QMessageId & id, const QMessageMana
         msgManager->removeMessage(id);
 
         qDebug() << "starting shooter";
-        nshooter->go();
+        camShooter->go();
     }
-
-
 }
 
 void SmsHandler::slot_imageReady(const QString &filename) {
@@ -69,10 +67,3 @@ void SmsHandler::slot_imageReady(const QString &filename) {
     }
     qDebug() << "message" << response.id().toString() << "queued";
 }
-
-/*
-void SmsHandler::slot_timer_activation() {
-    // cam_shoot();
-    nshooter->go();
-}
-*/
index 163ff74a29b7f40b29a8eb785a35c19a9dd11f54..b421c02f186b0b9f98b475c84865ca3ad295d4ee 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <QObject>
 #include <QMessageManager>
-#include "nshooter.h"
+#include "camshooter.h"
 
 using namespace QtMobility;
 
@@ -21,7 +21,7 @@ public slots:
 
 protected:
     QtMobility::QMessageManager *msgManager;
-    NShooter *nshooter;
+    CamShooter *camShooter;
 //    QTimer *timer;
     QMessageAddress remoteAddr;