diff --git a/templateparser/autotests/CMakeLists.txt b/templateparser/autotests/CMakeLists.txt index 3b15ee08..b7e659e2 100644 --- a/templateparser/autotests/CMakeLists.txt +++ b/templateparser/autotests/CMakeLists.txt @@ -1,39 +1,39 @@ include(ECMAddTests) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") include ( ${CMAKE_SOURCE_DIR}/cmake/modules/kdepim_add_gpg_crypto_test.cmake ) # convenience macro to add qtest unit tests macro(add_templateparser_unittest _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) add_executable( ${_name} ${_test} ) ecm_mark_as_test(templateparser-${_name}) target_link_libraries(${_name} KF5::Libkleo KF5::TemplateParser KF5::MimeTreeParser QGpgme Qt5::Test KF5::KIOCore KF5::Mime KF5::IdentityManagement KF5::XmlGui KF5::Completion KF5::IconThemes Qt5::WebEngineWidgets ) add_gpg_crypto_test(${_name} templateparser-${_name}) endmacro() add_templateparser_unittest(customtemplatesmenutest.cpp) -add_templateparser_unittest(templatewebengineviewtest.cpp) -add_templateparser_unittest(templateextracthtmlelementwebengineviewtest.cpp) +add_templateparser_unittest(templateextracttextfrommailtest.cpp) +add_templateparser_unittest(templateextracthtmlelementfrommailtest.cpp) add_templateparser_unittest(templateparserjobtest.cpp) add_templateparser_unittest(templateparserextracthtmlinfotest.cpp) add_templateparser_unittest(templateparseremailaddressrequesterlineedittest.cpp) add_templateparser_unittest(templateparseremailaddressrequesterinterfacewidgettest.cpp) add_templateparser_unittest(templatesinsertcommandactiontest.cpp) add_templateparser_unittest(templatesinsertcommandpushbuttontest.cpp) diff --git a/templateparser/autotests/templateextracthtmlelementwebengineviewtest.cpp b/templateparser/autotests/templateextracthtmlelementfrommailtest.cpp similarity index 73% rename from templateparser/autotests/templateextracthtmlelementwebengineviewtest.cpp rename to templateparser/autotests/templateextracthtmlelementfrommailtest.cpp index 74ca7fbe..9c77b913 100644 --- a/templateparser/autotests/templateextracthtmlelementwebengineviewtest.cpp +++ b/templateparser/autotests/templateextracthtmlelementfrommailtest.cpp @@ -1,65 +1,65 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "templateextracthtmlelementwebengineviewtest.h" -#include "templateextracthtmlelementwebengineview.h" +#include "templateextracthtmlelementfrommailtest.h" +#include "templateextracthtmlelementfrommail.h" #include #include -TemplateExtractHtmlElementWebEngineViewTest::TemplateExtractHtmlElementWebEngineViewTest(QObject *parent) +TemplateExtractHtmlElementFromMailTest::TemplateExtractHtmlElementFromMailTest(QObject *parent) : QObject(parent) { } -void TemplateExtractHtmlElementWebEngineViewTest::shouldHaveDefaultValue() +void TemplateExtractHtmlElementFromMailTest::shouldHaveDefaultValue() { - TemplateParser::TemplateExtractHtmlElementWebEngineView w; + TemplateParser::TemplateExtractHtmlElementFromMail w; QVERIFY(w.bodyElement().isEmpty()); QVERIFY(w.headerElement().isEmpty()); QVERIFY(w.htmlElement().isEmpty()); } -void TemplateExtractHtmlElementWebEngineViewTest::shouldExtractHtml_data() +void TemplateExtractHtmlElementFromMailTest::shouldExtractHtml_data() { QTest::addColumn("html"); QTest::addColumn("body"); QTest::addColumn("header"); QTest::newRow("test1") << QStringLiteral("HTML Text") << QStringLiteral("HTML Text") << QString(); QTest::newRow("empty") << QString() << QString() << QString(); } -void TemplateExtractHtmlElementWebEngineViewTest::shouldExtractHtml() +void TemplateExtractHtmlElementFromMailTest::shouldExtractHtml() { QFETCH(QString, html); QFETCH(QString, body); QFETCH(QString, header); - TemplateParser::TemplateExtractHtmlElementWebEngineView w; + TemplateParser::TemplateExtractHtmlElementFromMail w; QVERIFY(w.htmlElement().isEmpty()); - QSignalSpy spy(&w, &TemplateParser::TemplateExtractHtmlElementWebEngineView::loadContentDone); + QSignalSpy spy(&w, &TemplateParser::TemplateExtractHtmlElementFromMail::loadContentDone); w.setHtmlContent(html); QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); const bool result = spy.at(0).at(0).toBool(); QVERIFY(result); QCOMPARE(w.htmlElement(), html); QCOMPARE(w.headerElement(), header); QCOMPARE(w.bodyElement(), body); } -QTEST_MAIN(TemplateExtractHtmlElementWebEngineViewTest) +QTEST_MAIN(TemplateExtractHtmlElementFromMailTest) diff --git a/templateparser/autotests/templateextracthtmlelementwebengineviewtest.h b/templateparser/autotests/templateextracthtmlelementfrommailtest.h similarity index 84% rename from templateparser/autotests/templateextracthtmlelementwebengineviewtest.h rename to templateparser/autotests/templateextracthtmlelementfrommailtest.h index 9a30ab3f..0313b70e 100644 --- a/templateparser/autotests/templateextracthtmlelementwebengineviewtest.h +++ b/templateparser/autotests/templateextracthtmlelementfrommailtest.h @@ -1,37 +1,37 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TEMPLATEEXTRACTHTMLELEMENTWEBENGINEVIEWTEST_H #define TEMPLATEEXTRACTHTMLELEMENTWEBENGINEVIEWTEST_H #include -class TemplateExtractHtmlElementWebEngineViewTest : public QObject +class TemplateExtractHtmlElementFromMailTest : public QObject { Q_OBJECT public: - explicit TemplateExtractHtmlElementWebEngineViewTest(QObject *parent = nullptr); - ~TemplateExtractHtmlElementWebEngineViewTest() = default; + explicit TemplateExtractHtmlElementFromMailTest(QObject *parent = nullptr); + ~TemplateExtractHtmlElementFromMailTest() = default; private Q_SLOTS: void shouldHaveDefaultValue(); void shouldExtractHtml_data(); void shouldExtractHtml(); }; #endif // TEMPLATEEXTRACTHTMLELEMENTWEBENGINEVIEWTEST_H diff --git a/templateparser/autotests/templatewebengineviewtest.cpp b/templateparser/autotests/templateextracttextfrommailtest.cpp similarity index 68% rename from templateparser/autotests/templatewebengineviewtest.cpp rename to templateparser/autotests/templateextracttextfrommailtest.cpp index e82b1c1b..ef7dcf17 100644 --- a/templateparser/autotests/templatewebengineviewtest.cpp +++ b/templateparser/autotests/templateextracttextfrommailtest.cpp @@ -1,53 +1,53 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "templatewebengineviewtest.h" -#include "templatewebengineview.h" +#include "templateextracttextfrommailtest.h" +#include "templateextracttextfrommail.h" #include #include -TemplateWebEngineViewTest::TemplateWebEngineViewTest(QObject *parent) +TemplateExtractTextFromMailTest::TemplateExtractTextFromMailTest(QObject *parent) : QObject(parent) { } -TemplateWebEngineViewTest::~TemplateWebEngineViewTest() +TemplateExtractTextFromMailTest::~TemplateExtractTextFromMailTest() { } -void TemplateWebEngineViewTest::shouldHaveDefaultValue() +void TemplateExtractTextFromMailTest::shouldHaveDefaultValue() { - TemplateParser::TemplateWebEngineView w; + TemplateParser::TemplateExtractTextFromMail w; QVERIFY(w.plainText().isEmpty()); } -void TemplateWebEngineViewTest::shouldExtractHtml() +void TemplateExtractTextFromMailTest::shouldExtractHtml() { - TemplateParser::TemplateWebEngineView w; + TemplateParser::TemplateExtractTextFromMail w; QVERIFY(w.plainText().isEmpty()); - QSignalSpy spy(&w, &TemplateParser::TemplateWebEngineView::loadContentDone); + QSignalSpy spy(&w, &TemplateParser::TemplateExtractTextFromMail::loadContentDone); w.setHtmlContent(QStringLiteral("HTML Text")); QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); const bool result = spy.at(0).at(0).toBool(); QVERIFY(result); QCOMPARE(w.plainText(), QStringLiteral("HTML Text")); } -QTEST_MAIN(TemplateWebEngineViewTest) +QTEST_MAIN(TemplateExtractTextFromMailTest) diff --git a/templateparser/autotests/templatewebengineviewtest.h b/templateparser/autotests/templateextracttextfrommailtest.h similarity index 86% rename from templateparser/autotests/templatewebengineviewtest.h rename to templateparser/autotests/templateextracttextfrommailtest.h index 699ddde5..bcad38cb 100644 --- a/templateparser/autotests/templatewebengineviewtest.h +++ b/templateparser/autotests/templateextracttextfrommailtest.h @@ -1,36 +1,36 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TEMPLATEWEBENGINEVIEWTEST_H #define TEMPLATEWEBENGINEVIEWTEST_H #include -class TemplateWebEngineViewTest : public QObject +class TemplateExtractTextFromMailTest : public QObject { Q_OBJECT public: - explicit TemplateWebEngineViewTest(QObject *parent = nullptr); - ~TemplateWebEngineViewTest(); + explicit TemplateExtractTextFromMailTest(QObject *parent = nullptr); + ~TemplateExtractTextFromMailTest(); private Q_SLOTS: void shouldHaveDefaultValue(); void shouldExtractHtml(); }; #endif // TEMPLATEWEBENGINEVIEWTEST_H diff --git a/templateparser/src/CMakeLists.txt b/templateparser/src/CMakeLists.txt index 2af04aab..fb3053b7 100644 --- a/templateparser/src/CMakeLists.txt +++ b/templateparser/src/CMakeLists.txt @@ -1,126 +1,126 @@ add_definitions(-DTRANSLATION_DOMAIN=\"libtemplateparser\") set(templateparser_LIB_SRCS templateparserjob.cpp defaulttemplates.cpp templatesutil.cpp customtemplates.cpp customtemplatesmenu.cpp templatesconfiguration.cpp templatesinsertcommandpushbutton.cpp templatescommandmenu.cpp templatesinsertcommandaction.cpp templatestextedit.cpp templatestexteditor.cpp - templatewebengineview.cpp + templateextracttextfrommail.cpp templatewebenginepage.cpp - templateextracthtmlelementwebengineview.cpp + templateextracthtmlelementfrommail.cpp templateparserextracthtmlinfo.cpp templateparserextracthtmlinforesult.cpp templateparseremailaddressrequesterbase.cpp templateparseremailaddressrequesterlineedit.cpp templateparseremailaddressrequesterinterfacewidget.cpp templateconvertcommandjob.cpp ) ecm_qt_declare_logging_category(templateparser_LIB_SRCS HEADER templateparser_debug.h IDENTIFIER TEMPLATEPARSER_LOG CATEGORY_NAME org.kde.pim.templateparser) kconfig_add_kcfg_files(templateparser_LIB_SRCS settings/templatesconfiguration_kfg.kcfgc) kconfig_add_kcfg_files(templateparser_LIB_SRCS settings/customtemplates_kfg.kcfgc settings/globalsettings_templateparser.kcfgc ) ki18n_wrap_ui(templateparser_LIB_SRCS ui/templatesconfiguration_base.ui ui/customtemplates_base.ui ) add_library(KF5TemplateParser ${templateparser_LIB_SRCS}) generate_export_header(KF5TemplateParser BASE_NAME templateparser) add_library(KF5::TemplateParser ALIAS KF5TemplateParser) target_link_libraries(KF5TemplateParser PRIVATE KF5::Mime KF5::MimeTreeParser KF5::IdentityManagement KF5::MessageCore KF5::XmlGui KF5::IconThemes KF5::Completion KF5::Libkleo KF5::I18n KF5::SonnetUi KF5::SyntaxHighlighting Qt5::WebEngineWidgets ) set_target_properties(KF5TemplateParser PROPERTIES VERSION ${TEMPLATEPARSER_VERSION_STRING} SOVERSION ${TEMPLATEPARSER_SOVERSION} EXPORT_NAME TemplateParser ) target_include_directories(KF5TemplateParser INTERFACE "$") install(FILES settings/customtemplates_kfg.kcfg settings/templatesconfiguration_kfg.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} ) ecm_generate_headers(TemplateParser_CamelCase_HEADERS HEADER_NAMES CustomTemplates CustomTemplatesMenu DefaultTemplates TemplatesConfiguration TemplatesTextEdit TemplatesUtil TemplatesInsertCommandPushButton TemplatesCommandMenu TemplatesInsertCommandAction TemplateParserJob TemplateParserExtractHtmlInfoResult TemplateParserEmailAddressRequesterBase TemplateConvertCommandJob REQUIRED_HEADERS TemplateParser_HEADERS PREFIX TemplateParser ) ecm_generate_pri_file(BASE_NAME TemplateParser LIB_NAME KF5TemplateParser DEPS "" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/TemplateParser ) install(TARGETS KF5TemplateParser EXPORT KF5TemplateParserTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK}) install(FILES ${TemplateParser_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/TemplateParser COMPONENT Devel ) install(FILES ${TemplateParser_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/templateparser_export.h ${CMAKE_CURRENT_BINARY_DIR}/globalsettings_templateparser.h ${CMAKE_CURRENT_BINARY_DIR}/customtemplates_kfg.h ${CMAKE_CURRENT_BINARY_DIR}/ui_templatesconfiguration_base.h ${CMAKE_CURRENT_BINARY_DIR}/templatesconfiguration_kfg.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/templateparser COMPONENT Devel ) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) install(FILES syntax/kmail-template.xml DESTINATION ${KDE_INSTALL_DATADIR}/org.kde.syntax-highlighting/syntax) diff --git a/templateparser/src/templateextracthtmlelementwebengineview.cpp b/templateparser/src/templateextracthtmlelementfrommail.cpp similarity index 77% rename from templateparser/src/templateextracthtmlelementwebengineview.cpp rename to templateparser/src/templateextracthtmlelementfrommail.cpp index 9d83f2c4..032ffa37 100644 --- a/templateparser/src/templateextracthtmlelementwebengineview.cpp +++ b/templateparser/src/templateextracthtmlelementfrommail.cpp @@ -1,118 +1,118 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "templateextracthtmlelementwebengineview.h" +#include "templateextracthtmlelementfrommail.h" #include "templateparser_debug.h" #include "templatewebenginepage.h" #include template struct InvokeWrapper { R *receiver; void (C::*memberFun)(Arg); void operator()(Arg result) { (receiver->*memberFun)(result); } }; template InvokeWrapper invoke(R *receiver, void (C::*memberFun)(Arg)) { InvokeWrapper wrapper = {receiver, memberFun}; return wrapper; } using namespace TemplateParser; -TemplateExtractHtmlElementWebEngineView::TemplateExtractHtmlElementWebEngineView(QObject *parent) +TemplateExtractHtmlElementFromMail::TemplateExtractHtmlElementFromMail(QObject *parent) : QObject(parent) { mPage = new TemplateWebEnginePage(this); - connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateExtractHtmlElementWebEngineView::slotLoadFinished); + connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateExtractHtmlElementFromMail::slotLoadFinished); } -TemplateExtractHtmlElementWebEngineView::~TemplateExtractHtmlElementWebEngineView() +TemplateExtractHtmlElementFromMail::~TemplateExtractHtmlElementFromMail() { } -void TemplateExtractHtmlElementWebEngineView::clear() +void TemplateExtractHtmlElementFromMail::clear() { mBodyElement.clear(); mHeaderElement.clear(); mHtmlElement.clear(); } -void TemplateExtractHtmlElementWebEngineView::setHtmlContent(const QString &html) +void TemplateExtractHtmlElementFromMail::setHtmlContent(const QString &html) { clear(); mHtmlElement = html; mPage->setHtml(html); } QString extractHeaderBodyScript() { const QString source = QStringLiteral("(function() {" "var res = {" " body: document.getElementsByTagName('body')[0].innerHTML," " header: document.getElementsByTagName('head')[0].innerHTML" "};" "return res;" "})()"); return source; } -void TemplateExtractHtmlElementWebEngineView::slotLoadFinished(bool success) +void TemplateExtractHtmlElementFromMail::slotLoadFinished(bool success) { if (success) { mPage->runJavaScript(extractHeaderBodyScript(), (QWebEngineScript::UserWorld + 2), - invoke(this, &TemplateExtractHtmlElementWebEngineView::handleHtmlInfo)); + invoke(this, &TemplateExtractHtmlElementFromMail::handleHtmlInfo)); } else { Q_EMIT loadContentDone(false); } } -void TemplateExtractHtmlElementWebEngineView::handleHtmlInfo(const QVariant &result) +void TemplateExtractHtmlElementFromMail::handleHtmlInfo(const QVariant &result) { if (result.isValid()) { const QVariantMap map = result.toMap(); mBodyElement = map.value(QStringLiteral("body")).toString(); mHeaderElement = map.value(QStringLiteral("header")).toString(); Q_EMIT loadContentDone(true); } else { qCWarning(TEMPLATEPARSER_LOG) << "Impossible to get value"; Q_EMIT loadContentDone(false); } } -QString TemplateExtractHtmlElementWebEngineView::htmlElement() const +QString TemplateExtractHtmlElementFromMail::htmlElement() const { return mHtmlElement; } -QString TemplateExtractHtmlElementWebEngineView::headerElement() const +QString TemplateExtractHtmlElementFromMail::headerElement() const { return mHeaderElement; } -QString TemplateExtractHtmlElementWebEngineView::bodyElement() const +QString TemplateExtractHtmlElementFromMail::bodyElement() const { return mBodyElement; } diff --git a/templateparser/src/templateextracthtmlelementwebengineview.h b/templateparser/src/templateextracthtmlelementfrommail.h similarity index 88% rename from templateparser/src/templateextracthtmlelementwebengineview.h rename to templateparser/src/templateextracthtmlelementfrommail.h index 83116fb5..9de9f43e 100644 --- a/templateparser/src/templateextracthtmlelementwebengineview.h +++ b/templateparser/src/templateextracthtmlelementfrommail.h @@ -1,57 +1,57 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TEMPLATEEXTRACTHTMLELEMENTWEBENGINEVIEW_H #define TEMPLATEEXTRACTHTMLELEMENTWEBENGINEVIEW_H #include #include "templateparser_private_export.h" namespace TemplateParser { class TemplateWebEnginePage; -class TEMPLATEPARSER_TESTS_EXPORT TemplateExtractHtmlElementWebEngineView : public QObject +class TEMPLATEPARSER_TESTS_EXPORT TemplateExtractHtmlElementFromMail : public QObject { Q_OBJECT public: - explicit TemplateExtractHtmlElementWebEngineView(QObject *parent = nullptr); - ~TemplateExtractHtmlElementWebEngineView(); + explicit TemplateExtractHtmlElementFromMail(QObject *parent = nullptr); + ~TemplateExtractHtmlElementFromMail(); Q_REQUIRED_RESULT QString bodyElement() const; Q_REQUIRED_RESULT QString headerElement() const; Q_REQUIRED_RESULT QString htmlElement() const; void setHtmlContent(const QString &html); Q_SIGNALS: void loadContentDone(bool success); private: void clear(); void slotLoadFinished(bool success); void handleHtmlInfo(const QVariant &result); QString mBodyElement; QString mHeaderElement; QString mHtmlElement; TemplateWebEnginePage *mPage = nullptr; }; } #endif // TEMPLATEEXTRACTHTMLELEMENTWEBENGINEVIEW_H diff --git a/templateparser/src/templatewebengineview.cpp b/templateparser/src/templateextracttextfrommail.cpp similarity index 76% rename from templateparser/src/templatewebengineview.cpp rename to templateparser/src/templateextracttextfrommail.cpp index c1160e35..9f8ea645 100644 --- a/templateparser/src/templatewebengineview.cpp +++ b/templateparser/src/templateextracttextfrommail.cpp @@ -1,79 +1,79 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "templatewebengineview.h" +#include "templateextracttextfrommail.h" #include "templatewebenginepage.h" #include "templateparser_debug.h" using namespace TemplateParser; template struct InvokeWrapper { R *receiver; void (C::*memberFun)(Arg); void operator()(Arg result) { (receiver->*memberFun)(result); } }; template InvokeWrapper invoke(R *receiver, void (C::*memberFun)(Arg)) { InvokeWrapper wrapper = {receiver, memberFun}; return wrapper; } -TemplateWebEngineView::TemplateWebEngineView(QObject *parent) +TemplateExtractTextFromMail::TemplateExtractTextFromMail(QObject *parent) : QObject(parent) { mPage = new TemplateWebEnginePage(this); - connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateWebEngineView::slotLoadFinished); + connect(mPage, &TemplateWebEnginePage::loadFinished, this, &TemplateExtractTextFromMail::slotLoadFinished); } -TemplateWebEngineView::~TemplateWebEngineView() +TemplateExtractTextFromMail::~TemplateExtractTextFromMail() { } -void TemplateWebEngineView::setHtmlContent(const QString &html) +void TemplateExtractTextFromMail::setHtmlContent(const QString &html) { mExtractedPlainText.clear(); mPage->setHtml(html); } -void TemplateWebEngineView::slotLoadFinished(bool ok) +void TemplateExtractTextFromMail::slotLoadFinished(bool ok) { if (ok) { - mPage->toPlainText(invoke(this, &TemplateWebEngineView::setPlainText)); + mPage->toPlainText(invoke(this, &TemplateExtractTextFromMail::setPlainText)); } else { qCWarning(TEMPLATEPARSER_LOG) << "Loading page failed"; Q_EMIT loadContentDone(false); } } -void TemplateWebEngineView::setPlainText(const QString &plainText) +void TemplateExtractTextFromMail::setPlainText(const QString &plainText) { mExtractedPlainText = plainText; Q_EMIT loadContentDone(true); } -QString TemplateWebEngineView::plainText() const +QString TemplateExtractTextFromMail::plainText() const { return mExtractedPlainText; } diff --git a/templateparser/src/templatewebengineview.h b/templateparser/src/templateextracttextfrommail.h similarity index 88% rename from templateparser/src/templatewebengineview.h rename to templateparser/src/templateextracttextfrommail.h index c72b3818..578627b7 100644 --- a/templateparser/src/templatewebengineview.h +++ b/templateparser/src/templateextracttextfrommail.h @@ -1,50 +1,50 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TEMPLATEWEBENGINEVIEW_H #define TEMPLATEWEBENGINEVIEW_H #include #include "templateparser_export.h" namespace TemplateParser { class TemplateWebEnginePage; -class TEMPLATEPARSER_EXPORT TemplateWebEngineView : public QObject +class TEMPLATEPARSER_EXPORT TemplateExtractTextFromMail : public QObject { Q_OBJECT public: - explicit TemplateWebEngineView(QObject *parent = nullptr); - ~TemplateWebEngineView(); + explicit TemplateExtractTextFromMail(QObject *parent = nullptr); + ~TemplateExtractTextFromMail(); void setHtmlContent(const QString &html); Q_REQUIRED_RESULT QString plainText() const; Q_SIGNALS: void loadContentDone(bool success); private: void slotLoadFinished(bool ok); void setPlainText(const QString &plainText); QString mExtractedPlainText; TemplateWebEnginePage *mPage = nullptr; }; } #endif // TEMPLATEWEBENGINEVIEW_H diff --git a/templateparser/src/templateparserextracthtmlinfo.cpp b/templateparser/src/templateparserextracthtmlinfo.cpp index f7478f38..cda56c8d 100644 --- a/templateparser/src/templateparserextracthtmlinfo.cpp +++ b/templateparser/src/templateparserextracthtmlinfo.cpp @@ -1,99 +1,99 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "templateparserextracthtmlinfo.h" -#include "templateextracthtmlelementwebengineview.h" -#include "templatewebengineview.h" +#include "templateextracthtmlelementfrommail.h" +#include "templateextracttextfrommail.h" #include "templateparser_debug.h" using namespace TemplateParser; TemplateParserExtractHtmlInfo::TemplateParserExtractHtmlInfo(QObject *parent) : QObject(parent) { } TemplateParserExtractHtmlInfo::~TemplateParserExtractHtmlInfo() { if (mTemplateWebEngineView) { mTemplateWebEngineView->deleteLater(); } if (mExtractHtmlElementWebEngineView) { mExtractHtmlElementWebEngineView->deleteLater(); } } void TemplateParserExtractHtmlInfo::setHtmlForExtractingTextPlain(const QString &html) { mHtmlForExtractingTextPlain = html; } void TemplateParserExtractHtmlInfo::setHtmlForExtractionHeaderAndBody(const QString &html) { mHtmlForExtractionHeaderAndBody = html; } void TemplateParserExtractHtmlInfo::setTemplate(const QString &str) { mTemplateStr = str; } void TemplateParserExtractHtmlInfo::start() { mResult.clear(); mResult.mTemplate = mTemplateStr; if (!mHtmlForExtractingTextPlain.isEmpty()) { - mTemplateWebEngineView = new TemplateWebEngineView; - connect(mTemplateWebEngineView, &TemplateWebEngineView::loadContentDone, this, &TemplateParserExtractHtmlInfo::slotExtractToPlainTextFinished); + mTemplateWebEngineView = new TemplateExtractTextFromMail; + connect(mTemplateWebEngineView, &TemplateExtractTextFromMail::loadContentDone, this, &TemplateParserExtractHtmlInfo::slotExtractToPlainTextFinished); mTemplateWebEngineView->setHtmlContent(mHtmlForExtractingTextPlain); } else { qCDebug(TEMPLATEPARSER_LOG) << "html string is empty for extracting to plainText"; slotExtractToPlainTextFinished(false); } } void TemplateParserExtractHtmlInfo::slotExtractToPlainTextFinished(bool success) { if (success) { mResult.mPlainText = mTemplateWebEngineView->plainText(); } else { qCDebug(TEMPLATEPARSER_LOG) << "Impossible to extract plaintext"; } if (!mHtmlForExtractionHeaderAndBody.isEmpty()) { - mExtractHtmlElementWebEngineView = new TemplateExtractHtmlElementWebEngineView; - connect(mExtractHtmlElementWebEngineView, &TemplateExtractHtmlElementWebEngineView::loadContentDone, this, &TemplateParserExtractHtmlInfo::slotExtractHtmlElementFinished); + mExtractHtmlElementWebEngineView = new TemplateExtractHtmlElementFromMail; + connect(mExtractHtmlElementWebEngineView, &TemplateExtractHtmlElementFromMail::loadContentDone, this, &TemplateParserExtractHtmlInfo::slotExtractHtmlElementFinished); mExtractHtmlElementWebEngineView->setHtmlContent(mHtmlForExtractionHeaderAndBody); } else { qCDebug(TEMPLATEPARSER_LOG) << "html string is empty for extracting to header and body"; slotExtractHtmlElementFinished(false); } } void TemplateParserExtractHtmlInfo::slotExtractHtmlElementFinished(bool success) { if (success) { mResult.mBodyElement = mExtractHtmlElementWebEngineView->bodyElement(); mResult.mHeaderElement = mExtractHtmlElementWebEngineView->headerElement(); mResult.mHtmlElement = mExtractHtmlElementWebEngineView->htmlElement(); } else { qCDebug(TEMPLATEPARSER_LOG) << "Impossible to extract html element"; } Q_EMIT finished(mResult); deleteLater(); } diff --git a/templateparser/src/templateparserextracthtmlinfo.h b/templateparser/src/templateparserextracthtmlinfo.h index faeb2259..ee541869 100644 --- a/templateparser/src/templateparserextracthtmlinfo.h +++ b/templateparser/src/templateparserextracthtmlinfo.h @@ -1,61 +1,61 @@ /* Copyright (C) 2017-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TEMPLATEPARSEREXTRACTHTMLINFO_H #define TEMPLATEPARSEREXTRACTHTMLINFO_H #include #include "templateparser_private_export.h" #include "templateparserextracthtmlinforesult.h" namespace TemplateParser { -class TemplateWebEngineView; -class TemplateExtractHtmlElementWebEngineView; +class TemplateExtractTextFromMail; +class TemplateExtractHtmlElementFromMail; class TEMPLATEPARSER_TESTS_EXPORT TemplateParserExtractHtmlInfo : public QObject { Q_OBJECT public: explicit TemplateParserExtractHtmlInfo(QObject *parent = nullptr); ~TemplateParserExtractHtmlInfo(); void setHtmlForExtractingTextPlain(const QString &html); void setHtmlForExtractionHeaderAndBody(const QString &html); void setTemplate(const QString &str); void start(); Q_SIGNALS: void finished(const TemplateParserExtractHtmlInfoResult &result); private: void slotExtractHtmlElementFinished(bool success); void slotExtractToPlainTextFinished(bool success); TemplateParserExtractHtmlInfoResult mResult; QString mHtmlForExtractingTextPlain; QString mHtmlForExtractionHeaderAndBody; QString mTemplateStr; - TemplateWebEngineView *mTemplateWebEngineView = nullptr; - TemplateExtractHtmlElementWebEngineView *mExtractHtmlElementWebEngineView = nullptr; + TemplateExtractTextFromMail *mTemplateWebEngineView = nullptr; + TemplateExtractHtmlElementFromMail *mExtractHtmlElementWebEngineView = nullptr; }; } #endif // TEMPLATEPARSEREXTRACTHTMLINFO_H