Changeset View
Changeset View
Standalone View
Standalone View
src/solid/devices/backends/fstab/fstabdevice.cpp
Show All 13 Lines | 1 | /* | |||
---|---|---|---|---|---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Lesser General Public License for more details. | 15 | Lesser General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "fstabdevice.h" | 21 | #include "fstabdevice.h" | ||
22 | #include "fstabhandling.h" | | |||
23 | #include "fstabnetworkshare.h" | 22 | #include "fstabnetworkshare.h" | ||
24 | #include "fstabstorageaccess.h" | 23 | #include "fstabstorageaccess.h" | ||
25 | #include "fstabservice.h" | 24 | #include "fstabservice.h" | ||
26 | #include "fstab_debug.h" | 25 | #include "fstab_debug.h" | ||
27 | #include <QCoreApplication> | 26 | #include <QCoreApplication> | ||
28 | #include <QStringList> | 27 | #include <QStringList> | ||
29 | #include <QDir> | 28 | #include <QDir> | ||
30 | #include <QUrl> | 29 | #include <QUrl> | ||
31 | 30 | | |||
32 | using namespace Solid::Backends::Fstab; | 31 | using namespace Solid::Backends::Fstab; | ||
33 | 32 | | |||
34 | FstabDevice::FstabDevice(QString uid) : | 33 | FstabDevice::FstabDevice(QString uid, const FilesystemEntry& fsEntry, const SystemFilesystemTable& sysFsTable) : | ||
35 | Solid::Ifaces::Device(), | 34 | Solid::Ifaces::Device(), | ||
36 | m_uid(uid) | 35 | m_uid(uid), | ||
36 | m_fsEntry(fsEntry), | ||||
37 | m_systemFilesystemTable(sysFsTable) | ||||
37 | { | 38 | { | ||
38 | m_device = m_uid; | 39 | m_device = m_uid; | ||
39 | m_device.remove(parentUdi() + "/"); | 40 | m_device.remove(parentUdi() + "/"); | ||
40 | 41 | | |||
41 | const QString& fstype = FstabHandling::fstype(m_device); | 42 | QString fstype = m_fsEntry.type(); | ||
42 | qCDebug(FSTAB) << "Adding " << m_device << "type:" << fstype; | 43 | qCDebug(FSTAB) << "Adding " << m_device << "type:" << fstype; | ||
43 | 44 | | |||
44 | if (m_device.startsWith("//")) { | 45 | if (m_device.startsWith("//")) { | ||
45 | m_vendor = m_device.mid(2, m_device.indexOf("/", 2) - 2); | 46 | m_vendor = m_device.mid(2, m_device.indexOf("/", 2) - 2); | ||
46 | m_product = m_device.mid(m_device.indexOf("/", 2) + 1); | 47 | m_product = m_device.mid(m_device.indexOf("/", 2) + 1); | ||
47 | m_storageType = StorageType::NetworkShare; | 48 | m_storageType = StorageType::NetworkShare; | ||
48 | } else if (fstype.startsWith("nfs")) { | 49 | } else if (fstype.startsWith("nfs")) { | ||
49 | m_vendor = m_device.left(m_device.indexOf(":/")); | 50 | m_vendor = m_device.left(m_device.indexOf(":/")); | ||
50 | m_product = m_device.mid(m_device.indexOf(":/") + 1); | 51 | m_product = m_device.mid(m_device.indexOf(":/") + 1); | ||
51 | m_storageType = StorageType::NetworkShare; | 52 | m_storageType = StorageType::NetworkShare; | ||
52 | } else if (fstype.startsWith("fuse.") || | 53 | } else if (fstype.startsWith("fuse.") || | ||
53 | fstype == QLatin1String("overlay")) { | 54 | fstype == QLatin1String("overlay")) { | ||
54 | m_vendor = fstype; | 55 | m_vendor = fstype; | ||
55 | m_product = m_device.mid(m_device.indexOf(fstype) + fstype.length()); | 56 | m_product = m_fsEntry.mountPath(); | ||
56 | QString home = QDir::homePath(); | 57 | QString home = QDir::homePath(); | ||
57 | if (m_product.startsWith(home)) { | 58 | if (m_product.startsWith(home)) { | ||
58 | m_product = "~" + m_product.mid(home.length()); | 59 | m_product = "~" + m_product.mid(home.length()); | ||
59 | } | 60 | } | ||
60 | if ((fstype == QLatin1String("fuse.encfs")) || | 61 | if ((fstype == QLatin1String("fuse.encfs")) || | ||
61 | (fstype == QLatin1String("fuse.cryfs"))) { | 62 | (fstype == QLatin1String("fuse.cryfs"))) { | ||
62 | m_storageType = StorageType::Encrypted; | 63 | m_storageType = StorageType::Encrypted; | ||
63 | } | 64 | } | ||
64 | } | 65 | } | ||
65 | 66 | | |||
66 | const QStringList& gvfsOptions = FstabHandling::options(m_device); | 67 | QStringList gvfsOptions = m_fsEntry.mountOptions(); | ||
67 | 68 | | |||
68 | foreach (const QString& option, gvfsOptions) { | 69 | foreach (const QString& option, gvfsOptions) { | ||
69 | if (option.startsWith(QLatin1String("x-gvfs-name="))) { | 70 | if (option.startsWith(QLatin1String("x-gvfs-name="))) { | ||
70 | QStringRef encoded = option.midRef(12); | 71 | QStringRef encoded = option.midRef(12); | ||
71 | m_description = QUrl::fromPercentEncoding(encoded.toLatin1()); | 72 | m_description = QUrl::fromPercentEncoding(encoded.toLatin1()); | ||
72 | } else if (option.startsWith(QLatin1String("x-gvfs-icon="))) { | 73 | } else if (option.startsWith(QLatin1String("x-gvfs-icon="))) { | ||
73 | QStringRef encoded = option.midRef(12); | 74 | QStringRef encoded = option.midRef(12); | ||
74 | m_iconName = QUrl::fromPercentEncoding(encoded.toLatin1()); | 75 | m_iconName = QUrl::fromPercentEncoding(encoded.toLatin1()); | ||
Show All 11 Lines | |||||
86 | } | 87 | } | ||
87 | 88 | | |||
88 | if (m_iconName.isEmpty()) { | 89 | if (m_iconName.isEmpty()) { | ||
89 | if (m_storageType == StorageType::NetworkShare) { | 90 | if (m_storageType == StorageType::NetworkShare) { | ||
90 | m_iconName = QLatin1String("network-server"); | 91 | m_iconName = QLatin1String("network-server"); | ||
91 | } else if (m_storageType == StorageType::Encrypted) { | 92 | } else if (m_storageType == StorageType::Encrypted) { | ||
92 | m_iconName = QLatin1String("folder-decrypted"); | 93 | m_iconName = QLatin1String("folder-decrypted"); | ||
93 | } else { | 94 | } else { | ||
94 | const QStringList& mountPoints = FstabHandling::mountPoints(m_device); | 95 | QStringList mountPoints; | ||
96 | mountPoints << m_fsEntry.mountPath(); | ||||
95 | const QString home = QDir::homePath(); | 97 | const QString home = QDir::homePath(); | ||
96 | if (mountPoints.contains("/")) { | 98 | if (mountPoints.contains("/")) { | ||
97 | m_iconName = QStringLiteral("drive-harddisk-root"); | 99 | m_iconName = QStringLiteral("drive-harddisk-root"); | ||
98 | } else if (mountPoints.contains(home)) { | 100 | } else if (mountPoints.contains(home)) { | ||
99 | m_iconName = QStringLiteral("user-home"); | 101 | m_iconName = QStringLiteral("user-home"); | ||
100 | } else { | 102 | } else { | ||
101 | m_iconName = QStringLiteral("folder"); | 103 | m_iconName = QStringLiteral("folder"); | ||
102 | } | 104 | } | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 172 | { | |||
180 | return nullptr; | 182 | return nullptr; | ||
181 | } | 183 | } | ||
182 | 184 | | |||
183 | QString FstabDevice::device() const | 185 | QString FstabDevice::device() const | ||
184 | { | 186 | { | ||
185 | return m_device; | 187 | return m_device; | ||
186 | } | 188 | } | ||
187 | 189 | | |||
188 | void FstabDevice::onMtabChanged(const QString &device) | 190 | const FilesystemEntry& FstabDevice::filesystemEntry() const | ||
189 | { | 191 | { | ||
190 | if (m_device == device) { | 192 | return m_fsEntry; | ||
191 | emit mtabChanged(device); | | |||
192 | } | 193 | } | ||
194 | | ||||
195 | const SystemFilesystemTable& FstabDevice::systemFilesystemTable() const | ||||
196 | { | ||||
197 | return m_systemFilesystemTable; | ||||
198 | } | ||||
199 | | ||||
200 | void FstabDevice::onFilesystemEntryChanged(const FilesystemEntry &fsEntry) | ||||
201 | { | ||||
202 | if (fsEntry.id() != m_fsEntry.id()) { | ||||
203 | return; | ||||
204 | } | ||||
205 | m_fsEntry = fsEntry; | ||||
206 | emit filesystemEntryChanged(m_fsEntry); | ||||
193 | } | 207 | } |