Merge KFileItemListProperties into KFileItemList
Open, Needs TriagePublic

Description

There is this old KF5 TODO that was never addressed: https://invent.kde.org/frameworks/kio/-/blob/master/src/core/kfileitem.h#L691

Currently the problem is that whenever KFileItemLists are passed around in application code like Dolphin and we need some meta-information about common qualities of the KFileItems in the list, the information isn't passed along together with the KFileItemList but has to be retrieved separately through a KFileItemListProperties object. This can lead to multiple KFileItemListProperties objects being created at different places for the same KFileItemList just because the information is only available elsewhere. It is slightly inefficient but also more complicated than it should be because API users need to learn that the KFileItemListProperties class exists when the methods could simply be part of the KFileItemList API.

I'd be interested in fixing this and merging the two classes but I need some input on how to best do this.

The main problem is that the KFileItemList inherits from QList<KFileItem>. QList doesn't notify anyone when its contents changes which means that pretty much every method from KFileItemListProperties can't efficiently be merged into how the KFileItemList currently works. We never know if the contents of the QList<KFileItem> changed so a re-computation of a property would be necessary every time methods like e.g. isDirectory() are called.

I see two solutions to this:

  1. Don't publicly inherit from QList<KFileItem>: This either means we publicly inherit from something else or that we have wrapper methods for typical list manipulation.
  1. Have KFileItemList be a "const-only" class: All methods of construction only return const objects. This way we can be (reasonably) sure that the underlying QList<KFileItem> didn't change and all calls to the merged KFileItemListProperties methods are as efficient as possible.

I think the second solution would make the most sense. What do you think?

Another question is how to do the ABI change. Should we just replace the KFileItemList class with this new one for KF6 and then applications have to adapt as part of the porting or should this new merge of KFileItemListProperties into KFileItemList be a separate class for now (KFileItemListWithProperties) and we deprecate the old one.

I haven't really involved myself into KF6 preparations until now so let me know if this is the wrong way to discuss this.

felixernst moved this task from Backlog to Needs Input on the KF6 board.