]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiAbout.cpp
No need (any longer?) to create a new view for lyxfiles-open
[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 #include "GuiApplication.h"
15
16 #include "ui_AboutUi.h"
17
18 #include "qt_helpers.h"
19 #include "version.h"
20
21 #include "support/filetools.h"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
24 #include "support/Package.h"
25
26 #include <QClipboard>
27 #include <QDate>
28 #include <QFile>
29 #include <QTextStream>
30
31 using namespace lyx::support;
32 using lyx::support::package;
33 using lyx::support::makeDisplayPath;
34
35
36 namespace lyx {
37 namespace frontend {
38
39
40 static QDate release_date()
41 {
42         return QDate::fromString(QString(lyx_release_date), Qt::ISODate);
43 }
44
45
46 static QString credits()
47 {
48         QString res;
49         QFile file(toqstr(package().system_support().absFileName()) + "/CREDITS");
50         QTextStream out(&res);
51
52         if (!file.exists()) {
53                 out << qt_("ERROR: LyX wasn't able to find the CREDITS file\n");
54                 out << qt_("Please install correctly to estimate the great\namount of work other people have done for the LyX project.");
55         } else {
56                 file.open(QIODevice::ReadOnly);
57                 if (!file.isReadable()) {
58                         out << qt_("ERROR: LyX wasn't able to read the CREDITS file\n");
59                         out << qt_("Please install correctly to estimate the great\namount of work other people have done for the LyX project.");
60                 } else {
61                         QTextStream ts(&file);
62 #if QT_VERSION < 0x060000
63                         ts.setCodec("UTF-8");
64 #endif
65                         QString line;
66                         do {
67                                 line = ts.readLine();
68                                 if (line.startsWith("#"))
69                                         continue;
70                                 if (line.startsWith("@b"))
71                                         out << "<b>" << line.mid(2) << "</b>";
72                                 else if (line.startsWith("@i")) {
73                                         if (line.startsWith("@iE-mail")) {
74                                                 // unmask email
75                                                 line.replace(QString(" () "), QString("@"));
76                                                 line.replace(QString(" ! "), QString("."));
77                                         }
78                                         out << "<i>" << line.mid(2) << "</i>";
79                                 } else
80                                         out << line;
81                                 out << "<br>";
82                         } while (!line.isNull());
83                 }
84         }
85         out.flush();
86         return res;
87 }
88
89
90 static QString release_notes()
91 {
92         QString res;
93         QFile file(toqstr(package().system_support().absFileName()) + "/RELEASE-NOTES");
94         QTextStream out(&res);
95
96         if (!file.exists()) {
97                 out << qt_("ERROR: LyX wasn't able to find the RELEASE-NOTES file\n");
98                 out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
99         } else {
100                 file.open(QIODevice::ReadOnly);
101                 if (!file.isReadable()) {
102                         out << qt_("ERROR: LyX wasn't able to read the RELEASE-NOTES file\n");
103                         out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
104                 } else {
105                         QTextStream ts(&file);
106 #if QT_VERSION < 0x060000
107                         ts.setCodec("UTF-8");
108 #endif
109                         QString line;
110                         bool incomment = false;
111                         bool inlist = false;
112                         do {
113                                 // a simple markdown parser
114                                 line = ts.readLine();
115                                 // skipe empty lines
116                                 if (line.isEmpty())
117                                         continue;
118                                 // parse (:comments:)
119                                 if (line.startsWith("(:")) {
120                                         if (!line.endsWith(":)"))
121                                                 incomment = true;
122                                         continue;
123                                 } if (line.endsWith(":)") && incomment) {
124                                         incomment = false;
125                                         continue;
126                                 } if (incomment)
127                                         continue;
128
129                                 // detect links to the tracker
130                                 line.replace(QRegularExpression("(bug )(\\#)(\\d+)*"),
131                                              "<a href=\"http://www.lyx.org/trac/ticket/\\3\">\\1\\3</a>");
132
133                                 // headings
134                                 if (line.startsWith("!!!")) {
135                                         if (inlist) {
136                                             out << "</li>";
137                                             out << "</ul><br>";
138                                             inlist = false;
139                                         }
140                                         out << "<h4>" << line.mid(3) << "</h4>";
141                                 }
142                                 else if (line.startsWith("!!")) {
143                                         if (inlist) {
144                                             out << "</li>";
145                                             out << "</ul><br>";
146                                             inlist = false;
147                                         }
148                                         out << "<h3>" << line.mid(2) << "</h3>";
149                                 } else if (line.startsWith("!")) {
150                                         if (inlist) {
151                                             out << "</li>";
152                                             out << "</ul><br>";
153                                             inlist = false;
154                                         }
155                                         out << "<h2>" << line.mid(1) << "</h2>";
156                                 // lists
157                                 } else if (line.startsWith("* ")) {
158                                         if (inlist)
159                                                 out << "</li>";
160                                         else
161                                                 out << "<ul>";
162                                         inlist = true;
163                                         out << "<li>" << line.mid(2);
164                                 } else if (inlist && line.startsWith("  ")) {
165                                         out << line.mid(2);
166                                 } else if (inlist) {
167                                         inlist = false;
168                                         out << "</li>";
169                                         out << "</ul><br>";
170                                         out << line;
171                                 } else
172                                         out << line;
173
174                                 out << " ";
175                         } while (!line.isNull());
176                 }
177         }
178         out.flush();
179         return res;
180 }
181
182
183 static QString copyright()
184 {
185         QString release_year = release_date().toString("yyyy");
186         docstring copy_message =
187                 bformat(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995--%1$s LyX Team"),
188                         qstring_to_ucs4(release_year));
189         return toqstr(copy_message);
190 }
191
192
193 static QString license()
194 {
195         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.");
196 }
197
198
199 static QString disclaimer()
200 {
201         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.");
202 }
203
204
205 static QString buildinfo()
206 {
207         QString res;
208         QTextStream out(&res);
209         out << "LyX " << lyx_version
210                 << " (" << lyx_release_date << ")"
211 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
212                 << Qt::endl;
213 #else
214                 << endl;
215 #endif
216         if (std::string(lyx_git_commit_hash) != "none")
217                 out << qt_("  Git commit hash ")
218                     << QString(lyx_git_commit_hash).left(8)
219 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
220                     << Qt::endl;
221 #else
222                     << endl;
223 #endif
224
225         out << lyx_version_info
226 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
227             << Qt::endl;
228 #else
229             << endl;
230 #endif
231         return res;
232 }
233
234
235 static QString dirLibrary()
236 {
237         return toqstr(makeDisplayPath(package().system_support().absFileName()));
238 }
239
240
241 static QString dirUser()
242 {
243         return toqstr(makeDisplayPath(package().user_support().absFileName()));
244 }
245
246
247 static QString version(bool const plain = false)
248 {
249         QString loc_release_date;
250         QDate date = release_date();
251         if (date.isValid()) {
252                 QLocale loc;
253                 loc_release_date = loc.toString(date, QLocale::LongFormat);
254         } else {
255                 if (QString(lyx_release_date) == "not released yet")
256                         loc_release_date = qt_("not released yet");
257                 else
258                         loc_release_date = toqstr(lyx_release_date);
259         }
260         docstring version_date =
261                 bformat(_("Version %1$s\n(%2$s)"),
262                         from_ascii(lyx_version),
263                         qstring_to_ucs4(loc_release_date))+"\n";
264         if (std::string(lyx_git_commit_hash) != "none") {
265                 if (plain)
266                         version_date += '\n';
267                 else
268                         version_date += from_ascii("</p><p>");
269                 version_date += _("Built from git commit hash ")
270                         + from_utf8(lyx_git_commit_hash).substr(0,8);
271         }
272
273         QString res;
274         QTextStream out(&res);
275         if (!plain)
276                 out << toqstr("<html><head/><body><p><span style=\" font-weight:600;\">");
277         out << toqstr(version_date);
278         if (plain)
279                 out << '\n';
280         else
281                 out << "</span></p><p>";
282         out << toqstr(bformat(_("Qt Version (run-time): %1$s on platform %2$s"), from_ascii(qVersion()), qstring_to_ucs4(guiApp->platformName())));
283         if (plain)
284                 out << '\n';
285         else
286                 out << "</p><p>";
287         out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR)));
288         if (plain)
289                 out << '\n';
290         else
291                 out << "</p><p>";
292 #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
293         out << toqstr(bformat(_("OS Version (run-time): %1$s"),
294                 qstring_to_ucs4(QSysInfo::prettyProductName())));
295         if (plain)
296                 out << '\n';
297         else
298                 out << "</p><p>";
299 #endif
300         out << toqstr(bformat(_("Python detected: %1$s"), from_utf8(os::python_info())));
301         if (!plain)
302                 out << toqstr("</p></body></html>");
303         return res;
304 }
305
306
307 struct GuiAbout::Private
308 {
309         Ui::AboutUi ui;
310 };
311
312 void GuiAbout::on_showDirLibraryPB_clicked()
313 {
314         showDirectory(package().system_support());
315 }
316
317
318 void GuiAbout::on_showDirUserPB_clicked()
319 {
320         showDirectory(package().user_support());
321 }
322
323
324 void GuiAbout::on_versionCopyPB_clicked()
325 {
326         qApp->clipboard()->setText(version(true));
327 }
328
329
330 GuiAbout::GuiAbout(GuiView & lv)
331         : DialogView(lv, "aboutlyx", qt_("About LyX")),
332         d(new GuiAbout::Private)
333 {
334         d->ui.setupUi(this);
335
336         d->ui.copyrightTB->setPlainText(copyright());
337         d->ui.copyrightTB->append(QString());
338         d->ui.copyrightTB->append(license());
339         d->ui.copyrightTB->append(QString());
340         d->ui.copyrightTB->append(disclaimer());
341
342         d->ui.versionLA->setText(version());
343         int const iconsize = d->ui.versionLA->height() * 1.5;
344         QString path = "images/";
345         QString name = "lyx";
346         QString ext = "svg";
347         FileName fname = imageLibFileSearch(path, name, ext, theGuiApp()->imageSearchMode());
348         QString fpath = toqstr(fname.absFileName());
349         d->ui.iconSW->load(fpath);
350         d->ui.iconSW->setFixedSize(iconsize, iconsize);
351         d->ui.dirLibraryLA->setText(dirLibrary());
352         d->ui.dirLibraryLA->adjustSize();
353         d->ui.dirUserLA->setText(dirUser());
354         d->ui.dirUserLA->adjustSize();
355         d->ui.buildinfoTB->setText(buildinfo());
356         d->ui.releasenotesTB->setHtml(release_notes());
357         d->ui.releasenotesTB->setOpenExternalLinks(true);
358         d->ui.creditsTB->setHtml(credits());
359
360         d->ui.tab->setUsesScrollButtons(false);
361
362         // fix height to minimum
363         // setFixedHeight(sizeHint().height());
364 }
365
366
367 GuiAbout::~GuiAbout()
368 {
369         delete d;
370 }
371
372
373 void GuiAbout::on_buttonBox_rejected()
374 {
375         close();
376 }
377
378
379 } // namespace frontend
380 } // namespace lyx
381
382 #include "moc_GuiAbout.cpp"