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

List:       kde-commits
Subject:    KDE/kdebase/runtime/phonon/kcm
From:       Colin Guthrie <kde () colin ! guthr ! ie>
Date:       2009-11-20 0:17:31
Message-ID: 1258676251.445840.6367.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1051736 by cguthrie:

phonon: Convert the phonon kcm to use the new GlobalConfig system now exported in \
libphonon.

Previously, the code here would look directly at the configuration files used
by libphonon in order to tweak the devices and reorder their priority.

This meant that a lot of code was copied from libphonon to here which is not
really ideal from a Good Programming Practice/code reuse perspective.

In addition to this, if the new PulseAudio support in phonon is in use then
the config files themselves are not consulted (all of the priority list
handling being handed over to PA) thus making the adjustment of the
configuration files rather irrelevent.

The solution implemented here is to use the new GlobalConfig class which is
now exported from from libphonon. This class basically wraps up the
configuration and either reads/writes the configuration files (when PA is not
in use) or reads/writes from the module-device-manager extension of PA which
I've specifically written to implement the routing policy used in KDE/phonon.

Note: One functional change is that the ticky box for showing advanced devices
is now written to the config immediately rather than waiting for the user to
hit the Apply button. This is needed so as to retrieve an approriate listing
of the devices from the configuration system (which looks at the advanced flag
to determin what devices to return via a different (existing) API).

Note 2: There is only one direct access to the config files left which relates
to an version update which I think we can just leave or eventually remove
completely (if the loss of these settings on upgrade is acceptable).

This change means that we rely on phonon trunk from kdesupport.

 M  +1 -1      CMakeLists.txt  
 M  +34 -193   devicepreference.cpp  
 D             globalconfig.cpp  
 D             globalconfig_p.h  


--- trunk/KDE/kdebase/runtime/phonon/kcm/CMakeLists.txt #1051735:1051736
@@ -1,6 +1,6 @@
 add_subdirectory(xine)
 
-set(kcmphonon_SRCS main.cpp devicepreference.cpp backendselection.cpp \
globalconfig.cpp) +set(kcmphonon_SRCS main.cpp devicepreference.cpp \
backendselection.cpp)  kde4_add_ui_files(kcmphonon_SRCS devicepreference.ui \
backendselection.ui)  
 kde4_add_plugin(kcm_phonon ${kcmphonon_SRCS})
--- trunk/KDE/kdebase/runtime/phonon/kcm/devicepreference.cpp #1051735:1051736
@@ -34,11 +34,12 @@
 
 #include <Phonon/AudioOutput>
 #include <Phonon/MediaObject>
+#include <phonon/backendinterface.h>
 #include <phonon/backendcapabilities.h>
+#include <phonon/globalconfig.h>
 #include <phonon/objectdescription.h>
 #include <phonon/phononnamespace.h>
-#include "qsettingsgroup_p.h"
-#include "globalconfig_p.h"
+#include "factory_p.h"
 #include <kfadewidgeteffect.h>
 
 #include <kdialog.h>
@@ -55,8 +56,6 @@
 Q_DECLARE_METATYPE(QList<int>)
 #endif
 
-using Phonon::QSettingsGroup;
-
 static const Phonon::Category captureCategories[] = {
     Phonon::NoCategory,
     Phonon::CommunicationCategory,
@@ -318,111 +317,35 @@
 
 QList<Phonon::AudioOutputDevice> DevicePreference::availableAudioOutputDevices() \
const  {
-    QList<Phonon::AudioOutputDevice> ret;
-    const QList<int> deviceIndexes = \
                Phonon::GlobalConfig().audioOutputDeviceListFor(Phonon::NoCategory,
-            showCheckBox->isChecked()
-            ? Phonon::GlobalConfig::ShowAdvancedDevices
-            : Phonon::GlobalConfig::HideAdvancedDevices);
-    foreach (int i, deviceIndexes) {
-        ret.append(Phonon::AudioOutputDevice::fromIndex(i));
-    }
-    return ret;
+    return Phonon::BackendCapabilities::availableAudioOutputDevices();
 }
 
 QList<Phonon::AudioCaptureDevice> DevicePreference::availableAudioCaptureDevices() \
const  {
-    QList<Phonon::AudioCaptureDevice> ret;
-    const QList<int> deviceIndexes = \
                Phonon::GlobalConfig().audioCaptureDeviceListFor(Phonon::NoCategory,
-            showCheckBox->isChecked()
-            ? Phonon::GlobalConfig::ShowAdvancedDevices
-            : Phonon::GlobalConfig::HideAdvancedDevices);
-    kDebug() << deviceIndexes;
-    foreach (int i, deviceIndexes) {
-        ret.append(Phonon::AudioCaptureDevice::fromIndex(i));
-    }
-    return ret;
+    return Phonon::BackendCapabilities::availableAudioCaptureDevices();
 }
 
 void DevicePreference::load()
 {
-    QSettings phononConfig(QLatin1String("kde.org"), QLatin1String("libphonon"));
-    QSettingsGroup outputDeviceGroup(&phononConfig, \
                QLatin1String("AudioOutputDevice"));
-    QSettingsGroup captureDeviceGroup(&phononConfig, \
                QLatin1String("AudioCaptureDevice"));
-    QSettingsGroup generalGroup(&phononConfig, QLatin1String("General"));
-    showCheckBox->setChecked(!generalGroup.value(QLatin1String("HideAdvancedDevices"), \
true)); +    showCheckBox->setChecked(!Phonon::GlobalConfig().getHideAdvancedDevices());
  
-    {
-        // the following call returns ordered according to NoCategory
-        const QList<Phonon::AudioOutputDevice> list = availableAudioOutputDevices();
-        m_outputModel[Phonon::NoCategory]->setModelData(list);
-
-        QHash<int, Phonon::AudioOutputDevice> hash;
-        foreach (const Phonon::AudioOutputDevice &dev, list) {
-            hash.insert(dev.index(), dev);
+    // "Load" the settings from the backend.
+    for (Phonon::Category cat = Phonon::NoCategory; cat <= Phonon::LastCategory; \
++cat) { +        QList<Phonon::AudioOutputDevice> list;
+        const QList<int> deviceIndexes = \
Phonon::GlobalConfig().audioOutputDeviceListFor(cat); +        foreach (int i, \
deviceIndexes) { +            list.append(Phonon::AudioOutputDevice::fromIndex(i));
         }
-        for (int i = 0; i <= Phonon::LastCategory; ++i) {
-            const QString configKey(QLatin1String("Category_") + \
                QString::number(i));
-            if (!outputDeviceGroup.hasKey(configKey)) {
-                m_outputModel[i]->setModelData(list); // use the NoCategory order
-                continue;
-            }
-            QHash<int, Phonon::AudioOutputDevice> hashCopy(hash);
-            const QList<int> order = outputDeviceGroup.value(configKey, \
                QList<int>());
-            QList<Phonon::AudioOutputDevice> orderedList;
-            foreach (int idx, order) {
-                if (hashCopy.contains(idx)) {
-                    orderedList << hashCopy.take(idx);
-                }
-            }
-            if (hashCopy.size() > 1) {
-                // keep the order of the original list
-                foreach (const Phonon::AudioOutputDevice &dev, list) {
-                    if (hashCopy.contains(dev.index())) {
-                        orderedList << hashCopy.take(dev.index());
-                    }
-                }
-            } else if (hashCopy.size() == 1) {
-                orderedList += hashCopy.values();
-            }
-            m_outputModel[i]->setModelData(orderedList);
-        }
+        m_outputModel[cat]->setModelData(list);
     }
-    {
-        // the following call returns ordered according to NoCategory
-        QList<Phonon::AudioCaptureDevice> list = availableAudioCaptureDevices();
-        m_captureModel[Phonon::NoCategory]->setModelData(list);
-
-        QHash<int, Phonon::AudioCaptureDevice> hash;
-        foreach (const Phonon::AudioCaptureDevice &dev, list) {
-            hash.insert(dev.index(), dev);
+    for (int i = 0; i < captureCategoriesCount; ++i) {
+        const Phonon::Category cat = captureCategories[i];
+        QList<Phonon::AudioCaptureDevice> list;
+        const QList<int> deviceIndexes = \
Phonon::GlobalConfig().audioCaptureDeviceListFor(cat); +        foreach (int i, \
deviceIndexes) { +            list.append(Phonon::AudioCaptureDevice::fromIndex(i));
         }
-        for (int i = 1; i < captureCategoriesCount; ++i) { // i == 1 to skip \
                NoCategory
-            const Phonon::Category cat = captureCategories[i];
-            const QString configKey(QLatin1String("Category_") + \
                QString::number(cat));
-            if (!captureDeviceGroup.hasKey(configKey)) {
-                m_captureModel[cat]->setModelData(list); // use the NoCategory order
-                continue;
-            }
-            QHash<int, Phonon::AudioCaptureDevice> hashCopy(hash);
-            const QList<int> order = captureDeviceGroup.value(configKey, \
                QList<int>());
-            QList<Phonon::AudioCaptureDevice> orderedList;
-            foreach (int idx, order) {
-                if (hashCopy.contains(idx)) {
-                    orderedList << hashCopy.take(idx);
-                }
-            }
-            if (hashCopy.size() > 1) {
-                // keep the order of the original list
-                foreach (const Phonon::AudioCaptureDevice &dev, list) {
-                    if (hashCopy.contains(dev.index())) {
-                        orderedList << hashCopy.take(dev.index());
-                    }
-                }
-            } else if (hashCopy.size() == 1) {
-                orderedList += hashCopy.values();
-            }
-            m_captureModel[cat]->setModelData(orderedList);
-        }
+        m_captureModel[cat]->setModelData(list);
     }
 
     deviceList->resizeColumnToContents(0);
@@ -430,11 +353,6 @@
 
 void DevicePreference::save()
 {
-    QSettings config(QLatin1String("kde.org"), QLatin1String("libphonon"));
-    {
-        QSettingsGroup generalGroup(&config, QLatin1String("General"));
-        generalGroup.setValue(QLatin1String("HideAdvancedDevices"), \
                !showCheckBox->isChecked());
-    }
     if (!m_removeOnApply.isEmpty()) {
         QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kded", \
"/modules/phononserver",  "org.kde.PhononServer", "removeAudioDevices");
@@ -442,34 +360,17 @@
         QDBusConnection::sessionBus().send(msg);
         m_removeOnApply.clear();
     }
-    {
-        QSettingsGroup globalGroup(&config, QLatin1String("AudioOutputDevice"));
-        const QList<int> noCategoryOrder = \
                m_outputModel.value(Phonon::NoCategory)->tupleIndexOrder();
-        globalGroup.setValue(QLatin1String("Category_") + \
                QString::number(Phonon::NoCategory), noCategoryOrder);
-        for (int i = 0; i <= Phonon::LastCategory; ++i) {
-            Q_ASSERT(m_outputModel.value(i));
-            const QList<int> order = m_outputModel.value(i)->tupleIndexOrder();
-            if (order == noCategoryOrder) {
-                globalGroup.removeEntry(QLatin1String("Category_") + \
                QString::number(i));
-            } else {
-                globalGroup.setValue(QLatin1String("Category_") + \
                QString::number(i), order);
-            }
-        }
+
+    for (Phonon::Category cat = Phonon::NoCategory; cat <= Phonon::LastCategory; \
++cat) { +        Q_ASSERT(m_outputModel.value(cat));
+        const QList<int> order = m_outputModel.value(cat)->tupleIndexOrder();
+        Phonon::GlobalConfig().setAudioOutputDeviceListFor(cat, order);
     }
-    {
-        QSettingsGroup globalGroup(&config, QLatin1String("AudioCaptureDevice"));
-        const QList<int> noCategoryOrder = \
                m_captureModel.value(Phonon::NoCategory)->tupleIndexOrder();
-        globalGroup.setValue(QLatin1String("Category_") + \
                QString::number(Phonon::NoCategory), noCategoryOrder);
-        for (int i = 1; i < captureCategoriesCount; ++i) {
-            const Phonon::Category cat = captureCategories[i];
-            Q_ASSERT(m_captureModel.value(cat));
-            const QList<int> order = m_captureModel.value(cat)->tupleIndexOrder();
-            if (order == noCategoryOrder) {
-                globalGroup.removeEntry(QLatin1String("Category_") + \
                QString::number(cat));
-            } else {
-                globalGroup.setValue(QLatin1String("Category_") + \
                QString::number(cat), order);
-            }
-        }
+    for (int i = 1; i < captureCategoriesCount; ++i) {
+        const Phonon::Category cat = captureCategories[i];
+        Q_ASSERT(m_captureModel.value(cat));
+        const QList<int> order = m_captureModel.value(cat)->tupleIndexOrder();
+        Phonon::GlobalConfig().setAudioCaptureDeviceListFor(cat, order);
     }
 }
 
@@ -638,70 +539,10 @@
 
 void DevicePreference::on_showCheckBox_toggled()
 {
-    {
-        // the following call returns ordered according to NoCategory
-        const QList<Phonon::AudioOutputDevice> list = availableAudioOutputDevices();
-        m_outputModel[Phonon::NoCategory]->setModelData(list);
-
-        QHash<int, Phonon::AudioOutputDevice> hash;
-        foreach (const Phonon::AudioOutputDevice &dev, list) {
-            hash.insert(dev.index(), dev);
-        }
-        for (int i = 0; i <= Phonon::LastCategory; ++i) {
-            QHash<int, Phonon::AudioOutputDevice> hashCopy(hash);
-            const QList<int> order = m_outputModel[i]->tupleIndexOrder();
-            QList<Phonon::AudioOutputDevice> orderedList;
-            foreach (int idx, order) {
-                if (hashCopy.contains(idx)) {
-                    orderedList << hashCopy.take(idx);
-                }
-            }
-            if (hashCopy.size() > 1) {
-                // keep the order of the original list
-                foreach (const Phonon::AudioOutputDevice &dev, list) {
-                    if (hashCopy.contains(dev.index())) {
-                        orderedList << hashCopy.take(dev.index());
-                    }
-                }
-            } else if (hashCopy.size() == 1) {
-                orderedList += hashCopy.values();
-            }
-            m_outputModel[i]->setModelData(orderedList);
-        }
-    }
-    {
-        // the following call returns ordered according to NoCategory
-        const QList<Phonon::AudioCaptureDevice> list = \
                availableAudioCaptureDevices();
-        m_captureModel[Phonon::NoCategory]->setModelData(list);
-
-        QHash<int, Phonon::AudioCaptureDevice> hash;
-        foreach (const Phonon::AudioCaptureDevice &dev, list) {
-            hash.insert(dev.index(), dev);
-        }
-        for (int i = 1; i < captureCategoriesCount; ++i) {
-            const Phonon::Category cat = captureCategories[i];
-            QHash<int, Phonon::AudioCaptureDevice> hashCopy(hash);
-            const QList<int> order = m_captureModel[cat]->tupleIndexOrder();
-            QList<Phonon::AudioCaptureDevice> orderedList;
-            foreach (int idx, order) {
-                if (hashCopy.contains(idx)) {
-                    orderedList << hashCopy.take(idx);
-                }
-            }
-            if (hashCopy.size() > 1) {
-                // keep the order of the original list
-                foreach (const Phonon::AudioCaptureDevice &dev, list) {
-                    if (hashCopy.contains(dev.index())) {
-                        orderedList << hashCopy.take(dev.index());
-                    }
-                }
-            } else if (hashCopy.size() == 1) {
-                orderedList += hashCopy.values();
-            }
-            m_captureModel[cat]->setModelData(orderedList);
-        }
-    }
-    deviceList->resizeColumnToContents(0);
+    // In order to get the right list from the backend, we need to update the \
settings now +    // before calling availableAudio{Output,Capture}Devices()
+    Phonon::GlobalConfig().hideAdvancedDevices(!showCheckBox->isChecked());
+    load();
 }
 
 void DevicePreference::on_testPlaybackButton_toggled(bool down)


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

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