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