Use KPluginFactory for loading thumbnail plugins
Open, Needs TriagePublic

Description

Relevant code is at https://invent.kde.org/network/kio-extras/-/blob/master/thumbnail/thumbnail.cpp#L658

Currently when loading a thumbnail plugin we:

  • Take the name and pass that to KPluginLoader::findPlugin (which is deprecated) to get the full path
  • Load that path via QLibrary
  • Resolve the new_creator symbol
  • Call new_creator to instantiate a creator
  • if the plugin name starts with kf5/thumbcreator/ we create a KPluginMetaData for it
  • if not we look up the metadata using KServiceTypeTrader
  • profit

This is different to how we do plugins anywhere else for no apparent reason. The first half is basically reinventing KPluginFactory.

There is a 20 year old comment about this

// Don't use KPluginFactory here, this is not a QObject and
// neither is ThumbCreator

If we made ThumbCreator a QObject that would allow to simplify/align that code at cost of changing all the plugins, but we need to do that anyway to get rid of KServiceTypeTrader

alex added a subscriber: alex.Apr 29 2022, 2:40 PM

but we need to do that anyway to get rid of KServiceTypeTrader

The thumbnailers that are part of kio-extras are already ported away from it. Only the directory thumbnailer is a special case, because it is kindof a placeholder for the thumbnailer

((plugin.isEmpty() || plugin == "directorythumbnail") && m_mimeType == "inode/directory")

Take the name and pass that to KPluginLoader::findPlugin (which is deprecated) to get the full path

https://invent.kde.org/network/kio-extras/-/merge_requests/153

If we made ThumbCreator a QObject that would allow to simplify/align that code at cost of changing all the plugins,

From my interpretation T13527 goes in this direction. Though the task seems to have fallen under the radar.

With https://invent.kde.org/network/kio-extras/-/blob/master/thumbnail/macros.h, we would only need to touch one files and not all kio-extras thumbnailers.

alex awarded a token.Apr 29 2022, 2:40 PM

There's a good amount of thumbnailers outside of kio-extras though, which suggests we want something like https://invent.kde.org/network/kio-extras/-/blob/master/thumbnail/macros.h in a library

alex added a comment.Apr 29 2022, 5:29 PM

the macro is of course a bit opiniated and I am not sure if we even want to have it during all of KF6 just to ease the transition period a bit. If we use KPluginFactory, we could simply do:

#if KF6_BUILD
K_PLUGIN_CLASS_WITH_JSON(MyClass, "bla.json")
#else
code that is currently around
#endif

Though on the other hand, this macro would serve an actual purpose unlike the ones I deprecated as part of T14542.

nicolasfella moved this task from Backlog to In Progress on the KF6 board.May 8 2022, 1:13 PM
nicolasfella moved this task from In Progress to Done on the KF6 board.Feb 20 2023, 4:57 PM