1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-05 21:52:10 +01:00

OP309/OP179/GCS - Fixes maps cache location not being selectable, now defaults to "C:\Users\name_of_user\AppData\Roaming\OpenPilot\mapscache" on windows, no idea where this goes on nix.

Also tried to fix crashes seen on Mac, but I'll need a Mac or a stack trace to do a better job.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3106 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2011-03-30 15:57:53 +00:00 committed by zedamota
parent b125e51251
commit 282661734e
8 changed files with 621 additions and 610 deletions

View File

@ -25,7 +25,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "cache.h" #include "cache.h"
#include <QSettings>
namespace core { namespace core {
Cache* Cache::m_pInstance=0; Cache* Cache::m_pInstance=0;
@ -53,7 +53,11 @@ namespace core {
{ {
if(cache.isNull()|cache.isEmpty()) if(cache.isNull()|cache.isEmpty())
{ {
cache=QDir::currentPath()+QDir::separator()+"mapscache"+QDir::separator(); QSettings set(QSettings::IniFormat, QSettings::UserScope,QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
QDir dir(set.fileName());
QFileInfo f(dir.absolutePath());
f.dir().absolutePath();
cache=f.dir().absolutePath()+QDir::separator()+"mapscache"+QDir::separator();
setCacheLocation(cache); setCacheLocation(cache);
} }
} }

View File

@ -26,36 +26,19 @@
*/ */
#include "pureimagecache.h" #include "pureimagecache.h"
#include <QDateTime> #include <QDateTime>
#include <QSettings>
//#define DEBUG_PUREIMAGECACHE //#define DEBUG_PUREIMAGECACHE
namespace core { namespace core {
qlonglong PureImageCache::ConnCounter=0; qlonglong PureImageCache::ConnCounter=0;
PureImageCache::PureImageCache() PureImageCache::PureImageCache()
{ {
gtilecache=QDir::currentPath()+QDir::separator()+"mapscache"+QDir::separator();
QDir d;
if(!d.exists(gtilecache))
{
d.mkdir(gtilecache);
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create Cache directory";
#endif //DEBUG_PUREIMAGECACHE
}
{
QString db=gtilecache+"Data.qmdb";
if(!QFileInfo(db).exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Try to create EmptyDB";
#endif //DEBUG_PUREIMAGECACHE
CreateEmptyDB(db);
}
}
} }
void PureImageCache::setGtileCache(const QString &value) void PureImageCache::setGtileCache(const QString &value)
{ {
lock.lockForWrite();
gtilecache=value; gtilecache=value;
QDir d; QDir d;
if(!d.exists(gtilecache)) if(!d.exists(gtilecache))
@ -75,6 +58,7 @@ namespace core {
CreateEmptyDB(db); CreateEmptyDB(db);
} }
} }
lock.unlock();
} }
QString PureImageCache::GtileCache() QString PureImageCache::GtileCache()
{ {
@ -187,6 +171,9 @@ namespace core {
} }
bool PureImageCache::PutImageToCache(const QByteArray &tile, const MapType::Types &type,const Point &pos,const int &zoom) bool PureImageCache::PutImageToCache(const QByteArray &tile, const MapType::Types &type,const Point &pos,const int &zoom)
{ {
if(gtilecache.isEmpty()|gtilecache.isNull())
return false;
lock.lockForRead();
#ifdef DEBUG_PUREIMAGECACHE #ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"PutImageToCache Start:";//<<pos; qDebug()<<"PutImageToCache Start:";//<<pos;
#endif //DEBUG_PUREIMAGECACHE #endif //DEBUG_PUREIMAGECACHE
@ -222,11 +209,15 @@ namespace core {
} }
} }
QSqlDatabase::removeDatabase(QString::number(id)); QSqlDatabase::removeDatabase(QString::number(id));
lock.unlock();
return true; return true;
} }
QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int zoom) QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int zoom)
{ {
lock.lockForRead();
QByteArray ar; QByteArray ar;
if(gtilecache.isEmpty()|gtilecache.isNull())
return ar;
QString dir=gtilecache; QString dir=gtilecache;
Mcounter.lock(); Mcounter.lock();
qlonglong id=++ConnCounter; qlonglong id=++ConnCounter;
@ -260,10 +251,13 @@ namespace core {
} }
} }
QSqlDatabase::removeDatabase(QString::number(id)); QSqlDatabase::removeDatabase(QString::number(id));
lock.unlock();
return ar; return ar;
} }
void PureImageCache::deleteOlderTiles(int const& days) void PureImageCache::deleteOlderTiles(int const& days)
{ {
if(gtilecache.isEmpty()|gtilecache.isNull())
return;
QList<long> add; QList<long> add;
bool ret=true; bool ret=true;
QString dir=gtilecache; QString dir=gtilecache;

View File

@ -41,7 +41,7 @@
#include "pureimage.h" #include "pureimage.h"
#include <QList> #include <QList>
#include <QMutex> #include <QMutex>
#include <QReadWriteLock>
namespace core { namespace core {
class PureImageCache class PureImageCache
{ {
@ -58,6 +58,7 @@ namespace core {
private: private:
QString gtilecache; QString gtilecache;
QMutex Mcounter; QMutex Mcounter;
QReadWriteLock lock;
static qlonglong ConnCounter; static qlonglong ConnCounter;
}; };

View File

@ -80,7 +80,6 @@ namespace core {
void UrlFactory::setIsCorrectGoogleVersions(bool value) void UrlFactory::setIsCorrectGoogleVersions(bool value)
{ {
isCorrectedGoogleVersions=value; isCorrectedGoogleVersions=value;
} }
bool UrlFactory::IsCorrectGoogleVersions() bool UrlFactory::IsCorrectGoogleVersions()
@ -90,6 +89,7 @@ namespace core {
void UrlFactory::TryCorrectGoogleVersions() void UrlFactory::TryCorrectGoogleVersions()
{ {
QMutexLocker locker(&mutex);
if(CorrectGoogleVersions && !IsCorrectGoogleVersions()) if(CorrectGoogleVersions && !IsCorrectGoogleVersions())
{ {
QNetworkReply *reply; QNetworkReply *reply;

View File

@ -71,6 +71,7 @@ namespace core {
bool UsePlacemarkCache;//TODO GetSet bool UsePlacemarkCache;//TODO GetSet
static const double EarthRadiusKm; static const double EarthRadiusKm;
double GetDistance(internals::PointLatLng p1,internals::PointLatLng p2); double GetDistance(internals::PointLatLng p1,internals::PointLatLng p2);
QMutex mutex;
protected: protected:
static short timelapse; static short timelapse;

View File

@ -41,6 +41,11 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings*
m_useMemoryCache(true), m_useMemoryCache(true),
m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator()) m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator())
{ {
QSettings set(QSettings::IniFormat, QSettings::UserScope,QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
QDir dir(set.fileName());
QFileInfo f(dir.absolutePath());
f.dir().absolutePath();
m_cacheLocation=f.dir().absolutePath()+QDir::separator() + "mapscache" + QDir::separator();
//if a saved configuration exists load it //if a saved configuration exists load it
if(qSettings != 0) { if(qSettings != 0) {
@ -95,3 +100,6 @@ void OPMapGadgetConfiguration::saveConfig(QSettings* qSettings) const {
qSettings->setValue("useMemoryCache", m_useMemoryCache); qSettings->setValue("useMemoryCache", m_useMemoryCache);
qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation)); qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation));
} }
void OPMapGadgetConfiguration::setCacheLocation(QString cacheLocation){
m_cacheLocation = cacheLocation;
}

View File

@ -72,7 +72,7 @@ public slots:
void setShowTileGridLines(bool showTileGridLines) { m_showTileGridLines = showTileGridLines; } void setShowTileGridLines(bool showTileGridLines) { m_showTileGridLines = showTileGridLines; }
void setAccessMode(QString accessMode) { m_accessMode = accessMode; } void setAccessMode(QString accessMode) { m_accessMode = accessMode; }
void setUseMemoryCache(bool useMemoryCache) { m_useMemoryCache = useMemoryCache; } void setUseMemoryCache(bool useMemoryCache) { m_useMemoryCache = useMemoryCache; }
void setCacheLocation(QString cacheLocation) { m_cacheLocation = cacheLocation; } void setCacheLocation(QString cacheLocation);
private: private:
QString m_mapProvider; QString m_mapProvider;

View File

@ -94,8 +94,11 @@ void OPMapGadgetOptionsPage::on_pushButtonCacheDefaults_clicked()
m_page->accessModeComboBox->setCurrentIndex(index); m_page->accessModeComboBox->setCurrentIndex(index);
m_page->checkBoxUseMemoryCache->setChecked(true); m_page->checkBoxUseMemoryCache->setChecked(true);
QSettings set(QSettings::IniFormat, QSettings::UserScope,QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
m_page->lineEditCacheLocation->setPath(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator()); QDir dir(set.fileName());
QFileInfo f(dir.absolutePath());
f.dir().absolutePath();
m_page->lineEditCacheLocation->setPath(f.dir().absolutePath()+QDir::separator() + "mapscache" + QDir::separator());
} }