+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include "qtcamconfig.h"
#include <QSettings>
#include <QStringList>
#include <QDebug>
-#define CONFIGURATION_FILE "/etc/qtcamera.ini"
+#define CONFIGURATION_FILE "/etc/qtcamera/qtcamera.ini"
class QtCamConfigPrivate {
public:
return QSize(parts[0].toInt(), parts[1].toInt());
}
+ QVariant readWithFallback(const QString& generic, const QString& specific, const QString& key) {
+ QString genericKey = QString("%1/%2").arg(generic).arg(key);
+ QString specificKey = QString("%1/%2").arg(specific).arg(key);
+
+ QVariant var = conf->value(genericKey);
+
+ return conf->value(specificKey, var);
+ }
+
QSettings *conf;
QList<QtCamImageSettings> imageSettings;
QObject(parent), d_ptr(new QtCamConfigPrivate) {
d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
-
- defaultImageSettings();
}
QtCamConfig::~QtCamConfig() {
return d_ptr->conf->value("viewfinder-sink/renderer").toString();
}
+bool QtCamConfig::viewfinderUseFence() const {
+ return d_ptr->conf->value("viewfinder-sink/use-fence").toBool();
+}
+
QString QtCamConfig::audioSource() const {
return d_ptr->element("audio-source");
}
return d_ptr->conf->value("wrapper-video-source/property").toString();
}
-QtCamImageSettings QtCamConfig::defaultImageSettings() {
+QtCamImageSettings *QtCamConfig::imageSettings(const QVariant& id) {
+ QString generic = "image";
+ QString specific = QString("%1-%2").arg(generic).arg(id.toString());
- QList<QtCamImageSettings> settings = imageSettings();
+ QString profileName = d_ptr->readWithFallback(generic, specific, "profile-name").toString();
+ QString profilePath = d_ptr->readWithFallback(generic, specific, "profile-path").toString();
+ QString suffix = d_ptr->readWithFallback(generic, specific, "extension").toString();
+ QStringList presets = d_ptr->readWithFallback(generic, specific, "presets").toStringList();
- QString def = d_ptr->conf->value("image/default").toString();
- foreach (const QtCamImageSettings& s, settings) {
- if (s.id() == def) {
- return s;
- }
- }
+ QList<QtCamImageResolution> resolutions;
- // This will crash if no presets have been shipped but you deserve paying
- // the price of shipping a broken configuration file.
- return settings[0];
-}
+ foreach (const QString& preset, presets) {
+ d_ptr->conf->beginGroup(preset);
-QList<QtCamImageSettings> QtCamConfig::imageSettings() {
- if (d_ptr->imageSettings.isEmpty()) {
- QStringList presets = d_ptr->conf->value("image/presets").toStringList();
- foreach (const QString& preset, presets) {
- d_ptr->conf->beginGroup(preset);
+ QString id = preset;
+ QString name = d_ptr->conf->value("name").toString();
+ QSize capture = d_ptr->readResolution("capture");
+ QSize preview = d_ptr->readResolution("preview");
+ QSize viewfinder = d_ptr->readResolution("viewfinder");
+ int fps = d_ptr->conf->value("fps").toInt();
+ int nightFps = d_ptr->conf->value("night").toInt();
+ int megaPixels = d_ptr->conf->value("megapixels").toInt();
+ QString aspectRatio = d_ptr->conf->value("aspectratio").toString();
- d_ptr->imageSettings <<
- QtCamImageSettings(preset, d_ptr->conf->value("name").toString(),
- d_ptr->readResolution("capture"),
- d_ptr->readResolution("preview"),
- d_ptr->readResolution("viewfinder"),
- d_ptr->conf->value("fps").toInt(),
- d_ptr->conf->value("night").toInt());
+ d_ptr->conf->endGroup();
- d_ptr->conf->endGroup();
- }
+ resolutions << QtCamImageResolution(id, name, capture, preview, viewfinder,
+ fps, nightFps, megaPixels, aspectRatio);
}
- return d_ptr->imageSettings;
+ return new QtCamImageSettings(id.toString(), suffix, profileName, profilePath, resolutions);
}
-QtCamVideoSettings QtCamConfig::defaultVideoSettings() {
- QList<QtCamVideoSettings> settings = videoSettings();
+QtCamVideoSettings *QtCamConfig::videoSettings(const QVariant& id) {
+ QString generic = "video";
+ QString specific = QString("%1-%2").arg(generic).arg(id.toString());
- QString def = d_ptr->conf->value("video/default").toString();
- foreach (const QtCamVideoSettings& s, settings) {
- if (s.id() == def) {
- return s;
- }
- }
+ QString profileName = d_ptr->readWithFallback(generic, specific, "profile-name").toString();
+ QString profilePath = d_ptr->readWithFallback(generic, specific, "profile-path").toString();
+ QString suffix = d_ptr->readWithFallback(generic, specific, "extension").toString();
+ QStringList presets = d_ptr->readWithFallback(generic, specific, "presets").toStringList();
- // This will crash if no presets have been shipped but you deserve paying
- // the price of shipping a broken configuration file.
- return settings[0];
-}
+ QList<QtCamVideoResolution> resolutions;
-QList<QtCamVideoSettings> QtCamConfig::videoSettings() {
- if (d_ptr->videoSettings.isEmpty()) {
- QStringList presets = d_ptr->conf->value("video/presets").toStringList();
- foreach (const QString& preset, presets) {
- d_ptr->conf->beginGroup(preset);
+ foreach (const QString& preset, presets) {
+ d_ptr->conf->beginGroup(preset);
- d_ptr->videoSettings <<
- QtCamVideoSettings(preset, d_ptr->conf->value("name").toString(),
- d_ptr->readResolution("capture"),
- d_ptr->readResolution("preview"),
- d_ptr->conf->value("fps").toInt(),
- d_ptr->conf->value("night").toInt());
+ QString id = preset;
+ QString name = d_ptr->conf->value("name").toString();
+ QSize capture = d_ptr->readResolution("capture");
+ QSize preview = d_ptr->readResolution("preview");
+ int fps = d_ptr->conf->value("fps").toInt();
+ int nightFps = d_ptr->conf->value("night").toInt();
+ QString aspectRatio = d_ptr->conf->value("aspectratio").toString();
+ QString resolution = d_ptr->conf->value("resolution").toString();
- d_ptr->conf->endGroup();
- }
+ d_ptr->conf->endGroup();
+
+ resolutions << QtCamVideoResolution(id, name, capture, preview,
+ fps, nightFps, aspectRatio, resolution);
}
- return d_ptr->videoSettings;
+ return new QtCamVideoSettings(id.toString(), suffix, profileName, profilePath, resolutions);
}
QString QtCamConfig::imageEncodingProfileName() const {
QString QtCamConfig::audioCaptureCaps() const {
return d_ptr->conf->value("audio-capture-caps/caps").toString();
}
+
+QString QtCamConfig::imageSuffix() const {
+ return d_ptr->conf->value("image/extension").toString();
+}
+
+QString QtCamConfig::videoSuffix() const {
+ return d_ptr->conf->value("video/extension").toString();
+}
+
+QString QtCamConfig::imageCaptureStartedSound() const {
+ return d_ptr->conf->value("sounds/imageCaptureStarted").toString();
+}
+
+QString QtCamConfig::imageCaptureEndedSound() const {
+ return d_ptr->conf->value("sounds/imageCaptureEnded").toString();
+}
+
+QString QtCamConfig::videoRecordingStartedSound() const {
+ return d_ptr->conf->value("sounds/videoRecordingStarted").toString();
+}
+
+QString QtCamConfig::videoRecordingEndedSound() const {
+ return d_ptr->conf->value("sounds/videoRecordingEnded").toString();
+}
+
+QString QtCamConfig::autoFocusAcquiredSound() const {
+ return d_ptr->conf->value("sounds/autoFocusAcquired").toString();
+}
+
+QStringList QtCamConfig::viewfinderFilters() const {
+ return d_ptr->conf->value("viewfinder-filters/elements").toStringList();
+}