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 // This dialog is only a fallback for Qt < 5.2, which does not feature
36 // QMessageBox::setCheckBox() yet. Note that it has issues with line
37 // breaking and size, in particular with html.
38 #if QT_VERSION < 0x050200
39 class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi
42 GuiToggleWarningDialog(QWidget * parent) : QDialog(parent)
44 Ui::ToggleWarningUi::setupUi(this);
45 QDialog::setModal(true);
51 GuiProgress::GuiProgress()
53 connect(this, SIGNAL(processStarted(QString const &)), SLOT(doProcessStarted(QString const &)));
54 connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(QString const &)));
55 connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &)));
56 connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &)));
57 connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages()));
60 connect(this, SIGNAL(warning(QString const &, QString const &)),
61 SLOT(doWarning(QString const &, QString const &)));
62 connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)),
63 SLOT(doToggleWarning(QString const &, QString const &, QString const &)));
64 connect(this, SIGNAL(error(QString const &, QString const &, QString const &)),
65 SLOT(doError(QString const &, QString const &, QString const &)));
66 connect(this, SIGNAL(information(QString const &, QString const &)),
67 SLOT(doInformation(QString const &, QString const &)));
68 connect(this, SIGNAL(triggerFlush()),
69 SLOT(startFlushing()));
71 flushDelay_.setInterval(200);
72 flushDelay_.setSingleShot(true);
73 connect(&flushDelay_, SIGNAL(timeout()), this, SLOT(updateWithLyXErr()));
77 int GuiProgress::prompt(docstring const & title, docstring const & question,
78 int default_button, int cancel_button,
79 docstring const & b1, docstring const & b2)
81 return Alert::prompt(title, question, default_button, cancel_button, b1, b2);
85 QString GuiProgress::currentTime()
87 return QTime::currentTime().toString("hh:mm:ss.zzz");
91 void GuiProgress::doProcessStarted(QString const & cmd)
93 appendText(currentTime() + ": <" + cmd + "> started");
97 void GuiProgress::doProcessFinished(QString const & cmd)
99 appendText(currentTime() + ": <" + cmd + "> done");
103 void GuiProgress::doAppendMessage(QString const & msg)
109 void GuiProgress::doAppendError(QString const & msg)
115 void GuiProgress::doClearMessages()
121 void GuiProgress::startFlushing()
127 void GuiProgress::lyxerrFlush()
133 void GuiProgress::updateWithLyXErr()
135 appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
136 lyxerr_stream_.str("");
140 void GuiProgress::lyxerrConnect()
142 lyxerr.setSecondStream(&lyxerr_stream_);
146 void GuiProgress::lyxerrDisconnect()
148 lyxerr.setSecondStream(0);
152 GuiProgress::~GuiProgress()
158 void GuiProgress::appendText(QString const & text)
161 updateStatusBarMessage(text);
165 void GuiProgress::doWarning(QString const & title, QString const & message)
167 QMessageBox::warning(qApp->focusWidget(), title, message);
171 void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
174 if (settings.value("hidden_warnings/" + msg, false).toBool())
177 // Qt < 5.2 does not feature QMessageBox::setCheckBox() yet,
178 // so we roll our own dialog.
179 #if QT_VERSION < 0x050200
180 GuiToggleWarningDialog * dlg =
181 new GuiToggleWarningDialog(qApp->focusWidget());
183 dlg->setWindowTitle(title);
184 dlg->messageLA->setText(formatted);
185 dlg->dontShowAgainCB->setChecked(false);
187 if (dlg->exec() == QDialog::Accepted)
188 if (dlg->dontShowAgainCB->isChecked())
189 settings.setValue("hidden_warnings/"
192 QCheckBox * dontShowAgainCB = new QCheckBox();
193 dontShowAgainCB->setText(qt_("&Do not show this warning again!"));
194 dontShowAgainCB->setToolTip(qt_("If you check this, LyX will not warn you again in the given case."));
195 QMessageBox box(QMessageBox::Warning, title, formatted,
196 QMessageBox::Ok, qApp->focusWidget());
197 box.setCheckBox(dontShowAgainCB);
198 if (box.exec() == QMessageBox::Ok)
199 if (dontShowAgainCB->isChecked())
200 settings.setValue("hidden_warnings/"
206 void GuiProgress::doError(QString const & title, QString const & message, QString const & details)
208 QMessageBox box(QMessageBox::Critical, title, message, QMessageBox::Ok, qApp->focusWidget());
209 if (!details.isEmpty()) {
210 box.setDetailedText(details);
216 void GuiProgress::doInformation(QString const & title, QString const & message)
218 QMessageBox::information(qApp->focusWidget(), title, message);
222 } // namespace frontend
225 #include "moc_GuiProgress.cpp"