]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgress.cpp
Qt 5.6 renames signal QProcesss::error()
[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 "frontends/alert.h"
21
22 #include "support/debug.h"
23 #include "support/Systemcall.h"
24
25 #include <QApplication>
26 #include <QTime>
27 #include <QMessageBox>
28 #include <QSettings>
29
30
31 namespace lyx {
32 namespace frontend {
33
34
35 class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi
36 {
37 public:
38         GuiToggleWarningDialog(QWidget * parent) : QDialog(parent)
39         {
40                 Ui::ToggleWarningUi::setupUi(this);
41                 QDialog::setModal(true);
42         }
43 };
44
45
46 GuiProgress::GuiProgress()
47 {
48         connect(this, SIGNAL(processStarted(QString const &)), SLOT(doProcessStarted(QString const &)));
49         connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(QString const &)));
50         connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &)));
51         connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &)));
52         connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages()));
53         
54         // Alert interface
55         connect(this, SIGNAL(warning(QString const &, QString const &)),
56                 SLOT(doWarning(QString const &, QString const &)));
57         connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)),
58                 SLOT(doToggleWarning(QString const &, QString const &, QString const &)));
59 #if QT_VERSION >= 0x050600
60         connect(this, SIGNAL(errorOccurred(QString const &, QString const &, QString const &)),
61 #else
62         connect(this, SIGNAL(error(QString const &, QString const &, QString const &)),
63 #endif
64                 SLOT(doError(QString const &, QString const &, QString const &)));
65         connect(this, SIGNAL(information(QString const &, QString const &)),
66                 SLOT(doInformation(QString const &, QString const &)));
67         connect(this, SIGNAL(triggerFlush()),
68                 SLOT(startFlushing()));
69
70         flushDelay_.setInterval(200);
71         flushDelay_.setSingleShot(true);
72         connect(&flushDelay_, SIGNAL(timeout()), this, SLOT(updateWithLyXErr()));
73 }
74
75
76 int GuiProgress::prompt(docstring const & title, docstring const & question,
77                         int default_button, int cancel_button,
78                         docstring const & b1, docstring const & b2)
79 {
80         return Alert::prompt(title, question, default_button, cancel_button, b1, b2);
81 }
82
83
84 QString GuiProgress::currentTime()
85 {
86         return QTime::currentTime().toString("hh:mm:ss.zzz");
87 }
88
89
90 void GuiProgress::doProcessStarted(QString const & cmd)
91 {
92         appendText(currentTime() + ": <" + cmd + "> started");
93 }
94
95
96 void GuiProgress::doProcessFinished(QString const & cmd)
97 {
98         appendText(currentTime() + ": <" + cmd + "> done");
99 }
100
101
102 void GuiProgress::doAppendMessage(QString const & msg)
103 {
104         appendText(msg);
105 }
106
107
108 void GuiProgress::doAppendError(QString const & msg)
109 {
110         appendText(msg);
111 }
112
113
114 void GuiProgress::doClearMessages()
115 {
116         clearMessageText();
117 }
118
119
120 void GuiProgress::startFlushing()
121 {
122         flushDelay_.start();
123 }
124
125
126 void GuiProgress::lyxerrFlush()
127 {
128         triggerFlush();
129 }
130
131
132 void GuiProgress::updateWithLyXErr()
133 {
134         appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
135         lyxerr_stream_.str("");
136 }
137
138
139 void GuiProgress::lyxerrConnect()
140 {
141         lyxerr.setSecondStream(&lyxerr_stream_);
142 }
143
144
145 void GuiProgress::lyxerrDisconnect()
146 {
147         lyxerr.setSecondStream(0);
148 }
149
150
151 GuiProgress::~GuiProgress()
152 {
153         lyxerrDisconnect();
154 }
155
156
157 void GuiProgress::appendText(QString const & text)
158 {
159         if (!text.isEmpty())
160                 updateStatusBarMessage(text);
161 }
162
163
164 void GuiProgress::doWarning(QString const & title, QString const & message)
165 {
166         QMessageBox::warning(qApp->focusWidget(), title, message);
167 }
168
169
170 void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
171 {
172         QSettings settings;
173         if (settings.value("hidden_warnings/" + msg, false).toBool())
174                         return;
175
176         GuiToggleWarningDialog * dlg =
177                 new GuiToggleWarningDialog(qApp->focusWidget());
178
179         dlg->setWindowTitle(title);
180         dlg->messageLA->setText(formatted);
181         dlg->dontShowAgainCB->setChecked(false);
182
183         if (dlg->exec() == QDialog::Accepted)
184                 if (dlg->dontShowAgainCB->isChecked())
185                         settings.setValue("hidden_warnings/"
186                                 + msg, true);
187 }
188
189
190 void GuiProgress::doError(QString const & title, QString const & message, QString const & details)
191 {
192         QMessageBox box(QMessageBox::Critical, title, message, QMessageBox::Ok, qApp->focusWidget());
193         if (!details.isEmpty()) {
194                 box.setDetailedText(details);
195         }
196         box.exec();
197 }
198
199
200 void GuiProgress::doInformation(QString const & title, QString const & message)
201 {
202         QMessageBox::information(qApp->focusWidget(), title, message);
203 }
204
205
206 } // namespace frontend
207 } // namespace lyx
208
209 #include "moc_GuiProgress.cpp"