Implemented per device resolution setting and selection
[harmattan/cameraplus] / src / settings.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "settings.h"
22 #include <QSettings>
23 #include <QDir>
24
25 #define PATH QString("%1%2.config%2/cameraplus.conf").arg(QDir::homePath()).arg(QDir::separator())
26
27 #define DEFAULT_MODE                    1
28 #define DEFAULT_SCENE_MODE              6 // Auto
29 #define DEFAULT_USE_GPS                 true
30 #define DEFAULT_USE_GEOTAGS             true
31 #define DEFAULT_COLOR_FILTER            0
32 #define DEFAULT_WHITE_BALANCE           0
33 #define DEFAULT_EV_COMP                 0.0
34 #define DEFAULT_FLASH_MODE              0
35 #define DEFAULT_IMAGE_ISO               0
36 #define DEFAULT_SOUND_ENABLED           true
37 #define DEFAULT_VIDEO_TORCH_ON          false
38 #define DEFAULT_SHOW_TOOL_BAR           false
39 #define DEFAULT_VIDEO_MUTE              false
40 #define DEFAULT_GRID_ENABLED            false
41 #define DEFAULT_FACE_DETECTION_ENABLED  true
42 #define DEFAULT_ZOOM_AS_SHUTTER         false
43 #define DEFAULT_DEVICE                  0
44
45 #define DEFAULT_PRIMARY_IMAGE_RESOLUTION        "high"
46 #define DEFAULT_PRIMARY_IMAGE_ASPECT_RATIO      "16:9"
47 #define DEFAULT_PRIMARY_VIDEO_RESOLUTION        "high"
48 #define DEFAULT_PRIMARY_VIDEO_ASPECT_RATIO      "16:9"
49
50 #define DEFAULT_SECONDARY_IMAGE_RESOLUTION       "low"
51 #define DEFAULT_SECONDARY_IMAGE_ASPECT_RATIO     "4:3"
52 #define DEFAULT_SECONDARY_VIDEO_RESOLUTION       "low"
53 #define DEFAULT_SECONDARY_VIDEO_ASPECT_RATIO     "4:3"
54
55 Settings::Settings(QObject *parent) :
56   QObject(parent),
57   m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
58
59 }
60
61 Settings::~Settings() {
62   delete m_settings; m_settings = 0;
63 }
64
65 int Settings::mode() const {
66   return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
67 }
68
69 void Settings::setMode(int mode) {
70   if (mode != Settings::mode()) {
71     m_settings->setValue("camera/mode", mode);
72
73     emit modeChanged();
74   }
75 }
76
77 QString Settings::creatorName() const {
78   return m_settings->value("camera/creatorName").toString();
79 }
80
81 void Settings::setCreatorName(const QString& name) {
82   if (name != creatorName()) {
83     m_settings->setValue("camera/creatorName", name);
84
85     emit creatorNameChanged();
86   }
87 }
88
89 bool Settings::useGps() const {
90   return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
91 }
92
93 void Settings::setUseGps(bool enable) {
94   if (enable != useGps()) {
95     m_settings->setValue("camera/useGps", enable);
96
97     emit useGpsChanged();
98   }
99 }
100
101 bool Settings::useGeotags() const {
102   return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
103 }
104
105 void Settings::setUseGeotags(bool enable) {
106   if (enable != useGeotags()) {
107     m_settings->setValue("camera/useGeotags", enable);
108
109     emit useGeotagsChanged();
110   }
111 }
112
113 int Settings::imageSceneMode() const {
114   return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
115 }
116
117 void Settings::setImageSceneMode(int mode) {
118   if (mode != imageSceneMode()) {
119     m_settings->setValue("image/sceneMode", mode);
120   }
121
122   emit imageSceneModeChanged();
123 }
124
125 int Settings::imageColorFilter() const {
126   return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
127 }
128
129 void Settings::setImageColorFilter(int filter) {
130   if (filter != imageColorFilter()) {
131     m_settings->setValue("image/colorFilter", filter);
132
133     emit imageColorFilterChanged();
134   }
135 }
136
137 int Settings::imageWhiteBalance() const {
138   return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
139 }
140
141 void Settings::setImageWhiteBalance(int wb) {
142   if (wb != imageWhiteBalance()) {
143     m_settings->setValue("image/whiteBalance", wb);
144
145     emit imageWhiteBalanceChanged();
146   }
147 }
148
149 qreal Settings::imageEvComp() const {
150   return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
151 }
152
153 void Settings::setImageEvComp(qreal ev) {
154   if (!qFuzzyCompare(ev, imageEvComp())) {
155     m_settings->setValue("image/evComp", ev);
156
157     emit imageEvCompChanged();
158   }
159 }
160
161 int Settings::videoSceneMode() const {
162   return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
163 }
164
165 void Settings::setVideoSceneMode(int mode) {
166   if (mode != videoSceneMode()) {
167     m_settings->setValue("video/sceneMode", mode);
168   }
169
170   emit videoSceneModeChanged();
171 }
172
173 int Settings::videoColorFilter() const {
174   return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
175 }
176
177 void Settings::setVideoColorFilter(int filter) {
178   if (filter != videoColorFilter()) {
179     m_settings->setValue("video/colorFilter", filter);
180
181     emit videoColorFilterChanged();
182   }
183 }
184
185 int Settings::videoWhiteBalance() const {
186   return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
187 }
188
189 void Settings::setVideoWhiteBalance(int wb) {
190   if (wb != videoWhiteBalance()) {
191     m_settings->setValue("video/whiteBalance", wb);
192
193     emit videoWhiteBalanceChanged();
194   }
195 }
196
197 qreal Settings::videoEvComp() const {
198   return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
199 }
200
201 void Settings::setVideoEvComp(qreal ev) {
202   if (!qFuzzyCompare(ev, videoEvComp())) {
203     m_settings->setValue("video/evComp", ev);
204
205     emit videoEvCompChanged();
206   }
207 }
208
209 int Settings::imageFlashMode() const {
210   return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
211 }
212
213 void Settings::setImageFlashMode(int mode) {
214   if (mode != imageFlashMode()) {
215     m_settings->setValue("image/flashMode", mode);
216
217     emit imageFlashModeChanged();
218   }
219 }
220
221 int Settings::imageIso() const {
222   return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
223 }
224
225 void Settings::setImageIso(int iso) {
226   if (imageIso() != iso) {
227     m_settings->setValue("image/iso", iso);
228     emit imageIsoChanged();
229   }
230 }
231
232 bool Settings::isSoundEnabled() const {
233   return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
234 }
235
236 void Settings::setSoundEnabled(bool enabled) {
237   if (isSoundEnabled() != enabled) {
238     m_settings->setValue("camera/soundEnabled", enabled);
239     emit soundEnabledChanged();
240   }
241 }
242
243 bool Settings::isVideoTorchOn() const {
244   return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
245 }
246
247 void Settings::setVideoTorchOn(bool on) {
248   if (isVideoTorchOn() != on) {
249     m_settings->setValue("video/torchOn", on);
250     emit videoTorchOnChanged();
251   }
252 }
253
254 bool Settings::isToolBarShown() const {
255   return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
256 }
257
258 void Settings::setToolBarShown(bool shown) {
259   if (isToolBarShown() != shown) {
260     m_settings->setValue("camera/showToolBar", shown);
261
262     emit toolBarShownChanged();
263   }
264 }
265
266 bool Settings::isVideoMuted() const {
267   return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
268 }
269
270 void Settings::setVideoMuted(bool muted) {
271   if (isVideoMuted() != muted) {
272     m_settings->setValue("video/mute", muted);
273     emit videoMutedChanged();
274   }
275 }
276
277 bool Settings::isGridEnabled() const {
278   return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
279 }
280
281 void Settings::setGridEnabled(bool enabled) {
282   if (enabled != isGridEnabled()) {
283     m_settings->setValue("camera/gridEnabled", enabled);
284     emit gridEnabledChanged();
285   }
286 }
287
288 bool Settings::isFaceDetectionEnabled() const {
289   return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
290 }
291
292 void Settings::setFaceDetectionEnabled(bool enabled) {
293   if (isFaceDetectionEnabled() != enabled) {
294     m_settings->setValue("image/faceDetectionEnabled", enabled);
295     emit faceDetectionEnabledChanged();
296   }
297 }
298
299 bool Settings::isZoomAsShutterEnabled() {
300   return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
301 }
302
303 void Settings::setZoomAsShutterEnabled(bool enabled) {
304   if (isZoomAsShutterEnabled() != enabled) {
305     m_settings->setValue("camera/zoomAsShutter", enabled);
306
307     emit zoomAsShutterChanged();
308   }
309 }
310
311 int Settings::device() const {
312   return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
313 }
314
315 void Settings::setDevice(int device) {
316   if (device != Settings::device()) {
317     m_settings->setValue("camera/device", device);
318     emit deviceChanged();
319   }
320 }
321
322 QString Settings::primaryImageAspectRatio() const {
323   return m_settings->value("image/primaryAspectRatio",
324                            DEFAULT_PRIMARY_IMAGE_ASPECT_RATIO).toString();
325 }
326
327 void Settings::setPrimaryImageAspectRatio(const QString& aspectRatio) {
328   if (primaryImageAspectRatio() != aspectRatio) {
329     m_settings->setValue("image/primaryAspectRatio", aspectRatio);
330     emit primaryImageAspectRatioChanged();
331   }
332 }
333
334 QString Settings::primaryImageResolution() const {
335   return m_settings->value("image/primaryResolution",
336                            DEFAULT_PRIMARY_IMAGE_RESOLUTION).toString();
337 }
338
339 void Settings::setPrimaryImageResolution(const QString& resolution) {
340   if (primaryImageResolution() != resolution) {
341     m_settings->setValue("image/primaryResolution", resolution);
342     emit primaryImageResolutionChanged();
343   }
344 }
345
346 QString Settings::primaryVideoAspectRatio() const {
347   return m_settings->value("video/primaryAspectRatio",
348                            DEFAULT_PRIMARY_VIDEO_ASPECT_RATIO).toString();
349 }
350
351 void Settings::setPrimaryVideoAspectRatio(const QString& aspectRatio) {
352   if (primaryVideoAspectRatio() != aspectRatio) {
353     m_settings->setValue("video/primaryAspectRatio", aspectRatio);
354     emit primaryVideoAspectRatioChanged();
355   }
356 }
357
358 QString Settings::primaryVideoResolution() const {
359   return m_settings->value("video/primaryResolution",
360                            DEFAULT_PRIMARY_VIDEO_RESOLUTION).toString();
361 }
362
363 void Settings::setPrimaryVideoResolution(const QString& resolution) {
364   if (primaryVideoResolution() != resolution) {
365     m_settings->setValue("video/primaryResolution", resolution);
366     emit primaryVideoResolutionChanged();
367   }
368 }
369
370 QString Settings::secondaryImageAspectRatio() const {
371   return m_settings->value("image/secondaryAspectRatio",
372                            DEFAULT_SECONDARY_IMAGE_ASPECT_RATIO).toString();
373 }
374
375 void Settings::setSecondaryImageAspectRatio(const QString& aspectRatio) {
376   if (secondaryImageAspectRatio() != aspectRatio) {
377     m_settings->setValue("image/secondaryAspectRatio", aspectRatio);
378     emit secondaryImageAspectRatioChanged();
379   }
380 }
381
382 QString Settings::secondaryImageResolution() const {
383   return m_settings->value("image/secondaryResolution",
384                            DEFAULT_SECONDARY_IMAGE_RESOLUTION).toString();
385 }
386
387 void Settings::setSecondaryImageResolution(const QString& resolution) {
388   if (secondaryImageResolution() != resolution) {
389     m_settings->setValue("image/secondaryResolution", resolution);
390     emit secondaryImageResolutionChanged();
391   }
392 }
393
394 QString Settings::secondaryVideoAspectRatio() const {
395   return m_settings->value("video/secondaryAspectRatio",
396                            DEFAULT_SECONDARY_VIDEO_ASPECT_RATIO).toString();
397 }
398
399 void Settings::setSecondaryVideoAspectRatio(const QString& aspectRatio) {
400   if (secondaryVideoAspectRatio() != aspectRatio) {
401     m_settings->setValue("video/secondaryAspectRatio", aspectRatio);
402     emit secondaryVideoAspectRatioChanged();
403   }
404 }
405
406 QString Settings::secondaryVideoResolution() const {
407   return m_settings->value("video/secondaryResolution",
408                            DEFAULT_SECONDARY_VIDEO_RESOLUTION).toString();
409 }
410
411 void Settings::setSecondaryVideoResolution(const QString& resolution) {
412   if (secondaryVideoResolution() != resolution) {
413     m_settings->setValue("video/secondaryResolution", resolution);
414     emit secondaryVideoResolutionChanged();
415   }
416 }