]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiAbout.cpp
Assure correct spacing of colored items in mathed
[lyx.git] / src / frontends / qt / 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
15 #include "ui_AboutUi.h"
16
17 #include "qt_helpers.h"
18 #include "version.h"
19
20 #include "support/filetools.h"
21 #include "support/gettext.h"
22 #include "support/lstrings.h"
23 #include "support/Package.h"
24
25 #include <QDate>
26 #include <QFile>
27 #include <QTextStream>
28
29 using namespace lyx::support;
30 using lyx::support::package;
31 using lyx::support::makeDisplayPath;
32
33
34 namespace lyx {
35 namespace frontend {
36
37
38 static QDate release_date()
39 {
40         return QDate::fromString(QString(lyx_release_date), Qt::ISODate);
41 }
42
43
44 static QString credits()
45 {
46         QString res;
47         QFile file(toqstr(package().system_support().absFileName()) + "/CREDITS");
48         QTextStream out(&res);
49
50         if (!file.exists()) {
51                 out << qt_("ERROR: LyX wasn't able to find the CREDITS file\n");
52                 out << qt_("Please install correctly to estimate the great\namount of work other people have done for the LyX project.");
53         } else {
54                 file.open(QIODevice::ReadOnly);
55                 if (!file.isReadable()) {
56                         out << qt_("ERROR: LyX wasn't able to read the CREDITS file\n");
57                         out << qt_("Please install correctly to estimate the great\namount of work other people have done for the LyX project.");
58                 } else {
59                         QTextStream ts(&file);
60                         ts.setCodec("UTF-8");
61                         QString line;
62                         do {
63                                 line = ts.readLine();
64                                 if (line.startsWith("#"))
65                                         continue;
66                                 if (line.startsWith("@b"))
67                                         out << "<b>" << line.mid(2) << "</b>";
68                                 else if (line.startsWith("@i")) {
69                                         if (line.startsWith("@iE-mail")) {
70                                                 // unmask email
71                                                 line.replace(QString(" () "), QString("@"));
72                                                 line.replace(QString(" ! "), QString("."));
73                                         }
74                                         out << "<i>" << line.mid(2) << "</i>";
75                                 } else
76                                         out << line;
77                                 out << "<br>";
78                         } while (!line.isNull());
79                 }
80         }
81         out.flush();
82         return res;
83 }
84
85
86 static QString release_notes()
87 {
88         QString res;
89         QFile file(toqstr(package().system_support().absFileName()) + "/RELEASE-NOTES");
90         QTextStream out(&res);
91
92         if (!file.exists()) {
93                 out << qt_("ERROR: LyX wasn't able to find the RELEASE-NOTES file\n");
94                 out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
95         } else {
96                 file.open(QIODevice::ReadOnly);
97                 if (!file.isReadable()) {
98                         out << qt_("ERROR: LyX wasn't able to read the RELEASE-NOTES file\n");
99                         out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
100                 } else {
101                         QTextStream ts(&file);
102                         ts.setCodec("UTF-8");
103                         QString line;
104                         bool incomment = false;
105                         bool inlist = false;
106                         do {
107                                 // a simple markdown parser
108                                 line = ts.readLine();
109                                 // skipe empty lines
110                                 if (line.isEmpty())
111                                         continue;
112                                 // parse (:comments:)
113                                 if (line.startsWith("(:")) {
114                                         if (!line.endsWith(":)"))
115                                                 incomment = true;
116                                         continue;
117                                 } if (line.endsWith(":)") && incomment) {
118                                         incomment = false;
119                                         continue;
120                                 } if (incomment)
121                                         continue;
122
123                                 // detect links to the tracker
124                                 line.replace(QRegExp("(bug )(\\#)(\\d+)*"),
125                                              "<a href=\"http://www.lyx.org/trac/ticket/\\3\">\\1\\3</a>");
126
127                                 // headings
128                                 if (line.startsWith("!!!")) {
129                                         if (inlist) {
130                                             out << "</li>";
131                                             out << "</ul><br>";
132                                             inlist = false;
133                                         }
134                                         out << "<h4>" << line.mid(3) << "</h4>";
135                                 }
136                                 else if (line.startsWith("!!")) {
137                                         if (inlist) {
138                                             out << "</li>";
139                                             out << "</ul><br>";
140                                             inlist = false;
141                                         }
142                                         out << "<h3>" << line.mid(2) << "</h3>";
143                                 } else if (line.startsWith("!")) {
144                                         if (inlist) {
145                                             out << "</li>";
146                                             out << "</ul><br>";
147                                             inlist = false;
148                                         }
149                                         out << "<h2>" << line.mid(1) << "</h2>";
150                                 // lists
151                                 } else if (line.startsWith("* ")) {
152                                         if (inlist)
153                                                 out << "</li>";
154                                         else
155                                                 out << "<ul>";
156                                         inlist = true;
157                                         out << "<li>" << line.mid(2);
158                                 } else if (inlist && line.startsWith("  ")) {
159                                         out << line.mid(2);
160                                 } else if (inlist) {
161                                         inlist = false;
162                                         out << "</li>";
163                                         out << "</ul><br>";
164                                         out << line;
165                                 } else
166                                         out << line;
167
168                                 out << " ";
169                         } while (!line.isNull());
170                 }
171         }
172         out.flush();
173         return res;
174 }
175
176
177 static QString copyright()
178 {
179         QString release_year = release_date().toString("yyyy");
180         docstring copy_message =
181                 bformat(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995--%1$s LyX Team"),
182                         qstring_to_ucs4(release_year));
183         return toqstr(copy_message);
184 }
185
186
187 static QString license()
188 {
189         return qt_("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.");
190 }
191
192
193 static QString disclaimer()
194 {
195         return qt_("LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for more details.\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.");
196 }
197
198
199 static QString version()
200 {
201         QString loc_release_date;
202         QDate date = release_date();
203         if (date.isValid()) {
204                 QLocale loc;
205                 loc_release_date = loc.toString(date, QLocale::LongFormat);
206         } else {
207                 if (QString(lyx_release_date) == "not released yet")
208                         loc_release_date = qt_("not released yet");
209                 else
210                         loc_release_date = toqstr(lyx_release_date);
211         }
212         docstring version_date =
213                 bformat(_("LyX Version %1$s\n(%2$s)"),
214                         from_ascii(lyx_version),
215                         qstring_to_ucs4(loc_release_date))+"\n";
216         if (std::string(lyx_git_commit_hash) != "none")
217                 version_date += _("Built from git commit hash ")
218                         + from_utf8(lyx_git_commit_hash).substr(0,8);
219         version_date += "\n";
220
221         QString res;
222         QTextStream out(&res);
223         out << toqstr(version_date);
224         out << qt_("Library directory: ");
225         out << toqstr(makeDisplayPath(package().system_support().absFileName()));
226         out << "\n";
227         out << qt_("User directory: ");
228         out << toqstr(makeDisplayPath(package().user_support().absFileName()));
229         out << "\n";
230         out << toqstr(bformat(_("Qt Version (run-time): %1$s"), from_ascii(qVersion()))) << "\n";
231         out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR))) << "\n";
232         return res;
233 }
234
235 static QString buildinfo()
236 {
237         QString res;
238         QTextStream out(&res);
239         out << "LyX " << lyx_version
240                 << " (" << lyx_release_date << ")" << endl;
241         if (std::string(lyx_git_commit_hash) != "none")
242                 out << qt_("  Git commit hash ")
243                     << QString(lyx_git_commit_hash).left(8) << endl;
244
245         out << lyx_version_info << endl;
246         return res;
247 }
248
249
250 struct GuiAbout::Private
251 {
252         Ui::AboutUi ui;
253 };
254
255
256 GuiAbout::GuiAbout(GuiView & lv)
257         : DialogView(lv, "aboutlyx", qt_("About LyX")),
258         d(new GuiAbout::Private)
259 {
260         d->ui.setupUi(this);
261
262         d->ui.copyrightTB->setPlainText(copyright());
263         d->ui.copyrightTB->append(QString());
264         d->ui.copyrightTB->append(license());
265         d->ui.copyrightTB->append(QString());
266         d->ui.copyrightTB->append(disclaimer());
267
268         d->ui.versionLA->setText(version());
269         d->ui.buildinfoTB->setText(buildinfo());
270         d->ui.releasenotesTB->setHtml(release_notes());
271         d->ui.releasenotesTB->setOpenExternalLinks(true);
272         d->ui.creditsTB->setHtml(credits());
273
274         d->ui.tab->setUsesScrollButtons(false);
275 }
276
277
278 void GuiAbout::on_buttonBox_rejected()
279 {
280         close();
281 }
282
283
284 Dialog * createGuiAbout(GuiView & lv) { return new GuiAbout(lv); }
285
286
287 } // namespace frontend
288 } // namespace lyx
289
290 #include "moc_GuiAbout.cpp"