00001 /* This file is part of the KDE project 00002 * Copyright (c) 2006 Boudewijn Rempt (boud@valdyas.org) 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include <QString> 00021 #include <QStringList> 00022 00023 #include <kdebug.h> 00024 #include <kservice.h> 00025 #include <kservicetypetrader.h> 00026 #include <kstaticdeleter.h> 00027 00028 #include <KoPluginLoader.h> 00029 00030 KoPluginLoader::KoPluginLoader() 00031 { 00032 } 00033 00034 KoPluginLoader::~KoPluginLoader() 00035 { 00036 } 00037 00038 KoPluginLoader *KoPluginLoader::m_singleton = 0; 00039 static KStaticDeleter<KoPluginLoader> staticShapeRegistryDeleter; 00040 00041 KoPluginLoader* KoPluginLoader::instance() 00042 { 00043 if(KoPluginLoader::m_singleton == 0) 00044 { 00045 staticShapeRegistryDeleter.setObject(m_singleton, new KoPluginLoader()); 00046 } 00047 return KoPluginLoader::m_singleton; 00048 } 00049 00050 void KoPluginLoader::load(const QString & serviceType, const QString & versionString) 00051 { 00052 // Don't load the same plugins again 00053 if (m_loadedServiceTypes.contains(serviceType)) { 00054 return; 00055 } 00056 m_loadedServiceTypes << serviceType; 00057 00058 const KService::List offers = KServiceTypeTrader::self()->query(serviceType, 00059 QString::fromLatin1("(Type == 'Service') and (%1)").arg(versionString)); 00060 00061 kDebug(30008) << ">>>>>>>>>>>>>>>>>>>>>>>> KoPluginLoader searching for plugins, " << serviceType << " " << offers.count() << " found\n"; 00062 00063 foreach(KService::Ptr service, offers) { 00064 int errCode = 0; 00065 QObject * plugin = KService::createInstance<QObject>(service, this, QStringList(), &errCode ); 00066 if ( plugin ) { 00067 kDebug(30008) <<">>>>>>>>>>>>>>>>>>>>>>>>>>> found plugin '"<< service->name() << "'\n"; 00068 delete plugin; 00069 } 00070 else { 00071 kWarning(30008) <<"loading plugin '" << service->name() << "' failed, "<< KLibLoader::errorString( errCode ) << " ("<< errCode << ")\n"; 00072 } 00073 } 00074 } 00075 #include "KoPluginLoader.moc"