┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/userfeedback/placesdatasource.cpp
blob: 6db89636d0862e208c1399d8b0dc0396b12a8a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * SPDX-FileCopyrightText: 2020 Elvis Angelaccio <[email protected]
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "placesdatasource.h"

#include <KLocalizedString>
#include <KMountPoint>
#include <KUserFeedback/Provider>
#include <Solid/Device>
#include <Solid/NetworkShare>
#include <Solid/StorageAccess>

#include <QVariant>

PlacesDataSource::PlacesDataSource()
    : KUserFeedback::AbstractDataSource(QStringLiteral("places"), KUserFeedback::Provider::DetailedSystemInformation)
{}

QString PlacesDataSource::name() const
{
    return i18nc("name of kuserfeedback data source provided by dolphin", "Places");
}

QString PlacesDataSource::description() const
{
    // TODO: add count of remote places grouped by protocol type.
    return i18nc("description of kuserfeedback data source provided by dolphin", "Count of available Network Shares");
}

QVariant PlacesDataSource::data()
{
    QVariantMap map;

    bool hasSSHFS = false;
    bool hasSambaShare = false;
    bool hasNfsShare = false;

    const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::NetworkShare);
    for (const auto &device : devices) {
        if (!hasSSHFS && device.vendor() == QLatin1String("fuse.sshfs")) {
            // Ignore kdeconnect SSHFS mounts, we already know that people have those.
            auto storageAccess = device.as<Solid::StorageAccess>();
            if (storageAccess) {
                auto mountPoint = KMountPoint::currentMountPoints().findByPath(storageAccess->filePath());
                if (!mountPoint->mountedFrom().startsWith(QLatin1String("kdeconnect@"))) {
                    hasSSHFS = true;
                    continue;
                }
            }
        }

        if (!device.is<Solid::NetworkShare>()) {
            continue;
        }

        switch (device.as<Solid::NetworkShare>()->type()) {
        case Solid::NetworkShare::Cifs:
            hasSambaShare = true;
            continue;
        case Solid::NetworkShare::Nfs:
            hasNfsShare = true;
            continue;
        default:
            continue;
        }
    }

    map.insert(QStringLiteral("hasSSHFSMount"), hasSSHFS);
    map.insert(QStringLiteral("hasSambaShare"), hasSambaShare);
    map.insert(QStringLiteral("hasNfsShare"), hasNfsShare);

    return map;
}