Added copyright headers and COPYING file.
[harmattan/cameraplus] / src / settings.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "settings.h"
22 #include <QSettings>
23 #include <QDir>
24
25 #define PATH QString("%1%2.config%2/cameraplus.conf").arg(QDir::homePath()).arg(QDir::separator())
26
27 #define DEFAULT_MODE          0
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
38 Settings::Settings(QObject *parent) :
39   QObject(parent),
40   m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
41
42 }
43
44 Settings::~Settings() {
45   delete m_settings; m_settings = 0;
46 }
47
48 int Settings::mode() const {
49   return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
50 }
51
52 void Settings::setMode(int mode) {
53   if (mode != Settings::mode()) {
54     m_settings->setValue("camera/mode", mode);
55
56     emit modeChanged();
57   }
58 }
59
60 QString Settings::creatorName() const {
61   return m_settings->value("camera/creatorName").toString();
62 }
63
64 void Settings::setCreatorName(const QString& name) {
65   if (name != creatorName()) {
66     m_settings->setValue("camera/creatorName", name);
67
68     emit creatorNameChanged();
69   }
70 }
71
72 int Settings::postCaptureTimeout() const {
73   return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
74 }
75
76 void Settings::setPostCaptureTimeout(int timeout) {
77   if (timeout != postCaptureTimeout()) {
78     m_settings->setValue("camera/postCaptureTimeout", timeout);
79
80     emit postCaptureTimeoutChanged();
81   }
82 }
83
84 bool Settings::useGps() const {
85   return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
86 }
87
88 void Settings::setUseGps(bool enable) {
89   if (enable != useGps()) {
90     m_settings->setValue("camera/useGps", enable);
91
92     emit useGpsChanged();
93   }
94 }
95
96 bool Settings::useGeotags() const {
97   return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
98 }
99
100 void Settings::setUseGeotags(bool enable) {
101   if (enable != useGeotags()) {
102     m_settings->setValue("camera/useGeotags", enable);
103
104     emit useGeotagsChanged();
105   }
106 }
107
108 int Settings::imageSceneMode() const {
109   return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
110 }
111
112 void Settings::setImageSceneMode(int mode) {
113   if (mode != imageSceneMode()) {
114     m_settings->setValue("image/sceneMode", mode);
115
116     emit imageSceneModeChanged();
117   }
118 }
119
120 int Settings::imageColorFilter() const {
121   return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
122 }
123
124 void Settings::setImageColorFilter(int filter) {
125   if (filter != imageColorFilter()) {
126     m_settings->setValue("image/colorFilter", filter);
127
128     emit imageColorFilterChanged();
129   }
130 }
131
132 int Settings::imageWhiteBalance() const {
133   return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
134 }
135
136 void Settings::setImageWhiteBalance(int wb) {
137   if (wb != imageWhiteBalance()) {
138     m_settings->setValue("image/whiteBalance", wb);
139
140     emit imageWhiteBalanceChanged();
141   }
142 }
143
144 qreal Settings::imageEvComp() const {
145   return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
146 }
147
148 void Settings::setImageEvComp(qreal ev) {
149   if (ev != imageEvComp()) {
150     m_settings->setValue("image/evComp", ev);
151
152     emit imageEvCompChanged();
153   }
154 }
155
156 int Settings::videoSceneMode() const {
157   return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
158 }
159
160 void Settings::setVideoSceneMode(int mode) {
161   if (mode != videoSceneMode()) {
162     m_settings->setValue("video/sceneMode", mode);
163
164     emit videoSceneModeChanged();
165   }
166 }
167
168 int Settings::videoColorFilter() const {
169   return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
170 }
171
172 void Settings::setVideoColorFilter(int filter) {
173   if (filter != videoColorFilter()) {
174     m_settings->setValue("video/colorFilter", filter);
175
176     emit videoColorFilterChanged();
177   }
178 }
179
180 int Settings::videoWhiteBalance() const {
181   return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
182 }
183
184 void Settings::setVideoWhiteBalance(int wb) {
185   if (wb != videoWhiteBalance()) {
186     m_settings->setValue("video/whiteBalance", wb);
187
188     emit videoWhiteBalanceChanged();
189   }
190 }
191
192 qreal Settings::videoEvComp() const {
193   return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
194 }
195
196 void Settings::setVideoEvComp(qreal ev) {
197   if (ev != videoEvComp()) {
198     m_settings->setValue("video/evComp", ev);
199
200     emit videoEvCompChanged();
201   }
202 }
203
204 int Settings::imageFlashMode() const {
205   return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
206 }
207
208 void Settings::setImageFlashMode(int mode) {
209   if (mode != imageFlashMode()) {
210     m_settings->setValue("image/flashMode", mode);
211
212     emit imageFlashModeChanged();
213   }
214 }
215
216 int Settings::imageIso() const {
217   return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
218 }
219
220 void Settings::setImageIso(int iso) {
221   if (imageIso() != iso) {
222     m_settings->setValue("image/iso", iso);
223     emit imageIsoChanged();
224   }
225 }