QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCCompressionJob.h
Go to the documentation of this file.
1#pragma once
2
5
6#include "QGCCompression.h"
7
8#include <atomic>
9#include <memory>
10#include <QtCore/QFuture>
11#include <QtCore/QFutureWatcher>
12#include <QtCore/QObject>
13
59class QGCCompressionJob : public QObject
60{
61 Q_OBJECT
62 Q_DISABLE_COPY_MOVE(QGCCompressionJob)
63
64
65 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged FINAL)
66
67
68 Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged FINAL)
69
70
71 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged FINAL)
72
73
74 Q_PROPERTY(QString sourcePath READ sourcePath NOTIFY sourcePathChanged FINAL)
75
76
77 Q_PROPERTY(QString outputPath READ outputPath NOTIFY outputPathChanged FINAL)
78
79public:
89 Q_ENUM(Operation)
90
91 explicit QGCCompressionJob(QObject *parent = nullptr);
92 ~QGCCompressionJob() override;
93
94 // Property getters
95 qreal progress() const { return _progress; }
96 bool isRunning() const { return _running; }
97 QString errorString() const { return _errorString; }
98 QString sourcePath() const { return _sourcePath; }
99 QString outputPath() const { return _outputPath; }
100
102 Operation currentOperation() const { return _operation; }
103
106 QFuture<bool> future() const { return _future; }
107
108 // ========================================================================
109 // Static Async Methods (return QFuture directly)
110 // ========================================================================
111
117 static QFuture<bool> extractArchiveAsync(const QString &archivePath,
118 const QString &outputDirectoryPath,
119 qint64 maxBytes = 0);
120
126 static QFuture<bool> decompressFileAsync(const QString &inputPath,
127 const QString &outputPath = QString(),
128 qint64 maxBytes = 0);
129
130public slots:
135 void extractArchive(const QString &archivePath, const QString &outputDirectoryPath,
136 qint64 maxBytes = 0);
137
142 void extractArchiveAtomic(const QString &archivePath, const QString &outputDirectoryPath,
143 qint64 maxBytes = 0);
144
149 void decompressFile(const QString &inputPath, const QString &outputPath = QString(),
150 qint64 maxBytes = 0);
151
156 void extractFile(const QString &archivePath, const QString &fileName,
157 const QString &outputPath);
158
163 void extractFiles(const QString &archivePath, const QStringList &fileNames,
164 const QString &outputDirectoryPath);
165
167 void cancel();
168
169signals:
172
174 void runningChanged(bool running);
175
178 void finished(bool success);
179
181 void errorStringChanged(const QString &errorString);
182
184 void sourcePathChanged(const QString &sourcePath);
185
187 void outputPathChanged(const QString &outputPath);
188
189private slots:
190 void _onProgressValueChanged(int progressValue);
191 void _onFutureFinished();
192
193private:
194 using WorkFunction = std::function<bool(QGCCompression::ProgressCallback)>;
195
196 void _startOperation(Operation op, const QString &source, const QString &output,
197 WorkFunction work);
198 void _setProgress(qreal progress);
199 void _setRunning(bool running);
200 void _setErrorString(const QString &error);
201
202 static QFuture<bool> _runWithProgress(WorkFunction work,
203 const std::shared_ptr<std::atomic_bool> &cancelRequested);
204
205 QFutureWatcher<bool> *_watcher = nullptr;
206 QFuture<bool> _future;
207
208 qreal _progress = 0.0;
209 bool _running = false;
210 QString _errorString;
211 QString _sourcePath;
212 QString _outputPath;
213 Operation _operation = Operation::None;
214 std::shared_ptr<std::atomic_bool> _cancelRequested;
215};
QGCCompressionJob(QObject *parent=nullptr)
void runningChanged(bool running)
Emitted when running state changes.
QString sourcePath() const
QString errorString() const
void progressChanged(qreal progress)
Emitted when progress changes (0.0 to 1.0).
qreal progress() const
void errorStringChanged(const QString &errorString)
Emitted when error string changes.
Operation currentOperation() const
Get current operation type.
void extractArchiveAtomic(const QString &archivePath, const QString &outputDirectoryPath, qint64 maxBytes=0)
Operation
Current progress (0.0 to 1.0).
void extractFiles(const QString &archivePath, const QStringList &fileNames, const QString &outputDirectoryPath)
void extractFile(const QString &archivePath, const QString &fileName, const QString &outputPath)
void cancel()
Cancel current operation.
static QFuture< bool > extractArchiveAsync(const QString &archivePath, const QString &outputDirectoryPath, qint64 maxBytes=0)
void sourcePathChanged(const QString &sourcePath)
Emitted when source path changes.
void finished(bool success)
void outputPathChanged(const QString &outputPath)
Emitted when output path changes.
void decompressFile(const QString &inputPath, const QString &outputPath=QString(), qint64 maxBytes=0)
QString outputPath() const
void extractArchive(const QString &archivePath, const QString &outputDirectoryPath, qint64 maxBytes=0)
static QFuture< bool > decompressFileAsync(const QString &inputPath, const QString &outputPath=QString(), qint64 maxBytes=0)
QFuture< bool > future() const
~QGCCompressionJob() override
std::function< bool(qint64 bytesProcessed, qint64 totalBytes)> ProgressCallback