File indexing completed on 2024-04-28 05:26:13
0001 /* This file is part of the KDE libraries 0002 0003 SPDX-FileCopyrightText: 2010 Eduardo Robles Elvira <edulix@gmail.com> 0004 SPDX-FileCopyrightText: 2010 Rafael Fernández López <ereslibre@kde.org> 0005 SPDX-FileCopyrightText: 2010 UFO Coders <info@ufocoders.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include "kdedbluedevil.h" 0013 0014 #include <QLoggingCategory> 0015 #include <QObject> 0016 #include <QUrl> 0017 0018 #include <KIO/WorkerBase> 0019 0020 /** 0021 * @short This class implements a bluetooth kioworker that list devices and their services. 0022 */ 0023 class KioBluetoothPrivate; 0024 0025 class KioBluetooth : public QObject, public KIO::WorkerBase 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 KioBluetooth(const QByteArray &pool, const QByteArray &app); 0031 0032 struct Service { 0033 QString name; 0034 QString icon; 0035 QString mimetype; 0036 QString uuid; 0037 }; 0038 0039 /** 0040 * As our kio does not perform any service action, but just list devices and their services, the 0041 * get function shall not do much other than setting a mimetype and returning some data that 0042 * could be useful for the mimetype handler. 0043 */ 0044 KIO::WorkerResult get(const QUrl &url) override; 0045 0046 /** 0047 * List current directory. There are two types of current directories in this kio: 0048 * 0049 * 1. First type, is the root dir, bluetooth:/. This directory is unique, and lists the remote 0050 * devices that our default bluetooth adapter sees. 0051 * 2. Remote device directory (something like bluetoth:/00_12_34_56_6d_34). This directory lists 0052 * the services provided by the given remote device. 0053 */ 0054 KIO::WorkerResult listDir(const QUrl &url) override; 0055 0056 KIO::WorkerResult stat(const QUrl &url) override; 0057 0058 /** 0059 * As at the momento we don't handle more than one level url paths, @p setHost has not much 0060 * difference with @p listDir 0061 * 0062 */ 0063 void setHost(const QString &hostname, quint16 port, const QString &user, const QString &pass) override; 0064 0065 /** 0066 * Returns a list of supported service names corresponding to the given uuids list. If an uuid is 0067 * not found in the uuids list, it is not added to the list of service names. 0068 */ 0069 QList<Service> getSupportedServices(const QStringList &uuids); 0070 0071 /** 0072 * Called by @p Bluetooth::listDir to create a "Received Files" folder entry. 0073 */ 0074 void listDownload(); 0075 0076 /** 0077 * Called by @p Bluetooth::listDir when listing root dir, bluetooth:/. 0078 */ 0079 void listDevices(); 0080 0081 /** 0082 * Called by @p Bluetooth::listDir when listing a remote device (something like 0083 * bluetoth:/00_12_34_56_6d_34) services. 0084 */ 0085 [[nodiscard]] KIO::WorkerResult listRemoteDeviceServices(); 0086 0087 public Q_SLOTS: 0088 void listDevice(const DeviceInfo device); 0089 0090 private: 0091 /** 0092 * This is set to true when @p setHost is called to list a given remote device, like for example 0093 * 00:2a:5E:8e:6e:f5. If listing the remote devices (bluetooth:/ uri), it's set back to false. 0094 */ 0095 bool m_hasCurrentHost; 0096 0097 /** 0098 * This is set in @p setHost when it's called to list a given remote device like for example 0099 * 00:2a:5E:8e:6e:f5. We don't directly set @p currentHost in @p setHost because libbludevil might not 0100 * have ready the remote bluetooth device yet ready at that time (it.s being created by the call 0101 * to @p Solid::Control::BluetoothDevice::createBluetoothRemoteDevice . 0102 */ 0103 QString m_currentHostname; 0104 0105 /** 0106 * Uppercase colon separated address (ex. 00:2A:5E:8E:6E:F5) 0107 */ 0108 QString m_currentHostAddress; 0109 0110 /** 0111 * This is an array containing as key the uuid and as value the name of the service that the 0112 * given uuid represents, and a representative icon. It only contains the supported service names. 0113 */ 0114 QMap<QString, Service> m_supportedServices; 0115 0116 /** 0117 * KDED DBus interface, used to communicate to the daemon since we need some status (like connected) 0118 */ 0119 org::kde::BlueDevil *m_kded; 0120 }; 0121 0122 Q_DECLARE_LOGGING_CATEGORY(BLUETOOTH)