]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgress.cpp
LyXErr and statusbar messages hsould have different routes.
[lyx.git] / src / frontends / qt4 / GuiProgress.cpp
1 // -*- C++ -*-
2 /**
3  * \file GuiProgress.cpp
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Peter Kümmel
8  * \author Pavel Sanda
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiProgress.h"
16 #include "ui_ToggleWarningUi.h"
17
18 #include "qt_helpers.h"
19
20 #include "support/debug.h"
21 #include "support/Systemcall.h"
22
23 #include <QApplication>
24 #include <QTime>
25 #include <QMessageBox>
26 #include <QSettings>
27
28
29 namespace lyx {
30 namespace frontend {
31
32
33 class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi
34 {
35 public:
36         GuiToggleWarningDialog(QWidget * parent) : QDialog(parent)
37         {
38                 Ui::ToggleWarningUi::setupUi(this);
39                 QDialog::setModal(true);
40         }
41 };
42
43
44 GuiProgress::GuiProgress(GuiView * view) : view_(view)
45 {
46         connect(this, SIGNAL(processStarted(QString const &)), SLOT(doProcessStarted(QString const &)));
47         connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(QString const &)));
48         connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &)));
49         connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &)));
50         connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages()));
51         connect(this, SIGNAL(lyxerrFlush()), SLOT(dolyxerrFlush()));
52         
53         // Alert interface
54         connect(this, SIGNAL(warning(QString const &, QString const &)),
55                 SLOT(doWarning(QString const &, QString const &)));
56         connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)),
57                 SLOT(doToggleWarning(QString const &, QString const &, QString const &)));
58         connect(this, SIGNAL(error(QString const &, QString const &)),
59                 SLOT(doError(QString const &, QString const &)));
60         connect(this, SIGNAL(information(QString const &, QString const &)),
61                 SLOT(doInformation(QString const &, QString const &)));
62
63         support::ProgressInterface::setInstance(this);
64 }
65
66
67 void GuiProgress::doProcessStarted(QString const & cmd)
68 {
69         QString time = QTime::currentTime().toString();
70         appendText(time + ": <" + cmd + "> started\n");
71 }
72
73
74 void GuiProgress::doProcessFinished(QString const & cmd)
75 {
76         QString time = QTime::currentTime().toString();
77         appendText(time + ": <" + cmd + "> done\n");
78 }
79
80
81 void GuiProgress::doAppendMessage(QString const & msg)
82 {
83         appendText(msg + "\n");
84 }
85
86
87 void GuiProgress::doAppendError(QString const & msg)
88 {
89         appendText(msg);
90 }
91
92
93 void GuiProgress::doClearMessages()
94 {
95         view_->message(docstring());
96 }
97
98
99 void GuiProgress::dolyxerrFlush()
100 {
101         appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
102         lyxerr_stream_.str("");
103         // give the user a chance to disable debug messages because 
104         // showing Debug::ANY messages completely blocks the GUI
105         QApplication::processEvents();
106 }
107
108
109 void GuiProgress::lyxerrConnect()
110 {
111         lyxerr.setSecond(&lyxerr_stream_);
112 }
113
114
115 void GuiProgress::lyxerrDisconnect()
116 {
117         lyxerr.setSecond(0);
118 }
119
120
121 GuiProgress::~GuiProgress()
122 {
123         lyxerrDisconnect();
124 }
125
126
127 void GuiProgress::appendText(QString const & text)
128 {
129         if (!text.isEmpty())
130                 view_->updateMessage(text);
131 }
132
133
134 void GuiProgress::doWarning(QString const & title, QString const & message)
135 {
136         QMessageBox::warning(qApp->focusWidget(), title, message);
137 }
138
139
140 void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
141 {
142         QSettings settings;
143         if (settings.value("hidden_warnings/" + msg, false).toBool())
144                         return;
145
146         GuiToggleWarningDialog * dlg =
147                 new GuiToggleWarningDialog(qApp->focusWidget());
148
149         dlg->setWindowTitle(title);
150         dlg->messageLA->setText(formatted);
151         dlg->dontShowAgainCB->setChecked(false);
152
153         if (dlg->exec() == QDialog::Accepted)
154                 if (dlg->dontShowAgainCB->isChecked())
155                         settings.setValue("hidden_warnings/"
156                                 + msg, true);
157 }
158
159
160 void GuiProgress::doError(QString const & title, QString const & message)
161 {
162         QMessageBox::critical(qApp->focusWidget(), title, message);
163 }
164
165
166 void GuiProgress::doInformation(QString const & title, QString const & message)
167 {
168         QMessageBox::information(qApp->focusWidget(), title, message);
169 }
170
171
172 } // namespace frontend
173 } // namespace lyx
174
175 #include "moc_GuiProgress.cpp"