Emit canCaptureChanged on the active mode when ready-for-capture changes
[harmattan/cameraplus] / lib / qtcammode_p.h
1 // -*- c++ -*-
2
3 #ifndef QT_CAM_MODE_P_H
4 #define QT_CAM_MODE_P_H
5
6 #include <QSize>
7 #include "qtcamdevice_p.h"
8 #include <gst/pbutils/encoding-profile.h>
9 #include <gst/pbutils/encoding-target.h>
10
11 class QtCamDevicePrivate;
12 class PreviewImageHandler;
13 class DoneHandler;
14
15 class QtCamModePrivate {
16 public:
17   QtCamModePrivate(QtCamDevicePrivate *d) : id(-1), dev(d) {}
18   virtual ~QtCamModePrivate() {}
19
20   int modeId(const char *mode) {
21     if (!dev->cameraBin) {
22       return -1;
23     }
24
25     GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(dev->cameraBin),
26                                                      "mode");
27     if (!pspec) {
28       return -1;
29     }
30
31     if (!G_IS_PARAM_SPEC_ENUM(pspec)) {
32       return -1;
33     }
34
35     GParamSpecEnum *e = (GParamSpecEnum *)pspec;
36     GEnumClass *klass = e->enum_class;
37
38     for (unsigned x = 0; x < klass->n_values; x++) {
39       if (QLatin1String(mode) == QLatin1String(klass->values[x].value_nick)) {
40         return klass->values[x].value;
41       }
42     }
43
44     return -1;
45   }
46
47   GstEncodingProfile *loadProfile(const QString& path, const QString& name) {
48     GError *error = NULL;
49
50     GstEncodingTarget *target = gst_encoding_target_load_from_file(path.toUtf8().data(), &error);
51     if (!target) {
52       qCritical() << "Failed to load encoding target from" << path << error->message;
53       g_error_free(error);
54       return 0;
55     }
56
57     GstEncodingProfile *profile = gst_encoding_target_get_profile(target, name.toUtf8().data());
58     if (!profile) {
59       qCritical() << "Failed to load encoding profile from" << path;
60       gst_encoding_target_unref(target);
61       return 0;
62     }
63
64     gst_encoding_target_unref(target);
65
66     return profile;
67   }
68
69   int id;
70   QtCamDevicePrivate *dev;
71   PreviewImageHandler *previewImageHandler;
72   DoneHandler *doneHandler;
73 };
74
75 #endif /* QT_CAM_MODE_P_H */