forked from Skycoder42/AndroidContentDevice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentdevice.h
55 lines (42 loc) · 1.33 KB
/
contentdevice.h
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
#ifndef CONTENTDEVICE_H
#define CONTENTDEVICE_H
#include <qglobal.h>
#ifdef Q_OS_ANDROID
#include <QIODevice>
#include <QUrl>
#include <QtAndroidExtras/QAndroidJniObject>
#include <QtAndroidExtras/QAndroidJniEnvironment>
class ContentDevice : public QIODevice
{
Q_OBJECT
Q_PROPERTY(QUrl fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
Q_PROPERTY(qint64 size READ size)
Q_ENUMS(OpenMode)
public :
explicit ContentDevice(QObject *parent = nullptr);
explicit ContentDevice(const QUrl &url, QObject *parent = nullptr);
explicit ContentDevice(const QAndroidJniObject &context, const QUrl &url, QObject *parent = nullptr);
public Q_SLOTS:
void setContext(const QAndroidJniObject &context);
bool isSequential() const override;
bool open(OpenMode mode = QIODevice::ReadOnly) override;
void close() override;
qint64 bytesAvailable() const override;
void flush();
QUrl fileName() const;
qint64 size() const;
public Q_SLOTS:
void setFileName(QUrl url);
Q_SIGNALS:
void fileNameChanged(QUrl url);
protected:
qint64 readData(char *data, qint64 maxlen) override;
qint64 writeData(const char *data, qint64 len) override;
private:
QAndroidJniObject _context;
QUrl _url;
QAndroidJniObject _stream;
bool checkJniError(QAndroidJniEnvironment &env);
};
#endif //Q_OS_ANDROID
#endif // CONTENTDEVICE_H