Commit 42d2b9fa authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Create grammar plugin support

parent c9de8079
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.10.47")
set(PIM_VERSION "5.10.48")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......@@ -33,7 +33,7 @@ set(KMIME_LIB_VERSION "5.10.41")
set(KPIMTEXTEDIT_LIB_VERSION "5.10.40")
set(LIBKDEPIM_LIB_VERSION "5.10.40")
set(LIBKLEO_LIB_VERSION "5.10.40")
set(PIMCOMMON_LIB_VERSION "5.10.40")
set(PIMCOMMON_LIB_VERSION "5.10.42")
set(GPGME_LIB_VERSION "1.8.0")
set(AKONADI_CONTACT_VERSION "5.10.40")
......
......@@ -125,7 +125,10 @@ set(messagecomposer_plugineditorconverttext_SRCS
plugineditorconverttext/plugineditorconverterinitialdata.cpp
plugineditorconverttext/plugineditorconverterbeforeconvertingdata.cpp
)
set(messagecomposer_plugineditorgrammar_SRCS
plugineditorgrammar/plugineditorgrammarmanager.cpp
plugineditorgrammar/plugineditorgrammarcustomtoolsviewinterface.cpp
)
set( messagecomposer_src
${messagecomposer_plugineditorconverttext_SRCS}
......@@ -142,6 +145,7 @@ set( messagecomposer_src
${messagecomposer_sender_src}
${messagecomposer_followupreminder_SRCS}
${messagecomposer_plugineditorcheckbeforesend_SRCS}
${messagecomposer_plugineditorgrammar_SRCS}
utils/util.cpp
settings/messagecomposersettings.cpp
)
......@@ -250,6 +254,15 @@ ecm_generate_headers(MessageComposer_Camelplugineditorconverttext_HEADERS
RELATIVE plugineditorconverttext
)
ecm_generate_headers(MessageComposer_Camelplugineditorgrammar_HEADERS
HEADER_NAMES
PluginEditorGrammarManager
PluginEditorGrammarCustomToolsViewInterface
REQUIRED_HEADERS MessageComposer_plugineditorgrammar_HEADERS
PREFIX MessageComposer
RELATIVE plugineditorgrammar
)
ecm_generate_headers(MessageComposer_Camelplugineditorcheckbeforesend_HEADERS
HEADER_NAMES
......@@ -413,6 +426,7 @@ install(FILES
${MessageComposer_Camelcasejob_HEADERS}
${MessageComposer_Camelcaseattachement_HEADERS}
${MessageComposer_Camelplugineditor_HEADERS}
${MessageComposer_Camelplugineditorgrammar_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageComposer
COMPONENT Devel
)
......@@ -438,6 +452,7 @@ install(FILES
${MessageComposer_job_HEADERS}
${MessageComposer_plugineditor_HEADERS}
${MessageComposer_plugineditorcheckbeforesend_HEADERS}
${MessageComposer_plugineditorgrammar_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/messagecomposer
COMPONENT Devel
......
/*
Copyright (C) 2019 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "plugineditorgrammarcustomtoolsviewinterface.h"
#include <KPIMTextEdit/RichTextComposer>
using namespace MessageComposer;
class MessageComposer::PluginEditorGrammarCustomToolsViewInterfacePrivate
{
public:
PluginEditorGrammarCustomToolsViewInterfacePrivate()
{
}
QWidget *mParentWidget = nullptr;
KPIMTextEdit::RichTextComposer *mEditor = nullptr;
};
PluginEditorGrammarCustomToolsViewInterface::PluginEditorGrammarCustomToolsViewInterface(QWidget *parent)
: PimCommon::CustomToolsViewInterface(parent)
, d(new PluginEditorGrammarCustomToolsViewInterfacePrivate)
{
}
PluginEditorGrammarCustomToolsViewInterface::~PluginEditorGrammarCustomToolsViewInterface()
{
}
void PluginEditorGrammarCustomToolsViewInterface::setParentWidget(QWidget *parent)
{
d->mParentWidget = parent;
}
QWidget *PluginEditorGrammarCustomToolsViewInterface::parentWidget() const
{
return d->mParentWidget;
}
KPIMTextEdit::RichTextComposer *PluginEditorGrammarCustomToolsViewInterface::richTextEditor() const
{
return d->mEditor;
}
void PluginEditorGrammarCustomToolsViewInterface::setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor)
{
d->mEditor = richTextEditor;
}
/*
Copyright (C) 2019 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef PLUGINEDITORGRAMMARCUSTOMTOOLSVIEWINTERFACE_H
#define PLUGINEDITORGRAMMARCUSTOMTOOLSVIEWINTERFACE_H
#include <PimCommon/CustomToolsViewInterface>
#include "messagecomposer_export.h"
namespace KPIMTextEdit {
class RichTextComposer;
}
namespace MessageComposer {
class PluginEditorGrammarCustomToolsViewInterfacePrivate;
class MESSAGECOMPOSER_EXPORT PluginEditorGrammarCustomToolsViewInterface : public PimCommon::CustomToolsViewInterface
{
Q_OBJECT
public:
explicit PluginEditorGrammarCustomToolsViewInterface(QWidget *parent = nullptr);
~PluginEditorGrammarCustomToolsViewInterface();
void setParentWidget(QWidget *parent);
Q_REQUIRED_RESULT QWidget *parentWidget() const;
Q_REQUIRED_RESULT KPIMTextEdit::RichTextComposer *richTextEditor() const;
void setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor);
private:
PluginEditorGrammarCustomToolsViewInterfacePrivate *const d;
};
}
#endif // PLUGINEDITORGRAMMARCUSTOMTOOLSVIEWINTERFACE_H
/*
Copyright (C) 2019 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 "plugineditorgrammarmanager.h"
#include <PimCommon/CustomToolsPlugin>
#include "messagecomposer_debug.h"
#include <QFileInfo>
#include <QSet>
#include <KPluginLoader>
#include <kpluginmetadata.h>
#include <KPluginFactory>
using namespace MessageComposer;
class PluginEditorGrammarInfo
{
public:
PluginEditorGrammarInfo()
{
}
PimCommon::PluginUtilData pluginData;
QString metaDataFileNameBaseName;
QString metaDataFileName;
PimCommon::CustomToolsPlugin *plugin = nullptr;
bool isEnabled = true;
};
namespace {
QString pluginVersion()
{
return QStringLiteral("1.0");
}
}
class MessageComposer::PluginEditorGrammarManagerPrivate
{
public:
PluginEditorGrammarManagerPrivate(PluginEditorGrammarManager *qq)
: q(qq)
{
initializePlugins();
}
void loadPlugin(PluginEditorGrammarInfo *item);
QVector<PimCommon::CustomToolsPlugin *> pluginsList() const;
bool initializePlugins();
QVector<PluginEditorGrammarInfo> mPluginList;
QString configPrefixSettingKey() const;
QString configGroupName() const;
QVector<PimCommon::PluginUtilData> pluginsDataList() const;
PimCommon::CustomToolsPlugin *pluginFromIdentifier(const QString &id);
private:
QVector<PimCommon::PluginUtilData> mPluginDataList;
PluginEditorGrammarManager *q;
};
QString PluginEditorGrammarManagerPrivate::configGroupName() const
{
return QStringLiteral("KMailPluginEditorGrammar");
}
QString PluginEditorGrammarManagerPrivate::configPrefixSettingKey() const
{
return QStringLiteral("PluginEditorGrammar");
}
QVector<PimCommon::PluginUtilData> PluginEditorGrammarManagerPrivate::pluginsDataList() const
{
return mPluginDataList;
}
bool PluginEditorGrammarManagerPrivate::initializePlugins()
{
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("kmail"), [](const KPluginMetaData &md) {
return md.serviceTypes().contains(QLatin1String("KMailEditor/PluginEditorGrammar"));
});
const QPair<QStringList, QStringList> pair = PimCommon::PluginUtil::loadPluginSetting(configGroupName(), configPrefixSettingKey());
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
PluginEditorGrammarInfo 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<PluginEditorGrammarInfo>::iterator end(mPluginList.end());
for (QVector<PluginEditorGrammarInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
loadPlugin(&(*it));
}
return true;
}
void PluginEditorGrammarManagerPrivate::loadPlugin(PluginEditorGrammarInfo *item)
{
KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
item->plugin = pluginLoader.factory()->create<PimCommon::CustomToolsPlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
item->plugin->setIsEnabled(item->isEnabled);
item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
mPluginDataList.append(item->pluginData);
}
}
QVector<PimCommon::CustomToolsPlugin *> PluginEditorGrammarManagerPrivate::pluginsList() const
{
QVector<PimCommon::CustomToolsPlugin *> lst;
QVector<PluginEditorGrammarInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<PluginEditorGrammarInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if (auto plugin = (*it).plugin) {
lst << plugin;
}
}
return lst;
}
PimCommon::CustomToolsPlugin *PluginEditorGrammarManagerPrivate::pluginFromIdentifier(const QString &id)
{
QVector<PluginEditorGrammarInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<PluginEditorGrammarInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if ((*it).pluginData.mIdentifier == id) {
return (*it).plugin;
}
}
return {};
}
PluginEditorGrammarManager::PluginEditorGrammarManager(QObject *parent)
: QObject(parent)
, d(new MessageComposer::PluginEditorGrammarManagerPrivate(this))
{
}
PluginEditorGrammarManager::~PluginEditorGrammarManager()
{
delete d;
}
PluginEditorGrammarManager *PluginEditorGrammarManager::self()
{
static PluginEditorGrammarManager s_self;
return &s_self;
}
QVector<PimCommon::CustomToolsPlugin *> PluginEditorGrammarManager::pluginsList() const
{
return d->pluginsList();
}
QString PluginEditorGrammarManager::configGroupName() const
{
return d->configGroupName();
}
QString PluginEditorGrammarManager::configPrefixSettingKey() const
{
return d->configPrefixSettingKey();
}
QVector<PimCommon::PluginUtilData> PluginEditorGrammarManager::pluginsDataList() const
{
return d->pluginsDataList();
}
PimCommon::CustomToolsPlugin *PluginEditorGrammarManager::pluginFromIdentifier(const QString &id)
{
return d->pluginFromIdentifier(id);
}
/*
Copyright (C) 2019 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 PLUGINEDITORGRAMMARMANAGER_H
#define PLUGINEDITORGRAMMARMANAGER_H
#include <QObject>
#include "messagecomposer_export.h"
#include <PimCommon/PluginUtil>
namespace PimCommon {
class CustomToolsPlugin;
}
namespace MessageComposer {
class PluginEditorGrammarManagerPrivate;
class PluginEditorConvertText;
class MESSAGECOMPOSER_EXPORT PluginEditorGrammarManager : public QObject
{
Q_OBJECT
public:
explicit PluginEditorGrammarManager(QObject *parent = nullptr);
~PluginEditorGrammarManager();
static PluginEditorGrammarManager *self();
Q_REQUIRED_RESULT QVector<PimCommon::CustomToolsPlugin *> pluginsList() const;
Q_REQUIRED_RESULT QString configGroupName() const;
Q_REQUIRED_RESULT QString configPrefixSettingKey() const;
Q_REQUIRED_RESULT QVector<PimCommon::PluginUtilData> pluginsDataList() const;
Q_REQUIRED_RESULT PimCommon::CustomToolsPlugin *pluginFromIdentifier(const QString &id);
private:
PluginEditorGrammarManagerPrivate *const d;
};
}
#endif // PLUGINEDITORGRAMMARMANAGER_H
......@@ -269,6 +269,7 @@ void DistributionListDialog::slotUser1()
Akonadi::ContactGroupSearchJob *job = new Akonadi::ContactGroupSearchJob();
job->setQuery(Akonadi::ContactGroupSearchJob::Name, name);
job->setProperty("name", name);
qDebug() << " name " << name;
connect(job, &Akonadi::ContactSearchJob::result, this, &DistributionListDialog::slotDelayedUser1);
}
......@@ -278,6 +279,7 @@ void DistributionListDialog::slotDelayedUser1(KJob *job)
const QString name = searchJob->property("name").toString();
if (!searchJob->contactGroups().isEmpty()) {
qDebug() << " searchJob->contactGroups()" << searchJob->contactGroups().count();
KMessageBox::information(this,
xi18nc("@info", "<para>Distribution list with the given name <resource>%1</resource> "
"already exists. Please select a different name.</para>", name));
......
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