From 150dbef19ff0d944dfb177c4e4c4918ee1fae843 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 4 Sep 2021 22:39:50 +0300 Subject: [PATCH] Added ability to save icon of last voice playback speed. --- Telegram/SourceFiles/core/core_settings.cpp | 21 +++++++++++++------ Telegram/SourceFiles/core/core_settings.h | 14 +++++++++---- .../media/player/media_player_widget.cpp | 1 + 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index b7518a7883..ba1dfee505 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -140,7 +140,7 @@ QByteArray Settings::serialize() const { << qint32(_askDownloadPath ? 1 : 0) << _downloadPath.current() << _downloadPathBookmark - << qint32(0) // Old double voice playback speed. + << qint32(_nonDefaultVoicePlaybackSpeed ? 1 : 0) << qint32(_soundNotify ? 1 : 0) << qint32(_desktopNotify ? 1 : 0) << qint32(_flashBounceNotify ? 1 : 0) @@ -241,7 +241,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 askDownloadPath = _askDownloadPath ? 1 : 0; QString downloadPath = _downloadPath.current(); QByteArray downloadPathBookmark = _downloadPathBookmark; - qint32 oldVoiceMsgPlaybackDoubled = 0; + qint32 nonDefaultVoicePlaybackSpeed = _nonDefaultVoicePlaybackSpeed ? 1 : 0; qint32 soundNotify = _soundNotify ? 1 : 0; qint32 desktopNotify = _desktopNotify ? 1 : 0; qint32 flashBounceNotify = _flashBounceNotify ? 1 : 0; @@ -314,7 +314,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { >> askDownloadPath >> downloadPath >> downloadPathBookmark - >> oldVoiceMsgPlaybackDoubled + >> nonDefaultVoicePlaybackSpeed >> soundNotify >> desktopNotify >> flashBounceNotify @@ -529,9 +529,17 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _suggestStickersByEmoji = (suggestStickersByEmoji == 1); _spellcheckerEnabled = (spellcheckerEnabled == 1); _videoPlaybackSpeed = DeserializePlaybackSpeed(videoPlaybackSpeed); - _voicePlaybackSpeed = oldVoiceMsgPlaybackDoubled - ? 2.0 - : voicePlaybackSpeed / 100.; + { + // Restore settings from 3.0.1 version. + if (voicePlaybackSpeed == 100) { + _nonDefaultVoicePlaybackSpeed = false; + _voicePlaybackSpeed = 2.0; + } else { + _nonDefaultVoicePlaybackSpeed = + (nonDefaultVoicePlaybackSpeed == 1); + _voicePlaybackSpeed = voicePlaybackSpeed / 100.; + } + } _videoPipGeometry = (videoPipGeometry); _dictionariesEnabled = std::move(dictionariesEnabled); _autoDownloadDictionaries = (autoDownloadDictionaries == 1); @@ -789,6 +797,7 @@ void Settings::resetOnLastLogout() { _downloadPath = QString(); _downloadPathBookmark = QByteArray(); + _nonDefaultVoicePlaybackSpeed = false; _soundNotify = true; _desktopNotify = true; _flashBounceNotify = true; diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 89aa33bcc0..86b2145e2f 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -421,11 +421,16 @@ public: void setVideoPlaybackSpeed(float64 speed) { _videoPlaybackSpeed = speed; } - [[nodiscard]] float64 voicePlaybackSpeed() const { - return _voicePlaybackSpeed; + [[nodiscard]] float64 voicePlaybackSpeed( + bool lastNonDefault = false) const { + return (_nonDefaultVoicePlaybackSpeed || lastNonDefault) + ? _voicePlaybackSpeed + : 1.0; } void setVoicePlaybackSpeed(float64 speed) { - _voicePlaybackSpeed = speed; + if ((_nonDefaultVoicePlaybackSpeed = (speed != 1.0))) { + _voicePlaybackSpeed = speed; + } } [[nodiscard]] QByteArray videoPipGeometry() const { return _videoPipGeometry; @@ -669,7 +674,8 @@ private: bool _suggestStickersByEmoji = true; rpl::variable _spellcheckerEnabled = true; rpl::variable _videoPlaybackSpeed = 1.; - float64 _voicePlaybackSpeed = 1.; + float64 _voicePlaybackSpeed = 2.; + bool _nonDefaultVoicePlaybackSpeed = false; QByteArray _videoPipGeometry; rpl::variable> _dictionariesEnabled; rpl::variable _autoDownloadDictionaries = true; diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index fa60aa9152..5cb2d26874 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -75,6 +75,7 @@ private: public: SpeedController() { setSpeed(Core::App().settings().voicePlaybackSpeed()); + _speed = Core::App().settings().voicePlaybackSpeed(true); } [[nodiscard]] rpl::producer speedValue() const {