27 #include <QtCore/QFile>
28 #include <QtCore/QObject>
29 #include <QtCore/QFileInfo>
39 using namespace KParts;
41 class Plugin::PluginPrivate
49 :
QObject( parent ),d(new PluginPrivate())
63 if ( !d->m_parentInstance.isValid() || ( path.length() > 0 && path[ 0 ] ==
'/' ) )
67 assert( !absPath.isEmpty() );
75 if ( !d->m_parentInstance.isValid() || ( path.length() > 0 && path[ 0 ] ==
'/' ) )
79 assert( !absPath.isEmpty() );
87 kError(1000) <<
"No componentData ???" << endl;
89 QList<PluginInfo> plugins;
97 QStringList::ConstIterator pIt = pluginDocs.begin();
98 QStringList::ConstIterator pEnd = pluginDocs.end();
99 for (; pIt != pEnd; ++pIt )
101 QFileInfo fInfo( *pIt );
102 if ( fInfo.completeSuffix() == QLatin1String(
"desktop" ) )
106 if ( mapIt == sortedPlugins.end() )
107 mapIt = sortedPlugins.insert( fInfo.fileName(),
QStringList() );
109 mapIt.value().append( *pIt );
114 for (; mapIt != mapEnd; ++mapIt )
127 if ( info.
m_document.documentElement().isNull() )
130 plugins.append( info );
143 QList<PluginInfo>::ConstIterator pIt = pluginInfos.begin();
144 QList<PluginInfo>::ConstIterator pEnd = pluginInfos.end();
145 for (; pIt != pEnd; ++pIt )
147 QString library = (*pIt).m_document.documentElement().attribute(
"library" );
149 if ( library.isEmpty() || hasPlugin( parent, library ) )
152 Plugin *plugin =
loadPlugin( parent, library, (*pIt).m_document.documentElement().attribute(
"X-KDE-PluginKeyword" ) );
157 plugin->
setXMLFile( (*pIt).m_relXMLFileName,
false,
false );
171 #ifndef KDE_NO_DEPRECATED
174 Plugin* plugin = KLibLoader::createInstance<Plugin>( libname, parent );
177 plugin->d->m_library = libname;
183 #ifndef KDE_NO_DEPRECATED
208 plugin->d->m_library = libname;
214 QList<KParts::Plugin *> objects;
220 const QObjectList plugins = parent->children();
222 QObjectList::ConstIterator it = plugins.begin();
223 for ( ; it != plugins.end() ; ++it )
227 objects.append( plugin );
235 const QObjectList plugins = parent->children();
237 QObjectList::ConstIterator it = plugins.begin();
238 for ( ; it != plugins.end() ; ++it )
241 if ( plugin && plugin->d->m_library == library )
256 const KComponentData &componentData,
bool enableNewPluginsByDefault,
257 int interfaceVersionRequired)
260 const QList<PluginInfo> plugins =
pluginInfos( componentData );
261 QList<PluginInfo>::ConstIterator pIt = plugins.begin();
262 const QList<PluginInfo>::ConstIterator pEnd = plugins.end();
263 for (; pIt != pEnd; ++pIt )
265 QDomElement docElem = (*pIt).m_document.documentElement();
266 QString library = docElem.attribute(
"library" );
269 if ( library.isEmpty() )
275 bool pluginEnabled = enableNewPluginsByDefault;
276 if ( cfgGroup.hasKey( name +
"Enabled" ) )
278 pluginEnabled = cfgGroup.readEntry( name +
"Enabled" ,
false );
283 relPath.truncate( relPath.lastIndexOf(
'.' ) );
284 relPath +=
".desktop";
287 if( !desktopfile.isEmpty() )
292 keyword = desktop.
readEntry(
"X-KDE-PluginKeyword",
"");
293 pluginEnabled = desktop.
readEntry(
"X-KDE-PluginInfo-EnabledByDefault",
294 enableNewPluginsByDefault );
295 if ( interfaceVersionRequired != 0 )
298 if ( version != interfaceVersionRequired )
300 kDebug(1000) <<
"Discarding plugin " << name <<
", interface version " << version <<
", expected " << interfaceVersionRequired;
301 pluginEnabled =
false;
312 const QObjectList pluginList = parent->children();
314 bool pluginFound =
false;
315 for ( QObjectList::ConstIterator it = pluginList.begin(); it != pluginList.end() ; ++it )
318 if( plugin && plugin->d->m_library == library )
323 kDebug( 1000 ) <<
"remove plugin " << name;
337 if( pluginFound || !pluginEnabled )
340 kDebug( 1000 ) <<
"load plugin " << name <<
" " << library <<
" " << keyword;
346 plugin->
setXMLFile( (*pIt).m_relXMLFileName,
false,
false );
355 #include "plugin.moc"