27 #include <kpimutils/processes.h>
29 #include <kparts/componentfactory.h>
30 #include <kxmlguifactory.h>
31 #include <kaboutdata.h>
35 #include <kcomponentdata.h>
36 #include <kstandarddirs.h>
40 #include <QDBusConnection>
44 using namespace KontactInterface;
57 void removeInvisibleToolbarActions(
Plugin *plugin );
67 QByteArray partLibraryName;
68 QByteArray pluginName;
70 KParts::ReadOnlyPart *
part;
76 : KXMLGUIClient( core ), QObject( parent ), d( new Private )
78 setObjectName( appName );
79 core->factory()->addClient(
this );
80 KGlobal::locale()->insertCatalog( appName );
82 d->pluginName = pluginName ? pluginName : appName;
102 return d->identifier;
127 d->executableName = bin;
132 return d->executableName;
137 d->partLibraryName = libName;
142 Q_UNUSED( serviceType );
158 KPluginLoader loader( d->partLibraryName );
159 KPluginFactory *factory = loader.factory();
160 kDebug() <<
"filename:" << loader.fileName();
161 kDebug() <<
"libname:" << d->partLibraryName;
164 if ( factory->componentData().isValid() ) {
165 kDebug() <<
"returning factory component aboutdata";
166 return factory->componentData().aboutData();
173 kDebug() <<
"Unable to load component data for" << loader.fileName()
174 <<
"trying to use the old style plugin system now.";
175 const KComponentData instance =
176 KParts::Factory::partComponentDataFromLibrary( d->partLibraryName );
177 if ( instance.isValid() ) {
178 return instance.aboutData();
180 kDebug() <<
"Invalid instance, unable to get about information!";
185 kError() <<
"Cannot load instance for" <<
title();
194 connect( d->part, SIGNAL(destroyed()), SLOT(partDestroyed()) );
195 d->removeInvisibleToolbarActions(
this );
209 if ( d->serviceName.isEmpty() ) {
210 d->serviceName =
"org.kde." + objectName().toLatin1();
212 const QString pid = QString::number( getpid() );
213 d->serviceName.append(
".unique-" + pid );
215 QDBusConnection::sessionBus().registerService( d->serviceName );
217 return d->serviceName;
227 d->newActions.append( action );
232 d->syncActions.append( action );
237 return d->newActions;
242 return d->syncActions;
247 return QStringList();
291 void Plugin::Private::partDestroyed()
296 void Plugin::Private::removeInvisibleToolbarActions(
Plugin *plugin )
298 if ( pluginName.isEmpty() ) {
308 QDomDocument doc = part->domDocument();
309 QDomElement docElem = doc.documentElement();
311 for ( QDomElement containerElem = docElem.firstChildElement();
312 !containerElem.isNull(); containerElem = containerElem.nextSiblingElement() ) {
313 if ( QString::compare( containerElem.tagName(),
"ToolBar", Qt::CaseInsensitive ) == 0 ) {
315 QDomElement actionElem = containerElem.firstChildElement();
316 while ( !actionElem.isNull() ) {
317 QDomElement nextActionElem = actionElem.nextSiblingElement();
318 if ( QString::compare( actionElem.tagName(),
"Action", Qt::CaseInsensitive ) == 0 ) {
320 if ( hideActions.contains( actionElem.attribute(
"name" ) ) ) {
322 containerElem.removeChild( actionElem );
325 actionElem = nextActionElem;
336 const QString newAppFile =
337 KStandardDirs::locateLocal(
"data",
"kontact/default-" + pluginName +
".rc" );
338 QFile file( newAppFile );
339 if ( !file.open( QFile::WriteOnly ) ) {
340 kWarning() <<
"error writing to" << newAppFile;
343 file.write( doc.toString().toUtf8() );
349 void Plugin::Private::setXmlFiles()
351 const QString newAppFile =
352 KStandardDirs::locateLocal(
"data",
"kontact/default-" + pluginName +
".rc" );
353 const QString localFile =
354 KStandardDirs::locateLocal(
"data",
"kontact/local-" + pluginName +
".rc" );
355 if ( part->xmlFile() != newAppFile || part->localXMLFile() != localFile ) {
356 part->replaceXMLFile( newAppFile, localFile );
368 if ( d->executableName.isEmpty() ) {
372 KPIMUtils::activateWindowForProcess( d->executableName );
374 KRun::runCommand( d->executableName, 0 );
391 d->hasPart = hasPart;
414 #include "moc_plugin.cpp"