forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog_manage_groups.cpp
58 lines (48 loc) · 1.87 KB
/
dialog_manage_groups.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "dialog_manage_groups.h"
#include "ui_dialog_manage_groups.h"
#include "db/Database.hpp"
#include "sub/GroupUpdater.hpp"
#include "main/GuiUtils.hpp"
#include "ui/widget/GroupItem.h"
#include "ui/edit/dialog_edit_group.h"
#include <QInputDialog>
#include <QListWidgetItem>
#include <QMessageBox>
#define AddGroupToListIfExist(_id) \
auto __ent = NekoGui::profileManager->GetGroup(_id); \
if (__ent != nullptr) { \
auto wI = new QListWidgetItem(); \
auto w = new GroupItem(this, __ent, wI); \
wI->setData(114514, _id); \
ui->listWidget->addItem(wI); \
ui->listWidget->setItemWidget(wI, w); \
}
DialogManageGroups::DialogManageGroups(QWidget *parent) : QDialog(parent), ui(new Ui::DialogManageGroups) {
ui->setupUi(this);
for (auto id: NekoGui::profileManager->groupsTabOrder) {
AddGroupToListIfExist(id)
}
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, [=](QListWidgetItem *wI) {
auto w = dynamic_cast<GroupItem *>(ui->listWidget->itemWidget(wI));
emit w->edit_clicked();
});
}
DialogManageGroups::~DialogManageGroups() {
delete ui;
}
void DialogManageGroups::on_add_clicked() {
auto ent = NekoGui::ProfileManager::NewGroup();
auto dialog = new DialogEditGroup(ent, this);
int ret = dialog->exec();
dialog->deleteLater();
if (ret == QDialog::Accepted) {
NekoGui::profileManager->AddGroup(ent);
AddGroupToListIfExist(ent->id);
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
}
}
void DialogManageGroups::on_update_all_clicked() {
if (QMessageBox::question(this, tr("Confirmation"), tr("Update all subscriptions?")) == QMessageBox::StandardButton::Yes) {
UI_update_all_groups();
}
}