2
* This file is part of uvolman.dfiloni
4
* Copyright (C) 2016 Devid Antonio Filoni https://launchpad.net/~d.filoni
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "PulseRestoreEntry.h"
21
#include "DBusRestoreEntryVolume.h"
23
#include <QDBusInterface>
26
#include <QDBusMetaType>
29
#define PA_VOLUME_NORM 65536
30
Q_DECLARE_METATYPE(DBusRestoreEntryVolume)
32
PulseRestoreEntry::PulseRestoreEntry(QObject *parent, const QString &peerConnName, const QString &entryPath)
36
qDBusRegisterMetaType<DBusRestoreEntryVolume>();
40
name = getProperty("Name").toString();
41
device = getProperty("Device").toString();
45
const QDBusArgument &volumeArg = getProperty("Volume").value<QDBusArgument>();
46
volumeArg.beginArray();
47
while (!volumeArg.atEnd())
51
volume = tmp/PA_VOLUME_NORM;
53
isMute = getProperty("Mute").toBool();
56
connected = conn.connect("org.PulseAudio1",
58
"org.PulseAudio.Ext.StreamRestore1.RestoreEntry",
61
SLOT(VolumeUpdated(QDBusMessage)));
63
qWarning() << "[FAILED] PulseStreamRestore[message=signalConnFailed; signal=VolumeUpdated; entry=" << path << "]: " << conn.lastError();
67
QString PulseRestoreEntry::getName()
72
double PulseRestoreEntry::getVolume()
77
bool PulseRestoreEntry::setVolume(const double &newVolume)
79
if (newVolume != volume)
81
if (setProperty("Volume", QVariant::fromValue(newVolume)))
84
Q_EMIT volumeChanged(QVariant::fromValue(volume));
87
return volume == newVolume;
90
QVariant PulseRestoreEntry::getProperty(const QString &property)
93
QDBusInterface interface (
96
"org.freedesktop.DBus.Properties",
100
if (interface.isValid()) {
101
QDBusReply<QDBusVariant> reply = interface.call(
103
"org.PulseAudio.Ext.StreamRestore1.RestoreEntry",
105
if (reply.isValid()) {
106
return reply.value().variant();
109
qWarning() << "[FAILED] PulseRestoreEntry[path=" << path << "; property=" << property << "; action=GET]: " << reply.error();
114
bool PulseRestoreEntry::setProperty(const QString &property, const QVariant &value)
116
QDBusInterface interface (
119
"org.freedesktop.DBus.Properties",
123
if (interface.isValid())
126
if (property == "Volume")
128
uint tmp = (value.toDouble()*PA_VOLUME_NORM);
129
DBusRestoreEntryVolume volume = DBusRestoreEntryVolume(((uint) 0), tmp);
130
QDBusArgument argument;
131
argument.beginArray(qMetaTypeId<DBusRestoreEntryVolume>() );
133
argument.endStructure();
135
newValue = QVariant::fromValue(QDBusVariant(QVariant::fromValue(argument)));
138
newValue = QVariant::fromValue(QDBusVariant(value));
140
QDBusMessage message = interface.call("Set",
141
"org.PulseAudio.Ext.StreamRestore1.RestoreEntry",
143
QVariant::fromValue(newValue));
144
if (message.type() == QDBusMessage::ErrorMessage)
145
qWarning() << "[FAILED] PulseRestoreEntry[path=" << path << "; property=" << property << "; value=" << value << "; action=SET]: " << message.errorMessage();
147
return message.type() == QDBusMessage::ReplyMessage;
153
void PulseRestoreEntry::VolumeUpdated(const QDBusMessage &message)
155
qWarning() << "[PulseRestoreEntry#TODO] IMPLEMENT PARSING OF MESSAGE: " << message;
157
Q_EMIT volumeChanged(QVariant::fromValue(volume)); */