annotate src/gui/dialog/settings/library.cc @ 318:3b355fa948c7

config: use TOML instead of INI unfortunately, INI is not enough, and causes some paths including semicolons to break with our current storage of the library folders. so, I decided to switch to TOML which does support real arrays...
author Paper <paper@paper.us.eu.org>
date Wed, 12 Jun 2024 05:25:41 -0400
parents b1f4d1867ab1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "core/session.h"
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include "core/strings.h"
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include "gui/dialog/settings.h"
317
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
4 #include "gui/widgets/drop_list_widget.h"
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
6 #include <QCheckBox>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
7 #include <QDir>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
8 #include <QFileDialog>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
9 #include <QGroupBox>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
10 #include <QLabel>
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #include <QListWidget>
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 #include <QListWidgetItem>
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
13 #include <QPushButton>
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <QSizePolicy>
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 #include <QVBoxLayout>
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 QWidget* SettingsPageLibrary::CreateFoldersWidget() {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 QWidget* result = new QWidget(this);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 QVBoxLayout* full_layout = new QVBoxLayout(result);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 QGroupBox* group_box = new QGroupBox(tr("Library folders"), result);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 QLabel* label = new QLabel(tr("These folders will be scanned and monitored for new episodes."), group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 group_box_layout->addWidget(label);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 DroppableListWidget* listwidget = new DroppableListWidget(group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 listwidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 for (const auto& path : paths) {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 QListWidgetItem* item = new QListWidgetItem(listwidget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 item->setText(Strings::ToQString(path));
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 /* add icons as well soon */
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
44 connect(listwidget, &DroppableListWidget::FilesDropped, this, [this, listwidget](QStringList list) {
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 for (const auto& dir : list) {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 paths.insert(Strings::ToUtf8String(dir));
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 QListWidgetItem* item = new QListWidgetItem(listwidget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 item->setText(dir);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 });
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 group_box_layout->addWidget(listwidget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 QWidget* widget = new QWidget(group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 QHBoxLayout* widget_layout = new QHBoxLayout(widget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 QLabel* label = new QLabel(tr("Tip: You can drag and drop folders here."), widget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 widget_layout->addWidget(label);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 widget_layout->addStretch();
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 QPushButton* button = new QPushButton(tr("Add new..."), widget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
68 connect(button, &QPushButton::clicked, this, [this, listwidget] {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
69 const QString dir = QFileDialog::getExistingDirectory(
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
70 this, tr("Open Directory"), QDir::homePath(),
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
71 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
72 const std::string s_dir = Strings::ToUtf8String(dir);
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
73 if (dir.isEmpty() || paths.count(s_dir))
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 return;
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
75
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
76 paths.insert(s_dir);
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 QListWidgetItem* item = new QListWidgetItem(listwidget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 item->setText(dir);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
79 });
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81 widget_layout->addWidget(button);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85 QPushButton* button = new QPushButton(tr("Remove"), widget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
87 connect(listwidget, &QListWidget::itemSelectionChanged, this, [button, listwidget] {
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 QList<QListWidgetItem*> selection = listwidget->selectedItems();
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 button->setEnabled(selection.size() > 0);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 });
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
92 connect(button, &QPushButton::clicked, this, [this, listwidget] {
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 QList<QListWidgetItem*> selection = listwidget->selectedItems();
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 for (const auto& item : selection) {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95 paths.erase(Strings::ToUtf8String(item->text()));
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96 delete item;
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98 });
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 widget_layout->addWidget(button);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 group_box_layout->addWidget(widget);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 full_layout->addWidget(group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111 QGroupBox* group_box = new QGroupBox(tr("Real-time monitor"), result);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
113
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
114 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
115
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
116 {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
117 QCheckBox* checkbox = new QCheckBox(tr("Detect new files and folders under library folders"), group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118 checkbox->setCheckState(real_time_monitor ? Qt::Checked : Qt::Unchecked);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
120 connect(checkbox, &QCheckBox::stateChanged, this,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
121 [this](int state) { real_time_monitor = (state != Qt::Unchecked); });
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123 group_box_layout->addWidget(checkbox);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
124 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 full_layout->addWidget(group_box);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 full_layout->setSpacing(10);
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130 full_layout->addStretch();
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 return result;
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 void SettingsPageLibrary::SaveInfo() {
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 session.config.library.paths = paths;
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137 session.config.library.real_time_monitor = real_time_monitor;
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138 }
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
139
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140 SettingsPageLibrary::SettingsPageLibrary(QWidget* parent)
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
141 : SettingsPage(parent, tr("Library")), paths(session.config.library.paths) {
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142 real_time_monitor = session.config.library.real_time_monitor;
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143 AddTab(CreateFoldersWidget(), tr("Folder"));
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144 }