KInstance and KIconLoader

David Faure faure at kde.org
Mon Dec 11 14:34:38 GMT 2006


KIconLoader is the main reason kdecore still needs QtGui, but the problem is 
KInstance::iconLoader and KGlobal::iconLoader, which return iconloader instances.

KInstance::iconLoader() creates an iconloader with the right setup (name and kstandarddirs)
and it remembers it, so that only one such iconloader per kinstance gets created, and reused.

To move kiconloader out of kdecore I would simply get rid of {KInstance,KGlobal}::iconLoader()
and provide the right API at the KIconLoader level (in kdeui).

But KIconLoader::KIconLoader(KInstance*) wouldn't be enough, people would create tons
of iconloader instances, which would be slow.

The only solution I can think of right now is
  static KIconLoader* KIconLoader::instance( KInstance* = 0 )
with a qmap in the implementation to reuse kiconloader instances.
This would mean that the porting would look like:
  KGlobal::iconLoader()             =>  KIconLoader::instance()
  KGlobal::instance()->iconLoader() =>  KIconLoader::instance()
  myInstance->iconLoader()          =>  KIconLoader::instance( myInstance )
For all code using DeskopIcon/SmallIcon/BarIcon/UserIcon (with an optional instance argument) etc. there is no change.

Naming the method "instance" is a bit confusing, but it's not a real singletion so self() would be bad,
and I don't have a better idea.

I guess the better solution (but which involves more work) is to move all logic to KIconLoaderPrivate
and have a <instance,loaderprivate> qmap, so that "KIconLoader iconLoader(instance)" reuses an existing
private backend; then creating iconloaders is cheap and there's no need for factory methods.

The problem in all cases is also that the qmap would keep old deleted instances...
(and we can't turn kinstance into a qobject since kapp multiply derives from qapp+kinstance).

Any other ideas?

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list