onWebpageDownloadComplete A callback when a webpage download completes.
55 const QByteArray data{
self->getDownloadedData()};
56 const QUrl url{
self->getUrl()};
59 if(error != QNetworkReply::NoError) {
61 qDebug() <<
"FINISHED DOWNLOADING WEBPAGE WITH ERROR" << error;
65 const QString document(data);
67 QRegularExpression imageTagRegex(
"\\<img[^\\>]*src\\s*=\\s*\"([^\"]*)\"[^\\>]*\\>", QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
69 QStringList imageMatches;
70 QStringList urlMatches;
72 QRegularExpressionMatchIterator it = imageTagRegex.globalMatch(document);
74 QRegularExpressionMatch match = it.next();
75 imageMatches.append(match.captured(0));
76 urlMatches.append(match.captured(1));
79 QList<QUrl> imageUrls;
80 for(
const QString& url : urlMatches) {
81 imageUrls.push_back(QUrl(url));
84 const QString currentPathUrl{url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash | QUrl::RemoveFragment).toString()};
85 for(QUrl& imageUrl : imageUrls) {
88 if(imageUrl.scheme().isEmpty()) {
89 const QString imageUrlString{imageUrl.toString(QUrl::PrettyDecoded)};
90 if(imageUrlString.startsWith(
"//")) {
92 if(!url.scheme().isEmpty()) {
93 imageUrl.setScheme(url.scheme());
95 imageUrl.setScheme(
"http");
97 }
else if(imageUrlString.startsWith(
"/")) {
98 imageUrl = imageUrl.resolved(currentPathUrl);
100 imageUrl = QUrl(currentPathUrl + imageUrl.toString());