[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: PATCH KonqPluginInterface Second try
From: Holger Freyther <freyther () gmx ! net>
Date: 2001-10-30 17:00:55
[Download RAW message or body]
Hi all,
Recently I talked a lot with Simon to make the PluginInterface fitting better
in KDE.
This new enchanged PluginInterface supports creating a GUI without the
uglynes of calling things with the parent pointer.
I created a class called KonqXMLGUIClient which helps to manipulate the
XMLGUI better or can use setXMLFile in the plugin to setup the gui or you can
still use the popup-> Pointer.
How to write a plugin?
You need to inherit KonqPopupMenuPlugin and set up all the stuff neceassry in
the constructor. A no use plugin will come shortly afterward.
There are still some design questions left please look at the source.
I think it's ready to commit. If some questions are left just mail me
regards Holger Freyther
--
Kwebsuite http://kwebsuite.sf.net Holger Freyther alias zecke(123)
freyther@yahoo.com
freyther@gmx.net
spamme@keul-dir-ein.de for spmmers
["libkonq.patch" (text/x-diff)]
diff -urN libkoqn_orig/AUTHORS libkonq/AUTHORS
--- libkoqn_orig/AUTHORS Sun Jul 2 22:00:05 2000
+++ libkonq/AUTHORS Tue Oct 30 17:41:46 2001
@@ -2,5 +2,6 @@
Torben Weis <weis@kde.org>
David Faure <faure@kde.org>
Simon Hausmann <hausmann@kde.org>
+Holger Freyther <freyther@yahoo.com>
and are all available under the LGPL license.
See the individual files for more.
diff -urN libkoqn_orig/DESIGN libkonq/DESIGN
--- libkoqn_orig/DESIGN Thu Jul 27 11:43:43 2000
+++ libkonq/DESIGN Tue Oct 30 17:43:23 2001
@@ -14,6 +14,7 @@
kbookmarkmenu.* : bookmark menu
kbookmarkbar.* : bookmark bar
konq_popupmenu.*: popupmenu for URLs
+konq_xmlguiclient.* : general purpose xmlgui manipulating class
knewmenu.* : implements the 'new' menu (file templates)
2) files
@@ -44,3 +45,5 @@
6) other
konq_events.* : events sent by konqueror, for use by the views [& metaviews]
+7) plugin interface
+konq_popupmenu.h : class KonqPopupMenuPlugin
\ No newline at end of file
diff -urN libkoqn_orig/Makefile.am libkonq/Makefile.am
--- libkoqn_orig/Makefile.am Mon Aug 6 19:01:33 2001
+++ libkonq/Makefile.am Tue Oct 30 11:46:36 2001
@@ -27,7 +27,7 @@
kbookmarkmenu.cc kbookmark.cc kbookmarkbar.cc kbookmarkimporter.cc \
kbookmarkexporter.cc kbookmarkmanager.cc kbookmarkmanager.skel \
kbookmarkdrag.cc \
- konq_dirlister.cc \
+ konq_dirlister.cc konq_xmlguiclient.cc\
kfileivi.cc konq_iconviewwidget.cc konq_imagepreviewjob.cc \
konq_settings.cc konq_drag.cc \
konq_operations.cc \
@@ -39,9 +39,12 @@
kdirnotify_DIR = $(kde_includes)
-directory_DATA = directory_bookmarkbar.desktop
+directory_DATA = directory_bookmarkbar.desktop
directorydir = $(kde_datadir)/kbookmark
+servicetype_DATA = konqpopupmenuplugin.desktop
+servicetypedir = $(kde_servicetypesdir)
+
METASOURCES = AUTO
include_HEADERS = konq_popupmenu.h knewmenu.h \
@@ -54,7 +57,7 @@
konq_dirpart.h konq_propsview.h konq_events.h konq_bgnddlg.h \
konq_undo.h konq_historymgr.h konq_historycomm.h \
konq_pixmapprovider.h \
- konq_faviconmgr.h
+ konq_faviconmgr.h konq_xmlguiclient.h
kde_module_LTLIBRARIES = libkonqsound.la
libkonqsound_la_SOURCES = konq_sound.cpp
diff -urN libkoqn_orig/PLUGINS libkonq/PLUGINS
--- libkoqn_orig/PLUGINS Thu Jan 1 01:00:00 1970
+++ libkonq/PLUGINS Tue Oct 30 17:47:01 2001
@@ -0,0 +1,13 @@
+Thus file explains how to add plugins into the konqpopupmenu
+used by konqueror and kdesktop.
+
+Why?
+Why do we need this kind of functionality? We do have SERVICEMENUS.
+A plugin can be much more dynamic. If you want to add features that
+are runtime specific or need some interaction with different things
+a plugin comes in handy
+
+How?
+Please look at ?no_location? to get the latest plugin template
+
+Holger Freyther 30th October 2001
\ No newline at end of file
diff -urN libkoqn_orig/konq_popupmenu.cc libkonq/konq_popupmenu.cc
--- libkoqn_orig/konq_popupmenu.cc Sun Oct 21 02:30:27 2001
+++ libkonq/konq_popupmenu.cc Tue Oct 30 17:48:09 2001
@@ -1,5 +1,6 @@
/* This file is part of the KDE project
Copyright (C) 1998, 1999 David Faure <faure@kde.org>
+ Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -30,6 +31,7 @@
#include <kstandarddirs.h>
#include <kxmlguifactory.h>
#include <kxmlguibuilder.h>
+#include <klibloader.h>
#include <assert.h>
@@ -85,12 +87,14 @@
int id = 0;
setFont(KGlobalSettings::menuFont());
-
+ m_pluginList.setAutoDelete( true );
m_ownActions.setHighlightingEnabled( true );
attrName = QString::fromLatin1( "name" );
prepareXMLGUIStuff();
+ m_builder = new KonqPopupMenuGUIBuilder( this );
+ m_factory = new KXMLGUIFactory( m_builder );
KURL url;
KFileItemListIterator it ( m_lstItems );
@@ -414,6 +418,9 @@
if ( insertedOffer )
addSeparator();
}
+ addGroup( "plugins" );
+ addPlugins( ); // now it's time to add plugins
+ addMerge( "plugins" );
if ( !m_sMimeType.isEmpty() && showPropertiesAndFileType )
{
@@ -440,6 +447,7 @@
KonqPopupMenu::~KonqPopupMenu()
{
+ m_pluginList.clear( );
delete m_factory;
delete m_builder;
}
@@ -531,77 +539,78 @@
return res;
}
-
-QDomDocument KonqPopupMenu::domDocument() const
-{
- return m_doc;
-}
-
KActionCollection *KonqPopupMenu::actionCollection() const
{
return const_cast<KActionCollection *>( &m_ownActions );
}
-void KonqPopupMenu::addAction( KAction *act, const QDomElement &menu )
-{
- addAction( act->name(), menu );
+QString KonqPopupMenu::mimeType( ){
+ return m_sMimeType;
}
-
-void KonqPopupMenu::addAction( const char *name, const QDomElement &menu )
-{
- static QString tagAction = QString::fromLatin1( "action" );
-
- QDomElement parent = menu;
- if ( parent.isNull() )
- parent = m_menuElement;
-
- QDomElement e = m_doc.createElement( tagAction );
- parent.appendChild( e );
- e.setAttribute( attrName, name );
+void KonqPopupMenu::addPlugins( ){
+// search for Konq_PopupMenuPlugins inspired by simons kpropsdlg
+//search for a plugin with the right protocol
+ KTrader::OfferList plugin_offers = KTrader::self()->query(m_sMimeType, \
"'KonqPopupMenu/Plugin' in ServiceTypes"); + KTrader::OfferList::ConstIterator \
iterator = plugin_offers.begin( ); + KTrader::OfferList::ConstIterator end = \
plugin_offers.end( ); + // travers the offerlist
+ for(; iterator != end; ++iterator ){
+ QString libName = (*iterator)->library( );
+ if( libName.isEmpty( ) ) // if there is no lib go to the next offer
+
+ continue;
+ KLibrary *lib = KLibLoader::self()->library( libName.local8Bit() );
+ if ( !lib )
+ continue;
+ KLibFactory *factory = lib->factory( );
+ if (!factory ) {
+ delete lib;
+ continue;
+ }
+ QObject *obj = factory->create( this, (*iterator)->name().latin1(), \
"KonqPopupMenuPlugin" ); + if ( !obj ) {
+ delete lib;
+ //delete factory; // makes sense but Simon didn't do it? so what?
+ continue;
+ }
+ if ( !obj->inherits("KonqPopupMenuPlugin") ){
+ delete obj;
+ continue;
+ //delete lib; // is this necessary?
+ //delete factory; // is this necessary?
+ }
+ KonqPopupMenuPlugin *plugin = static_cast<KonqPopupMenuPlugin *>( obj );
+ if ( !plugin ){
+ delete obj;
+ continue;
+ }
+ //connect(this, SIGNAL(XMLGUIFinished() ), plugin, SLOT(slotXMLGUIFinished() ) );
+ connect(this, SIGNAL(aboutToShow( ) ), plugin, SLOT( slotXMLGUIFinished( ) ) );
+ m_pluginList.append( plugin );
+ insertChildClient( plugin );
+ addMerge( 0 );
+ }
+
+}
+KURL KonqPopupMenu::kURL( ) const {
+ return m_sViewURL;
}
-
-void KonqPopupMenu::addSeparator( const QDomElement &menu )
-{
- static QString tagSeparator = QString::fromLatin1( "separator" );
-
- QDomElement parent = menu;
- if ( parent.isNull() )
- parent = m_menuElement;
-
- parent.appendChild( m_doc.createElement( tagSeparator ) );
+KFileItemList KonqPopupMenu::kfileItemList( ) const {
+ return m_lstItems;
}
-
-void KonqPopupMenu::addMerge( const char *name )
-{
- static QString tagMerge = QString::fromLatin1( "merge" );
- QDomElement merge = m_doc.createElement( tagMerge );
- m_menuElement.appendChild( merge );
- if ( name )
- merge.setAttribute( attrName, name );
+KURL::List KonqPopupMenu::popupURLList( ) const {
+ return m_lstPopupURLs;
}
+/**
+ Plugin
+*/
-void KonqPopupMenu::addGroup( const QString &grp )
-{
- QDomElement group = m_doc.createElement( "definegroup" );
- m_menuElement.appendChild( group );
- group.setAttribute( "name", grp );
+KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *_popup ){
}
+KonqPopupMenuPlugin::~KonqPopupMenuPlugin( ){
-void KonqPopupMenu::prepareXMLGUIStuff()
-{
- m_doc = QDomDocument( "kpartgui" );
-
- QDomElement root = m_doc.createElement( "kpartgui" );
- m_doc.appendChild( root );
- root.setAttribute( attrName, "popupmenu" );
-
- m_menuElement = m_doc.createElement( "Menu" );
- root.appendChild( m_menuElement );
- m_menuElement.setAttribute( attrName, "popupmenu" );
-
- m_builder = new KonqPopupMenuGUIBuilder( this );
- m_factory = new KXMLGUIFactory( m_builder );
}
+void KonqPopupMenuPlugin::slotXMLGUIFinished( ){
-
+}
#include "konq_popupmenu.moc"
diff -urN libkoqn_orig/konq_popupmenu.h libkonq/konq_popupmenu.h
--- libkoqn_orig/konq_popupmenu.h Tue May 1 12:04:44 2001
+++ libkonq/konq_popupmenu.h Tue Oct 30 17:06:00 2001
@@ -1,5 +1,6 @@
/* This file is part of the KDE project
Copyright (C) 1998, 1999 David Faure <faure@kde.org>
+ Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -25,22 +26,24 @@
#include <qpopupmenu.h>
#include <qmap.h>
#include <kaction.h>
-#include <kxmlguiclient.h>
+
#include <qstringlist.h>
#include <kfileitem.h>
#include <kmimetype.h> // for KDEDesktopMimeType
+#include "konq_xmlguiclient.h"
+
class KNewMenu;
class KService;
-
+class KonqPopupMenuPlugin;
/**
* This class implements the popup menu for URLs in konqueror and kdesktop
* It's usage is very simple : on right click, create the KonqPopupMenu instance
* with the correct arguments, then exec() to make it appear, then destroy it.
*
*/
-class KonqPopupMenu : public QPopupMenu, public KXMLGUIClient
+class KonqPopupMenu : public QPopupMenu, public KonqXMLGUIClient
{
Q_OBJECT
public:
@@ -73,13 +76,12 @@
*/
virtual KAction *action( const QDomElement &element ) const;
- /**
- * Reimplemented for internal purpose
- */
- virtual QDomDocument domDocument() const;
virtual KActionCollection *actionCollection() const;
-
+ QString mimeType( );
+ virtual KURL kURL( ) const;
+ virtual KFileItemList kfileItemList() const;
+ virtual KURL::List popupURLList( ) const;
public slots:
void slotPopupNewView();
void slotPopupEmptyTrashBin();
@@ -89,18 +91,15 @@
void slotPopupMimeType();
void slotPopupProperties();
-protected:
- void prepareXMLGUIStuff();
- void addAction( KAction *action, const QDomElement &menu = QDomElement() );
- void addAction( const char *name, const QDomElement &menu = QDomElement() );
- void addSeparator( const QDomElement &menu = QDomElement() );
- void addMerge( const char *name );
- void addGroup( const QString &grp );
+signals:
+ void XMLGUIFinished( );
+protected:
KActionCollection &m_actions;
KActionCollection m_ownActions;
private:
+ void addPlugins( );
KAction *m_paNewView;
KNewMenu *m_pMenuNew;
KURL m_sViewURL;
@@ -110,11 +109,27 @@
QMap<int,KService::Ptr> m_mapPopup;
QMap<int,KDEDesktopMimeType::Service> m_mapPopupServices;
bool m_bHandleEditOperations;
- QDomDocument m_doc;
- QDomElement m_menuElement;
KXMLGUIFactory *m_factory;
KXMLGUIBuilder *m_builder;
QString attrName;
+ QPtrList<KonqPopupMenuPlugin> m_pluginList;
+};
+
+class KonqPopupMenuPlugin : public QObject, public KonqXMLGUIClient {
+ Q_OBJECT
+public:
+ /**
+ * Constructor
+ * If you want to insert a dynamic item or menu to konqpopupmenu
+ * this class is the right choice.
+ * Create a KAction and use _popup->addAction(new KAction );
+ * If you want to create a submenu use _popup->addGroup( );
+ */
+ KonqPopupMenuPlugin( KonqPopupMenu *_popup ); // this should also be the parent
+ virtual ~KonqPopupMenuPlugin ( );
+public slots:
+ virtual void slotXMLGUIFinished( );
};
#endif
+
diff -urN libkoqn_orig/konq_xmlguiclient.cc libkonq/konq_xmlguiclient.cc
--- libkoqn_orig/konq_xmlguiclient.cc Thu Jan 1 01:00:00 1970
+++ libkonq/konq_xmlguiclient.cc Tue Oct 30 16:02:25 2001
@@ -0,0 +1,103 @@
+/* This file is part of the KDE project
+ Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
+ Copyright (c) 1998, 1999 David Faure <faure@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+#include <qstring.h>
+
+#include "konq_xmlguiclient.h"
+
+
+KonqXMLGUIClient::KonqXMLGUIClient( ) : KXMLGUIClient( )
+{
+ attrName = QString::fromLatin1( "name" );
+ prepareXMLGUIStuff( );
+}
+KonqXMLGUIClient::KonqXMLGUIClient( KXMLGUIClient *parent ) : KXMLGUIClient(parent )
+{
+ attrName = QString::fromLatin1( "name" );
+ prepareXMLGUIStuff( );
+}
+
+void KonqXMLGUIClient::prepareXMLGUIStuff()
+{
+ m_doc = QDomDocument( "kpartgui" );
+
+ QDomElement root = m_doc.createElement( "kpartgui" );
+ m_doc.appendChild( root );
+ root.setAttribute( attrName, "popupmenu" );
+
+ m_menuElement = m_doc.createElement( "Menu" );
+ root.appendChild( m_menuElement );
+ m_menuElement.setAttribute( attrName, "popupmenu" );
+
+ /*m_builder = new KonqPopupMenuGUIBuilder( this );
+ m_factory = new KXMLGUIFactory( m_builder ); */
+}
+
+QDomElement KonqXMLGUIClient::DomElement( ) const {
+ return m_menuElement;
+}
+QDomDocument KonqXMLGUIClient::domDocument( ) const {
+ return m_doc;
+}
+void KonqXMLGUIClient::addAction( KAction *act, const QDomElement &menu )
+{
+ addAction( act->name(), menu );
+}
+
+void KonqXMLGUIClient::addAction( const char *name, const QDomElement &menu )
+{
+ static QString tagAction = QString::fromLatin1( "action" );
+
+ QDomElement parent = menu;
+ if ( parent.isNull() )
+ parent = m_menuElement;
+
+ QDomElement e = m_doc.createElement( tagAction );
+ parent.appendChild( e );
+ e.setAttribute( attrName, name );
+}
+
+void KonqXMLGUIClient::addSeparator( const QDomElement &menu )
+{
+ static QString tagSeparator = QString::fromLatin1( "separator" );
+
+ QDomElement parent = menu;
+ if ( parent.isNull() )
+ parent = m_menuElement;
+
+ parent.appendChild( m_doc.createElement( tagSeparator ) );
+}
+
+void KonqXMLGUIClient::addMerge( const char *name )
+{
+ static QString tagMerge = QString::fromLatin1( "merge" );
+ QDomElement merge = m_doc.createElement( tagMerge );
+ m_menuElement.appendChild( merge );
+ if ( name )
+ merge.setAttribute( attrName, name );
+}
+
+void KonqXMLGUIClient::addGroup( const QString &grp )
+{
+ QDomElement group = m_doc.createElement( "definegroup" );
+ m_menuElement.appendChild( group );
+ group.setAttribute( "name", grp );
+}
+KonqXMLGUIClient::~KonqXMLGUIClient( ){
+}
\ No newline at end of file
diff -urN libkoqn_orig/konq_xmlguiclient.h libkonq/konq_xmlguiclient.h
--- libkoqn_orig/konq_xmlguiclient.h Thu Jan 1 01:00:00 1970
+++ libkonq/konq_xmlguiclient.h Tue Oct 30 17:05:55 2001
@@ -0,0 +1,57 @@
+/* This file is part of the KDE project
+ Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __konqxmlguiclient_h
+#define __konqxmlguiclient_h
+
+#include <sys/types.h>
+
+#include <kaction.h>
+#include <kxmlguiclient.h>
+#include <qstringlist.h>
+/** This class implements common methods to manipulate the DOMDocument of \
KXMLGUIClient + *
+ */
+class KonqXMLGUIClient : public KXMLGUIClient
+{
+public:
+ KonqXMLGUIClient( );
+ KonqXMLGUIClient( KXMLGUIClient *parent );
+ virtual ~KonqXMLGUIClient( );
+ /**
+ * Reimplemented for internal purpose
+ */
+ QDomDocument domDocument( ) const;
+
+ QDomElement DomElement( ) const;
+
+protected:
+ void addAction( KAction *action, const QDomElement &menu = QDomElement() );
+ void addAction( const char *name, const QDomElement &menu = QDomElement() );
+ void addSeparator( const QDomElement &menu = QDomElement() );
+ void addGroup( const QString &grp );
+ void addMerge( const char *name );
+ void prepareXMLGUIStuff();
+ QDomDocument m_doc;
+ QDomElement m_menuElement;
+ QString attrName;
+
+};
+#endif
+
diff -urN libkoqn_orig/konqpopupmenuplugin.desktop \
libkonq/konqpopupmenuplugin.desktop
--- libkoqn_orig/konqpopupmenuplugin.desktop Thu Jan 1 01:00:00 1970
+++ libkonq/konqpopupmenuplugin.desktop Tue Oct 30 16:57:00 2001
@@ -0,0 +1,4 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=KonqPopupMenu/Plugin
+Comment=Plugin for the Konquer PopupMenu
diff -urN libkoqn_orig/pics/.cvsignore libkonq/pics/.cvsignore
--- libkoqn_orig/pics/.cvsignore Tue Oct 31 01:45:37 2000
+++ libkonq/pics/.cvsignore Thu Jan 1 01:00:00 1970
@@ -1,2 +0,0 @@
-Makefile.in
-Makefile
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic