/src/kio-extras/thumbnail/cursorcreator.cpp
Line | Count | Source |
1 | | /* This file is part of the KDE libraries |
2 | | SPDX-FileCopyrightText: 2003 Fredrik Höglund <fredrik@kde.org> |
3 | | |
4 | | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | | */ |
6 | | |
7 | | #include "cursorcreator.h" |
8 | | |
9 | | #include <QFile> |
10 | | #include <QImage> |
11 | | |
12 | | #include <KPluginFactory> |
13 | | |
14 | | #include <X11/Xcursor/Xcursor.h> |
15 | | #include <X11/Xlib.h> |
16 | | |
17 | 0 | K_PLUGIN_CLASS_WITH_JSON(CursorCreator, "cursorthumbnail.json") Unexecuted instantiation: cursorthumbnail_factory::tr(char const*, char const*, int) Unexecuted instantiation: cursorthumbnail_factory::~cursorthumbnail_factory() |
18 | 0 |
|
19 | 0 | CursorCreator::CursorCreator(QObject *parent, const QVariantList &args) |
20 | 2.01k | : KIO::ThumbnailCreator(parent, args) |
21 | 2.01k | { |
22 | 2.01k | } |
23 | | |
24 | | KIO::ThumbnailResult CursorCreator::create(const KIO::ThumbnailRequest &request) |
25 | 2.01k | { |
26 | 2.01k | const int width = request.targetSize().width(); |
27 | 2.01k | const int height = request.targetSize().height(); |
28 | | |
29 | 2.01k | XcursorImage *cursor = XcursorFilenameLoadImage(QFile::encodeName(request.url().toLocalFile()).data(), width > height ? height : width); |
30 | | |
31 | 2.01k | if (cursor) { |
32 | 75 | QImage img(reinterpret_cast<uchar *>(cursor->pixels), cursor->width, cursor->height, QImage::Format_ARGB32_Premultiplied); |
33 | | |
34 | | // Create a deep copy of the image so the image data is preserved |
35 | 75 | img = img.copy(); |
36 | 75 | XcursorImageDestroy(cursor); |
37 | 75 | return KIO::ThumbnailResult::pass(img); |
38 | 75 | } |
39 | | |
40 | 1.93k | return KIO::ThumbnailResult::fail(); |
41 | 2.01k | } |
42 | | |
43 | | #include "cursorcreator.moc" |
44 | | #include "moc_cursorcreator.cpp" |