Apply the mode only if the device is running. Otherwise postpone it until we call...
authorMohammed Sameer <msameer@foolab.org>
Sat, 8 Sep 2012 11:49:34 +0000 (14:49 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 8 Sep 2012 13:58:12 +0000 (16:58 +0300)
imports/camera.cpp
imports/camera.h

index 2bb6b9d..aa8fedc 100644 (file)
@@ -69,13 +69,6 @@ void Camera::setDeviceId(const QVariant& id) {
 
   m_vf->setDevice(m_dev);
 
-  if (m_mode == Camera::VideoMode) {
-    m_dev->videoMode()->activate();
-  }
-  else {
-    m_dev->imageMode()->activate();
-  }
-
   QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
                      this, SIGNAL(runningStateChanged()));
   QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
@@ -99,24 +92,18 @@ QtCamDevice *Camera::device() const {
 }
 
 void Camera::setMode(const Camera::CameraMode& mode) {
-  m_mode = mode;
-
-  if (!m_dev) {
+  if (m_mode == mode) {
     return;
   }
 
-  Camera::CameraMode current = m_dev->activeMode() == m_dev->videoMode() ?
-    Camera::VideoMode : Camera::ImageMode;
+  m_mode = mode;
 
-  if (current == mode) {
+  if (!m_dev) {
     return;
   }
 
-  if (mode == Camera::VideoMode) {
-    m_dev->videoMode()->activate();
-  }
-  else {
-    m_dev->imageMode()->activate();
+  if (m_dev->isRunning()) {
+    applyMode();
   }
 
   emit modeChanged();
@@ -127,7 +114,13 @@ Camera::CameraMode Camera::mode() {
 }
 
 bool Camera::start() {
-  return m_dev ? m_dev->start() : false;
+  if (!m_dev) {
+    return false;
+  }
+
+  applyMode();
+
+  return m_dev->start();
 }
 
 void Camera::stop() {
@@ -143,3 +136,12 @@ bool Camera::isIdle() {
 bool Camera::isRunning() {
   return m_dev ? m_dev->isRunning() : false;
 }
+
+void Camera::applyMode() {
+  if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
+    m_dev->videoMode()->activate();
+  }
+  else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
+    m_dev->imageMode()->activate();
+  }
+}
index 0267a6a..72051e5 100644 (file)
@@ -63,6 +63,8 @@ protected:
   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
 
 private:
+  void applyMode();
+
   QtCamera *m_cam;
   QtCamDevice *m_dev;
   QVariant m_id;