2009-12-20 14:26:55 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GuiProgress.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
|
2009-12-20 14:26:55 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiProgress.h"
|
2009-12-21 11:48:19 +00:00
|
|
|
#include "ui_ToggleWarningUi.h"
|
2009-12-20 14:26:55 +00:00
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2012-02-18 14:16:25 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2009-12-23 15:39:18 +00:00
|
|
|
#include "support/debug.h"
|
2009-12-20 14:26:55 +00:00
|
|
|
#include "support/Systemcall.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
2009-12-21 11:48:19 +00:00
|
|
|
#include <QTime>
|
|
|
|
#include <QMessageBox>
|
2009-12-21 14:52:56 +00:00
|
|
|
#include <QSettings>
|
2009-12-20 14:26:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
2009-12-21 11:48:19 +00:00
|
|
|
class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi
|
2009-12-20 14:26:55 +00:00
|
|
|
{
|
2009-12-21 11:48:19 +00:00
|
|
|
public:
|
|
|
|
GuiToggleWarningDialog(QWidget * parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
Ui::ToggleWarningUi::setupUi(this);
|
|
|
|
QDialog::setModal(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-05 18:07:05 +00:00
|
|
|
GuiProgress::GuiProgress()
|
2009-12-21 11:48:19 +00:00
|
|
|
{
|
2009-12-20 14:26:55 +00:00
|
|
|
connect(this, SIGNAL(processStarted(QString const &)), SLOT(doProcessStarted(QString const &)));
|
2009-12-25 16:52:05 +00:00
|
|
|
connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(QString const &)));
|
2009-12-20 14:26:55 +00:00
|
|
|
connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &)));
|
|
|
|
connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &)));
|
|
|
|
connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages()));
|
2009-12-21 11:48:19 +00:00
|
|
|
|
|
|
|
// Alert interface
|
|
|
|
connect(this, SIGNAL(warning(QString const &, QString const &)),
|
|
|
|
SLOT(doWarning(QString const &, QString const &)));
|
|
|
|
connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)),
|
|
|
|
SLOT(doToggleWarning(QString const &, QString const &, QString const &)));
|
|
|
|
connect(this, SIGNAL(error(QString const &, QString const &)),
|
|
|
|
SLOT(doError(QString const &, QString const &)));
|
|
|
|
connect(this, SIGNAL(information(QString const &, QString const &)),
|
|
|
|
SLOT(doInformation(QString const &, QString const &)));
|
2011-01-15 22:39:46 +00:00
|
|
|
connect(this, SIGNAL(triggerFlush()),
|
|
|
|
SLOT(startFlushing()));
|
2010-06-07 20:25:41 +00:00
|
|
|
|
|
|
|
flushDelay_.setInterval(200);
|
|
|
|
flushDelay_.setSingleShot(true);
|
|
|
|
connect(&flushDelay_, SIGNAL(timeout()), this, SLOT(updateWithLyXErr()));
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-18 14:16:25 +00:00
|
|
|
int GuiProgress::prompt(docstring const & title, docstring const & question,
|
|
|
|
int default_button, int cancel_button,
|
|
|
|
docstring const & b1, docstring const & b2)
|
|
|
|
{
|
|
|
|
return Alert::prompt(title, question, default_button, cancel_button, b1, b2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-07 11:55:14 +00:00
|
|
|
QString GuiProgress::currentTime()
|
|
|
|
{
|
2011-02-15 15:25:16 +00:00
|
|
|
return QTime::currentTime().toString("hh:mm:ss.zzz");
|
2010-03-07 11:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-20 14:26:55 +00:00
|
|
|
void GuiProgress::doProcessStarted(QString const & cmd)
|
|
|
|
{
|
2010-03-07 11:55:14 +00:00
|
|
|
appendText(currentTime() + ": <" + cmd + "> started");
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgress::doProcessFinished(QString const & cmd)
|
|
|
|
{
|
2010-03-07 11:55:14 +00:00
|
|
|
appendText(currentTime() + ": <" + cmd + "> done");
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgress::doAppendMessage(QString const & msg)
|
|
|
|
{
|
2010-01-03 16:54:23 +00:00
|
|
|
appendText(msg);
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgress::doAppendError(QString const & msg)
|
|
|
|
{
|
2009-12-29 15:05:37 +00:00
|
|
|
appendText(msg);
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgress::doClearMessages()
|
|
|
|
{
|
2010-03-08 09:35:10 +00:00
|
|
|
clearMessageText();
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-15 22:39:46 +00:00
|
|
|
void GuiProgress::startFlushing()
|
2010-06-07 20:25:41 +00:00
|
|
|
{
|
|
|
|
flushDelay_.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-15 22:39:46 +00:00
|
|
|
void GuiProgress::lyxerrFlush()
|
|
|
|
{
|
|
|
|
triggerFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 20:25:41 +00:00
|
|
|
void GuiProgress::updateWithLyXErr()
|
2009-12-29 15:05:37 +00:00
|
|
|
{
|
2010-01-03 16:30:54 +00:00
|
|
|
appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
|
2009-12-29 15:05:37 +00:00
|
|
|
lyxerr_stream_.str("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgress::lyxerrConnect()
|
|
|
|
{
|
2010-11-06 00:34:03 +00:00
|
|
|
lyxerr.setSecondStream(&lyxerr_stream_);
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiProgress::lyxerrDisconnect()
|
|
|
|
{
|
2010-11-06 00:34:03 +00:00
|
|
|
lyxerr.setSecondStream(0);
|
2009-12-29 15:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiProgress::~GuiProgress()
|
|
|
|
{
|
|
|
|
lyxerrDisconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-20 14:26:55 +00:00
|
|
|
void GuiProgress::appendText(QString const & text)
|
|
|
|
{
|
2009-12-25 23:30:15 +00:00
|
|
|
if (!text.isEmpty())
|
2010-03-08 09:35:10 +00:00
|
|
|
updateStatusBarMessage(text);
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-21 11:48:19 +00:00
|
|
|
void GuiProgress::doWarning(QString const & title, QString const & message)
|
2009-12-20 14:26:55 +00:00
|
|
|
{
|
2009-12-21 11:48:19 +00:00
|
|
|
QMessageBox::warning(qApp->focusWidget(), title, message);
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-21 11:48:19 +00:00
|
|
|
void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
|
2009-12-20 14:26:55 +00:00
|
|
|
{
|
2009-12-21 11:48:19 +00:00
|
|
|
QSettings settings;
|
|
|
|
if (settings.value("hidden_warnings/" + msg, false).toBool())
|
|
|
|
return;
|
|
|
|
|
|
|
|
GuiToggleWarningDialog * dlg =
|
|
|
|
new GuiToggleWarningDialog(qApp->focusWidget());
|
|
|
|
|
|
|
|
dlg->setWindowTitle(title);
|
|
|
|
dlg->messageLA->setText(formatted);
|
|
|
|
dlg->dontShowAgainCB->setChecked(false);
|
2009-12-20 14:26:55 +00:00
|
|
|
|
2009-12-21 11:48:19 +00:00
|
|
|
if (dlg->exec() == QDialog::Accepted)
|
|
|
|
if (dlg->dontShowAgainCB->isChecked())
|
|
|
|
settings.setValue("hidden_warnings/"
|
|
|
|
+ msg, true);
|
|
|
|
}
|
2009-12-20 14:26:55 +00:00
|
|
|
|
|
|
|
|
2009-12-21 11:48:19 +00:00
|
|
|
void GuiProgress::doError(QString const & title, QString const & message)
|
2009-12-20 14:26:55 +00:00
|
|
|
{
|
2009-12-21 11:48:19 +00:00
|
|
|
QMessageBox::critical(qApp->focusWidget(), title, message);
|
2009-12-20 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-21 11:48:19 +00:00
|
|
|
void GuiProgress::doInformation(QString const & title, QString const & message)
|
|
|
|
{
|
|
|
|
QMessageBox::information(qApp->focusWidget(), title, message);
|
|
|
|
}
|
|
|
|
|
2009-12-20 14:26:55 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2009-12-22 12:00:01 +00:00
|
|
|
#include "moc_GuiProgress.cpp"
|