]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiAbout.cpp
Keep dialog connected to cross-ref inset after Apply.
[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                         ts.setCodec("UTF-8");
63                         QString line;
64                         do {
65                                 line = ts.readLine();
66                                 if (line.startsWith("#"))
67                                         continue;
68                                 if (line.startsWith("@b"))
69                                         out << "<b>" << line.mid(2) << "</b>";
70                                 else if (line.startsWith("@i")) {
71                                         if (line.startsWith("@iE-mail")) {
72                                                 // unmask email
73                                                 line.replace(QString(" () "), QString("@"));
74                                                 line.replace(QString(" ! "), QString("."));
75                                         }
76                                         out << "<i>" << line.mid(2) << "</i>";
77                                 } else
78                                         out << line;
79                                 out << "<br>";
80                         } while (!line.isNull());
81                 }
82         }
83         out.flush();
84         return res;
85 }
86
87
88 static QString release_notes()
89 {
90         QString res;
91         QFile file(toqstr(package().system_support().absFileName()) + "/RELEASE-NOTES");
92         QTextStream out(&res);
93
94         if (!file.exists()) {
95                 out << qt_("ERROR: LyX wasn't able to find the RELEASE-NOTES file\n");
96                 out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
97         } else {
98                 file.open(QIODevice::ReadOnly);
99                 if (!file.isReadable()) {
100                         out << qt_("ERROR: LyX wasn't able to read the RELEASE-NOTES file\n");
101                         out << qt_("Please install correctly to see what has changed\nfor 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
125                                 // detect links to the tracker
126                                 line.replace(QRegExp("(bug )(\\#)(\\d+)*"),
127                                              "<a href=\"http://www.lyx.org/trac/ticket/\\3\">\\1\\3</a>");
128
129                                 // headings
130                                 if (line.startsWith("!!!")) {
131                                         if (inlist) {
132                                             out << "</li>";
133                                             out << "</ul><br>";
134                                             inlist = false;
135                                         }
136                                         out << "<h4>" << line.mid(3) << "</h4>";
137                                 }
138                                 else if (line.startsWith("!!")) {
139                                         if (inlist) {
140                                             out << "</li>";
141                                             out << "</ul><br>";
142                                             inlist = false;
143                                         }
144                                         out << "<h3>" << line.mid(2) << "</h3>";
145                                 } else if (line.startsWith("!")) {
146                                         if (inlist) {
147                                             out << "</li>";
148                                             out << "</ul><br>";
149                                             inlist = false;
150                                         }
151                                         out << "<h2>" << line.mid(1) << "</h2>";
152                                 // lists
153                                 } else if (line.startsWith("* ")) {
154                                         if (inlist)
155                                                 out << "</li>";
156                                         else
157                                                 out << "<ul>";
158                                         inlist = true;
159                                         out << "<li>" << line.mid(2);
160                                 } else if (inlist && line.startsWith("  ")) {
161                                         out << line.mid(2);
162                                 } else if (inlist) {
163                                         inlist = false;
164                                         out << "</li>";
165                                         out << "</ul><br>";
166                                         out << line;
167                                 } else
168                                         out << line;
169
170                                 out << " ";
171                         } while (!line.isNull());
172                 }
173         }
174         out.flush();
175         return res;
176 }
177
178
179 static QString copyright()
180 {
181         QString release_year = release_date().toString("yyyy");
182         docstring copy_message =
183                 bformat(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995--%1$s LyX Team"),
184                         qstring_to_ucs4(release_year));
185         return toqstr(copy_message);
186 }
187
188
189 static QString license()
190 {
191         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.");
192 }
193
194
195 static QString disclaimer()
196 {
197         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.");
198 }
199
200
201 static QString buildinfo()
202 {
203         QString res;
204         QTextStream out(&res);
205         out << "LyX " << lyx_version
206                 << " (" << lyx_release_date << ")"
207 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
208                 << Qt::endl;
209 #else
210                 << endl;
211 #endif
212         if (std::string(lyx_git_commit_hash) != "none")
213                 out << qt_("  Git commit hash ")
214                     << QString(lyx_git_commit_hash).left(8)
215 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
216                     << Qt::endl;
217 #else
218                     << endl;
219 #endif
220
221         out << lyx_version_info 
222 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
223             << Qt::endl;
224 #else
225             << endl;
226 #endif
227         return res;
228 }
229
230
231 static QString dirLibrary()
232 {
233         return toqstr(makeDisplayPath(package().system_support().absFileName()));
234 }
235
236
237 static QString dirUser()
238 {
239         return toqstr(makeDisplayPath(package().user_support().absFileName()));
240 }
241
242
243 static QString version(bool const plain = false)
244 {
245         QString loc_release_date;
246         QDate date = release_date();
247         if (date.isValid()) {
248                 QLocale loc;
249                 loc_release_date = loc.toString(date, QLocale::LongFormat);
250         } else {
251                 if (QString(lyx_release_date) == "not released yet")
252                         loc_release_date = qt_("not released yet");
253                 else
254                         loc_release_date = toqstr(lyx_release_date);
255         }
256         docstring version_date =
257                 bformat(_("Version %1$s\n(%2$s)"),
258                         from_ascii(lyx_version),
259                         qstring_to_ucs4(loc_release_date))+"\n";
260         if (std::string(lyx_git_commit_hash) != "none") {
261                 if (plain)
262                         version_date += '\n';
263                 else
264                         version_date += from_ascii("</p><p>");
265                 version_date += _("Built from git commit hash ")
266                         + from_utf8(lyx_git_commit_hash).substr(0,8);
267         }
268
269         QString res;
270         QTextStream out(&res);
271         if (!plain)
272                 out << toqstr("<html><head/><body><p><span style=\" font-weight:600;\">");
273         out << toqstr(version_date);
274         if (plain)
275                 out << '\n';
276         else
277                 out << "</span></p><p>";
278         out << toqstr(bformat(_("Qt Version (run-time): %1$s"), from_ascii(qVersion())));
279         if (plain)
280                 out << '\n';
281         else
282                 out << "</p><p>";
283         out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR)));
284         if (!plain)
285                 out << toqstr("</p></body></html>");
286         return res;
287 }
288
289
290 struct GuiAbout::Private
291 {
292         Ui::AboutUi ui;
293 };
294
295 void GuiAbout::on_showDirLibraryPB_clicked()
296 {
297         showDirectory(package().system_support());
298 }
299
300
301 void GuiAbout::on_showDirUserPB_clicked()
302 {
303         showDirectory(package().user_support());
304 }
305
306
307 void GuiAbout::on_versionCopyPB_clicked()
308 {
309         qApp->clipboard()->setText(version(true));
310 }
311
312
313 GuiAbout::GuiAbout(GuiView & lv)
314         : DialogView(lv, "aboutlyx", qt_("About LyX")),
315         d(new GuiAbout::Private)
316 {
317         d->ui.setupUi(this);
318
319         d->ui.copyrightTB->setPlainText(copyright());
320         d->ui.copyrightTB->append(QString());
321         d->ui.copyrightTB->append(license());
322         d->ui.copyrightTB->append(QString());
323         d->ui.copyrightTB->append(disclaimer());
324
325         d->ui.versionLA->setText(version());
326         QPixmap icon = getPixmap("images/", "lyx", "svg,png");
327         int const iconsize = d->ui.versionLA->height() * 1.5;
328         d->ui.iconLA->setPixmap(icon.scaled(iconsize, iconsize,
329                                             Qt::IgnoreAspectRatio,
330                                             Qt::SmoothTransformation));
331         d->ui.iconLA->setFixedWidth(iconsize);
332         d->ui.dirLibraryLA->setText(dirLibrary());
333         d->ui.dirUserLA->setText(dirUser());
334         d->ui.buildinfoTB->setText(buildinfo());
335         d->ui.releasenotesTB->setHtml(release_notes());
336         d->ui.releasenotesTB->setOpenExternalLinks(true);
337         d->ui.creditsTB->setHtml(credits());
338
339         d->ui.tab->setUsesScrollButtons(false);
340
341         // fix height to minimum
342         setFixedHeight(sizeHint().height());
343 }
344
345
346 GuiAbout::~GuiAbout()
347 {
348         delete d;
349 }
350
351
352 void GuiAbout::on_buttonBox_rejected()
353 {
354         close();
355 }
356
357
358 } // namespace frontend
359 } // namespace lyx
360
361 #include "moc_GuiAbout.cpp"