index is still invalid if its row equals the number of resolutions
[harmattan/cameraplus] / imports / capability.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 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 "capability.h"
22 #include "camera.h"
23
24 Capability::Capability(QObject *parent) :
25   QObject(parent),
26   m_cam(0) {
27
28 }
29
30 Capability::~Capability() {
31
32 }
33
34 Camera *Capability::camera() {
35   return m_cam;
36 }
37
38 void Capability::setCamera(Camera *cam) {
39   if (cam == m_cam) {
40     return;
41   }
42
43   if (m_cam) {
44     QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
45     QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
46   }
47
48   m_cam = cam;
49
50   if (m_cam) {
51     QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
52     QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
53   }
54
55   emit cameraChanged();
56
57   deviceChanged();
58
59   emit isReadyChanged();
60 }
61
62 bool Capability::isReady() const {
63   return m_cam && m_cam->device();
64 }