Mercurial > minori
comparison src/gui/dialog/settings/recognition.cc @ 147:6fdf0632c003
track: use a bit of a more sane way to manage recognition
it also works with the new animia API
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 14 Nov 2023 13:19:40 -0500 |
parents | 69db40272acd |
children | e41505d24733 |
comparison
equal
deleted
inserted
replaced
146:d8a61e7e2a36 | 147:6fdf0632c003 |
---|---|
1 #include "core/session.h" | 1 #include "core/session.h" |
2 #include "core/strings.h" | 2 #include "core/strings.h" |
3 #include "gui/dialog/settings.h" | 3 #include "gui/dialog/settings.h" |
4 #include "track/types.h" | 4 |
5 #include <QListWidget> | 5 #include <QListWidget> |
6 #include <QListWidgetItem> | 6 #include <QListWidgetItem> |
7 #include <QGroupBox> | 7 #include <QGroupBox> |
8 #include <QCheckBox> | 8 #include <QCheckBox> |
9 #include <QLabel> | 9 #include <QLabel> |
10 #include <QSizePolicy> | 10 #include <QSizePolicy> |
11 #include <QVBoxLayout> | 11 #include <QVBoxLayout> |
12 | |
12 #include <algorithm> | 13 #include <algorithm> |
13 | |
14 Q_DECLARE_METATYPE(Track::Types::MediaPlayer); | |
15 | 14 |
16 QWidget* SettingsPageRecognition::CreatePlayersWidget() { | 15 QWidget* SettingsPageRecognition::CreatePlayersWidget() { |
17 QWidget* result = new QWidget(this); | 16 QWidget* result = new QWidget(this); |
18 result->setAutoFillBackground(true); | 17 result->setAutoFillBackground(true); |
19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 18 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
39 QListWidget* listwidget = new QListWidget(widget); | 38 QListWidget* listwidget = new QListWidget(widget); |
40 for (size_t i = 0; i < players.size(); i++) { | 39 for (size_t i = 0; i < players.size(); i++) { |
41 const auto& player = players[i]; | 40 const auto& player = players[i]; |
42 { | 41 { |
43 QListWidgetItem* item = new QListWidgetItem(listwidget); | 42 QListWidgetItem* item = new QListWidgetItem(listwidget); |
44 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked); | 43 item->setCheckState(player.first ? Qt::Checked : Qt::Unchecked); |
45 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")")); | 44 item->setText(Strings::ToQString(player.second.name)); |
46 item->setData(Qt::UserRole, QVariant::fromValue(i)); | 45 item->setData(Qt::UserRole, QVariant::fromValue(i)); |
47 } | 46 } |
48 } | 47 } |
49 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ | 48 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ |
50 if (!item) | 49 if (!item) |
51 return; | 50 return; |
52 size_t i = item->data(Qt::UserRole).toUInt(); | 51 size_t i = item->data(Qt::UserRole).toUInt(); |
53 players[i].SetEnabled(item->checkState()); | 52 players[i].first = item->checkState(); |
54 }); | 53 }); |
55 /* this is down here because the listwidget state depends on it */ | 54 /* this is down here because the listwidget state depends on it */ |
56 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) { | 55 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) { |
57 detect_media_players = (state == Qt::Checked); | 56 detect_media_players = (state == Qt::Checked); |
58 listwidget->setEnabled(detect_media_players); | 57 listwidget->setEnabled(detect_media_players); |
63 } | 62 } |
64 | 63 |
65 full_layout->addWidget(widget); | 64 full_layout->addWidget(widget); |
66 } | 65 } |
67 | 66 |
68 { | |
69 /* Feed link */ | |
70 QWidget* widget = new QWidget(result); | |
71 QVBoxLayout* widget_layout = new QVBoxLayout(widget); | |
72 | |
73 { | |
74 QLabel* label = new QLabel(tr("Allowed file extensions:"), widget); | |
75 widget_layout->addWidget(label); | |
76 } | |
77 | |
78 { | |
79 QListWidget* listwidget = new QListWidget(widget); | |
80 for (size_t i = 0; i < extensions.size(); i++) { | |
81 const auto& extension = extensions[i]; | |
82 { | |
83 QListWidgetItem* item = new QListWidgetItem(listwidget); | |
84 item->setCheckState(extension.GetEnabled() ? Qt::Checked : Qt::Unchecked); | |
85 item->setText(Strings::ToQString("." + extension.GetExtension())); | |
86 item->setData(Qt::UserRole, QVariant::fromValue(i)); | |
87 } | |
88 } | |
89 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ | |
90 if (!item) | |
91 return; | |
92 size_t i = item->data(Qt::UserRole).toUInt(); | |
93 extensions[i].SetEnabled(item->checkState()); | |
94 }); | |
95 | |
96 widget_layout->addWidget(listwidget); | |
97 } | |
98 | |
99 full_layout->addWidget(widget); | |
100 } | |
101 | |
102 full_layout->setSpacing(10); | 67 full_layout->setSpacing(10); |
103 | 68 |
104 return result; | 69 return result; |
105 } | 70 } |
106 | 71 |
107 void SettingsPageRecognition::SaveInfo() { | 72 void SettingsPageRecognition::SaveInfo() { |
108 session.config.recognition.detect_media_players = detect_media_players; | 73 session.config.recognition.detect_media_players = detect_media_players; |
109 session.recognition.players = players; | 74 session.config.recognition.players = players; |
110 session.recognition.extensions = extensions; | |
111 } | 75 } |
112 | 76 |
113 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) | 77 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) |
114 : SettingsPage(parent, tr("Recognition")), | 78 : SettingsPage(parent, tr("Recognition")), |
115 players(session.recognition.players), | 79 players(session.config.recognition.players) { |
116 extensions(session.recognition.extensions) { | |
117 detect_media_players = session.config.recognition.detect_media_players; | 80 detect_media_players = session.config.recognition.detect_media_players; |
118 AddTab(CreatePlayersWidget(), tr("Media players")); | 81 AddTab(CreatePlayersWidget(), tr("Media players")); |
119 } | 82 } |