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>
|
|
|
|
* SPDX-FileCopyrightText: 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com>
|
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 "findthisdeviceplugin.h"
|
|
|
|
|
|
|
|
// KF
|
|
|
|
#include <KPluginFactory>
|
2019-05-14 21:16:41 +01:00
|
|
|
|
|
|
|
#ifndef Q_OS_WIN
|
2019-05-13 23:36:29 +01:00
|
|
|
#include <PulseAudioQt/Context>
|
|
|
|
#include <PulseAudioQt/Sink>
|
2019-05-14 21:16:41 +01:00
|
|
|
#endif
|
2019-09-19 23:45:39 +01:00
|
|
|
|
2018-03-29 00:46:12 +01:00
|
|
|
// Qt
|
2022-09-10 22:23:52 +01:00
|
|
|
#include "plugin_findthisdevice_debug.h"
|
2018-03-29 00:46:12 +01:00
|
|
|
#include <QDBusConnection>
|
2019-04-30 17:24:09 +01:00
|
|
|
#include <QMediaPlayer>
|
2018-03-29 00:46:12 +01:00
|
|
|
|
2023-07-20 09:14:07 +01:00
|
|
|
#include <QAudioOutput>
|
|
|
|
|
2019-06-12 21:16:54 +01:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(FindThisDevicePlugin, "kdeconnect_findthisdevice.json")
|
2018-03-29 00:46:12 +01:00
|
|
|
|
2023-07-28 08:11:43 +01:00
|
|
|
void FindThisDevicePlugin::receivePacket(const NetworkPacket & /*np*/)
|
2018-03-29 00:46:12 +01:00
|
|
|
{
|
2019-10-27 17:08:51 +00:00
|
|
|
const QString soundFile = config()->getString(QStringLiteral("ringtone"), defaultSound());
|
2020-05-14 14:06:49 +01:00
|
|
|
const QUrl soundURL = QUrl::fromLocalFile(soundFile);
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2018-03-29 00:46:12 +01:00
|
|
|
if (soundURL.isEmpty()) {
|
2019-09-19 23:45:39 +01:00
|
|
|
qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sound, no valid ring tone specified.";
|
2023-07-31 08:25:45 +01:00
|
|
|
return;
|
2018-03-29 00:46:12 +01:00
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QMediaPlayer *player = new QMediaPlayer;
|
2023-07-20 09:14:07 +01:00
|
|
|
auto audioOutput = new QAudioOutput();
|
|
|
|
audioOutput->setVolume(100);
|
|
|
|
player->setSource(soundURL);
|
|
|
|
player->setAudioOutput(audioOutput);
|
|
|
|
connect(player, &QMediaPlayer::playingChanged, player, &QObject::deleteLater);
|
|
|
|
player->play();
|
2019-05-13 23:36:29 +01:00
|
|
|
|
2019-05-14 21:16:41 +01:00
|
|
|
#ifndef Q_OS_WIN
|
2019-05-13 23:36:29 +01:00
|
|
|
const auto sinks = PulseAudioQt::Context::instance()->sinks();
|
2022-09-10 22:23:52 +01:00
|
|
|
QVector<PulseAudioQt::Sink *> mutedSinks;
|
2019-05-13 23:36:29 +01:00
|
|
|
for (auto sink : sinks) {
|
|
|
|
if (sink->isMuted()) {
|
|
|
|
sink->setMuted(false);
|
|
|
|
mutedSinks.append(sink);
|
|
|
|
}
|
|
|
|
}
|
2024-04-21 16:45:08 +01:00
|
|
|
connect(player, &QMediaPlayer::playbackStateChanged, this, [mutedSinks] {
|
|
|
|
for (auto sink : std::as_const(mutedSinks)) {
|
2019-05-13 23:36:29 +01:00
|
|
|
sink->setMuted(true);
|
|
|
|
}
|
|
|
|
});
|
2019-05-14 21:16:41 +01:00
|
|
|
#endif
|
2019-05-13 23:36:29 +01:00
|
|
|
|
2019-09-19 23:45:39 +01:00
|
|
|
player->play();
|
2023-07-20 09:14:07 +01:00
|
|
|
connect(player, &QMediaPlayer::playingChanged, player, &QObject::deleteLater);
|
2018-03-29 00:46:12 +01:00
|
|
|
// TODO: ensure to use built-in loudspeakers
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FindThisDevicePlugin::dbusPath() const
|
|
|
|
{
|
2023-08-12 12:26:05 +01:00
|
|
|
return QLatin1String("/modules/kdeconnect/devices/%1/findthisdevice").arg(device()->id());
|
2018-03-29 00:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "findthisdeviceplugin.moc"
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_findthisdeviceplugin.cpp"
|