File indexing completed on 2024-04-28 05:27:35
0001 /* 0002 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "screencastingrequest.h" 0008 #include "logging.h" 0009 0010 #include <QCoreApplication> 0011 #include <QDebug> 0012 #include <QPointer> 0013 #include <functional> 0014 0015 struct ScreencastingRequestPrivate { 0016 QPointer<ScreencastingStream> m_stream; 0017 QString m_uuid; 0018 QString m_outputName; 0019 quint32 m_nodeId = 0; 0020 }; 0021 0022 ScreencastingRequest::ScreencastingRequest(QObject *parent) 0023 : QObject(parent) 0024 , d(new ScreencastingRequestPrivate) 0025 { 0026 } 0027 0028 ScreencastingRequest::~ScreencastingRequest() = default; 0029 0030 quint32 ScreencastingRequest::nodeId() const 0031 { 0032 return d->m_nodeId; 0033 } 0034 0035 void ScreencastingRequest::setUuid(const QString &uuid) 0036 { 0037 if (d->m_uuid == uuid) { 0038 return; 0039 } 0040 0041 d->m_stream->deleteLater(); 0042 setNodeid(0); 0043 0044 d->m_uuid = uuid; 0045 Q_EMIT uuidChanged(uuid); 0046 0047 if (!d->m_uuid.isEmpty()) { 0048 auto screencasting = new Screencasting(this); 0049 auto stream = screencasting->createWindowStream(d->m_uuid, Screencasting::CursorMode::Hidden); 0050 adopt(stream); 0051 } 0052 } 0053 0054 void ScreencastingRequest::setOutputName(const QString &outputName) 0055 { 0056 if (d->m_outputName == outputName) { 0057 return; 0058 } 0059 0060 setNodeid(0); 0061 d->m_outputName = outputName; 0062 Q_EMIT outputNameChanged(outputName); 0063 0064 if (!d->m_outputName.isEmpty()) { 0065 auto screencasting = new Screencasting(this); 0066 auto stream = screencasting->createOutputStream(d->m_outputName, Screencasting::CursorMode::Hidden); 0067 adopt(stream); 0068 stream->setObjectName(d->m_outputName); 0069 } 0070 } 0071 0072 void ScreencastingRequest::adopt(ScreencastingStream *stream) 0073 { 0074 connect(stream, &ScreencastingStream::created, this, &ScreencastingRequest::setNodeid); 0075 connect(stream, &ScreencastingStream::failed, this, [](const QString &error) { 0076 qWarning() << "error creating screencast" << error; 0077 }); 0078 connect(stream, &ScreencastingStream::closed, this, [this, stream] { 0079 if (stream->nodeId() == d->m_nodeId) { 0080 setNodeid(0); 0081 } 0082 }); 0083 } 0084 0085 void ScreencastingRequest::setNodeid(uint nodeId) 0086 { 0087 if (nodeId == d->m_nodeId) { 0088 return; 0089 } 0090 0091 d->m_nodeId = nodeId; 0092 Q_EMIT nodeIdChanged(nodeId); 0093 } 0094 0095 QString ScreencastingRequest::uuid() const 0096 { 0097 return d->m_uuid; 0098 } 0099 0100 QString ScreencastingRequest::outputName() const 0101 { 0102 return d->m_outputName; 0103 } 0104 0105 #include "moc_screencastingrequest.cpp"