1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

OP-153 Implemented a default storage path: "OpenPilot" in the user's home directory. OPMap will use this as its default path for its mapscache.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1661 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-09-16 17:17:42 +00:00 committed by edouard
parent 3b015b41c5
commit 9a31fea559
4 changed files with 57 additions and 7 deletions

View File

@ -90,4 +90,50 @@ QString PathUtils::InsertDataPath(QString path)
return QDir::toNativeSeparators(path);
}
/**
Gets a standard user-writable location for the system
*/
QString PathUtils::GetStoragePath()
{
// This routine works with "/" as the standard:
// Figure out root: Up one from 'bin'
const QString homeDirPath = QDir::home().canonicalPath();
QString storagePath = homeDirPath;
storagePath += QLatin1Char('/');
storagePath += QLatin1String("OpenPilot");
storagePath += QLatin1Char('/');
return storagePath;
}
/**
Removes the standard storage path and replace with a tag
*/
QString PathUtils::RemoveStoragePath(QString path)
{
// Depending on the platform, we might get either "/" or "\"
// so we need to go to the standard ("/")
QString goodPath = QDir::fromNativeSeparators(path);
if (goodPath.startsWith(GetStoragePath())) {
int i = goodPath.length()- GetStoragePath().length();
return QString("%%STOREPATH%%") + goodPath.right(i);
} else
return goodPath;
}
/**
Inserts the standard storage path is there is a storage path tag
*/
QString PathUtils::InsertStoragePath(QString path)
{
if (path.startsWith(QString("%%STOREPATH%%")))
{
QString newPath = GetStoragePath();
newPath += path.right(path.length()-13);
return QDir::toNativeSeparators(newPath);
}
return QDir::toNativeSeparators(path);
}
}

View File

@ -44,6 +44,10 @@ public:
QString RemoveDataPath(QString path);
QString InsertDataPath(QString path);
QString GetStoragePath();
QString RemoveStoragePath(QString path);
QString InsertStoragePath(QString path);
};
}

View File

@ -41,7 +41,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, const QByteA
m_showTileGridLines(false),
m_accessMode("ServerAndCache"),
m_useMemoryCache(true),
m_cacheLocation(QDir::currentPath() + QDir::separator() + "mapscache" + QDir::separator())
m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator())
{
if (state.count() > 0)
{
@ -76,7 +76,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, const QByteA
if (!accessMode.isEmpty()) m_accessMode = accessMode;
m_useMemoryCache = useMemoryCache;
if (!cacheLocation.isEmpty()) m_cacheLocation = Utils::PathUtils().InsertDataPath(cacheLocation);
if (!cacheLocation.isEmpty()) m_cacheLocation = Utils::PathUtils().InsertStoragePath(cacheLocation);
}
}
@ -90,7 +90,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings*
m_showTileGridLines(false),
m_accessMode("ServerAndCache"),
m_useMemoryCache(true),
m_cacheLocation(QDir::currentPath() + QDir::separator() + "mapscache" + QDir::separator())
m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator())
{
//if a saved configuration exists load it
@ -114,7 +114,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings*
if (!accessMode.isEmpty()) m_accessMode = accessMode;
m_useMemoryCache = useMemoryCache;
if (!cacheLocation.isEmpty()) m_cacheLocation = Utils::PathUtils().InsertDataPath(cacheLocation);
if (!cacheLocation.isEmpty()) m_cacheLocation = Utils::PathUtils().InsertStoragePath(cacheLocation);
}
}
@ -144,5 +144,5 @@ void OPMapGadgetConfiguration::saveConfig(QSettings* qSettings) const {
qSettings->setValue("showTileGridLines", m_showTileGridLines);
qSettings->setValue("accessMode", m_accessMode);
qSettings->setValue("useMemoryCache", m_useMemoryCache);
qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveDataPath(m_cacheLocation));
qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation));
}

View File

@ -36,7 +36,7 @@
#include <QtGui/QFileDialog>
#include "opmapcontrol/opmapcontrol.h"
#include "utils/pathutils.h"
#include "ui_opmapgadgetoptionspage.h"
// *********************************************
@ -95,7 +95,7 @@ void OPMapGadgetOptionsPage::on_pushButtonCacheDefaults_clicked()
m_page->checkBoxUseMemoryCache->setChecked(true);
m_page->lineEditCacheLocation->setPath(QDir::currentPath() + QDir::separator() + "mapscache" + QDir::separator());
m_page->lineEditCacheLocation->setPath(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator());
}