Mercurial > minori
annotate src/gui/dialog/settings/recognition.cc @ 232:ff0061e75f0f
theme: add OS detection with glib
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 13 Jan 2024 11:06:16 -0500 |
parents | ffa535b6d630 |
children | 862d0d8619f6 |
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->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]; |
e41505d24733
players: filter out web browsers, they aren't even supported in animia yet
Paper <mrpapersonic@gmail.com>
parents:
147
diff
changeset
|
40 if (player.type == animia::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 } |
137
69db40272acd
dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
134
diff
changeset
|
47 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ |
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); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 return result; |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 } |
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 void SettingsPageRecognition::SaveInfo() { |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
72 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
|
73 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
|
74 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
75 |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
76 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
77 : 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
|
78 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 | 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 } |