Some improvements to the output formating.

This commit is contained in:
LoRd_MuldeR 2013-05-20 02:50:59 +02:00
parent feee78444a
commit d2924b7c10
3 changed files with 46 additions and 27 deletions

View File

@ -23,11 +23,6 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTextBrowser" name="textBrowser"> <widget class="QTextBrowser" name="textBrowser">
<property name="font">
<font>
<family>Lucida Console</family>
</font>
</property>
<property name="horizontalScrollBarPolicy"> <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>

View File

@ -46,14 +46,19 @@
#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
#define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); } #define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); }
//////////////////////////////////////////////////////////// //Text
// Constructor const char *STATUS_BLNK = ">> You can drop any type of media files here <<";
//////////////////////////////////////////////////////////// const char *STATUS_WORK = "Analyzing file, this may take a moment or two...";
//Links
const char *LINK_MULDER = "http://muldersoft.com/"; 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";
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
CMainWindow::CMainWindow(const QString &tempFolder, QWidget *parent) CMainWindow::CMainWindow(const QString &tempFolder, QWidget *parent)
: :
QMainWindow(parent), QMainWindow(parent),
@ -83,12 +88,17 @@ CMainWindow::CMainWindow(const QString &tempFolder, QWidget *parent)
//Create label //Create label
m_floatingLabel = new QLabel(ui->textBrowser); m_floatingLabel = new QLabel(ui->textBrowser);
m_floatingLabel->setText(">> You can drop any type of media files here <<"); m_floatingLabel->setText(QString::fromLatin1(STATUS_BLNK));
m_floatingLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_floatingLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_floatingLabel->show(); m_floatingLabel->show();
SET_TEXT_COLOR(m_floatingLabel, Qt::darkGray); SET_TEXT_COLOR(m_floatingLabel, Qt::darkGray);
SET_FONT_BOLD(m_floatingLabel, true); SET_FONT_BOLD(m_floatingLabel, true);
//Update font
QFont font("Lucida Console");
font.setStyleHint(QFont::TypeWriter);
ui->textBrowser->setFont(font);
//Clear //Clear
m_mediaInfoPath.clear(); m_mediaInfoPath.clear();
m_mediaInfoHandle = INVALID_HANDLE_VALUE; m_mediaInfoHandle = INVALID_HANDLE_VALUE;
@ -238,6 +248,7 @@ void CMainWindow::clearButtonClicked(void)
} }
ui->textBrowser->clear(); ui->textBrowser->clear();
m_floatingLabel->setText(STATUS_BLNK);
m_floatingLabel->show(); m_floatingLabel->show();
} }
@ -247,17 +258,14 @@ void CMainWindow::outputAvailable(void)
{ {
while(m_process->canReadLine()) while(m_process->canReadLine())
{ {
QByteArray line = m_process->readLine(); if(m_floatingLabel->isVisible()) m_floatingLabel->hide();
ui->textBrowser->append(QString::fromUtf8(line).trimmed()); QString line = Qt::escape(QString::fromUtf8(m_process->readLine()).trimmed()).replace(' ', "&nbsp;");
if(!(line.isEmpty() || line.contains(':'))) line = QString("<b>%1</b>").arg(line);
ui->textBrowser->setHtml(m_output.append(line).append("<br>"));
} }
} }
} }
void CMainWindow::processStarted(void)
{
ui->textBrowser->clear();
}
void CMainWindow::processFinished(void) void CMainWindow::processFinished(void)
{ {
outputAvailable(); outputAvailable();
@ -451,12 +459,6 @@ QString CMainWindow::getMediaInfoPath(void)
//Validate file content //Validate file content
VALIDATE_MEDIAINFO(m_mediaInfoHandle); VALIDATE_MEDIAINFO(m_mediaInfoHandle);
//Failed?
if(m_mediaInfoPath.isEmpty())
{
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok);
}
return m_mediaInfoPath; return m_mediaInfoPath;
} }
@ -472,7 +474,6 @@ bool CMainWindow::analyzeFile(const QString &filePath)
connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(outputAvailable())); connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(outputAvailable()));
connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished())); connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished()));
connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processFinished())); connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processFinished()));
connect(m_process, SIGNAL(started()), this, SLOT(processStarted()));
} }
//Still running? //Still running?
@ -482,19 +483,42 @@ bool CMainWindow::analyzeFile(const QString &filePath)
return false; return false;
} }
//Clear data
ui->textBrowser->clear();
m_output.clear();
//Disable buttons
ui->analyzeButton->setEnabled(false);
ui->exitButton->setEnabled(false);
//Show banner
m_floatingLabel->show();
m_floatingLabel->setText(QString::fromLatin1(STATUS_WORK));
//Update
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
//Lookup MediaInfo path //Lookup MediaInfo path
const QString mediaInfoPath = getMediaInfoPath(); const QString mediaInfoPath = getMediaInfoPath();
if(mediaInfoPath.isEmpty()) if(mediaInfoPath.isEmpty())
{ {
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok);
return false; return false;
} }
//Start analyziation
qDebug("Analyzing media file:\n%s\n", filePath.toUtf8().constData()); qDebug("Analyzing media file:\n%s\n", filePath.toUtf8().constData());
m_process->start(mediaInfoPath, QStringList() << QDir::toNativeSeparators(filePath)); m_process->start(mediaInfoPath, QStringList() << QDir::toNativeSeparators(filePath));
//Wait for process to start
if(!m_process->waitForStarted())
{
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to create MediaInfo process!"), QMessageBox::Ok);
m_floatingLabel->hide(); m_floatingLabel->hide();
ui->analyzeButton->setEnabled(true); ui->analyzeButton->setEnabled(true);
ui->exitButton->setEnabled(true); ui->exitButton->setEnabled(true);
return false;
}
return true; return true;
} }

View File

@ -45,7 +45,6 @@ private slots:
void analyzeButtonClicked(void); void analyzeButtonClicked(void);
void clearButtonClicked(void); void clearButtonClicked(void);
void outputAvailable(void); void outputAvailable(void);
void processStarted(void);
void processFinished(void); void processFinished(void);
void linkTriggered(void); void linkTriggered(void);
void showAboutScreen(void); void showAboutScreen(void);
@ -69,6 +68,7 @@ private:
QProcess *m_process; QProcess *m_process;
QLabel *m_floatingLabel; QLabel *m_floatingLabel;
QString m_droppedFile; QString m_droppedFile;
QString m_output;
QDate getBuildDate(void); QDate getBuildDate(void);
QString getMediaInfoPath(void); QString getMediaInfoPath(void);