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