]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiAbout.cpp
Merge QController into individual dialogs. Also various cleanup
[lyx.git] / src / frontends / qt4 / GuiAbout.cpp
1 /**
2  * \file GuiAbout.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Kalle Dalheimer
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiAbout.h"
14 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16
17 #include "controllers/ButtonController.h"
18 #include "controllers/ControlAboutlyx.h"
19
20 #include "support/lstrings.h"
21
22 #include <sstream>
23
24 #include <QLabel>
25 #include <QPushButton>
26 #include <QTextCodec>
27 #include <QTextBrowser>
28
29 using lyx::support::prefixIs;
30
31 using std::getline;
32
33 using std::istringstream;
34 using std::ostringstream;
35 using std::string;
36
37 namespace lyx {
38 namespace frontend {
39
40
41 GuiAbout::GuiAbout(Dialog & parent)
42         : GuiView<GuiAboutDialog>(parent, _("About LyX"))
43 {
44 }
45
46
47 void GuiAbout::build_dialog()
48 {
49         dialog_.reset(new GuiAboutDialog);
50         connect(dialog_.get()->closePB, SIGNAL(clicked()),
51                 this, SLOT(slotClose()));
52
53         dialog_->copyrightTB->setPlainText(toqstr(controller().getCopyright()));
54         dialog_->copyrightTB->append("");
55         dialog_->copyrightTB->append(toqstr(controller().getLicense()));
56         dialog_->copyrightTB->append("");
57         dialog_->copyrightTB->append(toqstr(controller().getDisclaimer()));
58
59         dialog_->versionLA->setText(toqstr(controller().getVersion()));
60
61         // The code below should depend on a autoconf test. (Lgb)
62 #if 1
63         // There are a lot of buggy stringstream implementations..., but the
64         // code below will work on all of them (I hope). The drawback with
65         // this solutions os the extra copying. (Lgb)
66
67         ostringstream in;
68         controller().getCredits(in);
69
70         istringstream ss(in.str());
71
72         string s;
73         ostringstream out;
74
75         while (getline(ss, s)) {
76                 if (prefixIs(s, "@b"))
77                         out << "<b>" << s.substr(2) << "</b>";
78                 else if (prefixIs(s, "@i"))
79                         out << "<i>" << s.substr(2) << "</i>";
80                 else
81                         out << s;
82                 out << "<br>";
83         }
84 #else
85         // Good stringstream implementations can handle this. It avoids
86         // some copying, and should thus be faster and use less memory. (Lgb)
87         // I'll make this the default for a short while to see if anyone
88         // see the error...
89         stringstream in;
90         controller().getCredits(in);
91         in.seekg(0);
92         string s;
93         ostringstream out;
94
95         while (getline(in, s)) {
96                 if (prefixIs(s, "@b"))
97                         out << "<b>" << s.substr(2) << "</b>";
98                 else if (prefixIs(s, "@i"))
99                         out << "<i>" << s.substr(2) << "</i>";
100                 else
101                         out << s;
102                 out << "<br>";
103         }
104 #endif
105
106         dialog_->creditsTB->setHtml(toqstr(out.str()));
107
108         // try to resize to a good size
109         dialog_->copyrightTB->hide();
110         dialog_->setMinimumSize(dialog_->copyrightTB->sizeHint());
111         dialog_->copyrightTB->show();
112         dialog_->setMinimumSize(dialog_->sizeHint());
113
114         // Manage the cancel/close button
115         bcview().setCancel(dialog_->closePB);
116         bc().refresh();
117 }
118
119 } // namespace frontend
120 } // namespace lyx
121
122 #include "GuiAbout_moc.cpp"