X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lib%2Fqtcamconfig.cpp;h=1b2a1b83f4dbe197169b601d4635559c021ba214;hb=0da718e86100458cc336d51ca79554e4fbac415d;hp=25469e18a5baf2ae1f11fc4e4d09a5b45b7ee9b3;hpb=6925320432654d459f3b4151062198ecfce79d0d;p=harmattan%2Fcameraplus diff --git a/lib/qtcamconfig.cpp b/lib/qtcamconfig.cpp index 25469e1..1b2a1b8 100644 --- a/lib/qtcamconfig.cpp +++ b/lib/qtcamconfig.cpp @@ -1,9 +1,29 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * 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 #include #include -#define CONFIGURATION_FILE "/etc/qtcamera.ini" +#define CONFIGURATION_FILE DATA_DIR"/qtcamera.ini" class QtCamConfigPrivate { public: @@ -16,6 +36,15 @@ 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 imageSettings; @@ -32,8 +61,6 @@ QtCamConfig::QtCamConfig(const QString& configPath, QObject *parent) : QObject(parent), d_ptr(new QtCamConfigPrivate) { d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this); - - defaultImageSettings(); } QtCamConfig::~QtCamConfig() { @@ -60,6 +87,10 @@ QString QtCamConfig::viewfinderRenderer() const { 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"); } @@ -72,76 +103,69 @@ QString QtCamConfig::wrapperVideoSourceProperty() const { 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 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 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 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 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 resolutions; + + foreach (const QString& preset, presets) { + d_ptr->conf->beginGroup(preset); -QList 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); + 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->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()); + 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 { @@ -171,3 +195,27 @@ QString QtCamConfig::imageSuffix() const { QString QtCamConfig::videoSuffix() const { return d_ptr->conf->value("video/extension").toString(); } + +QStringList QtCamConfig::viewfinderFilters() const { + return d_ptr->conf->value("viewfinder-filters/elements").toStringList(); +} + +QString QtCamConfig::roiElement() const { + return d_ptr->conf->value("roi/element").toString(); +} + +QString QtCamConfig::roiMessageName() const { + return d_ptr->conf->value("roi/message").toString(); +} + +QString QtCamConfig::roiEnableProperty() const { + return d_ptr->conf->value("roi/enable").toString(); +} + +QString QtCamConfig::roiMessage() const { + return d_ptr->conf->value("roi/message").toString(); +} + +bool QtCamConfig::isPreviewSupported() const { + return d_ptr->conf->value("general/preview-supported").toBool(); +}