22 #include <tdeparts/plugin.h>
23 #include <tdeparts/part.h>
24 #include <tdeparts/componentfactory.h>
29 #include <tqobjectlist.h>
30 #include <tqfileinfo.h>
32 #include <klibloader.h>
33 #include <kinstance.h>
34 #include <kstandarddirs.h>
36 #include <kxmlguifactory.h>
38 #include <tdeconfig.h>
39 #include <ksimpleconfig.h>
41 using namespace KParts;
43 class Plugin::PluginPrivate
46 PluginPrivate() : m_parentInstance( 0 ) {}
53 : TQObject( parent, name )
56 d =
new PluginPrivate();
68 if ( !d->m_parentInstance || ( path.length() > 0 && path[ 0 ] ==
'/' ) )
71 TQString absPath =
locate(
"data", TQString::fromLatin1( d->m_parentInstance->instanceName() ) +
'/' + path );
72 assert( !absPath.isEmpty() );
80 if ( !d->m_parentInstance || ( path.length() > 0 && path[ 0 ] ==
'/' ) )
83 TQString absPath =
locateLocal(
"data", TQString::fromLatin1( d->m_parentInstance->instanceName() ) +
'/' + path );
84 assert( !absPath.isEmpty() );
94 TQValueList<PluginInfo> plugins;
100 TQMap<TQString,TQStringList> sortedPlugins;
102 TQStringList::ConstIterator pIt = pluginDocs.begin();
103 TQStringList::ConstIterator pEnd = pluginDocs.end();
104 for (; pIt != pEnd; ++pIt )
106 TQFileInfo fInfo( *pIt );
107 if ( fInfo.extension() == TQString::fromLatin1(
"desktop" ) )
110 TQMap<TQString,TQStringList>::Iterator mapIt = sortedPlugins.find( fInfo.fileName() );
111 if ( mapIt == sortedPlugins.end() )
112 mapIt = sortedPlugins.insert( fInfo.fileName(), TQStringList() );
114 mapIt.data().append( *pIt );
117 TQMap<TQString,TQStringList>::ConstIterator mapIt = sortedPlugins.begin();
118 TQMap<TQString,TQStringList>::ConstIterator mapEnd = sortedPlugins.end();
119 for (; mapIt != mapEnd; ++mapIt )
123 info.
m_absXMLFileName = KXMLGUIClient::findMostRecentXMLFile( mapIt.data(), doc );
131 info.m_document.setContent( doc );
132 if ( info.m_document.documentElement().isNull() )
135 plugins.append( info );
148 TQValueList<PluginInfo>::ConstIterator pIt =
pluginInfos.begin();
149 TQValueList<PluginInfo>::ConstIterator pEnd =
pluginInfos.end();
150 for (; pIt != pEnd; ++pIt )
152 TQString library = (*pIt).m_document.documentElement().attribute(
"library" );
154 if ( library.isEmpty() || hasPlugin( parent, library ) )
157 Plugin *plugin = loadPlugin( parent, TQFile::encodeName(library) );
161 plugin->d->m_parentInstance =
instance;
162 plugin->
setXMLFile( (*pIt).m_relXMLFileName,
false,
false );
176 Plugin* Plugin::loadPlugin( TQObject * parent,
const char* libname )
178 Plugin* plugin = ComponentFactory::createInstanceFromLibrary<Plugin>( libname, parent, libname );
181 plugin->d->m_library = libname;
187 TQPtrList<KParts::Plugin> objects;
192 TQObjectList *plugins = parent->queryList(
"KParts::Plugin", 0,
false,
false );
194 TQObjectListIt it( *plugins );
195 for ( ; it.current() ; ++it )
197 objects.append(
static_cast<Plugin *
>( it.current() ) );
205 bool Plugin::hasPlugin( TQObject* parent,
const TQString& library )
207 TQObjectList *plugins = parent->queryList(
"KParts::Plugin", 0,
false,
false );
208 TQObjectListIt it( *plugins );
209 for ( ; it.current() ; ++it )
211 if (
static_cast<Plugin *
>( it.current() )->d->m_library == library )
231 TQValueList<PluginInfo>::ConstIterator pIt = plugins.begin();
232 TQValueList<PluginInfo>::ConstIterator pEnd = plugins.end();
233 for (; pIt != pEnd; ++pIt )
235 TQDomElement docElem = (*pIt).m_document.documentElement();
236 TQString library = docElem.attribute(
"library" );
238 if ( library.isEmpty() )
242 const TQString name = docElem.attribute(
"name" );
244 bool pluginEnabled = enableNewPluginsByDefault;
245 if ( cfgGroup.
hasKey( name +
"Enabled" ) )
252 relPath.truncate( relPath.findRev(
'.' ) );
253 relPath +=
".desktop";
256 if( !desktopfile.isEmpty() )
262 "X-TDE-PluginInfo-EnabledByDefault", enableNewPluginsByDefault );
271 TQObjectList *pluginList = parent->queryList(
"KParts::Plugin", 0,
false,
false );
272 TQObjectListIt it( *pluginList );
273 bool pluginFound =
false;
274 for ( ; it.current() ; ++it )
276 Plugin * plugin =
static_cast<Plugin *
>( it.current() );
277 if( plugin->d->m_library == library )
282 kdDebug( 1000 ) <<
"remove plugin " << name <<
endl;
297 if( pluginFound || !pluginEnabled )
301 Plugin *plugin = loadPlugin( parent, TQFile::encodeName(library) );
305 plugin->d->m_parentInstance =
instance;
306 plugin->
setXMLFile( (*pIt).m_relXMLFileName,
false,
false );
312 #include "plugin.moc"
A plugin is the way to add actions to an existing KParts application, or to a Part.
virtual TQString localXMLFile() const
Reimplemented for internal reasons.
Plugin(TQObject *parent=0, const char *name=0)
Construct a new KParts plugin.
virtual TQString xmlFile() const
Reimplemented for internal reasons.
static void loadPlugins(TQObject *parent, const TDEInstance *instance)
Load the plugin libraries from the directories appropriate to instance and make the Plugin objects ch...
static TQPtrList< Plugin > pluginObjects(TQObject *parent)
Returns a list of plugin objects loaded for parent.
virtual ~Plugin()
Destructor.
static TQValueList< Plugin::PluginInfo > pluginInfos(const TDEInstance *instance)
Look for plugins in the instance's "data" directory (+"/kpartplugins")
virtual TQString xmlFile() const
virtual TDEInstance * instance() const
virtual void setXMLFile(const TQString &file, bool merge=false, bool setXMLDoc=true)
KXMLGUIFactory * factory() const
virtual void setDOMDocument(const TQDomDocument &document, bool merge=false)
void insertChildClient(KXMLGUIClient *child)
virtual void setInstance(TDEInstance *instance)
void removeClient(KXMLGUIClient *client)
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
bool hasKey(const TQString &key) const
static TDELocale * locale()
TDEStandardDirs * dirs() const
TQCString instanceName() const
TDEConfig * config() const
void insertCatalogue(const TQString &catalog)
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
TQString findResource(const char *type, const TQString &filename) const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdError(int area=0)
kdbgstream kdDebug(int area=0)
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
TQString locateLocal(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
Struct holding information about a plugin.
TQString m_absXMLFileName
full path of most recent filename matching the relative filename
TQString m_relXMLFileName
relative filename, i.e. kpartplugins/name