Messagelib

templateextracttextfrommail.cpp
1 /*
2  SPDX-FileCopyrightText: 2017-2022 Laurent Montel <[email protected]>
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 
11 using namespace TemplateParser;
12 
13 template<typename Arg, typename R, typename C>
14 struct InvokeWrapper {
15  R *receiver;
16  void (C::*memberFun)(Arg);
17  void operator()(Arg result)
18  {
19  (receiver->*memberFun)(result);
20  }
21 };
22 
23 template<typename Arg, typename R, typename C>
24 InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg))
25 {
26  InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
27  return wrapper;
28 }
29 
30 TemplateExtractTextFromMail::TemplateExtractTextFromMail(QObject *parent)
31  : QObject(parent)
32  , mPage(new TemplateWebEnginePage(this))
33 {
34  connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateExtractTextFromMail::slotLoadFinished);
35 }
36 
37 TemplateExtractTextFromMail::~TemplateExtractTextFromMail() = default;
38 
39 void TemplateExtractTextFromMail::setHtmlContent(const QString &html)
40 {
41  mExtractedPlainText.clear();
42  mPage->setHtml(html);
43 }
44 
45 void 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 
55 void TemplateExtractTextFromMail::setPlainText(const QString &plainText)
56 {
57  mExtractedPlainText = plainText;
58  Q_EMIT loadContentDone(true);
59 }
60 
61 QString TemplateExtractTextFromMail::plainText() const
62 {
63  return mExtractedPlainText;
64 }
Q_EMITQ_EMIT
void clear()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue May 17 2022 04:00:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.