]> cloud.milkyroute.net Git - dolphin.git/blob - src/userfeedback/placesdatasource.cpp
Port to KF6 rename of KUserFeedback
[dolphin.git] / src / userfeedback / placesdatasource.cpp
1 /*
2 * SPDX-FileCopyrightText: 2020 Elvis Angelaccio <elvis.angelaccio@kde.org
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "placesdatasource.h"
8
9 #include <KLocalizedString>
10 #include <KMountPoint>
11 #include <KUserFeedback/Provider>
12 #include <Solid/Device>
13 #include <Solid/NetworkShare>
14 #include <Solid/StorageAccess>
15
16 #include <QVariant>
17
18 PlacesDataSource::PlacesDataSource()
19 : KUserFeedback::AbstractDataSource(QStringLiteral("places"), KUserFeedback::Provider::DetailedSystemInformation)
20 {
21 }
22
23 QString PlacesDataSource::name() const
24 {
25 return i18nc("name of kuserfeedback data source provided by dolphin", "Places");
26 }
27
28 QString PlacesDataSource::description() const
29 {
30 // TODO: add count of remote places grouped by protocol type.
31 return i18nc("description of kuserfeedback data source provided by dolphin", "Count of available Network Shares");
32 }
33
34 QVariant PlacesDataSource::data()
35 {
36 QVariantMap map;
37
38 bool hasSSHFS = false;
39 bool hasSambaShare = false;
40 bool hasNfsShare = false;
41
42 const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::NetworkShare);
43 for (const auto &device : devices) {
44 if (!hasSSHFS && device.vendor() == QLatin1String("fuse.sshfs")) {
45 // Ignore kdeconnect SSHFS mounts, we already know that people have those.
46 auto storageAccess = device.as<Solid::StorageAccess>();
47 if (storageAccess) {
48 auto mountPoint = KMountPoint::currentMountPoints().findByPath(storageAccess->filePath());
49 if (mountPoint && !mountPoint->mountedFrom().startsWith(QLatin1String("kdeconnect@"))) {
50 hasSSHFS = true;
51 continue;
52 }
53 }
54 }
55
56 if (!device.is<Solid::NetworkShare>()) {
57 continue;
58 }
59
60 switch (device.as<Solid::NetworkShare>()->type()) {
61 case Solid::NetworkShare::Cifs:
62 hasSambaShare = true;
63 continue;
64 case Solid::NetworkShare::Nfs:
65 hasNfsShare = true;
66 continue;
67 default:
68 continue;
69 }
70 }
71
72 map.insert(QStringLiteral("hasSSHFSMount"), hasSSHFS);
73 map.insert(QStringLiteral("hasSambaShare"), hasSambaShare);
74 map.insert(QStringLiteral("hasNfsShare"), hasNfsShare);
75
76 return map;
77 }