File: kmtpdeviceinterface.cpp

package info (click to toggle)
kio-extras 4%3A22.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,768 kB
  • sloc: cpp: 26,898; ansic: 4,443; perl: 1,058; xml: 97; sh: 69; python: 28; makefile: 9
file content (68 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download
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
/*
    This file is part of the KMTP framework, part of the KDE project.

    SPDX-FileCopyrightText: 2018 Andreas Krutzler <andreas.krutzler@gmx.net>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#include "kmtpdeviceinterface.h"
#include "kmtpstorageinterface.h"

KMTPDeviceInterface::KMTPDeviceInterface(const QString &dbusObjectPath, QObject *parent)
    : QObject(parent)
{
    m_dbusInterface = new org::kde::kmtp::Device(QStringLiteral("org.kde.kiod5"),
                                                 dbusObjectPath,
                                                 QDBusConnection::sessionBus(),
                                                 this);
    updateStorages();
}

void KMTPDeviceInterface::updateStorages()
{
    qDeleteAll(m_storages);
    m_storages.clear();

    const auto storageNames = m_dbusInterface->listStorages().value();
    m_storages.reserve(storageNames.count());
    for (const QDBusObjectPath &storageName : storageNames) {
        m_storages.append(new KMTPStorageInterface(storageName.path(), this));
    }
}

QString KMTPDeviceInterface::udi() const
{
    return m_dbusInterface->udi();
}

QString KMTPDeviceInterface::friendlyName() const
{
    return m_dbusInterface->friendlyName();
}

QVector<KMTPStorageInterface *> KMTPDeviceInterface::storages()
{
    // Devices may have changed?
    if (m_dbusInterface->devicesUpdated()) {
        updateStorages();
    }

    return m_storages;
}

KMTPStorageInterface *KMTPDeviceInterface::storageFromDescription(const QString &description) const
{
    auto storageIt = std::find_if(m_storages.constBegin(), m_storages.constEnd(), [description] (KMTPStorageInterface *storage) {
        return storage->description() == description;
    });

    return storageIt == m_storages.constEnd() ? nullptr : *storageIt;
}

int KMTPDeviceInterface::setFriendlyName(const QString &friendlyName)
{
    return m_dbusInterface->setFriendlyName(friendlyName);
}

#include "moc_kmtpdeviceinterface.cpp"