OSDN Git Service

kmix: indent and format
authorIvailo Monev <xakepa10@gmail.com>
Thu, 25 Feb 2021 07:08:37 +0000 (09:08 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 25 Feb 2021 07:17:22 +0000 (09:17 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kmix/backends/mixer_alsa9.cpp
kmix/backends/mixer_mpris2.cpp

index 96ca4a0..b84acd1 100644 (file)
 //#define ALSA_SWITCH_DEBUG
 //#define KMIX_ALSA_VOLUME_DEBUG
 
-Mixer_Backend*
-ALSA_getMixer(Mixer *mixer, int device )
+Mixer_Backend* ALSA_getMixer(Mixer *mixer, int device )
 {
+    Mixer_Backend *l_mixer;
 
-   Mixer_Backend *l_mixer;
-
-   l_mixer = new Mixer_ALSA(mixer,  device );
-   return l_mixer;
+    l_mixer = new Mixer_ALSA(mixer,  device );
+    return l_mixer;
 }
 
 Mixer_ALSA::Mixer_ALSA( Mixer* mixer, int device ) : Mixer_Backend(mixer,  device )
 {
-   m_fds = 0;
-   _handle = 0;
-   ctl_handle = 0;
-   _initialUpdate = true;
+    m_fds = 0;
+    _handle = 0;
+    ctl_handle = 0;
+    _initialUpdate = true;
 }
 
 Mixer_ALSA::~Mixer_ALSA()
 {
-   close();
+    close();
 }
 
 int Mixer_ALSA::identify( snd_mixer_selem_id_t *sid )
@@ -119,9 +117,8 @@ int Mixer_ALSA::open()
     snd_mixer_elem_t *elem;
     snd_mixer_selem_id_t *sid;
     bool USE_ALSO_ALLOCA = true; //  TODO remove alloca() when adding "delete sid" in the destructor or close()
-    if (USE_ALSO_ALLOCA)
-    {
-       snd_mixer_selem_id_alloca( &sid );
+    if (USE_ALSO_ALLOCA) {
+        snd_mixer_selem_id_alloca( &sid );
     }
 
     // Determine a card name
@@ -145,8 +142,7 @@ int Mixer_ALSA::open()
     }
     // Run a loop over all controls of the card
     unsigned int idx = 0;
-    for ( elem = snd_mixer_first_elem( _handle ); elem; elem = snd_mixer_elem_next( elem ) )
-    {
+    for ( elem = snd_mixer_first_elem( _handle ); elem; elem = snd_mixer_elem_next( elem ) ) {
         // If element is not active, just skip
         if ( ! snd_mixer_selem_is_active ( elem ) ) {
             continue;
@@ -174,11 +170,9 @@ int Mixer_ALSA::open()
         if ( snd_mixer_selem_is_enumerated(elem) ) {
             // --- Enumerated ---
             addEnumerated(elem, enumList);
-        }
-        else
-        {
-                       volPlay    = addVolume(elem, false);
-                       volCapture = addVolume(elem, true );
+        } else {
+            volPlay    = addVolume(elem, false);
+            volCapture = addVolume(elem, true );
         }
 
 
@@ -193,14 +187,13 @@ int Mixer_ALSA::open()
             readableName += idxString;
         }
 
-               // There can be an Enum-Control with the same name as a regular control. So we append a ".[cp]enum" prefix to always create a unique ID
+        // There can be an Enum-Control with the same name as a regular control. So we append a ".[cp]enum" prefix to always create a unique ID
         QString finalMixdeviceID = mdID;
-        if ( ! enumList.isEmpty() )
-        {
-               if (snd_mixer_selem_is_enum_capture ( elem ) )
-                       finalMixdeviceID = mdID + ".cenum"; // capture enum
-               else
-                       finalMixdeviceID = mdID + ".penum"; // playback enum
+        if ( ! enumList.isEmpty() ) {
+            if (snd_mixer_selem_is_enum_capture ( elem ) )
+                finalMixdeviceID = mdID + ".cenum"; // capture enum
+            else
+                finalMixdeviceID = mdID + ".penum"; // playback enum
         }
 
         m_id2numHash[finalMixdeviceID] = idx;
@@ -209,62 +202,51 @@ int Mixer_ALSA::open()
         mixer_sid_list.append( sid );
         idx++;
 
-
         MixDevice* mdNew = new MixDevice(_mixer, finalMixdeviceID, readableName, ct );
 
-        if ( volPlay    != 0      )
-        {
-               mdNew->addPlaybackVolume(*volPlay);
+        if ( volPlay != 0) {
+            mdNew->addPlaybackVolume(*volPlay);
             delete volPlay;
         }
-        if ( volCapture != 0      )
-        {
-               mdNew->addCaptureVolume (*volCapture);
+        if ( volCapture != 0) {
+            mdNew->addCaptureVolume (*volCapture);
             delete volCapture;
         }
-               if ( !enumList.isEmpty()  )
-               {
-                       mdNew->addEnums(enumList);
+        if ( !enumList.isEmpty()) {
+            mdNew->addEnums(enumList);
             qDeleteAll(enumList); // clear temporary list
-               }
+        }
 
-               std::shared_ptr<MixDevice> md = mdNew->addToPool();
+        std::shared_ptr<MixDevice> md = mdNew->addToPool();
         m_mixDevices.append( md );
-         
 
         // --- Recommended master ----------------------------------------
-        if ( md->playbackVolume().hasVolume() )
-        {
-          if ( mdID == "Master:0" && masterChosenQuality < 100 ) {
+        if ( md->playbackVolume().hasVolume() ) {
+            if ( mdID == "Master:0" && masterChosenQuality < 100 ) {
 //              kDebug() << "Setting m_recommendedMaster to " << mdID;
-              m_recommendedMaster = md;
-              masterChosenQuality = 100;
-          }
-          else if ( mdID == "PCM:0" && masterChosenQuality < 80) {
+                m_recommendedMaster = md;
+                masterChosenQuality = 100;
+            } else if ( mdID == "PCM:0" && masterChosenQuality < 80) {
 //              kDebug() << "Setting m_recommendedMaster to " << mdID;
-              m_recommendedMaster = md;
-              masterChosenQuality = 80;
-          }
-          else if ( mdID == "Front:0" && masterChosenQuality < 60) {
+                m_recommendedMaster = md;
+                masterChosenQuality = 80;
+                } else if ( mdID == "Front:0" && masterChosenQuality < 60) {
 //              kDebug() << "Setting m_recommendedMaster to " << mdID;
-              m_recommendedMaster = md;
-              masterChosenQuality = 60;
-          }
-          else if ( mdID == "DAC:0" && masterChosenQuality < 50) {
+                m_recommendedMaster = md;
+                masterChosenQuality = 60;
+            } else if ( mdID == "DAC:0" && masterChosenQuality < 50) {
 //              kDebug() << "Setting m_recommendedMaster to " << mdID;
-              m_recommendedMaster = md;
-              masterChosenQuality = 50;
-          }
-          else if ( mdID == "Headphone:0" && masterChosenQuality < 40) {
+                m_recommendedMaster = md;
+                masterChosenQuality = 50;
+            } else if ( mdID == "Headphone:0" && masterChosenQuality < 40) {
 //              kDebug() << "Setting m_recommendedMaster to " << mdID;
-              m_recommendedMaster = md;
-              masterChosenQuality = 40;
-          }
-          else if ( mdID == "Master Mono:0" && masterChosenQuality < 30) {
+                m_recommendedMaster = md;
+                masterChosenQuality = 40;
+            } else if ( mdID == "Master Mono:0" && masterChosenQuality < 30) {
 //              kDebug() << "Setting m_recommendedMaster to " << mdID;
-              m_recommendedMaster = md;
-              masterChosenQuality = 30;
-          }
+                m_recommendedMaster = md;
+                masterChosenQuality = 30;
+            }
         }
     } // for all elems
 
@@ -289,27 +271,22 @@ int Mixer_ALSA::openAlsaDevice(const QString& devName)
     QString probeMessage;
     probeMessage += "Trying ALSA Device '" + devName + "': ";
 
-    if ( ( err = snd_ctl_open ( &ctl_handle, devName.toAscii().data(), 0 ) ) < 0 )
-    {
-       if (Mixer_ALSA::warnOnce)
-       {
-               Mixer_ALSA::warnOnce = false;
-               kDebug() << probeMessage << "not found: snd_ctl_open err=" << snd_strerror(err);
-       }
+    if ( ( err = snd_ctl_open ( &ctl_handle, devName.toAscii().data(), 0 ) ) < 0 ) {
+        if (Mixer_ALSA::warnOnce) {
+            Mixer_ALSA::warnOnce = false;
+            kDebug() << probeMessage << "not found: snd_ctl_open err=" << snd_strerror(err);
+        }
         return Mixer::ERR_OPEN;
     }
 
-
     // Mixer name
     snd_ctl_card_info_t *hw_info;
     snd_ctl_card_info_alloca(&hw_info);
-    if ( ( err = snd_ctl_card_info ( ctl_handle, hw_info ) ) < 0 )
-    {
-       if (Mixer_ALSA::warnOnce)
-       {
-               Mixer_ALSA::warnOnce = false;
-               kDebug() << probeMessage << "not found: snd_ctl_card_info err=" << snd_strerror(err);
-       }
+    if ( ( err = snd_ctl_card_info ( ctl_handle, hw_info ) ) < 0 ) {
+        if (Mixer_ALSA::warnOnce) {
+            Mixer_ALSA::warnOnce = false;
+            kDebug() << probeMessage << "not found: snd_ctl_card_info err=" << snd_strerror(err);
+        }
         //_stateMessage = errorText( Mixer::ERR_READ );
         snd_ctl_close( ctl_handle );
         return Mixer::ERR_READ;
@@ -322,44 +299,36 @@ int Mixer_ALSA::openAlsaDevice(const QString& devName)
     snd_ctl_close( ctl_handle );
 
     /* open mixer device */
-    if ( ( err = snd_mixer_open ( &_handle, 0 ) ) < 0 )
-    {
-       if (Mixer_ALSA::warnOnce)
-       {
-               Mixer_ALSA::warnOnce = false;
-               kDebug() << probeMessage << "not found: snd_mixer_open err=" << snd_strerror(err);
-       }
+    if ( ( err = snd_mixer_open ( &_handle, 0 ) ) < 0 ) {
+        if (Mixer_ALSA::warnOnce) {
+            Mixer_ALSA::warnOnce = false;
+            kDebug() << probeMessage << "not found: snd_mixer_open err=" << snd_strerror(err);
+        }
         _handle = 0;
         return Mixer::ERR_OPEN; // if we cannot open the mixer, we have no devices
     }
 
-    if ( ( err = snd_mixer_attach ( _handle, devName.toAscii().data() ) ) < 0 )
-    {
-       if (Mixer_ALSA::warnOnce)
-       {
-               Mixer_ALSA::warnOnce = false;
-               kDebug() << probeMessage << "not found: snd_mixer_attach err=" << snd_strerror(err);
-       }
+    if ( ( err = snd_mixer_attach ( _handle, devName.toAscii().data() ) ) < 0 ) {
+        if (Mixer_ALSA::warnOnce) {
+            Mixer_ALSA::warnOnce = false;
+            kDebug() << probeMessage << "not found: snd_mixer_attach err=" << snd_strerror(err);
+        }
         return Mixer::ERR_OPEN;
     }
 
-    if ( ( err = snd_mixer_selem_register ( _handle, NULL, NULL ) ) < 0 )
-    {
-       if (Mixer_ALSA::warnOnce)
-       {
-               Mixer_ALSA::warnOnce = false;
-               kDebug() << probeMessage << "not found: snd_mixer_selem_register err=" << snd_strerror(err);
-       }
+    if ( ( err = snd_mixer_selem_register ( _handle, NULL, NULL ) ) < 0 ) {
+        if (Mixer_ALSA::warnOnce) {
+            Mixer_ALSA::warnOnce = false;
+            kDebug() << probeMessage << "not found: snd_mixer_selem_register err=" << snd_strerror(err);
+        }
         return Mixer::ERR_READ;
     }
 
-    if ( ( err = snd_mixer_load ( _handle ) ) < 0 )
-    {
-       if (Mixer_ALSA::warnOnce)
-       {
-               Mixer_ALSA::warnOnce = false;
-               kDebug() << probeMessage << "not found: snd_mixer_load err=" << snd_strerror(err);
-       }
+    if ( ( err = snd_mixer_load ( _handle ) ) < 0 ) {
+        if (Mixer_ALSA::warnOnce) {
+            Mixer_ALSA::warnOnce = false;
+            kDebug() << probeMessage << "not found: snd_mixer_load err=" << snd_strerror(err);
+        }
         close();
         return Mixer::ERR_READ;
     }
@@ -374,71 +343,66 @@ int Mixer_ALSA::openAlsaDevice(const QString& devName)
 /* setup for select on stdin and the mixer fd */
 int Mixer_ALSA::setupAlsaPolling()
 {
-       // --- Step 1: Retrieve FD's from ALSALIB
-       int err;
-       int countNew = 0;
-       if ((countNew = snd_mixer_poll_descriptors_count(_handle)) < 0) {
-               kDebug() << "Mixer_ALSA::poll() , snd_mixer_poll_descriptors_count() err=" <<  countNew << "\n";
-               return Mixer::ERR_OPEN;
-       }
-
-       //if ( countNew != m_sns.size() )
-       if (true)
-       {
-               // Redo everything if count of FD's have changed (emulating alsamixer behaviour here)
-                while (!m_sns.isEmpty())
-                    delete m_sns.takeFirst();
-
-
-               free(m_fds);
-               m_fds = (struct pollfd*)calloc(countNew, sizeof(struct pollfd));
-               if (m_fds == NULL) {
-                       kDebug() << "Mixer_ALSA::poll() , calloc() = null" << "\n";
-                       return Mixer::ERR_OPEN;
-               }
-
-
-               if ((err = snd_mixer_poll_descriptors(_handle, m_fds, countNew)) < 0) {
-                       kDebug() << "Mixer_ALSA::poll() , snd_mixer_poll_descriptors_count() err=" <<  err << "\n";
-                       return Mixer::ERR_OPEN;
-               }
-               if (err != countNew) {
-                       kDebug() << "Mixer_ALSA::poll() , snd_mixer_poll_descriptors_count() err=" << err << " m_count=" <<  countNew << "\n";
-                       return Mixer::ERR_OPEN;
-               }
-
-
-               // --- Step 2: Create QSocketNotifier's for the FD's
-               //m_sns = new QSocketNotifier*[m_count];
-               for ( int i = 0; i < countNew; ++i )
-               {
-                       //kDebug() << "socket " << i;
-                       QSocketNotifier* qsn = new QSocketNotifier(m_fds[i].fd, QSocketNotifier::Read);
-                       m_sns.append(qsn);
-                       connect(m_sns[i], SIGNAL(activated(int)), SLOT(readSetFromHW()), Qt::QueuedConnection);
-               }
-       }
-
-       return 0;
+    // --- Step 1: Retrieve FD's from ALSALIB
+    int err;
+    int countNew = 0;
+    if ((countNew = snd_mixer_poll_descriptors_count(_handle)) < 0) {
+        kDebug() << "Mixer_ALSA::poll() , snd_mixer_poll_descriptors_count() err=" <<  countNew << "\n";
+        return Mixer::ERR_OPEN;
+    }
+
+    //if ( countNew != m_sns.size() )
+    if (true) {
+        // Redo everything if count of FD's have changed (emulating alsamixer behaviour here)
+        while (!m_sns.isEmpty())
+            delete m_sns.takeFirst();
+
+        free(m_fds);
+        m_fds = (struct pollfd*)calloc(countNew, sizeof(struct pollfd));
+        if (m_fds == NULL) {
+            kDebug() << "Mixer_ALSA::poll() , calloc() = null" << "\n";
+            return Mixer::ERR_OPEN;
+        }
+
+
+        if ((err = snd_mixer_poll_descriptors(_handle, m_fds, countNew)) < 0) {
+            kDebug() << "Mixer_ALSA::poll() , snd_mixer_poll_descriptors_count() err=" <<  err << "\n";
+            return Mixer::ERR_OPEN;
+        }
+        if (err != countNew) {
+            kDebug() << "Mixer_ALSA::poll() , snd_mixer_poll_descriptors_count() err=" << err << " m_count=" <<  countNew << "\n";
+            return Mixer::ERR_OPEN;
+        }
+
+        // --- Step 2: Create QSocketNotifier's for the FD's
+        //m_sns = new QSocketNotifier*[m_count];
+        for ( int i = 0; i < countNew; ++i ) {
+            //kDebug() << "socket " << i;
+            QSocketNotifier* qsn = new QSocketNotifier(m_fds[i].fd, QSocketNotifier::Read);
+            m_sns.append(qsn);
+            connect(m_sns[i], SIGNAL(activated(int)), SLOT(readSetFromHW()), Qt::QueuedConnection);
+        }
+    }
+
+    return 0;
 }
 
 void Mixer_ALSA::addEnumerated(snd_mixer_elem_t *elem, QList<QString*>& enumList)
 {
-   // --- get Enum names START ---
-   int numEnumitems = snd_mixer_selem_get_enum_items(elem);
-   if ( numEnumitems > 0 ) {
-      // OK. no error
-      for (int iEnum = 0; iEnum<numEnumitems; iEnum++ ) {
-         char buffer[100];
-         int ret = snd_mixer_selem_get_enum_item_name(elem, iEnum, 99, buffer);
-         buffer[99] = 0; // protect from overflow
-         if ( ret == 0 ) {
-            QString* enumName = new QString(buffer); // these QString* items are deleted above (search fo "clear temporary list")
-            enumList.append( enumName);
-         } // enumName could be read successfully
-      } // for all enum items of this device
-   } // no error in reading enum list
-   else {
+    // --- get Enum names START ---
+    int numEnumitems = snd_mixer_selem_get_enum_items(elem);
+    if ( numEnumitems > 0 ) {
+        // OK. no error
+        for (int iEnum = 0; iEnum<numEnumitems; iEnum++ ) {
+            char buffer[100];
+            int ret = snd_mixer_selem_get_enum_item_name(elem, iEnum, 99, buffer);
+            buffer[99] = 0; // protect from overflow
+            if ( ret == 0 ) {
+                QString* enumName = new QString(buffer); // these QString* items are deleted above (search fo "clear temporary list")
+                enumList.append( enumName);
+            } // enumName could be read successfully
+        } // for all enum items of this device
+   } else {  // no error in reading enum list
       // 0 items or Error code => ignore this entry
    }
 }
@@ -452,8 +416,7 @@ Volume* Mixer_ALSA::addVolume(snd_mixer_elem_t *elem, bool capture)
     // Add volumes
     if ( !capture && snd_mixer_selem_has_playback_volume(elem) ) {
         snd_mixer_selem_get_playback_volume_range( elem, &minVolume, &maxVolume );
-    }
-    else if ( capture && snd_mixer_selem_has_capture_volume(elem) ) {
+    } else if ( capture && snd_mixer_selem_has_capture_volume(elem) ) {
        snd_mixer_selem_get_capture_volume_range( elem, &minVolume, &maxVolume );
     }
 
@@ -472,30 +435,29 @@ Volume* Mixer_ALSA::addVolume(snd_mixer_elem_t *elem, bool capture)
     if ( hasVolume || hasSwitch ) {
         //kDebug() << "Add somthing with chn=" << chn << ", capture=" << capture;
         vol = new Volume( maxVolume, minVolume, hasSwitch, capture);
-       
-           // Add volumes
-      if ( !capture && snd_mixer_selem_has_playback_volume(elem) ) {
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_FRONT_LEFT  )) vol->addVolumeChannel(VolumeChannel(Volume::LEFT));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_FRONT_RIGHT )) vol->addVolumeChannel(VolumeChannel(Volume::RIGHT));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_FRONT_CENTER)) vol->addVolumeChannel(VolumeChannel(Volume::CENTER));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_REAR_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDLEFT));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_REAR_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDRIGHT));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_REAR_CENTER )) vol->addVolumeChannel(VolumeChannel(Volume::REARCENTER));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_WOOFER      )) vol->addVolumeChannel(VolumeChannel(Volume::WOOFER));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_SIDE_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDELEFT));
-         if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_SIDE_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDERIGHT));
-      }
-      else if ( capture && snd_mixer_selem_has_capture_volume(elem) ) {
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_FRONT_LEFT  )) vol->addVolumeChannel(VolumeChannel(Volume::LEFT));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_FRONT_RIGHT )) vol->addVolumeChannel(VolumeChannel(Volume::RIGHT));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_FRONT_CENTER)) vol->addVolumeChannel(VolumeChannel(Volume::CENTER));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_REAR_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDLEFT));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_REAR_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDRIGHT));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_REAR_CENTER )) vol->addVolumeChannel(VolumeChannel(Volume::REARCENTER));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_WOOFER      )) vol->addVolumeChannel(VolumeChannel(Volume::WOOFER));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_SIDE_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDELEFT));
-         if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_SIDE_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDERIGHT));
-      }
+
+        // Add volumes
+        if ( !capture && snd_mixer_selem_has_playback_volume(elem) ) {
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_FRONT_LEFT  )) vol->addVolumeChannel(VolumeChannel(Volume::LEFT));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_FRONT_RIGHT )) vol->addVolumeChannel(VolumeChannel(Volume::RIGHT));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_FRONT_CENTER)) vol->addVolumeChannel(VolumeChannel(Volume::CENTER));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_REAR_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDLEFT));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_REAR_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDRIGHT));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_REAR_CENTER )) vol->addVolumeChannel(VolumeChannel(Volume::REARCENTER));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_WOOFER      )) vol->addVolumeChannel(VolumeChannel(Volume::WOOFER));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_SIDE_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDELEFT));
+            if ( snd_mixer_selem_has_playback_channel(elem,SND_MIXER_SCHN_SIDE_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDERIGHT));
+        } else if ( capture && snd_mixer_selem_has_capture_volume(elem) ) {
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_FRONT_LEFT  )) vol->addVolumeChannel(VolumeChannel(Volume::LEFT));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_FRONT_RIGHT )) vol->addVolumeChannel(VolumeChannel(Volume::RIGHT));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_FRONT_CENTER)) vol->addVolumeChannel(VolumeChannel(Volume::CENTER));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_REAR_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDLEFT));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_REAR_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::SURROUNDRIGHT));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_REAR_CENTER )) vol->addVolumeChannel(VolumeChannel(Volume::REARCENTER));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_WOOFER      )) vol->addVolumeChannel(VolumeChannel(Volume::WOOFER));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_SIDE_LEFT   )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDELEFT));
+            if ( snd_mixer_selem_has_capture_channel(elem,SND_MIXER_SCHN_SIDE_RIGHT  )) vol->addVolumeChannel(VolumeChannel(Volume::REARSIDERIGHT));
+        }
     }
 
     return vol;
@@ -504,56 +466,52 @@ Volume* Mixer_ALSA::addVolume(snd_mixer_elem_t *elem, bool capture)
 
 void Mixer_ALSA::deinitAlsaPolling()
 {
-       if ( m_fds )
-               free( m_fds );
-       m_fds = 0;
+    if ( m_fds )
+        free( m_fds );
+    m_fds = 0;
 
-       while (!m_sns.isEmpty())
-               delete m_sns.takeFirst();
+    while (!m_sns.isEmpty())
+        delete m_sns.takeFirst();
 }
 
 int
 Mixer_ALSA::close()
 {
-//     kDebug() << "close " << this;
-
-  int ret=0;
-  m_isOpen = false;
-
-  if ( ctl_handle != 0)
-  {
-         //snd_ctl_close( ctl_handle );
-         ctl_handle = 0;
-  }
-
-  if ( _handle != 0 )
-  {
-    //kDebug() << "IN  Mixer_ALSA::close()";
-    snd_mixer_free ( _handle );
-    if ( ( ret = snd_mixer_detach ( _handle, devName.toAscii().data() ) ) < 0 )
-    {
-        kDebug() << "snd_mixer_detach err=" << snd_strerror(ret);
-    }
-    int ret2 = 0;
-    if ( ( ret2 = snd_mixer_close ( _handle ) ) < 0 )
-    {
-        kDebug() << "snd_mixer_close err=" << snd_strerror(ret2);
-       if ( ret == 0 ) ret = ret2; // no error before => use current error code
+    // kDebug() << "close " << this;
+
+    int ret=0;
+    m_isOpen = false;
+
+    if ( ctl_handle != 0) {
+        //snd_ctl_close( ctl_handle );
+        ctl_handle = 0;
     }
 
-    _handle = 0;
-    //kDebug() << "OUT Mixer_ALSA::close()";
+    if ( _handle != 0 ) {
+        //kDebug() << "IN  Mixer_ALSA::close()";
+        snd_mixer_free ( _handle );
+        if ( ( ret = snd_mixer_detach ( _handle, devName.toAscii().data() ) ) < 0 ) {
+            kDebug() << "snd_mixer_detach err=" << snd_strerror(ret);
+        }
+        int ret2 = 0;
+        if ( ( ret2 = snd_mixer_close ( _handle ) ) < 0 ) {
+            kDebug() << "snd_mixer_close err=" << snd_strerror(ret2);
+            if ( ret == 0 )
+                ret = ret2; // no error before => use current error code
+        }
 
-  }
+        _handle = 0;
+        //kDebug() << "OUT Mixer_ALSA::close()";
+    }
 
-  mixer_elem_list.clear();
-  mixer_sid_list.clear();
-  m_id2numHash.clear();
+    mixer_elem_list.clear();
+    mixer_sid_list.clear();
+    m_id2numHash.clear();
 
-  deinitAlsaPolling();
+    deinitAlsaPolling();
 
-  closeCommon();
-  return ret;
+    closeCommon();
+    return ret;
 }
 
 
@@ -562,43 +520,44 @@ Mixer_ALSA::close()
  * @par idx Index to query. For any invalid index (including -1) returns a 0 control.
  */
 snd_mixer_elem_t* Mixer_ALSA::getMixerElem(int idx) {
-       snd_mixer_elem_t* elem = 0;
-        if ( ! m_isOpen ) return elem; // unplugging guard
-
-       if ( idx == -1 ) {
-               return elem;
-       }
-       if ( int( mixer_sid_list.count() ) > idx ) {
-               snd_mixer_selem_id_t * sid = mixer_sid_list[ idx ];
-               // The next line (hopefully) only finds selem's, not elem's.
-               elem = snd_mixer_find_selem(_handle, sid);
-
-               if ( elem == 0 ) {
-                       // !! Check, whether the warning should be omitted. Probably
-                       //    Route controls are non-simple elements.
-                       kDebug() << "Error finding mixer element " << idx;
-               }
-       }
-       return elem;
+    snd_mixer_elem_t* elem = 0;
+    if ( ! m_isOpen )
+        return elem; // unplugging guard
+
+    if ( idx == -1 ) {
+        return elem;
+    }
+    if ( int( mixer_sid_list.count() ) > idx ) {
+        snd_mixer_selem_id_t * sid = mixer_sid_list[ idx ];
+        // The next line (hopefully) only finds selem's, not elem's.
+        elem = snd_mixer_find_selem(_handle, sid);
+
+        if ( elem == 0 ) {
+            // !! Check, whether the warning should be omitted. Probably
+            //    Route controls are non-simple elements.
+            kDebug() << "Error finding mixer element " << idx;
+        }
+    }
+    return elem;
 
 /*
  I would have liked to use the following trivial implementation instead of the
  code above. But it will also return elem's. which are not selem's. As there is
  no way to check an elem's type (e.g. elem->type == SND_MIXER_ELEM_SIMPLE), callers
  of getMixerElem() cannot check the type. :-(
-       snd_mixer_elem_t* elem = mixer_elem_list[ devnum ];
-       return elem;
+    snd_mixer_elem_t* elem = mixer_elem_list[ devnum ];
+    return elem;
  */
 }
 
 int Mixer_ALSA::id2num(const QString& id) {
-   //kDebug() << "id2num() id=" << id;
-   int num = -1;
-   if ( m_id2numHash.contains(id) ) {
-      num = m_id2numHash[id];
-   }
-   //kDebug() << "id2num() num=" << num;
-   return num;
+    //kDebug() << "id2num() id=" << id;
+    int num = -1;
+    if ( m_id2numHash.contains(id) ) {
+        num = m_id2numHash[id];
+    }
+    //kDebug() << "id2num() num=" << num;
+    return num;
 }
 
 bool Mixer_ALSA::prepareUpdateFromHW() {
@@ -618,9 +577,8 @@ bool Mixer_ALSA::prepareUpdateFromHW() {
 
         unsigned short revents;
 
-        if (snd_mixer_poll_descriptors_revents(_handle, m_fds, m_sns.size(), &revents) >= 0)
-        {
-        //kDebug() << "Mixer_ALSA::prepareUpdate() 6\n";
+        if (snd_mixer_poll_descriptors_revents(_handle, m_fds, m_sns.size(), &revents) >= 0) {
+            //kDebug() << "Mixer_ALSA::prepareUpdate() 6\n";
 
             if (revents & POLLNVAL) {
                 /* Bug 127294 shows, that we receive POLLNVAL when the user
@@ -667,8 +625,7 @@ bool Mixer_ALSA::isRecsrcHW( const QString& id )
 #ifdef ALSA_SWITCH_DEBUG
             kDebug() << "has_switch joined: #" << devnum << " >>> " << swLeft << " : " << isCurrentlyRecSrc;
 #endif
-        }
-        else {
+        } else {
             int swRight;
             snd_mixer_selem_get_capture_switch( elem, SND_MIXER_SCHN_FRONT_RIGHT, &swRight );
             isCurrentlyRecSrc = ( (swLeft != 0) || (swRight != 0) );
@@ -676,8 +633,7 @@ bool Mixer_ALSA::isRecsrcHW( const QString& id )
             kDebug() << "has_switch non-joined, state " << isCurrentlyRecSrc;
 #endif
         }
-    }
-    else {
+    } else {
         // Has no on-off switch
         if ( snd_mixer_selem_has_capture_volume( elem ) ) {
             // Has a volume, but has no OnOffSwitch => We assume that this is a fixed record source (always on). (esken)
@@ -703,15 +659,13 @@ void Mixer_ALSA::setEnumIdHW(const QString& id, unsigned int idx) {
     int devnum = id2num(id);
     snd_mixer_elem_t *elem = getMixerElem( devnum );
 
-    for (int i = 0; i <= SND_MIXER_SCHN_LAST; ++i)
-    {
-               int ret = snd_mixer_selem_set_enum_item(elem, (snd_mixer_selem_channel_id_t)i,idx);
-               if (ret < 0 && i == 0)
-               {
-                       // Log errors only for one channel. This should be enough, and another reason is that I also do not check which channels are supported at all.
-                       kError() << "Mixer_ALSA::setEnumIdHW(" << devnum << "), errno=" << ret << "\n";
-               }
-       }
+    for (int i = 0; i <= SND_MIXER_SCHN_LAST; ++i) {
+        int ret = snd_mixer_selem_set_enum_item(elem, (snd_mixer_selem_channel_id_t)i,idx);
+        if (ret < 0 && i == 0) {
+            // Log errors only for one channel. This should be enough, and another reason is that I also do not check which channels are supported at all.
+            kError() << "Mixer_ALSA::setEnumIdHW(" << devnum << "), errno=" << ret << "\n";
+        }
+    }
 
     return;
 }
@@ -727,8 +681,7 @@ unsigned int Mixer_ALSA::enumIdHW(const QString& id) {
     snd_mixer_elem_t *elem = getMixerElem( devnum );
     unsigned int idx = 0;
 
-    if ( elem != 0 && snd_mixer_selem_is_enumerated(elem) )
-    {
+    if ( elem != 0 && snd_mixer_selem_is_enumerated(elem) ) {
         int ret = snd_mixer_selem_get_enum_item(elem,SND_MIXER_SCHN_FRONT_LEFT,&idx);
         if (ret < 0) {
             idx = 0;
@@ -739,8 +692,7 @@ unsigned int Mixer_ALSA::enumIdHW(const QString& id) {
 }
 
 
-int
-Mixer_ALSA::readVolumeFromHW( const QString& id, std::shared_ptr<MixDevice> md )
+int Mixer_ALSA::readVolumeFromHW( const QString& id, std::shared_ptr<MixDevice> md )
 {
     Volume& volumePlayback = md->playbackVolume();
     Volume& volumeCapture  = md->captureVolume();
@@ -749,93 +701,85 @@ Mixer_ALSA::readVolumeFromHW( const QString& id, std::shared_ptr<MixDevice> md )
     long vol;
 
     snd_mixer_elem_t *elem = getMixerElem( devnum );
-    if ( !elem )
-    {
+    if ( !elem ) {
         return Mixer::OK_UNCHANGED;
     }
 
     vol = Volume::MNONE;
     // --- playback volume
-    if ( snd_mixer_selem_has_playback_volume( elem ) )
-    {
-       if ( md->isVirtuallyMuted() )
-       {
-               // Special code path for controls w/o physical mute switch. Doing it in all backends is not perfect,
-               // but it saves a lot of code and removes a lot of complexity in the Volume and MixDevice classes.
-
-               // Don't feed back the actual 0 volume back from the device to KMix. Just do nothing!
-       }
-       else
-       {
-        foreach (VolumeChannel vc, volumePlayback.getVolumes() )
-        {
-               int ret = 0;
-               switch(vc.chid) {
-                   case Volume::LEFT         : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , &vol); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , &vol); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, &vol); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , &vol); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , &vol); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , &vol); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , &vol); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , &vol); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , &vol); break;
-                   default: kDebug() << "FATAL: Unknown channel type for playback << " << vc.chid << " ... please report this";  break;
-              }
-              if ( ret != 0 )
-               kDebug() << "readVolumeFromHW(" << devnum << ") [get_playback_volume] failed, errno=" << ret;
-              else
-               volumePlayback.setVolume( vc.chid, vol);
-              //if (id== "Master:0" || id== "PCM:0" ) { kDebug() << "volumePlayback control=" << id << ", chid=" << i << ", vol=" << vol; }
-       }
-       }
+    if ( snd_mixer_selem_has_playback_volume( elem ) ) {
+        if ( md->isVirtuallyMuted() ) {
+            // Special code path for controls w/o physical mute switch. Doing it in all backends is not perfect,
+            // but it saves a lot of code and removes a lot of complexity in the Volume and MixDevice classes.
+
+            // Don't feed back the actual 0 volume back from the device to KMix. Just do nothing!
+        } else {
+            foreach (VolumeChannel vc, volumePlayback.getVolumes() ) {
+                int ret = 0;
+                switch(vc.chid) {
+                    case Volume::LEFT         : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , &vol); break;
+                    case Volume::RIGHT        : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , &vol); break;
+                    case Volume::CENTER       : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, &vol); break;
+                    case Volume::SURROUNDLEFT : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , &vol); break;
+                    case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , &vol); break;
+                    case Volume::REARCENTER   : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , &vol); break;
+                    case Volume::WOOFER       : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , &vol); break;
+                    case Volume::REARSIDELEFT : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , &vol); break;
+                    case Volume::REARSIDERIGHT: ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , &vol); break;
+                    default: kDebug() << "FATAL: Unknown channel type for playback << " << vc.chid << " ... please report this";  break;
+                }
+                if ( ret != 0 ) {
+                    kDebug() << "readVolumeFromHW(" << devnum << ") [get_playback_volume] failed, errno=" << ret;
+                } else {
+                    volumePlayback.setVolume( vc.chid, vol);
+                    //if (id== "Master:0" || id== "PCM:0" ) { kDebug() << "volumePlayback control=" << id << ", chid=" << i << ", vol=" << vol; }
+                }
+            }
+        }
     } // has playback volume
 
     // --- playback switch
     // TODO: What about has_common_switch()
-    if ( snd_mixer_selem_has_playback_switch( elem ) )
-    {
+    if ( snd_mixer_selem_has_playback_switch( elem ) ) {
         snd_mixer_selem_get_playback_switch( elem, SND_MIXER_SCHN_FRONT_LEFT, &elem_sw );
         md->setMuted( elem_sw == 0 );
     }
 
     vol = Volume::MNONE;
     // --- capture volume
-    if ( snd_mixer_selem_has_capture_volume ( elem ) )
-    {
-        foreach (VolumeChannel vc, volumeCapture.getVolumes() )
-               {
-               int ret = 0;
-               switch(vc.chid) {
-                   case Volume::LEFT         : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , &vol); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , &vol); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, &vol); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , &vol); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , &vol); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , &vol); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , &vol); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , &vol); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , &vol);     break;
-                   default: kDebug() << "FATAL: Unknown channel type for capture << " << vc.chid << " ... please report this";  break;
-              }
-              if ( ret != 0 )
-                 kDebug() << "readVolumeFromHW(" << devnum << ") [get_capture_volume] failed, errno=" << ret;
-              else volumeCapture.setVolume( vc.chid, vol);
+    if ( snd_mixer_selem_has_capture_volume ( elem ) ) {
+        foreach (VolumeChannel vc, volumeCapture.getVolumes() ) {
+            int ret = 0;
+            switch(vc.chid) {
+                case Volume::LEFT         : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , &vol); break;
+                case Volume::RIGHT        : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , &vol); break;
+                case Volume::CENTER       : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, &vol); break;
+                case Volume::SURROUNDLEFT : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , &vol); break;
+                case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , &vol); break;
+                case Volume::REARCENTER   : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , &vol); break;
+                case Volume::WOOFER       : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , &vol); break;
+                case Volume::REARSIDELEFT : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , &vol); break;
+                case Volume::REARSIDERIGHT: ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , &vol);     break;
+                default: kDebug() << "FATAL: Unknown channel type for capture << " << vc.chid << " ... please report this";  break;
+            }
+            if ( ret != 0 ) {
+                kDebug() << "readVolumeFromHW(" << devnum << ") [get_capture_volume] failed, errno=" << ret;
+            } else {
+                volumeCapture.setVolume( vc.chid, vol);
+            }
        }
     } // has capture volume
 
     // --- capture switch
     // TODO: What about has_common_switch()
-    if ( snd_mixer_selem_has_capture_switch( elem ) )
-    {
+    if ( snd_mixer_selem_has_capture_switch( elem ) ) {
         snd_mixer_selem_get_capture_switch( elem, SND_MIXER_SCHN_FRONT_LEFT, &elem_sw );
         md->setRecSource( elem_sw == 1 );
 
         // Refresh the capture switch information of *all* controls of this card.
         // Doing it for all is necessary, because enabling one record source often
         // automatically disables another record source (due to the hardware design)
-        foreach ( std::shared_ptr<MixDevice> md, m_mixDevices )
-        {
+        foreach ( std::shared_ptr<MixDevice> md, m_mixDevices ) {
             bool isRecsrc =  isRecsrcHW( md->id() );
             // kDebug() << "Mixer::setRecordSource(): isRecsrcHW(" <<  md->id() << ") =" <<  isRecsrc;
             md->setRecSource( isRecsrc );
@@ -848,8 +792,7 @@ Mixer_ALSA::readVolumeFromHW( const QString& id, std::shared_ptr<MixDevice> md )
     return Mixer::OK;
 }
 
-int
-Mixer_ALSA::writeVolumeToHW( const QString& id, std::shared_ptr<MixDevice> md )
+int Mixer_ALSA::writeVolumeToHW( const QString& id, std::shared_ptr<MixDevice> md )
 {
     Volume& volumePlayback = md->playbackVolume();
     Volume& volumeCapture  = md->captureVolume();
@@ -857,82 +800,73 @@ Mixer_ALSA::writeVolumeToHW( const QString& id, std::shared_ptr<MixDevice> md )
     int devnum = id2num(id);
 
     snd_mixer_elem_t *elem = getMixerElem( devnum );
-    if ( !elem )
-    {
+    if ( !elem ) {
         return 0;
     }
 
 
     // --- playback switch
     bool hasPlaybackSwitch = snd_mixer_selem_has_playback_switch( elem ) || snd_mixer_selem_has_common_switch  ( elem );
-       if (hasPlaybackSwitch)
-       {
-               int sw = 0;
-               if (!md->isMuted())
-                       sw = !sw; // invert all bits
-               snd_mixer_selem_set_playback_switch_all(elem, sw);
-       }
+    if (hasPlaybackSwitch) {
+        int sw = 0;
+        if (!md->isMuted())
+            sw = !sw; // invert all bits
+        snd_mixer_selem_set_playback_switch_all(elem, sw);
+    }
 
 
     // --- playback volume
-    if ( snd_mixer_selem_has_playback_volume( elem ) )
-    {
-//     kDebug() << "phys=" << md->hasPhysicalMuteSwitch() << ", muted=" << md->isMuted();
-       if ( md->isVirtuallyMuted() )
-       {
-               // Special code path for controls w/o physical mute switch. Doing it in all backends is not perfect,
-               // but it saves a lot of code and removes a lot of complexity in the Volume and MixDevice classes.
-               int ret = snd_mixer_selem_set_playback_volume_all( elem, (long)0);
+    if ( snd_mixer_selem_has_playback_volume( elem ) ) {
+//      kDebug() << "phys=" << md->hasPhysicalMuteSwitch() << ", muted=" << md->isMuted();
+        if ( md->isVirtuallyMuted() ) {
+            // Special code path for controls w/o physical mute switch. Doing it in all backends is not perfect,
+            // but it saves a lot of code and removes a lot of complexity in the Volume and MixDevice classes.
+            int ret = snd_mixer_selem_set_playback_volume_all( elem, (long)0);
             if ( ret != 0 )
-                 kDebug() << "writeVolumeToHW(" << devnum << ") [set_playback_volume] failed, errno=" << ret;
-       }
-       else
-       {
-      foreach (VolumeChannel vc, volumePlayback.getVolumes() )
-      {
-               int ret = 0;
-               switch(vc.chid)
-               {
-                   case Volume::LEFT         : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , vc.volume); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , vc.volume); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, vc.volume); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , vc.volume); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , vc.volume); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , vc.volume); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , vc.volume); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , vc.volume); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , vc.volume); break;
-                   default: kDebug() << "FATAL: Unknown channel type for playback << " << vc.chid << " ... please report this";  break;
-              }
-              if ( ret != 0 )
-                 kDebug() << "writeVolumeToHW(" << devnum << ") [set_playback_volume] failed, errno=" << ret;
-              //if (id== "Master:0" || id== "PCM:0" ) { kDebug() << "volumePlayback control=" << id << ", chid=" << vc.chid << ", vol=" << vc.volume; }
-          }
-       }
+                kDebug() << "writeVolumeToHW(" << devnum << ") [set_playback_volume] failed, errno=" << ret;
+        } else {
+            foreach (VolumeChannel vc, volumePlayback.getVolumes() ) {
+                int ret = 0;
+                switch(vc.chid) {
+                    case Volume::LEFT         : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , vc.volume); break;
+                    case Volume::RIGHT        : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , vc.volume); break;
+                    case Volume::CENTER       : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, vc.volume); break;
+                    case Volume::SURROUNDLEFT : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , vc.volume); break;
+                    case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , vc.volume); break;
+                    case Volume::REARCENTER   : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , vc.volume); break;
+                    case Volume::WOOFER       : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , vc.volume); break;
+                    case Volume::REARSIDELEFT : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , vc.volume); break;
+                    case Volume::REARSIDERIGHT: ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , vc.volume); break;
+                    default: kDebug() << "FATAL: Unknown channel type for playback << " << vc.chid << " ... please report this";  break;
+                }
+                if ( ret != 0 )
+                    kDebug() << "writeVolumeToHW(" << devnum << ") [set_playback_volume] failed, errno=" << ret;
+                //if (id== "Master:0" || id== "PCM:0" ) { kDebug() << "volumePlayback control=" << id << ", chid=" << vc.chid << ", vol=" << vc.volume; }
+            }
+        }
     } // has playback volume
 
 
 
     // --- capture volume
-    if ( snd_mixer_selem_has_capture_volume ( elem ) )
-    {
-      foreach (VolumeChannel vc, volumeCapture.getVolumes() )
-      {
-               int ret = 0;
-               switch(vc.chid) {
-                   case Volume::LEFT         : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , vc.volume); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , vc.volume); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, vc.volume); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , vc.volume); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , vc.volume); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , vc.volume); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , vc.volume); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , vc.volume); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , vc.volume); break;
-                   default: kDebug() << "FATAL: Unknown channel type for capture << " << vc.chid << " ... please report this";  break;
-              }
-              if ( ret != 0 ) kDebug() << "writeVolumeToHW(" << devnum << ") [set_capture_volume] failed, errno=" << ret;
-              //if (id== "Master:0" || id== "PCM:0" ) { kDebug() << "volumecapture control=" << id << ", chid=" << i << ", vol=" << vc.volume; }
+    if ( snd_mixer_selem_has_capture_volume ( elem ) ) {
+        foreach (VolumeChannel vc, volumeCapture.getVolumes() ) {
+            int ret = 0;
+            switch(vc.chid) {
+                case Volume::LEFT         : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , vc.volume); break;
+                case Volume::RIGHT        : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , vc.volume); break;
+                case Volume::CENTER       : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, vc.volume); break;
+                case Volume::SURROUNDLEFT : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , vc.volume); break;
+                case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , vc.volume); break;
+                case Volume::REARCENTER   : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , vc.volume); break;
+                case Volume::WOOFER       : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , vc.volume); break;
+                case Volume::REARSIDELEFT : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , vc.volume); break;
+                case Volume::REARSIDERIGHT: ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , vc.volume); break;
+                default: kDebug() << "FATAL: Unknown channel type for capture << " << vc.chid << " ... please report this";  break;
+            }
+            if ( ret != 0 )
+                kDebug() << "writeVolumeToHW(" << devnum << ") [set_capture_volume] failed, errno=" << ret;
+            //if (id== "Master:0" || id== "PCM:0" ) { kDebug() << "volumecapture control=" << id << ", chid=" << i << ", vol=" << vc.volume; }
           }
     } // has capture volume
 
@@ -950,37 +884,38 @@ Mixer_ALSA::writeVolumeToHW( const QString& id, std::shared_ptr<MixDevice> md )
     return 0;
 }
 
-QString
-Mixer_ALSA::errorText( int mixer_error )
+QString Mixer_ALSA::errorText( int mixer_error )
 {
-       QString l_s_errmsg;
-       switch ( mixer_error )
-       {
-               case Mixer::ERR_PERM:
-                       l_s_errmsg = i18n("You do not have permission to access the alsa mixer device.\n" \
-                                       "Please verify if all alsa devices are properly created.");
-      break;
-               case Mixer::ERR_OPEN:
-                       l_s_errmsg = i18n("Alsa mixer cannot be found.\n" \
-                                       "Please check that the soundcard is installed and the\n" \
-                                       "soundcard driver is loaded.\n" );
-                       break;
-               default:
-                       l_s_errmsg = Mixer_Backend::errorText( mixer_error );
-       }
-       return l_s_errmsg;
+    QString l_s_errmsg;
+    switch ( mixer_error ) {
+        case Mixer::ERR_PERM: {
+            l_s_errmsg = i18n("You do not have permission to access the alsa mixer device.\n" \
+                              "Please verify if all alsa devices are properly created.");
+            break;
+        }
+        case Mixer::ERR_OPEN: {
+            l_s_errmsg = i18n("Alsa mixer cannot be found.\n" \
+                              "Please check that the soundcard is installed and the\n" \
+                              "soundcard driver is loaded.\n" );
+            break;
+        }
+        default: {
+            l_s_errmsg = Mixer_Backend::errorText( mixer_error );
+            break;
+        }
+    }
+    return l_s_errmsg;
 }
 
 
-QString
-ALSA_getDriverName()
+QString ALSA_getDriverName()
 {
-       return "ALSA";
+    return "ALSA";
 }
 
 QString Mixer_ALSA::getDriverName()
 {
-       return "ALSA";
+    return "ALSA";
 }
 
 
index 7435c9b..c13b891 100644 (file)
@@ -36,7 +36,7 @@
 
 Mixer_Backend* MPRIS2_getMixer(Mixer *mixer, int device )
 {
-       return new Mixer_MPRIS2(mixer, device );
+    return new Mixer_MPRIS2(mixer, device );
 }
 
 Mixer_MPRIS2::Mixer_MPRIS2(Mixer *mixer, int device) : Mixer_Backend(mixer, device )
@@ -46,37 +46,37 @@ Mixer_MPRIS2::Mixer_MPRIS2(Mixer *mixer, int device) : Mixer_Backend(mixer, devi
 
 int Mixer_MPRIS2::open()
 {
-       if ( m_devnum !=  0 )
-               return Mixer::ERR_OPEN;
+    if ( m_devnum !=  0 )
+        return Mixer::ERR_OPEN;
 
-       registerCard(i18n("Playback Streams"));
-       _id = "Playback Streams";
-       _mixer->setDynamic();
-       return addAllRunningPlayersAndInitHotplug();
+    registerCard(i18n("Playback Streams"));
+    _id = "Playback Streams";
+    _mixer->setDynamic();
+    return addAllRunningPlayersAndInitHotplug();
 }
 
 int Mixer_MPRIS2::close()
 {
-         m_isOpen = false;
-         closeCommon();
-         qDeleteAll(controls);
-         controls.clear();
-        return 0;
+    m_isOpen = false;
+    closeCommon();
+    qDeleteAll(controls);
+    controls.clear();
+    return 0;
 }
 
 int Mixer_MPRIS2::mediaPlay(QString id)
 {
-       return mediaControl(id, "PlayPause");
+    return mediaControl(id, "PlayPause");
 }
 
 int Mixer_MPRIS2::mediaPrev(QString id)
 {
-       return mediaControl(id, "Previous");
+    return mediaControl(id, "Previous");
 }
 
 int Mixer_MPRIS2::mediaNext(QString id)
 {
-       return mediaControl(id, "Next");
+    return mediaControl(id, "Next");
 }
 
 /**
@@ -86,34 +86,32 @@ int Mixer_MPRIS2::mediaNext(QString id)
  */
 int Mixer_MPRIS2::mediaControl(QString applicationId, QString commandName)
 {
-       MPrisControl* mad = controls.value(applicationId);
-       if ( mad == 0 )
-         return 0; // Might have disconnected recently => simply ignore command
+    MPrisControl* mad = controls.value(applicationId);
+    if ( mad == 0 )
+        return 0; // Might have disconnected recently => simply ignore command
 
-       kDebug() << "Send " << commandName << " to id=" << applicationId;
-       QDBusPendingReply<> repl2 =
-               mad->playerIfc->asyncCall(commandName);
+    kDebug() << "Send " << commandName << " to id=" << applicationId;
+    QDBusPendingReply<> repl2 = mad->playerIfc->asyncCall(commandName);
 
 
-       QDBusPendingCallWatcher* watchMediaControlReply = new QDBusPendingCallWatcher(repl2, mad);
-       connect(watchMediaControlReply, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherMediaControl(QDBusPendingCallWatcher *)));
+    QDBusPendingCallWatcher* watchMediaControlReply = new QDBusPendingCallWatcher(repl2, mad);
+    connect(watchMediaControlReply, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherMediaControl(QDBusPendingCallWatcher *)));
 
-       return 0; // Presume everything went well. Can't do more for ASYNC calls
+    return 0; // Presume everything went well. Can't do more for ASYNC calls
 }
 
 void Mixer_MPRIS2::watcherMediaControl(QDBusPendingCallWatcher* watcher)
 {
-       MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
-       if (mprisCtl == 0)
-       {
-               return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
-       }
+    MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
+    if (mprisCtl == 0) {
+            return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
+    }
 
-       // Actually the code below in this method is more or less just debugging
-       const QDBusMessage& msg = watcher->reply();
-       QString id = mprisCtl->getId();
-       QString busDestination = mprisCtl->getBusDestination();
-       kDebug() << "Media control for id=" << id << ", path=" << msg.path() << ", interface=" << msg.interface() << ", busDestination" << busDestination;
+    // Actually the code below in this method is more or less just debugging
+    const QDBusMessage& msg = watcher->reply();
+    QString id = mprisCtl->getId();
+    QString busDestination = mprisCtl->getBusDestination();
+    kDebug() << "Media control for id=" << id << ", path=" << msg.path() << ", interface=" << msg.interface() << ", busDestination" << busDestination;
 }
 
 /**
@@ -122,8 +120,8 @@ void Mixer_MPRIS2::watcherMediaControl(QDBusPendingCallWatcher* watcher)
  */
 int Mixer_MPRIS2::readVolumeFromHW( const QString& /*id*/, std::shared_ptr<MixDevice> /*md*/)
 {
-       // Everything is done by notifications => no code neccessary
-       return Mixer::OK_UNCHANGED;
+    // Everything is done by notifications => no code neccessary
+    return Mixer::OK_UNCHANGED;
 }
 
 
@@ -135,10 +133,10 @@ int Mixer_MPRIS2::readVolumeFromHW( const QString& /*id*/, std::shared_ptr<MixDe
  */
 void Mixer_MPRIS2::playbackStateChanged(MPrisControl* mad, MediaController::PlayState playState)
 {
-       std::shared_ptr<MixDevice> md = m_mixDevices.get(mad->getId());
-       md->getMediaController()->setPlayState(playState);
-       QMetaObject::invokeMethod(this, "announceGUI", Qt::QueuedConnection);
-//     ControlManager::instance().announce(_mixer->id(), ControlChangeType::GUI, QString("MixerMPRIS2.playbackStateChanged"));
+    std::shared_ptr<MixDevice> md = m_mixDevices.get(mad->getId());
+    md->getMediaController()->setPlayState(playState);
+    QMetaObject::invokeMethod(this, "announceGUI", Qt::QueuedConnection);
+//      ControlManager::instance().announce(_mixer->id(), ControlChangeType::GUI, QString("MixerMPRIS2.playbackStateChanged"));
 }
 
 
@@ -150,25 +148,24 @@ void Mixer_MPRIS2::playbackStateChanged(MPrisControl* mad, MediaController::Play
  */
 void Mixer_MPRIS2::volumeChanged(MPrisControl* mad, double newVolume)
 {
-       std::shared_ptr<MixDevice> md = m_mixDevices.get(mad->getId());
-       int volInt = newVolume *100;
-       if (GlobalConfig::instance().data.debugVolume)
-               kDebug() << "changed" << volInt;
-       volumeChangedInternal(md, volInt);
+    std::shared_ptr<MixDevice> md = m_mixDevices.get(mad->getId());
+    int volInt = newVolume *100;
+    if (GlobalConfig::instance().data.debugVolume)
+        kDebug() << "changed" << volInt;
+    volumeChangedInternal(md, volInt);
 }
 
 void Mixer_MPRIS2::volumeChangedInternal(std::shared_ptr<MixDevice> md, int volumePercentage)
 {
-       if ( md->isVirtuallyMuted() && volumePercentage == 0)
-       {
-               // Special code path for virtual mute switches. Don't write back the volume if it is muted in the KMix GUI
-               return;
-       }
+    if ( md->isVirtuallyMuted() && volumePercentage == 0) {
+        // Special code path for virtual mute switches. Don't write back the volume if it is muted in the KMix GUI
+        return;
+    }
 
-       Volume& vol = md->playbackVolume();
-       vol.setVolume( Volume::LEFT, volumePercentage);
-       md->setMuted(volumePercentage == 0);
-       QMetaObject::invokeMethod(this, "announceVolume", Qt::QueuedConnection);
+    Volume& vol = md->playbackVolume();
+    vol.setVolume( Volume::LEFT, volumePercentage);
+    md->setMuted(volumePercentage == 0);
+    QMetaObject::invokeMethod(this, "announceVolume", Qt::QueuedConnection);
 //     ControlManager::instance().announce(_mixer->id(), ControlChangeType::Volume, QString("MixerMPRIS2.volumeChanged"));
 }
 
@@ -195,46 +192,45 @@ signal sender=:1.125 -> dest=(null destination) serial=503 path=/org/mpris/Media
  */
 int Mixer_MPRIS2::writeVolumeToHW( const QString& id, std::shared_ptr<MixDevice> md )
 {
-       Volume& vol = md->playbackVolume();
-       double volFloat = 0;
-       if ( ! md->isMuted() )
-       {
-               int volInt = vol.getVolume(Volume::LEFT);
-               volFloat = volInt/100.0;
-       }
+    Volume& vol = md->playbackVolume();
+    double volFloat = 0;
+    if ( ! md->isMuted() ) {
+        int volInt = vol.getVolume(Volume::LEFT);
+        volFloat = volInt/100.0;
+    }
 
-       QList<QVariant> arg;
-       arg.append(QString("org.mpris.MediaPlayer2.Player"));
-       arg.append(QString("Volume"));
-       arg << QVariant::fromValue(QDBusVariant(volFloat));
+    QList<QVariant> arg;
+    arg.append(QString("org.mpris.MediaPlayer2.Player"));
+    arg.append(QString("Volume"));
+    arg << QVariant::fromValue(QDBusVariant(volFloat));
 
-       MPrisControl* mad = controls.value(id);
+    MPrisControl* mad = controls.value(id);
 
-       QVariant v1 = QVariant(QString("org.mpris.MediaPlayer2.Player"));
-       QVariant v2 = QVariant(QString("Volume"));
-       QVariant v3 = QVariant::fromValue(QDBusVariant(volFloat));
-//     QVariant v3 = QVariant(volFloat);
+    QVariant v1 = QVariant(QString("org.mpris.MediaPlayer2.Player"));
+    QVariant v2 = QVariant(QString("Volume"));
+    QVariant v3 = QVariant::fromValue(QDBusVariant(volFloat));
+//      QVariant v3 = QVariant(volFloat);
 
-       // I don't care too much for the reply, as I won't receive a result. Thus fire-and-forget here.
-       mad->propertyIfc->asyncCall("Set", v1, v2, v3);
-       return 0;
+    // I don't care too much for the reply, as I won't receive a result. Thus fire-and-forget here.
+    mad->propertyIfc->asyncCall("Set", v1, v2, v3);
+    return 0;
 }
 
 void Mixer_MPRIS2::setEnumIdHW(const QString&, unsigned int)
 {
-       // no enums in MPRIS
+    // no enums in MPRIS
 }
 
 unsigned int Mixer_MPRIS2::enumIdHW(const QString&)
 {
-       // no enums in MPRIS
-       return 0;
+    // no enums in MPRIS
+    return 0;
 }
 
 bool Mixer_MPRIS2::moveStream( const QString&, const QString&  )
 {
-       // not supported in MPRIS
-       return false;
+    // not supported in MPRIS
+    return false;
 }
 
 
@@ -246,66 +242,60 @@ bool Mixer_MPRIS2::moveStream( const QString&, const QString&  )
  **/
 int Mixer_MPRIS2::addAllRunningPlayersAndInitHotplug()
 {
-       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;
-       }
-
-       // Start listening for new Mediaplayers
-       bool connected = dbusConn.connect("", QString("/org/freedesktop/DBus"), "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(newMediaPlayer(QString,QString,QString)) );
-       if (!connected)
-       {
-               kWarning() << "MPRIS2 hotplug init failure. New Media Players will not be detected.";
-       }
-
-       /* Here is a small concurrency issue.
-        * If new players appear between registeredServiceNames() below and the connect() above these players *might* show up doubled in KMix.
-        * There is no simple solution (reversing could have the problem of not-adding), so we live for now with it.
-        */
-        
-       /*
-        * Bug 311189: Introspecting via "dbusConn.interface()->registeredServiceNames()" does not work too well.
-        * Comment: I am not so sure that registeredServiceNames() is really an issue. It is more likely
-        *  in a later step, when talking to the probed apps. Still, I now do a hand crafted 3-line version of
-        *  registeredServiceNames() via "ListNames", so I can later more easily change to async.
-        */
-       QDBusInterface dbusIfc("org.freedesktop.DBus", "/org/freedesktop/DBus",
-                                 "org.freedesktop.DBus", dbusConn);
-       QDBusPendingReply<QStringList> repl = dbusIfc.asyncCall("ListNames");
-       repl.waitForFinished();
-
-       if (! repl.isValid() )
-       {
-               kError() << "Invalid reply while listing Media Players. MPRIS2 players will not be available." << repl.error();
-               return 1;
-       }
-
-       foreach (QString busDestination , repl.value() )
-       {
-               if ( busDestination.startsWith("org.mpris.MediaPlayer2") )
-               {
-                       addMprisControlAsync(busDestination);
-                       kDebug() << "MPRIS2: Attached media player on busDestination=" << busDestination;
-               }
-       }
-
-       return 0;
+    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;
+    }
+
+    // Start listening for new Mediaplayers
+    bool connected = dbusConn.connect("", QString("/org/freedesktop/DBus"), "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(newMediaPlayer(QString,QString,QString)) );
+    if (!connected) {
+        kWarning() << "MPRIS2 hotplug init failure. New Media Players will not be detected.";
+    }
+
+    /* Here is a small concurrency issue.
+    * If new players appear between registeredServiceNames() below and the connect() above these players *might* show up doubled in KMix.
+    * There is no simple solution (reversing could have the problem of not-adding), so we live for now with it.
+    */
+        
+    /*
+    * Bug 311189: Introspecting via "dbusConn.interface()->registeredServiceNames()" does not work too well.
+    * Comment: I am not so sure that registeredServiceNames() is really an issue. It is more likely
+    *  in a later step, when talking to the probed apps. Still, I now do a hand crafted 3-line version of
+    *  registeredServiceNames() via "ListNames", so I can later more easily change to async.
+    */
+    QDBusInterface dbusIfc("org.freedesktop.DBus", "/org/freedesktop/DBus",
+                                "org.freedesktop.DBus", dbusConn);
+    QDBusPendingReply<QStringList> repl = dbusIfc.asyncCall("ListNames");
+    repl.waitForFinished();
+
+    if (! repl.isValid() ) {
+        kError() << "Invalid reply while listing Media Players. MPRIS2 players will not be available." << repl.error();
+        return 1;
+    }
+
+    foreach (QString busDestination , repl.value() ) {
+        if ( busDestination.startsWith("org.mpris.MediaPlayer2") ){
+            addMprisControlAsync(busDestination);
+            kDebug() << "MPRIS2: Attached media player on busDestination=" << busDestination;
+        }
+    }
+
+    return 0;
 }
 
 QString Mixer_MPRIS2::busDestinationToControlId(const QString& busDestination)
 {
-       const QString prefix = "org.mpris.MediaPlayer2.";
-       if (! busDestination.startsWith(prefix))
-       {
-               kWarning() << "Ignoring unsupported control, busDestination=" << busDestination;
-               return QString();
-       }
+    const QString prefix = "org.mpris.MediaPlayer2.";
+    if (! busDestination.startsWith(prefix)) {
+        kWarning() << "Ignoring unsupported control, busDestination=" << busDestination;
+        return QString();
+    }
 
-       return busDestination.mid(prefix.length());
+    return busDestination.mid(prefix.length());
 }
 
 /**
@@ -317,110 +307,97 @@ QString Mixer_MPRIS2::busDestinationToControlId(const QString& busDestination)
  */
 void Mixer_MPRIS2::addMprisControlAsync(QString busDestination)
 {
-       // -1- Create a MPrisControl. Its fields will be filled partially here, partially via ASYNC DUBUS replies
-       QString id = busDestinationToControlId(busDestination);
-       kDebug() << "Get control of busDestination=" << busDestination << "id=" << id;
+    // -1- Create a MPrisControl. Its fields will be filled partially here, partially via ASYNC DUBUS replies
+    QString id = busDestinationToControlId(busDestination);
+    kDebug() << "Get control of busDestination=" << busDestination << "id=" << id;
 
-       QDBusConnection conn = QDBusConnection::sessionBus();
-       QDBusInterface *qdbiProps  = new QDBusInterface(QString(busDestination), QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", conn, this);
-       QDBusInterface *qdbiPlayer = new QDBusInterface(QString(busDestination), QString("/org/mpris/MediaPlayer2"), "org.mpris.MediaPlayer2.Player", conn, this);
+    QDBusConnection conn = QDBusConnection::sessionBus();
+    QDBusInterface *qdbiProps  = new QDBusInterface(QString(busDestination), QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", conn, this);
+    QDBusInterface *qdbiPlayer = new QDBusInterface(QString(busDestination), QString("/org/mpris/MediaPlayer2"), "org.mpris.MediaPlayer2.Player", conn, this);
 
-       // -2- Add the control to our official control list
-       MPrisControl* mad = new MPrisControl(id, busDestination);
-       mad->propertyIfc = qdbiProps;
-       mad->playerIfc = qdbiPlayer;
-       controls.insert(id, mad);
+    // -2- Add the control to our official control list
+    MPrisControl* mad = new MPrisControl(id, busDestination);
+    mad->propertyIfc = qdbiProps;
+    mad->playerIfc = qdbiPlayer;
+    controls.insert(id, mad);
 
 
-       /*
-        * WTF: - asyncCall("Get", arg)                          : returns an error message (see below)
-        *      - asyncCallWithArgumentList("Get", arg)          : returns an error message (see below)
-        *      - callWithArgumentList(QDBus::Block, "Get", arg) : works
-        *      - syncCall("Get", v1, v2)                        : works
-        *
-        * kmix(13543) Mixer_MPRIS2::addMPrisControl: (marok), msg2= QDBusMessage(type=Error, service=":1.44", error name="org.freedesktop.DBus.Error.UnknownMethod", error message="No such method 'Get' in interface 'org.freedesktop.DBus.Properties' at object path '/org/mpris/MediaPlayer2' (signature 'av')", signature="s", contents=("No such method 'Get' in interface 'org.freedesktop.DBus.Properties' at object path '/org/mpris/MediaPlayer2' (signature 'av')") ) , isValid= false , isFinished= true , isError= true
-        *
-        * This behavior is total counter-intuitive :-(((
-        */
+    /*
+    * WTF: - asyncCall("Get", arg)                          : returns an error message (see below)
+    *      - asyncCallWithArgumentList("Get", arg)          : returns an error message (see below)
+    *      - callWithArgumentList(QDBus::Block, "Get", arg) : works
+    *      - syncCall("Get", v1, v2)                        : works
+    *
+    * kmix(13543) Mixer_MPRIS2::addMPrisControl: (marok), msg2= QDBusMessage(type=Error, service=":1.44", error name="org.freedesktop.DBus.Error.UnknownMethod", error message="No such method 'Get' in interface 'org.freedesktop.DBus.Properties' at object path '/org/mpris/MediaPlayer2' (signature 'av')", signature="s", contents=("No such method 'Get' in interface 'org.freedesktop.DBus.Properties' at object path '/org/mpris/MediaPlayer2' (signature 'av')") ) , isValid= false , isFinished= true , isError= true
+    *
+    * This behavior is total counter-intuitive :-(((
+    */
 
-       // Create ASYNC DBUS queries for the new control. This effectively starts a chain of async DBUS commands.
-       QVariant v1 = QVariant(QString("org.mpris.MediaPlayer2"));
-       QVariant v2 = QVariant(QString("Identity"));
-       QDBusPendingReply<QVariant > repl2 = mad->propertyIfc->asyncCall("Get", v1, v2);
-       QDBusPendingCallWatcher* watchIdentity = new QDBusPendingCallWatcher(repl2, mad);
-       connect(watchIdentity, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherPlugControlId(QDBusPendingCallWatcher *)));
+    // Create ASYNC DBUS queries for the new control. This effectively starts a chain of async DBUS commands.
+    QVariant v1 = QVariant(QString("org.mpris.MediaPlayer2"));
+    QVariant v2 = QVariant(QString("Identity"));
+    QDBusPendingReply<QVariant > repl2 = mad->propertyIfc->asyncCall("Get", v1, v2);
+    QDBusPendingCallWatcher* watchIdentity = new QDBusPendingCallWatcher(repl2, mad);
+    connect(watchIdentity, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherPlugControlId(QDBusPendingCallWatcher *)));
 }
 
 MixDevice::ChannelType Mixer_MPRIS2::getChannelTypeFromPlayerId(const QString& id)
 {
-       // TODO This hardcoded application list is a quick hack. It should be generalized.
-       MixDevice::ChannelType ct = MixDevice::APPLICATION_STREAM;
-       if (id.startsWith("amarok"))
-       {
-               ct = MixDevice::APPLICATION_AMAROK;
-       }
-       else if (id.startsWith("banshee"))
-       {
-               ct = MixDevice::APPLICATION_BANSHEE;
-       }
-       else if (id.startsWith("vlc"))
-       {
-               ct = MixDevice::APPLICATION_VLC;
-       }
-       else if (id.startsWith("xmms"))
-       {
-               ct = MixDevice::APPLICATION_XMM2;
-       }
-       else if (id.startsWith("tomahawk"))
-       {
-               ct = MixDevice::APPLICATION_TOMAHAWK;
-       }
-       else if (id.startsWith("clementine"))
-       {
-               ct = MixDevice::APPLICATION_CLEMENTINE;
-       }
-
-       return ct;
+    // TODO This hardcoded application list is a quick hack. It should be generalized.
+    MixDevice::ChannelType ct = MixDevice::APPLICATION_STREAM;
+    if (id.startsWith("amarok")) {
+        ct = MixDevice::APPLICATION_AMAROK;
+    } else if (id.startsWith("banshee")) {
+        ct = MixDevice::APPLICATION_BANSHEE;
+    } else if (id.startsWith("vlc")) {
+        ct = MixDevice::APPLICATION_VLC;
+    } else if (id.startsWith("xmms")) {
+        ct = MixDevice::APPLICATION_XMM2;
+    } else if (id.startsWith("tomahawk")) {
+        ct = MixDevice::APPLICATION_TOMAHAWK;
+    } else if (id.startsWith("clementine")) {
+        ct = MixDevice::APPLICATION_CLEMENTINE;
+    }
+
+    return ct;
 }
 
 void Mixer_MPRIS2::watcherInitialVolume(QDBusPendingCallWatcher* watcher)
 {
-       MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
-       if (mprisCtl == 0)
-               return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
+    MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
+    if (mprisCtl == 0)
+        return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
 
-       const QDBusMessage& msg = watcher->reply();
-       QList<QVariant> repl = msg.arguments();
-       if ( ! repl.isEmpty() )
-       {
-               QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(repl.at(0));
-               QVariant result2 = dbusVariant.variant();
-               double volume = result2.toDouble();
-               volumeChanged(mprisCtl, volume);
-       }
+    const QDBusMessage& msg = watcher->reply();
+    QList<QVariant> repl = msg.arguments();
+    if ( ! repl.isEmpty() ) {
+        QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(repl.at(0));
+        QVariant result2 = dbusVariant.variant();
+        double volume = result2.toDouble();
+        volumeChanged(mprisCtl, volume);
+    }
 
-       watcher->deleteLater();
+    watcher->deleteLater();
 }
 
 void Mixer_MPRIS2::watcherInitialPlayState(QDBusPendingCallWatcher* watcher)
 {
-       MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
-       if (mprisCtl == 0)
-               return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
+    MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
+    if (mprisCtl == 0)
+        return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
 
-       const QDBusMessage& msg = watcher->reply();
-       QList<QVariant> repl = msg.arguments();
-       if ( ! repl.isEmpty() )
-       {
-               QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(repl.at(0));
-               QVariant result2 = dbusVariant.variant();
-               QString playbackStateString = result2.toString();
+    const QDBusMessage& msg = watcher->reply();
+    QList<QVariant> repl = msg.arguments();
+    if ( ! repl.isEmpty() ) {
+        QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(repl.at(0));
+        QVariant result2 = dbusVariant.variant();
+        QString playbackStateString = result2.toString();
 
-               MediaController::PlayState playState = Mixer_MPRIS2::mprisPlayStateString2PlayState(playbackStateString);
-               playbackStateChanged(mprisCtl, playState);
-       }
+        MediaController::PlayState playState = Mixer_MPRIS2::mprisPlayStateString2PlayState(playbackStateString);
+        playbackStateChanged(mprisCtl, playState);
+    }
 
-       watcher->deleteLater();
+    watcher->deleteLater();
 }
 
 
@@ -437,100 +414,92 @@ void Mixer_MPRIS2::watcherInitialPlayState(QDBusPendingCallWatcher* watcher)
  */
 MPrisControl* Mixer_MPRIS2::watcherHelperGetMPrisControl(QDBusPendingCallWatcher* watcher)
 {
-       const QDBusMessage& msg = watcher->reply();
-       if ( msg.type() == QDBusMessage::ReplyMessage )
-       {
-               QObject* obj = watcher->parent();
-               MPrisControl* mad = qobject_cast<MPrisControl*>(obj);
-               if (mad != 0)
-               {
-                       return mad;
-               }
-               kWarning() << "Ignoring unexpected Control Id. object=" << obj;
-       }
+    const QDBusMessage& msg = watcher->reply();
+    if ( msg.type() == QDBusMessage::ReplyMessage ) {
+        QObject* obj = watcher->parent();
+        MPrisControl* mad = qobject_cast<MPrisControl*>(obj);
+        if (mad != 0) {
+            return mad;
+        }
+            kWarning() << "Ignoring unexpected Control Id. object=" << obj;
+    } else if ( msg.type() == QDBusMessage::ErrorMessage ) {
+        kError() << "ERROR in Media control operation, path=" << msg.path() << ", msg=" << msg;
+    }
 
-       else if ( msg.type() == QDBusMessage::ErrorMessage )
-       {
-               kError() << "ERROR in Media control operation, path=" << msg.path() << ", msg=" << msg;
-       }
-
-
-       watcher->deleteLater();
-       return 0;
+    watcher->deleteLater();
+    return 0;
 }
 
 void Mixer_MPRIS2::watcherPlugControlId(QDBusPendingCallWatcher* watcher)
 {
-       MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
-       if (mprisCtl == 0)
-       {
-               return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
-       }
+    MPrisControl* mprisCtl = watcherHelperGetMPrisControl(watcher);
+    if (mprisCtl == 0) {
+        return; // Reply for unknown media player. Probably "unplugged" (or not yet plugged)
+    }
 
-       const QDBusMessage& msg = watcher->reply();
-       QString id = mprisCtl->getId();
-       QString busDestination = mprisCtl->getBusDestination();
-       QString readableName = id; // Start with ID, but replace with reply (if exists)
+    const QDBusMessage& msg = watcher->reply();
+    QString id = mprisCtl->getId();
+    QString busDestination = mprisCtl->getBusDestination();
+    QString readableName = id; // Start with ID, but replace with reply (if exists)
 
-       kDebug() << "Plugging id=" << id << ", busDestination" << busDestination << ", name= " << readableName;
+    kDebug() << "Plugging id=" << id << ", busDestination" << busDestination << ", name= " << readableName;
 
-       QList<QVariant> repl = msg.arguments();
-       if ( ! repl.isEmpty() )
-       {
-               // We have to do some very ugly casting from QVariant to QDBusVariant to QVariant. This API totally sucks.
-               QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(repl.at(0));
-               QVariant result2 = dbusVariant.variant();
-               readableName = result2.toString();
+    QList<QVariant> repl = msg.arguments();
+    if ( ! repl.isEmpty() ) {
+        // We have to do some very ugly casting from QVariant to QDBusVariant to QVariant. This API totally sucks.
+        QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(repl.at(0));
+        QVariant result2 = dbusVariant.variant();
+        readableName = result2.toString();
 
-//                     kDebug() << "REPLY " << result2.type() << ": " << readableName;
+//      kDebug() << "REPLY " << result2.type() << ": " << readableName;
 
-               MixDevice::ChannelType ct = getChannelTypeFromPlayerId(id);
-               MixDevice* mdNew = new MixDevice(_mixer, id, readableName, ct);
-               // MPRIS2 doesn't support an actual mute switch. Mute is defined as volume = 0.0
-               // Thus we won't add the playback switch
-               Volume* vol = new Volume( 100, 0, false, false);
-               vol->addVolumeChannel(VolumeChannel(Volume::LEFT)); // MPRIS is only one control ("Mono")
-               MediaController* mediaContoller = mdNew->getMediaController();
-               mediaContoller->addMediaPlayControl();
-               mediaContoller->addMediaNextControl();
-               mediaContoller->addMediaPrevControl();
-               mdNew->setApplicationStream(true);
-               mdNew->addPlaybackVolume(*vol);
+        MixDevice::ChannelType ct = getChannelTypeFromPlayerId(id);
+        MixDevice* mdNew = new MixDevice(_mixer, id, readableName, ct);
+        // MPRIS2 doesn't support an actual mute switch. Mute is defined as volume = 0.0
+        // Thus we won't add the playback switch
+        Volume* vol = new Volume( 100, 0, false, false);
+        vol->addVolumeChannel(VolumeChannel(Volume::LEFT)); // MPRIS is only one control ("Mono")
+        MediaController* mediaContoller = mdNew->getMediaController();
+        mediaContoller->addMediaPlayControl();
+        mediaContoller->addMediaNextControl();
+        mediaContoller->addMediaPrevControl();
+        mdNew->setApplicationStream(true);
+        mdNew->addPlaybackVolume(*vol);
 
-               m_mixDevices.append( mdNew->addToPool() );
+        m_mixDevices.append( mdNew->addToPool() );
 
-               delete vol; // vol is only temporary. mdNew has its own volume object. => delete
+        delete vol; // vol is only temporary. mdNew has its own volume object. => delete
 
-               QDBusConnection sessionBus = QDBusConnection::sessionBus();
-               sessionBus.connect(busDestination, QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", "PropertiesChanged", mprisCtl, SLOT(onPropertyChange(QString,QVariantMap,QStringList)) );
-               connect(mprisCtl, SIGNAL(volumeChanged(MPrisControl*,double)), this, SLOT(volumeChanged(MPrisControl*,double)) );
-               connect(mprisCtl, SIGNAL(playbackStateChanged(MPrisControl*,MediaController::PlayState)), SLOT (playbackStateChanged(MPrisControl*,MediaController::PlayState)) );
+        QDBusConnection sessionBus = QDBusConnection::sessionBus();
+        sessionBus.connect(busDestination, QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", "PropertiesChanged", mprisCtl, SLOT(onPropertyChange(QString,QVariantMap,QStringList)) );
+        connect(mprisCtl, SIGNAL(volumeChanged(MPrisControl*,double)), this, SLOT(volumeChanged(MPrisControl*,double)) );
+        connect(mprisCtl, SIGNAL(playbackStateChanged(MPrisControl*,MediaController::PlayState)), SLOT (playbackStateChanged(MPrisControl*,MediaController::PlayState)) );
 
-               sessionBus.connect(busDestination, QString("/Player"), "org.freedesktop.MediaPlayer", "TrackChange", mprisCtl, SLOT(trackChangedIncoming(QVariantMap)) );
+        sessionBus.connect(busDestination, QString("/Player"), "org.freedesktop.MediaPlayer", "TrackChange", mprisCtl, SLOT(trackChangedIncoming(QVariantMap)) );
 
-               // The following line is evil: mad->playerIfc->property("Volume") is in fact a synchronous call, and
-               // sync calls are strictly forbidden, see bug 317926
-               //volumeChanged(mad, mad->playerIfc->property("Volume").toDouble());
+        // The following line is evil: mad->playerIfc->property("Volume") is in fact a synchronous call, and
+        // sync calls are strictly forbidden, see bug 317926
+        // volumeChanged(mad, mad->playerIfc->property("Volume").toDouble());
 
 
-               // --- Query initial state --------------------------------------------------------------------------------
-               QVariant v1 = QVariant(QString("org.mpris.MediaPlayer2.Player"));
+        // --- Query initial state --------------------------------------------------------------------------------
+        QVariant v1 = QVariant(QString("org.mpris.MediaPlayer2.Player"));
 
-               QVariant v2 = QVariant(QString("Volume"));
-               QDBusPendingReply<QVariant > repl2 = mprisCtl->propertyIfc->asyncCall("Get", v1, v2);
-               QDBusPendingCallWatcher* watcherOutgoing = new QDBusPendingCallWatcher(repl2, mprisCtl);
-               connect(watcherOutgoing, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherInitialVolume(QDBusPendingCallWatcher *)));
+        QVariant v2 = QVariant(QString("Volume"));
+        QDBusPendingReply<QVariant > repl2 = mprisCtl->propertyIfc->asyncCall("Get", v1, v2);
+        QDBusPendingCallWatcher* watcherOutgoing = new QDBusPendingCallWatcher(repl2, mprisCtl);
+        connect(watcherOutgoing, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherInitialVolume(QDBusPendingCallWatcher *)));
 
-               v2 = QVariant(QString("PlaybackStatus"));
-               repl2 = mprisCtl->propertyIfc->asyncCall("Get", v1, v2);
-               watcherOutgoing = new QDBusPendingCallWatcher(repl2, mprisCtl);
-               connect(watcherOutgoing, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherInitialPlayState(QDBusPendingCallWatcher *)));
+        v2 = QVariant(QString("PlaybackStatus"));
+        repl2 = mprisCtl->propertyIfc->asyncCall("Get", v1, v2);
+        watcherOutgoing = new QDBusPendingCallWatcher(repl2, mprisCtl);
+        connect(watcherOutgoing, SIGNAL(finished(QDBusPendingCallWatcher *)), this, SLOT(watcherInitialPlayState(QDBusPendingCallWatcher *)));
 
-               // Push notifyToReconfigureControls to stack, so it will not be executed synchronously
-               announceControlListAsync(id);
-       }
+        // Push notifyToReconfigureControls to stack, so it will not be executed synchronously
+        announceControlListAsync(id);
+    }
 
-       watcher->deleteLater();
+    watcher->deleteLater();
 }
 
 
@@ -543,8 +512,8 @@ void Mixer_MPRIS2::watcherPlugControlId(QDBusPendingCallWatcher* watcher)
  */
 void Mixer_MPRIS2::announceControlListAsync(QString /*streamId*/)
 {
-       // currently we do not use the streamId
-       QMetaObject::invokeMethod(this, "announceControlList", Qt::QueuedConnection);
+    // currently we do not use the streamId
+    QMetaObject::invokeMethod(this, "announceControlList", Qt::QueuedConnection);
 }
 
 void Mixer_MPRIS2::announceControlList()
@@ -570,43 +539,34 @@ void Mixer_MPRIS2::announceVolume()
  */
 void Mixer_MPRIS2::newMediaPlayer(QString name, QString oldOwner, QString newOwner)
 {
-       if ( name.startsWith("org.mpris.MediaPlayer2") )
-       {
-               if ( oldOwner.isEmpty() && !newOwner.isEmpty())
-               {
-                       kDebug() << "Mediaplayer registers: " << name;
-                       addMprisControlAsync(name);
-               }
-               else if ( !oldOwner.isEmpty() && newOwner.isEmpty())
-               {
-                       QString id = busDestinationToControlId(name);
-                       kDebug() << "Mediaplayer unregisters: " << name << " , id=" << id;
-
-                       // -1- Remove Mediaplayer connection
-                       if (controls.contains(id))
-                       {
-                               const MPrisControl *control = controls.value(id);
-                               QObject::disconnect(control,0,0,0);
-                               controls.remove(id);
-                       }
-
-                       // -2- Remove MixDevice from internal list
-                       std::shared_ptr<MixDevice> md = m_mixDevices.get(id);
-                       if (md)
-                       {
-                               // We know about the player that is unregistering => remove internally
-                               md->close();
-                               m_mixDevices.removeById(id);
-                               announceControlListAsync(id);
-                               kDebug() << "MixDevice 4 useCount=" << md.use_count();
-                       }
-               }
-               else
-               {
-                       kWarning() << "Mediaplayer has registered under a new name. This is currently not supported by KMix";
-               }
-       }
-
+    if ( name.startsWith("org.mpris.MediaPlayer2") ) {
+        if ( oldOwner.isEmpty() && !newOwner.isEmpty()) {
+            kDebug() << "Mediaplayer registers: " << name;
+            addMprisControlAsync(name);
+        } else if ( !oldOwner.isEmpty() && newOwner.isEmpty()) {
+            QString id = busDestinationToControlId(name);
+            kDebug() << "Mediaplayer unregisters: " << name << " , id=" << id;
+
+            // -1- Remove Mediaplayer connection
+            if (controls.contains(id)) {
+                const MPrisControl *control = controls.value(id);
+                QObject::disconnect(control,0,0,0);
+                controls.remove(id);
+            }
+
+            // -2- Remove MixDevice from internal list
+            std::shared_ptr<MixDevice> md = m_mixDevices.get(id);
+            if (md) {
+                // We know about the player that is unregistering => remove internally
+                md->close();
+                m_mixDevices.removeById(id);
+                announceControlListAsync(id);
+                kDebug() << "MixDevice 4 useCount=" << md.use_count();
+            }
+        } else {
+            kWarning() << "Mediaplayer has registered under a new name. This is currently not supported by KMix";
+        }
+    }
 }
 
 /**
@@ -614,26 +574,21 @@ void Mixer_MPRIS2::newMediaPlayer(QString name, QString oldOwner, QString newOwn
  */
 void MPrisControl::trackChangedIncoming(QVariantMap /*msg*/)
 {
-       kDebug() << "Track changed";
+    kDebug() << "Track changed";
 }
 
 MediaController::PlayState Mixer_MPRIS2::mprisPlayStateString2PlayState(const QString& playbackStatus)
 {
-       MediaController::PlayState playState = MediaController::PlayUnknown;
-       if (playbackStatus == "Playing")
-       {
-               playState = MediaController::PlayPlaying;
-       }
-       else if (playbackStatus == "Stopped")
-       {
-               playState = MediaController::PlayStopped;
-       }
-       else if (playbackStatus == "Paused")
-       {
-               playState = MediaController::PlayPaused;
-       }
+    MediaController::PlayState playState = MediaController::PlayUnknown;
+    if (playbackStatus == "Playing") {
+        playState = MediaController::PlayPlaying;
+    } else if (playbackStatus == "Stopped") {
+        playState = MediaController::PlayStopped;
+    } else if (playbackStatus == "Paused") {
+        playState = MediaController::PlayPaused;
+    }
 
-       return playState;
+    return playState;
 }
 
 /**
@@ -641,56 +596,53 @@ MediaController::PlayState Mixer_MPRIS2::mprisPlayStateString2PlayState(const QS
  */
 void MPrisControl::onPropertyChange(QString /*ifc*/,QVariantMap msg ,QStringList /*sl*/)
 {
-       QMap<QString, QVariant>::iterator v = msg.find("Volume");
-       if (v != msg.end() )
-       {
-               double volDouble = v.value().toDouble();
-               kDebug(67100) << "volumeChanged incoming: vol=" << volDouble;
-               emit volumeChanged( this, volDouble);
-       }
+    QMap<QString, QVariant>::iterator v = msg.find("Volume");
+    if (v != msg.end() ) {
+        double volDouble = v.value().toDouble();
+        kDebug(67100) << "volumeChanged incoming: vol=" << volDouble;
+        emit volumeChanged( this, volDouble);
+    }
 
-       v = msg.find("PlaybackStatus");
-       if (v != msg.end() )
-       {
-               QString playbackStatus = v.value().toString();
-               MediaController::PlayState playState = Mixer_MPRIS2::mprisPlayStateString2PlayState(playbackStatus);
-               kDebug() << "PlaybackStatus is now " << playbackStatus;
+    v = msg.find("PlaybackStatus");
+    if (v != msg.end() ) {
+        QString playbackStatus = v.value().toString();
+        MediaController::PlayState playState = Mixer_MPRIS2::mprisPlayStateString2PlayState(playbackStatus);
+        kDebug() << "PlaybackStatus is now " << playbackStatus;
 
-               emit playbackStateChanged(this, playState);
-       }
+        emit playbackStateChanged(this, playState);
+    }
 }
 
 
 Mixer_MPRIS2::~Mixer_MPRIS2()
 {
-       close();
+    close();
 }
 
 MPrisControl::MPrisControl(QString id, QString busDestination)
- : propertyIfc(0)
- , playerIfc(0)
-
+    : propertyIfc(0)
+    , playerIfc(0)
 {
-       volume = 0;
-       this->id = id;
-       this->busDestination = busDestination;
-       retrievedElems = MPrisControl::NONE;
+    volume = 0;
+    this->id = id;
+    this->busDestination = busDestination;
+    retrievedElems = MPrisControl::NONE;
 }
 
 MPrisControl::~MPrisControl()
 {
-       delete propertyIfc;
-       delete playerIfc;
+    delete propertyIfc;
+    delete playerIfc;
 }
 
 QString Mixer_MPRIS2::getDriverName()
 {
-       return "MPRIS2";
+    return "MPRIS2";
 }
 
 QString MPRIS2_getDriverName()
 {
-       return "MPRIS2";
+    return "MPRIS2";
 }
 
 #include "moc_mixer_mpris2.cpp"