From a8bae3231ff2593bf333c204461964ed33221625 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 26 Aug 2022 22:06:21 +0300 Subject: [PATCH] [Option][GUI] Upload speed boost --- Telegram/Resources/langs/rewrites/en.json | 7 +++ .../SourceFiles/kotato/kotato_settings.cpp | 24 +++++++++ .../kotato/kotato_settings_menu.cpp | 51 +++++++++++++++++++ .../mtproto/dedicated_file_loader.cpp | 10 +++- Telegram/SourceFiles/mtproto/facade.h | 8 +-- Telegram/SourceFiles/storage/file_upload.cpp | 23 ++++++--- Telegram/SourceFiles/storage/file_upload.h | 2 +- 7 files changed, 113 insertions(+), 12 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 7135ec517..fd76c661c 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -45,6 +45,13 @@ "ktg_fonts_use_system_font": "Use system font", "ktg_fonts_use_original_metrics": "Use Open Sans height", "ktg_settings_network": "Network", + "ktg_settings_net_speed_boost": "Upload speed boost", + "ktg_net_speed_boost_title": "Upload 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_settings_system": "System", "ktg_settings_other": "Other", "ktg_profile_copy_id": "Copy ID", diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index 48e5b16b4..d47b1ec7f 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -155,6 +155,25 @@ CheckHandler IntLimitMin(int min) { } +CheckHandler NetSpeedBoostConv(CheckHandler wrapped = nullptr) { + return [=] (QVariant value) -> QVariant { + auto newValue = 0; + if (value.canConvert()) { + newValue = value.value(); + } else if (value.canConvert()) { + const auto strValue = value.value(); + if (strValue == "high") { + newValue = 3; + } else if (strValue == "medium") { + newValue = 2; + } else if (strValue == "low") { + newValue = 1; + } + } + return (wrapped) ? wrapped(newValue) : newValue; + }; +} + struct Definition { SettingScope scope = SettingScope::Global; SettingStorage storage = SettingStorage::MainJson; @@ -266,6 +285,10 @@ const std::map> DefinitionMap { .type = SettingType::IntSetting, .defaultValue = 2, .limitHandler = IntLimit(0, 2, 2), }}, + { "net_speed_boost", { + .type = SettingType::IntSetting, + .defaultValue = 0, + .limitHandler = NetSpeedBoostConv(IntLimit(0, 3)), }}, }; using OldOptionKey = QString; @@ -411,6 +434,7 @@ QByteArray GenerateSettingsJson(bool areDefault = false) { if (areDefault) { settings.insert(qsl("version"), QString::number(AppKotatoVersion)); + settings.insert(qsl("net_speed_boost"), QJsonValue(QJsonValue::Null)); } auto document = QJsonDocument(); diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index 5ddefdb3a..a19344605 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -48,6 +48,26 @@ namespace Settings { namespace { +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 ChatIdLabel(int option) { switch (option) { case 0: @@ -211,6 +231,37 @@ void SetupKotatoNetwork(not_null container) { AddSkip(container); AddSubsectionTitle(container, rktr("ktg_settings_network")); + const auto netBoostButton = container->add( + object_ptr