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
9#include <QCoreApplication>
10#include <QDebug>
11
12ScreencastingRequest::ScreencastingRequest(QObject *parent)
13 : QObject(parent)
14{
15}
16
17ScreencastingRequest::~ScreencastingRequest() = default;
18
19quint32 ScreencastingRequest::nodeId() const
20{
21 return m_nodeId;
22}
23
24void ScreencastingRequest::resetUuid()
25{
26 setUuid(QString());
27}
28
29void ScreencastingRequest::setUuid(const QString &uuid)
30{
31 if (m_uuid == uuid) {
32 return;
33 }
34
35 setStream(nullptr);
36 m_uuid = uuid;
37 Q_EMIT uuidChanged(uuid);
38
39 if (!m_uuid.isEmpty()) {
40 if (!m_screenCasting) {
41 m_screenCasting = std::make_unique<Screencasting>();
42 }
43 setStream(m_screenCasting->createWindowStream(m_uuid, Screencasting::pointer_hidden));
44 }
45}
46
47void ScreencastingRequest::resetOutputName()
48{
49 setOutputName(QString());
50}
51
52void ScreencastingRequest::setOutputName(const QString &outputName)
53{
54 if (m_outputName == outputName) {
55 return;
56 }
57
58 setStream(nullptr);
59 m_outputName = outputName;
60 Q_EMIT outputNameChanged(outputName);
61
62 if (!m_outputName.isEmpty()) {
63 if (!m_screenCasting) {
64 m_screenCasting = std::make_unique<Screencasting>();
65 }
66 setStream(m_screenCasting->createOutputStream(m_outputName, Screencasting::pointer_hidden));
67 }
68}
69
70void ScreencastingRequest::setStream(std::unique_ptr<ScreencastingStream> stream)
71{
72 if (stream) {
73 m_stream = std::move(stream);
74
75 connect(m_stream.get(), &ScreencastingStream::created, this, &ScreencastingRequest::setNodeid);
76 connect(m_stream.get(), &ScreencastingStream::closed, this, [this]() {
77 setNodeid(0);
78 });
79 connect(m_stream.get(), &ScreencastingStream::failed, this, [](const QString &error) {
80 qWarning() << "error creating screencast" << error;
81 });
82 } else {
83 m_stream.reset();
84 setNodeid(0);
85 }
86}
87
88void ScreencastingRequest::setNodeid(uint nodeId)
89{
90 if (nodeId != m_nodeId) {
91 m_nodeId = nodeId;
92 Q_EMIT nodeIdChanged(nodeId);
93 }
94}
95
97{
98 return m_uuid;
99}
100
102{
103 return m_outputName;
104}
QML_ELEMENTQString uuid
The unique identifier of the window we want to cast.
quint32 nodeId
The offered nodeId to give to a source.
QString outputName
The output name as define in Screen.name.
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.