From 0bbe9838c497fe9ebbecb5b272fc03181907f734 Mon Sep 17 00:00:00 2001 From: m4x3t Date: Sat, 29 Jun 2019 19:54:27 +0200 Subject: [PATCH] Add option: notification on playback resume (#196) * Add option: notification on playback resume This adds an optional setting to show the notification that is displayed when changing the track when resuming playback as well. * Modify resume notification calling This adds a new signal "Resumed" that is emitted when the player status is changed from Paused to Playing. The AlbumArtLoaded function will only be called again when playback is manually resumed, and not when the player is started for the first time or when the track is changed. --- src/core/mainwindow.cpp | 1 + src/core/player.cpp | 1 + src/core/player.h | 2 ++ src/settings/notificationssettingspage.cpp | 2 ++ src/settings/notificationssettingspage.ui | 7 +++++++ src/widgets/osd.cpp | 8 ++++++++ src/widgets/osd.h | 2 ++ 7 files changed, 23 insertions(+) diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index bc840a12a..04b1430bc 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -492,6 +492,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co connect(app_->player(), SIGNAL(Stopped()), ui_->playlist, SLOT(ActiveStopped())); connect(app_->player(), SIGNAL(Paused()), osd_, SLOT(Paused())); + connect(app_->player(), SIGNAL(Resumed()), osd_, SLOT(Resumed())); connect(app_->player(), SIGNAL(Stopped()), osd_, SLOT(Stopped())); connect(app_->player(), SIGNAL(PlaylistFinished()), osd_, SLOT(PlaylistFinished())); connect(app_->player(), SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int))); diff --git a/src/core/player.cpp b/src/core/player.cpp index b2713a96a..53d162456 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -450,6 +450,7 @@ void Player::PlayPause() { switch (engine_->state()) { case Engine::Paused: engine_->Unpause(); + emit Resumed(); break; case Engine::Playing: { diff --git a/src/core/player.h b/src/core/player.h index 3fc70f044..072b34c26 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -104,6 +104,8 @@ class PlayerInterface : public QObject { signals: void Playing(); void Paused(); + // Emitted only when playback is manually resumed + void Resumed(); void Stopped(); void Error(); void PlaylistFinished(); diff --git a/src/settings/notificationssettingspage.cpp b/src/settings/notificationssettingspage.cpp index b46a3ccc1..45691bc52 100644 --- a/src/settings/notificationssettingspage.cpp +++ b/src/settings/notificationssettingspage.cpp @@ -169,6 +169,7 @@ void NotificationsSettingsPage::Load() { ui_->notifications_volume->setChecked( s.value("ShowOnVolumeChange", false).toBool()); ui_->notifications_play_mode->setChecked( s.value("ShowOnPlayModeChange", true).toBool()); ui_->notifications_pause->setChecked(s.value("ShowOnPausePlayback", true).toBool()); + ui_->notifications_resume->setChecked(s.value("ShowOnResumePlayback", false).toBool()); ui_->notifications_art->setChecked(s.value("ShowArt", true).toBool()); ui_->notifications_custom_text_enabled->setChecked(s.value("CustomTextEnabled", false).toBool()); ui_->notifications_custom_text1->setText(s.value("CustomText1").toString()); @@ -211,6 +212,7 @@ void NotificationsSettingsPage::Save() { s.setValue("ShowOnVolumeChange", ui_->notifications_volume->isChecked()); s.setValue("ShowOnPlayModeChange", ui_->notifications_play_mode->isChecked()); s.setValue("ShowOnPausePlayback", ui_->notifications_pause->isChecked()); + s.setValue("ShowOnResumePlayback", ui_->notifications_resume->isChecked()); s.setValue("ShowArt", ui_->notifications_art->isChecked()); s.setValue("CustomTextEnabled", ui_->notifications_custom_text_enabled->isChecked()); s.setValue("CustomText1", ui_->notifications_custom_text1->text()); diff --git a/src/settings/notificationssettingspage.ui b/src/settings/notificationssettingspage.ui index 00e98dd75..1003bf61a 100644 --- a/src/settings/notificationssettingspage.ui +++ b/src/settings/notificationssettingspage.ui @@ -147,6 +147,13 @@ + + + + Show a notification when I resume playback + + + diff --git a/src/widgets/osd.cpp b/src/widgets/osd.cpp index 415e26062..1007d8262 100644 --- a/src/widgets/osd.cpp +++ b/src/widgets/osd.cpp @@ -58,6 +58,7 @@ OSD::OSD(SystemTrayIcon *tray_icon, Application *app, QObject *parent) show_art_(true), show_on_play_mode_change_(true), show_on_pause_(true), + show_on_resume_(false), use_custom_text_(false), custom_text1_(QString()), custom_text2_(QString()), @@ -90,6 +91,7 @@ void OSD::ReloadSettings() { show_art_ = s.value("ShowArt", true).toBool(); show_on_play_mode_change_ = s.value("ShowOnPlayModeChange", true).toBool(); show_on_pause_ = s.value("ShowOnPausePlayback", true).toBool(); + show_on_resume_ = s.value("ShowOnResumePlayback", false).toBool(); use_custom_text_ = s.value(("CustomTextEnabled"), false).toBool(); custom_text1_ = s.value("CustomText1").toString(); custom_text2_ = s.value("CustomText2").toString(); @@ -183,6 +185,12 @@ void OSD::Paused() { } } +void OSD::Resumed() { + if (show_on_resume_) { + AlbumArtLoaded(last_song_, last_image_uri_, last_image_); + } +} + void OSD::Stopped() { if (tray_icon_) tray_icon_->ClearNowPlaying(); if (ignore_next_stopped_) { diff --git a/src/widgets/osd.h b/src/widgets/osd.h index 5bb994b92..3b636250e 100644 --- a/src/widgets/osd.h +++ b/src/widgets/osd.h @@ -80,6 +80,7 @@ class OSD : public QObject { void ReloadSettings(); void Paused(); + void Resumed(); void Stopped(); void StopAfterToggle(bool stop); void PlaylistFinished(); @@ -115,6 +116,7 @@ class OSD : public QObject { bool show_art_; bool show_on_play_mode_change_; bool show_on_pause_; + bool show_on_resume_; bool use_custom_text_; QString custom_text1_; QString custom_text2_;