Commit 6fd87793 authored by Kevin Whitaker's avatar Kevin Whitaker

Add missing connect statements. Implement workaround for QTBUG-48008.

parent 10b41d66
......@@ -17,6 +17,7 @@
#include "mprisinterface.h"
#include <qcryptographichash.h>
#include <QtDBus/QDBusMessage>
MPRISInterface::MPRISInterface(QObject* parent) : QDBusAbstractAdaptor(parent)
{
......@@ -57,27 +58,52 @@ QStringList MPRISInterface::SupportedUriSchemes()
MPRISPlayerInterface::MPRISPlayerInterface(MiniMediaPlayer *player,QObject* parent) : QDBusAbstractAdaptor(parent),player(player)
{
//Connected Changed values from media player.
connect(player,&MiniMediaPlayer::playStateChanged,this,&MPRISPlayerInterface::mediaStateChanged);
connect(player,&MiniMediaPlayer::playlistChanged,this,&MPRISPlayerInterface::mediaPlaylistChanged);
connect(player,&MiniMediaPlayer::mediaVolumeChanged,this,&MPRISPlayerInterface::mediaVolumeChanged);
connect(player,&MiniMediaPlayer::trackPositionChanged,this,&MPRISPlayerInterface::mediaPositionChanged);
}
void MPRISPlayerInterface::dbusUpdate(QVariantMap changed)
{
//Workaround for qt dbus not sending this signal
QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2","org.freedesktop.DBus.Properties","PropertiesChanged");
msg << "org.mpris.MediaPlayer2.Player";
msg << changed;
msg << QStringList();
QDBusConnection::sessionBus().send(msg);
}
void MPRISPlayerInterface::mediaPositionChanged(qint64 position)
{
emit positionChanged(Position());
QVariantMap map;
map.insert("Position",Position());
dbusUpdate(map);
}
void MPRISPlayerInterface::mediaStateChanged(QMediaPlayer::State state)
void MPRISPlayerInterface::mediaStateChanged(bool isPlaying)
{
emit playbackStatusChanged(PlaybackStatus());
QVariantMap map;
map.insert("PlaybackStatus",PlaybackStatus());
dbusUpdate(map);
}
void MPRISPlayerInterface::mediaVolumeChanged(int volume)
{
emit volumeChanged(Volume());
QVariantMap map;
map.insert("Volume",Volume());
dbusUpdate(map);
}
void MPRISPlayerInterface::mediaPlaylistChanged(QStringList playlist)
{
emit metadataChanged(Metadata());
QVariantMap map;
map.insert("Metadata",Metadata());
dbusUpdate(map);
}
bool MPRISPlayerInterface::CanControl()
......@@ -186,12 +212,15 @@ void MPRISPlayerInterface::setVolume(double volume)
player->setVolume(volume*100); //QMediaPlayer uses 0 to 100
}
QMap<QString, QDBusVariant> MPRISPlayerInterface::Metadata()
QVariantMap MPRISPlayerInterface::Metadata()
{
QMap<QString,QDBusVariant> map;
map.insert("mpris:trackid",QDBusVariant("org.mpris.MediaPlayer2.simplecast.Player."+QString(QCryptographicHash::hash(player->getTrackNames()[0].toUtf8(),QCryptographicHash::Algorithm::Md5))));
map.insert("mpris:length",QDBusVariant(player->getTrackDuration()*1000));
map.insert("xesam:title",QDBusVariant(player->getTrackNames()[0]));
QVariantMap map;
if(player->getTrackNames().size() > 0)
{
map.insert("mpris:trackid",QVariant("org.mpris.MediaPlayer2.simplecast.Player."+QString(QCryptographicHash::hash(player->getTrackNames()[0].toUtf8(),QCryptographicHash::Algorithm::Md5))));
map.insert("mpris:length",QVariant(player->getTrackDuration()*1000));
map.insert("xesam:title",QVariant(player->getTrackNames()[0]));
}
return map;
}
......
......@@ -56,7 +56,7 @@ class MPRISPlayerInterface : public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Interface","org.mpris.MediaPlayer2.Player")
Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus NOTIFY playbackStatusChanged)
Q_PROPERTY(double Rate READ Rate WRITE setRate)
Q_PROPERTY(QMap<QString,QDBusVariant>Metadata READ Metadata NOTIFY metadataChanged)
Q_PROPERTY(QVariantMap Metadata READ Metadata NOTIFY metadataChanged)
Q_PROPERTY(double Volume READ Volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(qlonglong Position READ Position NOTIFY positionChanged)
Q_PROPERTY(double MinimumRate READ MinimumRate)
......@@ -72,7 +72,7 @@ public:
QString PlaybackStatus();
double Rate();
void setRate(double rate) {};
QMap<QString,QDBusVariant> Metadata();
QVariantMap Metadata();
double Volume();
void setVolume(double volume);
qlonglong Position();
......@@ -97,16 +97,17 @@ public slots:
signals:
void Seeked(qlonglong position); //Not used
void playbackStatusChanged(QString status);
void metadataChanged(QMap<QString,QDBusVariant> metadata);
void metadataChanged(QVariantMap metadata);
void volumeChanged(double volume);
void positionChanged(qlonglong position);
private slots:
void mediaStateChanged(QMediaPlayer::State state);
void mediaStateChanged(bool isPlaying);
void mediaPositionChanged(qint64 position);
void mediaVolumeChanged(int volume);
void mediaPlaylistChanged(QStringList playlist);
private:
MiniMediaPlayer *player;
void dbusUpdate(QVariantMap changed);
};
#endif // MPRISINTERFACE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment