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
43 #define DEFAULT_GRID_ENABLED false
44 #define DEFAULT_FACE_DETECTION_ENABLED true
46 Settings::Settings(QObject *parent) :
48 m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
52 Settings::~Settings() {
53 delete m_settings; m_settings = 0;
56 int Settings::mode() const {
57 return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
60 void Settings::setMode(int mode) {
61 if (mode != Settings::mode()) {
62 m_settings->setValue("camera/mode", mode);
68 QString Settings::creatorName() const {
69 return m_settings->value("camera/creatorName").toString();
72 void Settings::setCreatorName(const QString& name) {
73 if (name != creatorName()) {
74 m_settings->setValue("camera/creatorName", name);
76 emit creatorNameChanged();
80 bool Settings::useGps() const {
81 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
84 void Settings::setUseGps(bool enable) {
85 if (enable != useGps()) {
86 m_settings->setValue("camera/useGps", enable);
92 bool Settings::useGeotags() const {
93 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
96 void Settings::setUseGeotags(bool enable) {
97 if (enable != useGeotags()) {
98 m_settings->setValue("camera/useGeotags", enable);
100 emit useGeotagsChanged();
104 int Settings::imageSceneMode() const {
105 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
108 void Settings::setImageSceneMode(int mode) {
109 if (mode != imageSceneMode()) {
110 m_settings->setValue("image/sceneMode", mode);
113 emit imageSceneModeChanged();
116 int Settings::imageColorFilter() const {
117 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
120 void Settings::setImageColorFilter(int filter) {
121 if (filter != imageColorFilter()) {
122 m_settings->setValue("image/colorFilter", filter);
124 emit imageColorFilterChanged();
128 int Settings::imageWhiteBalance() const {
129 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
132 void Settings::setImageWhiteBalance(int wb) {
133 if (wb != imageWhiteBalance()) {
134 m_settings->setValue("image/whiteBalance", wb);
136 emit imageWhiteBalanceChanged();
140 qreal Settings::imageEvComp() const {
141 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
144 void Settings::setImageEvComp(qreal ev) {
145 if (!qFuzzyCompare(ev, imageEvComp())) {
146 m_settings->setValue("image/evComp", ev);
148 emit imageEvCompChanged();
152 int Settings::videoSceneMode() const {
153 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
156 void Settings::setVideoSceneMode(int mode) {
157 if (mode != videoSceneMode()) {
158 m_settings->setValue("video/sceneMode", mode);
161 emit videoSceneModeChanged();
164 int Settings::videoColorFilter() const {
165 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
168 void Settings::setVideoColorFilter(int filter) {
169 if (filter != videoColorFilter()) {
170 m_settings->setValue("video/colorFilter", filter);
172 emit videoColorFilterChanged();
176 int Settings::videoWhiteBalance() const {
177 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
180 void Settings::setVideoWhiteBalance(int wb) {
181 if (wb != videoWhiteBalance()) {
182 m_settings->setValue("video/whiteBalance", wb);
184 emit videoWhiteBalanceChanged();
188 qreal Settings::videoEvComp() const {
189 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
192 void Settings::setVideoEvComp(qreal ev) {
193 if (!qFuzzyCompare(ev, videoEvComp())) {
194 m_settings->setValue("video/evComp", ev);
196 emit videoEvCompChanged();
200 int Settings::imageFlashMode() const {
201 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
204 void Settings::setImageFlashMode(int mode) {
205 if (mode != imageFlashMode()) {
206 m_settings->setValue("image/flashMode", mode);
208 emit imageFlashModeChanged();
212 int Settings::imageIso() const {
213 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
216 void Settings::setImageIso(int iso) {
217 if (imageIso() != iso) {
218 m_settings->setValue("image/iso", iso);
219 emit imageIsoChanged();
223 QString Settings::imageAspectRatio() const {
224 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
227 void Settings::setImageAspectRatio(const QString& aspectRatio) {
228 if (aspectRatio != imageAspectRatio()) {
229 m_settings->setValue("image/aspectRatio", aspectRatio);
230 emit imageAspectRatioChanged();
234 QString Settings::imageResolution() const {
235 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
238 void Settings::setImageResolution(const QString& resolution) {
239 if (resolution != imageResolution()) {
240 m_settings->setValue("image/resolution", resolution);
241 emit imageResolutionChanged();
245 QString Settings::videoAspectRatio() const {
246 // This is not used for anything so we will return an empty string for now
247 // which will make the backend return all resolutions.
252 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
253 Q_UNUSED(aspectRatio);
255 // This is not used for anything so we will just ignore it.
258 QString Settings::videoResolution() const {
259 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
262 void Settings::setVideoResolution(const QString& resolution) {
263 if (resolution != videoResolution()) {
264 m_settings->setValue("video/resolution", resolution);
265 emit videoResolutionChanged();
269 bool Settings::isSoundEnabled() const {
270 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
273 void Settings::setSoundEnabled(bool enabled) {
274 if (isSoundEnabled() != enabled) {
275 m_settings->setValue("camera/soundEnabled", enabled);
276 emit soundEnabledChanged();
280 bool Settings::isVideoTorchOn() const {
281 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
284 void Settings::setVideoTorchOn(bool on) {
285 if (isVideoTorchOn() != on) {
286 m_settings->setValue("video/torchOn", on);
287 emit videoTorchOnChanged();
291 bool Settings::isToolBarShown() const {
292 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
295 void Settings::setToolBarShown(bool shown) {
296 if (isToolBarShown() != shown) {
297 m_settings->setValue("camera/showToolBar", shown);
299 emit toolBarShownChanged();
303 bool Settings::isVideoMuted() const {
304 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
307 void Settings::setVideoMuted(bool muted) {
308 if (isVideoMuted() != muted) {
309 m_settings->setValue("video/mute", muted);
310 emit videoMutedChanged();
314 bool Settings::isGridEnabled() const {
315 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
318 void Settings::setGridEnabled(bool enabled) {
319 if (enabled != isGridEnabled()) {
320 m_settings->setValue("camera/gridEnabled", enabled);
321 emit gridEnabledChanged();
325 bool Settings::isFaceDetectionEnabled() const {
326 return m_settings->value("image/faceDetectionEnabled", DEFAULT_FACE_DETECTION_ENABLED).toBool();
329 void Settings::setFaceDetectionEnabled(bool enabled) {
330 if (isFaceDetectionEnabled() != enabled) {
331 m_settings->setValue("image/faceDetectionEnabled", enabled);
332 emit faceDetectionEnabledChanged();