Adding the declarative imports
[harmattan/cameraplus] / imports / videotorch.cpp
1 #include "videotorch.h"
2 #include "qtcamvideotorch.h"
3 #include "camera.h"
4 #include "qtcamdevice.h"
5 #include "qtcamvideomode.h"
6
7 VideoTorch::VideoTorch(QObject *parent) :
8   QObject(parent), m_cam(0), m_torch(0) {
9
10 }
11
12 VideoTorch::~VideoTorch() {
13   m_cam = 0;
14 }
15
16 Camera *VideoTorch::camera() {
17   return m_cam;
18 }
19
20 void VideoTorch::setCamera(Camera *camera) {
21   if (camera == m_cam) {
22     return;
23   }
24
25   if (m_cam) {
26     QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
27   }
28
29   m_cam = camera;
30
31   if (m_cam) {
32     QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
33   }
34
35   emit cameraChanged();
36
37   deviceChanged();
38 }
39
40 bool VideoTorch::isOn() const {
41   return m_torch ? m_torch->isOn() : false;
42 }
43
44 void VideoTorch::setOn(bool on) {
45   if (m_torch) {
46     m_torch->setOn(on);
47   }
48 }
49
50 void VideoTorch::deviceChanged() {
51   if (m_torch) {
52     delete m_torch; m_torch = 0;
53   }
54
55   if (m_cam->device()) {
56     m_torch = new QtCamVideoTorch(m_cam->device(), this);
57     QObject::connect(m_torch, SIGNAL(stateChanged()), this, SIGNAL(stateChanged()));
58
59     emit stateChanged();
60   }
61 }