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
47 Settings::Settings(QObject *parent) :
49 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
53 Settings::~Settings() {
54 delete m_settings; m_settings = 0;
57 int Settings::mode() const {
58 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
61 void Settings::setMode(int mode) {
62 if (mode != Settings::mode()) {
63 m_settings->setValue("camera/mode", mode);
69 QString Settings::creatorName() const {
70 return m_settings->value("camera/creatorName").toString();
73 void Settings::setCreatorName(const QString& name) {
74 if (name != creatorName()) {
75 m_settings->setValue("camera/creatorName", name);
77 emit creatorNameChanged();
81 bool Settings::useGps() const {
82 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
85 void Settings::setUseGps(bool enable) {
86 if (enable != useGps()) {
87 m_settings->setValue("camera/useGps", enable);
93 bool Settings::useGeotags() const {
94 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
97 void Settings::setUseGeotags(bool enable) {
98 if (enable != useGeotags()) {
99 m_settings->setValue("camera/useGeotags", enable);
101 emit useGeotagsChanged();
105 int Settings::imageSceneMode() const {
106 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
109 void Settings::setImageSceneMode(int mode) {
110 if (mode != imageSceneMode()) {
111 m_settings->setValue("image/sceneMode", mode);
114 emit imageSceneModeChanged();
117 int Settings::imageColorFilter() const {
118 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
121 void Settings::setImageColorFilter(int filter) {
122 if (filter != imageColorFilter()) {
123 m_settings->setValue("image/colorFilter", filter);
125 emit imageColorFilterChanged();
129 int Settings::imageWhiteBalance() const {
130 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
133 void Settings::setImageWhiteBalance(int wb) {
134 if (wb != imageWhiteBalance()) {
135 m_settings->setValue("image/whiteBalance", wb);
137 emit imageWhiteBalanceChanged();
141 qreal Settings::imageEvComp() const {
142 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
145 void Settings::setImageEvComp(qreal ev) {
146 if (!qFuzzyCompare(ev, imageEvComp())) {
147 m_settings->setValue("image/evComp", ev);
149 emit imageEvCompChanged();
153 int Settings::videoSceneMode() const {
154 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
157 void Settings::setVideoSceneMode(int mode) {
158 if (mode != videoSceneMode()) {
159 m_settings->setValue("video/sceneMode", mode);
162 emit videoSceneModeChanged();
165 int Settings::videoColorFilter() const {
166 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
169 void Settings::setVideoColorFilter(int filter) {
170 if (filter != videoColorFilter()) {
171 m_settings->setValue("video/colorFilter", filter);
173 emit videoColorFilterChanged();
177 int Settings::videoWhiteBalance() const {
178 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
181 void Settings::setVideoWhiteBalance(int wb) {
182 if (wb != videoWhiteBalance()) {
183 m_settings->setValue("video/whiteBalance", wb);
185 emit videoWhiteBalanceChanged();
189 qreal Settings::videoEvComp() const {
190 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
193 void Settings::setVideoEvComp(qreal ev) {
194 if (!qFuzzyCompare(ev, videoEvComp())) {
195 m_settings->setValue("video/evComp", ev);
197 emit videoEvCompChanged();
201 int Settings::imageFlashMode() const {
202 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
205 void Settings::setImageFlashMode(int mode) {
206 if (mode != imageFlashMode()) {
207 m_settings->setValue("image/flashMode", mode);
209 emit imageFlashModeChanged();
213 int Settings::imageIso() const {
214 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
217 void Settings::setImageIso(int iso) {
218 if (imageIso() != iso) {
219 m_settings->setValue("image/iso", iso);
220 emit imageIsoChanged();
224 QString Settings::imageAspectRatio() const {
225 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
228 void Settings::setImageAspectRatio(const QString& aspectRatio) {
229 if (aspectRatio != imageAspectRatio()) {
230 m_settings->setValue("image/aspectRatio", aspectRatio);
231 emit imageAspectRatioChanged();
235 QString Settings::imageResolution() const {
236 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
239 void Settings::setImageResolution(const QString& resolution) {
240 if (resolution != imageResolution()) {
241 m_settings->setValue("image/resolution", resolution);
242 emit imageResolutionChanged();
246 QString Settings::videoAspectRatio() const {
247 // This is not used for anything so we will return an empty string for now
248 // which will make the backend return all resolutions.
253 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
254 Q_UNUSED(aspectRatio);
256 // This is not used for anything so we will just ignore it.
259 QString Settings::videoResolution() const {
260 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
263 void Settings::setVideoResolution(const QString& resolution) {
264 if (resolution != videoResolution()) {
265 m_settings->setValue("video/resolution", resolution);
266 emit videoResolutionChanged();
270 bool Settings::isSoundEnabled() const {
271 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
274 void Settings::setSoundEnabled(bool enabled) {
275 if (isSoundEnabled() != enabled) {
276 m_settings->setValue("camera/soundEnabled", enabled);
277 emit soundEnabledChanged();
281 bool Settings::isVideoTorchOn() const {
282 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
285 void Settings::setVideoTorchOn(bool on) {
286 if (isVideoTorchOn() != on) {
287 m_settings->setValue("video/torchOn", on);
288 emit videoTorchOnChanged();
292 bool Settings::isToolBarShown() const {
293 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
296 void Settings::setToolBarShown(bool shown) {
297 if (isToolBarShown() != shown) {
298 m_settings->setValue("camera/showToolBar", shown);
300 emit toolBarShownChanged();
304 bool Settings::isVideoMuted() const {
305 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
308 void Settings::setVideoMuted(bool muted) {
309 if (isVideoMuted() != muted) {
310 m_settings->setValue("video/mute", muted);
311 emit videoMutedChanged();
315 bool Settings::isGridEnabled() const {
316 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
319 void Settings::setGridEnabled(bool enabled) {
320 if (enabled != isGridEnabled()) {
321 m_settings->setValue("camera/gridEnabled", enabled);
322 emit gridEnabledChanged();
326 bool Settings::isFaceDetectionEnabled() const {
327 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
330 void Settings::setFaceDetectionEnabled(bool enabled) {
331 if (isFaceDetectionEnabled() != enabled) {
332 m_settings->setValue("image/faceDetectionEnabled", enabled);
333 emit faceDetectionEnabledChanged();
337 bool Settings::isZoomAsShutterEnabled() {
338 return m_settings->value("camera/zoomAsShutter", DEFAULT_ZOOM_AS_SHUTTER).toBool();
341 void Settings::setZoomAsShutterEnabled(bool enabled) {
342 if (isZoomAsShutterEnabled() != enabled) {
343 m_settings->setValue("camera/zoomAsShutter", enabled);
345 emit zoomAsShutterChanged();