diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,14 +110,14 @@ set(HAVE_KF5Syndication 1) endif() -find_package(KF5WebKit ${KF5_REQUIRED_VERSION}) -set_package_properties(KF5WebKit +find_package(Qt5WebEngineWidgets ${QT_MIN_VERSION}) +set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's search and syndication plugins" ) -if(KF5WebKit_FOUND) - set(HAVE_KF5WebKit 1) +if(Qt5WebEngineWidgets_FOUND) + set(HAVE_Qt5WebEngineWidgets 1) endif() find_package(KF5DNSSD ${KF5_REQUIRED_VERSION}) diff --git a/ktorrent/main.cpp b/ktorrent/main.cpp --- a/ktorrent/main.cpp +++ b/ktorrent/main.cpp @@ -107,6 +107,7 @@ bt::SetClientInfo(QStringLiteral("KTorrent"), kt::MAJOR, kt::MINOR, kt::RELEASE, kt::VERSION_TYPE, QStringLiteral("KT")); QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); KLocalizedString::setApplicationDomain("ktorrent"); QApplication app(argc, argv); diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -13,7 +13,7 @@ if (HAVE_KF5Completion) macro_kt_plugin(ENABLE_UPNP_PLUGIN upnp upnp) endif() -if (HAVE_KF5WebKit) +if (HAVE_Qt5WebEngineWidgets) macro_kt_plugin(ENABLE_SEARCH_PLUGIN search search) endif() #macro_kt_plugin(ENABLE_WEBINTERFACE_PLUGIN webinterface webinterface) @@ -34,7 +34,7 @@ if (HAVE_KF5Archive AND HAVE_KF5ItemViews AND HAVE_KF5Kross) macro_kt_plugin(ENABLE_SCRIPTING_PLUGIN scripting scripting) endif() -if (HAVE_KF5Syndication AND HAVE_KF5WebKit) +if (HAVE_KF5Syndication AND HAVE_Qt5WebEngineWidgets) macro_kt_plugin(ENABLE_SYNDICATION_PLUGIN syndication syndication) endif() macro_kt_plugin(ENABLE_DOWNLOADORDER_PLUGIN downloadorder downloadorder) diff --git a/plugins/search/CMakeLists.txt b/plugins/search/CMakeLists.txt --- a/plugins/search/CMakeLists.txt +++ b/plugins/search/CMakeLists.txt @@ -1,16 +1,15 @@ set(ktsearchplugin_SRC webview.cpp - localfilenetworkreply.cpp - buffernetworkreply.cpp searchenginelist.cpp searchprefpage.cpp searchwidget.cpp searchtoolbar.cpp searchplugin.cpp searchengine.cpp opensearchdownloadjob.cpp searchactivity.cpp - proxy_helper.cpp) + proxy_helper.cpp + magneturlschemehandler.cpp) ki18n_wrap_ui(ktsearchplugin_SRC searchpref.ui) kconfig_add_kcfg_files(ktsearchplugin_SRC searchpluginsettings.kcfgc) @@ -21,7 +20,7 @@ target_link_libraries( ktorrent_search ktcore - Qt5::WebKitWidgets + Qt5::WebEngineWidgets KF5::Torrent KF5::CoreAddons KF5::Completion @@ -32,7 +31,6 @@ KF5::KIOCore KF5::KIOWidgets KF5::Notifications - KF5::WebKit KF5::WidgetsAddons KF5::XmlGui ) diff --git a/plugins/search/buffernetworkreply.h b/plugins/search/buffernetworkreply.h deleted file mode 100644 --- a/plugins/search/buffernetworkreply.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Joris Guisson * - * joris.guisson@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KT_BUFFERNETWORKREPLY_H -#define KT_BUFFERNETWORKREPLY_H - -#include -#include - - -namespace kt -{ - /** - * QNetworkReply which reads from a buffer - */ - class BufferNetworkReply : public QNetworkReply - { - public: - /** - * @param data The data to put into the buffer - * @param content_type Content type of the data - * @param parent Parent of the BufferNetworkReply - */ - BufferNetworkReply(const QByteArray& data, const QString& content_type, QObject* parent = 0); - ~BufferNetworkReply() override; - - void abort() override; - bool isSequential() const override {return true;} - qint64 bytesAvailable() const override; - - protected: - qint64 readData(char* data, qint64 maxlen) override; - - private: - QBuffer buf; - }; - -} - -#endif // KT_BUFFERNETWORKREPLY_H diff --git a/plugins/search/buffernetworkreply.cpp b/plugins/search/buffernetworkreply.cpp deleted file mode 100644 --- a/plugins/search/buffernetworkreply.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Joris Guisson * - * joris.guisson@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "buffernetworkreply.h" -#include -#include - -namespace kt -{ - BufferNetworkReply::BufferNetworkReply(const QByteArray& data, const QString& content_type, QObject* parent) - : QNetworkReply(parent) - { - buf.open(ReadWrite); - buf.write(data); - buf.seek(0); - - open(ReadOnly | Unbuffered); - setHeader(QNetworkRequest::ContentTypeHeader, content_type); - setHeader(QNetworkRequest::ContentLengthHeader, data.size()); - setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); - setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QStringLiteral("OK")); - - QTimer::singleShot(0, this, SIGNAL(readyRead())); - QTimer::singleShot(0, this, SIGNAL(finished())); - } - - BufferNetworkReply::~BufferNetworkReply() - { - - } - - void BufferNetworkReply::abort() - { - // Do nothing - } - - qint64 BufferNetworkReply::readData(char* data, qint64 maxlen) - { - return buf.read(data, maxlen); - } - - qint64 BufferNetworkReply::bytesAvailable() const - { - return buf.size(); - } - -} - diff --git a/plugins/search/localfilenetworkreply.h b/plugins/search/localfilenetworkreply.h deleted file mode 100644 --- a/plugins/search/localfilenetworkreply.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Joris Guisson * - * joris.guisson@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KT_LOCALFILENETWORKREPLY_H -#define KT_LOCALFILENETWORKREPLY_H - -#include -#include - -namespace kt -{ - /** - * QNetworkReply which reads a local file. - */ - class LocalFileNetworkReply : public QNetworkReply - { - public: - LocalFileNetworkReply(const QString& file, QObject* parent = 0); - ~LocalFileNetworkReply() override; - - void abort() override; - bool isSequential() const override {return true;} - bool atEnd() const override; - qint64 bytesAvailable() const override; - - protected: - qint64 readData(char* data, qint64 maxlen) override; - - private: - QFile* fptr; - }; - -} - -#endif // KT_LOCALFILENETWORKREPLY_H diff --git a/plugins/search/localfilenetworkreply.cpp b/plugins/search/localfilenetworkreply.cpp deleted file mode 100644 --- a/plugins/search/localfilenetworkreply.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Joris Guisson * - * joris.guisson@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "localfilenetworkreply.h" -#include -#include - -using namespace bt; - -namespace kt -{ - LocalFileNetworkReply::LocalFileNetworkReply(const QString& file, QObject* parent): QNetworkReply(parent), fptr(0) - { - fptr = new QFile(file, this); - if (fptr->open(QIODevice::ReadOnly)) - { - open(ReadOnly | Unbuffered); - setHeader(QNetworkRequest::ContentLengthHeader, QVariant(fptr->size())); - setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); - setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QStringLiteral("OK")); - - QTimer::singleShot(0, this, SIGNAL(readyRead())); - QTimer::singleShot(0, this, SIGNAL(finished())); - } - else - { - Out(SYS_SRC | LOG_IMPORTANT) << "Cannot open " << file << ": " << fptr->errorString() << endl; - delete fptr; - fptr = 0; - setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 500); - setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QStringLiteral("Internal server error")); - QTimer::singleShot(0, this, SIGNAL(finished())); - } - } - - LocalFileNetworkReply::~LocalFileNetworkReply() - { - } - - void LocalFileNetworkReply::abort() - { - delete fptr; - fptr = 0; - } - - qint64 LocalFileNetworkReply::readData(char* data, qint64 maxlen) - { - return fptr ? fptr->read(data, maxlen) : 0; - } - - bool LocalFileNetworkReply::atEnd() const - { - return !fptr || fptr->atEnd(); - } - - qint64 LocalFileNetworkReply::bytesAvailable() const - { - return fptr ? fptr->size() : 0; - } -} - - diff --git a/plugins/search/magneturlschemehandler.h b/plugins/search/magneturlschemehandler.h new file mode 100644 --- /dev/null +++ b/plugins/search/magneturlschemehandler.h @@ -0,0 +1,39 @@ +/* + * Copyright 2019 gassaf@gmx.de + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MAGNETURLSCHEMEHANDLER_H +#define MAGNETURLSCHEMEHANDLER_H + +#include + +class MagnetUrlSchemeHandler : public QWebEngineUrlSchemeHandler +{ + Q_OBJECT + +public: + explicit MagnetUrlSchemeHandler(QObject *parent = nullptr ); + void requestStarted(QWebEngineUrlRequestJob *request); + +signals: + void magnetUrlDetected(const QUrl &url); + +}; + +#endif // MAGNETURLSCHEMEHANDLER_H diff --git a/plugins/search/magneturlschemehandler.cpp b/plugins/search/magneturlschemehandler.cpp new file mode 100644 --- /dev/null +++ b/plugins/search/magneturlschemehandler.cpp @@ -0,0 +1,34 @@ +/* + * Copyright 2019 gassaf@gmx.de + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "magneturlschemehandler.h" +#include +#include + +MagnetUrlSchemeHandler::MagnetUrlSchemeHandler(QObject *parent ) : QWebEngineUrlSchemeHandler(parent) { + +} + +void MagnetUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request) { + request->fail(QWebEngineUrlRequestJob::RequestAborted); + const QUrl url = request->requestUrl(); + + emit magnetUrlDetected(url); +} diff --git a/plugins/search/searchwidget.h b/plugins/search/searchwidget.h --- a/plugins/search/searchwidget.h +++ b/plugins/search/searchwidget.h @@ -72,22 +72,20 @@ void loadStarted(); void loadFinished(bool ok); void loadProgress(int p); - void unsupportedContent(QNetworkReply* reply); - void torrentDownloadFinished(); void iconChanged(); void titleChanged(const QString& text); + void downloadTorrentFile(QWebEngineDownloadItem *download); private: QUrl searchUrl(const QString& search_text) override; - QWebView* newTab() override; + QWebEngineView* newTab() override; void magnetUrl(const QUrl& magnet_url) override; private: WebView* webview; KToolBar* sbar; SearchPlugin* sp; QProgressBar* prog; - QNetworkReply* torrent_download; KComboBox* search_engine; QLineEdit* search_text; diff --git a/plugins/search/searchwidget.cpp b/plugins/search/searchwidget.cpp --- a/plugins/search/searchwidget.cpp +++ b/plugins/search/searchwidget.cpp @@ -57,7 +57,7 @@ namespace kt { - SearchWidget::SearchWidget(SearchPlugin* sp) : webview(nullptr), sp(sp), prog(nullptr), torrent_download(nullptr) + SearchWidget::SearchWidget(SearchPlugin* sp) : webview(nullptr), sp(sp), prog(nullptr) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(0); @@ -67,9 +67,9 @@ KActionCollection* ac = sp->getSearchActivity()->part()->actionCollection(); sbar = new KToolBar(this); sbar->setToolButtonStyle(Qt::ToolButtonIconOnly); - sbar->addAction(webview->pageAction(QWebPage::Back)); - sbar->addAction(webview->pageAction(QWebPage::Forward)); - sbar->addAction(webview->pageAction(QWebPage::Reload)); + sbar->addAction(webview->pageAction(QWebEnginePage::Back)); + sbar->addAction(webview->pageAction(QWebEnginePage::Forward)); + sbar->addAction(webview->pageAction(QWebEnginePage::Reload)); sbar->addAction(ac->action(QStringLiteral("search_home"))); search_text = new QLineEdit(sbar); sbar->addWidget(search_text); @@ -89,11 +89,9 @@ connect(webview, &WebView::loadStarted, this, &SearchWidget::loadStarted); connect(webview, &WebView::loadFinished, this, &SearchWidget::loadFinished); connect(webview, &WebView::loadProgress, this, &SearchWidget::loadProgress); - connect(webview->page(), SIGNAL(unsupportedContent(QNetworkReply*)), - this, SLOT(unsupportedContent(QNetworkReply*))); - connect(webview, &WebView::linkMiddleOrCtrlClicked, this, &SearchWidget::openNewTab); connect(webview, &WebView::iconChanged, this, &SearchWidget::iconChanged); connect(webview, &WebView::titleChanged, this, &SearchWidget::titleChanged); + connect(webview, &WebView::torrentFileDownloadRequested, this, &SearchWidget::downloadTorrentFile); } @@ -213,40 +211,8 @@ KNotification::event(QStringLiteral("MagnetLinkDownloadStarted"), msg, QPixmap(), sp->getGUI()->getMainWindow()); } - void SearchWidget::unsupportedContent(QNetworkReply* r) + void SearchWidget::downloadTorrentFile(QWebEngineDownloadItem *download) { - if (r->url().scheme() == QStringLiteral("magnet")) - { - magnetUrl(r->url()); - } - else if (r->header(QNetworkRequest::ContentTypeHeader).toString() == QStringLiteral("application/x-bittorrent") || - r->url().path().endsWith(QLatin1String(".torrent"))) - { - torrent_download = r; - - if (!r->isFinished()) - connect(r, SIGNAL(finished()), this, SLOT(torrentDownloadFinished())); - else - torrentDownloadFinished(); - } - else - { - webview->downloadResponse(r); - } - } - - void SearchWidget::torrentDownloadFinished() - { - if (!torrent_download) - return; - - if (torrent_download->error() != QNetworkReply::NoError) - { - KMessageBox::error(this, torrent_download->errorString()); - torrent_download = 0; - return; - } - int ret = KMessageBox::questionYesNoCancel(0, i18n("Do you want to download or save the torrent?"), @@ -256,20 +222,19 @@ KStandardGuiItem::cancel(), QStringLiteral(":TorrentDownloadFinishedQuestion")); - if (ret == KMessageBox::Yes) - sp->getCore()->load(torrent_download->readAll(), torrent_download->url(), QString(), QString()); - else if (ret == KMessageBox::No) - webview->downloadResponse(torrent_download); - - torrent_download = 0; + if (ret == KMessageBox::Yes){ + sp->getCore()->load(download->url(), QString()); + } else if (ret == KMessageBox::No) { + webview->downloadFile(download); + } } void SearchWidget::search() { search(search_text->text(), search_engine->currentIndex()); } - QWebView* SearchWidget::newTab() + QWebEngineView* SearchWidget::newTab() { return sp->getSearchActivity()->newTab()->webview; } @@ -282,7 +247,6 @@ bool SearchWidget::backAvailable() const { - return webview->pageAction(QWebPage::Back)->isEnabled(); + return webview->pageAction(QWebEnginePage::Back)->isEnabled(); } } - diff --git a/plugins/search/webview.h b/plugins/search/webview.h --- a/plugins/search/webview.h +++ b/plugins/search/webview.h @@ -21,7 +21,7 @@ #ifndef KT_WEBVIEW_H #define KT_WEBVIEW_H -#include +#include #include #include @@ -40,16 +40,16 @@ virtual QUrl searchUrl(const QString& search_text) = 0; /// Create a new tab - virtual QWebView* newTab() = 0; + virtual QWebEngineView* newTab() = 0; /// Handle magnet urls virtual void magnetUrl(const QUrl& magnet_url) = 0; }; /** WebView provides a webkit view which supports for the ktorrent homepage. */ - class WebView : public KWebView + class WebView : public QWebEngineView { Q_OBJECT public: @@ -74,12 +74,6 @@ */ QUrl searchUrl(const QString& search_text); - /** - * Download a response using KIO - * @param reply The QNetworkReply to download - */ - void downloadResponse(QNetworkReply* reply); - /// Get the html code of the homepage QString homePageData(); @@ -91,16 +85,23 @@ /// Get heloper object that applies proxy settings ProxyHelper* getProxy() const {return m_proxy;} + + void downloadFile(QWebEngineDownloadItem *download); protected: void loadHomePage(); - QWebView* createWindow(QWebPage::WebWindowType type) override; + QWebEngineView* createWindow(QWebEnginePage::WebWindowType type) override; public slots: /** - * Download a netwerk request - * @param req The request + * Download a QWebEngineDownloadItem + * @param download The QWebEngineDownloadItem */ - void downloadRequested(const QNetworkRequest& req); + void downloadRequested(QWebEngineDownloadItem *download); + void magnetUrlDetected(const QUrl &url); + + signals: + void torrentFileDownloadRequested(QWebEngineDownloadItem *download); + private: QString home_page_html; QString home_page_base_url; diff --git a/plugins/search/webview.cpp b/plugins/search/webview.cpp --- a/plugins/search/webview.cpp +++ b/plugins/search/webview.cpp @@ -23,85 +23,36 @@ #include #include #include -#include #include #include #include #include -#include -#include +#include +#include #include #include #include #include #include #include -#include #include -#include "buffernetworkreply.h" -#include "localfilenetworkreply.h" +#include "magneturlschemehandler.h" using namespace bt; namespace kt { - class NetworkAccessManager : public KIO::AccessManager - { - public: - NetworkAccessManager(WebView* parent) : KIO::AccessManager(parent), webview(parent) - { - webview->getProxy()->ApplyProxy(sessionMetaData()); - } - - ~NetworkAccessManager() override - {} - - QNetworkReply* createRequest(Operation op, const QNetworkRequest& req, QIODevice* outgoingData) override - { - if (req.url().scheme() == QStringLiteral("magnet")) - { - webview->handleMagnetUrl(req.url()); - return KIO::AccessManager::createRequest(op, req, outgoingData); - } - else if (req.url().host() == QStringLiteral("ktorrent.searchplugin")) - { - QString search_text = QUrlQuery(req.url()).queryItemValue(QStringLiteral("search_text")); - - if (!search_text.isEmpty()) - { - QUrl url(webview->searchUrl(search_text)); - QNetworkRequest request(url); - return KIO::AccessManager::createRequest(op, request, outgoingData); - } - else if (req.url().path() == QStringLiteral("/")) - { - return new BufferNetworkReply(webview->homePageData().toLocal8Bit(), QStringLiteral("text/html"), this); - } - else - { - return new LocalFileNetworkReply(webview->homePageBaseDir() + req.url().path(), this); - } - } - - return KIO::AccessManager::createRequest(op, req, outgoingData); - } - - WebView* webview; - }; - - - ////////////////////////////////////////////////////// - WebView::WebView(kt::WebViewClient* client, ProxyHelper* proxy, QWidget* parentWidget) - : KWebView(parentWidget), client(client), m_proxy(proxy) + : QWebEngineView(parentWidget), client(client), m_proxy(proxy) { - page()->setNetworkAccessManager(new NetworkAccessManager(this)); - page()->setForwardUnsupportedContent(true); + MagnetUrlSchemeHandler *magneturlschemehandler = new MagnetUrlSchemeHandler(this); + page()->profile()->installUrlSchemeHandler("magnet", magneturlschemehandler); - connect(page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); + connect(magneturlschemehandler, &MagnetUrlSchemeHandler::magnetUrlDetected, this, &WebView::magnetUrlDetected); + connect(page()->profile(), &QWebEngineProfile::downloadRequested, this, &WebView::downloadRequested); } WebView::~WebView() @@ -126,8 +77,10 @@ { if (home_page_html.isEmpty()) loadHomePage(); - - load(QUrl(QStringLiteral("http://ktorrent.searchplugin/"))); + if(!home_page_html.isEmpty()){ + const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("ktorrent/search/home")); + setHtml(home_page_html, QUrl(file)); + } } QString WebView::homePageData() @@ -191,26 +144,37 @@ return QUrl(QStringLiteral("http://ktorrent.searchplugin/")); } - QWebView* WebView::createWindow(QWebPage::WebWindowType type) + QWebEngineView* WebView::createWindow(QWebEnginePage::WebWindowType type) { Q_UNUSED(type); return client->newTab(); } - void WebView::downloadRequested(const QNetworkRequest& req) + void WebView::downloadRequested(QWebEngineDownloadItem *download) { - QString filename = QFileInfo(req.url().path()).fileName(); + if(download->mimeType() == QStringLiteral("application/x-bittorrent") || download->url().path().endsWith(QLatin1String(".torrent"))) { + emit torrentFileDownloadRequested(download); + } else { + downloadFile(download); + } + } + + void WebView::downloadFile(QWebEngineDownloadItem * download) + { + QString filename = QFileInfo(download->url().path()).fileName(); QString path = QFileDialog::getExistingDirectory(this, i18n("Save %1 to"), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); - if (!path.isEmpty()) - KIO::copy(req.url(), QUrl(path)); + if (!path.isEmpty()){ + download->setPath(path); + download->accept(); + } } - void WebView::downloadResponse(QNetworkReply* reply) + void WebView::magnetUrlDetected(const QUrl &url) { - KWebPage* p = (KWebPage*)page(); - p->downloadResponse(reply); + client->magnetUrl(url); } } + diff --git a/plugins/syndication/CMakeLists.txt b/plugins/syndication/CMakeLists.txt --- a/plugins/syndication/CMakeLists.txt +++ b/plugins/syndication/CMakeLists.txt @@ -25,14 +25,14 @@ target_link_libraries( ktorrent_syndication ktcore + Qt5::WebEngineWidgets KF5::Torrent KF5::CoreAddons KF5::ConfigCore KF5::I18n KF5::KIOCore KF5::KIOWidgets KF5::Syndication - KF5::WebKit KF5::WidgetsAddons KF5::XmlGui ) diff --git a/plugins/syndication/feedwidget.h b/plugins/syndication/feedwidget.h --- a/plugins/syndication/feedwidget.h +++ b/plugins/syndication/feedwidget.h @@ -60,7 +60,6 @@ void updated(); void onFeedRenamed(Feed* f); void refreshRateChanged(int v); - void linkClicked(const QUrl& url); void resizeColumns(); Q_SIGNALS: diff --git a/plugins/syndication/feedwidget.cpp b/plugins/syndication/feedwidget.cpp --- a/plugins/syndication/feedwidget.cpp +++ b/plugins/syndication/feedwidget.cpp @@ -89,8 +89,6 @@ m_active_filters->clear(); m_item_view->setEnabled(false); - m_item_view->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); - connect(m_item_view, &KWebView::linkClicked, this, &FeedWidget::linkClicked); setEnabled(false); } @@ -253,11 +251,5 @@ updateCaption(this, f->displayName()); } - void FeedWidget::linkClicked(const QUrl& url) - { - Out(SYS_SYN | LOG_DEBUG) << "linkClicked " << url.toString() << endl; - new KRun(url, QApplication::activeWindow()); - } - } diff --git a/plugins/syndication/feedwidget.ui b/plugins/syndication/feedwidget.ui --- a/plugins/syndication/feedwidget.ui +++ b/plugins/syndication/feedwidget.ui @@ -184,22 +184,12 @@ - + - - QWebView - QWidget -
QtWebKit/QWebView
-
- - KWebView - QWebView -
kwebview.h
-
KSqueezedTextLabel QLabel