2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiLog.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
2007-10-06 11:45:53 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiLog.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-10-06 11:45:53 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "Lexer.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-03-26 04:25:49 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QTextBrowser>
|
2007-09-05 20:33:29 +00:00
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
#include <fstream>
|
2007-09-05 20:33:29 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
using std::istringstream;
|
|
|
|
using std::ostream;
|
|
|
|
using std::string;
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
using support::FileName;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-04-24 19:37:34 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-09-05 20:33:29 +00:00
|
|
|
// LogHighlighter
|
2007-04-24 19:37:34 +00:00
|
|
|
//
|
2007-09-05 20:33:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
class LogHighlighter : public QSyntaxHighlighter
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
public:
|
|
|
|
LogHighlighter(QTextDocument * parent);
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
private:
|
|
|
|
void highlightBlock(QString const & text);
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
private:
|
|
|
|
QTextCharFormat infoFormat;
|
|
|
|
QTextCharFormat warningFormat;
|
|
|
|
QTextCharFormat errorFormat;
|
|
|
|
};
|
2007-04-24 19:37:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LogHighlighter::LogHighlighter(QTextDocument * parent)
|
|
|
|
: QSyntaxHighlighter(parent)
|
2007-03-26 04:25:49 +00:00
|
|
|
{
|
2007-03-28 00:26:04 +00:00
|
|
|
infoFormat.setForeground(Qt::darkGray);
|
2007-03-26 04:25:49 +00:00
|
|
|
warningFormat.setForeground(Qt::darkBlue);
|
|
|
|
errorFormat.setForeground(Qt::red);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-24 19:37:34 +00:00
|
|
|
void LogHighlighter::highlightBlock(QString const & text)
|
2007-03-26 04:25:49 +00:00
|
|
|
{
|
|
|
|
// Info
|
|
|
|
QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
|
|
|
|
int index = text.indexOf(exprInfo);
|
|
|
|
while (index >= 0) {
|
|
|
|
int length = exprInfo.matchedLength();
|
|
|
|
setFormat(index, length, infoFormat);
|
|
|
|
index = text.indexOf(exprInfo, index + length);
|
|
|
|
}
|
|
|
|
// LaTeX Warning:
|
|
|
|
QRegExp exprWarning("^LaTeX Warning.*$");
|
|
|
|
index = text.indexOf(exprWarning);
|
|
|
|
while (index >= 0) {
|
|
|
|
int length = exprWarning.matchedLength();
|
|
|
|
setFormat(index, length, warningFormat);
|
|
|
|
index = text.indexOf(exprWarning, index + length);
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
// ! error
|
2007-03-26 04:25:49 +00:00
|
|
|
QRegExp exprError("^!.*$");
|
|
|
|
index = text.indexOf(exprError);
|
|
|
|
while (index >= 0) {
|
|
|
|
int length = exprError.matchedLength();
|
|
|
|
setFormat(index, length, errorFormat);
|
|
|
|
index = text.indexOf(exprError, index + length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-24 19:37:34 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiLog
|
2007-04-24 19:37:34 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
GuiLog::GuiLog(LyXView & lv)
|
2007-10-09 19:34:27 +00:00
|
|
|
: GuiDialog(lv, "log"), type_(LatexLog)
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-10-06 11:45:53 +00:00
|
|
|
connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().setPolicy(ButtonPolicy::OkCancelPolicy);
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-03-26 04:25:49 +00:00
|
|
|
// set syntax highlighting
|
2007-09-05 20:33:29 +00:00
|
|
|
highlighter = new LogHighlighter(logTB->document());
|
|
|
|
|
|
|
|
logTB->setReadOnly(true);
|
2007-03-26 04:25:49 +00:00
|
|
|
QFont font(toqstr(theApp()->typewriterFontName()));
|
|
|
|
font.setKerning(false);
|
|
|
|
font.setFixedPitch(true);
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
2007-09-05 20:33:29 +00:00
|
|
|
logTB->setFont(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
void GuiLog::closeEvent(QCloseEvent * e)
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-10-06 11:45:53 +00:00
|
|
|
slotClose();
|
|
|
|
e->accept();
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
void GuiLog::updateContents()
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-10-06 11:45:53 +00:00
|
|
|
setViewTitle(title());
|
|
|
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
getContents(ss);
|
|
|
|
|
|
|
|
logTB->setPlainText(toqstr(ss.str()));
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
bool GuiLog::initialiseParams(string const & data)
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-10-06 11:45:53 +00:00
|
|
|
istringstream is(data);
|
|
|
|
Lexer lex(0,0);
|
|
|
|
lex.setStream(is);
|
|
|
|
|
|
|
|
string logtype, logfile;
|
|
|
|
lex >> logtype;
|
|
|
|
if (lex) {
|
|
|
|
lex.next(true);
|
|
|
|
logfile = lex.getString();
|
|
|
|
}
|
|
|
|
if (!lex)
|
|
|
|
// Parsing of the data failed.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (logtype == "latex")
|
|
|
|
type_ = LatexLog;
|
|
|
|
else if (logtype == "literate")
|
|
|
|
type_ = LiterateLog;
|
|
|
|
else if (logtype == "lyx2lyx")
|
|
|
|
type_ = Lyx2lyxLog;
|
|
|
|
else if (logtype == "vc")
|
|
|
|
type_ = VCLog;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
logfile_ = FileName(logfile);
|
|
|
|
return true;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
void GuiLog::clearParams()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 11:45:53 +00:00
|
|
|
logfile_.erase();
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
docstring GuiLog::title() const
|
|
|
|
{
|
|
|
|
switch (type_) {
|
|
|
|
case LatexLog:
|
|
|
|
return _("LaTeX Log");
|
|
|
|
case LiterateLog:
|
|
|
|
return _("Literate Programming Build Log");
|
|
|
|
case Lyx2lyxLog:
|
|
|
|
return _("lyx2lyx Error Log");
|
|
|
|
case VCLog:
|
|
|
|
return _("Version Control Log");
|
|
|
|
default:
|
|
|
|
return docstring();
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
|
|
|
|
void GuiLog::getContents(std::ostream & ss) const
|
|
|
|
{
|
|
|
|
std::ifstream in(logfile_.toFilesystemEncoding().c_str());
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
// Our caller interprets the file contents as UTF8, but is that
|
|
|
|
// correct?
|
|
|
|
if (in) {
|
|
|
|
ss << in.rdbuf();
|
|
|
|
success = ss.good();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (type_) {
|
|
|
|
case LatexLog:
|
|
|
|
ss << to_utf8(_("No LaTeX log file found."));
|
|
|
|
break;
|
|
|
|
case LiterateLog:
|
|
|
|
ss << to_utf8(_("No literate programming build log file found."));
|
|
|
|
break;
|
|
|
|
case Lyx2lyxLog:
|
|
|
|
ss << to_utf8(_("No lyx2lyx error log file found."));
|
|
|
|
break;
|
|
|
|
case VCLog:
|
|
|
|
ss << to_utf8(_("No version control log file found."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 18:15:30 +00:00
|
|
|
void GuiLog::on_copyPB_clicked()
|
|
|
|
{
|
|
|
|
qApp->clipboard()->setText(logTB->toPlainText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 11:45:53 +00:00
|
|
|
Dialog * createGuiLog(LyXView & lv) { return new GuiLog(lv); }
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-03-26 04:25:49 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiLog_moc.cpp"
|