Messagelib

templateextracttextfrommail.cpp
1 /*
2  SPDX-FileCopyrightText: 2017-2021 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> struct InvokeWrapper {
14  R *receiver;
15  void (C::*memberFun)(Arg);
16  void operator()(Arg result)
17  {
18  (receiver->*memberFun)(result);
19  }
20 };
21 
22 template<typename Arg, typename R, typename C> InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg))
23 {
24  InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
25  return wrapper;
26 }
27 
28 TemplateExtractTextFromMail::TemplateExtractTextFromMail(QObject *parent)
29  : QObject(parent)
30  , mPage(new TemplateWebEnginePage(this))
31 {
32  connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateExtractTextFromMail::slotLoadFinished);
33 }
34 
35 TemplateExtractTextFromMail::~TemplateExtractTextFromMail() = default;
36 
37 void TemplateExtractTextFromMail::setHtmlContent(const QString &html)
38 {
39  mExtractedPlainText.clear();
40  mPage->setHtml(html);
41 }
42 
43 void TemplateExtractTextFromMail::slotLoadFinished(bool ok)
44 {
45  if (ok) {
46  mPage->toPlainText(invoke(this, &TemplateExtractTextFromMail::setPlainText));
47  } else {
48  qCWarning(TEMPLATEPARSER_LOG) << "Loading page failed";
49  Q_EMIT loadContentDone(false);
50  }
51 }
52 
53 void TemplateExtractTextFromMail::setPlainText(const QString &plainText)
54 {
55  mExtractedPlainText = plainText;
56  Q_EMIT loadContentDone(true);
57 }
58 
59 QString TemplateExtractTextFromMail::plainText() const
60 {
61  return mExtractedPlainText;
62 }
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.