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
42 #define DEFAULT_SHOW_TOOL_BAR false
44 Settings::Settings(QObject *parent) :
46 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
50 Settings::~Settings() {
51 delete m_settings; m_settings = 0;
54 int Settings::mode() const {
55 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
58 void Settings::setMode(int mode) {
59 if (mode != Settings::mode()) {
60 m_settings->setValue("camera/mode", mode);
66 QString Settings::creatorName() const {
67 return m_settings->value("camera/creatorName").toString();
70 void Settings::setCreatorName(const QString& name) {
71 if (name != creatorName()) {
72 m_settings->setValue("camera/creatorName", name);
74 emit creatorNameChanged();
78 int Settings::postCaptureTimeout() const {
79 return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
82 void Settings::setPostCaptureTimeout(int timeout) {
83 if (timeout != postCaptureTimeout()) {
84 m_settings->setValue("camera/postCaptureTimeout", timeout);
86 emit postCaptureTimeoutChanged();
90 bool Settings::useGps() const {
91 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
94 void Settings::setUseGps(bool enable) {
95 if (enable != useGps()) {
96 m_settings->setValue("camera/useGps", enable);
102 bool Settings::useGeotags() const {
103 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
106 void Settings::setUseGeotags(bool enable) {
107 if (enable != useGeotags()) {
108 m_settings->setValue("camera/useGeotags", enable);
110 emit useGeotagsChanged();
114 int Settings::imageSceneMode() const {
115 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
118 void Settings::setImageSceneMode(int mode) {
119 if (mode != imageSceneMode()) {
120 m_settings->setValue("image/sceneMode", mode);
123 emit imageSceneModeChanged();
126 int Settings::imageColorFilter() const {
127 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
130 void Settings::setImageColorFilter(int filter) {
131 if (filter != imageColorFilter()) {
132 m_settings->setValue("image/colorFilter", filter);
134 emit imageColorFilterChanged();
138 int Settings::imageWhiteBalance() const {
139 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
142 void Settings::setImageWhiteBalance(int wb) {
143 if (wb != imageWhiteBalance()) {
144 m_settings->setValue("image/whiteBalance", wb);
146 emit imageWhiteBalanceChanged();
150 qreal Settings::imageEvComp() const {
151 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
154 void Settings::setImageEvComp(qreal ev) {
155 if (!qFuzzyCompare(ev, imageEvComp())) {
156 m_settings->setValue("image/evComp", ev);
158 emit imageEvCompChanged();
162 int Settings::videoSceneMode() const {
163 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
166 void Settings::setVideoSceneMode(int mode) {
167 if (mode != videoSceneMode()) {
168 m_settings->setValue("video/sceneMode", mode);
171 emit videoSceneModeChanged();
174 int Settings::videoColorFilter() const {
175 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
178 void Settings::setVideoColorFilter(int filter) {
179 if (filter != videoColorFilter()) {
180 m_settings->setValue("video/colorFilter", filter);
182 emit videoColorFilterChanged();
186 int Settings::videoWhiteBalance() const {
187 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
190 void Settings::setVideoWhiteBalance(int wb) {
191 if (wb != videoWhiteBalance()) {
192 m_settings->setValue("video/whiteBalance", wb);
194 emit videoWhiteBalanceChanged();
198 qreal Settings::videoEvComp() const {
199 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
202 void Settings::setVideoEvComp(qreal ev) {
203 if (!qFuzzyCompare(ev, videoEvComp())) {
204 m_settings->setValue("video/evComp", ev);
206 emit videoEvCompChanged();
210 int Settings::imageFlashMode() const {
211 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
214 void Settings::setImageFlashMode(int mode) {
215 if (mode != imageFlashMode()) {
216 m_settings->setValue("image/flashMode", mode);
218 emit imageFlashModeChanged();
222 int Settings::imageIso() const {
223 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
226 void Settings::setImageIso(int iso) {
227 if (imageIso() != iso) {
228 m_settings->setValue("image/iso", iso);
229 emit imageIsoChanged();
233 QString Settings::imageAspectRatio() const {
234 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
237 void Settings::setImageAspectRatio(const QString& aspectRatio) {
238 if (aspectRatio != imageAspectRatio()) {
239 m_settings->setValue("image/aspectRatio", aspectRatio);
240 emit imageAspectRatioChanged();
244 QString Settings::imageResolution() const {
245 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
248 void Settings::setImageResolution(const QString& resolution) {
249 if (resolution != imageResolution()) {
250 m_settings->setValue("image/resolution", resolution);
251 emit imageResolutionChanged();
255 QString Settings::videoAspectRatio() const {
256 // This is not used for anything so we will return an empty string for now
257 // which will make the backend return all resolutions.
262 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
263 Q_UNUSED(aspectRatio);
265 // This is not used for anything so we will just ignore it.
268 QString Settings::videoResolution() const {
269 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
272 void Settings::setVideoResolution(const QString& resolution) {
273 if (resolution != videoResolution()) {
274 m_settings->setValue("video/resolution", resolution);
275 emit videoResolutionChanged();
279 bool Settings::isSoundEnabled() const {
280 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
283 void Settings::setSoundEnabled(bool enabled) {
284 if (isSoundEnabled() != enabled) {
285 m_settings->setValue("camera/soundEnabled", enabled);
286 emit soundEnabledChanged();
290 bool Settings::isVideoTorchOn() const {
291 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
294 void Settings::setVideoTorchOn(bool on) {
295 if (isVideoTorchOn() != on) {
296 m_settings->setValue("video/torchOn", on);
297 emit videoTorchOnChanged();
301 bool Settings::isToolBarShown() const {
302 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
305 void Settings::setToolBarShown(bool shown) {
306 if (isToolBarShown() != shown) {
307 m_settings->setValue("camera/showToolBar", shown);
309 emit toolBarShownChanged();