annotate src/gui/dialog/licenses.cc @ 365:f81bed4e04ac

*: megacommit that probably breaks things
author Paper <paper@paper.us.eu.org>
date Wed, 02 Oct 2024 23:06:43 -0400
parents a0aa8c8c4307
children 8d45d892be88
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
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
27 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
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);
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
30 paragraph->setPlainText(license);
339
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
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
35 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
36 QFile f(filename);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
37 if (!f.exists())
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
38 return;
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 f.open(QFile::ReadOnly | QFile::Text);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
41 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
42 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
43
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
44 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
45 QString l1, l2;
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 QFile f1(filename1), f2(filename2);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
48 if (!f1.exists() || !f2.exists())
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
49 return;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
50
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
51 f1.open(QFile::ReadOnly | QFile::Text);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
52 f2.open(QFile::ReadOnly | QFile::Text);
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 l1 = f1.readAll();
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
55 l2 = f2.readAll();
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
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
58 QWidget *dual = new QWidget(tab_widget);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
59 QVBoxLayout *dual_layout = new QVBoxLayout(dual);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
60
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
61 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
62 dual_notice->setWordWrap(true);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
63 dual_layout->addWidget(dual_notice);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
64 dual_layout->addWidget(create_license_widget(dual, l1));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
65 dual_layout->addWidget(create_license_widget(dual, l2));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
66
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
67 tab_widget->addTab(dual, title1);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
68 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
69
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 LicensesWindow::LicensesWindow(QWidget* parent) : QDialog(parent) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71 resize(641, 500);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
72 setWindowTitle(tr("About Minori"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
73 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 setAutoFillBackground(true);
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 QHBoxLayout* layout = new QHBoxLayout(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 setBackgroundRole(QPalette::Base);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
80 QTabWidget *tab_widget = new QTabWidget(this);
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 layout->addWidget(tab_widget);
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.minori", tr("Minori"));
339
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
85
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
86 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
87
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
88 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
89 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
90 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
91 create_basic_license(tab_widget, ":/licenses/LICENSE.pugixml", tr("pugixml"));
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
92 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
93 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
94 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
95 }
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
97 void LicensesWindow::showEvent(QShowEvent* event) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
98 QDialog::showEvent(event);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
99 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
100 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
101 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
102 }