Commit 3d9acb3b authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Add pkpass thumbnailer

It shows the thumbnail (e.g. a movie poster), when available,
alternatively the logo or icon (e.g. airline logo)
parent 79e263d7
......@@ -84,7 +84,7 @@ if (ANDROID)
else()
find_package(Qt5 REQUIRED COMPONENTS Widgets DBus)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS DBusAddons QQC2DesktopStyle)
find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS Solid Crash)
find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS Solid Crash KIO)
endif()
if (TARGET KF5::Crash)
set(HAVE_KCRASH TRUE)
......
......@@ -8,3 +8,7 @@ add_subdirectory(weather)
add_subdirectory(kandroidextras)
add_subdirectory(gpx)
add_subdirectory(app)
if (TARGET KF5::KIOWidgets)
add_subdirectory(thumbnailer)
endif()
# SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
# SPDX-License-Identifier: BSD-3-Clause
set(itinerarythumbnail_SRCS itinerarycreator.cpp)
add_library(itinerarythumbnail MODULE ${itinerarythumbnail_SRCS})
target_link_libraries(itinerarythumbnail
KF5::KIOWidgets
Qt5::Gui
KPim::PkPass
)
install(TARGETS itinerarythumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES itinerarythumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
/*
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "itinerarycreator.h"
#include <QImage>
#include <QScopedPointer>
#include <KPkPass/Pass>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new ItineraryCreator;
}
}
ItineraryCreator::ItineraryCreator() = default;
ItineraryCreator::~ItineraryCreator() = default;
bool ItineraryCreator::create(const QString &path, int width, int height, QImage &image)
{
Q_UNUSED(width);
Q_UNUSED(height);
QScopedPointer<KPkPass::Pass> pass(KPkPass::Pass::fromFile(path, nullptr));
if (pass.isNull()) {
return false;
}
// See if it has a dedicated thumbnail
// The thumbnails are typically quite small, so we just pick the largest one
// rather than taking into account UI scaling
for (uint dpr = 3; dpr >= 1; --dpr) {
image = pass->image(QStringLiteral("thumbnail"), dpr);
if (!image.isNull()) {
return true;
}
}
for (const QString &imageName : {QStringLiteral("icon"), QStringLiteral("logo")}) {
for (uint dpr = 3; dpr >= 1; --dpr) {
image = pass->image(imageName, dpr);
if (!image.isNull()) {
return true;
}
}
}
return false;
}
ThumbCreator::Flags ItineraryCreator::flags() const
{
return None;
}
/*
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef ITINERARYCREATOR_H
#define ITINERARYCREATOR_H
#include <kio/thumbcreator.h>
class ItineraryCreator : public ThumbCreator
{
public:
ItineraryCreator();
~ItineraryCreator() override;
bool create(const QString &path, int width, int height, QImage &image) override;
Flags flags() const override;
};
#endif // ITINERARYCREATOR_H
[Desktop Entry]
Type=Service
Name=Tickets and boarding passes
X-KDE-ServiceTypes=ThumbCreator
MimeType=application/vnd.apple.pkpass;
X-KDE-Library=itinerarythumbnail
CacheThumbnail=false # FIXME
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: none
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment