diff --git a/src/YQIconPool.cc b/src/YQIconPool.cc index 4e031f1..2f1bbed 100644 --- a/src/YQIconPool.cc +++ b/src/YQIconPool.cc @@ -42,9 +42,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #define YUILogComponent "qt-ui" #include "YUILog.h" +#include "utf8.h" #include "YQIconPool.h" +using std::endl; + YQIconPool * YQIconPool::_iconPool = 0; @@ -113,19 +116,46 @@ YQIconPool::cachedIcon( const QString icon_name, const bool enabled ) if ( !iconPixmap ) { - if ( QIcon::hasThemeIcon(icon_name) ) - { - QIcon icon = QIcon::fromTheme(icon_name, QIcon( ":/" + icon_name )); - iconPixmap = icon.pixmap(QSize(16,16), enabled ? QIcon::Normal : QIcon::Disabled); - } - else + iconPixmap = loadIcon( icon_name, enabled ); + + if ( !iconPixmap ) { - QIcon icon = QIcon( ":/" + icon_name ); - iconPixmap = icon.pixmap(QSize(16,16), enabled ? QIcon::Normal : QIcon::Disabled); + // Create an icon for the cache to avoid more than one complaint + // and to have a clearly visible error icon (a small red square) + iconPixmap = QPixmap( 8, 8 ); + iconPixmap.fill( Qt::red ); } } - _iconCache.insert( icon_name + enabled, iconPixmap); + _iconCache.insert( icon_name + enabled, iconPixmap ); + + return iconPixmap; +} + + +QPixmap +YQIconPool::loadIcon( const QString icon_name, const bool enabled ) +{ + QPixmap iconPixmap = _iconCache[ icon_name + enabled ]; + + if ( QIcon::hasThemeIcon( icon_name ) ) + { + yuiDebug() << "Loading theme icon " << icon_name << endl; + + QIcon icon = QIcon::fromTheme( icon_name, QIcon( ":/" + icon_name ) ); + iconPixmap = icon.pixmap( QSize( 16, 16 ), enabled ? QIcon::Normal : QIcon::Disabled ); + } + else + { + yuiDebug() << "Loading built-in icon " << icon_name << endl; + + QIcon icon = QIcon( ":/" + icon_name ); + iconPixmap = icon.pixmap( QSize( 16, 16 ), enabled ? QIcon::Normal : QIcon::Disabled ); + } + + if ( !iconPixmap ) + yuiError() << "Could not load icon " << icon_name << endl; + return iconPixmap; } diff --git a/src/YQIconPool.h b/src/YQIconPool.h index e3edfd4..588a9ec 100644 --- a/src/YQIconPool.h +++ b/src/YQIconPool.h @@ -70,12 +70,12 @@ class YQIconPool static QPixmap disabledPkgProtected(); static QPixmap disabledPkgTaboo(); static QPixmap disabledPkgUpdate(); - + static QPixmap normalPkgConflict(); static QPixmap treePlus(); static QPixmap treeMinus(); - + static QPixmap warningSign(); static QPixmap pkgSatisfied(); @@ -92,12 +92,20 @@ class YQIconPool static YQIconPool * iconPool(); /** - * Return the cached icon for 'xpm_data' ( an included XPM file ). - * If the icon isn't in the cache yet, create it and store it in the - * cache. + * Return the cached icon for 'icon_name'. If the icon isn't in the cache + * yet, load it and store it in the cache. + * + * Return a red square as an error icon if there is no icon by that name. **/ QPixmap cachedIcon(const QString icon_name, const bool enabled ); + /** + * Load the icon for 'icon_name' from the icon theme or, if that fails, + * from the compiled-in icons (using the Qt resource system). Return a null + * pixmap if there is no such icon. + **/ + QPixmap loadIcon( const QString icon_name, const bool enabled ); + private: /** @@ -111,7 +119,7 @@ class YQIconPool **/ virtual ~YQIconPool(); - + // // Data members //