Debian Codegraph @

src/librssguard/gui/notifications/notificationseditor.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "gui/notifications/notificationseditor.h"
4
5 #include "3rd-party/boolinq/boolinq.h"
6 #include "definitions/definitions.h"
7 #include "gui/notifications/singlenotificationeditor.h"
8
9 #include <QVBoxLayout>
10
11 NotificationsEditor::NotificationsEditor(QWidget* parent) : QWidget(parent), m_layout(new QVBoxLayout(this)) {
12 m_ui.setupUi(this);
13 setLayout(m_layout);
14 }
15
16 void NotificationsEditor::loadNotifications(const QList<Notification>& notifications) {
17 auto all_events = Notification::allEvents();
18 auto notif = boolinq::from(notifications);
19
20 for (auto ev : all_events) {
21 if (notif.any([ev](auto n) {
22 return n.event() == ev;
23 })) {
24 auto* notif_editor = new SingleNotificationEditor(notif.first([ev](auto n) {
25 return n.event() == ev;
26 }),
27 this);
28
29 connect(notif_editor,
30 &SingleNotificationEditor::notificationChanged,
31 this,
32 &NotificationsEditor::someNotificationChanged);
33
34 m_layout->addWidget(notif_editor);
35 }
36 else {
37 auto* notif_editor = new SingleNotificationEditor(Notification(ev), this);
38
39 connect(notif_editor,
40 &SingleNotificationEditor::notificationChanged,
41 this,
42 &NotificationsEditor::someNotificationChanged);
43
44 m_layout->addWidget(notif_editor);
45 }
46 }
47
48 m_layout->addSpacerItem(new QSpacerItem(20, 40, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding));
49 }
50
51 QList<Notification> NotificationsEditor::allNotifications() const {
52 auto lst = boolinq::from(findChildren<SingleNotificationEditor*>())
53 .select([](const SingleNotificationEditor* ed) {
54 return ed->notification();
55 })
56 .toStdList();
57
58 return FROM_STD_LIST(QList<Notification>, lst);
59 }