07bb31f5f2624e0b462a1bb45d42ab2c2d2e4c50
[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   if (m_artist != artist) {
173     m_artist = artist;
174     emit artistChanged();
175   }
176 }
177
178 int MetaData::captureDirection() const {
179   return m_captureDirection;
180 }
181
182 void MetaData::setCaptureDirection(int captureDirection) {
183   if (m_captureDirection != captureDirection) {
184     m_captureDirection = captureDirection;
185     emit captureDirectionChanged();
186   }
187 }
188
189 double MetaData::horizontalError() const {
190   return m_horizontalError;
191 }
192
193 void MetaData::setHorizontalError(double horizontalError) {
194   if (!qFuzzyCompare(m_horizontalError, horizontalError)) {
195     m_horizontalError = horizontalError;
196     emit horizontalErrorChanged();
197   }
198 }
199
200 void MetaData::setMetaData() {
201   if (!m_data) {
202     return;
203   }
204
205   m_data->reset();
206
207   if (!m_manufacturer.isEmpty()) {
208     m_data->setManufacturer(m_manufacturer);
209   }
210
211   if (!m_model.isEmpty()) {
212     m_data->setModel(m_model);
213   }
214
215   if (!m_country.isEmpty()) {
216     m_data->setCountry(m_country);
217   }
218
219   if (!m_city.isEmpty()) {
220     m_data->setCity(m_city);
221   }
222
223   if (!m_suburb.isEmpty()) {
224     m_data->setSuburb(m_suburb);
225   }
226
227   if (m_longitudeValid) {
228     m_data->setLongitude(m_longitude);
229   }
230
231   if (m_latitudeValid) {
232     m_data->setLatitude(m_latitude);
233   }
234
235   if (m_elevationValid) {
236     m_data->setElevation(m_elevation);
237   }
238
239   if (m_orientation != MetaData::Unknown) {
240     m_data->setOrientation((QtCamMetaData::Orientation)m_orientation);
241
242     // TODO:
243     //    qDebug() << m_orientation << m_captureDirection << m_captureDirectionValid;
244
245     if (m_captureDirectionValid) {
246       //      m_data->setCaptureDirection(m_captureDirection);
247     }
248   }
249
250   if (!m_artist.isEmpty()) {
251     m_data->setArtist(m_artist);
252   }
253
254   if (m_dateTimeEnabled) {
255     m_data->setDateTime(QDateTime::currentDateTime());
256   }
257
258   if (m_horizontalErrorValid) {
259     m_data->setHorizontalError(m_horizontalError);
260   }
261 }
262
263 void MetaData::deviceChanged() {
264   if (m_data) {
265     delete m_data; m_data = 0;
266   }
267
268   m_data = new QtCamMetaData(this);
269   m_data->setDevice(m_cam->device());
270 }
271
272 bool MetaData::isLongitudeValid() const {
273   return m_longitudeValid;
274 }
275
276 void MetaData::setLongitudeValid(bool valid) {
277   if (valid != m_longitudeValid) {
278     m_longitudeValid = valid;
279     emit longitudeValidChanged();
280   }
281 }
282
283 bool MetaData::isLatitudeValid() const {
284   return m_latitudeValid;
285 }
286
287 void MetaData::setLatitudeValid(bool valid) {
288   if (valid != m_latitudeValid) {
289     m_latitudeValid = valid;
290     emit latitudeValidChanged();
291   }
292 }
293
294 bool MetaData::isElevationValid() const {
295   return m_elevationValid;
296 }
297
298 void MetaData::setElevationValid(bool valid) {
299   if (valid != m_elevationValid) {
300     m_elevationValid = valid;
301     emit elevationValidChanged();
302   }
303 }
304
305 bool MetaData::isCaptureDirectionValid() const {
306   return m_captureDirectionValid;
307 }
308
309 void MetaData::setCaptureDirectionValid(bool valid) {
310   if (valid != m_captureDirectionValid) {
311     m_captureDirectionValid = valid;
312     emit captureDirectionValidChanged();
313   }
314 }
315
316 bool MetaData::isHorizontalErrorValid() const {
317   return m_horizontalErrorValid;
318 }
319
320 void MetaData::setHorizontalErrorValid(bool valid) {
321   if (valid != m_horizontalErrorValid) {
322     m_horizontalErrorValid = valid;
323     emit horizontalErrorValidChanged();
324   }
325 }
326
327 bool MetaData::isDateTimeEnabled() const {
328   return m_dateTimeEnabled;
329 }
330
331 void MetaData::setDateTimeEnabled(bool enabled) {
332   if (m_dateTimeEnabled != enabled) {
333     m_dateTimeEnabled = enabled;
334     emit dateTimeEnabledChanged();
335   }
336 }