2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 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_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
43 Settings::Settings(QObject *parent) :
45 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
49 Settings::~Settings() {
50 delete m_settings; m_settings = 0;
53 int Settings::mode() const {
54 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
57 void Settings::setMode(int mode) {
58 if (mode != Settings::mode()) {
59 m_settings->setValue("camera/mode", mode);
65 QString Settings::creatorName() const {
66 return m_settings->value("camera/creatorName").toString();
69 void Settings::setCreatorName(const QString& name) {
70 if (name != creatorName()) {
71 m_settings->setValue("camera/creatorName", name);
73 emit creatorNameChanged();
77 int Settings::postCaptureTimeout() const {
78 return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
81 void Settings::setPostCaptureTimeout(int timeout) {
82 if (timeout != postCaptureTimeout()) {
83 m_settings->setValue("camera/postCaptureTimeout", timeout);
85 emit postCaptureTimeoutChanged();
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 QString Settings::imageAspectRatio() const {
233 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
236 void Settings::setImageAspectRatio(const QString& aspectRatio) {
237 if (aspectRatio != imageAspectRatio()) {
238 m_settings->setValue("image/aspectRatio", aspectRatio);
239 emit imageAspectRatioChanged();
243 QString Settings::imageResolution() const {
244 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
247 void Settings::setImageResolution(const QString& resolution) {
248 if (resolution != imageResolution()) {
249 m_settings->setValue("image/resolution", resolution);
250 emit imageResolutionChanged();
254 QString Settings::videoAspectRatio() const {
255 // This is not used for anything so we will return an empty string for now
256 // which will make the backend return all resolutions.
261 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
262 Q_UNUSED(aspectRatio);
264 // This is not used for anything so we will just ignore it.
267 QString Settings::videoResolution() const {
268 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
271 void Settings::setVideoResolution(const QString& resolution) {
272 if (resolution != videoResolution()) {
273 m_settings->setValue("video/resolution", resolution);
274 emit videoResolutionChanged();
278 bool Settings::isSoundEnabled() const {
279 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
282 void Settings::setSoundEnabled(bool enabled) {
283 if (isSoundEnabled() != enabled) {
284 m_settings->setValue("camera/soundEnabled", enabled);
285 emit soundEnabledChanged();
289 bool Settings::isVideoTorchOn() const {
290 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
293 void Settings::setVideoTorchOn(bool on) {
294 if (isVideoTorchOn() != on) {
295 m_settings->setValue("video/torchOn", on);
296 emit videoTorchOnChanged();