File indexing completed on 2024-04-28 03:55:12

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2015 Olivier Goffart <ogoffart@woboq.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef KOVERLAYICONPLUGIN_H
0009 #define KOVERLAYICONPLUGIN_H
0010 
0011 #include "kiocore_export.h"
0012 #include <QObject>
0013 
0014 class QUrl;
0015 
0016 /**
0017  * @class KOverlayIconPlugin koverlayiconplugin.h <KOverlayIconPlugin>
0018  *
0019  * @brief Base class for overlay icon plugins.
0020  * Enables file managers to show custom overlay icons on files.
0021  *
0022  * This plugin can be created and installed through kcoreaddons_add_plugin
0023  * @code
0024  * kcoreaddons_add_plugin(myoverlayplugin SOURCES myoverlayplugin.cpp INSTALL_NAMESPACE "kf6/overlayicon")
0025  * target_link_libraries(myoverlayplugin KF6::KIOCore)
0026  * @endcode
0027  * The C++ file should look like this:
0028  * @code
0029 #include <KOverlayIconPlugin>
0030 
0031 class MyOverlayPlugin : public KOverlayIconPlugin
0032 {
0033     Q_PLUGIN_METADATA(IID "org.kde.overlayicon.myplugin")
0034     Q_OBJECT
0035 
0036 public:
0037     MyOverlayPlugin() {
0038     }
0039 
0040     QStringList getOverlays(const QUrl &url) override {
0041         // Implement your logic
0042     }
0043 };
0044 
0045 #include "myoverlayplugin.moc"
0046  * @endcode
0047  * @since 5.16
0048  */
0049 class KIOCORE_EXPORT KOverlayIconPlugin : public QObject
0050 {
0051     Q_OBJECT
0052 public:
0053     explicit KOverlayIconPlugin(QObject *parent = nullptr);
0054     ~KOverlayIconPlugin() override;
0055 
0056     /**
0057      * Returns a list of overlay icons to add to a file
0058      * This can be a path to an icon, or the icon name
0059      *
0060      * This function is called from the main thread and must not block.
0061      * It is recommended to have a cache. And if the item is not in cache
0062      * just return an empty list and call the overlaysChanged when the
0063      * information is available.
0064      */
0065     virtual QStringList getOverlays(const QUrl &item) = 0;
0066 Q_SIGNALS:
0067     /**
0068      * Emit this signal when the list of overlay icons changed for a given URL
0069      */
0070     void overlaysChanged(const QUrl &url, const QStringList &overlays);
0071 };
0072 
0073 #endif