X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fphononnotificationbackend.cpp;h=b7317d253359892288fb9b91d7cad2b2cf55675e;hp=b2116b5a7ce422617321a4b3906cef3b78654ba6;hb=307cafe026abea9badd8400b8fd594738f0160fe;hpb=694f9bfbf7f1af19108461c7e00d133e55082bce diff --git a/src/qtui/phononnotificationbackend.cpp b/src/qtui/phononnotificationbackend.cpp index b2116b5a..b7317d25 100644 --- a/src/qtui/phononnotificationbackend.cpp +++ b/src/qtui/phononnotificationbackend.cpp @@ -1,26 +1,27 @@ /*************************************************************************** -* Copyright (C) 2005-09 by the Quassel Project * -* devel@quassel-irc.org * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) version 3. * -* * -* This program 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 General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ + * Copyright (C) 2005-2013 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ #include #include +#include #include "phononnotificationbackend.h" @@ -34,11 +35,13 @@ PhononNotificationBackend::PhononNotificationBackend(QObject *parent) _media(0) { 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(); } @@ -51,9 +54,13 @@ PhononNotificationBackend::~PhononNotificationBackend() void PhononNotificationBackend::notify(const Notification ¬ification) { - if (_enabled && _media && (notification.type == Highlight || notification.type == PrivMsg)) { - _media->stop(); - _media->play(); + if (_enabled && (notification.type == Highlight || notification.type == PrivMsg)) { + if (_audioAvailable && _media) { + _media->stop(); + _media->play(); + } + else + QApplication::beep(); } } @@ -92,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))); } @@ -104,6 +110,7 @@ PhononNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) audioPreview(0) { ui.setupUi(this); + _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")); @@ -122,12 +129,20 @@ PhononNotificationBackend::ConfigWidget::~ConfigWidget() void PhononNotificationBackend::ConfigWidget::widgetChanged() { - ui.play->setEnabled(ui.enabled->isChecked() && !ui.filename->text().isEmpty()); + if (! _audioAvailable) { + ui.play->setEnabled(ui.enabled->isChecked()); + ui.open->setEnabled(false); + ui.filename->setEnabled(false); + ui.filename->setText(QString()); + } + 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); + } } @@ -180,12 +195,15 @@ void PhononNotificationBackend::ConfigWidget::on_open_clicked() void PhononNotificationBackend::ConfigWidget::on_play_clicked() { - if (!ui.filename->text().isEmpty()) { - if (audioPreview) - delete audioPreview; + if (_audioAvailable) { + if (!ui.filename->text().isEmpty()) { + if (audioPreview) + delete audioPreview; - audioPreview = Phonon::createPlayer(Phonon::NotificationCategory, - Phonon::MediaSource(ui.filename->text())); - audioPreview->play(); + audioPreview = Phonon::createPlayer(Phonon::NotificationCategory, Phonon::MediaSource(QUrl::fromLocalFile(ui.filename->text()))); + audioPreview->play(); + } } + else + QApplication::beep(); }