9#include "storagedevices.h"
10#include "baloodebug.h"
12#include <Solid/DeviceNotifier>
13#include <Solid/DeviceInterface>
15#include <Solid/StorageDrive>
16#include <Solid/StorageVolume>
17#include <Solid/StorageAccess>
18#include <Solid/NetworkShare>
19#include <Solid/OpticalDisc>
20#include <Solid/Predicate>
24StorageDevices::StorageDevices(
QObject* parent)
28 this, &StorageDevices::slotSolidDeviceAdded);
30 this, &StorageDevices::slotSolidDeviceRemoved);
35StorageDevices::~StorageDevices()
39void StorageDevices::initCacheEntries()
42 for (
const Solid::Device& dev : devices) {
43 createCacheEntry(dev);
47QList<StorageDevices::Entry> StorageDevices::allMedia()
const
49 return m_metadataCache.values();
52StorageDevices::Entry* StorageDevices::createCacheEntry(
const Solid::Device& dev)
58 const Solid::StorageAccess* storage = dev.
as<Solid::StorageAccess>();
64 auto it = m_metadataCache.insert(dev.
udi(), entry);
67 this, &StorageDevices::slotAccessibilityChanged);
73bool StorageDevices::isEmpty()
const
75 return m_metadataCache.isEmpty();
78void StorageDevices::slotSolidDeviceAdded(
const QString& udi)
80 qCDebug(BALOO) << udi;
81 Entry* e = createCacheEntry(Solid::Device(udi));
87void StorageDevices::slotSolidDeviceRemoved(
const QString& udi)
89 QHash< QString, Entry >::iterator it = m_metadataCache.find(udi);
90 if (it != m_metadataCache.end()) {
91 qCDebug(BALOO) <<
"Found removable storage volume for Baloo undocking:" << udi;
92 Q_EMIT deviceRemoved(&it.value());
93 m_metadataCache.erase(it);
97void StorageDevices::slotAccessibilityChanged(
bool accessible,
const QString& udi)
99 qCDebug(BALOO) << accessible << udi;
100 Q_UNUSED(accessible);
105 Entry* entry = &m_metadataCache[udi];
106 Q_ASSERT(entry !=
nullptr);
107 Q_EMIT deviceAccessibilityChanged(entry);
110StorageDevices::Entry::Entry()
114StorageDevices::Entry::Entry(
const Solid::Device& device)
119QString StorageDevices::Entry::mountPath()
const
121 if (
const Solid::StorageAccess* sa = m_device.as<Solid::StorageAccess>()) {
122 return sa->filePath();
128bool StorageDevices::Entry::isMounted()
const
130 if (
const Solid::StorageAccess* sa = m_device.as<Solid::StorageAccess>()) {
131 return sa->isAccessible();
137bool StorageDevices::Entry::isUsable()
const
139 if (mountPath().isEmpty()) {
145 const Solid::Device& dev = m_device;
146 if (dev.
is<Solid::StorageVolume>() && dev.
parent().
is<Solid::StorageDrive>()) {
148 if (
parent->isRemovable() ||
parent->isHotpluggable()) {
152 const Solid::StorageVolume*
volume = dev.
as<Solid::StorageVolume>();
153 if (
volume->isIgnored() ||
volume->usage() != Solid::StorageVolume::FileSystem) {
158 if (dev.
is<Solid::NetworkShare>()) {
160 }
else if (dev.
is<Solid::OpticalDisc>()) {
162 }
else if (dev.
is<Solid::StorageAccess>() && dev.
parentUdi() == QStringLiteral(
"/org/kde/fstab")) {
167 if (
const Solid::StorageAccess* sa = dev.
as<Solid::StorageAccess>()) {
168 usable = sa->isAccessible();
175#include "moc_storagedevices.cpp"
void deviceRemoved(const QString &udi)
void deviceAdded(const QString &udi)
QString parentUdi() const
static QList< Device > allDevices()
void accessibilityChanged(bool accessible, const QString &udi)
Implements storage for docIds without any associated data Instantiated for:
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)