KDE PIM support for the p≡p engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

191 lines
7.0 KiB

/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pepcomposerplugineditorinterface.h"
#include "pepplugincomposerinterface.h"
#include "kmail/src/widgets/kactionmenutransport.h"
#include <pEp/message.h>
#include <pEp/mime.h>
#include <QAction>
#include <QDebug>
#include <QPushButton>
#include <QTextBlock>
#include <QIcon>
#include <KActionCollection>
#include <KLocalizedString>
#include <KPIMTextEdit/RichTextEditor>
#include <KPIMTextEdit/RichTextComposer>
#include <KConfigGroup>
#include <KSharedConfig>
pEpComposerPluginEditorInterface::pEpComposerPluginEditorInterface(QObject *parent)
: MessageComposer::PluginEditorInterface(parent)
{
}
pEpComposerPluginEditorInterface::~pEpComposerPluginEditorInterface()
{
}
void pEpComposerPluginEditorInterface::exec()
{
qDebug() << __func__;
}
void pEpComposerPluginEditorInterface::prepareMessage()
{
char *ms;
bool might_be_pep;
::message *m = ::new_message(PEP_dir_outgoing);
m->longmsg = richTextEditor()->toPlainText().toLatin1().data();
::mime_encode_message(m, true, &ms, true);
::mime_decode_message(ms, strlen(ms), &m, &might_be_pep);
//::mime_decode_message(mqs.toLatin1().data(), mqs.toLatin1().size(), &m, &might_be_pep );
qDebug() << m->longmsg;
qDebug() << composerInterface()->convertText(QStringLiteral("miau"));
// qDebug() << richTextEditor()->toPlainText();
}
void pEpComposerPluginEditorInterface::slotSendNow()
{
prepareMessage();
}
void pEpComposerPluginEditorInterface::slotSendNowByShortcut()
{
prepareMessage();
}
void pEpComposerPluginEditorInterface::slotSendLater()
{
prepareMessage();
}
void pEpComposerPluginEditorInterface::slotSendNowVia(MailTransport::Transport *transport)
{
prepareMessage();
}
void pEpComposerPluginEditorInterface::slotSendLaterVia(MailTransport::Transport *transport)
{
prepareMessage();
}
void pEpComposerPluginEditorInterface::slotActivated()
{
emit emitPluginActivated(this);
}
void pEpComposerPluginEditorInterface::createAction(KActionCollection *ac)
{
QIcon::setThemeName(QStringLiteral("hicolor"));
QAction *action;
KActionMenuTransport* actActionNowMenu;
KActionMenuTransport* actActionLaterMenu;
if (MessageComposer::MessageComposerSettings::self()->sendImmediate()) {
// default = send now, alternative = queue
action = new QAction(QIcon::fromTheme(QStringLiteral("mail-send")), i18n("&Send Mail"), this);
ac->addAction(QStringLiteral("send_default"), action);
ac->setDefaultShortcut(action, QKeySequence(Qt::CTRL | Qt::Key_Return));
connect(action, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotSendNowByShortcut);
actActionNowMenu = new KActionMenuTransport(this);
actActionNowMenu->setIcon(QIcon::fromTheme(QStringLiteral("mail-send")));
actActionNowMenu->setText(i18n("&Send Mail Via"));
actActionNowMenu->setIconText(i18n("Send"));
ac->addAction(QStringLiteral("send_default_via"), actActionNowMenu);
action = new QAction(QIcon::fromTheme(QStringLiteral("mail-queue")), i18n("Send &Later"), this);
ac->addAction(QStringLiteral("send_alternative"), action);
connect(action, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotSendLater);
actActionLaterMenu = new KActionMenuTransport(this);
actActionLaterMenu->setIcon(QIcon::fromTheme(QStringLiteral("mail-queue")));
actActionLaterMenu->setText(i18n("Send &Later Via"));
actActionLaterMenu->setIconText(i18nc("Queue the message for sending at a later date", "Queue"));
ac->addAction(QStringLiteral("send_alternative_via"), actActionLaterMenu);
} else {
// default = queue, alternative = send now
action = new QAction(QIcon::fromTheme(QStringLiteral("mail-queue")), i18n("Send &Later"), this);
ac->addAction(QStringLiteral("send_default"), action);
connect(action, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotSendLater);
ac->setDefaultShortcut(action, QKeySequence(Qt::CTRL | Qt::Key_Return));
actActionLaterMenu = new KActionMenuTransport(this);
actActionLaterMenu->setIcon(QIcon::fromTheme(QStringLiteral("mail-queue")));
actActionLaterMenu->setText(i18n("Send &Later Via"));
ac->addAction(QStringLiteral("send_default_via"), actActionLaterMenu);
action = new QAction(QIcon::fromTheme(QStringLiteral("mail-send")), i18n("&Send Mail"), this);
ac->addAction(QStringLiteral("send_alternative"), action);
connect(action, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotSendNow);
actActionNowMenu = new KActionMenuTransport(this);
actActionNowMenu->setIcon(QIcon::fromTheme(QStringLiteral("mail-send")));
actActionNowMenu->setText(i18n("&Send Mail Via"));
ac->addAction(QStringLiteral("send_alternative_via"), actActionNowMenu);
}
connect(actActionNowMenu, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotSendNow);
connect(actActionLaterMenu, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotSendLater);
connect(actActionNowMenu, &KActionMenuTransport::transportSelected, this, &pEpComposerPluginEditorInterface::slotSendNowVia);
connect(actActionLaterMenu, &KActionMenuTransport::transportSelected, this, &pEpComposerPluginEditorInterface::slotSendLaterVia);
action = new QAction(QStringLiteral("&p≡p Security"), this);
action->setIcon(QIcon::fromTheme(QStringLiteral("akonadi-pep")));
ac->addAction(QStringLiteral("pep_icon"), action);
ac->addAction(QStringLiteral("encrypt_message"), action);
ac->addAction(QStringLiteral("sign_message"), action);
MessageComposer::PluginActionType type(action, MessageComposer::PluginActionType::ToolBar);
setActionType(type);
connect(action, &QAction::triggered, this, &pEpComposerPluginEditorInterface::slotActivated);
auto button = new QPushButton(QStringLiteral("pEp button"));
button->setIcon(QIcon::fromTheme(QStringLiteral("akonadi-pep")));
setStatusBarWidget(button);
//PimCommon::ActionType type(action, PimCommon::ActionType::Tools);
//addActionType(type);
}
void pEpComposerPluginEditorInterface::reloadConfig()
{
}
#if 0
bool pEpComposerPluginEditorInterface::exec(const MessageComposer::PluginEditorCheckBeforeSendParams &params)
{
/*if (mEnabled) {
richTextEditor()->setUsepEpEditor(mEnabled);
richTextEditor()->setpEpEditorPath(mpEpComposerPath);
}*/
qDebug() << "Execute autencrypt";
params.setHtmlMail(false);
qDebug() << "Original: " << params.plainText();
params.setPlainText(QStringLiteral("Miau Test 42"));
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());
}
#endif