Commit 99df0b36 authored by Laurent Montel's avatar Laurent Montel 😁

Add more plugins

parent 9bee07e5
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 "plugineditorcheckbeforesend.h"
using namespace MessageComposer;
class MessageComposer::PluginEditorCheckBeforeSendPrivate
{
public:
PluginEditorCheckBeforeSendPrivate()
{
}
};
PluginEditorCheckBeforeSend::PluginEditorCheckBeforeSend(QObject *parent)
: QObject(parent),
d(new MessageComposer::PluginEditorCheckBeforeSendPrivate)
{
}
PluginEditorCheckBeforeSend::~PluginEditorCheckBeforeSend()
{
delete d;
}
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
*/
#ifndef PLUGINEDITORCHECKBEFORESEND_H
#define PLUGINEDITORCHECKBEFORESEND_H
#include <QObject>
#include "messagecomposer_export.h"
namespace MessageComposer
{
class PluginEditorCheckBeforeSendPrivate;
class PluginEditorCheckBeforeSendInterface;
class MESSAGECOMPOSER_EXPORT PluginEditorCheckBeforeSend : public QObject
{
Q_OBJECT
public:
explicit PluginEditorCheckBeforeSend(QObject *parent = Q_NULLPTR);
~PluginEditorCheckBeforeSend();
virtual PluginEditorCheckBeforeSendInterface *createInterface(QWidget *parent) = 0;
private:
PluginEditorCheckBeforeSendPrivate *const d;
};
}
#endif // PLUGINEDITORCHECKBEFORESEND_H
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 "plugineditorcheckbeforesendinterface.h"
using namespace MessageComposer;
class MessageComposer::PluginEditorCheckBeforeSendInterfacePrivate
{
public:
PluginEditorCheckBeforeSendInterfacePrivate()
{
}
};
PluginEditorCheckBeforeSendInterface::PluginEditorCheckBeforeSendInterface(QObject *parent)
: QObject(parent),
d(new MessageComposer::PluginEditorCheckBeforeSendInterfacePrivate)
{
}
PluginEditorCheckBeforeSendInterface::~PluginEditorCheckBeforeSendInterface()
{
delete d;
}
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
*/
#ifndef PLUGINEDITORCHECKBEFORESENDINTERFACE_H
#define PLUGINEDITORCHECKBEFORESENDINTERFACE_H
#include <QObject>
#include "messagecomposer_export.h"
namespace MessageComposer
{
class PluginEditorCheckBeforeSendInterfacePrivate;
class MESSAGECOMPOSER_EXPORT PluginEditorCheckBeforeSendInterface : public QObject
{
Q_OBJECT
public:
explicit PluginEditorCheckBeforeSendInterface(QObject *parent = Q_NULLPTR);
~PluginEditorCheckBeforeSendInterface();
private:
PluginEditorCheckBeforeSendInterfacePrivate *const d;
};
}
#endif // PLUGINEDITORCHECKBEFORESENDINTERFACE_H
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 "plugineditorcheckbeforesendmanager.h"
#include "plugineditorcheckbeforesend.h"
#include <QFileInfo>
#include <QSet>
#include <QDebug>
#include <KPluginLoader>
#include <kpluginmetadata.h>
#include <KPluginFactory>
using namespace MessageComposer;
class PluginEditorCheckBeforeSendManagerInstancePrivate
{
public:
PluginEditorCheckBeforeSendManagerInstancePrivate()
: pluginManager(new PluginEditorCheckBeforeSendManager)
{
}
~PluginEditorCheckBeforeSendManagerInstancePrivate()
{
delete pluginManager;
}
PluginEditorCheckBeforeSendManager *pluginManager;
};
class PluginEditorCheckBeforeSendInfo
{
public:
PluginEditorCheckBeforeSendInfo()
: plugin(Q_NULLPTR)
{
}
QString saveName() const;
KPluginMetaData metaData;
PluginEditorCheckBeforeSend *plugin;
};
Q_GLOBAL_STATIC(PluginEditorCheckBeforeSendManagerInstancePrivate, sInstance)
namespace
{
QString pluginVersion()
{
return QStringLiteral("1.0");
}
}
class MessageComposer::PluginEditorCheckBeforeSendManagerPrivate
{
public:
PluginEditorCheckBeforeSendManagerPrivate(PluginEditorCheckBeforeSendManager *qq)
: q(qq)
{
initializePlugins();
}
void loadPlugin(PluginEditorCheckBeforeSendInfo *item);
QVector<PluginEditorCheckBeforeSend *> pluginsList() const;
bool initializePlugins();
QVector<PluginEditorCheckBeforeSendInfo> mPluginList;
PluginEditorCheckBeforeSendManager *q;
};
bool PluginEditorCheckBeforeSendManagerPrivate::initializePlugins()
{
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("kmail"), [](const KPluginMetaData & md) {
return md.serviceTypes().contains(QStringLiteral("KMailEditor/PluginCheckBeforeSend"));
});
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
PluginEditorCheckBeforeSendInfo info;
info.metaData = i.previous();
if (pluginVersion() == info.metaData.version()) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.saveName())) {
continue;
}
info.plugin = Q_NULLPTR;
mPluginList.push_back(info);
unique.insert(info.saveName());
} else {
qWarning() << "Plugin " << info.metaData.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<PluginEditorCheckBeforeSendInfo>::iterator end(mPluginList.end());
for (QVector<PluginEditorCheckBeforeSendInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
loadPlugin(&(*it));
}
return true;
}
void PluginEditorCheckBeforeSendManagerPrivate::loadPlugin(PluginEditorCheckBeforeSendInfo *item)
{
item->plugin = KPluginLoader(item->metaData.fileName()).factory()->create<PluginEditorCheckBeforeSend>(q, QVariantList() << item->saveName());
}
QVector<PluginEditorCheckBeforeSend *> PluginEditorCheckBeforeSendManagerPrivate::pluginsList() const
{
QVector<PluginEditorCheckBeforeSend *> lst;
QVector<PluginEditorCheckBeforeSendInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<PluginEditorCheckBeforeSendInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if ((*it).plugin) {
lst << (*it).plugin;
}
}
return lst;
}
PluginEditorCheckBeforeSendManager::PluginEditorCheckBeforeSendManager(QObject *parent)
: QObject(parent),
d(new MessageComposer::PluginEditorCheckBeforeSendManagerPrivate(this))
{
}
PluginEditorCheckBeforeSendManager::~PluginEditorCheckBeforeSendManager()
{
delete d;
}
PluginEditorCheckBeforeSendManager *PluginEditorCheckBeforeSendManager::self()
{
return sInstance->pluginManager;
}
QString PluginEditorCheckBeforeSendInfo::saveName() const
{
return QFileInfo(metaData.fileName()).baseName();
}
QVector<PluginEditorCheckBeforeSend *> PluginEditorCheckBeforeSendManager::pluginsList() const
{
return d->pluginsList();
}
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
*/
#ifndef PLUGINEDITORCHECKBEFORESENDMANAGER_H
#define PLUGINEDITORCHECKBEFORESENDMANAGER_H
#include <QObject>
#include "messagecomposer_export.h"
namespace MessageComposer
{
class PluginEditorCheckBeforeSendManagerPrivate;
class PluginEditorCheckBeforeSend;
class MESSAGECOMPOSER_EXPORT PluginEditorCheckBeforeSendManager : public QObject
{
Q_OBJECT
public:
explicit PluginEditorCheckBeforeSendManager(QObject *parent = Q_NULLPTR);
~PluginEditorCheckBeforeSendManager();
static PluginEditorCheckBeforeSendManager *self();
QVector<PluginEditorCheckBeforeSend *> pluginsList() const;
private:
PluginEditorCheckBeforeSendManagerPrivate *const d;
};
}
#endif // PLUGINEDITORCHECKBEFORESENDMANAGER_H
Markdown is supported
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