Plasma-workspace

screencastingrequest.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "screencastingrequest.h"
8#include "logging.h"
9
10#include <QCoreApplication>
11#include <QDebug>
12#include <QPointer>
13#include <functional>
14
15struct ScreencastingRequestPrivate {
16 Screencasting *m_screenCasting = nullptr;
18 QString m_uuid;
19 QString m_outputName;
20 quint32 m_nodeId = 0;
21};
22
23ScreencastingRequest::ScreencastingRequest(QObject *parent)
24 : QObject(parent)
25 , d(new ScreencastingRequestPrivate)
26{
27}
28
29ScreencastingRequest::~ScreencastingRequest() = default;
30
31quint32 ScreencastingRequest::nodeId() const
32{
33 return d->m_nodeId;
34}
35
36void ScreencastingRequest::setUuid(const QString &uuid)
37{
38 if (d->m_uuid == uuid) {
39 return;
40 }
41
42 setNodeid(0);
43 d->m_uuid = uuid;
44 Q_EMIT uuidChanged(uuid);
45
46 if (!d->m_uuid.isEmpty()) {
47 if (!d->m_screenCasting) {
48 d->m_screenCasting = new Screencasting(this);
49 }
50 auto stream = d->m_screenCasting->createWindowStream(d->m_uuid, Screencasting::CursorMode::Hidden);
51 if (!stream) {
52 return;
53 }
54 adopt(stream);
55 }
56}
57
58void ScreencastingRequest::setOutputName(const QString &outputName)
59{
60 if (d->m_outputName == outputName) {
61 return;
62 }
63
64 setNodeid(0);
65 d->m_outputName = outputName;
66 Q_EMIT outputNameChanged(outputName);
67
68 if (!d->m_outputName.isEmpty()) {
69 if (!d->m_screenCasting) {
70 d->m_screenCasting = new Screencasting(this);
71 }
72 auto stream = d->m_screenCasting->createOutputStream(d->m_outputName, Screencasting::CursorMode::Hidden);
73 if (!stream) {
74 return;
75 }
76 adopt(stream);
77 stream->setObjectName(d->m_outputName);
78 }
79}
80
81void ScreencastingRequest::adopt(ScreencastingStream *stream)
82{
83 d->m_stream = stream;
84
85 connect(stream, &ScreencastingStream::created, this, &ScreencastingRequest::setNodeid);
86 connect(stream, &ScreencastingStream::failed, this, [](const QString &error) {
87 qWarning() << "error creating screencast" << error;
88 });
89 connect(stream, &ScreencastingStream::closed, this, [this, stream] {
90 if (stream->nodeId() == d->m_nodeId) {
91 setNodeid(0);
92 }
93 });
94}
95
96void ScreencastingRequest::setNodeid(uint nodeId)
97{
98 if (nodeId != d->m_nodeId) {
99 d->m_nodeId = nodeId;
100 Q_EMIT nodeIdChanged(nodeId);
101 }
102
103 if (nodeId == 0 && d->m_stream) {
104 delete d->m_stream;
105 }
106}
107
109{
110 return d->m_uuid;
111}
112
114{
115 return d->m_outputName;
116}
quint32 nodeId
The offered nodeId to give to a source.
QString outputName
The output name as define in Screen.name.
QString uuid
The unique identifier of the window we want to cast.
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.