Mercurial > minori
annotate 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 |
| 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 | |
| 393 | 17 QWidget *SettingsPageLibrary::CreateFoldersWidget() |
| 18 { | |
| 19 QWidget *result = new QWidget(this); | |
| 226 | 20 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 21 | |
| 393 | 22 QVBoxLayout *full_layout = new QVBoxLayout(result); |
| 226 | 23 |
| 24 { | |
| 393 | 25 QGroupBox *group_box = new QGroupBox(tr("Library folders"), result); |
| 226 | 26 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 27 | |
| 393 | 28 QVBoxLayout *group_box_layout = new QVBoxLayout(group_box); |
| 226 | 29 |
| 30 { | |
| 393 | 31 QLabel *label = new QLabel(tr("These folders will be scanned and monitored for new episodes."), group_box); |
| 226 | 32 group_box_layout->addWidget(label); |
| 33 } | |
| 34 | |
| 35 { | |
| 393 | 36 DroppableListWidget *listwidget = new DroppableListWidget(group_box); |
| 226 | 37 listwidget->setSelectionMode(QAbstractItemView::ExtendedSelection); |
| 38 | |
| 393 | 39 for (const auto &path : paths) { |
| 40 QListWidgetItem *item = new QListWidgetItem(listwidget); | |
| 226 | 41 item->setText(Strings::ToQString(path)); |
| 42 /* add icons as well soon */ | |
| 43 } | |
| 44 | |
| 258 | 45 connect(listwidget, &DroppableListWidget::FilesDropped, this, [this, listwidget](QStringList list) { |
| 393 | 46 for (const auto &dir : list) { |
| 226 | 47 paths.insert(Strings::ToUtf8String(dir)); |
| 393 | 48 QListWidgetItem *item = new QListWidgetItem(listwidget); |
| 226 | 49 item->setText(dir); |
| 50 } | |
| 51 }); | |
| 52 | |
| 53 group_box_layout->addWidget(listwidget); | |
| 54 | |
| 55 { | |
| 393 | 56 QWidget *widget = new QWidget(group_box); |
| 57 QHBoxLayout *widget_layout = new QHBoxLayout(widget); | |
| 226 | 58 |
| 59 { | |
| 393 | 60 QLabel *label = new QLabel(tr("Tip: You can drag and drop folders here."), widget); |
| 226 | 61 widget_layout->addWidget(label); |
| 62 } | |
| 63 | |
| 64 widget_layout->addStretch(); | |
| 65 | |
| 66 { | |
| 393 | 67 QPushButton *button = new QPushButton(tr("Add new..."), widget); |
| 226 | 68 |
| 258 | 69 connect(button, &QPushButton::clicked, this, [this, listwidget] { |
| 70 const QString dir = QFileDialog::getExistingDirectory( | |
| 71 this, tr("Open Directory"), QDir::homePath(), | |
| 72 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); | |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
73 const std::string s_dir = Strings::ToUtf8String(dir); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
74 if (dir.isEmpty() || paths.count(s_dir)) |
| 226 | 75 return; |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
76 |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
77 paths.insert(s_dir); |
| 393 | 78 QListWidgetItem *item = new QListWidgetItem(listwidget); |
| 226 | 79 item->setText(dir); |
| 80 }); | |
| 81 | |
| 82 widget_layout->addWidget(button); | |
| 83 } | |
| 84 | |
| 85 { | |
| 393 | 86 QPushButton *button = new QPushButton(tr("Remove"), widget); |
| 226 | 87 |
| 258 | 88 connect(listwidget, &QListWidget::itemSelectionChanged, this, [button, listwidget] { |
| 393 | 89 QList<QListWidgetItem *> selection = listwidget->selectedItems(); |
| 226 | 90 button->setEnabled(selection.size() > 0); |
| 91 }); | |
| 92 | |
| 258 | 93 connect(button, &QPushButton::clicked, this, [this, listwidget] { |
| 393 | 94 QList<QListWidgetItem *> selection = listwidget->selectedItems(); |
| 95 for (const auto &item : selection) { | |
| 226 | 96 paths.erase(Strings::ToUtf8String(item->text())); |
| 97 delete item; | |
| 98 } | |
| 99 }); | |
| 100 | |
| 101 widget_layout->addWidget(button); | |
| 102 } | |
| 103 | |
| 104 group_box_layout->addWidget(widget); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 full_layout->addWidget(group_box); | |
| 109 } | |
| 110 | |
| 111 { | |
| 393 | 112 QGroupBox *group_box = new QGroupBox(tr("Real-time monitor"), result); |
| 226 | 113 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 114 | |
| 393 | 115 QVBoxLayout *group_box_layout = new QVBoxLayout(group_box); |
| 226 | 116 |
| 117 { | |
| 393 | 118 QCheckBox *checkbox = new QCheckBox(tr("Detect new files and folders under library folders"), group_box); |
| 226 | 119 checkbox->setCheckState(real_time_monitor ? Qt::Checked : Qt::Unchecked); |
| 120 | |
| 258 | 121 connect(checkbox, &QCheckBox::stateChanged, this, |
| 122 [this](int state) { real_time_monitor = (state != Qt::Unchecked); }); | |
| 226 | 123 |
| 124 group_box_layout->addWidget(checkbox); | |
| 125 } | |
| 126 | |
| 127 full_layout->addWidget(group_box); | |
| 128 } | |
| 129 | |
| 130 full_layout->setSpacing(10); | |
| 131 full_layout->addStretch(); | |
| 132 | |
| 133 return result; | |
| 134 } | |
| 135 | |
| 393 | 136 void SettingsPageLibrary::SaveInfo() |
| 137 { | |
| 226 | 138 session.config.library.paths = paths; |
| 139 session.config.library.real_time_monitor = real_time_monitor; | |
| 140 } | |
| 141 | |
| 393 | 142 SettingsPageLibrary::SettingsPageLibrary(QWidget *parent) |
| 143 : SettingsPage(parent, tr("Library")), paths(session.config.library.paths) | |
| 144 { | |
| 226 | 145 real_time_monitor = session.config.library.real_time_monitor; |
| 146 AddTab(CreateFoldersWidget(), tr("Folder")); | |
| 147 } |
