9#include <QtCore/QPointer>
18 qCDebug(QGCFileDialogControllerLog) <<
this;
23 qCDebug(QGCFileDialogControllerLog) <<
this;
28 qCDebug(QGCFileDialogControllerLog) <<
"getFiles" << directoryPath << nameFilters;
30 QDir fileDir(directoryPath);
31 const QFileInfoList fileInfoList = fileDir.entryInfoList(nameFilters, QDir::Files, QDir::Name);
34 for (
const QFileInfo &fileInfo: fileInfoList) {
35 qCDebug(QGCFileDialogControllerLog) <<
"getFiles found" << fileInfo.fileName();
36 files << fileInfo.fileName();
44 return QFile(filename).exists();
49 QString firstFileExtention;
53 bool extensionFound =
true;
54 if (nameFilters.count()) {
55 extensionFound =
false;
56 for (
const QString& nameFilter: nameFilters) {
57 if (nameFilter.startsWith(
"*.")) {
58 const QString fileExtension = nameFilter.right(nameFilter.length() - 2);
59 if (fileExtension !=
"*") {
60 if (firstFileExtention.isEmpty()) {
61 firstFileExtention = fileExtension;
63 if (filename.endsWith(fileExtension)) {
64 extensionFound =
true;
68 }
else if (nameFilter !=
"*") {
69 qCWarning(QGCFileDialogControllerLog) <<
"unsupported name filter format" << nameFilter;
75 QString filenameWithExtension = filename;
76 if (!extensionFound) {
77 filenameWithExtension = QStringLiteral(
"%1.%2").arg(filename).arg(firstFileExtention);
80 return (directoryPath + QStringLiteral(
"/") + filenameWithExtension);
85 QFile::remove(filename);
90#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
92 if (fullFolderPath.startsWith(defaultSavePath)) {
93 const int lastDirSepIndex = fullFolderPath.lastIndexOf(QStringLiteral(
"/"));
94 return (QCoreApplication::applicationName() + QStringLiteral(
"/") + fullFolderPath.right(fullFolderPath.length() - lastDirSepIndex));
97 qCWarning(QGCFileDialogControllerLog) << Q_FUNC_INFO <<
"should only be used in mobile builds";
99 return fullFolderPath;
107 if (url.isLocalFile()) {
108 result = url.toLocalFile();
110 result = url.toString();
118 if (result.startsWith(QStringLiteral(
"//"))) {
119 result = result.mid(1);
130 if (missionPath.isEmpty()) {
131 qCWarning(QGCFileDialogControllerLog) <<
"Missions save path is empty";
132 emit
importFailed(tr(
"Missions directory is not configured"));
136 QDir dir(missionPath);
138 qCWarning(QGCFileDialogControllerLog) <<
"Missions save path does not exist";
139 emit
importFailed(tr(
"Missions save path does not exist"));
143 QPointer<QGCFileDialogController> self =
this;
146 QMetaObject::invokeMethod(
148 [filePath, self]() { self->_handleImportResult(filePath); },
149 Qt::QueuedConnection);
153 qCWarning(QGCFileDialogControllerLog) << Q_FUNC_INFO <<
"only supported on Android";
159void QGCFileDialogController::_handleImportResult(
const QString& filePath)
161 if (filePath.isEmpty()) {
162 qCWarning(QGCFileDialogControllerLog) <<
"Import failed: empty file path received from Java";
167 qCDebug(QGCFileDialogControllerLog) <<
"File imported successfully to:" << filePath;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QString missionSavePath()
void fileImported(const QString &filePath)
static Q_INVOKABLE bool fileExists(const QString &filename)
Check for file existence of specified fully qualified file name.
static Q_INVOKABLE QString fullFolderPathToShortMobilePath(const QString &fullFolderPath)
static Q_INVOKABLE QString urlToLocalFile(QUrl url)
static Q_INVOKABLE void deleteFile(const QString &filename)
Deletes the file specified by the fully qualified file name.
~QGCFileDialogController()
static Q_INVOKABLE QStringList getFiles(const QString &directoryPath, const QStringList &nameFilters)
Return all file in the specified path which match the specified extension.
Q_INVOKABLE void importFromNativePicker()
static Q_INVOKABLE QString fullyQualifiedFilename(const QString &directoryPath, const QString &filename, const QStringList &nameFilters=QStringList())
void importFailed(const QString &errorMessage)
static SettingsManager * instance()
AppSettings * appSettings() const
void openFileImportDialog(const QString &destPath, std::function< void(const QString &)> callback)