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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FINDTHISDEVICEPLUGIN_H
|
|
|
|
#define FINDTHISDEVICEPLUGIN_H
|
|
|
|
|
|
|
|
#include <core/kdeconnectplugin.h>
|
2019-09-19 23:45:39 +01:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#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
|
|
|
// Qt
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_findthisdevice_debug.h"
|
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
|
|
|
~FindThisDevicePlugin() override;
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void connected() override{};
|
2018-03-29 00:46:12 +01:00
|
|
|
QString dbusPath() const override;
|
2022-09-10 22:23:52 +01:00
|
|
|
bool 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)) {
|
2019-09-19 23:45:39 +01:00
|
|
|
qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Error with getting the Windows Directory.";
|
|
|
|
} 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()) {
|
|
|
|
qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Could not find default ring tone.";
|
|
|
|
}
|
2020-05-14 14:06:49 +01:00
|
|
|
return soundURL.toLocalFile();
|
2019-09-19 23:45:39 +01:00
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
#endif // FINDTHISDEVICEPLUGIN_H
|