]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QAbout.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / frontends / qt2 / QAbout.C
1 /**
2  * \file QAbout.C
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 "QAbout.h"
14 #include "QAboutDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "controllers/ButtonController.h"
19 #include "controllers/ControlAboutlyx.h"
20
21 #include "support/lstrings.h"
22
23 #include <sstream>
24
25 #include <qlabel.h>
26 #include <qpushbutton.h>
27 #include <qtextview.h>
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 typedef QController<ControlAboutlyx, QView<QAboutDialog> > base_class;
41
42 QAbout::QAbout(Dialog & parent)
43         : base_class(parent, _("About LyX"))
44 {
45 }
46
47
48 void QAbout::build_dialog()
49 {
50         dialog_.reset(new QAboutDialog);
51         connect(dialog_.get()->closePB, SIGNAL(clicked()),
52                 this, SLOT(slotClose()));
53
54         dialog_->copyright->setText(toqstr(controller().getCopyright()));
55         dialog_->copyright->append("\n");
56         dialog_->copyright->append(toqstr(controller().getLicense()));
57         dialog_->copyright->append("\n");
58         dialog_->copyright->append(toqstr(controller().getDisclaimer()));
59
60         dialog_->versionLA->setText(toqstr(controller().getVersion()));
61
62         // The code below should depend on a autoconf test. (Lgb)
63 #if 1
64         // There are a lot of buggy stringstream implementations..., but the
65         // code below will work on all of them (I hope). The drawback with
66         // this solutions os the extra copying. (Lgb)
67
68         ostringstream in;
69         controller().getCredits(in);
70
71         istringstream ss(in.str());
72
73         string s;
74         ostringstream out;
75
76         while (getline(ss, s)) {
77                 if (prefixIs(s, "@b"))
78                         out << "<b>" << s.substr(2) << "</b>";
79                 else if (prefixIs(s, "@i"))
80                         out << "<i>" << s.substr(2) << "</i>";
81                 else
82                         out << s;
83                 out << "<br>";
84         }
85 #else
86         // Good stringstream implementations can handle this. It avoids
87         // some copying, and should thus be faster and use less memory. (Lgb)
88         // I'll make this the default for a short while to see if anyone
89         // see the error...
90         stringstream in;
91         controller().getCredits(in);
92         in.seekg(0);
93         string s;
94         ostringstream out;
95
96         while (getline(in, s)) {
97                 if (prefixIs(s, "@b"))
98                         out << "<b>" << s.substr(2) << "</b>";
99                 else if (prefixIs(s, "@i"))
100                         out << "<i>" << s.substr(2) << "</i>";
101                 else
102                         out << s;
103                 out << "<br>";
104         }
105 #endif
106
107         dialog_->creditsTV->setText(toqstr(out.str()));
108
109         // try to resize to a good size
110         dialog_->copyright->hide();
111         dialog_->setMinimumSize(dialog_->copyright->sizeHint());
112         dialog_->copyright->show();
113         dialog_->setMinimumSize(dialog_->sizeHint());
114
115         // Manage the cancel/close button
116         bcview().setCancel(dialog_->closePB);
117         bc().refresh();
118 }
119
120 } // namespace frontend
121 } // namespace lyx