mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-01 18:29:16 +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:
parent
3b015b41c5
commit
9a31fea559
@ -90,4 +90,50 @@ QString PathUtils::InsertDataPath(QString path)
|
|||||||
return QDir::toNativeSeparators(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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ public:
|
|||||||
QString RemoveDataPath(QString path);
|
QString RemoveDataPath(QString path);
|
||||||
QString InsertDataPath(QString path);
|
QString InsertDataPath(QString path);
|
||||||
|
|
||||||
|
QString GetStoragePath();
|
||||||
|
QString RemoveStoragePath(QString path);
|
||||||
|
QString InsertStoragePath(QString path);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, const QByteA
|
|||||||
m_showTileGridLines(false),
|
m_showTileGridLines(false),
|
||||||
m_accessMode("ServerAndCache"),
|
m_accessMode("ServerAndCache"),
|
||||||
m_useMemoryCache(true),
|
m_useMemoryCache(true),
|
||||||
m_cacheLocation(QDir::currentPath() + QDir::separator() + "mapscache" + QDir::separator())
|
m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator())
|
||||||
{
|
{
|
||||||
if (state.count() > 0)
|
if (state.count() > 0)
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, const QByteA
|
|||||||
|
|
||||||
if (!accessMode.isEmpty()) m_accessMode = accessMode;
|
if (!accessMode.isEmpty()) m_accessMode = accessMode;
|
||||||
m_useMemoryCache = useMemoryCache;
|
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_showTileGridLines(false),
|
||||||
m_accessMode("ServerAndCache"),
|
m_accessMode("ServerAndCache"),
|
||||||
m_useMemoryCache(true),
|
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
|
//if a saved configuration exists load it
|
||||||
@ -114,7 +114,7 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings*
|
|||||||
|
|
||||||
if (!accessMode.isEmpty()) m_accessMode = accessMode;
|
if (!accessMode.isEmpty()) m_accessMode = accessMode;
|
||||||
m_useMemoryCache = useMemoryCache;
|
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("showTileGridLines", m_showTileGridLines);
|
||||||
qSettings->setValue("accessMode", m_accessMode);
|
qSettings->setValue("accessMode", m_accessMode);
|
||||||
qSettings->setValue("useMemoryCache", m_useMemoryCache);
|
qSettings->setValue("useMemoryCache", m_useMemoryCache);
|
||||||
qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveDataPath(m_cacheLocation));
|
qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation));
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
|
|
||||||
#include "opmapcontrol/opmapcontrol.h"
|
#include "opmapcontrol/opmapcontrol.h"
|
||||||
|
#include "utils/pathutils.h"
|
||||||
#include "ui_opmapgadgetoptionspage.h"
|
#include "ui_opmapgadgetoptionspage.h"
|
||||||
|
|
||||||
// *********************************************
|
// *********************************************
|
||||||
@ -95,7 +95,7 @@ void OPMapGadgetOptionsPage::on_pushButtonCacheDefaults_clicked()
|
|||||||
|
|
||||||
m_page->checkBoxUseMemoryCache->setChecked(true);
|
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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user