KApplicationTrader API

David Faure faure at kde.org
Sun Jan 12 10:50:03 GMT 2020


I wrote a KApplicationTrader class in https://phabricator.kde.org/D25698
and I need input on API.

Use case: the user types "km" in krunner.
In order to find all applications that contain "km" (case insensitive), do we want to write

auto offers = KApplicationTrader::self()->query("'km' ~~ Name");

or

auto filter = [](const KService::Ptr &service) { return service->name().contains("km", Qt::CaseInsensitive); }
auto offers = KApplicationTrader::self()->query(filter);

?

And once we have decided on trader-language (like the old traders) vs filter function (like KPluginLoader)
we need to decide on how to provide such a global method in a C++ world ;)

auto offers = KApplicationTrader::self()->query(...);
or
auto offers = KApplicationTrader::query(...);
or
auto offers = KApplicationTrader().query(...);

Input very welcome.

Note that the least-porting-effort solution is self() and trader language, since the code currently uses KServiceTypeTrader for this.

But I'm tempted to say lambdas are nicer (you can debug the filtering more easily), and would allow to kill the whole
trader-language-parser from kservice in KF6.
And for the second question, Qt doesn't have any self(). I don't think it has many functions-in-namespace either?
The last one is more like QFontDatabase/QMimeDatabase, but creating an instance is annoying.
I think I like the middle one (function-in-namespace) best, from the calling-site point of view.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5





More information about the Kde-frameworks-devel mailing list