From bbcb990c65f6c936fa5f2b728c9de1d0066149f7 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 29 Nov 2022 06:28:51 +0200 Subject: [PATCH] kmediaplayer: restore the pause/play state aswell chromium and some other applications have to catch up on session restoration, chromium for example cannot even shutdown correctly and it's a "uh, oh" situation the next time it is launched after logout (unless closed manually before logout). tabs restoration is not session restoration btw, not to X11 anyway. Signed-off-by: Ivailo Monev --- kmediaplayer/kmediawindow.cpp | 13 +++++++++---- kmediaplayer/kmediawindow.h | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kmediaplayer/kmediawindow.cpp b/kmediaplayer/kmediawindow.cpp index a2baeac8..58b4f37b 100644 --- a/kmediaplayer/kmediawindow.cpp +++ b/kmediaplayer/kmediawindow.cpp @@ -41,7 +41,8 @@ KMediaWindow::KMediaWindow(QWidget *parent, Qt::WindowFlags flags) m_player(nullptr), m_recentfiles(nullptr), m_menu(nullptr), - m_currenttime(float(0.0)) + m_currenttime(float(0.0)), + m_playing(true) { m_config = new KConfig("kmediaplayerrc", KConfig::SimpleConfig); @@ -201,27 +202,31 @@ void KMediaWindow::slotQuit() qApp->quit(); } -void KMediaWindow::slotDelayedPosition() +void KMediaWindow::slotDelayedRestore() { - disconnect(m_player->player(), SIGNAL(loaded()), this, SLOT(slotDelayedPosition())); + disconnect(m_player->player(), SIGNAL(loaded()), this, SLOT(slotDelayedRestore())); m_player->setPosition(m_currenttime); + m_player->setPlay(int(!m_playing)); } void KMediaWindow::saveProperties(KConfigGroup &configgroup) { const QString path = m_player->player()->path(); const float currenttime = m_player->player()->currentTime(); + const bool playing = m_player->player()->isPlaying(); configgroup.writeEntry("Path", path); configgroup.writeEntry("Position", currenttime); + configgroup.writeEntry("Playing", playing); } void KMediaWindow::readProperties(const KConfigGroup &configgroup) { const QString path = configgroup.readEntry("Path", QString()); m_currenttime = configgroup.readEntry("Position", float(0.0)); + m_playing = configgroup.readEntry("Playing", true); kDebug() << path << m_currenttime; if (!path.isEmpty()) { - connect(m_player->player(), SIGNAL(loaded()), this, SLOT(slotDelayedPosition())); + connect(m_player->player(), SIGNAL(loaded()), this, SLOT(slotDelayedRestore())); m_player->open(path); } } diff --git a/kmediaplayer/kmediawindow.h b/kmediaplayer/kmediawindow.h index 2e5332f0..6387555f 100644 --- a/kmediaplayer/kmediawindow.h +++ b/kmediaplayer/kmediawindow.h @@ -44,7 +44,7 @@ public slots: void slotQuit(); private slots: - void slotDelayedPosition(); + void slotDelayedRestore(); protected: // KMainWindow reimplementations @@ -57,6 +57,7 @@ private: KRecentFilesAction *m_recentfiles; QMenu *m_menu; float m_currenttime; + bool m_playing; }; #endif // KMEDIAWINDOW_H