File indexing completed on 2024-05-12 05:29:22

0001 /*
0002  *   SPDX-FileCopyrightText: 2011-2016 Ivan Cukic <ivan.cukic@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 // Self
0008 #include "Plugin.h"
0009 
0010 // KDE
0011 #include <ksharedconfig.h>
0012 
0013 // Utils
0014 #include <utils/d_ptr_implementation.h>
0015 
0016 // Local
0017 #include "DebugApplication.h"
0018 
0019 class Plugin::Private
0020 {
0021 public:
0022     Private()
0023         : config(nullptr)
0024     {
0025     }
0026 
0027     QString name;
0028     KSharedConfig::Ptr config;
0029 };
0030 
0031 Plugin::Plugin(QObject *parent)
0032     : Module(QString(), parent)
0033     , d()
0034 {
0035 }
0036 
0037 Plugin::~Plugin()
0038 {
0039 }
0040 
0041 KConfigGroup Plugin::config() const
0042 {
0043     if (d->name.isEmpty()) {
0044         qCWarning(KAMD_LOG_APPLICATION) << "The plugin needs a name in order to have a config section";
0045         return KConfigGroup();
0046     }
0047 
0048     if (!d->config) {
0049         d->config = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerd-pluginsrc"));
0050     }
0051 
0052     return d->config->group(QStringLiteral("Plugin-") + d->name);
0053 }
0054 
0055 void Plugin::setName(const QString &name)
0056 {
0057     Q_ASSERT_X(d->name.isEmpty(), "Plugin::setName", "The name can not be set twice");
0058     Q_ASSERT_X(!name.isEmpty(), "Plugin::setName", "The name can not be empty");
0059 
0060     qCDebug(KAMD_LOG_APPLICATION) << "Setting the name of " << (void *)this << " to " << name;
0061     d->name = name;
0062 }
0063 
0064 QString Plugin::name() const
0065 {
0066     return d->name;
0067 }
0068 
0069 bool Plugin::init(QHash<QString, QObject *> &modules)
0070 {
0071     if (!name().isEmpty()) {
0072         modules[name()] = this;
0073     }
0074 
0075     return true;
0076 }
0077 
0078 #include "moc_Plugin.cpp"