VideoTorch and VideoMute are now properties of Camera
[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               0
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
43 Settings::Settings(QObject *parent) :
44   QObject(parent),
45   m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
46
47 }
48
49 Settings::~Settings() {
50   delete m_settings; m_settings = 0;
51 }
52
53 int Settings::mode() const {
54   return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
55 }
56
57 void Settings::setMode(int mode) {
58   if (mode != Settings::mode()) {
59     m_settings->setValue("camera/mode", mode);
60
61     emit modeChanged();
62   }
63 }
64
65 QString Settings::creatorName() const {
66   return m_settings->value("camera/creatorName").toString();
67 }
68
69 void Settings::setCreatorName(const QString& name) {
70   if (name != creatorName()) {
71     m_settings->setValue("camera/creatorName", name);
72
73     emit creatorNameChanged();
74   }
75 }
76
77 int Settings::postCaptureTimeout() const {
78   return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
79 }
80
81 void Settings::setPostCaptureTimeout(int timeout) {
82   if (timeout != postCaptureTimeout()) {
83     m_settings->setValue("camera/postCaptureTimeout", timeout);
84
85     emit postCaptureTimeoutChanged();
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 (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 (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 QString Settings::imageAspectRatio() const {
233   return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
234 }
235
236 void Settings::setImageAspectRatio(const QString& aspectRatio) {
237   if (aspectRatio != imageAspectRatio()) {
238     m_settings->setValue("image/aspectRatio", aspectRatio);
239     emit imageAspectRatioChanged();
240   }
241 }
242
243 QString Settings::imageResolution() const {
244   return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
245 }
246
247 void Settings::setImageResolution(const QString& resolution) {
248   if (resolution != imageResolution()) {
249     m_settings->setValue("image/resolution", resolution);
250     emit imageResolutionChanged();
251   }
252 }
253
254 QString Settings::videoAspectRatio() const {
255   // This is not used for anything so we will return an empty string for now
256   // which will make the backend return all resolutions.
257
258   return QString();
259 }
260
261 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
262   Q_UNUSED(aspectRatio);
263
264   // This is not used for anything so we will just ignore it.
265 }
266
267 QString Settings::videoResolution() const {
268   return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
269 }
270
271 void Settings::setVideoResolution(const QString& resolution) {
272   if (resolution != videoResolution()) {
273     m_settings->setValue("video/resolution", resolution);
274     emit videoResolutionChanged();
275   }
276 }
277
278 bool Settings::isSoundEnabled() const {
279   return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
280 }
281
282 void Settings::setSoundEnabled(bool enabled) {
283   if (isSoundEnabled() != enabled) {
284     m_settings->setValue("camera/soundEnabled", enabled);
285     emit soundEnabledChanged();
286   }
287 }
288
289 bool Settings::isVideoTorchOn() const {
290   return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
291 }
292
293 void Settings::setVideoTorchOn(bool on) {
294   if (isVideoTorchOn() != on) {
295     m_settings->setValue("video/torchOn", on);
296     emit videoTorchOnChanged();
297   }
298 }