summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--library/applnk.cpp60
-rw-r--r--library/resource.cpp11
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
@@ -972,35 +972,70 @@ void AppLnk::removeFiles()
\sa removeFiles()
*/
void AppLnk::removeLinkFile()
{
if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
e << linkFile();
#endif
}
}
+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:
AppLnkSetPrivate()
{
typPix.setAutoDelete(TRUE);
- typPixBig.setAutoDelete(TRUE);
typName.setAutoDelete(TRUE);
}
- QDict<QPixmap> typPix;
- QDict<QPixmap> typPixBig;
+ QDict<AppLnkImagePrivate> typPix;
QDict<QString> typName;
};
/*!
\class AppLnkSet applnk.h
\brief The AppLnkSet class is a set of AppLnk objects.
*/
/*!
\fn QStringList AppLnkSet::types() const
Returns the list of \link applnk.html#Types types\endlink in the set.
@@ -1081,32 +1116,29 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin
depth++;
if ( depth > 10 )
return;
QDir dir( dr );
QString typNameLocal = typName;
if ( dir.exists( ".directory" ) ) {
Config config( dr + "/.directory", Config::File );
config.setGroup( "Desktop Entry" );
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));
+
}
}
const QFileInfoList *list = dir.entryInfoList();
if ( list ) {
QFileInfo* fi;
bool cadded=FALSE;
for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
QString bn = fi->fileName();
// qDebug("findChildren "+bn);
if ( bn[0] != '.' && bn != "CVS" ) {
if ( fi->isDir() ) {
@@ -1183,38 +1215,38 @@ QString AppLnkSet::typeName( const QString& t ) const
QString *st = d->typName.find(t);
return st ? *st : QString::null;
}
/*!
Returns the small pixmap associated with type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
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();
}
/*!
Returns the large pixmap associated with type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
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();
}
/*!
Returns the AppLnk with the given \a id.
*/
const AppLnk *AppLnkSet::find( int id ) const
{
QListIterator<AppLnk> it( children() );
for ( ; it.current(); ++it ) {
const AppLnk *app = it.current();
if ( app->id() == id )
diff --git a/library/resource.cpp b/library/resource.cpp
index cfa0d26..b31876f 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -50,32 +50,38 @@ static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET");
\ingroup qtopiaemb
*/
/*!
\fn Resource::Resource()
\internal
*/
/*!
Returns the QPixmap called \a pix. You should avoid including
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;
}
/*!
Returns the QBitmap called \a pix. You should avoid including
any filename type extension (e.g. .png, .xpm).
*/
QBitmap Resource::loadBitmap( const QString &pix )
{
QBitmap bm;
bm = loadPixmap(pix);
return bm;
@@ -92,25 +98,24 @@ QString Resource::findPixmap( const QString &pix )
QString picsPath = QPEApplication::qpeDir() + "pics/";
QString f;
// Common case optimizations...
f = picsPath + pix + ".png";
if ( QFile( f ).exists() )
return f;
f = picsPath + pix + ".xpm";
if ( QFile( f ).exists() )
return f;
-
// All formats...
QStrList fileFormats = QImageIO::inputFormats();
QString ff = fileFormats.first();
while ( fileFormats.current() ) {
QStringList exts = MimeType("image/"+ff.lower()).extensions();
for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
QString f = picsPath + pix + "." + *it;
if ( QFile(f).exists() )
return f;
}
ff = fileFormats.next();
}