From f4d5f31f2ad24a605479d968fc5af5cf80aee900 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 31 Mar 2021 12:32:23 +0400 Subject: [PATCH 1/3] Fix ifndef of gtk integration in settings --- Telegram/SourceFiles/kotato/settings_menu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index e5ec3a887..939442948 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -438,7 +438,7 @@ void SetupKotatoSystem( AddSkip(container); AddSubsectionTitle(container, tr::ktg_settings_system()); -#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION +#ifndef DESKTOP_APP_DISABLE_GTK_INTEGRATION if (Platform::IsLinux()) { const auto gtkIntegrationToggled = Ui::CreateChild>( container.get()); @@ -467,7 +467,7 @@ void SetupKotatoSystem( cancelled)); }, container->lifetime()); } -#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION +#endif // !DESKTOP_APP_DISABLE_GTK_INTEGRATION if (Platform::IsMac()) { const auto useNativeDecorationsToggled = Ui::CreateChild>( From a618181120519a83b5957632c9e34ee52f0706ea Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 31 Mar 2021 12:33:13 +0400 Subject: [PATCH 2/3] Make RadioBox API simpler --- .../kotato/customboxes/radio_box.cpp | 18 ++++---- .../kotato/customboxes/radio_box.h | 7 ++-- Telegram/SourceFiles/kotato/settings_menu.cpp | 41 ++++--------------- 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp b/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp index c16b535a9..6d1502c55 100644 --- a/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp +++ b/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp @@ -23,12 +23,14 @@ RadioBox::RadioBox( QWidget*, const QString &title, int currentValue, - const QMap &options, + int valueCount, + Fn labelGetter, Fn saveCallback, bool warnRestart) : _title(title) , _startValue(currentValue) -, _options(options) +, _valueCount(valueCount) +, _labelGetter(labelGetter) , _saveCallback(std::move(saveCallback)) , _warnRestart(warnRestart) { } @@ -38,13 +40,15 @@ RadioBox::RadioBox( const QString &title, const QString &description, int currentValue, - const QMap &options, + int valueCount, + Fn labelGetter, Fn saveCallback, bool warnRestart) : _title(title) , _description(description) , _startValue(currentValue) -, _options(options) +, _valueCount(valueCount) +, _labelGetter(labelGetter) , _saveCallback(std::move(saveCallback)) , _warnRestart(warnRestart) { } @@ -69,13 +73,13 @@ void RadioBox::prepare() { _group = std::make_shared(_startValue); - for (auto i = _options.constBegin(); i != _options.constEnd(); ++i) { + for (auto i = 0; i != _valueCount; ++i) { content->add( object_ptr( this, _group, - i.key(), - i.value(), + i, + _labelGetter(i), st::autolockButton), style::margins( st::boxPadding.left(), diff --git a/Telegram/SourceFiles/kotato/customboxes/radio_box.h b/Telegram/SourceFiles/kotato/customboxes/radio_box.h index 50f7bdf57..680c2ca92 100644 --- a/Telegram/SourceFiles/kotato/customboxes/radio_box.h +++ b/Telegram/SourceFiles/kotato/customboxes/radio_box.h @@ -19,8 +19,8 @@ namespace Kotato { class RadioBox : public Ui::BoxContent { public: - RadioBox(QWidget* parent, const QString &title, int currentValue, const QMap &options, Fn saveCallback, bool warnRestart = false); - RadioBox(QWidget* parent, const QString &title, const QString &description, int currentValue, const QMap &options, Fn saveCallback, bool warnRestart = false); + RadioBox(QWidget* parent, const QString &title, int currentValue, int valueCount, Fn labelGetter, Fn saveCallback, bool warnRestart = false); + RadioBox(QWidget* parent, const QString &title, const QString &description, int currentValue, int valueCount, Fn labelGetter, Fn saveCallback, bool warnRestart = false); protected: void prepare() override; @@ -31,7 +31,8 @@ private: QString _title; QString _description; int _startValue; - QMap _options; + int _valueCount; + Fn _labelGetter; Fn _saveCallback; bool _warnRestart = false; std::shared_ptr _group; diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index 939442948..3a97172b4 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -250,13 +250,6 @@ void SetupKotatoChats( Ui::show(Box()); }); - const QMap userpicRoundOptions = { - { 0, UserpicRoundingLabel(0) }, - { 1, UserpicRoundingLabel(1) }, - { 2, UserpicRoundingLabel(2) }, - { 3, UserpicRoundingLabel(3) } - }; - AddButtonWithLabel( container, tr::ktg_settings_userpic_rounding(), @@ -267,7 +260,8 @@ void SetupKotatoChats( tr::ktg_settings_userpic_rounding(tr::now), tr::ktg_settings_userpic_rounding_desc(tr::now), cUserpicCornersType(), - userpicRoundOptions, + 4, + UserpicRoundingLabel, [=] (int value) { cSetUserpicCornersType(value); ::Kotato::JsonSettings::Write(); @@ -389,13 +383,6 @@ void SetupKotatoNetwork(not_null container) { AddSkip(container); AddSubsectionTitle(container, tr::ktg_settings_network()); - const QMap netBoostOptions = { - { 0, NetBoostLabel(0) }, - { 1, NetBoostLabel(1) }, - { 2, NetBoostLabel(2) }, - { 3, NetBoostLabel(3) } - }; - AddButtonWithLabel( container, tr::ktg_settings_net_speed_boost(), @@ -406,7 +393,8 @@ void SetupKotatoNetwork(not_null container) { tr::ktg_net_speed_boost_title(tr::now), tr::ktg_net_speed_boost_desc(tr::now), cNetSpeedBoost(), - netBoostOptions, + 4, + NetBoostLabel, [=] (int value) { SetNetworkBoost(value); ::Kotato::JsonSettings::Write(); @@ -530,15 +518,6 @@ void SetupKotatoSystem( }, container->lifetime()); } - const QMap trayIconOptions = { - { 0, TrayIconLabel(0) }, - { 1, TrayIconLabel(1) }, - { 2, TrayIconLabel(2) }, - { 3, TrayIconLabel(3) }, - { 4, TrayIconLabel(4) }, - { 5, TrayIconLabel(5) }, - }; - auto trayIconText = rpl::single( rpl::empty_value() ) | rpl::then( @@ -557,7 +536,8 @@ void SetupKotatoSystem( tr::ktg_settings_tray_icon(tr::now), tr::ktg_settings_tray_icon_desc(tr::now), cCustomAppIcon(), - trayIconOptions, + 6, + TrayIconLabel, [=] (int value) { cSetCustomAppIcon(value); controller->session().data().notifyUnreadBadgeChanged(); @@ -575,12 +555,6 @@ void SetupKotatoOther(not_null container) { SettingsMenuCSwitch(ktg_settings_show_phone_number, ShowPhoneInDrawer); - const QMap chatIdOptions = { - { 0, ChatIdLabel(0) }, - { 1, ChatIdLabel(1) }, - { 2, ChatIdLabel(2) }, - }; - const auto chatIdButton = container->add( object_ptr