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