diff --git a/ground/src/libs/utils/pathutils.cpp b/ground/src/libs/utils/pathutils.cpp index ce6322fd0..a4942becf 100644 --- a/ground/src/libs/utils/pathutils.cpp +++ b/ground/src/libs/utils/pathutils.cpp @@ -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); + +} + } diff --git a/ground/src/libs/utils/pathutils.h b/ground/src/libs/utils/pathutils.h index c4646f970..b8e459b85 100644 --- a/ground/src/libs/utils/pathutils.h +++ b/ground/src/libs/utils/pathutils.h @@ -44,6 +44,10 @@ public: QString RemoveDataPath(QString path); QString InsertDataPath(QString path); + QString GetStoragePath(); + QString RemoveStoragePath(QString path); + QString InsertStoragePath(QString path); + }; } diff --git a/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp b/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp index 2805ccdba..45fd4e628 100644 --- a/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp +++ b/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp @@ -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)); } diff --git a/ground/src/plugins/opmap/opmapgadgetoptionspage.cpp b/ground/src/plugins/opmap/opmapgadgetoptionspage.cpp index 7c99df487..f36a4ed90 100644 --- a/ground/src/plugins/opmap/opmapgadgetoptionspage.cpp +++ b/ground/src/plugins/opmap/opmapgadgetoptionspage.cpp @@ -36,7 +36,7 @@ #include #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()); }