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
21 #include "qtcamconfig.h"
23 #include <QStringList>
26 #define CONFIGURATION_FILE DATA_DIR"/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());
39 QVariant readWithFallback(const QString& generic, const QString& specific, const QString& key) {
40 QString genericKey = QString("%1/%2").arg(generic).arg(key);
41 QString specificKey = QString("%1/%2").arg(specific).arg(key);
43 QVariant var = conf->value(genericKey);
45 return conf->value(specificKey, var);
50 QList<QtCamImageSettings> imageSettings;
51 QList<QtCamVideoSettings> videoSettings;
54 QtCamConfig::QtCamConfig(QObject *parent) :
55 QObject(parent), d_ptr(new QtCamConfigPrivate) {
57 d_ptr->conf = new QSettings(CONFIGURATION_FILE, QSettings::IniFormat, this);
60 QtCamConfig::QtCamConfig(const QString& configPath, QObject *parent) :
61 QObject(parent), d_ptr(new QtCamConfigPrivate) {
63 d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
66 QtCamConfig::~QtCamConfig() {
70 QString QtCamConfig::deviceScannerType() const {
71 return d_ptr->conf->value("devices/scanner").toString();
74 QString QtCamConfig::deviceScannerProperty() const {
75 return d_ptr->conf->value("devices/property").toString();
78 QString QtCamConfig::videoSource() const {
79 return d_ptr->element("video-source");
82 QString QtCamConfig::viewfinderSink() const {
83 return d_ptr->element("viewfinder-sink");
86 QString QtCamConfig::viewfinderRenderer() const {
87 return d_ptr->conf->value("viewfinder-sink/renderer").toString();
90 bool QtCamConfig::viewfinderUseFence() const {
91 return d_ptr->conf->value("viewfinder-sink/use-fence").toBool();
94 QString QtCamConfig::audioSource() const {
95 return d_ptr->element("audio-source");
98 QString QtCamConfig::wrapperVideoSource() const {
99 return d_ptr->element("wrapper-video-source");
102 QString QtCamConfig::wrapperVideoSourceProperty() const {
103 return d_ptr->conf->value("wrapper-video-source/property").toString();
106 QtCamImageSettings *QtCamConfig::imageSettings(const QVariant& id) {
107 QString generic = "image";
108 QString specific = QString("%1-%2").arg(generic).arg(id.toString());
110 QString profileName = d_ptr->readWithFallback(generic, specific, "profile-name").toString();
111 QString profilePath = d_ptr->readWithFallback(generic, specific, "profile-path").toString();
112 QString suffix = d_ptr->readWithFallback(generic, specific, "extension").toString();
113 QStringList presets = d_ptr->readWithFallback(generic, specific, "presets").toStringList();
115 QList<QtCamImageResolution> resolutions;
117 foreach (const QString& preset, presets) {
118 d_ptr->conf->beginGroup(preset);
121 QString name = d_ptr->conf->value("name").toString();
122 QSize capture = d_ptr->readResolution("capture");
123 QSize preview = d_ptr->readResolution("preview");
124 QSize viewfinder = d_ptr->readResolution("viewfinder");
125 int fps = d_ptr->conf->value("fps").toInt();
126 int nightFps = d_ptr->conf->value("night").toInt();
127 int megaPixels = d_ptr->conf->value("megapixels").toInt();
128 QString aspectRatio = d_ptr->conf->value("aspectratio").toString();
130 d_ptr->conf->endGroup();
132 resolutions << QtCamImageResolution(id, name, capture, preview, viewfinder,
133 fps, nightFps, megaPixels, aspectRatio);
136 return new QtCamImageSettings(id.toString(), suffix, profileName, profilePath, resolutions);
139 QtCamVideoSettings *QtCamConfig::videoSettings(const QVariant& id) {
140 QString generic = "video";
141 QString specific = QString("%1-%2").arg(generic).arg(id.toString());
143 QString profileName = d_ptr->readWithFallback(generic, specific, "profile-name").toString();
144 QString profilePath = d_ptr->readWithFallback(generic, specific, "profile-path").toString();
145 QString suffix = d_ptr->readWithFallback(generic, specific, "extension").toString();
146 QStringList presets = d_ptr->readWithFallback(generic, specific, "presets").toStringList();
148 QList<QtCamVideoResolution> resolutions;
150 foreach (const QString& preset, presets) {
151 d_ptr->conf->beginGroup(preset);
154 QString name = d_ptr->conf->value("name").toString();
155 QSize capture = d_ptr->readResolution("capture");
156 QSize preview = d_ptr->readResolution("preview");
157 int fps = d_ptr->conf->value("fps").toInt();
158 int nightFps = d_ptr->conf->value("night").toInt();
159 QString aspectRatio = d_ptr->conf->value("aspectratio").toString();
160 QString resolution = d_ptr->conf->value("resolution").toString();
162 d_ptr->conf->endGroup();
164 resolutions << QtCamVideoResolution(id, name, capture, preview,
165 fps, nightFps, aspectRatio, resolution);
168 return new QtCamVideoSettings(id.toString(), suffix, profileName, profilePath, resolutions);
171 QString QtCamConfig::imageEncodingProfileName() const {
172 return d_ptr->conf->value("image/profile-name").toString();
175 QString QtCamConfig::imageEncodingProfilePath() const {
176 return d_ptr->conf->value("image/profile-path").toString();
179 QString QtCamConfig::videoEncodingProfileName() const {
180 return d_ptr->conf->value("video/profile-name").toString();
183 QString QtCamConfig::videoEncodingProfilePath() const {
184 return d_ptr->conf->value("video/profile-path").toString();
187 QString QtCamConfig::audioCaptureCaps() const {
188 return d_ptr->conf->value("audio-capture-caps/caps").toString();
191 QString QtCamConfig::imageSuffix() const {
192 return d_ptr->conf->value("image/extension").toString();
195 QString QtCamConfig::videoSuffix() const {
196 return d_ptr->conf->value("video/extension").toString();
199 QStringList QtCamConfig::viewfinderFilters() const {
200 return d_ptr->conf->value("viewfinder-filters/elements").toStringList();
203 QString QtCamConfig::roiElement() const {
204 return d_ptr->conf->value("roi/element").toString();
207 QString QtCamConfig::roiMessageName() const {
208 return d_ptr->conf->value("roi/message").toString();
211 QString QtCamConfig::roiEnableProperty() const {
212 return d_ptr->conf->value("roi/enable").toString();
215 QString QtCamConfig::roiMessage() const {
216 return d_ptr->conf->value("roi/message").toString();