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 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
42 Settings::Settings(QObject *parent) :
44 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
48 Settings::~Settings() {
49 delete m_settings; m_settings = 0;
52 int Settings::mode() const {
53 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
56 void Settings::setMode(int mode) {
57 if (mode != Settings::mode()) {
58 m_settings->setValue("camera/mode", mode);
64 QString Settings::creatorName() const {
65 return m_settings->value("camera/creatorName").toString();
68 void Settings::setCreatorName(const QString& name) {
69 if (name != creatorName()) {
70 m_settings->setValue("camera/creatorName", name);
72 emit creatorNameChanged();
76 int Settings::postCaptureTimeout() const {
77 return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
80 void Settings::setPostCaptureTimeout(int timeout) {
81 if (timeout != postCaptureTimeout()) {
82 m_settings->setValue("camera/postCaptureTimeout", timeout);
84 emit postCaptureTimeoutChanged();
88 bool Settings::useGps() const {
89 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
92 void Settings::setUseGps(bool enable) {
93 if (enable != useGps()) {
94 m_settings->setValue("camera/useGps", enable);
100 bool Settings::useGeotags() const {
101 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
104 void Settings::setUseGeotags(bool enable) {
105 if (enable != useGeotags()) {
106 m_settings->setValue("camera/useGeotags", enable);
108 emit useGeotagsChanged();
112 int Settings::imageSceneMode() const {
113 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
116 void Settings::setImageSceneMode(int mode) {
117 if (mode != imageSceneMode()) {
118 m_settings->setValue("image/sceneMode", mode);
120 emit imageSceneModeChanged();
124 int Settings::imageColorFilter() const {
125 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
128 void Settings::setImageColorFilter(int filter) {
129 if (filter != imageColorFilter()) {
130 m_settings->setValue("image/colorFilter", filter);
132 emit imageColorFilterChanged();
136 int Settings::imageWhiteBalance() const {
137 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
140 void Settings::setImageWhiteBalance(int wb) {
141 if (wb != imageWhiteBalance()) {
142 m_settings->setValue("image/whiteBalance", wb);
144 emit imageWhiteBalanceChanged();
148 qreal Settings::imageEvComp() const {
149 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
152 void Settings::setImageEvComp(qreal ev) {
153 if (ev != imageEvComp()) {
154 m_settings->setValue("image/evComp", ev);
156 emit imageEvCompChanged();
160 int Settings::videoSceneMode() const {
161 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
164 void Settings::setVideoSceneMode(int mode) {
165 if (mode != videoSceneMode()) {
166 m_settings->setValue("video/sceneMode", mode);
168 emit videoSceneModeChanged();
172 int Settings::videoColorFilter() const {
173 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
176 void Settings::setVideoColorFilter(int filter) {
177 if (filter != videoColorFilter()) {
178 m_settings->setValue("video/colorFilter", filter);
180 emit videoColorFilterChanged();
184 int Settings::videoWhiteBalance() const {
185 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
188 void Settings::setVideoWhiteBalance(int wb) {
189 if (wb != videoWhiteBalance()) {
190 m_settings->setValue("video/whiteBalance", wb);
192 emit videoWhiteBalanceChanged();
196 qreal Settings::videoEvComp() const {
197 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
200 void Settings::setVideoEvComp(qreal ev) {
201 if (ev != videoEvComp()) {
202 m_settings->setValue("video/evComp", ev);
204 emit videoEvCompChanged();
208 int Settings::imageFlashMode() const {
209 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
212 void Settings::setImageFlashMode(int mode) {
213 if (mode != imageFlashMode()) {
214 m_settings->setValue("image/flashMode", mode);
216 emit imageFlashModeChanged();
220 int Settings::imageIso() const {
221 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
224 void Settings::setImageIso(int iso) {
225 if (imageIso() != iso) {
226 m_settings->setValue("image/iso", iso);
227 emit imageIsoChanged();
231 QString Settings::imageAspectRatio() const {
232 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
235 void Settings::setImageAspectRatio(const QString& aspectRatio) {
236 if (aspectRatio != imageAspectRatio()) {
237 m_settings->setValue("image/aspectRatio", aspectRatio);
238 emit imageAspectRatioChanged();
242 QString Settings::imageResolution() const {
243 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
246 void Settings::setImageResolution(const QString& resolution) {
247 if (resolution != imageResolution()) {
248 m_settings->setValue("image/resolution", resolution);
249 emit imageResolutionChanged();
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.
260 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
261 Q_UNUSED(aspectRatio);
263 // This is not used for anything so we will just ignore it.
266 QString Settings::videoResolution() const {
267 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
270 void Settings::setVideoResolution(const QString& resolution) {
271 if (resolution != videoResolution()) {
272 m_settings->setValue("video/resolution", resolution);
273 emit videoResolutionChanged();
277 bool Settings::isSoundEnabled() const {
278 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
281 void Settings::setSoundEnabled(bool enabled) {
282 if (isSoundEnabled() != enabled) {
283 m_settings->setValue("camera/soundEnabled", enabled);
284 emit soundEnabledChanged();