summaryrefslogtreecommitdiffstats
path: root/kuickshow/src/filecache.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kuickshow/src/filecache.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kuickshow/src/filecache.cpp')
-rw-r--r--kuickshow/src/filecache.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/kuickshow/src/filecache.cpp b/kuickshow/src/filecache.cpp
new file mode 100644
index 00000000..c1c1affe
--- /dev/null
+++ b/kuickshow/src/filecache.cpp
@@ -0,0 +1,83 @@
+#include <unistd.h>
+
+#include <qstring.h>
+
+#include <kdebug.h>
+#include <kstandarddirs.h>
+#include <ktempdir.h>
+
+#include "filecache.h"
+
+FileCache * FileCache::s_self;
+
+FileCache::FileCache()
+ : m_limit( 0 ),
+ m_tempDir( 0L )
+{
+ m_files.setAutoDelete( true );
+ m_files.setMaxCost( 100 ); // good default? ### make configurable?
+}
+
+FileCache::~FileCache()
+{
+ delete m_tempDir;
+}
+
+void FileCache::shutdown()
+{
+ if ( s_self )
+ {
+ delete s_self;
+ s_self = 0L;
+ }
+}
+
+FileCache * FileCache::self()
+{
+ if ( !s_self )
+ s_self = new FileCache();
+ return s_self;
+}
+
+KuickFile * FileCache::getFile( const KURL& url )
+{
+ QString urlString = url.prettyURL();
+ KuickFile *file = m_files.find( urlString );
+ if ( !file ) {
+ file = new KuickFile( url );
+ m_files.insert( urlString, file );
+ }
+
+ return file;
+}
+
+QString FileCache::tempDir()
+{
+ if ( !m_tempDir ) {
+ m_tempDir = createTempDir();
+
+ if ( !m_tempDir ) {
+ kdWarning() << "Unable to create temporary directory for KuickShow" << endl;
+ return QString::null;
+ }
+ }
+
+ return m_tempDir->name();
+}
+
+
+KTempDir * FileCache::createTempDir()
+{
+ QString tmpName = QString::fromLatin1( KGlobal::instance()->instanceName() );
+ tmpName.append( QString::number( getpid() ) );
+ QString dirName = locateLocal( "tmp", tmpName );
+ KTempDir *dir = new KTempDir( dirName );
+ dir->setAutoDelete( true );
+ if ( dir->status() != 0L )
+ {
+ delete dir;
+ return 0L;
+ }
+
+ return dir;
+}