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