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());
21 QList<QtCamImageSettings> imageSettings;
22 QList<QtCamVideoSettings> videoSettings;
25 QtCamConfig::QtCamConfig(QObject *parent) :
26 QObject(parent), d_ptr(new QtCamConfigPrivate) {
28 d_ptr->conf = new QSettings(CONFIGURATION_FILE, QSettings::IniFormat, this);
31 QtCamConfig::QtCamConfig(const QString& configPath, QObject *parent) :
32 QObject(parent), d_ptr(new QtCamConfigPrivate) {
34 d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
36 defaultImageSettings();
39 QtCamConfig::~QtCamConfig() {
43 QString QtCamConfig::deviceScannerType() const {
44 return d_ptr->conf->value("devices/scanner").toString();
47 QString QtCamConfig::deviceScannerProperty() const {
48 return d_ptr->conf->value("devices/property").toString();
51 QString QtCamConfig::videoSource() const {
52 return d_ptr->element("video-source");
55 QString QtCamConfig::viewfinderSink() const {
56 return d_ptr->element("viewfinder-sink");
59 QString QtCamConfig::viewfinderRenderer() const {
60 return d_ptr->conf->value("viewfinder-sink/renderer").toString();
63 QString QtCamConfig::audioSource() const {
64 return d_ptr->element("audio-source");
67 QString QtCamConfig::wrapperVideoSource() const {
68 return d_ptr->element("wrapper-video-source");
71 QString QtCamConfig::wrapperVideoSourceProperty() const {
72 return d_ptr->conf->value("wrapper-video-source/property").toString();
75 QtCamImageSettings QtCamConfig::defaultImageSettings() {
77 QList<QtCamImageSettings> settings = imageSettings();
79 QString def = d_ptr->conf->value("image/default").toString();
80 foreach (const QtCamImageSettings& s, settings) {
86 // This will crash if no presets have been shipped but you deserve paying
87 // the price of shipping a broken configuration file.
91 QList<QtCamImageSettings> QtCamConfig::imageSettings() {
92 if (d_ptr->imageSettings.isEmpty()) {
93 QStringList presets = d_ptr->conf->value("image/presets").toStringList();
94 foreach (const QString& preset, presets) {
95 d_ptr->conf->beginGroup(preset);
97 d_ptr->imageSettings <<
98 QtCamImageSettings(preset, d_ptr->conf->value("name").toString(),
99 d_ptr->readResolution("capture"),
100 d_ptr->readResolution("preview"),
101 d_ptr->readResolution("viewfinder"),
102 d_ptr->conf->value("fps").toInt(),
103 d_ptr->conf->value("night").toInt());
105 d_ptr->conf->endGroup();
109 return d_ptr->imageSettings;
112 QtCamVideoSettings QtCamConfig::defaultVideoSettings() {
113 QList<QtCamVideoSettings> settings = videoSettings();
115 QString def = d_ptr->conf->value("video/default").toString();
116 foreach (const QtCamVideoSettings& s, settings) {
122 // This will crash if no presets have been shipped but you deserve paying
123 // the price of shipping a broken configuration file.
127 QList<QtCamVideoSettings> QtCamConfig::videoSettings() {
128 if (d_ptr->videoSettings.isEmpty()) {
129 QStringList presets = d_ptr->conf->value("video/presets").toStringList();
130 foreach (const QString& preset, presets) {
131 d_ptr->conf->beginGroup(preset);
133 d_ptr->videoSettings <<
134 QtCamVideoSettings(preset, d_ptr->conf->value("name").toString(),
135 d_ptr->readResolution("capture"),
136 d_ptr->readResolution("preview"),
137 d_ptr->conf->value("fps").toInt(),
138 d_ptr->conf->value("night").toInt());
140 d_ptr->conf->endGroup();
144 return d_ptr->videoSettings;
147 QString QtCamConfig::imageEncodingProfileName() const {
148 return d_ptr->conf->value("image/profile-name").toString();
151 QString QtCamConfig::imageEncodingProfilePath() const {
152 return d_ptr->conf->value("image/profile-path").toString();
155 QString QtCamConfig::videoEncodingProfileName() const {
156 return d_ptr->conf->value("video/profile-name").toString();
159 QString QtCamConfig::videoEncodingProfilePath() const {
160 return d_ptr->conf->value("video/profile-path").toString();
163 QString QtCamConfig::audioCaptureCaps() const {
164 return d_ptr->conf->value("audio-capture-caps/caps").toString();