Verified Commit 76fd650e authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 59f4efe4
......@@ -8,7 +8,6 @@
namespace QPulseAudio
{
CanberraContext *CanberraContext::s_context = nullptr;
CanberraContext *CanberraContext::instance()
......@@ -25,7 +24,6 @@ CanberraContext::CanberraContext(QObject *parent)
ca_context_create(&m_canberra);
}
CanberraContext::~CanberraContext()
{
if (m_canberra) {
......
......@@ -5,12 +5,11 @@
*/
#pragma once
#include <canberra.h>
#include <QObject>
#include <canberra.h>
namespace QPulseAudio
{
class CanberraContext : public QObject
{
Q_OBJECT
......@@ -31,7 +30,6 @@ private:
int m_references = 0;
static CanberraContext *s_context;
};
}
......@@ -12,7 +12,6 @@
namespace QPulseAudio
{
Card::Card(QObject *parent)
: PulseObject(parent)
{
......
......@@ -12,26 +12,30 @@
#include <QMap>
#include <QVariant>
#include "profile.h"
#include "port.h"
#include "profile.h"
#include "pulseobject.h"
namespace QPulseAudio
{
class CardPort : public Port
{
Q_OBJECT
Q_PROPERTY(QVariantMap properties READ properties NOTIFY propertiesChanged)
public:
explicit CardPort(QObject *parent = nullptr) : Port(parent) {}
~CardPort() override {}
explicit CardPort(QObject *parent = nullptr)
: Port(parent)
{
}
~CardPort() override
{
}
// int direction; /**< A #pa_direction enum, indicating the direction of this port. */
// uint32_t n_profiles; /**< Number of entries in profile array */
// pa_card_profile_info** profiles; /**< \deprecated Superseded by profiles2 */
// int64_t latency_offset; /**< Latency offset of the port that gets added to the sink/source latency when the port is active. \since 3.0 */
// pa_card_profile_info2** profiles2; /**< Array of pointers to available profiles, or NULL. Array is terminated by an entry set to NULL. \since 5.0 */
// int direction; /**< A #pa_direction enum, indicating the direction of this port. */
// uint32_t n_profiles; /**< Number of entries in profile array */
// pa_card_profile_info** profiles; /**< \deprecated Superseded by profiles2 */
// int64_t latency_offset; /**< Latency offset of the port that gets added to the sink/source latency when the port is active. \since 3.0 */
// pa_card_profile_info2** profiles2; /**< Array of pointers to available profiles, or NULL. Array is terminated by an entry set to NULL. \since 5.0 */
void update(const pa_card_port_info *info)
{
......@@ -56,7 +60,10 @@ public:
}
}
QVariantMap properties() const { return m_properties; }
QVariantMap properties() const
{
return m_properties;
}
Q_SIGNALS:
void propertiesChanged();
......@@ -69,7 +76,7 @@ class Card : public PulseObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QList<QObject *> profiles READ profiles NOTIFY profilesChanged)
Q_PROPERTY(QList<QObject *> profiles READ profiles NOTIFY profilesChanged)
Q_PROPERTY(quint32 activeProfileIndex READ activeProfileIndex WRITE setActiveProfileIndex NOTIFY activeProfileIndexChanged)
Q_PROPERTY(QList<QObject *> ports READ ports NOTIFY portsChanged)
public:
......
......@@ -10,7 +10,6 @@
namespace QPulseAudio
{
Client::Client(QObject *parent)
: PulseObject(parent)
{
......
......@@ -15,7 +15,6 @@
namespace QPulseAudio
{
class Client : public PulseObject
{
Q_OBJECT
......
......@@ -7,28 +7,27 @@
#include "context.h"
#include "server.h"
#include <QAbstractEventDispatcher>
#include "debug.h"
#include <QAbstractEventDispatcher>
#include <QDBusConnection>
#include <QDBusServiceWatcher>
#include <QMutexLocker>
#include <QTimer>
#include <QDBusServiceWatcher>
#include <QDBusConnection>
#include "card.h"
#include "client.h"
#include "module.h"
#include "sink.h"
#include "sinkinput.h"
#include "source.h"
#include "sourceoutput.h"
#include "streamrestore.h"
#include "module.h"
#include <KLocalizedString>
namespace QPulseAudio
{
Context* Context::s_context = nullptr;
Context *Context::s_context = nullptr;
const qint64 Context::NormalVolume = PA_VOLUME_NORM;
const qint64 Context::MinimalVolume = 0;
......@@ -98,9 +97,9 @@ static void source_output_cb(pa_context *context, const pa_source_output_info *i
// FIXME: This forces excluding these apps
if (const char *app = pa_proplist_gets(info->proplist, PA_PROP_APPLICATION_ID)) {
if (strcmp(app, "org.PulseAudio.pavucontrol") == 0 //
|| strcmp(app, "org.gnome.VolumeControl") == 0 //
|| strcmp(app, "org.kde.kmixd") == 0 //
|| strcmp(app, "org.kde.plasma-pa") == 0)
|| strcmp(app, "org.gnome.VolumeControl") == 0 //
|| strcmp(app, "org.kde.kmixd") == 0 //
|| strcmp(app, "org.kde.plasma-pa") == 0)
return;
}
Q_ASSERT(context);
......@@ -348,14 +347,12 @@ void Context::subscribeCallback(pa_context *context, pa_subscription_event_type_
}
break;
case PA_SUBSCRIPTION_EVENT_SERVER:
if (!PAOperation(pa_context_get_server_info(context, server_cb, this))) {
qCWarning(PLASMAPA) << "pa_context_get_server_info() failed";
return;
}
break;
}
}
......@@ -370,15 +367,13 @@ void Context::contextStateCallback(pa_context *c)
if (m_context == c) {
pa_context_set_subscribe_callback(c, subscribe_cb, this);
if (!PAOperation(pa_context_subscribe(c, (pa_subscription_mask_t)
(PA_SUBSCRIPTION_MASK_SINK|
PA_SUBSCRIPTION_MASK_SOURCE|
PA_SUBSCRIPTION_MASK_CLIENT|
PA_SUBSCRIPTION_MASK_SINK_INPUT|
PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
PA_SUBSCRIPTION_MASK_CARD|
PA_SUBSCRIPTION_MASK_MODULE|
PA_SUBSCRIPTION_MASK_SERVER), nullptr, nullptr))) {
if (!PAOperation(
pa_context_subscribe(c,
(pa_subscription_mask_t)(PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_CLIENT
| PA_SUBSCRIPTION_MASK_SINK_INPUT | PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT
| PA_SUBSCRIPTION_MASK_CARD | PA_SUBSCRIPTION_MASK_MODULE | PA_SUBSCRIPTION_MASK_SERVER),
nullptr,
nullptr))) {
qCWarning(PLASMAPA) << "pa_context_subscribe() failed";
return;
}
......@@ -488,8 +483,7 @@ void Context::streamRestoreCallback(const pa_ext_stream_restore_info *info)
if (!obj) {
QVariantMap props;
props.insert(QStringLiteral("application.icon_name"),
QStringLiteral("preferences-desktop-notification"));
props.insert(QStringLiteral("application.icon_name"), QStringLiteral("preferences-desktop-notification"));
obj = new StreamRestore(eventRoleIndex, props, this);
obj->update(info);
m_streamRestores.insert(obj);
......@@ -509,10 +503,7 @@ void Context::setCardProfile(quint32 index, const QString &profile)
return;
}
qCDebug(PLASMAPA) << index << profile;
if (!PAOperation(pa_context_set_card_profile_by_index(m_context,
index,
profile.toUtf8().constData(),
nullptr, nullptr))) {
if (!PAOperation(pa_context_set_card_profile_by_index(m_context, index, profile.toUtf8().constData(), nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_context_set_card_profile_by_index failed";
return;
}
......@@ -524,18 +515,13 @@ void Context::setDefaultSink(const QString &name)
return;
}
const QByteArray nameData = name.toUtf8();
if (!PAOperation(pa_context_set_default_sink(m_context,
nameData.constData(),
nullptr,
nullptr))) {
if (!PAOperation(pa_context_set_default_sink(m_context, nameData.constData(), nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_context_set_default_sink failed";
}
// Change device for all entries in stream-restore database
m_newDefaultSink = name;
if (!PAOperation(pa_ext_stream_restore_read(m_context,
ext_stream_restore_change_sink_cb,
this))) {
if (!PAOperation(pa_ext_stream_restore_read(m_context, ext_stream_restore_change_sink_cb, this))) {
qCWarning(PLASMAPA) << "pa_ext_stream_restore_read failed";
}
}
......@@ -546,18 +532,13 @@ void Context::setDefaultSource(const QString &name)
return;
}
const QByteArray nameData = name.toUtf8();
if (!PAOperation(pa_context_set_default_source(m_context,
nameData.constData(),
nullptr,
nullptr))) {
if (!PAOperation(pa_context_set_default_source(m_context, nameData.constData(), nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_context_set_default_source failed";
}
// Change device for all entries in stream-restore database
m_newDefaultSource = name;
if (!PAOperation(pa_ext_stream_restore_read(m_context,
ext_stream_restore_change_source_cb,
this))) {
if (!PAOperation(pa_ext_stream_restore_read(m_context, ext_stream_restore_change_source_cb, this))) {
qCWarning(PLASMAPA) << "pa_ext_stream_restore_read failed";
}
}
......@@ -567,13 +548,7 @@ void Context::streamRestoreWrite(const pa_ext_stream_restore_info *info)
if (!m_context) {
return;
}
if (!PAOperation(pa_ext_stream_restore_write(m_context,
PA_UPDATE_REPLACE,
info,
1,
true,
nullptr,
nullptr))) {
if (!PAOperation(pa_ext_stream_restore_write(m_context, PA_UPDATE_REPLACE, info, 1, true, nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_ext_stream_restore_write failed";
}
}
......@@ -585,13 +560,13 @@ void Context::connectToDaemon()
}
// We require a glib event loop
if (!QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("EventDispatcherGlib") &&
!QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("GlibEventDispatcher")) {
if (!QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("EventDispatcherGlib")
&& !QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("GlibEventDispatcher")) {
qCWarning(PLASMAPA) << "Disabling PulseAudio integration for lack of GLib event loop";
return;
}
qCDebug(PLASMAPA) << "Attempting connection to PulseAudio sound daemon";
qCDebug(PLASMAPA) << "Attempting connection to PulseAudio sound daemon";
if (!m_mainloop) {
m_mainloop = pa_glib_mainloop_new(nullptr);
Q_ASSERT(m_mainloop);
......
......@@ -11,17 +11,16 @@
#include <QObject>
#include <QSet>
#include <pulse/ext-stream-restore.h>
#include <pulse/glib-mainloop.h>
#include <pulse/mainloop.h>
#include <pulse/pulseaudio.h>
#include <pulse/glib-mainloop.h>
#include <pulse/ext-stream-restore.h>
#include "maps.h"
#include "operation.h"
namespace QPulseAudio
{
class Server;
class Context : public QObject
......@@ -40,21 +39,60 @@ public:
void ref();
void unref();
bool isValid() { return m_context && m_mainloop; }
bool isValid()
{
return m_context && m_mainloop;
}
pa_context *context() const { return m_context; }
pa_context *context() const
{
return m_context;
}
const SinkMap &sinks() const { return m_sinks; }
const SinkInputMap &sinkInputs() const { return m_sinkInputs; }
const SourceMap &sources() const { return m_sources; }
const SourceOutputMap &sourceOutputs() const { return m_sourceOutputs; }
const ClientMap &clients() const { return m_clients; }
const CardMap &cards() const { return m_cards; }
const ModuleMap &modules() const { return m_modules; }
const StreamRestoreMap &streamRestores() const { return m_streamRestores; }
Server *server() const { return m_server; }
QString newDefaultSink() const { return m_newDefaultSink; }
QString newDefaultSource() const { return m_newDefaultSource; }
const SinkMap &sinks() const
{
return m_sinks;
}
const SinkInputMap &sinkInputs() const
{
return m_sinkInputs;
}
const SourceMap &sources() const
{
return m_sources;
}
const SourceOutputMap &sourceOutputs() const
{
return m_sourceOutputs;
}
const ClientMap &clients() const
{
return m_clients;
}
const CardMap &cards() const
{
return m_cards;
}
const ModuleMap &modules() const
{
return m_modules;
}
const StreamRestoreMap &streamRestores() const
{
return m_streamRestores;
}
Server *server() const
{
return m_server;
}
QString newDefaultSink() const
{
return m_newDefaultSink;
}
QString newDefaultSource() const
{
return m_newDefaultSource;
}
void subscribeCallback(pa_context *context, pa_subscription_event_type_t type, uint32_t index);
void contextStateCallback(pa_context *context);
......@@ -74,9 +112,8 @@ public:
void setDefaultSource(const QString &name);
void streamRestoreWrite(const pa_ext_stream_restore_info *info);
template <typename PAFunction>
void setGenericVolume(quint32 index, int channel, qint64 newVolume,
pa_cvolume cVolume, PAFunction pa_set_volume)
template<typename PAFunction>
void setGenericVolume(quint32 index, int channel, qint64 newVolume, pa_cvolume cVolume, PAFunction pa_set_volume)
{
if (!m_context) {
return;
......@@ -93,14 +130,13 @@ public:
newCVolume.values[channel] = newVolume;
}
if (!PAOperation(pa_set_volume(m_context, index, &newCVolume, nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_set_volume failed";
qCWarning(PLASMAPA) << "pa_set_volume failed";
return;
}
}
template <typename PAFunction>
void setGenericVolumes(quint32 index, QVector<qint64> channelVolumes,
pa_cvolume cVolume, PAFunction pa_set_volume)
template<typename PAFunction>
void setGenericVolumes(quint32 index, QVector<qint64> channelVolumes, pa_cvolume cVolume, PAFunction pa_set_volume)
{
if (!m_context) {
return;
......@@ -113,52 +149,42 @@ public:
}
if (!PAOperation(pa_set_volume(m_context, index, &newCVolume, nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_set_volume failed";
qCWarning(PLASMAPA) << "pa_set_volume failed";
return;
}
}
template <typename PAFunction>
template<typename PAFunction>
void setGenericMute(quint32 index, bool mute, PAFunction pa_set_mute)
{
if (!m_context) {
return;
}
if (!PAOperation(pa_set_mute(m_context, index, mute, nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_set_mute failed";
qCWarning(PLASMAPA) << "pa_set_mute failed";
return;
}
}
template <typename PAFunction>
template<typename PAFunction>
void setGenericPort(quint32 index, const QString &portName, PAFunction pa_set_port)
{
if (!m_context) {
return;
}
if (!PAOperation(pa_set_port(m_context,
index,
portName.toUtf8().constData(),
nullptr,
nullptr))) {
if (!PAOperation(pa_set_port(m_context, index, portName.toUtf8().constData(), nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_set_port failed";
return;
}
}
template <typename PAFunction>
void setGenericDeviceForStream(quint32 streamIndex,
quint32 deviceIndex,
PAFunction pa_move_stream_to_device)
template<typename PAFunction>
void setGenericDeviceForStream(quint32 streamIndex, quint32 deviceIndex, PAFunction pa_move_stream_to_device)
{
if (!m_context) {
return;
}
if (!PAOperation(pa_move_stream_to_device(m_context,
streamIndex,
deviceIndex,
nullptr,
nullptr))) {
if (!PAOperation(pa_move_stream_to_device(m_context, streamIndex, deviceIndex, nullptr, nullptr))) {
qCWarning(PLASMAPA) << "pa_move_stream_to_device failed";
return;
}
......@@ -186,7 +212,7 @@ private:
QString m_newDefaultSource;
int m_references;
static Context* s_context;
static Context *s_context;
};
} // QPulseAudio
......
......@@ -11,4 +11,3 @@
Q_DECLARE_LOGGING_CATEGORY(PLASMAPA)
#endif
......@@ -56,11 +56,11 @@ QPulseAudio::Device::State QPulseAudio::Device::stateFromPaState(int value) cons
switch (value) {
case -1: // PA_X_INVALID_STATE
return InvalidState;
case 0: // PA_X_RUNNING
case 0: // PA_X_RUNNING
return RunningState;
case 1: // PA_X_IDLE
case 1: // PA_X_IDLE
return IdleState;
case 2: // PA_X_SUSPENDED
case 2: // PA_X_SUSPENDED
return SuspendedState;
default:
return UnknownState;
......
......@@ -11,13 +11,12 @@
#include <pulse/volume.h>
#include "volumeobject.h"
#include "port.h"
#include "pulseobject.h"
#include "volumeobject.h"
namespace QPulseAudio
{
class Device : public VolumeObject
{
Q_OBJECT
......@@ -40,9 +39,11 @@ public:
};
Q_ENUMS(State);
~Device() override {}
~Device() override
{
}
template <typename PAInfo>
template<typename PAInfo>
void updateDevice(const PAInfo *info)
{
updateVolumeObject(info);
......
......@@ -6,27 +6,26 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
#include <QString>
#include <QByteArray>
#include <QVariant>
#include <QDebug>
#include <QString>
#include <QVariant>
#include "gconfitem.h"
#include <glib.h>
#include <gconf/gconf-value.h>
#include <gconf/gconf-client.h>
#include <gconf/gconf-value.h>
#include <glib.h>
struct GConfItemPrivate
{
struct GConfItemPrivate {
QString root;
QVariant value;
guint notify_id;
static void notify_trampoline(GConfClient*, guint, GConfEntry *, gpointer);
static void notify_trampoline(GConfClient *, guint, GConfEntry *, gpointer);
};
#define withClient(c) for(GConfClient *c = (gconf_client_get_default()); c; g_object_unref(c), c=NULL)
#define withClient(c) for (GConfClient *c = (gconf_client_get_default()); c; g_object_unref(c), c = NULL)
static QByteArray convertKey(QString key)
{
......@@ -62,20 +61,18 @@ static QVariant convertValue(GConfValue *src)
return QVariant(QString::fromUtf8(gconf_value_get_string(src)));
case GCONF_VALUE_LIST:
switch (gconf_value_get_list_type(src)) {
case GCONF_VALUE_STRING:
{
QStringList result;
for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next)
result.append(QString::fromUtf8(gconf_value_get_string((GConfValue *)elts->data)));
return QVariant(result);
}
default:
{
QList<QVariant> result;
for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next)
result.append(convertValue((GConfValue *)elts->data));
return QVariant(result);
}
case GCONF_VALUE_STRING: {
QStringList result;
for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next)
result.append(QString::fromUtf8(gconf_value_get_string((GConfValue *)elts->data)));
return QVariant(result);
}
default: {
QList<QVariant> result;
for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next)
result.append(convertValue((GConfValue *)elts->data));
return QVariant(result);
}
}
case GCONF_VALUE_SCHEMA:
default:
......@@ -86,14 +83,14 @@ static QVariant convertValue(GConfValue *src)
static GConfValue *convertString(const QString &str)
{
GConfValue *v = gconf_value_new (GCONF_VALUE_STRING);
gconf_value_set_string (v, str.toUtf8().data());
GConfValue *v = gconf_value_new(GCONF_VALUE_STRING);
gconf_value_set_string(v, str.toUtf8().data());
return v;
}
static GConfValueType primitiveType (const QVariant &elt)
static GConfValueType primitiveType(const QVariant &elt)
{
switch(elt.type()) {
switch (elt.type()) {
case QVariant::String:
return GCONF_VALUE_STRING;
case QVariant::Int:
......@@ -112,7 +109,7 @@ static GConfValueType uniformType(const QList<QVariant> &list)