[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    PATCH adds PluginInterface to KonqPopupMenu
From:       Holger Freyther <freyther () gmx ! net>
Date:       2001-10-28 23:38:17
[Download RAW message or body]

Moin,
this patch adds a plugin interface to KonqPopupmenu. If found the current way 
was too static. 
This PATCH consists of two parts.
1. It adds some public function to make information public to 
KonqPopupMenuPlugin Classes.
2. it adds a new class called KonqPopupMenuPlugin. You need to inherit this 
one and KLibLoader to create your own plugins.
The Plugin class has two choices. Either use KonqPopupMenu::addAction( ) or 
it can use KonqPopupMenu directly.
In some situations the XML GUI stuff is too limited then you could add a 
dummy entry and use the slotXMLGUIFinished()  to manipulate the menu.
A couple of plugins are still to come.
One is a so called quick copy and quick move. It adds something similiar as 
the disknavigator to a popupmenu.
Then you would right click go to the quick copy submenu and choose the path.
I would be happy if this patch would be applied
	regards Holger
["konqpopuplugin.patch" (text/x-diff)]

diff -urN libkonq_orig/Makefile.am libkonq/Makefile.am
--- libkonq_orig/Makefile.am	Mon Aug  6 19:01:33 2001
+++ libkonq/Makefile.am	Sun Oct 28 18:29:02 2001
@@ -39,8 +39,11 @@
 
 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
 
diff -urN libkonq_orig/konq_popupmenu.cc libkonq/konq_popupmenu.cc
--- libkonq_orig/konq_popupmenu.cc	Sun Oct 21 02:30:27 2001
+++ libkonq/konq_popupmenu.cc	Mon Oct 29 00:22:53 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,7 +87,7 @@
   int id = 0;
 
   setFont(KGlobalSettings::menuFont());
-
+	m_pluginList.setAutoDelete( true );
   m_ownActions.setHighlightingEnabled( true );
 
   attrName = QString::fromLatin1( "name" );
@@ -414,7 +416,10 @@
       if ( insertedOffer )
         addSeparator();
   }
-
+  addGroup( "plugins" );	
+  addPlugins( ); // now it's time to add plugins
+  addMerge( "plugins" );
+  
   if ( !m_sMimeType.isEmpty() && showPropertiesAndFileType )
   {
       act = new KAction( i18n( "Edit File Type..." ), 0, this, SLOT( slotPopupMimeType() ),
@@ -440,6 +445,7 @@
 
 KonqPopupMenu::~KonqPopupMenu()
 {
+  m_pluginList.clear( );
   delete m_factory;
   delete m_builder;
 }
@@ -602,6 +608,79 @@
   m_builder = new KonqPopupMenuGUIBuilder( this );
   m_factory = new KXMLGUIFactory( m_builder );
 }
+QDomElement KonqPopupMenu::getDomElement( ){
+	return m_menuElement;
+}
+QString KonqPopupMenu::getMimeType( ){
+    return m_sMimeType;
+}
+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("KonqPopupMenu/Plugin");
+	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;
+		}
+		plugin->activatePopup( );
+		//connect(this, SIGNAL(XMLGUIFinished() ), plugin, SLOT(slotXMLGUIFinished() ) );
+		connect(this, SIGNAL(aboutToShow( ) ), plugin, SLOT( slotXMLGUIFinished( ) ) );
+		m_pluginList.append( plugin );
+
+	}
+
+}
+KURL KonqPopupMenu::getURL( ) const {
+  return m_sViewURL;
+}
+KFileItemList KonqPopupMenu::getKFileItemList( ) const {
+  return m_lstItems;
+}
+KURL::List KonqPopupMenu::getPopupURLList( ) const {
+  return m_lstPopupURLs;
+}
+/**
+	Plugin
+*/
+
+KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *_popup ){
+}
+KonqPopupMenuPlugin::~KonqPopupMenuPlugin( ){
 
+}
+void KonqPopupMenuPlugin::activatePopup( ){
 
+}
+void KonqPopupMenuPlugin::slotXMLGUIFinished( ){
+
+}
 #include "konq_popupmenu.moc"
diff -urN libkonq_orig/konq_popupmenu.h libkonq/konq_popupmenu.h
--- libkonq_orig/konq_popupmenu.h	Tue May  1 12:04:44 2001
+++ libkonq/konq_popupmenu.h	Sun Oct 28 23:21:32 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
@@ -31,9 +32,10 @@
 #include <kfileitem.h>
 #include <kmimetype.h> // for KDEDesktopMimeType
 
+
 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
@@ -79,7 +81,15 @@
   virtual QDomDocument domDocument() const;
 
   virtual KActionCollection *actionCollection() const;
-
+  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 );
+  QDomElement getDomElement( );
+  QString getMimeType( );
+	virtual KURL getURL( ) const;
+  virtual KFileItemList getKFileItemList() const;
+  virtual KURL::List getPopupURLList( ) const;
 public slots:
   void slotPopupNewView();
   void slotPopupEmptyTrashBin();
@@ -89,18 +99,17 @@
   void slotPopupMimeType();
   void slotPopupProperties();
 
+signals:
+  void XMLGUIFinished( );
+
 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 );
-
   KActionCollection &m_actions;
   KActionCollection m_ownActions;
 
 private:
+  void addPlugins( );
   KAction *m_paNewView;
   KNewMenu *m_pMenuNew;
   KURL m_sViewURL;
@@ -115,6 +124,24 @@
   KXMLGUIFactory *m_factory;
   KXMLGUIBuilder *m_builder;
   QString attrName;
+  QPtrList<KonqPopupMenuPlugin> m_pluginList;
+};
+
+class KonqPopupMenuPlugin : public QObject {
+	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 ( );
+	virtual void activatePopup( );
+public slots:
+	virtual void slotXMLGUIFinished( );
 };
 
 #endif
diff -urN libkonq_orig/konqpopupmenuplugin.desktop libkonq/konqpopupmenuplugin.desktop
--- libkonq_orig/konqpopupmenuplugin.desktop	Thu Jan  1 01:00:00 1970
+++ libkonq/konqpopupmenuplugin.desktop	Sun Oct 28 18:24:18 2001
@@ -0,0 +1,4 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=KonqPopupMenu/Plugin
+Comment=Plugin for the Konquer PopupMenu


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic