Changeset View
Changeset View
Standalone View
Standalone View
dataengines/devicenotifications/ksolidnotify.cpp
Show All 31 Lines | |||||
32 | #include <Solid/Predicate> | 32 | #include <Solid/Predicate> | ||
33 | 33 | | |||
34 | #include <KLocalizedString> | 34 | #include <KLocalizedString> | ||
35 | #include <processcore/process.h> | 35 | #include <processcore/process.h> | ||
36 | #include <processcore/processes.h> | 36 | #include <processcore/processes.h> | ||
37 | 37 | | |||
38 | #include <QStringList> | 38 | #include <QStringList> | ||
39 | #include <QProcess> | 39 | #include <QProcess> | ||
40 | #include <QFutureWatcher> | ||||
41 | #include <QtConcurrentRun> | ||||
40 | 42 | | |||
41 | KSolidNotify::KSolidNotify(QObject *parent): | 43 | KSolidNotify::KSolidNotify(QObject *parent): | ||
42 | QObject(parent) | 44 | QObject(parent) | ||
43 | { | 45 | { | ||
44 | Solid::Predicate p(Solid::DeviceInterface::StorageAccess); | 46 | QFutureWatcher<QVector<QString>>* watcher = new QFutureWatcher<QVector<QString>>(this); | ||
45 | p |= Solid::Predicate(Solid::DeviceInterface::OpticalDrive); | 47 | connect(watcher, &QFutureWatcher<QVector<QString>>::finished, this, [this, watcher] { | ||
46 | p |= Solid::Predicate(Solid::DeviceInterface::PortableMediaPlayer); | 48 | const QVector<QString> devices = watcher->future(); | ||
47 | const QList<Solid::Device> &devices = Solid::Device::listFromQuery(p); | 49 | for (const QString & udi: devices) { | ||
48 | for (const Solid::Device &dev : devices) { | 50 | auto it = m_devices.insert(udi, Solid::Device(udi)); | ||
49 | m_devices.insert(dev.udi(), dev); | 51 | connectSignals(&*it); | ||
50 | connectSignals(&m_devices[dev.udi()]); | | |||
51 | } | 52 | } | ||
52 | 53 | | |||
53 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, | 54 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, | ||
54 | this, &KSolidNotify::onDeviceAdded); | 55 | this, &KSolidNotify::onDeviceAdded); | ||
55 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceRemoved, | 56 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceRemoved, | ||
56 | this, &KSolidNotify::onDeviceRemoved); | 57 | this, &KSolidNotify::onDeviceRemoved); | ||
58 | watcher->deleteLater(); | ||||
59 | }); | ||||
60 | watcher->setFuture(QtConcurrent::run([] { | ||||
61 | Solid::Predicate p(Solid::DeviceInterface::StorageAccess); | ||||
62 | p |= Solid::Predicate(Solid::DeviceInterface::OpticalDrive); | ||||
63 | p |= Solid::Predicate(Solid::DeviceInterface::PortableMediaPlayer); | ||||
64 | const auto devices = Solid::Device::listFromQuery(p); | ||||
65 | | ||||
66 | QVector<QString> ret; | ||||
67 | ret.reserve(devices.size()); | ||||
68 | for (const Solid::Device &dev : devices) { | ||||
69 | ret << dev.udi(); | ||||
70 | } | ||||
71 | return ret; | ||||
72 | })); | ||||
57 | } | 73 | } | ||
58 | 74 | | |||
59 | void KSolidNotify::onDeviceAdded(const QString &udi) | 75 | void KSolidNotify::onDeviceAdded(const QString &udi) | ||
60 | { | 76 | { | ||
61 | // Clear any stale message from a previous instance | 77 | // Clear any stale message from a previous instance | ||
62 | emit clearNotification(udi); | 78 | emit clearNotification(udi); | ||
63 | Solid::Device device(udi); | 79 | Solid::Device device(udi); | ||
64 | m_devices.insert(udi, device); | 80 | m_devices.insert(udi, device); | ||
▲ Show 20 Lines • Show All 186 Lines • Show Last 20 Lines |