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