diff --git a/CMakeLists.txt b/CMakeLists.txt index 68350786..0eeab704 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,188 +1,188 @@ cmake_minimum_required(VERSION 3.5) set(PIM_VERSION "5.14.40") project(kdepim-addons VERSION ${PIM_VERSION}) if(POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif() set(KF5_MIN_VERSION "5.70.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ ${ECM_MODULE_PATH}) # Do NOT add quote set(KDEPIM_DEV_VERSION alpha) # add an extra space if(DEFINED KDEPIM_DEV_VERSION) set(KDEPIM_DEV_VERSION " ${KDEPIM_DEV_VERSION}") endif() set(KDEPIMADDONS_VERSION_NUMBER ${PIM_VERSION}) set(KDEPIMADDONS_VERSION "${KDEPIMADDONS_VERSION_NUMBER}${KDEPIM_DEV_VERSION}") set(KDEPIMADDONS_LIB_VERSION "${KDEPIMADDONS_VERSION_NUMBER}") set(KDEPIMADDONS_LIB_SOVERSION "5") set(AKONADINOTES_LIB_VERSION "5.14.40") set(QT_REQUIRED_VERSION "5.13.0") include(ECMInstallIcons) include(ECMSetupVersion) include(ECMAddTests) include(GenerateExportHeader) include(ECMGenerateHeaders) include(FeatureSummary) include(CheckFunctionExists) include(ECMGeneratePriFile) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) option(KDEPIM_ENTERPRISE_BUILD "Enable features specific to the enterprise branch, which are normally disabled. Also, it disables many components not needed for Kontact such as the Kolab client." FALSE) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets Widgets Test) find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Config ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiNotes ${AKONADINOTES_LIB_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Declarative ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5SyntaxHighlighting ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Parts ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Prison ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Holidays ${KF5_MIN_VERSION} CONFIG REQUIRED) set(MAILCOMMON_LIB_VERSION "5.14.40") set(GRAVATAR_LIB_VERSION "5.14.41") set(PIMCOMMON_LIB_VERSION "5.14.40") set(GRANTLEETHEME_LIB_VERSION "5.14.40") set(CALENDARSUPPORT_LIB_VERSION "5.14.40") set(EVENTVIEW_LIB_VERSION "5.14.40") set(LIBKDEPIM_LIB_VERSION "5.14.40") set(KDEPIM_APPS_LIB_VERSION "5.14.40") set(LIBKLEO_LIB_VERSION "5.14.40") set(AKONADI_LIB_VERSION "5.14.40") set(INCIDENCEEDITOR_LIB_VERSION "5.14.40") set(KTNEF_LIB_VERSION "5.14.40") set(MESSAGELIB_LIB_VERSION "5.14.40") set(AKONADICALENDAR_LIB_VERSION "5.14.40") set(CALENDAR_UTILS_VERSION "5.14.40") set(KPIMTEXTEDIT_LIB_VERSION "5.14.40") set(KIMAP_LIB_VERSION "5.14.40") set(LIBKSIEVE_LIB_VERSION "5.14.40") set(KMAILTRANSPORT_LIB_VERSION "5.14.40") set(AKONADICONTACT_LIB_VERSION "5.14.40") set(IMPORTWIZARD_LIB_VERSION "5.14.40") set(MAILIMPORTER_LIB_VERSION "5.14.40") -set(KPIMPKPASS_LIB_VERSION "5.14.40") +set(KPIMPKPASS_LIB_VERSION "5.14.41") set(KPIMITINERARY_LIB_VERSION "5.14.41") set(KONTACTINTERFACE_LIB_VERSION "5.14.40") set(CALENDARSUPPORT_LIB_VERSION_LIB "5.14.40") find_package(KF5CalendarCore ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5CalendarUtils ${CALENDAR_UTILS_VERSION} CONFIG REQUIRED) find_package(KF5WebEngineViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5TemplateParser ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailCommon ${MAILCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KaddressbookGrantlee ${KDEPIM_APPS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KaddressbookImportExport ${KDEPIM_APPS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Libkleo ${LIBKLEO_LIB_VERSION} CONFIG REQUIRED) find_package(KF5GrantleeTheme ${GRANTLEETHEME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimCommonAkonadi ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibkdepimAkonadi ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5IncidenceEditor ${INCIDENCEEDITOR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageCore ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageComposer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageList ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarSupport ${CALENDARSUPPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5EventViews ${EVENTVIEW_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Akonadi ${AKONADI_LIB_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiCalendar ${AKONADICALENDAR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Gravatar ${GRAVATAR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5IdentityManagement ${KIDENTITYMANAGEMENT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5IMAP ${KIMAP_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibKSieve ${LIBKSIEVE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Tnef ${KTNEF_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailTransportAkonadi ${KMAILTRANSPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Contacts ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiContact ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5ContactEditor ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED) find_package(KPimImportWizard ${IMPORTWIZARD_LIB_VERSION} CONFIG) find_package(KF5MailImporterAkonadi ${MAILIMPORTER_LIB_VERSION} CONFIG REQUIRED) find_package(KPimPkPass ${KPIMPKPASS_LIB_VERSION} CONFIG REQUIRED) find_package(KPimItinerary ${KPIMITINERARY_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KontactInterface ${KONTACTINTERFACE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarSupport ${CALENDARSUPPORT_LIB_VERSION_LIB} CONFIG REQUIRED) set(CMAKE_CXX_STANDARD 14) if(BUILD_TESTING) add_definitions(-DBUILD_TESTING) endif(BUILD_TESTING) if(KDEPIM_ENTERPRISE_BUILD) set(KDEPIM_ENTERPRISE_BUILD true) else() set(KDEPIM_ENTERPRISE_BUILD false) endif() # Extra package find_package(Gpgmepp 1.11.1 CONFIG) set_package_properties(Gpgmepp PROPERTIES DESCRIPTION "GpgME library" URL "https://www.gnupg.org" TYPE REQUIRED) if (EXISTS "${CMAKE_SOURCE_DIR}/.git") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050e00) add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x054700) endif() add_definitions(-DQT_NO_FOREACH) add_definitions(-DQT_NO_KEYWORDS) option(KDEPIM_RUN_AKONADI_TEST "Enable autotest based on Akonadi." TRUE) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(QTCREATOR_TEMPLATE_INSTALL_DIR ${KDE_INSTALL_DATADIR}/qtcreator/templates CACHE PATH "Define qtcreator template install path (default is /usr/share/qtcreator/templates)") find_package(Discount "2") set_package_properties("discount" PROPERTIES DESCRIPTION "A library that gives you formatting functions suitable for marking down entire documents or lines of text" URL "https://www.pell.portland.or.us/~orc/Code/discount/" TYPE RECOMMENDED PURPOSE "Generate Markdown file.") if(discount_FOUND) if (${PC_LIBMARKDOWN_VERSION_STRING}) if (${PC_LIBMARKDOWN_VERSION_STRING} VERSION_GREATER "2.2.5") set(DISCOUNT_HAS_HIGHLIGHTING_SUPPORT TRUE) MESSAGE(STATUS "Discount ${PC_LIBMARKDOWN_VERSION_STRING}: has hightlighting support") endif() endif() endif() add_subdirectory(plugins) add_subdirectory(korganizer) add_subdirectory(kmail) add_subdirectory(kaddressbook) add_subdirectory(sieveeditor) add_subdirectory(kmailtransport) if(KPimImportWizard_FOUND) add_subdirectory(akonadi-import-wizard) endif() ecm_qt_install_logging_categories( EXPORT KDEPIMADDONS FILE kdepim-addons.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp b/plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp index 34a7e6f2..da21e57b 100644 --- a/plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp +++ b/plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp @@ -1,184 +1,193 @@ /* Copyright (c) 2017 Volker Krause 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 #include #include #include #include #include #include #include #include #include #include #include #include #include static bool isPkPassContent(KMime::Content *content) { const auto ct = content->contentType(false); if (ct && ct->mimeType() == "application/vnd.apple.pkpass") { return true; } if (ct && ct->mimeType() != "application/octet-stream" && ct->mimeType() != "application/zip") { return false; } if (ct && ct->name().endsWith(QLatin1String("pkpass"))) { return true; } const auto cd = content->contentDisposition(false); return cd && cd->filename().endsWith(QLatin1String("pkpass")); } // Grantlee has no Q_GADGET support yet #define GRANTLEE_MAKE_GADGET(Class) \ GRANTLEE_BEGIN_LOOKUP(Class) \ const auto idx = Class::staticMetaObject.indexOfProperty(property.toUtf8().constData()); \ if (idx < 0) { \ return {}; \ } \ const auto mp = Class::staticMetaObject.property(idx); \ return mp.readOnGadget(&object); \ GRANTLEE_END_LOOKUP GRANTLEE_MAKE_GADGET(KPkPass::Barcode) GRANTLEE_MAKE_GADGET(KPkPass::Field) namespace { class Formatter : public MessageViewer::MessagePartRendererBase { public: bool render(const MimeTreeParser::MessagePartPtr &msgPart, MessageViewer::HtmlWriter *htmlWriter, MessageViewer::RenderContext *context) const override { Q_UNUSED(context); auto mp = msgPart.dynamicCast(); if (!mp || context->isHiddenHint(msgPart) || !msgPart->content() || !isPkPassContent(msgPart->content())) { return false; } std::unique_ptr pass(KPkPass::Pass::fromData(msgPart->content()->decodedContent())); const auto dir = mp->nodeHelper()->createTempDir(QStringLiteral("pkpass")); const auto logo = pass->logo(); if (!logo.isNull()) { const QString fileName = dir + QStringLiteral("/logo.png"); logo.save(fileName); pass->setProperty("logoUrl", QUrl::fromLocalFile(fileName)); mp->nodeHelper()->addTempFile(fileName); } const auto strip = pass->strip(); if (!strip.isNull()) { const QString fileName = dir + QStringLiteral("/strip.png"); strip.save(fileName); pass->setProperty("stripUrl", QUrl::fromLocalFile(fileName)); mp->nodeHelper()->addTempFile(fileName); } const auto background = pass->background(); if (!background.isNull()) { const QString fileName = dir + QStringLiteral("/background.png"); background.save(fileName); pass->setProperty("backgroundUrl", QUrl::fromLocalFile(fileName)); mp->nodeHelper()->addTempFile(fileName); } const auto footer = pass->footer(); if (!footer.isNull()) { const QString fileName = dir + QStringLiteral("/footer.png"); footer.save(fileName); pass->setProperty("footerUrl", QUrl::fromLocalFile(fileName)); mp->nodeHelper()->addTempFile(fileName); } + const auto thumbnail = pass->thumbnail(); + if (!thumbnail.isNull()) { + const QString fileName = dir + QStringLiteral("/thumbnail.png"); + thumbnail.save(fileName); + pass->setProperty("thumbnailUrl", QUrl::fromLocalFile(fileName)); + mp->nodeHelper()->addTempFile(fileName); + } const auto barcodes = pass->barcodes(); if (!barcodes.isEmpty()) { const auto barcode = barcodes.at(0); std::unique_ptr code; switch (barcode.format()) { case KPkPass::Barcode::QR: code.reset(Prison::createBarcode(Prison::QRCode)); break; case KPkPass::Barcode::Aztec: code.reset(Prison::createBarcode(Prison::Aztec)); break; default: break; } if (code) { code->setData(barcode.message()); const QString fileName = dir + QStringLiteral("/barcode.png"); code->toImage(code->preferredSize(qGuiApp->devicePixelRatio())).save(fileName); pass->setProperty("barcodeUrl", QUrl::fromLocalFile(fileName)); mp->nodeHelper()->addTempFile(fileName); } } // Grantlee can't handle QColor... pass->setProperty("foregroundColorName", pass->foregroundColor().name()); pass->setProperty("backgroundColorName", pass->backgroundColor().name()); pass->setProperty("labelColorName", pass->labelColor().name()); auto c = MessageViewer::MessagePartRendererManager::self()->createContext(); c.insert(QStringLiteral("block"), mp.data()); c.insert(QStringLiteral("pass"), pass.get()); Grantlee::Template t; if (qobject_cast(pass.get())) { t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral("org.kde.messageviewer/pkpass/boardingpass.html")); } else if (pass->type() == KPkPass::Pass::EventTicket) { t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral("org.kde.messageviewer/pkpass/eventticket.html")); + } else if (pass->type() == KPkPass::Pass::Generic) { + t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral("org.kde.messageviewer/pkpass/generic.html")); } else { // unknown pass type we have no template for return false; } Grantlee::OutputStream s(htmlWriter->stream()); t->render(&s, &c); return true; } }; class Plugin : public QObject, public MessageViewer::MessagePartRenderPlugin { Q_OBJECT Q_INTERFACES(MessageViewer::MessagePartRenderPlugin) Q_PLUGIN_METADATA(IID "com.kde.messageviewer.bodypartformatter" FILE "pkpass_plugin.json") public: explicit Plugin(QObject *parent = nullptr) : QObject(parent) { Grantlee::registerMetaType(); Grantlee::registerMetaType(); } MessageViewer::MessagePartRendererBase *renderer(int index) override { return index == 0 ? new Formatter() : nullptr; } }; } #include "pkpass_plugin.moc" diff --git a/plugins/messageviewer/bodypartformatter/pkpass/templates.qrc b/plugins/messageviewer/bodypartformatter/pkpass/templates.qrc index 91bc32a6..6cf834df 100644 --- a/plugins/messageviewer/bodypartformatter/pkpass/templates.qrc +++ b/plugins/messageviewer/bodypartformatter/pkpass/templates.qrc @@ -1,7 +1,8 @@ templates/barcode.html templates/boardingpass.html templates/eventticket.html + templates/generic.html diff --git a/plugins/messageviewer/bodypartformatter/pkpass/templates/generic.html b/plugins/messageviewer/bodypartformatter/pkpass/templates/generic.html new file mode 100644 index 00000000..b6f5a9b2 --- /dev/null +++ b/plugins/messageviewer/bodypartformatter/pkpass/templates/generic.html @@ -0,0 +1,96 @@ + +
+ +
+ +
+ + + + + {% for field in pass.headerFields %} + + {% endfor %} + + {% for field in pass.headerFields %} + + {% endfor %} + +
+ {% if pass.logoUrl %} + + {% endif %} + {{ pass.logoText }}{{ field.label }}
{{ field.value }}
+
+
+
+ + + {% for field in pass.primaryFields%} + + {% endfor %} + {% if pass.thumbnailUrl %} + + {% endif %} + + {% for field in pass.primaryFields %} + + {% endfor %} + +
{{ field.label }}
{{ field.value }}
+
+ +
+ + + {% for field in pass.secondaryFields %} + + {% endfor %} + + {% for field in pass.secondaryFields %} + + {% endfor %} + +
{{ field.label }}
{{ field.value }}
+
+ +
+ + + {% for field in pass.auxiliaryFields %} + + {% endfor %} + + {% for field in pass.auxiliaryFields %} + + {% endfor %} + +
{{ field.label }}
{{ field.value }}
+
+ +{% include "org.kde.messageviewer/pkpass/barcode.html" %} + +{% if pass.footerUrl %} +
+
+
+{% endif %} + +
+{% for field in pass.backFields %} +
{{ field.label }}
+
{{ field.value|safe|linebreaksbr }}
+{% endfor %} +
+ +