ThumbCreator

ThumbCreator Class Referenceabstract

#include <KIO/ThumbCreator>

Inheritance diagram for ThumbCreator:

Public Types

enum  Flags { None = 0, DrawFrame = 1, 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

set(foothumbnail_SRCS foothumbnail.cpp)
add_library(foothumbnail MODULE ${foothumbnail_SRCS})
target_link_libraries(foothumbnail PRIVATE KF5::KIOWidgets)
install(TARGETS foothumbnail DESTINATION ${PLUGIN_INSTALL_DIR})

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

[Desktop Entry]
Type=Service
Name=Foo Documents
X-KDE-ServiceTypes=ThumbCreator
MimeType=application/x-foo;
CacheThumbnail=true
X-KDE-Library=foothumbcreator

Of course, you will need to install it:

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

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

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

CacheThumbnail=false

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

ThumbnailerVersion=5

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 86 of file thumbcreator.h.

Member Enumeration Documentation

Flags to provide hints to the user of this plugin.

See also
flags()
Enumerator
None 

No hints.

DrawFrame 
Deprecated:
since 5.32.

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

BlendIcon 

The mimetype icon should be blended over the preview.

Definition at line 93 of file thumbcreator.h.

Constructor & Destructor Documentation

ThumbCreator::~ThumbCreator ( )
virtual

Destructor.

Definition at line 12 of file thumbcreator.cpp.

Member Function Documentation

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).

Parameters
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.
Returns
true if a preview was successfully generated and store in img, false otherwise.
QWidget * ThumbCreator::createConfigurationWidget ( )
virtual

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:

Configurable=true
Returns
A QWidget instance, which the caller takes ownership of, or nullptr.

Definition at line 27 of file thumbcreator.cpp.

ThumbCreator::Flags ThumbCreator::flags ( ) const
virtual

Returns the flags for this plugin.

Returns
XOR'd flags values.
See also
Flags

Definition at line 16 of file thumbcreator.cpp.

void ThumbCreator::writeConfiguration ( const QWidget configurationWidget)
virtual

Write the updated configuration.

Parameters
configurationWidgetAn object returned by createConfigurationWidget().

Definition at line 32 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-2020 The KDE developers.
Generated on Sat Sep 19 2020 23:00:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.