kcmoduleloader.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qfile.h>
00023
00024 #include <kapplication.h>
00025 #include <kmessagebox.h>
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 #include <kparts/componentfactory.h>
00029
00030 #include "kcmoduleloader.h"
00031
00032 KCModule* KCModuleLoader::load(const KCModuleInfo &mod, const QString &libname, KLibLoader *loader, QWidget * parent, const char * name, const QStringList & args )
00033 {
00034
00035
00036
00037 KLibrary *lib = loader->library(QFile::encodeName(libname.arg(mod.library())));
00038 if (lib) {
00039 QString initSym("init_");
00040 initSym += libname.arg(mod.library());
00041
00042 if ( lib->hasSymbol(QFile::encodeName(initSym)) )
00043 {
00044
00045
00046 KLibFactory *factory = lib->factory();
00047 if ( factory )
00048 {
00049 KCModule *module = KParts::ComponentFactory::createInstanceFromFactory<KCModule>( factory, parent, name ? name : mod.handle().latin1(), args );
00050 if (module)
00051 return module;
00052 }
00053
00054 kdDebug(1208) << "Unable to load module using ComponentFactory! Falling back to old loader." << endl;
00055 }
00056
00057
00058 QString factory("create_%1");
00059 void *create = lib->symbol(QFile::encodeName(factory.arg(mod.handle())));
00060
00061 if (create)
00062 {
00063
00064 KCModule* (*func)(QWidget *, const char *);
00065 func = (KCModule* (*)(QWidget *, const char *)) create;
00066 return func( parent, name ? name : mod.handle().latin1() );
00067 }
00068
00069 lib->unload();
00070 }
00071 return 0;
00072 }
00073
00074
00075 KCModule* KCModuleLoader::loadModule(const KCModuleInfo &mod, bool withfallback, QWidget * parent, const char * name, const QStringList & args )
00076 {
00077
00078
00079
00080
00081
00082
00083 if (!mod.library().isEmpty())
00084 {
00085
00086
00087 KLibLoader *loader = KLibLoader::self();
00088
00089 KCModule *module = load(mod, "kcm_%1", loader, parent, name, args );
00090 if (!module) {
00091
00092
00093 if ( !KLibLoader::findLibrary( QCString( "libkcm_" ) + QFile::encodeName( mod.library() ) ).isEmpty() )
00094 module = load(mod, "libkcm_%1", loader, parent, name, args );
00095 }
00096 if (module)
00097 return module;
00098 }
00099 else
00100 kdWarning() << "Module " << mod.fileName() << " doesn't specify a library!" << endl;
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 if(withfallback)
00111 KApplication::startServiceByDesktopPath(mod.fileName(), QString::null);
00112 return 0;
00113 }
00114
00115 KCModule* KCModuleLoader::loadModule(const QString &module, QWidget *parent,
00116 const char *name, const QStringList & args)
00117 {
00118 KService::Ptr serv = KService::serviceByDesktopName(module);
00119 if (!serv)
00120 {
00121 kdError(1208) << i18n("Module %1 not found!").arg(module) << endl;
00122 return 0;
00123 }
00124
00125 KCModuleInfo mod(serv);
00126
00127 return loadModule(mod, false, parent, name, args);
00128 }
00129
00130 void KCModuleLoader::unloadModule(const KCModuleInfo &mod)
00131 {
00132
00133 KLibLoader *loader = KLibLoader::self();
00134
00135
00136 QString libname("libkcm_%1");
00137 loader->unloadLibrary(QFile::encodeName(libname.arg(mod.library())));
00138
00139 libname = "kcm_%1";
00140 loader->unloadLibrary(QFile::encodeName(libname.arg(mod.library())));
00141 }
00142
00143 void KCModuleLoader::showLastLoaderError(QWidget *parent)
00144 {
00145 KMessageBox::detailedError(parent,
00146 i18n("There was an error loading the module."),i18n("<qt><p>The diagnostics is:<br>%1"
00147 "<p>Possible reasons:</p><ul><li>An error occurred during your last "
00148 "KDE upgrade leaving an orphaned control module<li>You have old third party "
00149 "modules lying around.</ul><p>Check these points carefully and try to remove "
00150 "the module mentioned in the error message. If this fails, consider contacting "
00151 "your distributor or packager.</p></qt>")
00152 .arg(KLibLoader::self()->lastErrorMessage()));
00153
00154 }
00155
00156
This file is part of the documentation for kutils Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 23 17:12:43 2004 by
doxygen 1.3.8-20040913 written by
Dimitri van Heesch, © 1997-2003