Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
133:4c5d11d294dd | 134:54c9d36207db |
---|---|
3 #include "gui/dialog/settings.h" | 3 #include "gui/dialog/settings.h" |
4 #include "track/types.h" | 4 #include "track/types.h" |
5 #include <QListWidget> | 5 #include <QListWidget> |
6 #include <QListWidgetItem> | 6 #include <QListWidgetItem> |
7 #include <QGroupBox> | 7 #include <QGroupBox> |
8 #include <QCheckBox> | |
8 #include <QLabel> | 9 #include <QLabel> |
9 #include <QSizePolicy> | 10 #include <QSizePolicy> |
10 #include <QVBoxLayout> | 11 #include <QVBoxLayout> |
11 #include <algorithm> | 12 #include <algorithm> |
12 | 13 |
19 | 20 |
20 QVBoxLayout* full_layout = new QVBoxLayout(result); | 21 QVBoxLayout* full_layout = new QVBoxLayout(result); |
21 | 22 |
22 { | 23 { |
23 /* URLs */ | 24 /* URLs */ |
24 QGroupBox* group = new QGroupBox(tr("URLs"), result); | 25 QGroupBox* group = new QGroupBox(tr("Media players"), result); |
25 group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 26 group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
26 | 27 |
27 QVBoxLayout* group_layout = new QVBoxLayout(group); | 28 QVBoxLayout* group_layout = new QVBoxLayout(group); |
28 | 29 |
29 { | 30 { |
30 /* Feed link */ | 31 /* Feed link */ |
31 QWidget* widget = new QWidget(group); | 32 QWidget* widget = new QWidget(group); |
32 QVBoxLayout* widget_layout = new QVBoxLayout(widget); | 33 QVBoxLayout* widget_layout = new QVBoxLayout(widget); |
33 | 34 |
35 QCheckBox* checkbox = new QCheckBox(group); | |
36 checkbox->setText(tr("Enable media player detection")); | |
37 widget_layout->addWidget(checkbox); | |
38 | |
34 { | 39 { |
35 QLabel* label = new QLabel(tr("Allowed media players:"), widget); | 40 QLabel* label = new QLabel(tr("Allowed media players:"), widget); |
36 widget_layout->addWidget(label); | 41 widget_layout->addWidget(label); |
37 } | 42 } |
38 | 43 |
39 { | 44 { |
40 QListWidget* listwidget = new QListWidget(widget); | 45 QListWidget* listwidget = new QListWidget(widget); |
41 for (const auto& player : session.recognition.players) { | 46 for (size_t i = 0; i < players.size(); i++) { |
42 QListWidgetItem* item = new QListWidgetItem(listwidget); | 47 const auto& player = players[i]; |
43 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked); | |
44 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")")); | |
45 { | 48 { |
46 QVariant v(QVariant::fromValue(player)); | 49 QListWidgetItem* item = new QListWidgetItem(listwidget); |
47 item->setData(Qt::UserRole, v); | 50 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked); |
51 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")")); | |
52 item->setData(Qt::UserRole, QVariant::fromValue(i)); | |
48 } | 53 } |
49 } | 54 } |
55 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ | |
56 if (!item) | |
57 return; | |
58 size_t i = item->data(Qt::UserRole).toUInt(); | |
59 players[i].SetEnabled(item->checkState()); | |
60 }); | |
61 /* this is down here because the listwidget state depends on it */ | |
62 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) { | |
63 detect_media_players = (state == Qt::Checked); | |
64 listwidget->setEnabled(detect_media_players); | |
65 }); | |
66 listwidget->setEnabled(detect_media_players); | |
67 | |
50 widget_layout->addWidget(listwidget); | 68 widget_layout->addWidget(listwidget); |
51 } | 69 } |
52 | 70 |
53 group_layout->addWidget(widget); | 71 group_layout->addWidget(widget); |
54 } | 72 } |
61 | 79 |
62 return result; | 80 return result; |
63 } | 81 } |
64 | 82 |
65 void SettingsPageRecognition::SaveInfo() { | 83 void SettingsPageRecognition::SaveInfo() { |
84 session.config.recognition.detect_media_players = detect_media_players; | |
85 session.recognition.players = players; | |
66 } | 86 } |
67 | 87 |
68 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) : SettingsPage(parent, tr("Recognition")) { | 88 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) |
89 : SettingsPage(parent, tr("Recognition")), | |
90 players(session.recognition.players) { | |
91 detect_media_players = session.config.recognition.detect_media_players; | |
69 AddTab(CreatePlayersWidget(), tr("Media players")); | 92 AddTab(CreatePlayersWidget(), tr("Media players")); |
70 } | 93 } |