Added sync parameter to QtCamVideo::stopRecording()
[harmattan/cameraplus] / declarative / metadata.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 "metadata.h"
22 #include "camera.h"
23 #include <QDateTime>
24
25 MetaData::MetaData(QObject *parent) :
26   QObject(parent),
27   m_data(0),
28   m_cam(0),
29   m_longitude(0),
30   m_latitude(0),
31   m_elevation(0),
32   m_orientation(MetaData::Unknown),
33   m_captureDirection(0),
34   m_horizontalError(0),
35   m_longitudeValid(false),
36   m_latitudeValid(false),
37   m_elevationValid(false),
38   m_captureDirectionValid(false),
39   m_horizontalErrorValid(false),
40   m_dateTimeEnabled(true) {
41
42 }
43
44 MetaData::~MetaData() {
45   m_cam = 0;
46 }
47
48 Camera *MetaData::camera() const {
49   return m_cam;
50 }
51
52 void MetaData::setCamera(Camera *camera) {
53   if (m_cam) {
54     QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
55   }
56
57   m_cam = camera;
58
59   if (m_cam) {
60     QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
61   }
62
63   deviceChanged();
64
65   emit cameraChanged();
66 }
67
68 QString MetaData::manufacturer() const {
69   return m_manufacturer;
70 }
71
72 void MetaData::setManufacturer(const QString& manufacturer) {
73   if (m_manufacturer != manufacturer) {
74     m_manufacturer = manufacturer;
75     emit manufacturerChanged();
76   }
77 }
78
79 QString MetaData::model() const {
80   return m_model;
81 }
82
83 void MetaData::setModel(const QString& model) {
84   if (m_model != model) {
85     m_model = model;
86     emit modelChanged();
87   }
88 }
89
90 QString MetaData::country() const {
91   return m_country;
92 }
93
94 void MetaData::setCountry(const QString& country) {
95   if (m_country != country) {
96     m_country = country;
97     emit countryChanged();
98   }
99 }
100
101 QString MetaData::city() const {
102   return m_city;
103 }
104
105 void MetaData::setCity(const QString& city) {
106   if (m_city != city) {
107     m_city = city;
108     emit cityChanged();
109   }
110 }
111
112 QString MetaData::suburb() const {
113   return m_suburb;
114 }
115
116 void MetaData::setSuburb(const QString& suburb) {
117   if (m_suburb != suburb) {
118     m_suburb = suburb;
119     emit suburbChanged();
120   }
121 }
122
123 double MetaData::longitude() const {
124   return m_longitude;
125 }
126
127 void MetaData::setLongitude(double longitude) {
128   if (!qFuzzyCompare(m_longitude, longitude)) {
129     m_longitude = longitude;
130     emit longitudeChanged();
131   }
132 }
133
134 double MetaData::latitude() const {
135   return m_latitude;
136 }
137
138 void MetaData::setLatitude(double latitude) {
139   if (!qFuzzyCompare(m_latitude, latitude)) {
140     m_latitude = latitude;
141     emit latitudeChanged();
142   }
143 }
144
145 double MetaData::elevation() const {
146   return m_elevation;
147 }
148
149 void MetaData::setElevation(double elevation) {
150   if (!qFuzzyCompare(m_elevation, elevation)) {
151     m_elevation = elevation;
152     emit elevationChanged();
153   }
154 }
155
156 MetaData::Orientation MetaData::orientation() const {
157   return m_orientation;
158 }
159
160 void MetaData::setOrientation(const MetaData::Orientation& orientation) {
161   if (m_orientation != orientation) {
162     m_orientation = orientation;
163     emit orientationChanged();
164   }
165 }
166
167 QString MetaData::artist() const {
168   return m_artist;
169 }
170
171 void MetaData::setArtist(const QString& artist) {
172   // TODO: there is a limit for the number of bytes in the artist
173   if (m_artist != artist) {
174     m_artist = artist;
175     emit artistChanged();
176   }
177 }
178
179 int MetaData::captureDirection() const {
180   return m_captureDirection;
181 }
182
183 void MetaData::setCaptureDirection(int captureDirection) {
184   if (m_captureDirection != captureDirection) {
185     m_captureDirection = captureDirection;
186     emit captureDirectionChanged();
187   }
188 }
189
190 double MetaData::horizontalError() const {
191   return m_horizontalError;
192 }
193
194 void MetaData::setHorizontalError(double horizontalError) {
195   if (!qFuzzyCompare(m_horizontalError, horizontalError)) {
196     m_horizontalError = horizontalError;
197     emit horizontalErrorChanged();
198   }
199 }
200
201 void MetaData::setMetaData() {
202   if (!m_data) {
203     return;
204   }
205
206   m_data->reset();
207
208   if (!m_manufacturer.isEmpty()) {
209     m_data->setManufacturer(m_manufacturer);
210   }
211
212   if (!m_model.isEmpty()) {
213     m_data->setModel(m_model);
214   }
215
216   if (!m_country.isEmpty()) {
217     m_data->setCountry(m_country);
218   }
219
220   if (!m_city.isEmpty()) {
221     m_data->setCity(m_city);
222   }
223
224   if (!m_suburb.isEmpty()) {
225     m_data->setSuburb(m_suburb);
226   }
227
228   if (m_longitudeValid) {
229     m_data->setLongitude(m_longitude);
230   }
231
232   if (m_latitudeValid) {
233     m_data->setLatitude(m_latitude);
234   }
235
236   if (m_elevationValid) {
237     m_data->setElevation(m_elevation);
238   }
239
240   if (m_orientation != MetaData::Unknown) {
241     m_data->setOrientation((QtCamMetaData::Orientation)m_orientation);
242
243     // TODO:
244     //    qDebug() << m_orientation << m_captureDirection << m_captureDirectionValid;
245
246     if (m_captureDirectionValid) {
247       //      m_data->setCaptureDirection(m_captureDirection);
248     }
249   }
250
251   if (!m_artist.isEmpty()) {
252     m_data->setArtist(m_artist);
253   }
254
255   if (m_dateTimeEnabled) {
256     m_data->setDateTime(QDateTime::currentDateTime());
257   }
258
259   if (m_horizontalErrorValid) {
260     m_data->setHorizontalError(m_horizontalError);
261   }
262 }
263
264 void MetaData::deviceChanged() {
265   if (m_data) {
266     delete m_data; m_data = 0;
267   }
268
269   m_data = new QtCamMetaData(this);
270   m_data->setDevice(m_cam->device());
271 }
272
273 bool MetaData::isLongitudeValid() const {
274   return m_longitudeValid;
275 }
276
277 void MetaData::setLongitudeValid(bool valid) {
278   if (valid != m_longitudeValid) {
279     m_longitudeValid = valid;
280     emit longitudeValidChanged();
281   }
282 }
283
284 bool MetaData::isLatitudeValid() const {
285   return m_latitudeValid;
286 }
287
288 void MetaData::setLatitudeValid(bool valid) {
289   if (valid != m_latitudeValid) {
290     m_latitudeValid = valid;
291     emit latitudeValidChanged();
292   }
293 }
294
295 bool MetaData::isElevationValid() const {
296   return m_elevationValid;
297 }
298
299 void MetaData::setElevationValid(bool valid) {
300   if (valid != m_elevationValid) {
301     m_elevationValid = valid;
302     emit elevationValidChanged();
303   }
304 }
305
306 bool MetaData::isCaptureDirectionValid() const {
307   return m_captureDirectionValid;
308 }
309
310 void MetaData::setCaptureDirectionValid(bool valid) {
311   if (valid != m_captureDirectionValid) {
312     m_captureDirectionValid = valid;
313     emit captureDirectionValidChanged();
314   }
315 }
316
317 bool MetaData::isHorizontalErrorValid() const {
318   return m_horizontalErrorValid;
319 }
320
321 void MetaData::setHorizontalErrorValid(bool valid) {
322   if (valid != m_horizontalErrorValid) {
323     m_horizontalErrorValid = valid;
324     emit horizontalErrorValidChanged();
325   }
326 }
327
328 bool MetaData::isDateTimeEnabled() const {
329   return m_dateTimeEnabled;
330 }
331
332 void MetaData::setDateTimeEnabled(bool enabled) {
333   if (m_dateTimeEnabled != enabled) {
334     m_dateTimeEnabled = enabled;
335     emit dateTimeEnabledChanged();
336   }
337 }