]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiProgress.cpp
4fa8a134909a80fd80089788f7aa13d54b2ada3d
[features.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 }
62
63
64 void GuiProgress::doProcessStarted(QString const & cmd)
65 {
66         QString time = QTime::currentTime().toString();
67         appendText(time + ": <" + cmd + "> started");
68 }
69
70
71 void GuiProgress::doProcessFinished(QString const & cmd)
72 {
73         QString time = QTime::currentTime().toString();
74         appendText(time + ": <" + cmd + "> done");
75 }
76
77
78 void GuiProgress::doAppendMessage(QString const & msg)
79 {
80         appendText(msg);
81 }
82
83
84 void GuiProgress::doAppendError(QString const & msg)
85 {
86         appendText(msg);
87 }
88
89
90 void GuiProgress::doClearMessages()
91 {
92         Q_EMIT clearMessageText();
93 }
94
95
96 void GuiProgress::lyxerrFlush()
97 {
98         appendLyXErrMessage(toqstr(lyxerr_stream_.str()));
99         lyxerr_stream_.str("");
100 }
101
102
103 void GuiProgress::lyxerrConnect()
104 {
105         lyxerr.setSecond(&lyxerr_stream_);
106 }
107
108
109 void GuiProgress::lyxerrDisconnect()
110 {
111         lyxerr.setSecond(0);
112 }
113
114
115 GuiProgress::~GuiProgress()
116 {
117         lyxerrDisconnect();
118 }
119
120
121 void GuiProgress::appendText(QString const & text)
122 {
123         if (!text.isEmpty())
124                 Q_EMIT updateStatusBarMessage(text);
125 }
126
127
128 void GuiProgress::doWarning(QString const & title, QString const & message)
129 {
130         QMessageBox::warning(qApp->focusWidget(), title, message);
131 }
132
133
134 void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted)
135 {
136         QSettings settings;
137         if (settings.value("hidden_warnings/" + msg, false).toBool())
138                         return;
139
140         GuiToggleWarningDialog * dlg =
141                 new GuiToggleWarningDialog(qApp->focusWidget());
142
143         dlg->setWindowTitle(title);
144         dlg->messageLA->setText(formatted);
145         dlg->dontShowAgainCB->setChecked(false);
146
147         if (dlg->exec() == QDialog::Accepted)
148                 if (dlg->dontShowAgainCB->isChecked())
149                         settings.setValue("hidden_warnings/"
150                                 + msg, true);
151 }
152
153
154 void GuiProgress::doError(QString const & title, QString const & message)
155 {
156         QMessageBox::critical(qApp->focusWidget(), title, message);
157 }
158
159
160 void GuiProgress::doInformation(QString const & title, QString const & message)
161 {
162         QMessageBox::information(qApp->focusWidget(), title, message);
163 }
164
165
166 } // namespace frontend
167 } // namespace lyx
168
169 #include "moc_GuiProgress.cpp"