Commit 7e871112 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Enable or not header style plugins

parent 3bc1cccc
......@@ -133,10 +133,12 @@ void HeaderStyleMenuManagerPrivate::initialize(KActionCollection *ac)
const QVector<MessageViewer::HeaderStylePlugin *> lstPlugin = MessageViewer::HeaderStylePluginManager::self()->pluginsList();
Q_FOREACH (MessageViewer::HeaderStylePlugin *plugin, lstPlugin) {
MessageViewer::HeaderStyleInterface *interface = plugin->createView(headerMenu, group, ac, q);
lstInterface.insert(plugin->name(), interface);
q->connect(interface, &HeaderStyleInterface::styleChanged, q, &HeaderStyleMenuManager::slotStyleChanged);
q->connect(interface, &HeaderStyleInterface::styleUpdated, q, &HeaderStyleMenuManager::styleUpdated);
if (plugin->isEnabled()) {
MessageViewer::HeaderStyleInterface *interface = plugin->createView(headerMenu, group, ac, q);
lstInterface.insert(plugin->name(), interface);
q->connect(interface, &HeaderStyleInterface::styleChanged, q, &HeaderStyleMenuManager::slotStyleChanged);
q->connect(interface, &HeaderStyleInterface::styleUpdated, q, &HeaderStyleMenuManager::styleUpdated);
}
}
}
......
......@@ -24,9 +24,11 @@ class MessageViewer::HeaderStylePluginPrivate
{
public:
HeaderStylePluginPrivate()
: mIsEnabled(false)
{
}
bool mIsEnabled;
};
HeaderStylePlugin::HeaderStylePlugin(QObject *parent)
......@@ -55,3 +57,13 @@ int HeaderStylePlugin::elidedTextSize() const
{
return -1;
}
void HeaderStylePlugin::setIsEnabled(bool enabled)
{
d->mIsEnabled = enabled;
}
bool HeaderStylePlugin::isEnabled() const
{
return d->mIsEnabled;
}
......@@ -47,6 +47,10 @@ public:
virtual QString alignment() const;
virtual int elidedTextSize() const;
void setIsEnabled(bool enabled);
bool isEnabled() const;
private:
HeaderStylePluginPrivate *const d;
};
......
......@@ -50,21 +50,19 @@ class HeaderStylePluginInfo
{
public:
HeaderStylePluginInfo()
: plugin(Q_NULLPTR)
: plugin(Q_NULLPTR),
isEnabled(false)
{
}
QString saveName() const;
KPluginMetaData metaData;
QString metaDataFileNameBaseName;
QString metaDataFileName;
PimCommon::PluginUtilData pluginData;
MessageViewer::HeaderStylePlugin *plugin;
bool isEnabled;
};
QString HeaderStylePluginInfo::saveName() const
{
return QFileInfo(metaData.fileName()).baseName();
}
class MessageViewer::HeaderStylePluginManagerPrivate
{
public:
......@@ -122,40 +120,42 @@ void HeaderStylePluginManagerPrivate::initializePluginList()
QList<int> listOrder;
while (i.hasPrevious()) {
HeaderStylePluginInfo info;
info.metaData = i.previous();
PimCommon::PluginUtilData pluginData = PimCommon::PluginUtil::createPluginMetaData(info.metaData);
mPluginDataList.append(pluginData);
const bool isPluginActivated = PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, pluginData.mEnableByDefault, pluginData.mIdentifier);
if (isPluginActivated) {
const QString version = info.metaData.version();
if (pluginVersion() == version) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.saveName())) {
continue;
}
const QVariant p = info.metaData.rawData().value(QStringLiteral("X-KDE-MessageViewer-Header-Order")).toVariant();
int order = -1;
if (p.isValid()) {
order = p.toInt();
}
int pos = 0;
for (; pos < listOrder.count(); ++pos) {
if (listOrder.at(pos) > order) {
pos--;
break;
}
const KPluginMetaData data = i.previous();
//1) get plugin data => name/description etc.
info.pluginData = PimCommon::PluginUtil::createPluginMetaData(data);
//2) look at if plugin is activated
const bool isPluginActivated = PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, info.pluginData.mEnableByDefault, info.pluginData.mIdentifier);
info.isEnabled = isPluginActivated;
info.metaDataFileNameBaseName = QFileInfo(data.fileName()).baseName();
info.metaDataFileName = data.fileName();
const QString version = data.version();
if (pluginVersion() == version) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.metaDataFileNameBaseName)) {
continue;
}
const QVariant p = data.rawData().value(QStringLiteral("X-KDE-MessageViewer-Header-Order")).toVariant();
int order = -1;
if (p.isValid()) {
order = p.toInt();
}
int pos = 0;
for (; pos < listOrder.count(); ++pos) {
if (listOrder.at(pos) > order) {
pos--;
break;
}
pos = qMax(0, pos);
listOrder.insert(pos, order);
info.plugin = Q_NULLPTR;
mPluginList.insert(pos, info);
unique.insert(info.saveName());
} else {
qCWarning(MESSAGEVIEWER_LOG) << "Plugin " << info.metaData.name() << " doesn't have correction plugin version. It will not be loaded.";
}
pos = qMax(0, pos);
listOrder.insert(pos, order);
info.plugin = Q_NULLPTR;
mPluginList.insert(pos, info);
unique.insert(info.metaDataFileNameBaseName);
} else {
qCWarning(MESSAGEVIEWER_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<HeaderStylePluginInfo>::iterator end(mPluginList.end());
......@@ -178,9 +178,12 @@ QVector<MessageViewer::HeaderStylePlugin *> HeaderStylePluginManagerPrivate::plu
void HeaderStylePluginManagerPrivate::loadPlugin(HeaderStylePluginInfo *item)
{
KPluginLoader pluginLoader(item->metaData.fileName());
KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
item->plugin = pluginLoader.factory()->create<MessageViewer::HeaderStylePlugin>(q, QVariantList() << item->saveName());
item->plugin = pluginLoader.factory()->create<MessageViewer::HeaderStylePlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
item->plugin->setIsEnabled(item->isEnabled);
item->pluginData.mHasConfigureDialog = false;
mPluginDataList.append(item->pluginData);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment