]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiAbout.cpp
the fun begins....
[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 "qt_helpers.h"
15 #include "gettext.h"
16
17 #include "support/lstrings.h"
18
19 #include <sstream>
20
21 #include <QLabel>
22 #include <QPushButton>
23 #include <QTextCodec>
24 #include <QTextBrowser>
25
26 using lyx::support::prefixIs;
27
28 using std::getline;
29
30 using std::istringstream;
31 using std::ostringstream;
32 using std::string;
33
34
35 namespace lyx {
36 namespace frontend {
37
38 GuiAboutDialog::GuiAboutDialog(LyXView & lv)
39         : GuiDialog(lv, "aboutlyx")
40 {
41         setupUi(this);
42         setViewTitle(_("About LyX"));
43
44         setController(new ControlAboutlyx(*this));
45
46         connect(closePB, SIGNAL(clicked()), this, SLOT(reject()));
47
48         connect(closePB, SIGNAL(clicked()),
49                 this, SLOT(slotClose()));
50
51         copyrightTB->setPlainText(toqstr(controller().getCopyright()));
52         copyrightTB->append("");
53         copyrightTB->append(toqstr(controller().getLicense()));
54         copyrightTB->append("");
55         copyrightTB->append(toqstr(controller().getDisclaimer()));
56
57         versionLA->setText(toqstr(controller().getVersion()));
58
59         // The code below should depend on a autoconf test. (Lgb)
60 #if 1
61         // There are a lot of buggy stringstream implementations..., but the
62         // code below will work on all of them (I hope). The drawback with
63         // this solutions os the extra copying. (Lgb)
64
65         ostringstream in;
66         controller().getCredits(in);
67
68         istringstream ss(in.str());
69
70         string s;
71         ostringstream out;
72
73         while (getline(ss, s)) {
74                 if (prefixIs(s, "@b"))
75                         out << "<b>" << s.substr(2) << "</b>";
76                 else if (prefixIs(s, "@i"))
77                         out << "<i>" << s.substr(2) << "</i>";
78                 else
79                         out << s;
80                 out << "<br>";
81         }
82 #else
83         // Good stringstream implementations can handle this. It avoids
84         // some copying, and should thus be faster and use less memory. (Lgb)
85         // I'll make this the default for a short while to see if anyone
86         // see the error...
87         stringstream in;
88         controller().getCredits(in);
89         in.seekg(0);
90         string s;
91         ostringstream out;
92
93         while (getline(in, s)) {
94                 if (prefixIs(s, "@b"))
95                         out << "<b>" << s.substr(2) << "</b>";
96                 else if (prefixIs(s, "@i"))
97                         out << "<i>" << s.substr(2) << "</i>";
98                 else
99                         out << s;
100                 out << "<br>";
101         }
102 #endif
103
104         creditsTB->setHtml(toqstr(out.str()));
105
106         // try to resize to a good size
107         copyrightTB->hide();
108         setMinimumSize(copyrightTB->sizeHint());
109         copyrightTB->show();
110         setMinimumSize(sizeHint());
111
112         // Manage the cancel/close button
113         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
114         bc().setCancel(closePB);
115         bc().refresh();
116 }
117
118
119 ControlAboutlyx & GuiAboutDialog::controller() const
120 {
121         return static_cast<ControlAboutlyx &>(Dialog::controller());
122 }
123
124 } // namespace frontend
125 } // namespace lyx
126
127 #include "GuiAbout_moc.cpp"