-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJob.h
264 lines (202 loc) · 7.87 KB
/
Job.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*!
* This file is part of OffloadBuddy.
* COPYRIGHT (C) 2020 Emeric Grange - All Rights Reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* \date 2021
* \author Emeric Grange <[email protected]>
*/
#ifndef JOB_H
#define JOB_H
/* ************************************************************************** */
#include "JobUtils.h"
#include "Shot.h"
#include <QObject>
#include <QString>
#include <QVariant>
#include <QDateTime>
class Shot;
class Device;
class MediaLibrary;
/* ************************************************************************** */
typedef struct JobDestination
{
QString mediaDirectory;
QString folder;
QString file;
QString extension;
} JobDestination;
typedef struct JobSettingsDelete
{
bool moveToTrash = true;
} JobSettingsDelete;
typedef struct JobSettingsOffload
{
bool ignoreJunk = true;
bool ignoreAudio = true;
bool extractTelemetry = true;
bool mergeChapters = true;
bool autoDelete = true;
} JobSettingsOffload;
typedef struct JobSettingsTelemetry
{
QString gps_format = "gpx";
int gps_frequency = 2;
QString telemetry_format = "json";
int telemetry_frequency = 30;
bool EGM96 = true;
} JobSettingsTelemetry;
typedef struct JobSettingsEncode
{
QString mode = "";
QString video_codec = "H.264";
QString image_codec = "JPEG";
int encoding_quality = 85; // [50:100]
int encoding_speed = 2; // [1:3] slow / balanced / fast
float fps = -1;
int resolution = -1; // height
int transform = 0;
QString scale;
QString crop;
QString gif_effect;
int timelapse_fps = 0;
QString defisheye;
bool deshake = false;
bool extractTelemetry = true;
int64_t startMs = -1;
int64_t durationMs = -1;
} JobSettingsEncode;
/* ************************************************************************** */
typedef struct JobElement
{
Shot *parent_shot = nullptr;
std::vector <ofb_file> files;
QString destination_folder;
QString destination_file;
QString destination_ext;
} JobElement;
/*!
* \brief The JobTracker class, used by the UI to display jobs and their status
*/
class JobTracker: public QObject
{
Q_OBJECT
Q_PROPERTY(int id READ getId CONSTANT)
Q_PROPERTY(int type READ getType CONSTANT)
Q_PROPERTY(QString typeStr READ getTypeString CONSTANT)
Q_PROPERTY(QStringList files READ getFiles CONSTANT)
Q_PROPERTY(QString destinationFile READ getDestinationFile NOTIFY jobUpdated)
Q_PROPERTY(QString destinationFolder READ getDestinationFolder NOTIFY jobUpdated)
Q_PROPERTY(QString name READ getName NOTIFY jobStateUpdated)
Q_PROPERTY(int state READ getState NOTIFY jobStateUpdated)
Q_PROPERTY(QString stateStr READ getStateString NOTIFY jobStateUpdated)
Q_PROPERTY(bool running READ isRunning NOTIFY jobStateUpdated)
Q_PROPERTY(bool paused READ isPaused NOTIFY jobStateUpdated)
Q_PROPERTY(float progress READ getProgress NOTIFY jobProgressUpdated)
Q_PROPERTY(int elementsIndex READ getElementsIndex NOTIFY jobProgressUpdated)
Q_PROPERTY(int elementsCount READ getElementsCount NOTIFY jobProgressUpdated)
Q_PROPERTY(int elapsed READ getElapsed NOTIFY jobProgressUpdated)
Q_PROPERTY(int eta READ getETA NOTIFY jobProgressUpdated)
Q_PROPERTY(QDateTime startDate READ getStartDate NOTIFY jobProgressUpdated)
Q_PROPERTY(QDateTime stopDate READ getStopDate NOTIFY jobProgressUpdated)
int m_id = -1;
JobUtils::JobType m_type;
JobUtils::JobState m_state = JobUtils::JOB_STATE_QUEUED;
QString m_name;
QStringList m_files;
Device *m_source_device = nullptr;
MediaLibrary *m_source_library = nullptr;
//ShotProvider *m_shot_provider = nullptr; // TODO
QString m_destinationFile;
QString m_destinationFolder;
// job element(s)
std::vector<JobElement *> elements;
int elements_index = 0;
// tracking
float m_percent = 0.0;
int totalFiles = 0;
int64_t totalSize = 0;
QDateTime m_start;
QDateTime m_stop;
QDateTime m_eta;
public:
// settings
JobSettingsDelete settings_delete;
JobSettingsOffload settings_offload;
JobSettingsTelemetry settings_telemetry;
JobSettingsEncode settings_encode;
Q_SIGNALS:
void jobUpdated();
void jobStateUpdated();
void jobProgressUpdated();
public:
JobTracker(int job_id, int job_type, QObject *parent);
~JobTracker();
int getId() const { return m_id; }
JobUtils::JobType getType() const { return m_type; }
QString getTypeString() const;
void setState(int state) {
m_state = static_cast<JobUtils::JobState>(state);
if (m_state == JobUtils::JOB_STATE_WORKING) m_start = QDateTime::currentDateTime();
if (m_state >= JobUtils::JOB_STATE_DONE) m_stop = QDateTime::currentDateTime();
Q_EMIT jobStateUpdated();
}
int getState() const { return m_state; }
QString getStateString() const;
int isRunning() const { return (m_state & JobUtils::JOB_STATE_WORKING); }
int isPaused() const { return (m_state & JobUtils::JOB_STATE_PAUSED); }
////////
void setDevice(Device *d) { m_source_device = d; }
Device *getDevice() const { return m_source_device; }
void setLibrary(MediaLibrary *ml) { m_source_library = ml; }
MediaLibrary *getLibrary() const { return m_source_library; }
// TODO unify through a ShotProvider ?
//void setProvider(ShotProvider *sp) { m_shot_provider = sp; }
//ShotProvider *getProvider() const { return m_shot_provider; }
////////
void setName(const QString &name) { m_name = name; Q_EMIT jobStateUpdated(); }
QString getName() const { return m_name; }
void setFiles(QStringList &fl) { m_files = fl; }
QStringList getFiles() const { return m_files; }
void setDestinationFile(QString dest) { m_destinationFile = dest; Q_EMIT jobUpdated(); }
QString getDestinationFile() const { return m_destinationFile; }
void setDestinationFolder(QString dest) { if (m_type != JobUtils::JOB_DELETE) m_destinationFolder = dest; Q_EMIT jobUpdated(); }
QString getDestinationFolder() const { return m_destinationFolder; }
void addElement(JobElement *je);
std::vector<JobElement *> &getElements() { return elements; }
JobElement *getElement(int index) { return elements.at(index); }
int getElementsCount() { return elements.size(); }
int getElementsIndex() { return elements_index; }
void setElementsIndex(int index) { elements_index = index; Q_EMIT jobProgressUpdated(); }
int getFilesCount() { return totalFiles; }
int getFilesSize() { return totalSize; }
void setProgress(float p) { m_percent = p; Q_EMIT jobProgressUpdated(); }
float getProgress() { return m_percent / 100.f; }
int getETA() { return -1; }
int getElapsed() {
if (m_start.isValid() && m_stop.isValid())
return m_stop.toSecsSinceEpoch() - m_start.toSecsSinceEpoch();
else if (m_start.isValid())
return QDateTime::currentSecsSinceEpoch() - m_start.toSecsSinceEpoch();
else
return -1;
}
QDateTime getStartDate() { return m_start; }
QDateTime getStopDate() { return m_stop; }
Q_INVOKABLE void openDestinationFile() const;
Q_INVOKABLE void openDestinationFolder() const;
};
/* ************************************************************************** */
#endif // JOB_H