Debian Codegraph @

src/librssguard/gui/notifications/singlenotificationeditor.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "gui/notifications/singlenotificationeditor.h"
4
5 #include "gui/dialogs/filedialog.h"
6 #include "miscellaneous/application.h"
7 #include "miscellaneous/iconfactory.h"
8
9 #include <QCompleter>
10 #include <QFileSystemModel>
11
12 SingleNotificationEditor::SingleNotificationEditor(const Notification& notification, QWidget* parent)
13 : QGroupBox(parent), m_notificationEvent(Notification::Event::NoEvent) {
14 m_ui.setupUi(this);
15
16 #if defined(Q_OS_OS2)
17 m_ui.m_wdgSound->setVisible(false);
18 #else
19 m_ui.m_btnBrowseSound->setIcon(qApp->icons()->fromTheme(QSL("document-open")));
20 m_ui.m_btnPlaySound->setIcon(qApp->icons()->fromTheme(QSL("media-playback-start")));
21 #endif
22
23 loadNotification(notification);
24
25 connect(m_ui.m_btnPlaySound, &QPushButton::clicked, this, &SingleNotificationEditor::playSound);
26 connect(m_ui.m_btnBrowseSound, &QPushButton::clicked, this, &SingleNotificationEditor::selectSoundFile);
27 connect(m_ui.m_txtSound, &QLineEdit::textChanged, this, &SingleNotificationEditor::notificationChanged);
28 connect(m_ui.m_cbBalloon, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged);
29 connect(m_ui.m_cbDialogs, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged);
30 connect(m_ui.m_cbPlaySound, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged);
31 connect(m_ui.m_slidVolume, &QSlider::valueChanged, this, &SingleNotificationEditor::notificationChanged);
32
33 QCompleter* completer = new QCompleter(qApp->builtinSounds(), this);
34 m_ui.m_txtSound->setCompleter(completer);
35
36 setFixedHeight(sizeHint().height());
37 }
38
39 Notification SingleNotificationEditor::notification() const {
40 return Notification(m_notificationEvent,
41 m_ui.m_cbBalloon->isChecked(),
42 m_ui.m_cbDialogs->isChecked(),
43 m_ui.m_cbPlaySound->isChecked(),
44 m_ui.m_txtSound->text(),
45 m_ui.m_slidVolume->value());
46 }
47
48 void SingleNotificationEditor::selectSoundFile() {
49 auto fil = FileDialog::openFileName(window(),
50 tr("Select sound file"),
51 qApp->homeFolder(),
52 tr("WAV files (*.wav);;MP3 files (*.mp3)"),
53 nullptr,
54 GENERAL_REMEMBERED_PATH);
55
56 if (!fil.isEmpty()) {
57 m_ui.m_txtSound->setText(fil);
58 }
59 }
60
61 void SingleNotificationEditor::playSound() {
62 notification().playSound(qApp);
63 }
64
65 void SingleNotificationEditor::loadNotification(const Notification& notification) {
66 m_ui.m_txtSound->setText(notification.soundPath());
67 m_ui.m_slidVolume->setValue(notification.volume());
68 m_ui.m_cbBalloon->setChecked(notification.balloonEnabled());
69 m_ui.m_cbDialogs->setChecked(notification.dialogEnabled());
70 m_ui.m_cbPlaySound->setChecked(notification.soundEnabled());
71 m_notificationEvent = notification.event();
72
73 setTitle(Notification::nameForEvent(notification.event()));
74 }