File indexing completed on 2024-04-21 05:48:34
0001 /* 0002 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 SPDX-License-Identifier: GPL-3.0-or-later 0004 */ 0005 0006 //////////////////////////////////////////////////////////////////////////////// 0007 // Linux implementation of UsbDeviceMonitor 0008 0009 #include <Solid/Device> 0010 #include <Solid/DeviceNotifier> 0011 #include <Solid/StorageDrive> 0012 #include "usbdevicemonitor.h" 0013 0014 UsbDeviceMonitor::UsbDeviceMonitor(QObject *parent) : 0015 QObject(parent), 0016 d_ptr(nullptr) 0017 { 0018 } 0019 0020 UsbDeviceMonitor::~UsbDeviceMonitor() = default; 0021 0022 void UsbDeviceMonitor::cleanup() 0023 { 0024 } 0025 0026 bool UsbDeviceMonitor::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) 0027 { 0028 Q_UNUSED(eventType); 0029 Q_UNUSED(message); 0030 Q_UNUSED(result); 0031 return false; 0032 } 0033 0034 bool UsbDeviceMonitor::startMonitoring() 0035 { 0036 auto notifier = Solid::DeviceNotifier::instance(); 0037 auto refresh = [this] (const QString &udi) { 0038 Solid::Device device(udi); 0039 if (!device.is<Solid::StorageDrive>()) { 0040 Q_EMIT deviceChanged(); 0041 } 0042 }; 0043 connect(notifier, &Solid::DeviceNotifier::deviceAdded, this, refresh); 0044 connect(notifier, &Solid::DeviceNotifier::deviceRemoved, this, refresh); 0045 return true; 0046 }