Commit 0bfdd89a authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Import kget plugin

With the KParts method being deprecated, we need to import the plugin in Konqueror.
Because this plugin only onteracts with kget using DBus, we don't have any dependency issues.

To avoid conflicts for package managers, the installed "konqueror_" prefix is added to the installed plugin.
The datafiles have been renamed from "*plug_in*" to "*plugin*", which is what most people would expect anyways.

Task: https://phabricator.kde.org/T13806
parent 9b7739ac
......@@ -9,6 +9,7 @@ add_subdirectory( dirfilter )
add_subdirectory( uachanger )
add_subdirectory( babelfish )
add_subdirectory( webarchiver )
add_subdirectory( kget )
if (Qt5TextToSpeech_FOUND)
add_subdirectory(ttsplugin)
......
add_library(konqueror_kget_browser_integration MODULE)
set(kget_browser_integration_dbus_SRCS)
qt_add_dbus_interface(kget_browser_integration_dbus_SRCS org.kde.kget.main.xml kget_interface )
target_sources(konqueror_kget_browser_integration PRIVATE
kget_plugin.cpp
${kget_browser_integration_dbus_SRCS}
)
target_link_libraries(konqueror_kget_browser_integration KF5::CoreAddons KF5::I18n KF5::IconThemes KF5Konq)
install(TARGETS konqueror_kget_browser_integration DESTINATION ${KDE_INSTALL_PLUGINDIR})
########### install files ###############
install(FILES kget_plugin.rc kget_plugin.desktop DESTINATION ${KDE_INSTALL_DATADIR}/khtml/kpartplugins)
install(FILES kget_plugin.rc kget_plugin.desktop DESTINATION ${KDE_INSTALL_DATADIR}/dolphinpart/kpartplugins)
install(FILES kget_plugin.rc kget_plugin.desktop DESTINATION ${KDE_INSTALL_DATADIR}/kwebkitpart/kpartplugins)
#! /bin/sh
$EXTRACTRC *.rc >> rc.cpp || exit 11
$XGETTEXT *.cpp -o $podir/kgetplugin.pot
rm -f rc.cpp
/* This file is part of the KDE project
Copyright (C) 2002 Patrick Charbonnier <pch@valleeurpe.net>
Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
Copyright (C) 2010 Dawit Alemayehu <adawit@kde.org>
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
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.
*/
#include "kget_plugin.h"
#include "kget_interface.h"
#include "konq_kpart_plugin.h"
#include <QDBusConnection>
#include <QIcon>
#include <QMenu>
#include <KActionCollection>
#include <KActionMenu>
#include <KDialogJobUiDelegate>
#include <KFileItem>
#include <KIO/CommandLauncherJob>
#include <KIconLoader>
#include <KLocalizedString>
#include <KMessageBox>
#include <KParts/FileInfoExtension>
#include <KParts/HtmlExtension>
#include <KParts/Part>
#include <KParts/PartManager>
#include <KParts/ReadOnlyPart>
#include <KParts/SelectorInterface>
#include <KPluginFactory>
#include <KProtocolInfo>
#include <KToggleAction>
#include <KToolInvocation>
#include <konq_kpart_plugin.h>
#define QL1S(x) QLatin1String(x)
K_PLUGIN_FACTORY(KGetPluginFactory, registerPlugin<KGetPlugin>();)
static QWidget *partWidget(QObject *obj)
{
auto *part = qobject_cast<KParts::ReadOnlyPart *>(obj);
return part ? part->widget() : nullptr;
}
KGetPlugin::KGetPlugin(QObject *parent, const QVariantList &)
: KonqParts::Plugin(parent)
{
auto *menu = new KActionMenu(QIcon::fromTheme("kget"), i18n("Download Manager"), actionCollection());
actionCollection()->addAction("kget_menu", menu);
menu->setDelayed(false);
connect(menu->menu(), &QMenu::aboutToShow, this, &KGetPlugin::showPopup);
m_dropTargetAction = new KToggleAction(i18n("Show Drop Target"), actionCollection());
connect(m_dropTargetAction, &QAction::triggered, this, &KGetPlugin::slotShowDrop);
actionCollection()->addAction(QL1S("show_drop"), m_dropTargetAction);
menu->addAction(m_dropTargetAction);
QAction *showLinksAction = actionCollection()->addAction(QL1S("show_links"));
showLinksAction->setText(i18n("List All Links"));
connect(showLinksAction, &QAction::triggered, this, &KGetPlugin::slotShowLinks);
menu->addAction(showLinksAction);
QAction *showSelectedLinksAction = actionCollection()->addAction(QL1S("show_selected_links"));
showSelectedLinksAction->setText(i18n("List Selected Links"));
connect(showSelectedLinksAction, &QAction::triggered, this, &KGetPlugin::slotShowSelectedLinks);
menu->addAction(showSelectedLinksAction);
// Hide this plugin if the parent part does not support either
// The FileInfo or Html extensions...
if (!KParts::HtmlExtension::childObject(parent) && !KParts::FileInfoExtension::childObject(parent))
menu->setVisible(false);
}
KGetPlugin::~KGetPlugin()
{
}
static bool hasDropTarget()
{
bool found = false;
if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) {
OrgKdeKgetMainInterface kgetInterface("org.kde.kget", "/KGet", QDBusConnection::sessionBus());
QDBusReply<bool> reply = kgetInterface.dropTargetVisible();
if (reply.isValid()) {
found = reply.value();
}
}
return found;
}
void KGetPlugin::showPopup()
{
// Check for HtmlExtension support...
KParts::HtmlExtension *htmlExtn = KParts::HtmlExtension::childObject(parent());
if (htmlExtn) {
KParts::SelectorInterface *selector = qobject_cast<KParts::SelectorInterface *>(htmlExtn);
if (selector) {
m_dropTargetAction->setChecked(hasDropTarget());
const KParts::SelectorInterface::QueryMethods methods = selector->supportedQueryMethods();
bool enable = (methods & KParts::SelectorInterface::EntireContent);
actionCollection()->action(QL1S("show_links"))->setEnabled(enable);
enable = (htmlExtn->hasSelection() && (methods & KParts::SelectorInterface::SelectedContent));
actionCollection()->action(QL1S("show_selected_links"))->setEnabled(enable);
enable = (actionCollection()->action(QL1S("show_links"))->isEnabled() || actionCollection()->action(QL1S("show_selected_links"))->isEnabled());
actionCollection()->action(QL1S("show_drop"))->setEnabled(enable);
return;
}
}
// Check for FileInfoExtension support...
KParts::FileInfoExtension *fileinfoExtn = KParts::FileInfoExtension::childObject(parent());
if (fileinfoExtn) {
m_dropTargetAction->setChecked(hasDropTarget());
const KParts::FileInfoExtension::QueryModes modes = fileinfoExtn->supportedQueryModes();
bool enable = (modes & KParts::FileInfoExtension::AllItems);
actionCollection()->action(QL1S("show_links"))->setEnabled(enable);
enable = (fileinfoExtn->hasSelection() && (modes & KParts::FileInfoExtension::SelectedItems));
actionCollection()->action(QL1S("show_selected_links"))->setEnabled(enable);
enable = (actionCollection()->action(QL1S("show_links"))->isEnabled() || actionCollection()->action(QL1S("show_selected_links"))->isEnabled());
actionCollection()->action(QL1S("show_drop"))->setEnabled(enable);
return;
}
actionCollection()->action(QL1S("show_selected_links"))->setEnabled(false);
actionCollection()->action(QL1S("show_links"))->setEnabled(false);
actionCollection()->action(QL1S("show_drop"))->setEnabled(false);
if (m_dropTargetAction->isChecked())
m_dropTargetAction->setChecked(false);
}
void KGetPlugin::slotShowDrop()
{
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) {
const QString command = QStringLiteral("kget --showDropTarget --hideMainWindow");
auto *job = new KIO::CommandLauncherJob(command);
job->setDesktopName(QStringLiteral("org.kde.kget"));
job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, partWidget(parent())));
job->start();
} else {
OrgKdeKgetMainInterface kgetInterface("org.kde.kget", "/KGet", QDBusConnection::sessionBus());
kgetInterface.setDropTargetVisible(m_dropTargetAction->isChecked());
}
}
void KGetPlugin::slotShowLinks()
{
getLinks(false);
}
void KGetPlugin::slotShowSelectedLinks()
{
getLinks(true);
}
void KGetPlugin::slotImportLinks()
{
if (m_linkList.isEmpty()) {
KMessageBox::sorry(partWidget(parent()), i18n("No downloadable links were found."), i18n("No Links"));
return;
}
// Remove any duplicates links from the list...
m_linkList.removeDuplicates();
OrgKdeKgetMainInterface kgetInterface("org.kde.kget", "/KGet", QDBusConnection::sessionBus());
kgetInterface.importLinks(m_linkList);
}
void KGetPlugin::getLinks(bool selectedOnly)
{
KParts::HtmlExtension *htmlExtn = KParts::HtmlExtension::childObject(parent());
if (htmlExtn) {
KParts::SelectorInterface *selector = qobject_cast<KParts::SelectorInterface *>(htmlExtn);
if (selector) {
m_linkList.clear();
const QUrl baseUrl = htmlExtn->baseUrl();
const QString query = QL1S("a[href], img[src], audio[src], video[src], embed[src], object[data]");
const KParts::SelectorInterface::QueryMethod method =
(selectedOnly ? KParts::SelectorInterface::SelectedContent : KParts::SelectorInterface::EntireContent);
const QList<KParts::SelectorInterface::Element> elements = selector->querySelectorAll(query, method);
QString attr;
Q_FOREACH (const KParts::SelectorInterface::Element &element, elements) {
if (element.hasAttribute(QL1S("href")))
attr = QL1S("href");
else if (element.hasAttribute(QL1S("src")))
attr = QL1S("src");
else if (element.hasAttribute(QL1S("data")))
attr = QL1S("data");
const QUrl resolvedUrl(baseUrl.resolved(QUrl(element.attribute(attr))));
// Only select valid and non-local links for download...
if (resolvedUrl.isValid() && !resolvedUrl.isLocalFile() && !resolvedUrl.host().isEmpty()) {
if (element.hasAttribute(QL1S("type")))
m_linkList << QString(QL1S("url ") + resolvedUrl.url() + QL1S(" type ") + element.attribute(QL1S("type")));
else
m_linkList << resolvedUrl.url();
}
}
}
slotImportLinks();
}
KParts::FileInfoExtension *fileinfoExtn = KParts::FileInfoExtension::childObject(parent());
if (fileinfoExtn) {
m_linkList.clear();
const KParts::FileInfoExtension::QueryMode mode = (selectedOnly ? KParts::FileInfoExtension::SelectedItems : KParts::FileInfoExtension::AllItems);
const KFileItemList items = fileinfoExtn->queryFor(mode);
Q_FOREACH (const KFileItem &item, items) {
const QUrl url = item.url();
// Only select valid and non local links for download...
if (item.isReadable() && item.isFile() && !item.isLocalFile() && !url.host().isEmpty()) {
if (item.mimetype().isEmpty())
m_linkList << url.url();
else
m_linkList << QString(QL1S("url ") + url.url() + QL1S(" type ") + item.mimetype());
}
}
slotImportLinks();
}
}
#include "kget_plugin.moc"
[Desktop Entry]
Encoding=UTF-8
Icon=kget
X-KDE-Library=konqueror_kget_browser_integration
X-KDE-PluginInfo-Author=KGet Maintainers
X-KDE-PluginInfo-Email=kget@kde.org
X-KDE-PluginInfo-Name=konqueror_kget_browser_integration
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Category=Tools
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Name=Download Manager
Name[bg]=Изтегляне на файлове
Name[bs]=Upravnik preuzimanjima datoteka
Name[ca]=Gestor de baixades
Name[ca@valencia]=Gestor de baixades
Name[cs]=Správce stahování
Name[da]=Downloadhåndtering
Name[de]=Download-Verwaltung
Name[el]=Διαχειριστής λήψεων
Name[en_GB]=Download Manager
Name[eo]=Elŝuta administrilo
Name[es]=Gestor de descargas
Name[et]=Allalaadimiste haldur
Name[eu]=Deskarga-kudeatzailea
Name[fi]=Tiedostonlataaja
Name[fr]=Gestionnaire de téléchargements
Name[ga]=Bainisteoir Íosluchtaithe
Name[gl]=Xestor de descargas
Name[hu]=Letöltéskezelő
Name[ia]=Gerente de discargamento
Name[id]=Unduh Manager
Name[it]=Gestore degli scaricamenti
Name[ja]=ダウンロードマネージャ
Name[kk]=Жүктеп алу менеджері
Name[km]=កម្មវិធី​គ្រប់គ្រង​ការ​ទាញយក
Name[ko]=다운로드 관리자
Name[lt]=Siuntimų valdymas
Name[mr]=डाउनलोड व्यवस्थापक
Name[nb]=Nedlastingsbehandler
Name[nds]=Daalladenpleger
Name[nl]=Downloadbeheerder
Name[nn]=Nedlastingshandsamar
Name[pa]=ਡਾਊਨਲੋਡ ਮੈਨੇਜਰ
Name[pl]=Zarządzanie pobieraniem
Name[pt]=Gestor de Transferências
Name[pt_BR]=Gerenciador de downloads
Name[ro]=Administrator descărcări
Name[ru]=Диспетчер загрузок
Name[si]=බාගත කළමනාකරු
Name[sk]=Správca preberaní
Name[sl]=Upravljalnik prejemov
Name[sr]=Менаџер преузимања
Name[sr@ijekavian]=Менаџер преузимања
Name[sr@ijekavianlatin]=Menadžer preuzimanja
Name[sr@latin]=Menadžer preuzimanja
Name[sv]=Nerladdningshanterare
Name[tr]=İndirme Yöneticisi
Name[ug]=چۈشۈرۈش باشقۇرغۇسى
Name[uk]=Керування отриманнями
Name[x-test]=xxDownload Managerxx
Name[zh_CN]=下载管理器
Name[zh_TW]=下載管理員
Comment=A versatile and easy to use file download manager
Comment[bg]=Удобна и лесна за използване програма за изтегляния
Comment[bs]=Svestran i jednostavan za korištenje upravljač preuzimanjem datoteka
Comment[ca]=Un gestor de baixades de fitxers versàtil i fàcil d'emprar
Comment[ca@valencia]=Un gestor de baixades de fitxers versàtil i fàcil d'emprar
Comment[cs]=Všestranný a jednoduše použitelný správce souborů
Comment[da]=En alsidig og brugervenlig downloadhåndtering
Comment[de]=Ein vielseitiges und einfach zu benutzendes Download-Verwaltungsprogramm
Comment[el]=Ένας ευέλικτος και εύκολος στη χρήση διαχειριστής λήψεων αρχείων
Comment[en_GB]=A versatile and easy to use file download manager
Comment[es]=Una manera sencilla y versátil de usar el gestor de descarga de archivos
Comment[et]=Tubli ja lihtne failide allalaadimise haldur
Comment[eu]=Erabilera askotako eta errazeko fitxategiak deskargatzeko kudeatzailea
Comment[fi]=Monipuolinen ja helppokäyttöinen latauksenhallinta
Comment[fr]=Un gestionnaire de téléchargements facile et polyvalent
Comment[gl]=Un xestor de descargas de ficheiros versátil e fácil de usar.
Comment[hu]=Egy sokoldalú és egyszerűen használható letöltéskezelő
Comment[ia]=Un gestor de discargamento versatile e facile de usar se
Comment[id]=Sebuah unduh manager file yang serbaguna dan mudah digunakan
Comment[is]=Fjölhæfur en einfaldur skráaniðurhalsstjóri
Comment[it]=Un gestore di scaricamenti versatile e facile da usare
Comment[kk]=Әмбебап және ыңғайлы жүктеп алу менеджері
Comment[km]=អាច​ផ្លាស់ប្ដូរ និង​ងាយស្រួល​ប្រើ​កម្មវិធី​គ្រប់គ្រង​ការ​ទាញយក
Comment[ko]=다운로드 관리자
Comment[lt]=Lanksti ir paprasta failų atsiuntimo tvarkyklė
Comment[mr]=एक बहुमुखी व वापरायला सोपा फाईल डाउनलोड व्यवस्थापक
Comment[nb]=En fleksibel nedlastingsbehandler som er lett å bruke
Comment[nds]=En ansleegsch un eenfach to bruken Daalladenpleger
Comment[nl]=Een veelzijdige en gemakkelijk te gebruiken downloadbeheerder
Comment[nn]=Ein allsidig og brukarvenleg nedlastingshandsamar
Comment[pl]=Wszechstronny i łatwy w użyciu program zarządzający pobieraniem plików
Comment[pt]=Um gestor de transferências de ficheiros simples e versátil de usar
Comment[pt_BR]=Um gerenciador de downloads de arquivos simples e fácil de usar
Comment[ru]=Гибкий и простой в использовании диспетчер файлов
Comment[si]=භාවිතයට පහසු හුරුබුහුටි ගොනු බාගත කළමනාකරු
Comment[sk]=Univerzálny správca preberaní s ľahkým používaním
Comment[sl]=Vsestranski in preprost upravljalnik prejemov
Comment[sr]=Свестран и предусретљив менаџер преузимања фајлова
Comment[sr@ijekavian]=Свестран и предусретљив менаџер преузимања фајлова
Comment[sr@ijekavianlatin]=Svestran i predusretljiv menadžer preuzimanja fajlova
Comment[sr@latin]=Svestran i predusretljiv menadžer preuzimanja fajlova
Comment[sv]=En mångsidig och lättanvänd nerladdningshanterare av filer
Comment[tr]=Çok yetenekli ve kolay kullanımlı bir indirme yöneticisi
Comment[ug]=كۆپ ئىقتىدارلىق، ئىشلىتىش قۇلاي ھۆججەت چۈشۈرۈشنى باشقۇرغۇچ
Comment[uk]=Гнучка і проста у користуванні програма для керування отриманнями
Comment[x-test]=xxA versatile and easy to use file download managerxx
Comment[zh_CN]=简单易用的多功能文件下载管理器
Comment[zh_TW]=一個多功能且容易使用的檔案下載管理員
X-KDE-ParentApp=konqueror
/* This file is part of the KDE project
Copyright (C) 2002 Patrick Charbonnier <pch@valleeurpe.net>
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
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.
*/
#ifndef KGETPLUGIN_H
#define KGETPLUGIN_H
#include <konq_kpart_plugin.h>
#include <QPointer>
class KToggleAction;
class KGetPlugin : public KonqParts::Plugin
{
Q_OBJECT
public:
KGetPlugin(QObject *parent, const QVariantList &);
~KGetPlugin() override;
private Q_SLOTS:
void slotShowDrop();
void slotShowLinks();
void slotShowSelectedLinks();
void slotImportLinks();
void showPopup();
private:
void getLinks(bool selectedOnly = false);
QStringList m_linkList;
KToggleAction *m_dropTargetAction;
};
#endif
<!DOCTYPE kpartplugin>
<kpartplugin library="konqueror_kget_browser_integration" name="konqueror_kget_browser_integration" version="5">
<MenuBar>
<Menu name="tools"><text>&amp;Tools</text>
<Action name="kget_menu"/>
</Menu>
</MenuBar>
<ToolBar name="mainToolBar">
<Action name="kget_menu"/>
</ToolBar>
</kpartplugin>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.kget.main">
<method name="dropTargetVisible">
<arg type="b" direction="out"/>
</method>
<method name="setDropTargetVisible">
<arg name="visible" type="b" direction="in"/>
</method>
<method name="offlineMode">
<arg type="b" direction="out"/>
</method>
<method name="setOfflineMode">
<arg type="b" direction="in"/>
</method>
<method name="addTransfer">
<arg name="src" type="s" direction="in"/>
<arg name="destDir" type="s" direction="in"/>
<arg name="start" type="b" direction="in"/>
<arg type="as" direction="out"/>
</method>
<method name="delTransfer">
<arg name="dbusObjectPath" type="s" direction="in"/>
<arg type="b" direction="out"/>
</method>
<method name="showNewTransferDialog">
<arg name="urls" type="as" direction="in"/>
</method>
<method name="transfers">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
<arg name="out" type="a{ss}" direction="out"/>
</method>
<method name="transfersSpeed">
<arg type="i" direction="out"/>
</method>
<method name="importLinks">
<arg name="links" type="as" direction="in" />
</method>
<method name="isSupported">
<arg type="b" direction="out"/>
<arg name="url" type="s" direction="in"/>
</method>
<signal name="transfersAdded">
<arg name="urls" type="as" direction="out"/>
<arg name="dBusObjectPaths" type="as" direction="out"/>
</signal>
<signal name="transfersRemoved">
<arg name="urls" type="as" direction="out"/>
<arg name="dBusObjectPaths" type="as" direction="out"/>
</signal>
</interface>
</node>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment