Messagelib

templateextracttextfrommail.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 "templateextracttextfrommail.h"
8#include "templateparser_debug.h"
9#include "templatewebenginepage.h"
10
11using namespace TemplateParser;
12
13template<typename Arg, typename R, typename C>
14struct InvokeWrapper {
15 R *receiver;
16 void (C::*memberFun)(Arg);
17 void operator()(Arg result)
18 {
19 (receiver->*memberFun)(result);
20 }
21};
22
23template<typename Arg, typename R, typename C>
24InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg))
25{
26 InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
27 return wrapper;
28}
29
30TemplateExtractTextFromMail::TemplateExtractTextFromMail(QObject *parent)
31 : QObject(parent)
32 , mPage(new TemplateWebEnginePage(this))
33{
34 connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateExtractTextFromMail::slotLoadFinished);
35}
36
37TemplateExtractTextFromMail::~TemplateExtractTextFromMail() = default;
38
39void TemplateExtractTextFromMail::setHtmlContent(const QString &html)
40{
41 mExtractedPlainText.clear();
42 mPage->setHtml(html);
43}
44
45void TemplateExtractTextFromMail::slotLoadFinished(bool ok)
46{
47 if (ok) {
48 mPage->toPlainText(invoke(this, &TemplateExtractTextFromMail::setPlainText));
49 } else {
50 qCWarning(TEMPLATEPARSER_LOG) << "Loading page failed";
51 Q_EMIT loadContentDone(false);
52 }
53}
54
55void TemplateExtractTextFromMail::setPlainText(const QString &plainText)
56{
57 mExtractedPlainText = plainText;
58 Q_EMIT loadContentDone(true);
59}
60
61QString TemplateExtractTextFromMail::plainText() const
62{
63 return mExtractedPlainText;
64}
65
66#include "moc_templateextracttextfrommail.cpp"
Q_EMITQ_EMIT
void clear()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.