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