2009-12-22 10:04:30 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GuiProgressView.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Peter Kümmel
|
2009-12-29 15:05:37 +00:00
|
|
|
* \author Pavel Sanda
|
2010-01-11 07:30:45 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2009-12-22 10:04:30 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiProgressView.h"
|
|
|
|
|
2010-01-10 12:37:50 +00:00
|
|
|
#include "GuiApplication.h"
|
2013-05-21 01:47:16 +00:00
|
|
|
#include "GuiProgress.h"
|
2009-12-22 10:04:30 +00:00
|
|
|
#include "qt_helpers.h"
|
2010-01-10 12:37:50 +00:00
|
|
|
|
2009-12-30 17:15:00 +00:00
|
|
|
#include "FuncRequest.h"
|
2009-12-22 10:04:30 +00:00
|
|
|
|
2009-12-30 17:15:00 +00:00
|
|
|
#include "support/convert.h"
|
2010-01-10 12:37:50 +00:00
|
|
|
#include "support/debug.h"
|
2009-12-30 14:48:47 +00:00
|
|
|
|
2016-06-09 15:09:14 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2009-12-30 14:48:47 +00:00
|
|
|
#include <QCheckBox>
|
2010-01-05 22:32:58 +00:00
|
|
|
#include <QDebug>
|
2010-01-10 12:37:50 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QTime>
|
2009-12-30 14:48:47 +00:00
|
|
|
|
2010-01-04 17:12:50 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace lyx::support;
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
2009-12-28 21:40:14 +00:00
|
|
|
ProgressViewWidget::ProgressViewWidget()
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiProgressView::~GuiProgressView()
|
|
|
|
{
|
|
|
|
delete widget_;
|
|
|
|
}
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
|
2014-03-28 16:51:55 +00:00
|
|
|
namespace{
|
|
|
|
typedef pair<int, QString> DebugMap;
|
|
|
|
typedef vector<DebugMap> DebugVector;
|
|
|
|
|
|
|
|
bool DebugSorter(DebugMap const & a, DebugMap const & b)
|
|
|
|
{
|
|
|
|
return a.second < b.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
|
2010-01-11 07:30:45 +00:00
|
|
|
Qt::WindowFlags flags)
|
2010-01-12 15:35:52 +00:00
|
|
|
: DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags)
|
2009-12-22 10:04:30 +00:00
|
|
|
{
|
2010-05-17 08:15:04 +00:00
|
|
|
eol_last_ = true;
|
2012-10-26 00:42:27 +00:00
|
|
|
widget_ = new ProgressViewWidget;
|
2010-01-12 16:21:50 +00:00
|
|
|
widget_->setMinimumHeight(150);
|
2010-01-13 21:45:48 +00:00
|
|
|
widget_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored,
|
|
|
|
QSizePolicy::Expanding);
|
2010-01-07 16:39:17 +00:00
|
|
|
widget_->adjustSize();
|
2009-12-28 21:40:14 +00:00
|
|
|
setWidget(widget_);
|
2009-12-22 10:04:30 +00:00
|
|
|
|
2016-04-15 09:49:04 +00:00
|
|
|
widget_->outTE->setFont(guiApp->typewriterSystemFont());
|
2010-01-03 17:26:46 +00:00
|
|
|
widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
|
2009-12-28 22:02:41 +00:00
|
|
|
|
2010-01-11 07:30:45 +00:00
|
|
|
connect(widget_->debugNoneRB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(debugSelectionChanged()));
|
|
|
|
connect(widget_->debugSelectedRB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(debugSelectionChanged()));
|
|
|
|
connect(widget_->debugAnyRB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(debugSelectionChanged()));
|
|
|
|
widget_->debugMessagesTW->setEnabled(false);
|
|
|
|
widget_->debugNoneRB->setChecked(true);
|
2010-01-05 22:32:58 +00:00
|
|
|
|
|
|
|
// ignore Debug::NONE and Debug::ANY
|
|
|
|
int const level_count = Debug::levelCount() - 1;
|
2014-03-28 16:51:55 +00:00
|
|
|
DebugVector dmap;
|
|
|
|
for (int i = 1 ; i < level_count; i++) {
|
|
|
|
Debug::Type const level = Debug::value(i);
|
2016-05-29 22:33:12 +00:00
|
|
|
QString const desc =
|
|
|
|
toqstr(from_ascii(Debug::name(level) + " - "))
|
|
|
|
+ qt_(Debug::description(level));
|
2014-03-28 16:51:55 +00:00
|
|
|
dmap.push_back(DebugMap(level, desc));
|
|
|
|
}
|
|
|
|
sort(dmap.begin(), dmap.end(), DebugSorter);
|
|
|
|
|
2010-01-11 07:30:45 +00:00
|
|
|
widget_->debugMessagesTW->setColumnCount(2);
|
|
|
|
widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
|
2010-01-13 21:45:44 +00:00
|
|
|
widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
|
2014-03-28 16:51:55 +00:00
|
|
|
|
|
|
|
DebugVector::const_iterator dit = dmap.begin();
|
|
|
|
DebugVector::const_iterator const den = dmap.end();
|
|
|
|
for (; dit != den; ++dit) {
|
2015-09-20 08:42:35 +00:00
|
|
|
QTreeWidgetItem * item = new QTreeWidgetItem(widget_->debugMessagesTW);
|
2014-03-28 16:51:55 +00:00
|
|
|
item->setText(0, dit->second);
|
|
|
|
item->setData(0, Qt::UserRole, int(dit->first));
|
2010-01-11 07:30:45 +00:00
|
|
|
item->setText(1, qt_("No"));
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
2010-01-11 07:30:45 +00:00
|
|
|
widget_->debugMessagesTW->resizeColumnToContents(0);
|
2010-01-13 21:45:44 +00:00
|
|
|
widget_->debugMessagesTW->resizeColumnToContents(1);
|
2010-01-11 07:30:45 +00:00
|
|
|
connect(widget_->debugMessagesTW,
|
|
|
|
SIGNAL(itemActivated(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(debugMessageActivated(QTreeWidgetItem *, int)));
|
|
|
|
|
2010-01-04 17:12:50 +00:00
|
|
|
GuiProgress * progress =
|
|
|
|
dynamic_cast<GuiProgress *>(ProgressInterface::instance());
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
if (progress) {
|
2010-01-04 17:12:50 +00:00
|
|
|
connect(progress, SIGNAL(processStarted(QString const &)),
|
|
|
|
this, SLOT(appendText(QString const &)));
|
|
|
|
//connect(progress, SIGNAL(processFinished(QString const &)),
|
|
|
|
// this, SLOT(appendText(QString const &)));
|
|
|
|
connect(progress, SIGNAL(appendMessage(QString const &)),
|
|
|
|
this, SLOT(appendText(QString const &)));
|
|
|
|
connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
|
2010-06-03 21:24:20 +00:00
|
|
|
this, SLOT(appendLyXErrText(QString const &)), Qt::QueuedConnection);
|
2010-01-04 17:12:50 +00:00
|
|
|
connect(progress, SIGNAL(appendError(QString const &)),
|
|
|
|
this, SLOT(appendText(QString const &)));
|
2009-12-22 10:33:01 +00:00
|
|
|
connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
|
2009-12-29 15:05:37 +00:00
|
|
|
progress->lyxerrConnect();
|
2009-12-22 10:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-11 07:30:45 +00:00
|
|
|
void GuiProgressView::debugMessageActivated(QTreeWidgetItem * item, int)
|
|
|
|
{
|
|
|
|
if (item == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString const no = qt_("No");
|
|
|
|
QString const yes = qt_("Yes");
|
|
|
|
|
|
|
|
bool selected = (item->text(1) == yes);
|
|
|
|
item->setText(1, selected ? no : yes);
|
|
|
|
|
|
|
|
levelChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-30 14:48:47 +00:00
|
|
|
void GuiProgressView::levelChanged()
|
2009-12-29 15:05:37 +00:00
|
|
|
{
|
2009-12-30 14:48:47 +00:00
|
|
|
int level = Debug::NONE;
|
2010-01-11 07:30:45 +00:00
|
|
|
QTreeWidgetItemIterator it(widget_->debugMessagesTW);
|
|
|
|
while (*it) {
|
|
|
|
if ((*it)->text(1) == qt_("Yes"))
|
|
|
|
level |= (*it)->data(0, Qt::UserRole).toInt();
|
|
|
|
++it;
|
2009-12-30 14:48:47 +00:00
|
|
|
}
|
2010-01-04 17:12:50 +00:00
|
|
|
dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
|
2010-01-05 22:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-11 07:30:45 +00:00
|
|
|
void GuiProgressView::debugSelectionChanged()
|
2010-01-05 22:32:58 +00:00
|
|
|
{
|
2010-01-11 07:30:45 +00:00
|
|
|
int level = Debug::NONE;
|
|
|
|
if (widget_->debugAnyRB->isChecked())
|
|
|
|
level = Debug::ANY;
|
|
|
|
else if (widget_->debugSelectedRB->isChecked()) {
|
|
|
|
widget_->debugMessagesTW->setEnabled(true);
|
2010-01-05 22:32:58 +00:00
|
|
|
levelChanged();
|
2010-01-11 07:30:45 +00:00
|
|
|
return;
|
2010-01-05 22:32:58 +00:00
|
|
|
}
|
2010-02-06 14:38:02 +00:00
|
|
|
QTreeWidgetItemIterator it(widget_->debugMessagesTW);
|
|
|
|
while (*it) {
|
|
|
|
(*it)->setText(1, level == Debug::NONE ?
|
|
|
|
qt_("No") : qt_("Yes"));
|
|
|
|
++it;
|
|
|
|
}
|
2010-01-11 07:30:45 +00:00
|
|
|
widget_->debugMessagesTW->setEnabled(false);
|
|
|
|
dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
void GuiProgressView::clearText()
|
|
|
|
{
|
2010-05-16 22:02:15 +00:00
|
|
|
if (widget_->autoClearCB->isChecked()){
|
2009-12-28 21:40:20 +00:00
|
|
|
widget_->outTE->clear();
|
2010-05-17 08:15:04 +00:00
|
|
|
eol_last_ = true;
|
2010-05-16 22:02:15 +00:00
|
|
|
}
|
2009-12-22 10:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-03 16:30:54 +00:00
|
|
|
void GuiProgressView::appendLyXErrText(QString const & text)
|
|
|
|
{
|
2016-08-17 20:32:14 +00:00
|
|
|
// Skip verbose messages meant for the terminal
|
|
|
|
if (text.startsWith("\nRunning:"))
|
|
|
|
return;
|
|
|
|
|
2010-01-11 18:04:51 +00:00
|
|
|
widget_->outTE->moveCursor(QTextCursor::End);
|
2010-01-03 16:30:54 +00:00
|
|
|
widget_->outTE->insertPlainText(text);
|
|
|
|
widget_->outTE->ensureCursorVisible();
|
2010-05-17 08:15:04 +00:00
|
|
|
eol_last_ = false;
|
2010-01-03 16:54:23 +00:00
|
|
|
// Give the user a chance to disable debug messages because
|
|
|
|
// showing Debug::ANY messages completely blocks the GUI.
|
|
|
|
// Text is not always send as the whole line, so we must be
|
|
|
|
// careful about eolns.
|
2010-01-15 10:53:56 +00:00
|
|
|
// WARNING: processing events could cause crashes!
|
|
|
|
// TODO: find a better solution
|
2010-05-16 22:02:15 +00:00
|
|
|
if (text.endsWith("\n")) {
|
2010-05-17 08:15:04 +00:00
|
|
|
eol_last_ = true;
|
2010-01-03 16:54:23 +00:00
|
|
|
QApplication::processEvents();
|
2010-05-16 22:02:15 +00:00
|
|
|
}
|
2010-01-03 16:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
void GuiProgressView::appendText(QString const & text)
|
|
|
|
{
|
2010-01-03 17:40:40 +00:00
|
|
|
if (text.isEmpty() || !widget_->sbarCB->isChecked())
|
2009-12-22 10:33:01 +00:00
|
|
|
return;
|
2010-03-07 11:55:14 +00:00
|
|
|
QString str = GuiProgress::currentTime();
|
2010-01-03 16:30:54 +00:00
|
|
|
str += ": " + text;
|
2010-05-17 08:15:04 +00:00
|
|
|
if (!eol_last_)
|
2010-05-16 22:02:15 +00:00
|
|
|
str = "\n" + str;
|
2010-05-17 08:15:04 +00:00
|
|
|
eol_last_ = text.endsWith("\n");
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2010-01-11 18:04:51 +00:00
|
|
|
widget_->outTE->moveCursor(QTextCursor::End);
|
2010-01-03 16:30:54 +00:00
|
|
|
widget_->outTE->insertPlainText(str);
|
2009-12-28 21:40:14 +00:00
|
|
|
widget_->outTE->ensureCursorVisible();
|
2009-12-22 10:04:30 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2009-12-28 21:55:50 +00:00
|
|
|
void GuiProgressView::saveSession() const
|
|
|
|
{
|
|
|
|
Dialog::saveSession();
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
|
2010-01-03 17:40:40 +00:00
|
|
|
settings.setValue(
|
|
|
|
sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
|
2009-12-28 21:55:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2009-12-28 21:55:50 +00:00
|
|
|
void GuiProgressView::restoreSession()
|
|
|
|
{
|
|
|
|
DockView::restoreSession();
|
|
|
|
QSettings settings;
|
|
|
|
widget_->autoClearCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/autoclear", true).toBool());
|
2010-01-03 17:40:40 +00:00
|
|
|
widget_->sbarCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
|
2009-12-28 21:55:50 +00:00
|
|
|
}
|
2009-12-22 10:04:30 +00:00
|
|
|
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
void GuiProgressView::showEvent(QShowEvent*)
|
|
|
|
{
|
2010-01-04 17:12:50 +00:00
|
|
|
ProgressInterface::instance()->lyxerrConnect();
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgressView::hideEvent(QHideEvent*)
|
|
|
|
{
|
2010-01-04 17:12:50 +00:00
|
|
|
ProgressInterface::instance()->lyxerrDisconnect();
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
Dialog * createGuiProgressView(GuiView & guiview)
|
|
|
|
{
|
|
|
|
return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2009-12-25 16:52:03 +00:00
|
|
|
#include "moc_GuiProgressView.cpp"
|