QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
androidfilechooser.h
1 #ifndef QTMVVM_ANDROIDFILECHOOSER_H
2 #define QTMVVM_ANDROIDFILECHOOSER_H
3 
4 #include <QtCore/QObject>
5 #include <QtCore/QUrl>
6 #include <QtCore/QVariant>
7 
8 #include <QtAndroidExtras/QAndroidActivityResultReceiver>
9 #include <QtAndroidExtras/QAndroidJniObject>
10 
11 #ifdef DOXYGEN_RUN
13 
27 class FileChooser : public QtObject
28 #else
29 namespace QtMvvm {
30 
31 class AndroidFileChooser : public QObject, public QAndroidActivityResultReceiver
32 #endif
33 {
34  Q_OBJECT
35 
45  Q_PROPERTY(QString title MEMBER _title NOTIFY titleChanged)
46 
47 
56  Q_PROPERTY(QUrl folderUrl MEMBER _folderUrl NOTIFY folderUrlChanged)
70  Q_PROPERTY(ChooserType type MEMBER _type NOTIFY typeChanged)
80  Q_PROPERTY(QStringList mimeTypes MEMBER _mimeTypes NOTIFY mimeTypesChanged)
92  Q_PROPERTY(ChooserFlags chooserFlags READ chooserFlags WRITE setChooserFlags NOTIFY chooserFlagsChanged)
93 
108  Q_PROPERTY(QVariant result READ result NOTIFY resultChanged)
109 
110 public:
112  enum ChooserType {
118  };
119  Q_ENUM(ChooserType)
120 
121 
122  enum ChooserFlag {
123  OpenableFlag = 0x01,
124  LocalOnlyFlag = 0x02,
127  };
128  Q_DECLARE_FLAGS(ChooserFlags, ChooserFlag)
129  Q_FLAG(ChooserFlags)
130 
131 
132  explicit AndroidFileChooser(QObject *parent = nullptr);
133  ~AndroidFileChooser() override;
134 
136  ChooserFlags chooserFlags() const;
138  QVariant result() const;
139 
140 #ifdef DOXYGEN_RUN
141 public:
142 #else
143 public Q_SLOTS:
144 #endif
145  void open();
147 
149  void setChooserFlags(ChooserFlags chooserFlags);
150 
151 Q_SIGNALS:
153  void accepted();
155  void rejected();
156 
158  void titleChanged(const QString &title);
160  void folderUrlChanged(const QUrl &folderUrl);
166  void chooserFlagsChanged(ChooserFlags chooserFlags);
168  void resultChanged(QVariant result);
169 
170 protected:
172  void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) override;
173 
174 private:
175  const static int RequestCodeNormal = 0x1091c657;
176  const static int RequestCodePersist = 0x1091c658;
177 
178  QString _title;
179  QUrl _folderUrl;
180  ChooserType _type;
181  QStringList _mimeTypes;
182  ChooserFlags _flags;
183 
184  bool _active;
185  QVariant _result;
186 
187  QAndroidJniObject createGetIntent();
188  QAndroidJniObject createOpenIntent();
189  QAndroidJniObject createOpenMultipleIntent();
190  QAndroidJniObject createSaveIntent();
191  QAndroidJniObject createOpenTreeIntent();
192 
193  void setupBasic(QAndroidJniObject &intent, bool asTree = false);
194 };
195 
196 }
197 
198 Q_DECLARE_OPERATORS_FOR_FLAGS(QtMvvm::AndroidFileChooser::ChooserFlags)
199 
200 #endif // QTMVVM_ANDROIDFILECHOOSER_H
The returned URL must be openable (for reading)
QString title
The activity title/description of the file chooser.
ChooserFlag
Extra flags to configure how to open the URLs.
void typeChanged(ChooserType type)
NOTIFY accessor for FileChooser::type.
ChooserType type
The type of URL to get.
void titleChanged(const QString &title)
NOTIFY accessor for FileChooser::title.
void rejected()
Emitted when the user cancels without selecting a url.
void folderUrlChanged(const QUrl &folderUrl)
NOTIFY accessor for FileChooser::folderUrl.
A QML class access the native file chooser on android.
void chooserFlagsChanged(ChooserFlags chooserFlags)
NOTIFY accessor for FileChooser::chooserFlags.
void accepted()
Emitted when the user select a url (or multiple)
void mimeTypesChanged(const QStringList &mimeTypes)
NOTIFY accessor for FileChooser::mimeTypes.
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4
QUrl folderUrl
The URL of the place to show the dialog from.
Persist the permission to access the content across reboots.
Get a non-permanent, read only content url.
Always allow writing, not only for FileChooser::CreateDocument.
void resultChanged(QVariant result)
NOTIFY accessor for FileChooser::result.
void open()
Opens the file chooser by sending the show intent.
QStringList mimeTypes
A list of acceptable mimetypes. Can contain wildcards.
The primary namespace of the QtMvvm library.
ChooserType
The different modes the chooser can return urls for.