]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiAbout.cpp
Make RELEASE-NOTES accessible from GUI (#8616)
[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
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\n");
53                 out << qt_("amount of work other people have done for the LyX project.");
54         } else {
55                 file.open(QIODevice::ReadOnly);
56                 if (!file.isReadable()) {
57                         out << qt_("ERROR: LyX wasn't able to read the CREDITS file\n");
58                         out << qt_("Please install correctly to estimate the great\n");
59                         out << qt_("amount of work other people have done for the LyX project.");
60                 } else {
61                         QTextStream ts(&file);
62                         ts.setCodec("UTF-8");
63                         QString line;
64                         do {
65                                 line = ts.readLine();
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\n");
95                 out << qt_("for this version of LyX.");
96         } else {
97                 file.open(QIODevice::ReadOnly);
98                 if (!file.isReadable()) {
99                         out << qt_("ERROR: LyX wasn't able to read the RELEASE-NOTES file\n");
100                         out << qt_("Please install correctly to see what has changed\n");
101                         out << qt_("for this version of LyX.");
102                 } else {
103                         QTextStream ts(&file);
104                         ts.setCodec("UTF-8");
105                         QString line;
106                         bool incomment = false;
107                         bool inlist = false;
108                         do {
109                                 // a simple markdown parser
110                                 line = ts.readLine();
111                                 // skipe empty lines
112                                 if (line.isEmpty())
113                                         continue;
114                                 // parse (:comments:)
115                                 if (line.startsWith("(:")) {
116                                         if (!line.endsWith(":)"))
117                                                 incomment = true;
118                                         continue;
119                                 } if (line.endsWith(":)") && incomment) {
120                                         incomment = false;
121                                         continue;
122                                 } if (incomment)
123                                         continue;
124                                 // headings
125                                 if (line.startsWith("!!!")) {
126                                         if (inlist) {
127                                             out << "</li>";
128                                             out << "</ul><br>";
129                                             inlist = false;
130                                         }
131                                         out << "<h4>" << line.mid(3) << "</h4>";
132                                 }
133                                 else if (line.startsWith("!!")) {
134                                         if (inlist) {
135                                             out << "</li>";
136                                             out << "</ul><br>";
137                                             inlist = false;
138                                         }
139                                         out << "<h3>" << line.mid(2) << "</h3>";
140                                 } else if (line.startsWith("!")) {
141                                         if (inlist) {
142                                             out << "</li>";
143                                             out << "</ul><br>";
144                                             inlist = false;
145                                         }
146                                         out << "<h2>" << line.mid(1) << "</h2>";
147                                 // lists
148                                 } else if (line.startsWith("* ")) {
149                                         if (inlist)
150                                                 out << "</li>";
151                                         else
152                                                 out << "<ul>";
153                                         inlist = true;
154                                         out << "<li>" << line.mid(2);
155                                 } else if (inlist && line.startsWith("  ")) {
156                                         out << line.mid(2);
157                                 } else if (inlist) {
158                                         inlist = false;
159                                         out << "</li>";
160                                         out << "</ul><br>";
161                                         out << line;
162                                 } else
163                                         out << line;
164
165                                 out << " ";
166                         } while (!line.isNull());
167                 }
168         }
169         out.flush();
170         return res;
171 }
172
173
174 static QString copyright()
175 {
176         QString release_year = release_date().toString("yyyy");
177         docstring copy_message =
178                 bformat(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995--%1$s LyX Team"),
179                         qstring_to_ucs4(release_year));
180         return toqstr(copy_message);
181 }
182
183
184 static QString license()
185 {
186         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.");
187 }
188
189
190 static QString disclaimer()
191 {
192         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.");
193 }
194
195
196 static QString version()
197 {
198         QString loc_release_date;
199         QDate date = release_date();
200         if (date.isValid()) {
201                 QLocale loc;
202                 loc_release_date = loc.toString(date, QLocale::LongFormat);
203         } else {
204                 if (QString(lyx_release_date) == "not released yet")
205                         loc_release_date = qt_("not released yet");
206                 else
207                         loc_release_date = toqstr(lyx_release_date);
208         }
209         docstring version_date =
210                 bformat(_("LyX Version %1$s\n(%2$s)"),
211                         from_ascii(lyx_version),
212                         qstring_to_ucs4(loc_release_date))+"\n";
213         if (std::string(lyx_git_commit_hash) != "none")
214                 version_date += _("Built from git commit hash ")
215                         + from_utf8(lyx_git_commit_hash).substr(0,8);
216         version_date += "\n";
217
218         QString res;
219         QTextStream out(&res);
220         out << toqstr(version_date);
221         out << qt_("Library directory: ");
222         out << toqstr(makeDisplayPath(package().system_support().absFileName()));
223         out << "\n";
224         out << qt_("User directory: ");
225         out << toqstr(makeDisplayPath(package().user_support().absFileName()));
226         if (std::string(lyx_git_commit_hash) != "none") {
227                 out << "\n";
228                 out << toqstr(bformat(_("Qt Version (run-time): %1$s"), from_ascii(qVersion()))) << "\n";
229                 out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR))) << "\n";
230         }
231         return res;
232 }
233
234 static QString buildinfo()
235 {
236         QString res;
237         QTextStream out(&res);
238         out << "LyX " << lyx_version
239                 << " (" << lyx_release_date << ")" << endl;
240         if (std::string(lyx_git_commit_hash) != "none")
241                 out << qt_("  Git commit hash ")
242                     << QString(lyx_git_commit_hash).left(8) << endl;
243
244         out << lyx_version_info << endl;
245         return res;
246 }
247
248
249 struct GuiAbout::Private
250 {
251         Ui::AboutUi ui;
252 };
253
254
255 GuiAbout::GuiAbout(GuiView & lv)
256         : DialogView(lv, "aboutlyx", qt_("About LyX")),
257         d(new GuiAbout::Private)
258 {
259         d->ui.setupUi(this);
260
261         d->ui.copyrightTB->setPlainText(copyright());
262         d->ui.copyrightTB->append(QString());
263         d->ui.copyrightTB->append(license());
264         d->ui.copyrightTB->append(QString());
265         d->ui.copyrightTB->append(disclaimer());
266
267         d->ui.versionLA->setText(version());
268         d->ui.buildinfoTB->setText(buildinfo());
269         d->ui.releasenotesTB->setHtml(release_notes());
270         d->ui.creditsTB->setHtml(credits());
271 }
272
273
274 void GuiAbout::on_closePB_clicked()
275 {
276         close();
277 }
278
279
280 Dialog * createGuiAbout(GuiView & lv) { return new GuiAbout(lv); }
281
282
283 } // namespace frontend
284 } // namespace lyx
285
286 #include "moc_GuiAbout.cpp"