fixed a bug in musredit_startup.xml and added proper error handling in the XML handler

This commit is contained in:
nemu
2010-06-23 09:18:35 +00:00
parent c3ba0077eb
commit 3b0bff23c5
3 changed files with 71 additions and 3 deletions

View File

@ -416,6 +416,66 @@ bool PAdminXMLParser::endDocument()
return true; return true;
} }
//--------------------------------------------------------------------------
/**
* <p>
*
* \param exception
*/
bool PAdminXMLParser::warning( const QXmlParseException & exception )
{
QString msg;
msg = QString("**WARNING** while parsing musredit_startup.xml in line no %1\n").arg(exception.lineNumber());
msg += QString("**WARNING MESSAGE** ") + exception.message();
qWarning() << endl << msg << endl;
QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
return true;
}
//--------------------------------------------------------------------------
/**
* <p>
*
* \param exception
*/
bool PAdminXMLParser::error( const QXmlParseException & exception )
{
QString msg;
msg = QString("**ERROR** while parsing musredit_startup.xml in line no %1\n").arg(exception.lineNumber());
msg += QString("**ERROR MESSAGE** ") + exception.message();
qWarning() << endl << msg << endl;
QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
return true;
}
//--------------------------------------------------------------------------
/**
* <p>
*
* \param exception
*/
bool PAdminXMLParser::fatalError( const QXmlParseException & exception )
{
QString msg;
msg = QString("**FATAL ERROR** while parsing musredit_startup.xml in line no %1\n").arg(exception.lineNumber());
msg += QString("**FATAL ERROR MESSAGE** ") + exception.message();
qWarning() << endl << msg << endl;
QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
return true;
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Expands system variables to full path, e.g. <tt>$HOME -> \home\user</tt> * <p>Expands system variables to full path, e.g. <tt>$HOME -> \home\user</tt>
@ -510,7 +570,12 @@ PAdmin::PAdmin()
QXmlInputSource source( &xmlFile ); QXmlInputSource source( &xmlFile );
QXmlSimpleReader reader; QXmlSimpleReader reader;
reader.setContentHandler( &handler ); reader.setContentHandler( &handler );
reader.parse( source ); reader.setErrorHandler( &handler );
if (!reader.parse( source )) {
QMessageBox::critical(0, "ERROR",
"Error parsing musredit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
QMessageBox::Ok, QMessageBox::NoButton);
}
} else { } else {
QMessageBox::critical(0, "ERROR", QMessageBox::critical(0, "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.",

View File

@ -86,6 +86,10 @@ class PAdminXMLParser : public QXmlDefaultHandler
bool characters(const QString&); bool characters(const QString&);
bool endDocument(); bool endDocument();
bool warning( const QXmlParseException & exception );
bool error( const QXmlParseException & exception );
bool fatalError( const QXmlParseException & exception );
QString expandPath(const QString&); QString expandPath(const QString&);
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content

View File

@ -46,7 +46,7 @@
<create_msr_file_only>n</create_msr_file_only> <create_msr_file_only>n</create_msr_file_only>
<fit_only>n</fit_only> <fit_only>n</fit_only>
<global>n</global> <global>n</global>
</msr2data_default> </msr2data_defaults>
<func_pixmap_path>$HOME/analysis/musrfit/src/musredit/latex_images</func_pixmap_path> <func_pixmap_path>$HOME/analysis/musrfit/src/musredit/latex_images</func_pixmap_path>
<theory_functions> <theory_functions>
<func> <func>
@ -198,4 +198,3 @@
</func> </func>
</theory_functions> </theory_functions>
</musredit_startup> </musredit_startup>