Skip to content

Commit

Permalink
make sounds of notification switchable on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Sep 27, 2024
1 parent 4ce2d32 commit 6fa233f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SingleNotificationEditor::SingleNotificationEditor(const Notification& notificat
connect(m_ui.m_btnBrowseSound, &QPushButton::clicked, this, &SingleNotificationEditor::selectSoundFile);
connect(m_ui.m_txtSound, &QLineEdit::textChanged, this, &SingleNotificationEditor::notificationChanged);
connect(m_ui.m_cbBalloon, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged);
connect(m_ui.m_cbPlaySound, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged);
connect(m_ui.m_slidVolume, &QSlider::valueChanged, this, &SingleNotificationEditor::notificationChanged);

QCompleter* completer = new QCompleter(qApp->builtinSounds(), this);
Expand All @@ -37,6 +38,7 @@ SingleNotificationEditor::SingleNotificationEditor(const Notification& notificat
Notification SingleNotificationEditor::notification() const {
return Notification(m_notificationEvent,
m_ui.m_cbBalloon->isChecked(),
m_ui.m_cbPlaySound->isChecked(),
m_ui.m_txtSound->text(),
m_ui.m_slidVolume->value());
}
Expand All @@ -60,6 +62,7 @@ void SingleNotificationEditor::loadNotification(const Notification& notification
m_ui.m_txtSound->setText(notification.soundPath());
m_ui.m_slidVolume->setValue(notification.volume());
m_ui.m_cbBalloon->setChecked(notification.balloonEnabled());
m_ui.m_cbPlaySound->setChecked(notification.soundEnabled());
m_notificationEvent = notification.event();

setTitle(Notification::nameForEvent(notification.event()));
Expand Down
11 changes: 10 additions & 1 deletion src/librssguard/gui/notifications/singlenotificationeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="m_cbPlaySound">
<property name="text">
<string>Play sound</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="m_wdgSound" native="true">
<property name="sizePolicy">
Expand Down Expand Up @@ -86,7 +93,7 @@
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -114,9 +121,11 @@
</customwidgets>
<tabstops>
<tabstop>m_cbBalloon</tabstop>
<tabstop>m_cbPlaySound</tabstop>
<tabstop>m_txtSound</tabstop>
<tabstop>m_btnBrowseSound</tabstop>
<tabstop>m_btnPlaySound</tabstop>
<tabstop>m_slidVolume</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down
5 changes: 4 additions & 1 deletion src/librssguard/miscellaneous/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ Application::Application(const QString& id, int& argc, char** argv, const QStrin
if (isFirstRun()) {
m_notifications->save({Notification(Notification::Event::GeneralEvent, true),
Notification(Notification::Event::NewUnreadArticlesFetched,
true,
true,
QSL("%1/notify.wav").arg(SOUNDS_BUILTIN_DIRECTORY)),
Notification(Notification::Event::NewAppVersionAvailable, true),
Expand Down Expand Up @@ -775,7 +776,9 @@ void Application::showGuiMessageCore(Notification::Event event,
if (m_notifications->areNotificationsEnabled()) {
auto notification = m_notifications->notificationForEvent(event);

notification.playSound(this);
if (notification.soundEnabled()) {
notification.playSound(this);
}

if (notification.balloonEnabled() && dest.m_tray) {
if (notification.event() == Notification::Event::ArticlesFetchingStarted && m_mainForm != nullptr &&
Expand Down
16 changes: 14 additions & 2 deletions src/librssguard/miscellaneous/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
#endif
#endif

Notification::Notification(Notification::Event event, bool balloon, const QString& sound_path, int volume)
: m_event(event), m_balloonEnabled(balloon), m_soundPath(sound_path), m_volume(volume) {}
Notification::Notification(Notification::Event event,
bool balloon,
bool play_sound,
const QString& sound_path,
int volume)
: m_event(event), m_balloonEnabled(balloon), m_soundEnabled(play_sound), m_soundPath(sound_path), m_volume(volume) {}

Notification::Event Notification::event() const {
return m_event;
Expand Down Expand Up @@ -153,6 +157,10 @@ QString Notification::nameForEvent(Notification::Event event) {
}
}

void Notification::setSoundEnabled(bool play_sound) {
m_soundEnabled = play_sound;
}

int Notification::volume() const {
return m_volume;
}
Expand All @@ -165,6 +173,10 @@ void Notification::setVolume(int volume) {
m_volume = volume;
}

bool Notification::soundEnabled() const {
return m_soundEnabled;
}

bool Notification::balloonEnabled() const {
return m_balloonEnabled;
}
5 changes: 5 additions & 0 deletions src/librssguard/miscellaneous/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Notification {

explicit Notification(Event event = Event::NoEvent,
bool balloon = {},
bool play_sound = true,
const QString& sound_path = {},
int volume = DEFAULT_NOTIFICATION_VOLUME);

Expand All @@ -57,6 +58,9 @@ class Notification {
qreal fractionalVolume() const;
void setVolume(int volume);

bool soundEnabled() const;
void setSoundEnabled(bool play_sound);

// Returns full path to audio file which should be played when notification
// is launched.
// NOTE: This property supports "%data%" placeholder.
Expand All @@ -71,6 +75,7 @@ class Notification {
private:
Event m_event;
bool m_balloonEnabled;
bool m_soundEnabled;
QString m_soundPath;
qreal m_volume;
};
Expand Down
8 changes: 5 additions & 3 deletions src/librssguard/miscellaneous/notificationfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ void NotificationFactory::load(Settings* settings) {
auto event = Notification::Event(key.toInt());
auto data = settings->value(GROUP(Notifications), key).toStringList();
auto enabled = data.at(0).toInt() != 0;
auto sound = data.at(1);
auto sound_path = data.at(1);
auto volume = data.size() > 2 ? data.at(2).toInt() : DEFAULT_NOTIFICATION_VOLUME;
auto play_sound = data.size() > 3 ? data.at(3).toInt() != 0 : true;

m_notifications.append(Notification(event, enabled, sound, volume));
m_notifications.append(Notification(event, enabled, play_sound, sound_path, volume));
}
}

Expand All @@ -67,6 +68,7 @@ void NotificationFactory::save(const QList<Notification>& new_notifications, Set
QString::number(int(n.event())),
QStringList{n.balloonEnabled() ? QSL("1") : QSL("0"),
n.soundPath(),
QString::number(n.volume())});
QString::number(n.volume()),
n.soundEnabled() ? QSL("1") : QSL("0")});
}
}

0 comments on commit 6fa233f

Please sign in to comment.