Avoid Phonon's deprecation warnings
[quassel.git] / src / qtui / phononnotificationbackend.cpp
index 821507c..b7317d2 100644 (file)
@@ -21,7 +21,8 @@
 #include <QFileDialog>
 
 #include <phonon/mediaobject.h>
-#include <Phonon/BackendCapabilities>
+#include <phonon/backendcapabilities.h>
+
 #include "phononnotificationbackend.h"
 
 #include "clientsettings.h"
@@ -33,13 +34,14 @@ PhononNotificationBackend::PhononNotificationBackend(QObject *parent)
     : AbstractNotificationBackend(parent),
     _media(0)
 {
-    _audioAvailable = ! Phonon::BackendCapabilities::availableAudioOutputDevices().isEmpty() ;
     NotificationSettings notificationSettings;
-    _enabled = notificationSettings.value("Phonon/Enabled", true).toBool();
-    createMediaObject(notificationSettings.value("Phonon/AudioFile", QString()).toString());
-
     notificationSettings.notify("Phonon/Enabled", this, SLOT(enabledChanged(const QVariant &)));
     notificationSettings.notify("Phonon/AudioFile", this, SLOT(audioFileChanged(const QVariant &)));
+
+    createMediaObject(notificationSettings.value("Phonon/AudioFile", QString()).toString());
+
+    _enabled = notificationSettings.value("Phonon/Enabled", true).toBool();
+    _audioAvailable = !Phonon::BackendCapabilities::availableAudioOutputDevices().isEmpty();
 }
 
 
@@ -53,7 +55,7 @@ PhononNotificationBackend::~PhononNotificationBackend()
 void PhononNotificationBackend::notify(const Notification &notification)
 {
     if (_enabled && (notification.type == Highlight || notification.type == PrivMsg)) {
-        if (_audioAvailable) {
+        if (_audioAvailable && _media) {
             _media->stop();
             _media->play();
         }
@@ -97,8 +99,7 @@ void PhononNotificationBackend::createMediaObject(const QString &file)
         return;
     }
 
-    _media = Phonon::createPlayer(Phonon::NotificationCategory,
-        Phonon::MediaSource(file));
+    _media = Phonon::createPlayer(Phonon::NotificationCategory, Phonon::MediaSource(QUrl::fromLocalFile(file)));
 }
 
 
@@ -109,7 +110,7 @@ PhononNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent)
     audioPreview(0)
 {
     ui.setupUi(this);
-    _audioAvailable = ! Phonon::BackendCapabilities::availableAudioOutputDevices().isEmpty() ;
+    _audioAvailable = !Phonon::BackendCapabilities::availableAudioOutputDevices().isEmpty();
     ui.enabled->setIcon(SmallIcon("media-playback-start"));
     ui.play->setIcon(SmallIcon("media-playback-start"));
     ui.open->setIcon(SmallIcon("document-open"));
@@ -128,21 +129,19 @@ PhononNotificationBackend::ConfigWidget::~ConfigWidget()
 
 void PhononNotificationBackend::ConfigWidget::widgetChanged()
 {
-    if ( ! _audioAvailable )
-    {
-        ui.play->setEnabled( ui.enabled->isChecked() );
-        ui.open->setEnabled( false );
-        ui.filename->setEnabled( false );
-        ui.filename->setText( QString() );
+    if (! _audioAvailable) {
+        ui.play->setEnabled(ui.enabled->isChecked());
+        ui.open->setEnabled(false);
+        ui.filename->setEnabled(false);
+        ui.filename->setText(QString());
     }
-    else
-    {
+    else {
         ui.play->setEnabled(ui.enabled->isChecked() && !ui.filename->text().isEmpty());
 
-        bool changed = (enabled != ui.enabled->isChecked()
-                || filename != ui.filename->text());
+        bool changed = (enabled != ui.enabled->isChecked() || filename != ui.filename->text());
 
-        if (changed != hasChanged()) setChangedState(changed);
+        if (changed != hasChanged())
+            setChangedState(changed);
     }
 }
 
@@ -201,8 +200,7 @@ void PhononNotificationBackend::ConfigWidget::on_play_clicked()
             if (audioPreview)
                 delete audioPreview;
 
-            audioPreview = Phonon::createPlayer(Phonon::NotificationCategory,
-                    Phonon::MediaSource(ui.filename->text()));
+            audioPreview = Phonon::createPlayer(Phonon::NotificationCategory, Phonon::MediaSource(QUrl::fromLocalFile(ui.filename->text())));
             audioPreview->play();
         }
     }