[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-03 21:39:18
Message-ID: 20100903213918.B25EFAC888 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1171458 by coates:
Create a common.cpp file to hold cache related functions.
Other common functions and/or constants will be moved there in the future.
* createCache() is a function for creating KImageCache objects, to
guarantee that all uses of KImageCache in LibKCardGame are consistent.
This will be useful mostly when porting KCardThemeWidget to KImageCache.
* cacheFind() is a template function that allows one to extract any
type from a KSharedDataCache provided it has an operator<< method for
QDataStream.
* cacheInsert() is a template function that allows one to insert any
type into a KSharedDataCache provided it has a operator>> method for
QDataStream.
M +1 -0 CMakeLists.txt
A common.cpp [License: GPL (v2+)]
A common.h [License: GPL (v2+)]
M +7 -48 kabstractcarddeck.cpp
--- trunk/KDE/kdegames/kpat/libkcardgame/CMakeLists.txt #1171457:1171458
@@ -1,4 +1,5 @@
set( libkcardgame_SRCS
+ common.cpp
kabstractcarddeck.cpp
kcard.cpp
kcardpile.cpp
--- trunk/KDE/kdegames/kpat/libkcardgame/kabstractcarddeck.cpp #1171457:1171458
@@ -21,6 +21,7 @@
#include "kabstractcarddeck_p.h"
+#include "common.h"
#include "kcardtheme.h"
#include "kcardpile.h"
#include "shuffle.h"
@@ -33,10 +34,9 @@
#include <QtGui/QPainter>
#include <QtSvg/QSvgRenderer>
+
namespace
{
- const QString cacheNameTemplate( "libkcardgame-themes/%1" );
- const QString timeStampKey( "libkcardgame_timestamp" );
const QString unscaledSizeKey( "libkcardgame_unscaledsize" );
const QString lastUsedSizeKey( "libkcardgame_lastusedsize" );
@@ -188,24 +188,13 @@
if ( !theme.isValid() )
return size;
-
- QByteArray buffer;
- if ( cache->find( unscaledSizeKey, &buffer ) )
+ if ( !cacheFind( cache, unscaledSizeKey, &size ) )
{
- QDataStream stream( &buffer, QIODevice::ReadOnly );
- stream >> size;
- }
- else
{
- {
QMutexLocker l( &rendererMutex );
size = renderer()->boundsOnElement( "back" ).size();
}
-
- buffer.clear();
- QDataStream stream( &buffer, QIODevice::WriteOnly );
- stream << size;
- cache->insert( unscaledSizeKey, buffer );
+ cacheInsert( cache, unscaledSizeKey, size );
}
return size;
@@ -411,10 +400,7 @@
if ( !d->theme.isValid() )
return;
- QByteArray buffer;
- QDataStream stream( &buffer, QIODevice::WriteOnly );
- stream << d->currentCardSize;
- d->cache->insert( lastUsedSizeKey, buffer );
+ cacheInsert( d->cache, lastUsedSizeKey, d->currentCardSize );
foreach ( KCard * c, d->cards )
{
@@ -470,40 +456,13 @@
}
delete d->cache;
- QString cacheName = QString( cacheNameTemplate ).arg( theme.dirName() );
- d->cache = new KImageCache( cacheName, 3 * 1024 * 1024 );
- d->cache->setPixmapCaching( true );
- d->cache->setEvictionPolicy( KSharedDataCache::EvictLeastRecentlyUsed );
+ d->cache = createCache( d->theme );
- bool keepCache = false;
- QByteArray buffer;
- if ( d->cache->find( timeStampKey, &buffer ) )
- {
- QDataStream stream( &buffer, QIODevice::ReadOnly );
- QDateTime cacheTimeStamp;
- stream >> cacheTimeStamp;
- keepCache = cacheTimeStamp >= theme.lastModified();
- }
-
- if ( !keepCache )
- {
- d->cache->clear();
- buffer.clear();
- QDataStream stream( &buffer, QIODevice::WriteOnly );
- stream << theme.lastModified();
- d->cache->insert( timeStampKey, buffer );
- }
-
d->originalCardSize = d->unscaledCardSize();
Q_ASSERT( !d->originalCardSize.isNull() );
- if ( d->cache->find( lastUsedSizeKey, &buffer ) )
+ if ( !cacheFind( d->cache, lastUsedSizeKey, &(d->currentCardSize) ) )
{
- QDataStream stream( &buffer, QIODevice::ReadOnly );
- stream >> d->currentCardSize;
- }
- else
- {
qreal ratio = d->originalCardSize.height() / d->originalCardSize.width();
d->currentCardSize = QSize( 10, 10 * ratio );
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic