File indexing completed on 2024-05-12 05:36:58
0001 /* 0002 0003 SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "module.h" 0009 0010 #include <KPluginFactory> 0011 #include <QQmlContext> 0012 #include <QQmlEngine> 0013 0014 KQuickConfigModule *Module::kcm() const 0015 { 0016 return m_kcm; 0017 } 0018 0019 QString Module::path() const 0020 { 0021 return m_path; 0022 } 0023 0024 void Module::setPath(const QString &path) 0025 { 0026 if (m_path == path) { 0027 return; 0028 } 0029 0030 // In case the user clicks from the UI we pass in the absolute path 0031 KPluginMetaData kcmMetaData(path); 0032 if (!kcmMetaData.isValid()) { 0033 // From the command line or DBus we usually get only the plugin id 0034 if (KPluginMetaData data(QStringLiteral("plasma/kcms/systemsettings/") + path); data.isValid()) { 0035 kcmMetaData = data; 0036 } else if (KPluginMetaData altData(QStringLiteral("kcms/") + path); altData.isValid()) { 0037 // Also check the old "kcms" namespace 0038 // TODO KF6 remove this branch of the if statement 0039 kcmMetaData = altData; 0040 } 0041 } 0042 0043 if (kcmMetaData.isValid()) { 0044 m_path = kcmMetaData.fileName(); 0045 Q_EMIT pathChanged(); 0046 0047 auto *ctx = QQmlEngine::contextForObject(this); 0048 auto engine = (std::shared_ptr<QQmlEngine>)ctx->engine(); 0049 auto kcm = KQuickConfigModuleLoader::loadModule(kcmMetaData, nullptr, QVariantList(), engine).plugin; 0050 0051 // Fixes double header in kcm_kaccounts 0052 if (ctx) { 0053 auto context = new QQmlContext(ctx->engine(), this); 0054 QQmlEngine::setContextForObject(kcm, context); 0055 } 0056 0057 m_kcm = kcm; 0058 0059 Q_EMIT kcmChanged(); 0060 } else { 0061 qWarning() << "Unknown module" << path << "requested"; 0062 } 0063 } 0064 0065 #include "moc_module.cpp"