File indexing completed on 2024-04-28 05:45:22
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Elvis Angelaccio <elvis.angelaccio@kde.org 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "placesdatasource.h" 0008 0009 #include <KLocalizedString> 0010 #include <KMountPoint> 0011 #include <KUserFeedback/Provider> 0012 #include <Solid/Device> 0013 #include <Solid/NetworkShare> 0014 #include <Solid/StorageAccess> 0015 0016 #include <QVariant> 0017 0018 PlacesDataSource::PlacesDataSource() 0019 : KUserFeedback::AbstractDataSource(QStringLiteral("places"), KUserFeedback::Provider::DetailedSystemInformation) 0020 { 0021 } 0022 0023 QString PlacesDataSource::name() const 0024 { 0025 return i18nc("name of kuserfeedback data source provided by dolphin", "Places"); 0026 } 0027 0028 QString PlacesDataSource::description() const 0029 { 0030 // TODO: add count of remote places grouped by protocol type. 0031 return i18nc("description of kuserfeedback data source provided by dolphin", "Count of available Network Shares"); 0032 } 0033 0034 QVariant PlacesDataSource::data() 0035 { 0036 QVariantMap map; 0037 0038 bool hasSSHFS = false; 0039 bool hasSambaShare = false; 0040 bool hasNfsShare = false; 0041 0042 const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::NetworkShare); 0043 for (const auto &device : devices) { 0044 if (!hasSSHFS && device.vendor() == QLatin1String("fuse.sshfs")) { 0045 // Ignore kdeconnect SSHFS mounts, we already know that people have those. 0046 auto storageAccess = device.as<Solid::StorageAccess>(); 0047 if (storageAccess) { 0048 auto mountPoint = KMountPoint::currentMountPoints().findByPath(storageAccess->filePath()); 0049 if (mountPoint && !mountPoint->mountedFrom().startsWith(QLatin1String("kdeconnect@"))) { 0050 hasSSHFS = true; 0051 continue; 0052 } 0053 } 0054 } 0055 0056 if (!device.is<Solid::NetworkShare>()) { 0057 continue; 0058 } 0059 0060 switch (device.as<Solid::NetworkShare>()->type()) { 0061 case Solid::NetworkShare::Cifs: 0062 hasSambaShare = true; 0063 continue; 0064 case Solid::NetworkShare::Nfs: 0065 hasNfsShare = true; 0066 continue; 0067 default: 0068 continue; 0069 } 0070 } 0071 0072 map.insert(QStringLiteral("hasSSHFSMount"), hasSSHFS); 0073 map.insert(QStringLiteral("hasSambaShare"), hasSambaShare); 0074 map.insert(QStringLiteral("hasNfsShare"), hasNfsShare); 0075 0076 return map; 0077 }