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
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 bool Settings::useGps() const {
80 return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
83 void Settings::setUseGps(bool enable) {
84 if (enable != useGps()) {
85 m_settings->setValue("camera/useGps", enable);
91 bool Settings::useGeotags() const {
92 return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
95 void Settings::setUseGeotags(bool enable) {
96 if (enable != useGeotags()) {
97 m_settings->setValue("camera/useGeotags", enable);
99 emit useGeotagsChanged();
103 int Settings::imageSceneMode() const {
104 return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
107 void Settings::setImageSceneMode(int mode) {
108 if (mode != imageSceneMode()) {
109 m_settings->setValue("image/sceneMode", mode);
112 emit imageSceneModeChanged();
115 int Settings::imageColorFilter() const {
116 return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
119 void Settings::setImageColorFilter(int filter) {
120 if (filter != imageColorFilter()) {
121 m_settings->setValue("image/colorFilter", filter);
123 emit imageColorFilterChanged();
127 int Settings::imageWhiteBalance() const {
128 return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
131 void Settings::setImageWhiteBalance(int wb) {
132 if (wb != imageWhiteBalance()) {
133 m_settings->setValue("image/whiteBalance", wb);
135 emit imageWhiteBalanceChanged();
139 qreal Settings::imageEvComp() const {
140 return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
143 void Settings::setImageEvComp(qreal ev) {
144 if (!qFuzzyCompare(ev, imageEvComp())) {
145 m_settings->setValue("image/evComp", ev);
147 emit imageEvCompChanged();
151 int Settings::videoSceneMode() const {
152 return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
155 void Settings::setVideoSceneMode(int mode) {
156 if (mode != videoSceneMode()) {
157 m_settings->setValue("video/sceneMode", mode);
160 emit videoSceneModeChanged();
163 int Settings::videoColorFilter() const {
164 return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
167 void Settings::setVideoColorFilter(int filter) {
168 if (filter != videoColorFilter()) {
169 m_settings->setValue("video/colorFilter", filter);
171 emit videoColorFilterChanged();
175 int Settings::videoWhiteBalance() const {
176 return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
179 void Settings::setVideoWhiteBalance(int wb) {
180 if (wb != videoWhiteBalance()) {
181 m_settings->setValue("video/whiteBalance", wb);
183 emit videoWhiteBalanceChanged();
187 qreal Settings::videoEvComp() const {
188 return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
191 void Settings::setVideoEvComp(qreal ev) {
192 if (!qFuzzyCompare(ev, videoEvComp())) {
193 m_settings->setValue("video/evComp", ev);
195 emit videoEvCompChanged();
199 int Settings::imageFlashMode() const {
200 return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
203 void Settings::setImageFlashMode(int mode) {
204 if (mode != imageFlashMode()) {
205 m_settings->setValue("image/flashMode", mode);
207 emit imageFlashModeChanged();
211 int Settings::imageIso() const {
212 return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
215 void Settings::setImageIso(int iso) {
216 if (imageIso() != iso) {
217 m_settings->setValue("image/iso", iso);
218 emit imageIsoChanged();
222 QString Settings::imageAspectRatio() const {
223 return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
226 void Settings::setImageAspectRatio(const QString& aspectRatio) {
227 if (aspectRatio != imageAspectRatio()) {
228 m_settings->setValue("image/aspectRatio", aspectRatio);
229 emit imageAspectRatioChanged();
233 QString Settings::imageResolution() const {
234 return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
237 void Settings::setImageResolution(const QString& resolution) {
238 if (resolution != imageResolution()) {
239 m_settings->setValue("image/resolution", resolution);
240 emit imageResolutionChanged();
244 QString Settings::videoAspectRatio() const {
245 // This is not used for anything so we will return an empty string for now
246 // which will make the backend return all resolutions.
251 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
252 Q_UNUSED(aspectRatio);
254 // This is not used for anything so we will just ignore it.
257 QString Settings::videoResolution() const {
258 return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
261 void Settings::setVideoResolution(const QString& resolution) {
262 if (resolution != videoResolution()) {
263 m_settings->setValue("video/resolution", resolution);
264 emit videoResolutionChanged();
268 bool Settings::isSoundEnabled() const {
269 return m_settings->value("camera/soundEnabled", DEFAULT_SOUND_ENABLED).toBool();
272 void Settings::setSoundEnabled(bool enabled) {
273 if (isSoundEnabled() != enabled) {
274 m_settings->setValue("camera/soundEnabled", enabled);
275 emit soundEnabledChanged();
279 bool Settings::isVideoTorchOn() const {
280 return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool();
283 void Settings::setVideoTorchOn(bool on) {
284 if (isVideoTorchOn() != on) {
285 m_settings->setValue("video/torchOn", on);
286 emit videoTorchOnChanged();
290 bool Settings::isToolBarShown() const {
291 return m_settings->value("camera/showToolBar", DEFAULT_SHOW_TOOL_BAR).toBool();
294 void Settings::setToolBarShown(bool shown) {
295 if (isToolBarShown() != shown) {
296 m_settings->setValue("camera/showToolBar", shown);
298 emit toolBarShownChanged();
302 bool Settings::isVideoMuted() const {
303 return m_settings->value("video/mute", DEFAULT_VIDEO_MUTE).toBool();
306 void Settings::setVideoMuted(bool muted) {
307 if (isVideoMuted() != muted) {
308 m_settings->setValue("video/mute", muted);
309 emit videoMutedChanged();
313 bool Settings::isGridEnabled() const {
314 return m_settings->value("camera/gridEnabled", DEFAULT_GRID_ENABLED).toBool();
317 void Settings::setGridEnabled(bool enabled) {
318 if (enabled != isGridEnabled()) {
319 m_settings->setValue("camera/gridEnabled", enabled);
320 emit gridEnabledChanged();