4
Kopete Now Listening To plugin
6
Copyright (c) 2012 by Volker Härtel <cyberbeat@gmx.de>
8
Kopete (c) 2002,2003 by the Kopete developers <kopete-devel@kde.org>
11
This class abstracts the interface to mpris by
12
implementing NLMediaPlayer
14
*************************************************************************
16
* This program is free software; you can redistribute it and/or modify *
17
* it under the terms of the GNU General Public License as published by *
18
* the Free Software Foundation; either version 2 of the License, or *
19
* (at your option) any later version. *
21
*************************************************************************
27
#include <QtDBus/QtDBus>
32
NLmpris2::NLmpris2() : NLMediaPlayer()
35
m_name = "MPRIS2 compatible player";
44
void NLmpris2::update()
48
if( m_client == 0 || !m_client->isValid() ) {
50
const QDBusConnection& sessionConn( QDBusConnection::sessionBus() );
52
// Check if the connection is successful
53
if( sessionConn.isConnected() )
55
const QDBusConnectionInterface* bus = sessionConn.interface();
56
const QDBusReply<QStringList>& reply( bus->registeredServiceNames() );
60
// Search for "org.mpris.MediaPlayer2" string
61
services = reply.value().filter( "org.mpris.MediaPlayer2" );
65
// If no service was found then return false and unlock the mutex
66
if( services.isEmpty() )
70
// Start the d-bus interface, needed to check the application status and make calls to it
75
m_client = new QDBusInterface( services.at(0), "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties" );
76
QDBusInterface dbusMprisRoot ( services.at(0), "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2");
78
// See if the application is registered.
79
if( !m_client->isValid() )
84
if ( !dbusMprisRoot.isValid() )
86
m_name = QString( "MPRIS2 compatible player" );
90
m_name = dbusMprisRoot.property( "Identity" ).toString();
94
// see if it's playing
95
QDBusReply <QVariant> mprisStatus = m_client->call ( "Get", "org.mpris.MediaPlayer2.Player", "PlaybackStatus" );
96
if (!mprisStatus.isValid())
100
m_playing = ( mprisStatus.value().toString() == "Playing" );
102
QDBusReply<QVariant> metaDataReply = m_client->call( "Get", "org.mpris.MediaPlayer2.Player", "Metadata" );
103
if ( !metaDataReply.isValid() )
107
if ( !metaDataReply.value().canConvert<QDBusArgument>() )
109
QVariantMap metaData;
110
QDBusArgument arg = metaDataReply.value().value<QDBusArgument>();
114
const QString newTrack = metaData["xesam:title"].toString();
116
if ( newTrack != m_track )
123
m_album = metaData["xesam:album"].toString();
126
m_artist = metaData["xesam:artist"].toString();