Search for usage in LXR

ThumbCreator Class Referenceabstract

#include <KIO/ThumbCreator>

Inheritance diagram for ThumbCreator:

Public Types

enum  Flags { None = 0, DrawFrame, BlendIcon = 2 }

Public Member Functions

virtual ~ThumbCreator ()
virtual bool create (const QString &path, int width, int height, QImage &img)=0
virtual QWidgetcreateConfigurationWidget ()
virtual Flags flags () const
virtual void writeConfiguration (const QWidget *configurationWidget)

Detailed Description

Base class for thumbnail generator plugins.

KIO::PreviewJob, via the "thumbnail" kioslave, uses instances of this class to generate the thumbnail previews.

To add support for a new document type, subclass ThumbCreator and implement create() to generate a thumbnail for a given path. Then create a factory method called "new_creator" to return instances of your subclass:

extern "C"
Q_DECL_EXPORT ThumbCreator *new_creator()
return new FooThumbCreator();

Compile your ThumbCreator as a module; for example, the relevant CMake code for a thumbnailer for the "foo" filetype might look like

add_library(foothumbnail MODULE foothumbnail.cpp)
target_link_libraries(foothumbnail PRIVATE KF5::KIOWidgets)

You also need to create a desktop file describing the thumbnailer. For example:

[Desktop Entry]
Name=Foo Documents

Of course, you will need to install it:

install(FILES foothumbcreator.desktop DESTINATION ${KDE_INSTALL_KSERVICESDIR})

Note that you can supply a comma-separated list of MIME types to the MimeTypes entry, naming all MIME types your ThumbCreator supports. You can also use simple wildcards, like "text/*".

If the thumbnail creation is cheap (such as text previews), you can set


in the desktop file to prevent your thumbnails from being cached on disk.

You can also use the "ThumbnailerVersion" optional property in the .desktop file, like


When this is incremented (or defined when it previously was not), all the previously-cached thumbnails for this creator will be discarded. You should increase the version if and only if old thumbnails need to be regenerated.

Definition at line 85 of file thumbcreator.h.

Member Enumeration Documentation

◆ Flags

Flags to provide hints to the user of this plugin.

See also

No hints.

since 5.32.

Used to paint a frame around the preview, but applications take care of that nowadays.


The MIME type icon should be blended over the preview.

Definition at line 92 of file thumbcreator.h.

Constructor & Destructor Documentation

◆ ~ThumbCreator()

ThumbCreator::~ThumbCreator ( )


Definition at line 12 of file thumbcreator.cpp.

Member Function Documentation

◆ create()

virtual bool ThumbCreator::create ( const QString path,
int  width,
int  height,
QImage img 
pure virtual

Creates a thumbnail.

Note that this method should not do any scaling. The width and height parameters are provided as hints for images that are generated from non-image data (like text).

pathThe path of the file to create a preview for. This is always a local path.
widthThe requested preview width (see the note on scaling above).
heightThe requested preview height (see the note on scaling above).
imgThe QImage to store the preview in.
true if a preview was successfully generated and store in img, false otherwise.

◆ createConfigurationWidget()

QWidget * ThumbCreator::createConfigurationWidget ( )

Create a widget for configuring the thumb creator.

The caller will take ownership of the returned instance and must ensure its deletion.

The default implementation returns nullptr.

The following key in the thumbcreator .desktop file must be set to mark the plugin as configurable:

A QWidget instance, which the caller takes ownership of, or nullptr.
Since 5.87, deprecated for lack of usage and only being used for niche usecases. Instead use sane defaults and keep reading the config if it exists.

Definition at line 28 of file thumbcreator.cpp.

◆ flags()

ThumbCreator::Flags ThumbCreator::flags ( ) const

Returns the flags for this plugin.

XOR'd flags values.
See also

Definition at line 16 of file thumbcreator.cpp.

◆ writeConfiguration()

void ThumbCreator::writeConfiguration ( const QWidget configurationWidget)

Write the updated configuration.

configurationWidgetAn object returned by createConfigurationWidget().
Since 5.87, see API docs of createConfigurationWidget

Definition at line 33 of file thumbcreator.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed May 25 2022 03:51:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.