annotate src/gui/dialog/settings/recognition.cc @ 137:69db40272acd

dep/animia: [WIP] huge refactor this WILL NOT compile, because lots of code has been changed and every API in the original codebase has been removed. note that this api setup is not exactly permanent...
author Paper <mrpapersonic@gmail.com>
date Fri, 10 Nov 2023 13:52:47 -0500
parents 54c9d36207db
children 6fdf0632c003
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"
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 {
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
24 /* Feed link */
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
25 QWidget* widget = new QWidget(result);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
26 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
27
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
28 QCheckBox* checkbox = new QCheckBox(result);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
29 checkbox->setText(tr("Enable media player detection"));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
30 checkbox->setCheckState(detect_media_players ? Qt::Checked : Qt::Unchecked);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
31 widget_layout->addWidget(checkbox);
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 {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
34 QLabel* label = new QLabel(tr("Allowed media players:"), widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
35 widget_layout->addWidget(label);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
36 }
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 {
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
39 QListWidget* listwidget = new QListWidget(widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
40 for (size_t i = 0; i < players.size(); i++) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
41 const auto& player = players[i];
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
42 {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
43 QListWidgetItem* item = new QListWidgetItem(listwidget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
44 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
45 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")"));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
46 item->setData(Qt::UserRole, QVariant::fromValue(i));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
47 }
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 }
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
49 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
50 if (!item)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
51 return;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
52 size_t i = item->data(Qt::UserRole).toUInt();
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
53 players[i].SetEnabled(item->checkState());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
54 });
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
55 /* 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
56 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
57 detect_media_players = (state == Qt::Checked);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
58 listwidget->setEnabled(detect_media_players);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
59 });
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
60 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
61
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
62 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
63 }
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
65 full_layout->addWidget(widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
66 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
67
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
68 {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
69 /* Feed link */
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
70 QWidget* widget = new QWidget(result);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
71 QVBoxLayout* widget_layout = new QVBoxLayout(widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
72
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
73 {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
74 QLabel* label = new QLabel(tr("Allowed file extensions:"), widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
75 widget_layout->addWidget(label);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
76 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
77
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
78 {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
79 QListWidget* listwidget = new QListWidget(widget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
80 for (size_t i = 0; i < extensions.size(); i++) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
81 const auto& extension = extensions[i];
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
82 {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
83 QListWidgetItem* item = new QListWidgetItem(listwidget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
84 item->setCheckState(extension.GetEnabled() ? Qt::Checked : Qt::Unchecked);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
85 item->setText(Strings::ToQString("." + extension.GetExtension()));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
86 item->setData(Qt::UserRole, QVariant::fromValue(i));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
87 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
88 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
89 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
90 if (!item)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
91 return;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
92 size_t i = item->data(Qt::UserRole).toUInt();
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
93 extensions[i].SetEnabled(item->checkState());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
94 });
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
95
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
96 widget_layout->addWidget(listwidget);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
97 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
98
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
99 full_layout->addWidget(widget);
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 }
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102 full_layout->setSpacing(10);
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 return result;
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 }
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 void SettingsPageRecognition::SaveInfo() {
134
54c9d36207db settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
108 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
109 session.recognition.players = players;
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
110 session.recognition.extensions = extensions;
119
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111 }
4eae379cb1ff settings: add a very early recognition tab for configuring players and extensions
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112
134
54c9d36207db settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
113 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent)
54c9d36207db settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
114 : SettingsPage(parent, tr("Recognition")),
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
115 players(session.recognition.players),
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents: 134
diff changeset
116 extensions(session.recognition.extensions) {
134
54c9d36207db settings/recognition: implement real media player stuff
Paper <mrpapersonic@gmail.com>
parents: 120
diff changeset
117 detect_media_players = session.config.recognition.detect_media_players;
120
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 119
diff changeset
118 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
119 }