21 #include "formatfactory.h"
22 #include "vcardformat.h"
25 #include <klocalizedstring.h>
27 #include <kstandarddirs.h>
28 #include <kconfiggroup.h>
31 #include <QtCore/QCoreApplication>
32 #include <QtCore/QFile>
36 class FormatFactory::Private
41 qRemovePostRoutine( cleanupFormatFactory );
44 KLibrary *openLibrary(
const QString &libName );
46 QHash<QString, FormatInfo> mFormatList;
49 static void cleanupFormatFactory()
57 KLibrary *FormatFactory::Private::openLibrary(
const QString &libName )
59 KLibrary *library =
new KLibrary( libName );
60 if ( library->load() ) {
63 kDebug() << library->errorString();
75 qAddPostRoutine( Private::cleanupFormatFactory );
80 FormatFactory::FormatFactory()
85 info.
library = QLatin1String(
"<NoLibrary>" );
88 d->mFormatList.insert( QLatin1String(
"vcard" ), info );
90 const QStringList list =
91 KGlobal::dirs()->findAllResources(
"data", QLatin1String(
"kabc/formats/*.desktop" ),
92 KStandardDirs::Recursive |
93 KStandardDirs::NoDuplicates );
94 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
95 KConfig config( *it, KConfig::SimpleConfig );
97 if ( !config.hasGroup(
"Misc" ) || !config.hasGroup(
"Plugin" ) ) {
101 KConfigGroup group = config.group(
"Plugin" );
102 QString type = group.readEntry(
"Type" );
103 info.
library = group.readEntry(
"X-KDE-Library" );
105 group = config.group(
"Misc" );
106 info.
nameLabel = group.readEntry(
"Name" );
107 info.
descriptionLabel = group.readEntry(
"Comment", i18n(
"No description available." ) );
109 d->mFormatList.insert( type, info );
123 retval << QLatin1String(
"vcard" );
125 QHashIterator<QString, FormatInfo> it( d->mFormatList );
126 while ( it.hasNext() ) {
128 if ( it.key() != QLatin1String(
"vcard" ) ) {
138 if ( type.isEmpty() || !d->mFormatList.contains( type ) ) {
141 return d->mFormatList[ type ];
149 if ( type.isEmpty() ) {
153 if ( type == QLatin1String(
"vcard" ) ) {
161 if ( !d->mFormatList.contains( type ) ) {
168 KLibrary *library = d->openLibrary( libName );
173 KLibrary::void_function_ptr format_func = library->resolveFunction(
"format" );
176 format = ( (
Format *(*)())format_func )();
181 kDebug() <<
"'" << libName <<
"' is not a format plugin.";
virtual void setNameLabel(const QString &label)
Sets the plugin's name.
virtual void setDescriptionLabel(const QString &label)
Sets the plugin's description.
virtual void setType(const QString &type)
Sets the plugin's type.