File indexing completed on 2022-09-27 16:29:37

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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0027 bool UsbDeviceMonitor::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
0028 #else
0029 bool UsbDeviceMonitor::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
0030 #endif
0031 {
0032     Q_UNUSED(eventType);
0033     Q_UNUSED(message);
0034     Q_UNUSED(result);
0035     return false;
0036 }
0037 
0038 bool UsbDeviceMonitor::startMonitoring()
0039 {
0040     auto notifier = Solid::DeviceNotifier::instance();
0041     auto refresh = [this] (const QString &udi) {
0042         Solid::Device device(udi);
0043         if (!device.is<Solid::StorageDrive>()) {
0044             Q_EMIT deviceChanged();
0045         }
0046     };
0047     connect(notifier, &Solid::DeviceNotifier::deviceAdded, this, refresh);
0048     connect(notifier, &Solid::DeviceNotifier::deviceRemoved, this, refresh);
0049     return true;
0050 }