Code cleanup
[harmattan/cameraplus] / lib / qtcamvideomode.cpp
index 87177cf..1f7121f 100644 (file)
 #include "qtcamdevice_p.h"
 #include "qtcamdevice.h"
 #include "qtcamvideosettings.h"
+#include "qtcamnotifications.h"
 
 class QtCamVideoModePrivate : public QtCamModePrivate {
 public:
   QtCamVideoModePrivate(QtCamDevicePrivate *dev) :
   QtCamModePrivate(dev),
-  settings(dev->conf->defaultVideoSettings()) {
+  settings(dev->conf->videoSettings(dev->id)),
+  resolution(settings->defaultResolution()) {
 
   }
 
-  ~QtCamVideoModePrivate() {}
+  ~QtCamVideoModePrivate() {
+    delete settings;
+  }
 
   void _d_idleStateChanged(bool isIdle) {
     if (isIdle && dev->active == dev->video) {
@@ -42,7 +46,8 @@ public:
     }
   }
 
-  QtCamVideoSettings settings;
+  QtCamVideoSettings *settings;
+  QtCamVideoResolution resolution;
 };
 
 QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
@@ -75,16 +80,16 @@ bool QtCamVideoMode::canCapture() {
 void QtCamVideoMode::applySettings() {
   bool night = d_ptr->inNightMode();
 
-  int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
+  int fps = night ? d->resolution.nightFrameRate() : d->resolution.frameRate();
 
-  d_ptr->setCaps("viewfinder-caps", d->settings.captureResolution(), fps);
+  d_ptr->setCaps("viewfinder-caps", d->resolution.captureResolution(), fps);
 
-  d_ptr->setCaps("video-capture-caps", d->settings.captureResolution(), fps);
+  d_ptr->setCaps("video-capture-caps", d->resolution.captureResolution(), fps);
 
-  setPreviewSize(d->settings.previewResolution());
+  d_ptr->setPreviewSize(d->resolution.previewResolution());
 
-  // TODO:
-  //  d_ptr->resetCaps("image-capture-caps");
+  // Not sure this is needed but just in case.
+  d_ptr->resetCaps("image-capture-caps");
 }
 
 void QtCamVideoMode::start() {
@@ -110,7 +115,9 @@ bool QtCamVideoMode::startRecording(const QString& fileName) {
     return false;
   }
 
-  setFileName(fileName);
+  d_ptr->setFileName(fileName);
+
+  QMetaObject::invokeMethod(d_ptr->dev->notifications, "videoRecordingStarted");
 
   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
@@ -128,10 +135,17 @@ void QtCamVideoMode::stopRecording() {
   }
 }
 
-bool QtCamVideoMode::setSettings(const QtCamVideoSettings& settings) {
-  d->settings = settings;
+bool QtCamVideoMode::setResolution(const QtCamVideoResolution& resolution) {
+  d->resolution = resolution;
+
+  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->isRunning() || isRecording()) {
+  if (isRecording()) {
     return false;
   }
 
@@ -149,4 +163,8 @@ void QtCamVideoMode::setProfile(GstEncodingProfile *profile) {
   g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
 }
 
+QtCamVideoSettings *QtCamVideoMode::settings() {
+  return d->settings;
+}
+
 #include "moc_qtcamvideomode.cpp"