f3e67382f1e0acfd9122371dacd55755fbfaa3d1
[harmattan/cameraplus] / src / settings.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 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_IMAGE_RESOLUTION        "high"
37 #define DEFAULT_IMAGE_ASPECT_RATIO      "16:9"
38 #define DEFAULT_VIDEO_RESOLUTION        "high"
39 #define DEFAULT_SOUND_ENABLED           true
40 #define DEFAULT_VIDEO_TORCH_ON          false
41 #define DEFAULT_SHOW_TOOL_BAR           false
42 #define DEFAULT_VIDEO_MUTE              false
43 #define DEFAULT_GRID_ENABLED            false
44 #define DEFAULT_FACE_DETECTION_ENABLED  true
45
46 Settings::Settings(QObject *parent) :
47   QObject(parent),
48   m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
49
50 }
51
52 Settings::~Settings() {
53   delete m_settings; m_settings = 0;
54 }
55
56 int Settings::mode() const {
57   return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
58 }
59
60 void Settings::setMode(int mode) {
61   if (mode != Settings::mode()) {
62     m_settings->setValue("camera/mode", mode);
63
64     emit modeChanged();
65   }
66 }
67
68 QString Settings::creatorName() const {
69   return m_settings->value("camera/creatorName").toString();
70 }
71
72 void Settings::setCreatorName(const QString& name) {
73   if (name != creatorName()) {
74     m_settings->setValue("camera/creatorName", name);
75
76     emit creatorNameChanged();
77   }
78 }
79
80 bool Settings::useGps() const {
81   return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
82 }
83
84 void Settings::setUseGps(bool enable) {
85   if (enable != useGps()) {
86     m_settings->setValue("camera/useGps", enable);
87
88     emit useGpsChanged();
89   }
90 }
91
92 bool Settings::useGeotags() const {
93   return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
94 }
95
96 void Settings::setUseGeotags(bool enable) {
97   if (enable != useGeotags()) {
98     m_settings->setValue("camera/useGeotags", enable);
99
100     emit useGeotagsChanged();
101   }
102 }
103
104 int Settings::imageSceneMode() const {
105   return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
106 }
107
108 void Settings::setImageSceneMode(int mode) {
109   if (mode != imageSceneMode()) {
110     m_settings->setValue("image/sceneMode", mode);
111   }
112
113   emit imageSceneModeChanged();
114 }
115
116 int Settings::imageColorFilter() const {
117   return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
118 }
119
120 void Settings::setImageColorFilter(int filter) {
121   if (filter != imageColorFilter()) {
122     m_settings->setValue("image/colorFilter", filter);
123
124     emit imageColorFilterChanged();
125   }
126 }
127
128 int Settings::imageWhiteBalance() const {
129   return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
130 }
131
132 void Settings::setImageWhiteBalance(int wb) {
133   if (wb != imageWhiteBalance()) {
134     m_settings->setValue("image/whiteBalance", wb);
135
136     emit imageWhiteBalanceChanged();
137   }
138 }
139
140 qreal Settings::imageEvComp() const {
141   return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
142 }
143
144 void Settings::setImageEvComp(qreal ev) {
145   if (!qFuzzyCompare(ev, imageEvComp())) {
146     m_settings->setValue("image/evComp", ev);
147
148     emit imageEvCompChanged();
149   }
150 }
151
152 int Settings::videoSceneMode() const {
153   return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
154 }
155
156 void Settings::setVideoSceneMode(int mode) {
157   if (mode != videoSceneMode()) {
158     m_settings->setValue("video/sceneMode", mode);
159   }
160
161   emit videoSceneModeChanged();
162 }
163
164 int Settings::videoColorFilter() const {
165   return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
166 }
167
168 void Settings::setVideoColorFilter(int filter) {
169   if (filter != videoColorFilter()) {
170     m_settings->setValue("video/colorFilter", filter);
171
172     emit videoColorFilterChanged();
173   }
174 }
175
176 int Settings::videoWhiteBalance() const {
177   return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
178 }
179
180 void Settings::setVideoWhiteBalance(int wb) {
181   if (wb != videoWhiteBalance()) {
182     m_settings->setValue("video/whiteBalance", wb);
183
184     emit videoWhiteBalanceChanged();
185   }
186 }
187
188 qreal Settings::videoEvComp() const {
189   return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
190 }
191
192 void Settings::setVideoEvComp(qreal ev) {
193   if (!qFuzzyCompare(ev, videoEvComp())) {
194     m_settings->setValue("video/evComp", ev);
195
196     emit videoEvCompChanged();
197   }
198 }
199
200 int Settings::imageFlashMode() const {
201   return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
202 }
203
204 void Settings::setImageFlashMode(int mode) {
205   if (mode != imageFlashMode()) {
206     m_settings->setValue("image/flashMode", mode);
207
208     emit imageFlashModeChanged();
209   }
210 }
211
212 int Settings::imageIso() const {
213   return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
214 }
215
216 void Settings::setImageIso(int iso) {
217   if (imageIso() != iso) {
218     m_settings->setValue("image/iso", iso);
219     emit imageIsoChanged();
220   }
221 }
222
223 QString Settings::imageAspectRatio() const {
224   return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
225 }
226
227 void Settings::setImageAspectRatio(const QString& aspectRatio) {
228   if (aspectRatio != imageAspectRatio()) {
229     m_settings->setValue("image/aspectRatio", aspectRatio);
230     emit imageAspectRatioChanged();
231   }
232 }
233
234 QString Settings::imageResolution() const {
235   return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
236 }
237
238 void Settings::setImageResolution(const QString& resolution) {
239   if (resolution != imageResolution()) {
240     m_settings->setValue("image/resolution", resolution);
241     emit imageResolutionChanged();
242   }
243 }
244
245 QString Settings::videoAspectRatio() const {
246   // This is not used for anything so we will return an empty string for now
247   // which will make the backend return all resolutions.
248
249   return QString();
250 }
251
252 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
253   Q_UNUSED(aspectRatio);
254
255   // This is not used for anything so we will just ignore it.
256 }
257
258 QString Settings::videoResolution() const {
259   return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
260 }
261
262 void Settings::setVideoResolution(const QString& resolution) {
263   if (resolution != videoResolution()) {
264     m_settings->setValue("video/resolution", resolution);
265     emit videoResolutionChanged();
266   }
267 }
268
269 bool Settings::isSoundEnabled() const {
270   return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
271 }
272
273 void Settings::setSoundEnabled(bool enabled) {
274   if (isSoundEnabled() != enabled) {
275     m_settings->setValue("camera/soundEnabled", enabled);
276     emit soundEnabledChanged();
277   }
278 }
279
280 bool Settings::isVideoTorchOn() const {
281   return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
282 }
283
284 void Settings::setVideoTorchOn(bool on) {
285   if (isVideoTorchOn() != on) {
286     m_settings->setValue("video/torchOn", on);
287     emit videoTorchOnChanged();
288   }
289 }
290
291 bool Settings::isToolBarShown() const {
292   return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
293 }
294
295 void Settings::setToolBarShown(bool shown) {
296   if (isToolBarShown() != shown) {
297     m_settings->setValue("camera/showToolBar", shown);
298
299     emit toolBarShownChanged();
300   }
301 }
302
303 bool Settings::isVideoMuted() const {
304   return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
305 }
306
307 void Settings::setVideoMuted(bool muted) {
308   if (isVideoMuted() != muted) {
309     m_settings->setValue("video/mute", muted);
310     emit videoMutedChanged();
311   }
312 }
313
314 bool Settings::isGridEnabled() const {
315   return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
316 }
317
318 void Settings::setGridEnabled(bool enabled) {
319   if (enabled != isGridEnabled()) {
320     m_settings->setValue("camera/gridEnabled", enabled);
321     emit gridEnabledChanged();
322   }
323 }
324
325 bool Settings::isFaceDetectionEnabled() const {
326   return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
327 }
328
329 void Settings::setFaceDetectionEnabled(bool enabled) {
330   if (isFaceDetectionEnabled() != enabled) {
331     m_settings->setValue("image/faceDetectionEnabled", enabled);
332     emit faceDetectionEnabledChanged();
333   }
334 }