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()
# 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()
# 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()) {
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) {
if (Download *download = Download::fromUrl(line)) {
if (Download *const download = Download::fromUrl(line)) {
addDownload(download);
if (m_trayIcon && m_trayIcon->isVisible()) {
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()
{
QStringList parts = ui()->hostNameLineEdit->text().split(":", QString::SkipEmptyParts);
QStringList parts = ui()->hostNameLineEdit->text().split(":", Qt::SkipEmptyParts);
if (parts.count() == 2) {
bool 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("referer"), QString());
query.addQueryItem(QStringLiteral("method_free"), QStringLiteral("Free"));
m_postData.append(query.toString(QUrl::FullyEncoded));
m_postData.append(query.toString(QUrl::FullyEncoded).toUtf8());
++m_currentStep;
doInit();
}
@ -61,7 +61,7 @@ void FileNukeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer
pos = videoInfo.indexOf(QLatin1String(",'"), pos + 1);
if (pos > 0) {
substring(videoInfo, str, pos, QStringLiteral("'"), QStringLiteral("'"));
QStringList parts = str.split(QChar('|'), QString::KeepEmptyParts);
QStringList parts = str.split(QChar('|'), Qt::KeepEmptyParts);
if (parts.count() >= 21) {
addDownloadUrl(tr("H.264/AAC/MP4"),

View File

@ -4,7 +4,7 @@
#include "../../application/utils.h"
#include <QRegExp>
#include <QRegularExpression>
using namespace CppUtilities;
using namespace Application;
@ -33,64 +33,61 @@ Download *LinkFinder::createRequest(QString &)
DownloadFinder::ParsingResult LinkFinder::parseResults(const QByteArray &data, QString &)
{
QString html(data);
QRegExp titlePattern(QStringLiteral("<title>(.+)</title>"), Qt::CaseInsensitive);
QRegExp linkPattern(QStringLiteral("<a([^>]+)>(.+)</a>"), Qt::CaseInsensitive);
QRegExp commentPattern(QStringLiteral("<!--(.+)-->"), Qt::CaseInsensitive);
QRegExp hrefPattern1(QStringLiteral("\\s*href\\s*=\\s*['](.+)['>]"), Qt::CaseInsensitive);
QRegExp hrefPattern2(QStringLiteral("\\s*href\\s*=\\s*[\"](.+)[\">]"), Qt::CaseInsensitive);
titlePattern.setMinimal(true);
linkPattern.setMinimal(true);
commentPattern.setMinimal(true);
hrefPattern1.setMinimal(true);
hrefPattern2.setMinimal(true);
static const QRegularExpression titlePattern(
QStringLiteral("<title>(.+)</title>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
static const QRegularExpression linkPattern(
QStringLiteral("<a([^>]+)>(.+)</a>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
static const QRegularExpression commentPattern(
QStringLiteral("<!--(.+)-->"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
static const QRegularExpression hrefPattern1(
QStringLiteral("\\s*href\\s*=\\s*['](.+)['>]"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
static const QRegularExpression hrefPattern2(
QStringLiteral("\\s*href\\s*=\\s*[\"](.+)[\">]"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption);
QString pageTitle;
if (titlePattern.indexIn(html) >= 0 && titlePattern.captureCount() >= 1) {
pageTitle = titlePattern.cap(1);
const auto titleMatch = titlePattern.match(html);
if (titleMatch.hasMatch()) {
pageTitle = titleMatch.captured(1);
replaceHtmlEntities(pageTitle);
}
int overallIndex = 0;
int commentIndex = commentPattern.indexIn(html, overallIndex);
int linkIndex = 0;
while (((linkIndex = linkPattern.indexIn(html, overallIndex)) >= 0)) {
if (commentIndex >= 0 && commentIndex < linkIndex) {
auto commentMatch = commentPattern.match(html, 0);
decltype(commentMatch.capturedEnd()) overallIndex = 0;
for (auto linkMatch = linkPattern.match(html, overallIndex); linkMatch.hasMatch(); linkMatch = linkPattern.match(html, overallIndex)) {
if (commentMatch.capturedStart() >= 0 && commentMatch.capturedStart() < linkMatch.capturedStart()) {
// skip comment
overallIndex = commentIndex + commentPattern.matchedLength();
commentIndex = commentPattern.indexIn(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
overallIndex = commentMatch.capturedEnd();
commentMatch = commentPattern.match(html, overallIndex);
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;
}

View File

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

View File

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

View File

@ -72,7 +72,7 @@ void SockshareDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffe
QUrlQuery query;
query.addQueryItem(QStringLiteral("hash"), str);
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++;
doInit();
}

View File

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

View File

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