00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "kcmoduleloader.h"
00025
00026 #include <QtCore/QFile>
00027 #include <QtGui/QLabel>
00028 #include <QtGui/QLayout>
00029
00030 #include <kapplication.h>
00031 #include <kpluginloader.h>
00032 #include <kdebug.h>
00033 #include <klocale.h>
00034 #include <kmessagebox.h>
00035 #include <klibloader.h>
00036
00037 using namespace KCModuleLoader;
00038
00039
00044 class KCMError : public KCModule
00045 {
00046 public:
00047 KCMError( const QString& msg, const QString& details, QWidget* parent )
00048 : KCModule( KGlobal::mainComponent(), parent )
00049 {
00050 QVBoxLayout* topLayout = new QVBoxLayout( this );
00051 QLabel *lab = new QLabel( msg, this );
00052 lab->setWordWrap(true);
00053 topLayout->addWidget( lab );
00054 lab = new QLabel(details, this );
00055 lab->setWordWrap(true);
00056 topLayout->addWidget( lab );
00057 }
00058 };
00059
00060
00061 KCModule *KCModuleLoader::loadModule(const QString &module, ErrorReporting report, QWidget *parent, const QStringList &args)
00062 {
00063 return loadModule( KCModuleInfo( module ), report, parent, args );
00064 }
00065
00066 KCModule* KCModuleLoader::loadModule(const KCModuleInfo& mod, ErrorReporting report, QWidget* parent, const QStringList& args )
00067 {
00068
00069
00070
00071
00072
00073
00074 if ( !mod.service() )
00075 return reportError( report,
00076 i18n("The module %1 could not be found.",
00077 mod.moduleName() ), i18n("<qt><p>The diagnostics is:<br />The desktop file %1 could not be found.</p></qt>", mod.fileName()), parent );
00078 if( mod.service()->noDisplay() )
00079 return reportError( report, i18n( "The module %1 is disabled.", mod.moduleName() ),
00080 i18n( "<qt><p>Either the hardware/software the module configures is not available or the module has been disabled by the administrator.</p></qt>" ),
00081 parent );
00082
00083 if (!mod.library().isEmpty())
00084 {
00085 QString error;
00086 QVariantList args2;
00087 foreach (const QString &arg, args) {
00088 args2 << arg;
00089 }
00090 KCModule *module = KService::createInstance<KCModule>(mod.service(), parent, args2, &error);
00091 if (module) {
00092 return module;
00093 }
00094
00095 int error2 = 0;
00096 module = KService::createInstance<KCModule>(mod.service(), parent, args, &error2);
00097 if (module) {
00098 kWarning(1208) << "This module still uses K_EXPORT_COMPONENT_FACTORY. Please port it to use KPluginFactory and K_EXPORT_PLUGIN.";
00099 return module;
00100 }
00101 error += KLibLoader::errorString(error2);
00102
00103 {
00104
00105 KLibrary *lib = KLibLoader::self()->library(mod.library());
00106 if (lib) {
00107 KCModule *(*create)(QWidget *, const char *);
00108 QByteArray factorymethod("create_");
00109 factorymethod += mod.handle().toLatin1();
00110 create = reinterpret_cast<KCModule *(*)(QWidget *, const char*)>(lib->resolveFunction(factorymethod));
00111 if (create) {
00112 return create(parent, mod.handle().toLatin1());
00113 kFatal(1208) << "This module still uses a custom factory method (" << factorymethod << "). This is not supported anymore. Please fix the module.";
00114 } else {
00115 kWarning(1208) << "This module has no valid entry symbol at all. The reason could be that it's still using K_EXPORT_COMPONENT_FACTORY with a custom X-KDE-FactoryName which is not supported anymore";
00116 }
00117 lib->unload();
00118 }
00119 }
00120
00121 return reportError(report, error, QString(), parent);
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 return reportError( report,
00133 i18n("The module %1 is not a valid configuration module.", mod.moduleName() ),
00134 i18n("<qt>The diagnostics is:<br />The desktop file %1 does not specify a library.</qt>", mod.fileName()), parent );
00135 }
00136
00137
00138 void KCModuleLoader::unloadModule(const KCModuleInfo &mod)
00139 {
00140
00141 KLibLoader *loader = KLibLoader::self();
00142
00143
00144 QString libname("lib%1");
00145 loader->unloadLibrary(libname.arg(mod.library()));
00146
00147 loader->unloadLibrary(mod.library());
00148 }
00149
00150 void KCModuleLoader::showLastLoaderError(QWidget *parent)
00151 {
00152 KMessageBox::detailedError(parent,
00153 i18n("There was an error loading the module."),i18n("<qt>The diagnostics is:<br />%1"
00154 "<p>Possible reasons:</p><ul><li>An error occurred during your last "
00155 "KDE upgrade leaving an orphaned control module</li><li>You have old third party "
00156 "modules lying around.</li></ul><p>Check these points carefully and try to remove "
00157 "the module mentioned in the error message. If this fails, consider contacting "
00158 "your distributor or packager.</p></qt>",
00159 KLibLoader::self()->lastErrorMessage()));
00160
00161 }
00162
00163 KCModule* KCModuleLoader::reportError( ErrorReporting report, const QString & text,
00164 const QString &details, QWidget * parent )
00165 {
00166 QString realDetails = details;
00167 if (realDetails.isNull()) {
00168 realDetails = i18n("<qt><p>Possible reasons:<ul><li>An error occurred during your last "
00169 "KDE upgrade leaving an orphaned control module</li><li>You have old third party "
00170 "modules lying around.</li></ul></p><p>Check these points carefully and try to remove "
00171 "the module mentioned in the error message. If this fails, consider contacting "
00172 "your distributor or packager.</p></qt>");
00173 }
00174 if (report & KCModuleLoader::Dialog) {
00175 KMessageBox::detailedError(parent, text, realDetails);
00176 }
00177 if (report & KCModuleLoader::Inline) {
00178 return new KCMError(text, realDetails, parent);
00179 }
00180 return 0;
00181 }
00182
00183