Commit a9b5503b authored by Laurent Montel's avatar Laurent Montel 😁

Move plugin here

parent d3fcd2a4
......@@ -89,7 +89,14 @@ set(messagecomposer_richtextcomposerng_SRCS
composer-ng/richtextcomposersignatures.cpp
)
set(messagecomposer_plugineditor_SRCS
plugineditor/plugineditormanager.cpp
plugineditor/plugineditor.cpp
plugineditor/plugineditorinterface.cpp
)
set( messagecomposer_src
${messagecomposer_plugineditor_SRCS}
${messagecomposer_richtextcomposerng_SRCS}
${messagecomposer_part_src}
${messagecomposer_imagescaling_src}
......@@ -169,6 +176,16 @@ install(TARGETS
)
ecm_generate_headers(MessageComposer_Camelplugineditor_HEADERS
HEADER_NAMES
PluginEditor
PluginEditorInterface
PluginEditorManager
REQUIRED_HEADERS MessageComposer_plugineditor_HEADERS
PREFIX MessageComposer
RELATIVE plugineditor
)
ecm_generate_headers(MessageComposer_Camelcaseattachement_HEADERS
HEADER_NAMES
AttachmentModel
......@@ -311,7 +328,7 @@ install(FILES
${MessageComposer_Camelcaseimagescaling_HEADERS}
${MessageComposer_Camelcasejob_HEADERS}
${MessageComposer_Camelcaseattachement_HEADERS}
${MessageComposer_Camelplugineditor_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageComposer
COMPONENT Devel
)
......@@ -333,6 +350,7 @@ install(FILES
${MessageComposer_imagescaling_HEADERS}
${MessageComposer_attachement_HEADERS}
${MessageComposer_job_HEADERS}
${MessageComposer_plugineditor_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/messagecomposer
COMPONENT Devel
......
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "plugineditor.h"
using namespace MessageComposer;
PluginEditor::PluginEditor(QObject *parent)
: QObject(parent)
{
}
PluginEditor::~PluginEditor()
{
}
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PLUGINEDITOR_H
#define PLUGINEDITOR_H
#include <QObject>
#include "messagecomposer_export.h"
class KActionCollection;
namespace MessageComposer
{
class PluginEditorInterface;
class MESSAGECOMPOSER_EXPORT PluginEditor : public QObject
{
Q_OBJECT
public:
explicit PluginEditor(QObject *parent = Q_NULLPTR);
~PluginEditor();
virtual PluginEditorInterface *createInterface(KActionCollection *ac, QWidget *parent = Q_NULLPTR) = 0;
};
}
#endif // PLUGINEDITOR_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "plugineditorinterface.h"
using namespace MessageComposer;
ActionType::ActionType()
: mAction(Q_NULLPTR),
mType(Tools)
{
}
ActionType::ActionType(QAction *action, ActionType::Type type)
: mAction(action),
mType(type)
{
}
QAction *ActionType::action() const
{
return mAction;
}
ActionType::Type ActionType::type() const
{
return mType;
}
class MessageComposer::PluginEditorInterfacePrivate
{
public:
PluginEditorInterfacePrivate()
: mParentWidget(Q_NULLPTR),
mRichTextEditor(Q_NULLPTR)
{
}
ActionType mActionType;
QWidget *mParentWidget;
KPIMTextEdit::RichTextEditor *mRichTextEditor;
};
PluginEditorInterface::PluginEditorInterface(QObject *parent)
: QObject(parent),
d(new MessageComposer::PluginEditorInterfacePrivate)
{
}
PluginEditorInterface::~PluginEditorInterface()
{
delete d;
}
void PluginEditorInterface::setActionType(const ActionType &type)
{
d->mActionType = type;
}
ActionType PluginEditorInterface::actionType() const
{
return d->mActionType;
}
void PluginEditorInterface::setParentWidget(QWidget *parent)
{
d->mParentWidget = parent;
}
QWidget *PluginEditorInterface::parentWidget() const
{
return d->mParentWidget;
}
KPIMTextEdit::RichTextEditor *PluginEditorInterface::richTextEditor() const
{
return d->mRichTextEditor;
}
void PluginEditorInterface::setRichTextEditor(KPIMTextEdit::RichTextEditor *richTextEditor)
{
d->mRichTextEditor = richTextEditor;
}
bool PluginEditorInterface::hasPopupMenuSupport() const
{
return false;
}
bool PluginEditorInterface::hasConfigureDialog() const
{
return false;
}
void PluginEditorInterface::showConfigureDialog(QWidget *parentWidget)
{
Q_UNUSED(parentWidget);
}
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PLUGINEDITORINTERFACE_H
#define PLUGINEDITORINTERFACE_H
#include <QObject>
#include "messagecomposer_export.h"
class QAction;
class KActionCollection;
namespace KPIMTextEdit
{
class RichTextEditor;
}
namespace MessageComposer
{
class MESSAGECOMPOSER_EXPORT ActionType
{
public:
enum Type {
Tools = 0,
Edit = 1,
File = 2,
Action = 3,
PopupMenu = 4
};
ActionType();
ActionType(QAction *action, Type type);
QAction *action() const;
Type type() const;
private:
QAction *mAction;
Type mType;
};
class PluginEditorInterfacePrivate;
class MESSAGECOMPOSER_EXPORT PluginEditorInterface : public QObject
{
Q_OBJECT
public:
explicit PluginEditorInterface(QObject *parent = Q_NULLPTR);
~PluginEditorInterface();
void setActionType(const ActionType &type);
ActionType actionType() const;
virtual void createAction(KActionCollection *ac) = 0;
virtual void exec() = 0;
void setParentWidget(QWidget *parent);
QWidget *parentWidget() const;
KPIMTextEdit::RichTextEditor *richTextEditor() const;
void setRichTextEditor(KPIMTextEdit::RichTextEditor *richTextEditor);
virtual bool hasPopupMenuSupport() const;
virtual bool hasConfigureDialog() const;
virtual void showConfigureDialog(QWidget *parentWidget = Q_NULLPTR);
Q_SIGNALS:
void emitPluginActivated(PluginEditorInterface *interface);
private:
PluginEditorInterfacePrivate *const d;
};
}
#endif // PLUGINEDITORINTERFACE_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "plugineditor.h"
#include "plugineditormanager.h"
#include <QFileInfo>
#include <QSet>
#include <KPluginLoader>
#include <kpluginmetadata.h>
#include <KPluginFactory>
using namespace MessageComposer;
class PluginEditorManagerInstancePrivate
{
public:
PluginEditorManagerInstancePrivate()
: pluginManager(new PluginEditorManager)
{
}
~PluginEditorManagerInstancePrivate()
{
delete pluginManager;
}
PluginEditorManager *pluginManager;
};
class PluginEditorInfo
{
public:
PluginEditorInfo()
: plugin(Q_NULLPTR)
{
}
QString saveName() const;
KPluginMetaData metaData;
PluginEditor *plugin;
};
Q_GLOBAL_STATIC(PluginEditorManagerInstancePrivate, sInstance)
namespace {
QString pluginVersion() {
return QStringLiteral("1.0");
}
}
class MessageComposer::PluginEditorManagerPrivate
{
public:
PluginEditorManagerPrivate(PluginEditorManager *qq)
: q(qq)
{
initializePlugins();
}
void loadPlugin(PluginEditorInfo *item);
QVector<PluginEditor *> pluginsList() const;
bool initializePlugins();
QVector<PluginEditorInfo> mPluginList;
PluginEditorManager *q;
};
bool PluginEditorManagerPrivate::initializePlugins()
{
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("kmail"), [](const KPluginMetaData & md) {
return md.serviceTypes().contains(QStringLiteral("KMailEditor/Plugin"));
});
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
PluginEditorInfo 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());
}
}
QVector<PluginEditorInfo>::iterator end(mPluginList.end());
for (QVector<PluginEditorInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
loadPlugin(&(*it));
}
return true;
}
void PluginEditorManagerPrivate::loadPlugin(PluginEditorInfo *item)
{
item->plugin = KPluginLoader(item->metaData.fileName()).factory()->create<PluginEditor>(q, QVariantList() << item->saveName());
}
QVector<PluginEditor *> PluginEditorManagerPrivate::pluginsList() const
{
QVector<PluginEditor *> lst;
QVector<PluginEditorInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<PluginEditorInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if ((*it).plugin) {
lst << (*it).plugin;
}
}
return lst;
}
PluginEditorManager::PluginEditorManager(QObject *parent)
: QObject(parent),
d(new MessageComposer::PluginEditorManagerPrivate(this))
{
}
PluginEditorManager::~PluginEditorManager()
{
delete d;
}
PluginEditorManager *PluginEditorManager::self()
{
return sInstance->pluginManager;
}
QString PluginEditorInfo::saveName() const
{
return QFileInfo(metaData.fileName()).baseName();
}
QVector<PluginEditor *> PluginEditorManager::pluginsList() const
{
return d->pluginsList();
}
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PLUGINEDITORMANAGER_H
#define PLUGINEDITORMANAGER_H
#include <QObject>
#include "messagecomposer_export.h"
namespace MessageComposer
{
class PluginEditorManagerPrivate;
class PluginEditor;
class MESSAGECOMPOSER_EXPORT PluginEditorManager : public QObject
{
Q_OBJECT
public:
explicit PluginEditorManager(QObject *parent = Q_NULLPTR);
~PluginEditorManager();
static PluginEditorManager *self();
QVector<PluginEditor *> pluginsList() const;
private:
PluginEditorManagerPrivate *const d;
};
}
#endif // PLUGINEDITORMANAGER_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