File indexing completed on 2025-03-09 04:54:39

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "testmailwebengineselection.h"
0007 
0008 #include <KActionCollection>
0009 #include <QApplication>
0010 #include <QMessageBox>
0011 #include <QPushButton>
0012 #include <QVBoxLayout>
0013 #include <QWebEngineSettings>
0014 
0015 #include <MessageViewer/MailWebEngineView>
0016 
0017 TestMailWebEngineSelection::TestMailWebEngineSelection(QWidget *parent)
0018     : QWidget(parent)
0019     , mNumber(0)
0020 {
0021     auto vbox = new QVBoxLayout(this);
0022     mTestWebEngine = new MessageViewer::MailWebEngineView(new KActionCollection(this), this);
0023     connect(mTestWebEngine, &MessageViewer::MailWebEngineView::openUrl, this, &TestMailWebEngineSelection::slotOpenUrl);
0024     QString str = QStringLiteral(
0025         "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
0026         "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n  <style type=\"text/css\">\n  "
0027         "/*<![CDATA[*/\n    @import \"main.css\";\n  /*]]>*/\n\n.links {\n    margin: auto;\n}\n\n.links td {\n    padding-top: 5px;\n    padding-bottom: "
0028         "5px;\n}\n\n  </style>\n\n  <title>Akregator</title>\n</head>\n\n<body>\n  <div id=\"header\"><img "
0029         "src=\"file:///opt/kde5/share/icons/maia/apps/scalable/akregator.svg\" align=\"top\" height=\"128\" width=\"128\" alt=\"akregator\" title=\"\" />\n    "
0030         "<div id=\"title\">\n        <h1>Akregator</h1>Akregator est un agrégateur de flux pour KDE.\n    </div>\n  </div>\n\n  <div id=\"box\">\n    <div "
0031         "id=\"boxInner\">\n\n<div class=\"center\">\n    <p>Feed readers provide a convenient way to browse different kinds of content, including news, blogs, "
0032         "and other content from online sites. Instead of checking all your favorite web sites manually for updates, Akregator collects the content for "
0033         "you.</p>\n    <p> For more information about using Akregator, check the <a href='http://akregator.kde.org/'>Akregator website</a>. If you do not want "
0034         "to see this page anymore, <a href='config:/disable_introduction'>click here</a>.</p>\n    <p>We hope that you will enjoy Akregator.</p>\n    <p>Thank "
0035         "you, The Akregator Team </p>\n</div>\n\n    </div>\n  </div>\n</body>\n</html>\n\n<!-- vim:set sw=2 et nocindent smartindent: -->\n");
0036     mTestWebEngine->setHtml(str, QUrl(QStringLiteral("file:///")));
0037     mTestWebEngine->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
0038     vbox->addWidget(mTestWebEngine);
0039     auto hButtonBox = new QHBoxLayout;
0040     vbox->addLayout(hButtonBox);
0041 
0042     auto changeHtml = new QPushButton(QStringLiteral("switch html"), this);
0043     connect(changeHtml, &QPushButton::clicked, this, &TestMailWebEngineSelection::slotSwitchHtml);
0044     hButtonBox->addWidget(changeHtml);
0045 
0046     auto showSelection = new QPushButton(QStringLiteral("Show Selection"), this);
0047     connect(showSelection, &QPushButton::clicked, this, &TestMailWebEngineSelection::slotShowSelection);
0048     hButtonBox->addWidget(showSelection);
0049 }
0050 
0051 TestMailWebEngineSelection::~TestMailWebEngineSelection() = default;
0052 
0053 void TestMailWebEngineSelection::slotSwitchHtml()
0054 {
0055     QString str = QStringLiteral(
0056                       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
0057                       "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n  <style "
0058                       "type=\"text/css\">\n  /*<![CDATA[*/\n    @import \"main.css\";\n  /*]]>*/\n\n.links {\n    margin: auto;\n}\n\n.links td {\n    "
0059                       "padding-top: 5px;\n    padding-bottom: 5px;\n}\n\n  </style>\n\n  <title>Akregator</title>\n</head>\n\n<body>\n  <div "
0060                       "id=\"header\"><img src=\"file:///opt/kde5/share/icons/maia/apps/scalable/akregator.svg\" align=\"top\" height=\"128\" width=\"128\" "
0061                       "alt=\"akregator\" title=\"\" />\n    <div id=\"title\">\n        <h1>Akregator</h1>Akregator est un agrégateur de flux pour KDE.\n    "
0062                       "</div>\n  </div>\n\n  <div id=\"box\">\n    <div id=\"boxInner\">\n\n<div class=\"center\">\n    <p>Feed readers provide a convenient "
0063                       "way to browse different kinds of content, including news, blogs, and other content from online sites. Instead of checking all your "
0064                       "favorite web sites manually for updates, Akregator collects the content for you.</p>\n    <p> For more information about using "
0065                       "Akregator, check the <a href='http://akregator.kde.org/'>Akregator website</a>. If you do not want to see this page anymore, <a "
0066                       "href='config:/disable_introduction'>click here</a>.</p>\n    <p>We hope that you will enjoy Akregator.</p>\n    <p>Thank you, number %1 "
0067                       "</p>\n</div>\n\n    </div>\n  </div>\n</body>\n</html>\n\n<!-- vim:set sw=2 et nocindent smartindent: -->\n")
0068                       .arg(mNumber);
0069     mTestWebEngine->setHtml(str, QUrl(QStringLiteral("file:///")));
0070     mNumber++;
0071 }
0072 
0073 void TestMailWebEngineSelection::slotShowSelection()
0074 {
0075     QMessageBox::information(this, QStringLiteral("selection"), mTestWebEngine->selectedText());
0076 }
0077 
0078 void TestMailWebEngineSelection::slotOpenUrl(const QUrl &url)
0079 {
0080     mTestWebEngine->load(url);
0081 }
0082 
0083 int main(int argc, char *argv[])
0084 {
0085     QApplication app(argc, argv);
0086     auto testWebEngine = new TestMailWebEngineSelection;
0087     testWebEngine->show();
0088     const int ret = app.exec();
0089     return ret;
0090 }
0091 
0092 #include "moc_testmailwebengineselection.cpp"