File indexing completed on 2025-02-02 05:02:43
0001 /* 0002 SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "itinerarycreator.h" 0008 0009 #include <QImage> 0010 #include <QScopedPointer> 0011 0012 #include <KPkPass/Pass> 0013 #include <KPluginFactory> 0014 0015 K_PLUGIN_CLASS_WITH_JSON(ItineraryCreator, "itinerarythumbnail.json") 0016 0017 ItineraryCreator::ItineraryCreator(QObject *parent, const QVariantList &args) 0018 : KIO::ThumbnailCreator(parent, args) 0019 { 0020 } 0021 0022 ItineraryCreator::~ItineraryCreator() = default; 0023 0024 KIO::ThumbnailResult ItineraryCreator::create(const KIO::ThumbnailRequest &request) 0025 { 0026 QScopedPointer<KPkPass::Pass> pass(KPkPass::Pass::fromFile(request.url().toLocalFile(), nullptr)); 0027 if (pass.isNull()) { 0028 return KIO::ThumbnailResult::fail(); 0029 } 0030 0031 // See if it has a dedicated thumbnail 0032 // The thumbnails are typically quite small, so we just pick the largest one 0033 // rather than taking into account UI scaling 0034 for (uint dpr = 3; dpr >= 1; --dpr) { 0035 QImage image = pass->image(QStringLiteral("thumbnail"), dpr); 0036 if (!image.isNull()) { 0037 return KIO::ThumbnailResult::pass(image); 0038 } 0039 } 0040 0041 for (const QString &imageName : {QStringLiteral("icon"), QStringLiteral("logo")}) { 0042 for (uint dpr = 3; dpr >= 1; --dpr) { 0043 QImage image = pass->image(imageName, dpr); 0044 if (!image.isNull()) { 0045 return KIO::ThumbnailResult::pass(image); 0046 } 0047 } 0048 } 0049 0050 return KIO::ThumbnailResult::fail(); 0051 } 0052 0053 #include "itinerarycreator.moc" 0054 0055 #include "moc_itinerarycreator.cpp"