Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 03c1821c authored by Laurent Montel's avatar Laurent Montel 😁

Start to implement plugins for generating specific emails format or convert text before sending

parent 7f0ab386
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.7.80")
set(PIM_VERSION "5.7.81")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......
......@@ -113,12 +113,20 @@ set(messagecomposer_plugineditorinit_SRCS
plugineditorinit/plugineditorinitinterface.cpp
)
set(messagecomposer_plugineditorconverttext_SRCS
plugineditorconverttext/plugineditorconverttextconfigurewidget.cpp
plugineditorconverttext/plugineditorconverttext.cpp
plugineditorconverttext/plugineditorconverttextmanager.cpp
plugineditorconverttext/plugineditorconverttextinterface.cpp
)
set(messagecomposer_widgets_SRCS
widgets/dictionarycombobox.cpp
)
set( messagecomposer_src
${messagecomposer_widgets_SRCS}
${messagecomposer_plugineditorconverttext_SRCS}
${messagecomposer_plugineditorinit_SRCS}
${messagecomposer_plugineditor_SRCS}
${messagecomposer_richtextcomposerng_SRCS}
......@@ -226,6 +234,17 @@ ecm_generate_headers(MessageComposer_Camelplugineditorinit_HEADERS
RELATIVE plugineditorinit
)
ecm_generate_headers(MessageComposer_Camelplugineditorconverttext_HEADERS
HEADER_NAMES
PluginEditorConvertTextConfigureWidget
PluginEditorConvertText
PluginEditorConvertTextManager
PluginEditorConvertTextInterface
REQUIRED_HEADERS MessageComposer_plugineditorconverttext_HEADERS
PREFIX MessageComposer
RELATIVE plugineditorconverttext
)
ecm_generate_headers(MessageComposer_Camelwidgets_HEADERS
HEADER_NAMES
DictionaryComboBox
......@@ -380,6 +399,7 @@ ecm_generate_pri_file(BASE_NAME MessageComposer
install(FILES
${MessageComposer_Camelplugineditorconverttext_HEADERS}
${MessageComposer_Camelplugineditorinit_HEADERS}
${MessageComposer_Camelplugineditorcheckbeforesend_HEADERS}
${MessageComposer_Camelcasecomposer_HEADERS}
......@@ -402,6 +422,7 @@ install(FILES
install(FILES
${MessageComposer_HEADERS}
${MessageComposer_plugineditorconverttext_HEADERS}
${MessageComposer_plugineditorinit_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/messagecomposer_export.h
${CMAKE_CURRENT_BINARY_DIR}/messagecomposersettings_base.h
......
/*
Copyright (C) 2017-2018 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 "plugineditorconverttext.h"
using namespace MessageComposer;
class MessageComposer::PluginEditorConverttextPrivate
{
public:
PluginEditorConverttextPrivate()
{
}
bool mIsEnabled = false;
};
PluginEditorConvertText::PluginEditorConvertText(QObject *parent)
: QObject(parent)
, d(new MessageComposer::PluginEditorConverttextPrivate)
{
}
PluginEditorConvertText::~PluginEditorConvertText()
{
delete d;
}
bool PluginEditorConvertText::hasConfigureDialog() const
{
return false;
}
void PluginEditorConvertText::showConfigureDialog(QWidget *parent)
{
Q_UNUSED(parent);
}
void PluginEditorConvertText::emitConfigChanged()
{
Q_EMIT configChanged();
}
QString PluginEditorConvertText::description() const
{
return {};
}
void PluginEditorConvertText::setIsEnabled(bool enabled)
{
d->mIsEnabled = enabled;
}
bool PluginEditorConvertText::isEnabled() const
{
return d->mIsEnabled;
}
/*
Copyright (C) 2018 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 PLUGINEDITORCONVERTTEXT_H
#define PLUGINEDITORCONVERTTEXT_H
#include <QObject>
#include "messagecomposer_export.h"
namespace MessageComposer {
class PluginEditorConverttextPrivate;
class PluginEditorConverttextInterface;
class MESSAGECOMPOSER_EXPORT PluginEditorConvertText : public QObject
{
Q_OBJECT
public:
explicit PluginEditorConvertText(QObject *parent = nullptr);
~PluginEditorConvertText();
virtual PluginEditorConverttextInterface *createInterface(QObject *parent) = 0;
virtual bool hasConfigureDialog() const;
virtual void showConfigureDialog(QWidget *parent = nullptr);
void emitConfigChanged();
virtual QString description() const;
void setIsEnabled(bool enabled);
bool isEnabled() const;
Q_SIGNALS:
void configChanged();
private:
PluginEditorConverttextPrivate *const d;
};
}
#endif // PLUGINEDITORCONVERTTEXT_H
/*
Copyright (C) 2018 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 "plugineditorconverttextconfigurewidget.h"
using namespace MessageComposer;
PluginEditorConvertTextConfigureWidget::PluginEditorConvertTextConfigureWidget(QWidget *parent)
: QWidget(parent)
{
}
PluginEditorConvertTextConfigureWidget::~PluginEditorConvertTextConfigureWidget()
{
}
QString PluginEditorConvertTextConfigureWidget::helpAnchor() const
{
return QString();
}
/*
Copyright (C) 2018 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 PluginEditorConvertTextConfigureWidget_H
#define PluginEditorConvertTextConfigureWidget_H
#include "messagecomposer_export.h"
#include <QWidget>
namespace MessageComposer {
class MESSAGECOMPOSER_EXPORT PluginEditorConvertTextConfigureWidget : public QWidget
{
Q_OBJECT
public:
explicit PluginEditorConvertTextConfigureWidget(QWidget *parent = nullptr);
~PluginEditorConvertTextConfigureWidget();
virtual void loadSettings() = 0;
virtual void saveSettings() = 0;
virtual void resetSettings() = 0;
virtual QString helpAnchor() const;
Q_SIGNALS:
void configureChanged();
};
}
#endif // PluginEditorConvertTextConfigureWidget_H
/*
Copyright (C) 2018 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 "plugineditorconverttextinterface.h"
using namespace MessageComposer;
class MessageComposer::PluginEditorConvertTextInterfacePrivate
{
public:
PluginEditorConvertTextInterfacePrivate()
: mParentWidget(nullptr)
, mEditor(nullptr)
{
}
QWidget *mParentWidget = nullptr;
KPIMTextEdit::RichTextComposer *mEditor = nullptr;
};
PluginEditorConvertTextInterface::PluginEditorConvertTextInterface(QObject *parent)
: QObject(parent)
, d(new MessageComposer::PluginEditorConvertTextInterfacePrivate)
{
}
PluginEditorConvertTextInterface::~PluginEditorConvertTextInterface()
{
delete d;
}
void PluginEditorConvertTextInterface::setParentWidget(QWidget *parent)
{
d->mParentWidget = parent;
}
QWidget *PluginEditorConvertTextInterface::parentWidget() const
{
return d->mParentWidget;
}
KPIMTextEdit::RichTextComposer *PluginEditorConvertTextInterface::richTextEditor() const
{
return d->mEditor;
}
void PluginEditorConvertTextInterface::setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor)
{
d->mEditor = richTextEditor;
}
void PluginEditorConvertTextInterface::reloadConfig()
{
//Reimplement it
}
/*
Copyright (C) 2018 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 PLUGINEDITORCONVERTTEXTINTERFACE_H
#define PLUGINEDITORCONVERTTEXTINTERFACE_H
#include <QObject>
#include "messagecomposer_export.h"
namespace KPIMTextEdit {
class RichTextComposer;
}
namespace MessageComposer {
class PluginEditorConvertTextInterfacePrivate;
class MESSAGECOMPOSER_EXPORT PluginEditorConvertTextInterface : public QObject
{
Q_OBJECT
public:
explicit PluginEditorConvertTextInterface(QObject *parent = nullptr);
~PluginEditorConvertTextInterface();
virtual bool exec() = 0;
void setParentWidget(QWidget *parent);
QWidget *parentWidget() const;
KPIMTextEdit::RichTextComposer *richTextEditor() const;
void setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor);
public Q_SLOTS:
virtual void reloadConfig();
private:
PluginEditorConvertTextInterfacePrivate *const d;
};
}
#endif // PLUGINEDITORCONVERTTEXTINTERFACE_H
/*
Copyright (C) 2017-2018 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 "plugineditorconverttextmanager.h"
#include "plugineditorconverttext.h"
#include "messagecomposer_debug.h"
#include <QFileInfo>
#include <QSet>
#include <KPluginLoader>
#include <kpluginmetadata.h>
#include <KPluginFactory>
using namespace MessageComposer;
class PluginEditorConvertTextInfo
{
public:
PluginEditorConvertTextInfo()
{
}
QString metaDataFileNameBaseName;
QString metaDataFileName;
PimCommon::PluginUtilData pluginData;
PluginEditorConvertText *plugin = nullptr;
bool isEnabled = true;
};
namespace {
QString pluginVersion()
{
return QStringLiteral("1.0");
}
}
class MessageComposer::PluginEditorConvertTextManagerPrivate
{
public:
PluginEditorConvertTextManagerPrivate(PluginEditorConvertTextManager *qq)
: q(qq)
{
initializePlugins();
}
void loadPlugin(PluginEditorConvertTextInfo *item);
QVector<PluginEditorConvertText *> pluginsList() const;
bool initializePlugins();
QVector<PluginEditorConvertTextInfo> mPluginList;
QString configPrefixSettingKey() const;
QString configGroupName() const;
QVector<PimCommon::PluginUtilData> pluginsDataList() const;
PluginEditorConvertText *pluginFromIdentifier(const QString &id);
private:
QVector<PimCommon::PluginUtilData> mPluginDataList;
PluginEditorConvertTextManager *q;
};
QString PluginEditorConvertTextManagerPrivate::configGroupName() const
{
return QStringLiteral("KMailPluginEditorConvertText");
}
QString PluginEditorConvertTextManagerPrivate::configPrefixSettingKey() const
{
return QStringLiteral("PluginEditorConvertText");
}
QVector<PimCommon::PluginUtilData> PluginEditorConvertTextManagerPrivate::pluginsDataList() const
{
return mPluginDataList;
}
bool PluginEditorConvertTextManagerPrivate::initializePlugins()
{
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("kmail"), [](const KPluginMetaData &md) {
return md.serviceTypes().contains(QLatin1String("KMailEditor/PluginEditorConvertText"));
});
const QPair<QStringList, QStringList> pair = PimCommon::PluginUtil::loadPluginSetting(configGroupName(), configPrefixSettingKey());
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
PluginEditorConvertTextInfo info;
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();
if (pluginVersion() == data.version()) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.metaDataFileNameBaseName)) {
continue;
}
info.plugin = nullptr;
mPluginList.push_back(info);
unique.insert(info.metaDataFileNameBaseName);
} else {
qCWarning(MESSAGECOMPOSER_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<PluginEditorConvertTextInfo>::iterator end(mPluginList.end());
for (QVector<PluginEditorConvertTextInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
loadPlugin(&(*it));
}
return true;
}
void PluginEditorConvertTextManagerPrivate::loadPlugin(PluginEditorConvertTextInfo *item)
{
KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
item->plugin = pluginLoader.factory()->create<PluginEditorConvertText>(q, QVariantList() << item->metaDataFileNameBaseName);
item->plugin->setIsEnabled(item->isEnabled);
item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
mPluginDataList.append(item->pluginData);
}
}
QVector<PluginEditorConvertText *> PluginEditorConvertTextManagerPrivate::pluginsList() const
{
QVector<PluginEditorConvertText *> lst;
QVector<PluginEditorConvertTextInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<PluginEditorConvertTextInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if (auto plugin = (*it).plugin) {
lst << plugin;
}
}
return lst;
}
PluginEditorConvertText *PluginEditorConvertTextManagerPrivate::pluginFromIdentifier(const QString &id)
{
QVector<PluginEditorConvertTextInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<PluginEditorConvertTextInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if ((*it).pluginData.mIdentifier == id) {
return (*it).plugin;
}
}
return {};
}
PluginEditorConvertTextManager::PluginEditorConvertTextManager(QObject *parent)
: QObject(parent)
, d(new MessageComposer::PluginEditorConvertTextManagerPrivate(this))
{
}
PluginEditorConvertTextManager::~PluginEditorConvertTextManager()
{
delete d;
}
PluginEditorConvertTextManager *PluginEditorConvertTextManager::self()
{
static PluginEditorConvertTextManager s_self;
return &s_self;
}
QVector<PluginEditorConvertText *> PluginEditorConvertTextManager::pluginsList() const
{
return d->pluginsList();
}
QString PluginEditorConvertTextManager::configGroupName() const
{
return d->configGroupName();
}
QString PluginEditorConvertTextManager::configPrefixSettingKey() const
{
return d->configPrefixSettingKey();
}
QVector<PimCommon::PluginUtilData> PluginEditorConvertTextManager::pluginsDataList() const
{
return d->pluginsDataList();
}
PluginEditorConvertText *PluginEditorConvertTextManager::pluginFromIdentifier(const QString &id)
{
return d->pluginFromIdentifier(id);
}
/*
Copyright (C) 2018 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 PLUGINEDITORCONVERTTEXTMANAGER_H
#define PLUGINEDITORCONVERTTEXTMANAGER_H
#include <QObject>
#include "messagecomposer_export.h"
#include <PimCommon/PluginUtil>
namespace MessageComposer {
class PluginEditorConvertTextManagerPrivate;
class PluginEditorConvertText;
class MESSAGECOMPOSER_EXPORT PluginEditorConvertTextManager : public QObject
{
Q_OBJECT
public:
explicit PluginEditorConvertTextManager(QObject *parent = nullptr);
~PluginEditorConvertTextManager();
static PluginEditorConvertTextManager *self();
QVector<PluginEditorConvertText *> pluginsList() const;
QString configGroupName() const;
QString configPrefixSettingKey() const;
QVector<PimCommon::PluginUtilData> pluginsDataList() const;
PluginEditorConvertText *pluginFromIdentifier(const QString &id);
private:
PluginEditorConvertTextManagerPrivate *const d;
};
}
#endif // PLU