3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
17 #include "GuiApplication.h"
18 #include "qt_helpers.h"
21 #include "support/docstring.h"
22 #include "support/FileName.h"
23 #include "support/gettext.h"
25 #include <QTextBrowser>
26 #include <QSyntaxHighlighter>
33 using namespace lyx::support;
39 // Regular expressions needed at several places
40 // FIXME: These regexes are incomplete. It would be good if we could collect those used in LaTeX::scanLogFile
41 // and LaTeX::scanBlgFile and re-use them here!(spitz, 2013-05-27)
43 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|.*> INFO - |\\(|\\\\).*$");
45 QRegExp exprWarning("^(LaTeX Warning|LaTeX Font Warning|Package [\\w\\.]+ Warning|Class \\w+ Warning|Warning--|.*> WARN - ).*$");
47 QRegExp exprError("^(!|.*---line [0-9]+ of file|.*> FATAL - |.*> ERROR - ).*$");
50 /////////////////////////////////////////////////////////////////////
54 ////////////////////////////////////////////////////////////////////
56 class LogHighlighter : public QSyntaxHighlighter
59 LogHighlighter(QTextDocument * parent);
62 void highlightBlock(QString const & text);
65 QTextCharFormat infoFormat;
66 QTextCharFormat warningFormat;
67 QTextCharFormat errorFormat;
72 LogHighlighter::LogHighlighter(QTextDocument * parent)
73 : QSyntaxHighlighter(parent)
75 infoFormat.setForeground(Qt::darkGray);
76 warningFormat.setForeground(Qt::darkBlue);
77 errorFormat.setForeground(Qt::red);
81 void LogHighlighter::highlightBlock(QString const & text)
84 int index = exprInfo.indexIn(text);
86 int length = exprInfo.matchedLength();
87 setFormat(index, length, infoFormat);
88 index = exprInfo.indexIn(text, index + length);
91 index = exprWarning.indexIn(text);
93 int length = exprWarning.matchedLength();
94 setFormat(index, length, warningFormat);
95 index = exprWarning.indexIn(text, index + length);
98 index = exprError.indexIn(text);
100 int length = exprError.matchedLength();
101 setFormat(index, length, errorFormat);
102 index = exprError.indexIn(text, index + length);
107 /////////////////////////////////////////////////////////////////////
111 /////////////////////////////////////////////////////////////////////
113 GuiLog::GuiLog(GuiView & lv)
114 : GuiDialog(lv, "log", qt_("LaTeX Log")), type_(LatexLog)
118 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
119 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
120 connect(findPB, SIGNAL(clicked()), this, SLOT(find()));
121 // FIXME: find via returnPressed() does not work!
122 connect(findLE, SIGNAL(returnPressed()), this, SLOT(find()));
123 connect(logTypeCO, SIGNAL(activated(int)),
124 this, SLOT(typeChanged(int)));
126 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
128 // set syntax highlighting
129 highlighter = new LogHighlighter(logTB->document());
131 logTB->setReadOnly(true);
132 QFont font(guiApp->typewriterFontName());
133 font.setKerning(false);
134 font.setFixedPitch(true);
135 font.setStyleHint(QFont::TypeWriter);
136 logTB->setFont(font);
140 void GuiLog::updateContents()
142 setTitle(toqstr(title()));
147 logTB->setPlainText(toqstr(ss.str()));
149 nextErrorPB->setEnabled(contains(exprError));
150 nextWarningPB->setEnabled(contains(exprWarning));
154 void GuiLog::typeChanged(int i)
157 fromqstr(logTypeCO->itemData(i).toString());
161 else if (type == "bibtex")
163 else if (type == "index")
167 logfile_.changeExtension(ext);
175 logTB->find(findLE->text());
179 void GuiLog::on_nextErrorPB_clicked()
185 void GuiLog::on_nextWarningPB_clicked()
191 void GuiLog::goTo(QRegExp const & exp) const
193 QTextCursor const newc =
194 logTB->document()->find(exp, logTB->textCursor());
195 logTB->setTextCursor(newc);
199 bool GuiLog::contains(QRegExp const & exp) const
201 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
205 bool GuiLog::initialiseParams(string const & data)
207 istringstream is(data);
211 string logtype, logfile;
215 logfile = lex.getString();
218 // Parsing of the data failed.
221 logTypeCO->setEnabled(logtype == "latex");
224 FileName log(logfile);
226 if (logtype == "latex") {
228 logTypeCO->addItem(qt_("LaTeX"), toqstr(logtype));
230 tmp.changeExtension("blg");
232 logTypeCO->addItem(qt_("BibTeX"), QString("bibtex"));
233 tmp.changeExtension("ilg");
235 logTypeCO->addItem(qt_("Index"), QString("index"));
236 // FIXME: not sure "literate" still works.
237 } else if (logtype == "literate") {
239 logTypeCO->addItem(qt_("Literate"), toqstr(logtype));
240 } else if (logtype == "lyx2lyx") {
242 logTypeCO->addItem(qt_("LyX2LyX"), toqstr(logtype));
243 } else if (logtype == "vc") {
245 logTypeCO->addItem(qt_("Version Control"), toqstr(logtype));
257 void GuiLog::clearParams()
263 docstring GuiLog::title() const
267 return _("LaTeX Log");
269 return _("Literate Programming Build Log");
271 return _("lyx2lyx Error Log");
273 return _("Version Control Log");
280 void GuiLog::getContents(ostream & ss) const
282 ifstream in(logfile_.toFilesystemEncoding().c_str());
284 bool success = false;
287 // Our caller interprets the file contents as UTF8, but is that
299 ss << to_utf8(_("Log file not found."));
302 ss << to_utf8(_("No literate programming build log file found."));
305 ss << to_utf8(_("No lyx2lyx error log file found."));
308 ss << to_utf8(_("No version control log file found."));
314 void GuiLog::on_copyPB_clicked()
316 qApp->clipboard()->setText(logTB->toPlainText());
320 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
323 } // namespace frontend
326 #include "moc_GuiLog.cpp"