Warning, file /network/kio-extras/mtp/kiod_module/mtpstorage.h 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 MTP KIOD module, part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2018 Andreas Krutzler <andreas.krutzler@gmx.net> 0005 SPDX-FileCopyrightText: 2023 Harald Sitter <sitter@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef MTPSTORAGE_H 0011 #define MTPSTORAGE_H 0012 0013 #include <optional> 0014 0015 #include <QDBusContext> 0016 #include <QObject> 0017 0018 #include <kmtpfile.h> 0019 #include <libmtp.h> 0020 0021 class MTPDevice; 0022 0023 /** 0024 * @brief This D-Bus interface is used to access a single MTP storage. 0025 * 0026 * This includes storage management like file-, folder- and object-access. 0027 * 0028 * As a performance optimization to reduce hardware interaction, 0029 * a time based cache for file ids, mapping their path to their ID is used. 0030 */ 0031 class MTPStorage : public QObject, protected QDBusContext 0032 { 0033 Q_OBJECT 0034 Q_PROPERTY(QString description READ description) 0035 Q_PROPERTY(quint64 maxCapacity READ maxCapacity) 0036 Q_PROPERTY(quint64 freeSpaceInBytes READ freeSpaceInBytes) 0037 0038 public: 0039 explicit MTPStorage(const QString &dbusObjectPath, const LIBMTP_devicestorage_t *mtpStorage, MTPDevice *parent); 0040 0041 QString dbusObjectPath() const; 0042 0043 // D-Bus properties 0044 QString description() const; 0045 quint64 maxCapacity() const; 0046 quint64 freeSpaceInBytes(); 0047 0048 private: 0049 void setStorageProperties(const LIBMTP_devicestorage_t *storage); 0050 void updateStorageInfo(); 0051 0052 LIBMTP_mtpdevice_t *getDevice() const; 0053 0054 /** 0055 * @brief Get the correct file/folder from the device. 0056 * 0057 * @param path 0058 * @return 0059 */ 0060 KMTPFile getFileFromPath(const QString &path); 0061 0062 /** 0063 * @brief Get all children files/folders of @a parentId and cache them. 0064 * 0065 * @param path parent path, used for caching 0066 * @param parentId 0067 * @return 0068 */ 0069 KMTPFileList getFilesAndFoldersCached(const QString &path, quint32 parentId); 0070 0071 /** 0072 * @brief Find a given filename in the parentId's children 0073 * 0074 * @param fileNeedle 0075 * @param parentPath 0076 * @param parentId 0077 * @return std::optional<KMTPFile> 0078 */ 0079 std::optional<KMTPFile> findEntry(const QString &fileNeedle, const QString &parentPath, quint32 parentId); 0080 0081 /** 0082 * @brief Returns the ID of the item at the given path, else 0. 0083 * 0084 * Automatically discards old items. 0085 * 0086 * @param path The Path to query the cache for 0087 * @return The ID of the Item if it exists, else 0 0088 */ 0089 std::optional<quint32> queryPath(const QString &path, int timeToLive = 60); 0090 0091 /** 0092 * @brief Adds a Path to the Cache with the given id and ttl. 0093 * 0094 * @param path The path of the file/folder 0095 * @param id The file ID on the storage 0096 * @param timeToLive The time in seconds the entry should be valid 0097 */ 0098 void addPath(const QString &path, quint32 id, int timeToLive = 60); 0099 0100 /** 0101 * @brief Remove the given path from the cache, i.e. if it got deleted 0102 * 0103 * @param path The path that should be removed 0104 */ 0105 void removePath(const QString &path); 0106 0107 const QString m_dbusObjectPath; 0108 0109 // LIBMTP_devicestorage_t properties 0110 quint32 m_id = 0; /**< Unique ID for this storage */ 0111 quint64 m_maxCapacity = 0; /**< Maximum capability */ 0112 quint64 m_freeSpaceInBytes = 0; /**< Free space in bytes */ 0113 QString m_description; /**< A brief description of this storage */ 0114 0115 QHash<QString, QPair<QDateTime, uint32_t>> m_cache; 0116 0117 public Q_SLOTS: 0118 // D-Bus methods 0119 0120 // file management 0121 KMTPFileList getFilesAndFolders(const QString &path, int &result); 0122 QDBusObjectPath getFilesAndFolders2(const QString &path); 0123 KMTPFile getFileMetadata(const QString &path); 0124 0125 int getFileToHandler(const QString &path); 0126 int getFileToFileDescriptor(const QDBusUnixFileDescriptor &descriptor, const QString &sourcePath); 0127 0128 int sendFileFromFileDescriptor(const QDBusUnixFileDescriptor &descriptor, const QString &destinationPath); 0129 int setFileName(const QString &path, const QString &newName); 0130 0131 // folder management 0132 quint32 createFolder(const QString &path); 0133 0134 // object management 0135 int deleteObject(const QString &path); 0136 0137 Q_SIGNALS: 0138 // D-Bus signals 0139 void dataReady(const QByteArray &data); 0140 void copyProgress(qulonglong transferredBytes, qulonglong totalBytes); 0141 void copyFinished(int result); 0142 }; 0143 0144 #endif // MTPSTORAGE_H