Browse Source

Adding initial composer plugin

master
David Lanzendörfer 1 month ago
parent
commit
e1855fae30
14 changed files with 400 additions and 25 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +46
    -8
      messageviewerplugin/pephelpers.cpp
  3. +12
    -14
      messageviewerplugin/viewerpluginpepinterface.cpp
  4. +3
    -3
      messageviewerplugin/viewerpluginpepinterface.h
  5. +16
    -0
      pepcomposer/CMakeLists.txt
  6. +7
    -0
      pepcomposer/kmail_pepcomposereditorplugin.json
  7. +47
    -0
      pepcomposer/pepcomposerconfiguredialog.cpp
  8. +29
    -0
      pepcomposer/pepcomposerconfiguredialog.h
  9. +84
    -0
      pepcomposer/pepcomposerconfigurewidget.cpp
  10. +28
    -0
      pepcomposer/pepcomposerconfigurewidget.h
  11. +40
    -0
      pepcomposer/pepcomposerplugineditor.cpp
  12. +26
    -0
      pepcomposer/pepcomposerplugineditor.h
  13. +36
    -0
      pepcomposer/pepcomposerplugineditorinterface.cpp
  14. +25
    -0
      pepcomposer/pepcomposerplugineditorinterface.h

+ 1
- 0
CMakeLists.txt View File

@ -133,4 +133,5 @@ include_directories(${PROJECT_SOURCE_DIR}/pEpDBusAdapter)
include_directories(${PROJECT_SOURCE_DIR}/pEpDBusAdapter/types)
add_subdirectory(akonadi_pep_agent)
add_subdirectory(messageviewerplugin)
add_subdirectory(pepcomposer)

+ 46
- 8
messageviewerplugin/pephelpers.cpp View File

@ -1,18 +1,25 @@
#include "viewerpluginpepinterface.h"
#include <MimeTreeParser/NodeHelper>
#include <KMime/Headers>
#include <KMime/Types>
#include <KMime/HeaderParsing>
#include <QStringLiteral>
#include <QByteArray>
#include <QRegularExpression>
#include <pEp/message.h>
using namespace MessageViewer;
void pEpViewerInterface::convert_pEpMessage_to_mMessage(message *m)
KMime::Message::Ptr pEpViewerInterface::to_mMessage(message *m)
{
if(!m)
return;
KMime::Message::Ptr mMessage;
if(!m) {
return mMessage;
}
mMessage->from()->from7BitString( QByteArray(m->from->address) );
mMessage->to()->from7BitString( QByteArray(m->to->ident->address) );
@ -20,19 +27,50 @@ void pEpViewerInterface::convert_pEpMessage_to_mMessage(message *m)
attachment->setContent(QByteArray("pEp"));
attachment->contentType()->setMimeType(QByteArray("text/plain"));
}
return mMessage;
}
void pEpViewerInterface::mboxlist_to_message(KMime::Types::Mailbox::List mboxlist, identity_list* peplist)
{
KMime::Types::Mailbox mbox;
foreach ( mbox, mboxlist ) {
peplist = identity_list_add(peplist,
new_identity(
mbox.address().data(),
"",
mbox.address().split('@').at(0).data(),
mbox.name().toLatin1().data()
)
);
}
}
message* pEpViewerInterface::convert_mMessage_to_pEpMessage(PEP_msg_direction direction)
message* pEpViewerInterface::to_pEpMessage(KMime::Message::Ptr mMessage, PEP_msg_direction direction)
{
KMime::Types::Mailbox mbox;
if(!mMessage)
return NULL;
message *m = new_message(direction);
if(!m)
return NULL;
m->from = new_identity( mMessage->from()->asUnicodeString().toLatin1().data(), "", "", "" );
m->to = identity_list_add(m->to,
new_identity( mMessage->to()->asUnicodeString().toLatin1().data(), "", "", "" )
);
m->longmsg = mMessage->decodedContent().data(),
m->longmsg_formatted = mMessage->decodedContent().data(),
mbox = mMessage->from()->mailboxes().at(0);
m->from = new_identity(
mbox.address().data(),
"",
mbox.address().split('@').at(0).data(),
mbox.name().toLatin1().data()
);
mboxlist_to_message( mMessage->to()->mailboxes(), m->to );
mboxlist_to_message( mMessage->cc()->mailboxes(), m->cc );
mboxlist_to_message( mMessage->bcc()->mailboxes(), m->bcc );
mboxlist_to_message( mMessage->replyTo()->mailboxes(), m->reply_to );
foreach ( KMime::Content *attachment, mMessage->contents() ) {
m->attachments = bloblist_add(


+ 12
- 14
messageviewerplugin/viewerpluginpepinterface.cpp View File

@ -87,16 +87,20 @@ void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
{
message *m;
QList<QVariant> args;
QByteArray type;
char *ms;
if(value) {
qDebug() << "Set message";
mMessage = value;
m = convert_mMessage_to_pEpMessage(PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
if(m_pEpClient->isValid()) {
auto ret = m_pEpClient->call(QStringLiteral("decrypt_message"), QLatin1String(ms));
args = ret.arguments();
qDebug() << args;
type = value->contentType()->mimeType();
qDebug() << type;
if(type.contains("encrypted")) {
m = to_pEpMessage(value, PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
if(m_pEpClient->isValid()) {
auto ret = m_pEpClient->call(QStringLiteral("decrypt_message"), QLatin1String(ms));
args = ret.arguments();
qDebug() << args;
}
} else if(type.contains("multipart")) {
}
}
}
@ -113,8 +117,6 @@ void pEpViewerInterface::showWidget()
void pEpViewerInterface::setMessageItem(const Akonadi::Item &item)
{
qDebug() << __FUNCTION__;
mMessageItem = item;
if(item.hasPayload()) {
setMessage(item.payload<KMime::Message::Ptr>());
}
@ -122,16 +124,12 @@ void pEpViewerInterface::setMessageItem(const Akonadi::Item &item)
ViewerPluginInterface::SpecificFeatureTypes pEpViewerInterface::featureTypes() const
{
qDebug() << __FUNCTION__;
return ViewerPluginInterface::NeedMessage;
}
void pEpViewerInterface::updateAction(const Akonadi::Item &item)
{
qDebug() << __FUNCTION__;
mMessageItem = item;
if(item.hasPayload()) {
qDebug() << __FUNCTION__;
setMessageItem(item);
}
}


+ 3
- 3
messageviewerplugin/viewerpluginpepinterface.h View File

@ -41,13 +41,13 @@ public:
private:
// glue between Akonadi and pEp:
message *convert_mMessage_to_pEpMessage(PEP_msg_direction direction);
void convert_pEpMessage_to_mMessage(message *m);
message* to_pEpMessage(KMime::Message::Ptr mMessage, PEP_msg_direction direction);
KMime::Message::Ptr to_mMessage(message *m);
void mboxlist_to_message(KMime::Types::Mailbox::List mboxlist, identity_list *peplist);
bool isApEpMessage(KMime::Content *c);
QDBusInterface *m_pEpClient = nullptr;
KMime::Message::Ptr mMessage;
Akonadi::Item mMessageItem;
QList<QAction *> mAction;
QWidget *mStatusWidget = nullptr;


+ 16
- 0
pepcomposer/CMakeLists.txt View File

@ -0,0 +1,16 @@
kcoreaddons_add_plugin(kmail_pepcomposer INSTALL_NAMESPACE kmail/plugineditorinit)
target_sources(kmail_pepcomposer PRIVATE
pepcomposerplugineditor.cpp
pepcomposerplugineditorinterface.cpp
pepcomposerconfiguredialog.cpp
pepcomposerconfigurewidget.cpp
)
if (COMPILE_WITH_UNITY_CMAKE_SUPPORT)
set_target_properties(kmail_pepcomposer PROPERTIES UNITY_BUILD ON)
endif()
target_link_libraries(kmail_pepcomposer
KF5::MessageComposer KF5::XmlGui KF5::I18n KF5::KIOWidgets
)

+ 7
- 0
pepcomposer/kmail_pepcomposereditorplugin.json View File

@ -0,0 +1,7 @@
{
"KPlugin": {
"Description": "The plugin for writing autoencrypted mails with p≡p",
"Version": "1.0"
},
"X-KDE-KMailEditor-Order": "2"
}

+ 47
- 0
pepcomposer/pepcomposerconfiguredialog.cpp View File

@ -0,0 +1,47 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pepcomposerconfiguredialog.h"
#include "pepcomposerconfigurewidget.h"
#include <KLocalizedString>
pEpComposerConfigureDialog::pEpComposerConfigureDialog(QWidget *parent)
: PimCommon::ConfigurePluginDialog(parent)
{
setWindowTitle(i18nc("@title:window", "Configure \"p≡p Composer\" Plugin"));
initLayout();
}
pEpComposerConfigureDialog::~pEpComposerConfigureDialog()
{
}
QWidget *pEpComposerConfigureDialog::createLayout()
{
mConfigureWidget = new pEpComposerConfigureWidget(this);
mConfigureWidget->setObjectName(QStringLiteral("configurewidget"));
return mConfigureWidget;
}
void pEpComposerConfigureDialog::save()
{
mConfigureWidget->saveSettings();
}
void pEpComposerConfigureDialog::load()
{
mConfigureWidget->loadSettings();
}
void pEpComposerConfigureDialog::reset()
{
mConfigureWidget->resetSettings();
}
void pEpComposerConfigureDialog::help()
{
showHelp(QStringLiteral("kmail2"), mConfigureWidget->helpAnchor());
}

+ 29
- 0
pepcomposer/pepcomposerconfiguredialog.h View File

@ -0,0 +1,29 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <PimCommon/ConfigurePluginDialog>
class pEpComposerConfigureWidget;
class pEpComposerConfigureDialog : public PimCommon::ConfigurePluginDialog
{
Q_OBJECT
public:
explicit pEpComposerConfigureDialog(QWidget *parent = nullptr);
~pEpComposerConfigureDialog() override;
protected:
QWidget *createLayout() override;
void save() override;
void load() override;
void reset() override;
void help() override;
private:
pEpComposerConfigureWidget *mConfigureWidget = nullptr;
};

+ 84
- 0
pepcomposer/pepcomposerconfigurewidget.cpp View File

@ -0,0 +1,84 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pepcomposerconfigurewidget.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KUrlRequester>
#include <QCheckBox>
#include <QLabel>
#include <QVBoxLayout>
pEpComposerConfigureWidget::pEpComposerConfigureWidget(QWidget *parent)
: MessageComposer::PluginEditorConfigureBaseWidget(parent)
, mpEpEditorCheck(new QCheckBox(i18n("Use pep editor instead of composer"), this))
, mEditorRequester(new KUrlRequester(this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins({});
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mpEpEditorCheck->setObjectName(QStringLiteral("enabled"));
mpEpEditorCheck->setChecked(false);
mainLayout->addWidget(mpEpEditorCheck);
auto hbox = new QHBoxLayout;
auto label = new QLabel(QStringLiteral("Specify editor:"), this);
label->setObjectName(QStringLiteral("urlrequesterlabel"));
hbox->addWidget(label);
mEditorRequester->setObjectName(QStringLiteral("mEditorRequester"));
hbox->addWidget(mEditorRequester);
mEditorRequester->setMimeTypeFilters(
{QStringLiteral("application/x-executable"), QStringLiteral("application/x-shellscript"), QStringLiteral("application/x-desktop")});
mEditorRequester->setMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly);
mEditorRequester->setEnabled(false);
mainLayout->addLayout(hbox);
label = new QLabel(i18n("<b>%f</b> will be replaced with the "
"filename to edit.<br />"
"<b>%w</b> will be replaced with the window id.<br />"
"<b>%l</b> will be replaced with the line number."),
this);
label->setObjectName(QStringLiteral("explanationlabel"));
label->setEnabled(false); // see above
mainLayout->addWidget(label);
mainLayout->addStretch(1);
connect(mpEpEditorCheck, &QAbstractButton::toggled, label, &QWidget::setEnabled);
connect(mpEpEditorCheck, &QAbstractButton::toggled, mEditorRequester, &QWidget::setEnabled);
}
pEpComposerConfigureWidget::~pEpComposerConfigureWidget()
{
}
void pEpComposerConfigureWidget::loadSettings()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(QStringLiteral("pEp Composer"));
mpEpEditorCheck->setChecked(group.readEntry("Enabled", false));
mEditorRequester->setText(group.readEntry("ComposerPath", QStringLiteral("kwrite %f")));
}
void pEpComposerConfigureWidget::saveSettings()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(QStringLiteral("pEp Composer"));
group.writeEntry("Enabled", mpEpEditorCheck->isChecked());
group.writeEntry("ComposerPath", mEditorRequester->text());
}
void pEpComposerConfigureWidget::resetSettings()
{
mpEpEditorCheck->setChecked(false);
mEditorRequester->setText(QStringLiteral("kwrite %f"));
}

+ 28
- 0
pepcomposer/pepcomposerconfigurewidget.h View File

@ -0,0 +1,28 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <MessageComposer/PluginEditorConfigureBaseWidget>
class QWidget;
class QCheckBox;
class KUrlRequester;
class pEpComposerConfigureWidget : public MessageComposer::PluginEditorConfigureBaseWidget
{
Q_OBJECT
public:
explicit pEpComposerConfigureWidget(QWidget *parent = nullptr);
~pEpComposerConfigureWidget() override;
void loadSettings() override;
void saveSettings() override;
void resetSettings() override;
private:
QCheckBox *const mpEpEditorCheck;
KUrlRequester *const mEditorRequester;
};

+ 40
- 0
pepcomposer/pepcomposerplugineditor.cpp View File

@ -0,0 +1,40 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pepcomposerplugineditor.h"
#include "pepcomposerconfiguredialog.h"
#include "pepcomposerplugineditorinterface.h"
#include <KPluginFactory>
K_PLUGIN_CLASS_WITH_JSON(pEpComposerPluginEditor, "kmail_pepcomposereditorplugin.json")
pEpComposerPluginEditor::pEpComposerPluginEditor(QObject *parent, const QList<QVariant> &)
: MessageComposer::PluginEditorInit(parent)
{
}
pEpComposerPluginEditor::~pEpComposerPluginEditor()
{
}
MessageComposer::PluginEditorInitInterface *pEpComposerPluginEditor::createInterface(QObject *parent)
{
auto interface = new pEpComposerPluginEditorInterface(parent);
return interface;
}
bool pEpComposerPluginEditor::hasConfigureDialog() const
{
return true;
}
void pEpComposerPluginEditor::showConfigureDialog(QWidget *parent)
{
pEpComposerConfigureDialog dlg(parent);
dlg.exec();
}
#include "pepcomposerplugineditor.moc"

+ 26
- 0
pepcomposer/pepcomposerplugineditor.h View File

@ -0,0 +1,26 @@
/*
SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <MessageComposer/PluginEditorInit>
#include <MessageComposer/PluginEditorInterface>
#include <QVariant>
class pEpComposerPluginEditor : public MessageComposer::PluginEditorInit
{
Q_OBJECT
public:
explicit pEpComposerPluginEditor(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
~pEpComposerPluginEditor() override;
MessageComposer::PluginEditorInitInterface *createInterface(QObject *parent = nullptr) override;
Q_REQUIRED_RESULT bool hasConfigureDialog() const override;
void showConfigureDialog(QWidget *parent) override;
};

+ 36
- 0
pepcomposer/pepcomposerplugineditorinterface.cpp View File

@ -0,0 +1,36 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pepcomposerplugineditorinterface.h"
#include <KConfigGroup>
#include <KPIMTextEdit/RichTextComposer>
#include <KSharedConfig>
pEpComposerPluginEditorInterface::pEpComposerPluginEditorInterface(QObject *parent)
: MessageComposer::PluginEditorInitInterface(parent)
{
}
pEpComposerPluginEditorInterface::~pEpComposerPluginEditorInterface()
{
}
bool pEpComposerPluginEditorInterface::exec()
{
/*if (mEnabled) {
richTextEditor()->setUsepEpEditor(mEnabled);
richTextEditor()->setpEpEditorPath(mpEpComposerPath);
}*/
return true;
}
void pEpComposerPluginEditorInterface::reloadConfig()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(QStringLiteral("pEp Composer"));
mEnabled = group.readEntry("Enabled", false);
mpEpComposerPath = group.readEntry("ComposerPath", QString());
}

+ 25
- 0
pepcomposer/pepcomposerplugineditorinterface.h View File

@ -0,0 +1,25 @@
/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <MessageComposer/PluginEditorInitInterface>
class pEpComposerPluginEditorInterface : public MessageComposer::PluginEditorInitInterface
{
Q_OBJECT
public:
explicit pEpComposerPluginEditorInterface(QObject *parent = nullptr);
~pEpComposerPluginEditorInterface() override;
Q_REQUIRED_RESULT bool exec() override;
void reloadConfig() override;
private:
QString mpEpComposerPath;
bool mEnabled = false;
};

Loading…
Cancel
Save