097305dad0034ca9d55637f85b74f3e10303d985
[harmattan/cameraplus] / lib / qtcamautofocus_p.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef QT_CAM_AUTO_FOCUS_P_H
24 #define QT_CAM_AUTO_FOCUS_P_H
25
26 #include "qtcamautofocus.h"
27 #include "qtcamgstreamermessagehandler.h"
28 #include "qtcamgstreamermessagelistener.h"
29 #include "qtcamdevice.h"
30 #include "qtcamdevice_p.h"
31
32 #include <QDebug>
33
34 #ifndef GST_USE_UNSTABLE_API
35 #define GST_USE_UNSTABLE_API
36 #endif /* GST_USE_UNSTABLE_API */
37 #include <gst/interfaces/photography.h>
38
39 class QtCamAutoFocusPrivate : public QObject {
40   Q_OBJECT
41
42 public:
43   QtCamAutoFocusPrivate(QtCamDevice *device, QtCamAutoFocus *q, QObject *parent = 0) :
44     QObject(parent),
45     dev(device),
46     q_ptr(q),
47     status(QtCamAutoFocus::None) {
48
49     handler = new QtCamGStreamerMessageHandler(GST_PHOTOGRAPHY_AUTOFOCUS_DONE, this);
50
51     QObject::connect(handler, SIGNAL(messageSent(GstMessage *)),
52                      this, SLOT(handleMessage(GstMessage *)));
53
54     dev->listener()->addHandler(handler);
55   }
56
57   ~QtCamAutoFocusPrivate() {
58     dev->listener()->removeHandler(handler);
59     delete handler; handler = 0;
60     dev = 0;
61     q_ptr = 0;
62   }
63
64   bool setEnabled(bool enabled) {
65     if (!dev->d_ptr->videoSource) {
66       return false;
67     }
68
69     if (!GST_IS_PHOTOGRAPHY(dev->d_ptr->videoSource)) {
70       return false;
71     }
72
73     GstPhotography *photo = GST_PHOTOGRAPHY(dev->d_ptr->videoSource);
74     if (!photo) {
75       return false;
76     }
77
78     gst_photography_set_autofocus(photo, enabled ? TRUE : FALSE);
79
80     return true;
81   }
82
83 public slots:
84   void handleMessage(GstMessage *message) {
85     const GstStructure *s = gst_message_get_structure(message);
86     int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
87
88     if (gst_structure_get_int(s, "status", &st)) {
89       if (status != st) {
90         status = (QtCamAutoFocus::Status) st;
91
92         // TODO: focus-window-rows, focus-window-columns, focus-windows and the rest
93         emit q_ptr->statusChanged();
94       }
95     }
96   }
97
98 public:
99   QtCamDevice *dev;
100   QtCamAutoFocus *q_ptr;
101   QtCamAutoFocus::Status status;
102   QtCamGStreamerMessageHandler *handler;
103 };
104
105 #endif /* QT_CAM_AUTO_FOCUS_P_H */