]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiAbout.cpp
linguistics.lyx: document how to insert footnotes in glosses.
[features.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 copyright()
87 {
88         QString release_year = release_date().toString("yyyy");
89         docstring copy_message =
90                 bformat(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995--%1$s LyX Team"),
91                         qstring_to_ucs4(release_year));
92         return toqstr(copy_message);
93 }
94
95
96 static QString license()
97 {
98         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.");
99 }
100
101
102 static QString disclaimer()
103 {
104         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.");
105 }
106
107
108 static QString version()
109 {
110         QString loc_release_date;
111         QDate date = release_date();
112         if (date.isValid()) {
113                 QLocale loc;
114                 loc_release_date = loc.toString(date, QLocale::LongFormat);
115         } else {
116                 if (QString(lyx_release_date) == "not released yet")
117                         loc_release_date = qt_("not released yet");
118                 else
119                         loc_release_date = toqstr(lyx_release_date);
120         }
121         docstring version_date =
122                 bformat(_("LyX Version %1$s\n(%2$s)"),
123                         from_ascii(lyx_version),
124                         qstring_to_ucs4(loc_release_date))+"\n";
125         if (std::string(lyx_git_commit_hash) != "none")
126                 version_date += _("Built from git commit hash ")
127                         + from_utf8(lyx_git_commit_hash).substr(0,8);
128         version_date += "\n";
129
130         QString res;
131         QTextStream out(&res);
132         out << toqstr(version_date);
133         out << qt_("Library directory: ");
134         out << toqstr(makeDisplayPath(package().system_support().absFileName()));
135         out << "\n";
136         out << qt_("User directory: ");
137         out << toqstr(makeDisplayPath(package().user_support().absFileName()));
138         if (std::string(lyx_git_commit_hash) != "none") {
139                 out << "\n";
140                 out << toqstr(bformat(_("Qt Version (run-time): %1$s"), from_ascii(qVersion()))) << "\n";
141                 out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR))) << "\n";
142         }
143         return res;
144 }
145
146 static QString buildinfo()
147 {
148         QString res;
149         QTextStream out(&res);
150         out << "LyX " << lyx_version
151                 << " (" << lyx_release_date << ")" << endl;
152         if (std::string(lyx_git_commit_hash) != "none")
153                 out << qt_("  Git commit hash ")
154                     << QString(lyx_git_commit_hash).left(8) << endl;
155
156         out << lyx_version_info << endl;
157         return res;
158 }
159
160
161 struct GuiAbout::Private
162 {
163         Ui::AboutUi ui;
164 };
165
166
167 GuiAbout::GuiAbout(GuiView & lv)
168         : DialogView(lv, "aboutlyx", qt_("About LyX")),
169         d(new GuiAbout::Private)
170 {
171         d->ui.setupUi(this);
172
173         d->ui.copyrightTB->setPlainText(copyright());
174         d->ui.copyrightTB->append(QString());
175         d->ui.copyrightTB->append(license());
176         d->ui.copyrightTB->append(QString());
177         d->ui.copyrightTB->append(disclaimer());
178
179         d->ui.versionLA->setText(version());
180         d->ui.buildinfoTB->setText(buildinfo());
181         d->ui.creditsTB->setHtml(credits());
182 }
183
184
185 void GuiAbout::on_closePB_clicked()
186 {
187         close();
188 }
189
190
191 Dialog * createGuiAbout(GuiView & lv) { return new GuiAbout(lv); }
192
193
194 } // namespace frontend
195 } // namespace lyx
196
197 #include "moc_GuiAbout.cpp"