-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 | |||
@@ -976,27 +976,62 @@ void AppLnk::removeLinkFile() | |||
976 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { | 976 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { |
977 | #ifndef QT_NO_COP | 977 | #ifndef QT_NO_COP |
978 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 978 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
979 | e << linkFile(); | 979 | e << linkFile(); |
980 | #endif | 980 | #endif |
981 | } | 981 | } |
982 | } | 982 | } |
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 { |
985 | public: | 1022 | public: |
986 | AppLnkSetPrivate() | 1023 | AppLnkSetPrivate() |
987 | { | 1024 | { |
988 | typPix.setAutoDelete(TRUE); | 1025 | typPix.setAutoDelete(TRUE); |
989 | typPixBig.setAutoDelete(TRUE); | ||
990 | typName.setAutoDelete(TRUE); | 1026 | 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; |
996 | }; | 1031 | }; |
997 | 1032 | ||
998 | /*! | 1033 | /*! |
999 | \class AppLnkSet applnk.h | 1034 | \class AppLnkSet applnk.h |
1000 | \brief The AppLnkSet class is a set of AppLnk objects. | 1035 | \brief The AppLnkSet class is a set of AppLnk objects. |
1001 | */ | 1036 | */ |
1002 | 1037 | ||
@@ -1085,24 +1120,21 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin | |||
1085 | QDir dir( dr ); | 1120 | QDir dir( dr ); |
1086 | QString typNameLocal = typName; | 1121 | QString typNameLocal = typName; |
1087 | 1122 | ||
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 ) ); | ||
1097 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | ||
1098 | d->typPix.insert(typ, new QPixmap(pm)); | ||
1099 | d->typPixBig.insert(typ, new QPixmap(bpm)); | ||
1100 | d->typName.insert(typ, new QString(typNameLocal)); | 1131 | d->typName.insert(typ, new QString(typNameLocal)); |
1132 | |||
1101 | } | 1133 | } |
1102 | } | 1134 | } |
1103 | 1135 | ||
1104 | const QFileInfoList *list = dir.entryInfoList(); | 1136 | const QFileInfoList *list = dir.entryInfoList(); |
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 ) { |
@@ -1187,30 +1219,30 @@ QString AppLnkSet::typeName( const QString& t ) const | |||
1187 | /*! | 1219 | /*! |
1188 | Returns the small pixmap associated with type \a t. | 1220 | Returns the small pixmap associated with type \a t. |
1189 | 1221 | ||
1190 | For applications, games and settings the type is \c Application; | 1222 | For applications, games and settings the type is \c Application; |
1191 | for documents the type is the document's MIME type. | 1223 | for documents the type is the document's MIME type. |
1192 | */ | 1224 | */ |
1193 | QPixmap AppLnkSet::typePixmap( const QString& t ) const | 1225 | 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 | } |
1198 | 1230 | ||
1199 | /*! | 1231 | /*! |
1200 | Returns the large pixmap associated with type \a t. | 1232 | Returns the large pixmap associated with type \a t. |
1201 | 1233 | ||
1202 | For applications, games and settings the type is \c Application; | 1234 | For applications, games and settings the type is \c Application; |
1203 | for documents the type is the document's MIME type. | 1235 | for documents the type is the document's MIME type. |
1204 | */ | 1236 | */ |
1205 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const | 1237 | 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 | } |
1210 | 1242 | ||
1211 | /*! | 1243 | /*! |
1212 | Returns the AppLnk with the given \a id. | 1244 | Returns the AppLnk with the given \a id. |
1213 | */ | 1245 | */ |
1214 | const AppLnk *AppLnkSet::find( int id ) const | 1246 | const AppLnk *AppLnkSet::find( int id ) const |
1215 | { | 1247 | { |
1216 | QListIterator<AppLnk> it( children() ); | 1248 | QListIterator<AppLnk> it( children() ); |
diff --git a/library/resource.cpp b/library/resource.cpp index cfa0d26..b31876f 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -54,24 +54,30 @@ static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | |||
54 | \fn Resource::Resource() | 54 | \fn Resource::Resource() |
55 | \internal | 55 | \internal |
56 | */ | 56 | */ |
57 | 57 | ||
58 | /*! | 58 | /*! |
59 | Returns the QPixmap called \a pix. You should avoid including | 59 | Returns the QPixmap called \a pix. You should avoid including |
60 | any filename type extension (e.g. .png, .xpm). | 60 | any filename type extension (e.g. .png, .xpm). |
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); |
69 | if( I.isNull() ) { | ||
70 | qWarning( "Could not load %s", pix.latin1() ); | ||
71 | } else { | ||
72 | pm.convertFromImage(I); | ||
68 | QPixmapCache::insert(key,pm); | 73 | QPixmapCache::insert(key,pm); |
69 | } | 74 | } |
75 | } | ||
70 | return pm; | 76 | return pm; |
71 | } | 77 | } |
72 | 78 | ||
73 | /*! | 79 | /*! |
74 | Returns the QBitmap called \a pix. You should avoid including | 80 | Returns the QBitmap called \a pix. You should avoid including |
75 | any filename type extension (e.g. .png, .xpm). | 81 | any filename type extension (e.g. .png, .xpm). |
76 | */ | 82 | */ |
77 | QBitmap Resource::loadBitmap( const QString &pix ) | 83 | QBitmap Resource::loadBitmap( const QString &pix ) |
@@ -96,17 +102,16 @@ QString Resource::findPixmap( const QString &pix ) | |||
96 | // Common case optimizations... | 102 | // Common case optimizations... |
97 | f = picsPath + pix + ".png"; | 103 | f = picsPath + pix + ".png"; |
98 | if ( QFile( f ).exists() ) | 104 | if ( QFile( f ).exists() ) |
99 | return f; | 105 | return f; |
100 | f = picsPath + pix + ".xpm"; | 106 | f = picsPath + pix + ".xpm"; |
101 | if ( QFile( f ).exists() ) | 107 | if ( QFile( f ).exists() ) |
102 | return f; | 108 | return f; |
103 | 109 | ||
104 | |||
105 | // All formats... | 110 | // All formats... |
106 | QStrList fileFormats = QImageIO::inputFormats(); | 111 | QStrList fileFormats = QImageIO::inputFormats(); |
107 | QString ff = fileFormats.first(); | 112 | QString ff = fileFormats.first(); |
108 | while ( fileFormats.current() ) { | 113 | while ( fileFormats.current() ) { |
109 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 114 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
110 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 115 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
111 | QString f = picsPath + pix + "." + *it; | 116 | QString f = picsPath + pix + "." + *it; |
112 | if ( QFile(f).exists() ) | 117 | if ( QFile(f).exists() ) |