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