Merge lp:qtubuntu-camera/staging into lp:qtubuntu-camera
- staging
- Merge into trunk
Proposed by
Florian Boucault
Status: | Merged |
---|---|
Approved by: | Florian Boucault |
Approved revision: | 185 |
Merged at revision: | 159 |
Proposed branch: | lp:qtubuntu-camera/staging |
Merge into: | lp:qtubuntu-camera |
Diff against target: |
631 lines (+341/-43) 14 files modified
src/aalcameracontrol.cpp (+13/-9) src/aalcamerainfocontrol.cpp (+33/-0) src/aalcamerainfocontrol.h (+32/-0) src/aalcameraservice.cpp (+17/-12) src/aalcameraservice.h (+3/-0) src/aalcameraserviceplugin.cpp (+71/-5) src/aalcameraserviceplugin.h (+5/-1) src/aalvideodeviceselectorcontrol.cpp (+4/-14) src/src.pro (+2/-0) unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro (+6/-2) unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp (+5/-0) unittests/stubs/qcamerainfo_stub.cpp (+81/-0) unittests/stubs/qcamerainfodata.cpp (+30/-0) unittests/stubs/qcamerainfodata.h (+39/-0) |
To merge this branch: | bzr merge lp:qtubuntu-camera/staging |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phablet Team | Pending | ||
Review via email: mp+288647@code.launchpad.net |
Commit message
New release:
- Make it possible to set camera's captureMode before the camera stack is loaded.
- Implement qtmultimedia APIs to query the system for available cameras, their orientation and facing and replace some hardcoded logic to calls to these APIs.
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/aalcameracontrol.cpp' |
2 | --- src/aalcameracontrol.cpp 2015-12-22 11:51:25 +0000 |
3 | +++ src/aalcameracontrol.cpp 2016-03-23 15:17:49 +0000 |
4 | @@ -48,6 +48,12 @@ |
5 | Q_EMIT error(QCamera::ServiceMissingError, QLatin1String("Unable to connect to camera")); |
6 | return; |
7 | } |
8 | + if (m_captureMode == QCamera::CaptureStillImage) { |
9 | + m_service->enablePhotoMode(); |
10 | + } else { |
11 | + m_service->enableVideoMode(); |
12 | + } |
13 | + Q_EMIT captureModeChanged(m_captureMode); |
14 | m_service->startPreview(); |
15 | } else if (state == QCamera::LoadedState) { |
16 | if (m_state == QCamera::UnloadedState) { |
17 | @@ -83,20 +89,18 @@ |
18 | if (m_captureMode == mode) |
19 | return; |
20 | |
21 | - if (m_service->androidControl() == 0) |
22 | - return; |
23 | - |
24 | if (m_service->isRecording()) |
25 | return; |
26 | |
27 | m_captureMode = mode; |
28 | - if (m_service->isCameraActive() && mode == QCamera::CaptureStillImage) { |
29 | - m_service->enablePhotoMode(); |
30 | - } else { |
31 | - m_service->enableVideoMode(); |
32 | + if (m_service->androidControl()) { |
33 | + if (mode == QCamera::CaptureStillImage) { |
34 | + m_service->enablePhotoMode(); |
35 | + } else { |
36 | + m_service->enableVideoMode(); |
37 | + } |
38 | + Q_EMIT captureModeChanged(mode); |
39 | } |
40 | - |
41 | - Q_EMIT captureModeChanged(mode); |
42 | } |
43 | |
44 | bool AalCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const |
45 | |
46 | === added file 'src/aalcamerainfocontrol.cpp' |
47 | --- src/aalcamerainfocontrol.cpp 1970-01-01 00:00:00 +0000 |
48 | +++ src/aalcamerainfocontrol.cpp 2016-03-23 15:17:49 +0000 |
49 | @@ -0,0 +1,33 @@ |
50 | +/* |
51 | + * Copyright (C) 2016 Canonical, Ltd. |
52 | + * |
53 | + * This program is free software; you can redistribute it and/or modify |
54 | + * it under the terms of the GNU Lesser General Public License as published by |
55 | + * the Free Software Foundation; version 3. |
56 | + * |
57 | + * This program is distributed in the hope that it will be useful, |
58 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
59 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
60 | + * GNU Lesser General Public License for more details. |
61 | + * |
62 | + * You should have received a copy of the GNU Lesser General Public License |
63 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
64 | + */ |
65 | + |
66 | +#include "aalcamerainfocontrol.h" |
67 | + |
68 | +#include <QCameraInfo> |
69 | + |
70 | +AalCameraInfoControl::AalCameraInfoControl(QObject *parent) : QCameraInfoControl(parent) |
71 | +{ |
72 | +} |
73 | + |
74 | +QCamera::Position AalCameraInfoControl::cameraPosition(const QString &deviceName) const |
75 | +{ |
76 | + return QCameraInfo(deviceName.toLatin1()).position(); |
77 | +} |
78 | + |
79 | +int AalCameraInfoControl::cameraOrientation(const QString &deviceName) const |
80 | +{ |
81 | + return QCameraInfo(deviceName.toLatin1()).orientation(); |
82 | +} |
83 | |
84 | === added file 'src/aalcamerainfocontrol.h' |
85 | --- src/aalcamerainfocontrol.h 1970-01-01 00:00:00 +0000 |
86 | +++ src/aalcamerainfocontrol.h 2016-03-23 15:17:49 +0000 |
87 | @@ -0,0 +1,32 @@ |
88 | +/* |
89 | + * Copyright (C) 2016 Canonical, Ltd. |
90 | + * |
91 | + * This program is free software; you can redistribute it and/or modify |
92 | + * it under the terms of the GNU Lesser General Public License as published by |
93 | + * the Free Software Foundation; version 3. |
94 | + * |
95 | + * This program is distributed in the hope that it will be useful, |
96 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
97 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
98 | + * GNU Lesser General Public License for more details. |
99 | + * |
100 | + * You should have received a copy of the GNU Lesser General Public License |
101 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
102 | + */ |
103 | + |
104 | +#ifndef AALCAMERAINFOCONTROL_H |
105 | +#define AALCAMERAINFOCONTROL_H |
106 | + |
107 | +#include <QCameraInfoControl> |
108 | + |
109 | +class AalCameraInfoControl : public QCameraInfoControl |
110 | +{ |
111 | + Q_OBJECT |
112 | +public: |
113 | + AalCameraInfoControl(QObject *parent = 0); |
114 | + |
115 | + QCamera::Position cameraPosition(const QString &deviceName) const; |
116 | + int cameraOrientation(const QString &deviceName) const; |
117 | +}; |
118 | + |
119 | +#endif // AALCAMERAINFOCONTROL_H |
120 | |
121 | === modified file 'src/aalcameraservice.cpp' |
122 | --- src/aalcameraservice.cpp 2016-01-12 12:04:31 +0000 |
123 | +++ src/aalcameraservice.cpp 2016-03-23 15:17:49 +0000 |
124 | @@ -27,6 +27,7 @@ |
125 | #include "aalvideoencodersettingscontrol.h" |
126 | #include "aalvideorenderercontrol.h" |
127 | #include "aalviewfindersettingscontrol.h" |
128 | +#include "aalcamerainfocontrol.h" |
129 | #include "storagemanager.h" |
130 | #include "aalcameraexposurecontrol.h" |
131 | |
132 | @@ -60,6 +61,7 @@ |
133 | m_videoOutput = new AalVideoRendererControl(this); |
134 | m_viewfinderControl = new AalViewfinderSettingsControl(this); |
135 | m_exposureControl = new AalCameraExposureControl(this); |
136 | + m_infoControl = new AalCameraInfoControl(this); |
137 | |
138 | QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance()); |
139 | m_previousApplicationState = application->applicationState(); |
140 | @@ -84,6 +86,7 @@ |
141 | delete m_videoOutput; |
142 | delete m_viewfinderControl; |
143 | delete m_exposureControl; |
144 | + delete m_infoControl; |
145 | if (m_androidControl) |
146 | android_camera_delete(m_androidControl); |
147 | delete m_storageManager; |
148 | @@ -130,6 +133,9 @@ |
149 | if (qstrcmp(name, QCameraExposureControl_iid) == 0) |
150 | return m_exposureControl; |
151 | |
152 | + if (qstrcmp(name, QCameraInfoControl_iid) == 0) |
153 | + return m_infoControl; |
154 | + |
155 | return 0; |
156 | } |
157 | |
158 | @@ -153,21 +159,18 @@ |
159 | if (m_androidControl) |
160 | return true; |
161 | |
162 | - CameraType device = BACK_FACING_CAMERA_TYPE; |
163 | - if (!isBackCameraUsed()) |
164 | - device = FRONT_FACING_CAMERA_TYPE; |
165 | - |
166 | m_androidListener = new CameraControlListener; |
167 | memset(m_androidListener, 0, sizeof(*m_androidListener)); |
168 | |
169 | - m_androidControl = android_camera_connect_to(device, m_androidListener); |
170 | - |
171 | - // fallback if there is only one camera |
172 | - if (!m_androidControl && m_deviceSelectControl->deviceCount() == 1) { |
173 | - if (device == BACK_FACING_CAMERA_TYPE) |
174 | + // if there is only one camera fallback directly to the ID of whatever device we have |
175 | + if (m_deviceSelectControl->deviceCount() == 1) { |
176 | + m_androidControl = android_camera_connect_by_id(m_deviceSelectControl->selectedDevice(), m_androidListener); |
177 | + } else { |
178 | + CameraType device = BACK_FACING_CAMERA_TYPE; |
179 | + if (!isBackCameraUsed()) { |
180 | device = FRONT_FACING_CAMERA_TYPE; |
181 | - else |
182 | - device = BACK_FACING_CAMERA_TYPE; |
183 | + } |
184 | + |
185 | m_androidControl = android_camera_connect_to(device, m_androidListener); |
186 | } |
187 | |
188 | @@ -232,7 +235,9 @@ |
189 | |
190 | bool AalCameraService::isBackCameraUsed() const |
191 | { |
192 | - return m_deviceSelectControl->selectedDevice() == 0; |
193 | + int deviceIndex = m_deviceSelectControl->selectedDevice(); |
194 | + QString deviceName = m_deviceSelectControl->deviceName(deviceIndex); |
195 | + return m_infoControl->cameraPosition(deviceName) == QCamera::BackFace; |
196 | } |
197 | |
198 | /*! |
199 | |
200 | === modified file 'src/aalcameraservice.h' |
201 | --- src/aalcameraservice.h 2015-12-16 11:22:04 +0000 |
202 | +++ src/aalcameraservice.h 2016-03-23 15:17:49 +0000 |
203 | @@ -34,6 +34,7 @@ |
204 | class AalVideoRendererControl; |
205 | class AalViewfinderSettingsControl; |
206 | class AalCameraExposureControl; |
207 | +class AalCameraInfoControl; |
208 | class QCameraControl; |
209 | |
210 | struct CameraControl; |
211 | @@ -64,6 +65,7 @@ |
212 | AalVideoRendererControl *videoOutputControl() const { return m_videoOutput; } |
213 | AalViewfinderSettingsControl *viewfinderControl() const { return m_viewfinderControl; } |
214 | AalCameraExposureControl *exposureControl() const { return m_exposureControl; } |
215 | + AalCameraInfoControl *infoControl() const { return m_infoControl; } |
216 | |
217 | CameraControl *androidControl(); |
218 | |
219 | @@ -110,6 +112,7 @@ |
220 | AalVideoRendererControl *m_videoOutput; |
221 | AalViewfinderSettingsControl *m_viewfinderControl; |
222 | AalCameraExposureControl *m_exposureControl; |
223 | + AalCameraInfoControl *m_infoControl; |
224 | |
225 | CameraControl *m_androidControl; |
226 | CameraControlListener *m_androidListener; |
227 | |
228 | === modified file 'src/aalcameraserviceplugin.cpp' |
229 | --- src/aalcameraserviceplugin.cpp 2013-03-12 16:17:37 +0000 |
230 | +++ src/aalcameraserviceplugin.cpp 2016-03-23 15:17:49 +0000 |
231 | @@ -21,6 +21,10 @@ |
232 | #include <QMetaType> |
233 | #include <qgl.h> |
234 | |
235 | +#include <hybris/camera/camera_compatibility_layer.h> |
236 | +#include <hybris/camera/camera_compatibility_layer_capabilities.h> |
237 | + |
238 | + |
239 | AalServicePlugin::AalServicePlugin() |
240 | { |
241 | } |
242 | @@ -42,13 +46,75 @@ |
243 | |
244 | QList<QByteArray> AalServicePlugin::devices(const QByteArray &service) const |
245 | { |
246 | - Q_UNUSED(service); |
247 | - return QList<QByteArray>(); |
248 | + QList<QByteArray> deviceList; |
249 | + |
250 | + if (QString::fromLatin1(service) != QLatin1String(Q_MEDIASERVICE_CAMERA)) { |
251 | + return deviceList; |
252 | + } |
253 | + |
254 | + // Devices are identified in android only by their index, so we do the same |
255 | + int cameras = android_camera_get_number_of_devices(); |
256 | + for (int deviceId = 0; deviceId < cameras; deviceId++) { |
257 | + QString camera("%1"); |
258 | + camera = camera.arg(deviceId); |
259 | + deviceList.append(camera.toLatin1()); |
260 | + } |
261 | + |
262 | + return deviceList; |
263 | } |
264 | |
265 | QString AalServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) |
266 | { |
267 | - Q_UNUSED(service); |
268 | - Q_UNUSED(device); |
269 | - return QString(); |
270 | + if (QString::fromLatin1(service) != QLatin1String(Q_MEDIASERVICE_CAMERA)) { |
271 | + return QString(); |
272 | + } |
273 | + |
274 | + // Android does not provice a descriptive identifier for devices, so we just |
275 | + // send back the index plus some useful human readable information about position. |
276 | + bool ok; |
277 | + int deviceID = device.toInt(&ok, 10); |
278 | + if (!ok || deviceID >= android_camera_get_number_of_devices()) { |
279 | + qWarning() << "Requested description for invalid device ID:" << device; |
280 | + return QString(); |
281 | + } else { |
282 | + QCamera::Position position = cameraPosition(device); |
283 | + return QString("Camera %1%2").arg(QLatin1String(device)) |
284 | + .arg(position == QCamera::FrontFace ? " Front facing" : |
285 | + (position == QCamera::BackFace ? " Back facing" : "")); |
286 | + } |
287 | +} |
288 | + |
289 | +int AalServicePlugin::cameraOrientation(const QByteArray & device) const |
290 | +{ |
291 | + int facing; |
292 | + int orientation; |
293 | + |
294 | + bool ok; |
295 | + int deviceID = device.toInt(&ok, 10); |
296 | + if (!ok) { |
297 | + return 0; |
298 | + } |
299 | + |
300 | + int result = android_camera_get_device_info(deviceID, &facing, &orientation); |
301 | + return (result != 0) ? 0 : orientation; |
302 | +} |
303 | + |
304 | +QCamera::Position AalServicePlugin::cameraPosition(const QByteArray & device) const |
305 | +{ |
306 | + int facing; |
307 | + int orientation; |
308 | + |
309 | + bool ok; |
310 | + int deviceID = device.toInt(&ok, 10); |
311 | + if (!ok) { |
312 | + return QCamera::UnspecifiedPosition; |
313 | + } |
314 | + |
315 | + int result = android_camera_get_device_info(deviceID, &facing, &orientation); |
316 | + if (result != 0) { |
317 | + return QCamera::UnspecifiedPosition; |
318 | + } else { |
319 | + return facing == BACK_FACING_CAMERA_TYPE ? QCamera::BackFace : |
320 | + QCamera::FrontFace; |
321 | + } |
322 | } |
323 | |
324 | === modified file 'src/aalcameraserviceplugin.h' |
325 | --- src/aalcameraserviceplugin.h 2013-02-11 15:56:21 +0000 |
326 | +++ src/aalcameraserviceplugin.h 2016-03-23 15:17:49 +0000 |
327 | @@ -20,10 +20,12 @@ |
328 | #include <QMediaServiceProviderPlugin> |
329 | |
330 | class AalServicePlugin : public QMediaServiceProviderPlugin, |
331 | - public QMediaServiceSupportedDevicesInterface |
332 | + public QMediaServiceSupportedDevicesInterface, |
333 | + public QMediaServiceCameraInfoInterface |
334 | { |
335 | Q_OBJECT |
336 | Q_INTERFACES(QMediaServiceSupportedDevicesInterface) |
337 | + Q_INTERFACES(QMediaServiceCameraInfoInterface) |
338 | Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "aalcamera.json") |
339 | |
340 | public: |
341 | @@ -34,6 +36,8 @@ |
342 | |
343 | QList<QByteArray> devices(const QByteArray &service) const; |
344 | QString deviceDescription(const QByteArray &service, const QByteArray &device); |
345 | + int cameraOrientation(const QByteArray & device) const; |
346 | + QCamera::Position cameraPosition(const QByteArray & device) const; |
347 | }; |
348 | |
349 | #endif |
350 | |
351 | === modified file 'src/aalvideodeviceselectorcontrol.cpp' |
352 | --- src/aalvideodeviceselectorcontrol.cpp 2015-12-07 15:16:51 +0000 |
353 | +++ src/aalvideodeviceselectorcontrol.cpp 2016-03-23 15:17:49 +0000 |
354 | @@ -23,6 +23,7 @@ |
355 | |
356 | #include <QDebug> |
357 | #include <QtMultimedia/QCamera> |
358 | +#include <QtMultimedia/QCameraInfo> |
359 | |
360 | #include <hybris/camera/camera_compatibility_layer_capabilities.h> |
361 | |
362 | @@ -41,28 +42,17 @@ |
363 | |
364 | int AalVideoDeviceSelectorControl::deviceCount() const |
365 | { |
366 | - if (m_numberOfCameras < 0) |
367 | - m_numberOfCameras = android_camera_get_number_of_devices(); |
368 | - |
369 | - return m_numberOfCameras; |
370 | + return QCameraInfo::availableCameras().count(); |
371 | } |
372 | |
373 | QString AalVideoDeviceSelectorControl::deviceDescription(int index) const |
374 | { |
375 | - switch (index) { |
376 | - case 0: return QLatin1String("Back camera"); |
377 | - case 1: return QLatin1String("Front camera"); |
378 | - default: return QLatin1String(""); |
379 | - } |
380 | + return QCameraInfo::availableCameras().value(index).description(); |
381 | } |
382 | |
383 | QString AalVideoDeviceSelectorControl::deviceName(int index) const |
384 | { |
385 | - switch (index) { |
386 | - case 0: return QLatin1String("Back"); |
387 | - case 1: return QLatin1String("Front"); |
388 | - default: return QLatin1String(""); |
389 | - } |
390 | + return QCameraInfo::availableCameras().value(index).deviceName(); |
391 | } |
392 | |
393 | int AalVideoDeviceSelectorControl::selectedDevice() const |
394 | |
395 | === modified file 'src/src.pro' |
396 | --- src/src.pro 2015-11-12 10:32:24 +0000 |
397 | +++ src/src.pro 2016-03-23 15:17:49 +0000 |
398 | @@ -29,6 +29,7 @@ |
399 | aalvideoencodersettingscontrol.h \ |
400 | aalvideorenderercontrol.h \ |
401 | aalviewfindersettingscontrol.h \ |
402 | + aalcamerainfocontrol.h \ |
403 | audiocapture.h \ |
404 | aalcameraexposurecontrol.h \ |
405 | storagemanager.h |
406 | @@ -48,6 +49,7 @@ |
407 | aalvideoencodersettingscontrol.cpp \ |
408 | aalvideorenderercontrol.cpp \ |
409 | aalviewfindersettingscontrol.cpp \ |
410 | + aalcamerainfocontrol.cpp \ |
411 | audiocapture.cpp \ |
412 | aalcameraexposurecontrol.cpp \ |
413 | storagemanager.cpp |
414 | |
415 | === modified file 'unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro' |
416 | --- unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro 2015-12-18 15:16:06 +0000 |
417 | +++ unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro 2016-03-23 15:17:49 +0000 |
418 | @@ -7,11 +7,13 @@ |
419 | LIBS += -L../mocks/aal -laal |
420 | INCLUDEPATH += ../../src |
421 | INCLUDEPATH += ../mocks/aal |
422 | +INCLUDEPATH += ../stubs/ |
423 | |
424 | HEADERS += ../../src/aalvideodeviceselectorcontrol.h \ |
425 | ../../src/aalcameracontrol.h \ |
426 | ../../src/aalcameraservice.h \ |
427 | - ../../src/aalvideoencodersettingscontrol.h |
428 | + ../../src/aalvideoencodersettingscontrol.h \ |
429 | + ../stubs/qcamerainfodata.h |
430 | |
431 | SOURCES += tst_aalvideodeviceselectorcontrol.cpp \ |
432 | ../../src/aalvideodeviceselectorcontrol.cpp \ |
433 | @@ -19,7 +21,9 @@ |
434 | aalimageencodercontrol.cpp \ |
435 | aalviewfindersettingscontrol.cpp \ |
436 | ../stubs/aalcameracontrol_stub.cpp \ |
437 | - ../stubs/aalvideoencodersettingscontrol_stub.cpp |
438 | + ../stubs/aalvideoencodersettingscontrol_stub.cpp \ |
439 | + ../stubs/qcamerainfo_stub.cpp \ |
440 | + ../stubs/qcamerainfodata.cpp |
441 | |
442 | check.depends = $${TARGET} |
443 | check.commands = ./$${TARGET} |
444 | |
445 | === modified file 'unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp' |
446 | --- unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp 2014-07-31 16:44:03 +0000 |
447 | +++ unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp 2016-03-23 15:17:49 +0000 |
448 | @@ -21,6 +21,7 @@ |
449 | |
450 | #define private public |
451 | #include "aalvideodeviceselectorcontrol.h" |
452 | +#include "qcamerainfodata.h" |
453 | |
454 | class tst_AalVideoDeviceSelectorControl : public QObject |
455 | { |
456 | @@ -53,6 +54,10 @@ |
457 | QSignalSpy spy(m_selectControl, SIGNAL(selectedDeviceChanged(int))); |
458 | QSignalSpy spy2(m_selectControl, SIGNAL(selectedDeviceChanged(QString))); |
459 | |
460 | + QCameraInfoData::availableDevices.clear(); |
461 | + QCameraInfoData::availableDevices.append(CameraInfo("0", "Camera 0")); |
462 | + QCameraInfoData::availableDevices.append(CameraInfo("1", "Camera 1")); |
463 | + |
464 | m_selectControl->setSelectedDevice(1); |
465 | |
466 | QCOMPARE(m_selectControl->selectedDevice(), 1); |
467 | |
468 | === added file 'unittests/stubs/qcamerainfo_stub.cpp' |
469 | --- unittests/stubs/qcamerainfo_stub.cpp 1970-01-01 00:00:00 +0000 |
470 | +++ unittests/stubs/qcamerainfo_stub.cpp 2016-03-23 15:17:49 +0000 |
471 | @@ -0,0 +1,81 @@ |
472 | +/* |
473 | + * Copyright (C) 2016 Canonical, Ltd. |
474 | + * |
475 | + * This program is free software; you can redistribute it and/or modify |
476 | + * it under the terms of the GNU Lesser General Public License as published by |
477 | + * the Free Software Foundation; version 3. |
478 | + * |
479 | + * This program is distributed in the hope that it will be useful, |
480 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
481 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
482 | + * GNU Lesser General Public License for more details. |
483 | + * |
484 | + * You should have received a copy of the GNU Lesser General Public License |
485 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
486 | + */ |
487 | + |
488 | +#include <QtMultimedia/QCameraInfo> |
489 | +#include "qcamerainfodata.h" |
490 | + |
491 | +class QCameraInfoPrivate { |
492 | +public: |
493 | + QString deviceID; |
494 | + QString description; |
495 | + int orientation; |
496 | + QCamera::Position position; |
497 | +}; |
498 | + |
499 | +QCameraInfo::QCameraInfo(const QByteArray &name) : d(new QCameraInfoPrivate()) |
500 | +{ |
501 | + QStringList info = QString::fromLatin1(name).split('|'); |
502 | + d->deviceID = info.at(0); |
503 | + d->description = info.at(1); |
504 | + d->orientation = info.at(2).toInt(); |
505 | + d->position = QCamera::Position(info.at(3).toInt()); |
506 | +} |
507 | + |
508 | +QCameraInfo::QCameraInfo(const QCamera &camera) : d(new QCameraInfoPrivate()) { |
509 | + Q_UNUSED(camera); |
510 | +} |
511 | + |
512 | +QCameraInfo::QCameraInfo(const QCameraInfo& other) : d(new QCameraInfoPrivate()) |
513 | +{ |
514 | + d->deviceID = other.deviceName(); |
515 | + d->description = other.description(); |
516 | + d->orientation = other.orientation(); |
517 | + d->position = other.position(); |
518 | +} |
519 | +QCameraInfo::~QCameraInfo() { } |
520 | + |
521 | +QCameraInfo& QCameraInfo::operator=(const QCameraInfo& other) { |
522 | + if (this != &other) { |
523 | + d->deviceID = other.deviceName(); |
524 | + d->description = other.description(); |
525 | + d->orientation = other.orientation(); |
526 | + d->position = other.position(); |
527 | + } |
528 | + return *this; |
529 | +} |
530 | +bool QCameraInfo::operator==(const QCameraInfo &other) const { Q_UNUSED(other); return false; } |
531 | + |
532 | +bool QCameraInfo::isNull() const { return false; } |
533 | + |
534 | +QString QCameraInfo::deviceName() const { return d->deviceID; } |
535 | +QString QCameraInfo::description() const { return d->description; } |
536 | +QCamera::Position QCameraInfo::position() const { return d->position; } |
537 | +int QCameraInfo::orientation() const { return d->orientation; } |
538 | + |
539 | +QCameraInfo QCameraInfo::defaultCamera() { return QCameraInfo(); } |
540 | +QList<QCameraInfo> QCameraInfo::availableCameras(QCamera::Position position) { |
541 | + Q_UNUSED(position); |
542 | + |
543 | + QList<QCameraInfo> list; |
544 | + Q_FOREACH(CameraInfo info, QCameraInfoData::availableDevices) { |
545 | + QString infoString = QString("%1|%2|%3|%4").arg(info.deviceID).arg(info.description) |
546 | + .arg(info.orientation).arg(info.position); |
547 | + QCameraInfo camera(infoString.toLatin1()); |
548 | + list.append(camera); |
549 | + } |
550 | + |
551 | + return list; |
552 | +} |
553 | |
554 | === added file 'unittests/stubs/qcamerainfodata.cpp' |
555 | --- unittests/stubs/qcamerainfodata.cpp 1970-01-01 00:00:00 +0000 |
556 | +++ unittests/stubs/qcamerainfodata.cpp 2016-03-23 15:17:49 +0000 |
557 | @@ -0,0 +1,30 @@ |
558 | +/* |
559 | + * Copyright (C) 2016 Canonical, Ltd. |
560 | + * |
561 | + * This program is free software; you can redistribute it and/or modify |
562 | + * it under the terms of the GNU Lesser General Public License as published by |
563 | + * the Free Software Foundation; version 3. |
564 | + * |
565 | + * This program is distributed in the hope that it will be useful, |
566 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
567 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
568 | + * GNU Lesser General Public License for more details. |
569 | + * |
570 | + * You should have received a copy of the GNU Lesser General Public License |
571 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
572 | + */ |
573 | + |
574 | +#include "qcamerainfodata.h" |
575 | + |
576 | +QList<CameraInfo> QCameraInfoData::availableDevices = QList<CameraInfo>(); |
577 | + |
578 | +CameraInfo::CameraInfo(QString deviceID, QString description, |
579 | + int orientation, QCamera::Position position) : |
580 | + deviceID(deviceID), |
581 | + description(description), |
582 | + orientation(orientation), |
583 | + position(position) |
584 | +{ |
585 | +} |
586 | + |
587 | + |
588 | |
589 | === added file 'unittests/stubs/qcamerainfodata.h' |
590 | --- unittests/stubs/qcamerainfodata.h 1970-01-01 00:00:00 +0000 |
591 | +++ unittests/stubs/qcamerainfodata.h 2016-03-23 15:17:49 +0000 |
592 | @@ -0,0 +1,39 @@ |
593 | +/* |
594 | + * Copyright (C) 2016 Canonical, Ltd. |
595 | + * |
596 | + * This program is free software; you can redistribute it and/or modify |
597 | + * it under the terms of the GNU Lesser General Public License as published by |
598 | + * the Free Software Foundation; version 3. |
599 | + * |
600 | + * This program is distributed in the hope that it will be useful, |
601 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
602 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
603 | + * GNU Lesser General Public License for more details. |
604 | + * |
605 | + * You should have received a copy of the GNU Lesser General Public License |
606 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
607 | + */ |
608 | + |
609 | +#ifndef QCAMERAINFODATA_H |
610 | +#define QCAMERAINFODATA_H |
611 | + |
612 | +#include <QCamera> |
613 | + |
614 | +class CameraInfo { |
615 | +public: |
616 | + CameraInfo(QString deviceID = QString(), QString description = QString(), |
617 | + int orientation = 0, QCamera::Position position = QCamera::UnspecifiedPosition); |
618 | + |
619 | + QString deviceID; |
620 | + QString description; |
621 | + int orientation; |
622 | + QCamera::Position position; |
623 | +}; |
624 | + |
625 | +class QCameraInfoData |
626 | +{ |
627 | +public: |
628 | + static QList<CameraInfo> availableDevices; |
629 | +}; |
630 | + |
631 | +#endif // QCAMERAINFODATA_H |