27 #include <kpimutils/processes.h>
29 #include <kparts/componentfactory.h>
30 #include <kxmlguifactory.h>
31 #include <kaboutdata.h>
33 #include <klocalizedstring.h>
35 #include <kcomponentdata.h>
36 #include <kstandarddirs.h>
40 #include <QDBusConnection>
41 #include <QDomDocument>
45 using namespace KontactInterface;
58 void removeInvisibleToolbarActions(
Plugin *plugin );
68 QByteArray partLibraryName;
69 QByteArray pluginName;
71 KParts::ReadOnlyPart *
part;
77 : KXMLGUIClient( core ), QObject( parent ), d( new Private )
79 setObjectName( appName );
80 core->factory()->addClient(
this );
81 KGlobal::locale()->insertCatalog( appName );
83 d->pluginName = pluginName ? pluginName : appName;
103 return d->identifier;
128 d->executableName = bin;
133 return d->executableName;
138 d->partLibraryName = libName;
143 Q_UNUSED( serviceType );
159 KPluginLoader loader( d->partLibraryName );
160 KPluginFactory *factory = loader.factory();
161 kDebug() <<
"filename:" << loader.fileName();
162 kDebug() <<
"libname:" << d->partLibraryName;
165 if ( factory->componentData().isValid() ) {
166 kDebug() <<
"returning factory component aboutdata";
167 return factory->componentData().aboutData();
174 kDebug() <<
"Unable to load component data for" << loader.fileName()
175 <<
"trying to use the old style plugin system now.";
176 const KComponentData instance =
177 KParts::Factory::partComponentDataFromLibrary( d->partLibraryName );
178 if ( instance.isValid() ) {
179 return instance.aboutData();
181 kDebug() <<
"Invalid instance, unable to get about information!";
186 kError() <<
"Cannot load instance for" <<
title();
195 connect( d->part, SIGNAL(destroyed()), SLOT(partDestroyed()) );
196 d->removeInvisibleToolbarActions(
this );
210 if ( d->serviceName.isEmpty() ) {
211 d->serviceName =
"org.kde." + objectName().toLatin1();
213 const QString pid = QString::number( getpid() );
214 d->serviceName.append(
".unique-" + pid );
216 QDBusConnection::sessionBus().registerService( d->serviceName );
218 return d->serviceName;
228 d->newActions.append( action );
233 d->syncActions.append( action );
238 return d->newActions;
243 return d->syncActions;
248 return QStringList();
292 void Plugin::Private::partDestroyed()
297 void Plugin::Private::removeInvisibleToolbarActions(
Plugin *plugin )
299 if ( pluginName.isEmpty() ) {
309 QDomDocument doc = part->domDocument();
310 QDomElement docElem = doc.documentElement();
312 for ( QDomElement containerElem = docElem.firstChildElement();
313 !containerElem.isNull(); containerElem = containerElem.nextSiblingElement() ) {
314 if ( QString::compare( containerElem.tagName(),
"ToolBar", Qt::CaseInsensitive ) == 0 ) {
316 QDomElement actionElem = containerElem.firstChildElement();
317 while ( !actionElem.isNull() ) {
318 QDomElement nextActionElem = actionElem.nextSiblingElement();
319 if ( QString::compare( actionElem.tagName(),
"Action", Qt::CaseInsensitive ) == 0 ) {
321 if ( hideActions.contains( actionElem.attribute(
"name" ) ) ) {
323 containerElem.removeChild( actionElem );
326 actionElem = nextActionElem;
337 const QString newAppFile =
338 KStandardDirs::locateLocal(
"data",
"kontact/default-" + pluginName +
".rc" );
339 QFile file( newAppFile );
340 if ( !file.open( QFile::WriteOnly ) ) {
341 kWarning() <<
"error writing to" << newAppFile;
344 file.write( doc.toString().toUtf8() );
350 void Plugin::Private::setXmlFiles()
352 const QString newAppFile =
353 KStandardDirs::locateLocal(
"data",
"kontact/default-" + pluginName +
".rc" );
354 const QString localFile =
355 KStandardDirs::locateLocal(
"data",
"kontact/local-" + pluginName +
".rc" );
356 if ( part->xmlFile() != newAppFile || part->localXMLFile() != localFile ) {
357 part->replaceXMLFile( newAppFile, localFile );
369 if ( d->executableName.isEmpty() ) {
373 KPIMUtils::activateWindowForProcess( d->executableName );
375 KRun::runCommand( d->executableName, 0 );
392 d->hasPart = hasPart;
415 #include "moc_plugin.cpp"