diff --git a/CMakeLists.txt b/CMakeLists.txt index 90867d7..7f6ba28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,55 +1,55 @@ cmake_minimum_required(VERSION 3.0) project(plasma-volume-control) set(PROJECT_VERSION "5.13.80") set(PROJECT_VERSION_MAJOR 5) set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.42.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/) -add_definitions(-DTRANSLATION_DOMAIN=\"kcm_pulseaudio\") +add_definitions(-DTRANSLATION_DOMAIN=\"kcm_pulseaudio\" -DQT_NO_KEYWORDS) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMOptionalAddSubdirectory) include(FindPkgConfig) pkg_check_modules(GCONF gconf-2.0) pkg_check_modules(GOBJECT gobject-2.0) if (GCONF_FOUND AND GOBJECT_FOUND) set(HAVE_GCONF TRUE) endif() find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Gui DBus Widgets Quick ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons Declarative DocTools GlobalAccel I18n Plasma ) find_package(PulseAudio 5.0.0 REQUIRED) find_package(Canberra REQUIRED) find_package(GLIB2 REQUIRED) configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_subdirectory(applet) add_subdirectory(src) add_subdirectory(data) add_subdirectory(doc) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/card.cpp b/src/card.cpp index e418c6e..bc6970f 100644 --- a/src/card.cpp +++ b/src/card.cpp @@ -1,94 +1,94 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "card.h" #include "debug.h" #include "context.h" namespace QPulseAudio { Card::Card(QObject *parent) : PulseObject(parent) { } void Card::update(const pa_card_info *info) { updatePulseObject(info); QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { m_name = infoName; - emit nameChanged(); + Q_EMIT nameChanged(); } qDeleteAll(m_profiles); m_profiles.clear(); for (auto **it = info->profiles2; it && *it != nullptr; ++it) { Profile *profile = new Profile(this); profile->setInfo(*it); m_profiles.append(profile); if (info->active_profile2 == *it) { m_activeProfileIndex = m_profiles.length() - 1; } } - emit profilesChanged(); - emit activeProfileIndexChanged(); + Q_EMIT profilesChanged(); + Q_EMIT activeProfileIndexChanged(); qDeleteAll(m_ports); m_ports.clear(); for (auto **it = info->ports; it && *it != nullptr; ++it) { CardPort *port = new CardPort(this); port->update(*it); m_ports.append(port); } - emit portsChanged(); + Q_EMIT portsChanged(); } QString Card::name() const { return m_name; } QList Card::profiles() const { return m_profiles; } quint32 Card::activeProfileIndex() const { return m_activeProfileIndex; } void Card::setActiveProfileIndex(quint32 profileIndex) { const Profile *profile = qobject_cast(profiles().at(profileIndex)); context()->setCardProfile(index(), profile->name()); } QList Card::ports() const { return m_ports; } } // QPulseAudio diff --git a/src/card.h b/src/card.h index 10d79cf..331d422 100644 --- a/src/card.h +++ b/src/card.h @@ -1,111 +1,111 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef CARD_H #define CARD_H #include #include #include #include "profile.h" #include "port.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 {} // 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) { setInfo(info); m_properties.clear(); void *it = nullptr; while (const char *key = pa_proplist_iterate(info->proplist, &it)) { Q_ASSERT(key); const char *value = pa_proplist_gets(info->proplist, key); if (!value) { qCDebug(PLASMAPA) << "property" << key << "not a string"; continue; } Q_ASSERT(value); m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value)); } - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } QVariantMap properties() const { return m_properties; } -signals: +Q_SIGNALS: void propertiesChanged(); private: QVariantMap m_properties; }; class Card : public PulseObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QList profiles READ profiles NOTIFY profilesChanged) Q_PROPERTY(quint32 activeProfileIndex READ activeProfileIndex WRITE setActiveProfileIndex NOTIFY activeProfileIndexChanged) Q_PROPERTY(QList ports READ ports NOTIFY portsChanged) public: explicit Card(QObject *parent); void update(const pa_card_info *info); QString name() const; QList profiles() const; quint32 activeProfileIndex() const; void setActiveProfileIndex(quint32 profileIndex); QList ports() const; -signals: +Q_SIGNALS: void nameChanged(); void profilesChanged(); void activeProfileIndexChanged(); void portsChanged(); private: QString m_name; QList m_profiles; quint32 m_activeProfileIndex; QList m_ports; }; } // QPulseAudio #endif // CARD_H diff --git a/src/client.cpp b/src/client.cpp index 6fc5814..f283b89 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1,53 +1,53 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "client.h" #include "debug.h" namespace QPulseAudio { Client::Client(QObject *parent) : PulseObject(parent) { } Client::~Client() { } void Client::update(const pa_client_info *info) { updatePulseObject(info); QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { m_name = infoName; - emit nameChanged(); + Q_EMIT nameChanged(); } } QString Client::name() const { return m_name; } } // QPulseAudio diff --git a/src/client.h b/src/client.h index c5c4ed1..860fc3c 100644 --- a/src/client.h +++ b/src/client.h @@ -1,54 +1,54 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef CLIENT_H #define CLIENT_H #include #include #include "pulseobject.h" namespace QPulseAudio { class Client : public PulseObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) public: explicit Client(QObject *parent); ~Client() override; void update(const pa_client_info *info); QString name() const; -signals: +Q_SIGNALS: void nameChanged(); private: QString m_name; }; } // QPulseAudio #endif // CLIENT_H diff --git a/src/device.h b/src/device.h index 85019f8..2bc5921 100644 --- a/src/device.h +++ b/src/device.h @@ -1,155 +1,155 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef DEVICE_H #define DEVICE_H #include #include #include "volumeobject.h" #include "port.h" #include "pulseobject.h" namespace QPulseAudio { class Device : public VolumeObject { Q_OBJECT Q_PROPERTY(State state READ state NOTIFY stateChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(QString formFactor READ formFactor NOTIFY formFactorChanged) Q_PROPERTY(quint32 cardIndex READ cardIndex NOTIFY cardIndexChanged) Q_PROPERTY(QList ports READ ports NOTIFY portsChanged) Q_PROPERTY(quint32 activePortIndex READ activePortIndex WRITE setActivePortIndex NOTIFY activePortIndexChanged) Q_PROPERTY(bool default READ isDefault WRITE setDefault NOTIFY defaultChanged) Q_PROPERTY(bool virtualDevice READ isVirtualDevice NOTIFY virtualDeviceChanged) public: enum State { InvalidState = 0, RunningState, IdleState, SuspendedState, UnknownState }; Q_ENUMS(State); ~Device() override {} template void updateDevice(const PAInfo *info) { updateVolumeObject(info); if (m_name != info->name) { m_name = info->name; - emit nameChanged(); + Q_EMIT nameChanged(); } if (m_description != info->description) { m_description = info->description; - emit descriptionChanged(); + Q_EMIT descriptionChanged(); } const char *form_factor = pa_proplist_gets(info->proplist, PA_PROP_DEVICE_FORM_FACTOR); if (form_factor) { QString formFactor = QString::fromUtf8(form_factor); if (m_formFactor != formFactor) { m_formFactor = formFactor; - emit formFactorChanged(); + Q_EMIT formFactorChanged(); } } m_cardIndex = info->card; - emit cardIndexChanged(); + Q_EMIT cardIndexChanged(); // TODO: this rebuilds the entire port list on every update. would be // nicer if it actually removed what needs removing updates what needs // updating and adds what needs adding. Alas, this is a tad more // involved. qDeleteAll(m_ports); m_ports.clear(); for (auto **ports = info->ports; ports && *ports != nullptr; ++ports) { Port *port = new Port(this); port->setInfo(*ports); m_ports.append(port); if (info->active_port == *ports) { m_activePortIndex = m_ports.length() - 1; } } - emit portsChanged(); - emit activePortIndexChanged(); + Q_EMIT portsChanged(); + Q_EMIT activePortIndexChanged(); State infoState = stateFromPaState(info->state); if (infoState != m_state) { m_state = infoState; - emit stateChanged(); + Q_EMIT stateChanged(); } const bool isVirtual = !(info->flags & 4); // PA_X_HARDWARE if (m_virtualDevice != isVirtual) { m_virtualDevice = isVirtual; - emit virtualDeviceChanged(); + Q_EMIT virtualDeviceChanged(); } } State state() const; QString name() const; QString description() const; QString formFactor() const; quint32 cardIndex() const; QList ports() const; quint32 activePortIndex() const; virtual void setActivePortIndex(quint32 port_index) = 0; virtual bool isDefault() const = 0; virtual void setDefault(bool enable) = 0; bool isVirtualDevice() const; -signals: +Q_SIGNALS: void stateChanged(); void nameChanged(); void descriptionChanged(); void formFactorChanged(); void cardIndexChanged(); void portsChanged(); void activePortIndexChanged(); void defaultChanged(); void virtualDeviceChanged(); protected: explicit Device(QObject *parent); private: State stateFromPaState(int value) const; QString m_name; QString m_description; QString m_formFactor; quint32 m_cardIndex = -1; QList m_ports; quint32 m_activePortIndex = -1; State m_state = UnknownState; bool m_virtualDevice = false; }; } // QPulseAudio #endif // DEVICE_H diff --git a/src/kcm/module.h b/src/kcm/module.h index 73c46c5..3bb6e85 100644 --- a/src/kcm/module.h +++ b/src/kcm/module.h @@ -1,49 +1,49 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef MODULE_H #define MODULE_H #include class CardModel; class Context; class SinkInputModel; class SinkModel; class SourceModel; class SourceOutputModel; class KCMPulseAudio : public KQuickAddons::ConfigModule { Q_OBJECT public: KCMPulseAudio(QObject *parent, const QVariantList &args); ~KCMPulseAudio() override; -public slots: +public Q_SLOTS: void defaults() final; void load() final; void save() final; private: Context *m_context; }; #endif // MODULE_H diff --git a/src/maps.h b/src/maps.h index e443a4a..2c6bdcf 100644 --- a/src/maps.h +++ b/src/maps.h @@ -1,180 +1,180 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef MAPS_H #define MAPS_H #include "debug.h" #include #include #include #include namespace QPulseAudio { // Used for typedefs. class Card; class Client; class Sink; class SinkInput; class Source; class SourceOutput; class StreamRestore; class Module; /** * @see MapBase * This class is nothing more than the QObject base since moc cannot handle * templates. */ class MapBaseQObject : public QObject { Q_OBJECT public: virtual int count() const = 0; virtual QObject *objectAt(int index) const = 0; virtual int indexOfObject(QObject *object) const = 0; -signals: +Q_SIGNALS: void aboutToBeAdded(int index); void added(int index); void aboutToBeRemoved(int index); void removed(int index); }; /** * Maps a specific index to a specific object pointer. * This is used to give the unique arbitrary PulseAudio index of a PulseObject a * serialized list index. Namely it enables us to translate a discrete list * index to a pulse index to an object, and any permutation thereof. */ template class MapBase : public MapBaseQObject { public: ~MapBase() override {} const QMap &data() const { return m_data; } int count() const override { return m_data.count(); } int indexOfObject(QObject *object) const override { int index = 0; QMapIterator it(m_data); while (it.hasNext()) { it.next(); if (it.value() == object) { return index; } index++; } return -1; } QObject *objectAt(int index) const override { return (m_data.constBegin() + index).value(); } void reset() { while (!m_data.isEmpty()) { removeEntry(m_data.lastKey()); } m_pendingRemovals.clear(); } void insert(Type *object) { Q_ASSERT(!m_data.contains(object->index())); int modelIndex = 0; for (auto it = m_data.constBegin(); it != m_data.constEnd(); ++it) { if (object->index() < it.key()) { break; } modelIndex++; } - emit aboutToBeAdded(modelIndex); + Q_EMIT aboutToBeAdded(modelIndex); m_data.insert(object->index(), object); Q_ASSERT(modelIndex == m_data.keys().indexOf(object->index())); - emit added(modelIndex); + Q_EMIT added(modelIndex); } // Context is passed in as parent because context needs to include the maps // so we'd cause a circular dep if we were to try to use the instance here. // Plus that's weird separation anyway. void updateEntry(const PAInfo *info, QObject *parent) { Q_ASSERT(info); if (m_pendingRemovals.remove(info->index)) { // Was already removed again. return; } auto *obj = m_data.value(info->index, nullptr); if (!obj) { obj = new Type(parent); } obj->update(info); if (!m_data.contains(info->index)) { insert(obj); } } void removeEntry(quint32 index) { if (!m_data.contains(index)) { m_pendingRemovals.insert(index); } else { const int modelIndex = m_data.keys().indexOf(index); - emit aboutToBeRemoved(modelIndex); + Q_EMIT aboutToBeRemoved(modelIndex); delete m_data.take(index); - emit removed(modelIndex); + Q_EMIT removed(modelIndex); } } protected: QMap m_data; QSet m_pendingRemovals; }; typedef MapBase SinkMap; typedef MapBase SinkInputMap; typedef MapBase SourceMap; typedef MapBase SourceOutputMap; typedef MapBase ClientMap; typedef MapBase CardMap; typedef MapBase ModuleMap; typedef MapBase StreamRestoreMap; } // QPulseAudio #endif // MAPS_H diff --git a/src/module.cpp b/src/module.cpp index 63d495b..55889da 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -1,61 +1,61 @@ /* Copyright 2017 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "module.h" #include "debug.h" #include "context.h" namespace QPulseAudio { Module::Module(QObject *parent) : PulseObject(parent) { } void Module::update(const pa_module_info *info) { updatePulseObject(info); const QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { m_name = infoName; - emit nameChanged(); + Q_EMIT nameChanged(); } const QString infoArgument = QString::fromUtf8(info->argument); if (m_argument != infoArgument) { m_argument = infoArgument; - emit argumentChanged(); + Q_EMIT argumentChanged(); } } QString Module::name() const { return m_name; } QString Module::argument() const { return m_argument; } } // QPulseAudio diff --git a/src/module.h b/src/module.h index 9adc6a3..d429128 100644 --- a/src/module.h +++ b/src/module.h @@ -1,59 +1,59 @@ /* Copyright 2017 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef MODULE_H #define MODULE_H #include #include #include #include "pulseobject.h" namespace QPulseAudio { class Module : public PulseObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString argument READ argument NOTIFY argumentChanged) public: explicit Module(QObject *parent); void update(const pa_module_info *info); QString name() const; QString argument() const; -signals: +Q_SIGNALS: void nameChanged(); void argumentChanged(); private: QString m_name; QString m_argument; }; } // QPulseAudio #endif // MODULE_H diff --git a/src/profile.h b/src/profile.h index 21a0450..39cfced 100644 --- a/src/profile.h +++ b/src/profile.h @@ -1,104 +1,104 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PROFILE_H #define PROFILE_H #include #include namespace QPulseAudio { class Profile : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(quint32 priority READ priority NOTIFY priorityChanged) Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) public: enum Availability { Unknown, Available, Unavailable }; Q_ENUM(Availability) explicit Profile(QObject *parent); ~Profile() override; template void setInfo(const PAInfo *info) { setCommonInfo(info, info->available ? Available : Unavailable); } QString name() const; QString description() const; quint32 priority() const; Availability availability() const; -signals: +Q_SIGNALS: void nameChanged(); void descriptionChanged(); void priorityChanged(); void availabilityChanged(); protected: template void setCommonInfo(const PAInfo *info, Availability newAvailability) { // Description is optional. Name not so much as we need some ID. Q_ASSERT(info->name); QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { m_name = infoName; - emit nameChanged(); + Q_EMIT nameChanged(); } if (info->description) { QString infoDescription = QString::fromUtf8(info->description); if (m_description != infoDescription) { m_description = infoDescription; - emit descriptionChanged(); + Q_EMIT descriptionChanged(); } } if (m_priority != info->priority) { m_priority = info->priority; - emit priorityChanged(); + Q_EMIT priorityChanged(); } if (m_availability != newAvailability) { m_availability = newAvailability; - emit availabilityChanged(); + Q_EMIT availabilityChanged(); } } private: QString m_name; QString m_description; quint32 m_priority; Availability m_availability; }; } // QPulseAudio #endif // PROFILE_H diff --git a/src/pulseaudio.cpp b/src/pulseaudio.cpp index 70c6a4a..7e6a9e4 100644 --- a/src/pulseaudio.cpp +++ b/src/pulseaudio.cpp @@ -1,385 +1,385 @@ /* Copyright 2014-2015 Harald Sitter Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "pulseaudio.h" #include "debug.h" #include "card.h" #include "sink.h" #include "sinkinput.h" #include "source.h" #include "sourceoutput.h" #include "server.h" #include "streamrestore.h" #include "module.h" #include namespace QPulseAudio { AbstractModel::AbstractModel(const MapBaseQObject *map, QObject *parent) : QAbstractListModel(parent) , m_map(map) { Context::instance()->ref(); connect(m_map, &MapBaseQObject::aboutToBeAdded, this, [this](int index) { beginInsertRows(QModelIndex(), index, index); }); connect(m_map, &MapBaseQObject::added, this, [this](int index) { onDataAdded(index); endInsertRows(); }); connect(m_map, &MapBaseQObject::aboutToBeRemoved, this, [this](int index) { beginRemoveRows(QModelIndex(), index, index); }); connect(m_map, &MapBaseQObject::removed, this, [this](int index) { Q_UNUSED(index); endRemoveRows(); }); } AbstractModel::~AbstractModel() { //deref context after we've deleted this object //see https://bugs.kde.org/show_bug.cgi?id=371215 Context::instance()->unref(); } QHash AbstractModel::roleNames() const { if (!m_roles.empty()) { qCDebug(PLASMAPA) << "returning roles" << m_roles; return m_roles; } Q_UNREACHABLE(); return QHash(); } int AbstractModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return m_map->count(); } QVariant AbstractModel::data(const QModelIndex &index, int role) const { if (!hasIndex(index.row(), index.column())) { return QVariant(); } QObject *data = m_map->objectAt(index.row()); Q_ASSERT(data); if (role == PulseObjectRole) { return QVariant::fromValue(data); } else if (role == Qt::DisplayRole) { return static_cast(data)->properties().value(QStringLiteral("name")).toString(); } int property = m_objectProperties.value(role, -1); if (property == -1) { return QVariant(); } return data->metaObject()->property(property).read(data); } bool AbstractModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!hasIndex(index.row(), index.column())) { return false; } int propertyIndex = m_objectProperties.value(role, -1); if (propertyIndex == -1) { return false; } QObject *data = m_map->objectAt(index.row()); auto property = data->metaObject()->property(propertyIndex); return property.write(data, value); } int AbstractModel::role(const QByteArray &roleName) const { qCDebug(PLASMAPA) << roleName << m_roles.key(roleName, -1); return m_roles.key(roleName, -1); } Context *AbstractModel::context() const { return Context::instance(); } void AbstractModel::initRoleNames(const QMetaObject &qobjectMetaObject) { m_roles[PulseObjectRole] = QByteArrayLiteral("PulseObject"); QMetaEnum enumerator; for (int i = 0; i < metaObject()->enumeratorCount(); ++i) { if (metaObject()->enumerator(i).name() == QLatin1String("ItemRole")) { enumerator = metaObject()->enumerator(i); break; } } for (int i = 0; i < enumerator.keyCount(); ++i) { // Clip the Role suffix and glue it in the hash. const int roleLength = 4; QByteArray key(enumerator.key(i)); // Enum values must end in Role or the enum is crap Q_ASSERT(key.right(roleLength) == QByteArrayLiteral("Role")); key.chop(roleLength); m_roles[enumerator.value(i)] = key; } int maxEnumValue = -1; for (auto it = m_roles.constBegin(); it != m_roles.constEnd(); ++it) { if (it.key() > maxEnumValue) { maxEnumValue = it.key(); } } Q_ASSERT(maxEnumValue != -1); auto mo = qobjectMetaObject; for (int i = 0; i < mo.propertyCount(); ++i) { QMetaProperty property = mo.property(i); QString name(property.name()); name.replace(0, 1, name.at(0).toUpper()); m_roles[++maxEnumValue] = name.toLatin1(); m_objectProperties.insert(maxEnumValue, i); if (!property.hasNotifySignal()) { continue; } m_signalIndexToProperties.insert(property.notifySignalIndex(), i); } qCDebug(PLASMAPA) << m_roles; // Connect to property changes also with objects already in model for (int i = 0; i < m_map->count(); ++i) { onDataAdded(i); } } void AbstractModel::propertyChanged() { if (!sender() || senderSignalIndex() == -1) { return; } int propertyIndex = m_signalIndexToProperties.value(senderSignalIndex(), -1); if (propertyIndex == -1) { return; } int role = m_objectProperties.key(propertyIndex, -1); if (role == -1) { return; } int index = m_map->indexOfObject(sender()); qCDebug(PLASMAPA) << "PROPERTY CHANGED (" << index << ") :: " << role << roleNames().value(role); - emit dataChanged(createIndex(index, 0), createIndex(index, 0), {role}); + Q_EMIT dataChanged(createIndex(index, 0), createIndex(index, 0), {role}); } void AbstractModel::onDataAdded(int index) { QObject *data = m_map->objectAt(index); const QMetaObject *mo = data->metaObject(); // We have all the data changed notify signals already stored auto keys = m_signalIndexToProperties.keys(); - foreach (int index, keys) { + Q_FOREACH (int index, keys) { QMetaMethod meth = mo->method(index); connect(data, meth, this, propertyChangedMetaMethod()); } } QMetaMethod AbstractModel::propertyChangedMetaMethod() const { auto mo = metaObject(); int methodIndex = mo->indexOfMethod("propertyChanged()"); if (methodIndex == -1) { return QMetaMethod(); } return mo->method(methodIndex); } SinkModel::SinkModel(QObject *parent) : AbstractModel(&context()->sinks(), parent) , m_preferredSink(nullptr) { initRoleNames(Sink::staticMetaObject); for (int i = 0; i < context()->sinks().count(); ++i) { sinkAdded(i); } connect(&context()->sinks(), &MapBaseQObject::added, this, &SinkModel::sinkAdded); connect(&context()->sinks(), &MapBaseQObject::removed, this, &SinkModel::sinkRemoved); connect(context()->server(), &Server::defaultSinkChanged, this, [this]() { updatePreferredSink(); - emit defaultSinkChanged(); + Q_EMIT defaultSinkChanged(); }); } Sink *SinkModel::defaultSink() const { return context()->server()->defaultSink(); } Sink *SinkModel::preferredSink() const { return m_preferredSink; } QVariant SinkModel::data(const QModelIndex &index, int role) const { if (role == SortByDefaultRole) { // Workaround QTBUG-1548 const QString pulseIndex = data(index, AbstractModel::role(QByteArrayLiteral("Index"))).toString(); const QString defaultDevice = data(index, AbstractModel::role(QByteArrayLiteral("Default"))).toString(); return defaultDevice + pulseIndex; } return AbstractModel::data(index, role); } void SinkModel::sinkAdded(int index) { Q_ASSERT(qobject_cast(context()->sinks().objectAt(index))); Sink *sink = static_cast(context()->sinks().objectAt(index)); connect(sink, &Sink::stateChanged, this, &SinkModel::updatePreferredSink); updatePreferredSink(); } void SinkModel::sinkRemoved(int index) { Q_UNUSED(index); updatePreferredSink(); } void SinkModel::updatePreferredSink() { Sink *sink = findPreferredSink(); if (sink != m_preferredSink) { qCDebug(PLASMAPA) << "Changing preferred sink to" << sink << (sink ? sink->name() : ""); m_preferredSink = sink; - emit preferredSinkChanged(); + Q_EMIT preferredSinkChanged(); } } Sink *SinkModel::findPreferredSink() const { const auto &sinks = context()->sinks(); // Only one sink is the preferred one if (sinks.count() == 1) { return static_cast(sinks.objectAt(0)); } auto lookForState = [this](Device::State state) { Sink *ret = nullptr; QMapIterator it(context()->sinks().data()); while (it.hasNext()) { it.next(); if (it.value()->isVirtualDevice() || it.value()->state() != state) { continue; } if (!ret) { ret = it.value(); } else if (it.value() == defaultSink()) { ret = it.value(); break; } } return ret; }; Sink *preferred = nullptr; // Look for playing sinks + prefer default sink preferred = lookForState(Device::RunningState); if (preferred) { return preferred; } // Look for idle sinks + prefer default sink preferred = lookForState(Device::IdleState); if (preferred) { return preferred; } // Fallback to default sink return defaultSink(); } SourceModel::SourceModel(QObject *parent) : AbstractModel(&context()->sources(), parent) { initRoleNames(Source::staticMetaObject); connect(context()->server(), &Server::defaultSourceChanged, this, &SourceModel::defaultSourceChanged); } Source *SourceModel::defaultSource() const { return context()->server()->defaultSource(); } QVariant SourceModel::data(const QModelIndex &index, int role) const { if (role == SortByDefaultRole) { // Workaround QTBUG-1548 const QString pulseIndex = data(index, AbstractModel::role(QByteArrayLiteral("Index"))).toString(); const QString defaultDevice = data(index, AbstractModel::role(QByteArrayLiteral("Default"))).toString(); return defaultDevice + pulseIndex; } return AbstractModel::data(index, role); } SinkInputModel::SinkInputModel(QObject *parent) : AbstractModel(&context()->sinkInputs(), parent) { initRoleNames(SinkInput::staticMetaObject); } SourceOutputModel::SourceOutputModel(QObject *parent) : AbstractModel(&context()->sourceOutputs(), parent) { initRoleNames(SourceOutput::staticMetaObject); } CardModel::CardModel(QObject *parent) : AbstractModel(&context()->cards(), parent) { initRoleNames(Card::staticMetaObject); } StreamRestoreModel::StreamRestoreModel(QObject *parent) : AbstractModel(&context()->streamRestores(), parent) { initRoleNames(StreamRestore::staticMetaObject); } ModuleModel::ModuleModel(QObject *parent) : AbstractModel(&context()->modules(), parent) { initRoleNames(Module::staticMetaObject); } } // QPulseAudio diff --git a/src/pulseaudio.h b/src/pulseaudio.h index af6be9a..b064663 100644 --- a/src/pulseaudio.h +++ b/src/pulseaudio.h @@ -1,157 +1,157 @@ /* Copyright 2014-2015 Harald Sitter Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PULSEAUDIO_H #define PULSEAUDIO_H #include #include "maps.h" namespace QPulseAudio { class Context; class AbstractModel : public QAbstractListModel { Q_OBJECT public: enum ItemRole { PulseObjectRole = Qt::UserRole + 1 }; ~AbstractModel() override; QHash roleNames() const final; int rowCount(const QModelIndex &parent = QModelIndex()) const final; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) final; Q_INVOKABLE int role(const QByteArray &roleName) const; protected: AbstractModel(const MapBaseQObject *map, QObject *parent); void initRoleNames(const QMetaObject &qobjectMetaObject); Context *context() const; -private slots: +private Q_SLOTS: void propertyChanged(); private: void onDataAdded(int index); void onDataRemoved(int index); QMetaMethod propertyChangedMetaMethod() const; const MapBaseQObject *m_map; QHash m_roles; QHash m_objectProperties; QHash m_signalIndexToProperties; private: // Prevent leaf-classes from default constructing as we want to enforce // them passing us a context or explicit nullptrs. AbstractModel() {} }; class CardModel : public AbstractModel { Q_OBJECT public: explicit CardModel(QObject *parent = nullptr); }; class SinkModel : public AbstractModel { Q_OBJECT Q_PROPERTY(QPulseAudio::Sink *defaultSink READ defaultSink NOTIFY defaultSinkChanged) Q_PROPERTY(QPulseAudio::Sink *preferredSink READ preferredSink NOTIFY preferredSinkChanged) public: enum ItemRole { SortByDefaultRole = PulseObjectRole + 1 }; Q_ENUMS(ItemRole) explicit SinkModel(QObject *parent = nullptr); Sink *defaultSink() const; Sink *preferredSink() const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; -signals: +Q_SIGNALS: void defaultSinkChanged(); void preferredSinkChanged(); private: void sinkAdded(int index); void sinkRemoved(int index); void updatePreferredSink(); Sink *findPreferredSink() const; Sink *m_preferredSink; }; class SinkInputModel : public AbstractModel { Q_OBJECT public: explicit SinkInputModel(QObject *parent = nullptr); }; class SourceModel : public AbstractModel { Q_OBJECT Q_PROPERTY(QPulseAudio::Source *defaultSource READ defaultSource NOTIFY defaultSourceChanged) public: enum ItemRole { SortByDefaultRole = PulseObjectRole + 1 }; Q_ENUMS(ItemRole) explicit SourceModel(QObject *parent = nullptr); Source *defaultSource() const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; -signals: +Q_SIGNALS: void defaultSourceChanged(); }; class SourceOutputModel : public AbstractModel { Q_OBJECT public: explicit SourceOutputModel(QObject *parent = nullptr); }; class StreamRestoreModel : public AbstractModel { Q_OBJECT public: explicit StreamRestoreModel(QObject *parent = nullptr); }; class ModuleModel : public AbstractModel { Q_OBJECT public: explicit ModuleModel(QObject *parent = nullptr); }; } // QPulseAudio #endif // PULSEAUDIO_H diff --git a/src/pulseobject.h b/src/pulseobject.h index 4aa2cf9..208ff94 100644 --- a/src/pulseobject.h +++ b/src/pulseobject.h @@ -1,83 +1,83 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PULSEOBJECT_H #define PULSEOBJECT_H #include "debug.h" #include #include namespace QPulseAudio { class Context; class PulseObject : public QObject { Q_OBJECT Q_PROPERTY(quint32 index READ index CONSTANT) Q_PROPERTY(QString iconName READ iconName CONSTANT) Q_PROPERTY(QVariantMap properties READ properties NOTIFY propertiesChanged) public: template void updatePulseObject(PAInfo *info) { m_index = info->index; m_properties.clear(); void *it = nullptr; while (const char *key = pa_proplist_iterate(info->proplist, &it)) { Q_ASSERT(key); const char *value = pa_proplist_gets(info->proplist, key); if (!value) { qCDebug(PLASMAPA) << "property" << key << "not a string"; continue; } Q_ASSERT(value); m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value)); } - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } quint32 index() const; QString iconName() const; QVariantMap properties() const; -signals: +Q_SIGNALS: void propertiesChanged(); protected: explicit PulseObject(QObject *parent); ~PulseObject() override; Context *context() const; quint32 m_index; QVariantMap m_properties; private: // Ensure that we get properly parented. PulseObject(); }; } // QPulseAudio #endif // PULSEOBJECT_H diff --git a/src/qml/globalactioncollection.cpp b/src/qml/globalactioncollection.cpp index c99cae3..38ffd78 100644 --- a/src/qml/globalactioncollection.cpp +++ b/src/qml/globalactioncollection.cpp @@ -1,70 +1,70 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "globalactioncollection.h" #include GlobalAction::GlobalAction(QObject *parent) : QAction(parent) { } GlobalActionCollection::GlobalActionCollection() { } QString GlobalActionCollection::name() const { return m_name; } void GlobalActionCollection::setName(const QString &name) { m_name = name; - emit nameChanged(); + Q_EMIT nameChanged(); } QString GlobalActionCollection::displayName() const { return m_displayName; } void GlobalActionCollection::setDisplayName(const QString &displayName) { m_displayName = displayName; - emit displayNameChanged(); + Q_EMIT displayNameChanged(); } void GlobalActionCollection::componentComplete() { - foreach (QObject *item, children()) { + Q_FOREACH (QObject *item, children()) { GlobalAction *action = qobject_cast(item); if (!action) { continue; } action->setProperty("componentName", m_name); action->setProperty("componentDisplayName", m_displayName); KGlobalAccel::setGlobalShortcut(action, action->shortcuts()); } QQuickItem::componentComplete(); } diff --git a/src/qml/globalactioncollection.h b/src/qml/globalactioncollection.h index 57248cb..7cd6530 100644 --- a/src/qml/globalactioncollection.h +++ b/src/qml/globalactioncollection.h @@ -1,60 +1,60 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef GLOBALACTIONCOLLECTION_H #define GLOBALACTIONCOLLECTION_H #include #include class GlobalAction : public QAction { Q_OBJECT public: explicit GlobalAction(QObject *parent = nullptr); }; class GlobalActionCollection : public QQuickItem { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) public: GlobalActionCollection(); QString name() const; void setName(const QString &name); QString displayName() const; void setDisplayName(const QString &displayName); -signals: +Q_SIGNALS: void nameChanged(); void displayNameChanged(); protected: void componentComplete() final; private: QString m_name; QString m_displayName; }; #endif // GLOBALACTIONCOLLECTION_H diff --git a/src/qml/volumefeedback.h b/src/qml/volumefeedback.h index 9c58f34..27263c9 100644 --- a/src/qml/volumefeedback.h +++ b/src/qml/volumefeedback.h @@ -1,43 +1,43 @@ /* Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef VOLUMEFEEDBACK_H #define VOLUMEFEEDBACK_H #include #include class VolumeFeedback : public QObject { Q_OBJECT Q_PROPERTY(bool valid READ isValid CONSTANT) public: explicit VolumeFeedback(QObject *parent = nullptr); ~VolumeFeedback() override; bool isValid() const; -public slots: +public Q_SLOTS: void play(quint32 sinkIndex); }; #endif // VOLUMEFEEDBACK_H diff --git a/src/qml/volumeosd.h b/src/qml/volumeosd.h index 3c3f2e6..53f08b9 100644 --- a/src/qml/volumeosd.h +++ b/src/qml/volumeosd.h @@ -1,38 +1,38 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef VOLUMEOSD_H #define VOLUMEOSD_H #include class VolumeOSD : public QObject { Q_OBJECT public: explicit VolumeOSD(QObject *parent = nullptr); -public slots: +public Q_SLOTS: void show(int percent); void showMicrophone(int percent); void showText(const QString &iconName, const QString &text); }; #endif // VOLUMEOSD_H diff --git a/src/server.cpp b/src/server.cpp index 5df8431..602c05d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,123 +1,123 @@ /* Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "server.h" #include "context.h" #include "sink.h" #include "source.h" #include "debug.h" namespace QPulseAudio { Server::Server(Context *context) : QObject(context) , m_defaultSink(nullptr) , m_defaultSource(nullptr) { Q_ASSERT(context); connect(&context->sinks(), &MapBaseQObject::added, this, &Server::updateDefaultDevices); connect(&context->sinks(), &MapBaseQObject::removed, this, &Server::updateDefaultDevices); connect(&context->sources(), &MapBaseQObject::added, this, &Server::updateDefaultDevices); connect(&context->sources(), &MapBaseQObject::removed, this, &Server::updateDefaultDevices); } Sink *Server::defaultSink() const { return m_defaultSink; } void Server::setDefaultSink(Sink *sink) { Q_ASSERT(sink); Context::instance()->setDefaultSink(sink->name()); } Source *Server::defaultSource() const { return m_defaultSource; } void Server::setDefaultSource(Source *source) { Q_ASSERT(source); Context::instance()->setDefaultSource(source->name()); } void Server::reset() { if (m_defaultSink) { m_defaultSink = nullptr; - emit defaultSinkChanged(m_defaultSink); + Q_EMIT defaultSinkChanged(m_defaultSink); } if (m_defaultSource) { m_defaultSource = nullptr; - emit defaultSourceChanged(m_defaultSource); + Q_EMIT defaultSourceChanged(m_defaultSource); } } void Server::update(const pa_server_info *info) { m_defaultSinkName = QString::fromUtf8(info->default_sink_name); m_defaultSourceName = QString::fromUtf8(info->default_source_name); updateDefaultDevices(); } template static Type *findByName(const Map &map, const QString &name) { Type *out = nullptr; if (name.isEmpty()) { return out; } QMapIterator it(map); while (it.hasNext()) { it.next(); out = it.value(); if (out->name() == name) { return out; } } qCWarning(PLASMAPA) << "No object for name" << name; return out; } void Server::updateDefaultDevices() { Sink *sink = findByName(Context::instance()->sinks().data(), m_defaultSinkName); Source *source = findByName(Context::instance()->sources().data(), m_defaultSourceName); if (m_defaultSink != sink) { qCDebug(PLASMAPA) << "Default sink changed" << sink; m_defaultSink = sink; - emit defaultSinkChanged(m_defaultSink); + Q_EMIT defaultSinkChanged(m_defaultSink); } if (m_defaultSource != source) { qCDebug(PLASMAPA) << "Default source changed" << source; m_defaultSource = source; - emit defaultSourceChanged(m_defaultSource); + Q_EMIT defaultSourceChanged(m_defaultSource); } } } // QPulseAudio diff --git a/src/server.h b/src/server.h index dfd713f..bf896d7 100644 --- a/src/server.h +++ b/src/server.h @@ -1,65 +1,65 @@ /* Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef SERVER_H #define SERVER_H #include #include namespace QPulseAudio { class Sink; class Source; class Context; class Server : public QObject { Q_OBJECT public: explicit Server(Context *context); Sink *defaultSink() const; void setDefaultSink(Sink *sink); Source *defaultSource() const; void setDefaultSource(Source *source); void reset(); void update(const pa_server_info *info); -signals: +Q_SIGNALS: void defaultSinkChanged(Sink *sink); void defaultSourceChanged(Source *source); private: void updateDefaultDevices(); QString m_defaultSinkName; QString m_defaultSourceName; Sink *m_defaultSink; Source *m_defaultSource; }; } // QPulseAudio #endif // CONTEXT_H diff --git a/src/sink.h b/src/sink.h index 99a6c74..115d702 100644 --- a/src/sink.h +++ b/src/sink.h @@ -1,59 +1,59 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef SINK_H #define SINK_H #include "device.h" #include #include namespace QPulseAudio { class Sink : public Device { Q_OBJECT public: explicit Sink(QObject *parent); virtual ~Sink(); void update(const pa_sink_info *info); void setVolume(qint64 volume) override; void setMuted(bool muted) override; void setActivePortIndex(quint32 port_index) override; void setChannelVolume(int channel, qint64 volume) override; bool isDefault() const override; void setDefault(bool enable) override; -public slots: +public Q_SLOTS: void testChannel(const QString &name); private: pa_channel_position_t channelNameToPosition(const QString &name); QString positionToChannelName(pa_channel_position_t position); QString positionAsString(pa_channel_position_t pos); }; } // QPulseAudio #endif // SINK_H diff --git a/src/sinkinput.cpp b/src/sinkinput.cpp index d0fcb98..147e60b 100644 --- a/src/sinkinput.cpp +++ b/src/sinkinput.cpp @@ -1,62 +1,62 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "sinkinput.h" #include "context.h" namespace QPulseAudio { SinkInput::SinkInput(QObject *parent) : Stream(parent) { } void SinkInput::update(const pa_sink_input_info *info) { updateStream(info); if (m_deviceIndex != info->sink) { m_deviceIndex = info->sink; - emit deviceIndexChanged(); + Q_EMIT deviceIndexChanged(); } } void SinkInput::setDeviceIndex(quint32 deviceIndex) { context()->setGenericDeviceForStream(index(), deviceIndex, &pa_context_move_sink_input_by_index); } void SinkInput::setVolume(qint64 volume) { context()->setGenericVolume(index(), -1, volume, cvolume(), &pa_context_set_sink_input_volume); } void SinkInput::setMuted(bool muted) { context()->setGenericMute(index(), muted, &pa_context_set_sink_input_mute); } void SinkInput::setChannelVolume(int channel, qint64 volume) { context()->setGenericVolume(index(), channel, volume, cvolume(), &pa_context_set_sink_input_volume); } } // QPulseAudio diff --git a/src/sourceoutput.cpp b/src/sourceoutput.cpp index f44242e..ad0011f 100644 --- a/src/sourceoutput.cpp +++ b/src/sourceoutput.cpp @@ -1,62 +1,62 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "sourceoutput.h" #include "context.h" namespace QPulseAudio { SourceOutput::SourceOutput(QObject *parent) : Stream(parent) { } void SourceOutput::update(const pa_source_output_info *info) { updateStream(info); if (m_deviceIndex != info->source) { m_deviceIndex = info->source; - emit deviceIndexChanged(); + Q_EMIT deviceIndexChanged(); } } void SourceOutput::setDeviceIndex(quint32 deviceIndex) { context()->setGenericDeviceForStream(index(), deviceIndex, &pa_context_move_source_output_by_index); } void SourceOutput::setVolume(qint64 volume) { context()->setGenericVolume(index(), -1, volume, cvolume(), &pa_context_set_source_output_volume); } void SourceOutput::setMuted(bool muted) { context()->setGenericMute(index(), muted, &pa_context_set_source_output_mute); } void SourceOutput::setChannelVolume(int channel, qint64 volume) { context()->setGenericVolume(index(), channel, volume, cvolume(), &pa_context_set_source_output_volume); } } // QPulseAudio diff --git a/src/stream.h b/src/stream.h index 6ad4638..0aa1a5c 100644 --- a/src/stream.h +++ b/src/stream.h @@ -1,108 +1,108 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef STREAM_H #define STREAM_H #include #include #include "volumeobject.h" #include "pulseobject.h" #include "context.h" // Properties need fully qualified classes even with pointers. #include "client.h" namespace QPulseAudio { class Stream : public VolumeObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QPulseAudio::Client *client READ client NOTIFY clientChanged) Q_PROPERTY(bool virtualStream READ isVirtualStream NOTIFY virtualStreamChanged) Q_PROPERTY(quint32 deviceIndex READ deviceIndex WRITE setDeviceIndex NOTIFY deviceIndexChanged) Q_PROPERTY(bool corked READ isCorked NOTIFY corkedChanged) public: template void updateStream(const PAInfo *info) { updateVolumeObject(info); if (m_name != QString::fromUtf8(info->name)) { m_name = QString::fromUtf8(info->name); - emit nameChanged(); + Q_EMIT nameChanged(); } if (m_hasVolume != info->has_volume) { m_hasVolume = info->has_volume; - emit hasVolumeChanged(); + Q_EMIT hasVolumeChanged(); } if (m_volumeWritable != info->volume_writable) { m_volumeWritable = info->volume_writable; - emit isVolumeWritableChanged(); + Q_EMIT isVolumeWritableChanged(); } if (m_clientIndex != info->client) { m_clientIndex = info->client; - emit clientChanged(); + Q_EMIT clientChanged(); } if (m_virtualStream != (info->client == PA_INVALID_INDEX)) { m_virtualStream = info->client == PA_INVALID_INDEX; - emit virtualStreamChanged(); + Q_EMIT virtualStreamChanged(); } if (m_corked != info->corked) { m_corked = info->corked; - emit corkedChanged(); + Q_EMIT corkedChanged(); } } QString name() const; Client *client() const; bool isVirtualStream() const; quint32 deviceIndex() const; bool isCorked() const; virtual void setDeviceIndex(quint32 deviceIndex) = 0; -signals: +Q_SIGNALS: void nameChanged(); void clientChanged(); void virtualStreamChanged(); void deviceIndexChanged(); void corkedChanged(); protected: explicit Stream(QObject *parent); ~Stream() override; quint32 m_deviceIndex; private: QString m_name; quint32 m_clientIndex; bool m_virtualStream; bool m_corked; }; } // QPulseAudio #endif // STREAM_H diff --git a/src/streamrestore.cpp b/src/streamrestore.cpp index 46fa0c6..3f8eaeb 100644 --- a/src/streamrestore.cpp +++ b/src/streamrestore.cpp @@ -1,201 +1,201 @@ /* Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "streamrestore.h" #include "context.h" #include "debug.h" namespace QPulseAudio { StreamRestore::StreamRestore(quint32 index, const QVariantMap &properties, QObject *parent) : PulseObject(parent) , m_muted(false) { memset(&m_volume, 0, sizeof(m_volume)); memset(&m_channelMap, 0, sizeof(m_channelMap)); m_index = index; m_properties = properties; } void StreamRestore::update(const pa_ext_stream_restore_info *info) { m_cache.valid = false; const QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { m_name = infoName; - emit nameChanged(); + Q_EMIT nameChanged(); } const QString infoDevice = QString::fromUtf8(info->device); if (m_device != infoDevice) { m_device = infoDevice; - emit deviceChanged(); + Q_EMIT deviceChanged(); } if (m_muted != info->mute) { m_muted = info->mute; - emit mutedChanged(); + Q_EMIT mutedChanged(); } if (memcmp(&m_volume, &info->volume, sizeof(pa_cvolume)) != 0) { m_volume = info->volume; - emit volumeChanged(); - emit channelVolumesChanged(); + Q_EMIT volumeChanged(); + Q_EMIT channelVolumesChanged(); } if (memcmp(&m_channelMap, &info->channel_map, sizeof(pa_channel_map)) != 0) { m_channels.clear(); m_channels.reserve(info->channel_map.channels); for (int i = 0; i < info->channel_map.channels; ++i) { m_channels << QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i])); } m_channelMap = info->channel_map; - emit channelsChanged(); + Q_EMIT channelsChanged(); } } QString StreamRestore::name() const { return m_name; } QString StreamRestore::device() const { return m_device; } void StreamRestore::setDevice(const QString &device) { if (m_cache.valid) { if (m_cache.device != device) { writeChanges(m_cache.volume, m_cache.muted, device); } } else { if (m_device != device) { writeChanges(m_volume, m_muted, device); } } } qint64 StreamRestore::volume() const { return m_volume.values[0]; } void StreamRestore::setVolume(qint64 volume) { pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; vol.channels = 1; vol.values[0] = volume; if (m_cache.valid) { writeChanges(vol, m_cache.muted, m_cache.device); } else { writeChanges(vol, m_muted, m_device); } } bool StreamRestore::isMuted() const { return m_muted; } void StreamRestore::setMuted(bool muted) { if (m_cache.valid) { if (m_cache.muted != muted) { writeChanges(m_cache.volume, muted, m_cache.device); } } else { if (m_muted != muted) { writeChanges(m_volume, muted, m_device); } } } bool StreamRestore::hasVolume() const { return true; } bool StreamRestore::isVolumeWritable() const { return true; } QStringList StreamRestore::channels() const { return m_channels; } QList StreamRestore::channelVolumes() const { QList ret; ret.reserve(m_volume.channels); for (int i = 0; i < m_volume.channels; ++i) { ret << m_volume.values[i]; } return ret; } void StreamRestore::setChannelVolume(int channel, qint64 volume) { Q_ASSERT(channel >= 0 && channel < m_volume.channels); pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; vol.values[channel] = volume; if (m_cache.valid) { writeChanges(vol, m_cache.muted, m_cache.device); } else { writeChanges(vol, m_muted, m_device); } } quint32 StreamRestore::deviceIndex() const { return PA_INVALID_INDEX; } void StreamRestore::setDeviceIndex(quint32 deviceIndex) { Q_UNUSED(deviceIndex); qCWarning(PLASMAPA) << "Not implemented"; } void StreamRestore::writeChanges(const pa_cvolume &volume, bool muted, const QString &device) { const QByteArray nameData = m_name.toUtf8(); const QByteArray deviceData = device.toUtf8(); pa_ext_stream_restore_info info; info.name = nameData.constData(); info.channel_map.channels = 1; info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO; info.volume = volume; info.device = deviceData.isEmpty() ? nullptr : deviceData.constData(); info.mute = muted; m_cache.valid = true; m_cache.volume = volume; m_cache.muted = muted; m_cache.device = device; context()->streamRestoreWrite(&info); } } // QPulseAudio diff --git a/src/streamrestore.h b/src/streamrestore.h index 7131e1c..d6c5539 100644 --- a/src/streamrestore.h +++ b/src/streamrestore.h @@ -1,100 +1,100 @@ /* Copyright 2016 David Rosca This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef STREAMRESTORE_H #define STREAMRESTORE_H #include "pulseobject.h" #include namespace QPulseAudio { class StreamRestore : public PulseObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString device READ device WRITE setDevice NOTIFY deviceChanged) Q_PROPERTY(qint64 volume READ volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) Q_PROPERTY(bool hasVolume READ hasVolume CONSTANT) Q_PROPERTY(bool volumeWritable READ isVolumeWritable CONSTANT) Q_PROPERTY(QStringList channels READ channels NOTIFY channelsChanged) Q_PROPERTY(QList channelVolumes READ channelVolumes NOTIFY channelVolumesChanged) Q_PROPERTY(quint32 deviceIndex READ deviceIndex WRITE setDeviceIndex NOTIFY deviceIndexChanged) public: StreamRestore(quint32 index, const QVariantMap &properties, QObject *parent); void update(const pa_ext_stream_restore_info *info); QString name() const; QString device() const; void setDevice(const QString &device); qint64 volume() const; void setVolume(qint64 volume); bool isMuted() const; void setMuted(bool muted); bool hasVolume() const; bool isVolumeWritable() const; QStringList channels() const; QList channelVolumes() const; quint32 deviceIndex() const; void setDeviceIndex(quint32 deviceIndex); Q_INVOKABLE void setChannelVolume(int channel, qint64 volume); -signals: +Q_SIGNALS: void nameChanged(); void deviceChanged(); void volumeChanged(); void mutedChanged(); void channelsChanged(); void channelVolumesChanged(); void deviceIndexChanged(); private: void writeChanges(const pa_cvolume &volume, bool muted, const QString &device); QString m_name; QString m_device; pa_cvolume m_volume; pa_channel_map m_channelMap; QStringList m_channels; bool m_muted; struct { bool valid = false; pa_cvolume volume; bool muted; QString device; } m_cache; }; } // QPulseAudio #endif // STREAMRESTORE_H diff --git a/src/volumeobject.h b/src/volumeobject.h index b3204b1..4208610 100644 --- a/src/volumeobject.h +++ b/src/volumeobject.h @@ -1,101 +1,101 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef VOLUMEOBJECT_H #define VOLUMEOBJECT_H #include #include "pulseobject.h" namespace QPulseAudio { class VolumeObject : public PulseObject { Q_OBJECT Q_PROPERTY(qint64 volume READ volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) Q_PROPERTY(bool hasVolume READ hasVolume NOTIFY hasVolumeChanged) Q_PROPERTY(bool volumeWritable READ isVolumeWritable NOTIFY isVolumeWritableChanged) Q_PROPERTY(QStringList channels READ channels NOTIFY channelsChanged) Q_PROPERTY(QList channelVolumes READ channelVolumes NOTIFY channelVolumesChanged) public: explicit VolumeObject(QObject *parent); ~VolumeObject() override; template void updateVolumeObject(PAInfo *info) { updatePulseObject(info); if (m_muted != info->mute) { m_muted = info->mute; - emit mutedChanged(); + Q_EMIT mutedChanged(); } if (!pa_cvolume_equal(&m_volume, &info->volume)) { m_volume = info->volume; - emit volumeChanged(); - emit channelVolumesChanged(); + Q_EMIT volumeChanged(); + Q_EMIT channelVolumesChanged(); } QStringList infoChannels; infoChannels.reserve(info->channel_map.channels); for (int i = 0; i < info->channel_map.channels; ++i) { infoChannels << QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i])); } if (m_channels != infoChannels) { m_channels = infoChannels; - emit channelsChanged(); + Q_EMIT channelsChanged(); } } qint64 volume() const; virtual void setVolume(qint64 volume) = 0; bool isMuted() const; virtual void setMuted(bool muted) = 0; bool hasVolume() const; bool isVolumeWritable() const; QStringList channels() const; QList channelVolumes() const; Q_INVOKABLE virtual void setChannelVolume(int channel, qint64 volume) = 0; -signals: +Q_SIGNALS: void volumeChanged(); void mutedChanged(); void hasVolumeChanged(); void isVolumeWritableChanged(); void channelsChanged(); void channelVolumesChanged(); protected: pa_cvolume cvolume() const; pa_cvolume m_volume; bool m_muted; bool m_hasVolume; bool m_volumeWritable; QStringList m_channels; }; } // QPulseAudio #endif // VOLUMEOBJECT_H