# HG changeset patch # User Paper # Date 1699555984 18000 # Node ID 54c9d36207db91ee0a7d1b79d31ad8bc8263d66d # Parent 4c5d11d294dd9f7e4e12f6fb971ad9f02994e22f settings/recognition: implement real media player stuff diff -r 4c5d11d294dd -r 54c9d36207db include/gui/dialog/settings.h --- a/include/gui/dialog/settings.h Thu Nov 09 11:45:38 2023 -0500 +++ b/include/gui/dialog/settings.h Thu Nov 09 13:53:04 2023 -0500 @@ -80,7 +80,9 @@ private: QWidget* CreatePlayersWidget(); + decltype(session.config.recognition.detect_media_players) detect_media_players; decltype(session.recognition.players) players; + decltype(session.recognition.extensions) extensions; }; class SettingsDialog final : public QDialog { diff -r 4c5d11d294dd -r 54c9d36207db src/core/filesystem.cc --- a/src/core/filesystem.cc Thu Nov 09 11:45:38 2023 -0500 +++ b/src/core/filesystem.cc Thu Nov 09 13:53:04 2023 -0500 @@ -21,6 +21,8 @@ #include "core/strings.h" #include +/* TODO: remove this and use std::filesystem */ + namespace Filesystem { Path::Path() { diff -r 4c5d11d294dd -r 54c9d36207db src/gui/dialog/settings/recognition.cc --- 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 #include #include +#include #include #include #include @@ -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")); }