annotate src/gui/dialog/licenses.cc @ 345:d085c05247bd

build: fix windows build
author Paper <paper@paper.us.eu.org>
date Thu, 20 Jun 2024 07:39:01 -0400
parents eac06513db86
children a0aa8c8c4307
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>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
20
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21 #include <curl/curl.h>
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 # include "sys/win32/dark_theme.h"
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26 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
27 QTextBrowser* paragraph = new QTextBrowser(parent);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 paragraph->setFrameShape(QFrame::NoFrame);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 paragraph->setPlainText(Strings::ToQString(license));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30 paragraph->setFont(QFont("monospace"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31 return paragraph;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 }
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 LicensesWindow::LicensesWindow(QWidget* parent) : QDialog(parent) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35 resize(641, 500);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 setWindowTitle(tr("About Minori"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38 setAutoFillBackground(true);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40 QHBoxLayout* layout = new QHBoxLayout(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42 setBackgroundRole(QPalette::Base);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44 QTabWidget *tab_widget = new QTabWidget(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
45
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
46 layout->addWidget(tab_widget);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
47
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49 QFile f(":/licenses/LICENSE.minori");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
52
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 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
55 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
58 QFile f(":/licenses/LICENSE.MIT.animone");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
59 QFile b(":/licenses/LICENSE.BSD.animone");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 if (!f.exists() || !b.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 b.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
65
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66 std::string mit = Strings::ToUtf8String(f.readAll());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 std::string bsd = Strings::ToUtf8String(b.readAll());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69 QWidget *dual = new QWidget(this);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 QVBoxLayout *dual_layout = new QVBoxLayout(dual);
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 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
73 dual_notice->setWordWrap(true);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 dual_layout->addWidget(dual_notice);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
75 dual_layout->addWidget(create_license_widget(dual, bsd));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
76 dual_layout->addWidget(create_license_widget(dual, mit));
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 tab_widget->addTab(dual, tr("Animone"));
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
80
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
81 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
82 QFile f(":/licenses/LICENSE.anitomy");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
83 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
84 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
85
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
86 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
87 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
88 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
89
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
90 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
91 QFile f(":/licenses/LICENSE.fmt");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
92 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
93 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
94
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
95 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96 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
97 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
98
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
99 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
100 QFile f(":/licenses/LICENSE.nlohmann");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
101 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
102 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
103
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
104 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
105 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
106 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
107
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
108 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
109 QFile f(":/licenses/LICENSE.pugixml");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
110 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
111 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
112
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
113 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
114 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
115 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
116
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
117 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
118 QFile f(":/licenses/LICENSE.semver");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
119 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
120 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
121
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
122 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
123 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
124 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
125
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
126 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
127 QFile f(":/licenses/LICENSE.toml11");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
128 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
129 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
130
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
131 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
132 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
133 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
134
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
135 do {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
136 QFile f(":/licenses/LICENSE.utf8proc");
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
137 if (!f.exists())
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
138 break;
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
139
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
140 f.open(QFile::ReadOnly | QFile::Text);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
141 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
142 } while (0);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
143 }
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 void LicensesWindow::showEvent(QShowEvent* event) {
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
146 QDialog::showEvent(event);
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
147 #ifdef WIN32
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
148 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme());
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
149 #endif
eac06513db86 dialog/about: add licenses button
Paper <paper@paper.us.eu.org>
parents:
diff changeset
150 }