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_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
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 bool Settings::useGps() const {
79 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
82 void Settings::setUseGps(bool enable) {
83 if (enable != useGps()) {
84 m_settings->setValue("camera/useGps", enable);
90 bool Settings::useGeotags() const {
91 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
94 void Settings::setUseGeotags(bool enable) {
95 if (enable != useGeotags()) {
96 m_settings->setValue("camera/useGeotags", enable);
98 emit useGeotagsChanged();
102 int Settings::imageSceneMode() const {
103 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
106 void Settings::setImageSceneMode(int mode) {
107 if (mode != imageSceneMode()) {
108 m_settings->setValue("image/sceneMode", mode);
111 emit imageSceneModeChanged();
114 int Settings::imageColorFilter() const {
115 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
118 void Settings::setImageColorFilter(int filter) {
119 if (filter != imageColorFilter()) {
120 m_settings->setValue("image/colorFilter", filter);
122 emit imageColorFilterChanged();
126 int Settings::imageWhiteBalance() const {
127 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
130 void Settings::setImageWhiteBalance(int wb) {
131 if (wb != imageWhiteBalance()) {
132 m_settings->setValue("image/whiteBalance", wb);
134 emit imageWhiteBalanceChanged();
138 qreal Settings::imageEvComp() const {
139 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
142 void Settings::setImageEvComp(qreal ev) {
143 if (!qFuzzyCompare(ev, imageEvComp())) {
144 m_settings->setValue("image/evComp", ev);
146 emit imageEvCompChanged();
150 int Settings::videoSceneMode() const {
151 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
154 void Settings::setVideoSceneMode(int mode) {
155 if (mode != videoSceneMode()) {
156 m_settings->setValue("video/sceneMode", mode);
159 emit videoSceneModeChanged();
162 int Settings::videoColorFilter() const {
163 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
166 void Settings::setVideoColorFilter(int filter) {
167 if (filter != videoColorFilter()) {
168 m_settings->setValue("video/colorFilter", filter);
170 emit videoColorFilterChanged();
174 int Settings::videoWhiteBalance() const {
175 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
178 void Settings::setVideoWhiteBalance(int wb) {
179 if (wb != videoWhiteBalance()) {
180 m_settings->setValue("video/whiteBalance", wb);
182 emit videoWhiteBalanceChanged();
186 qreal Settings::videoEvComp() const {
187 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
190 void Settings::setVideoEvComp(qreal ev) {
191 if (!qFuzzyCompare(ev, videoEvComp())) {
192 m_settings->setValue("video/evComp", ev);
194 emit videoEvCompChanged();
198 int Settings::imageFlashMode() const {
199 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
202 void Settings::setImageFlashMode(int mode) {
203 if (mode != imageFlashMode()) {
204 m_settings->setValue("image/flashMode", mode);
206 emit imageFlashModeChanged();
210 int Settings::imageIso() const {
211 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
214 void Settings::setImageIso(int iso) {
215 if (imageIso() != iso) {
216 m_settings->setValue("image/iso", iso);
217 emit imageIsoChanged();
221 QString Settings::imageAspectRatio() const {
222 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
225 void Settings::setImageAspectRatio(const QString& aspectRatio) {
226 if (aspectRatio != imageAspectRatio()) {
227 m_settings->setValue("image/aspectRatio", aspectRatio);
228 emit imageAspectRatioChanged();
232 QString Settings::imageResolution() const {
233 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
236 void Settings::setImageResolution(const QString& resolution) {
237 if (resolution != imageResolution()) {
238 m_settings->setValue("image/resolution", resolution);
239 emit imageResolutionChanged();
243 QString Settings::videoAspectRatio() const {
244 // This is not used for anything so we will return an empty string for now
245 // which will make the backend return all resolutions.
250 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
251 Q_UNUSED(aspectRatio);
253 // This is not used for anything so we will just ignore it.
256 QString Settings::videoResolution() const {
257 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
260 void Settings::setVideoResolution(const QString& resolution) {
261 if (resolution != videoResolution()) {
262 m_settings->setValue("video/resolution", resolution);
263 emit videoResolutionChanged();
267 bool Settings::isSoundEnabled() const {
268 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
271 void Settings::setSoundEnabled(bool enabled) {
272 if (isSoundEnabled() != enabled) {
273 m_settings->setValue("camera/soundEnabled", enabled);
274 emit soundEnabledChanged();
278 bool Settings::isVideoTorchOn() const {
279 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
282 void Settings::setVideoTorchOn(bool on) {
283 if (isVideoTorchOn() != on) {
284 m_settings->setValue("video/torchOn", on);
285 emit videoTorchOnChanged();
289 bool Settings::isToolBarShown() const {
290 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
293 void Settings::setToolBarShown(bool shown) {
294 if (isToolBarShown() != shown) {
295 m_settings->setValue("camera/showToolBar", shown);
297 emit toolBarShownChanged();
301 bool Settings::isVideoMuted() const {
302 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
305 void Settings::setVideoMuted(bool muted) {
306 if (isVideoMuted() != muted) {
307 m_settings->setValue("video/mute", muted);
308 emit videoMutedChanged();