Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
androidcontentfileengine.h
Go to the documentation of this file.
1// Copyright (C) 2019 Volker Krause <vkrause@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef ANDROIDCONTENTFILEENGINE_H
5#define ANDROIDCONTENTFILEENGINE_H
6
7#include <private/qfsfileengine_p.h>
8
9#include <QtCore/qjniobject.h>
10#include <QtCore/qlist.h>
11
13
14using DocumentFilePtr = std::shared_ptr<class DocumentFile>;
15
17{
18public:
20 bool open(QIODevice::OpenMode openMode, std::optional<QFile::Permissions> permissions) override;
21 bool close() override;
22 qint64 size() const override;
23 bool remove() override;
24 bool rename(const QString &newName) override;
25 bool mkdir(const QString &dirName, bool createParentDirectories,
26 std::optional<QFile::Permissions> permissions = std::nullopt) const override;
27 bool rmdir(const QString &dirName, bool recurseParentDirectories) const override;
28 QByteArray id() const override;
29 bool caseSensitive() const override { return true; }
30 QDateTime fileTime(FileTime time) const override;
31 FileFlags fileFlags(FileFlags type = FileInfoAll) const override;
32 QString fileName(FileName file = DefaultName) const override;
33 QAbstractFileEngine::Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override;
35
36private:
37 void closeNativeFileDescriptor();
38
39 QString m_initialFile;
40 QJniObject m_pfd;
41 DocumentFilePtr m_documentFile;
42};
43
45{
46public:
49 QAbstractFileEngine *create(const QString &fileName) const override;
50};
51
53{
54public:
55 AndroidContentFileEngineIterator(QDir::Filters filters, const QStringList &filterNames);
57 QString next() override;
58 bool hasNext() const override;
59 QString currentFileName() const override;
60 QString currentFilePath() const override;
61private:
62 mutable QList<DocumentFilePtr> m_files;
63 mutable qsizetype m_index = -1;
64};
65
73class DocumentFile : public std::enable_shared_from_this<DocumentFile>
74{
75public:
76 static DocumentFilePtr parseFromAnyUri(const QString &filename);
78 static DocumentFilePtr fromTreeUri(const QJniObject &treeUri);
79
82 const QJniObject &uri() const;
83 const DocumentFilePtr &parent() const;
84 QString name() const;
85 QString id() const;
86 QString mimeType() const;
87 bool isDirectory() const;
88 bool isFile() const;
89 bool isVirtual() const;
90 QDateTime lastModified() const;
91 int64_t length() const;
92 bool canRead() const;
93 bool canWrite() const;
94 bool remove();
95 bool exists() const;
96 std::vector<DocumentFilePtr> listFiles();
97 bool rename(const QString &newName);
98
99protected:
100 DocumentFile(const QJniObject &uri, const std::shared_ptr<DocumentFile> &parent);
101
102protected:
105};
106
108
109#endif // ANDROIDCONTENTFILEENGINE_H
std::shared_ptr< class DocumentFile > DocumentFilePtr
QString next() override
This pure virtual function advances the iterator to the next directory entry, and returns the file pa...
QString currentFilePath() const override
Returns the path to the current directory entry.
bool hasNext() const override
This pure virtual function returns true if there is at least one more entry in the current directory ...
QString currentFileName() const override
This pure virtual function returns the name of the current directory entry, excluding the path.
QDateTime fileTime(FileTime time) const override
If time is BirthTime, return when the file was born (created).
QByteArray id() const override
qint64 size() const override
Returns the size of the file.
bool mkdir(const QString &dirName, bool createParentDirectories, std::optional< QFile::Permissions > permissions=std::nullopt) const override
Requests that the directory dirName be created with the specified permissions.
bool caseSensitive() const override
Should return true if the underlying file system is case-sensitive; otherwise return false.
FileFlags fileFlags(FileFlags type=FileInfoAll) const override
This function should return the set of OR'd flags that are true for the file engine's file,...
QAbstractFileEngine::Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames) override
Returns an instance of a QAbstractFileEngineIterator using filters for entry filtering and filterName...
bool rmdir(const QString &dirName, bool recurseParentDirectories) const override
Requests that the directory dirName is deleted from the file system.
bool close() override
Closes the file, returning true if successful; otherwise returns false.
QAbstractFileEngine::Iterator * endEntryList() override
bool rename(const QString &newName) override
Requests that the file be renamed to newName in the file system.
bool open(QIODevice::OpenMode openMode, std::optional< QFile::Permissions > permissions) override
Opens the file in the specified mode.
bool remove() override
Requests that the file is deleted from the file system.
DocumentFile Api.
DocumentFilePtr m_parent
const DocumentFilePtr & parent() const
bool rename(const QString &newName)
const QJniObject & uri() const
DocumentFilePtr createFile(const QString &mimeType, const QString &displayName)
DocumentFilePtr createDirectory(const QString &displayName)
std::vector< DocumentFilePtr > listFiles()
static DocumentFilePtr fromTreeUri(const QJniObject &treeUri)
static DocumentFilePtr fromSingleUri(const QJniObject &uri)
static DocumentFilePtr parseFromAnyUri(const QString &filename)
QDateTime lastModified() const
\inmodule QtCore \reentrant
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
QDir::Filters filters() const
Returns the entry filters for this iterator.
\inmodule QtCore \reentrant
FileTime
These are used by the fileTime() function.
FileName
These values are used to request a file name in a particular format.
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:257
\inmodule QtCore
\inmodule QtCore
Definition qlist.h:74
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
static QString displayName(CGDirectDisplayID displayID)
GLenum type
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
QFile file
[0]
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
view create()