Mercurial > minori
annotate 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 |
rev | line source |
---|---|
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include "core/session.h" |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 #include "core/strings.h" |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 #include "gui/dialog/settings.h" |
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
4 |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
5 #include <QListWidget> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
6 #include <QListWidgetItem> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 #include <QGroupBox> |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
8 #include <QCheckBox> |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 #include <QLabel> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 #include <QSizePolicy> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 #include <QVBoxLayout> |
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
12 |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 #include <algorithm> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 QWidget* SettingsPageRecognition::CreatePlayersWidget() { |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 QWidget* result = new QWidget(this); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 result->setAutoFillBackground(true); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 QVBoxLayout* full_layout = new QVBoxLayout(result); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 { |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
23 /* Feed link */ |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
24 QWidget* widget = new QWidget(result); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
25 QVBoxLayout* widget_layout = new QVBoxLayout(widget); |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
27 QCheckBox* checkbox = new QCheckBox(result); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
28 checkbox->setText(tr("Enable media player detection")); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
29 checkbox->setCheckState(detect_media_players ? Qt::Checked : Qt::Unchecked); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
30 widget_layout->addWidget(checkbox); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
31 |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
32 { |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
33 QLabel* label = new QLabel(tr("Allowed media players:"), widget); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
34 widget_layout->addWidget(label); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
35 } |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
37 { |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
38 QListWidget* listwidget = new QListWidget(widget); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
39 for (size_t i = 0; i < players.size(); i++) { |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
40 const auto& player = players[i]; |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
41 { |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
42 QListWidgetItem* item = new QListWidgetItem(listwidget); |
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
43 item->setCheckState(player.first ? Qt::Checked : Qt::Unchecked); |
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
44 item->setText(Strings::ToQString(player.second.name)); |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
45 item->setData(Qt::UserRole, QVariant::fromValue(i)); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
46 } |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 } |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
48 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
49 if (!item) |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
50 return; |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
51 size_t i = item->data(Qt::UserRole).toUInt(); |
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
52 players[i].first = item->checkState(); |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
53 }); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
54 /* this is down here because the listwidget state depends on it */ |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
55 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) { |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
56 detect_media_players = (state == Qt::Checked); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
57 listwidget->setEnabled(detect_media_players); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
58 }); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
59 listwidget->setEnabled(checkbox->checkState() == Qt::Checked); |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
60 |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
61 widget_layout->addWidget(listwidget); |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
62 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
63 |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
64 full_layout->addWidget(widget); |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
65 } |
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
66 |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 full_layout->setSpacing(10); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 return result; |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
70 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
71 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
72 void SettingsPageRecognition::SaveInfo() { |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
73 session.config.recognition.detect_media_players = detect_media_players; |
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
74 session.config.recognition.players = players; |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
75 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
76 |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
77 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
78 : SettingsPage(parent, tr("Recognition")), |
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
137
diff
changeset
|
79 players(session.config.recognition.players) { |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
80 detect_media_players = session.config.recognition.detect_media_players; |
120 | 81 AddTab(CreatePlayersWidget(), tr("Media players")); |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
82 } |