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_SOUND_ENABLED true
37 #define DEFAULT_VIDEO_TORCH_ON false
38 #define DEFAULT_SHOW_TOOL_BAR false
39 #define DEFAULT_VIDEO_MUTE false
40 #define DEFAULT_GRID_ENABLED false
41 #define DEFAULT_FACE_DETECTION_ENABLED true
42 #define DEFAULT_ZOOM_AS_SHUTTER false
43 #define DEFAULT_DEVICE 0
45 #define DEFAULT_PRIMARY_IMAGE_RESOLUTION "high"
46 #define DEFAULT_PRIMARY_IMAGE_ASPECT_RATIO "16:9"
47 #define DEFAULT_PRIMARY_VIDEO_RESOLUTION "high"
48 #define DEFAULT_PRIMARY_VIDEO_ASPECT_RATIO "16:9"
50 #define DEFAULT_SECONDARY_IMAGE_RESOLUTION "low"
51 #define DEFAULT_SECONDARY_IMAGE_ASPECT_RATIO "4:3"
52 #define DEFAULT_SECONDARY_VIDEO_RESOLUTION "low"
53 #define DEFAULT_SECONDARY_VIDEO_ASPECT_RATIO "4:3"
55 Settings::Settings(QObject *parent) :
57 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
61 Settings::~Settings() {
62 delete m_settings; m_settings = 0;
65 int Settings::mode() const {
66 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
69 void Settings::setMode(int mode) {
70 if (mode != Settings::mode()) {
71 m_settings->setValue("camera/mode", mode);
77 QString Settings::creatorName() const {
78 return m_settings->value("camera/creatorName").toString();
81 void Settings::setCreatorName(const QString& name) {
82 if (name != creatorName()) {
83 m_settings->setValue("camera/creatorName", name);
85 emit creatorNameChanged();
89 bool Settings::useGps() const {
90 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
93 void Settings::setUseGps(bool enable) {
94 if (enable != useGps()) {
95 m_settings->setValue("camera/useGps", enable);
101 bool Settings::useGeotags() const {
102 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
105 void Settings::setUseGeotags(bool enable) {
106 if (enable != useGeotags()) {
107 m_settings->setValue("camera/useGeotags", enable);
109 emit useGeotagsChanged();
113 int Settings::imageSceneMode() const {
114 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
117 void Settings::setImageSceneMode(int mode) {
118 if (mode != imageSceneMode()) {
119 m_settings->setValue("image/sceneMode", mode);
122 emit imageSceneModeChanged();
125 int Settings::imageColorFilter() const {
126 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
129 void Settings::setImageColorFilter(int filter) {
130 if (filter != imageColorFilter()) {
131 m_settings->setValue("image/colorFilter", filter);
133 emit imageColorFilterChanged();
137 int Settings::imageWhiteBalance() const {
138 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
141 void Settings::setImageWhiteBalance(int wb) {
142 if (wb != imageWhiteBalance()) {
143 m_settings->setValue("image/whiteBalance", wb);
145 emit imageWhiteBalanceChanged();
149 qreal Settings::imageEvComp() const {
150 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
153 void Settings::setImageEvComp(qreal ev) {
154 if (!qFuzzyCompare(ev, imageEvComp())) {
155 m_settings->setValue("image/evComp", ev);
157 emit imageEvCompChanged();
161 int Settings::videoSceneMode() const {
162 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
165 void Settings::setVideoSceneMode(int mode) {
166 if (mode != videoSceneMode()) {
167 m_settings->setValue("video/sceneMode", mode);
170 emit videoSceneModeChanged();
173 int Settings::videoColorFilter() const {
174 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
177 void Settings::setVideoColorFilter(int filter) {
178 if (filter != videoColorFilter()) {
179 m_settings->setValue("video/colorFilter", filter);
181 emit videoColorFilterChanged();
185 int Settings::videoWhiteBalance() const {
186 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
189 void Settings::setVideoWhiteBalance(int wb) {
190 if (wb != videoWhiteBalance()) {
191 m_settings->setValue("video/whiteBalance", wb);
193 emit videoWhiteBalanceChanged();
197 qreal Settings::videoEvComp() const {
198 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
201 void Settings::setVideoEvComp(qreal ev) {
202 if (!qFuzzyCompare(ev, videoEvComp())) {
203 m_settings->setValue("video/evComp", ev);
205 emit videoEvCompChanged();
209 int Settings::imageFlashMode() const {
210 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
213 void Settings::setImageFlashMode(int mode) {
214 if (mode != imageFlashMode()) {
215 m_settings->setValue("image/flashMode", mode);
217 emit imageFlashModeChanged();
221 int Settings::imageIso() const {
222 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
225 void Settings::setImageIso(int iso) {
226 if (imageIso() != iso) {
227 m_settings->setValue("image/iso", iso);
228 emit imageIsoChanged();
232 bool Settings::isSoundEnabled() const {
233 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
236 void Settings::setSoundEnabled(bool enabled) {
237 if (isSoundEnabled() != enabled) {
238 m_settings->setValue("camera/soundEnabled", enabled);
239 emit soundEnabledChanged();
243 bool Settings::isVideoTorchOn() const {
244 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
247 void Settings::setVideoTorchOn(bool on) {
248 if (isVideoTorchOn() != on) {
249 m_settings->setValue("video/torchOn", on);
250 emit videoTorchOnChanged();
254 bool Settings::isToolBarShown() const {
255 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
258 void Settings::setToolBarShown(bool shown) {
259 if (isToolBarShown() != shown) {
260 m_settings->setValue("camera/showToolBar", shown);
262 emit toolBarShownChanged();
266 bool Settings::isVideoMuted() const {
267 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
270 void Settings::setVideoMuted(bool muted) {
271 if (isVideoMuted() != muted) {
272 m_settings->setValue("video/mute", muted);
273 emit videoMutedChanged();
277 bool Settings::isGridEnabled() const {
278 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
281 void Settings::setGridEnabled(bool enabled) {
282 if (enabled != isGridEnabled()) {
283 m_settings->setValue("camera/gridEnabled", enabled);
284 emit gridEnabledChanged();
288 bool Settings::isFaceDetectionEnabled() const {
289 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
292 void Settings::setFaceDetectionEnabled(bool enabled) {
293 if (isFaceDetectionEnabled() != enabled) {
294 m_settings->setValue("image/faceDetectionEnabled", enabled);
295 emit faceDetectionEnabledChanged();
299 bool Settings::isZoomAsShutterEnabled() {
300 return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
303 void Settings::setZoomAsShutterEnabled(bool enabled) {
304 if (isZoomAsShutterEnabled() != enabled) {
305 m_settings->setValue("camera/zoomAsShutter", enabled);
307 emit zoomAsShutterChanged();
311 int Settings::device() const {
312 return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
315 void Settings::setDevice(int device) {
316 if (device != Settings::device()) {
317 m_settings->setValue("camera/device", device);
318 emit deviceChanged();
322 QString Settings::primaryImageAspectRatio() const {
323 return m_settings->value("image/primaryAspectRatio",
324 DEFAULT_PRIMARY_IMAGE_ASPECT_RATIO).toString();
327 void Settings::setPrimaryImageAspectRatio(const QString& aspectRatio) {
328 if (primaryImageAspectRatio() != aspectRatio) {
329 m_settings->setValue("image/primaryAspectRatio", aspectRatio);
330 emit primaryImageAspectRatioChanged();
334 QString Settings::primaryImageResolution() const {
335 return m_settings->value("image/primaryResolution",
336 DEFAULT_PRIMARY_IMAGE_RESOLUTION).toString();
339 void Settings::setPrimaryImageResolution(const QString& resolution) {
340 if (primaryImageResolution() != resolution) {
341 m_settings->setValue("image/primaryResolution", resolution);
342 emit primaryImageResolutionChanged();
346 QString Settings::primaryVideoAspectRatio() const {
347 return m_settings->value("video/primaryAspectRatio",
348 DEFAULT_PRIMARY_VIDEO_ASPECT_RATIO).toString();
351 void Settings::setPrimaryVideoAspectRatio(const QString& aspectRatio) {
352 if (primaryVideoAspectRatio() != aspectRatio) {
353 m_settings->setValue("video/primaryAspectRatio", aspectRatio);
354 emit primaryVideoAspectRatioChanged();
358 QString Settings::primaryVideoResolution() const {
359 return m_settings->value("video/primaryResolution",
360 DEFAULT_PRIMARY_VIDEO_RESOLUTION).toString();
363 void Settings::setPrimaryVideoResolution(const QString& resolution) {
364 if (primaryVideoResolution() != resolution) {
365 m_settings->setValue("video/primaryResolution", resolution);
366 emit primaryVideoResolutionChanged();
370 QString Settings::secondaryImageAspectRatio() const {
371 return m_settings->value("image/secondaryAspectRatio",
372 DEFAULT_SECONDARY_IMAGE_ASPECT_RATIO).toString();
375 void Settings::setSecondaryImageAspectRatio(const QString& aspectRatio) {
376 if (secondaryImageAspectRatio() != aspectRatio) {
377 m_settings->setValue("image/secondaryAspectRatio", aspectRatio);
378 emit secondaryImageAspectRatioChanged();
382 QString Settings::secondaryImageResolution() const {
383 return m_settings->value("image/secondaryResolution",
384 DEFAULT_SECONDARY_IMAGE_RESOLUTION).toString();
387 void Settings::setSecondaryImageResolution(const QString& resolution) {
388 if (secondaryImageResolution() != resolution) {
389 m_settings->setValue("image/secondaryResolution", resolution);
390 emit secondaryImageResolutionChanged();
394 QString Settings::secondaryVideoAspectRatio() const {
395 return m_settings->value("video/secondaryAspectRatio",
396 DEFAULT_SECONDARY_VIDEO_ASPECT_RATIO).toString();
399 void Settings::setSecondaryVideoAspectRatio(const QString& aspectRatio) {
400 if (secondaryVideoAspectRatio() != aspectRatio) {
401 m_settings->setValue("video/secondaryAspectRatio", aspectRatio);
402 emit secondaryVideoAspectRatioChanged();
406 QString Settings::secondaryVideoResolution() const {
407 return m_settings->value("video/secondaryResolution",
408 DEFAULT_SECONDARY_VIDEO_RESOLUTION).toString();
411 void Settings::setSecondaryVideoResolution(const QString& resolution) {
412 if (secondaryVideoResolution() != resolution) {
413 m_settings->setValue("video/secondaryResolution", resolution);
414 emit secondaryVideoResolutionChanged();