annotate src/gui/dialog/licenses.cc @ 355:83e6ba09338f

gui/pages/seasons: fix function disambiguation on win32
author Paper <paper@paper.us.eu.org>
date Sun, 14 Jul 2024 23:46:18 -0400
parents a0aa8c8c4307
children f81bed4e04ac
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 "pugixml.hpp"
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 "utf8proc.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
11 #include <fmt/core.h>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
12
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
13 #include <QCoreApplication>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14 #include <QFont>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15 #include <QHBoxLayout>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
16 #include <QTabWidget>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
17 #include <QTextBrowser>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
18 #include <QTextCharFormat>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
19 #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
20 #include <QFile>
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22 #include <curl/curl.h>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24 # include "sys/win32/dark_theme.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27 static QWidget *create_license_widget(QWidget *parent, const std::string& license) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 QTextBrowser* paragraph = new QTextBrowser(parent);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 paragraph->setFrameShape(QFrame::NoFrame);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30 paragraph->setPlainText(Strings::ToQString(license));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31 paragraph->setFont(QFont("monospace"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 return paragraph;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
33 }
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
34
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35 LicensesWindow::LicensesWindow(QWidget* parent) : QDialog(parent) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 resize(641, 500);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37 setWindowTitle(tr("About Minori"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39 setAutoFillBackground(true);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41 QHBoxLayout* layout = new QHBoxLayout(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43 setBackgroundRole(QPalette::Base);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
45 QTabWidget *tab_widget = new QTabWidget(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
46
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
47 layout->addWidget(tab_widget);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50 QFile f(":/licenses/LICENSE.minori");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
52 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
55 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("Minori"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
58 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
59 QFile f(":/licenses/LICENSE.MIT.animone");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 QFile b(":/licenses/LICENSE.BSD.animone");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61 if (!f.exists() || !b.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
65 b.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 std::string mit = Strings::ToUtf8String(f.readAll());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 std::string bsd = Strings::ToUtf8String(b.readAll());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 QWidget *dual = new QWidget(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71 QVBoxLayout *dual_layout = new QVBoxLayout(dual);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
72
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
73 QLabel *dual_notice = new QLabel(tr("Animone was originally forked from Anisthesia, where any changes divergent from Anisthesia are now under a different license. Both the licenses for Animone and Anisthesia are provided below, respectfully:"), dual);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 dual_notice->setWordWrap(true);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
75 dual_layout->addWidget(dual_notice);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
76 dual_layout->addWidget(create_license_widget(dual, bsd));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
77 dual_layout->addWidget(create_license_widget(dual, mit));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
78
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79 tab_widget->addTab(dual, tr("Animone"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
80 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
81
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
82 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
83 QFile f(":/licenses/LICENSE.anitomy");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
84 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
85 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
86
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
87 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
88 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("Anitomy"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
89 } while (0);
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 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
92 QFile f(":/licenses/LICENSE.fmt");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
93 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
94 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
95
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
97 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("fmt"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
98 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
99
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
100 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
101 QFile f(":/licenses/LICENSE.nlohmann");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
102 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
103 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
104
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
105 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
106 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("JSON for Modern C++"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
107 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
108
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
109 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
110 QFile f(":/licenses/LICENSE.pugixml");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
111 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
112 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
113
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
114 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
115 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("pugixml"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
116 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
117
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
118 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
119 QFile f(":/licenses/LICENSE.semver");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
120 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
121 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
122
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
123 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
124 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("semver"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
125 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
126
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
127 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
128 QFile f(":/licenses/LICENSE.toml11");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
129 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
130 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
131
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
132 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
133 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("toml11"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
134 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
135
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
136 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
137 QFile f(":/licenses/LICENSE.utf8proc");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
138 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
139 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
140
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
141 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
142 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("utf8proc"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
143 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
144 }
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
145
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
146 void LicensesWindow::showEvent(QShowEvent* event) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
147 QDialog::showEvent(event);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
148 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
149 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
150 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
151 }