Am 29.03.10 22:26 schrieb(en) Oliver Eichler:
Not being a c++ expert, there is one thing which confused me: is the method run 
in COsmTilesHashCacheCleanup unused?  I changed the prototype, but noone 
complained...

Ah, that won't work. See, the run() method is the thread that is triggered by 
start(). Thus if you change API the default implementation of run() is started 
instead of your run(QString &forFolder). But as everything is within one class, 
and there is no concurrent read/write access to the folder string, it should be ok 
to share it as member variable, without further serialization.

Ooooops - as I said, I actually have no idea of c++ programming :-(  Sorry!

A new patch is attached, using a static class member and an accessor function 
instead.  Hope this solution is ok?  At least I always see the right path 
everywhere in gdb...

BTW, I noticed that Ubuntu purges the tmp folder upon each reboot.  Thus, it 
may be desirable to put the cache somewhere else.  The new patch now checks for 
an environment variable QLGT_CACHE, and if it is found, that location is used 
as cache folder.

Opinions?

Cheers, Albrecht.
Index: src/COsmTilesHash.cpp
===================================================================
--- src/COsmTilesHash.cpp	(Revision 2041)
+++ src/COsmTilesHash.cpp	(Arbeitskopie)
@@ -22,10 +22,19 @@
 #include <QtGui>
 #include <QtNetwork/QHttp>
 
+#ifndef Q_OS_WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <pwd.h>
+#include <unistd.h>
+#endif
+
 #ifndef M_PI
 # define M_PI   3.14159265358979323846
 #endif
 
+QString COsmTilesHash::cacheFolder = 0;
+
 class COsmTilesHashCacheCleanup: public QThread
 {
     public:
@@ -46,11 +55,9 @@ class COsmTilesHashCacheCleanup: public QThread
 
         void run()
         {
-            QString tempDir = QDir::tempPath() + "/qlandkarteqt/cache/";
-
             qint32 totalSize = 0;
             QFileInfoList fileList;
-            QDirIterator it(tempDir, QStringList("*.png"), QDir::Files | QDir::Writable, QDirIterator::Subdirectories);
+            QDirIterator it(COsmTilesHash::getCacheFolder(), QStringList("*.png"), QDir::Files | QDir::Writable, QDirIterator::Subdirectories);
             while (it.hasNext())
             {
                 it.next();
@@ -81,6 +88,23 @@ class COsmTilesHashCacheCleanup: public QThread
 
 COsmTilesHash::COsmTilesHash(QString tileUrl)
 {
+    if (cacheFolder == 0) {
+#ifndef Q_OS_WIN32
+        const char *envCache = getenv("QLGT_CACHE");
+
+        if (envCache)
+            cacheFolder = envCache;
+        else {
+            struct passwd * userInfo = getpwuid(getuid());
+                        
+            cacheFolder = QDir::tempPath() + "/qlandkarteqt-" + userInfo->pw_name + "/cache/";
+        }
+#else
+        cacheFolder = QDir::tempPath() + "/qlandkarteqt/cache/";
+#endif
+        qDebug() << "using OSM tile cache folder" << cacheFolder;
+    }
+
     qDebug() << "cccccccccccc" << tileUrl;
     int index = tileUrl.indexOf('/');
     tileServer = tileUrl.left(index);
@@ -178,7 +202,7 @@ void COsmTilesHash::getImage(int osm_zoom, int osm
     // * Each zoom level is a directory, each column is a subdirectory, and each tile in that column is a file
     // * Filename(url) format is /zoom/x/y.png
     QString osmUrlPart = QString(tileUrlPart).arg(osm_zoom).arg(osm_x).arg(osm_y);
-    QString osmFilePath = QString("%1/qlandkarteqt/cache/%2/%3").arg(QDir::tempPath()).arg(tileServer).arg(osmUrlPart);
+    QString osmFilePath = QString("%1/%2/%3").arg(cacheFolder).arg(tileServer).arg(osmUrlPart);
 //    qDebug() << osmUrlPart;
 //    qDebug() << osmFilePath;
     bool needHttpAction = true;
@@ -259,13 +283,20 @@ void COsmTilesHash::slotRequestFinished(int id, bo
     }
     QString osmUrlPart = osmUrlPartHash.value(id);
 
-    QString filePath = QString("%1/qlandkarteqt/cache/%2/%3").arg(QDir::tempPath()).arg(tileServer).arg(osmUrlPart);
+    QString filePath = QString("%1/%2/%3").arg(cacheFolder).arg(tileServer).arg(osmUrlPart);
 
     //qDebug() << filePath;
     QFileInfo fi(filePath);
 
-    if( ! (fi.dir().exists()) )
+    if( ! (fi.dir().exists()) ) {
+#ifndef Q_OS_WIN32
+        mode_t mask = umask(S_IRWXG | S_IRWXO);
+#endif
         QDir().mkpath(fi.dir().path());
+#ifndef Q_OS_WIN32
+        umask(mask);
+#endif
+    }
 
     QFile f(filePath);
     if (f.open(QIODevice::WriteOnly))
Index: src/COsmTilesHash.h
===================================================================
--- src/COsmTilesHash.h	(Revision 2041)
+++ src/COsmTilesHash.h	(Arbeitskopie)
@@ -32,6 +32,7 @@ class COsmTilesHash: public QObject
         COsmTilesHash(QString tileUrl);
         virtual ~COsmTilesHash();
         void startNewDrawing( double lon, double lat, int osm_zoom, const QRect& window);
+        static const QString &getCacheFolder(void) { return cacheFolder; };
         signals:
         void newImageReady(QImage image, bool lastTileLoaded);
     private:
@@ -54,6 +55,7 @@ class COsmTilesHash: public QObject
         bool requestInProgress;
         QHash<QString,QImage> tiles;
         int getid;
+        static QString cacheFolder;
     private slots:
         // void slotCreate();
         void slotRequestFinished(int , bool error);

Attachment: pgpqLexZn6CQ2.pgp
Description: PGP signature

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
QLandkarte-users mailing list
QLandkarte-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qlandkarte-users

Reply via email to