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
24 #include "devicesettings.h"
26 #define PATH QString("%1%2.config%2/cameraplus.conf").arg(QDir::homePath()).arg(QDir::separator())
28 #define DEFAULT_MODE 1
29 #define DEFAULT_USE_GPS true
30 #define DEFAULT_USE_GEOTAGS true
31 #define DEFAULT_SOUND_ENABLED true
32 #define DEFAULT_SHOW_TOOL_BAR false
33 #define DEFAULT_VIDEO_MUTE false
34 #define DEFAULT_GRID_ENABLED false
35 #define DEFAULT_FACE_DETECTION_ENABLED true
36 #define DEFAULT_ZOOM_AS_SHUTTER false
37 #define DEFAULT_PROXIMITY_AS_SHUTTER false
38 #define DEFAULT_DEVICE 0
39 #define DEFAULT_ENABLE_PREVIEW true
41 Settings::Settings(QObject *parent) :
43 m_settings(new QSettings(PATH, QSettings::IniFormat, this)),
48 Settings::~Settings() {
49 delete m_settings; m_settings = 0;
50 delete m_device; m_device = 0;
53 int Settings::mode() const {
54 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
57 void Settings::setMode(int mode) {
58 if (mode != Settings::mode()) {
59 m_settings->setValue("camera/mode", mode);
65 QString Settings::creatorName() const {
66 return m_settings->value("camera/creatorName").toString();
69 void Settings::setCreatorName(const QString& name) {
70 if (name != creatorName()) {
71 m_settings->setValue("camera/creatorName", name);
73 emit creatorNameChanged();
77 bool Settings::useGps() const {
78 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
81 void Settings::setUseGps(bool enable) {
82 if (enable != useGps()) {
83 m_settings->setValue("camera/useGps", enable);
89 bool Settings::useGeotags() const {
90 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
93 void Settings::setUseGeotags(bool enable) {
94 if (enable != useGeotags()) {
95 m_settings->setValue("camera/useGeotags", enable);
97 emit useGeotagsChanged();
101 bool Settings::isSoundEnabled() const {
102 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
105 void Settings::setSoundEnabled(bool enabled) {
106 if (isSoundEnabled() != enabled) {
107 m_settings->setValue("camera/soundEnabled", enabled);
108 emit soundEnabledChanged();
112 bool Settings::isToolBarShown() const {
113 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
116 void Settings::setToolBarShown(bool shown) {
117 if (isToolBarShown() != shown) {
118 m_settings->setValue("camera/showToolBar", shown);
120 emit toolBarShownChanged();
124 bool Settings::isVideoMuted() const {
125 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
128 void Settings::setVideoMuted(bool muted) {
129 if (isVideoMuted() != muted) {
130 m_settings->setValue("video/mute", muted);
131 emit videoMutedChanged();
135 bool Settings::isGridEnabled() const {
136 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
139 void Settings::setGridEnabled(bool enabled) {
140 if (enabled != isGridEnabled()) {
141 m_settings->setValue("camera/gridEnabled", enabled);
142 emit gridEnabledChanged();
146 bool Settings::isFaceDetectionEnabled() const {
147 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
150 void Settings::setFaceDetectionEnabled(bool enabled) {
151 if (isFaceDetectionEnabled() != enabled) {
152 m_settings->setValue("image/faceDetectionEnabled", enabled);
153 emit faceDetectionEnabledChanged();
157 bool Settings::isZoomAsShutterEnabled() const {
158 return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
161 void Settings::setZoomAsShutterEnabled(bool enabled) {
162 if (isZoomAsShutterEnabled() != enabled) {
163 m_settings->setValue("camera/zoomAsShutter", enabled);
165 emit zoomAsShutterChanged();
169 bool Settings::isProximityAsShutterEnabled() const {
170 return m_settings->value("camera/proximityAsShutter", DEFAULT_PROXIMITY_AS_SHUTTER).toBool();
173 void Settings::setProximityAsShutterEnabled(bool enabled) {
174 if (isProximityAsShutterEnabled() != enabled) {
175 m_settings->setValue("camera/proximityAsShutter", enabled);
177 emit proximityAsShutterChanged();
181 int Settings::device() const {
182 return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
185 void Settings::setDevice(int device) {
186 if (device != Settings::device()) {
187 emit deviceAboutToChange();
189 m_settings->setValue("camera/device", device);
191 delete m_device; m_device = 0;
193 if (mode() == DEFAULT_MODE) {
195 emit imageSceneModeChanged();
196 emit imageColorFilterChanged();
197 emit imageWhiteBalanceChanged();
198 emit imageEvCompChanged();
199 emit imageFlashModeChanged();
200 emit imageIsoChanged();
201 emit imageAspectRatioChanged();
202 emit imageResolutionChanged();
206 emit videoSceneModeChanged();
207 emit videoColorFilterChanged();
208 emit videoWhiteBalanceChanged();
209 emit videoEvCompChanged();
210 emit videoAspectRatioChanged();
211 emit videoResolutionChanged();
212 emit videoTorchOnChanged();
215 emit deviceChanged();
219 DeviceSettings *Settings::deviceSettings() {
224 int device = Settings::device();
227 m_device = new PrimaryDeviceSettings;
230 m_device = new SecondaryDeviceSettings;
236 QVariant Settings::deviceValue(const char *key, const QVariant& defaultValue) {
237 QString k = QString("%1/%2").arg(deviceSettings()->id()).arg(key);
239 return m_settings->value(k, defaultValue);
242 void Settings::setDeviceValue(const char *key, const QVariant& value) {
243 QString k = QString("%1/%2").arg(deviceSettings()->id()).arg(key);
245 m_settings->setValue(k, value);
248 // Device dependant settings
250 int Settings::imageSceneMode() {
251 return deviceValue("image/sceneMode", deviceSettings()->defaultImageSceneMode()).toInt();
254 void Settings::setImageSceneMode(int mode) {
255 if (mode != imageSceneMode()) {
256 setDeviceValue("image/sceneMode", mode);
259 // We always emit the signal to reset scene and all scene associated values
260 emit imageSceneModeChanged();
263 int Settings::imageColorFilter() {
264 return deviceValue("image/colorFilter", deviceSettings()->defaultImageColorFilter()).toInt();
267 void Settings::setImageColorFilter(int filter) {
268 if (filter != imageColorFilter()) {
269 setDeviceValue("image/colorFilter", filter);
271 emit imageColorFilterChanged();
275 int Settings::imageWhiteBalance() {
276 return deviceValue("image/whiteBalance", deviceSettings()->defaultImageWhiteBalance()).toInt();
279 void Settings::setImageWhiteBalance(int wb) {
280 if (wb != imageWhiteBalance()) {
281 setDeviceValue("image/whiteBalance", wb);
283 emit imageWhiteBalanceChanged();
287 qreal Settings::imageEvComp() {
288 return deviceValue("image/evComp", deviceSettings()->defaultImageEvComp()).toReal();
291 void Settings::setImageEvComp(qreal ev) {
292 if (!qFuzzyCompare(ev, imageEvComp())) {
293 setDeviceValue("image/evComp", ev);
295 emit imageEvCompChanged();
299 int Settings::videoSceneMode() {
300 return deviceValue("video/sceneMode", deviceSettings()->defaultVideoSceneMode()).toInt();
303 void Settings::setVideoSceneMode(int mode) {
304 if (mode != videoSceneMode()) {
305 setDeviceValue("video/sceneMode", mode);
308 emit videoSceneModeChanged();
311 int Settings::videoColorFilter() {
312 return deviceValue("video/colorFilter", deviceSettings()->defaultVideoColorFilter()).toInt();
315 void Settings::setVideoColorFilter(int filter) {
316 if (filter != videoColorFilter()) {
317 setDeviceValue("video/colorFilter", filter);
319 emit videoColorFilterChanged();
323 int Settings::videoWhiteBalance() {
324 return deviceValue("video/whiteBalance", deviceSettings()->defaultVideoWhiteBalance()).toInt();
327 void Settings::setVideoWhiteBalance(int wb) {
328 if (wb != videoWhiteBalance()) {
329 setDeviceValue("video/whiteBalance", wb);
331 emit videoWhiteBalanceChanged();
335 qreal Settings::videoEvComp() {
336 return deviceValue("video/evComp", deviceSettings()->defaultVideoEvComp()).toReal();
339 void Settings::setVideoEvComp(qreal ev) {
340 if (!qFuzzyCompare(ev, videoEvComp())) {
341 setDeviceValue("video/evComp", ev);
343 emit videoEvCompChanged();
347 int Settings::imageFlashMode() {
348 return deviceValue("image/flashMode", deviceSettings()->defaultImageFlashMode()).toInt();
351 void Settings::setImageFlashMode(int mode) {
352 if (mode != imageFlashMode()) {
353 setDeviceValue("image/flashMode", mode);
355 emit imageFlashModeChanged();
359 int Settings::imageIso() {
360 return deviceValue("image/iso", deviceSettings()->defaultImageIso()).toInt();
363 void Settings::setImageIso(int iso) {
364 if (imageIso() != iso) {
365 setDeviceValue("image/iso", iso);
366 emit imageIsoChanged();
370 QString Settings::imageAspectRatio() {
371 return deviceValue("image/aspectRatio", deviceSettings()->defaultImageAspectRatio()).toString();
374 void Settings::setImageAspectRatio(const QString& aspectRatio) {
375 if (aspectRatio != imageAspectRatio()) {
376 setDeviceValue("image/aspectRatio", aspectRatio);
377 emit imageAspectRatioChanged();
381 QString Settings::imageResolution() {
382 return deviceValue("image/resolution", deviceSettings()->defaultImageResolution()).toString();
385 void Settings::setImageResolution(const QString& resolution) {
386 if (resolution != imageResolution()) {
387 setDeviceValue("image/resolution", resolution);
388 emit imageResolutionChanged();
392 QString Settings::videoAspectRatio() {
393 return deviceValue("video/aspectRatio", deviceSettings()->defaultVideoAspectRatio()).toString();
397 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
398 if (Settings::videoAspectRatio() != aspectRatio) {
399 setDeviceValue("video/aspectRatio", aspectRatio);
400 emit videoAspectRatioChanged();
404 QString Settings::videoResolution() {
405 return deviceValue("video/resolution", deviceSettings()->defaultVideoResolution()).toString();
408 void Settings::setVideoResolution(const QString& resolution) {
409 if (resolution != videoResolution()) {
410 setDeviceValue("video/resolution", resolution);
411 emit videoResolutionChanged();
415 bool Settings::isVideoTorchOn() {
416 return deviceValue("video/torchOn", deviceSettings()->defaultVideoTorchOn()).toBool();
419 void Settings::setVideoTorchOn(bool on) {
420 if (isVideoTorchOn() != on) {
421 setDeviceValue("video/torchOn", on);
422 emit videoTorchOnChanged();
426 QString Settings::fileNamingStamp(const QString& id) const {
427 QString key = QString("fileNaming/%1").arg(id);
428 return m_settings->value(key).toString();
431 void Settings::setFileNamingStamp(const QString& id, const QString& stamp) {
432 QString key = QString("fileNaming/%1").arg(id);
433 m_settings->setValue(key, stamp);
436 int Settings::fileNamingCounter(const QString& id) const {
437 QString key = QString("fileNaming/%1").arg(id);
438 return m_settings->value(key).toInt();
441 void Settings::setFileNamingCounter(const QString& id, int counter) {
442 QString key = QString("fileNaming/%1").arg(id);
443 m_settings->setValue(key, counter);
446 bool Settings::isPreviewEnabled() const {
447 return m_settings->value("camera/enablePreview", DEFAULT_ENABLE_PREVIEW).toBool();
450 void Settings::setPreviewEnabled(bool enabled) {
451 if (enabled != isPreviewEnabled()) {
452 m_settings->setValue("camera/enablePreview", enabled);
454 emit previewEnabledChanged();