diff 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
line wrap: on
line diff
--- a/src/gui/dialog/licenses.cc	Tue Jul 16 21:15:59 2024 -0400
+++ b/src/gui/dialog/licenses.cc	Wed Oct 02 23:06:43 2024 -0400
@@ -24,14 +24,49 @@
 #	include "sys/win32/dark_theme.h"
 #endif
 
-static QWidget *create_license_widget(QWidget *parent, const std::string& license) {
+static QWidget *create_license_widget(QWidget *parent, const QString& license) {
 	QTextBrowser* paragraph = new QTextBrowser(parent);
 	paragraph->setFrameShape(QFrame::NoFrame);
-	paragraph->setPlainText(Strings::ToQString(license));
+	paragraph->setPlainText(license);
 	paragraph->setFont(QFont("monospace"));
 	return paragraph;
 }
 
+static void create_basic_license(QTabWidget *tab_widget, const QString& filename, const QString& title) {
+	QFile f(filename);
+	if (!f.exists())
+		return;
+
+	f.open(QFile::ReadOnly | QFile::Text);
+	tab_widget->addTab(create_license_widget(tab_widget, f.readAll()), title);
+}
+
+static void create_dual_license(QTabWidget *tab_widget, const QString& filename1, const QString& title1, const QString& filename2, const QString& title2) {
+	QString l1, l2;
+	{
+		QFile f1(filename1), f2(filename2);
+		if (!f1.exists() || !f2.exists())
+			return;
+
+		f1.open(QFile::ReadOnly | QFile::Text);
+		f2.open(QFile::ReadOnly | QFile::Text);
+
+		l1 = f1.readAll();
+		l2 = f2.readAll();
+	}
+
+	QWidget *dual = new QWidget(tab_widget);
+	QVBoxLayout *dual_layout = new QVBoxLayout(dual);
+
+	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);
+	dual_notice->setWordWrap(true);
+	dual_layout->addWidget(dual_notice);
+	dual_layout->addWidget(create_license_widget(dual, l1));
+	dual_layout->addWidget(create_license_widget(dual, l2));
+
+	tab_widget->addTab(dual, title1);
+}
+
 LicensesWindow::LicensesWindow(QWidget* parent) : QDialog(parent) {
 	resize(641, 500);
 	setWindowTitle(tr("About Minori"));
@@ -46,101 +81,17 @@
 
 	layout->addWidget(tab_widget);
 
-	do {
-		QFile f(":/licenses/LICENSE.minori");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("Minori"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.MIT.animone");
-		QFile b(":/licenses/LICENSE.BSD.animone");
-		if (!f.exists() || !b.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		b.open(QFile::ReadOnly | QFile::Text);
-
-		std::string mit = Strings::ToUtf8String(f.readAll());
-		std::string bsd = Strings::ToUtf8String(b.readAll());
+	create_basic_license(tab_widget, ":/licenses/LICENSE.minori", tr("Minori"));
 
-		QWidget *dual = new QWidget(this);
-		QVBoxLayout *dual_layout = new QVBoxLayout(dual);
-
-		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);
-		dual_notice->setWordWrap(true);
-		dual_layout->addWidget(dual_notice);
-		dual_layout->addWidget(create_license_widget(dual, bsd));
-		dual_layout->addWidget(create_license_widget(dual, mit));
-
-		tab_widget->addTab(dual, tr("Animone"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.anitomy");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("Anitomy"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.fmt");
-		if (!f.exists())
-			break;
+	create_dual_license(tab_widget, ":/licenses/LICENSE.MIT.animone", tr("Animone"), ":/licenses/LICENSE.BSD.animone", tr("Anisthesia"));
 
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("fmt"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.nlohmann");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("JSON for Modern C++"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.pugixml");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("pugixml"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.semver");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("semver"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.toml11");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("toml11"));
-	} while (0);
-
-	do {
-		QFile f(":/licenses/LICENSE.utf8proc");
-		if (!f.exists())
-			break;
-
-		f.open(QFile::ReadOnly | QFile::Text);
-		tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("utf8proc"));
-	} while (0);
+	create_basic_license(tab_widget, ":/licenses/LICENSE.anitomy", tr("Anitomy"));
+	create_basic_license(tab_widget, ":/licenses/LICENSE.fmt", tr("fmt"));
+	create_basic_license(tab_widget, ":/licenses/LICENSE.nlohmann", tr("JSON for Modern C++"));
+	create_basic_license(tab_widget, ":/licenses/LICENSE.pugixml", tr("pugixml"));
+	create_basic_license(tab_widget, ":/licenses/LICENSE.semver", tr("semver"));
+	create_basic_license(tab_widget, ":/licenses/LICENSE.toml11", tr("toml11"));
+	create_basic_license(tab_widget, ":/licenses/LICENSE.utf8proc", tr("utf8proc"));
 }
 
 void LicensesWindow::showEvent(QShowEvent* event) {