2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 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
21 #include "qtcamconfig.h"
23 #include <QStringList>
26 #define CONFIGURATION_FILE "/etc/qtcamera/qtcamera.ini"
28 class QtCamConfigPrivate {
30 QString element(const QString& name) const {
31 return conf->value(QString("%1/element").arg(name)).toString();
34 QSize readResolution(const QString key) {
35 QList<QString> parts = conf->value(key).toString().trimmed().split("x");
36 return QSize(parts[0].toInt(), parts[1].toInt());
41 QList<QtCamImageSettings> imageSettings;
42 QList<QtCamVideoSettings> videoSettings;
45 QtCamConfig::QtCamConfig(QObject *parent) :
46 QObject(parent), d_ptr(new QtCamConfigPrivate) {
48 d_ptr->conf = new QSettings(CONFIGURATION_FILE, QSettings::IniFormat, this);
51 QtCamConfig::QtCamConfig(const QString& configPath, QObject *parent) :
52 QObject(parent), d_ptr(new QtCamConfigPrivate) {
54 d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
56 defaultImageSettings();
59 QtCamConfig::~QtCamConfig() {
63 QString QtCamConfig::deviceScannerType() const {
64 return d_ptr->conf->value("devices/scanner").toString();
67 QString QtCamConfig::deviceScannerProperty() const {
68 return d_ptr->conf->value("devices/property").toString();
71 QString QtCamConfig::videoSource() const {
72 return d_ptr->element("video-source");
75 QString QtCamConfig::viewfinderSink() const {
76 return d_ptr->element("viewfinder-sink");
79 QString QtCamConfig::viewfinderRenderer() const {
80 return d_ptr->conf->value("viewfinder-sink/renderer").toString();
83 QString QtCamConfig::audioSource() const {
84 return d_ptr->element("audio-source");
87 QString QtCamConfig::wrapperVideoSource() const {
88 return d_ptr->element("wrapper-video-source");
91 QString QtCamConfig::wrapperVideoSourceProperty() const {
92 return d_ptr->conf->value("wrapper-video-source/property").toString();
95 QtCamImageSettings QtCamConfig::defaultImageSettings() {
97 QList<QtCamImageSettings> settings = imageSettings();
99 QString def = d_ptr->conf->value("image/default").toString();
100 foreach (const QtCamImageSettings& s, settings) {
106 // This will crash if no presets have been shipped but you deserve paying
107 // the price of shipping a broken configuration file.
111 QList<QtCamImageSettings> QtCamConfig::imageSettings() {
112 if (d_ptr->imageSettings.isEmpty()) {
113 QStringList presets = d_ptr->conf->value("image/presets").toStringList();
114 foreach (const QString& preset, presets) {
115 d_ptr->conf->beginGroup(preset);
117 d_ptr->imageSettings <<
118 QtCamImageSettings(preset, d_ptr->conf->value("name").toString(),
119 d_ptr->readResolution("capture"),
120 d_ptr->readResolution("preview"),
121 d_ptr->readResolution("viewfinder"),
122 d_ptr->conf->value("fps").toInt(),
123 d_ptr->conf->value("night").toInt());
125 d_ptr->conf->endGroup();
129 return d_ptr->imageSettings;
132 QtCamVideoSettings QtCamConfig::defaultVideoSettings() {
133 QList<QtCamVideoSettings> settings = videoSettings();
135 QString def = d_ptr->conf->value("video/default").toString();
136 foreach (const QtCamVideoSettings& s, settings) {
142 // This will crash if no presets have been shipped but you deserve paying
143 // the price of shipping a broken configuration file.
147 QList<QtCamVideoSettings> QtCamConfig::videoSettings() {
148 if (d_ptr->videoSettings.isEmpty()) {
149 QStringList presets = d_ptr->conf->value("video/presets").toStringList();
150 foreach (const QString& preset, presets) {
151 d_ptr->conf->beginGroup(preset);
153 d_ptr->videoSettings <<
154 QtCamVideoSettings(preset, d_ptr->conf->value("name").toString(),
155 d_ptr->readResolution("capture"),
156 d_ptr->readResolution("preview"),
157 d_ptr->conf->value("fps").toInt(),
158 d_ptr->conf->value("night").toInt());
160 d_ptr->conf->endGroup();
164 return d_ptr->videoSettings;
167 QString QtCamConfig::imageEncodingProfileName() const {
168 return d_ptr->conf->value("image/profile-name").toString();
171 QString QtCamConfig::imageEncodingProfilePath() const {
172 return d_ptr->conf->value("image/profile-path").toString();
175 QString QtCamConfig::videoEncodingProfileName() const {
176 return d_ptr->conf->value("video/profile-name").toString();
179 QString QtCamConfig::videoEncodingProfilePath() const {
180 return d_ptr->conf->value("video/profile-path").toString();
183 QString QtCamConfig::audioCaptureCaps() const {
184 return d_ptr->conf->value("audio-capture-caps/caps").toString();
187 QString QtCamConfig::imageSuffix() const {
188 return d_ptr->conf->value("image/extension").toString();
191 QString QtCamConfig::videoSuffix() const {
192 return d_ptr->conf->value("video/extension").toString();