Commit 35c61df6 authored by Don Gagne's avatar Don Gagne

MobileFileDialog bug fixes

parent 944d7224
......@@ -67,7 +67,8 @@
<file alias="QGroundControl/Controls/QGCFlickableVerticalIndicator.qml">src/QmlControls/QGCFlickableVerticalIndicator.qml</file>
<file alias="QGroundControl/Controls/QGCLabel.qml">src/QmlControls/QGCLabel.qml</file>
<file alias="QGroundControl/Controls/QGCListView.qml">src/QmlControls/QGCListView.qml</file>
<file alias="QGroundControl/Controls/QGCMobileFileDialog.qml">src/QmlControls/QGCMobileFileDialog.qml</file>
<file alias="QGroundControl/Controls/QGCMobileFileOpenDialog.qml">src/QmlControls/QGCMobileFileOpenDialog.qml</file>
<file alias="QGroundControl/Controls/QGCMobileFileSaveDialog.qml">src/QmlControls/QGCMobileFileSaveDialog.qml</file>
<file alias="QGroundControl/Controls/QGCMovableItem.qml">src/QmlControls/QGCMovableItem.qml</file>
<file alias="QGroundControl/Controls/QGCPipable.qml">src/QmlControls/QGCPipable.qml</file>
<file alias="QGroundControl/Controls/QGCRadioButton.qml">src/QmlControls/QGCRadioButton.qml</file>
......
......@@ -207,7 +207,7 @@ QGCView {
function loadFromSelectedFile() {
if (ScreenTools.isMobile) {
qgcView.showDialog(mobileFilePicker, qsTr("Select Mission File"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
qgcView.showDialog(mobileFilePicker, qsTr("Select Mission File"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
} else {
missionController.loadFromFilePicker()
fitMapViewportToMissionItems()
......@@ -366,9 +366,8 @@ QGCView {
Component {
id: mobileFilePicker
QGCMobileFileDialog {
openDialog: true
fileExtension: _syncDropDownController.fileExtension
QGCMobileFileOpenDialog {
fileExtension: _syncDropDownController.fileExtension
onFilenameReturned: {
_syncDropDownController.loadFromFile(filename)
_syncDropDownController.fitViewportToItems()
......@@ -379,8 +378,7 @@ QGCView {
Component {
id: mobileFileSaver
QGCMobileFileDialog {
openDialog: false
QGCMobileFileSaveDialog {
fileExtension: _syncDropDownController.fileExtension
onFilenameReturned: _syncDropDownController.saveToFile(filename)
}
......
......@@ -33,6 +33,7 @@ QStringList QGCMobileFileDialogController::getFiles(const QString& fileExtension
QString QGCMobileFileDialogController::fullPath(const QString& filename, const QString& fileExtension)
{
qDebug() << "QGCMobileFileDialogController::fullPath" << filename << fileExtension;
QString saveLocation(_getSaveLocation());
if (saveLocation.isEmpty()) {
return filename;
......@@ -52,6 +53,7 @@ QString QGCMobileFileDialogController::fullPath(const QString& filename, const Q
bool QGCMobileFileDialogController::fileExists(const QString& filename, const QString& fileExtension)
{
QFile file(fullPath(filename, fileExtension));
qDebug() << "QGCMobileFileDialogController::fileExists" << file.fileName();
return file.exists();
}
......@@ -59,10 +61,15 @@ QString QGCMobileFileDialogController::_getSaveLocation(void)
{
QStringList docDirs = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
if (docDirs.count() <= 0) {
qCWarning(QGCMobileFileDialogControllerLog) << "No Documents location";
qCWarning(QGCMobileFileDialogControllerLog) << "No save location";
return QString();
}
qCDebug(QGCMobileFileDialogControllerLog) << "Save directory" << docDirs.at(0);
QString saveDirectory = docDirs[0];
if (!QDir(saveDirectory).exists()) {
QDir().mkdir(saveDirectory);
}
qCDebug(QGCMobileFileDialogControllerLog) << "Save directory" << saveDirectory;
return docDirs.at(0);
return saveDirectory;
}
......@@ -96,7 +96,7 @@ QGCView {
text: qsTr("Load from file...")
onTriggered: {
if (ScreenTools.isMobile) {
qgcView.showDialog(mobileFilePicker, qsTr("Select Parameter File"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
qgcView.showDialog(mobileFilePicker, qsTr("Select Parameter File"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
} else {
controller.loadFromFilePicker()
}
......@@ -263,7 +263,7 @@ QGCView {
Component {
id: mobileFilePicker
QGCMobileFileDialog {
QGCMobileFileOpenDialog {
fileExtension: QGroundControl.parameterFileExtension
onFilenameReturned: controller.loadFromFile(filename)
}
......@@ -272,8 +272,7 @@ QGCView {
Component {
id: mobileFileSaver
QGCMobileFileDialog {
openDialog: false
QGCMobileFileSaveDialog {
fileExtension: QGroundControl.parameterFileExtension
onFilenameReturned: controller.saveToFile(filename)
}
......
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.5
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2
import QGroundControl 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.Palette 1.0
/// Simple file picker for mobile
QGCViewDialog {
property bool openDialog: true ///< true: Show file open dialog, false: show file save dialog
property string fileExtension ///< File extension for file listing
signal filenameReturned(string filename)
readonly property real _margins: ScreenTools.defaultFontPixelHeight / 2
function accept() {
if (!openDialog) {
console.log("filename", dialogLoader.item.filename)
if (!dialogLoader.item.replaceMessageShown) {
if (controller.fileExists(dialogLoader.item.filename, fileExtension)) {
dialogLoader.item.replaceMessageShown = true
return
}
}
filenameReturned(controller.fullPath(dialogLoader.item.filename, fileExtension))
}
hideDialog()
}
QGCMobileFileDialogController { id: controller }
QGCPalette { id: qgcPal; colorGroupEnabled: true }
Loader {
id: dialogLoader
anchors.fill: parent
sourceComponent: openDialog ? openDialogComponent : saveDialogComponent
}
Component {
id: saveDialogComponent
Column {
anchors.left: parent.left
anchors.right: parent.right
spacing: ScreenTools.defaultFontPixelHeight
property alias filename: filenameTextField.text
property alias replaceMessageShown: replaceMessage.visible
QGCLabel {
text: qsTr("File name:")
}
QGCTextField {
id: filenameTextField
onTextChanged: replaceMessage.visible = false
}
QGCLabel {
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: qsTr("File names must end with .%1 file extension. If missing it will be added.").arg(fileExtension)
}
QGCLabel {
id: replaceMessage
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: qsTr("The file %1 exists. Click Save again to replace it.").arg(filename)
visible: false
color: qgcPal.warningText
}
}
}
Component {
id: openDialogComponent
Item {
anchors.margins: _margins
anchors.fill: parent
QGCListView {
anchors.fill: parent
spacing: _margins / 2
orientation: ListView.Vertical
model: controller.getFiles(fileExtension)
delegate: QGCButton {
text: modelData
onClicked: {
hideDialog()
filenameReturned(controller.fullPath(modelData, fileExtension))
}
}
}
QGCLabel {
text: qsTr("No files")
visible: controller.getFiles(fileExtension).length == 0
}
}
}
}
......@@ -28,7 +28,8 @@ QGCComboBox 1.0 QGCComboBox.qml
QGCFlickable 1.0 QGCFlickable.qml
QGCLabel 1.0 QGCLabel.qml
QGCListView 1.0 QGCListView.qml
QGCMobileFileDialog 1.0 QGCMobileFileDialog.qml
QGCMobileFileOpenDialog 1.0 QGCMobileFileOpenDialog.qml
QGCMobileFileSaveDialog 1.0 QGCMobileFileSaveDialog.qml
QGCMovableItem 1.0 QGCMovableItem.qml
QGCPipable 1.0 QGCPipable.qml
QGCRadioButton 1.0 QGCRadioButton.qml
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment