From 00e14ded78757a3fb68e74c391f773666a50bf2d Mon Sep 17 00:00:00 2001 From: crashmatt Date: Fri, 13 Mar 2015 03:44:32 +0100 Subject: [PATCH] mavlink-ftp : Initial upload file added to file view --- src/ui/QGCUASFileView.cc | 29 ++++++++++++++++++++++++++++- src/ui/QGCUASFileView.h | 2 ++ src/ui/QGCUASFileView.ui | 21 +++++++++++++++++---- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/ui/QGCUASFileView.cc b/src/ui/QGCUASFileView.cc index bfd8137b8..9ef758bcf 100644 --- a/src/ui/QGCUASFileView.cc +++ b/src/ui/QGCUASFileView.cc @@ -33,7 +33,8 @@ QGCUASFileView::QGCUASFileView(QWidget *parent, QGCUASFileManager *manager) : QWidget(parent), _manager(manager), _listInProgress(false), - _downloadInProgress(false) + _downloadInProgress(false), + _uploadInProgress(false) { _ui.setupUi(this); @@ -48,6 +49,8 @@ QGCUASFileView::QGCUASFileView(QWidget *parent, QGCUASFileManager *manager) : Q_ASSERT(success); success = connect(_ui.downloadButton, SIGNAL(clicked()), this, SLOT(_downloadFile())); Q_ASSERT(success); + success = connect(_ui.uploadButton, SIGNAL(clicked()), this, SLOT(_uploadFile())); + Q_ASSERT(success); success = connect(_ui.treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(_currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); Q_ASSERT(success); } @@ -90,6 +93,29 @@ void QGCUASFileView::_downloadFile(void) } } +/// @brief uploads a file into the currently selected directory the tree view +void QGCUASFileView::_uploadFile(void) +{ + Q_ASSERT(!_uploadInProgress); + + _ui.statusText->clear(); + + // And now download to this location + QString path; + QTreeWidgetItem* item = _ui.treeWidget->currentItem(); + if (item && item->type() != _typeDir) { + return; + } + + QString targetDir = item->text(0); + + QString uploadFromHere = QGCFileDialog::getOpenFileName(this, tr("Upload File"), + QDir::homePath()); + + _manager->uploadPath(targetDir, uploadFromHere); +} + + /// @brief Called when length of file being downloaded is known. void QGCUASFileView::_downloadLength(unsigned int length) { @@ -267,6 +293,7 @@ void QGCUASFileView::_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetIt Q_UNUSED(previous); // FIXME: Should not enable when downloading _ui.downloadButton->setEnabled(current ? (current->type() == _typeFile) : false); + _ui.uploadButton->setEnabled(current ? (current->type() == _typeDir) : false); } void QGCUASFileView::_requestDirectoryList(const QString& dir) diff --git a/src/ui/QGCUASFileView.h b/src/ui/QGCUASFileView.h index 7172e064d..7c2549d51 100644 --- a/src/ui/QGCUASFileView.h +++ b/src/ui/QGCUASFileView.h @@ -47,6 +47,7 @@ private slots: void _listComplete(void); void _downloadFile(void); + void _uploadFile(void); void _downloadLength(unsigned int length); void _downloadProgress(unsigned int length); void _downloadErrorMessage(const QString& msg); @@ -74,6 +75,7 @@ private: bool _listInProgress; ///< Indicates that a listDirectory command is in progress bool _downloadInProgress; ///< Indicates that a downloadPath command is in progress + bool _uploadInProgress; ///< Indicates that a upload command is in progress }; #endif // QGCUASFILEVIEW_H diff --git a/src/ui/QGCUASFileView.ui b/src/ui/QGCUASFileView.ui index 1ac6fd119..79ff8f89a 100644 --- a/src/ui/QGCUASFileView.ui +++ b/src/ui/QGCUASFileView.ui @@ -6,7 +6,7 @@ 0 0 - 200 + 216 518 @@ -14,7 +14,7 @@ Form - + List Files @@ -33,6 +33,9 @@ + + Qt::NoContextMenu + true @@ -43,7 +46,7 @@ - + false @@ -53,7 +56,7 @@ - + @@ -66,6 +69,16 @@ + + + + false + + + Upload File + + + -- 2.22.0