author | wimpie <wimpie> | 2005-01-09 02:59:13 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-09 02:59:13 (UTC) |
commit | 987bc9a2c5b39ddd4dc2a665cea65688bfd2179e (patch) (side-by-side diff) | |
tree | 815fc6d12162f1a5eccc4b1ae0da61dea3811bdf | |
parent | e54346d28b19d3ac671802a25e8c03f346693291 (diff) | |
download | opie-987bc9a2c5b39ddd4dc2a665cea65688bfd2179e.zip opie-987bc9a2c5b39ddd4dc2a665cea65688bfd2179e.tar.gz opie-987bc9a2c5b39ddd4dc2a665cea65688bfd2179e.tar.bz2 |
applnk : lazy loading of mime type icons (load only when needed)
resource.cpp : print warning when requested image cannot be found
and print the name of that image too
-rw-r--r-- | library/applnk.cpp | 60 | ||||
-rw-r--r-- | library/resource.cpp | 11 |
2 files changed, 54 insertions, 17 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 1c1a227..80f2c62 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp @@ -982,4 +982,41 @@ void AppLnk::removeLinkFile() } +class AppLnkImagePrivate { +public : + AppLnkImagePrivate( const QString & ImageName ) { + IconName = ImageName; + Small = 0; + Big = 0; + } + ~AppLnkImagePrivate( ) { + if ( Small ) delete Small; + if ( Big ) delete Big; + } + + inline QPixmap * small( void ) { + if( ! Small ) { + QImage unscaledIcon = Resource::loadImage( IconName ); + // works as long as smallSize remains static + Small = new QPixmap(); + Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); + } + return Small; + } + + inline QPixmap * big( void ) { + if( ! Big ) { + QImage unscaledIcon = Resource::loadImage( IconName ); + // works as long as bigSize remains static + Big = new QPixmap(); + Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); + } + return Big; + } + + QString IconName; + QPixmap * Small; + QPixmap * Big; +}; + class AppLnkSetPrivate { public: @@ -987,10 +1024,8 @@ public: { typPix.setAutoDelete(TRUE); - typPixBig.setAutoDelete(TRUE); typName.setAutoDelete(TRUE); } - QDict<QPixmap> typPix; - QDict<QPixmap> typPixBig; + QDict<AppLnkImagePrivate> typPix; QDict<QString> typName; }; @@ -1091,12 +1126,9 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin typNameLocal = config.readEntry( "Name", typNameLocal ); if ( !typ.isEmpty() ) { - QString iconFile = config.readEntry( "Icon", "AppsIcon" ); - QImage unscaledIcon = Resource::loadImage( iconFile ); - QPixmap pm, bpm; - pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); - bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); - d->typPix.insert(typ, new QPixmap(pm)); - d->typPixBig.insert(typ, new QPixmap(bpm)); + d->typPix.insert( typ, + new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) ) + ); d->typName.insert(typ, new QString(typNameLocal)); + } } @@ -1193,6 +1225,6 @@ QString AppLnkSet::typeName( const QString& t ) const QPixmap AppLnkSet::typePixmap( const QString& t ) const { - QPixmap *pm = d->typPix.find(t); - return pm ? *pm : QPixmap(); + AppLnkImagePrivate *alip = d->typPix.find(t); + return alip ? *(alip->small()) : QPixmap(); } @@ -1205,6 +1237,6 @@ QPixmap AppLnkSet::typePixmap( const QString& t ) const QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const { - QPixmap *pm = d->typPixBig.find(t); - return pm ? *pm : QPixmap(); + AppLnkImagePrivate *alip = d->typPix.find(t); + return alip ? *(alip->big()) : QPixmap(); } diff --git a/library/resource.cpp b/library/resource.cpp index cfa0d26..b31876f 100644 --- a/library/resource.cpp +++ b/library/resource.cpp @@ -60,12 +60,18 @@ static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); any filename type extension (e.g. .png, .xpm). */ +#include <stdio.h> QPixmap Resource::loadPixmap( const QString &pix ) { - QPixmap pm; + QPixmap pm; // null pixmap QString key="QPE_"+pix; if ( !QPixmapCache::find(key,pm) ) { - pm.convertFromImage(loadImage(pix)); + QImage I = loadImage(pix); + if( I.isNull() ) { + qWarning( "Could not load %s", pix.latin1() ); + } else { + pm.convertFromImage(I); QPixmapCache::insert(key,pm); } + } return pm; } @@ -102,5 +108,4 @@ QString Resource::findPixmap( const QString &pix ) return f; - // All formats... QStrList fileFormats = QImageIO::inputFormats(); |