From ae6d413cd4a50464d24dceecfa66f0f5b4955fd4 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 5 Apr 2020 10:08:55 -0700 Subject: [PATCH] Mobile QGCFileDialog: Show dir location --- src/QmlControls/QGCFileDialog.qml | 17 ++++++++++++++--- src/QmlControls/QGCFileDialogController.cc | 19 +++++++++++++++++++ src/QmlControls/QGCFileDialogController.h | 5 +++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/QmlControls/QGCFileDialog.qml b/src/QmlControls/QGCFileDialog.qml index 06fe48e..21932d7 100644 --- a/src/QmlControls/QGCFileDialog.qml +++ b/src/QmlControls/QGCFileDialog.qml @@ -26,11 +26,20 @@ Item { property real _margins: ScreenTools.defaultFontPixelHeight / 2 property bool _mobileDlg: QGroundControl.corePlugin.options.useMobileFileDialog property var _rgExtensions + property string _mobileShortPath - Component.onCompleted: setupFileExtensions() + Component.onCompleted: { + setupFileExtensions() + _updateMobileShortPath() + } + + onFileExtensionChanged: setupFileExtensions() + onFileExtension2Changed: setupFileExtensions() + onFolderChanged: _updateMobileShortPath() - onFileExtensionChanged: setupFileExtensions() - onFileExtension2Changed: setupFileExtensions() + function _updateMobileShortPath() { + _mobileShortPath = controller.fullFolderPathToShortMobilePath(folder); + } function setupFileExtensions() { if (fileExtension2 == "") { @@ -105,6 +114,8 @@ Item { anchors.right: parent.right spacing: ScreenTools.defaultFontPixelHeight / 2 + QGCLabel { text: qsTr("Path: %1").arg(_mobileShortPath) } + Repeater { id: fileRepeater model: controller.getFiles(folder, _rgExtensions) diff --git a/src/QmlControls/QGCFileDialogController.cc b/src/QmlControls/QGCFileDialogController.cc index 0b02720..a353e31 100644 --- a/src/QmlControls/QGCFileDialogController.cc +++ b/src/QmlControls/QGCFileDialogController.cc @@ -9,6 +9,9 @@ #include "QGCFileDialogController.h" +#include "QGCApplication.h" +#include "SettingsManager.h" +#include "AppSettings.h" #include #include @@ -72,3 +75,19 @@ void QGCFileDialogController::deleteFile(const QString& filename) { QFile::remove(filename); } + +QString QGCFileDialogController::fullFolderPathToShortMobilePath(const QString& fullFolderPath) +{ +#ifdef __mobile__ + QString defaultSavePath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValueString(); + if (fullFolderPath.startsWith(defaultSavePath)) { + int lastDirSepIndex = fullFolderPath.lastIndexOf(QStringLiteral("/")); + return qgcApp()->applicationName() + QStringLiteral("/") + fullFolderPath.right(fullFolderPath.length() - lastDirSepIndex); + } else { + return fullFolderPath; + } +#else + qWarning() << "QGCFileDialogController::fullFolderPathToShortMobilePath should only be used in mobile builds"; + return fullFolderPath; +#endif +} diff --git a/src/QmlControls/QGCFileDialogController.h b/src/QmlControls/QGCFileDialogController.h index 4e80503..01f6517 100644 --- a/src/QmlControls/QGCFileDialogController.h +++ b/src/QmlControls/QGCFileDialogController.h @@ -39,6 +39,11 @@ public: Q_INVOKABLE void deleteFile(const QString& filename); Q_INVOKABLE QString urlToLocalFile(QUrl url) { return url.toLocalFile(); } + + /// Important: Should only be used in mobile builds where default save location cannot be changed. + /// Returns the standard QGC location portion of a fully qualified folder path. + /// Example: "/Users/Don/Document/QGroundControl/Missions" returns "QGroundControl/Missions" + Q_INVOKABLE QString fullFolderPathToShortMobilePath(const QString& fullFolderPath); }; #endif