64#include <QProcessEnvironment>
102 if ((r>=0) && (r<=255))
104 if ((g>=0) && (g<=255))
106 if ((b>=0) && (b<=255))
129 if (!file.open(QFile::ReadOnly | QFile::Text)) {
153 fXml.setDevice(device);
155 bool expectChars =
false;
156 while (!
fXml.atEnd()) {
158 if (
fXml.isStartDocument()) {
160 }
else if (
fXml.isStartElement()) {
163 }
else if (
fXml.isCharacters() && expectChars) {
165 }
else if (
fXml.isEndElement()) {
168 }
else if (
fXml.isEndDocument()) {
172 if (
fXml.hasError()) {
174 msg = QString(
"%1 Line %2, column %3").arg(
fXml.errorString()).arg(
fXml.lineNumber()).arg(
fXml.columnNumber());
175 QMessageBox::critical(0,
"**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton);
218 QString qName =
fXml.name().toString();
220 if (qName ==
"path_file_name") {
222 }
else if (qName ==
"ignore_theme_auto_detection") {
224 }
else if (qName ==
"dark_theme_icon_menu") {
226 }
else if (qName ==
"dark_theme_icon_toolbar") {
228 }
else if (qName ==
"marker") {
230 }
else if (qName ==
"color") {
274 QString str =
fXml.text().toString();
286 fAdmin->addRecentFile(QString(str.toLatin1()).trimmed());
289 if ((str ==
"yes") || (str ==
"y") || (str ==
"1") || (str ==
"true"))
290 fAdmin->setIgnoreThemeAutoDetection(
true);
292 fAdmin->setIgnoreThemeAutoDetection(
false);
295 if ((str ==
"yes") || (str ==
"y") || (str ==
"1") || (str ==
"true"))
296 fAdmin->setThemeIconsMenu(
true);
298 fAdmin->setThemeIconsMenu(
false);
301 if ((str ==
"yes") || (str ==
"y") || (str ==
"1") || (str ==
"true"))
302 fAdmin->setThemeIconsToolbar(
true);
304 fAdmin->setThemeIconsToolbar(
false);
307 tok = str.split(
",", Qt::SkipEmptyParts);
309 if ((tok.count() != 1) && (tok.count() != 2)) {
313 ival = tok[0].toInt(&ok);
318 if (tok.count() == 2) {
319 dval = tok[1].toDouble(&ok);
323 fAdmin->setMarker(ival, dval);
326 tok = str.split(
",", Qt::SkipEmptyParts);
328 if ((tok.count() != 3) && (tok.count() != 4)) {
331 ival = tok[0].toInt(&ok);
335 ival = tok[1].toInt(&ok);
339 ival = tok[2].toInt(&ok);
343 if (tok.count() == 4)
345 fAdmin->setColor(r, g, b, name);
392 QString path = QString(
"./");
393 QString fln = QString(
"mupp_startup.xml");
394 QString pathFln = path + fln;
395 QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
396 if (!QFile::exists(pathFln)) {
398 path = procEnv.value(
"HOME",
"");
399 pathFln = path +
"/.musrfit/mupp/" + fln;
400 if (!QFile::exists(pathFln)) {
402 path = procEnv.value(
"MUSRFITPATH",
"");
403 pathFln = path +
"/" + fln;
404 if (!QFile::exists(pathFln)) {
406 path = procEnv.value(
"ROOTSYS",
"");
407 pathFln = path +
"/bin/" + fln;
408 if (!QFile::exists(pathFln)) {
410 path = procEnv.value(
"HOME",
"");
411 pathFln = path +
"/.musrfit/mupp/" + fln;
418 if (QFile::exists(pathFln)) {
421 QMessageBox::critical(0,
"**ERROR**",
422 "Error parsing mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
423 QMessageBox::Ok, QMessageBox::NoButton);
427 QMessageBox::critical(0,
"**ERROR**",
428 "Couldn't find the mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
429 QMessageBox::Ok, QMessageBox::NoButton);
527 for (
int i=0; i<
fColor.size(); i++) {
528 if (
fColor[i].getName() == name) {
539 fColor[idx].getRGB(r, g, b);
558 if ((idx<=0) || (idx>
fColor.size())) {
563 fColor[idx].getRGB(r, g, b);
583 if ((marker<1) || (marker>49)) {
584 QMessageBox::warning(0,
"WARNING", QString(
"Found Marker (%1) not in the expected range.\nWill ignore it.").arg(marker));
608 if (((r<0) || (r>255)) ||
609 ((g<0) || (g>255)) ||
610 ((b<0) || (b>255))) {
611 QMessageBox::warning(0,
"WARNING", QString(
"Found Color (%1,%2,%3) not in the expected range.\nWill ignore it.").arg(r).arg(g).arg(b));
646 QString fln = QString(
"./mupp_startup.xml");
647 if (!QFile::exists(fln)) {
648 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
649 fln = QString(
"%1/.musrfit/mupp/mupp_startup.xml").arg(env.value(
"HOME"));
652 if (QFile::exists(fln)) {
653 QVector<QString> data;
655 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
656 std::cerr << std::endl <<
">> PmuppAdmin::saveRecentFile: **ERROR** Cannot open " << fln.toLatin1().data() <<
" for reading." << std::endl;
659 QTextStream fin(&file);
660 while (!fin.atEnd()) {
661 data.push_back(fin.readLine());
666 for (QVector<QString>::iterator it = data.begin(); it != data.end(); ++it) {
667 if (it->contains(
"<path_file_name>")) {
675 for (i=0; i<data.size(); i++) {
676 if (data[i].contains(
"<recent_files>"))
680 if (i == data.size()) {
681 std::cerr << std::endl <<
">> PmuppAdmin::saveRecentFile: **ERROR** " << fln.toLatin1().data() <<
" seems to be corrupt." << std::endl;
686 str =
" <path_file_name>" +
fRecentFile[j] +
"</path_file_name>";
687 data.insert(i++, str);
690 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
691 std::cerr << std::endl <<
">> PmuppAdmin::saveRecentFile: **ERROR** Cannot open " << fln.toLatin1().data() <<
" for reading." << std::endl;
694 fin.setDevice(&file);
695 for (
int i=0; i<data.size(); i++) {
696 fin << data[i] << Qt::endl;
700 QString msg(
"Failed to write mupp_startup.xml. Neither a local nor a global copy found.");
701 QMessageBox::warning(0,
"WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
725 QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
726 QString pathName = procEnv.value(
"HOME",
"");
727 pathName +=
"/.musrfit/mupp";
733 dir.mkpath(pathName);
737 pathName +=
"/mupp_startup.xml";
740 QFile fres(
":/mupp_startup.xml.in");
741 if (!fres.exists()) {
742 QString msg = QString(
"Neither couldn't find nor create mupp_startup.xml. Things are likely not to work.");
743 QMessageBox::critical(0,
"ERROR", msg);
747 if (!fres.open(QIODevice::ReadOnly | QIODevice::Text)) {
748 QString msg = QString(
"Couldn't open internal resource file mupp_startup.xml.in. Things are likely not to work.");
749 QMessageBox::critical(0,
"ERROR", msg);
753 QTextStream fin(&fres);
756 QFile file(pathName);
758 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
762 QTextStream fout(&file);
765 while (!fin.atEnd()) {
766 line = fin.readLine();
767 fout << line << Qt::endl;
Administration and configuration management for mupp application.
bool startDocument()
Handler for XML document start.
PmuppAdmin * fAdmin
pointer to the admin object being populated
bool parse(QIODevice *device)
Main parsing method that processes the XML document.
EAdminKeyWords fKeyWord
current element type being processed
QXmlStreamReader fXml
Qt XML stream reader object for parsing.
virtual bool isValid()
Checks if the XML parsing was successful.
PmuppAdminXMLParser(const QString &fln, PmuppAdmin *)
Constructor that parses the XML configuration file.
bool fValid
flag indicating successful XML parsing
bool characters()
Handler for XML element text content.
bool startElement()
Handler for XML element opening tags.
@ eIgnoreThemeAutoDetection
theme auto-detection override
@ eEmpty
no specific element being processed
@ eDarkThemeIconsMenu
menu icon theme setting
@ eDarkThemeIconsToolbar
toolbar icon theme setting
@ eRecentFile
recent file path element
@ eMarker
marker definition element
bool endElement()
Handler for XML element closing tags.
bool endDocument()
Handler for XML document end.
Main administration class for mupp configuration management.
void addRecentFile(const QString str)
Adds a file to the recent files list.
void setMarker(const int marker, const double size)
Adds a marker definition to the configuration.
QVector< PmuppColor > fColor
vector of configured plot colors
PmuppAdmin()
Constructor. Loads configuration from mupp_startup.xml.
virtual ~PmuppAdmin()
Destructor. Saves recent files list before destruction.
QVector< PmuppMarker > fMarker
vector of configured plot markers
QString getRecentFile(int idx)
Gets a recent file path by index.
friend class PmuppAdminXMLParser
void setColor(const int r, const int g, const int b, QString name="")
Adds a color definition to the configuration.
void createMuppStartupFile()
Creates a default mupp_startup.xml configuration file.
void saveRecentFiles()
Saves the recent files list to the configuration file.
QVector< QString > fRecentFile
ring buffer of recent file paths (max MAX_RECENT_FILES)
void getColor(QString name, int &r, int &g, int &b)
Gets a color by name.
PmuppMarker getMarker(int idx)
Gets a marker definition by index.
Represents an RGB color for plotting.
int fBlue
blue component (0-255)
int fRed
red component (0-255)
PmuppColor()
Default constructor. Initializes color with undefined values.
QString fName
optional name identifier for the color
int fGreen
green component (0-255)
void setName(const QString name)
Sets the color name.
void setRGB(const int r, const int g, const int b)
Sets the RGB values with validation.
Represents a plot marker style and size.
void setMarker(int marker)
Sets the marker code.
void setMarkerSize(double size)
Sets the marker size multiplier.
#define MAX_RECENT_FILES
Maximum number of recent files to be tracked.