From d9572949f60960f2b825d4399df2921877ff98d1 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 3 May 2024 21:01:36 +0300 Subject: [PATCH] Replaced confirmation box for proxy links with generic box. --- Telegram/Resources/langs/lang.strings | 7 ++ Telegram/SourceFiles/boxes/boxes.style | 4 ++ Telegram/SourceFiles/boxes/connection_box.cpp | 68 ++++++++++++------- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index bf8781ace3..1ce2489af5 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -304,6 +304,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_sure_ban_admin" = "This user is an admin. Are you sure you want to go ahead and restrict them?"; "lng_sure_enable_socks" = "Are you sure you want to enable this proxy?\n\nServer: {server}\nPort: {port}\n\nYou can change your proxy server later in the Settings (Connection Type)."; "lng_sure_enable" = "Enable"; +"lng_proxy_box_title" = "Enable proxy"; +"lng_proxy_box_server" = "Server"; +"lng_proxy_box_port" = "Port"; +"lng_proxy_box_secret" = "Secret"; +"lng_proxy_box_status" = "Status"; +"lng_proxy_box_username" = "Username"; +"lng_proxy_box_password" = "Password"; "lng_proxy_invalid" = "The proxy link is invalid."; "lng_proxy_unsupported" = "Your Telegram Desktop version doesn't support this proxy type or the proxy link is invalid. Please update Telegram Desktop to the latest version."; diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 6d3d639ba0..cfd123c933 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -642,6 +642,10 @@ proxyDropdownUpPosition: point(-2px, 20px); proxyAboutPadding: margins(22px, 7px, 22px, 14px); proxyAboutSponsorPadding: margins(22px, 7px, 22px, 0px); +proxyApplyBoxLabel : FlatLabel(defaultFlatLabel) { + maxHeight: 30px; +} + markdownLinkFieldPadding: margins(22px, 0px, 22px, 10px); termsContent: FlatLabel(defaultFlatLabel) { diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 93aeba1a8d..9775ae058c 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_regex.h" #include "base/qthelp_url.h" #include "core/application.h" -#include "core/click_handler_types.h" #include "core/core_settings.h" #include "core/local_url_handlers.h" #include "lang/lang_keys.h" @@ -36,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" +#include "ui/vertical_list.h" #include "boxes/abstract_box.h" // Ui::show(). #include "window/window_session_controller.h" #include "styles/style_layers.h" @@ -1220,35 +1220,51 @@ void ProxiesBoxController::ShowApplyConfirmation( UrlStartRegExp, QString() ).replace(UrlEndRegExp, QString()); - const auto text = tr::lng_sure_enable_socks( - tr::now, - lt_server, - displayServer, - lt_port, - QString::number(proxy.port)) - + (proxy.type == Type::Mtproto - ? "\n\n" + tr::lng_proxy_sponsor_warning(tr::now) - : QString()); - auto callback = [=](Fn &&close) { - auto &proxies = Core::App().settings().proxy().list(); - if (!ranges::contains(proxies, proxy)) { - proxies.push_back(proxy); + const auto box = [=](not_null box) { + box->setTitle(tr::lng_proxy_box_title()); + if (type == Type::Mtproto) { + box->addRow(object_ptr( + box, + tr::lng_proxy_sponsor_warning(), + st::boxDividerLabel)); + Ui::AddSkip(box->verticalLayout()); + Ui::AddSkip(box->verticalLayout()); } - Core::App().setCurrentProxy( - proxy, - ProxyData::Settings::Enabled); - Local::writeSettings(); - close(); + const auto &stL = st::proxyApplyBoxLabel; + const auto &stSubL = st::boxDividerLabel; + const auto add = [&](const QString &s, tr::phrase<> phrase) { + if (!s.isEmpty()) { + box->addRow(object_ptr(box, s, stL)); + box->addRow(object_ptr(box, phrase(), stSubL)); + Ui::AddSkip(box->verticalLayout()); + Ui::AddSkip(box->verticalLayout()); + } + }; + if (!displayServer.isEmpty()) { + add(displayServer, tr::lng_proxy_box_server); + } + add(QString::number(proxy.port), tr::lng_proxy_box_port); + if (type == Type::Socks5) { + add(proxy.user, tr::lng_proxy_box_username); + add(proxy.password, tr::lng_proxy_box_password); + } else if (type == Type::Mtproto) { + add(proxy.password, tr::lng_proxy_box_secret); + } + box->addButton(tr::lng_sure_enable(), [=] { + auto &proxies = Core::App().settings().proxy().list(); + if (!ranges::contains(proxies, proxy)) { + proxies.push_back(proxy); + } + Core::App().setCurrentProxy(proxy, ProxyData::Settings::Enabled); + Local::writeSettings(); + box->closeBox(); + }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; - auto box = Ui::MakeConfirmBox({ - .text = text, - .confirmed = std::move(callback), - .confirmText = tr::lng_sure_enable(), - }); if (controller) { - controller->uiShow()->showBox(std::move(box)); + controller->uiShow()->showBox(Box(box)); } else { - Ui::show(std::move(box)); + Ui::show(Box(box)); } }