File indexing completed on 2024-05-12 05:11:15
0001 // SPDX-FileCopyrightText: 2023 g10 code GmbH 0002 // SPDX-Contributor: Carl Schwan <carl.schwan@gnupg.com> 0003 // SPDX-License-Identifier: LGPL-2.0-or-later 0004 0005 #include <QGuiApplication> 0006 0007 #include <KAboutData> 0008 #include <KLocalizedString> 0009 #include <QCommandLineParser> 0010 #include <iostream> 0011 0012 #ifdef Q_OS_WIN32 0013 #include <fcntl.h> 0014 #include <io.h> 0015 #endif 0016 0017 #ifdef HAS_HTMLPARSER 0018 #include <lib.rs.h> 0019 #else 0020 #include <QTextDocument> 0021 #endif 0022 0023 int main(int argc, char *argv[]) 0024 { 0025 QGuiApplication app(argc, argv); 0026 0027 KLocalizedString::setApplicationDomain(QByteArrayLiteral("akonadi_search")); 0028 0029 KAboutData about(QStringLiteral("akonadi_html_to_text"), 0030 i18n("Akonadi HTML To Text"), 0031 QStringLiteral("1.0"), 0032 i18n("Akonadi HTML To Text Converter"), 0033 KAboutLicense::LGPL_V2, 0034 i18n("© 2023 KDE Community")); 0035 0036 about.addAuthor(i18n("Carl Schwan"), i18n("Maintainer"), QStringLiteral("carl@carlschwan.eu"), QStringLiteral("https://carlschwan.eu")); 0037 0038 KAboutData::setApplicationData(about); 0039 0040 QCommandLineParser parser; 0041 parser.setApplicationDescription(i18n("Akonadi HTML To Text Converter")); 0042 0043 about.setupCommandLine(&parser); 0044 parser.process(app); 0045 about.processCommandLine(&parser); 0046 0047 QByteArray content; 0048 0049 #ifdef Q_OS_WIN32 0050 _setmode(_fileno(stdin), _O_BINARY); 0051 #endif 0052 0053 while (!std::cin.eof()) { 0054 char arr[1024]; 0055 std::cin.read(arr, sizeof(arr)); 0056 int s = std::cin.gcount(); 0057 content.append(arr, s); 0058 } 0059 0060 #ifdef HAS_HTMLPARSER 0061 const auto html = content.toStdString(); 0062 const auto text = std::string(convert_to_text(rust::String(html))); 0063 #else 0064 QTextDocument doc; 0065 doc.setHtml(QString::fromUtf8(content)); 0066 const std::string text(doc.toPlainText().toStdString()); 0067 #endif 0068 0069 std::cout << text; 0070 0071 return 0; 0072 }