populate post capture model when page is current and clear it when we leave
[harmattan/cameraplus] / lib / qtcamimagemode.cpp
index 05a6d10..6aae13b 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
@@ -42,7 +42,9 @@ public:
 };
 
 QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *dev, QObject *parent) :
-  QtCamMode(new QtCamImageModePrivate(dev), "mode-image", "image-done", parent) {
+  QtCamMode(new QtCamImageModePrivate(dev), "mode-image", parent) {
+
+  d_ptr->init(new DoneHandler(d_ptr, "image-done", this));
 
   d = (QtCamImageModePrivate *)d_ptr;
 
@@ -62,7 +64,7 @@ QtCamImageMode::~QtCamImageMode() {
 }
 
 bool QtCamImageMode::canCapture() {
-  return QtCamMode::canCapture() && d_ptr->dev->isWrapperReady();
+  return QtCamMode::canCapture() && d_ptr->dev->isReadyForCapture();
 }
 
 void QtCamImageMode::applySettings() {
@@ -78,14 +80,15 @@ void QtCamImageMode::applySettings() {
   // we use. For now we will not set any FPS.
   d_ptr->setCaps("image-capture-caps", d->resolution.captureResolution(), -1);
 
-  setPreviewSize(d->resolution.previewResolution());
+  d_ptr->setPreviewSize(d->resolution.previewResolution());
 
-  // TODO: ?
-  // d_ptr->resetCaps("video-capture-caps");
+  // If we don't reset the caps then: if we switch from video to image then we fail
+  // the next time we restart the pipeline.
+  d_ptr->resetCaps("video-capture-caps");
 }
 
 void QtCamImageMode::start() {
-  // Nothing
+  d_ptr->enableViewfinderFilters();
 }
 
 void QtCamImageMode::stop() {
@@ -101,7 +104,7 @@ bool QtCamImageMode::capture(const QString& fileName) {
     return false;
   }
 
-  setFileName(fileName);
+  d_ptr->setFileName(fileName);
 
   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
@@ -112,7 +115,14 @@ bool QtCamImageMode::capture(const QString& fileName) {
 bool QtCamImageMode::setResolution(const QtCamImageResolution& resolution) {
   d->resolution = resolution;
 
-  if (!d_ptr->dev->q_ptr->isRunning() || !d_ptr->dev->q_ptr->isIdle()) {
+  if (!d_ptr->dev->q_ptr->isRunning()) {
+    // We will return true here because setting the resolution on a non-running pipeline
+    // doesn't make much sense (Probably the only use case is as a kind of optimization only).
+    // We will set it anyway when the pipeline gets started.
+    return true;
+  }
+
+  if (!d_ptr->dev->q_ptr->isIdle()) {
     return false;
   }
 
@@ -133,3 +143,7 @@ void QtCamImageMode::setProfile(GstEncodingProfile *profile) {
 QtCamImageSettings *QtCamImageMode::settings() const {
   return d->settings;
 }
+
+QtCamImageResolution QtCamImageMode::currentResolution() {
+  return d->resolution;
+}