diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index e77d098baa..63c93cd117 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -523,6 +523,8 @@ PRIVATE data/notify/data_notify_settings.h data/notify/data_peer_notify_settings.cpp data/notify/data_peer_notify_settings.h + data/notify/data_peer_notify_volume.cpp + data/notify/data_peer_notify_volume.h data/stickers/data_custom_emoji.cpp data/stickers/data_custom_emoji.h data/stickers/data_stickers_set.cpp diff --git a/Telegram/SourceFiles/data/notify/data_peer_notify_volume.cpp b/Telegram/SourceFiles/data/notify/data_peer_notify_volume.cpp new file mode 100644 index 0000000000..f9148408e2 --- /dev/null +++ b/Telegram/SourceFiles/data/notify/data_peer_notify_volume.cpp @@ -0,0 +1,112 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "data/notify/data_peer_notify_volume.h" + +#include "data/data_peer.h" +#include "data/data_thread.h" +#include "data/notify/data_peer_notify_settings.h" +#include "main/main_session.h" +#include "main/main_session_settings.h" +#include "platform/platform_notifications_manager.h" +#include "settings/settings_common.h" +#include "ui/vertical_list.h" +#include "ui/widgets/continuous_sliders.h" +#include "ui/widgets/labels.h" +#include "ui/wrap/slide_wrap.h" +#include "ui/wrap/vertical_layout.h" +#include "styles/style_settings.h" + +namespace Data { + +Data::VolumeController DefaultRingtonesVolumeController( + not_null session, + Data::DefaultNotify defaultNotify) { + return Data::VolumeController{ + .volume = [=]() -> ushort { + const auto volume = session->settings().ringtoneVolume( + defaultNotify); + return volume ? volume : 100; + }, + .saveVolume = [=](ushort volume) { + session->settings().setRingtoneVolume(defaultNotify, volume); + session->saveSettingsDelayed(); + }}; +} + +Data::VolumeController ThreadRingtonesVolumeController( + not_null thread) { + return Data::VolumeController{ + .volume = [=]() -> ushort { + const auto volume = thread->session().settings().ringtoneVolume( + thread->peer()->id, + thread->topicRootId(), + thread->monoforumPeerId()); + return volume ? volume : 100; + }, + .saveVolume = [=](ushort volume) { + thread->session().settings().setRingtoneVolume( + thread->peer()->id, + thread->topicRootId(), + thread->monoforumPeerId(), + volume); + thread->session().saveSettingsDelayed(); + }}; +} + +} // namespace Data + +namespace Ui { + +void AddRingtonesVolumeSlider( + not_null container, + rpl::producer toggleOn, + rpl::producer subtitle, + Data::VolumeController volumeController) { + if (!Platform::Notifications::VolumeSupported()) { + return; + } + Expects(volumeController.volume && volumeController.saveVolume); + + const auto volumeWrap = container->add( + object_ptr>( + container, + object_ptr(container))); + volumeWrap->toggleOn(std::move(toggleOn), anim::type::normal); + volumeWrap->finishAnimating(); + + Ui::AddSubsectionTitle(volumeWrap->entity(), std::move(subtitle)); + auto sliderWithLabel = Settings::MakeSliderWithLabel( + volumeWrap->entity(), + st::settingsScale, + st::settingsScaleLabel, + st::normalFont->spacew * 2, + st::settingsScaleLabel.style.font->width("100%"), + true); + const auto slider = sliderWithLabel.slider; + const auto label = sliderWithLabel.label; + + volumeWrap->entity()->add( + std::move(sliderWithLabel.widget), + st::settingsBigScalePadding); + + const auto updateLabel = [=](int volume) { + label->setText(QString::number(volume) + '%'); + }; + + slider->setPseudoDiscrete( + 100, + [=](int index) { return index + 1; }, + int(volumeController.volume()), + updateLabel, + [saveVolume = volumeController.saveVolume](int volume) { + saveVolume(volume); + }); + updateLabel(volumeController.volume()); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/data/notify/data_peer_notify_volume.h b/Telegram/SourceFiles/data/notify/data_peer_notify_volume.h new file mode 100644 index 0000000000..cc6833e7a1 --- /dev/null +++ b/Telegram/SourceFiles/data/notify/data_peer_notify_volume.h @@ -0,0 +1,45 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Main { +class Session; +} // namespace Main + +namespace Ui { +class VerticalLayout; +} // namespace Ui + +namespace Data { + +enum class DefaultNotify : uint8_t; +class Thread; + +struct VolumeController { + Fn volume = nullptr; + Fn saveVolume = nullptr; +}; + +[[nodiscard]] VolumeController DefaultRingtonesVolumeController( + not_null session, + Data::DefaultNotify defaultNotify); + +[[nodiscard]] VolumeController ThreadRingtonesVolumeController( + not_null thread); + +} // namespace Data + +namespace Ui { + +void AddRingtonesVolumeSlider( + not_null container, + rpl::producer toggleOn, + rpl::producer subtitle, + Data::VolumeController volumeController); + +} // namespace Ui