7#include "iokitstorageaccess.h"
9#include <CoreFoundation/CoreFoundation.h>
10#include <DiskArbitration/DiskArbitration.h>
12using namespace Solid::Backends::IOKit;
14IOKitStorageAccess::IOKitStorageAccess(IOKitDevice *device)
15 : DeviceInterface(device)
16 , daDict(new DADictionary(device))
21IOKitStorageAccess::IOKitStorageAccess(
const IOKitDevice *device)
22 : DeviceInterface(device)
23 , daDict(new DADictionary(device))
28IOKitStorageAccess::~IOKitStorageAccess()
33bool IOKitStorageAccess::isAccessible()
const
36 const QVariant isMounted = m_device->property(QStringLiteral(
"isMounted"));
40QString IOKitStorageAccess::filePath()
const
44 if (
const CFURLRef urlRef = daDict->cfUrLRefForKey(kDADiskDescriptionVolumePathKey)) {
45 const CFStringRef mpRef = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
48 m_device->setProperty(
"mountPoint", QVariant(mountPoint));
49 bool isMounted = !mountPoint.
isEmpty();
50 const QString isMountedKey = QStringLiteral(
"isMounted");
51 const QVariant wasMounted = m_device->property(isMountedKey);
52 if (wasMounted.
isValid() && wasMounted.
toBool() != isMounted) {
53 IOKitStorageAccess(m_device).onPropertyChanged(QMap<QString, int>{{isMountedKey, isMounted}});
55 m_device->setProperty(
"isMounted", QVariant(isMounted));
60bool IOKitStorageAccess::isIgnored()
const
62 if (m_device->iOKitPropertyExists(QStringLiteral(
"Open"))) {
64 bool isIgnored = m_device->property(QStringLiteral(
"Open")).toBool() ==
false;
65 m_device->setProperty(
"isIgnored", QVariant(isIgnored));
68 const QVariant isIgnored = m_device->property(QStringLiteral(
"isIgnored"));
69 return isIgnored.isValid() && isIgnored.toBool();
72bool IOKitStorageAccess::isEncrypted()
const
78bool IOKitStorageAccess::setup()
84bool IOKitStorageAccess::teardown()
90void IOKitStorageAccess::onPropertyChanged(
const QMap<QString, int> &changes)
92 for (
auto it = changes.
cbegin(); it != changes.
cend(); ++it) {
93 if (it.key() == QLatin1String(
"isMounted")) {
94 Q_EMIT accessibilityChanged(m_device->property(QStringLiteral(
"isMounted")).toBool(), m_device->udi());
99#include "moc_iokitstorageaccess.cpp"
const_iterator cbegin() const const
const_iterator cend() const const
QString fromCFString(CFStringRef string)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const
bool toBool() const const