Enroute Flight Navigation
A navigation app for VFR pilots
FileExchange_Android.h
1/***************************************************************************
2 * Copyright (C) 2019-2025 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include "platform/FileExchange_Abstract.h"
24
25namespace Platform {
26
28
29
31{
32 Q_OBJECT
33 QML_ELEMENT
34 QML_SINGLETON
35
36public:
41 explicit FileExchange(QObject *parent = nullptr);
42
43 // No default constructor, important for QML singleton
44 explicit FileExchange() = delete;
45
46 // factory function for QML singleton
47 static Platform::FileExchange* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
48 {
50 }
51
52 ~FileExchange() override = default;
53
54
55 //
56 // Methods
57 //
58
60 void importContent() override;
61
72 QString shareContent(const QByteArray& content, const QString& mimeType, const QString& fileNameTemplate) override;
73
84 QString viewContent(const QByteArray& content, const QString& mimeType, const QString& fileNameTemplate) override;
85
97 Q_INVOKABLE static void openFilePicker(const QString& mimeType);
98
99public slots:
101 void onGUISetupCompleted() override;
102
104 void processFileOpenRequest(const QString& path) override;
105
106
107protected:
109 void deferredInitialization() override;
110
111
112private:
113 Q_DISABLE_COPY_MOVE(FileExchange)
114
115 // Helper function. Saves content to a file in a directory from where
116 // sharing to other android apps is possible
117 auto contentToTempFile(const QByteArray& content, const QString& fileNameTemplate) -> QString;
118
119 // Name of a subdirectory within the AppDataLocation for sending and
120 // receiving files.
121 QString fileExchangeDirectoryName;
122
123 // @returns True if an app could be started, false if no app was found
124 static bool outgoingIntent(const QString& methodName, const QString& filePath, const QString& mimeType);
125
126 bool receiveOpenFileRequestsStarted {false};
127 QString pendingReceiveOpenFileRequest;
128};
129
130} // namespace Platform
static Q_INVOKABLE Platform::FileExchange * fileExchange()
Pointer to appplication-wide static FileExchange instance.
Interface to platform-specific file exchange functionality.
Implementation of FileExchange for Android devices.
QString viewContent(const QByteArray &content, const QString &mimeType, const QString &fileNameTemplate) override
Implements pure virtual method from FileExchange_Abstract.
void importContent() override
Implements pure virtual method from FileExchange_Abstract.
QString shareContent(const QByteArray &content, const QString &mimeType, const QString &fileNameTemplate) override
Implements pure virtual method from FileExchange_Abstract.
void onGUISetupCompleted() override
Implements pure virtual method from FileExchange_Abstract.
void deferredInitialization() override
Implements virtual method from FileExchange_Abstract.
FileExchange(QObject *parent=nullptr)
Standard constructor.
static Q_INVOKABLE void openFilePicker(const QString &mimeType)
Opens the native Android file picker.
void processFileOpenRequest(const QString &path) override
Implements pure virtual method from FileExchange_Abstract.