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_DEVICE 0
39 Settings::Settings(QObject *parent) :
41 m_settings(new QSettings(PATH, QSettings::IniFormat, this)),
46 Settings::~Settings() {
47 delete m_settings; m_settings = 0;
48 delete m_device; m_device = 0;
51 int Settings::mode() const {
52 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
55 void Settings::setMode(int mode) {
56 if (mode != Settings::mode()) {
57 m_settings->setValue("camera/mode", mode);
63 QString Settings::creatorName() const {
64 return m_settings->value("camera/creatorName").toString();
67 void Settings::setCreatorName(const QString& name) {
68 if (name != creatorName()) {
69 m_settings->setValue("camera/creatorName", name);
71 emit creatorNameChanged();
75 bool Settings::useGps() const {
76 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
79 void Settings::setUseGps(bool enable) {
80 if (enable != useGps()) {
81 m_settings->setValue("camera/useGps", enable);
87 bool Settings::useGeotags() const {
88 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
91 void Settings::setUseGeotags(bool enable) {
92 if (enable != useGeotags()) {
93 m_settings->setValue("camera/useGeotags", enable);
95 emit useGeotagsChanged();
99 bool Settings::isSoundEnabled() const {
100 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
103 void Settings::setSoundEnabled(bool enabled) {
104 if (isSoundEnabled() != enabled) {
105 m_settings->setValue("camera/soundEnabled", enabled);
106 emit soundEnabledChanged();
110 bool Settings::isToolBarShown() const {
111 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
114 void Settings::setToolBarShown(bool shown) {
115 if (isToolBarShown() != shown) {
116 m_settings->setValue("camera/showToolBar", shown);
118 emit toolBarShownChanged();
122 bool Settings::isVideoMuted() const {
123 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
126 void Settings::setVideoMuted(bool muted) {
127 if (isVideoMuted() != muted) {
128 m_settings->setValue("video/mute", muted);
129 emit videoMutedChanged();
133 bool Settings::isGridEnabled() const {
134 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
137 void Settings::setGridEnabled(bool enabled) {
138 if (enabled != isGridEnabled()) {
139 m_settings->setValue("camera/gridEnabled", enabled);
140 emit gridEnabledChanged();
144 bool Settings::isFaceDetectionEnabled() const {
145 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
148 void Settings::setFaceDetectionEnabled(bool enabled) {
149 if (isFaceDetectionEnabled() != enabled) {
150 m_settings->setValue("image/faceDetectionEnabled", enabled);
151 emit faceDetectionEnabledChanged();
155 bool Settings::isZoomAsShutterEnabled() const {
156 return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
159 void Settings::setZoomAsShutterEnabled(bool enabled) {
160 if (isZoomAsShutterEnabled() != enabled) {
161 m_settings->setValue("camera/zoomAsShutter", enabled);
163 emit zoomAsShutterChanged();
167 int Settings::device() const {
168 return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
171 void Settings::setDevice(int device) {
172 if (device != Settings::device()) {
173 emit deviceAboutToChange();
175 m_settings->setValue("camera/device", device);
177 delete m_device; m_device = 0;
179 if (mode() == DEFAULT_MODE) {
181 emit imageSceneModeChanged();
182 emit imageColorFilterChanged();
183 emit imageWhiteBalanceChanged();
184 emit imageEvCompChanged();
185 emit imageFlashModeChanged();
186 emit imageIsoChanged();
187 emit imageAspectRatioChanged();
188 emit imageResolutionChanged();
192 emit videoSceneModeChanged();
193 emit videoColorFilterChanged();
194 emit videoWhiteBalanceChanged();
195 emit videoEvCompChanged();
196 emit videoAspectRatioChanged();
197 emit videoResolutionChanged();
198 emit videoTorchOnChanged();
201 emit deviceChanged();
205 DeviceSettings *Settings::deviceSettings() {
210 int device = Settings::device();
213 m_device = new PrimaryDeviceSettings;
216 m_device = new SecondaryDeviceSettings;
222 QVariant Settings::deviceValue(const char *key, const QVariant& defaultValue) {
223 QString k = QString("%1/%2").arg(deviceSettings()->id()).arg(key);
225 return m_settings->value(k, defaultValue);
228 void Settings::setDeviceValue(const char *key, const QVariant& value) {
229 QString k = QString("%1/%2").arg(deviceSettings()->id()).arg(key);
231 m_settings->setValue(k, value);
234 // Device dependant settings
236 int Settings::imageSceneMode() {
237 return deviceValue("image/sceneMode", deviceSettings()->defaultImageSceneMode()).toInt();
240 void Settings::setImageSceneMode(int mode) {
241 if (mode != imageSceneMode()) {
242 setDeviceValue("image/sceneMode", mode);
245 // We always emit the signal to reset scene and all scene associated values
246 emit imageSceneModeChanged();
249 int Settings::imageColorFilter() {
250 return deviceValue("image/colorFilter", deviceSettings()->defaultImageColorFilter()).toInt();
253 void Settings::setImageColorFilter(int filter) {
254 if (filter != imageColorFilter()) {
255 setDeviceValue("image/colorFilter", filter);
257 emit imageColorFilterChanged();
261 int Settings::imageWhiteBalance() {
262 return deviceValue("image/whiteBalance", deviceSettings()->defaultImageWhiteBalance()).toInt();
265 void Settings::setImageWhiteBalance(int wb) {
266 if (wb != imageWhiteBalance()) {
267 setDeviceValue("image/whiteBalance", wb);
269 emit imageWhiteBalanceChanged();
273 qreal Settings::imageEvComp() {
274 return deviceValue("image/evComp", deviceSettings()->defaultImageEvComp()).toReal();
277 void Settings::setImageEvComp(qreal ev) {
278 if (!qFuzzyCompare(ev, imageEvComp())) {
279 setDeviceValue("image/evComp", ev);
281 emit imageEvCompChanged();
285 int Settings::videoSceneMode() {
286 return deviceValue("video/sceneMode", deviceSettings()->defaultVideoSceneMode()).toInt();
289 void Settings::setVideoSceneMode(int mode) {
290 if (mode != videoSceneMode()) {
291 setDeviceValue("video/sceneMode", mode);
294 emit videoSceneModeChanged();
297 int Settings::videoColorFilter() {
298 return deviceValue("video/colorFilter", deviceSettings()->defaultVideoColorFilter()).toInt();
301 void Settings::setVideoColorFilter(int filter) {
302 if (filter != videoColorFilter()) {
303 setDeviceValue("video/colorFilter", filter);
305 emit videoColorFilterChanged();
309 int Settings::videoWhiteBalance() {
310 return deviceValue("video/whiteBalance", deviceSettings()->defaultVideoWhiteBalance()).toInt();
313 void Settings::setVideoWhiteBalance(int wb) {
314 if (wb != videoWhiteBalance()) {
315 setDeviceValue("video/whiteBalance", wb);
317 emit videoWhiteBalanceChanged();
321 qreal Settings::videoEvComp() {
322 return deviceValue("video/evComp", deviceSettings()->defaultVideoEvComp()).toReal();
325 void Settings::setVideoEvComp(qreal ev) {
326 if (!qFuzzyCompare(ev, videoEvComp())) {
327 setDeviceValue("video/evComp", ev);
329 emit videoEvCompChanged();
333 int Settings::imageFlashMode() {
334 return deviceValue("image/flashMode", deviceSettings()->defaultImageFlashMode()).toInt();
337 void Settings::setImageFlashMode(int mode) {
338 if (mode != imageFlashMode()) {
339 setDeviceValue("image/flashMode", mode);
341 emit imageFlashModeChanged();
345 int Settings::imageIso() {
346 return deviceValue("image/iso", deviceSettings()->defaultImageIso()).toInt();
349 void Settings::setImageIso(int iso) {
350 if (imageIso() != iso) {
351 setDeviceValue("image/iso", iso);
352 emit imageIsoChanged();
356 QString Settings::imageAspectRatio() {
357 return deviceValue("image/aspectRatio", deviceSettings()->defaultImageAspectRatio()).toString();
360 void Settings::setImageAspectRatio(const QString& aspectRatio) {
361 if (aspectRatio != imageAspectRatio()) {
362 setDeviceValue("image/aspectRatio", aspectRatio);
363 emit imageAspectRatioChanged();
367 QString Settings::imageResolution() {
368 return deviceValue("image/resolution", deviceSettings()->defaultImageResolution()).toString();
371 void Settings::setImageResolution(const QString& resolution) {
372 if (resolution != imageResolution()) {
373 setDeviceValue("image/resolution", resolution);
374 emit imageResolutionChanged();
378 QString Settings::videoAspectRatio() {
379 return deviceValue("video/aspectRatio", deviceSettings()->defaultVideoAspectRatio()).toString();
383 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
384 if (Settings::videoAspectRatio() != aspectRatio) {
385 setDeviceValue("video/aspectRatio", aspectRatio);
386 emit videoAspectRatioChanged();
390 QString Settings::videoResolution() {
391 return deviceValue("video/resolution", deviceSettings()->defaultVideoResolution()).toString();
394 void Settings::setVideoResolution(const QString& resolution) {
395 if (resolution != videoResolution()) {
396 setDeviceValue("video/resolution", resolution);
397 emit videoResolutionChanged();
401 bool Settings::isVideoTorchOn() {
402 return deviceValue("video/torchOn", deviceSettings()->defaultVideoTorchOn()).toBool();
405 void Settings::setVideoTorchOn(bool on) {
406 if (isVideoTorchOn() != on) {
407 setDeviceValue("video/torchOn", on);
408 emit videoTorchOnChanged();
412 QString Settings::fileNamingStamp() const {
413 return m_settings->value("fileNaming/stamp").toString();
416 void Settings::setFileNamingStamp(const QString& stamp) {
417 m_settings->setValue("fileNaming/stamp", stamp);
420 int Settings::fileNamingCounter() const {
421 return m_settings->value("fileNaming/counter").toInt();
424 void Settings::setFileNamingCounter(int counter) {
425 m_settings->setValue("fileNaming/counter", counter);