File indexing completed on 2024-04-28 15:34:03
0001 /* 0002 SPDX-FileCopyrightText: 2013 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef SOLID_DEVICES_P_H 0008 #define SOLID_DEVICES_P_H 0009 0010 #include "devices.h" 0011 0012 #include <QSharedPointer> 0013 #include <QWeakPointer> 0014 0015 #include <solid/device.h> 0016 #include <solid/devicenotifier.h> 0017 0018 namespace Solid 0019 { 0020 /** 0021 * Instances of this class are used as backends for 0022 * Devices and DevicesPrivate classes. 0023 * 0024 * The purpose of it is to create only one filter 0025 * (Solid::Predicate) and the corresponding devices list 0026 * per query, because there can be multiple clients 0027 * interested in the same device types. 0028 * 0029 * The user of the class needs not to worry about object 0030 * allocation and deallocation - just use DevicesQueryPrivate::forQuery 0031 * and store the retrieved smart pointer. 0032 */ 0033 class DevicesQueryPrivate : public QObject 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 /** 0039 * Returns a shared pointer to a handler for the specified query 0040 */ 0041 static QSharedPointer<DevicesQueryPrivate> forQuery(const QString &query); 0042 0043 ~DevicesQueryPrivate() override; 0044 0045 /** 0046 * Returns a list of devices that match the query 0047 */ 0048 const QStringList &devices() const; 0049 0050 /** 0051 * A query which is used to create the predicate. 0052 * It can be public since it is immutable. 0053 */ 0054 const QString query; 0055 0056 /** 0057 * A predicate used for checking whether a device 0058 * satisfies the specified query. 0059 * It can be public since it is immutable. 0060 */ 0061 const Solid::Predicate predicate; 0062 0063 Q_SIGNALS: 0064 void deviceAdded(const QString &udi); 0065 void deviceRemoved(const QString &udi); 0066 0067 public Q_SLOTS: 0068 void addDevice(const QString &udi); 0069 void removeDevice(const QString &udi); 0070 0071 private: 0072 DevicesQueryPrivate(const QString &query); 0073 0074 // TODO: This could be static or something 0075 Solid::DeviceNotifier *const notifier; 0076 0077 QStringList matchingDevices; 0078 0079 // Maps queries to the handler objects 0080 static QHash<QString, QWeakPointer<DevicesQueryPrivate>> handlers; 0081 }; 0082 0083 } // namespace Solid 0084 0085 #endif