QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCArchiveWatcher.h
Go to the documentation of this file.
1#pragma once
2
5
6#include "QGCFileWatcher.h"
7#include "QGCCompression.h"
8
9#include <QtCore/QLoggingCategory>
10#include <QtCore/QObject>
11#include <QtCore/QSet>
12#include <QtCore/QString>
13
14Q_DECLARE_LOGGING_CATEGORY(QGCArchiveWatcherLog)
15
17
36class QGCArchiveWatcher : public QObject
37{
38 Q_OBJECT
39 Q_DISABLE_COPY_MOVE(QGCArchiveWatcher)
40
41
42 Q_PROPERTY(bool autoDecompress READ autoDecompress WRITE setAutoDecompress NOTIFY autoDecompressChanged FINAL)
43
44
45 Q_PROPERTY(bool extracting READ isExtracting NOTIFY extractingChanged FINAL)
46
47
48 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged FINAL)
49
50
51 Q_PROPERTY(QString outputDirectory READ outputDirectory WRITE setOutputDirectory
52 NOTIFY outputDirectoryChanged FINAL)
53
54public:
56 enum class FilterMode {
57 Archives,
58 Compressed,
59 Both
60 };
61 Q_ENUM(FilterMode)
62
63 explicit QGCArchiveWatcher(QObject *parent = nullptr);
64 ~QGCArchiveWatcher() override;
65
66 // ========================================================================
67 // Configuration
68 // ========================================================================
69
72 void setFilterMode(FilterMode mode);
73 FilterMode filterMode() const { return _filterMode; }
74
77 void setAutoDecompress(bool enable);
78 bool autoDecompress() const { return _autoDecompress; }
79
82 void setOutputDirectory(const QString &directory);
83 QString outputDirectory() const { return _outputDirectory; }
84
87 void setRemoveAfterExtraction(bool remove);
88 bool removeAfterExtraction() const { return _removeAfterExtraction; }
89
92 void setDebounceDelay(int milliseconds);
93 int debounceDelay() const;
94
95 // ========================================================================
96 // Directory Watching
97 // ========================================================================
98
102 bool watchDirectory(const QString &directoryPath);
103
107 bool unwatchDirectory(const QString &directoryPath);
108
111 QStringList watchedDirectories() const;
112
114 void clear();
115
116 // ========================================================================
117 // Status
118 // ========================================================================
119
121 bool isExtracting() const { return _extracting; }
122
124 qreal progress() const { return _progress; }
125
126 // ========================================================================
127 // Manual Operations
128 // ========================================================================
129
133 QStringList scanDirectory(const QString &directoryPath) const;
134
136 void cancelExtraction();
137
138signals:
142 void archiveDetected(const QString &archivePath, QGCCompression::Format format);
143
149 void extractionComplete(const QString &archivePath, const QString &outputPath,
150 bool success, const QString &errorString);
151
153 void autoDecompressChanged(bool autoDecompress);
154 void extractingChanged(bool extracting);
155 void progressChanged(qreal progress);
156 void outputDirectoryChanged(const QString &directory);
157
158private slots:
159 void _onDirectoryChanged(const QString &path);
160 void _onExtractionProgress(qreal progress);
161 void _onExtractionFinished(bool success);
162
163private:
164 bool _isWatchedFormat(const QString &filePath) const;
165 void _processNewFile(const QString &filePath);
166 void _startExtraction(const QString &archivePath);
167 void _setExtracting(bool extracting);
168 void _setProgress(qreal progress);
169
170 QGCFileWatcher *_fileWatcher = nullptr;
171 QGCCompressionJob *_extractionJob = nullptr;
172
173 // Configuration
174 FilterMode _filterMode = FilterMode::Both;
175 bool _autoDecompress = false;
176 bool _removeAfterExtraction = false;
177 QString _outputDirectory;
178
179 // State
180 bool _extracting = false;
181 qreal _progress = 0.0;
182
183 // Track files to avoid duplicate processing
184 QHash<QString, QSet<QString>> _knownFiles; // directory -> known files
185
186 // Pending extractions queue
187 QStringList _pendingExtractions;
188 QString _currentArchive;
189 bool _cancelPending = false;
190};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
QString errorString
Wrapper around QFileSystemWatcher with callback-based API.
void autoDecompressChanged(bool autoDecompress)
Property change signals.
void progressChanged(qreal progress)
void extractionComplete(const QString &archivePath, const QString &outputPath, bool success, const QString &errorString)
void outputDirectoryChanged(const QString &directory)
void extractingChanged(bool extracting)
void archiveDetected(const QString &archivePath, QGCCompression::Format format)
Format
Archive and compression format types (for decompression)