[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/kmix
From:       Christian Esken <esken () kde ! org>
Date:       2011-12-12 23:40:02
Message-ID: 20111212234002.BC9D3AC80E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1268427 by esken:

Show new MPRIS2 Streams (Stream hotplug)
CCBUGS: 288637

 M  +55 -15    backends/mixer_mpris2.cpp  
 M  +6 -5      backends/mixer_mpris2.h  
 M  +0 -6      core/volume.cpp  


--- trunk/KDE/kdemultimedia/kmix/backends/mixer_mpris2.cpp #1268426:1268427
@@ -62,13 +62,6 @@
 	return 0;
 }
 
-QString Mixer_MPRIS2::getBusDestination(const QString& id)
-{
-	return QString("org.mpris.MediaPlayer2.").append(id);
-}
-
-
-
 int Mixer_MPRIS2::mediaPlay(QString id)
 {
 	return mediaControl(id, "PlayPause");
@@ -141,6 +134,7 @@
 int Mixer_MPRIS2::writeVolumeToHW( const QString& id, MixDevice *md )
 {
 
+	qDebug() << "Shall send updated volume to MPRIS Player for " << id;
 	Volume& vol = md->playbackVolume();
 	double volFloat = 0;
 	if ( ! md->isMuted() )
@@ -198,26 +192,23 @@
 		return Mixer::ERR_OPEN;
 	}
 
-	kDebug(67100) << "--- B ---------------------------------";
+	this->dbusConnPtr = &dbusConn;
+
 	QDBusReply<QStringList> repl = \
dbusConn.interface()->registeredServiceNames();  
-	kDebug(67100) << "--- C ---------------------------------";
 	if ( repl.isValid() )
 	{
-		kDebug(67100) << "--- D ---------------------------------";
-
 		QStringList result = repl.value();
 		QString s;
 		foreach (  s , result )
 		{
 			if ( s.startsWith("org.mpris.MediaPlayer2") )
-			{
 				getMprisControl(dbusConn, s);
-
 			}
 		}
-	}
 
+	// Start listening for new Mediaplayers
+	dbusConn.connect("", QString("/org/freedesktop/DBus"), \
"org.freedesktop.DBus", "NameOwnerChanged", this, \
SLOT(newMediaPlayer(QString,QString,QString)) );  
 	return 0;
 }
@@ -282,9 +273,10 @@
 			m_mixDevices.append( md );
 
 			//	conn.connect("", QString("/org/mpris/MediaPlayer2"), \
"org.freedesktop.DBus.Properties", "PropertiesChanged", mad, \
                SLOT(volumeChangedIncoming(QString,QList<QVariant>)) );
-			conn.connect("", QString("/org/mpris/MediaPlayer2"), \
"org.freedesktop.DBus.Properties", "PropertiesChanged", mad, \
SLOT(volumeChangedIncoming(QString,QVariantMap,QStringList)) ); \
+			conn.connect(busDestination, QString("/org/mpris/MediaPlayer2"), \
"org.freedesktop.DBus.Properties", "PropertiesChanged", mad, \
SLOT(volumeChangedIncoming(QString,QVariantMap,QStringList)) );  \
connect(mad, SIGNAL(volumeChanged(MPrisAppdata*,double)), this, \
SLOT(volumeChanged(MPrisAppdata*,double)) );  
+			conn.connect(busDestination, QString("/Player"), \
"org.freedesktop.MediaPlayer", "TrackChange", mad, \
SLOT(trackChangedIncoming(QVariantMap)) );  }
 	}
 	else
@@ -294,18 +286,66 @@
 }
 
 
+
 /**
  * This slot is a simple proxy that enriches the DBUS signal with our \
                data, which especially contains the id of the MixDevice.
  */
+void Mixer_MPRIS2::newMediaPlayer(QString name, QString oldOwner, QString \
newOwner) +{
+	if (dbusConnPtr == 0)
+	{
+		kError() << "We see a new application is registering on DBUS, but we \
have no DBUS connection. This is most definitely weird."; +		return; // No \
DBUS connection. We should never enter this SLOT at all +	}
+
+	if ( name.startsWith("org.mpris.MediaPlayer2") )
+	{
+		kDebug() << "DO SOMETHING: " << name << "," << oldOwner << "," << \
newOwner; +		if ( oldOwner.isEmpty() && !newOwner.isEmpty())
+		{
+			kDebug() << "Mediaplayer registers: " << name;
+			QDBusConnection dbusConn = QDBusConnection::sessionBus();
+			getMprisControl(dbusConn, name);
+		    QMetaObject::invokeMethod(this,
+		                              "controlsReconfigured",
+		                              Qt::QueuedConnection,
+		                              Q_ARG(QString, _mixer->id()));
+		}
+		else if ( !oldOwner.isEmpty() && newOwner.isEmpty())
+			kDebug() << "Mediaplayer unregisters: " << name;
+	}
+
+}
+
+/**
+ * This slot is a simple proxy that enriches the DBUS signal with our \
data, which especially contains the id of the MixDevice. + */
+void MPrisAppdata::trackChangedIncoming(QVariantMap msg)
+{
+	kDebug() << "Track changed";
+}
+
+/**
+ * This slot is a simple proxy that enriches the DBUS signal with our \
data, which especially contains the id of the MixDevice. + */
 void MPrisAppdata::volumeChangedIncoming(QString ifc,QVariantMap msg \
,QStringList sl)  {
 	QMap<QString, QVariant>::iterator v = msg.find("Volume");
 	if (v != msg.end() )
 	{
+		kDebug(67100) << "volumeChanged incoming: !!!!!!!!!" ;
 		double volDouble = v.value().toDouble();
 		emit volumeChanged( this, volDouble);
 	}
+
+	v = msg.find("PlaybackStatus");
+	if (v != msg.end() )
+	{
+		QString playbackStatus = v.value().toString();
+		// "Stopped", "Playing", "Paused"
+		kDebug() << "PlaybackStatus is now " << playbackStatus;
 }
+}
 
 
 
--- trunk/KDE/kdemultimedia/kmix/backends/mixer_mpris2.h #1268426:1268427
@@ -41,13 +41,15 @@
   QDBusInterface* playerIfc;
 
 public slots:
-//  void volumeChangedIncoming(QString ifc, QList<QVariant> msg);
+  void trackChangedIncoming(QVariantMap msg);
   void volumeChangedIncoming(QString,QVariantMap,QStringList);
   
 signals:
   void volumeChanged(MPrisAppdata* mad, double);
 };
 
+
+
 class Mixer_MPRIS2 : public Mixer_Backend
 {
   Q_OBJECT
@@ -73,14 +75,13 @@
 
 public slots:
   void volumeChanged(MPrisAppdata* mad, double);
+  void newMediaPlayer(QString name, QString oldOwner, QString newOwner);
 
 private:
   int run();
-//  static char MPRIS_IFC2[40];
+
+  QDBusConnection* dbusConnPtr;
   static QString MPRIS_IFC2;
-  
-  static QString getBusDestination(const QString& id);
-  
   QMap<QString,MPrisAppdata*> apps;
 };
 
--- trunk/KDE/kdemultimedia/kmix/core/volume.cpp #1268426:1268427
@@ -63,12 +63,6 @@
 
 VolumeChannel::VolumeChannel() {}
 
-// @Deprecated  use method without chmask
-// Volume::Volume( ChannelMask chmask, long maxVolume, long minVolume, \
                bool hasSwitch, bool isCapture  )
-// {
-//     init(chmask, maxVolume, minVolume, hasSwitch, isCapture );
-// }
-
 Volume::Volume(long maxVolume, long minVolume, bool hasSwitch, bool \
isCapture )  {
 	init((ChannelMask)0, maxVolume, minVolume, hasSwitch, isCapture );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic