Convert TextSwitch to a platform specific component and rename it to CameraTextSwitch
[harmattan/cameraplus] / lib / qtcamcapability.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "qtcamcapability.h"
22 #include "qtcamdevice.h"
23 #include "qtcamdevice_p.h"
24 #include "qtcamcapability_p.h"
25
26 #ifndef GST_USE_UNSTABLE_API
27 #define GST_USE_UNSTABLE_API
28 #endif
29 #include <gst/interfaces/photography.h>
30
31 QtCamCapability::Capabilities QtCamCapability::capabilities(QtCamDevice *dev) {
32   if (!dev || !dev->d_ptr || !dev->d_ptr->videoSource) {
33     return QtCamCapability::Capabilities(0);
34   }
35
36   if (!GST_IS_PHOTOGRAPHY(dev->d_ptr->videoSource)) {
37     return QtCamCapability::Capabilities(0);
38   }
39
40   GstPhotography *photo = GST_PHOTOGRAPHY(dev->d_ptr->videoSource);
41   return QtCamCapability::Capabilities(gst_photography_get_capabilities(photo));
42 }
43
44 QtCamCapability::QtCamCapability(QtCamCapabilityPrivate *d, QObject *parent) :
45   QObject(parent), d_ptr(d) {
46   d_ptr->bin = d_ptr->dev->d_ptr->cameraBin;
47   d_ptr->src = d_ptr->dev->d_ptr->videoSource;
48   d_ptr->q_ptr = this;
49
50   if (!d_ptr->prop.isEmpty()) {
51     d_ptr->startMonitoring();
52   }
53 }
54
55 QtCamCapability::~QtCamCapability() {
56   if (!d_ptr->prop.isEmpty()) {
57     d_ptr->stopMonitoring();
58   }
59
60   delete d_ptr; d_ptr = 0;
61 }
62
63 bool QtCamCapability::isSupported() {
64   return QtCamCapability::capabilities(d_ptr->dev).testFlag(d_ptr->cap);
65 }