Initial implementation
[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   bool wrapperIsReady() {
19     if (!dev->wrapperVideoSource) {
20       return false;
21     }
22
23     gboolean ready = FALSE;
24     g_object_get(dev->wrapperVideoSource, "ready-for-capture", &ready, NULL);
25
26     return ready == TRUE;
27   }
28
29   QtCamImageSettings settings;
30 };
31
32 QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *d, QObject *parent) :
33   QtCamMode(new QtCamImageModePrivate(d), "mode-image", "image-done", parent) {
34
35   d_ptr = (QtCamImageModePrivate *)QtCamMode::d_ptr;
36
37   QString name = d_ptr->dev->conf->imageEncodingProfileName();
38   QString path = d_ptr->dev->conf->imageEncodingProfilePath();
39
40   if (!name.isEmpty() && !path.isEmpty()) {
41     GstEncodingProfile *profile = d_ptr->loadProfile(path, name);
42     if (profile) {
43       setProfile(profile);
44     }
45   }
46 }
47
48 QtCamImageMode::~QtCamImageMode() {
49
50 }
51
52 bool QtCamImageMode::canCapture() {
53   return QtCamMode::canCapture() && d_ptr->wrapperIsReady();
54 }
55
56 void QtCamImageMode::applySettings() {
57   setCaps("image-capture-caps", d_ptr->settings.captureResolution(),
58           d_ptr->settings.frameRate());
59   setCaps("viewfinder-caps", d_ptr->settings.viewfinderResolution(),
60           d_ptr->settings.frameRate());
61   setPreviewSize(d_ptr->settings.previewResolution());
62 }
63
64 void QtCamImageMode::start() {
65   // Nothing
66 }
67
68 void QtCamImageMode::stop() {
69   // Nothing
70 }
71
72 bool QtCamImageMode::capture(const QString& fileName) {
73   if (!canCapture()) {
74     return false;
75   }
76
77   setFileName(fileName);
78
79   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
80   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
81
82   return true;
83 }
84
85 bool QtCamImageMode::setSettings(const QtCamImageSettings& settings) {
86   d_ptr->settings = settings;
87
88   if (!d_ptr->dev->q_ptr->isIdle()) {
89     return false;
90   }
91
92   applySettings();
93
94   return true;
95 }
96
97 void QtCamImageMode::setProfile(GstEncodingProfile *profile) {
98   if (!d_ptr->dev->cameraBin) {
99     gst_encoding_profile_unref(profile);
100     return;
101   }
102
103   g_object_set(d_ptr->dev->cameraBin, "image-profile", profile, NULL);
104 }