comparison 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
comparison
equal deleted inserted replaced
136:7d3ad9529c4c 137:69db40272acd
19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
20 20
21 QVBoxLayout* full_layout = new QVBoxLayout(result); 21 QVBoxLayout* full_layout = new QVBoxLayout(result);
22 22
23 { 23 {
24 /* URLs */ 24 /* Feed link */
25 QGroupBox* group = new QGroupBox(tr("Media players"), result); 25 QWidget* widget = new QWidget(result);
26 group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 26 QVBoxLayout* widget_layout = new QVBoxLayout(widget);
27 27
28 QVBoxLayout* group_layout = new QVBoxLayout(group); 28 QCheckBox* checkbox = new QCheckBox(result);
29 checkbox->setText(tr("Enable media player detection"));
30 checkbox->setCheckState(detect_media_players ? Qt::Checked : Qt::Unchecked);
31 widget_layout->addWidget(checkbox);
29 32
30 { 33 {
31 /* Feed link */ 34 QLabel* label = new QLabel(tr("Allowed media players:"), widget);
32 QWidget* widget = new QWidget(group); 35 widget_layout->addWidget(label);
33 QVBoxLayout* widget_layout = new QVBoxLayout(widget);
34
35 QCheckBox* checkbox = new QCheckBox(group);
36 checkbox->setText(tr("Enable media player detection"));
37 widget_layout->addWidget(checkbox);
38
39 {
40 QLabel* label = new QLabel(tr("Allowed media players:"), widget);
41 widget_layout->addWidget(label);
42 }
43
44 {
45 QListWidget* listwidget = new QListWidget(widget);
46 for (size_t i = 0; i < players.size(); i++) {
47 const auto& player = players[i];
48 {
49 QListWidgetItem* item = new QListWidgetItem(listwidget);
50 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked);
51 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")"));
52 item->setData(Qt::UserRole, QVariant::fromValue(i));
53 }
54 }
55 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
56 if (!item)
57 return;
58 size_t i = item->data(Qt::UserRole).toUInt();
59 players[i].SetEnabled(item->checkState());
60 });
61 /* this is down here because the listwidget state depends on it */
62 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {
63 detect_media_players = (state == Qt::Checked);
64 listwidget->setEnabled(detect_media_players);
65 });
66 listwidget->setEnabled(detect_media_players);
67
68 widget_layout->addWidget(listwidget);
69 }
70
71 group_layout->addWidget(widget);
72 } 36 }
73 37
74 full_layout->addWidget(group); 38 {
39 QListWidget* listwidget = new QListWidget(widget);
40 for (size_t i = 0; i < players.size(); i++) {
41 const auto& player = players[i];
42 {
43 QListWidgetItem* item = new QListWidgetItem(listwidget);
44 item->setCheckState(player.GetEnabled() ? Qt::Checked : Qt::Unchecked);
45 item->setText(Strings::ToQString(player.GetName() + " (" + player.GetExecutable() + ")"));
46 item->setData(Qt::UserRole, QVariant::fromValue(i));
47 }
48 }
49 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
50 if (!item)
51 return;
52 size_t i = item->data(Qt::UserRole).toUInt();
53 players[i].SetEnabled(item->checkState());
54 });
55 /* this is down here because the listwidget state depends on it */
56 connect(checkbox, &QCheckBox::stateChanged, this, [this, listwidget](int state) {
57 detect_media_players = (state == Qt::Checked);
58 listwidget->setEnabled(detect_media_players);
59 });
60 listwidget->setEnabled(checkbox->checkState() == Qt::Checked);
61
62 widget_layout->addWidget(listwidget);
63 }
64
65 full_layout->addWidget(widget);
66 }
67
68 {
69 /* Feed link */
70 QWidget* widget = new QWidget(result);
71 QVBoxLayout* widget_layout = new QVBoxLayout(widget);
72
73 {
74 QLabel* label = new QLabel(tr("Allowed file extensions:"), widget);
75 widget_layout->addWidget(label);
76 }
77
78 {
79 QListWidget* listwidget = new QListWidget(widget);
80 for (size_t i = 0; i < extensions.size(); i++) {
81 const auto& extension = extensions[i];
82 {
83 QListWidgetItem* item = new QListWidgetItem(listwidget);
84 item->setCheckState(extension.GetEnabled() ? Qt::Checked : Qt::Unchecked);
85 item->setText(Strings::ToQString("." + extension.GetExtension()));
86 item->setData(Qt::UserRole, QVariant::fromValue(i));
87 }
88 }
89 connect(listwidget, &QListWidget::itemChanged, this, [this](QListWidgetItem* item){
90 if (!item)
91 return;
92 size_t i = item->data(Qt::UserRole).toUInt();
93 extensions[i].SetEnabled(item->checkState());
94 });
95
96 widget_layout->addWidget(listwidget);
97 }
98
99 full_layout->addWidget(widget);
75 } 100 }
76 101
77 full_layout->setSpacing(10); 102 full_layout->setSpacing(10);
78 full_layout->addStretch();
79 103
80 return result; 104 return result;
81 } 105 }
82 106
83 void SettingsPageRecognition::SaveInfo() { 107 void SettingsPageRecognition::SaveInfo() {
84 session.config.recognition.detect_media_players = detect_media_players; 108 session.config.recognition.detect_media_players = detect_media_players;
85 session.recognition.players = players; 109 session.recognition.players = players;
110 session.recognition.extensions = extensions;
86 } 111 }
87 112
88 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent) 113 SettingsPageRecognition::SettingsPageRecognition(QWidget* parent)
89 : SettingsPage(parent, tr("Recognition")), 114 : SettingsPage(parent, tr("Recognition")),
90 players(session.recognition.players) { 115 players(session.recognition.players),
116 extensions(session.recognition.extensions) {
91 detect_media_players = session.config.recognition.detect_media_players; 117 detect_media_players = session.config.recognition.detect_media_players;
92 AddTab(CreatePlayersWidget(), tr("Media players")); 118 AddTab(CreatePlayersWidget(), tr("Media players"));
93 } 119 }