Add a new data member for the class specific private pointer instead of the mess...
[harmattan/cameraplus] / lib / qtcamimagemode.cpp
1 #include "qtcamimagemode.h"
2 #include "qtcammode_p.h"
3 #include "qtcamdevice_p.h"
4 #include "qtcamimagesettings.h"
5 #include "qtcamdevice.h"
6
7 class QtCamImageModePrivate : public QtCamModePrivate {
8 public:
9   QtCamImageModePrivate(QtCamDevicePrivate *dev) :
10   QtCamModePrivate(dev),
11   settings(dev->conf->defaultImageSettings()) {
12
13   }
14
15   ~QtCamImageModePrivate() {
16   }
17
18   QtCamImageSettings settings;
19 };
20
21 QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *dev, QObject *parent) :
22   QtCamMode(new QtCamImageModePrivate(dev), "mode-image", "image-done", parent) {
23
24   d = (QtCamImageModePrivate *)d_ptr;
25
26   QString name = d_ptr->dev->conf->imageEncodingProfileName();
27   QString path = d_ptr->dev->conf->imageEncodingProfilePath();
28
29   if (!name.isEmpty() && !path.isEmpty()) {
30     GstEncodingProfile *profile = d_ptr->loadProfile(path, name);
31     if (profile) {
32       setProfile(profile);
33     }
34   }
35 }
36
37 QtCamImageMode::~QtCamImageMode() {
38   d = 0;
39 }
40
41 bool QtCamImageMode::canCapture() {
42   return QtCamMode::canCapture() && d_ptr->dev->isWrapperReady();
43 }
44
45 void QtCamImageMode::applySettings() {
46   d_ptr->setCaps("image-capture-caps", d->settings.captureResolution(),
47                  d->settings.frameRate());
48   d_ptr->setCaps("viewfinder-caps", d->settings.viewfinderResolution(),
49                  d->settings.frameRate());
50
51   setPreviewSize(d->settings.previewResolution());
52 }
53
54 void QtCamImageMode::start() {
55   // Nothing
56 }
57
58 void QtCamImageMode::stop() {
59   // Nothing
60 }
61
62 bool QtCamImageMode::capture(const QString& fileName) {
63   if (!canCapture()) {
64     return false;
65   }
66
67   setFileName(fileName);
68
69   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
70   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
71
72   return true;
73 }
74
75 bool QtCamImageMode::setSettings(const QtCamImageSettings& settings) {
76   d->settings = settings;
77
78   if (!d_ptr->dev->q_ptr->isIdle()) {
79     return false;
80   }
81
82   applySettings();
83
84   return true;
85 }
86
87 void QtCamImageMode::setProfile(GstEncodingProfile *profile) {
88   if (!d_ptr->dev->cameraBin) {
89     gst_encoding_profile_unref(profile);
90     return;
91   }
92
93   g_object_set(d_ptr->dev->cameraBin, "image-profile", profile, NULL);
94 }