27 #include <kpimutils/processes.h>
29 #include <kparts/componentfactory.h>
30 #include <kxmlguifactory.h>
31 #include <kaboutdata.h>
34 #include <kcomponentdata.h>
35 #include <kstandarddirs.h>
39 #include <QDBusConnection>
43 using namespace KontactInterface;
56 void removeInvisibleToolbarActions(
Plugin *plugin );
66 QByteArray partLibraryName;
67 QByteArray pluginName;
69 KParts::ReadOnlyPart *
part;
75 : KXMLGUIClient( core ), QObject( parent ), d( new Private )
77 setObjectName( appName );
78 core->factory()->addClient(
this );
79 KGlobal::locale()->insertCatalog( appName );
81 d->pluginName = pluginName ? pluginName : appName;
101 return d->identifier;
126 d->executableName = bin;
131 return d->executableName;
136 d->partLibraryName = libName;
141 Q_UNUSED( serviceType );
157 KPluginLoader loader( d->partLibraryName );
158 KPluginFactory *factory = loader.factory();
159 kDebug() <<
"filename:" << loader.fileName();
160 kDebug() <<
"libname:" << d->partLibraryName;
163 if ( factory->componentData().isValid() ) {
164 kDebug() <<
"returning factory component aboutdata";
165 return factory->componentData().aboutData();
172 kDebug() <<
"Unable to load component data for" << loader.fileName()
173 <<
"trying to use the old style plugin system now.";
174 const KComponentData instance =
175 KParts::Factory::partComponentDataFromLibrary( d->partLibraryName );
176 if ( instance.isValid() ) {
177 return instance.aboutData();
179 kDebug() <<
"Invalid instance, unable to get about information!";
184 kError() <<
"Cannot load instance for" <<
title();
193 connect( d->part, SIGNAL(destroyed()), SLOT(partDestroyed()) );
194 d->removeInvisibleToolbarActions(
this);
208 if ( d->serviceName.isEmpty() ) {
209 d->serviceName =
"org.kde." + objectName().toLatin1();
211 const QString pid = QString::number( getpid() );
212 d->serviceName.append(
".unique-" + pid );
214 QDBusConnection::sessionBus().registerService( d->serviceName );
216 return d->serviceName;
226 d->newActions.append( action );
231 d->syncActions.append( action );
236 return d->newActions;
241 return d->syncActions;
246 return QStringList();
290 void Plugin::Private::partDestroyed()
295 void Plugin::Private::removeInvisibleToolbarActions(
Plugin *plugin )
297 if ( pluginName.isEmpty() ) {
307 QDomDocument doc = part->domDocument();
308 QDomElement docElem = doc.documentElement();
310 for ( QDomElement containerElem = docElem.firstChildElement();
311 !containerElem.isNull(); containerElem = containerElem.nextSiblingElement() ) {
312 if ( QString::compare( containerElem.tagName(),
"ToolBar", Qt::CaseInsensitive ) == 0 ) {
314 QDomElement actionElem = containerElem.firstChildElement();
315 while ( !actionElem.isNull() ) {
316 QDomElement nextActionElem = actionElem.nextSiblingElement();
317 if ( QString::compare( actionElem.tagName(),
"Action", Qt::CaseInsensitive ) == 0 ) {
319 if ( hideActions.contains( actionElem.attribute(
"name" ) ) ) {
321 containerElem.removeChild( actionElem );
324 actionElem = nextActionElem;
335 const QString newAppFile =
336 KStandardDirs::locateLocal(
"data",
"kontact/default-" + pluginName +
".rc" );
337 QFile file( newAppFile );
338 if ( !file.open( QFile::WriteOnly ) ) {
339 kWarning() <<
"error writing to" << newAppFile;
342 file.write( doc.toString().toUtf8() );
348 void Plugin::Private::setXmlFiles()
350 const QString newAppFile =
351 KStandardDirs::locateLocal(
"data",
"kontact/default-" + pluginName +
".rc" );
352 const QString localFile =
353 KStandardDirs::locateLocal(
"data",
"kontact/local-" + pluginName +
".rc" );
354 if ( part->xmlFile() != newAppFile || part->localXMLFile() != localFile ) {
355 part->replaceXMLFile( newAppFile, localFile );
367 if ( d->executableName.isEmpty() ) {
371 KPIMUtils::activateWindowForProcess( d->executableName );
373 KRun::runCommand( d->executableName, 0 );
390 d->hasPart = hasPart;
413 #include "plugin.moc"