annotate src/gui/dialog/settings/recognition.cc @ 294:99cbc51433e4

*: cleanup uses of QPalette I didn't know about setBackgroundRole() which is very useful in 99% of the cases where I even needed to edit the palette
author Paper <paper@paper.us.eu.org>
date Sun, 12 May 2024 18:16:08 -0400
parents 862d0d8619f6
children b1f625b0227c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 232
diff changeset
5 #include <QCheckBox>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 232
diff changeset
6 #include <QGroupBox>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 232
diff changeset
7 #include <QLabel>
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include <QListWidget>
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <QListWidgetItem>
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->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
18
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 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
20
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 {
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
22 /* Feed link */
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
23 QWidget* widget = new QWidget(result);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
24 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
25
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
26 QCheckBox* checkbox = new QCheckBox(result);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
27 checkbox->setText(tr("Enable media player detection"));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
28 checkbox->setCheckState(detect_media_players ? Qt::Checked : Qt::Unchecked);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
29 widget_layout->addWidget(checkbox);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
30
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 QLabel* label = new QLabel(tr("Allowed media players:"), widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
33 widget_layout->addWidget(label);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
34 }
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 {
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
37 QListWidget* listwidget = new QListWidget(widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
38 for (size_t i = 0; i < players.size(); i++) {
149
e41505d24733 players: filter out web browsers, they aren't even supported in animia yet
Paper <mrpapersonic@gmail.com>
parents: 147
diff changeset
39 const auto& [enabled, player] = players[i];
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 232
diff changeset
40 if (player.type == animone::PlayerType::Default) {
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
41 QListWidgetItem* item = new QListWidgetItem(listwidget);
149
e41505d24733 players: filter out web browsers, they aren't even supported in animia yet
Paper <mrpapersonic@gmail.com>
parents: 147
diff changeset
42 item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
e41505d24733 players: filter out web browsers, they aren't even supported in animia yet
Paper <mrpapersonic@gmail.com>
parents: 147
diff changeset
43 item->setText(Strings::ToQString(player.name));
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
44 item->setData(Qt::UserRole, QVariant::fromValue(i));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
45 }
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 }
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 232
diff changeset
47 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item) {
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
48 if (!item)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
49 return;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
50 size_t i = item->data(Qt::UserRole).toUInt();
150
ffa535b6d630 *: avoid usage of std::[pair,tuple]
Paper <mrpapersonic@gmail.com>
parents: 149
diff changeset
51 players[i].enabled = item->checkState();
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
52 });
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
53 /* 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
54 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
55 detect_media_players = (state == Qt::Checked);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
56 listwidget->setEnabled(detect_media_players);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
57 });
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
58 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
59
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
60 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
61 }
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
63 full_layout->addWidget(widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
64 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
65
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 full_layout->setSpacing(10);
294
99cbc51433e4 *: cleanup uses of QPalette
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
67 full_layout->setContentsMargins(0, 0, 0, 0);
119
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)
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 232
diff changeset
78 : SettingsPage(parent, tr("Recognition")), players(session.config.recognition.players) {
134
54c9d36207db settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
79 detect_media_players = session.config.recognition.detect_media_players;
120
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 119
diff changeset
80 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
81 }