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
40 #define DEFAULT_FILE_NAMING_UTC true
42 Settings::Settings(QObject *parent) :
44 m_settings(new QSettings(PATH, QSettings::IniFormat, this)),
49 Settings::~Settings() {
50 delete m_settings; m_settings = 0;
51 delete m_device; m_device = 0;
54 int Settings::mode() const {
55 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
58 void Settings::setMode(int mode) {
59 if (mode != Settings::mode()) {
60 m_settings->setValue("camera/mode", mode);
66 QString Settings::creatorName() const {
67 return m_settings->value("camera/creatorName").toString();
70 void Settings::setCreatorName(const QString& name) {
71 if (name != creatorName()) {
72 m_settings->setValue("camera/creatorName", name);
74 emit creatorNameChanged();
78 bool Settings::useGps() const {
79 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
82 void Settings::setUseGps(bool enable) {
83 if (enable != useGps()) {
84 m_settings->setValue("camera/useGps", enable);
90 bool Settings::useGeotags() const {
91 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
94 void Settings::setUseGeotags(bool enable) {
95 if (enable != useGeotags()) {
96 m_settings->setValue("camera/useGeotags", enable);
98 emit useGeotagsChanged();
102 bool Settings::isSoundEnabled() const {
103 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
106 void Settings::setSoundEnabled(bool enabled) {
107 if (isSoundEnabled() != enabled) {
108 m_settings->setValue("camera/soundEnabled", enabled);
109 emit soundEnabledChanged();
113 bool Settings::isToolBarShown() const {
114 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
117 void Settings::setToolBarShown(bool shown) {
118 if (isToolBarShown() != shown) {
119 m_settings->setValue("camera/showToolBar", shown);
121 emit toolBarShownChanged();
125 bool Settings::isVideoMuted() const {
126 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
129 void Settings::setVideoMuted(bool muted) {
130 if (isVideoMuted() != muted) {
131 m_settings->setValue("video/mute", muted);
132 emit videoMutedChanged();
136 bool Settings::isGridEnabled() const {
137 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
140 void Settings::setGridEnabled(bool enabled) {
141 if (enabled != isGridEnabled()) {
142 m_settings->setValue("camera/gridEnabled", enabled);
143 emit gridEnabledChanged();
147 bool Settings::isFaceDetectionEnabled() const {
148 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
151 void Settings::setFaceDetectionEnabled(bool enabled) {
152 if (isFaceDetectionEnabled() != enabled) {
153 m_settings->setValue("image/faceDetectionEnabled", enabled);
154 emit faceDetectionEnabledChanged();
158 bool Settings::isZoomAsShutterEnabled() const {
159 return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
162 void Settings::setZoomAsShutterEnabled(bool enabled) {
163 if (isZoomAsShutterEnabled() != enabled) {
164 m_settings->setValue("camera/zoomAsShutter", enabled);
166 emit zoomAsShutterChanged();
170 bool Settings::isProximityAsShutterEnabled() const {
171 return m_settings->value("camera/proximityAsShutter", DEFAULT_PROXIMITY_AS_SHUTTER).toBool();
174 void Settings::setProximityAsShutterEnabled(bool enabled) {
175 if (isProximityAsShutterEnabled() != enabled) {
176 m_settings->setValue("camera/proximityAsShutter", enabled);
178 emit proximityAsShutterChanged();
182 int Settings::device() const {
183 return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
186 void Settings::setDevice(int device) {
187 if (device != Settings::device()) {
188 emit deviceAboutToChange();
190 m_settings->setValue("camera/device", device);
192 delete m_device; m_device = 0;
194 if (mode() == DEFAULT_MODE) {
196 emit imageSceneModeChanged();
197 emit imageColorFilterChanged();
198 emit imageWhiteBalanceChanged();
199 emit imageEvCompChanged();
200 emit imageFlashModeChanged();
201 emit imageIsoChanged();
202 emit imageAspectRatioChanged();
203 emit imageResolutionChanged();
207 emit videoSceneModeChanged();
208 emit videoColorFilterChanged();
209 emit videoWhiteBalanceChanged();
210 emit videoEvCompChanged();
211 emit videoAspectRatioChanged();
212 emit videoResolutionChanged();
213 emit videoTorchOnChanged();
216 emit deviceChanged();
220 DeviceSettings *Settings::deviceSettings() {
225 int device = Settings::device();
228 m_device = new PrimaryDeviceSettings;
231 m_device = new SecondaryDeviceSettings;
237 QVariant Settings::deviceValue(const char *key, const QVariant& defaultValue) {
238 QString k = QString("%1/%2").arg(deviceSettings()->id()).arg(key);
240 return m_settings->value(k, defaultValue);
243 void Settings::setDeviceValue(const char *key, const QVariant& value) {
244 QString k = QString("%1/%2").arg(deviceSettings()->id()).arg(key);
246 m_settings->setValue(k, value);
249 // Device dependant settings
251 int Settings::imageSceneMode() {
252 return deviceValue("image/sceneMode", deviceSettings()->defaultImageSceneMode()).toInt();
255 void Settings::setImageSceneMode(int mode) {
256 if (mode != imageSceneMode()) {
257 setDeviceValue("image/sceneMode", mode);
260 // We always emit the signal to reset scene and all scene associated values
261 emit imageSceneModeChanged();
264 int Settings::imageColorFilter() {
265 return deviceValue("image/colorFilter", deviceSettings()->defaultImageColorFilter()).toInt();
268 void Settings::setImageColorFilter(int filter) {
269 if (filter != imageColorFilter()) {
270 setDeviceValue("image/colorFilter", filter);
272 emit imageColorFilterChanged();
276 int Settings::imageWhiteBalance() {
277 return deviceValue("image/whiteBalance", deviceSettings()->defaultImageWhiteBalance()).toInt();
280 void Settings::setImageWhiteBalance(int wb) {
281 if (wb != imageWhiteBalance()) {
282 setDeviceValue("image/whiteBalance", wb);
284 emit imageWhiteBalanceChanged();
288 qreal Settings::imageEvComp() {
289 return deviceValue("image/evComp", deviceSettings()->defaultImageEvComp()).toReal();
292 void Settings::setImageEvComp(qreal ev) {
293 if (!qFuzzyCompare(ev, imageEvComp())) {
294 setDeviceValue("image/evComp", ev);
296 emit imageEvCompChanged();
300 int Settings::videoSceneMode() {
301 return deviceValue("video/sceneMode", deviceSettings()->defaultVideoSceneMode()).toInt();
304 void Settings::setVideoSceneMode(int mode) {
305 if (mode != videoSceneMode()) {
306 setDeviceValue("video/sceneMode", mode);
309 emit videoSceneModeChanged();
312 int Settings::videoColorFilter() {
313 return deviceValue("video/colorFilter", deviceSettings()->defaultVideoColorFilter()).toInt();
316 void Settings::setVideoColorFilter(int filter) {
317 if (filter != videoColorFilter()) {
318 setDeviceValue("video/colorFilter", filter);
320 emit videoColorFilterChanged();
324 int Settings::videoWhiteBalance() {
325 return deviceValue("video/whiteBalance", deviceSettings()->defaultVideoWhiteBalance()).toInt();
328 void Settings::setVideoWhiteBalance(int wb) {
329 if (wb != videoWhiteBalance()) {
330 setDeviceValue("video/whiteBalance", wb);
332 emit videoWhiteBalanceChanged();
336 qreal Settings::videoEvComp() {
337 return deviceValue("video/evComp", deviceSettings()->defaultVideoEvComp()).toReal();
340 void Settings::setVideoEvComp(qreal ev) {
341 if (!qFuzzyCompare(ev, videoEvComp())) {
342 setDeviceValue("video/evComp", ev);
344 emit videoEvCompChanged();
348 int Settings::imageFlashMode() {
349 return deviceValue("image/flashMode", deviceSettings()->defaultImageFlashMode()).toInt();
352 void Settings::setImageFlashMode(int mode) {
353 if (mode != imageFlashMode()) {
354 setDeviceValue("image/flashMode", mode);
356 emit imageFlashModeChanged();
360 int Settings::imageIso() {
361 return deviceValue("image/iso", deviceSettings()->defaultImageIso()).toInt();
364 void Settings::setImageIso(int iso) {
365 if (imageIso() != iso) {
366 setDeviceValue("image/iso", iso);
367 emit imageIsoChanged();
371 QString Settings::imageAspectRatio() {
372 return deviceValue("image/aspectRatio", deviceSettings()->defaultImageAspectRatio()).toString();
375 void Settings::setImageAspectRatio(const QString& aspectRatio) {
376 if (aspectRatio != imageAspectRatio()) {
377 setDeviceValue("image/aspectRatio", aspectRatio);
378 emit imageAspectRatioChanged();
382 QString Settings::imageResolution() {
383 return deviceValue("image/resolution", deviceSettings()->defaultImageResolution()).toString();
386 void Settings::setImageResolution(const QString& resolution) {
387 if (resolution != imageResolution()) {
388 setDeviceValue("image/resolution", resolution);
389 emit imageResolutionChanged();
393 QString Settings::videoAspectRatio() {
394 return deviceValue("video/aspectRatio", deviceSettings()->defaultVideoAspectRatio()).toString();
398 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
399 if (Settings::videoAspectRatio() != aspectRatio) {
400 setDeviceValue("video/aspectRatio", aspectRatio);
401 emit videoAspectRatioChanged();
405 QString Settings::videoResolution() {
406 return deviceValue("video/resolution", deviceSettings()->defaultVideoResolution()).toString();
409 void Settings::setVideoResolution(const QString& resolution) {
410 if (resolution != videoResolution()) {
411 setDeviceValue("video/resolution", resolution);
412 emit videoResolutionChanged();
416 bool Settings::isVideoTorchOn() {
417 return deviceValue("video/torchOn", deviceSettings()->defaultVideoTorchOn()).toBool();
420 void Settings::setVideoTorchOn(bool on) {
421 if (isVideoTorchOn() != on) {
422 setDeviceValue("video/torchOn", on);
423 emit videoTorchOnChanged();
427 QString Settings::fileNamingStamp(const QString& id) const {
428 QString key = QString("fileNaming/%1").arg(id);
429 return m_settings->value(key).toString();
432 void Settings::setFileNamingStamp(const QString& id, const QString& stamp) {
433 QString key = QString("fileNaming/%1").arg(id);
434 m_settings->setValue(key, stamp);
437 int Settings::fileNamingCounter(const QString& id) const {
438 QString key = QString("fileNaming/%1").arg(id);
439 return m_settings->value(key).toInt();
442 void Settings::setFileNamingCounter(const QString& id, int counter) {
443 QString key = QString("fileNaming/%1").arg(id);
444 m_settings->setValue(key, counter);
447 bool Settings::isPreviewEnabled() const {
448 return m_settings->value("camera/enablePreview", DEFAULT_ENABLE_PREVIEW).toBool();
451 void Settings::setPreviewEnabled(bool enabled) {
452 if (enabled != isPreviewEnabled()) {
453 m_settings->setValue("camera/enablePreview", enabled);
455 emit previewEnabledChanged();
459 bool Settings::isUtcForFileNamingUsed() const {
460 return m_settings->value("fileNaming/useUtc", DEFAULT_FILE_NAMING_UTC).toBool();