Solid

udisksstoragevolume.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Michael Zanetti <mzanetti@kde.org>
3 SPDX-FileCopyrightText: 2010-2012 Lukáš Tinkl <ltinkl@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "udisksstoragevolume.h"
9#include "udisks2.h"
10
11#include <QDir>
12
13using namespace Solid::Backends::UDisks2;
14
15StorageVolume::StorageVolume(Device *device)
16 : Block(device)
17{
18}
19
20StorageVolume::~StorageVolume()
21{
22}
23
24QString StorageVolume::encryptedContainerUdi() const
25{
26 const QString path = m_device->prop(QStringLiteral("CryptoBackingDevice")).value<QDBusObjectPath>().path();
27 if (path.isEmpty() || path == QLatin1String("/")) {
28 return QString();
29 } else {
30 return path;
31 }
32}
33
34qulonglong StorageVolume::size() const
35{
36 return m_device->prop(QStringLiteral("Size")).toULongLong();
37}
38
39QString StorageVolume::uuid() const
40{
41 return m_device->prop(QStringLiteral("IdUUID")).toString();
42}
43
44QString StorageVolume::label() const
45{
46 QString label = m_device->prop(QStringLiteral("HintName")).toString();
47 if (label.isEmpty()) {
48 label = m_device->prop(QStringLiteral("IdLabel")).toString();
49 }
50 if (label.isEmpty()) {
51 label = m_device->prop(QStringLiteral("Name")).toString();
52 }
53 return label;
54}
55
56QString StorageVolume::fsType() const
57{
58 return m_device->prop(QStringLiteral("IdType")).toString();
59}
60
61Solid::StorageVolume::UsageType StorageVolume::usage() const
62{
63 const QString usage = m_device->prop(QStringLiteral("IdUsage")).toString();
64
65 if (m_device->hasInterface(QStringLiteral(UD2_DBUS_INTERFACE_FILESYSTEM))) {
66 return Solid::StorageVolume::FileSystem;
67 } else if (m_device->isPartitionTable()) {
68 return Solid::StorageVolume::PartitionTable;
69 } else if (usage == QLatin1String("raid")) {
70 return Solid::StorageVolume::Raid;
71 } else if (m_device->isEncryptedContainer()) {
72 return Solid::StorageVolume::Encrypted;
73 } else if (usage == QLatin1String("unused") || usage.isEmpty()) {
74 return Solid::StorageVolume::Unused;
75 } else {
76 return Solid::StorageVolume::Other;
77 }
78}
79
80bool StorageVolume::isIgnored() const
81{
82 if (m_device->prop(QStringLiteral("HintIgnore")).toBool()) {
83 return true;
84 }
85
86 const QStringList mountOptions = m_device->prop(QStringLiteral("UserspaceMountOptions")).toStringList();
87 if (mountOptions.contains(QLatin1String("x-gdu.hide"))) {
88 return true;
89 }
90
91 const Solid::StorageVolume::UsageType usg = usage();
92
93 /* clang-format off */
94 if (m_device->isSwap()
95 || ((usg == Solid::StorageVolume::Unused
96 || usg == Solid::StorageVolume::Other
97 || usg == Solid::StorageVolume::PartitionTable)
98 && !m_device->isOpticalDisc())) { /* clang-format on */
99 return true;
100 }
101
102 const QString backingFile = m_device->prop(QStringLiteral("BackingFile")).toString();
103 return !backingFile.isEmpty() && !backingFile.startsWith(QDir::homePath());
104}
105
106#include "moc_udisksstoragevolume.cpp"
UsageType
This enum type defines the how a volume is used.
QString path(const QString &relativePath)
QString label(StandardShortcut id)
QString homePath()
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString toString() const const
QStringList toStringList() const const
qulonglong toULongLong(bool *ok) const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.