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
|
|
|
*/
|
|
|
|
|
2023-07-21 19:22:59 +01:00
|
|
|
#pragma once
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
#include <core/kdeconnectplugin.h>
|
2019-09-19 23:45:39 +01:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2023-07-21 13:53:23 +01:00
|
|
|
#include <QDebug>
|
2019-09-19 23:45:39 +01:00
|
|
|
#include <Windows.h>
|
|
|
|
#define INFO_BUFFER_SIZE 32767
|
|
|
|
#else
|
|
|
|
#include <QFile>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QStandardPaths>
|
2019-09-19 23:45:39 +01:00
|
|
|
#include <QUrl>
|
|
|
|
#endif
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
#define PACKET_TYPE_FINDMYPHONE_REQUEST QStringLiteral("kdeconnect.findmyphone.request")
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
class FindThisDevicePlugin : public KdeConnectPlugin
|
2018-03-29 00:46:12 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.findthisdevice")
|
|
|
|
|
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
explicit FindThisDevicePlugin(QObject *parent, const QVariantList &args);
|
2018-03-29 00:46:12 +01:00
|
|
|
|
|
|
|
QString dbusPath() const override;
|
2023-07-31 08:25:45 +01:00
|
|
|
void receivePacket(const NetworkPacket &np) override;
|
2018-03-29 00:46:12 +01:00
|
|
|
};
|
|
|
|
|
2019-09-19 23:45:39 +01:00
|
|
|
inline QString defaultSound()
|
|
|
|
{
|
|
|
|
QString dirPath;
|
|
|
|
QUrl soundURL;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
wchar_t infoBuf[INFO_BUFFER_SIZE];
|
2022-09-10 22:23:52 +01:00
|
|
|
if (!GetWindowsDirectory(infoBuf, INFO_BUFFER_SIZE)) {
|
2023-07-21 13:53:23 +01:00
|
|
|
qWarning() << "Error with getting the Windows Directory.";
|
2019-09-19 23:45:39 +01:00
|
|
|
} else {
|
|
|
|
dirPath = QString::fromStdWString(infoBuf) + QStringLiteral("/media");
|
|
|
|
if (!dirPath.isEmpty()) {
|
2022-09-10 22:23:52 +01:00
|
|
|
soundURL = QUrl::fromUserInput(QStringLiteral("Ring01.wav"), dirPath, QUrl::AssumeLocalFile);
|
2019-09-19 23:45:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
const QStringList dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
|
|
|
for (const QString &dataLocation : dataLocations) {
|
|
|
|
dirPath = dataLocation + QStringLiteral("/sounds");
|
2022-09-10 22:23:52 +01:00
|
|
|
soundURL = QUrl::fromUserInput(QStringLiteral("Oxygen-Im-Phone-Ring.ogg"), dirPath, QUrl::AssumeLocalFile);
|
2020-05-14 14:06:49 +01:00
|
|
|
if ((soundURL.isLocalFile() && soundURL.isValid() && QFile::exists(soundURL.toLocalFile()))) {
|
2019-09-19 23:45:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-29 00:46:12 +01:00
|
|
|
#endif
|
2019-09-19 23:45:39 +01:00
|
|
|
if (soundURL.isEmpty()) {
|
2023-07-20 14:59:08 +01:00
|
|
|
qWarning() << "Could not find default ring tone.";
|
2019-09-19 23:45:39 +01:00
|
|
|
}
|
2020-05-14 14:06:49 +01:00
|
|
|
return soundURL.toLocalFile();
|
2019-09-19 23:45:39 +01:00
|
|
|
}
|