back ported some qt6 recent file handling.

This commit is contained in:
suter_a 2025-03-30 18:14:04 +02:00
parent c3b4c7c3b1
commit 5648757389
3 changed files with 27 additions and 32 deletions

View File

@ -59,8 +59,12 @@ PAdminXMLParser::PAdminXMLParser(const QString& fln, PAdmin *admin) : fAdmin(adm
fFunc = false; fFunc = false;
QFile file(fln); QFile file(fln);
if (!file.open(QFile::ReadOnly | QFile::Text)) { if (!file.open(QFile::ReadOnly | QFile::Text) || (file.size()==0)) {
// warning and create default - STILL MISSING // 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); fValid = parse(&file);
@ -98,7 +102,7 @@ bool PAdminXMLParser::parse(QIODevice *device)
if (fXml.hasError()) { if (fXml.hasError()) {
QString msg; QString msg;
msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber()); 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; return false;
} }
@ -717,14 +721,14 @@ QString PAdminXMLParser::expandPath(const QString &str)
token.remove('$'); token.remove('$');
if (!procEnv.contains(token)) { if (!procEnv.contains(token)) {
msg = QString("Couldn't find '%1'. Some things might not work properly").arg(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 = ""; newStr = "";
break; break;
} }
path = procEnv.value(token, ""); path = procEnv.value(token, "");
if (path.isEmpty()) { if (path.isEmpty()) {
msg = QString("Couldn't expand '%1'. Some things might not work properly").arg(token); 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 = ""; newStr = "";
break; break;
} }
@ -769,13 +773,13 @@ PAdmin::PAdmin() : QObject()
// XML Parser part // XML Parser part
// 1st: check local directory // 1st: check local directory
QString path = QString("./"); QString path = QDir::currentPath();
QString fln = QString("musredit_startup.xml"); QString fln = QString("musredit_startup.xml");
QString pathFln = path + fln; QString pathFln = path + fln;
QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment(); QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
if (!QFile::exists(pathFln)) { if (!QFile::exists(pathFln)) {
// 2nd: check $HOME/.musrfit/musredit/musredit_startup.xml // 2nd: check $HOME/.musrfit/musredit/musredit_startup.xml
path = procEnv.value("HOME", ""); path = QDir::homePath();
pathFln = path + "/.musrfit/musredit/" + fln; pathFln = path + "/.musrfit/musredit/" + fln;
if (!QFile::exists(pathFln)) { if (!QFile::exists(pathFln)) {
// 3rd: check $MUSRFITPATH/musredit_startup.xml // 3rd: check $MUSRFITPATH/musredit_startup.xml
@ -803,9 +807,9 @@ PAdmin::PAdmin() : QObject()
QFileInfo info(str); QFileInfo info(str);
if (info.exists()) { if (info.exists()) {
if (!info.isExecutable()) 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 { } 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 // check if system variables are set properly
@ -823,19 +827,10 @@ PAdmin::PAdmin() : QObject()
} }
if (sysVarMissing) { if (sysVarMissing) {
msg += "Please set this/these system variables."; msg += "Please set this/these system variables.";
QMessageBox::warning(0, "WARNING", msg); QMessageBox::warning(nullptr, "WARNING", msg);
} }
} }
//--------------------------------------------------------------------------
/**
* <p>Destructor
*/
PAdmin::~PAdmin()
{
saveRecentFiles();
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>returns the help url corresponding the the tag. * <p>returns the help url corresponding the the tag.
@ -903,13 +898,13 @@ int PAdmin::loadPrefs(QString fln)
if (QFile::exists(fln)) { // administration file present if (QFile::exists(fln)) { // administration file present
PAdminXMLParser handler(fln, this); PAdminXMLParser handler(fln, this);
if (!handler.isValid()) { 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.", "Error parsing musredit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
QMessageBox::Ok, QMessageBox::NoButton); QMessageBox::Ok, QMessageBox::NoButton);
return 0; return 0;
} }
} else { } 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.", "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); QMessageBox::Ok, QMessageBox::NoButton);
return 0; return 0;
@ -1054,7 +1049,7 @@ int PAdmin::savePrefs(QString pref_fln)
file.close(); file.close();
} else { } else {
QString msg("Failed to write musredit_startup.xml. Neither a local nor a global copy found."); 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; return 1;
@ -1148,7 +1143,7 @@ void PAdmin::saveRecentFiles()
file.close(); file.close();
} else { } else {
QString msg("Failed to write musredit_startup.xml. Neither a local nor a global copy found."); 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);
} }
} }
@ -1177,13 +1172,13 @@ void PAdmin::createMusreditStartupFile()
QFile fres(":/musredit_startup.xml.in"); QFile fres(":/musredit_startup.xml.in");
if (!fres.exists()) { if (!fres.exists()) {
QString msg = QString("Neither couldn't find nor create musredit_startup.xml. Things are likely not to work."); 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; return;
} }
if (!fres.open(QIODevice::ReadOnly | QIODevice::Text)) { 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."); 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; return;
} }
// text stream for fres // text stream for fres

View File

@ -65,7 +65,6 @@ class PAdminXMLParser
{ {
public: public:
PAdminXMLParser(const QString &fln, PAdmin*); PAdminXMLParser(const QString &fln, PAdmin*);
virtual ~PAdminXMLParser() {}
virtual bool isValid() { return fValid; } virtual bool isValid() { return fValid; }
@ -113,7 +112,6 @@ class PAdmin : public QObject
{ {
public: public:
PAdmin(); PAdmin();
virtual ~PAdmin();
int getTimeout() { return fTimeout; } int getTimeout() { return fTimeout; }
QString getFontName() { return fFontName; } QString getFontName() { return fFontName; }
@ -173,6 +171,7 @@ class PAdmin : public QObject
int loadPrefs(QString fln); int loadPrefs(QString fln);
int savePrefs(QString pref_fln); int savePrefs(QString pref_fln);
void saveRecentFiles(); ///< save recent file list
protected: protected:
void setExecPath(const QString str) { fExecPath = str; } void setExecPath(const QString str) { fExecPath = str; }
@ -228,7 +227,6 @@ class PAdmin : public QObject
QVector<PTheory> fTheory; ///< stores all known theories. Needed when generating theory blocks from within musredit. QVector<PTheory> fTheory; ///< stores all known theories. Needed when generating theory blocks from within musredit.
void saveRecentFiles(); ///< save recent file list
void createMusreditStartupFile(); ///< create default musredit_startup.xml void createMusreditStartupFile(); ///< create default musredit_startup.xml
}; };

View File

@ -1558,7 +1558,7 @@ void PTextEdit::fileClose(const bool check)
int result = QMessageBox::warning(this, "**WARNING**", int result = QMessageBox::warning(this, "**WARNING**",
"Do you really want to close this file.\nChanges will be lost", "Do you really want to close this file.\nChanges will be lost",
"Close", "Cancel"); "Close", "Cancel");
if (result == 1) // Cancel if (result == QMessageBox::Cancel) // Cancel
return; return;
} }
@ -1588,7 +1588,7 @@ void PTextEdit::fileCloseAll()
int result = QMessageBox::warning(this, "**WARNING**", int result = QMessageBox::warning(this, "**WARNING**",
"Do you really want to close all files.\nChanges of unsaved files will be lost", "Do you really want to close all files.\nChanges of unsaved files will be lost",
"Close", "Cancel"); "Close", "Cancel");
if (result == 1) // Cancel if (result == QMessageBox::Cancel) // Cancel
return; return;
break; break;
} }
@ -1625,7 +1625,7 @@ void PTextEdit::fileCloseAllOthers()
int result = QMessageBox::warning(this, "**WARNING**", int result = QMessageBox::warning(this, "**WARNING**",
"Do you really want to close all files.\nChanges of unsaved files will be lost", "Do you really want to close all files.\nChanges of unsaved files will be lost",
"Close", "Cancel"); "Close", "Cancel");
if (result == 1) // Cancel if (result == QMessageBox::Cancel) // Cancel
return; return;
break; break;
} }
@ -1668,12 +1668,14 @@ void PTextEdit::fileExit()
int result = QMessageBox::warning(this, "**WARNING**", int result = QMessageBox::warning(this, "**WARNING**",
"Do you really want to exit from the applcation.\nChanges will be lost", "Do you really want to exit from the applcation.\nChanges will be lost",
"Exit", "Cancel"); "Exit", "Cancel");
if (result == 1) // Cancel if (result == QMessageBox::Cancel) // Cancel
return; return;
break; break;
} }
} }
fAdmin->saveRecentFiles();
qApp->quit(); qApp->quit();
} }