3 * \file GuiProgress.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
15 #include "GuiProgress.h"
16 #include "ui_ToggleWarningUi.h"
18 #include "qt_helpers.h"
20 #include "frontends/alert.h"
22 #include "support/debug.h"
23 #include "support/Systemcall.h"
25 #include <QApplication>
27 #include <QMessageBox>
35 // FIXME: This dialog has issues with line breaking and size, in particular with
36 // html. But it could easily be reimplemented as a QMessageBox using
37 // QMessageBox::setCheckBox() available starting from Qt 5.2
38 class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi
41 GuiToggleWarningDialog(QWidget * parent) : QDialog(parent)
43 Ui::ToggleWarningUi::setupUi(this);
44 QDialog::setModal(true);
49 GuiProgress::GuiProgress()
51 connect(this, SIGNAL(processStarted(QString const &)), SLOT(doProcessStarted(QString const &)));
52 connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(QString const &)));
53 connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &)));
54 connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &)));
55 connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages()));
58 connect(this, SIGNAL(warning(QString const &, QString const &)),
59 SLOT(doWarning(QString const &, QString const &)));
60 connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)),
61 SLOT(doToggleWarning(QString const &, QString const &, QString const &)));
62 connect(this, SIGNAL(error(QString const &, QString const &, QString const &)),
63 SLOT(doError(QString const &, QString const &, QString const &)));
64 connect(this, SIGNAL(information(QString const &, QString const &)),
65 SLOT(doInformation(QString const &, QString const &)));
66 connect(this, SIGNAL(triggerFlush()),
67 SLOT(startFlushing()));
69 flushDelay_.setInterval(200);
70 flushDelay_.setSingleShot(true);
71 connect(&flushDelay_, SIGNAL(timeout()), this, SLOT(updateWithLyXErr()));
75 int GuiProgress::prompt(docstring const & title, docstring const & question,
76 int default_button, int cancel_button,
77 docstring const & b1, docstring const & b2)
79 return Alert::prompt(title, question, default_button, cancel_button, b1, b2);
83 QString GuiProgress::currentTime()
85 return QTime::currentTime().toString("hh:mm:ss.zzz");
89 void GuiProgress::doProcessStarted(QString const & cmd)
91 appendText(currentTime() + ": <" + cmd + "> started");
95 void GuiProgress::doProcessFinished(QString const & cmd)
97 appendText(currentTime() + ": <" + cmd + "> done");
101 void GuiProgress::doAppendMessage(QString const & msg)
107 void GuiProgress::doAppendError(QString const & msg)
113 void GuiProgress::doClearMessages()
119 void GuiProgress::startFlushing()
125 void GuiProgress::lyxerrFlush()
131 void GuiProgress::updateWithLyXErr()
133 appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
134 lyxerr_stream_.str("");
138 void GuiProgress::lyxerrConnect()
140 lyxerr.setSecondStream(&lyxerr_stream_);
144 void GuiProgress::lyxerrDisconnect()
146 lyxerr.setSecondStream(0);
150 GuiProgress::~GuiProgress()
156 void GuiProgress::appendText(QString const & text)
159 updateStatusBarMessage(text);
163 void GuiProgress::doWarning(QString const & title, QString const & message)
165 QMessageBox::warning(qApp->focusWidget(), title, message);
169 void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
172 if (settings.value("hidden_warnings/" + msg, false).toBool())
175 GuiToggleWarningDialog * dlg =
176 new GuiToggleWarningDialog(qApp->focusWidget());
178 dlg->setWindowTitle(title);
179 dlg->messageLA->setText(formatted);
180 dlg->dontShowAgainCB->setChecked(false);
182 if (dlg->exec() == QDialog::Accepted)
183 if (dlg->dontShowAgainCB->isChecked())
184 settings.setValue("hidden_warnings/"
189 void GuiProgress::doError(QString const & title, QString const & message, QString const & details)
191 QMessageBox box(QMessageBox::Critical, title, message, QMessageBox::Ok, qApp->focusWidget());
192 if (!details.isEmpty()) {
193 box.setDetailedText(details);
199 void GuiProgress::doInformation(QString const & title, QString const & message)
201 QMessageBox::information(qApp->focusWidget(), title, message);
205 } // namespace frontend
208 #include "moc_GuiProgress.cpp"