1 /* This file is part of the KDE libraries
2 Copyright (C) 2000 Malte Starostik <malte@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef _THUMBCREATOR_H_
21 #define _THUMBCREATOR_H_
23 #include <kio/kio_export.h>
28 * This is the baseclass for "thumbnail-plugins" in KDE. Using the class
29 * KIO::PreviewJob allows you to generate small images (thumbnails)
30 * for any kind of file, where a "ThumbCreator" is available. Have a look
31 * at kdebase/kioslave/thumbnail/ for existing ThumbCreators.
33 * What you need to do to create and register a ThumbCreator:
34 * @li Inherit from this class and reimplement the create() method to
35 * generate a thumbnail for the given file-path.
36 * @li Provide a factory method in your implementation file to instantiate
41 * KDE_EXPORT ThumbCreator *new_creator()
43 * return new YourThumbCreator();
48 * Compile your ThumbCreator as a module. The contents of CMakeLists.txt
49 * should look something like this, with "filetype" replaced by the type of
50 * file this plugin creates thumbnails for:
52 * project(filetypethumbcreator)
54 * find_package(KDE4 REQUIRED)
55 * include (KDE4Defaults)
56 * include(MacroOptionalAddSubdirectory)
58 * set(filetypethumbnail_SRCS filetypethumbnail.cpp)
61 * kde4_add_ui_files(filetypethumbnail_SRCS config.ui )
63 * kde4_add_plugin(filetypethumbnail ${filetypethumbnail_SRCS})
64 * target_link_libraries(filetypethumbnail ${KDE4_KIO_LIBS})
66 * install(TARGETS filetypethumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
67 * install(FILES filetypethumbcreator.desktop DESTINATION ${SERVICES_INSTALL_DIR})
71 * @li Create a file filetypethumbcreator.desktop with the following contents:
76 * Name=Name of the type of files your ThumbCreator supports
77 * ServiceTypes=ThumbCreator
78 * MimeType=application/x-somemimetype;
80 * X-KDE-Library=yourthumbcreator
83 * You can supply a comma-separated list of mimetypes to the MimeTypes entry,
84 * naming all mimetypes your ThumbCreator supports. You can also use simple
85 * wildcards, like (where you see [slash], put a /)
87 * text[slash]* or image[slash]*.
90 * If your plugin is rather inexpensive (e.g. like the text preview ThumbCreator),
91 * you can set CacheThumbnail=false to prevent your thumbnails from being cached
94 * @short Baseclass for thumbnail-generating plugins.
96 class KIO_EXPORT ThumbCreator
100 * The flags of this plugin.
103 enum Flags
{ None
= 0, DrawFrame
= 1, BlendIcon
= 2 };
104 virtual ~ThumbCreator();
107 * Creates a thumbnail
108 * Note that the width and height parameters should not be used
109 * for scaling. Only plugins that create an image "from scratch",
110 * like the TextCreator should directly use the specified size.
111 * If the resulting preview is larger than width x height, it will be
114 * @param path the (always local) file path to create a preview for
115 * @param width maximum width for the preview
116 * @param height maximum height for the preview
117 * @param img this image will contain the preview on success
119 * @return true if preview generation succeeded
121 virtual bool create(const QString
&path
, int width
, int height
, QImage
&img
) = 0;
124 * The flags of this plugin:
125 * @li None nothing special
126 * @li DrawFrame a frame should be painted around the preview
127 * @li BlendIcon the mimetype icon should be blended over the preview
129 * @return flags for this plugin
131 virtual Flags
flags() const { return None
; } //krazy:exclude=inline
134 typedef ThumbCreator
*(*newCreator
)();