diff --git a/CMakeLists.txt b/CMakeLists.txt index a5792a19..e050f0f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,210 +1,210 @@ cmake_minimum_required(VERSION 2.8.12) project(KTORRENT) set (QT_MIN_VERSION "5.7.0") set (KF5_MIN_VERSION "5.15") find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) include(GenerateExportHeader) include(ECMInstallIcons) include(ECMAddAppIcon) include(ECMMarkAsTest) include(ECMMarkNonGuiExecutable) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core DBus Network Script Widgets ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Config ConfigWidgets CoreAddons Crash DBusAddons I18n IconThemes KIO Notifications NotifyConfig KCMUtils Parts Solid WidgetsAddons WindowSystem XmlGui OPTIONAL_COMPONENTS DocTools ) find_package(KF5Torrent 2.1 CONFIG REQUIRED) find_package(Boost REQUIRED) find_package(KF5TextWidgets ${KF5_REQUIRED_VERSION}) set_package_properties(KF5TextWidgets PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's IP Filter plugin" ) if(KF5TextWidgets_FOUND) set(HAVE_KF5TextWidgets 1) endif() find_package(KF5Archive ${KF5_REQUIRED_VERSION}) set_package_properties(KF5Archive PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's scripting plugin" ) if(KF5Archive_FOUND) set(HAVE_KF5Archive 1) endif() find_package(KF5ItemViews ${KF5_REQUIRED_VERSION}) set_package_properties(KF5ItemViews PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's scripting plugin" ) if(KF5ItemViews_FOUND) set(HAVE_KF5ItemViews 1) endif() find_package(KF5Kross ${KF5_REQUIRED_VERSION}) set_package_properties(KF5Kross PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's scripting plugin" ) if(KF5Kross_FOUND) set(HAVE_KF5Kross 1) endif() find_package(KF5Plotting ${KF5_REQUIRED_VERSION}) set_package_properties(KF5Plotting PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's statistics plugin" ) if(KF5Plotting_FOUND) set(HAVE_KF5Plotting 1) endif() find_package(KF5Syndication) set_package_properties(KF5Syndication PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's syndication plugin" ) if(KF5Syndication_FOUND) 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}) set_package_properties(KF5DNSSD PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's Zeroconf plugin" ) if(KF5DNSSD_FOUND) set(HAVE_KF5DNSSD 1) endif() find_package(KF5Completion ${KF5_REQUIRED_VERSION}) set_package_properties(KF5Completion PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's UPnP plugin" ) if(KF5Completion_FOUND) set(HAVE_KF5Completion 1) endif() find_package(LibKWorkspace CONFIG) set_package_properties(LibKWorkspace PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's shutdown plugin" ) if(LibKWorkspace_FOUND) set(HAVE_LibKWorkspace 1) endif() find_package(Taglib) if(TAGLIB_FOUND) set(HAVE_Taglib 1) endif() #find_package(Qt5 ${QT_MIN_VERSION} OPTIONAL_COMPONENTS Multimedia MultimediaWidgets) find_package(Phonon4Qt5) set_package_properties(Taglib PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's multimedia plugin" ) set_package_properties(Phonon4Qt5 PROPERTIES TYPE OPTIONAL PURPOSE "Required for KTorrent's multimedia plugin" ) # # checks for functions and stuff # include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckTypeSize) #XFS # according to http://www.cmake.org/pipermail/cmake/2008-June/022381.html kde_enable_exceptions() add_definitions( -DQT_USE_QSTRINGBUILDER -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_CAST_TO_BYTEARRAY # -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_FAST_OPERATOR_PLUS ) set (KTORRENT_DBUS_XML_DIR ${KTORRENT_SOURCE_DIR}/dbus_xml) set (KTORRENT_PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}/ktorrent) include_directories( ${Boost_INCLUDE_DIR} ) add_subdirectory(libktcore) add_subdirectory(plugins) add_subdirectory(ktorrent) add_subdirectory(ktupnptest) #add_subdirectory(plasma) add_subdirectory(ktmagnetdownloader) if (KF5DocTools_FOUND) add_subdirectory(doc) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/ktorrent/main.cpp b/ktorrent/main.cpp index 5c8fa51f..65f6e09d 100644 --- a/ktorrent/main.cpp +++ b/ktorrent/main.cpp @@ -1,258 +1,259 @@ /*************************************************************************** * Copyright (C) 2007 by Joris Guisson and Ivan Vasic * * joris.guisson@gmail.com * * ivasic@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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gui.h" #include "version.h" #include "ktversion.h" #include #include #include #ifndef Q_OS_WIN #include #endif using namespace bt; #ifndef Q_WS_WIN bool GrabPIDLock() { // open the PID file in the /tmp directory and attempt to lock it QString pid_file = QDir::tempPath() + QStringLiteral("/.ktorrent_kf5_%1.lock").arg(getuid()); int fd = open(QFile::encodeName(pid_file).data(), O_RDWR | O_CREAT, 0640); if (fd < 0) { fprintf(stderr, "Failed to open KT lock file %s : %s\n", pid_file.toLatin1().constData(), strerror(errno)); return false; } if (lockf(fd, F_TLOCK, 0) < 0) { fprintf(stderr, "Failed to get lock on %s : %s\n", pid_file.toLatin1().constData(), strerror(errno)); return false; } char str[20]; sprintf(str, "%d\n", getpid()); write(fd, str, strlen(str)); /* record pid to lockfile */ // leave file open, so nobody else can lock it until KT exists return true; } #endif int main(int argc, char** argv) { #ifndef Q_WS_WIN // ignore SIGPIPE and SIGXFSZ signal(SIGPIPE, SIG_IGN); signal(SIGXFSZ, SIG_IGN); #endif if (!bt::InitLibKTorrent()) { fprintf(stderr, "Failed to initialize libktorrent\n"); return -1; } 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); app.setWindowIcon(QIcon::fromTheme(QStringLiteral("ktorrent"))); KCrash::initialize(); QCommandLineParser parser; KAboutData about(QStringLiteral("ktorrent"), i18nc("@title", "KTorrent"), QStringLiteral(KT_VERSION_MACRO), i18n("Bittorrent client by KDE"), KAboutLicense::GPL, i18nc("@info:credit", "(C) 2005 - 2011 Joris Guisson and Ivan Vasic"), QString(), QStringLiteral("http://www.kde.org/applications/internet/ktorrent/")); about.setOrganizationDomain(QByteArray("kde.org")); about.setDesktopFileName(QStringLiteral("org.kde.ktorrent")); about.addAuthor(i18n("Joris Guisson"), QString(), QStringLiteral("joris.guisson@gmail.com"), QStringLiteral("http://kde.org/applications/internet/ktorrent")); about.addAuthor(i18n("Ivan Vasic"), QString(), QStringLiteral("ivasic@gmail.com")); about.addAuthor(i18n("Alan Jones"), i18n("BitFinder Plugin"), QStringLiteral("skyphyr@gmail.com")); about.addCredit(i18n("Diego Rosario Brogna"), i18n("Webinterface Plugin, global max share ratio patch"), QStringLiteral("dierbro@gmail.com")); about.addAuthor(i18n("Krzysztof Kundzicz"), i18n("Statistics Plugin"), QStringLiteral("athantor@gmail.com")); about.addAuthor(i18n("Christian Weilbach"), i18n("kio-magnet"), QStringLiteral("christian_weilbach@web.de")); about.addCredit(i18n("Mladen Babic"), i18n("Application icon and a couple of others"), QStringLiteral("bmladen@EUnet.yu")); about.addCredit(i18n("Adam Treat"), QString(), QStringLiteral("treat@kde.org")); about.addCredit(i18n("Danny Allen"), i18n("1.0 application icon"), QStringLiteral("danny@dannyallen.co.uk")); about.addCredit(i18n("Vincent Wagelaar"), QString(), QStringLiteral("vincent@ricardis.tudelft.nl")); about.addCredit(i18n("Knut Morten Johansson"), QString(), QStringLiteral("knut@johansson.com")); about.addCredit(i18n("Felix Berger"), i18n("ChunkBar's tooltip and IWFileTreeItem sorting"), QStringLiteral("bflat1@gmx.net")); about.addCredit(i18n("Andreas Kling"), QString(), QStringLiteral("kling@impul.se")); about.addCredit(i18n("Felipe Sateler"), QString(), QStringLiteral("fsateler@gmail.com")); about.addCredit(i18n("Maxmind"), i18n("Country locator for InfoWidget plugin. Flags are taken from http://flags.blogpotato.de/ so thanks to them too."), QString(), QStringLiteral("http://www.maxmind.com/")); about.addCredit(i18n("Adam Forsyth"), i18n("File prioritization and some other patches"), QStringLiteral("agforsyth@gmail.com")); about.addCredit(i18n("Thomas Bernard"), i18n("Miniupnp was used as an example for our own UPnP implementation"), QString(), QStringLiteral("http://miniupnp.free.fr/")); about.addCredit(i18n("Lesly Weyts"), i18n("Zeroconf enhancements")); about.addCredit(i18n("Kevin Andre"), i18n("Zeroconf enhancements"), QString(), QStringLiteral("http://users.edpnet.be/hyperquantum/")); about.addCredit(i18n("Dagur Valberg Johannsson"), i18n("Coldmilk webgui"), QStringLiteral("dagurval@pvv.ntnu.no")); about.addCredit(i18n("Alexander Dymo"), i18n("IDEAl code from KDevelop"), QStringLiteral("adymo@kdevelop.org")); about.addCredit(i18n("Scott Wolchok"), i18n("Conversion speed improvement in ipfilter plugin"), QStringLiteral("swolchok@umich.edu")); about.addCredit(i18n("Bryan Burns of Juniper Networks"), i18n("Discovered 2 security vulnerabilities (both are fixed)")); about.addCredit(i18n("Goten Xiao"), i18n("Patch to load silently with a save location")); about.addCredit(i18n("Rapsys"), i18n("Fixes in PHP code of webinterface")); about.addCredit(i18n("Athantor"), i18n("XFS specific disk preallocation")); about.addCredit(i18n("twisted_fall"), i18n("Patch to not show very low speeds"), QStringLiteral("twisted.fall@gmail.com")); about.addCredit(i18n("Lucke"), i18n("Patch to show potentially firewalled status")); about.addCredit(i18n("Modestas Vainius"), i18n("Several patches"), QStringLiteral("modestas@vainius.eu")); about.addCredit(i18n("Stefan Monov"), i18n("Patch to hide menu bar"), QStringLiteral("logixoul@gmail.com")); about.addCredit(i18n("The_Kernel"), i18n("Patch to change file priorities in the webgui"), QStringLiteral("kernja@cs.earlham.edu")); about.addCredit(i18n("Rafał Miłecki"), i18n("Several webgui patches"), QStringLiteral("zajec5@gmail.com")); about.addCredit(i18n("Ozzi"), i18n("Fixes for several warnings"), QStringLiteral("ossi@masiina.no-ip.info")); about.addCredit(i18n("Markus Brueffer"), i18n("Patch to fix free diskspace calculation on FreeBSD"), QStringLiteral("markus@brueffer.de")); about.addCredit(i18n("Lukas Appelhans"), i18n("Patch to fix a crash in ChunkDownloadView"), QStringLiteral("l.appelhans@gmx.de")); about.addCredit(i18n("Rickard Närström"), i18n("A couple of bugfixes"), QStringLiteral("rickard.narstrom@gmail.com")); about.addCredit(i18n("caruccio"), i18n("Patch to load torrents silently from the command line"), QStringLiteral("mateus@caruccio.com")); about.addCredit(i18n("Lee Olson"), i18n("New set of icons"), QStringLiteral("leetolson@gmail.com")); about.addCredit(i18n("Aaron J. Seigo"), i18n("Drag and drop support for Plasma applet"), QStringLiteral("aseigo@kde.org")); about.addCredit(i18n("Ian Higginson"), i18n("Patch to cleanup the plugin list"), QStringLiteral("xeriouxi@fastmail.fm")); about.addCredit(i18n("Amichai Rothman"), i18n("Patch to make the Plasma applet a popup applet"), QStringLiteral("amichai@amichais.net")); about.addCredit(i18n("Leo Trubach"), i18n("Patch to add support for IP ranges in IP filter dialog"), QStringLiteral("leotrubach@gmail.com")); about.addCredit(i18n("Andrei Barbu"), i18n("Feature which adds the date a torrent was added"), QStringLiteral("andrei@0xab.com")); about.addCredit(i18n("Jonas Lundqvist"), i18n("Feature to disable authentication in the webinterface"), QStringLiteral("jonas@gannon.se")); about.addCredit(i18n("Jaroslaw Swierczynski"), i18n("Exclusion patterns in the syndication plugin"), QStringLiteral("swiergot@gmail.com")); about.addCredit(i18n("Alexey Shildyakov "), i18n("Patch to rename single file torrents to the file inside"), QStringLiteral("ashl1future@gmail.com")); about.addCredit(i18n("Maarten De Meyer"), i18n("Fix for bug 305379"), QStringLiteral("de.meyer.maarten@gmail.com")); about.addCredit(i18n("Rex Dieter"), i18n("Add support for x-scheme-handler/magnet mimetype"), QStringLiteral("rdieter@gmail.com")); about.addCredit(i18n("Leszek Lesner"), i18n("Fix for bug 339584"), QStringLiteral("leszek.lesner@web.de")); about.addCredit(i18n("Andrius Štikonas"), i18n("KF5 porting"), QStringLiteral("andrius@stikonas.eu")); about.addCredit(i18n("Nick Shaforostoff"), i18n("KF5 porting"), QStringLiteral("shaforostoff@gmail.com")); KAboutData::setApplicationData(about); about.setupCommandLine(&parser); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), i18n("Enable logging to standard output"))); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("silent"), i18n( "Silently open torrent given on URL"))); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[URL]"), i18n( "Document to open" ))); parser.process(app); about.processCommandLine(&parser); const KDBusService dbusService(KDBusService::Unique); #if 0 //ndef Q_WS_WIN // need to grab lock after the fork call in start, otherwise this will not work properly if (!GrabPIDLock()) { fprintf(stderr, "ktorrent is already running !\n"); return 0; } #endif try { #ifndef Q_WS_WIN bt::SignalCatcher catcher; catcher.catchSignal(SIGINT); catcher.catchSignal(SIGTERM); QObject::connect(&catcher, &bt::SignalCatcher::triggered, &app, &QApplication::quit); #endif const bool logToStdout = parser.isSet(QStringLiteral("verbose")); bt::InitLog(kt::DataDir(kt::CreateIfNotExists) + QLatin1String("log"), true, true, logToStdout); kt::GUI widget; widget.show(); auto handleCmdLine = [&widget, &parser](const QStringList &arguments, const QString &workingDirectory) { if (!arguments.isEmpty()) { parser.parse(arguments); KStartupInfo::setNewStartupId(&widget, KStartupInfo::startupId()); KWindowSystem::forceActiveWindow(widget.winId()); } QString oldCurrent = QDir::currentPath(); if (!workingDirectory.isEmpty()) QDir::setCurrent(workingDirectory); bool silent = parser.isSet(QStringLiteral("silent")); auto loadMethod = silent ? &kt::GUI::loadSilently : &kt::GUI::load; const auto positionalArguments = parser.positionalArguments(); for (const QString& filePath : positionalArguments) { QUrl url = QFile::exists(filePath) ? QUrl::fromLocalFile(filePath) : QUrl(filePath); (widget.*loadMethod)(url); } if (!workingDirectory.isEmpty()) QDir::setCurrent(oldCurrent); }; QObject::connect(&dbusService, &KDBusService::activateRequested, handleCmdLine); handleCmdLine(QStringList(), QString()); app.setQuitOnLastWindowClosed(false); app.exec(); } catch (bt::Error& err) { Out(SYS_GEN | LOG_IMPORTANT) << "Uncaught exception: " << err.toString() << endl; } catch (std::exception& err) { Out(SYS_GEN | LOG_IMPORTANT) << "Uncaught exception: " << err.what() << endl; } catch (...) { Out(SYS_GEN | LOG_IMPORTANT) << "Uncaught unknown exception " << endl; } bt::Globals::cleanup(); return 0; } diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index affe1608..6bbd4fdb 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,47 +1,47 @@ MACRO (MACRO_KT_PLUGIN _option _name _dir) option(${_option} "Whether to build the ${_name} plugin or not" true) if (${_option}) message(STATUS "Building ${_name} plugin (-D${_option}=false to disable)") add_subdirectory(${_dir}) else (${_option}) message(STATUS "Not building ${_name} plugin (-D${_option}=true to enable)") endif (${_option}) ENDMACRO (MACRO_KT_PLUGIN) macro_kt_plugin(ENABLE_LOGVIEWER_PLUGIN logviewer logviewer) macro_kt_plugin(ENABLE_INFOWIDGET_PLUGIN infowidget infowidget) 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) macro_kt_plugin(ENABLE_SCANFOLDER_PLUGIN scanfolder scanfolder) if(HAVE_QT5_Test) set(HAVE_QT5_Test2 1) endif() if (HAVE_KF5TextWidgets) macro_kt_plugin(ENABLE_IPFILTER_PLUGIN ipfilter ipfilter) endif() if (HAVE_KF5Plotting) macro_kt_plugin(ENABLE_STATS_PLUGIN stats stats) endif() macro_kt_plugin(ENABLE_BWSCHEDULER_PLUGIN bwscheduler bwscheduler) if (HAVE_Taglib AND PHONON_FOUND_EXPERIMENTAL) #AND Qt5Multimedia_FOUND) macro_kt_plugin(ENABLE_MEDIAPLAYER_PLUGIN mediaplayer mediaplayer) endif() 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) if (HAVE_LibKWorkspace) macro_kt_plugin(ENABLE_SHUTDOWN_PLUGIN shutdown shutdown) endif() if (HAVE_KF5DNSSD) macro_kt_plugin(ENABLE_ZEROCONF_PLUGIN zeroconf zeroconf) endif() macro_kt_plugin(ENABLE_MAGNETGENERATOR_PLUGIN magnetgenerator magnetgenerator) diff --git a/plugins/search/CMakeLists.txt b/plugins/search/CMakeLists.txt index 8fabad6c..9f9b24e6 100644 --- a/plugins/search/CMakeLists.txt +++ b/plugins/search/CMakeLists.txt @@ -1,44 +1,42 @@ 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) add_library(ktorrent_search MODULE ${ktsearchplugin_SRC}) kcoreaddons_desktop_to_json(ktorrent_search ktorrent_search.desktop) target_link_libraries( ktorrent_search ktcore - Qt5::WebKitWidgets + Qt5::WebEngineWidgets KF5::Torrent KF5::CoreAddons KF5::Completion KF5::ConfigCore KF5::ConfigGui KF5::I18n KF5::IconThemes KF5::KIOCore KF5::KIOWidgets KF5::Notifications - KF5::WebKit KF5::WidgetsAddons KF5::XmlGui ) install(TARGETS ktorrent_search DESTINATION ${KTORRENT_PLUGIN_INSTALL_DIR} ) install(FILES ktorrent_searchui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/ktorrent ) add_subdirectory(opensearch) add_subdirectory(home) diff --git a/plugins/search/buffernetworkreply.cpp b/plugins/search/buffernetworkreply.cpp deleted file mode 100644 index b1a0adbb..00000000 --- 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/buffernetworkreply.h b/plugins/search/buffernetworkreply.h deleted file mode 100644 index 90040cb2..00000000 --- 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/localfilenetworkreply.cpp b/plugins/search/localfilenetworkreply.cpp deleted file mode 100644 index f9fb606b..00000000 --- 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/localfilenetworkreply.h b/plugins/search/localfilenetworkreply.h deleted file mode 100644 index 45435218..00000000 --- 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/magneturlschemehandler.cpp b/plugins/search/magneturlschemehandler.cpp new file mode 100644 index 00000000..ee33fdf4 --- /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/magneturlschemehandler.h b/plugins/search/magneturlschemehandler.h new file mode 100644 index 00000000..a38dc26b --- /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/searchwidget.cpp b/plugins/search/searchwidget.cpp index c80b2224..5f43d756 100644 --- a/plugins/search/searchwidget.cpp +++ b/plugins/search/searchwidget.cpp @@ -1,288 +1,252 @@ /*************************************************************************** * Copyright (C) 2005-2007 by Joris Guisson, Ivan Vasic * * joris.guisson@gmail.com * * ivasic@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 "searchwidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "searchplugin.h" #include "searchenginelist.h" #include "webview.h" #include "searchactivity.h" using namespace bt; 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); layout->setMargin(0); webview = new WebView(this, sp->getProxy()); 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); sbar->addAction(ac->action(QStringLiteral("search_tab_search"))); sbar->addWidget(new QLabel(i18n(" Engine: "))); // same i18n string as in SearchToolBar() search_engine = new KComboBox(sbar); search_engine->setModel(sp->getSearchEngineList()); sbar->addWidget(search_engine); connect(search_text, SIGNAL(returnPressed()), this, SLOT(search()));; layout->addWidget(sbar); layout->addWidget(webview); search_text->setClearButtonEnabled(true); 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); } SearchWidget::~SearchWidget() { if (prog) { sp->getGUI()->getStatusBar()->removeProgressBar(prog); prog = 0; } } void SearchWidget::iconChanged() { changeIcon(this, webview->icon()); } void SearchWidget::titleChanged(const QString& text) { if (!text.isEmpty()) { changeTitle(this, text); } else { // no empty tab titles allowed changeTitle(this, webview->url().toString()); } } QUrl SearchWidget::getCurrentUrl() const { return webview->url(); } QString SearchWidget::getSearchBarText() const { return search_text->text(); } int SearchWidget::getSearchBarEngine() const { return search_engine->currentIndex(); } void SearchWidget::restore(const QUrl &url, const QString& text, const QString& sb_text, int engine) { Q_UNUSED(text); if (url.scheme() == QLatin1String("home")) webview->home(); else webview->openUrl(url); search_text->setText(sb_text); search_engine->setCurrentIndex(engine); } void SearchWidget::search(const QString& text, int engine) { if (search_text->text() != text) search_text->setText(text); if (search_engine->currentIndex() != engine) search_engine->setCurrentIndex(engine); QUrl url = sp->getSearchEngineList()->search(engine, text); webview->openUrl(url); } QUrl SearchWidget::searchUrl(const QString& search_text) { return sp->getSearchEngineList()->search(search_engine->currentIndex(), search_text); } void SearchWidget::setSearchBarEngine(int engine) { search_engine->setCurrentIndex(engine); } void SearchWidget::loadProgress(int perc) { if (!prog) prog = sp->getGUI()->getStatusBar()->createProgressBar(); if (prog) prog->setValue(perc); } void SearchWidget::loadStarted() { if (!prog) { prog = sp->getGUI()->getStatusBar()->createProgressBar(); if (prog) prog->setValue(0); } } void SearchWidget::loadFinished(bool ok) { Q_UNUSED(ok); if (prog) { sp->getGUI()->getStatusBar()->removeProgressBar(prog); prog = 0; } } void SearchWidget::magnetUrl(const QUrl& magnet_url) { MagnetLinkLoadOptions options; options.silently = false; sp->getCore()->load(bt::MagnetLink(magnet_url.toString()), options); QString msg = i18n("Downloading:
%1", magnet_url.toString()); 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?"), i18n("Download Torrent"), KGuiItem(i18n("Download"), QStringLiteral("ktorrent")), KStandardGuiItem::save(), 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; } void SearchWidget::home() { webview->home(); } bool SearchWidget::backAvailable() const { - return webview->pageAction(QWebPage::Back)->isEnabled(); + return webview->pageAction(QWebEnginePage::Back)->isEnabled(); } } - diff --git a/plugins/search/searchwidget.h b/plugins/search/searchwidget.h index f74d7374..2a3d2c27 100644 --- a/plugins/search/searchwidget.h +++ b/plugins/search/searchwidget.h @@ -1,98 +1,96 @@ /*************************************************************************** * Copyright (C) 2005-2007 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 BTSEARCHWIDGET_H #define BTSEARCHWIDGET_H #include #include #include "webview.h" class QProgressBar; class QNetworkReply; class QMenu; class KComboBox; namespace kt { class SearchWidget; class SearchPlugin; /** @author Joris Guisson Widget which shows a KHTML window with the users search in it */ class SearchWidget : public QWidget, public WebViewClient { Q_OBJECT public: SearchWidget(SearchPlugin* sp); ~SearchWidget() override; QString getSearchText() const {return search_text->text();} QUrl getCurrentUrl() const; QString getSearchBarText() const; int getSearchBarEngine() const; void setSearchBarEngine(int engine); bool backAvailable() const; void restore(const QUrl &url, const QString& text, const QString& sb_text, int engine); signals: void enableBack(bool on); void openNewTab(const QUrl &url); void changeTitle(SearchWidget* w, const QString& title); void changeIcon(SearchWidget* w, const QIcon& icon); public slots: void search(const QString& text, int engine = 0); void home(); void search(); private slots: 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; }; } #endif diff --git a/plugins/search/webview.cpp b/plugins/search/webview.cpp index a5a8fdba..b643ba25 100644 --- a/plugins/search/webview.cpp +++ b/plugins/search/webview.cpp @@ -1,216 +1,180 @@ /*************************************************************************** * Copyright (C) 2009 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 "webview.h" #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() { } void WebView::handleMagnetUrl(const QUrl& magnet_url) { if (client) client->magnetUrl(magnet_url); } void WebView::openUrl(const QUrl &url) { if (url.host() == QStringLiteral("ktorrent.searchplugin")) home(); else load(url); } void WebView::home() { 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() { if (home_page_html.isEmpty()) loadHomePage(); return home_page_html; } void WebView::loadHomePage() { QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("ktorrent/search/home/home.html")); QFile fptr(file); if (fptr.open(QIODevice::ReadOnly)) { Out(SYS_SRC | LOG_DEBUG) << "Loading home page from " << file << endl; home_page_base_url = file.left(file.lastIndexOf(QLatin1Char('/')) + 1); home_page_html = QTextStream(&fptr).readAll(); // %1 home_page_html = home_page_html.arg(QStringLiteral("ktorrent_infopage.css")); // %2 if (qApp->layoutDirection() == Qt::RightToLeft) { QString link = QStringLiteral(""); link = link.arg(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kdeui/about/kde_infopage_rtl.css"))); home_page_html = home_page_html.arg(link); } else home_page_html = home_page_html.arg(QString()); KIconLoader* iconloader = KIconLoader::global(); int icon_size = iconloader->currentSize(KIconLoader::Desktop); home_page_html = home_page_html .arg(i18n("Home")) // %3 Title .arg(i18n("KTorrent")) // %4 .arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free.")) // %5 .arg(i18n("Search the web for torrents.")) // %6 .arg(i18n("Search")) // %7 .arg(QStringLiteral("search_text")) // %8 .arg(icon_size).arg(icon_size); // %9 and %10 } else { Out(SYS_SRC | LOG_IMPORTANT) << "Failed to load " << file << " : " << fptr.errorString() << endl; } } QUrl WebView::searchUrl(const QString& search_text) { if (client) return client->searchUrl(search_text); else // client is broken -> browse to home 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/search/webview.h b/plugins/search/webview.h index 894faeb1..451aa65c 100644 --- a/plugins/search/webview.h +++ b/plugins/search/webview.h @@ -1,115 +1,116 @@ /*************************************************************************** * Copyright (C) 2009 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_WEBVIEW_H #define KT_WEBVIEW_H -#include +#include #include #include #include "proxy_helper.h" namespace kt { class WebViewClient { public: virtual ~WebViewClient() {} /// Get a search url for a search text 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: WebView(WebViewClient* client, ProxyHelper* proxy, QWidget* parentWidget = 0); ~WebView() override; /** * Open a url * @param url The QUrl */ void openUrl(const QUrl &url); /** * Show the home page */ void home(); /** * Get a search url for a search text * @param search_text The text to search * @return A QUrl to load */ 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(); /// Get the home page base directory QString homePageBaseDir() const {return home_page_base_url;} /// Handle magnet url void handleMagnetUrl(const QUrl& magnet_url); /// 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; WebViewClient* client; QUrl clicked_url; QUrl image_url; ProxyHelper* m_proxy; }; } #endif // KT_HOMEPAGE_H diff --git a/plugins/syndication/CMakeLists.txt b/plugins/syndication/CMakeLists.txt index 657f25f3..925d66fe 100644 --- a/plugins/syndication/CMakeLists.txt +++ b/plugins/syndication/CMakeLists.txt @@ -1,42 +1,42 @@ set(ktsyndicationplugin_SRC syndicationplugin.cpp syndicationactivity.cpp syndicationtab.cpp feedlistview.cpp feedlist.cpp feedlistdelegate.cpp feedwidget.cpp feedwidgetmodel.cpp feedretriever.cpp ktfeed.cpp linkdownloader.cpp managefiltersdlg.cpp filter.cpp filterlist.cpp filterlistview.cpp filterlistmodel.cpp filtereditor.cpp) ki18n_wrap_ui(ktsyndicationplugin_SRC feedwidget.ui managefiltersdlg.ui filtereditor.ui) add_library(ktorrent_syndication MODULE ${ktsyndicationplugin_SRC}) kcoreaddons_desktop_to_json(ktorrent_syndication ktorrent_syndication.desktop) 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 ) install(TARGETS ktorrent_syndication DESTINATION ${KTORRENT_PLUGIN_INSTALL_DIR} ) install(FILES ktorrent_syndicationui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/ktorrent ) add_subdirectory(icons) diff --git a/plugins/syndication/feedwidget.cpp b/plugins/syndication/feedwidget.cpp index 56ec3b86..ba75a2b2 100644 --- a/plugins/syndication/feedwidget.cpp +++ b/plugins/syndication/feedwidget.cpp @@ -1,263 +1,255 @@ /*************************************************************************** * Copyright (C) 2008 by Joris Guisson and Ivan Vasic * * joris.guisson@gmail.com * * ivasic@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 #include #include #include #include #include #include #include #include "ktfeed.h" #include "feedwidget.h" #include "feedwidgetmodel.h" #include "managefiltersdlg.h" #include "filterlist.h" #include "syndicationplugin.h" using namespace bt; namespace kt { QString FeedWidget::item_template = i18n("\ \ \
\ Title: %1
\ Date: %2
\
\

%3

\ \ \ "); FeedWidget::FeedWidget(FilterList* filters, SyndicationActivity* act, QWidget* parent) : QWidget(parent), feed(nullptr), filters(filters), act(act) { setupUi(this); m_splitter->setStretchFactor(0, 3); m_splitter->setStretchFactor(1, 1); connect(m_download, &QPushButton::clicked, this, &FeedWidget::downloadClicked); connect(m_refresh, &QPushButton::clicked, this, &FeedWidget::refreshClicked); connect(m_filters, &QPushButton::clicked, this, &FeedWidget::filtersClicked); connect(m_refresh_rate, static_cast(&QSpinBox::valueChanged), this, &FeedWidget::refreshRateChanged); connect(m_cookies, &QPushButton::clicked, this, &FeedWidget::cookiesClicked); m_refresh->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); m_filters->setIcon(QIcon::fromTheme(QStringLiteral("view-filter"))); m_cookies->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies"))); m_download->setIcon(QIcon::fromTheme(QStringLiteral("ktorrent"))); model = new FeedWidgetModel(this); m_item_list->setModel(model); m_item_list->setAlternatingRowColors(true); m_item_list->setSelectionMode(QAbstractItemView::ExtendedSelection); QHeaderView* hv = m_item_list->header(); hv->setSectionResizeMode(QHeaderView::Interactive); connect(m_item_list->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FeedWidget::selectionChanged); m_download->setEnabled(false); m_url->clear(); m_refresh_rate->clear(); 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); } FeedWidget::~FeedWidget() { } void FeedWidget::loadState(KConfigGroup& g) { m_splitter->restoreState(g.readEntry("feed_widget_splitter", QByteArray())); QHeaderView* hv = m_item_list->header(); QByteArray state = g.readEntry("feed_widget_list_header", QByteArray()); if (!state.isEmpty()) hv->restoreState(state); else QTimer::singleShot(3000, this, &FeedWidget::resizeColumns); } void FeedWidget::saveState(KConfigGroup& g) { g.writeEntry("feed_widget_splitter", m_splitter->saveState()); QHeaderView* hv = m_item_list->header(); g.writeEntry("feed_widget_list_header", hv->saveState()); } void FeedWidget::resizeColumns() { m_item_list->header()->resizeSections(QHeaderView::ResizeToContents); } void FeedWidget::setFeed(Feed* f) { if (feed) { disconnect(feed, &Feed::updated, this, &FeedWidget::updated); disconnect(feed, &Feed::feedRenamed, this, &FeedWidget::onFeedRenamed); feed = 0; } feed = f; setEnabled(feed != 0); model->setCurrentFeed(f); if (feed) { connect(feed, &Feed::updated, this, &FeedWidget::updated); connect(feed, &Feed::feedRenamed, this, &FeedWidget::onFeedRenamed); m_url->setText(QStringLiteral("%1").arg(feed->feedUrl().toDisplayString())); m_refresh_rate->setValue(feed->refreshRate()); updated(); selectionChanged(m_item_list->selectionModel()->selection(), QItemSelection()); } } void FeedWidget::downloadClicked() { if (!feed) return; QModelIndexList sel = m_item_list->selectionModel()->selectedRows(); foreach (const QModelIndex& idx, sel) { Syndication::ItemPtr ptr = model->itemForIndex(idx); if (ptr) feed->downloadItem(ptr, QString(), QString(), QString(), false); } } void FeedWidget::refreshClicked() { if (feed) feed->refresh(); } void FeedWidget::refreshRateChanged(int v) { if (v > 0 && feed) feed->setRefreshRate(v); } void FeedWidget::filtersClicked() { if (!feed) return; ManageFiltersDlg dlg(feed, filters, act, this); if (dlg.exec() == QDialog::Accepted) { feed->save(); feed->runFilters(); } } void FeedWidget::cookiesClicked() { if (!feed) return; bool ok = false; QString cookie = feed->authenticationCookie(); QString nc = QInputDialog::getText(0, i18n("Authentication Cookie"), i18n("Enter the new authentication cookie"), QLineEdit::Normal, cookie, &ok); if (ok) { feed->setAuthenticationCookie(nc); feed->save(); } } void FeedWidget::selectionChanged(const QItemSelection& sel, const QItemSelection& prev) { Q_UNUSED(prev); m_download->setEnabled(sel.count() > 0); m_item_view->setEnabled(sel.count() > 0); if (sel.count() > 0 && feed) { Syndication::ItemPtr item = model->itemForIndex(m_item_list->selectionModel()->selectedRows().front()); if (item) { m_item_view->setHtml(item_template .arg(item->title()) .arg(QLocale().toString(QDateTime::fromTime_t(item->datePublished()), QLocale::ShortFormat)) .arg(item->description()) .arg(QApplication::palette().text().color().name(QColor::NameFormat::HexRgb)) , QUrl(feed->feedData()->link())); } } } void FeedWidget::updated() { if (!feed) return; switch (feed->feedStatus()) { case Feed::OK: m_status->setText(i18n("OK")); break; case Feed::UNLOADED: m_status->setText(i18n("Not Loaded")); break; case Feed::FAILED_TO_DOWNLOAD: m_status->setText(i18n("Download Failed: %1", feed->errorString())); break; case Feed::DOWNLOADING: m_status->setText(i18n("Downloading")); break; } updateCaption(this, feed->title()); m_active_filters->setText(QStringLiteral("") + feed->filterNamesString() + QStringLiteral("")); } void FeedWidget::onFeedRenamed(kt::Feed* f) { 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.h b/plugins/syndication/feedwidget.h index 99498cd9..26cac6eb 100644 --- a/plugins/syndication/feedwidget.h +++ b/plugins/syndication/feedwidget.h @@ -1,80 +1,79 @@ /*************************************************************************** * Copyright (C) 2008 by Joris Guisson and Ivan Vasic * * joris.guisson@gmail.com * * ivasic@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 KTFEEDWIDGET_H #define KTFEEDWIDGET_H #include #include #include "ui_feedwidget.h" namespace kt { class Feed; class FeedWidgetModel; class FilterList; class SyndicationActivity; /** Displays a Feed */ class FeedWidget : public QWidget, public Ui_FeedWidget { Q_OBJECT public: FeedWidget(FilterList* filters, SyndicationActivity* act, QWidget* parent); ~FeedWidget(); /// Set the Feed to show, can be 0 void setFeed(Feed* feed); Feed* getFeed() {return feed;} void loadState(KConfigGroup& g); void saveState(KConfigGroup& g); void downloadClicked(); void refreshClicked(); void filtersClicked(); void cookiesClicked(); void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); void updated(); void onFeedRenamed(Feed* f); void refreshRateChanged(int v); - void linkClicked(const QUrl& url); void resizeColumns(); Q_SIGNALS: void updateCaption(QWidget* w, const QString& text); private: Feed* feed; FeedWidgetModel* model; FilterList* filters; SyndicationActivity* act; static QString item_template; }; } #endif diff --git a/plugins/syndication/feedwidget.ui b/plugins/syndication/feedwidget.ui index 72b9df6b..2c104e6c 100644 --- a/plugins/syndication/feedwidget.ui +++ b/plugins/syndication/feedwidget.ui @@ -1,211 +1,201 @@ FeedWidget 0 0 867 511 Qt::Vertical 0 0 URL: 0 0 KSqueezedTextLabel Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse 0 0 Status: 0 0 KSqueezedTextLabel Active Filters: false true false true Download Refresh Refresh every: Time between automatic refreshes of the feed. minutes 1 10000 60 Qt::Vertical 20 40 Cookies Filters - + - - QWebView - QWidget -
QtWebKit/QWebView
-
- - KWebView - QWebView -
kwebview.h
-
KSqueezedTextLabel QLabel
ksqueezedtextlabel.h