diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5d568d3c8..5503f7ed1 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2259,6 +2259,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_emoji_outline" = "Big emoji outline"; "ktg_settings_always_show_scheduled" = "Always show scheduled"; "ktg_settings_fonts" = "Change application fonts"; +"ktg_settings_network" = "Network"; +"ktg_settings_net_speed_boost" = "Speed boost"; "ktg_fonts_title" = "Fonts"; "ktg_fonts_reset" = "Reset"; @@ -2274,4 +2276,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_fonts_restart" = "Restart"; +"ktg_net_speed_boost_title" = "Network speed boost"; +"ktg_net_speed_boost_desc" = "Warning: changing this parameter to high values on slow networks can make even worse. Use at your own risk.\n\nYou'll need to restart app to save changes."; + +"ktg_net_speed_boost_default" = "Disabled"; +"ktg_net_speed_boost_slight" = "Slight"; +"ktg_net_speed_boost_medium" = "Medium"; +"ktg_net_speed_boost_big" = "Big"; + +"ktg_net_boost_restart_desc" = "You'll need to restart app to change network boost.\n\nRestart now?"; + // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 5451a0ebd..fc853aa2c 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -33,6 +33,8 @@ "ktg_settings_emoji_outline": "Обводка у больших эмодзи", "ktg_settings_always_show_scheduled": "Всегда показывать отложенные", "ktg_settings_fonts": "Изменить шрифты приложения", + "ktg_settings_network": "Сеть", + "ktg_settings_net_speed_boost": "Ускорение загрузки", "ktg_fonts_title": "Шрифты", "ktg_fonts_reset": "Сброс", "ktg_fonts_about": "Если вы хотите использовать жирное начертание для полужирного шрифта, не пишите «Bold» в названии, используйте настройку «Сделать полужирный жирным».\n\nДля применения и просмотра изменений требуется перезапуск.", @@ -42,5 +44,12 @@ "ktg_fonts_monospaced": "Моноширинный шрифт", "ktg_fonts_restart_new_fonts": "Для применения новых шрифтов требуется перезапуск.\n\nПерезапустить сейчас?", "ktg_fonts_restart_reset": "Для сброса шрифтов к стандартным требуется перезапуск.\n\nПерезапустить сейчас?", - "ktg_fonts_restart": "Перезапустить" + "ktg_fonts_restart": "Перезапустить", + "ktg_net_speed_boost_title": "Ускорение загрузки", + "ktg_net_speed_boost_desc": "Внимание: высокие значения параметра при слабых сетях могут сделать ещё хуже. Используйте на свой страх и риск.\n\nДля сохранения изменений требуется перезапуск.", + "ktg_net_speed_boost_default": "Отключено", + "ktg_net_speed_boost_slight": "Небольшое", + "ktg_net_speed_boost_medium": "Среднее", + "ktg_net_speed_boost_big": "Высокое", + "ktg_net_boost_restart_desc": "Для изменения ускорения загрузки требуется перезапуск.\n\nПерезапустить сейчас?" } diff --git a/Telegram/SourceFiles/boxes/net_boost_box.cpp b/Telegram/SourceFiles/boxes/net_boost_box.cpp new file mode 100644 index 000000000..a99766943 --- /dev/null +++ b/Telegram/SourceFiles/boxes/net_boost_box.cpp @@ -0,0 +1,88 @@ +/* +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 "boxes/net_boost_box.h" + +#include "lang/lang_keys.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/labels.h" +#include "styles/style_boxes.h" +#include "boxes/confirm_box.h" +#include "core/kotato_settings.h" +#include "app.h" + +NetBoostBox::NetBoostBox(QWidget* parent) +{ +} + +void NetBoostBox::prepare() { + setTitle(tr::ktg_net_speed_boost_title()); + + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); + + auto y = st::boxOptionListPadding.top(); + _description.create( + this, + tr::ktg_net_speed_boost_desc(tr::now), + st::boxLabel); + _description->moveToLeft(st::boxPadding.left(), y); + + y += _description->height() + st::boxMediumSkip; + + _boostGroup = std::make_shared(cNetSpeedBoost()); + + for (int i = 0; i <= 3; i++) { + const auto button = Ui::CreateChild( + this, + _boostGroup, + i, + BoostLabel(i), + st::autolockButton); + button->moveToLeft(st::boxPadding.left(), y); + y += button->heightNoMargins() + st::boxOptionListSkip; + } + showChildren(); + setDimensions(st::boxWidth, y); +} + +QString NetBoostBox::BoostLabel(int boost) { + switch (boost) { + case 0: + return tr::ktg_net_speed_boost_default(tr::now); + + case 1: + return tr::ktg_net_speed_boost_slight(tr::now); + + case 2: + return tr::ktg_net_speed_boost_medium(tr::now); + + case 3: + return tr::ktg_net_speed_boost_big(tr::now); + + default: + Unexpected("Boost in NetBoostBox::BoostLabel."); + } + return QString(); +} + +void NetBoostBox::save() { + const auto changeBoost = [=] { + SetNetworkBoost(_boostGroup->value()); + KotatoSettings::Write(); + App::restart(); + }; + + const auto box = std::make_shared>(); + + *box = getDelegate()->show( + Box( + tr::ktg_net_boost_restart_desc(tr::now), + tr::ktg_fonts_restart(tr::now), + tr::lng_cancel(tr::now), + changeBoost)); +} \ No newline at end of file diff --git a/Telegram/SourceFiles/boxes/net_boost_box.h b/Telegram/SourceFiles/boxes/net_boost_box.h new file mode 100644 index 000000000..1476b9e7f --- /dev/null +++ b/Telegram/SourceFiles/boxes/net_boost_box.h @@ -0,0 +1,33 @@ +/* +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 +*/ +#pragma once + +#include "boxes/abstract_box.h" + +namespace Ui { +class RadiobuttonGroup; +class Radiobutton; +class FlatLabel; +} // namespace Ui + +class NetBoostBox : public BoxContent { +public: + NetBoostBox(QWidget* parent); + + static QString BoostLabel(int boost); + +protected: + void prepare() override; + +private: + void save(); + + object_ptr _description = { nullptr }; + std::shared_ptr _boostGroup; + +}; \ No newline at end of file diff --git a/Telegram/SourceFiles/settings/settings_kotato.cpp b/Telegram/SourceFiles/settings/settings_kotato.cpp index 9078b10cd..a6a43c574 100644 --- a/Telegram/SourceFiles/settings/settings_kotato.cpp +++ b/Telegram/SourceFiles/settings/settings_kotato.cpp @@ -17,6 +17,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "boxes/connection_box.h" #include "boxes/fonts_box.h" +#include "boxes/net_boost_box.h" #include "boxes/about_box.h" #include "boxes/confirm_box.h" #include "info/profile/info_profile_button.h" @@ -104,6 +105,24 @@ void SetupKotatoChats(not_null container) { st::settingsButton )->addClickHandler([=] { Ui::show(Box()); + }); + + + AddSkip(container); +} + +void SetupKotatoNetwork(not_null container) { + AddDivider(container); + AddSkip(container); + AddSubsectionTitle(container, tr::ktg_settings_network()); + + AddButtonWithLabel( + container, + tr::ktg_settings_net_speed_boost(), + rpl::single(NetBoostBox::BoostLabel(cNetSpeedBoost())), + st::settingsButton + )->addClickHandler([=] { + Ui::show(Box()); }); AddSkip(container); @@ -121,7 +140,7 @@ void Kotato::setupContent(not_null controller) { SetupKotatoChats(content); //SetupKotatoFonts(content); - //SetupKotatoNetwork(content); + SetupKotatoNetwork(content); //SetupKotatoOther(content); Ui::ResizeFitChild(this, content); diff --git a/Telegram/SourceFiles/settings/settings_kotato.h b/Telegram/SourceFiles/settings/settings_kotato.h index fd7ef8092..53c2b646f 100644 --- a/Telegram/SourceFiles/settings/settings_kotato.h +++ b/Telegram/SourceFiles/settings/settings_kotato.h @@ -15,7 +15,7 @@ namespace Settings { void SetupKotatoChats(not_null container); //void SetupKotatoFonts(not_null container); -//void SetupKotatoNetwork(not_null container); +void SetupKotatoNetwork(not_null container); //void SetupKotatoOther(not_null container); class Kotato : public Section { diff --git a/Telegram/gyp/telegram/sources.txt b/Telegram/gyp/telegram/sources.txt index 284fc8ca9..abe4c65b0 100644 --- a/Telegram/gyp/telegram/sources.txt +++ b/Telegram/gyp/telegram/sources.txt @@ -68,6 +68,8 @@ <(src_loc)/boxes/local_storage_box.h <(src_loc)/boxes/mute_settings_box.cpp <(src_loc)/boxes/mute_settings_box.h +<(src_loc)/boxes/net_boost_box.cpp +<(src_loc)/boxes/net_boost_box.h <(src_loc)/boxes/peer_list_box.cpp <(src_loc)/boxes/peer_list_box.h <(src_loc)/boxes/peer_list_controllers.cpp