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