make sounds of notification switchable on/off
This commit is contained in:
parent
4ce2d32872
commit
6fa233f1e8
6 changed files with 41 additions and 7 deletions
|
@ -26,6 +26,7 @@ SingleNotificationEditor::SingleNotificationEditor(const Notification& notificat
|
||||||
connect(m_ui.m_btnBrowseSound, &QPushButton::clicked, this, &SingleNotificationEditor::selectSoundFile);
|
connect(m_ui.m_btnBrowseSound, &QPushButton::clicked, this, &SingleNotificationEditor::selectSoundFile);
|
||||||
connect(m_ui.m_txtSound, &QLineEdit::textChanged, this, &SingleNotificationEditor::notificationChanged);
|
connect(m_ui.m_txtSound, &QLineEdit::textChanged, this, &SingleNotificationEditor::notificationChanged);
|
||||||
connect(m_ui.m_cbBalloon, &QCheckBox::toggled, 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);
|
connect(m_ui.m_slidVolume, &QSlider::valueChanged, this, &SingleNotificationEditor::notificationChanged);
|
||||||
|
|
||||||
QCompleter* completer = new QCompleter(qApp->builtinSounds(), this);
|
QCompleter* completer = new QCompleter(qApp->builtinSounds(), this);
|
||||||
|
@ -37,6 +38,7 @@ SingleNotificationEditor::SingleNotificationEditor(const Notification& notificat
|
||||||
Notification SingleNotificationEditor::notification() const {
|
Notification SingleNotificationEditor::notification() const {
|
||||||
return Notification(m_notificationEvent,
|
return Notification(m_notificationEvent,
|
||||||
m_ui.m_cbBalloon->isChecked(),
|
m_ui.m_cbBalloon->isChecked(),
|
||||||
|
m_ui.m_cbPlaySound->isChecked(),
|
||||||
m_ui.m_txtSound->text(),
|
m_ui.m_txtSound->text(),
|
||||||
m_ui.m_slidVolume->value());
|
m_ui.m_slidVolume->value());
|
||||||
}
|
}
|
||||||
|
@ -60,6 +62,7 @@ void SingleNotificationEditor::loadNotification(const Notification& notification
|
||||||
m_ui.m_txtSound->setText(notification.soundPath());
|
m_ui.m_txtSound->setText(notification.soundPath());
|
||||||
m_ui.m_slidVolume->setValue(notification.volume());
|
m_ui.m_slidVolume->setValue(notification.volume());
|
||||||
m_ui.m_cbBalloon->setChecked(notification.balloonEnabled());
|
m_ui.m_cbBalloon->setChecked(notification.balloonEnabled());
|
||||||
|
m_ui.m_cbPlaySound->setChecked(notification.soundEnabled());
|
||||||
m_notificationEvent = notification.event();
|
m_notificationEvent = notification.event();
|
||||||
|
|
||||||
setTitle(Notification::nameForEvent(notification.event()));
|
setTitle(Notification::nameForEvent(notification.event()));
|
||||||
|
|
|
@ -24,6 +24,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="m_cbPlaySound">
|
||||||
|
<property name="text">
|
||||||
|
<string>Play sound</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="m_wdgSound" native="true">
|
<widget class="QWidget" name="m_wdgSound" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -86,7 +93,7 @@
|
||||||
<number>100</number>
|
<number>100</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -114,9 +121,11 @@
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>m_cbBalloon</tabstop>
|
<tabstop>m_cbBalloon</tabstop>
|
||||||
|
<tabstop>m_cbPlaySound</tabstop>
|
||||||
<tabstop>m_txtSound</tabstop>
|
<tabstop>m_txtSound</tabstop>
|
||||||
<tabstop>m_btnBrowseSound</tabstop>
|
<tabstop>m_btnBrowseSound</tabstop>
|
||||||
<tabstop>m_btnPlaySound</tabstop>
|
<tabstop>m_btnPlaySound</tabstop>
|
||||||
|
<tabstop>m_slidVolume</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
@ -284,6 +284,7 @@ Application::Application(const QString& id, int& argc, char** argv, const QStrin
|
||||||
if (isFirstRun()) {
|
if (isFirstRun()) {
|
||||||
m_notifications->save({Notification(Notification::Event::GeneralEvent, true),
|
m_notifications->save({Notification(Notification::Event::GeneralEvent, true),
|
||||||
Notification(Notification::Event::NewUnreadArticlesFetched,
|
Notification(Notification::Event::NewUnreadArticlesFetched,
|
||||||
|
true,
|
||||||
true,
|
true,
|
||||||
QSL("%1/notify.wav").arg(SOUNDS_BUILTIN_DIRECTORY)),
|
QSL("%1/notify.wav").arg(SOUNDS_BUILTIN_DIRECTORY)),
|
||||||
Notification(Notification::Event::NewAppVersionAvailable, true),
|
Notification(Notification::Event::NewAppVersionAvailable, true),
|
||||||
|
@ -775,7 +776,9 @@ void Application::showGuiMessageCore(Notification::Event event,
|
||||||
if (m_notifications->areNotificationsEnabled()) {
|
if (m_notifications->areNotificationsEnabled()) {
|
||||||
auto notification = m_notifications->notificationForEvent(event);
|
auto notification = m_notifications->notificationForEvent(event);
|
||||||
|
|
||||||
notification.playSound(this);
|
if (notification.soundEnabled()) {
|
||||||
|
notification.playSound(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (notification.balloonEnabled() && dest.m_tray) {
|
if (notification.balloonEnabled() && dest.m_tray) {
|
||||||
if (notification.event() == Notification::Event::ArticlesFetchingStarted && m_mainForm != nullptr &&
|
if (notification.event() == Notification::Event::ArticlesFetchingStarted && m_mainForm != nullptr &&
|
||||||
|
|
|
@ -15,8 +15,12 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Notification::Notification(Notification::Event event, bool balloon, const QString& sound_path, int volume)
|
Notification::Notification(Notification::Event event,
|
||||||
: m_event(event), m_balloonEnabled(balloon), m_soundPath(sound_path), m_volume(volume) {}
|
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 {
|
Notification::Event Notification::event() const {
|
||||||
return m_event;
|
return m_event;
|
||||||
|
@ -153,6 +157,10 @@ QString Notification::nameForEvent(Notification::Event event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Notification::setSoundEnabled(bool play_sound) {
|
||||||
|
m_soundEnabled = play_sound;
|
||||||
|
}
|
||||||
|
|
||||||
int Notification::volume() const {
|
int Notification::volume() const {
|
||||||
return m_volume;
|
return m_volume;
|
||||||
}
|
}
|
||||||
|
@ -165,6 +173,10 @@ void Notification::setVolume(int volume) {
|
||||||
m_volume = volume;
|
m_volume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Notification::soundEnabled() const {
|
||||||
|
return m_soundEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
bool Notification::balloonEnabled() const {
|
bool Notification::balloonEnabled() const {
|
||||||
return m_balloonEnabled;
|
return m_balloonEnabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Notification {
|
||||||
|
|
||||||
explicit Notification(Event event = Event::NoEvent,
|
explicit Notification(Event event = Event::NoEvent,
|
||||||
bool balloon = {},
|
bool balloon = {},
|
||||||
|
bool play_sound = true,
|
||||||
const QString& sound_path = {},
|
const QString& sound_path = {},
|
||||||
int volume = DEFAULT_NOTIFICATION_VOLUME);
|
int volume = DEFAULT_NOTIFICATION_VOLUME);
|
||||||
|
|
||||||
|
@ -57,6 +58,9 @@ class Notification {
|
||||||
qreal fractionalVolume() const;
|
qreal fractionalVolume() const;
|
||||||
void setVolume(int volume);
|
void setVolume(int volume);
|
||||||
|
|
||||||
|
bool soundEnabled() const;
|
||||||
|
void setSoundEnabled(bool play_sound);
|
||||||
|
|
||||||
// Returns full path to audio file which should be played when notification
|
// Returns full path to audio file which should be played when notification
|
||||||
// is launched.
|
// is launched.
|
||||||
// NOTE: This property supports "%data%" placeholder.
|
// NOTE: This property supports "%data%" placeholder.
|
||||||
|
@ -71,6 +75,7 @@ class Notification {
|
||||||
private:
|
private:
|
||||||
Event m_event;
|
Event m_event;
|
||||||
bool m_balloonEnabled;
|
bool m_balloonEnabled;
|
||||||
|
bool m_soundEnabled;
|
||||||
QString m_soundPath;
|
QString m_soundPath;
|
||||||
qreal m_volume;
|
qreal m_volume;
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,10 +51,11 @@ void NotificationFactory::load(Settings* settings) {
|
||||||
auto event = Notification::Event(key.toInt());
|
auto event = Notification::Event(key.toInt());
|
||||||
auto data = settings->value(GROUP(Notifications), key).toStringList();
|
auto data = settings->value(GROUP(Notifications), key).toStringList();
|
||||||
auto enabled = data.at(0).toInt() != 0;
|
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 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ void NotificationFactory::save(const QList<Notification>& new_notifications, Set
|
||||||
QString::number(int(n.event())),
|
QString::number(int(n.event())),
|
||||||
QStringList{n.balloonEnabled() ? QSL("1") : QSL("0"),
|
QStringList{n.balloonEnabled() ? QSL("1") : QSL("0"),
|
||||||
n.soundPath(),
|
n.soundPath(),
|
||||||
QString::number(n.volume())});
|
QString::number(n.volume()),
|
||||||
|
n.soundEnabled() ? QSL("1") : QSL("0")});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue