3 * \file GuiProgressView.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * \author Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
16 #include "GuiProgressView.h"
18 #include "GuiApplication.h"
19 #include "GuiProgress.h"
20 #include "qt_helpers.h"
22 #include "FuncRequest.h"
24 #include "support/convert.h"
25 #include "support/debug.h"
35 using namespace lyx::support;
41 ProgressViewWidget::ProgressViewWidget()
47 GuiProgressView::~GuiProgressView()
54 typedef pair<Debug::base_type, QString> DebugMap;
55 typedef vector<DebugMap> DebugVector;
57 bool DebugSorter(DebugMap const & a, DebugMap const & b)
59 return a.second < b.second;
64 GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
65 Qt::WindowFlags flags)
66 : DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags)
69 widget_ = new ProgressViewWidget;
70 widget_->setMinimumHeight(150);
71 widget_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored,
72 QSizePolicy::Expanding);
73 widget_->adjustSize();
76 widget_->outTE->setFont(guiApp->typewriterSystemFont());
77 widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
79 connect(widget_->debugNoneRB, SIGNAL(clicked()),
80 this, SLOT(debugSelectionChanged()));
81 connect(widget_->debugSelectedRB, SIGNAL(clicked()),
82 this, SLOT(debugSelectionChanged()));
83 connect(widget_->debugAnyRB, SIGNAL(clicked()),
84 this, SLOT(debugSelectionChanged()));
85 widget_->debugMessagesTW->setEnabled(false);
86 widget_->debugNoneRB->setChecked(true);
88 int const level_count = Debug::levelCount();
90 for (int i = 0 ; i < level_count; i++) {
91 Debug::Type const level = Debug::value(i);
92 string const dbgname = Debug::realName(i);
94 if (dbgname == "any" || dbgname == "all"
95 || dbgname == "none" || dbgname == "latex")
98 toqstr(from_ascii(dbgname + " - "))
99 + qt_(Debug::description(level));
100 dmap.push_back(DebugMap(level, desc));
102 sort(dmap.begin(), dmap.end(), DebugSorter);
104 widget_->debugMessagesTW->setColumnCount(2);
105 widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
106 widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
108 DebugVector::const_iterator dit = dmap.begin();
109 DebugVector::const_iterator const den = dmap.end();
110 for (; dit != den; ++dit) {
111 QTreeWidgetItem * item = new QTreeWidgetItem(widget_->debugMessagesTW);
112 item->setText(0, dit->second);
113 item->setData(0, Qt::UserRole, dit->first);
114 item->setText(1, qt_("No"));
116 widget_->debugMessagesTW->resizeColumnToContents(0);
117 widget_->debugMessagesTW->resizeColumnToContents(1);
118 connect(widget_->debugMessagesTW,
119 SIGNAL(itemActivated(QTreeWidgetItem *, int)),
120 this, SLOT(debugMessageActivated(QTreeWidgetItem *, int)));
122 GuiProgress * progress =
123 dynamic_cast<GuiProgress *>(ProgressInterface::instance());
126 connect(progress, SIGNAL(processStarted(QString const &)),
127 this, SLOT(appendText(QString const &)));
128 //connect(progress, SIGNAL(processFinished(QString const &)),
129 // this, SLOT(appendText(QString const &)));
130 connect(progress, SIGNAL(appendMessage(QString const &)),
131 this, SLOT(appendText(QString const &)));
132 connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
133 this, SLOT(appendLyXErrText(QString const &)), Qt::QueuedConnection);
134 connect(progress, SIGNAL(appendError(QString const &)),
135 this, SLOT(appendText(QString const &)));
136 connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
137 progress->lyxerrConnect();
142 void GuiProgressView::debugMessageActivated(QTreeWidgetItem * item, int)
147 QString const no = qt_("No");
148 QString const yes = qt_("Yes");
150 bool selected = (item->text(1) == yes);
151 item->setText(1, selected ? no : yes);
157 void GuiProgressView::levelChanged()
159 Debug::base_type level = Debug::NONE;
160 QTreeWidgetItemIterator it(widget_->debugMessagesTW);
162 if ((*it)->text(1) == qt_("Yes")) {
163 level |= (*it)->data(0, Qt::UserRole).toULongLong();
167 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>(level)));
171 void GuiProgressView::debugSelectionChanged()
173 Debug::Type level = Debug::NONE;
174 if (widget_->debugAnyRB->isChecked())
176 else if (widget_->debugSelectedRB->isChecked()) {
177 widget_->debugMessagesTW->setEnabled(true);
181 QTreeWidgetItemIterator it(widget_->debugMessagesTW);
183 (*it)->setText(1, level == Debug::NONE ?
184 qt_("No") : qt_("Yes"));
187 widget_->debugMessagesTW->setEnabled(false);
188 dispatch(FuncRequest(LFUN_DEBUG_LEVEL_SET, convert<string>((int)level)));
192 void GuiProgressView::clearText()
194 if (widget_->autoClearCB->isChecked()){
195 widget_->outTE->clear();
201 void GuiProgressView::appendLyXErrText(QString const & text)
203 // Skip verbose messages meant for the terminal
204 if (text.startsWith("\nRunning:"))
207 widget_->outTE->moveCursor(QTextCursor::End);
208 widget_->outTE->insertPlainText(text);
209 widget_->outTE->ensureCursorVisible();
211 // Give the user a chance to disable debug messages because
212 // showing Debug::ANY messages completely blocks the GUI.
213 // Text is not always send as the whole line, so we must be
214 // careful about eolns.
215 // WARNING: processing events could cause crashes!
216 // TODO: find a better solution
217 if (text.endsWith("\n")) {
219 QApplication::processEvents();
224 void GuiProgressView::appendText(QString const & text)
226 if (text.isEmpty() || !widget_->sbarCB->isChecked())
228 QString str = GuiProgress::currentTime();
232 eol_last_ = text.endsWith("\n");
234 widget_->outTE->moveCursor(QTextCursor::End);
235 widget_->outTE->insertPlainText(str);
236 widget_->outTE->ensureCursorVisible();
240 void GuiProgressView::saveSession(QSettings & settings) const
242 Dialog::saveSession(settings);
244 sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
246 sessionKey() + "/statusbarmsgs", widget_->sbarCB->isChecked());
250 void GuiProgressView::restoreSession()
252 DockView::restoreSession();
254 widget_->autoClearCB->setChecked(
255 settings.value(sessionKey() + "/autoclear", true).toBool());
256 widget_->sbarCB->setChecked(
257 settings.value(sessionKey() + "/statusbarmsgs", true).toBool());
261 void GuiProgressView::showEvent(QShowEvent*)
263 ProgressInterface::instance()->lyxerrConnect();
267 void GuiProgressView::hideEvent(QHideEvent*)
269 ProgressInterface::instance()->lyxerrDisconnect();
273 } // namespace frontend
276 #include "moc_GuiProgressView.cpp"