Warning, file /network/kio-extras/mtp/shared/kmtpdeviceinterface.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the KMTP framework, part of the KDE project.
0003 
0004     SPDX-FileCopyrightText: 2018 Andreas Krutzler <andreas.krutzler@gmx.net>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "kmtpdeviceinterface.h"
0010 #include "kmtpstorageinterface.h"
0011 
0012 KMTPDeviceInterface::KMTPDeviceInterface(const QString &dbusObjectPath, QObject *parent)
0013     : QObject(parent)
0014 {
0015     m_dbusInterface = new org::kde::kmtp::Device(QStringLiteral("org.kde.kmtpd5"), dbusObjectPath, QDBusConnection::sessionBus(), this);
0016     updateStorages();
0017 }
0018 
0019 void KMTPDeviceInterface::updateStorages()
0020 {
0021     qDeleteAll(m_storages);
0022     m_storages.clear();
0023 
0024     const auto storageNames = m_dbusInterface->listStorages().value();
0025     m_storages.reserve(storageNames.count());
0026     for (const QDBusObjectPath &storageName : storageNames) {
0027         m_storages.append(new KMTPStorageInterface(storageName.path(), this));
0028     }
0029 }
0030 
0031 QString KMTPDeviceInterface::udi() const
0032 {
0033     return m_dbusInterface->udi();
0034 }
0035 
0036 QString KMTPDeviceInterface::friendlyName() const
0037 {
0038     return m_dbusInterface->friendlyName();
0039 }
0040 
0041 QVector<KMTPStorageInterface *> KMTPDeviceInterface::storages()
0042 {
0043     // Devices may have changed?
0044     if (m_dbusInterface->devicesUpdated()) {
0045         updateStorages();
0046     }
0047 
0048     return m_storages;
0049 }
0050 
0051 KMTPStorageInterface *KMTPDeviceInterface::storageFromDescription(const QString &description) const
0052 {
0053     auto storageIt = std::find_if(m_storages.constBegin(), m_storages.constEnd(), [description](KMTPStorageInterface *storage) {
0054         return storage->description() == description;
0055     });
0056 
0057     return storageIt == m_storages.constEnd() ? nullptr : *storageIt;
0058 }
0059 
0060 int KMTPDeviceInterface::setFriendlyName(const QString &friendlyName)
0061 {
0062     return m_dbusInterface->setFriendlyName(friendlyName);
0063 }
0064 
0065 #include "moc_kmtpdeviceinterface.cpp"