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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "screencastingrequest.h"
#include "logging.h"
#include <QCoreApplication>
#include <QDebug>
#include <QPointer>
#include <functional>
struct ScreencastingRequestPrivate {
Screencasting *m_screenCasting = nullptr;
QPointer<ScreencastingStream> m_stream;
QString m_uuid;
QString m_outputName;
quint32 m_nodeId = 0;
};
ScreencastingRequest::ScreencastingRequest(QObject *parent)
: QObject(parent)
, d(new ScreencastingRequestPrivate)
{
}
ScreencastingRequest::~ScreencastingRequest() = default;
quint32 ScreencastingRequest::nodeId() const
{
return d->m_nodeId;
}
void ScreencastingRequest::setUuid(const QString &uuid)
{
if (d->m_uuid == uuid) {
return;
}
setNodeid(0);
d->m_uuid = uuid;
Q_EMIT uuidChanged(uuid);
if (!d->m_uuid.isEmpty()) {
if (!d->m_screenCasting) {
d->m_screenCasting = new Screencasting(this);
}
auto stream = d->m_screenCasting->createWindowStream(d->m_uuid, Screencasting::CursorMode::Hidden);
if (!stream) {
return;
}
adopt(stream);
}
}
void ScreencastingRequest::setOutputName(const QString &outputName)
{
if (d->m_outputName == outputName) {
return;
}
setNodeid(0);
d->m_outputName = outputName;
Q_EMIT outputNameChanged(outputName);
if (!d->m_outputName.isEmpty()) {
if (!d->m_screenCasting) {
d->m_screenCasting = new Screencasting(this);
}
auto stream = d->m_screenCasting->createOutputStream(d->m_outputName, Screencasting::CursorMode::Hidden);
if (!stream) {
return;
}
adopt(stream);
stream->setObjectName(d->m_outputName);
}
}
void ScreencastingRequest::adopt(ScreencastingStream *stream)
{
d->m_stream = stream;
connect(stream, &ScreencastingStream::created, this, &ScreencastingRequest::setNodeid);
connect(stream, &ScreencastingStream::failed, this, [](const QString &error) {
qWarning() << "error creating screencast" << error;
});
connect(stream, &ScreencastingStream::closed, this, [this, stream] {
if (stream->nodeId() == d->m_nodeId) {
setNodeid(0);
}
});
}
void ScreencastingRequest::setNodeid(uint nodeId)
{
if (nodeId != d->m_nodeId) {
d->m_nodeId = nodeId;
Q_EMIT nodeIdChanged(nodeId);
}
if (nodeId == 0 && d->m_stream) {
delete d->m_stream;
}
}
QString ScreencastingRequest::uuid() const
{
return d->m_uuid;
}
QString ScreencastingRequest::outputName() const
{
return d->m_outputName;
}
|