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.
 

167 lines
4.5 KiB

/*
SPDX-FileCopyrightText: 2015-2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "viewerpluginpepinterface.h"
#include "pepjob.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 <QDBusInterface>
#include <QDBusReply>
#include <ItemFetchJob>
#include <ItemFetchScope>
#include <MessageViewer/CSSHelper>
#include <KontactInterface/Core>
#include <KontactInterface/PimUniqueApplication>
#include <AkonadiCore/ServerManager>
using namespace MessageViewer;
pEpViewerInterface::pEpViewerInterface(KActionCollection *ac, QWidget *parent)
: ViewerPluginInterface(parent)
{
QDBusInterface *pEpAgent = nullptr;
mStatusWidget = new QWidget(parent);
mStatusWidget->setFixedHeight(20);
parent->layout()->addWidget(mStatusWidget);
const QString service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("pEpAgent"));
qDebug() << service;
//qDebug() << QDBusConnection::sessionBus().objectRegisteredAt(service);
pEpAgent = new QDBusInterface(
service,
QStringLiteral("/pEpAgent"),
QStringLiteral("org.freedesktop.Akonadi.Agent.pEpAgent"),
QDBusConnection::sessionBus()
);
if (pEpAgent->isValid()) {
m_pEpAgent = pEpAgent;
//qDebug() << m_pEpAgent->call(QStringLiteral("decryptMessage"), QVariant::fromValue(42));
qDebug() << m_pEpAgent->call(QStringLiteral("resetIdentity"));
} else {
qDebug() << __FUNCTION__ << ": Could not connect to the pEp agent (" << pEpAgent->lastError().message() << ")";
}
/*korgIface.call(QStringLiteral("showEventView"));
korgIface.call(QStringLiteral("showDate"), date);*/
//} else {
// qDebug() << __FUNCTION__ << "Could not activate pEp agent";
//}
}
pEpViewerInterface::~pEpViewerInterface()
{
qDebug() << __FUNCTION__;
}
void pEpViewerInterface::setText(const QString &text)
{
qDebug() << __FUNCTION__;
//if(mTestWidget) mTestWidget->setText(text);
//Q_UNUSED(text);
//Nothing
}
QList<QAction *> pEpViewerInterface::actions() const
{
qDebug() << __FUNCTION__;
return mAction;
}
bool pEpViewerInterface::isApEpMessage(KMime::Content *content)
{
if(!content)
return false;
if(content->attachments().size()) {
qDebug() << __FUNCTION__ << "Has attachments";
for(KMime::Content *c : content->attachments()) {
//if(isApEpMessage(c)) return true;
isApEpMessage(c);
}
} else {
//qDebug() << content->decodedContent();
}
qDebug() << __FUNCTION__ << "Not a pEp message";
//qDebug() << content->contentType()->name();
return false;
}
void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
{
QByteArray type;
QDBusReply<QVariant> reply;
QVariant testload = QVariant(QStringLiteral("test"));
if(value) {
mMessage = value;
if(!m_pEpAgent) { qDebug() << "DBus not connected"; return; } // We're not connected to the agent
type = mMessage->contentType()->mimeType();
if(type==QByteArray("multipart/mixed")) {
qDebug() << "Multipart detected";
} else if(type==QByteArray("multipart/encrypted")) {
qDebug() << "Encrypted message detected";
//reply = m_pEpAgent->call(QStringLiteral("decryptMessage"), mMessage);
reply = m_pEpAgent->call(QStringLiteral("decryptMessage"), testload);
qDebug() << reply;
} else {
qDebug() << type;
}
//value->mainBodyPart()->assemble();
//if(isApEpMessage(value->mainBodyPart())) qDebug() << "pEp message detected";
//else qDebug() << "Not a pEp message";
}
}
void pEpViewerInterface::closePlugin()
{
qDebug() << __FUNCTION__;
}
void pEpViewerInterface::showWidget()
{
qDebug() << __FUNCTION__;
}
void pEpViewerInterface::setMessageItem(const Akonadi::Item &item)
{
mMessageItem = item;
if(item.hasPayload()) {
setMessage(item.payload<KMime::Message::Ptr>());
}
}
ViewerPluginInterface::SpecificFeatureTypes pEpViewerInterface::featureTypes() const
{
qDebug() << __FUNCTION__;
return ViewerPluginInterface::NeedMessage;
}
void pEpViewerInterface::updateAction(const Akonadi::Item &item)
{
qDebug() << __FUNCTION__;
mMessageItem = item;
if(item.hasPayload()) {
setMessage(item.payload<KMime::Message::Ptr>());
}
}