2018-03-29 00:46:12 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
|
2018-03-29 00:46:12 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2018-03-29 00:46:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "findthisdevice_config.h"
|
2019-03-21 22:26:32 +00:00
|
|
|
#include "findthisdeviceplugin.h"
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
#include "ui_findthisdevice_config.h"
|
|
|
|
// KF
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
// Qt
|
|
|
|
#include <QStandardPaths>
|
2019-04-30 17:24:09 +01:00
|
|
|
#include <QMediaPlayer>
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
K_PLUGIN_FACTORY(FindThisDeviceConfigFactory, registerPlugin<FindThisDeviceConfig>();)
|
|
|
|
|
|
|
|
|
|
|
|
FindThisDeviceConfig::FindThisDeviceConfig(QWidget* parent, const QVariantList& args)
|
|
|
|
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_findthisdevice_config"))
|
|
|
|
, m_ui(new Ui::FindThisDeviceConfigUi())
|
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
|
|
const QStringList soundDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
|
|
|
QStringLiteral("sounds"),
|
|
|
|
QStandardPaths::LocateDirectory);
|
|
|
|
if (!soundDirs.isEmpty()) {
|
|
|
|
m_ui->soundFileRequester->setStartDir(QUrl::fromLocalFile(soundDirs.last()));
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(m_ui->playSoundButton, &QToolButton::clicked,
|
|
|
|
this, &FindThisDeviceConfig::playSound);
|
|
|
|
connect(m_ui->soundFileRequester, &KUrlRequester::textChanged,
|
2019-12-20 00:23:49 +00:00
|
|
|
this, &FindThisDeviceConfig::markAsChanged);
|
2018-03-29 00:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FindThisDeviceConfig::~FindThisDeviceConfig()
|
|
|
|
{
|
|
|
|
delete m_ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FindThisDeviceConfig::defaults()
|
|
|
|
{
|
|
|
|
KCModule::defaults();
|
|
|
|
|
2019-03-21 22:26:32 +00:00
|
|
|
m_ui->soundFileRequester->setText(defaultSound());
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
Q_EMIT changed(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindThisDeviceConfig::load()
|
|
|
|
{
|
|
|
|
KCModule::load();
|
|
|
|
|
2019-10-27 17:08:51 +00:00
|
|
|
const QString ringTone = config()->getString(QStringLiteral("ringtone"), defaultSound());
|
2018-03-29 00:46:12 +01:00
|
|
|
m_ui->soundFileRequester->setText(ringTone);
|
|
|
|
|
|
|
|
Q_EMIT changed(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindThisDeviceConfig::save()
|
|
|
|
{
|
|
|
|
config()->set(QStringLiteral("ringtone"), m_ui->soundFileRequester->text());
|
|
|
|
|
|
|
|
KCModule::save();
|
|
|
|
|
|
|
|
Q_EMIT changed(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindThisDeviceConfig::playSound()
|
|
|
|
{
|
2019-09-19 23:45:39 +01:00
|
|
|
const QString soundFile = m_ui->soundFileRequester->text();
|
|
|
|
|
|
|
|
QUrl soundURL = QUrl(soundFile);
|
2019-04-30 17:24:09 +01:00
|
|
|
QMediaPlayer* player = new QMediaPlayer;
|
|
|
|
player->setAudioRole(QAudio::Role(QAudio::NotificationRole));
|
|
|
|
player->setMedia(soundURL);
|
|
|
|
player->setVolume(100);
|
|
|
|
player->play();
|
|
|
|
connect(player, &QMediaPlayer::stateChanged, player, &QObject::deleteLater);
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "findthisdevice_config.moc"
|