Don't reuse file names
[harmattan/cameraplus] / lib / qtcamdevice.cpp
index 82bb19f..38da29b 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
@@ -102,8 +102,14 @@ QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name,
   g_signal_connect(d_ptr->cameraBin, "notify::idle",
                   G_CALLBACK(QtCamDevicePrivate::on_idle_changed), d_ptr);
 
-  g_signal_connect(d_ptr->wrapperVideoSource, "notify::ready-for-capture",
-                  G_CALLBACK(QtCamDevicePrivate::on_ready_for_capture_changed), d_ptr);
+  if (d_ptr->wrapperVideoSource) {
+    g_signal_connect(d_ptr->wrapperVideoSource, "notify::ready-for-capture",
+                    G_CALLBACK(QtCamDevicePrivate::on_ready_for_capture_changed), d_ptr);
+  }
+  else {
+    g_signal_connect(d_ptr->videoSource, "notify::ready-for-capture",
+                    G_CALLBACK(QtCamDevicePrivate::on_ready_for_capture_changed), d_ptr);
+  }
 
   d_ptr->image = new QtCamImageMode(d_ptr, this);
   d_ptr->video = new QtCamVideoMode(d_ptr, this);
@@ -142,20 +148,18 @@ bool QtCamDevice::setViewfinder(QtCamViewfinder *viewfinder) {
   }
 
   if (!viewfinder) {
-    qWarning() << "QtCamDevice: viewfinder cannot be unset.";
-    return false;
-  }
+    if (d_ptr->cameraBin) {
+      g_object_set(d_ptr->cameraBin, "viewfinder-sink", NULL, NULL);
+    }
 
-  if (d_ptr->viewfinder) {
-    qWarning() << "QtCamDevice: viewfinder cannot be replaced.";
-    return false;
-  }
+    d_ptr->sink = 0;
 
-  if (!viewfinder->setDevice(this)) {
-    return false;
+    d_ptr->viewfinder = 0;
+    return true;
   }
 
   d_ptr->viewfinder = viewfinder;
+  d_ptr->sink = 0;
 
   return true;
 }