1 /*
2 * %kadu copyright begin%
3 * Copyright 2011 Tomasz Rostanski (rozteck@interia.pl)
4 * Copyright 2011, 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
5 * Copyright 2011, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
6 * %kadu copyright end%
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <QtWidgets/QHBoxLayout>
22 #include <QtWidgets/QLabel>
23 #include <QtWidgets/QLineEdit>
24 #include <QtWidgets/QPushButton>
25
26 #include "configuration/configuration.h"
27 #include "configuration/deprecated-configuration-api.h"
28 #include "core/core.h"
29 #include "gui/widgets/configuration/notify-group-box.h"
30 #include "icons/kadu-icon.h"
31
32 #include "pcspeaker-notifier.h"
33
34 #include "pcspeaker-configuration-widget.h"
35
PCSpeakerConfigurationWidget(PCSpeakerNotifier * notifier,QWidget * parent)36 PCSpeakerConfigurationWidget::PCSpeakerConfigurationWidget(PCSpeakerNotifier *notifier, QWidget *parent) :
37 NotifierConfigurationWidget{parent},
38 m_notifier{notifier}
39 {
40 }
41
~PCSpeakerConfigurationWidget()42 PCSpeakerConfigurationWidget::~PCSpeakerConfigurationWidget()
43 {
44 }
45
setConfiguration(Configuration * configuration)46 void PCSpeakerConfigurationWidget::setConfiguration(Configuration *configuration)
47 {
48 m_configuration = configuration;
49 }
50
setIconsManager(IconsManager * iconsManager)51 void PCSpeakerConfigurationWidget::setIconsManager(IconsManager *iconsManager)
52 {
53 m_iconsManager = iconsManager;
54 }
55
init()56 void PCSpeakerConfigurationWidget::init()
57 {
58 soundEdit = new QLineEdit(this);
59 soundEdit->setToolTip(tr("Put the played sounds separate by space, _ for pause, eg. D2 C1# G0"));
60 testButton = new QPushButton(m_iconsManager->iconByPath(KaduIcon("external_modules/mediaplayer-media-playback-play")), QString(), this);
61 testButton->setIconSize(QSize{14, 14});
62 connect(testButton, SIGNAL(clicked()), this, SLOT(test()));
63
64 QHBoxLayout *layout = new QHBoxLayout(this);
65 layout->setMargin(0);
66 layout->addWidget(testButton);
67 layout->addWidget(soundEdit);
68
69 static_cast<NotifyGroupBox *>(parent())->addWidget(this);
70
71 }
72
saveNotifyConfigurations()73 void PCSpeakerConfigurationWidget::saveNotifyConfigurations()
74 {
75 if (!CurrentNotificationEvent.isEmpty())
76 Sounds[CurrentNotificationEvent] = soundEdit->text();
77
78 for (QMap<QString, QString>::const_iterator it = Sounds.constBegin(), end = Sounds.constEnd(); it != end; ++it)
79 m_configuration->deprecatedApi()->writeEntry("PC Speaker", it.key() + "_Sound", it.value());
80 }
81
switchToEvent(const QString & event)82 void PCSpeakerConfigurationWidget::switchToEvent(const QString &event)
83 {
84 if (!CurrentNotificationEvent.isEmpty())
85 Sounds[CurrentNotificationEvent] = soundEdit->text();
86
87 CurrentNotificationEvent = event;
88
89 if (Sounds.contains(event))
90 soundEdit->setText(Sounds[event]);
91 else
92 soundEdit->setText(m_configuration->deprecatedApi()->readEntry("PC Speaker", event + "_Sound"));
93 }
94
test()95 void PCSpeakerConfigurationWidget::test()
96 {
97 m_notifier->parseAndPlay(soundEdit->text());
98 }
99
100 #include "moc_pcspeaker-configuration-widget.cpp"
101