47 changed files with 951 additions and 989 deletions
@ -1,75 +0,0 @@
@@ -1,75 +0,0 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
|
||||
#include "QGCMobileFileDialogController.h" |
||||
|
||||
#include <QStandardPaths> |
||||
#include <QDebug> |
||||
#include <QDir> |
||||
|
||||
QGC_LOGGING_CATEGORY(QGCMobileFileDialogControllerLog, "QGCMobileFileDialogControllerLog") |
||||
|
||||
QStringList QGCMobileFileDialogController::getFiles(const QString& fileExtension) |
||||
{ |
||||
QStringList files; |
||||
|
||||
QDir fileDir(_getSaveLocation()); |
||||
|
||||
QFileInfoList fileInfoList = fileDir.entryInfoList(QStringList(QString("*.%1").arg(fileExtension)), QDir::Files, QDir::Name); |
||||
|
||||
foreach (const QFileInfo& fileInfo, fileInfoList) { |
||||
files << fileInfo.baseName() + QStringLiteral(".") + fileExtension; |
||||
} |
||||
|
||||
return files; |
||||
} |
||||
|
||||
QString QGCMobileFileDialogController::fullPath(const QString& filename, const QString& fileExtension) |
||||
{ |
||||
qDebug() << "QGCMobileFileDialogController::fullPath" << filename << fileExtension; |
||||
QString saveLocation(_getSaveLocation()); |
||||
if (saveLocation.isEmpty()) { |
||||
return filename; |
||||
} |
||||
|
||||
QString fixedFilename(filename); |
||||
QString correctExtension = QString(".%1").arg(fileExtension); |
||||
if (!filename.endsWith(correctExtension)) { |
||||
fixedFilename += correctExtension; |
||||
} |
||||
|
||||
QString fullPath = saveLocation + QDir::separator() + fixedFilename; |
||||
qCDebug(QGCMobileFileDialogControllerLog) << "Full path" << fullPath; |
||||
return fullPath; |
||||
} |
||||
|
||||
bool QGCMobileFileDialogController::fileExists(const QString& filename, const QString& fileExtension) |
||||
{ |
||||
QFile file(fullPath(filename, fileExtension)); |
||||
qDebug() << "QGCMobileFileDialogController::fileExists" << file.fileName(); |
||||
return file.exists(); |
||||
} |
||||
|
||||
QString QGCMobileFileDialogController::_getSaveLocation(void) |
||||
{ |
||||
QStringList docDirs = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); |
||||
if (docDirs.count() <= 0) { |
||||
qCWarning(QGCMobileFileDialogControllerLog) << "No save location"; |
||||
return QString(); |
||||
} |
||||
|
||||
QString saveDirectory = docDirs[0]; |
||||
if (!QDir(saveDirectory).exists()) { |
||||
QDir().mkdir(saveDirectory); |
||||
} |
||||
qCDebug(QGCMobileFileDialogControllerLog) << "Save directory" << saveDirectory; |
||||
|
||||
return saveDirectory; |
||||
} |
@ -1,43 +0,0 @@
@@ -1,43 +0,0 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
|
||||
#ifndef QGCMobileFileDialogController_H |
||||
#define QGCMobileFileDialogController_H |
||||
|
||||
#include <QObject> |
||||
|
||||
#include "QGCLoggingCategory.h" |
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(QGCMobileFileDialogControllerLog) |
||||
|
||||
class QGCMobileFileDialogController : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
/// Return all file in Documents location which match the specified extension
|
||||
Q_INVOKABLE QStringList getFiles(const QString& fileExtension); |
||||
|
||||
/// Return the full path for specified file in the Documents location
|
||||
/// @param filename File name, not fully qualified, may not have extension
|
||||
/// @param fileExtension Expected file extension, added if needed
|
||||
Q_INVOKABLE QString fullPath(const QString& filename, const QString& fileExtension); |
||||
|
||||
/// Check for file existence
|
||||
/// @param filename File name, not fully qualified, may not have extension
|
||||
/// @param fileExtension Expected file extension, added if needed
|
||||
/// @return true: File exists at Documents location
|
||||
Q_INVOKABLE bool fileExists(const QString& filename, const QString& fileExtension); |
||||
|
||||
private: |
||||
QString _getSaveLocation(void); |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
|
||||
#include "QFileDialogController.h" |
||||
|
||||
#include <QStandardPaths> |
||||
#include <QDebug> |
||||
#include <QDir> |
||||
|
||||
QGC_LOGGING_CATEGORY(QFileDialogControllerLog, "QFileDialogControllerLog") |
||||
|
||||
QStringList QFileDialogController::getFiles(const QString& directoryPath, const QString& fileExtension) |
||||
{ |
||||
qCDebug(QFileDialogControllerLog) << "getFiles" << directoryPath << fileExtension; |
||||
QStringList files; |
||||
|
||||
QDir fileDir(directoryPath); |
||||
|
||||
QFileInfoList fileInfoList = fileDir.entryInfoList(QStringList(QString("*.%1").arg(fileExtension)), QDir::Files, QDir::Name); |
||||
|
||||
foreach (const QFileInfo& fileInfo, fileInfoList) { |
||||
qCDebug(QFileDialogControllerLog) << "getFiles found" << fileInfo.baseName(); |
||||
files << fileInfo.baseName() + QStringLiteral(".") + fileExtension; |
||||
} |
||||
|
||||
return files; |
||||
} |
||||
|
||||
QString QFileDialogController::filenameWithExtension(const QString& filename, const QString& fileExtension) |
||||
{ |
||||
QString filenameWithExtension(filename); |
||||
|
||||
QString correctExtension = QString(".%1").arg(fileExtension); |
||||
if (!filenameWithExtension.endsWith(correctExtension)) { |
||||
filenameWithExtension += correctExtension; |
||||
} |
||||
|
||||
return filenameWithExtension; |
||||
} |
||||
|
||||
bool QFileDialogController::fileExists(const QString& filename) |
||||
{ |
||||
return QFile(filename).exists(); |
||||
} |
||||
|
||||
QString QFileDialogController::fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QString& fileExtension) |
||||
{ |
||||
return directoryPath + QStringLiteral("/") + filenameWithExtension(filename, fileExtension); |
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
|
||||
#ifndef QFileDialogController_H |
||||
#define QFileDialogController_H |
||||
|
||||
#include <QObject> |
||||
#include <QUrl> |
||||
|
||||
#include "QGCLoggingCategory.h" |
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(QFileDialogControllerLog) |
||||
|
||||
class QFileDialogController : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
/// Return all file in the specified path which match the specified extension
|
||||
Q_INVOKABLE QStringList getFiles(const QString& directoryPath, const QString& fileExtension); |
||||
|
||||
/// Returns the specified file name with the extension added it needed
|
||||
Q_INVOKABLE QString filenameWithExtension(const QString& filename, const QString& fileExtension); |
||||
|
||||
/// Returns the fully qualified file name from the specified parts
|
||||
Q_INVOKABLE QString fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QString& fileExtension); |
||||
|
||||
/// Check for file existence of specified fully qualified file name
|
||||
Q_INVOKABLE bool fileExists(const QString& filename); |
||||
|
||||
Q_INVOKABLE QString urlToLocalFile(QUrl url) { return url.toLocalFile(); } |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,159 @@
@@ -0,0 +1,159 @@
|
||||
import QtQuick 2.3 |
||||
import QtQuick.Controls 1.2 |
||||
import QtQuick.Dialogs 1.2 |
||||
|
||||
import QGroundControl 1.0 |
||||
import QGroundControl.ScreenTools 1.0 |
||||
import QGroundControl.Palette 1.0 |
||||
import QGroundControl.Controllers 1.0 |
||||
|
||||
/// This control is meant to be a direct replacement for the standard Qml FileDialog control. |
||||
/// It differs for mobile builds which uses a completely custom file picker. |
||||
Item { |
||||
id: _root |
||||
visible: false |
||||
|
||||
property var qgcView |
||||
property string folder |
||||
property var nameFilters |
||||
property string fileExtension |
||||
property string title |
||||
property bool selectExisting |
||||
property bool selectFolder |
||||
|
||||
property bool _openForLoad |
||||
property real _margins: ScreenTools.defaultFontPixelHeight / 2 |
||||
|
||||
function openForLoad() { |
||||
_openForLoad = true |
||||
if (ScreenTools.isMobile && folder.length !== 0) { |
||||
qgcView.showDialog(mobileFileOpenDialog, title, qgcView.showDialogDefaultWidth, StandardButton.Cancel) |
||||
} else { |
||||
fullFileDialog.open() |
||||
} |
||||
} |
||||
|
||||
function openForSave() { |
||||
_openForLoad = false |
||||
if (ScreenTools.isMobile && folder.length !== 0) { |
||||
qgcView.showDialog(mobileFileSaveDialog, title, qgcView.showDialogDefaultWidth, StandardButton.Cancel | StandardButton.Ok) |
||||
} else { |
||||
fullFileDialog.open() |
||||
} |
||||
} |
||||
|
||||
function close() { |
||||
fullFileDialog.close() |
||||
} |
||||
|
||||
signal acceptedForLoad(string file) |
||||
signal acceptedForSave(string file) |
||||
signal rejected |
||||
|
||||
QFileDialogController { id: controller } |
||||
QGCPalette { id: qgcPal; colorGroupEnabled: true } |
||||
|
||||
FileDialog { |
||||
id: fullFileDialog |
||||
folder: "file://" + _root.folder |
||||
nameFilters: _root.nameFilters |
||||
title: _root.title |
||||
selectExisting: _root.selectExisting |
||||
selectMultiple: false |
||||
selectFolder: _root.selectFolder |
||||
|
||||
onAccepted: { |
||||
if (_openForLoad) { |
||||
_root.acceptedForLoad(controller.urlToLocalFile(fileUrl)) |
||||
} else { |
||||
_root.acceptedForSave(controller.urlToLocalFile(fileUrl)) |
||||
} |
||||
} |
||||
onRejected: _root.rejected() |
||||
} |
||||
|
||||
Component { |
||||
id: mobileFileOpenDialog |
||||
|
||||
QGCViewDialog { |
||||
Item { |
||||
anchors.margins: _margins |
||||
anchors.fill: parent |
||||
|
||||
QGCListView { |
||||
id: listView |
||||
anchors.fill: parent |
||||
spacing: _margins / 2 |
||||
orientation: ListView.Vertical |
||||
model: controller.getFiles(folder, fileExtension) |
||||
|
||||
delegate: QGCButton { |
||||
text: modelData |
||||
|
||||
onClicked: { |
||||
hideDialog() |
||||
_root.acceptedForLoad(controller.fullyQualifiedFilename(folder, modelData, fileExtension)) |
||||
} |
||||
} |
||||
} |
||||
|
||||
QGCLabel { |
||||
text: qsTr("No files") |
||||
visible: listView.model.length == 0 |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
Component { |
||||
id: mobileFileSaveDialog |
||||
|
||||
QGCViewDialog { |
||||
function accept() { |
||||
if (filenameTextField.text == "") { |
||||
return |
||||
} |
||||
if (!replaceMessage.visible) { |
||||
if (controller.fileExists(controller.fullyQualifiedFilename(folder, filenameTextField.text, fileExtension))) { |
||||
replaceMessage.visible = true |
||||
return |
||||
} |
||||
} |
||||
_root.acceptedForSave(controller.fullyQualifiedFilename(folder, filenameTextField.text, fileExtension)) |
||||
hideDialog() |
||||
} |
||||
|
||||
Column { |
||||
anchors.left: parent.left |
||||
anchors.right: parent.right |
||||
spacing: ScreenTools.defaultFontPixelHeight |
||||
|
||||
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(filenameTextField.text) |
||||
visible: false |
||||
color: qgcPal.warningText |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,56 +0,0 @@
@@ -1,56 +0,0 @@
|
||||
/**************************************************************************** |
||||
* |
||||
* (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.3 |
||||
import QtQuick.Controls 1.2 |
||||
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 open dialog for mobile |
||||
QGCViewDialog { |
||||
property string fileExtension ///< File extension for file listing |
||||
|
||||
signal filenameReturned(string filename) |
||||
|
||||
readonly property real _margins: ScreenTools.defaultFontPixelHeight / 2 |
||||
|
||||
QGCMobileFileDialogController { id: controller } |
||||
QGCPalette { id: qgcPal; colorGroupEnabled: true } |
||||
|
||||
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 |
||||
} |
||||
} |
||||
} |
@ -1,79 +0,0 @@
@@ -1,79 +0,0 @@
|
||||
/**************************************************************************** |
||||
* |
||||
* (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.3 |
||||
import QtQuick.Controls 1.2 |
||||
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 string fileExtension ///< File extension for file listing |
||||
|
||||
signal filenameReturned(string filename) |
||||
|
||||
readonly property real _margins: ScreenTools.defaultFontPixelHeight / 2 |
||||
|
||||
function accept() { |
||||
if (filenameTextField.text == "") { |
||||
return |
||||
} |
||||
if (!replaceMessage.visible) { |
||||
if (controller.fileExists(filenameTextField.text, fileExtension)) { |
||||
console.log("File exists") |
||||
replaceMessage.visible = true |
||||
return |
||||
} |
||||
} |
||||
filenameReturned(controller.fullPath(filenameTextField.text, fileExtension)) |
||||
hideDialog() |
||||
} |
||||
|
||||
QGCMobileFileDialogController { id: controller } |
||||
QGCPalette { id: qgcPal; colorGroupEnabled: true } |
||||
|
||||
Column { |
||||
anchors.left: parent.left |
||||
anchors.right: parent.right |
||||
spacing: ScreenTools.defaultFontPixelHeight |
||||
|
||||
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(filenameTextField.text) |
||||
visible: false |
||||
color: qgcPal.warningText |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue