First bunch of files
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 18:10:58 +0000 (18:10 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 10 Mar 2011 18:10:58 +0000 (18:10 +0000)
main.cpp [new file with mode: 0644]
mainwindow.cpp [new file with mode: 0644]
mainwindow.h [new file with mode: 0644]
mainwindow.ui [new file with mode: 0644]
nnokia.pro [new file with mode: 0644]
nshooter.cpp [new file with mode: 0644]
nshooter.h [new file with mode: 0644]

diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..ce69cf7
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,14 @@
+#include "mainwindow.h"
+
+#include <QtGui/QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication app(argc, argv);
+
+    MainWindow mainWindow;
+    mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
+    mainWindow.showExpanded();
+
+    return app.exec();
+}
diff --git a/mainwindow.cpp b/mainwindow.cpp
new file mode 100644 (file)
index 0000000..c3ef62f
--- /dev/null
@@ -0,0 +1,147 @@
+// checksum 0xa193 version 0x30001
+/*
+  This file was generated by the Mobile Qt Application wizard of Qt Creator.
+  MainWindow is a convenience class containing mobile device specific code
+  such as screen orientation handling.
+  It is recommended not to modify this file, since newer versions of Qt Creator
+  may offer an updated version of it.
+*/
+
+#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)
+{
+    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()
+{
+    delete ui;
+}
+
+void MainWindow::setOrientation(ScreenOrientation orientation)
+{
+#if defined(Q_OS_SYMBIAN)
+    // If the version of Qt on the device is < 4.7.2, that attribute won't work
+    if (orientation != ScreenOrientationAuto) {
+        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
+        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
+            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
+            return;
+        }
+    }
+#endif // Q_OS_SYMBIAN
+
+    Qt::WidgetAttribute attribute;
+    switch (orientation) {
+#if QT_VERSION < 0x040702
+    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
+    case ScreenOrientationLockPortrait:
+        attribute = static_cast<Qt::WidgetAttribute>(128);
+        break;
+    case ScreenOrientationLockLandscape:
+        attribute = static_cast<Qt::WidgetAttribute>(129);
+        break;
+    default:
+    case ScreenOrientationAuto:
+        attribute = static_cast<Qt::WidgetAttribute>(130);
+        break;
+#else // QT_VERSION < 0x040702
+    case ScreenOrientationLockPortrait:
+        attribute = Qt::WA_LockPortraitOrientation;
+        break;
+    case ScreenOrientationLockLandscape:
+        attribute = Qt::WA_LockLandscapeOrientation;
+        break;
+    default:
+    case ScreenOrientationAuto:
+        attribute = Qt::WA_AutoOrientation;
+        break;
+#endif // QT_VERSION < 0x040702
+    };
+    setAttribute(attribute, true);
+}
+
+void MainWindow::showExpanded()
+{
+#ifdef Q_OS_SYMBIAN
+    showFullScreen();
+#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
+    showMaximized();
+#else
+    show();
+#endif
+}
+
+void MainWindow::on_gobutton_clicked() {
+    qDebug() << "go clicked";
+    //timer->start();
+    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();
+}
+*/
diff --git a/mainwindow.h b/mainwindow.h
new file mode 100644 (file)
index 0000000..709a202
--- /dev/null
@@ -0,0 +1,56 @@
+// checksum 0x9a77 version 0x30001
+/*
+  This file was generated by the Mobile Qt Application wizard of Qt Creator.
+  MainWindow is a convenience class containing mobile device specific code
+  such as screen orientation handling.
+  It is recommended not to modify this file, since newer versions of Qt Creator
+  may offer an updated version of it.
+*/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+#include <QTimer>
+//#include <QMessageId>
+#include <QMessageManager>
+#include <mainwindow.h>
+#include "nshooter.h"
+
+namespace Ui {
+    class MainWindow;
+}
+using namespace QtMobility;
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+public:
+    enum ScreenOrientation {
+        ScreenOrientationLockPortrait,
+        ScreenOrientationLockLandscape,
+        ScreenOrientationAuto
+    };
+
+    explicit MainWindow(QWidget *parent = 0);
+    virtual ~MainWindow();
+
+    void setOrientation(ScreenOrientation orientation);
+    void showExpanded();
+
+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;
+};
+
+#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
new file mode 100644 (file)
index 0000000..5e12b6f
--- /dev/null
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>200</width>
+    <height>320</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QWidget" name="verticalLayoutWidget">
+    <property name="geometry">
+     <rect>
+      <x>0</x>
+      <y>0</y>
+      <width>201</width>
+      <height>321</height>
+     </rect>
+    </property>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <spacer name="verticalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <spacer name="horizontalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QPushButton" name="gobutton">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>go</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <spacer name="verticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </widget>
+  </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/nnokia.pro b/nnokia.pro
new file mode 100644 (file)
index 0000000..3f342ff
--- /dev/null
@@ -0,0 +1,26 @@
+# Add files and directories to ship with the application 
+# by adapting the examples below.
+# file1.source = myfile
+# dir1.source = mydir
+DEPLOYMENTFOLDERS = # file1 dir1
+
+symbian:TARGET.UID3 = 0xE0B4133F
+
+# Allow network access on Symbian
+symbian:TARGET.CAPABILITY += NetworkServices UserEnvironment ReadUserData WriteUserData ReadDeviceData WriteDeviceData
+
+# 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
+
+SOURCES += main.cpp mainwindow.cpp \
+    nshooter.cpp
+HEADERS += mainwindow.h \
+    nshooter.h
+FORMS += mainwindow.ui
+
+# Please do not modify the following two lines. Required for deployment.
+include(deployment.pri)
+qtcAddDeployment()
diff --git a/nshooter.cpp b/nshooter.cpp
new file mode 100644 (file)
index 0000000..f87eea0
--- /dev/null
@@ -0,0 +1,161 @@
+#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
new file mode 100644 (file)
index 0000000..77afd93
--- /dev/null
@@ -0,0 +1,36 @@
+#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 *);
+
+private:
+    QCamera *camera;
+    QCameraImageCapture *imageCapture;
+    QImageEncoderSettings encoderSettings;
+};
+
+
+#endif // NSHOOTER_H