annotate src/gui/dialog/licenses.cc @ 367:8d45d892be88 default tip

*: instead of pugixml, use Qt XML features this means we have one extra Qt dependency though...
author Paper <paper@tflc.us>
date Sun, 17 Nov 2024 22:55:47 -0500
parents f81bed4e04ac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
1 #include "gui/dialog/licenses.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
2 #include "core/json.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
3 #include "core/session.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
4 #include "core/strings.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
5 #include "gui/widgets/text.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
6
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
7 #include <fmt/core.h>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
8
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
9 #include <QCoreApplication>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10 #include <QFont>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
11 #include <QHBoxLayout>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
12 #include <QTabWidget>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
13 #include <QTextBrowser>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14 #include <QTextCharFormat>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15 #include <QTextCursor>
347
a0aa8c8c4307 dep/anitomy: port to use UCS-4 rather than wide strings
Paper <paper@paper.us.eu.org>
parents: 339
diff changeset
16 #include <QFile>
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
17
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
18 #include <curl/curl.h>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
19 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
20 # include "sys/win32/dark_theme.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
23 static QWidget *create_license_widget(QWidget *parent, const QString& license) {
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24 QTextBrowser* paragraph = new QTextBrowser(parent);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25 paragraph->setFrameShape(QFrame::NoFrame);
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
26 paragraph->setPlainText(license);
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27 paragraph->setFont(QFont("monospace"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 return paragraph;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 }
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
31 static void create_basic_license(QTabWidget *tab_widget, const QString& filename, const QString& title) {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
32 QFile f(filename);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
33 if (!f.exists())
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
34 return;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
35
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
36 f.open(QFile::ReadOnly | QFile::Text);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
37 tab_widget->addTab(create_license_widget(tab_widget, f.readAll()), title);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
38 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
39
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
40 static void create_dual_license(QTabWidget *tab_widget, const QString& filename1, const QString& title1, const QString& filename2, const QString& title2) {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
41 QString l1, l2;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
42 {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
43 QFile f1(filename1), f2(filename2);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
44 if (!f1.exists() || !f2.exists())
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
45 return;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
46
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
47 f1.open(QFile::ReadOnly | QFile::Text);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
48 f2.open(QFile::ReadOnly | QFile::Text);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
49
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
50 l1 = f1.readAll();
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
51 l2 = f2.readAll();
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
52 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
53
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
54 QWidget *dual = new QWidget(tab_widget);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
55 QVBoxLayout *dual_layout = new QVBoxLayout(dual);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
56
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
57 QLabel *dual_notice = new QLabel(QCoreApplication::tr("%1 was originally forked from %2, where any changes divergent from %2 are now under a different license. Both the licenses for %1 and %2 are provided below, respectfully:").arg(title1, title2), dual);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
58 dual_notice->setWordWrap(true);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
59 dual_layout->addWidget(dual_notice);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
60 dual_layout->addWidget(create_license_widget(dual, l1));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
61 dual_layout->addWidget(create_license_widget(dual, l2));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
62
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
63 tab_widget->addTab(dual, title1);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
64 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
65
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66 LicensesWindow::LicensesWindow(QWidget* parent) : QDialog(parent) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 resize(641, 500);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 setWindowTitle(tr("About Minori"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 setAutoFillBackground(true);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
72 QHBoxLayout* layout = new QHBoxLayout(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
73
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 setBackgroundRole(QPalette::Base);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
75
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
76 QTabWidget *tab_widget = new QTabWidget(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
77
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
78 layout->addWidget(tab_widget);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
80 create_basic_license(tab_widget, ":/licenses/LICENSE.minori", tr("Minori"));
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
81
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
82 create_dual_license(tab_widget, ":/licenses/LICENSE.MIT.animone", tr("Animone"), ":/licenses/LICENSE.BSD.animone", tr("Anisthesia"));
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
83
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
84 create_basic_license(tab_widget, ":/licenses/LICENSE.anitomy", tr("Anitomy"));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
85 create_basic_license(tab_widget, ":/licenses/LICENSE.fmt", tr("fmt"));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
86 create_basic_license(tab_widget, ":/licenses/LICENSE.nlohmann", tr("JSON for Modern C++"));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
87 create_basic_license(tab_widget, ":/licenses/LICENSE.semver", tr("semver"));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
88 create_basic_license(tab_widget, ":/licenses/LICENSE.toml11", tr("toml11"));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
89 create_basic_license(tab_widget, ":/licenses/LICENSE.utf8proc", tr("utf8proc"));
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
90 }
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
91
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
92 void LicensesWindow::showEvent(QShowEvent* event) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
93 QDialog::showEvent(event);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
94 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
95 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
97 }