diff --git a/src/musredit_qt5/musredit/PAdmin.cpp b/src/musredit_qt5/musredit/PAdmin.cpp index 8d54ba53..fbe1c431 100644 --- a/src/musredit_qt5/musredit/PAdmin.cpp +++ b/src/musredit_qt5/musredit/PAdmin.cpp @@ -59,8 +59,12 @@ PAdminXMLParser::PAdminXMLParser(const QString& fln, PAdmin *admin) : fAdmin(adm fFunc = false; QFile file(fln); - if (!file.open(QFile::ReadOnly | QFile::Text)) { - // warning and create default - STILL MISSING + if (!file.open(QFile::ReadOnly | QFile::Text) || (file.size()==0)) { + // warning and create default + QMessageBox::StandardButton ret = QMessageBox::warning(nullptr, "WARNING", "The musredit_startup.xml is corrupted. Create a default one?", QMessageBox::Yes | QMessageBox::No); + if (ret == QMessageBox::Yes) { + fAdmin->createMusreditStartupFile(); + } } fValid = parse(&file); @@ -98,7 +102,7 @@ bool PAdminXMLParser::parse(QIODevice *device) if (fXml.hasError()) { QString msg; msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber()); - QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton); + QMessageBox::critical(nullptr, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton); return false; } @@ -717,14 +721,14 @@ QString PAdminXMLParser::expandPath(const QString &str) token.remove('$'); if (!procEnv.contains(token)) { msg = QString("Couldn't find '%1'. Some things might not work properly").arg(token); - QMessageBox::warning(0, "**WARNING**", msg, QMessageBox::Ok, QMessageBox::NoButton); + QMessageBox::warning(nullptr, "**WARNING**", msg, QMessageBox::Ok, QMessageBox::NoButton); newStr = ""; break; } path = procEnv.value(token, ""); 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); + QMessageBox::warning(nullptr, "**WARNING**", msg, QMessageBox::Ok, QMessageBox::NoButton); newStr = ""; break; } @@ -769,13 +773,13 @@ PAdmin::PAdmin() : QObject() // XML Parser part // 1st: check local directory - QString path = QString("./"); + QString path = QDir::currentPath(); QString fln = QString("musredit_startup.xml"); QString pathFln = path + fln; QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment(); if (!QFile::exists(pathFln)) { // 2nd: check $HOME/.musrfit/musredit/musredit_startup.xml - path = procEnv.value("HOME", ""); + path = QDir::homePath(); pathFln = path + "/.musrfit/musredit/" + fln; if (!QFile::exists(pathFln)) { // 3rd: check $MUSRFITPATH/musredit_startup.xml @@ -803,9 +807,9 @@ PAdmin::PAdmin() : QObject() QFileInfo info(str); if (info.exists()) { if (!info.isExecutable()) - QMessageBox::critical(0, "ERROR", "musrfit found but not recognized as executable.\nPlease check!"); + QMessageBox::critical(nullptr, "ERROR", "musrfit found but not recognized as executable.\nPlease check!"); } else { - QMessageBox::critical(0, "ERROR", "musrfit not found.\nHave you set the necessary system variables properly?\nPlease check the manual.\nBefore you can use musrfit, this needs to be fixed."); + QMessageBox::critical(nullptr, "ERROR", "musrfit not found.\nHave you set the necessary system variables properly?\nPlease check the manual.\nBefore you can use musrfit, this needs to be fixed."); } // check if system variables are set properly @@ -828,19 +832,10 @@ PAdmin::PAdmin() : QObject() } if (sysVarMissing) { msg += "Please set this/these system variables."; - QMessageBox::warning(0, "WARNING", msg); + QMessageBox::warning(nullptr, "WARNING", msg); } } -//-------------------------------------------------------------------------- -/** - *
Destructor - */ -PAdmin::~PAdmin() -{ - saveRecentFiles(); -} - //-------------------------------------------------------------------------- /** *
returns the help url corresponding the the tag.
@@ -908,13 +903,13 @@ int PAdmin::loadPrefs(QString fln)
if (QFile::exists(fln)) { // administration file present
PAdminXMLParser handler(fln, this);
if (!handler.isValid()) {
- QMessageBox::critical(0, "**ERROR**",
+ QMessageBox::critical(nullptr, "**ERROR**",
"Error parsing musredit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
QMessageBox::Ok, QMessageBox::NoButton);
return 0;
}
} else {
- QMessageBox::critical(0, "**ERROR**",
+ QMessageBox::critical(nullptr, "**ERROR**",
"Couldn't find the musredit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
QMessageBox::Ok, QMessageBox::NoButton);
return 0;
@@ -1059,7 +1054,7 @@ int PAdmin::savePrefs(QString pref_fln)
file.close();
} else {
QString msg("Failed to write musredit_startup.xml. Neither a local nor a global copy found.");
- QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
+ QMessageBox::warning(nullptr, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
}
return 1;
@@ -1153,7 +1148,7 @@ void PAdmin::saveRecentFiles()
file.close();
} else {
QString msg("Failed to write musredit_startup.xml. Neither a local nor a global copy found.");
- QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
+ QMessageBox::warning(nullptr, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
}
}
@@ -1182,13 +1177,13 @@ void PAdmin::createMusreditStartupFile()
QFile fres(":/musredit_startup.xml.in");
if (!fres.exists()) {
QString msg = QString("Neither couldn't find nor create musredit_startup.xml. Things are likely not to work.");
- QMessageBox::critical(0, "ERROR", msg);
+ QMessageBox::critical(nullptr, "ERROR", msg);
return;
}
if (!fres.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString msg = QString("Couldn't open internal resource file musredit_startup.xml.in. Things are likely not to work.");
- QMessageBox::critical(0, "ERROR", msg);
+ QMessageBox::critical(nullptr, "ERROR", msg);
return;
}
// text stream for fres
diff --git a/src/musredit_qt5/musredit/PAdmin.h b/src/musredit_qt5/musredit/PAdmin.h
index 1e118355..99344d8f 100644
--- a/src/musredit_qt5/musredit/PAdmin.h
+++ b/src/musredit_qt5/musredit/PAdmin.h
@@ -65,7 +65,6 @@ class PAdminXMLParser
{
public:
PAdminXMLParser(const QString &fln, PAdmin*);
- virtual ~PAdminXMLParser() {}
virtual bool isValid() { return fValid; }
@@ -113,7 +112,6 @@ class PAdmin : public QObject
{
public:
PAdmin();
- virtual ~PAdmin();
int getTimeout() { return fTimeout; }
QString getFontName() { return fFontName; }
@@ -173,6 +171,7 @@ class PAdmin : public QObject
int loadPrefs(QString fln);
int savePrefs(QString pref_fln);
+ void saveRecentFiles(); ///< save recent file list
protected:
void setExecPath(const QString str) { fExecPath = str; }
@@ -228,7 +227,6 @@ class PAdmin : public QObject
QVector