From dd6b9bb38d1ffe620ee938b44aefefc9e7938f38 Mon Sep 17 00:00:00 2001 From: Adam Hill Date: Sat, 3 Feb 2024 19:03:21 -0800 Subject: [PATCH] MainWindow: Add function to display progress on taskbar --- src/core/mainwindow.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/core/mainwindow.h | 4 ++++ 2 files changed, 44 insertions(+) diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 350c9828..0195f2c0 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -73,6 +73,10 @@ #include #include #include +#ifdef HAVE_DBUS +# include +# include +#endif #include "core/logging.h" @@ -1269,6 +1273,11 @@ void MainWindow::Exit() { return; // Don't quit the application now: wait for the fadeout finished signal } } + +#ifdef HAVE_DBUS + UpdateTaskbarProgress(false, 0, 0); +#endif + DoExit(); } @@ -1321,6 +1330,10 @@ void MainWindow::MediaStopped() { tray_icon_->SetProgress(0); tray_icon_->SetStopped(); +#ifdef HAVE_DBUS + UpdateTaskbarProgress(false, 0, 0); +#endif + song_playing_ = Song(); song_ = Song(); album_cover_ = AlbumCoverImageResult(); @@ -1397,6 +1410,10 @@ void MainWindow::SongChanged(const Song &song) { setWindowTitle(song.PrettyTitleWithArtist()); tray_icon_->SetProgress(0); +#ifdef HAVE_DBUS + UpdateTaskbarProgress(false, 0, 0); +#endif + SendNowPlaying(); const bool enable_change_art = song.is_collection_song() && !song.effective_albumartist().isEmpty() && !song.album().isEmpty(); @@ -1686,6 +1703,10 @@ void MainWindow::Seeked(const qint64 microseconds) { const qint64 length = app_->player()->GetCurrentItem()->Metadata().length_nanosec() / kNsecPerSec; tray_icon_->SetProgress(static_cast(static_cast(position) / static_cast(length) * 100.0)); +#ifdef HAVE_DBUS + UpdateTaskbarProgress(true, position, length); +#endif + } void MainWindow::UpdateTrackPosition() { @@ -1700,6 +1721,10 @@ void MainWindow::UpdateTrackPosition() { // Update the tray icon every 10 seconds if (position % 10 == 0) tray_icon_->SetProgress(static_cast(static_cast(position) / static_cast(length) * 100.0)); +#ifdef HAVE_DBUS + UpdateTaskbarProgress(true, position, length); +#endif + // Send Scrobble if (app_->scrobbler()->enabled() && item->Metadata().is_metadata_good()) { Playlist *playlist = app_->playlist_manager()->active(); @@ -1726,6 +1751,21 @@ void MainWindow::UpdateTrackSliderPosition() { } +#ifdef HAVE_DBUS +void MainWindow::UpdateTaskbarProgress(const bool visible, const double position, const double length) { + + QVariantMap map; + QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/org/strawberrymusicplayer/strawberry"), QStringLiteral("com.canonical.Unity.LauncherEntry"), QStringLiteral("Update")); + + map.insert(QStringLiteral("progress-visible"), visible); + map.insert(QStringLiteral("progress"), position / length); + msg << QString("application://org.strawberrymusicplayer.strawberry.desktop") << map; + + QDBusConnection::sessionBus().send(msg); + +} +#endif + void MainWindow::ApplyAddBehaviour(const BehaviourSettingsPage::AddBehaviour b, MimeData *mimedata) { switch (b) { diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 31a71017..6053f92e 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -290,6 +290,10 @@ class MainWindow : public QMainWindow, public PlatformInterface { void SetToggleScrobblingIcon(const bool value); +#ifdef HAVE_DBUS + void UpdateTaskbarProgress(const bool visible, const double position, const double length); +#endif + private: Ui_MainWindow *ui_; #ifdef Q_OS_WIN