]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiAbout.cpp
Start using QDialogButtonGroup rather than manual OK etc. buttons
[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\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("@b"))
65                                         out << "<b>" << line.mid(2) << "</b>";
66                                 else if (line.startsWith("@i")) {
67                                         if (line.startsWith("@iE-mail")) {
68                                                 // unmask email
69                                                 line.replace(QString(" () "), QString("@"));
70                                                 line.replace(QString(" ! "), QString("."));
71                                         }
72                                         out << "<i>" << line.mid(2) << "</i>";
73                                 } else
74                                         out << line;
75                                 out << "<br>";
76                         } while (!line.isNull());
77                 }
78         }
79         out.flush();
80         return res;
81 }
82
83
84 static QString release_notes()
85 {
86         QString res;
87         QFile file(toqstr(package().system_support().absFileName()) + "/RELEASE-NOTES");
88         QTextStream out(&res);
89
90         if (!file.exists()) {
91                 out << qt_("ERROR: LyX wasn't able to find the RELEASE-NOTES file\n");
92                 out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
93         } else {
94                 file.open(QIODevice::ReadOnly);
95                 if (!file.isReadable()) {
96                         out << qt_("ERROR: LyX wasn't able to read the RELEASE-NOTES file\n");
97                         out << qt_("Please install correctly to see what has changed\nfor this version of LyX.");
98                 } else {
99                         QTextStream ts(&file);
100                         ts.setCodec("UTF-8");
101                         QString line;
102                         bool incomment = false;
103                         bool inlist = false;
104                         do {
105                                 // a simple markdown parser
106                                 line = ts.readLine();
107                                 // skipe empty lines
108                                 if (line.isEmpty())
109                                         continue;
110                                 // parse (:comments:)
111                                 if (line.startsWith("(:")) {
112                                         if (!line.endsWith(":)"))
113                                                 incomment = true;
114                                         continue;
115                                 } if (line.endsWith(":)") && incomment) {
116                                         incomment = false;
117                                         continue;
118                                 } if (incomment)
119                                         continue;
120
121                                 // detect links to the tracker
122                                 line.replace(QRegExp("(bug )(\\#)(\\d+)*"),
123                                              "<a href=\"http://www.lyx.org/trac/ticket/\\3\">\\1\\3</a>");
124
125                                 // headings
126                                 if (line.startsWith("!!!")) {
127                                         if (inlist) {
128                                             out << "</li>";
129                                             out << "</ul><br>";
130                                             inlist = false;
131                                         }
132                                         out << "<h4>" << line.mid(3) << "</h4>";
133                                 }
134                                 else if (line.startsWith("!!")) {
135                                         if (inlist) {
136                                             out << "</li>";
137                                             out << "</ul><br>";
138                                             inlist = false;
139                                         }
140                                         out << "<h3>" << line.mid(2) << "</h3>";
141                                 } else if (line.startsWith("!")) {
142                                         if (inlist) {
143                                             out << "</li>";
144                                             out << "</ul><br>";
145                                             inlist = false;
146                                         }
147                                         out << "<h2>" << line.mid(1) << "</h2>";
148                                 // lists
149                                 } else if (line.startsWith("* ")) {
150                                         if (inlist)
151                                                 out << "</li>";
152                                         else
153                                                 out << "<ul>";
154                                         inlist = true;
155                                         out << "<li>" << line.mid(2);
156                                 } else if (inlist && line.startsWith("  ")) {
157                                         out << line.mid(2);
158                                 } else if (inlist) {
159                                         inlist = false;
160                                         out << "</li>";
161                                         out << "</ul><br>";
162                                         out << line;
163                                 } else
164                                         out << line;
165
166                                 out << " ";
167                         } while (!line.isNull());
168                 }
169         }
170         out.flush();
171         return res;
172 }
173
174
175 static QString copyright()
176 {
177         QString release_year = release_date().toString("yyyy");
178         docstring copy_message =
179                 bformat(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995--%1$s LyX Team"),
180                         qstring_to_ucs4(release_year));
181         return toqstr(copy_message);
182 }
183
184
185 static QString license()
186 {
187         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.");
188 }
189
190
191 static QString disclaimer()
192 {
193         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.");
194 }
195
196
197 static QString version()
198 {
199         QString loc_release_date;
200         QDate date = release_date();
201         if (date.isValid()) {
202                 QLocale loc;
203                 loc_release_date = loc.toString(date, QLocale::LongFormat);
204         } else {
205                 if (QString(lyx_release_date) == "not released yet")
206                         loc_release_date = qt_("not released yet");
207                 else
208                         loc_release_date = toqstr(lyx_release_date);
209         }
210         docstring version_date =
211                 bformat(_("LyX Version %1$s\n(%2$s)"),
212                         from_ascii(lyx_version),
213                         qstring_to_ucs4(loc_release_date))+"\n";
214         if (std::string(lyx_git_commit_hash) != "none")
215                 version_date += _("Built from git commit hash ")
216                         + from_utf8(lyx_git_commit_hash).substr(0,8);
217         version_date += "\n";
218
219         QString res;
220         QTextStream out(&res);
221         out << toqstr(version_date);
222         out << qt_("Library directory: ");
223         out << toqstr(makeDisplayPath(package().system_support().absFileName()));
224         out << "\n";
225         out << qt_("User directory: ");
226         out << toqstr(makeDisplayPath(package().user_support().absFileName()));
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         return res;
231 }
232
233 static QString buildinfo()
234 {
235         QString res;
236         QTextStream out(&res);
237         out << "LyX " << lyx_version
238                 << " (" << lyx_release_date << ")" << endl;
239         if (std::string(lyx_git_commit_hash) != "none")
240                 out << qt_("  Git commit hash ")
241                     << QString(lyx_git_commit_hash).left(8) << endl;
242
243         out << lyx_version_info << endl;
244         return res;
245 }
246
247
248 struct GuiAbout::Private
249 {
250         Ui::AboutUi ui;
251 };
252
253
254 GuiAbout::GuiAbout(GuiView & lv)
255         : DialogView(lv, "aboutlyx", qt_("About LyX")),
256         d(new GuiAbout::Private)
257 {
258         d->ui.setupUi(this);
259
260         d->ui.copyrightTB->setPlainText(copyright());
261         d->ui.copyrightTB->append(QString());
262         d->ui.copyrightTB->append(license());
263         d->ui.copyrightTB->append(QString());
264         d->ui.copyrightTB->append(disclaimer());
265
266         d->ui.versionLA->setText(version());
267         d->ui.buildinfoTB->setText(buildinfo());
268         d->ui.releasenotesTB->setHtml(release_notes());
269         d->ui.releasenotesTB->setOpenExternalLinks(true);
270         d->ui.creditsTB->setHtml(credits());
271
272         d->ui.tab->setUsesScrollButtons(false);
273 }
274
275
276 void GuiAbout::on_buttonBox_rejected()
277 {
278         close();
279 }
280
281
282 Dialog * createGuiAbout(GuiView & lv) { return new GuiAbout(lv); }
283
284
285 } // namespace frontend
286 } // namespace lyx
287
288 #include "moc_GuiAbout.cpp"