diff --git a/src/settings.cpp b/src/settings.cpp index 9b6f62af0..f57f01055 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -57,6 +57,7 @@ void Settings::load() general.style = g["style"].toString(); general.lastPlaylist = g["last_playlist"].toString(); general.lastVersion = g["last_version"].toString(); + general.lastVolume = g["last_volume"].toInt(); general.pulseVolume = g["pulse_volume"].toBool(false); general.mediaController = g["media_controller"].toBool(hasMediaControllerSupport()); general.spotifyPlaybackOrder = g["spotify_playback_order"].toBool(false); @@ -102,6 +103,7 @@ void Settings::save() {"hidden_song_headers", jsonHiddenSongHeaders}, {"last_playlist", general.lastPlaylist}, {"last_version", general.lastVersion}, + {"last_volume", general.lastVolume}, {"media_controller", general.mediaController}, {"pulse_volume", general.pulseVolume}, {"refresh_interval", general.refreshInterval}, diff --git a/src/settings.hpp b/src/settings.hpp index 18cf0eddf..a66d2e446 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -39,7 +39,7 @@ class Settings showChangelog, fallbackIcons, fixedWidthTime, trayAlbumArt; Palette stylePalette; QVector hiddenSongHeaders; - int songHeaderResizeMode, songHeaderSortBy, refreshInterval; + int songHeaderResizeMode, songHeaderSortBy, refreshInterval, lastVolume; } General; typedef struct { diff --git a/src/volumebutton.cpp b/src/volumebutton.cpp index f038a5530..e3df2c801 100644 --- a/src/volumebutton.cpp +++ b/src/volumebutton.cpp @@ -1,6 +1,6 @@ #include "volumebutton.hpp" -VolumeButton::VolumeButton(const Settings &settings, spt::Spotify &spotify, QWidget *parent) +VolumeButton::VolumeButton(Settings &settings, spt::Spotify &spotify, QWidget *parent) : settings(settings), spotify(spotify), volume(new QSlider(this)), QToolButton(parent) { // Volume slider @@ -8,7 +8,8 @@ VolumeButton::VolumeButton(const Settings &settings, spt::Spotify &spotify, QWid volume->setFixedHeight(100); volume->setMinimum(0); volume->setMaximum(20); - volume->setValue(spt::ClientHandler::getVolume() * 20); + volume->setValue(settings.general.lastVolume > 0 + ? settings.general.lastVolume : spt::ClientHandler::getVolume() * 20); // Layout for volume slider auto volumeMenu = new QMenu(this); @@ -48,6 +49,12 @@ VolumeButton::VolumeButton(const Settings &settings, spt::Spotify &spotify, QWid } } +VolumeButton::~VolumeButton() +{ + settings.general.lastVolume = volume->value(); + settings.save(); +} + void VolumeButton::wheelEvent(QWheelEvent *event) { volume->setValue(volume->value() + (event->angleDelta().y() < 0 ? -1 : 1)); diff --git a/src/volumebutton.hpp b/src/volumebutton.hpp index 2346dfca9..f125b1bd3 100644 --- a/src/volumebutton.hpp +++ b/src/volumebutton.hpp @@ -17,7 +17,9 @@ class VolumeButton : public QToolButton Q_OBJECT public: - VolumeButton(const Settings &settings, spt::Spotify &spotify, QWidget *parent); + VolumeButton(Settings &settings, spt::Spotify &spotify, QWidget *parent); + ~VolumeButton(); + void updateIcon(); protected: @@ -26,6 +28,6 @@ class VolumeButton : public QToolButton private: QSlider *volume; - const Settings &settings; + Settings &settings; spt::Spotify &spotify; }; \ No newline at end of file