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>
36class FormatFactory::Private
41 qRemovePostRoutine( cleanupFormatFactory );
44 KLibrary *openLibrary(
const QString &libName );
46 QHash<QString, FormatInfo> mFormatList;
49 static void cleanupFormatFactory()
57KLibrary *FormatFactory::Private::openLibrary(
const QString &libName )
59 KLibrary *library =
new KLibrary( libName );
60 if ( library->load() ) {
63 kDebug() << library->errorString();
75 qAddPostRoutine( Private::cleanupFormatFactory );
80FormatFactory::FormatFactory()
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" );
105 group = config.group(
"Misc" );
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 setType(const QString &type)
Sets the plugin's type.
virtual void setDescriptionLabel(const QString &label)
Sets the plugin's description.
virtual void setNameLabel(const QString &label)
Sets the plugin's name.
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)