diff --git a/src/kcmoduleloader.cpp b/src/kcmoduleloader.cpp index 76adcdc..6a0d31f 100644 --- a/src/kcmoduleloader.cpp +++ b/src/kcmoduleloader.cpp @@ -1,170 +1,170 @@ /* Copyright (c) 1999 Matthias Hoelzer-Kluepfel Copyright (c) 2000 Matthias Elter Copyright (c) 2003,2004,2006 Matthias Kretz Copyright (c) 2004 Frans Englich This file is part of the KDE project This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2, as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kcmoduleloader.h" #include "kcmoduleqml_p.h" #include #include #include #include #include #include #include #include #include #include using namespace KCModuleLoader; /***************************************************************/ /** * When something goes wrong in loading the module, this one * jumps in as a "dummy" module. */ class KCMError : public KCModule { public: KCMError(const QString &msg, const QString &details, QWidget *parent) : KCModule(parent) { QVBoxLayout *topLayout = new QVBoxLayout(this); QLabel *lab = new QLabel(msg, this); lab->setWordWrap(true); topLayout->addWidget(lab); lab = new QLabel(details, this); lab->setWordWrap(true); topLayout->addWidget(lab); } }; /***************************************************************/ KCModule *KCModuleLoader::loadModule(const QString &module, ErrorReporting report, QWidget *parent, const QStringList &args) { return loadModule(KCModuleInfo(module), report, parent, args); } KCModule *KCModuleLoader::loadModule(const KCModuleInfo &mod, ErrorReporting report, QWidget *parent, const QStringList &args) { /* * Simple libraries as modules are the easiest case: * We just have to load the library and get the module * from the factory. */ if (!mod.service()) return reportError(report, i18n("The module %1 could not be found.", mod.moduleName()), i18n("

The diagnosis is:
The desktop file %1 could not be found.

", mod.fileName()), parent); if (mod.service()->noDisplay()) return reportError(report, i18n("The module %1 is disabled.", mod.moduleName()), i18n("

Either the hardware/software the module configures is not available or the module has been disabled by the administrator.

"), parent); if (!mod.library().isEmpty()) { QString error; QVariantList args2; args2.reserve(args.count()); for (const QString &arg : args) { args2 << arg; } KCModule *module = mod.service()->createInstance(parent, args2, &error); if (module) { return module; } else { KPluginLoader loader(KPluginLoader::findPlugin(QLatin1String("kcms/") + mod.service()->library())); KPluginFactory* factory = loader.factory(); if (!factory) { qWarning() << "Error loading plugin:" << loader.errorString(); } else { KQuickAddons::ConfigModule *cm = factory->create(); if (!cm) { qWarning() << "Error creating object from plugin" << loader.fileName(); } module = new KCModuleQml(cm, parent, args2); return module; } } //#ifndef NDEBUG { // get the create_ function QLibrary lib(KPluginLoader::findPlugin(mod.library())); if (lib.load()) { KCModule *(*create)(QWidget *, const char *); QByteArray factorymethod("create_"); factorymethod += mod.handle().toLatin1(); create = reinterpret_cast(lib.resolve(factorymethod.constData())); if (create) { return create(parent, mod.handle().toLatin1().constData()); } else { qWarning() << "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"; } lib.unload(); } } //#endif // NDEBUG return reportError(report, error, QString(), parent); } /* * Ok, we could not load the library. * Try to run it as an executable. * This must not be done when calling from kcmshell, or you'll * have infinite recursion * (startService calls kcmshell which calls modloader which calls startService...) * */ return reportError(report, i18n("The module %1 is not a valid configuration module.", mod.moduleName()), i18n("The diagnosis is:
The desktop file %1 does not specify a library.
", mod.fileName()), parent); } void KCModuleLoader::unloadModule(const KCModuleInfo &mod) { // get the library loader instance KPluginLoader loader(mod.library()); loader.unload(); } KCModule *KCModuleLoader::reportError(ErrorReporting report, const QString &text, const QString &details, QWidget *parent) { QString realDetails = details; if (realDetails.isNull()) { realDetails = i18n("

Possible reasons:

  • An error occurred during your last " - "KDE upgrade leaving an orphaned control module
  • You have old third party " + "system upgrade, leaving an orphaned control module behind
  • You have old third party " "modules lying around.

Check these points carefully and try to remove " "the module mentioned in the error message. If this fails, consider contacting " "your distributor or packager.

"); } if (report & KCModuleLoader::Dialog) { KMessageBox::detailedError(parent, text, realDetails); } if (report & KCModuleLoader::Inline) { return new KCMError(text, realDetails, parent); } return nullptr; }