File indexing completed on 2024-06-16 04:29:31

0001 /*
0002     SnoreNotify is a Notification Framework based on Qt
0003     Copyright (C) 2015  Hannah von Reth <vonreth@kde.org>
0004 
0005     SnoreNotify is free software: you can redistribute it and/or modify
0006     it under the terms of the GNU Lesser General Public License as published by
0007     the Free Software Foundation, either version 3 of the License, or
0008     (at your option) any later version.
0009 
0010     SnoreNotify is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU Lesser General Public License for more details.
0014 
0015     You should have received a copy of the GNU Lesser General Public License
0016     along with SnoreNotify.  If not, see <http://www.gnu.org/licenses/>.
0017 */
0018 #include "soundsettings.h"
0019 #include "soundconstants.h"
0020 #include "plugins/plugins.h"
0021 
0022 #include <QFileDialog>
0023 #include <QLineEdit>
0024 #include <QSpinBox>
0025 #include <QPushButton>
0026 
0027 SoundSettings::SoundSettings(Snore::SnorePlugin *snorePlugin, QWidget *parent) :
0028     PluginSettingsWidget(snorePlugin, parent),
0029     m_lineEditFileName(new QLineEdit),
0030     m_spinBoxVolume(new QSpinBox)
0031 {
0032     m_spinBoxVolume->setRange(0, 100);
0033     addRow(tr("Volume:"), m_spinBoxVolume);
0034 
0035     addRow(tr("Audio file:"), m_lineEditFileName, tr("The sound played when a notification is received."));
0036     QPushButton *button = new QPushButton(tr("Select a audio file"));
0037     connect(button, &QPushButton::clicked, [this]() {
0038         QFileDialog dialog;
0039         dialog.setNameFilter(tr("All Audio files").append(QLatin1String("(*.mp3 *.wav *.ogg)")));
0040         dialog.setFileMode(QFileDialog::ExistingFile);
0041         dialog.setDirectory(m_lineEditFileName->text());
0042         if (dialog.exec()) {
0043             QStringList files = dialog.selectedFiles();
0044             m_lineEditFileName->setText(files.first());
0045         }
0046     });
0047     addRow(QString(), button);
0048 }
0049 
0050 SoundSettings::~SoundSettings()
0051 {
0052 }
0053 
0054 void SoundSettings::load()
0055 {
0056     m_lineEditFileName->setText(settingsValue(SoundConstants::SoundKey).toString());
0057     m_spinBoxVolume->setValue(settingsValue(SoundConstants::Volume).toInt());
0058 }
0059 
0060 void SoundSettings::save()
0061 {
0062     setSettingsValue(SoundConstants::SoundKey, m_lineEditFileName->text());
0063     setSettingsValue(SoundConstants::Volume, m_spinBoxVolume->value());
0064 }
0065