Commit 73e4f082 authored by Stefano Crocco's avatar Stefano Crocco

Remove conditional code for old versions of Qt/KDE

Since Konqueror now needs at least Qt 5.12 and Frameworks 5.70 a number
of conditional code needed to compile it with previous versions
of Qt and Frameworks can be removed.
parent 1b12d1e1
......@@ -90,10 +90,6 @@ install( FILES org.kde.konqueror.desktop DESTINATION ${KDE_INSTALL_KSERVICES5D
install(FILES konqy_preload.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR})
if (${ECM_VERSION} STRGREATER "5.58.0")
install(FILES konqueror.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})
else()
install(FILES konqueror.categories DESTINATION ${KDE_INSTALL_CONFDIR})
endif()
install(FILES konqueror.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -32,8 +32,4 @@ install( FILES akregator_konqfeedicon.desktop akregator_konqfeedicon.rc DESTINA
install( FILES feed.png DESTINATION ${KDE_INSTALL_DATADIR}/akregator/pics )
# contains list of debug categories, for kdebugsettings
if (${ECM_VERSION} STRGREATER "5.58.0")
install(FILES akregatorplugin.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})
else()
install(FILES akregatorplugin.categories DESTINATION ${KDE_INSTALL_CONFDIR})
endif()
install(FILES akregatorplugin.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})
......@@ -173,11 +173,7 @@ SessionRestoreDialog::SessionRestoreDialog(const QStringList &sessionFilePaths,
item->setData(0, Qt::UserRole, viewIdFor(sessionFile, viewId));
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
item->setCheckState(0, Qt::Checked);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
w = qMax(w, fm.horizontalAdvance(displayText));
#else
w = qMax(w, fm.width(displayText));
#endif
m_sessionItemsCount++;
}
}
......
......@@ -34,13 +34,6 @@ ki18n_wrap_ui(kwebenginepartlib_LIB_SRCS webenginecustomizecacheablefieldsdlg.ui
qt5_add_resources(kwebenginepartlib_LIB_SRCS webenginepart.qrc)
if(NOT Qt5WebEngineWidgets_VERSION VERSION_LESS "5.12.0")
add_definitions(-DUSE_QWEBENGINE_URL_SCHEME)
add_definitions(-DDOWNLOADITEM_KNOWS_PAGE)
else()
list(APPEND kwebenginepartlib_LIB_SRCS webengineparthtmlembedder.cpp)
endif()
qt5_wrap_ui(kwebenginepartlib_LIB_SRCS
ui/searchbar.ui
)
......
......@@ -295,10 +295,7 @@ bool WebEnginePage::acceptNavigationRequest(const QUrl& url, NavigationType type
// Honor the enabling/disabling of plugins per host.
settings()->setAttribute(QWebEngineSettings::PluginsEnabled, WebEngineSettings::self()->isPluginsEnabled(reqUrl.host()));
#ifndef DOWNLOADITEM_KNOWS_PAGE
emit navigationRequested(this, url);
#endif
return QWebEnginePage::acceptNavigationRequest(url, type, isMainFrame);
}
......@@ -779,11 +776,9 @@ NewWindowPage::NewWindowPage(WebWindowType type, WebEnginePart* part, QWidget* p
connect(this, SIGNAL(statusBarVisibilityChangeRequested(bool)),
this, SLOT(slotStatusBarVisibilityChangeRequested(bool)));
connect(this, &QWebEnginePage::loadFinished, this, &NewWindowPage::slotLoadFinished);
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (m_type == WebBrowserBackgroundTab) {
m_windowArgs.setLowerWindow(true);
}
#endif
}
NewWindowPage::~NewWindowPage()
......@@ -799,9 +794,7 @@ static KParts::BrowserArguments browserArgs(WebEnginePage::WebWindowType type)
bargs.setForcesNewWindow(true);
break;
case WebEnginePage::WebBrowserTab:
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
case WebEnginePage::WebBrowserBackgroundTab:
#endif
// let konq decide, based on user configuration
//bargs.setNewTab(true);
break;
......@@ -898,9 +891,6 @@ bool NewWindowPage::acceptNavigationRequest(const QUrl &url, NavigationType type
}
#ifndef DOWNLOADITEM_KNOWS_PAGE
emit navigationRequested(this, url);
#endif
return WebEnginePage::acceptNavigationRequest(url, type, isMainFrame);
}
......
......@@ -90,10 +90,6 @@ Q_SIGNALS:
void leavingPage(QWebEnginePage::NavigationType type);
#ifndef DOWNLOADITEM_KNOWS_PAGE
void navigationRequested(WebEnginePage* page, const QUrl& url);
#endif
protected:
/**
* Returns the webengine part in use by this object.
......
......@@ -81,33 +81,21 @@
#include <QMenu>
#include <QStatusBar>
#include <QWebEngineScriptCollection>
#ifdef USE_QWEBENGINE_URL_SCHEME
#include <QWebEngineUrlScheme>
#endif
#include "utils.h"
#include <kio_version.h>
void WebEnginePart::initWebEngineUrlSchemes()
{
#ifdef USE_QWEBENGINE_URL_SCHEME
static bool needToInitUrlSchemes = true;
if (needToInitUrlSchemes) {
needToInitUrlSchemes = false;
QVector<QByteArray> localSchemes = {"error", "konq"};
const QStringList protocols = KProtocolInfo::protocols();
for(const QString &prot : protocols){
#if KIO_VERSION >= QT_VERSION_CHECK(5,60,0)
if (KProtocolInfo::defaultMimetype(prot) == "text/html") {
localSchemes.append(QByteArray(prot.toLatin1()));
}
#else
QUrl fakeUrl;
fakeUrl.setScheme(prot);
fakeUrl.setPath("fake");
if (KProtocolManager::defaultMimetype(fakeUrl) == "text/html"){
localSchemes.append(QByteArray(prot.toLatin1()));
}
#endif
}
for (const QByteArray &name : qAsConst(localSchemes)){
QWebEngineUrlScheme scheme(name);
......@@ -116,7 +104,6 @@ void WebEnginePart::initWebEngineUrlSchemes()
QWebEngineUrlScheme::registerScheme(scheme);
}
}
#endif
}
WebEnginePart::WebEnginePart(QWidget *parentWidget, QObject *parent,
......
......@@ -118,20 +118,18 @@ WebEngineView* WebEngineBrowserExtension::view()
int WebEngineBrowserExtension::xOffset()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (view())
if (view()) {
return view()->page()->scrollPosition().x();
#endif
}
return KParts::BrowserExtension::xOffset();
}
int WebEngineBrowserExtension::yOffset()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (view())
if (view()) {
return view()->page()->scrollPosition().y();
#endif
}
return KParts::BrowserExtension::yOffset();
}
......@@ -251,7 +249,6 @@ void WebEngineBrowserExtension::slotSaveFrame()
void WebEngineBrowserExtension::print()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 8, 0)
if (view()) {
mCurrentPrinter = new QPrinter();
QPointer<QPrintDialog> dialog = new QPrintDialog(mCurrentPrinter, nullptr);
......@@ -264,7 +261,6 @@ void WebEngineBrowserExtension::print()
delete dialog;
view()->page()->print(mCurrentPrinter, invoke(this, &WebEngineBrowserExtension::slotHandlePagePrinted));
}
#endif
}
void WebEngineBrowserExtension::slotHandlePagePrinted(bool result)
......@@ -401,9 +397,9 @@ void WebEngineBrowserExtension::slotSaveImageAs()
void WebEngineBrowserExtension::slotSendImage()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QStringList urls;
urls.append(view()->contextMenuResult().mediaUrl().path());
......@@ -412,14 +408,13 @@ void WebEngineBrowserExtension::slotSendImage()
QString(), //body
QString(),
urls); // attachments
#endif
}
void WebEngineBrowserExtension::slotCopyImageURL()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QUrl safeURL = view()->contextMenuResult().mediaUrl();
safeURL.setPassword(QString());
......@@ -434,15 +429,14 @@ void WebEngineBrowserExtension::slotCopyImageURL()
mimeData = new QMimeData;
mimeData->setUrls(safeURLList);
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
#endif
}
void WebEngineBrowserExtension::slotCopyImage()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QUrl safeURL; //(view()->contextMenuResult().imageUrl());
safeURL.setPassword(QString());
......@@ -460,22 +454,20 @@ void WebEngineBrowserExtension::slotCopyImage()
// mimeData->setImageData(view()->contextMenuResult().pixmap());
mimeData->setUrls(safeURLList);
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
#endif
}
void WebEngineBrowserExtension::slotViewImage()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (view())
if (view()) {
emit createNewWindow(view()->contextMenuResult().mediaUrl());
#endif
}
}
void WebEngineBrowserExtension::slotBlockImage()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
bool ok = false;
const QString url = QInputDialog::getText(view(), i18n("Add URL to Filter"),
......@@ -486,7 +478,6 @@ void WebEngineBrowserExtension::slotBlockImage()
WebEngineSettings::self()->addAdFilter(url);
reparseConfiguration();
}
#endif
}
void WebEngineBrowserExtension::slotBlockHost()
......@@ -508,25 +499,21 @@ void WebEngineBrowserExtension::slotCopyLinkURL()
void WebEngineBrowserExtension::slotCopyLinkText()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (view()) {
QMimeData* data = new QMimeData;
data->setText(view()->contextMenuResult().linkText());
QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard);
}
#endif
}
void WebEngineBrowserExtension::slotCopyEmailAddress()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (view()) {
QMimeData* data = new QMimeData;
const QUrl url(view()->contextMenuResult().linkUrl());
data->setText(url.path());
QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard);
}
#endif
}
void WebEngineBrowserExtension::slotSaveLinkAs(const QUrl &url)
......@@ -567,7 +554,6 @@ void WebEngineBrowserExtension::slotViewDocumentSource()
}
}
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
static bool isMultimediaElement(QWebEngineContextMenuData::MediaType mediaType)
{
switch(mediaType)
......@@ -579,58 +565,53 @@ static bool isMultimediaElement(QWebEngineContextMenuData::MediaType mediaType)
return false;
}
}
#endif
void WebEngineBrowserExtension::slotLoopMedia()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QWebEngineContextMenuData data = view()->contextMenuResult();
if (!isMultimediaElement( data.mediaType()))
return;
view()->page()->triggerAction(QWebEnginePage::ToggleMediaLoop);
#endif
}
void WebEngineBrowserExtension::slotMuteMedia()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QWebEngineContextMenuData data = view()->contextMenuResult();
if (!isMultimediaElement( data.mediaType()))
return;
view()->page()->triggerAction(QWebEnginePage::ToggleMediaMute);
#endif
}
void WebEngineBrowserExtension::slotPlayMedia()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QWebEngineContextMenuData data = view()->contextMenuResult();
if (!isMultimediaElement( data.mediaType()))
return;
view()->page()->triggerAction(QWebEnginePage::ToggleMediaPlayPause);
#endif
}
void WebEngineBrowserExtension::slotShowMediaControls()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QWebEngineContextMenuData data = view()->contextMenuResult();
if (!isMultimediaElement( data.mediaType()))
return;
view()->page()->triggerAction(QWebEnginePage::ToggleMediaControls);
#endif
}
#if 0
......@@ -650,22 +631,21 @@ static QUrl mediaUrlFrom(QWebElement& element)
void WebEngineBrowserExtension::slotSaveMedia()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QWebEngineContextMenuData data = view()->contextMenuResult();
if (!isMultimediaElement( data.mediaType()))
return;
emit saveUrl(data.mediaUrl());
#endif
}
void WebEngineBrowserExtension::slotCopyMedia()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
QWebEngineContextMenuData data = view()->contextMenuResult();
if (!isMultimediaElement( data.mediaType()))
return;
......@@ -686,7 +666,6 @@ void WebEngineBrowserExtension::slotCopyMedia()
mimeData = new QMimeData;
mimeData->setUrls(safeURLList);
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
#endif
}
void WebEngineBrowserExtension::slotTextDirectionChanged()
......@@ -843,9 +822,9 @@ void WebEngineBrowserExtension::slotOpenSelection()
void WebEngineBrowserExtension::slotLinkInTop()
{
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (!view())
if (!view()) {
return;
}
KParts::OpenUrlArguments uargs;
uargs.setActionRequestedByUser(true);
......@@ -856,7 +835,6 @@ void WebEngineBrowserExtension::slotLinkInTop()
const QUrl url(view()->contextMenuResult().linkUrl());
emit openUrlRequest(url, uargs, bargs);
#endif
}
////
......
......@@ -70,23 +70,18 @@ WebEnginePartCookieJar::WebEnginePartCookieJar(QWebEngineProfile *prof, QObject
loadKIOCookies();
//QWebEngineCookieStore::setCookieFilter only exists from Qt 5.11.0
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0)
auto filter = [this](const QWebEngineCookieStore::FilterRequest &req){return filterCookie(req);};
m_cookieStore->setCookieFilter(filter);
#endif //QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0)
}
WebEnginePartCookieJar::~WebEnginePartCookieJar()
{
}
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0)
bool WebEnginePartCookieJar::filterCookie(const QWebEngineCookieStore::FilterRequest& req)
{
return WebEngineSettings::self()->acceptCrossDomainCookies() || !req.thirdParty;
}
#endif //QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0)
void WebEnginePartCookieJar::deleteSessionCookies()
{
......@@ -160,13 +155,6 @@ void WebEnginePartCookieJar::addCookie(const QNetworkCookie& _cookie)
if (cookie.expirationDate().isValid()) {
//There's a bug in KCookieJar which causes the expiration date to be interpreted as local time
//instead of GMT as it should. The bug is fixed in KIO 5.50
#if KIO_VERSION < QT_VERSION_CHECK(5,50,0)
QTimeZone local = QTimeZone::systemTimeZone();
int offset = local.offsetFromUtc(QDateTime::currentDateTime());
QDateTime dt = cookie.expirationDate();
dt.setTime(dt.time().addSecs(offset));
cookie.setExpirationDate(dt);
#endif
}
QUrl url = constructUrlForCookie(cookie);
if (url.isEmpty()) {
......
......@@ -247,7 +247,6 @@ private:
*/
static CookieWithUrl parseKIOCookie(const QStringList &data, int start);
#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0)
/**
* @brief Function used to filter cookies
*
......@@ -265,7 +264,6 @@ private:
* @sa addCookie()
*/
bool filterCookie(const QWebEngineCookieStore::FilterRequest &req);
#endif //QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0)
/**
* @brief Removes the domain from the cookie if the domain doesn't start with a dot
......
......@@ -50,9 +50,6 @@ WebEnginePartDownloadManager::WebEnginePartDownloadManager()
WebEnginePartDownloadManager::~WebEnginePartDownloadManager()
{
#ifndef DOWNLOADITEM_KNOWS_PAGE
m_requests.clear();
#endif
}
WebEnginePartDownloadManager * WebEnginePartDownloadManager::instance()
......@@ -66,28 +63,17 @@ void WebEnginePartDownloadManager::addPage(WebEnginePage* page)
if (!m_pages.contains(page)) {
m_pages.append(page);
}
#ifndef DOWNLOADITEM_KNOWS_PAGE
connect(page, &WebEnginePage::navigationRequested, this, &WebEnginePartDownloadManager::recordNavigationRequest);
#endif
connect(page, &QObject::destroyed, this, &WebEnginePartDownloadManager::removePage);
}
void WebEnginePartDownloadManager::removePage(QObject* page)
{
#ifndef DOWNLOADITEM_KNOWS_PAGE
const QUrl url = m_requests.key(static_cast<WebEnginePage *>(page));
m_requests.remove(url);
#endif
m_pages.removeOne(static_cast<WebEnginePage*>(page));
}
void WebEnginePartDownloadManager::performDownload(QWebEngineDownloadItem* it)
{
#ifdef DOWNLOADITEM_KNOWS_PAGE
WebEnginePage *page = qobject_cast<WebEnginePage*>(it->page());
#else
WebEnginePage *page = m_requests.take(it->url());
#endif
bool forceNew = false;
//According to the documentation, QWebEngineDownloadItem::page() can return nullptr "if the download was not triggered by content in a page"
if (!page && !m_pages.isEmpty()) {
......@@ -195,24 +181,6 @@ void WebEnginePartDownloadManager::blobDownloadedToFile(QWebEngineDownloadItem *
}
}
#ifndef DOWNLOADITEM_KNOWS_PAGE
void WebEnginePartDownloadManager::recordNavigationRequest(WebEnginePage *page, const QUrl& url)
{
// qCDebug(WEBENGINEPART_LOG) << url;
m_requests.insert(url, page);
}
WebEnginePage* WebEnginePartDownloadManager::pageForDownload(QWebEngineDownloadItem* it)
{
WebEnginePage *page = m_requests.value(it->url());
if (!page && !m_pages.isEmpty()) {
page = m_pages.first();
}
return page;
}
#endif
WebEngineBlobDownloadJob::WebEngineBlobDownloadJob(QWebEngineDownloadItem* it, QObject* parent) : KJob(parent), m_downloadItem(it)
{
setCapabilities(KJob::Killable|KJob::Suspendable);
......
......@@ -22,7 +22,6 @@
#define WEBENGINEPARTDOWNLOADMANAGER_H
#include <QObject>
#include <QHash>
#include <QVector>
#include <QWebEngineDownloadItem>
#include <QTemporaryDir>
......@@ -57,19 +56,8 @@ private Q_SLOTS:
void openBlob(QWebEngineDownloadItem *it, WebEnginePage *page);
void blobDownloadedToFile(QWebEngineDownloadItem *it, WebEnginePage *page);
#ifndef DOWNLOADITEM_KNOWS_PAGE
private:
WebEnginePage* pageForDownload(QWebEngineDownloadItem *it);
private Q_SLOTS:
void recordNavigationRequest(WebEnginePage* page, const QUrl& url);
#endif
private:
QVector<WebEnginePage*> m_pages;
#ifndef DOWNLOADITEM_KNOWS_PAGE
QHash<QUrl, WebEnginePage*> m_requests;
#endif
QTemporaryDir m_tempDownloadDir;
};
......
/*
* This file is part of the KDE project.
*
* Copyright (C) 2018 Stefano Crocco <stefano.crocco@alice.it>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "webengineparthtmlembedder.h"
#include <KIO/StoredTransferJob>
#include <QWebEngineUrlRequestJob>
#include <QBuffer>
#include <QFileInfo>
#include <QWebEnginePage>
#include <QWebEngineProfile>
#include <QJsonDocument>
#include <QMimeDatabase>
#include <QMetaObject>
static const char s_extractUrlsJs[] = "extractUrlsForTag = function(name, attr){\n"
" var elems = document.getElementsByTagName(name);\n"
" var urls = [];\n"
" for(var i = 0; i < elems.length; i++){\n"
" var url = elems[i].getAttribute(attr);\n"
" if(url.length > 0) urls.push(url);\n"
" }\n"
" return urls;\n"
"};\n"
"extractUrlsForTag(\"link\", \"href\").concat(extractUrlsForTag(\"img\", \"src\"));";
static const char s_replaceUrlsJs[] = "urlMap = %1;\n"
"replaceUrlsForTag = function(name, attr){\n"
" var elems = document.getElementsByTagName(name);\n"
" var urls = [];\n"
" for(var i = 0; i < elems.length; i++){\n"