Pimcommon

pluginutil.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "pluginutil.h"
8#include <KConfigGroup>
9#include <KSharedConfig>
10
11namespace
12{
13inline QString pluginConfigFile()
14{
15 return QStringLiteral("pimpluginsrc");
16}
17}
18
19bool PimCommon::PluginUtil::isPluginActivated(const QStringList &enabledPluginsList,
20 const QStringList &disabledPluginsList,
21 bool isEnabledByDefault,
22 const QString &pluginId)
23{
24 if (pluginId.isEmpty()) {
25 return false;
26 }
27 const bool pluginEnabledByUser = enabledPluginsList.contains(pluginId);
28 const bool pluginDisabledByUser = disabledPluginsList.contains(pluginId);
29 if ((isEnabledByDefault && !pluginDisabledByUser) || (!isEnabledByDefault && pluginEnabledByUser)) {
30 return true;
31 }
32 return false;
33}
34
35QPair<QStringList, QStringList> PimCommon::PluginUtil::loadPluginSetting(const QString &groupName, const QString &prefixSettingKey)
36{
37 QPair<QStringList, QStringList> pair;
38 KSharedConfigPtr config = KSharedConfig::openConfig(pluginConfigFile());
39 QStringList enabledPlugins;
40 QStringList disabledPlugins;
41 if (config->hasGroup(groupName)) {
42 KConfigGroup grp = config->group(groupName);
43 enabledPlugins = grp.readEntry(QStringLiteral("%1Enabled").arg(prefixSettingKey), QStringList());
44 disabledPlugins = grp.readEntry(QStringLiteral("%1Disabled").arg(prefixSettingKey), QStringList());
45 }
46
47 pair.first = enabledPlugins;
48 pair.second = disabledPlugins;
49 return pair;
50}
51
52void PimCommon::PluginUtil::savePluginSettings(const QString &groupName,
53 const QString &prefixSettingKey,
54 const QStringList &enabledPluginsList,
55 const QStringList &disabledPluginsList)
56{
57 KSharedConfigPtr config = KSharedConfig::openConfig(pluginConfigFile());
58 KConfigGroup grp = config->group(groupName);
59 grp.writeEntry(QStringLiteral("%1Enabled").arg(prefixSettingKey), enabledPluginsList);
60 grp.writeEntry(QStringLiteral("%1Disabled").arg(prefixSettingKey), disabledPluginsList);
61}
62
63PimCommon::PluginUtilData PimCommon::PluginUtil::createPluginMetaData(const KPluginMetaData &metaData)
64{
65 PluginUtilData pluginData;
66 pluginData.mDescription = metaData.description();
67 pluginData.mName = metaData.name();
68 pluginData.mIdentifier = metaData.pluginId();
69 pluginData.mEnableByDefault = metaData.isEnabledByDefault();
70 return pluginData;
71}
KConfigGroup group(const QString &group)
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
QString pluginId() const
QString name() const
bool isEnabledByDefault() const
QString description() const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
The PluginUtilData class.
Definition pluginutil.h:23
T & first()
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.