[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/graphics/gwenview
From: Aurélien Gâteau <aurelien.gateau () free ! fr>
Date: 2006-10-07 20:29:30
Message-ID: 1160252970.099569.24847.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 593428 by gateau:
Use KStaticDeleter to implement Cache singleton.
M +0 -1 app/main.cpp
M +15 -17 gvcore/cache.cpp
M +1 -4 gvcore/cache.h
M +0 -3 gvdirpart/gvdirpart.cpp
M +0 -3 gvimagepart/gvimagepart.cpp
--- trunk/extragear/graphics/gwenview/app/main.cpp #593427:593428
@@ -157,7 +157,6 @@
mainWindow->show();
}
- Cache::instance()->ref();
return kapplication.exec();
}
--- trunk/extragear/graphics/gwenview/gvcore/cache.cpp #593427:593428
@@ -27,6 +27,7 @@
#include <kconfig.h>
#include <kdebug.h>
#include <kdeversion.h>
+#include <kstaticdeleter.h>
#include <kio/global.h>
#include "cache.moc"
@@ -51,14 +52,24 @@
Cache::Cache()
: mMaxSize( DEFAULT_MAXSIZE )
, mThumbnailSize( 0 ) // don't remember size for every thumbnail, but have one \
global and dump all if needed
-, mUsageRefcount( 0 )
{
- connect( &mCleanupTimer, SIGNAL( timeout()), SLOT( cleanupTimeout()));
}
+
+Cache::~Cache() {
+ mImages.clear();
+}
+
+
+static Cache* sCache;
+static KStaticDeleter<Cache> sCacheDeleter;
+
+
Cache* Cache::instance() {
- static Cache manager;
- return &manager;
+ if (!sCache) {
+ sCacheDeleter.setObject(sCache, new Cache());
+ }
+ return sCache;
}
// Priority URLs are used e.g. when prefetching for the slideshow - after an image \
is prefetched, @@ -260,19 +271,6 @@
checkMaxSize();
}
-void Cache::ref() {
- ++mUsageRefcount;
- mCleanupTimer.stop();
-}
-
-void Cache::deref() {
- if( --mUsageRefcount == 0 ) mCleanupTimer.start( 60000, true );
-}
-
-void Cache::cleanupTimeout() {
- mImages.clear();
-}
-
Cache::ImageData::ImageData( const KURL& url, const QByteArray& f, const QDateTime& \
t ) : file( f )
, timestamp( t )
--- trunk/extragear/graphics/gwenview/gvcore/cache.h #593427:593428
@@ -42,6 +42,7 @@
Q_OBJECT
public:
static Cache* instance();
+ ~Cache();
void addImage( const KURL& url, const ImageFrames& frames, const QCString& format, \
const QDateTime& timestamp ); void addFile( const KURL& url, const QByteArray& file, \
const QDateTime& timestamp ); void addThumbnail( const KURL& url, const QPixmap& \
thumbnail, QSize imagesize, const QDateTime& timestamp ); @@ -89,11 +90,7 @@
QMap< KURL, ImageData > mImages;
int mMaxSize;
int mThumbnailSize;
- int mUsageRefcount;
- QTimer mCleanupTimer;
QValueList< KURL > mPriorityURLs;
-private slots:
- void cleanupTimeout();
};
} // namespace
--- trunk/extragear/graphics/gwenview/gvdirpart/gvdirpart.cpp #593427:593428
@@ -65,8 +65,6 @@
setInstance( GVDirFactory::instance() );
KGlobal::locale()->insertCatalogue( "gwenview" );
- Cache::instance()->ref();
-
mBrowserExtension = new GVDirPartBrowserExtension(this);
mSplitter = new QSplitter(Qt::Horizontal, parentWidget, "gwenview-kpart-splitter");
@@ -128,7 +126,6 @@
GVDirPartConfig::setFileViewWidth(mFileViewController->width());
GVDirPartConfig::writeConfig();
delete mSlideShow;
- Cache::instance()->deref();
}
--- trunk/extragear/graphics/gwenview/gvimagepart/gvimagepart.cpp #593427:593428
@@ -67,8 +67,6 @@
setInstance( GVImageFactory::instance() );
KGlobal::locale()->insertCatalogue( "gwenview" );
- Cache::instance()->ref();
-
mBrowserExtension = new GVImagePartBrowserExtension(this);
// Create the widgets
@@ -106,7 +104,6 @@
}
GVImagePart::~GVImagePart() {
- Cache::instance()->deref();
delete mDirLister;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic