Kill CameraButtonRow and use the QtQuick Row component
[harmattan/cameraplus] / lib / qtcamera.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 "qtcamera.h"
22 #include "qtcamscanner.h"
23 #include "qtcamconfig.h"
24 #include "qtcamdevice.h"
25 #include "gst/gstcopy.h"
26 #include <gst/gst.h>
27
28 class QtCameraPrivate {
29 public:
30   QtCamConfig *conf;
31   QtCamScanner *scanner;
32 };
33
34 QtCamera::QtCamera(QObject *parent) :
35   QObject(parent), d_ptr(new QtCameraPrivate) {
36
37   gst_init(0, 0);
38   qt_cam_copy_register();
39
40   d_ptr->conf = new QtCamConfig(this);
41   d_ptr->scanner = new QtCamScanner(d_ptr->conf, this);
42
43   refreshDevices();
44 }
45
46 QtCamera::QtCamera(const QString& configPath, QObject *parent) :
47   QObject(parent), d_ptr(new QtCameraPrivate) {
48
49   gst_init(0, 0);
50   qt_cam_copy_register();
51
52   d_ptr->conf = new QtCamConfig(configPath, this);
53   d_ptr->scanner = new QtCamScanner(d_ptr->conf, this);
54
55   refreshDevices();
56 }
57
58 QtCamera::QtCamera(QtCamConfig *config, QObject *parent) :
59   QObject(parent), d_ptr(new QtCameraPrivate) {
60
61   gst_init(0, 0);
62   qt_cam_copy_register();
63
64   d_ptr->conf = config;
65   d_ptr->scanner = new QtCamScanner(d_ptr->conf, this);
66
67   refreshDevices();
68 }
69
70 QtCamera::~QtCamera() {
71   delete d_ptr; d_ptr = 0;
72
73   gst_deinit();
74 }
75
76 void QtCamera::refreshDevices() {
77   d_ptr->scanner->refresh();
78 }
79
80 QList<QPair<QString, QVariant> > QtCamera::devices() const {
81   return d_ptr->scanner->devices();
82 }
83
84 QtCamDevice *QtCamera::device(const QVariant& id, QObject *parent) {
85   QList<QPair<QString, QVariant> > devs = devices();
86
87   // G++ barfs with foreach and class templates.
88   typedef QPair<QString, QVariant> Dev;
89   foreach (const Dev& dev, devs) {
90     if (dev.second == id) {
91       return new QtCamDevice(d_ptr->conf, dev.first, dev.second, parent ? parent : this);
92     }
93   }
94
95   return 0;
96 }
97
98 QtCamConfig *QtCamera::config() const {
99   return d_ptr->conf;
100 }