Mercurial > minori
annotate src/gui/dialog/settings/library.cc @ 351:c844f8bb87ce
gui/theme: add xsettings backend
this also adds newly-necessary endianness methods in core/endian.h
which just so happen to be constexpr as well
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 14 Jul 2024 23:23:56 -0400 |
parents | b1f4d1867ab1 |
children |
rev | line source |
---|---|
226 | 1 #include "core/session.h" |
2 #include "core/strings.h" | |
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 | 5 |
258 | 6 #include <QCheckBox> |
7 #include <QDir> | |
8 #include <QFileDialog> | |
9 #include <QGroupBox> | |
10 #include <QLabel> | |
226 | 11 #include <QListWidget> |
12 #include <QListWidgetItem> | |
258 | 13 #include <QPushButton> |
226 | 14 #include <QSizePolicy> |
15 #include <QVBoxLayout> | |
16 | |
17 QWidget* SettingsPageLibrary::CreateFoldersWidget() { | |
18 QWidget* result = new QWidget(this); | |
19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
20 | |
21 QVBoxLayout* full_layout = new QVBoxLayout(result); | |
22 | |
23 { | |
24 QGroupBox* group_box = new QGroupBox(tr("Library folders"), result); | |
25 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
26 | |
27 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box); | |
28 | |
29 { | |
30 QLabel* label = new QLabel(tr("These folders will be scanned and monitored for new episodes."), group_box); | |
31 group_box_layout->addWidget(label); | |
32 } | |
33 | |
34 { | |
35 DroppableListWidget* listwidget = new DroppableListWidget(group_box); | |
36 listwidget->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
37 | |
38 for (const auto& path : paths) { | |
39 QListWidgetItem* item = new QListWidgetItem(listwidget); | |
40 item->setText(Strings::ToQString(path)); | |
41 /* add icons as well soon */ | |
42 } | |
43 | |
258 | 44 connect(listwidget, &DroppableListWidget::FilesDropped, this, [this, listwidget](QStringList list) { |
226 | 45 for (const auto& dir : list) { |
46 paths.insert(Strings::ToUtf8String(dir)); | |
47 QListWidgetItem* item = new QListWidgetItem(listwidget); | |
48 item->setText(dir); | |
49 } | |
50 }); | |
51 | |
52 group_box_layout->addWidget(listwidget); | |
53 | |
54 { | |
55 QWidget* widget = new QWidget(group_box); | |
56 QHBoxLayout* widget_layout = new QHBoxLayout(widget); | |
57 | |
58 { | |
59 QLabel* label = new QLabel(tr("Tip: You can drag and drop folders here."), widget); | |
60 widget_layout->addWidget(label); | |
61 } | |
62 | |
63 widget_layout->addStretch(); | |
64 | |
65 { | |
66 QPushButton* button = new QPushButton(tr("Add new..."), widget); | |
67 | |
258 | 68 connect(button, &QPushButton::clicked, this, [this, listwidget] { |
69 const QString dir = QFileDialog::getExistingDirectory( | |
70 this, tr("Open Directory"), QDir::homePath(), | |
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 | 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 | 77 QListWidgetItem* item = new QListWidgetItem(listwidget); |
78 item->setText(dir); | |
79 }); | |
80 | |
81 widget_layout->addWidget(button); | |
82 } | |
83 | |
84 { | |
85 QPushButton* button = new QPushButton(tr("Remove"), widget); | |
86 | |
258 | 87 connect(listwidget, &QListWidget::itemSelectionChanged, this, [button, listwidget] { |
226 | 88 QList<QListWidgetItem*> selection = listwidget->selectedItems(); |
89 button->setEnabled(selection.size() > 0); | |
90 }); | |
91 | |
258 | 92 connect(button, &QPushButton::clicked, this, [this, listwidget] { |
226 | 93 QList<QListWidgetItem*> selection = listwidget->selectedItems(); |
94 for (const auto& item : selection) { | |
95 paths.erase(Strings::ToUtf8String(item->text())); | |
96 delete item; | |
97 } | |
98 }); | |
99 | |
100 widget_layout->addWidget(button); | |
101 } | |
102 | |
103 group_box_layout->addWidget(widget); | |
104 } | |
105 } | |
106 | |
107 full_layout->addWidget(group_box); | |
108 } | |
109 | |
110 { | |
111 QGroupBox* group_box = new QGroupBox(tr("Real-time monitor"), result); | |
112 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
113 | |
114 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box); | |
115 | |
116 { | |
117 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 | |
258 | 120 connect(checkbox, &QCheckBox::stateChanged, this, |
121 [this](int state) { real_time_monitor = (state != Qt::Unchecked); }); | |
226 | 122 |
123 group_box_layout->addWidget(checkbox); | |
124 } | |
125 | |
126 full_layout->addWidget(group_box); | |
127 } | |
128 | |
129 full_layout->setSpacing(10); | |
130 full_layout->addStretch(); | |
131 | |
132 return result; | |
133 } | |
134 | |
135 void SettingsPageLibrary::SaveInfo() { | |
136 session.config.library.paths = paths; | |
137 session.config.library.real_time_monitor = real_time_monitor; | |
138 } | |
139 | |
140 SettingsPageLibrary::SettingsPageLibrary(QWidget* parent) | |
258 | 141 : SettingsPage(parent, tr("Library")), paths(session.config.library.paths) { |
226 | 142 real_time_monitor = session.config.library.real_time_monitor; |
143 AddTab(CreateFoldersWidget(), tr("Folder")); | |
144 } |