Implemented video resolution setting
[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 #define DEFAULT_IMAGE_RESOLUTION   "high"
38 #define DEFAULT_IMAGE_ASPECT_RATIO "16:9"
39 #define DEFAULT_VIDEO_RESOLUTION   "high"
40
41 Settings::Settings(QObject *parent) :
42   QObject(parent),
43   m_settings(new QSettings(PATH, QSettings::IniFormat, this)) {
44
45 }
46
47 Settings::~Settings() {
48   delete m_settings; m_settings = 0;
49 }
50
51 int Settings::mode() const {
52   return m_settings->value("camera/mode", DEFAULT_MODE).toInt();
53 }
54
55 void Settings::setMode(int mode) {
56   if (mode != Settings::mode()) {
57     m_settings->setValue("camera/mode", mode);
58
59     emit modeChanged();
60   }
61 }
62
63 QString Settings::creatorName() const {
64   return m_settings->value("camera/creatorName").toString();
65 }
66
67 void Settings::setCreatorName(const QString& name) {
68   if (name != creatorName()) {
69     m_settings->setValue("camera/creatorName", name);
70
71     emit creatorNameChanged();
72   }
73 }
74
75 int Settings::postCaptureTimeout() const {
76   return m_settings->value("camera/postCaptureTimeout", DEFAULT_TIMEOUT).toInt();
77 }
78
79 void Settings::setPostCaptureTimeout(int timeout) {
80   if (timeout != postCaptureTimeout()) {
81     m_settings->setValue("camera/postCaptureTimeout", timeout);
82
83     emit postCaptureTimeoutChanged();
84   }
85 }
86
87 bool Settings::useGps() const {
88   return m_settings->value("camera/useGps", DEFAULT_USE_GPS).toBool();
89 }
90
91 void Settings::setUseGps(bool enable) {
92   if (enable != useGps()) {
93     m_settings->setValue("camera/useGps", enable);
94
95     emit useGpsChanged();
96   }
97 }
98
99 bool Settings::useGeotags() const {
100   return m_settings->value("camera/useGeotags", DEFAULT_USE_GEOTAGS).toBool();
101 }
102
103 void Settings::setUseGeotags(bool enable) {
104   if (enable != useGeotags()) {
105     m_settings->setValue("camera/useGeotags", enable);
106
107     emit useGeotagsChanged();
108   }
109 }
110
111 int Settings::imageSceneMode() const {
112   return m_settings->value("image/sceneMode", DEFAULT_SCENE_MODE).toInt();
113 }
114
115 void Settings::setImageSceneMode(int mode) {
116   if (mode != imageSceneMode()) {
117     m_settings->setValue("image/sceneMode", mode);
118
119     emit imageSceneModeChanged();
120   }
121 }
122
123 int Settings::imageColorFilter() const {
124   return m_settings->value("image/colorFilter", DEFAULT_COLOR_FILTER).toInt();
125 }
126
127 void Settings::setImageColorFilter(int filter) {
128   if (filter != imageColorFilter()) {
129     m_settings->setValue("image/colorFilter", filter);
130
131     emit imageColorFilterChanged();
132   }
133 }
134
135 int Settings::imageWhiteBalance() const {
136   return m_settings->value("image/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
137 }
138
139 void Settings::setImageWhiteBalance(int wb) {
140   if (wb != imageWhiteBalance()) {
141     m_settings->setValue("image/whiteBalance", wb);
142
143     emit imageWhiteBalanceChanged();
144   }
145 }
146
147 qreal Settings::imageEvComp() const {
148   return m_settings->value("image/evComp", DEFAULT_EV_COMP).toReal();
149 }
150
151 void Settings::setImageEvComp(qreal ev) {
152   if (ev != imageEvComp()) {
153     m_settings->setValue("image/evComp", ev);
154
155     emit imageEvCompChanged();
156   }
157 }
158
159 int Settings::videoSceneMode() const {
160   return m_settings->value("video/sceneMode", DEFAULT_SCENE_MODE).toInt();
161 }
162
163 void Settings::setVideoSceneMode(int mode) {
164   if (mode != videoSceneMode()) {
165     m_settings->setValue("video/sceneMode", mode);
166
167     emit videoSceneModeChanged();
168   }
169 }
170
171 int Settings::videoColorFilter() const {
172   return m_settings->value("video/colorFilter", DEFAULT_COLOR_FILTER).toInt();
173 }
174
175 void Settings::setVideoColorFilter(int filter) {
176   if (filter != videoColorFilter()) {
177     m_settings->setValue("video/colorFilter", filter);
178
179     emit videoColorFilterChanged();
180   }
181 }
182
183 int Settings::videoWhiteBalance() const {
184   return m_settings->value("video/whiteBalance", DEFAULT_WHITE_BALANCE).toInt();
185 }
186
187 void Settings::setVideoWhiteBalance(int wb) {
188   if (wb != videoWhiteBalance()) {
189     m_settings->setValue("video/whiteBalance", wb);
190
191     emit videoWhiteBalanceChanged();
192   }
193 }
194
195 qreal Settings::videoEvComp() const {
196   return m_settings->value("video/evComp", DEFAULT_EV_COMP).toReal();
197 }
198
199 void Settings::setVideoEvComp(qreal ev) {
200   if (ev != videoEvComp()) {
201     m_settings->setValue("video/evComp", ev);
202
203     emit videoEvCompChanged();
204   }
205 }
206
207 int Settings::imageFlashMode() const {
208   return m_settings->value("image/flashMode", DEFAULT_FLASH_MODE).toInt();
209 }
210
211 void Settings::setImageFlashMode(int mode) {
212   if (mode != imageFlashMode()) {
213     m_settings->setValue("image/flashMode", mode);
214
215     emit imageFlashModeChanged();
216   }
217 }
218
219 int Settings::imageIso() const {
220   return m_settings->value("image/iso", DEFAULT_IMAGE_ISO).toInt();
221 }
222
223 void Settings::setImageIso(int iso) {
224   if (imageIso() != iso) {
225     m_settings->setValue("image/iso", iso);
226     emit imageIsoChanged();
227   }
228 }
229
230 QString Settings::imageAspectRatio() const {
231   return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
232 }
233
234 void Settings::setImageAspectRatio(const QString& aspectRatio) {
235   if (aspectRatio != imageAspectRatio()) {
236     m_settings->setValue("image/aspectRatio", aspectRatio);
237     emit imageAspectRatioChanged();
238   }
239 }
240
241 QString Settings::imageResolution() const {
242   return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
243 }
244
245 void Settings::setImageResolution(const QString& resolution) {
246   if (resolution != imageResolution()) {
247     m_settings->setValue("image/resolution", resolution);
248     emit imageResolutionChanged();
249   }
250 }
251
252 QString Settings::videoAspectRatio() const {
253   // This is not used for anything so we will return an empty string for now
254   // which will make the backend return all resolutions.
255
256   return QString();
257 }
258
259 void Settings::setVideoAspectRatio(const QString& aspectRatio) {
260   Q_UNUSED(aspectRatio);
261
262   // This is not used for anything so we will just ignore it.
263 }
264
265 QString Settings::videoResolution() const {
266   return m_settings->value("video/resolution", DEFAULT_VIDEO_RESOLUTION).toString();
267 }
268
269 void Settings::setVideoResolution(const QString& resolution) {
270   if (resolution != videoResolution()) {
271     m_settings->setValue("video/resolution", resolution);
272     emit videoResolutionChanged();
273   }
274 }