-
Notifications
You must be signed in to change notification settings - Fork 11
/
gphotoserviceplugin.cpp
58 lines (47 loc) · 1.54 KB
/
gphotoserviceplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <QDebug>
#include "gphotocontroller.h"
#include "gphotomediaservice.h"
#include "gphotoserviceplugin.h"
QMediaService* GPhotoServicePlugin::create(const QString &key)
{
if (key == QLatin1String(Q_MEDIASERVICE_CAMERA))
return new GPhotoMediaService(getController());
qWarning() << "GPhoto service plugin: unsupported key:" << key;
return nullptr;
}
void GPhotoServicePlugin::release(QMediaService *service)
{
delete service;
}
QByteArray GPhotoServicePlugin::defaultDevice(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
if (const auto &controller = getController().lock())
return controller->defaultCameraName();
}
return {};
}
QList<QByteArray> GPhotoServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
if (const auto &controller = getController().lock())
return controller->cameraNames();
}
return QList<QByteArray>();
}
QString GPhotoServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
{
return (service == Q_MEDIASERVICE_CAMERA) ? device : QString();
}
std::weak_ptr<GPhotoController> GPhotoServicePlugin::getController() const
{
if (!m_controller) {
auto controller = std::make_shared<GPhotoController>();
if (!controller->init()) {
qWarning() << "GPhoto service plugin: unable to initialize GPhotoController";
return {};
}
m_controller = std::move(controller);
}
return m_controller;
}