Mercurial > minori
annotate 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 |
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" |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
4 #include "track/types.h" |
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> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 #include <algorithm> |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 Q_DECLARE_METATYPE(Track::Types::MediaPlayer); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 QWidget* SettingsPageRecognition::CreatePlayersWidget() { |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 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
|
18 result->setAutoFillBackground(true); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 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
|
20 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 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
|
22 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 { |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 /* URLs */ |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
25 QGroupBox* group = new QGroupBox(tr("Media players"), result); |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 group->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
|
27 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 QVBoxLayout* group_layout = new QVBoxLayout(group); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
30 { |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 /* Feed link */ |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 QWidget* widget = new QWidget(group); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 QVBoxLayout* widget_layout = new QVBoxLayout(widget); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
35 QCheckBox* checkbox = new QCheckBox(group); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
36 checkbox->setText(tr("Enable media player detection")); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
37 widget_layout->addWidget(checkbox); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
38 |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 { |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
40 QLabel* label = new QLabel(tr("Allowed media players:"), widget); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 widget_layout->addWidget(label); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
43 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 { |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
45 QListWidget* listwidget = new QListWidget(widget); |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
46 for (size_t i = 0; i < players.size(); i++) { |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
47 const auto& player = players[i]; |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
48 { |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
49 QListWidgetItem* item = new QListWidgetItem(listwidget); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
50 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
51 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")")); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
52 item->setData(Qt::UserRole, QVariant::fromValue(i)); |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
53 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
54 } |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
55 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){ |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
56 if (!item) |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
57 return; |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
58 size_t i = item->data(Qt::UserRole).toUInt(); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
59 players[i].SetEnabled(item->checkState()); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
60 }); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
61 /* this is down here because the listwidget state depends on it */ |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
62 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) { |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
63 detect_media_players = (state == Qt::Checked); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
64 listwidget->setEnabled(detect_media_players); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
65 }); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
66 listwidget->setEnabled(detect_media_players); |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
67 |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 widget_layout->addWidget(listwidget); |
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 group_layout->addWidget(widget); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
72 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
73 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
74 full_layout->addWidget(group); |
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 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
77 full_layout->setSpacing(10); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
78 full_layout->addStretch(); |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
79 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
80 return result; |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
81 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
82 |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
83 void SettingsPageRecognition::SaveInfo() { |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
84 session.config.recognition.detect_media_players = detect_media_players; |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
85 session.recognition.players = players; |
119
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
86 } |
4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
87 |
134
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
88 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
89 : SettingsPage(parent, tr("Recognition")), |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
90 players(session.recognition.players) { |
54c9d36207db
settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
91 detect_media_players = session.config.recognition.detect_media_players; |
120 | 92 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
|
93 } |