Commit 19f78a52 authored by Laurent Montel's avatar Laurent Montel 😁

Add support for embedeed part (cid image)

parent f71a5fe0
/*
Copyright (c) 2016 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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "webengineembedparttest.h"
#include "../webengineembedpart.h"
#include <QTest>
WebEngineEmbedPartTest::WebEngineEmbedPartTest(QObject *parent)
: QObject(parent)
{
}
WebEngineEmbedPartTest::~WebEngineEmbedPartTest()
{
}
void WebEngineEmbedPartTest::shouldHaveDefaultValue()
{
MessageViewer::WebEngineEmbedPart part;
QVERIFY(part.isEmpty());
}
void WebEngineEmbedPartTest::shouldClearValue()
{
MessageViewer::WebEngineEmbedPart part;
part.addEmbedPart(QByteArrayLiteral("foo"), QStringLiteral("bla"));
QVERIFY(!part.isEmpty());
QCOMPARE(part.embeddedPartMap().count(), 1);
part.clear();
QVERIFY(part.isEmpty());
}
void WebEngineEmbedPartTest::shouldAddValues()
{
MessageViewer::WebEngineEmbedPart part;
part.addEmbedPart(QByteArrayLiteral("foo"), QStringLiteral("bla"));
QVERIFY(!part.isEmpty());
QCOMPARE(part.embeddedPartMap().count(), 1);
part.addEmbedPart(QByteArrayLiteral("foo1"), QStringLiteral("bla"));
QCOMPARE(part.embeddedPartMap().count(), 2);
}
void WebEngineEmbedPartTest::shouldAddTwoIdenticalValues()
{
MessageViewer::WebEngineEmbedPart part;
part.addEmbedPart(QByteArrayLiteral("foo"), QStringLiteral("bla"));
QVERIFY(!part.isEmpty());
QCOMPARE(part.embeddedPartMap().count(), 1);
part.addEmbedPart(QByteArrayLiteral("foo"), QStringLiteral("bla"));
QCOMPARE(part.embeddedPartMap().count(), 1);
}
QTEST_MAIN(WebEngineEmbedPartTest)
/*
Copyright (c) 2016 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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef WEBENGINEEMBEDPARTTEST_H
#define WEBENGINEEMBEDPARTTEST_H
#include <QObject>
class WebEngineEmbedPartTest : public QObject
{
Q_OBJECT
public:
explicit WebEngineEmbedPartTest(QObject *parent = Q_NULLPTR);
~WebEngineEmbedPartTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldClearValue();
void shouldAddValues();
void shouldAddTwoIdenticalValues();
};
#endif // WEBENGINEEMBEDPARTTEST_H
/*
Copyright (c) 2016 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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "webengineembedpart.h"
using namespace MessageViewer;
class WebEngineEmbedPartInstancePrivate
{
public:
WebEngineEmbedPartInstancePrivate()
: webEngineEmbedPart(new WebEngineEmbedPart)
{
}
~WebEngineEmbedPartInstancePrivate()
{
delete webEngineEmbedPart;
}
WebEngineEmbedPart *webEngineEmbedPart;
};
Q_GLOBAL_STATIC(WebEngineEmbedPartInstancePrivate, sInstance)
WebEngineEmbedPart::WebEngineEmbedPart(QObject *parent)
: QObject(parent)
{
}
WebEngineEmbedPart::~WebEngineEmbedPart()
{
}
WebEngineEmbedPart *WebEngineEmbedPart::self()
{
return sInstance->webEngineEmbedPart;
}
QString WebEngineEmbedPart::contentUrl(const QString &contentId) const
{
return mEmbeddedPartMap.value(contentId);
}
void WebEngineEmbedPart::addEmbedPart(const QByteArray &contentId, const QString &contentURL)
{
mEmbeddedPartMap[QLatin1String(contentId)] = contentURL;
}
void WebEngineEmbedPart::clear()
{
mEmbeddedPartMap.clear();
}
bool WebEngineEmbedPart::isEmpty() const
{
return mEmbeddedPartMap.isEmpty();
}
QMap<QString, QString> WebEngineEmbedPart::embeddedPartMap() const
{
return mEmbeddedPartMap;
}
/*
Copyright (c) 2016 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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef WEBENGINEEMBEDPART_H
#define WEBENGINEEMBEDPART_H
#include <QObject>
#include <QMap>
namespace MessageViewer
{
class WebEngineEmbedPart : public QObject
{
Q_OBJECT
public:
explicit WebEngineEmbedPart(QObject *parent = Q_NULLPTR);
~WebEngineEmbedPart();
void clear();
bool isEmpty() const;
QMap<QString, QString> embeddedPartMap() const;
void addEmbedPart(const QByteArray &contentId, const QString &contentURL);
QString contentUrl(const QString &contentId) const;
static WebEngineEmbedPart *self();
private:
// Key is Content-Id, value is URL
QMap<QString, QString> mEmbeddedPartMap;
};
}
#endif // WEBENGINEEMBEDPART_H
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