[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kpat/libkcardgame
From:       Parker Coates <parker.coates () kdemail ! net>
Date:       2010-09-21 0:10:40
Message-ID: 20100921001040.36D43AC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1177709 by coates:

Use a single dedicated KImageCache for storing card deck previews.

This is simpler, cleaner, and more efficient. I'm not sure why I didn't
do this in the original KImageCache port.

 M  +19 -9     kcardthemewidget.cpp  
 M  +3 -1      kcardthemewidget_p.h  


--- trunk/KDE/kdegames/kpat/libkcardgame/kcardthemewidget.cpp #1177708:1177709
@@ -44,10 +44,18 @@
 
 namespace
 {
-    const QString previewKeyTemplate( "preview_%1" );
+    inline QString timestampKey( const KCardTheme & theme )
+    {
+        return theme.dirName() + "_timestamp";
 }
 
+    inline QString previewKey( const KCardTheme & theme, const QString & previewString )
+    {
+        return theme.dirName() + '_' + previewString;
+    }
+}
 
+
 PreviewThread::PreviewThread( const KCardThemeWidgetPrivate * d, const QList<KCardTheme> & themes )
   : d( d ),
     m_themes( themes ),
@@ -149,10 +157,11 @@
         if ( !theme.isValid() )
             continue;
 
-        QScopedPointer<KImageCache> cache( createCache( theme ) );
         QPixmap * pix = new QPixmap();
-        QString key = previewKeyTemplate.arg( d->previewString );
-        if ( cache->findPixmap( key, pix ) )
+        QDateTime timestamp;
+        if ( cacheFind( d->cache, timestampKey( theme ), &timestamp )
+             && timestamp >= theme.lastModified() 
+             && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) )
         {
             m_previews.insert( theme.displayName(), pix );
         }
@@ -192,13 +201,10 @@
 
 void CardThemeModel::submitPreview( const KCardTheme & theme, const QImage & image )
 {
-    QScopedPointer<KImageCache> cache( createCache( theme ) );
+    d->cache->insertImage( previewKey( theme, d->previewString ), image );
+    cacheInsert( d->cache, timestampKey( theme ), theme.lastModified() );
 
     QPixmap * pix = new QPixmap( QPixmap::fromImage( image ) );
-
-    QString key = previewKeyTemplate.arg( d->previewString );
-    cache->insertPixmap( key, *pix );
-
     delete m_previews.value( theme.displayName(), 0 );
     m_previews.insert( theme.displayName(), pix );
 
@@ -344,6 +350,10 @@
   : QWidget( parent ),
     d( new KCardThemeWidgetPrivate( this ) )
 {
+    d->cache = new KImageCache( "libkcardgame-themes/previews", 1 * 1024 * 1024 );
+    d->cache->setPixmapCaching( false );
+    d->cache->setEvictionPolicy( KSharedDataCache::EvictOldest );
+
     d->requiredFeatures = requiredFeatures;
     d->previewString = previewString;
 
--- trunk/KDE/kdegames/kpat/libkcardgame/kcardthemewidget_p.h #1177708:1177709
@@ -24,8 +24,8 @@
 
 #include "kcardtheme.h"
 
+class KImageCache;
 class KLineEdit;
-class KPixmapCache;
 class KPushButton;
 
 #include <QtCore/QAbstractItemModel>
@@ -111,6 +111,8 @@
 public:
     KCardThemeWidget * q;
 
+    KImageCache * cache;
+
     CardThemeModel * model;
     QListView * listView;
     KLineEdit * hiddenLineEdit;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic