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