summaryrefslogtreecommitdiffstats
path: root/kget/kget_plug_in
diff options
context:
space:
mode:
Diffstat (limited to 'kget/kget_plug_in')
-rw-r--r--kget/kget_plug_in/Makefile.am13
-rw-r--r--kget/kget_plug_in/cr22-action-khtml_kget.pngbin0 -> 978 bytes
-rw-r--r--kget/kget_plug_in/kget_linkview.cpp150
-rw-r--r--kget/kget_plug_in/kget_linkview.h54
-rw-r--r--kget/kget_plug_in/kget_plug_in.cpp189
-rw-r--r--kget/kget_plug_in/kget_plug_in.desktop77
-rw-r--r--kget/kget_plug_in/kget_plug_in.h58
-rw-r--r--kget/kget_plug_in/kget_plug_in.rc11
-rw-r--r--kget/kget_plug_in/links.cpp41
-rw-r--r--kget/kget_plug_in/links.h32
10 files changed, 625 insertions, 0 deletions
diff --git a/kget/kget_plug_in/Makefile.am b/kget/kget_plug_in/Makefile.am
new file mode 100644
index 00000000..4e2afd67
--- /dev/null
+++ b/kget/kget_plug_in/Makefile.am
@@ -0,0 +1,13 @@
+INCLUDES = $(all_includes)
+
+kde_module_LTLIBRARIES = khtml_kget.la
+
+khtml_kget_la_METASOURCES = AUTO
+khtml_kget_la_SOURCES = kget_plug_in.cpp kget_linkview.cpp links.cpp
+khtml_kget_la_LIBADD = $(LIB_KHTML)
+khtml_kget_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
+
+KDE_ICON = AUTO
+
+part_DATA = kget_plug_in.rc kget_plug_in.desktop
+partdir = $(kde_datadir)/khtml/kpartplugins
diff --git a/kget/kget_plug_in/cr22-action-khtml_kget.png b/kget/kget_plug_in/cr22-action-khtml_kget.png
new file mode 100644
index 00000000..6b0f14f3
--- /dev/null
+++ b/kget/kget_plug_in/cr22-action-khtml_kget.png
Binary files differ
diff --git a/kget/kget_plug_in/kget_linkview.cpp b/kget/kget_plug_in/kget_linkview.cpp
new file mode 100644
index 00000000..179cc81b
--- /dev/null
+++ b/kget/kget_plug_in/kget_linkview.cpp
@@ -0,0 +1,150 @@
+#include "kget_linkview.h"
+
+#include <qlayout.h>
+
+#include <dcopclient.h>
+#include <kaction.h>
+#include <kapplication.h>
+#include <kiconloader.h>
+#include <klistviewsearchline.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kprocess.h>
+#include <kstdaction.h>
+#include <ktoolbar.h>
+
+#define COL_NAME 0
+#define COL_DESC 1
+#define COL_MIME 2
+#define COL_URL 3
+
+LinkViewItem::LinkViewItem( QListView *parent, const LinkItem *lnk )
+ : QListViewItem( parent ),
+ link( lnk )
+{
+ QString file = link->url.fileName();
+ if ( file.isEmpty() )
+ file = link->url.host();
+
+ setPixmap( COL_NAME, SmallIcon( link->icon ) );
+ setText( COL_NAME, file );
+
+ setText( COL_DESC, link->text );
+ setText( COL_MIME, link->mimeType );
+ setText( COL_URL, link->url.prettyURL() );
+}
+
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+
+KGetLinkView::KGetLinkView( QWidget *parent, const char *name )
+ : KMainWindow( parent, name )
+{
+ setPlainCaption( i18n( "KGet" ) );
+
+ KAction* actionDownload = new KAction( i18n("Download Selected Files"),
+ "kget", CTRL+Key_D,
+ this, SLOT( slotStartLeech() ),
+ actionCollection(), "startDownload" );
+
+ KAction* actionSelectAll = KStdAction::selectAll( this, SLOT( slotSelectAll() ),
+ actionCollection() );
+
+ m_links.setAutoDelete( true );
+ actionDownload->plug( toolBar() );
+ toolBar()->insertLineSeparator();
+ actionSelectAll->plug( toolBar() );
+
+ QWidget *mainWidget = new QWidget( this );
+ QVBoxLayout *layout = new QVBoxLayout( mainWidget );
+ setCentralWidget( mainWidget );
+
+ m_view = new KListView( mainWidget, "listview" );
+ m_view->setSelectionMode( QListView::Extended );
+ m_view->addColumn( i18n("File Name") );
+ m_view->addColumn( i18n("Description") );
+ m_view->addColumn( i18n("File Type") );
+ m_view->addColumn( i18n("Location (URL)") );
+ m_view->setShowSortIndicator( true );
+
+ KListViewSearchLineWidget *line = new KListViewSearchLineWidget( m_view, mainWidget, "search line" );
+ layout->addWidget( line );
+ layout->addWidget( m_view );
+
+ // setting a fixed (not floating) toolbar
+ toolBar()->setMovingEnabled( false );
+ // setting Text next to Icons
+ toolBar()->setIconText( KToolBar::IconTextRight );
+}
+
+KGetLinkView::~KGetLinkView()
+{
+}
+
+void KGetLinkView::setLinks( QPtrList<LinkItem>& links )
+{
+ m_links = links; // now we 0wn them
+ showLinks( m_links );
+}
+
+void KGetLinkView::showLinks( const QPtrList<LinkItem>& links )
+{
+ m_view->clear();
+
+ QPtrListIterator<LinkItem> it( links );
+ for ( ; it.current(); ++it )
+ (void) new LinkViewItem( m_view, *it );
+
+ m_view->sort();
+}
+
+void KGetLinkView::slotStartLeech()
+{
+ KURL::List urls;
+ QListViewItemIterator it( m_view->firstChild() );
+ for ( ; it.current(); ++it )
+ {
+ if ( it.current()->isSelected() )
+ urls.append( static_cast<LinkViewItem*>( it.current() )->link->url );
+ }
+
+ if ( urls.isEmpty() )
+ KMessageBox::sorry( this,
+ i18n("You did not select any files to download."),
+ i18n("No Files Selected") );
+ else
+ {
+ DCOPClient* p_dcopServer = new DCOPClient();
+ p_dcopServer->attach();
+
+ if ( !p_dcopServer->isApplicationRegistered( "kget" ) )
+ {
+ KApplication::startServiceByDesktopName( "kget" );
+ }
+ kapp->updateRemoteUserTimestamp( "kget" );
+
+ QByteArray data;
+ QDataStream stream( data, IO_WriteOnly );
+ stream << urls << QString::null;
+ bool ok = DCOPClient::mainClient()->send( "kget", "KGet-Interface",
+ "addTransfers(KURL::List, QString)",
+ data );
+
+ kdDebug() << "*** startDownload: " << ok << endl;
+
+ p_dcopServer->detach();
+ delete p_dcopServer;
+ }
+}
+
+void KGetLinkView::setPageURL( const QString& url )
+{
+ setPlainCaption( i18n( "Links in: %1 - KGet" ).arg( url ) );
+}
+
+void KGetLinkView::slotSelectAll()
+{
+ m_view->selectAll( true );
+}
+
+#include "kget_linkview.moc"
diff --git a/kget/kget_plug_in/kget_linkview.h b/kget/kget_plug_in/kget_linkview.h
new file mode 100644
index 00000000..a6d7961c
--- /dev/null
+++ b/kget/kget_plug_in/kget_linkview.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+** $Id$
+**
+** Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
+**
+****************************************************************************/
+
+#ifndef KGET_LINKVIEW_H
+#define KGET_LINKVIEW_H
+
+#include <qptrlist.h>
+
+#include <klistview.h>
+#include <kmainwindow.h>
+#include <kurl.h>
+
+#include "links.h"
+
+class LinkViewItem : public QListViewItem
+{
+public:
+ LinkViewItem( QListView *parent, const LinkItem * lnk );
+ const LinkItem *link;
+};
+
+
+class KGetLinkView : public KMainWindow
+{
+ Q_OBJECT
+
+public:
+ KGetLinkView( QWidget *parent = 0L, const char *name = 0L );
+ ~KGetLinkView();
+
+ void setLinks( QPtrList<LinkItem>& links );
+ void setPageURL( const QString& url );
+
+signals:
+ void leechURLs( const KURL::List& urls );
+
+private slots:
+ void slotStartLeech();
+ void slotSelectAll();
+
+private:
+ void showLinks( const QPtrList<LinkItem>& links );
+
+ QPtrList<LinkItem> m_links;
+
+ KListView *m_view;
+
+};
+
+#endif // KGET_LINKVIEW_H
diff --git a/kget/kget_plug_in/kget_plug_in.cpp b/kget/kget_plug_in/kget_plug_in.cpp
new file mode 100644
index 00000000..dc5f5b9f
--- /dev/null
+++ b/kget/kget_plug_in/kget_plug_in.cpp
@@ -0,0 +1,189 @@
+/***************************************************************************
+ kget_plug_in.cpp - description
+ -------------------
+ begin : Wed Jul 3 22:09:28 CEST 2002
+ copyright : (C) 2002 by Patrick
+ email : pch@valleeurpe.net
+
+ Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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_plug_in.h"
+
+#include <dcopref.h>
+#include <kdatastream.h>
+#include <kdebug.h>
+#include <khtml_part.h>
+#include <kiconloader.h>
+#include <kglobal.h>
+#include <kaction.h>
+#include <kinstance.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kpopupmenu.h>
+#include <krun.h>
+
+#include <dom/html_document.h>
+#include <dom/html_misc.h>
+#include <dom/dom_element.h>
+
+#include <kparts/partmanager.h>
+
+#include <set>
+
+#include "links.h"
+#include "kget_linkview.h"
+
+KGet_plug_in::KGet_plug_in( QObject* parent, const char* name )
+ : Plugin( parent, name )
+{
+ QPixmap pix = KGlobal::iconLoader()->loadIcon("kget",
+ KIcon::MainToolbar);
+ KActionMenu *menu = new KActionMenu( i18n("Download Manager"), pix,
+ actionCollection(), "kget_menu" );
+ menu->setDelayed( false );
+ connect( menu->popupMenu(), SIGNAL( aboutToShow() ), SLOT( showPopup() ));
+
+ m_paToggleDropTarget=new KToggleAction(i18n("Show Drop Target"),
+ KShortcut(),
+ this, SLOT(slotShowDrop()),
+ actionCollection(), "show_drop" );
+
+ menu->insert( m_paToggleDropTarget );
+
+ KAction *action = new KAction(i18n("List All Links"), KShortcut(),
+ this, SLOT( slotShowLinks() ),
+ actionCollection(), "show_links");
+ menu->insert( action );
+
+ p_dcopServer= new DCOPClient();
+ p_dcopServer->attach ();
+}
+
+
+KGet_plug_in::~KGet_plug_in()
+{
+ p_dcopServer->detach();
+ delete p_dcopServer;
+}
+
+
+void KGet_plug_in::showPopup()
+{
+ bool hasDropTarget = false;
+
+ if (p_dcopServer->isApplicationRegistered ("kget"))
+ {
+ DCOPRef kget( "kget", "KGet-Interface" );
+ hasDropTarget = kget.call( "isDropTargetVisible" );
+ }
+
+ m_paToggleDropTarget->setChecked( hasDropTarget );
+}
+
+void KGet_plug_in::slotShowDrop()
+{
+ if (!p_dcopServer->isApplicationRegistered ("kget"))
+ KRun::runCommand("kget --showDropTarget");
+ else
+ {
+ DCOPRef kget( "kget", "KGet-Interface" );
+ kget.send( "setDropTargetVisible", m_paToggleDropTarget->isChecked());
+ }
+}
+
+void KGet_plug_in::slotShowLinks()
+{
+ if ( !parent() || !parent()->inherits( "KHTMLPart" ) )
+ return;
+
+ KHTMLPart *htmlPart = static_cast<KHTMLPart*>( parent() );
+ KParts::Part *activePart = 0L;
+ if ( htmlPart->partManager() )
+ {
+ activePart = htmlPart->partManager()->activePart();
+ if ( activePart && activePart->inherits( "KHTMLPart" ) )
+ htmlPart = static_cast<KHTMLPart*>( activePart );
+ }
+
+ DOM::HTMLDocument doc = htmlPart->htmlDocument();
+ if ( doc.isNull() )
+ return;
+
+ DOM::HTMLCollection links = doc.links();
+
+ QPtrList<LinkItem> linkList;
+ std::set<QString> dupeCheck;
+ for ( uint i = 0; i < links.length(); i++ )
+ {
+ DOM::Node link = links.item( i );
+ if ( link.isNull() || link.nodeType() != DOM::Node::ELEMENT_NODE )
+ continue;
+
+ LinkItem *item = new LinkItem( (DOM::Element) link );
+ if ( item->isValid() &&
+ dupeCheck.find( item->url.url() ) == dupeCheck.end() )
+ {
+ linkList.append( item );
+ dupeCheck.insert( item->url.url() );
+ }
+ else
+ delete item;
+ }
+
+ if ( linkList.isEmpty() )
+ {
+ KMessageBox::sorry( htmlPart->widget(),
+ i18n("There are no links in the active frame of the current HTML page."),
+ i18n("No Links") );
+ return;
+ }
+
+ KGetLinkView *view = new KGetLinkView();
+ QString url = doc.URL().string();
+ view->setPageURL( url );
+
+ view->setLinks( linkList );
+ view->show();
+}
+
+KPluginFactory::KPluginFactory( QObject* parent, const char* name )
+ : KLibFactory( parent, name )
+{
+ s_instance = new KInstance("KPluginFactory");
+}
+
+QObject* KPluginFactory::createObject( QObject* parent, const char* name, const char*, const QStringList & )
+{
+ QObject *obj = new KGet_plug_in( parent, name );
+ return obj;
+}
+
+KPluginFactory::~KPluginFactory()
+{
+ delete s_instance;
+}
+
+extern "C"
+{
+ KDE_EXPORT void* init_khtml_kget()
+ {
+ KGlobal::locale()->insertCatalogue("kget");
+ return new KPluginFactory;
+ }
+
+}
+
+KInstance* KPluginFactory::s_instance = 0L;
+
+#include "kget_plug_in.moc"
diff --git a/kget/kget_plug_in/kget_plug_in.desktop b/kget/kget_plug_in/kget_plug_in.desktop
new file mode 100644
index 00000000..8976c2f4
--- /dev/null
+++ b/kget/kget_plug_in/kget_plug_in.desktop
@@ -0,0 +1,77 @@
+[Desktop Entry]
+X-KDE-Library=khtml_kget
+X-KDE-PluginInfo-Author=Patrick Charbonnier, Carsten Pfeiffer
+X-KDE-PluginInfo-Email=pch@valleeurope.net, pfeiffer@kde.org
+X-KDE-PluginInfo-Name=kget
+X-KDE-PluginInfo-Version=3.4
+X-KDE-PluginInfo-Website=http://kget.sourceforge.net
+X-KDE-PluginInfo-Category=Tools
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+Name=KGet
+Name[ar]=ك.جيت
+Name[bn]=কে-গেট
+Name[cy]=KNôl
+Name[eo]=Prenilo
+Name[hi]=के-गेट
+Name[ne]=केडीई गेट
+Name[sv]=Kget
+Name[ta]=கேகெட்
+Name[th]=ดาวน์โหลด K
+Name[ven]=Wana ha K
+Comment=Download Manager
+Comment[be]=Праграма сцягвання файлаў
+Comment[bg]=Изтегляне на файлове
+Comment[bn]=ডাউনলোড ম্যানেজার
+Comment[br]=Merour enkargañ
+Comment[bs]=Upravitelj downloadom
+Comment[ca]=Gestor de descàrregues
+Comment[cs]=Správce stahování
+Comment[cy]=Trefnydd Lawrlwytho
+Comment[da]=Håndtering af download
+Comment[de]=Herunterladen von Dateien
+Comment[el]=Διαχειριστής λήψεων αρχείων
+Comment[eo]=Elŝut-administrilo
+Comment[es]=Gestor de descargas
+Comment[et]=Allalaadimiste haldur
+Comment[eu]=Deskarga kudeatzailea
+Comment[fa]=مدیر بارگیری
+Comment[fi]=Tiedostonlataaja
+Comment[fr]=Gestionnaire de téléchargements
+Comment[ga]=Bainisteoir Íosluchtaithe
+Comment[gl]=Xestor de Descargas
+Comment[he]=מנהל הורדות
+Comment[hu]=Letöltéskezelő
+Comment[is]=Niðurhalsstjóri
+Comment[it]=Gestore degli scaricamenti
+Comment[ja]=ダウンロードマネージャ
+Comment[ka]=ჩამოქაჩვათა მმართველი
+Comment[kk]=Жүктеп алу менеджері
+Comment[km]=កម្មវិធី​គ្រប់គ្រង​ការ​ទាញ​យក
+Comment[lt]=Siuntimų valdymas
+Comment[nb]=Nedlastingsbehandler
+Comment[nds]=Daallaadpleger
+Comment[ne]=डाउनलोड प्रबन्धक
+Comment[nl]=Downloadmanager
+Comment[nn]=Nedlastingshandsamar
+Comment[pa]=ਡਾਊਨਲੋਡ ਮੈਨੇਜਰ
+Comment[pl]=Menedżer pobierania
+Comment[pt]=Gestor de Transferências
+Comment[pt_BR]=Gerenciador de Download
+Comment[ro]=Manager de transferuri FTP
+Comment[ru]=Диспетчер загрузок
+Comment[sk]=Správca sťahovania
+Comment[sl]=Upravitelj prenosov
+Comment[sr]=Менаџер преузимања
+Comment[sr@Latn]=Menadžer preuzimanja
+Comment[sv]=Nerladdningshanterare
+Comment[tr]=İndirme Yöneticisi
+Comment[uk]=Менеджер звантажень
+Comment[uz]=Yozib olish boshqaruvchisi
+Comment[uz@cyrillic]=Ёзиб олиш бошқарувчиси
+Comment[zh_CN]=下载管理器
+Comment[zh_HK]=下載管理員
+Comment[zh_TW]=下載管理員
+Icon=khtml_kget
+
diff --git a/kget/kget_plug_in/kget_plug_in.h b/kget/kget_plug_in/kget_plug_in.h
new file mode 100644
index 00000000..75888b10
--- /dev/null
+++ b/kget/kget_plug_in/kget_plug_in.h
@@ -0,0 +1,58 @@
+/***************************************************************************
+ kget_plug_in.h - description
+ -------------------
+ begin : Wed Jul 3 22:09:28 CEST 2002
+ copyright : (C) 2002 by Patrick
+ email : pch@valleeurpe.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 __plugin_kget_plug_in_h
+#define __plugin_kget_plug_in_h
+
+#include <kparts/plugin.h>
+#include <klibloader.h>
+#include <dcopclient.h>
+#include <kurl.h>
+
+class KInstance;
+
+class KGet_plug_in : public KParts::Plugin
+{
+ Q_OBJECT
+public:
+ KGet_plug_in( QObject* parent = 0, const char* name = 0 );
+ KToggleAction *m_paToggleDropTarget ;
+ DCOPClient* p_dcopServer;
+ virtual ~KGet_plug_in();
+
+private slots:
+ void slotShowDrop();
+ void slotShowLinks();
+ void showPopup();
+};
+
+
+class KPluginFactory : public KLibFactory
+{
+ Q_OBJECT
+public:
+ KPluginFactory( QObject *parent = 0, const char *name = 0 );
+ ~KPluginFactory() ;
+
+ virtual QObject* createObject( QObject* parent = 0, const char* pname = 0,
+ const char* name = "QObject",
+ const QStringList &args = QStringList() );
+
+private:
+ static KInstance* s_instance;
+};
+
+#endif
diff --git a/kget/kget_plug_in/kget_plug_in.rc b/kget/kget_plug_in/kget_plug_in.rc
new file mode 100644
index 00000000..f40ee8b7
--- /dev/null
+++ b/kget/kget_plug_in/kget_plug_in.rc
@@ -0,0 +1,11 @@
+<!DOCTYPE kpartgui>
+<kpartgui library="khtml_kget" name="khtml_kget" version="3" >
+<MenuBar>
+ <Menu name="tools"><Text>&amp;Tools</Text>
+ <Action name="kget_menu"/>
+ </Menu>
+</MenuBar>
+<ToolBar name="mainToolBar">
+ <Action name="kget_menu"/>
+</ToolBar>
+</kpartgui>
diff --git a/kget/kget_plug_in/links.cpp b/kget/kget_plug_in/links.cpp
new file mode 100644
index 00000000..a597257d
--- /dev/null
+++ b/kget/kget_plug_in/links.cpp
@@ -0,0 +1,41 @@
+#include "links.h"
+
+#include <kmimetype.h>
+#include <kprotocolinfo.h>
+
+#include <dom/html_misc.h>
+#include <dom/html_document.h>
+
+LinkItem::LinkItem( DOM::Element link )
+ : m_valid( false )
+{
+ DOM::NamedNodeMap attrs = link.attributes();
+ DOM::Node href = attrs.getNamedItem( "href" );
+
+ // qDebug("*** href: %s", href.nodeValue().string().latin1() );
+
+ QString urlString = link.ownerDocument().completeURL( href.nodeValue() ).string();
+ if ( urlString.isEmpty() )
+ return;
+
+ url = KURL::fromPathOrURL( urlString );
+ if ( !KProtocolInfo::supportsReading( url ) )
+ return;
+
+
+ // somehow getElementsByTagName("#text") doesn't work :(
+ DOM::NodeList children = link.childNodes();
+ for ( uint i = 0; i < children.length(); i++ )
+ {
+ DOM::Node node = children.item( i );
+ if ( node.nodeType() == DOM::Node::TEXT_NODE )
+ text.append( node.nodeValue().string() );
+ }
+
+ // force "local file" mimetype determination
+ KMimeType::Ptr mt = KMimeType::findByURL( url, 0, true, true);
+ icon = mt->icon( QString::null, false ); // dummy parameters
+ mimeType = mt->comment();
+
+ m_valid = true;
+}
diff --git a/kget/kget_plug_in/links.h b/kget/kget_plug_in/links.h
new file mode 100644
index 00000000..89ba9ab5
--- /dev/null
+++ b/kget/kget_plug_in/links.h
@@ -0,0 +1,32 @@
+/****************************************************************************
+** $Id$
+**
+** Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
+**
+****************************************************************************/
+
+#ifndef LINKS_H
+#define LINKS_H
+
+#include <dom/dom_element.h>
+
+#include <kurl.h>
+
+class LinkItem
+{
+public:
+ LinkItem( DOM::Element link );
+
+ KURL url;
+ QString icon;
+ QString text;
+ QString mimeType;
+
+ bool isValid() const { return m_valid; }
+
+private:
+ bool m_valid : 1;
+};
+
+
+#endif // LINKS_H