Commit c299ecd0 authored by Volker Krause's avatar Volker Krause
Browse files

Determine embedded images without depending on a rich text widget

Iterating over a QTextDocument is hardly more work, and it will enable
to split core classes and widget classes into separate libraries in a
next step.
parent 822c6b39
Pipeline #136357 failed with stages
in 43 seconds
......@@ -14,12 +14,11 @@
#include <KMessageBox>
#include <KProcess>
#include <QDir>
#include <QSharedPointer>
#include <QTextBlock>
#include <QTextDocument>
#include <KPIMTextEdit/RichTextComposer>
#include <KPIMTextEdit/RichTextComposerControler>
#include <KPIMTextEdit/RichTextComposerImages>
#include <QDir>
#include <cassert>
using namespace KIdentityManagement;
......@@ -55,17 +54,21 @@ public:
// Returns the names of all images in the HTML code
static QStringList findImageNames(const QString &htmlCode)
{
QStringList ret;
// To complicated for us, so cheat and let a text edit do the hard work
KPIMTextEdit::RichTextComposer edit;
edit.setHtml(htmlCode);
const KPIMTextEdit::ImageWithNameList images = edit.composerControler()->composerImages()->imagesWithName();
ret.reserve(images.count());
for (const KPIMTextEdit::ImageWithNamePtr &image : images) {
ret << image->name;
QStringList imageNames;
QTextDocument doc;
doc.setHtml(htmlCode);
for (auto block = doc.begin(); block.isValid(); block = block.next()) {
for (auto it = block.begin(); !it.atEnd(); ++it) {
const auto fragment = it.fragment();
if (fragment.isValid()) {
const auto imageFormat = fragment.charFormat().toImageFormat();
if (imageFormat.isValid() && !imageFormat.name().startsWith(QLatin1String("http")) && !imageNames.contains(imageFormat.name())) {
imageNames.push_back(imageFormat.name());
}
}
}
}
return ret;
return imageNames;
}
void SignaturePrivate::assignFrom(const KIdentityManagement::Signature &that)
......
Supports Markdown
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