File indexing completed on 2024-04-28 08:49:07

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0003  * SPDX-FileCopyrightText: 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #pragma once
0009 
0010 #include <core/kdeconnectplugin.h>
0011 
0012 #ifdef Q_OS_WIN
0013 #include <QDebug>
0014 #include <Windows.h>
0015 #define INFO_BUFFER_SIZE 32767
0016 #else
0017 #include <QFile>
0018 #include <QStandardPaths>
0019 #include <QUrl>
0020 #endif
0021 
0022 #define PACKET_TYPE_FINDMYPHONE_REQUEST QStringLiteral("kdeconnect.findmyphone.request")
0023 
0024 class FindThisDevicePlugin : public KdeConnectPlugin
0025 {
0026     Q_OBJECT
0027     Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.findthisdevice")
0028 
0029 public:
0030     using KdeConnectPlugin::KdeConnectPlugin;
0031 
0032     QString dbusPath() const override;
0033     void receivePacket(const NetworkPacket &np) override;
0034 };
0035 
0036 inline QString defaultSound()
0037 {
0038     QString dirPath;
0039     QUrl soundURL;
0040 #ifdef Q_OS_WIN
0041     wchar_t infoBuf[INFO_BUFFER_SIZE];
0042     if (!GetWindowsDirectory(infoBuf, INFO_BUFFER_SIZE)) {
0043         qWarning() << "Error with getting the Windows Directory.";
0044     } else {
0045         dirPath = QString::fromStdWString(infoBuf) + QStringLiteral("/media");
0046         if (!dirPath.isEmpty()) {
0047             soundURL = QUrl::fromUserInput(QStringLiteral("Ring01.wav"), dirPath, QUrl::AssumeLocalFile);
0048         }
0049     }
0050 #else
0051     const QStringList dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
0052     for (const QString &dataLocation : dataLocations) {
0053         dirPath = dataLocation + QStringLiteral("/sounds");
0054         soundURL = QUrl::fromUserInput(QStringLiteral("Oxygen-Im-Phone-Ring.ogg"), dirPath, QUrl::AssumeLocalFile);
0055         if ((soundURL.isLocalFile() && soundURL.isValid() && QFile::exists(soundURL.toLocalFile()))) {
0056             break;
0057         }
0058     }
0059 #endif
0060     if (soundURL.isEmpty()) {
0061         qWarning() << "Could not find default ring tone.";
0062     }
0063     return soundURL.toLocalFile();
0064 }