Messagelib

templateparserextracthtmlinfo.cpp
1/*
2 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "templateparserextracthtmlinfo.h"
8#include "templateextracthtmlelementfrommail.h"
9#include "templateextracttextfrommail.h"
10#include "templateparser_debug.h"
11
12using namespace TemplateParser;
13
14TemplateParserExtractHtmlInfo::TemplateParserExtractHtmlInfo(QObject *parent)
15 : QObject(parent)
16{
17}
18
19TemplateParserExtractHtmlInfo::~TemplateParserExtractHtmlInfo()
20{
21 if (mTemplateWebEngineView) {
22 mTemplateWebEngineView->deleteLater();
23 }
24 if (mExtractHtmlElementWebEngineView) {
25 mExtractHtmlElementWebEngineView->deleteLater();
26 }
27}
28
29void TemplateParserExtractHtmlInfo::setHtmlForExtractingTextPlain(const QString &html)
30{
31 mHtmlForExtractingTextPlain = html;
32}
33
34void TemplateParserExtractHtmlInfo::setHtmlForExtractionHeaderAndBody(const QString &html)
35{
36 mHtmlForExtractionHeaderAndBody = html;
37}
38
39void TemplateParserExtractHtmlInfo::setTemplate(const QString &str)
40{
41 mTemplateStr = str;
42}
43
44void TemplateParserExtractHtmlInfo::start()
45{
46 mResult.clear();
47 mResult.mTemplate = mTemplateStr;
48 if (!mHtmlForExtractingTextPlain.isEmpty()) {
49 mTemplateWebEngineView = new TemplateExtractTextFromMail;
50 connect(mTemplateWebEngineView, &TemplateExtractTextFromMail::loadContentDone, this, &TemplateParserExtractHtmlInfo::slotExtractToPlainTextFinished);
51 mTemplateWebEngineView->setHtmlContent(mHtmlForExtractingTextPlain);
52 } else {
53 qCDebug(TEMPLATEPARSER_LOG) << "html string is empty for extracting to plainText";
54 slotExtractToPlainTextFinished(false);
55 }
56}
57
58void TemplateParserExtractHtmlInfo::slotExtractToPlainTextFinished(bool success)
59{
60 if (success) {
61 mResult.mPlainText = mTemplateWebEngineView->plainText();
62 } else {
63 qCDebug(TEMPLATEPARSER_LOG) << "Impossible to extract plaintext";
64 }
65 if (!mHtmlForExtractionHeaderAndBody.isEmpty()) {
66 mExtractHtmlElementWebEngineView = new TemplateExtractHtmlElementFromMail;
67 connect(mExtractHtmlElementWebEngineView,
68 &TemplateExtractHtmlElementFromMail::loadContentDone,
69 this,
70 &TemplateParserExtractHtmlInfo::slotExtractHtmlElementFinished);
71 mExtractHtmlElementWebEngineView->setHtmlContent(mHtmlForExtractionHeaderAndBody);
72 } else {
73 qCDebug(TEMPLATEPARSER_LOG) << "html string is empty for extracting to header and body";
74 slotExtractHtmlElementFinished(false);
75 }
76}
77
78void TemplateParserExtractHtmlInfo::slotExtractHtmlElementFinished(bool success)
79{
80 if (success) {
81 mResult.mBodyElement = mExtractHtmlElementWebEngineView->bodyElement();
82 mResult.mHeaderElement = mExtractHtmlElementWebEngineView->headerElement();
83 mResult.mHtmlElement = mExtractHtmlElementWebEngineView->htmlElement();
84 } else {
85 qCDebug(TEMPLATEPARSER_LOG) << "Impossible to extract html element";
86 }
87 Q_EMIT finished(mResult);
89}
90
91#include "moc_templateparserextracthtmlinfo.cpp"
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.