[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: Re: PATCH adds PluginInterface to KonqPopupMenu
From: Holger Freyther <freyther () gmx ! net>
Date: 2001-10-29 9:10:35
[Download RAW message or body]
Hi,
here is just a basic plugin. It simply just adds one entry into the
konqpopupmenu.
["plugin_test.h" (text/x-c++)]
/*
* Copyright (C) 2001 zecke123 / Holger Freyther <freyther@yahoo.com>
* This is a baic plugin. It show how to add a plugin
*/
#ifndef _PLUGIN_TEST_H_
#define _PLUGIN_TEST_H_
#include <klibloader.h>
#include <konq_popupmenu.h>
class KInstance;
class KAction;
class KTestMenu : public KonqPopupMenuPlugin {
Q_OBJECT
public:
KTestMenu (KonqPopupMenu *);
virtual ~KTestMenu( );
virtual void activatePopup( );
private:
KonqPopupMenu *popup;
KAction *my_action;
public slots:
void slotPopupMaeh( );
};
/**
* If you develop a library that is to be loaded dynamically at runtime, then
* you should provide a function that returns a pointer to your factory like this:
* <pre>
* extern "C"
* {
* void* init_libkspread()
* {
* return new KSpreadFactory;
* }
* };
* </pre>
* You should especially see that the function must follow the naming pattern
* "init_libname".
*
* In the constructor of your factory you should create an instance of @ref KInstance
* like this:
* <pre>
* s_global = new KInstance( "kspread" );
* </pre>
* This @ref KInstance is compareable to @ref KGlobal used by normal applications.
* It allows you to find ressource files (images, XML, sound etc.) belonging
* to the library.
*
* If you want to load a library, use @ref KLibLoader. You can query @ref KLibLoader
* directly for a pointer to the libraries factory by using the @ref KLibLoader::factory()
* function.
*
* The KLibFactory is used to create the components, the library has to offer.
* The factory of KSpread for example will create instances of KSpreadDoc,
* while the Konqueror factory will create KonqView widgets.
* All objects created by the factory must be derived from @ref QObject, since @ref QObject
* offers type safe casting.
*
* KLibFactory is an abstract class. Reimplement the @ref
* createObject() method to give it functionality.
*
* @author Torben Weis <weis@kde.org>
*/
class KPluginFactory : public KLibFactory
{
Q_OBJECT
public:
/**
* Create a new factory.
*/
KPluginFactory( QObject *parent = 0, const char *name = 0 );
/**
* Destroy factory.
*/
~KPluginFactory() ;
/**
* Creates a new object. The returned object has to be derived from
* the requested classname.
*
* It is valid behavior to create different kinds of objects
* depending on the requested @p classname. For example a koffice
* library may usually return a pointer to @ref KoDocument. But
* if asked for a "QWidget", it could create a wrapper widget,
* that encapsulates the Koffice specific features.
*
* Never reimplement this function. Instead, reimplement @ref
* createObject().
*
* create() automatically emits a signal @ref objectCreated to tell
* the library about its newly created object. This is very
* important for reference counting, and allows unloading the
* library automatically once all its objects have been destroyed.
*
* This function is virtual for compatibility reasons only.
*/
virtual QObject* createObject( QObject* parent = 0, const char* pname = 0,
const char* name = "QObject",
const QStringList &args = QStringList() );
private:
static KInstance* s_instance;
};
#endif
["plugin_test.cpp" (text/x-c++)]
/*
* Copyright (C) 2001 zecke123 / Holger Freyther,,, <ich@cosma>
*/
#include "plugin_test.h"
#include <kdebug.h>
#include <kaction.h>
#include <kinstance.h>
#include <kiconloader.h>
#include <klocale.h>
#include <konq_popupmenu.h>
KTestMenu::KTestMenu( KonqPopupMenu *popupmenu ) : KonqPopupMenuPlugin( popupmenu) {
popup=popupmenu;
};
KTestMenu::~KTestMenu( ){
popup=0L;
};
void KTestMenu::activatePopup ( ){
my_action = new KAction( "New KonqPlugin", 0, this, SLOT( slotPopupMaeh( ) ), \
popup->actionCollection( ), "Do some funky stuff" ); popup->addAction( my_action, \
popup->getDomElement() ); //my_action->plug(popup ); // either way works you can add \
a entry by popup->addAction or the known way qWarning("activate_popup6");
}
void KTestMenu::slotPopupMaeh( ){
qWarning("our action was triggered");
}
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 KTestMenu( (KonqPopupMenu*)parent );
return obj;
}
KPluginFactory::~KPluginFactory()
{ delete s_instance; }
extern "C"
{
void* init_libtestplugin()
{
return new KPluginFactory;
}
}
KInstance* KPluginFactory::s_instance = 0L;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic