KParts: add PartLoader as replacement to KMimeTypeTrader for parts
ClosedPublic

Authored by dfaure on Mar 10 2020, 10:33 AM.

Details

Summary

It's based on the JSON metadata embedded into the plugins in kf5/parts/,
but it also has fallback code using KMimeTypeTrader internally until
KF6, so that we can start using PartLoader in applications.

Test Plan

Tested with partviewer, see also next commit for unittest

Diff Detail

Repository
R306 KParts
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
dfaure created this revision.Mar 10 2020, 10:33 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptMar 10 2020, 10:33 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
dfaure requested review of this revision.Mar 10 2020, 10:33 AM
aacid added inline comments.Mar 10 2020, 9:25 PM
src/partloader.h
60

What's the use for this? The function below doesn't let me chose which one i want (i guess it always uses the one with the most preference?), so why would i need to query which parts are available?

Maybe there should be a version of create that takes a KPluginMetadata?

dfaure added inline comments.Mar 11 2020, 2:16 AM
src/partloader.h
60

This is an excellent point, thanks for this feedback.

Loading a part from a given KPluginMetadata is extremely simple, though:

KPluginLoader loader(md.fileName());
m_part = loader.factory()->create<KParts::ReadOnlyPart>(this, this);

Just like any other plugin.
[maybe with md.keyword() as third argument in the future, once that's implemented]

I can see the idea of providing everything that is needed for KParts at the KParts level, so that one doesn't actually have to figure out that the above is the way to do it. But then again, this is the way to do it for any plugin, there's nothing specific about KParts there. So an alternative would be to put this into the documentation for partsForMimeType?

What do you think? Docu or wrapper for a two-liner?

BTW I just implemented part listing (in an actionlist) and part switching in partviewer (which is turning into a mini-konqueror, hehe). It shows that the above works. It also shows that the duplication between new-style JSON and old-style desktop files is a problem, I'll add some duplicate pruning...

dfaure updated this revision to Diff 77381.Mar 11 2020, 2:31 AM

Ensure no duplicates in partsForMimeType

aacid added inline comments.Mar 11 2020, 11:17 PM
src/partloader.h
60

I'd say documentation is fine :)

dfaure updated this revision to Diff 77474.Mar 12 2020, 1:36 AM

Document how to load a part from a given KPluginMetaData

aacid added a comment.EditedMar 12 2020, 6:57 PM

Looks reasonable to me, but i'm not a huge expert here either, i guess you can commit given you are the expert.

Or maybe wait a few days in case someone else has comments?

Yeah I guess "looks reasonable" is the most I can expect :-)

Any chance you could take a look at https://phabricator.kde.org/D27967 which is needed for this to land? Thanks.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 21 2020, 10:00 AM
This revision was automatically updated to reflect the committed changes.