Changelog for 0.0.8
[harmattan/cameraplus] / declarative / mode.cpp
index 4d62458..f59ee36 100644 (file)
@@ -1,7 +1,7 @@
 /*!
  * This file is part of CameraPlus.
  *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -28,7 +28,8 @@ Mode::Mode(QObject *parent) :
   QObject(parent),
   m_cam(0),
   m_mode(0),
-  m_seq(0) {
+  m_seq(0),
+  m_previewEnabled(true) {
 
 }
 
@@ -47,6 +48,7 @@ void Mode::setCamera(Camera *camera) {
   }
 
   if (m_cam) {
+    QObject::disconnect(m_cam, SIGNAL(prepareForDeviceChange()), this, SLOT(prepareForDeviceChange()));
     QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
     QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
   }
@@ -54,6 +56,7 @@ void Mode::setCamera(Camera *camera) {
   m_cam = camera;
 
   if (m_cam) {
+    QObject::connect(m_cam, SIGNAL(prepareForDeviceChange()), this, SLOT(prepareForDeviceChange()));
     QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
     QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
   }
@@ -74,22 +77,6 @@ bool Mode::canCapture() {
 }
 
 void Mode::deviceChanged() {
-  if (m_mode) {
-    QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
-    QObject::disconnect(m_mode, SIGNAL(saved(const QString&)),
-                       this, SIGNAL(saved(const QString&)));
-    QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
-                       this, SLOT(gotPreview(const QImage&, const QString&)));
-    QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
-    QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
-    QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
-                       this, SIGNAL(canCaptureChanged()));
-    QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
-                       this, SIGNAL(canCaptureChanged()));
-
-    preChangeMode();
-  }
-
   if (!m_cam || !m_cam->device()) {
     return;
   }
@@ -108,6 +95,8 @@ void Mode::deviceChanged() {
     QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
                     this, SIGNAL(canCaptureChanged()));
 
+    setPreviewState();
+
     postChangeMode();
   }
 
@@ -128,3 +117,46 @@ void Mode::gotPreview(const QImage& image, const QString& fileName) {
 bool Mode::isReady() const {
   return m_mode;
 }
+
+void Mode::prepareForDeviceChange() {
+  if (m_mode) {
+    QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_mode, SIGNAL(saved(const QString&)),
+                       this, SIGNAL(saved(const QString&)));
+    QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
+                       this, SLOT(gotPreview(const QImage&, const QString&)));
+    QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
+    QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
+                       this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
+                       this, SIGNAL(canCaptureChanged()));
+
+    preChangeMode();
+  }
+}
+
+bool Mode::isPreviewEnabled() {
+  return m_previewEnabled;
+}
+
+void Mode::setPreviewEnabled(bool enabled) {
+  if (enabled != m_previewEnabled) {
+    m_previewEnabled = enabled;
+
+    if (m_mode) {
+      setPreviewState();
+    }
+
+    emit enablePreviewChanged();
+  }
+}
+
+void Mode::setPreviewState() {
+  if (m_previewEnabled) {
+    m_mode->enablePreview();
+  }
+  else {
+    m_mode->disablePreview();
+  }
+}