diff src/gui/dialog/settings/recognition.cc @ 134:54c9d36207db

settings/recognition: implement real media player stuff
author Paper <mrpapersonic@gmail.com>
date Thu, 09 Nov 2023 13:53:04 -0500
parents 275da698697d
children 69db40272acd
line wrap: on
line diff
--- a/src/gui/dialog/settings/recognition.cc	Thu Nov 09 11:45:38 2023 -0500
+++ b/src/gui/dialog/settings/recognition.cc	Thu Nov 09 13:53:04 2023 -0500
@@ -5,6 +5,7 @@
 #include <QListWidget>
 #include <QListWidgetItem>
 #include <QGroupBox>
+#include <QCheckBox>
 #include <QLabel>
 #include <QSizePolicy>
 #include <QVBoxLayout>
@@ -21,7 +22,7 @@
 
 	{
 		/* URLs */
-		QGroupBox* group = new QGroupBox(tr("URLs"), result);
+		QGroupBox* group = new QGroupBox(tr("Media players"), result);
 		group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
 
 		QVBoxLayout* group_layout = new QVBoxLayout(group);
@@ -31,6 +32,10 @@
 			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);
@@ -38,15 +43,28 @@
 
 			{
 				QListWidget* listwidget = new QListWidget(widget);
-				for (const auto& player : session.recognition.players) {
-					QListWidgetItem* item = new QListWidgetItem(listwidget);
-					item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked);
-					item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")"));
+				for (size_t i = 0; i < players.size(); i++) {
+					const auto& player = players[i];
 					{
-						QVariant v(QVariant::fromValue(player));
-						item->setData(Qt::UserRole, v);
+						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);
 			}
 
@@ -63,8 +81,13 @@
 }
 
 void SettingsPageRecognition::SaveInfo() {
+	session.config.recognition.detect_media_players = detect_media_players;
+	session.recognition.players = players;
 }
 
-SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) : SettingsPage(parent, tr("Recognition")) {
+SettingsPageRecognition::SettingsPageRecognition(QWidget* parent)
+	: SettingsPage(parent, tr("Recognition")),
+	  players(session.recognition.players) {
+	detect_media_players = session.config.recognition.detect_media_players;
 	AddTab(CreatePlayersWidget(), tr("Media players"));
 }