diff --git a/plugins/channelrx/demoddvb/CMakeLists.txt b/plugins/channelrx/demoddvb/CMakeLists.txt index d9d53c88a..4cea7f550 100644 --- a/plugins/channelrx/demoddvb/CMakeLists.txt +++ b/plugins/channelrx/demoddvb/CMakeLists.txt @@ -46,14 +46,14 @@ if(NOT SERVER_MODE) set(TARGET_NAME ${PLUGINS_PREFIX}demoddvb) set(TARGET_LIB Qt::Widgets) - # HbbTV applications are run in Qt WebEngine's browser (Qt 6) - if(Qt6WebEngineWidgets_FOUND AND Qt6QuickWidgets_FOUND) + # HbbTV applications are run in Qt WebEngine's browser (Qt 5.15 or 6) + if(Qt${QT_DEFAULT_MAJOR_VERSION}WebEngineWidgets_FOUND AND Qt${QT_DEFAULT_MAJOR_VERSION}QuickWidgets_FOUND) set(demoddvb_SOURCES ${demoddvb_SOURCES} dvbdemodhbbtv.cpp) set(demoddvb_HEADERS ${demoddvb_HEADERS} dvbdemodhbbtv.h) set(TARGET_LIB ${TARGET_LIB} Qt::WebEngineCore Qt::WebEngineWidgets Qt::QuickWidgets) set(DEMODDVB_HBBTV ON) else() - message(STATUS "DVB demodulator: not running HbbTV applications (no Qt 6 WebEngine)") + message(STATUS "DVB demodulator: not running HbbTV applications (no Qt WebEngine)") endif() set(TARGET_LIB_GUI "sdrgui") set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR}) diff --git a/plugins/channelrx/demoddvb/dvbdemodgui.cpp b/plugins/channelrx/demoddvb/dvbdemodgui.cpp index 0bb058a23..edae39b22 100644 --- a/plugins/channelrx/demoddvb/dvbdemodgui.cpp +++ b/plugins/channelrx/demoddvb/dvbdemodgui.cpp @@ -725,7 +725,7 @@ void DVBDemodGUI::appsMenu(const QPoint& position) "carousels or the internet. The coloured buttons are R, G, Y and B (or F1 to F4), and Back is Backspace"); #ifndef DVBDEMOD_HBBTV run->setEnabled(false); - run->setToolTip("Not built: Qt WebEngine (Qt 6) is needed"); + run->setToolTip("Not built: Qt WebEngine is needed"); #endif QAction *clear = menu.addAction("Forget HbbTV sign-ins (cookies and cache)"); diff --git a/plugins/channelrx/demoddvb/dvbdemodhbbtv.cpp b/plugins/channelrx/demoddvb/dvbdemodhbbtv.cpp index b7fde5ad1..381253d0b 100644 --- a/plugins/channelrx/demoddvb/dvbdemodhbbtv.cpp +++ b/plugins/channelrx/demoddvb/dvbdemodhbbtv.cpp @@ -31,8 +31,12 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include #include +#else +#include +#endif #include #include #include @@ -169,7 +173,8 @@ DVBDemodHbbTV::DVBDemodHbbTV(DTVApps *apps, QObject *parent) : m_keyset(0), m_pendingRed(false), m_mediaId(0), - m_appCarouselPid(-1) + m_appCarouselPid(-1), + m_loadsStarted(0) { m_server->start(); connect(m_server, &DTVCarouselServer::served, this, [this](const QString& path, int status) { @@ -189,11 +194,25 @@ DVBDemodHbbTV::DVBDemodHbbTV(DTVApps *apps, QObject *parent) : agent = "Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 HbbTV/1.4.1 (+DRM; LGE; 55UJ670V-ZD; WEBOS3.5 06.10.50; W3_K3LP; W3_K3LP;)"; } setUserAgent(agent); - connect(m_profile, &QWebEngineProfile::downloadRequested, this, &DVBDemodHbbTV::downloadRequested); + // Downloads: of this page's only, as the profile's shared +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(m_profile, &QWebEngineProfile::downloadRequested, this, [this](QWebEngineDownloadRequest *download) { +#else + connect(m_profile, &QWebEngineProfile::downloadRequested, this, [this](QWebEngineDownloadItem *download) { +#endif + if (download->page() == m_page) + { + const QUrl url = download->url(); + const QString mimeType = download->mimeType(); + download->cancel(); + downloadRequested(url, mimeType); + } + }); m_page = new DVBDemodHbbTVPage(m_profile, this); m_page->setUrlRequestInterceptor(m_interceptor); m_page->setBackgroundColor(Qt::transparent); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) connect(m_page, &QWebEnginePage::loadingChanged, this, [this](const QWebEngineLoadingInfo& info) { if (info.status() == QWebEngineLoadingInfo::LoadSucceededStatus) { loadFinished(true); @@ -202,6 +221,27 @@ DVBDemodHbbTV::DVBDemodHbbTV(DTVApps *apps, QObject *parent) : loadFinished(false); } }); +#else + // Qt 5 says a load's failed when it's replaced by another (as when a page goes to another as it loads): only a + // load not followed by another is taken to have failed + connect(m_page, &QWebEnginePage::loadStarted, this, [this]() { m_loadsStarted++; }); + connect(m_page, &QWebEnginePage::loadFinished, this, [this](bool ok) { + if (ok) + { + loadFinished(true); + return; + } + + const int loads = m_loadsStarted; + QTimer::singleShot(500, this, [this, loads]() { + if (loads == m_loadsStarted) + { + emit log(QString("Load failed: %1").arg(m_page->url().toString())); + loadFinished(false); + } + }); + }); +#endif connect(&m_timer, &QTimer::timeout, this, &DVBDemodHbbTV::check); m_timer.start(m_checkMs); @@ -1066,16 +1106,8 @@ void DVBDemodHbbTV::createApplication(const QString& uri) // An HbbTV application served as application/vnd.hbbtv.xhtml+xml, which the browser would download rather than show: // fetched, and given to it as HTML -void DVBDemodHbbTV::downloadRequested(QWebEngineDownloadRequest *download) +void DVBDemodHbbTV::downloadRequested(const QUrl& url, const QString& mimeType) { - if (download->page() != m_page) { - return; // Another demodulator's - } - - const QUrl url = download->url(); - const QString mimeType = download->mimeType(); - download->cancel(); - if (!isRunning() || (url != QUrl(m_appUrl)) || !(mimeType.contains("hbbtv") || mimeType.contains("xhtml") || mimeType.contains("cehtml"))) { emit log(QString("Download of %1 (%2) refused").arg(url.toString()).arg(mimeType)); @@ -1150,7 +1182,13 @@ void DVBDemodHbbTV::updateScript() { QWebEngineScriptCollection& scripts = m_page->scripts(); - for (const QWebEngineScript& old : scripts.find(m_scriptName)) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const QList oldScripts = scripts.find(m_scriptName); +#else + const QList oldScripts = scripts.findScripts(m_scriptName); +#endif + + for (const QWebEngineScript& old : oldScripts) { scripts.remove(old); } diff --git a/plugins/channelrx/demoddvb/dvbdemodhbbtv.h b/plugins/channelrx/demoddvb/dvbdemodhbbtv.h index f2d0ddec4..b3b224d82 100644 --- a/plugins/channelrx/demoddvb/dvbdemodhbbtv.h +++ b/plugins/channelrx/demoddvb/dvbdemodhbbtv.h @@ -167,7 +167,7 @@ private: QJsonObject channelJson(const Channel& channel) const; QString appUrl(const DTVApps::App& app) const; void makeTransparent(); - void downloadRequested(class QWebEngineDownloadRequest *download); + void downloadRequested(const QUrl& url, const QString& mimeType); DTVApps *m_apps; DTVCarouselServer *m_server; @@ -201,6 +201,7 @@ private: QElapsedTimer m_userRequest; //!< Since the user last pressed red or gave the application a key QElapsedTimer m_failed; //!< Since an application last failed to load int m_appCarouselPid; //!< The carousel the running application's loaded from, -1 if none + int m_loadsStarted; //!< Qt 5: page loads started, to tell a failed load from one replaced by another QElapsedTimer m_pendingRedTimer; };