BibleTime
btaboutdialog.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btaboutdialog.h"
14 
15 #include <QApplication>
16 #include <QColor>
17 #include <QDebug>
18 #include <QDesktopServices>
19 #include <QDialogButtonBox>
20 #include <QDir>
21 #include <QFile>
22 #include <QFont>
23 #include <QFontMetrics>
24 #include <QHBoxLayout>
25 #include <QIODevice>
26 #include <QLabel>
27 #include <QPalette>
28 #include <QPlainTextEdit>
29 #include <QTabWidget>
30 #include <QTextBrowser>
31 #include <QTextStream>
32 #include <QtGlobal>
33 #include <QUrl>
34 #include <QVBoxLayout>
35 #include <QWidget>
36 #include <utility>
37 #include "../util/btconnect.h"
38 #include "../util/bticons.h"
39 #include "../util/directory.h"
40 #include "messagedialog.h"
41 
42 // Sword includes:
43 #include <swversion.h>
44 
45 
46 #define MAKE_STYLE(t) "<style type=\"text/css\">"\
47  "body{"\
48  "background-color:" + (t)->palette().color(QPalette::Window).name() + ";"\
49  "color:" + (t)->palette().color(QPalette::WindowText).name() +\
50  "}"\
51  "h3{font-weight:bold;text-align:center}"\
52  "a{text-decoration:underline}"\
53  "a:link{color:" + (t)->palette().color(QPalette::Link).name() + "}"\
54  "a:visited{color:" + (t)->palette().color(QPalette::LinkVisited).name() + "}"\
55  "</style>"
56 #define MAKE_HTML(t,x) "<html><head>" MAKE_STYLE(t) "</head><body>" + (x) + "</body></html>"
57 #define MAKE_LINK(c,u,t) "<a href=\"" u "\">"; (c) += (t); (c) += "</a>"
58 #define MAKE_LINK_STATIC(u,t) "<a href=\"" u "\">" t "</a>"
59 #define MAKE_CONTR(c,n,r) "<li>" n " (";\
60  (c) += (r);\
61  (c) += ")</li>"
62 #define MAKE_CONTR2(c,n,r,r2) "<li>" n " (";\
63  (c) += (r);\
64  (c) += ", ";\
65  (c) += (r2);\
66  (c) += ")</li>"
67 
68 class BtAboutDialog::LicenseTab final : public QWidget {
69 
70 public: // Methods:
71 
72  LicenseTab(QWidget * parent)
73  : QWidget(parent)
74  , m_label(new QLabel(this))
75  , m_licenseBrowser(new QPlainTextEdit(this))
76  {
77  auto * const mainLayout = new QVBoxLayout(this);
78 
79  m_label->setWordWrap(true);
80  mainLayout->addWidget(m_label);
81 
82  m_licenseBrowser->setReadOnly(true);
83  { // Set monospace font:
84  QFont licenseFont(QStringLiteral("BibleTime nonexistant font"));
85  licenseFont.setStyleHint(QFont::Monospace);
86  m_licenseBrowser->setFont(std::move(licenseFont));
87  }
88  mainLayout->addWidget(m_licenseBrowser);
89  }
90 
91  void setLabelText(QString const & text) { m_label->setText(text); }
92 
93  void setLicense(QString const & license)
94  { m_licenseBrowser->setPlainText(license); }
95 
96 private: // Fields
97 
98  QLabel * const m_label;
99  QPlainTextEdit * const m_licenseBrowser;
100 
101 }; // LicenseTab
102 
103 BtAboutDialog::BtAboutDialog(QWidget *parent, Qt::WindowFlags wflags)
104  : QDialog(parent, wflags)
105 {
106  setAttribute(Qt::WA_DeleteOnClose);
107  resize(640, 380);
108 
109  QVBoxLayout *mainLayout = new QVBoxLayout;
110 
111  QWidget *top = new QWidget(this);
112  QHBoxLayout *topLayout = new QHBoxLayout;
113  m_iconLabel = new QLabel(this);
114  m_iconLabel->setPixmap(BtIcons::instance().icon_bibletime.pixmap(48));
115  topLayout->addWidget(m_iconLabel);
116  m_versionLabel = new QLabel(this);
117  QFont font = m_versionLabel->font();
118  font.setPointSize(font.pointSize()+6);
119  font.setBold(true);
120  m_versionLabel->setFont(font);
121  topLayout->addWidget(m_versionLabel);
122  top->setLayout(topLayout);
123  mainLayout->addWidget(top, 0, Qt::AlignCenter);
124 
125  m_tabWidget = new QTabWidget(this);
126  mainLayout->addWidget(m_tabWidget);
127 
128  auto const addTab = [this]{
129  auto * const tab = new QTextBrowser(this);
130  tab->setOpenLinks(false);
131  m_tabWidget->addTab(tab, "");
132  BT_CONNECT(tab, &QTextBrowser::anchorClicked,
133  [](QUrl const & url) {
134  if (url.scheme() == "qt") {
135  qApp->aboutQt();
136  } else {
137  QDesktopServices::openUrl(url);
138  }
139  });
140  return tab;
141  };
142 
143  m_bibletimeTab = addTab();
144  m_contributorsTab = addTab();
145  m_swordTab = addTab();
146  m_qtTab = addTab();
147 
148  {
149  auto const & licensePath = util::directory::getLicensePath();
150  QFile licenseFile(licensePath);
151  if (licenseFile.open(QFile::ReadOnly)) {
152  m_licenseTab = new LicenseTab(this);
153  m_licenseTab->setLicense(QTextStream(&licenseFile).readAll());
154  m_tabWidget->addTab(m_licenseTab, "");
155  licenseFile.close();
156  } else {
157  qWarning() << "Failed to read license from" << licensePath;
158  }
159  }
160 
161  m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
162  mainLayout->addWidget(m_buttonBox);
163  setLayout(mainLayout);
164 
165  BT_CONNECT(m_buttonBox, &QDialogButtonBox::rejected,
166  this, &BtAboutDialog::reject);
167 
168  retranslateUi();
169 }
170 
171 void BtAboutDialog::resizeEvent(QResizeEvent* event) {
172  Q_UNUSED(event)
173  QString version = "BibleTime " BT_VERSION;
174  QFontMetrics fm(m_versionLabel->font());
175  int w = width() - m_iconLabel->width() - 80;
176  QString shortVersion = fm.elidedText(version, Qt::ElideMiddle, w);
177  m_versionLabel->setText(shortVersion);
178 }
179 
181  setWindowTitle(tr("About BibleTime"));
182 
188 
190 }
191 
193  m_tabWidget->setTabText(0, tr("&BibleTime"));
194 
195  QString content("<p>");
196  content += tr("BibleTime is an easy to use but powerful Bible study tool.");
197  content += "</p><p>";
198  content += tr("(c)1999-2021, The BibleTime Team");
199  content += "</p><p>" MAKE_LINK_STATIC("https://bibletime.info", "bibletime.info")
200  "</p>";
201  m_bibletimeTab->setHtml(MAKE_HTML(m_bibletimeTab, content));
202 }
203 
205  m_tabWidget->setTabText(1, tr("&Contributors"));
206 
207  const QString developer(tr("developer"));
208  const QString designer(tr("designer"));
209  const QString artist(tr("artist"));
210 
211  /****************************************************************************************
212  *** NB!!! Credits are sorted alphabetically by last name! ***
213  ****************************************************************************************/
214 
215  QString content("<p><b>");
216  content += tr("The following people contributed to BibleTime:");
217  content += "</b></p><ul>"
218  MAKE_CONTR(content, "Thomas Abthorpe", tr("documentation and translation manager"))
219  MAKE_CONTR2(content, "Joachim Ansorg", tr("project founder"), developer)
220  MAKE_CONTR(content, "David Blue", designer)
221  MAKE_CONTR(content, "Tim Brodie", developer)
222  MAKE_CONTR(content, "Timothy R. Butler", designer)
223  MAKE_CONTR(content, "Jim Campbell", developer)
224  MAKE_CONTR(content, "Lee Carpenter", developer)
225  MAKE_CONTR(content, "Jeremy Erickson", tr("packager"))
226  MAKE_CONTR(content, "Troy A. Griffitts", tr("creator of The Sword Project"))
227  MAKE_CONTR(content, "Martin Gruner", developer)
228  MAKE_CONTR(content, "Thomas Hagedorn", tr("domain sponsor"))
229  MAKE_CONTR(content, "Bob Harman", tr("howto"))
230  MAKE_CONTR(content, "Gary Holmlund", developer)
231  MAKE_CONTR(content, "Nikolay Igotti", developer)
232  MAKE_CONTR(content, "Laurent Valentin Jospin", artist)
233  MAKE_CONTR(content, "Eeli Kaikkonnen", developer)
234  MAKE_CONTR(content, "Chris Kujawa", developer)
235  MAKE_CONTR(content, "Mark Lybarger", developer)
236  MAKE_CONTR(content, "Konstantin Maslyuk", developer)
237  MAKE_CONTR(content, "Luke Mauldin", developer)
238  MAKE_CONTR(content, "James Ots", designer)
239  MAKE_CONTR(content, "Andrus Raag", artist)
240  MAKE_CONTR2(content, "Jaak Ristioja", tr("project manager"), developer)
241  MAKE_CONTR(content, "Fred Saalbach", tr("documentation"))
242  MAKE_CONTR(content, "Erik Schanze", tr("documentation"))
243  MAKE_CONTR(content, "Gary Sims", developer)
244  MAKE_CONTR2(content, "Wolfgang Stradner", tr("tester"), tr("usability expert"))
245  MAKE_CONTR(content, "Kang Sun", developer)
246  MAKE_CONTR(content, "Thorsten Uhlmann", developer)
247  MAKE_CONTR(content, "John Turpish", developer)
248  MAKE_CONTR(content, "David White", developer)
249  MAKE_CONTR(content, "Mark Zealey", developer)
250  MAKE_CONTR(content, "Patrick Sebastian Zimmermann", developer)
251  "</ul><p><b>";
252 
253 
254  /****************************************************************************************
255  *** NB!!! Credits are sorted alphabetically by last name! ***
256  ****************************************************************************************/
257  content += tr("The following people translated BibleTime into their language:");
258  content += "</b></p><ul>"
259  "<li>Roy Alvear Aguirre</li>"
260  "<li>Horatiu Alexe</li>"
261  "<li>Andrew Alfy</li>"
262  "<li>Jan B&#x11B;lohoubek</li>"
263  "<li>Luis Barron</li>"
264  "<li>M&aacute;rio Castanheira</li>"
265  "<li>Chun-shek Chan</li>"
266  "<li>Ján Ďanovský</li>"
267  "<li>Nouhoun Y. Diarra</li>"
268  "<li>Rafael Fagundes</li>"
269  "<li>Eeli Kaikkonen</li>"
270  "<li>Ilpo Kantonen</li>"
271  "<li>Pavel Laukko</li>"
272  "<li>Johan van der Lingen</li>"
273  "<li>Piotr Markiewicz</li>"
274  "<li>Konstantin Maslyuk</li>"
275  "<li>G&eacute;za Nov&aacute;k</li>"
276  "<li>Gabriel P&eacute;rez</li>"
277  "<li>Igor Plisco</li>"
278  "<li>Zdenko Podobn&yacute;</li>"
279  "<li>Jaak Ristioja</li>"
280  "<li>Igor Rykhlin</li>"
281  "<li>Vlad Savitsky</li>"
282  "<li>Jean Van Schaftingen</li>"
283  "<li>Flavio Theodor de Lima Silva</li>"
284  "<li>Henrik Sonesson</li>"
285  "<li>Giovanni Tedaldi</li>"
286  "<li>Roland Teschner</li>"
287  "<li>Damian Wrzalski</li>"
288  "<li>Dmitry Yurevich</li>"
289  "<li>Esteban Zeller</li>"
290  "<li>Aaron Zhou</li>"
291  "</ul><p>";
292  content += tr("Some names may be missing, please file an issue at %1 if "
293  "you notice errors or omissions.").arg(MAKE_LINK_STATIC(
294  "https://github.com/bibletime/bibletime/issues",
295  "https://github.com/bibletime/bibletime/issues"));
296  content += "</p>";
297 
298  m_contributorsTab->setHtml(MAKE_HTML(m_contributorsTab, content));
299 }
300 
301 
303  m_tabWidget->setTabText(2, tr("&SWORD"));
304 
305  QString version(sword::SWVersion::currentVersion.getText());
306  QString content("<h3>");
307  content += tr("SWORD library version %1").arg(version);
308  content += "</h3><p>";
309  content += tr("BibleTime makes use of the SWORD Project. The SWORD Project is the "
310  "CrossWire Bible Society's free Bible software project. Its purpose is to "
311  "create cross-platform open-source tools &mdash; covered by the GNU "
312  "General Public License &mdash; that allow programmers and Bible "
313  "societies to write new Bible software more quickly and easily.");
314  content += "</p><p>";
315  content += tr("The SWORD Project: ");
316  content += MAKE_LINK_STATIC("http://www.crosswire.org/sword/",
317  "www.crosswire.org/sword") "</p>";
318 
319  m_swordTab->setHtml(MAKE_HTML(m_swordTab, content));
320 }
321 
323  m_tabWidget->setTabText(3, tr("&Qt"));
324 
325  QString content("<h3>");
326  content += tr("Qt toolkit version %1").arg(qVersion());
327  content += "</h3><p>";
328  content += tr("This program uses Qt version %1.").arg(qVersion());
329  content += "</p><p>";
330  content += tr("Qt is a cross-platform application and UI framework, created with C++ "
331  "language. It has been released under the LGPL license.");
332 
333  content += " " MAKE_LINK(content, "qt://about", tr("More info...")) "</p>";
334 
335  m_qtTab->setHtml(MAKE_HTML(m_qtTab, content));
336 }
337 
339  if (!m_licenseTab)
340  return;
341 
342  m_tabWidget->setTabText(m_tabWidget->indexOf(m_licenseTab), tr("&License"));
343 
345  QStringLiteral("<p>%1</p><p>%2</p>")
346  .arg(tr("BibleTime is released under the GPL license. You "
347  "can download and use the program for personal, "
348  "private, public or commercial purposes without "
349  "restrictions, but can give away or distribute the "
350  "program only if you also distribute the "
351  "corresponding source code."),
352  tr("The complete legally binding license is below.")));
353 }
#define MAKE_LINK(c, u, t)
#define MAKE_CONTR(c, n, r)
#define MAKE_CONTR2(c, n, r, r2)
#define MAKE_HTML(t, x)
#define MAKE_LINK_STATIC(u, t)
#define BT_CONNECT(...)
Definition: btconnect.h:20
void setLicense(QString const &license)
QPlainTextEdit *const m_licenseBrowser
LicenseTab(QWidget *parent)
void setLabelText(QString const &text)
QLabel * m_versionLabel
Definition: btaboutdialog.h:56
BtAboutDialog(QWidget *parent=nullptr, Qt::WindowFlags wflags=Qt::Dialog)
QTextBrowser * m_bibletimeTab
Definition: btaboutdialog.h:49
QTextBrowser * m_qtTab
Definition: btaboutdialog.h:52
QTextBrowser * m_swordTab
Definition: btaboutdialog.h:51
QTabWidget * m_tabWidget
Definition: btaboutdialog.h:48
QDialogButtonBox * m_buttonBox
Definition: btaboutdialog.h:54
void retranslateBtTab()
QLabel * m_iconLabel
Definition: btaboutdialog.h:55
void retranslateQtTab()
void retranslateSwordTab()
void retranslateLicenceTab()
void retranslateContributorsTab()
void resizeEvent(QResizeEvent *event) override
QTextBrowser * m_contributorsTab
Definition: btaboutdialog.h:50
LicenseTab * m_licenseTab
Definition: btaboutdialog.h:53
static BtIcons & instance()
Definition: bticons.h:44
void prepareDialogBox(QDialogButtonBox *box)
QString const & getLicensePath()
Definition: directory.cpp:272