comparison src/gui/dialog/settings/library.cc @ 393:963047512d34

*: clang-format
author Paper <paper@tflc.us>
date Fri, 07 Nov 2025 07:16:15 -0500
parents b1f4d1867ab1
children
comparison
equal deleted inserted replaced
392:a72d6d7b3568 393:963047512d34
12 #include <QListWidgetItem> 12 #include <QListWidgetItem>
13 #include <QPushButton> 13 #include <QPushButton>
14 #include <QSizePolicy> 14 #include <QSizePolicy>
15 #include <QVBoxLayout> 15 #include <QVBoxLayout>
16 16
17 QWidget* SettingsPageLibrary::CreateFoldersWidget() { 17 QWidget *SettingsPageLibrary::CreateFoldersWidget()
18 QWidget* result = new QWidget(this); 18 {
19 QWidget *result = new QWidget(this);
19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 20 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
20 21
21 QVBoxLayout* full_layout = new QVBoxLayout(result); 22 QVBoxLayout *full_layout = new QVBoxLayout(result);
22 23
23 { 24 {
24 QGroupBox* group_box = new QGroupBox(tr("Library folders"), result); 25 QGroupBox *group_box = new QGroupBox(tr("Library folders"), result);
25 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 26 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
26 27
27 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box); 28 QVBoxLayout *group_box_layout = new QVBoxLayout(group_box);
28 29
29 { 30 {
30 QLabel* label = new QLabel(tr("These folders will be scanned and monitored for new episodes."), group_box); 31 QLabel *label = new QLabel(tr("These folders will be scanned and monitored for new episodes."), group_box);
31 group_box_layout->addWidget(label); 32 group_box_layout->addWidget(label);
32 } 33 }
33 34
34 { 35 {
35 DroppableListWidget* listwidget = new DroppableListWidget(group_box); 36 DroppableListWidget *listwidget = new DroppableListWidget(group_box);
36 listwidget->setSelectionMode(QAbstractItemView::ExtendedSelection); 37 listwidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
37 38
38 for (const auto& path : paths) { 39 for (const auto &path : paths) {
39 QListWidgetItem* item = new QListWidgetItem(listwidget); 40 QListWidgetItem *item = new QListWidgetItem(listwidget);
40 item->setText(Strings::ToQString(path)); 41 item->setText(Strings::ToQString(path));
41 /* add icons as well soon */ 42 /* add icons as well soon */
42 } 43 }
43 44
44 connect(listwidget, &DroppableListWidget::FilesDropped, this, [this, listwidget](QStringList list) { 45 connect(listwidget, &DroppableListWidget::FilesDropped, this, [this, listwidget](QStringList list) {
45 for (const auto& dir : list) { 46 for (const auto &dir : list) {
46 paths.insert(Strings::ToUtf8String(dir)); 47 paths.insert(Strings::ToUtf8String(dir));
47 QListWidgetItem* item = new QListWidgetItem(listwidget); 48 QListWidgetItem *item = new QListWidgetItem(listwidget);
48 item->setText(dir); 49 item->setText(dir);
49 } 50 }
50 }); 51 });
51 52
52 group_box_layout->addWidget(listwidget); 53 group_box_layout->addWidget(listwidget);
53 54
54 { 55 {
55 QWidget* widget = new QWidget(group_box); 56 QWidget *widget = new QWidget(group_box);
56 QHBoxLayout* widget_layout = new QHBoxLayout(widget); 57 QHBoxLayout *widget_layout = new QHBoxLayout(widget);
57 58
58 { 59 {
59 QLabel* label = new QLabel(tr("Tip: You can drag and drop folders here."), widget); 60 QLabel *label = new QLabel(tr("Tip: You can drag and drop folders here."), widget);
60 widget_layout->addWidget(label); 61 widget_layout->addWidget(label);
61 } 62 }
62 63
63 widget_layout->addStretch(); 64 widget_layout->addStretch();
64 65
65 { 66 {
66 QPushButton* button = new QPushButton(tr("Add new..."), widget); 67 QPushButton *button = new QPushButton(tr("Add new..."), widget);
67 68
68 connect(button, &QPushButton::clicked, this, [this, listwidget] { 69 connect(button, &QPushButton::clicked, this, [this, listwidget] {
69 const QString dir = QFileDialog::getExistingDirectory( 70 const QString dir = QFileDialog::getExistingDirectory(
70 this, tr("Open Directory"), QDir::homePath(), 71 this, tr("Open Directory"), QDir::homePath(),
71 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); 72 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
72 const std::string s_dir = Strings::ToUtf8String(dir); 73 const std::string s_dir = Strings::ToUtf8String(dir);
73 if (dir.isEmpty() || paths.count(s_dir)) 74 if (dir.isEmpty() || paths.count(s_dir))
74 return; 75 return;
75 76
76 paths.insert(s_dir); 77 paths.insert(s_dir);
77 QListWidgetItem* item = new QListWidgetItem(listwidget); 78 QListWidgetItem *item = new QListWidgetItem(listwidget);
78 item->setText(dir); 79 item->setText(dir);
79 }); 80 });
80 81
81 widget_layout->addWidget(button); 82 widget_layout->addWidget(button);
82 } 83 }
83 84
84 { 85 {
85 QPushButton* button = new QPushButton(tr("Remove"), widget); 86 QPushButton *button = new QPushButton(tr("Remove"), widget);
86 87
87 connect(listwidget, &QListWidget::itemSelectionChanged, this, [button, listwidget] { 88 connect(listwidget, &QListWidget::itemSelectionChanged, this, [button, listwidget] {
88 QList<QListWidgetItem*> selection = listwidget->selectedItems(); 89 QList<QListWidgetItem *> selection = listwidget->selectedItems();
89 button->setEnabled(selection.size() > 0); 90 button->setEnabled(selection.size() > 0);
90 }); 91 });
91 92
92 connect(button, &QPushButton::clicked, this, [this, listwidget] { 93 connect(button, &QPushButton::clicked, this, [this, listwidget] {
93 QList<QListWidgetItem*> selection = listwidget->selectedItems(); 94 QList<QListWidgetItem *> selection = listwidget->selectedItems();
94 for (const auto& item : selection) { 95 for (const auto &item : selection) {
95 paths.erase(Strings::ToUtf8String(item->text())); 96 paths.erase(Strings::ToUtf8String(item->text()));
96 delete item; 97 delete item;
97 } 98 }
98 }); 99 });
99 100
106 107
107 full_layout->addWidget(group_box); 108 full_layout->addWidget(group_box);
108 } 109 }
109 110
110 { 111 {
111 QGroupBox* group_box = new QGroupBox(tr("Real-time monitor"), result); 112 QGroupBox *group_box = new QGroupBox(tr("Real-time monitor"), result);
112 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 113 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
113 114
114 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box); 115 QVBoxLayout *group_box_layout = new QVBoxLayout(group_box);
115 116
116 { 117 {
117 QCheckBox* checkbox = new QCheckBox(tr("Detect new files and folders under library folders"), group_box); 118 QCheckBox *checkbox = new QCheckBox(tr("Detect new files and folders under library folders"), group_box);
118 checkbox->setCheckState(real_time_monitor ? Qt::Checked : Qt::Unchecked); 119 checkbox->setCheckState(real_time_monitor ? Qt::Checked : Qt::Unchecked);
119 120
120 connect(checkbox, &QCheckBox::stateChanged, this, 121 connect(checkbox, &QCheckBox::stateChanged, this,
121 [this](int state) { real_time_monitor = (state != Qt::Unchecked); }); 122 [this](int state) { real_time_monitor = (state != Qt::Unchecked); });
122 123
130 full_layout->addStretch(); 131 full_layout->addStretch();
131 132
132 return result; 133 return result;
133 } 134 }
134 135
135 void SettingsPageLibrary::SaveInfo() { 136 void SettingsPageLibrary::SaveInfo()
137 {
136 session.config.library.paths = paths; 138 session.config.library.paths = paths;
137 session.config.library.real_time_monitor = real_time_monitor; 139 session.config.library.real_time_monitor = real_time_monitor;
138 } 140 }
139 141
140 SettingsPageLibrary::SettingsPageLibrary(QWidget* parent) 142 SettingsPageLibrary::SettingsPageLibrary(QWidget *parent)
141 : SettingsPage(parent, tr("Library")), paths(session.config.library.paths) { 143 : SettingsPage(parent, tr("Library")), paths(session.config.library.paths)
144 {
142 real_time_monitor = session.config.library.real_time_monitor; 145 real_time_monitor = session.config.library.real_time_monitor;
143 AddTab(CreateFoldersWidget(), tr("Folder")); 146 AddTab(CreateFoldersWidget(), tr("Folder"));
144 } 147 }