summaryrefslogtreecommitdiffabout
path: root/microkde/kresources
Unidiff
Diffstat (limited to 'microkde/kresources') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/factory.cpp100
-rw-r--r--microkde/kresources/factory.h13
2 files changed, 75 insertions, 38 deletions
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp
index 709cd4a..56b0ef3 100644
--- a/microkde/kresources/factory.cpp
+++ b/microkde/kresources/factory.cpp
@@ -28,2 +28,3 @@
28#include <kstaticdeleter.h> 28#include <kstaticdeleter.h>
29#include <klibloader.h>
29 30
@@ -31,10 +32,2 @@
31 32
32#include <plugins/file/resourcefile.h>
33#include <plugins/file/resourcefileconfig.h>
34#include <plugins/dir/resourcedir.h>
35#include <plugins/dir/resourcedirconfig.h>
36//#include <plugins/ldap/resourceldap.h>
37//#include <plugins/ldap/resourceldapconfig.h>
38
39
40#include "resource.h" 33#include "resource.h"
@@ -84,12 +77,46 @@ Factory::Factory( const QString& resourceFamily ) :
84 77
85//US !!!!!!!!!!!!!!! 78//US new
86 KRES::PluginFactoryBase* pf = (KRES::PluginFactoryBase*)new KRES::PluginFactory<KABC::ResourceFile,KABC::ResourceFileConfig>(); 79 PluginInfo* info = new PluginInfo;
87 mTypeMap.insert( "file", pf ); 80 info->library = "microkabc_file";
81 info->nameLabel = i18n( "file" );
82 info->descriptionLabel = i18n( "No description available." );
83 mTypeMap.insert( "file", info );
84
85 info = new PluginInfo;
86 info->library = "microkabc_dir";
87 info->nameLabel = i18n( "dir" );
88 info->descriptionLabel = i18n( "No description available." );
89 mTypeMap.insert( "dir", info );
90
91 info = new PluginInfo;
92 info->library = "microkabc_ldap";
93 info->nameLabel = i18n( "ldap" );
94 info->descriptionLabel = i18n( "No description available." );
95 mTypeMap.insert( "ldap", info );
96
97 //US add opie plugin only, if the library exists
98 QString libname = "microkabc_opie";
99 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
100 if ( !path.isEmpty() )
101 {
102 info = new PluginInfo;
103 info->library = libname;
104 info->nameLabel = i18n( "opie" );
105 info->descriptionLabel = i18n( "Opie PIM Addressbook." );
106 mTypeMap.insert( "opie", info );
107 }
108
109 //US add qtopia plugin only, if the library exists
110 libname = "microkabc_qtopia";
111 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
112 if ( !path.isEmpty() )
113 {
114 info = new PluginInfo;
115 info->library = libname;
116 info->nameLabel = i18n( "qtopia" );
117 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." );
118 mTypeMap.insert( "qtopia", info );
119 }
120
88 121
89 pf = (KRES::PluginFactoryBase*)new KRES::PluginFactory<KABC::ResourceDir,KABC::ResourceDirConfig>();
90 mTypeMap.insert( "dir", pf );
91 /*
92 pf = (KRES::PluginFactoryBase*)new KRES::PluginFactory<KABC::ResourceLDAP,KABC::ResourceLDAPConfig>();
93 mTypeMap.insert( "ldap", pf );
94 */
95} 122}
@@ -107,3 +134,3 @@ QStringList Factory::typeNames() const
107 134
108 QMap<QString, PluginFactoryBase*>::ConstIterator it; 135 QMap<QString, PluginInfo*>::ConstIterator it;
109 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { 136 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) {
@@ -121,12 +148,8 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
121 148
122/*US load the lib not dynamically. !! 149//US KService::Ptr ptr = mTypeMap[ type ];
123 KService::Ptr ptr = mTypeMap[ type ]; 150//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
124 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 151 PluginInfo* pi = mTypeMap[ type ];
125 if ( !factory ) { 152 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
126 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
127 return 0;
128 }
129*/
130 PluginFactoryBase *factory = mTypeMap[ type ];
131 if ( !factory ) { 153 if ( !factory ) {
154 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1());
132 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; 155 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
@@ -135,3 +158,2 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
135 158
136
137 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 159 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
@@ -139,2 +161,3 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
139 if ( !pluginFactory ) { 161 if ( !pluginFactory ) {
162 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1());
140 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; 163 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl;
@@ -146,3 +169,3 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
146//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 169//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
147 kdDebug() << " is not a " + mResourceFamily + " plugin." << endl; 170 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
148 return 0; 171 return 0;
@@ -157,7 +180,8 @@ QString Factory::typeName( const QString &type ) const
157 return QString(); 180 return QString();
158 181
182
159//US KService::Ptr ptr = mTypeMap[ type ]; 183//US KService::Ptr ptr = mTypeMap[ type ];
160//US return ptr->name(); 184//US return ptr->name();
161//US I guess this is correct since we loaded the factory staticly. 185 PluginInfo* pi = mTypeMap[ type ];
162 return type; 186 return pi->nameLabel;
163 187
@@ -172,5 +196,4 @@ QString Factory::typeDescription( const QString &type ) const
172//US return ptr->comment(); 196//US return ptr->comment();
173//US I guess this is correct since we loaded the factory staticly. 197 PluginInfo* pi = mTypeMap[ type ];
174 return type; 198 return pi->descriptionLabel;
175
176} 199}
@@ -192,4 +215,6 @@ Resource *Factory::resource( const QString& type, const KConfig *config )
192*/ 215*/
193 PluginFactoryBase *factory = mTypeMap[ type ]; 216 PluginInfo* pi = mTypeMap[ type ];
217 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
194 if ( !factory ) { 218 if ( !factory ) {
219 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1());
195 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 220 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
@@ -201,2 +226,3 @@ Resource *Factory::resource( const QString& type, const KConfig *config )
201 if ( !pluginFactory ) { 226 if ( !pluginFactory ) {
227 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1());
202 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; 228 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl;
@@ -208,3 +234,3 @@ Resource *Factory::resource( const QString& type, const KConfig *config )
208//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 234//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
209 kdDebug() << " is not a " + mResourceFamily + " plugin." << endl; 235 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
210 return 0; 236 return 0;
diff --git a/microkde/kresources/factory.h b/microkde/kresources/factory.h
index f391bb3..ad67ab3 100644
--- a/microkde/kresources/factory.h
+++ b/microkde/kresources/factory.h
@@ -36,2 +36,11 @@ namespace KRES {
36 36
37//US
38struct PluginInfo
39{
40 QString library;
41 QString nameLabel;
42 QString descriptionLabel;
43};
44
45
37/** 46/**
@@ -58,2 +67,3 @@ class Factory
58 67
68
59 /** 69 /**
@@ -108,3 +118,4 @@ class Factory
108//US QMap<QString, KService::Ptr> mTypeMap; 118//US QMap<QString, KService::Ptr> mTypeMap;
109 QMap<QString, PluginFactoryBase*> mTypeMap; 119//US lets store the pluginfo struct as value instead of a KService
120 QMap<QString, PluginInfo*> mTypeMap;
110}; 121};