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.
 

127 lines
3.2 KiB

/*
SPDX-FileCopyrightText: 2015-2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "viewerpluginpepinterface.h"
#include "pepplugin_debug.h"
#include <KLocalizedString>
#include <KActionCollection>
#include <QLayout>
#include <QLabel>
#include <QIcon>
#include <QAction>
#include <QPushButton>
#include <QPainter>
#include <QColor>
#include <QStringLiteral>
#include <QByteArray>
#include <QVariantList>
#include <MessageViewer/CSSHelper>
#include <KontactInterface/Core>
#include <KontactInterface/PimUniqueApplication>
#include <Akonadi/ItemFetchJob>
#include <Akonadi/ItemFetchScope>
#include <Akonadi/ServerManager>
// glue code for conversion
#include <kde_pep_common/pephelpers.h>
// The pEp engine
#include <pEp/mime.h>
#include <pEp/message.h>
using namespace MessageViewer;
pEpViewerInterface::pEpViewerInterface(KActionCollection *ac, QWidget *parent)
: ViewerPluginInterface(parent)
{
mStatusWidget = new QWidget(parent);
mStatusWidget->setFixedHeight(20);
parent->layout()->addWidget(mStatusWidget);
m_pEpClient = new QDBusInterface(
QStringLiteral("org.freedesktop.Akonadi.Agent.pEpAgent"),
QStringLiteral("/security/pep"),
QStringLiteral("security.pep"),
QDBusConnection::sessionBus()
);
}
pEpViewerInterface::~pEpViewerInterface()
{
qDebug() << __FUNCTION__;
}
QList<QAction *> pEpViewerInterface::actions() const
{
qDebug() << __FUNCTION__;
return mAction;
}
void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
{
message *m;
QList<QVariant> args;
QByteArray type;
char *ms;
if(value) {
type = value->contentType()->mimeType();
if (value->subject()->asUnicodeString() == QStringLiteral("p≡p")) {
if (m_pEpClient->isValid()) {
m = pEpKDE::to_pEpMessage(value, PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
qDebug() << "ms encoded: " << ms;
auto ret = m_pEpClient->call(QStringLiteral("decrypt_message"), QLatin1String(ms));
args = ret.arguments();
qDebug() << args;
}
}
/*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")) {
}*/
}
}
void pEpViewerInterface::closePlugin()
{
qDebug() << __FUNCTION__;
}
void pEpViewerInterface::showWidget()
{
qDebug() << __FUNCTION__;
}
void pEpViewerInterface::setMessageItem(const Akonadi::Item &item)
{
if(item.hasPayload()) {
setMessage(item.payload<KMime::Message::Ptr>());
}
}
ViewerPluginInterface::SpecificFeatureTypes pEpViewerInterface::featureTypes() const
{
return ViewerPluginInterface::NeedMessage;
}
void pEpViewerInterface::updateAction(const Akonadi::Item &item)
{
if(item.hasPayload()) {
setMessageItem(item);
}
}