File indexing completed on 2024-05-12 04:59:45

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 "kmtpstorageinterface.h"
0010 
0011 #include <chrono>
0012 
0013 #include "kmtpdeviceinterface.h"
0014 
0015 using namespace std::chrono_literals;
0016 
0017 KMTPStorageInterface::KMTPStorageInterface(const QString &dbusObjectPath, KMTPDeviceInterface *parent)
0018     : QObject(parent)
0019 {
0020     m_dbusInterface = new org::kde::kmtp::Storage(QStringLiteral("org.kde.kmtpd5"), dbusObjectPath, QDBusConnection::sessionBus(), this);
0021     // Arbitrarily large number to prevent timeouts on file listing.
0022     // https://bugs.kde.org/show_bug.cgi?id=462059
0023     // https://github.com/libmtp/libmtp/issues/144
0024     m_dbusInterface->setTimeout(std::chrono::milliseconds(60min).count());
0025 
0026     qDBusRegisterMetaType<KMTPFile>();
0027     qDBusRegisterMetaType<KMTPFileList>();
0028 
0029     connect(m_dbusInterface, &org::kde::kmtp::Storage::dataReady, this, &KMTPStorageInterface::dataReady);
0030     connect(m_dbusInterface, &org::kde::kmtp::Storage::copyProgress, this, &KMTPStorageInterface::copyProgress);
0031     connect(m_dbusInterface, &org::kde::kmtp::Storage::copyFinished, this, &KMTPStorageInterface::copyFinished);
0032 }
0033 
0034 QString KMTPStorageInterface::description() const
0035 {
0036     return m_dbusInterface->description();
0037 }
0038 
0039 quint64 KMTPStorageInterface::maxCapacity() const
0040 {
0041     return m_dbusInterface->maxCapacity();
0042 }
0043 
0044 quint64 KMTPStorageInterface::freeSpaceInBytes() const
0045 {
0046     return m_dbusInterface->freeSpaceInBytes();
0047 }
0048 
0049 KMTPFileList KMTPStorageInterface::getFilesAndFolders(const QString &path, int &result) const
0050 {
0051     return m_dbusInterface->getFilesAndFolders(path, result);
0052 }
0053 
0054 std::variant<QDBusObjectPath, QDBusError> KMTPStorageInterface::getFilesAndFolders2(const QString &path) const
0055 {
0056     auto reply = m_dbusInterface->getFilesAndFolders2(path);
0057     reply.waitForFinished();
0058     if (reply.error().isValid()) {
0059         return reply.error();
0060     }
0061     return reply;
0062 }
0063 
0064 KMTPFile KMTPStorageInterface::getFileMetadata(const QString &path) const
0065 {
0066     return m_dbusInterface->getFileMetadata(path);
0067 }
0068 
0069 int KMTPStorageInterface::getFileToHandler(const QString &path) const
0070 {
0071     return m_dbusInterface->getFileToHandler(path);
0072 }
0073 
0074 int KMTPStorageInterface::getFileToFileDescriptor(const QDBusUnixFileDescriptor &descriptor, const QString &sourcePath) const
0075 {
0076     return m_dbusInterface->getFileToFileDescriptor(descriptor, sourcePath).value();
0077 }
0078 
0079 int KMTPStorageInterface::sendFileFromFileDescriptor(const QDBusUnixFileDescriptor &descriptor, const QString &destinationPath) const
0080 {
0081     return m_dbusInterface->sendFileFromFileDescriptor(descriptor, destinationPath);
0082 }
0083 
0084 int KMTPStorageInterface::setFileName(const QString &path, const QString &newName) const
0085 {
0086     return m_dbusInterface->setFileName(path, newName);
0087 }
0088 
0089 quint32 KMTPStorageInterface::createFolder(const QString &path) const
0090 {
0091     return m_dbusInterface->createFolder(path);
0092 }
0093 
0094 int KMTPStorageInterface::deleteObject(const QString &path) const
0095 {
0096     return m_dbusInterface->deleteObject(path);
0097 }
0098 
0099 #include "moc_kmtpstorageinterface.cpp"