author | wimpie <wimpie> | 2005-01-09 02:59:13 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-09 02:59:13 (UTC) |
commit | 987bc9a2c5b39ddd4dc2a665cea65688bfd2179e (patch) (unidiff) | |
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 | 130 | ||||
-rw-r--r-- | library/resource.cpp | 13 |
2 files changed, 90 insertions, 53 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 1c1a227..80f2c62 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -983,2 +983,39 @@ void AppLnk::removeLinkFile() | |||
983 | 983 | ||
984 | class AppLnkImagePrivate { | ||
985 | public : | ||
986 | AppLnkImagePrivate( const QString & ImageName ) { | ||
987 | IconName = ImageName; | ||
988 | Small = 0; | ||
989 | Big = 0; | ||
990 | } | ||
991 | ~AppLnkImagePrivate( ) { | ||
992 | if ( Small ) delete Small; | ||
993 | if ( Big ) delete Big; | ||
994 | } | ||
995 | |||
996 | inline QPixmap * small( void ) { | ||
997 | if( ! Small ) { | ||
998 | QImage unscaledIcon = Resource::loadImage( IconName ); | ||
999 | // works as long as smallSize remains static | ||
1000 | Small = new QPixmap(); | ||
1001 | Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | ||
1002 | } | ||
1003 | return Small; | ||
1004 | } | ||
1005 | |||
1006 | inline QPixmap * big( void ) { | ||
1007 | if( ! Big ) { | ||
1008 | QImage unscaledIcon = Resource::loadImage( IconName ); | ||
1009 | // works as long as bigSize remains static | ||
1010 | Big = new QPixmap(); | ||
1011 | Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | ||
1012 | } | ||
1013 | return Big; | ||
1014 | } | ||
1015 | |||
1016 | QString IconName; | ||
1017 | QPixmap * Small; | ||
1018 | QPixmap * Big; | ||
1019 | }; | ||
1020 | |||
984 | class AppLnkSetPrivate { | 1021 | class AppLnkSetPrivate { |
@@ -987,9 +1024,7 @@ public: | |||
987 | { | 1024 | { |
988 | typPix.setAutoDelete(TRUE); | 1025 | typPix.setAutoDelete(TRUE); |
989 | typPixBig.setAutoDelete(TRUE); | 1026 | typName.setAutoDelete(TRUE); |
990 | typName.setAutoDelete(TRUE); | ||
991 | } | 1027 | } |
992 | 1028 | ||
993 | QDict<QPixmap> typPix; | 1029 | QDict<AppLnkImagePrivate> typPix; |
994 | QDict<QPixmap> typPixBig; | ||
995 | QDict<QString> typName; | 1030 | QDict<QString> typName; |
@@ -1088,15 +1123,12 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin | |||
1088 | if ( dir.exists( ".directory" ) ) { | 1123 | if ( dir.exists( ".directory" ) ) { |
1089 | Config config( dr + "/.directory", Config::File ); | 1124 | Config config( dr + "/.directory", Config::File ); |
1090 | config.setGroup( "Desktop Entry" ); | 1125 | config.setGroup( "Desktop Entry" ); |
1091 | typNameLocal = config.readEntry( "Name", typNameLocal ); | 1126 | typNameLocal = config.readEntry( "Name", typNameLocal ); |
1092 | if ( !typ.isEmpty() ) { | 1127 | if ( !typ.isEmpty() ) { |
1093 | QString iconFile = config.readEntry( "Icon", "AppsIcon" ); | 1128 | d->typPix.insert( typ, |
1094 | QImage unscaledIcon = Resource::loadImage( iconFile ); | 1129 | new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) ) |
1095 | QPixmap pm, bpm; | 1130 | ); |
1096 | pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 1131 | d->typName.insert(typ, new QString(typNameLocal)); |
1097 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 1132 | |
1098 | d->typPix.insert(typ, new QPixmap(pm)); | 1133 | } |
1099 | d->typPixBig.insert(typ, new QPixmap(bpm)); | ||
1100 | d->typName.insert(typ, new QString(typNameLocal)); | ||
1101 | } | ||
1102 | } | 1134 | } |
@@ -1105,34 +1137,34 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin | |||
1105 | if ( list ) { | 1137 | if ( list ) { |
1106 | QFileInfo* fi; | 1138 | QFileInfo* fi; |
1107 | bool cadded=FALSE; | 1139 | bool cadded=FALSE; |
1108 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1140 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1109 | QString bn = fi->fileName(); | 1141 | QString bn = fi->fileName(); |
1110 | // qDebug("findChildren "+bn); | 1142 | // qDebug("findChildren "+bn); |
1111 | if ( bn[0] != '.' && bn != "CVS" ) { | 1143 | if ( bn[0] != '.' && bn != "CVS" ) { |
1112 | if ( fi->isDir() ) { | 1144 | if ( fi->isDir() ) { |
1113 | QString c = typ.isNull() ? bn : typ+"/"+bn; | 1145 | QString c = typ.isNull() ? bn : typ+"/"+bn; |
1114 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; | 1146 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; |
1115 | findChildren(fi->filePath(), c, d, depth ); | 1147 | findChildren(fi->filePath(), c, d, depth ); |
1116 | } else { | 1148 | } else { |
1117 | if ( fi->extension(FALSE) == "desktop" ) { | 1149 | if ( fi->extension(FALSE) == "desktop" ) { |
1118 | AppLnk* app = new AppLnk( fi->filePath() ); | 1150 | AppLnk* app = new AppLnk( fi->filePath() ); |
1119 | #ifdef QT_NO_QWS_MULTIPROCESS | 1151 | #ifdef QT_NO_QWS_MULTIPROCESS |
1120 | if ( !Global::isBuiltinCommand( app->exec() ) ) | 1152 | if ( !Global::isBuiltinCommand( app->exec() ) ) |
1121 | delete app; | 1153 | delete app; |
1122 | else | 1154 | else |
1123 | #endif | 1155 | #endif |
1124 | { | 1156 | { |
1125 | if ( !typ.isEmpty() ) { | 1157 | if ( !typ.isEmpty() ) { |
1126 | if ( !cadded ) { | 1158 | if ( !cadded ) { |
1127 | typs.append(typ); | 1159 | typs.append(typ); |
1128 | cadded = TRUE; | 1160 | cadded = TRUE; |
1129 | } | 1161 | } |
1130 | app->setType(typ); | 1162 | app->setType(typ); |
1163 | } | ||
1164 | add(app); | ||
1165 | } | ||
1166 | } | ||
1131 | } | 1167 | } |
1132 | add(app); | ||
1133 | } | ||
1134 | } | 1168 | } |
1135 | } | ||
1136 | } | 1169 | } |
1137 | } | ||
1138 | } | 1170 | } |
@@ -1194,4 +1226,4 @@ QPixmap AppLnkSet::typePixmap( const QString& t ) const | |||
1194 | { | 1226 | { |
1195 | QPixmap *pm = d->typPix.find(t); | 1227 | AppLnkImagePrivate *alip = d->typPix.find(t); |
1196 | return pm ? *pm : QPixmap(); | 1228 | return alip ? *(alip->small()) : QPixmap(); |
1197 | } | 1229 | } |
@@ -1206,4 +1238,4 @@ QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const | |||
1206 | { | 1238 | { |
1207 | QPixmap *pm = d->typPixBig.find(t); | 1239 | AppLnkImagePrivate *alip = d->typPix.find(t); |
1208 | return pm ? *pm : QPixmap(); | 1240 | return alip ? *(alip->big()) : QPixmap(); |
1209 | } | 1241 | } |
diff --git a/library/resource.cpp b/library/resource.cpp index cfa0d26..b31876f 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -61,9 +61,15 @@ static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | |||
61 | */ | 61 | */ |
62 | #include <stdio.h> | ||
62 | QPixmap Resource::loadPixmap( const QString &pix ) | 63 | QPixmap Resource::loadPixmap( const QString &pix ) |
63 | { | 64 | { |
64 | QPixmap pm; | 65 | QPixmap pm; // null pixmap |
65 | QString key="QPE_"+pix; | 66 | QString key="QPE_"+pix; |
66 | if ( !QPixmapCache::find(key,pm) ) { | 67 | if ( !QPixmapCache::find(key,pm) ) { |
67 | pm.convertFromImage(loadImage(pix)); | 68 | QImage I = loadImage(pix); |
68 | QPixmapCache::insert(key,pm); | 69 | if( I.isNull() ) { |
70 | qWarning( "Could not load %s", pix.latin1() ); | ||
71 | } else { | ||
72 | pm.convertFromImage(I); | ||
73 | QPixmapCache::insert(key,pm); | ||
74 | } | ||
69 | } | 75 | } |
@@ -103,3 +109,2 @@ QString Resource::findPixmap( const QString &pix ) | |||
103 | 109 | ||
104 | |||
105 | // All formats... | 110 | // All formats... |