]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiProgress.cpp
Ammend 20addbbf
[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         connect(this, SIGNAL(error(QString const &, QString const &, QString const &)),
60                 SLOT(doError(QString const &, QString const &, QString const &)));
61         connect(this, SIGNAL(information(QString const &, QString const &)),
62                 SLOT(doInformation(QString const &, QString const &)));
63         connect(this, SIGNAL(triggerFlush()),
64                 SLOT(startFlushing()));
65
66         flushDelay_.setInterval(200);
67         flushDelay_.setSingleShot(true);
68         connect(&flushDelay_, SIGNAL(timeout()), this, SLOT(updateWithLyXErr()));
69 }
70
71
72 int GuiProgress::prompt(docstring const & title, docstring const & question,
73                         int default_button, int cancel_button,
74                         docstring const & b1, docstring const & b2)
75 {
76         return Alert::prompt(title, question, default_button, cancel_button, b1, b2);
77 }
78
79
80 QString GuiProgress::currentTime()
81 {
82         return QTime::currentTime().toString("hh:mm:ss.zzz");
83 }
84
85
86 void GuiProgress::doProcessStarted(QString const & cmd)
87 {
88         appendText(currentTime() + ": <" + cmd + "> started");
89 }
90
91
92 void GuiProgress::doProcessFinished(QString const & cmd)
93 {
94         appendText(currentTime() + ": <" + cmd + "> done");
95 }
96
97
98 void GuiProgress::doAppendMessage(QString const & msg)
99 {
100         appendText(msg);
101 }
102
103
104 void GuiProgress::doAppendError(QString const & msg)
105 {
106         appendText(msg);
107 }
108
109
110 void GuiProgress::doClearMessages()
111 {
112         clearMessageText();
113 }
114
115
116 void GuiProgress::startFlushing()
117 {
118         flushDelay_.start();
119 }
120
121
122 void GuiProgress::lyxerrFlush()
123 {
124         triggerFlush();
125 }
126
127
128 void GuiProgress::updateWithLyXErr()
129 {
130         appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
131         lyxerr_stream_.str("");
132 }
133
134
135 void GuiProgress::lyxerrConnect()
136 {
137         lyxerr.setSecondStream(&lyxerr_stream_);
138 }
139
140
141 void GuiProgress::lyxerrDisconnect()
142 {
143         lyxerr.setSecondStream(0);
144 }
145
146
147 GuiProgress::~GuiProgress()
148 {
149         lyxerrDisconnect();
150 }
151
152
153 void GuiProgress::appendText(QString const & text)
154 {
155         if (!text.isEmpty())
156                 updateStatusBarMessage(text);
157 }
158
159
160 void GuiProgress::doWarning(QString const & title, QString const & message)
161 {
162         QMessageBox::warning(qApp->focusWidget(), title, message);
163 }
164
165
166 void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
167 {
168         QSettings settings;
169         if (settings.value("hidden_warnings/" + msg, false).toBool())
170                         return;
171
172         GuiToggleWarningDialog * dlg =
173                 new GuiToggleWarningDialog(qApp->focusWidget());
174
175         dlg->setWindowTitle(title);
176         dlg->messageLA->setText(formatted);
177         dlg->dontShowAgainCB->setChecked(false);
178
179         if (dlg->exec() == QDialog::Accepted)
180                 if (dlg->dontShowAgainCB->isChecked())
181                         settings.setValue("hidden_warnings/"
182                                 + msg, true);
183 }
184
185
186 void GuiProgress::doError(QString const & title, QString const & message, QString const & details)
187 {
188         QMessageBox box(QMessageBox::Critical, title, message, QMessageBox::Ok, qApp->focusWidget());
189         if (!details.isEmpty()) {
190                 box.setDetailedText(details);
191         }
192         box.exec();
193 }
194
195
196 void GuiProgress::doInformation(QString const & title, QString const & message)
197 {
198         QMessageBox::information(qApp->focusWidget(), title, message);
199 }
200
201
202 } // namespace frontend
203 } // namespace lyx
204
205 #include "moc_GuiProgress.cpp"