PulseAudio Qt Bindings

context.h
1/*
2 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef CONTEXT_H
8#define CONTEXT_H
9
10#include "pulseaudioqt_export.h"
11#include <QObject>
12
13struct pa_context;
14
15/**
16 * The primary namespace of PulseAudioQt.
17 */
18namespace PulseAudioQt
19{
20class Card;
21class Client;
22class Sink;
23class SinkInput;
24class Source;
25class SourceOutput;
26class StreamRestore;
27class Module;
28class Server;
29
30/**
31 * The normal volume (100%, 0 dB). Equivalent to PA_VOLUME_NORM.
32 */
33PULSEAUDIOQT_EXPORT qint64 normalVolume();
34/**
35 * The minimum volume (0%). Equivalent to PA_VOLUME_MUTED.
36 */
37PULSEAUDIOQT_EXPORT qint64 minimumVolume();
38/**
39 * The maximum volume PulseAudio can store. Equivalent to PA_VOLUME_MAX.
40 * \warning For UI elements like volume sliders use maximumUIVolume instead.
41 */
42PULSEAUDIOQT_EXPORT qint64 maximumVolume();
43
44/**
45 * The maximum volume suitable to display in a UI. Equivalent to PA_VOLUME_UI_MAX.
46 */
47PULSEAUDIOQT_EXPORT qint64 maximumUIVolume();
48
49class PULSEAUDIOQT_EXPORT Context : public QObject
50{
51 Q_OBJECT
52 /**
53 * The state of the Context. This is further augmented by the autoConnecting property.
54 *
55 * @since 1.6
56 */
57 Q_PROPERTY(State state READ state NOTIFY stateChanged)
58 /**
59 * Regardless of the state, this property indicates whether the Context is presently trying to
60 * automatically establish a connection. When this is false it may be useful to give the
61 * user a manual way to trigger a connection attempt. AutoConnecting is subject to internal
62 * timeouts that when hit will prevent further auto connecting until the Context managed to
63 * connect.
64 */
65 Q_PROPERTY(bool autoConnecting READ isAutoConnecting NOTIFY autoConnectingChanged)
66
67public:
68 /**
69 * @since 1.6
70 */
71 enum class State {
72 Unconnected = 0,
74 Authorizing,
75 SettingName,
76 Ready,
77 Failed,
78 Terminated,
79 };
80 Q_ENUM(State)
81
82 ~Context() override;
83
84 static Context *instance();
85
86 /**
87 * Set the application id that is reported to PulseAudio.
88 * This needs to be called before accessing the context singleton the first time.
89 * If not set QGuiApplication::desktopFileName() is used.
90 */
91 static void setApplicationId(const QString &applicationId);
92
93 bool isValid();
94
95 /**
96 * Returns a list of all sinks.
97 *
98 * @return list of sinks
99 */
100 QList<Sink *> sinks() const;
101
102 /**
103 * Returns a list of all sink inputs.
104 *
105 * @return list of sink inputs
106 */
107 QList<SinkInput *> sinkInputs() const;
108
109 /**
110 * Returns a list of all sources.
111 *
112 * @return list of sources
113 */
114 QList<Source *> sources() const;
115
116 /**
117 * Returns a list of all source outputs.
118 *
119 * @return list of source outputs
120 */
121 QList<SourceOutput *> sourceOutputs() const;
122
123 /**
124 * Returns a list of all clients.
125 *
126 * @return list of clients
127 */
128 QList<Client *> clients() const;
129
130 /**
131 * Returns a list of all cards.
132 *
133 * @return list of cards
134 */
135 QList<Card *> cards() const;
136
137 /**
138 * Returns a list of all modules.
139 *
140 * @return list of modules
141 */
142 QList<Module *> modules() const;
143
144 /**
145 * Returns a list of all stream restores.
146 *
147 * @return list of stream restores
148 */
149 QList<StreamRestore *> streamRestores() const;
150
151 Server *server() const;
152
153 /**
154 * Returns a pointer to the raw PulseAudio context.
155 */
156 pa_context *context() const;
157
158 void setCardProfile(quint32 index, const QString &profile);
159 void setDefaultSink(const QString &name);
160 void setDefaultSource(const QString &name);
161
162 /**
163 * @returns the state of the context.
164 *
165 * @since 1.6
166 */
167 [[nodiscard]] State state() const;
168
169 /**
170 * @returns whether the Context is currently trying to auto-connect to the daemon
171 *
172 * @since 1.6
173 */
174 [[nodiscard]] bool isAutoConnecting() const;
175
176 /**
177 * Loads a new module.
178 *
179 * @param name the name of the module to load
180 * @param argument the argument to pass to the module
181 *
182 * To know if the module loaded successfully listen to moduleAdded.
183 *
184 * @since 1.7
185 */
186 void loadModule(const QString &name, const QString &argument);
187
188 /**
189 * Unloads the module.
190 *
191 * To know if the module unloaded successfully listen to moduleRemoved.
192 *
193 * @since 1.7
194 */
195 void unloadModule(PulseAudioQt::Module *module);
196
197public Q_SLOTS:
198 /**
199 * When the Context is not auto-connecting this may be used to give the user a manual trigger (e.g. a button)
200 *
201 * @since 1.6
202 */
203 void reconnectDaemon();
204
205Q_SIGNALS:
206 /**
207 * Indicates that sink was added.
208 */
209 void sinkAdded(PulseAudioQt::Sink *sink);
210
211 /**
212 * Indicates that sink was removed.
213 */
214 void sinkRemoved(PulseAudioQt::Sink *sink);
215
216 /**
217 * Indicates that sink input was added.
218 */
219 void sinkInputAdded(PulseAudioQt::SinkInput *sinkInput);
220
221 /**
222 * Indicates that sink input was removed.
223 */
224 void sinkInputRemoved(PulseAudioQt::SinkInput *sinkInput);
225
226 /**
227 * Indicates that source was added.
228 */
229 void sourceAdded(PulseAudioQt::Source *source);
230
231 /**
232 * Indicates that source was removed.
233 */
234 void sourceRemoved(PulseAudioQt::Source *source);
235
236 /**
237 * Indicates that source output was added.
238 */
239 void sourceOutputAdded(PulseAudioQt::SourceOutput *sourceOutput);
240
241 /**
242 * Indicates that source output was removed.
243 */
244 void sourceOutputRemoved(PulseAudioQt::SourceOutput *sourceOutput);
245
246 /**
247 * Indicates that client was added.
248 */
249 void clientAdded(PulseAudioQt::Client *client);
250
251 /**
252 * Indicates that client was removed.
253 */
254 void clientRemoved(PulseAudioQt::Client *client);
255
256 /**
257 * Indicates that card was added.
258 */
259 void cardAdded(PulseAudioQt::Card *card);
260
261 /**
262 * Indicates that card was removed.
263 */
264 void cardRemoved(PulseAudioQt::Card *card);
265
266 /**
267 * Indicates that module was added.
268 */
269 void moduleAdded(PulseAudioQt::Module *module);
270
271 /**
272 * Indicates that module was removed.
273 */
274 void moduleRemoved(PulseAudioQt::Module *module);
275
276 /**
277 * Indicates that stream restore was added.
278 */
279 void streamRestoreAdded(PulseAudioQt::StreamRestore *streamRestore);
280
281 /**
282 * Indicates that streamRestore was removed.
283 */
284 void streamRestoreRemoved(PulseAudioQt::StreamRestore *streamRestore);
285
286 /**
287 * Context state changed.
288 *
289 * @since 1.6
290 */
291 void stateChanged();
292
293 /**
294 * Indicates that autoConnecting changed.
295 *
296 * @since 1.6
297 */
298 void autoConnectingChanged();
299
300private:
301 explicit Context(QObject *parent = nullptr);
302
303 std::unique_ptr<class ContextPrivate> d;
304
305 friend class Sink;
306 friend class SinkInput;
307 friend class Source;
308 friend class SourceOutput;
309 friend class Stream;
310 friend class StreamRestorePrivate;
311 friend class Server;
312 friend class SinkModel;
313 friend class SinkInputModel;
314 friend class SourceModel;
315 friend class SourceOutputModel;
316 friend class StreamRestoreModel;
317 friend class CardModel;
318 friend class ModuleModel;
319};
320
321} // PulseAudioQt
322
323#endif // CONTEXT_H
A SinkInput stream.
Definition sinkinput.h:20
A PulseAudio sink.
Definition sink.h:20
A SourceOutput Stream.
A PulseAudio source.
Definition source.h:20
KCMUTILS_EXPORT KCModule * loadModule(const KPluginMetaData &metaData, QWidget *parent=nullptr, const QVariantList &args={}, const std::shared_ptr< QQmlEngine > &engine={})
bool isValid(QStringView ifopt)
The primary namespace of PulseAudioQt.
Definition card.cpp:17
qint64 normalVolume()
The normal volume (100%, 0 dB).
Definition context.cpp:35
qint64 maximumUIVolume()
The maximum volume suitable to display in a UI.
Definition context.cpp:50
qint64 minimumVolume()
The minimum volume (0%).
Definition context.cpp:40
qint64 maximumVolume()
The maximum volume PulseAudio can store.
Definition context.cpp:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.