/* This file is part of Kotatogram Desktop, the unofficial app based on Telegram Desktop. For license and copyright information please follow this link: https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL */ #include "kotato/kotato_settings_menu.h" #include "kotato/kotato_lang.h" #include "kotato/kotato_settings.h" #include "base/options.h" #include "base/platform/base_platform_info.h" #include "settings/settings_common.h" #include "settings/settings_chat.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/continuous_sliders.h" #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "boxes/connection_box.h" #include "kotato/boxes/kotato_fonts_box.h" #include "kotato/boxes/kotato_radio_box.h" #include "boxes/about_box.h" #include "ui/boxes/confirm_box.h" #include "platform/platform_specific.h" #include "platform/platform_file_utilities.h" #include "window/window_peer_menu.h" #include "window/window_session_controller.h" #include "lang/lang_keys.h" #include "core/update_checker.h" #include "core/application.h" #include "storage/localstorage.h" #include "data/data_session.h" #include "data/data_cloud_themes.h" #include "main/main_session.h" #include "mainwindow.h" #include "facades.h" #include "styles/style_settings.h" #include "ui/platform/ui_platform_utility.h" namespace Settings { namespace { QString FileDialogTypeLabel(int value) { const auto typedValue = Platform::FileDialog::ImplementationType(value); switch (typedValue) { case Platform::FileDialog::ImplementationType::Default: return ktr("ktg_file_dialog_type_default"); } return Platform::FileDialog::ImplementationTypeLabel(typedValue); } QString FileDialogTypeDescription(int value) { const auto typedValue = Platform::FileDialog::ImplementationType(value); return Platform::FileDialog::ImplementationTypeDescription(typedValue); } QString ForwardModeLabel(int mode) { switch (mode) { case 0: return ktr("ktg_forward_mode_quoted"); case 1: return ktr("ktg_forward_mode_unquoted"); case 2: return ktr("ktg_forward_mode_uncaptioned"); default: Unexpected("Boost in Settings::ForwardModeLabel."); } return QString(); } QString GroupingModeLabel(int mode) { switch (mode) { case 0: return ktr("ktg_forward_grouping_mode_preserve_albums"); case 1: return ktr("ktg_forward_grouping_mode_regroup"); case 2: return ktr("ktg_forward_grouping_mode_separate"); default: Unexpected("Boost in Settings::GroupingModeLabel."); } return QString(); } QString GroupingModeDescription(int mode) { switch (mode) { case 0: case 2: return QString(); case 1: return ktr("ktg_forward_grouping_mode_regroup_desc"); default: Unexpected("Boost in Settings::GroupingModeLabel."); } return QString(); } QString NetBoostLabel(int boost) { switch (boost) { case 0: return ktr("ktg_net_speed_boost_default"); case 1: return ktr("ktg_net_speed_boost_slight"); case 2: return ktr("ktg_net_speed_boost_medium"); case 3: return ktr("ktg_net_speed_boost_big"); default: Unexpected("Boost in Settings::NetBoostLabel."); } return QString(); } QString UserpicRoundingLabel(int rounding) { switch (rounding) { case 0: return ktr("ktg_settings_userpic_rounding_none"); case 1: return ktr("ktg_settings_userpic_rounding_small"); case 2: return ktr("ktg_settings_userpic_rounding_big"); case 3: return ktr("ktg_settings_userpic_rounding_full"); default: Unexpected("Rounding in Settings::UserpicRoundingLabel."); } return QString(); } QString TrayIconLabel(int icon) { switch (icon) { case 0: return ktr("ktg_settings_tray_icon_default"); case 1: return ktr("ktg_settings_tray_icon_blue"); case 2: return ktr("ktg_settings_tray_icon_green"); case 3: return ktr("ktg_settings_tray_icon_orange"); case 4: return ktr("ktg_settings_tray_icon_red"); case 5: return ktr("ktg_settings_tray_icon_legacy"); default: Unexpected("Icon in Settings::TrayIconLabel."); } return QString(); } QString ChatIdLabel(int option) { switch (option) { case 0: return ktr("ktg_settings_chat_id_disable"); case 1: return ktr("ktg_settings_chat_id_telegram"); case 2: return ktr("ktg_settings_chat_id_bot"); default: Unexpected("Option in Settings::ChatIdLabel."); } return QString(); } } // namespace #define SettingsMenuJsonSwitch(LangKey, Option) AddButton( \ container, \ rktr(#LangKey), \ st::settingsButton \ )->toggleOn( \ rpl::single(::Kotato::JsonSettings::GetBool(#Option)) \ )->toggledValue( \ ) | rpl::filter([](bool enabled) { \ return (enabled != ::Kotato::JsonSettings::GetBool(#Option)); \ }) | rpl::start_with_next([](bool enabled) { \ ::Kotato::JsonSettings::Set(#Option, enabled); \ ::Kotato::JsonSettings::Write(); \ }, container->lifetime()); #define SettingsMenuJsonFilterSwitch(LangKey, Option) AddButton( \ container, \ rktr(#LangKey), \ st::settingsButton \ )->toggleOn( \ rpl::single(::Kotato::JsonSettings::GetBool(#Option)) \ )->toggledValue( \ ) | rpl::filter([](bool enabled) { \ return (enabled != ::Kotato::JsonSettings::GetBool(#Option)); \ }) | rpl::start_with_next([controller](bool enabled) { \ ::Kotato::JsonSettings::Set(#Option, enabled); \ ::Kotato::JsonSettings::Write(); \ controller->reloadFiltersMenu(); \ App::wnd()->fixOrder(); \ }, container->lifetime()); void SetupKotatoChats( not_null controller, not_null container) { AddSkip(container); AddSubsectionTitle(container, rktr("ktg_settings_chats")); const auto recentStickersLimitLabel = container->add( object_ptr( container, st::settingsAudioVolumeLabel), st::settingsAudioVolumeLabelPadding); const auto recentStickersLimitSlider = container->add( object_ptr( container, st::settingsAudioVolumeSlider), st::settingsAudioVolumeSliderPadding); const auto updateRecentStickersLimitLabel = [=](int value) { if (value == 0) { recentStickersLimitLabel->setText( ktr("ktg_settings_recent_stickers_limit_none")); } else { recentStickersLimitLabel->setText( ktr("ktg_settings_recent_stickers_limit", value, { "count", QString::number(value) })); } }; const auto updateRecentStickersLimitHeight = [=](int value) { updateRecentStickersLimitLabel(value); ::Kotato::JsonSettings::Set("recent_stickers_limit", value); ::Kotato::JsonSettings::Write(); }; recentStickersLimitSlider->resize(st::settingsAudioVolumeSlider.seekSize); recentStickersLimitSlider->setPseudoDiscrete( 201, [](int val) { return val; }, ::Kotato::JsonSettings::GetInt("recent_stickers_limit"), updateRecentStickersLimitHeight); updateRecentStickersLimitLabel(::Kotato::JsonSettings::GetInt("recent_stickers_limit")); SettingsMenuJsonSwitch(ktg_settings_top_bar_mute, profile_top_mute); SettingsMenuJsonSwitch(ktg_settings_disable_up_edit, disable_up_edit); if (Ui::Platform::IsOverlapped(container, QRect()).has_value()) { SettingsMenuJsonSwitch(ktg_settings_auto_scroll_unfocused, auto_scroll_unfocused); } AddButton( container, rktr("ktg_settings_chat_list_compact"), st::settingsButton )->toggleOn( rpl::single(::Kotato::JsonSettings::GetInt("chat_list_lines") == 1) )->toggledValue( ) | rpl::filter([](bool enabled) { return (enabled != (::Kotato::JsonSettings::GetInt("chat_list_lines") == 1)); }) | rpl::start_with_next([](bool enabled) { ::Kotato::JsonSettings::Set("chat_list_lines", enabled ? 1 : 2); ::Kotato::JsonSettings::Write(); }, container->lifetime()); AddButton( container, rktr("ktg_settings_always_show_scheduled"), st::settingsButton )->toggleOn( rpl::single(::Kotato::JsonSettings::GetBool("always_show_scheduled")) )->toggledValue( ) | rpl::filter([](bool enabled) { return (enabled != ::Kotato::JsonSettings::GetBool("always_show_scheduled")); }) | rpl::start_with_next([controller](bool enabled) { ::Kotato::JsonSettings::Set("always_show_scheduled", enabled); Notify::showScheduledButtonChanged(&controller->session()); ::Kotato::JsonSettings::Write(); }, container->lifetime()); AddButton( container, rktr("ktg_settings_fonts"), st::settingsButton )->addClickHandler([=] { Ui::show(Box()); }); const auto userpicCornerButton = container->add( object_ptr