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 <QStandardPaths>
|
|
|
|
#include <QFile>
|
|
|
|
#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")
|
|
|
|
|
|
|
|
class FindThisDevicePlugin
|
|
|
|
: public KdeConnectPlugin
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.findthisdevice")
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit FindThisDevicePlugin(QObject* parent, const QVariantList& args);
|
|
|
|
~FindThisDevicePlugin() override;
|
|
|
|
|
2019-09-19 23:45:39 +01:00
|
|
|
void connected() override {};
|
2018-03-29 00:46:12 +01:00
|
|
|
QString dbusPath() const override;
|
|
|
|
bool receivePacket(const NetworkPacket& np) override;
|
|
|
|
};
|
|
|
|
|
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];
|
|
|
|
if(!GetWindowsDirectory(infoBuf, INFO_BUFFER_SIZE)) {
|
|
|
|
qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Error with getting the Windows Directory.";
|
|
|
|
} else {
|
|
|
|
dirPath = QString::fromStdWString(infoBuf) + QStringLiteral("/media");
|
|
|
|
if (!dirPath.isEmpty()) {
|
|
|
|
soundURL = QUrl::fromUserInput(QStringLiteral("Ring01.wav"),
|
|
|
|
dirPath,
|
|
|
|
QUrl::AssumeLocalFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
const QStringList dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
|
|
|
for (const QString &dataLocation : dataLocations) {
|
|
|
|
dirPath = dataLocation + QStringLiteral("/sounds");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#endif //FINDTHISDEVICEPLUGIN_H
|