ThumbCreator

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" KIO worker, 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)
install(TARGETS foothumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})

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 ${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

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.

Deprecated:
since 5.101, use KIO::ThumbnailCreator instead

Definition at line 87 of file thumbcreator.h.

Member Enumeration Documentation

◆ Flags

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 MIME type icon should be blended over the preview.

Definition at line 94 of file thumbcreator.h.

Constructor & Destructor Documentation

◆ ~ThumbCreator()

ThumbCreator::~ThumbCreator ( )
virtual

Destructor.

Definition at line 14 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).

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.
Deprecated:
since 5.101, use KIO::ThumbnailCreator instead.

◆ createConfigurationWidget()

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.
Deprecated:
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 30 of file thumbcreator.cpp.

◆ flags()

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

Returns the flags for this plugin.

Returns
XOR'd flags values.
See also
Flags

Definition at line 18 of file thumbcreator.cpp.

◆ writeConfiguration()

void ThumbCreator::writeConfiguration ( const QWidget configurationWidget)
virtual

Write the updated configuration.

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

Definition at line 35 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-2023 The KDE developers.
Generated on Thu Dec 7 2023 03:55:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.