1 /***************************************************************************
2 * Copyright (C) 2005-2012 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include <QFileDialog>
23 #include <phonon/mediaobject.h>
25 #include "phononnotificationbackend.h"
27 #include "clientsettings.h"
28 #include "iconloader.h"
32 PhononNotificationBackend::PhononNotificationBackend(QObject *parent)
33 : AbstractNotificationBackend(parent),
36 NotificationSettings notificationSettings;
37 _enabled = notificationSettings.value("Phonon/Enabled", true).toBool();
38 createMediaObject(notificationSettings.value("Phonon/AudioFile", QString()).toString());
40 notificationSettings.notify("Phonon/Enabled", this, SLOT(enabledChanged(const QVariant &)));
41 notificationSettings.notify("Phonon/AudioFile", this, SLOT(audioFileChanged(const QVariant &)));
45 PhononNotificationBackend::~PhononNotificationBackend()
52 void PhononNotificationBackend::notify(const Notification ¬ification)
54 if (_enabled && _media && (notification.type == Highlight || notification.type == PrivMsg)) {
61 void PhononNotificationBackend::close(uint notificationId)
63 Q_UNUSED(notificationId);
67 void PhononNotificationBackend::enabledChanged(const QVariant &v)
69 _enabled = v.toBool();
73 void PhononNotificationBackend::audioFileChanged(const QVariant &v)
75 createMediaObject(v.toString());
79 SettingsPage *PhononNotificationBackend::createConfigWidget() const
81 return new ConfigWidget();
85 void PhononNotificationBackend::createMediaObject(const QString &file)
95 _media = Phonon::createPlayer(Phonon::NotificationCategory,
96 Phonon::MediaSource(file));
100 /***************************************************************************/
102 PhononNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent)
103 : SettingsPage("Internal", "PhononNotification", parent),
107 ui.enabled->setIcon(SmallIcon("media-playback-start"));
108 ui.play->setIcon(SmallIcon("media-playback-start"));
109 ui.open->setIcon(SmallIcon("document-open"));
111 connect(ui.enabled, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
112 connect(ui.filename, SIGNAL(textChanged(const QString &)), SLOT(widgetChanged()));
116 PhononNotificationBackend::ConfigWidget::~ConfigWidget()
123 void PhononNotificationBackend::ConfigWidget::widgetChanged()
125 ui.play->setEnabled(ui.enabled->isChecked() && !ui.filename->text().isEmpty());
127 bool changed = (enabled != ui.enabled->isChecked()
128 || filename != ui.filename->text());
130 if (changed != hasChanged()) setChangedState(changed);
134 bool PhononNotificationBackend::ConfigWidget::hasDefaults() const
140 void PhononNotificationBackend::ConfigWidget::defaults()
142 ui.enabled->setChecked(false);
143 ui.filename->setText(QString());
148 void PhononNotificationBackend::ConfigWidget::load()
150 NotificationSettings s;
151 enabled = s.value("Phonon/Enabled", false).toBool();
152 filename = s.value("Phonon/AudioFile", QString()).toString();
154 ui.enabled->setChecked(enabled);
155 ui.filename->setText(filename);
157 setChangedState(false);
161 void PhononNotificationBackend::ConfigWidget::save()
163 NotificationSettings s;
164 s.setValue("Phonon/Enabled", ui.enabled->isChecked());
165 s.setValue("Phonon/AudioFile", ui.filename->text());
170 void PhononNotificationBackend::ConfigWidget::on_open_clicked()
172 QString file = QFileDialog::getOpenFileName(this, tr("Select Audio File"));
173 if (!file.isEmpty()) {
174 ui.filename->setText(file);
175 ui.play->setEnabled(true);
181 void PhononNotificationBackend::ConfigWidget::on_play_clicked()
183 if (!ui.filename->text().isEmpty()) {
187 audioPreview = Phonon::createPlayer(Phonon::NotificationCategory,
188 Phonon::MediaSource(ui.filename->text()));
189 audioPreview->play();