2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
25 #define PATH QString("%1%2.config%2/cameraplus.conf").arg(QDir::homePath()).arg(QDir::separator())
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 #define DEFAULT_FACE_DETECTION_ENABLED true
45 #define DEFAULT_ZOOM_AS_SHUTTER false
46 #define DEFAULT_DEVICE 0
48 Settings::Settings(QObject *parent) :
50 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
54 Settings::~Settings() {
55 delete m_settings; m_settings = 0;
58 int Settings::mode() const {
59 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
62 void Settings::setMode(int mode) {
63 if (mode != Settings::mode()) {
64 m_settings->setValue("camera/mode", mode);
70 QString Settings::creatorName() const {
71 return m_settings->value("camera/creatorName").toString();
74 void Settings::setCreatorName(const QString& name) {
75 if (name != creatorName()) {
76 m_settings->setValue("camera/creatorName", name);
78 emit creatorNameChanged();
82 bool Settings::useGps() const {
83 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
86 void Settings::setUseGps(bool enable) {
87 if (enable != useGps()) {
88 m_settings->setValue("camera/useGps", enable);
94 bool Settings::useGeotags() const {
95 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
98 void Settings::setUseGeotags(bool enable) {
99 if (enable != useGeotags()) {
100 m_settings->setValue("camera/useGeotags", enable);
102 emit useGeotagsChanged();
106 int Settings::imageSceneMode() const {
107 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
110 void Settings::setImageSceneMode(int mode) {
111 if (mode != imageSceneMode()) {
112 m_settings->setValue("image/sceneMode", mode);
115 emit imageSceneModeChanged();
118 int Settings::imageColorFilter() const {
119 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
122 void Settings::setImageColorFilter(int filter) {
123 if (filter != imageColorFilter()) {
124 m_settings->setValue("image/colorFilter", filter);
126 emit imageColorFilterChanged();
130 int Settings::imageWhiteBalance() const {
131 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
134 void Settings::setImageWhiteBalance(int wb) {
135 if (wb != imageWhiteBalance()) {
136 m_settings->setValue("image/whiteBalance", wb);
138 emit imageWhiteBalanceChanged();
142 qreal Settings::imageEvComp() const {
143 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
146 void Settings::setImageEvComp(qreal ev) {
147 if (!qFuzzyCompare(ev, imageEvComp())) {
148 m_settings->setValue("image/evComp", ev);
150 emit imageEvCompChanged();
154 int Settings::videoSceneMode() const {
155 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
158 void Settings::setVideoSceneMode(int mode) {
159 if (mode != videoSceneMode()) {
160 m_settings->setValue("video/sceneMode", mode);
163 emit videoSceneModeChanged();
166 int Settings::videoColorFilter() const {
167 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
170 void Settings::setVideoColorFilter(int filter) {
171 if (filter != videoColorFilter()) {
172 m_settings->setValue("video/colorFilter", filter);
174 emit videoColorFilterChanged();
178 int Settings::videoWhiteBalance() const {
179 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
182 void Settings::setVideoWhiteBalance(int wb) {
183 if (wb != videoWhiteBalance()) {
184 m_settings->setValue("video/whiteBalance", wb);
186 emit videoWhiteBalanceChanged();
190 qreal Settings::videoEvComp() const {
191 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
194 void Settings::setVideoEvComp(qreal ev) {
195 if (!qFuzzyCompare(ev, videoEvComp())) {
196 m_settings->setValue("video/evComp", ev);
198 emit videoEvCompChanged();
202 int Settings::imageFlashMode() const {
203 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
206 void Settings::setImageFlashMode(int mode) {
207 if (mode != imageFlashMode()) {
208 m_settings->setValue("image/flashMode", mode);
210 emit imageFlashModeChanged();
214 int Settings::imageIso() const {
215 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
218 void Settings::setImageIso(int iso) {
219 if (imageIso() != iso) {
220 m_settings->setValue("image/iso", iso);
221 emit imageIsoChanged();
225 QString Settings::imageAspectRatio() const {
226 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
229 void Settings::setImageAspectRatio(const QString& aspectRatio) {
230 if (aspectRatio != imageAspectRatio()) {
231 m_settings->setValue("image/aspectRatio", aspectRatio);
232 emit imageAspectRatioChanged();
236 QString Settings::imageResolution() const {
237 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
240 void Settings::setImageResolution(const QString& resolution) {
241 if (resolution != imageResolution()) {
242 m_settings->setValue("image/resolution", resolution);
243 emit imageResolutionChanged();
247 QString Settings::videoAspectRatio() const {
248 // This is not used for anything so we will return an empty string for now
249 // which will make the backend return all resolutions.
254 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
255 Q_UNUSED(aspectRatio);
257 // This is not used for anything so we will just ignore it.
260 QString Settings::videoResolution() const {
261 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
264 void Settings::setVideoResolution(const QString& resolution) {
265 if (resolution != videoResolution()) {
266 m_settings->setValue("video/resolution", resolution);
267 emit videoResolutionChanged();
271 bool Settings::isSoundEnabled() const {
272 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
275 void Settings::setSoundEnabled(bool enabled) {
276 if (isSoundEnabled() != enabled) {
277 m_settings->setValue("camera/soundEnabled", enabled);
278 emit soundEnabledChanged();
282 bool Settings::isVideoTorchOn() const {
283 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
286 void Settings::setVideoTorchOn(bool on) {
287 if (isVideoTorchOn() != on) {
288 m_settings->setValue("video/torchOn", on);
289 emit videoTorchOnChanged();
293 bool Settings::isToolBarShown() const {
294 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
297 void Settings::setToolBarShown(bool shown) {
298 if (isToolBarShown() != shown) {
299 m_settings->setValue("camera/showToolBar", shown);
301 emit toolBarShownChanged();
305 bool Settings::isVideoMuted() const {
306 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
309 void Settings::setVideoMuted(bool muted) {
310 if (isVideoMuted() != muted) {
311 m_settings->setValue("video/mute", muted);
312 emit videoMutedChanged();
316 bool Settings::isGridEnabled() const {
317 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
320 void Settings::setGridEnabled(bool enabled) {
321 if (enabled != isGridEnabled()) {
322 m_settings->setValue("camera/gridEnabled", enabled);
323 emit gridEnabledChanged();
327 bool Settings::isFaceDetectionEnabled() const {
328 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
331 void Settings::setFaceDetectionEnabled(bool enabled) {
332 if (isFaceDetectionEnabled() != enabled) {
333 m_settings->setValue("image/faceDetectionEnabled", enabled);
334 emit faceDetectionEnabledChanged();
338 bool Settings::isZoomAsShutterEnabled() {
339 return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
342 void Settings::setZoomAsShutterEnabled(bool enabled) {
343 if (isZoomAsShutterEnabled() != enabled) {
344 m_settings->setValue("camera/zoomAsShutter", enabled);
346 emit zoomAsShutterChanged();
350 int Settings::device() const {
351 return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
354 void Settings::setDevice(int device) {
355 if (device != Settings::device()) {
356 m_settings->setValue("camera/device", device);
357 emit deviceChanged();