diff src/gui/dialog/settings/recognition.cc @ 137:69db40272acd

dep/animia: [WIP] huge refactor this WILL NOT compile, because lots of code has been changed and every API in the original codebase has been removed. note that this api setup is not exactly permanent...
author Paper <mrpapersonic@gmail.com>
date Fri, 10 Nov 2023 13:52:47 -0500
parents 54c9d36207db
children 6fdf0632c003
line wrap: on
line diff
--- a/src/gui/dialog/settings/recognition.cc	Fri Nov 10 10:07:01 2023 -0500
+++ b/src/gui/dialog/settings/recognition.cc	Fri Nov 10 13:52:47 2023 -0500
@@ -21,61 +21,85 @@
 	QVBoxLayout* full_layout = new QVBoxLayout(result);
 
 	{
-		/* URLs */
-		QGroupBox* group = new QGroupBox(tr("Media players"), result);
-		group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+		/* Feed link */
+		QWidget* widget = new QWidget(result);
+		QVBoxLayout* widget_layout = new QVBoxLayout(widget);
 
-		QVBoxLayout* group_layout = new QVBoxLayout(group);
+		QCheckBox* checkbox = new QCheckBox(result);
+		checkbox->setText(tr("Enable media player detection"));
+		checkbox->setCheckState(detect_media_players ? Qt::Checked : Qt::Unchecked);
+		widget_layout->addWidget(checkbox);
+
+		{
+			QLabel* label = new QLabel(tr("Allowed media players:"), widget);
+			widget_layout->addWidget(label);
+		}
 
 		{
-			/* Feed link */
-			QWidget* widget = new QWidget(group);
-			QVBoxLayout* widget_layout = new QVBoxLayout(widget);
-
-			QCheckBox* checkbox = new QCheckBox(group);
-			checkbox->setText(tr("Enable media player detection"));
-			widget_layout->addWidget(checkbox);
-
-			{
-				QLabel* label = new QLabel(tr("Allowed media players:"), widget);
-				widget_layout->addWidget(label);
+			QListWidget* listwidget = new QListWidget(widget);
+			for (size_t i = 0; i < players.size(); i++) {
+				const auto& player = players[i];
+				{
+					QListWidgetItem* item = new QListWidgetItem(listwidget);
+					item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked);
+					item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")"));
+					item->setData(Qt::UserRole, QVariant::fromValue(i));
+				}
 			}
+			connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
+				if (!item)
+					return;
+				size_t i = item->data(Qt::UserRole).toUInt();
+				players[i].SetEnabled(item->checkState());
+			});
+			/* this is down here because the listwidget state depends on it */
+			connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {
+				detect_media_players = (state == Qt::Checked);
+				listwidget->setEnabled(detect_media_players);
+			});
+			listwidget->setEnabled(checkbox->checkState() == Qt::Checked);
 
-			{
-				QListWidget* listwidget = new QListWidget(widget);
-				for (size_t i = 0; i < players.size(); i++) {
-					const auto& player = players[i];
-					{
-						QListWidgetItem* item = new QListWidgetItem(listwidget);
-						item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked);
-						item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")"));
-						item->setData(Qt::UserRole, QVariant::fromValue(i));
-					}
-				}
-				connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
-					if (!item)
-						return;
-					size_t i = item->data(Qt::UserRole).toUInt();
-					players[i].SetEnabled(item->checkState());
-				});
-				/* this is down here because the listwidget state depends on it */
-				connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {
-					detect_media_players = (state == Qt::Checked);
-					listwidget->setEnabled(detect_media_players);
-				});
-				listwidget->setEnabled(detect_media_players);
-
-				widget_layout->addWidget(listwidget);
-			}
-
-			group_layout->addWidget(widget);
+			widget_layout->addWidget(listwidget);
 		}
 
-		full_layout->addWidget(group);
+		full_layout->addWidget(widget);
+	}
+
+	{
+		/* Feed link */
+		QWidget* widget = new QWidget(result);
+		QVBoxLayout* widget_layout = new QVBoxLayout(widget);
+
+		{
+			QLabel* label = new QLabel(tr("Allowed file extensions:"), widget);
+			widget_layout->addWidget(label);
+		}
+
+		{
+			QListWidget* listwidget = new QListWidget(widget);
+			for (size_t i = 0; i < extensions.size(); i++) {
+				const auto& extension = extensions[i];
+				{
+					QListWidgetItem* item = new QListWidgetItem(listwidget);
+					item->setCheckState(extension.GetEnabled() ? Qt::Checked : Qt::Unchecked);
+					item->setText(Strings::ToQString("." + extension.GetExtension()));
+					item->setData(Qt::UserRole, QVariant::fromValue(i));
+				}
+			}
+			connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
+				if (!item)
+					return;
+				size_t i = item->data(Qt::UserRole).toUInt();
+				extensions[i].SetEnabled(item->checkState());
+			});
+
+			widget_layout->addWidget(listwidget);
+		}
+
+		full_layout->addWidget(widget);
 	}
 
 	full_layout->setSpacing(10);
-	full_layout->addStretch();
 
 	return result;
 }
@@ -83,11 +107,13 @@
 void SettingsPageRecognition::SaveInfo() {
 	session.config.recognition.detect_media_players = detect_media_players;
 	session.recognition.players = players;
+	session.recognition.extensions = extensions;
 }
 
 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent)
 	: SettingsPage(parent, tr("Recognition")),
-	  players(session.recognition.players) {
+	  players(session.recognition.players),
+	  extensions(session.recognition.extensions) {
 	detect_media_players = session.config.recognition.detect_media_players;
 	AddTab(CreatePlayersWidget(), tr("Media players"));
 }