QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FTPController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtCore/QString>
5#include <QtCore/QStringList>
6#include <QtCore/QUrl>
7#include <QtQmlIntegration/QtQmlIntegration>
8
10#include "QGCLoggingCategory.h"
11
12Q_DECLARE_LOGGING_CATEGORY(FTPControllerLog)
13
14class FTPManager;
15class Vehicle;
16class QGCArchiveModel;
18
20class FTPController : public QObject
21{
22 Q_OBJECT
23 QML_ELEMENT
24 Q_MOC_INCLUDE("Vehicle.h")
25
26 Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
27 Q_PROPERTY(bool listInProgress READ listInProgress NOTIFY activeOperationChanged)
28 Q_PROPERTY(bool downloadInProgress READ downloadInProgress NOTIFY activeOperationChanged)
29 Q_PROPERTY(bool uploadInProgress READ uploadInProgress NOTIFY activeOperationChanged)
30 Q_PROPERTY(bool deleteInProgress READ deleteInProgress NOTIFY activeOperationChanged)
31 Q_PROPERTY(float progress READ progress NOTIFY progressChanged)
32 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
33 Q_PROPERTY(QString currentPath READ currentPath NOTIFY currentPathChanged)
34 Q_PROPERTY(QStringList directoryEntries READ directoryEntries NOTIFY directoryEntriesChanged)
35 Q_PROPERTY(QString lastDownloadFile READ lastDownloadFile NOTIFY lastDownloadFileChanged)
36 Q_PROPERTY(QString lastUploadTarget READ lastUploadTarget NOTIFY lastUploadTargetChanged)
37 Q_PROPERTY(bool lastDownloadIsArchive READ lastDownloadIsArchive NOTIFY lastDownloadFileChanged)
38 Q_PROPERTY(bool extracting READ extracting NOTIFY extractingChanged)
39 Q_PROPERTY(float extractionProgress READ extractionProgress NOTIFY extractionProgressChanged)
40 Q_PROPERTY(QGCArchiveModel* archiveModel READ archiveModel CONSTANT)
41
42public:
43 explicit FTPController(QObject *parent = nullptr);
44
45 bool busy() const { return _busy; }
46 bool listInProgress() const { return _operation == Operation::List; }
47 bool downloadInProgress() const { return _operation == Operation::Download; }
48 bool uploadInProgress() const { return _operation == Operation::Upload; }
49 bool deleteInProgress() const { return _operation == Operation::Delete; }
50 float progress() const { return _progress; }
51 QString errorString() const { return _errorString; }
52 QString currentPath() const { return _currentPath; }
53 QStringList directoryEntries() const { return _directoryEntries; }
54 QString lastDownloadFile() const { return _lastDownloadFile; }
55 QString lastUploadTarget() const { return _lastUploadTarget; }
56 bool lastDownloadIsArchive() const { return _lastDownloadIsArchive; }
57 bool extracting() const { return _extracting; }
58 float extractionProgress() const { return _extractionProgress; }
59 QGCArchiveModel* archiveModel() const { return _archiveModel; }
60
61 Q_INVOKABLE bool listDirectory(const QString &uri, int componentId = MAV_COMP_ID_AUTOPILOT1);
62 Q_INVOKABLE bool downloadFile(const QString &uri, const QString &localDir, const QString &fileName = QString(), int componentId = MAV_COMP_ID_AUTOPILOT1);
63 Q_INVOKABLE bool uploadFile(const QString &localFile, const QString &uri, int componentId = MAV_COMP_ID_AUTOPILOT1);
64 Q_INVOKABLE bool deleteFile(const QString &uri, int componentId = MAV_COMP_ID_AUTOPILOT1);
65 Q_INVOKABLE void cancelActiveOperation();
66
70 Q_INVOKABLE bool browseArchive(const QString &archivePath);
71
76 Q_INVOKABLE bool extractArchive(const QString &archivePath, const QString &outputDir = QString());
77
79 Q_INVOKABLE void cancelExtraction();
80
81signals:
90 void downloadComplete(const QString &filePath, const QString &error);
91 void uploadComplete(const QString &remotePath, const QString &error);
92 void deleteComplete(const QString &remotePath, const QString &error);
95 void extractionComplete(const QString &outputDir, const QString &error);
96
97private slots:
98 void _handleDownloadComplete(const QString &filePath, const QString &error);
99 void _handleUploadComplete(const QString &remotePath, const QString &error);
100 void _handleDirectoryComplete(const QStringList &entries, const QString &error);
101 void _handleDeleteComplete(const QString &remotePath, const QString &error);
102 void _handleCommandProgress(float value);
103 void _handleExtractionProgress(qreal progress);
104 void _handleExtractionFinished(bool success);
105
106private:
107 enum class Operation {
108 None,
109 List,
110 Download,
111 Upload,
112 Delete,
113 };
114
115 void _setBusy(bool busy);
116 void _setOperation(Operation operation);
117 void _clearOperation();
118 void _setErrorString(const QString &error);
119 void _resetDirectoryState();
120 uint8_t _componentIdForRequest(int componentId) const;
121
122 Vehicle *_vehicle = nullptr;
123 FTPManager *_ftpManager = nullptr;
124 Operation _operation = Operation::None;
125 bool _busy = false;
126 float _progress = 0.0F;
127 QString _errorString;
128 QString _currentPath;
129 QStringList _directoryEntries;
130 QString _lastDownloadFile;
131 QString _lastUploadTarget;
132 bool _lastDownloadIsArchive = false;
133 bool _extracting = false;
134 float _extractionProgress = 0.0F;
135 QString _extractionOutputDir;
136 QGCArchiveModel *_archiveModel = nullptr;
137 QGCCompressionJob *_extractionJob = nullptr;
138};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
Error error
QML-facing controller for MAVLink FTP operations.
void uploadComplete(const QString &remotePath, const QString &error)
void directoryEntriesChanged()
void downloadComplete(const QString &filePath, const QString &error)
void extractionComplete(const QString &outputDir, const QString &error)
void currentPathChanged()
void errorStringChanged()
void progressChanged()
void extractingChanged()
void deleteComplete(const QString &remotePath, const QString &error)
void extractionProgressChanged()
void activeOperationChanged()
void lastDownloadFileChanged()
void lastUploadTargetChanged()
void busyChanged()