1 #include "qtcamconfig.h"
6 #define CONFIGURATION_FILE "/etc/qtcamera.ini"
8 class QtCamConfigPrivate {
10 QString element(const QString& name) const {
11 return conf->value(QString("%1/element").arg(name)).toString();
14 QSize readResolution(const QString key) {
15 QList<QString> parts = conf->value(key).toString().trimmed().split("x");
16 return QSize(parts[0].toInt(), parts[1].toInt());
19 QPair<int, int> readFrameRate(const QString& key) {
20 QList<QString> parts = conf->value(key).toString().trimmed().split("/");
21 return qMakePair<int, int>(parts[0].toInt(), parts[1].toInt());
26 QList<QtCamImageSettings> imageSettings;
27 QList<QtCamVideoSettings> videoSettings;
30 QtCamConfig::QtCamConfig(QObject *parent) :
31 QObject(parent), d_ptr(new QtCamConfigPrivate) {
33 d_ptr->conf = new QSettings(CONFIGURATION_FILE, QSettings::IniFormat, this);
36 QtCamConfig::QtCamConfig(const QString& configPath, QObject *parent) :
37 QObject(parent), d_ptr(new QtCamConfigPrivate) {
39 d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
41 defaultImageSettings();
44 QtCamConfig::~QtCamConfig() {
48 QString QtCamConfig::deviceScannerType() const {
49 return d_ptr->conf->value("devices/scanner").toString();
52 QString QtCamConfig::deviceScannerProperty() const {
53 return d_ptr->conf->value("devices/property").toString();
56 QString QtCamConfig::videoSource() const {
57 return d_ptr->element("video-source");
60 QString QtCamConfig::viewfinderSink() const {
61 return d_ptr->element("viewfinder-sink");
64 QString QtCamConfig::viewfinderRenderer() const {
65 return d_ptr->conf->value("viewfinder-sink/renderer").toString();
68 QString QtCamConfig::audioSource() const {
69 return d_ptr->element("audio-source");
72 QString QtCamConfig::wrapperVideoSource() const {
73 return d_ptr->element("wrapper-video-source");
76 QString QtCamConfig::wrapperVideoSourceProperty() const {
77 return d_ptr->conf->value("wrapper-video-source/property").toString();
80 QtCamImageSettings QtCamConfig::defaultImageSettings() {
82 QList<QtCamImageSettings> settings = imageSettings();
84 QString def = d_ptr->conf->value("image/default").toString();
85 foreach (const QtCamImageSettings& s, settings) {
91 // This will crash if no presets have been shipped but you deserve paying
92 // the price of shipping a broken configuration file.
96 QList<QtCamImageSettings> QtCamConfig::imageSettings() {
97 if (d_ptr->imageSettings.isEmpty()) {
98 QStringList presets = d_ptr->conf->value("image/presets").toStringList();
99 foreach (const QString& preset, presets) {
100 d_ptr->conf->beginGroup(preset);
102 QPair<int, int> fps = d_ptr->readFrameRate("fps");
103 QPair<int, int> night = d_ptr->readFrameRate("night");
105 d_ptr->imageSettings <<
106 QtCamImageSettings(preset, d_ptr->conf->value("name").toString(),
107 d_ptr->readResolution("capture"),
108 d_ptr->readResolution("preview"),
109 d_ptr->readResolution("viewfinder"),
110 fps.first, fps.second, night.first, night.second);
112 d_ptr->conf->endGroup();
116 return d_ptr->imageSettings;
119 QtCamVideoSettings QtCamConfig::defaultVideoSettings() {
120 QList<QtCamVideoSettings> settings = videoSettings();
122 QString def = d_ptr->conf->value("video/default").toString();
123 foreach (const QtCamVideoSettings& s, settings) {
129 // This will crash if no presets have been shipped but you deserve paying
130 // the price of shipping a broken configuration file.
134 QList<QtCamVideoSettings> QtCamConfig::videoSettings() {
135 if (d_ptr->videoSettings.isEmpty()) {
136 QStringList presets = d_ptr->conf->value("video/presets").toStringList();
137 foreach (const QString& preset, presets) {
138 d_ptr->conf->beginGroup(preset);
140 QPair<int, int> fps = d_ptr->readFrameRate("fps");
141 QPair<int, int> night = d_ptr->readFrameRate("night");
143 d_ptr->videoSettings <<
144 QtCamVideoSettings(preset, d_ptr->conf->value("name").toString(),
145 d_ptr->readResolution("capture"),
146 d_ptr->readResolution("preview"),
147 fps.first, fps.second, night.first, night.second);
149 d_ptr->conf->endGroup();
153 return d_ptr->videoSettings;
156 QString QtCamConfig::imageEncodingProfileName() const {
157 return d_ptr->conf->value("image/profile-name").toString();
160 QString QtCamConfig::imageEncodingProfilePath() const {
161 return d_ptr->conf->value("image/profile-path").toString();
164 QString QtCamConfig::videoEncodingProfileName() const {
165 return d_ptr->conf->value("video/profile-name").toString();
168 QString QtCamConfig::videoEncodingProfilePath() const {
169 return d_ptr->conf->value("video/profile-path").toString();
172 QString QtCamConfig::audioCaptureCaps() const {
173 return d_ptr->conf->value("audio-capture-caps/caps").toString();