2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
23 #include "qtcamdevice.h"
24 #include "qtcammode.h"
25 #include "qtcamimagemode.h"
26 #include "qtcamvideomode.h"
27 #include "qtcamconfig.h"
29 #include "notificationscontainer.h"
32 #include <QDeclarativeInfo>
40 #include "whitebalance.h"
41 #include "colortone.h"
45 #include "noisereduction.h"
46 #include "flickerreduction.h"
48 #include "autofocus.h"
51 #include "videomute.h"
52 #include "videotorch.h"
53 #include "cameraconfig.h"
56 Camera::Camera(QObject *parent) :
58 m_cam(new QtCamera(this)),
60 m_mode(Camera::UnknownMode),
61 m_notifications(new NotificationsContainer(this)),
72 m_flickerReduction(0),
78 m_config(new CameraConfig(this)),
81 m_config->componentComplete();
86 if (m_dev->activeMode()) {
87 m_dev->activeMode()->deactivate();
99 delete m_whiteBalance;
104 delete m_noiseReduction;
105 delete m_flickerReduction;
114 int Camera::deviceCount() const {
115 return m_cam ? m_cam->devices().size() : 0;
118 QString Camera::deviceName(int index) const {
119 return m_cam->devices().at(index).first;
122 QVariant Camera::deviceId(int index) const {
123 return m_cam->devices().at(index).second;
126 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
127 if (mode == Camera::UnknownMode) {
128 qmlInfo(this) << "Cannot set mode to unknown";
132 QVariant oldId = m_id;
133 Camera::CameraMode oldMode = m_mode;
135 if (setDeviceId(deviceId) && setMode(mode)) {
137 emit deviceIdChanged();
138 emit deviceChanged();
143 if (oldMode != m_mode) {
153 bool Camera::setDeviceId(const QVariant& deviceId) {
154 if (deviceId == m_id) {
158 if (m_dev && m_dev->stop(false)) {
159 emit prepareForDeviceChange();
163 qmlInfo(this) << "Failed to stop device";
167 m_dev = m_cam->device(deviceId, this);
171 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
172 this, SIGNAL(runningStateChanged()));
173 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
174 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
175 this, SIGNAL(error(const QString&, int, const QString&)));
177 m_notifications->setDevice(m_dev);
182 QVariant Camera::deviceId() const {
186 QtCamDevice *Camera::device() const {
190 bool Camera::setMode(const Camera::CameraMode& mode) {
191 if (m_mode == mode) {
201 if (m_dev->isRunning()) {
208 Camera::CameraMode Camera::mode() {
212 bool Camera::start() {
221 return m_dev->start();
224 bool Camera::stop(bool force) {
226 return m_dev->stop(force);
232 bool Camera::isIdle() {
233 return m_dev ? m_dev->isIdle() : true;
236 bool Camera::isRunning() {
237 return m_dev ? m_dev->isRunning() : false;
240 bool Camera::applyMode() {
241 if (m_mode == Camera::UnknownMode) {
245 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
246 m_dev->videoMode()->activate();
248 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
249 m_dev->imageMode()->activate();
255 QString Camera::imageSuffix() const {
256 return m_cam->config()->imageSuffix();
259 QString Camera::videoSuffix() const {
260 return m_cam->config()->videoSuffix();
263 Sounds *Camera::sounds() const {
264 return m_notifications->sounds();
266 void Camera::setSounds(Sounds *sounds) {
267 if (m_notifications->setSounds(sounds)) {
269 emit soundsChanged();
273 void Camera::resetCapabilities() {
274 QtCamDevice *dev = device();
277 m_zoom = new Zoom(dev, this);
281 m_flash = new Flash(dev, this);
285 m_scene = new Scene(dev, this);
289 m_evComp = new EvComp(dev, this);
290 emit evCompChanged();
292 delete m_whiteBalance;
293 m_whiteBalance = new WhiteBalance(dev, this);
294 emit whiteBalanceChanged();
297 m_colorTone = new ColorTone(dev, this);
298 emit colorToneChanged();
301 m_iso = new Iso(dev, this);
305 m_exposure = new Exposure(dev, this);
306 emit exposureChanged();
309 m_aperture = new Aperture(dev, this);
310 emit apertureChanged();
312 delete m_noiseReduction;
313 m_noiseReduction = new NoiseReduction(dev, this);
314 emit noiseReductionChanged();
316 delete m_flickerReduction;
317 m_flickerReduction = new FlickerReduction(dev, this);
318 emit flickerReductionChanged();
321 m_focus = new Focus(dev, this);
325 m_autoFocus = new AutoFocus(dev, this);
326 emit autoFocusChanged();
329 m_roi = new Roi(dev, this);
333 m_videoMute = new VideoMute(dev, this);
334 emit videoMuteChanged();
337 m_videoTorch = new VideoTorch(dev, this);
338 emit videoTorchChanged();
341 m_quirks = new Quirks(dev->config()->quirks(dev->id()), this);
342 emit quirksChanged();
345 Zoom *Camera::zoom() const {
349 Flash *Camera::flash() const {
353 Scene *Camera::scene() const {
357 EvComp *Camera::evComp() const {
361 WhiteBalance *Camera::whiteBalance() const {
362 return m_whiteBalance;
365 ColorTone *Camera::colorTone() const {
369 Iso *Camera::iso() const {
373 Exposure *Camera::exposure() const {
377 Aperture *Camera::aperture() const {
381 NoiseReduction *Camera::noiseReduction() const {
382 return m_noiseReduction;
385 FlickerReduction *Camera::flickerReduction() const {
386 return m_flickerReduction;
389 Focus *Camera::focus() const {
393 AutoFocus *Camera::autoFocus() const {
397 Roi *Camera::roi() const {
401 VideoMute *Camera::videoMute() const {
405 VideoTorch *Camera::videoTorch() const {
409 CameraConfig *Camera::cameraConfig() const {
413 Quirks *Camera::quirks() const {