Index: phonon-4.3.1/phonon/audiooutput.cpp
===================================================================
--- phonon-4.3.1.orig/phonon/audiooutput.cpp
+++ phonon-4.3.1/phonon/audiooutput.cpp
@@ -28,6 +28,7 @@
 #include "audiooutputinterface.h"
 #include "phononnamespace_p.h"
 #include "platform_p.h"
+#include "pulsesupport.h"
 
 #include <qmath.h>
 
@@ -305,8 +306,9 @@ void AudioOutputPrivate::_k_audioDeviceF
     pDebug() << Q_FUNC_INFO;
     // outputDeviceIndex identifies a failing device
     // fall back in the preference list of output devices
-    QList<int> deviceList = GlobalConfig().audioOutputDeviceListFor(category, GlobalConfig::AdvancedDevicesFromSettings | GlobalConfig::HideUnavailableDevices);
-    foreach (int devIndex, deviceList) {
+    const QList<int> deviceList = GlobalConfig().audioOutputDeviceListFor(category, GlobalConfig::AdvancedDevicesFromSettings | GlobalConfig::HideUnavailableDevices);
+    for (int i = 0; i < deviceList.count(); ++i) {
+        const int devIndex = deviceList.at(i);
         // if it's the same device as the one that failed, ignore it
         if (device.index() != devIndex) {
             const AudioOutputDevice &info = AudioOutputDevice::fromIndex(devIndex);
@@ -396,6 +398,16 @@ void AudioOutputPrivate::handleAutomatic
         }
         break;
     }
+
+    PulseSupport *pulse=PulseSupport::getInstance();
+    pulse->enable();
+    if (pulse->isActive())
+    {
+       // PulseAudio detected. Since this phonon version doesn't support it, we'll change the default device
+       // to the one we're falling back to.
+       GlobalConfig().setMostPriorityDeviceFor(category, device.index() );
+    }
+    pulse->shutdown();
 }
 
 AudioOutputPrivate::~AudioOutputPrivate()
Index: phonon-4.3.1/phonon/CMakeLists.txt
===================================================================
--- phonon-4.3.1.orig/phonon/CMakeLists.txt
+++ phonon-4.3.1/phonon/CMakeLists.txt
@@ -8,6 +8,24 @@ endif (PHONON_BUILD_EXAMPLES)
 
 add_subdirectory(experimental)
 
+macro_optional_find_package(PulseAudio 0.9.15)
+macro_log_feature(PULSEAUDIO_FOUND "PulseAudio" "A cross-platform, networked sound server." "http://www.pulseaudio.org" FALSE "" "Allows audio playback via the PulseAudio soundserver when it is running")
+macro_optional_find_package(GLIB2)
+macro_log_feature(GLIB2_FOUND "GLib2" "GLib 2 is required to compile the pulseaudio for Phonon" "http://www.gtk.org/download/" FALSE)
+
+if (GLIB2_FOUND AND PULSEAUDIO_FOUND)
+   set(PHONON_PULSESUPPORT TRUE CACHE BOOL "Has Phonon pulseaudio support ?")
+   if(PHONON_PULSESUPPORT)
+       add_definitions(-DHAVE_PULSEAUDIO)
+   endif(PHONON_PULSESUPPORT)
+   include_directories(${GLIB2_INCLUDE_DIR} ${PULSEAUDIO_INCLUDE_DIR})
+else(GLIB2_FOUND AND PULSEAUDIO_FOUND)
+   set(PHONON_PULSESUPPORT FALSE CACHE BOOL "Has Phonon pulseaudio support ?")
+   set(PULSEAUDIO_INCLUDE_DIR "")
+   set(PULSEAUDIO_LIBRARY "")
+   set(PULSEAUDIO_MAINLOOP_LIBRARY "")
+endif(GLIB2_FOUND AND PULSEAUDIO_FOUND)
+
 set(phonon_LIB_SRCS
    objectdescription.cpp
    objectdescriptionmodel.cpp
@@ -31,6 +49,7 @@ set(phonon_LIB_SRCS
    globalconfig.cpp
    factory.cpp
    platform.cpp
+   pulsesupport.cpp
    mediacontroller.cpp
    videowidget.cpp
    videoplayer.cpp
@@ -53,6 +72,9 @@ target_link_libraries(phonon ${QT_QTCORE
 if (QT_QTDBUS_FOUND)
   target_link_libraries(phonon ${QT_QTDBUS_LIBRARY})
 endif (QT_QTDBUS_FOUND)
+if (PHONON_PULSESUPPORT)
+    target_link_libraries(phonon ${GOBJECT_LIBRARIES} ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY})
+endif (PHONON_PULSESUPPORT)
 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
   # We need to explicitly link libm to phonon in Solaris
   target_link_libraries(phonon m)
@@ -95,6 +117,7 @@ install(FILES
    videowidget.h
    videowidgetinterface.h
    videoplayer.h
+   pulsesupport.h
    seekslider.h
    volumeslider.h
    effectwidget.h
Index: phonon-4.3.1/phonon/pulsesupport.cpp
===================================================================
--- /dev/null
+++ phonon-4.3.1/phonon/pulsesupport.cpp
@@ -0,0 +1,292 @@
+/*
+    Copyright (C) 2010 Colin Guthrie <cguthrie@mandriva.org>
+    Copyright (C) 2013 Harald Sitter <sitter@kde.org>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) version 3, or any
+    later version accepted by the membership of KDE e.V. (or its
+    successor approved by the membership of KDE e.V.), Nokia Corporation
+    (or its successors, if any) and the KDE Free Qt Foundation, which shall
+    act as a proxy defined in Section 6 of version 3 of the license.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "pulsesupport.h"
+
+#include <QtCore/QAbstractEventDispatcher>
+#include <QtCore/QDebug>
+#include <QtCore/QStringList>
+#include <QtCore/QTimer>
+#include <QtCore/QMutex>
+#include <QApplication>
+
+#ifdef HAVE_PULSEAUDIO
+#include <pulse/pulseaudio.h>
+#include <pulse/xmalloc.h>
+#include <pulse/glib-mainloop.h>
+
+#define HAVE_PULSEAUDIO_DEVICE_MANAGER PA_CHECK_VERSION(0,9,21)
+#if HAVE_PULSEAUDIO_DEVICE_MANAGER
+#  include <pulse/ext-device-manager.h>
+#endif
+#endif // HAVE_PULSEAUDIO
+
+#include "phononnamespace_p.h"
+#include "platform_p.h"
+
+#define PA_PROP_PHONON_STREAMID "phonon.streamid"
+
+namespace Phonon
+{
+
+QMutex probeMutex;
+static PulseSupport *s_instance = NULL;
+
+#ifdef HAVE_PULSEAUDIO
+/***
+* Prints a conditional debug message based on the current debug level
+* If obj is provided, classname and objectname will be printed as well
+*
+* see debugLevel()
+*/
+
+static int debugLevel() {
+    static int level = -1;
+    if (level < 1) {
+        level = 0;
+        QByteArray pulseenv = qgetenv("PHONON_PULSEAUDIO_DEBUG");
+        int l = pulseenv.toInt();
+        if (l > 0)
+            level = (l > 2 ? 2 : l);
+    }
+    return level;
+}
+
+static void logMessage(const QString &message, int priority = 2, QObject *obj=0);
+static void logMessage(const QString &message, int priority, QObject *obj)
+{
+    if (debugLevel() > 0) {
+        QString output;
+        if (obj) {
+            // Strip away namespace from className
+            QByteArray className(obj->metaObject()->className());
+            int nameLength = className.length() - className.lastIndexOf(':') - 1;
+            className = className.right(nameLength);
+            output.sprintf("%s %s (%s %p)", message.toLatin1().constData(),
+                           obj->objectName().toLatin1().constData(),
+                           className.constData(), obj);
+        }
+        else {
+            output = message;
+        }
+        if (priority <= debugLevel()) {
+            qDebug() << QString::fromLatin1("PulseSupport(%1): %2").arg(priority).arg(output);
+        }
+    }
+}
+
+static bool s_pulseActive = false;
+
+static pa_glib_mainloop *s_mainloop = NULL;
+static pa_context *s_context = NULL;
+
+static QString statename(pa_context_state_t state)
+{
+    switch (state)
+    {
+        case PA_CONTEXT_UNCONNECTED:  return QLatin1String("Unconnected");
+        case PA_CONTEXT_CONNECTING:   return QLatin1String("Connecting");
+        case PA_CONTEXT_AUTHORIZING:  return QLatin1String("Authorizing");
+        case PA_CONTEXT_SETTING_NAME: return QLatin1String("Setting Name");
+        case PA_CONTEXT_READY:        return QLatin1String("Ready");
+        case PA_CONTEXT_FAILED:       return QLatin1String("Failed");
+        case PA_CONTEXT_TERMINATED:   return QLatin1String("Terminated");
+    }
+
+    return QString::fromLatin1("Unknown state: %0").arg(state);
+}
+
+static void context_state_callback(pa_context *c, void *)
+{
+    Q_ASSERT(c);
+
+    logMessage(QString::fromLatin1("context_state_callback %1").arg(statename(pa_context_get_state(c))));
+    pa_context_state_t state = pa_context_get_state(c);
+    if (state == PA_CONTEXT_READY) {
+        // We've connected to PA, so it is active
+        s_pulseActive = true;
+
+        // Attempt to load things up
+        pa_operation *o;
+
+        // If we know do not have Device Manager support, we just create our dummy devices now
+        if (s_context != c) {
+            // As this is our probe phase, exit immediately
+            pa_context_disconnect(c);
+        }
+
+    } else if (!PA_CONTEXT_IS_GOOD(state)) {
+        /// @todo Deal with reconnection...
+        //logMessage(QString("Connection to PulseAudio lost: %1").arg(pa_strerror(pa_context_errno(c))));
+
+        // If this is our probe phase, exit our context immediately
+        if (s_context != c)
+            pa_context_disconnect(c);
+    }
+
+}
+#endif // HAVE_PULSEAUDIO
+
+
+PulseSupport *PulseSupport::getInstance()
+{
+    if (NULL == s_instance) {
+        /*
+         * In order to prevent the instance being used from multiple threads
+         * prior to it being contructed fully, we need to ensure we obtain a
+         * lock prior to creating it. After we acquire the lock, check to see
+         * if the object is created again before proceeding.
+         */
+        probeMutex.lock();
+        if (NULL == s_instance)
+            s_instance = new PulseSupport();
+        probeMutex.unlock();
+    }
+    return s_instance;
+}
+
+void PulseSupport::shutdown()
+{
+    if (NULL != s_instance) {
+        delete s_instance;
+        s_instance = NULL;
+    }
+}
+
+void PulseSupport::debug()
+{
+#ifdef HAVE_PULSEAUDIO
+    logMessage(QString::fromLatin1("Have we been initialised yet? %1").arg(s_instance ? "Yes" : "No"));
+    if (s_instance) {
+        logMessage(QString::fromLatin1("Connected to PulseAudio? %1").arg(s_pulseActive ? "Yes" : "No"));
+        logMessage(QString::fromLatin1("PulseAudio support 'Active'? %1").arg(s_instance->isActive() ? "Yes" : "No"));
+    }
+#endif
+}
+
+PulseSupport::PulseSupport()
+ : QObject(), mEnabled(false)
+{
+#ifdef HAVE_PULSEAUDIO
+    // To allow for easy debugging, give an easy way to disable this pulseaudio check
+    QByteArray pulseenv = qgetenv("PHONON_PULSEAUDIO_DISABLE");
+    if (pulseenv.toInt()) {
+        logMessage(QLatin1String("PulseAudio support disabled: PHONON_PULSEAUDIO_DISABLE is set"));
+        return;
+    }
+
+    if (!QAbstractEventDispatcher::instance() || !QAbstractEventDispatcher::instance()->metaObject()) {
+        qWarning("WARNING: Cannot construct PulseSupport because there is no Eventloop."
+                 " May be because of application shutdown.");
+        return;
+    }
+
+    // We require a glib event loop
+    if (!QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("EventDispatcherGlib")) {
+        qWarning("WARNING: Disabling PulseAudio integration for lack of GLib event loop.");
+        return;
+    }
+
+    // First of all conenct to PA via simple/blocking means and if that succeeds,
+    // use a fully async integrated mainloop method to connect and get proper support.
+    pa_mainloop *p_test_mainloop;
+    if (!(p_test_mainloop = pa_mainloop_new())) {
+        logMessage(QLatin1String("PulseAudio support disabled: Unable to create mainloop"));
+        return;
+    }
+
+    pa_context *p_test_context;
+    if (!(p_test_context = pa_context_new(pa_mainloop_get_api(p_test_mainloop), "libphonon-probe"))) {
+        logMessage(QLatin1String("PulseAudio support disabled: Unable to create context"));
+        pa_mainloop_free(p_test_mainloop);
+        return;
+    }
+
+    logMessage(QLatin1String("Probing for PulseAudio..."));
+    // (cg) Convert to PA_CONTEXT_NOFLAGS when PulseAudio 0.9.19 is required
+    if (pa_context_connect(p_test_context, NULL, static_cast<pa_context_flags_t>(0), NULL) < 0) {
+        logMessage(QString::fromLatin1("PulseAudio support disabled: %1").arg(QString::fromLocal8Bit(pa_strerror(pa_context_errno(p_test_context)))));
+        pa_context_disconnect(p_test_context);
+        pa_context_unref(p_test_context);
+        pa_mainloop_free(p_test_mainloop);
+        return;
+    }
+
+    pa_context_set_state_callback(p_test_context, &context_state_callback, NULL);
+    for (;;) {
+        pa_mainloop_iterate(p_test_mainloop, 1, NULL);
+
+        if (!PA_CONTEXT_IS_GOOD(pa_context_get_state(p_test_context))) {
+            logMessage(QLatin1String("PulseAudio probe complete."));
+            break;
+        }
+    }
+    pa_context_disconnect(p_test_context);
+    pa_context_unref(p_test_context);
+    pa_mainloop_free(p_test_mainloop);
+
+    if (!s_pulseActive) {
+        logMessage(QLatin1String("PulseAudio support is not available."));
+        return;
+    }
+
+    // If we're still here, PA is available.
+    logMessage(QLatin1String("PulseAudio support enabled"));
+
+#endif
+}
+
+PulseSupport::~PulseSupport()
+{
+#ifdef HAVE_PULSEAUDIO
+    if (s_context) {
+        pa_context_disconnect(s_context);
+        s_context = NULL;
+    }
+
+    if (s_mainloop) {
+        pa_glib_mainloop_free(s_mainloop);
+        s_mainloop = NULL;
+    }
+#endif
+}
+
+bool PulseSupport::isActive()
+{
+#ifdef HAVE_PULSEAUDIO
+    return mEnabled && s_pulseActive;
+#else
+    return false;
+#endif
+}
+
+void PulseSupport::enable(bool enabled)
+{
+    mEnabled = enabled;
+#ifdef HAVE_PULSEAUDIO
+    logMessage(QString::fromLocal8Bit("Enabled Breakdown: mEnabled: %1, s_pulseActive %2").arg(mEnabled ? "Yes" : "No" ).arg(s_pulseActive ? "Yes" : "No"));
+#endif
+}
+
+} // namespace Phonon
+
+#include "moc_pulsesupport.cpp"
Index: phonon-4.3.1/phonon/pulsesupport.h
===================================================================
--- /dev/null
+++ phonon-4.3.1/phonon/pulsesupport.h
@@ -0,0 +1,60 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2009 Colin Guthrie <cguthrie@mandriva.org>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) version 3, or any
+    later version accepted by the membership of KDE e.V. (or its
+    successor approved by the membership of KDE e.V.), Nokia Corporation
+    (or its successors, if any) and the KDE Free Qt Foundation, which shall
+    act as a proxy defined in Section 6 of version 3 of the license.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef PHONON_PULSESUPPORT_H
+#define PHONON_PULSESUPPORT_H
+
+#include "phonon_export.h"
+#include "phononnamespace.h"
+
+#include <QtCore/QtGlobal>
+#include <QtCore/QSet>
+
+namespace Phonon
+{
+
+// This is a quite simplified version of the real PulseSupport class
+// (available in recent phonon releases) which is only used to check
+// if PulseAudio is running in the system by trying to connect to it
+
+    class PHONON_EXPORT PulseSupport : public QObject
+    {
+        Q_OBJECT
+        public:
+            static PulseSupport* getInstance();
+            static void shutdown();
+
+            bool isActive();
+            void enable(bool enabled = true);
+
+            static void debug();
+
+        private:
+            PulseSupport();
+            ~PulseSupport();
+
+            bool mEnabled;
+    };
+} // namespace Phonon
+
+
+#endif // PHONON_PULSESUPPORT_H
Index: phonon-4.3.1/cmake/FindPulseAudio.cmake
===================================================================
--- /dev/null
+++ phonon-4.3.1/cmake/FindPulseAudio.cmake
@@ -0,0 +1,106 @@
+# Try to find the PulseAudio library
+#
+# Once done this will define:
+#
+#  PULSEAUDIO_FOUND - system has the PulseAudio library
+#  PULSEAUDIO_INCLUDE_DIR - the PulseAudio include directory
+#  PULSEAUDIO_LIBRARY - the libraries needed to use PulseAudio
+#  PULSEAUDIO_MAINLOOP_LIBRARY - the libraries needed to use PulsAudio Mainloop
+#
+# The minimum required version of PulseAudio can be specified using the
+# standard syntax, e.g. find_package(PulseAudio 1.0)
+#
+# Copyright (c) 2008, Matthias Kretz, <kretz@kde.org>
+# Copyright (c) 2009, Marcus Hufgard, <Marcus.Hufgard@hufgard.de>
+# Copyright (c) 2011, Colin Guthrie, <colin@mageia.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+# Support PULSEAUDIO_MINIMUM_VERSION for compatibility:
+if(NOT PULSEAUDIO_FIND_VERSION)
+  set(PULSEAUDIO_FIND_VERSION "${PULSEAUDIO_MINIMUM_VERSION}")
+endif(NOT PULSEAUDIO_FIND_VERSION)
+
+# the minimum version of PulseAudio we require
+if(NOT PULSEAUDIO_FIND_VERSION)
+  set(PULSEAUDIO_FIND_VERSION "0.9.9")
+endif(NOT PULSEAUDIO_FIND_VERSION)
+
+# Newer PA's ship a PackageConfig.cmake file, so lets try and use it.
+macro_optional_find_package(PulseAudio ${PULSEAUDIO_FIND_VERSION} QUIET NO_MODULE)
+if (NOT PULSEAUDIO_FOUND)
+
+if (NOT WIN32)
+   include(FindPkgConfig)
+   pkg_check_modules(PC_PULSEAUDIO QUIET libpulse>=${PULSEAUDIO_FIND_VERSION})
+   pkg_check_modules(PC_PULSEAUDIO_MAINLOOP QUIET libpulse-mainloop-glib)
+endif (NOT WIN32)
+
+find_path(PULSEAUDIO_INCLUDE_DIR pulse/pulseaudio.h
+   HINTS
+   ${PC_PULSEAUDIO_INCLUDEDIR}
+   ${PC_PULSEAUDIO_INCLUDE_DIRS}
+   )
+
+find_library(PULSEAUDIO_LIBRARY NAMES pulse libpulse
+   HINTS
+   ${PC_PULSEAUDIO_LIBDIR}
+   ${PC_PULSEAUDIO_LIBRARY_DIRS}
+   )
+
+find_library(PULSEAUDIO_MAINLOOP_LIBRARY NAMES pulse-mainloop pulse-mainloop-glib libpulse-mainloop-glib
+   HINTS
+   ${PC_PULSEAUDIO_LIBDIR}
+   ${PC_PULSEAUDIO_LIBRARY_DIRS}
+   )
+
+if (PULSEAUDIO_VERSION)
+   # Already in cache, be silent
+   set(PULSEAUDIO_FIND_QUIETLY TRUE)
+endif (PULSEAUDIO_VERSION)
+
+if (PULSEAUDIO_INCLUDE_DIR AND NOT PULSEAUDIO_VERSION)
+   # Use the separate major, minor, micro defines as these are more reliable than the combined string
+   # which may change if/when the minor or micro bits are dropped...
+   file(STRINGS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h" pulse_version_h REGEX ".*define.+PA_MAJOR.+")
+   string(REGEX REPLACE ".*define.+PA_M[A-Z]+[^0-9]+([0-9]+).*" "\\1" PULSEAUDIO_MAJOR "${pulse_version_h}")
+
+   file(STRINGS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h" pulse_version_h REGEX ".*define.+PA_MINOR.+")
+   string(REGEX REPLACE ".*define.+PA_M[A-Z]+[^0-9]+([0-9]+).*" "\\1" PULSEAUDIO_MINOR "${pulse_version_h}")
+
+   file(STRINGS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h" pulse_version_h REGEX ".*define.+PA_MICRO.+")
+   string(REGEX REPLACE ".*define.+PA_M[A-Z]+[^0-9]+([0-9]+).*" "\\1" PULSEAUDIO_MICRO "${pulse_version_h}")
+
+   set(PULSEAUDIO_VERSION "${PULSEAUDIO_MAJOR}.${PULSEAUDIO_MINOR}.${PULSEAUDIO_MICRO}" CACHE STRING "Version number of PulseAudio" FORCE)
+endif (PULSEAUDIO_INCLUDE_DIR AND NOT PULSEAUDIO_VERSION)
+
+# NB find_package_handle_standard_args seems to fail horribly and not work
+
+#include(FindPackageHandleStandardArgs)
+#find_package_handle_standard_args(PulseAudio REQUIRED_VARS PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR
+#                                             VERSION_VAR PULSEAUDIO_VERSION )
+
+if (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARY)
+  include(MacroEnsureVersion)
+  macro_ensure_version("${PULSEAUDIO_FIND_VERSION}" "${PULSEAUDIO_VERSION}" PULSEAUDIO_FOUND)
+else (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARY)
+   set(PULSEAUDIO_FOUND FALSE)
+endif (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARY)
+
+if (PULSEAUDIO_FOUND)
+   if (NOT PULSEAUDIO_FIND_QUIETLY)
+      message(STATUS "Found PulseAudio: ${PULSEAUDIO_LIBRARY}")
+      if (PULSEAUDIO_MAINLOOP_LIBRARY)
+          message(STATUS "Found PulseAudio Mainloop: ${PULSEAUDIO_MAINLOOP_LIBRARY}")
+      else (PULSAUDIO_MAINLOOP_LIBRARY)
+          message(STATUS "Could NOT find PulseAudio Mainloop Library")
+      endif (PULSEAUDIO_MAINLOOP_LIBRARY)
+   endif (NOT PULSEAUDIO_FIND_QUIETLY)
+else (PULSEAUDIO_FOUND)
+   message(STATUS "Could NOT find PulseAudio")
+endif (PULSEAUDIO_FOUND)
+
+mark_as_advanced(PULSEAUDIO_INCLUDE_DIR PULSEAUDIO_LIBRARY PULSEAUDIO_MAINLOOP_LIBRARY)
+
+endif (NOT PULSEAUDIO_FOUND)
Index: phonon-4.3.1/phonon/globalconfig.cpp
===================================================================
--- phonon-4.3.1.orig/phonon/globalconfig.cpp
+++ phonon-4.3.1/phonon/globalconfig.cpp
@@ -127,6 +127,19 @@ static QList<int> listSortedByConfig(con
     return deviceList;
 }
 
+void GlobalConfig::setMostPriorityDeviceFor(Phonon::Category category, int device)
+{
+    QSettingsGroup backendConfig(&m_config, QLatin1String("AudioOutputDevice")); // + Factory::identifier());
+    QString categoryKey = QLatin1String("Category_") + QString::number(static_cast<int>(category));
+
+    //Now we take the current configuration and just move/put the device at the beginning
+    QList<int> deviceList = backendConfig.value(categoryKey, QList<int>());
+    deviceList.removeAll(device);
+    deviceList.prepend(device);
+
+    backendConfig.setValue(categoryKey, deviceList);
+}
+
 QList<int> GlobalConfig::audioOutputDeviceListFor(Phonon::Category category, int override) const
 {
     //The devices need to be stored independently for every backend
Index: phonon-4.3.1/phonon/globalconfig_p.h
===================================================================
--- phonon-4.3.1.orig/phonon/globalconfig_p.h
+++ phonon-4.3.1/phonon/globalconfig_p.h
@@ -49,6 +49,8 @@ namespace Phonon
         QList<int> audioOutputDeviceListFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
         int audioOutputDeviceFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
 
+        void setMostPriorityDeviceFor(Phonon::Category category, int device);
+
 #ifndef QT_NO_PHONON_AUDIOCAPTURE
         QList<int> audioCaptureDeviceListFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
         int audioCaptureDeviceFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
