more flexible handling of paths
This commit is contained in:
@ -213,10 +213,62 @@ bool PAdminXMLParser::characters(const QString& str)
|
||||
bool PAdminXMLParser::endDocument()
|
||||
{
|
||||
// check if all necessary items are found
|
||||
QString str;
|
||||
|
||||
if (fAdmin->getExecPath().find('$') >= 0) {
|
||||
str = expandPath(fAdmin->getExecPath());
|
||||
if (!str.isEmpty())
|
||||
fAdmin->setExecPath(str);
|
||||
}
|
||||
|
||||
if (fAdmin->getDefaultSavePath().find('$') >= 0) {
|
||||
str = expandPath(fAdmin->getDefaultSavePath());
|
||||
if (!str.isEmpty())
|
||||
fAdmin->setDefaultSavePath(str);
|
||||
}
|
||||
|
||||
if (fAdmin->getMsrDefaultFilePath().find('$') >= 0) {
|
||||
expandPath(fAdmin->getMsrDefaultFilePath());
|
||||
if (!str.isEmpty())
|
||||
fAdmin->setMsrDefaultFilePath(str);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Called at the end of the XML parse process.
|
||||
*/
|
||||
QString PAdminXMLParser::expandPath(const QString &str)
|
||||
{
|
||||
QString token;
|
||||
QString path;
|
||||
QString msg;
|
||||
QString newStr="";
|
||||
|
||||
QStringList list = QStringList::split("/", str);
|
||||
|
||||
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
|
||||
token = *it;
|
||||
if (token.contains("$")) {
|
||||
token.remove('$');
|
||||
path = std::getenv(token.latin1());
|
||||
if (path.isEmpty()) {
|
||||
msg = QString("Couldn't expand '%1'. Some things might not work properly").arg(token);
|
||||
QMessageBox::warning(0, "**WARNING**", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
newStr = "";
|
||||
break;
|
||||
}
|
||||
newStr += "/" + path;
|
||||
} else {
|
||||
newStr += "/" + token;
|
||||
}
|
||||
}
|
||||
|
||||
return newStr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// implementation of PAdmin class
|
||||
//--------------------------------------------------------------------------
|
||||
|
@ -69,6 +69,8 @@ class PAdminXMLParser : public QXmlDefaultHandler
|
||||
bool characters(const QString&);
|
||||
bool endDocument();
|
||||
|
||||
QString expandPath(const QString&);
|
||||
|
||||
EAdminKeyWords fKeyWord;
|
||||
bool fFunc;
|
||||
PTheory fTheoryItem;
|
||||
|
@ -5,9 +5,9 @@
|
||||
This is handling default setting parameters for the musrgui.
|
||||
</comment>
|
||||
<general>
|
||||
<exec_path>/home/nemu/analysis/bin</exec_path>
|
||||
<exec_path>$HOME/analysis/bin</exec_path>
|
||||
<default_save_path>./</default_save_path>
|
||||
<msr_default_file_path>/home/nemu/analysis/musrfit/src/musrgui</msr_default_file_path>
|
||||
<msr_default_file_path>$HOME/analysis/musrfit/src/musrgui</msr_default_file_path>
|
||||
</general>
|
||||
<msr_file_defaults>
|
||||
<beamline>mue4</beamline>
|
||||
@ -170,6 +170,6 @@
|
||||
<pixmap></pixmap>
|
||||
<params>0</params>
|
||||
</func>
|
||||
</theory_function>
|
||||
</theory_functions>
|
||||
</musrgui_startup>
|
||||
|
||||
|
Reference in New Issue
Block a user