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