Changes to night mode handling:
[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   bool night = d_ptr->inNightMode();
47
48   int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
49
50   d_ptr->setCaps("viewfinder-caps", d->settings.viewfinderResolution(), fps);
51
52   // FIXME:
53   // Ideally, we should query the image-capture-supported-caps and get a proper framerate
54   // as it seems that subdevsrc2 can only capture 15 FPS for at least the highest resolution
55   // we use. For now we will not set any FPS.
56   d_ptr->setCaps("image-capture-caps", d->settings.captureResolution(), -1);
57
58   setPreviewSize(d->settings.previewResolution());
59
60   // TODO: ?
61   // d_ptr->resetCaps("video-capture-caps");
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->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 }