File indexing completed on 2024-04-28 04:58:02
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2003 Fredrik Höglund <fredrik@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "cursorcreator.h" 0008 0009 #include <QFile> 0010 #include <QImage> 0011 0012 #include <KPluginFactory> 0013 0014 #include <X11/Xcursor/Xcursor.h> 0015 #include <X11/Xlib.h> 0016 0017 K_PLUGIN_CLASS_WITH_JSON(CursorCreator, "cursorthumbnail.json") 0018 0019 CursorCreator::CursorCreator(QObject *parent, const QVariantList &args) 0020 : KIO::ThumbnailCreator(parent, args) 0021 { 0022 } 0023 0024 KIO::ThumbnailResult CursorCreator::create(const KIO::ThumbnailRequest &request) 0025 { 0026 const int width = request.targetSize().width(); 0027 const int height = request.targetSize().height(); 0028 0029 XcursorImage *cursor = XcursorFilenameLoadImage(QFile::encodeName(request.url().toLocalFile()).data(), width > height ? height : width); 0030 0031 if (cursor) { 0032 QImage img(reinterpret_cast<uchar *>(cursor->pixels), cursor->width, cursor->height, QImage::Format_ARGB32_Premultiplied); 0033 0034 // Create a deep copy of the image so the image data is preserved 0035 img = img.copy(); 0036 XcursorImageDestroy(cursor); 0037 return KIO::ThumbnailResult::pass(img); 0038 } 0039 0040 return KIO::ThumbnailResult::fail(); 0041 } 0042 0043 #include "cursorcreator.moc" 0044 #include "moc_cursorcreator.cpp"