[PATCH]K_EXPORT_KICKER_MENUEXT(..., ...)
Simon Hausmann
hausmann at kde.org
Sun Jun 23 22:39:48 BST 2002
On Sun, Jun 23, 2002 at 11:18:03PM +0200, Gioele Barabucci wrote:
> All the three kicker menuext uses the same to create a KLibFactory and return
> a new menu. I made a new #define in kpanelmenu.h (kdelibs/kdeui) that creates
> those classes avoiding duplicate work.
>
> Usage is
> K_EXPORT_KICKERMENU(prefmenu, PrefMenu)
>
> [example attached]
>
> Can I commit this?
I think there's no need to create an extra macro. You can do it all
by reusing the existing macro and the KGenericFactory template. See
the attached patch.
Simon
-------------- next part --------------
Index: menuext/recentdocs/recentdocsmenu.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/menuext/recentdocs/recentdocsmenu.cpp,v
retrieving revision 1.1
diff -u -p -r1.1 recentdocsmenu.cpp
--- menuext/recentdocs/recentdocsmenu.cpp 2002/06/07 19:17:50 1.1
+++ menuext/recentdocs/recentdocsmenu.cpp 2002/06/23 21:37:04
@@ -32,16 +32,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE
#include <kapplication.h>
#include <kurldrag.h>
#include <krecentdocument.h>
+#include <kgenericfactory.h>
#include "recentdocsmenu.h"
-extern "C" {
- void* init_kickermenu_recentdocs() {
- return new RecentDocsMenuFactory;
- }
-}
+K_EXPORT_COMPONENT_FACTORY( kickermenu_recentdocs, KGenericFactory<RecentDocsMenu>( "libkickermenu_recentdocs" ) );
-RecentDocsMenu::RecentDocsMenu(QWidget *parent, const char *name)
+RecentDocsMenu::RecentDocsMenu(QWidget *parent, const char *name, const QStringList &/*args*/)
: KPanelMenu(KRecentDocument::recentDocumentDirectory(), parent, name)
{
}
@@ -126,23 +123,5 @@ void RecentDocsMenu::mouseMoveEvent(QMou
d->dragCopy();
close();
}
-
-// ********************************************************************
-
-RecentDocsMenuFactory::RecentDocsMenuFactory(QObject *parent,
- const char *name)
- : KLibFactory(parent, name)
-{
- KGlobal::locale()->insertCatalogue("libkickermenu_recentdocs");
-}
-
-QObject* RecentDocsMenuFactory::createObject(QObject *parent,
- const char *name,
- const char* /* classname */,
- const QStringList& /* args */)
-{
- return new RecentDocsMenu((QWidget*)parent, name);
-}
-
#include "recentdocsmenu.moc"
Index: menuext/recentdocs/recentdocsmenu.h
===================================================================
RCS file: /home/kde/kdebase/kicker/menuext/recentdocs/recentdocsmenu.h,v
retrieving revision 1.1
diff -u -p -r1.1 recentdocsmenu.h
--- menuext/recentdocs/recentdocsmenu.h 2002/06/07 19:17:50 1.1
+++ menuext/recentdocs/recentdocsmenu.h 2002/06/23 21:37:04
@@ -25,7 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE
#define RECENTDOCSMENU_H
#include <kpanelmenu.h>
-#include <klibloader.h>
class QStringList;
class QPoint;
@@ -35,7 +34,7 @@ class RecentDocsMenu : public KPanelMenu
Q_OBJECT
public:
- RecentDocsMenu(QWidget* parent = 0, const char* name = 0);
+ RecentDocsMenu(QWidget* parent, const char* name, const QStringList &/*args*/);
void initialize();
protected slots:
@@ -50,18 +49,5 @@ private:
QStringList fileList;
QPoint mouseDown;
};
-
-class RecentDocsMenuFactory : public KLibFactory
-{
-public:
- RecentDocsMenuFactory(QObject *parent = 0, const char *name = 0);
-
-protected:
- QObject* createObject(QObject* parent = 0,
- const char* name = 0,
- const char* classname = "QObject",
- const QStringList& args = QStringList());
-};
-
#endif // RECENTDOCSMENU_H
Index: share/menuinfo.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/share/menuinfo.cpp,v
retrieving revision 1.3
diff -u -p -r1.3 menuinfo.cpp
--- share/menuinfo.cpp 2001/12/31 02:04:09 1.3
+++ share/menuinfo.cpp 2002/06/23 21:37:04
@@ -30,17 +30,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE
#include <klibloader.h>
#include <kstandarddirs.h>
#include <kpanelmenu.h>
+#include <kparts/componentfactory.h>
MenuInfo::MenuInfo(const QString& desktopFile)
{
KSimpleConfig df(locate("data", QString::fromLatin1("kicker/menuext/%1").arg(desktopFile)));
df.setGroup("Desktop Entry");
- name_ = df.readEntry("Name");
+ name_ = df.readEntry("Name");
comment_ = df.readEntry("Comment");
icon_ = df.readEntry("Icon");
library_ = df.readEntry("X-KDE-Library");
- desktopfile_ = desktopFile;
+ desktopfile_ = desktopFile;
}
KPanelMenu* MenuInfo::load(QWidget *parent, const char *name)
@@ -48,10 +49,6 @@ KPanelMenu* MenuInfo::load(QWidget *pare
if (library_.isEmpty())
return NULL;
- KLibFactory *factory = KLibLoader::self()->factory(QFile::encodeName(library_));
- if (!factory)
- return NULL;
-
- KPanelMenu *menu = dynamic_cast<KPanelMenu*>(factory->create(parent, name));
- return menu;
+ return KParts::ComponentFactory::createInstanceFromLibrary<KPanelMenu>( QFile::encodeName( library_ ),
+ parent, name );
}
More information about the kde-core-devel
mailing list