48#include <QListWidgetItem>
51#include <QProcessEnvironment>
77 if (!file.open(QFile::ReadOnly | QFile::Text)) {
100 fXml.setDevice(device);
102 bool expectChars =
false;
103 while (!
fXml.atEnd()) {
105 if (
fXml.isStartDocument()) {
107 }
else if (
fXml.isStartElement()) {
110 }
else if (
fXml.isCharacters() && expectChars) {
112 }
else if (
fXml.isEndElement()) {
115 }
else if (
fXml.isEndDocument()) {
119 if (
fXml.hasError()) {
121 msg = QString(
"%1 Line %2, column %3").arg(
fXml.errorString()).arg(
fXml.lineNumber()).arg(
fXml.columnNumber());
122 QMessageBox::critical(
nullptr,
"ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
156 QString qName =
fXml.name().toString();
158 if (qName ==
"data_path") {
193 QString str =
fXml.text().toString();
248 QString path = QString(
"./");
249 QString fln = QString(
"musrfit_startup.xml");
250 QString pathFln = path + fln;
251 QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
252 if (!QFile::exists(pathFln)) {
254 path = procEnv.value(
"HOME",
"");
255 pathFln = path +
"/.musrfit/" + fln;
256 if (!QFile::exists(pathFln)) {
258 path = procEnv.value(
"MUSRFITPATH",
"");
259 pathFln = path +
"/" + fln;
260 if (!QFile::exists(pathFln)) {
262 path = procEnv.value(
"ROOTSYS",
"");
263 pathFln = path +
"/bin/" + fln;
273 QMessageBox::critical(
nullptr,
"ERROR",
274 "Error parsing musrfit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
275 QMessageBox::Ok, QMessageBox::NoButton);
304 QStringList *strList =
fDefaultPath->getDefaultPathList();
313 for (
int i=0; i<strList->count(); i++) {
314 fSearchPath_listWidget->addItem(strList->at(i));
317 QObject::connect(fDelete_pushButton, SIGNAL(clicked()),
this, SLOT(
deleteItem()));
318 QObject::connect(fAdd_pushButton, SIGNAL(clicked()),
this, SLOT(
addItem()));
337 QString dirName = QFileDialog::getExistingDirectory(
this, tr(
"Data File Directory"),
"",
338 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
343 QListWidgetItem *item =
new QListWidgetItem;
345 QMessageBox::critical(
this,
"ERROR",
"Couldn't invoke QListWidgetItem! Won't do anything.");
348 item->setText(dirName);
349 fSearchPath_listWidget->insertItem(fSearchPath_listWidget->currentRow()+1, item);
361 QListWidgetItem *item = fSearchPath_listWidget->takeItem(fSearchPath_listWidget->currentRow());
387 if (!fileIn.open(QIODevice::ReadOnly | QIODevice::Text)) {
388 QMessageBox::critical(
this,
"ERROR", QString(
"Cannot read '%1'. Won't do anything.").arg(
fDefaultPath->getPrefPathName()));
391 QTextStream in(&fileIn);
392 QStringList fileContent;
393 while (!in.atEnd()) {
394 fileContent << in.readLine();
399 bool dataPathPresent =
false;
401 for (
int i=0; i<fileContent.count(); i++) {
402 str = fileContent[i];
403 if (str.trimmed().startsWith(
"<data_path>")) {
404 dataPathPresent =
true;
411 if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text)) {
412 QMessageBox::critical(
this,
"ERROR", QString(
"Cannot write to '%1'.").arg(
fDefaultPath->getPrefPathName()));
415 QTextStream out(&fileOut);
417 for (
int i=0; i<fileContent.count(); i++) {
418 str = fileContent[i];
419 if (!str.trimmed().startsWith(
"<data_path>")) {
421 if ((dataPathPresent ==
false) && (str.trimmed().startsWith(
"</musrfit>"))) {
422 for (
int j=0; j<fSearchPath_listWidget->count(); j++) {
423 out <<
" <data_path>" << fSearchPath_listWidget->item(j)->text() <<
"</data_path>" << Qt::endl;
426 out << fileContent[i] << Qt::endl;
430 for (
int j=0; j<fSearchPath_listWidget->count(); j++)
431 out <<
" <data_path>" << fSearchPath_listWidget->item(j)->text() <<
"</data_path>" << Qt::endl;
Dialog for managing default data file search paths in musredit.
void addItem()
Add a new directory path via file browser dialog.
PChangeDefaultPathsDialog()
Constructs the default paths dialog.
std::unique_ptr< PDefaultPaths > fDefaultPath
Manages the default paths data.
void saveDefaultPathList()
Save the modified path list to the configuration file.
void deleteItem()
Remove the currently selected path from the list.
virtual bool isValid()
Check if the XML file was parsed successfully.
QXmlStreamReader fXml
Qt XML stream reader for parsing.
PDefaultPathsXMLParser(const QString &fln, PDefaultPaths *defaultPaths)
Constructs an XML parser for reading default data paths.
bool startElement()
Handler called when an XML start element is encountered.
bool characters()
Handler for XML element character content.
bool endDocument()
Handler called at the end of XML document parsing.
@ eDataPath
Processing a <data_path> element.
@ eEmpty
No element currently being processed.
bool startDocument()
Handler called at the start of XML document parsing.
bool fValid
Flag indicating successful parsing.
PDefaultPaths * fDefaultPaths
Pointer to the object storing parsed paths.
bool parse(QIODevice *device)
Parse the XML configuration file for data paths.
bool endElement()
Handler called when an XML end element is encountered.
EAdminKeyWords fKeyWord
Current element type being processed.
Container class for managing default data file search paths.
friend class PDefaultPathsXMLParser
Allow parser to access private members.
QString fPrefPathName
Full path to the active configuration file.
PDefaultPaths()
Constructs a PDefaultPaths object and loads paths from configuration.
bool fValid
Flag indicating if configuration loaded successfully.