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