From 884bed480d38330032234e0606f3dc608ce4dfe4 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 4 Sep 2020 00:57:42 +0200 Subject: [PATCH] Support Qt 6 (commit 174154b) --- CMakeLists.txt | 2 +- gui/mainwindow.cpp | 4 +- gui/settings.cpp | 2 +- network/filenukedownload.cpp | 4 +- network/finder/linkfinder.cpp | 103 ++++++++++++++++---------------- network/groovesharkdownload.cpp | 20 +++---- network/httpdownload.cpp | 4 +- network/socksharedownload.cpp | 2 +- network/vimeodownload.cpp | 14 ++--- network/youtubedownload.cpp | 14 ++--- 10 files changed, 80 insertions(+), 89 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39b855a..8ec593c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index aa24261..d7d18c1 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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)); diff --git a/gui/settings.cpp b/gui/settings.cpp index 2392f8b..cfd93f4 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -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); diff --git a/network/filenukedownload.cpp b/network/filenukedownload.cpp index f78bd27..64b028e 100644 --- a/network/filenukedownload.cpp +++ b/network/filenukedownload.cpp @@ -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"), diff --git a/network/finder/linkfinder.cpp b/network/finder/linkfinder.cpp index 13a183f..9d3551d 100644 --- a/network/finder/linkfinder.cpp +++ b/network/finder/linkfinder.cpp @@ -4,7 +4,7 @@ #include "../../application/utils.h" -#include +#include 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("(.+)"), Qt::CaseInsensitive); - QRegExp linkPattern(QStringLiteral("]+)>(.+)"), 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("(.+)"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption); + static const QRegularExpression linkPattern( + QStringLiteral("]+)>(.+)"), 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; } diff --git a/network/groovesharkdownload.cpp b/network/groovesharkdownload.cpp index 66df96e..ae136f1 100644 --- a/network/groovesharkdownload.cpp +++ b/network/groovesharkdownload.cpp @@ -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; diff --git a/network/httpdownload.cpp b/network/httpdownload.cpp index 9b4e9fa..862d634 100644 --- a/network/httpdownload.cpp +++ b/network/httpdownload.cpp @@ -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 { diff --git a/network/socksharedownload.cpp b/network/socksharedownload.cpp index 2d088f1..3ee185e 100644 --- a/network/socksharedownload.cpp +++ b/network/socksharedownload.cpp @@ -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(); } diff --git a/network/vimeodownload.cpp b/network/vimeodownload.cpp index 43bfa58..40ff344 100644 --- a/network/vimeodownload.cpp +++ b/network/vimeodownload.cpp @@ -1,5 +1,7 @@ #include "./vimeodownload.h" +#include + #include #include @@ -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(id.toULongLong(&isInt)); if (isInt) { setId(id #if QT_VERSION >= 0x050400 diff --git a/network/youtubedownload.cpp b/network/youtubedownload.cpp index df327c3..741dc3d 100644 --- a/network/youtubedownload.cpp +++ b/network/youtubedownload.cpp @@ -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 §ion : 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);