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
43 #define DEFAULT_VIDEO_MUTE false
45 Settings::Settings(QObject *parent) :
47 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
51 Settings::~Settings() {
52 delete m_settings; m_settings = 0;
55 int Settings::mode() const {
56 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
59 void Settings::setMode(int mode) {
60 if (mode != Settings::mode()) {
61 m_settings->setValue("camera/mode", mode);
67 QString Settings::creatorName() const {
68 return m_settings->value("camera/creatorName").toString();
71 void Settings::setCreatorName(const QString& name) {
72 if (name != creatorName()) {
73 m_settings->setValue("camera/creatorName", name);
75 emit creatorNameChanged();
79 int Settings::postCaptureTimeout() const {
80 return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
83 void Settings::setPostCaptureTimeout(int timeout) {
84 if (timeout != postCaptureTimeout()) {
85 m_settings->setValue("camera/postCaptureTimeout", timeout);
87 emit postCaptureTimeoutChanged();
91 bool Settings::useGps() const {
92 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
95 void Settings::setUseGps(bool enable) {
96 if (enable != useGps()) {
97 m_settings->setValue("camera/useGps", enable);
103 bool Settings::useGeotags() const {
104 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
107 void Settings::setUseGeotags(bool enable) {
108 if (enable != useGeotags()) {
109 m_settings->setValue("camera/useGeotags", enable);
111 emit useGeotagsChanged();
115 int Settings::imageSceneMode() const {
116 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
119 void Settings::setImageSceneMode(int mode) {
120 if (mode != imageSceneMode()) {
121 m_settings->setValue("image/sceneMode", mode);
124 emit imageSceneModeChanged();
127 int Settings::imageColorFilter() const {
128 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
131 void Settings::setImageColorFilter(int filter) {
132 if (filter != imageColorFilter()) {
133 m_settings->setValue("image/colorFilter", filter);
135 emit imageColorFilterChanged();
139 int Settings::imageWhiteBalance() const {
140 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
143 void Settings::setImageWhiteBalance(int wb) {
144 if (wb != imageWhiteBalance()) {
145 m_settings->setValue("image/whiteBalance", wb);
147 emit imageWhiteBalanceChanged();
151 qreal Settings::imageEvComp() const {
152 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
155 void Settings::setImageEvComp(qreal ev) {
156 if (!qFuzzyCompare(ev, imageEvComp())) {
157 m_settings->setValue("image/evComp", ev);
159 emit imageEvCompChanged();
163 int Settings::videoSceneMode() const {
164 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
167 void Settings::setVideoSceneMode(int mode) {
168 if (mode != videoSceneMode()) {
169 m_settings->setValue("video/sceneMode", mode);
172 emit videoSceneModeChanged();
175 int Settings::videoColorFilter() const {
176 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
179 void Settings::setVideoColorFilter(int filter) {
180 if (filter != videoColorFilter()) {
181 m_settings->setValue("video/colorFilter", filter);
183 emit videoColorFilterChanged();
187 int Settings::videoWhiteBalance() const {
188 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
191 void Settings::setVideoWhiteBalance(int wb) {
192 if (wb != videoWhiteBalance()) {
193 m_settings->setValue("video/whiteBalance", wb);
195 emit videoWhiteBalanceChanged();
199 qreal Settings::videoEvComp() const {
200 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
203 void Settings::setVideoEvComp(qreal ev) {
204 if (!qFuzzyCompare(ev, videoEvComp())) {
205 m_settings->setValue("video/evComp", ev);
207 emit videoEvCompChanged();
211 int Settings::imageFlashMode() const {
212 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
215 void Settings::setImageFlashMode(int mode) {
216 if (mode != imageFlashMode()) {
217 m_settings->setValue("image/flashMode", mode);
219 emit imageFlashModeChanged();
223 int Settings::imageIso() const {
224 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
227 void Settings::setImageIso(int iso) {
228 if (imageIso() != iso) {
229 m_settings->setValue("image/iso", iso);
230 emit imageIsoChanged();
234 QString Settings::imageAspectRatio() const {
235 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
238 void Settings::setImageAspectRatio(const QString& aspectRatio) {
239 if (aspectRatio != imageAspectRatio()) {
240 m_settings->setValue("image/aspectRatio", aspectRatio);
241 emit imageAspectRatioChanged();
245 QString Settings::imageResolution() const {
246 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
249 void Settings::setImageResolution(const QString& resolution) {
250 if (resolution != imageResolution()) {
251 m_settings->setValue("image/resolution", resolution);
252 emit imageResolutionChanged();
256 QString Settings::videoAspectRatio() const {
257 // This is not used for anything so we will return an empty string for now
258 // which will make the backend return all resolutions.
263 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
264 Q_UNUSED(aspectRatio);
266 // This is not used for anything so we will just ignore it.
269 QString Settings::videoResolution() const {
270 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
273 void Settings::setVideoResolution(const QString& resolution) {
274 if (resolution != videoResolution()) {
275 m_settings->setValue("video/resolution", resolution);
276 emit videoResolutionChanged();
280 bool Settings::isSoundEnabled() const {
281 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
284 void Settings::setSoundEnabled(bool enabled) {
285 if (isSoundEnabled() != enabled) {
286 m_settings->setValue("camera/soundEnabled", enabled);
287 emit soundEnabledChanged();
291 bool Settings::isVideoTorchOn() const {
292 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
295 void Settings::setVideoTorchOn(bool on) {
296 if (isVideoTorchOn() != on) {
297 m_settings->setValue("video/torchOn", on);
298 emit videoTorchOnChanged();
302 bool Settings::isToolBarShown() const {
303 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
306 void Settings::setToolBarShown(bool shown) {
307 if (isToolBarShown() != shown) {
308 m_settings->setValue("camera/showToolBar", shown);
310 emit toolBarShownChanged();
314 bool Settings::isVideoMuted() const {
315 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
318 void Settings::setVideoMuted(bool muted) {
319 if (isVideoMuted() != muted) {
320 m_settings->setValue("video/mute", muted);
321 emit videoMutedChanged();