Some fixes for HTML character escaping (seems like Qt doesn't like """).

This commit is contained in:
LoRd_MuldeR 2013-05-30 12:53:26 +02:00
parent 80c4388441
commit cfba22411d
2 changed files with 44 additions and 6 deletions

View File

@ -57,6 +57,16 @@ const char *LINK_MULDER = "http://muldersoft.com/";
const char *LINK_MEDIAINFO = "http://mediainfo.sourceforge.net/en"; const char *LINK_MEDIAINFO = "http://mediainfo.sourceforge.net/en";
const char *LINK_DISCUSS = "http://forum.doom9.org/showthread.php?t=96516"; const char *LINK_DISCUSS = "http://forum.doom9.org/showthread.php?t=96516";
//HTML characters
static QList<QPair<const QString, const QString>> HTML_ESCAPE(void)
{
QList<QPair<const QString, const QString>> htmlEscape;
htmlEscape << QPair<const QString, const QString>("<", "&lt;");
htmlEscape << QPair<const QString, const QString>(">", "&gt;");
htmlEscape << QPair<const QString, const QString>("&", "&amp;");
return htmlEscape;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Constructor // Constructor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -66,6 +76,7 @@ CMainWindow::CMainWindow(const QString &tempFolder, QWidget *parent)
QMainWindow(parent), QMainWindow(parent),
m_tempFolder(tempFolder), m_tempFolder(tempFolder),
m_firstShow(true), m_firstShow(true),
m_htmlEscape(HTML_ESCAPE()),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
//Init UI //Init UI
@ -135,7 +146,7 @@ void CMainWindow::showEvent(QShowEvent *event)
resize(this->minimumSize()); resize(this->minimumSize());
//Init test //Init test
ui->versionLabel->setText(QString("v%1 (%2)").arg(QString().sprintf("%u.%02u", mixp_versionMajor, mixp_versionMinor), mixp_get_build_date().toString(Qt::ISODate))); ui->versionLabel->setText(QString("v%1 / v%2 (%3)").arg(QString().sprintf("%u.%02u", mixp_versionMajor, mixp_versionMinor), QString().sprintf("%u.%u.%02u", mixp_miVersionMajor, mixp_miVersionMinor, mixp_miVersionPatch), mixp_get_build_date().toString(Qt::ISODate)));
ui->updateLabel->setText(tr("This version is more than six month old and probably outdated. Please check <a href=\"%1\">%1</a> for updates!").arg(LINK_MULDER)); ui->updateLabel->setText(tr("This version is more than six month old and probably outdated. Please check <a href=\"%1\">%1</a> for updates!").arg(LINK_MULDER));
//Show update hint? //Show update hint?
@ -303,6 +314,8 @@ void CMainWindow::clearButtonClicked(void)
void CMainWindow::outputAvailable(void) void CMainWindow::outputAvailable(void)
{ {
if(m_process) if(m_process)
{ {
bool bDataChanged = false; bool bDataChanged = false;
@ -312,7 +325,10 @@ void CMainWindow::outputAvailable(void)
{ {
bDataChanged = true; bDataChanged = true;
QString line = QString::fromUtf8(m_process->readLine()).trimmed(); QString line = QString::fromUtf8(m_process->readLine()).trimmed();
m_outputLines << line; if(!(line.isEmpty() && m_outputLines.empty()))
{
m_outputLines << line;
}
} }
if(bDataChanged) if(bDataChanged)
@ -322,10 +338,7 @@ void CMainWindow::outputAvailable(void)
//Convert to HTML //Convert to HTML
QStringList htmlData(m_outputLines); QStringList htmlData(m_outputLines);
htmlData.replaceInStrings("<", "&lt;", Qt::CaseInsensitive); escapeHtmlChars(htmlData);
htmlData.replaceInStrings(">", "&gt;", Qt::CaseInsensitive);
htmlData.replaceInStrings("\"", "&quot;", Qt::CaseInsensitive);
htmlData.replaceInStrings("&", "&amp;", Qt::CaseInsensitive);
//Highlight headers //Highlight headers
htmlData.replaceInStrings(QRegExp("^([^:]+):(.+)$"), "<font color=\"darkblue\">\\1:</font>\\2"); htmlData.replaceInStrings(QRegExp("^([^:]+):(.+)$"), "<font color=\"darkblue\">\\1:</font>\\2");
@ -342,6 +355,12 @@ void CMainWindow::processFinished(void)
//Fetch any remaining data //Fetch any remaining data
outputAvailable(); outputAvailable();
//Failed?
if(m_outputLines.empty())
{
ui->textBrowser->setHtml(QString("<pre>%1</pre>").arg(tr("Oups, apparently MediaInfo encountered a problem :-(")));
}
//Enable actions //Enable actions
if(!m_outputLines.empty()) if(!m_outputLines.empty())
{ {
@ -349,6 +368,7 @@ void CMainWindow::processFinished(void)
ui->actionCopyToClipboard->setEnabled(true); ui->actionCopyToClipboard->setEnabled(true);
ui->actionSave->setEnabled(true); ui->actionSave->setEnabled(true);
} }
ui->actionOpen->setEnabled(true); ui->actionOpen->setEnabled(true);
ui->analyzeButton->setEnabled(true); ui->analyzeButton->setEnabled(true);
ui->exitButton->setEnabled(true); ui->exitButton->setEnabled(true);
@ -356,6 +376,8 @@ void CMainWindow::processFinished(void)
//Scroll up //Scroll up
ui->textBrowser->verticalScrollBar()->setValue(0); ui->textBrowser->verticalScrollBar()->setValue(0);
ui->textBrowser->horizontalScrollBar()->setValue(0); ui->textBrowser->horizontalScrollBar()->setValue(0);
qDebug("Process has finished (Code: %d)\n", m_process->exitCode());
} }
void CMainWindow::linkTriggered(void) void CMainWindow::linkTriggered(void)
@ -562,6 +584,7 @@ bool CMainWindow::analyzeFile(const QString &filePath)
const QString mediaInfoPath = getMediaInfoPath(); const QString mediaInfoPath = getMediaInfoPath();
if(mediaInfoPath.isEmpty()) if(mediaInfoPath.isEmpty())
{ {
ui->textBrowser->setHtml(QString("<pre>%1</pre>").arg(tr("Oups, failed to extract MediaInfo binary!")));
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok); QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok);
m_floatingLabel->hide(); m_floatingLabel->hide();
ui->actionOpen->setEnabled(true); ui->actionOpen->setEnabled(true);
@ -577,6 +600,8 @@ bool CMainWindow::analyzeFile(const QString &filePath)
//Wait for process to start //Wait for process to start
if(!m_process->waitForStarted()) if(!m_process->waitForStarted())
{ {
qWarning("Process failed to start:\n%s\n", m_process->errorString().toLatin1().constData());
ui->textBrowser->setHtml(QString("<pre>%1</pre>").arg(tr("Oups, failed to create MediaInfo process!")));
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to create MediaInfo process!"), QMessageBox::Ok); QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to create MediaInfo process!"), QMessageBox::Ok);
m_floatingLabel->hide(); m_floatingLabel->hide();
ui->actionOpen->setEnabled(true); ui->actionOpen->setEnabled(true);
@ -585,5 +610,15 @@ bool CMainWindow::analyzeFile(const QString &filePath)
return false; return false;
} }
qDebug("Process started successfully (PID: %u)", m_process->pid()->dwProcessId);
return true; return true;
} }
void CMainWindow::escapeHtmlChars(QStringList &strings)
{
QList<QPair<const QString, const QString>>::ConstIterator iter;
for(iter = m_htmlEscape.constBegin(); iter != m_htmlEscape.constEnd(); iter++)
{
strings.replaceInStrings((*iter).first, (*iter).second);
}
}

View File

@ -71,7 +71,10 @@ private:
QLabel *m_floatingLabel; QLabel *m_floatingLabel;
QString m_droppedFile; QString m_droppedFile;
QStringList m_outputLines; QStringList m_outputLines;
const QList<QPair<const QString, const QString>> m_htmlEscape;
QString getMediaInfoPath(void); QString getMediaInfoPath(void);
void escapeHtmlChars(QStringList &strings);
bool analyzeFile(const QString &filePath); bool analyzeFile(const QString &filePath);
}; };