-
Notifications
You must be signed in to change notification settings - Fork 18
/
clipgrab.h
196 lines (161 loc) · 5.15 KB
/
clipgrab.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
/*
ClipGrab³
Copyright (C) The ClipGrab Project
http://clipgrab.de
feedback [at] clipgrab [dot] de
This file is part of ClipGrab.
ClipGrab 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.
ClipGrab 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 ClipGrab. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CLIPGRAB_H
#define CLIPGRAB_H
#include <QApplication>
#include <QtGui>
#include <QtNetwork>
#include <QtXml>
#include <QtDebug>
#include <QtWidgets>
#include "video.h"
#include "converter.h"
#include "converter_copy.h"
#include "converter_ffmpeg.h"
#include "ui_update_message.h"
#include "ui_helper_downloader.h"
#include "message_dialog.h"
struct format
{
converter* _converter;
QString _name;
int _mode;
bool _audioOnly;
};
struct language
{
language(): isRTL(false) {}
QString name;
QString code;
bool isRTL;
};
struct updateInfo
{
QString version;
QString url;
QString sha1;
QDomNodeList domNodes;
friend bool operator>(const updateInfo &a, const updateInfo &b)
{
return compare(a, b) > 0;
}
friend bool operator<(const updateInfo &a, const updateInfo &b)
{
return compare(a, b) < 0;
}
friend bool operator==(const updateInfo &a, const updateInfo &b)
{
return compare(a, b) == 0;
}
static int compare(const updateInfo &a, const updateInfo&b)
{
QRegExp regexp("^(\\d+)\\.(\\d+)\\.(\\d+)(-.*)?$");
if (regexp.indexIn(a.version) > -1 && regexp.indexIn((b.version)) > -1)
{
regexp.indexIn(a.version);
int majorA = regexp.cap(1).toInt();
int minorA = regexp.cap(2).toInt();
int patchA = regexp.cap(3).toInt();
QString restA = regexp.cap(4);
regexp.indexIn(b.version);
int majorB = regexp.cap(1).toInt();
int minorB = regexp.cap(2).toInt();
int patchB = regexp.cap(3).toInt();
QString restB = regexp.cap(4);
if (majorA > majorB) return 1;
if (majorA < majorB) return -1;
if (minorA > minorB) return 1;
if (minorA < minorB) return -1;
if (patchA > patchB) return 1;
if (patchA < patchB) return -1;
if (restA.isEmpty() && !restB.isEmpty()) return 1;
if (!restA.isEmpty() && restB.isEmpty()) return -1;
return restA.compare(restB);
}
return b.version.compare(a.version);
}
};
class ClipGrab : public QObject
{
Q_OBJECT
public:
ClipGrab();
QList<format> formats;
QList<video*> downloads;
QList<converter*> converters;
QSettings settings;
QSystemTrayIcon trayIcon;
bool isKnownVideoUrl(QString url);
QClipboard* clipboard;
QString clipboardUrl;
QString version;
void openTargetFolder(video*);
void openDownload(video*);
QList<language> languages;
video* getCurrentVideo();
int getRunningDownloadsCount();
QPair<qint64, qint64> getDownloadProgress();
void getUpdateInfo();
void downloadYoutubeDl(bool force = false);
void updateYoutubeDl();
QProcess* runYouTubeDl(QStringList);
void startYoutubeDlDownload();
void clearTempFiles();
// Helpers
QString humanizeBytes(qint64);
QString humanizeSeconds(qint64);
protected:
QDialog* updateMessageDialog;
Ui::UpdateMessage* updateMessageUi;
QList<updateInfo> availableUpdates;
QTemporaryFile* updateFile;
QDialog* helperDownloaderDialog;
Ui::HelperDownloader* helperDownloaderUi;
QFile* youtubeDlFile;
QNetworkReply* updateReply;
video* currentVideo;
video* currentSearch;
QString youtubeDlPath;
QProcess *youtubeDlUpdateProcess;
public slots:
void errorHandler(QString);
void errorHandler(QString, video*);
void parseUpdateInfo(QNetworkReply* reply);
void fetchVideoInfo(const QString & url);
void clearCurrentVideo();
void enqueueDownload(video* video);
void cancelAllDownloads();
void search(QString keywords = "");
void clipboardChanged();
void activateProxySettings();
void startUpdateDownload();
void skipUpdate();
void updateDownloadFinished();
void updateDownloadProgress(qint64, qint64);
void updateReadyRead();
signals:
void currentVideoStateChanged(video*);
void downloadEnqueued();
void downloadFinished(video*);
void searchFinished(video*);
void youtubeDlDownloadFinished();
void compatibleUrlFoundInClipboard(QString url);
void allDownloadsCanceled();
void updateInfoProcessed();
};
#endif // CLIPGRAB_H