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