Support Qt 6 (commit 174154b)

This commit is contained in:
Martchus 2020-09-04 00:57:42 +02:00
parent 8d09b4e308
commit 884bed480d
10 changed files with 80 additions and 89 deletions

View File

@ -146,7 +146,7 @@ find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED)
use_cpp_utilities() use_cpp_utilities()
# find qtutilities # find qtutilities
find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX} 6.0.0 REQUIRED) find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX} 6.3.0 REQUIRED)
use_qt_utilities() use_qt_utilities()
# add Qt modules which can currently not be detected automatically # add Qt modules which can currently not be detected automatically

View File

@ -668,9 +668,9 @@ void MainWindow::clipboardDataChanged()
{ {
if (!m_internalClipboardChange && m_superviseClipboardToolButton->isChecked()) { if (!m_internalClipboardChange && m_superviseClipboardToolButton->isChecked()) {
QString data = QApplication::clipboard()->text(); QString data = QApplication::clipboard()->text();
QStringList lines = data.split(QChar('\n'), QString::SkipEmptyParts); QStringList lines = data.split(QChar('\n'), Qt::SkipEmptyParts);
for (const QString &line : lines) { for (const QString &line : lines) {
if (Download *download = Download::fromUrl(line)) { if (Download *const download = Download::fromUrl(line)) {
addDownload(download); addDownload(download);
if (m_trayIcon && m_trayIcon->isVisible()) { if (m_trayIcon && m_trayIcon->isVisible()) {
m_trayIcon->showMessage(windowTitle(), tr("The download \"%1\" has been added.").arg(data)); m_trayIcon->showMessage(windowTitle(), tr("The download \"%1\" has been added.").arg(data));

View File

@ -256,7 +256,7 @@ QWidget *ProxyPage::setupWidget()
void ProxyPage::updateProxy() void ProxyPage::updateProxy()
{ {
QStringList parts = ui()->hostNameLineEdit->text().split(":", QString::SkipEmptyParts); QStringList parts = ui()->hostNameLineEdit->text().split(":", Qt::SkipEmptyParts);
if (parts.count() == 2) { if (parts.count() == 2) {
bool ok; bool ok;
int port = parts.at(1).toInt(&ok); int port = parts.at(1).toInt(&ok);

View File

@ -50,7 +50,7 @@ void FileNukeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer
query.addQueryItem(QStringLiteral("fname"), fname); query.addQueryItem(QStringLiteral("fname"), fname);
query.addQueryItem(QStringLiteral("referer"), QString()); query.addQueryItem(QStringLiteral("referer"), QString());
query.addQueryItem(QStringLiteral("method_free"), QStringLiteral("Free")); query.addQueryItem(QStringLiteral("method_free"), QStringLiteral("Free"));
m_postData.append(query.toString(QUrl::FullyEncoded)); m_postData.append(query.toString(QUrl::FullyEncoded).toUtf8());
++m_currentStep; ++m_currentStep;
doInit(); doInit();
} }
@ -61,7 +61,7 @@ void FileNukeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer
pos = videoInfo.indexOf(QLatin1String(",'"), pos + 1); pos = videoInfo.indexOf(QLatin1String(",'"), pos + 1);
if (pos > 0) { if (pos > 0) {
substring(videoInfo, str, pos, QStringLiteral("'"), QStringLiteral("'")); substring(videoInfo, str, pos, QStringLiteral("'"), QStringLiteral("'"));
QStringList parts = str.split(QChar('|'), QString::KeepEmptyParts); QStringList parts = str.split(QChar('|'), Qt::KeepEmptyParts);
if (parts.count() >= 21) { if (parts.count() >= 21) {
addDownloadUrl(tr("H.264/AAC/MP4"), addDownloadUrl(tr("H.264/AAC/MP4"),

View File

@ -4,7 +4,7 @@
#include "../../application/utils.h" #include "../../application/utils.h"
#include <QRegExp> #include <QRegularExpression>
using namespace CppUtilities; using namespace CppUtilities;
using namespace Application; using namespace Application;
@ -33,64 +33,61 @@ Download *LinkFinder::createRequest(QString &)
DownloadFinder::ParsingResult LinkFinder::parseResults(const QByteArray &data, QString &) DownloadFinder::ParsingResult LinkFinder::parseResults(const QByteArray &data, QString &)
{ {
QString html(data); QString html(data);
QRegExp titlePattern(QStringLiteral("<title>(.+)</title>"), Qt::CaseInsensitive); static const QRegularExpression titlePattern(
QRegExp linkPattern(QStringLiteral("<a([^>]+)>(.+)</a>"), Qt::CaseInsensitive); QStringLiteral("<title>(.+)</title>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
QRegExp commentPattern(QStringLiteral("<!--(.+)-->"), Qt::CaseInsensitive); static const QRegularExpression linkPattern(
QRegExp hrefPattern1(QStringLiteral("\\s*href\\s*=\\s*['](.+)['>]"), Qt::CaseInsensitive); QStringLiteral("<a([^>]+)>(.+)</a>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
QRegExp hrefPattern2(QStringLiteral("\\s*href\\s*=\\s*[\"](.+)[\">]"), Qt::CaseInsensitive); static const QRegularExpression commentPattern(
titlePattern.setMinimal(true); QStringLiteral("<!--(.+)-->"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
linkPattern.setMinimal(true); static const QRegularExpression hrefPattern1(
commentPattern.setMinimal(true); QStringLiteral("\\s*href\\s*=\\s*['](.+)['>]"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
hrefPattern1.setMinimal(true); static const QRegularExpression hrefPattern2(
hrefPattern2.setMinimal(true); QStringLiteral("\\s*href\\s*=\\s*[\"](.+)[\">]"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
QString pageTitle; QString pageTitle;
if (titlePattern.indexIn(html) >= 0 && titlePattern.captureCount() >= 1) { const auto titleMatch = titlePattern.match(html);
pageTitle = titlePattern.cap(1); if (titleMatch.hasMatch()) {
pageTitle = titleMatch.captured(1);
replaceHtmlEntities(pageTitle); replaceHtmlEntities(pageTitle);
} }
int overallIndex = 0; auto commentMatch = commentPattern.match(html, 0);
int commentIndex = commentPattern.indexIn(html, overallIndex); decltype(commentMatch.capturedEnd()) overallIndex = 0;
int linkIndex = 0; for (auto linkMatch = linkPattern.match(html, overallIndex); linkMatch.hasMatch(); linkMatch = linkPattern.match(html, overallIndex)) {
while (((linkIndex = linkPattern.indexIn(html, overallIndex)) >= 0)) { if (commentMatch.capturedStart() >= 0 && commentMatch.capturedStart() < linkMatch.capturedStart()) {
if (commentIndex >= 0 && commentIndex < linkIndex) {
// skip comment // skip comment
overallIndex = commentIndex + commentPattern.matchedLength(); overallIndex = commentMatch.capturedEnd();
commentIndex = commentPattern.indexIn(html, overallIndex); commentMatch = commentPattern.match(html, overallIndex);
} else if (linkIndex >= 0) {
// read actual link
if (linkPattern.captureCount() >= 2) {
QString title(linkPattern.cap(2));
QString href(linkPattern.cap(1));
QString urlStr;
if (hrefPattern1.indexIn(href) >= 0 && hrefPattern1.captureCount() >= 1) {
urlStr = hrefPattern1.cap(1);
} else if (hrefPattern2.indexIn(href) >= 0 && hrefPattern2.captureCount() >= 1) {
urlStr = hrefPattern2.cap(1);
}
if (!urlStr.isEmpty()) {
replaceHtmlEntities(title);
replaceHtmlEntities(urlStr);
// resolve relative URLs
QUrl url(urlStr);
if (url.isRelative()) {
url = m_url.resolved(url);
}
// avoid duplicate results
if (Download *duplicateDownload = downloadByInitialUrl(url)) {
if (!title.isEmpty() && duplicateDownload->title().isEmpty()) {
duplicateDownload->provideMetaData(title);
}
} else if (Download *result = Download::fromUrl(url)) {
result->provideMetaData(title, QString(), TimeSpan(), pageTitle, results().size());
reportResult(result);
}
}
}
overallIndex = linkIndex + linkPattern.matchedLength();
} else {
// no more links
break; break;
} }
// read actual link
QString title = linkMatch.captured(2), href = linkMatch.captured(1), urlStr;
const auto hrefMatch1 = hrefPattern1.match(href);
if (hrefMatch1.hasMatch()) {
urlStr = hrefMatch1.captured(1);
} else {
const auto hrefMatch2 = hrefPattern2.match(href);
if (hrefMatch2.hasMatch()) {
urlStr = hrefMatch2.captured(1);
}
}
if (!urlStr.isEmpty()) {
replaceHtmlEntities(title);
replaceHtmlEntities(urlStr);
// resolve relative URLs
QUrl url(urlStr);
if (url.isRelative()) {
url = m_url.resolved(url);
}
// avoid duplicate results
if (Download *const duplicateDownload = downloadByInitialUrl(url)) {
if (!title.isEmpty() && duplicateDownload->title().isEmpty()) {
duplicateDownload->provideMetaData(title);
}
} else if (Download *result = Download::fromUrl(url)) {
result->provideMetaData(title, QString(), TimeSpan(), pageTitle, results().size());
reportResult(result);
}
}
overallIndex = linkMatch.capturedEnd();
} }
return DownloadFinder::ParsingResult::Success; return DownloadFinder::ParsingResult::Success;
} }

View File

@ -304,7 +304,7 @@ bool GroovesharkDownload::loadAuthenticationInformationFromFile(const QString &p
} }
clientVal = fileObj.value(QStringLiteral("referer")); clientVal = fileObj.value(QStringLiteral("referer"));
if (clientVal.isString()) { if (clientVal.isString()) {
m_referer.append(clientVal.toString()); m_referer.append(clientVal.toString().toUtf8());
} }
return true; return true;
} }
@ -316,18 +316,18 @@ bool GroovesharkDownload::loadAuthenticationInformationFromFile(const QString &p
QJsonValue GroovesharkDownload::generateTokenHash(QString method, int mode) QJsonValue GroovesharkDownload::generateTokenHash(QString method, int mode)
{ {
QByteArray toHash; QByteArray toHash;
toHash.append(method); toHash.append(method.toUtf8());
toHash.append(':'); toHash.append(':');
toHash.append(m_token); toHash.append(m_token.toUtf8());
switch (mode) { switch (mode) {
case 1: case 1:
toHash.append(m_htmlRandomizer); toHash.append(m_htmlRandomizer.toUtf8());
break; break;
default: default:
toHash.append(m_jsRandomizer); toHash.append(m_jsRandomizer.toUtf8());
break; break;
} }
toHash.append(m_anyRandomizer); toHash.append(m_anyRandomizer.toUtf8());
QString res; QString res;
res.append(m_anyRandomizer); res.append(m_anyRandomizer);
res.append(QString(QCryptographicHash::hash(toHash, QCryptographicHash::Sha1).toHex()).toLower()); res.append(QString(QCryptographicHash::hash(toHash, QCryptographicHash::Sha1).toHex()).toLower());
@ -340,7 +340,7 @@ QJsonValue GroovesharkDownload::generateTokenHash(QString method, int mode)
QJsonValue GroovesharkDownload::generateSecretKey() QJsonValue GroovesharkDownload::generateSecretKey()
{ {
QByteArray toHash; QByteArray toHash;
toHash.append(m_sessionId.toString()); toHash.append(m_sessionId.toString().toUtf8());
QString secretKey(QCryptographicHash::hash(toHash, QCryptographicHash::Md5).toHex()); QString secretKey(QCryptographicHash::hash(toHash, QCryptographicHash::Md5).toHex());
return QJsonValue(secretKey); return QJsonValue(secretKey);
} }
@ -364,7 +364,7 @@ HttpDownload *GroovesharkDownload::createJsonPostRequest(const QString &method,
HttpDownload *download = new HttpDownload(QUrl(url)); HttpDownload *download = new HttpDownload(QUrl(url));
download->setMethod(HttpDownloadMethod::Post); download->setMethod(HttpDownloadMethod::Post);
download->setPostData(postData); download->setPostData(postData);
download->setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json")); download->setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/json")));
download->setHeader("Refer", m_referer); download->setHeader("Refer", m_referer);
download->setHeader("Accept", m_accept); download->setHeader("Accept", m_accept);
//download->setHeader("Connection", "keep-alive"); //download->setHeader("Connection", "keep-alive");
@ -379,12 +379,12 @@ void GroovesharkDownload::setupFinalRequest()
setMethod(HttpDownloadMethod::Post); setMethod(HttpDownloadMethod::Post);
switch (m_requestType) { switch (m_requestType) {
case GroovesharkRequestType::SongStream: { case GroovesharkRequestType::SongStream: {
setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
setHeader("Accept", m_accept); setHeader("Accept", m_accept);
QUrlQuery query; QUrlQuery query;
query.addQueryItem("streamKey", m_streamKey); query.addQueryItem("streamKey", m_streamKey);
QByteArray postData; QByteArray postData;
postData.append(query.toString(QUrl::FullyEncoded)); postData.append(query.toString(QUrl::FullyEncoded).toUtf8());
setPostData(postData); setPostData(postData);
addDownloadUrl(tr("MPEG-1 Layer 3"), QUrl(QStringLiteral("http://%1/stream.php").arg(m_streamHost))); addDownloadUrl(tr("MPEG-1 Layer 3"), QUrl(QStringLiteral("http://%1/stream.php").arg(m_streamHost)));
break; break;

View File

@ -78,13 +78,13 @@ void HttpDownload::startRequest(size_t optionIndex)
QByteArray rangeVal; QByteArray rangeVal;
rangeVal.append("bytes="); rangeVal.append("bytes=");
if (currentOffset > 0) { if (currentOffset > 0) {
rangeVal.append(QString::number(currentOffset)); rangeVal.append(QString::number(currentOffset).toUtf8());
} else { } else {
rangeVal.append('0'); rangeVal.append('0');
} }
rangeVal.append('-'); rangeVal.append('-');
if (endOffset > 0) { if (endOffset > 0) {
rangeVal.append(QString::number(endOffset)); rangeVal.append(QString::number(endOffset).toUtf8());
} }
m_request.setRawHeader("Range", rangeVal); m_request.setRawHeader("Range", rangeVal);
} else { } else {

View File

@ -72,7 +72,7 @@ void SockshareDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffe
QUrlQuery query; QUrlQuery query;
query.addQueryItem(QStringLiteral("hash"), str); query.addQueryItem(QStringLiteral("hash"), str);
query.addQueryItem(QStringLiteral("confirm"), QStringLiteral("Continue as Free User")); query.addQueryItem(QStringLiteral("confirm"), QStringLiteral("Continue as Free User"));
m_postData.append(query.toString(QUrl::FullyEncoded)); m_postData.append(query.toString(QUrl::FullyEncoded).toUtf8());
m_currentStep++; m_currentStep++;
doInit(); doInit();
} }

View File

@ -1,5 +1,7 @@
#include "./vimeodownload.h" #include "./vimeodownload.h"
#include <qtutilities/misc/compat.h>
#include <c++utilities/chrono/timespan.h> #include <c++utilities/chrono/timespan.h>
#include <QJsonDocument> #include <QJsonDocument>
@ -33,19 +35,11 @@ VimeoDownload::VimeoDownload(const QString &id, QObject *parent)
Download *VimeoDownload::infoRequestDownload(bool &success, QString &reasonForFail) Download *VimeoDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{ {
const auto pathParts = initialUrl() const auto pathParts = QtUtilities::splitRef(initialUrl().path(QUrl::FullyDecoded), QChar('/'), Qt::SkipEmptyParts);
.path(QUrl::FullyDecoded)
.
#if QT_VERSION >= 0x050400
splitRef
#else
split
#endif
(QChar('/'), QString::SkipEmptyParts);
if (pathParts.size() < 2) { if (pathParts.size() < 2) {
const auto &id = pathParts.back(); const auto &id = pathParts.back();
bool isInt; bool isInt;
id.toULongLong(&isInt); static_cast<void>(id.toULongLong(&isInt));
if (isInt) { if (isInt) {
setId(id setId(id
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400

View File

@ -62,9 +62,9 @@ void YoutubeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer)
m_itagInfo = loadJsonObjectFromResource(QStringLiteral(":/jsonobjects/itaginfo")); m_itagInfo = loadJsonObjectFromResource(QStringLiteral(":/jsonobjects/itaginfo"));
} }
QString videoInfo(videoInfoBuffer->readAll()); QString videoInfo(videoInfoBuffer->readAll());
QStringList completeFields = videoInfo.split(QChar('&'), QString::SkipEmptyParts, Qt::CaseSensitive); QStringList completeFields = videoInfo.split(QChar('&'), Qt::SkipEmptyParts, Qt::CaseSensitive);
for (const QString &completeField : completeFields) { for (const QString &completeField : completeFields) {
QStringList fieldParts = completeField.split(QChar('='), QString::SkipEmptyParts, Qt::CaseSensitive); QStringList fieldParts = completeField.split(QChar('='), Qt::SkipEmptyParts, Qt::CaseSensitive);
if (fieldParts.count() < 2) { if (fieldParts.count() < 2) {
continue; continue;
} }
@ -93,13 +93,13 @@ void YoutubeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer)
for (const QString &fmtFieldId : fmtFieldIds) { for (const QString &fmtFieldId : fmtFieldIds) {
QString fmtField = m_fields.value(fmtFieldId, QString()); QString fmtField = m_fields.value(fmtFieldId, QString());
if (!fmtField.isEmpty()) { if (!fmtField.isEmpty()) {
QStringList sections = fmtField.split(QChar(','), QString::SkipEmptyParts, Qt::CaseSensitive); QStringList sections = fmtField.split(QChar(','), Qt::SkipEmptyParts, Qt::CaseSensitive);
for (const QString &section : sections) { for (const QString &section : sections) {
QStringList fmtParts = section.split(QChar('&'), QString::SkipEmptyParts, Qt::CaseSensitive); QStringList fmtParts = section.split(QChar('&'), Qt::SkipEmptyParts, Qt::CaseSensitive);
QString itag, urlPart1, urlPart2, name; QString itag, urlPart1, urlPart2, name;
QJsonObject itagObj; QJsonObject itagObj;
for (const QString fmtPart : fmtParts) { for (const QString fmtPart : fmtParts) {
QStringList fmtSubParts = fmtPart.split(QChar('='), QString::SkipEmptyParts, Qt::CaseSensitive); QStringList fmtSubParts = fmtPart.split(QChar('='), Qt::SkipEmptyParts, Qt::CaseSensitive);
if (fmtSubParts.count() >= 2) { if (fmtSubParts.count() >= 2) {
QString fieldIdentifier = fmtSubParts.at(0).toLower(); QString fieldIdentifier = fmtSubParts.at(0).toLower();
if (fieldIdentifier == QLatin1String("url")) { if (fieldIdentifier == QLatin1String("url")) {
@ -146,10 +146,10 @@ void YoutubeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer)
name = itag; name = itag;
} }
QByteArray url; QByteArray url;
url.append(urlPart1); url.append(urlPart1.toUtf8());
if (!urlPart2.isEmpty()) { if (!urlPart2.isEmpty()) {
url.append("&signature="); url.append("&signature=");
url.append(urlPart2); url.append(urlPart2.toUtf8());
} }
addDownloadUrl(name, QUrl::fromPercentEncoding(url)); addDownloadUrl(name, QUrl::fromPercentEncoding(url));
m_itags.append(itag); m_itags.append(itag);