[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-07-21 23:15:15
Message-ID: 20110721231515.7CEE8AC86A () svn ! kde ! org
[Download RAW message or body]

SVN commit 1242596 by esken:

Retrieve volume change from DBUS/MPRIS Apps.

 M  +3 -0      CMakeLists.txt  
 M  +2 -2      backends/kmix-backends.cpp  
 M  +72 -32    backends/mixer_mpris2.cpp  
 M  +13 -3     backends/mixer_mpris2.h  
 M  +1 -1      backends/mixer_oss4.cpp  
 M  +2 -2      core/mixdevicecomposite.cpp  
 M  +11 -0     core/mixset.cpp  
 M  +3 -1      core/mixset.h  
 M  +2 -4      core/volume.cpp  
 M  +4 -2      dbus/dbusmixerwrapper.cpp  
 M  +2 -4      gui/mdwslider.cpp  
 M  +2 -2      gui/mixdevicewidget.cpp  
 M  +2 -2      gui/mixdevicewidget.h  
 M  +3 -5      gui/viewbase.cpp  


--- trunk/KDE/kdemultimedia/kmix/CMakeLists.txt #1242595:1242596
@@ -10,11 +10,14 @@
 
 
 add_definitions (${QT_DEFINITIONS} ${QT_QTDBUS_DEFINITIONS} ${KDE4_DEFINITIONS} )
+add_definitions(-DKDE_DEFAULT_DEBUG_AREA=67100)
+
 include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
 if(MSVC)
     include_directories( ${TAGLIB_INCLUDES} )
 endif(MSVC)
 
+
 configure_file (config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
 
 macro_display_feature_log()
--- trunk/KDE/kdemultimedia/kmix/backends/kmix-backends.cpp #1242595:1242596
@@ -125,7 +125,7 @@
     getDriverNameFunc *getDriverName;
 };
 
-// TODO encapsualte by #ifdef HAVE_DBUS
+// Possibly encapsualte by #ifdef HAVE_DBUS
 Mixer_Backend* MPRIS2_getMixer(Mixer *mixer, int device );
 QString MPRIS2_getDriverName();
 
@@ -148,7 +148,7 @@
     { ALSA_getMixer, ALSA_getDriverName },
 #endif
 
-    // TODO encapsualte by #ifdef HAVE_DBUS
+    // Possibly encapsualte by #ifdef HAVE_DBUS
     { MPRIS2_getMixer, MPRIS2_getDriverName },
 
 #if defined(OSS_MIXER)
--- trunk/KDE/kdemultimedia/kmix/backends/mixer_mpris2.cpp #1242595:1242596
@@ -61,8 +61,8 @@
   QList<QVariant> arg;
   arg.append(QString("org.mpris.MediaPlayer2.Player"));
   arg.append(QString("Volume"));
-  MPrisAppdata mad = apps.value(id);
-  QDBusMessage msg = mad.propertyIfc->callWithArgumentList(QDBus::Block, "Get", \
arg); +  MPrisAppdata* mad = apps.value(id);
+  QDBusMessage msg = mad->propertyIfc->callWithArgumentList(QDBus::Block, "Get", \
arg);  if ( msg.type() == QDBusMessage::ReplyMessage )
   {
     QList<QVariant> repl = msg.arguments();
@@ -100,17 +100,10 @@
   arg.append(QString("Volume"));
   arg << QVariant::fromValue(QDBusVariant(volFloat));
 
-  MPrisAppdata mad = apps.value(id);
-  QDBusMessage msg = mad.propertyIfc->callWithArgumentList(QDBus::NoBlock, "Set", \
                arg);
-  if ( msg.type() == QDBusMessage::ReplyMessage )
+    MPrisAppdata* mad = apps.value(id);
+    QDBusMessage msg = mad->propertyIfc->callWithArgumentList(QDBus::NoBlock, "Set", \
arg); +    if ( msg.type() == QDBusMessage::ErrorMessage )
   {
-    QList<QVariant> repl = msg.arguments();
-    if ( ! repl.isEmpty() )
-    {
-    }
-  }
-  else
-  {
     kError(67100) << "ERROR SET " << id << ": " << msg;
     return Mixer::ERR_WRITE;
   }
@@ -145,16 +138,16 @@
  **/
 int Mixer_MPRIS2::run()
 {
-  kDebug(67100) << "--- A ---------------------------------";
-       if (!QDBusConnection::sessionBus().isConnected()) {
-         kDebug() <<  "Cannot connect to the D-Bus session bus.\n"
+     QDBusConnection dbusConn = QDBusConnection::sessionBus();
+       if (! dbusConn.isConnected() )
+       {
+         kError(67100) <<  "Cannot connect to the D-Bus session bus.\n"
                  << "To start it, run:\n"
                   <<"\teval `dbus-launch --auto-syntax`\n";
 		  return Mixer::ERR_OPEN;
      }
      
   kDebug(67100) << "--- B ---------------------------------";
-     QDBusConnection dbusConn = QDBusConnection::sessionBus();
      QDBusReply<QStringList> repl = dbusConn.interface()->registeredServiceNames();
      
   kDebug(67100) << "--- C ---------------------------------";
@@ -184,26 +177,22 @@
 {
   int lastDot = busDestination.lastIndexOf('.');
   QString id = ( lastDot == -1 ) ? busDestination : busDestination.mid(lastDot+1); 
-  kDebug(67100) << "Get control of " << busDestination;
+  kDebug(67100) << "Get control of " << busDestination << "id=" << id;
 
 //  QDBusMessage query1 = QDBusMessage::createMethodCall(QString(busDestination), \
QString("/org/mpris/MediaPlayer2"), MPRIS_IFC2, QString("Raise"));  //  \
conn.call(query1, QDBus::NoBlock);  
   QDBusInterface *qdbiProps = new QDBusInterface(QString(busDestination), \
QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", conn, this);  
-  MPrisAppdata* app = new MPrisAppdata();
-  app->id = id;
-  app->propertyIfc = qdbiProps;
+  MPrisAppdata* mad = new MPrisAppdata();
+  mad->id = id;
+  mad->propertyIfc = qdbiProps;
   
-  apps.insert(id, *app);
+  apps.insert(id, mad);
   
   QList<QVariant> arg;
   arg.append(QString("org.mpris.MediaPlayer2"));
   arg.append(QString("Identity"));
-//  QDBusMessage query = QDBusMessage::createMethodCall(QString(busDestination), \
QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", \
                QString("Get"));
-//  query.setArguments(arg);
-//   QDBusMessage msg = conn.call(query, QDBus::Block, 1500);
-
   QDBusMessage msg = qdbiProps->callWithArgumentList(QDBus::Block, "Get", arg);
 
   //msg = conn.call(query, QDBus::Block, 5);
@@ -216,7 +205,7 @@
 	// We have to do some very ugly casting from QVariant to QDBusVariant to QVariant. \
This API totally sucks.  QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(qv);
 	QVariant result2 = dbusVariant.variant();
-	QString readableName = result2.toString();
+	QString readableName = result2.typeName();
 	
 	qDebug() << "REPLY " << result2.type() << ": " << readableName;
 	
@@ -228,7 +217,12 @@
 	md->addPlaybackVolume(*vol);
 	m_mixDevices.append( md );
 	
-	conn.connect("", QString("/org/mpris/MediaPlayer2"), \
"org.freedesktop.DBus.Properties", "PropertiesChanged", this, \
SLOT(volumeChanged(QString, QList<QVariant>)) ); +	conn.connect("", \
QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", \
"PropertiesChanged", mad, SLOT(volumeChangedIncoming(QString, QList<QVariant>)) ); \
+	connect(mad, SIGNAL(volumeChanged(MPrisAppdata* ,QString, QList<QVariant>)), this, \
SLOT(volumeChanged(MPrisAppdata* ,QString, QList<QVariant>)) ); +
+      
+	conn.connect("", QString("/org/mpris/MediaPlayer2"), \
"org.freedesktop.DBus.Properties", "PropertiesChanged", mad, \
SLOT(volumeChangedIncoming(QString,QVariantMap,QStringList)) ); +	
     }
   }
   else
@@ -237,8 +231,53 @@
   }
 }
 
+
+/**
+ * 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, QList< QVariant > msg)
+{
+ // emit volumeChanged( this, ifc, msg);
+}
+
+  void MPrisAppdata::volumeChangedIncoming(QString ifc,QVariantMap msg ,QStringList \
sl) +  {
+    kDebug() << "ZZZ " << ifc << "\nZZZ" << msg << "\nZZZ" << sl;
+    QMap<QString, QVariant>::iterator v = msg.find("Volume");
+    if (v != msg.end() )
+    {
+      kDebug() << "ZZZ=" << v.value();
+    }
+  }
+
+
+
+void Mixer_MPRIS2::volumeChanged(MPrisAppdata* mad, QString ifc, QList<QVariant> \
msg) +{
+  kDebug(67100) << "volumeChanged: " << mad->id << ": " << ifc << " (#" << \
msg.count()  << ")" << msg; +    if ( ! msg.isEmpty() )
+    {
+      QVariant qv = msg.at(0);
+	// We have to do some very ugly casting from QVariant to QDBusVariant to QVariant. \
This API totally sucks. +	QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(qv);
+	QVariant result2 = dbusVariant.variant();
+	QMap<QString,QVariant> qvm = result2.toMap();
+	kDebug() << "variant: " << qv.typeName() << "," << dbusVariant.variant().type() << \
"," << result2.typeName(); +	QVariant qvv = qvm["Volume"];
+	
+	
+	int volInt = qvv.toFloat() *100;
+
+	MixDevice * md = m_mixDevices.get(mad->id);
+	Volume& vol = md->playbackVolume();
+	vol.setVolume( Volume::LEFT, volInt);
+	md->playbackVolume().setVolume(vol);
+	kDebug(67100) << "REPLY " << qv << ":\n" << result2 << ":\n" << volInt << ":\n"<< \
vol; +    }
+
+}
+
 /*
-
 signal sender=:1.125 -> dest=(null destination) serial=503 \
path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; \
member=PropertiesChanged  string "org.mpris.MediaPlayer2.Player"
    array [
@@ -249,17 +288,18 @@
    ]
    array [
    ]
-
 */
 
 Mixer_MPRIS2::~Mixer_MPRIS2()
 {
+}
   
+MPrisAppdata::MPrisAppdata()
+{}
   
+MPrisAppdata::~MPrisAppdata()
+{}
   
-}
-
-
 QString Mixer_MPRIS2::getDriverName()
 {
 	return "MPRIS2";
--- trunk/KDE/kdemultimedia/kmix/backends/mixer_mpris2.h #1242595:1242596
@@ -9,11 +9,21 @@
 
 #include "mixer_backend.h"
 
-class MPrisAppdata
+class MPrisAppdata : public QObject
 {
+  Q_OBJECT 
 public:
+  MPrisAppdata();
+  ~MPrisAppdata();
   QString id;
   QDBusInterface* propertyIfc;
+
+public slots:
+  void volumeChangedIncoming(QString ifc, QList<QVariant> msg);
+  void volumeChangedIncoming(QString,QVariantMap,QStringList);
+  
+signals:
+  void volumeChanged(MPrisAppdata* mad, QString ifc, QList<QVariant> msg);
 };
 
 class Mixer_MPRIS2 : public Mixer_Backend
@@ -36,7 +46,7 @@
   virtual bool needsPolling() { return false; }
 
 public slots:
-  void volumeChanged(QString ifc, QList<QVariant> qvl) { kDebug(67100) << \
"volumeChanged: " << ifc << " : " << qvl; }; +  void volumeChanged(MPrisAppdata* mad, \
QString ifc, QList<QVariant> qvl);  
 private:
   int run();
@@ -45,7 +55,7 @@
   
   static QString getBusDestination(const QString& id);
   
-  QMap<QString,MPrisAppdata> apps;
+  QMap<QString,MPrisAppdata*> apps;
 };
 
 
--- trunk/KDE/kdemultimedia/kmix/backends/mixer_oss4.cpp #1242595:1242596
@@ -434,7 +434,7 @@
 					{
 						Volume vol(ext.maxvalue, ext.minvalue,
 									false, isCapture);
-						vol.addVolumeChannels(VolumeChannel(Volume::MLEFT));
+						vol.addVolumeChannel(VolumeChannel(Volume::MLEFT));
 
 						MixDevice* md = new MixDevice (_mixer,
 						                               QString::number(i),
--- trunk/KDE/kdemultimedia/kmix/core/mixdevicecomposite.cpp #1242595:1242596
@@ -30,8 +30,8 @@
 {
     setArtificial(true);
     _compositePlaybackVolume = new Volume( MixDeviceComposite::VolMax, 0, true, \
                false);
-    _compositePlaybackVolume->addVolumeChannels(Volume::MMAIN);
-//    _compositeCaptureVolume  = new Volume();
+    _compositePlaybackVolume->addVolumeChannel(Volume::LEFT);
+    _compositePlaybackVolume->addVolumeChannel(Volume::RIGHT);
 
     QListIterator<MixDevice*> it(mds);
     while ( it.hasNext()) {
--- trunk/KDE/kdemultimedia/kmix/core/mixset.cpp #1242595:1242596
@@ -65,3 +65,14 @@
     m_name = name;
 }
 
+MixDevice* MixSet::get(QString id)
+{
+  MixDevice* md = 0;
+  for(int i=0; i < count() ; i++ )
+  {
+    md = operator[](i);
+    if ( md->id() == id )
+      break;
+  }
+  return md;
+}
--- trunk/KDE/kdemultimedia/kmix/core/mixset.h #1242595:1242596
@@ -21,7 +21,7 @@
 #ifndef MixSet_h
 #define MixSet_h
 
-#include <QList>
+#include <QSet>
 
 #include "core/mixdevice.h"
 
@@ -34,6 +34,8 @@
       QString name() { return m_name; }
       void setName( const QString &name );
 
+      MixDevice* get(QString id);
+
    private:
       QString m_name;
 };
--- trunk/KDE/kdemultimedia/kmix/core/volume.cpp #1242595:1242596
@@ -142,12 +142,10 @@
 // @ compatibility
 void Volume::setVolume( ChannelID chid, long vol)
 {
-  if ( _volumesL.contains(chid))
-  {
     QMap<Volume::ChannelID, VolumeChannel>::iterator it = _volumesL.find(chid);
-//   kDebug(67100) << "sv; " << chid << " " <<  &(it.value()) << " at " << \
it.value().volume; +  if ( it != _volumesL.end())
+  {
   it.value().volume = vol;
-//   kDebug(67100) << "sv; " << chid << " " <<  &(it.value()) << " at " << \
it.value().volume;  }
 }
 
--- trunk/KDE/kdemultimedia/kmix/dbus/dbusmixerwrapper.cpp #1242595:1242596
@@ -51,8 +51,10 @@
 QStringList DBusMixerWrapper::controls()
 {
 	QStringList result;
-	for ( int i = 0; i < m_mixer->getMixSet().count(); i++ )
-		result.append( m_mixer->getMixSet()[i]->dbusPath() );
+	foreach ( MixDevice* md, m_mixer->getMixSet() )
+	{
+		result.append( md->dbusPath() );
+	}
 	return result;
 }
 
--- trunk/KDE/kdemultimedia/kmix/gui/mdwslider.cpp #1242595:1242596
@@ -970,13 +970,11 @@
 		long useVolume = vol.getVolume(chid);
 //		QWidget *labelAtSlider = ref_labels.at( i ); // TODO hide labels
 
-/*
-		if ( i==0 )
+/*		if ( i==0 )
 		{
 		  kDebug(67100) << "XXXX -------------------------";
 		}
-		  kDebug(67100) << "XXXX " << chid << " now at " << useVolume;
-*/
+		  kDebug(67100) << "XXXX " << chid << " now at " << useVolume;*/
 		slider->blockSignals( true );
 		slider->setValue( useVolume );
 		if ( slider->inherits( "KSmallSlider" ) )
--- trunk/KDE/kdemultimedia/kmix/gui/mixdevicewidget.cpp #1242595:1242596
@@ -99,8 +99,8 @@
 
 void MixDeviceWidget::volumeChange( int ) { /* is virtual */ }
 void MixDeviceWidget::setDisabled( bool ) { /* is virtual */ }
-void MixDeviceWidget::setVolume( int /*channel*/, int /*vol*/ ) { /* is virtual */ }
-void MixDeviceWidget::setVolume( Volume /*vol*/ ) { /* is virtual */ }
+//void MixDeviceWidget::setVolume( int /*channel*/, int /*vol*/ ) { /* is virtual */ \
} +//void MixDeviceWidget::setVolume( Volume /*vol*/ ) { /* is virtual */ }
 void MixDeviceWidget::update() { /* is virtual */ }
 void MixDeviceWidget::showContextMenu() { /* is virtual */ }
 void MixDeviceWidget::setColors( QColor , QColor , QColor ) { /* is virtual */ }
--- trunk/KDE/kdemultimedia/kmix/gui/mixdevicewidget.h #1242595:1242596
@@ -72,8 +72,8 @@
 
 protected slots:
     void volumeChange( int );
-    virtual void setVolume( int channel, int volume );
-    virtual void setVolume( Volume volume );
+//    virtual void setVolume( int channel, int volume );
+//    virtual void setVolume( Volume volume );
 
 protected:
 
--- trunk/KDE/kdemultimedia/kmix/gui/viewbase.cpp #1242595:1242596
@@ -115,12 +115,10 @@
 void ViewBase::createDeviceWidgets()
 {
     // create devices
-    for ( int i=0; i<_mixSet->count(); i++ )
+    foreach ( MixDevice* md, *_mixSet ) 
     {
-        MixDevice *mixDevice;
-        mixDevice = (*_mixSet)[i];
-        QWidget* mdw = add(mixDevice);
-        _mdws.append(mdw);
+        QWidget* mdw = add(md); // a) Let the View implementation do its work
+        _mdws.append(mdw); // b) Add it to the local list
     }
     // allow view to "polish" itself
     constructionFinished();


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

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