From 3a8898dd244f8875d189b8d26d13eef211738506 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 30 Jun 2025 10:50:14 +0300 Subject: [PATCH] Added ability to share proxy with QR code. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/boxes/connection_box.cpp | 34 +++++++++++++++---- Telegram/SourceFiles/boxes/connection_box.h | 4 +-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f2a47be760..9a8e6e2bf7 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1162,6 +1162,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_proxy_menu_delete" = "Delete"; "lng_proxy_menu_restore" = "Restore"; "lng_proxy_edit_share" = "Share"; +"lng_proxy_edit_share_qr_box_title" = "Share proxy with QR code"; "lng_proxy_address_label" = "Socket address"; "lng_proxy_credentials_optional" = "Credentials (optional)"; "lng_proxy_credentials" = "Credentials"; diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 621fd2c41e..7ec08e3b53 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "ui/basic_click_handlers.h" #include "ui/boxes/confirm_box.h" +#include "ui/boxes/peer_qr_box.h" #include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" #include "ui/painter.h" @@ -177,6 +178,7 @@ public: rpl::producer<> restoreClicks() const; rpl::producer<> editClicks() const; rpl::producer<> shareClicks() const; + rpl::producer<> showQrClicks() const; protected: int resizeGetHeight(int newWidth) override; @@ -198,6 +200,7 @@ private: rpl::event_stream<> _restoreClicks; rpl::event_stream<> _editClicks; rpl::event_stream<> _shareClicks; + rpl::event_stream<> _showQrClicks; base::unique_qptr _menu; bool _set = false; @@ -319,6 +322,10 @@ rpl::producer<> ProxyRow::shareClicks() const { return _shareClicks.events(); } +rpl::producer<> ProxyRow::showQrClicks() const { + return _showQrClicks.events(); +} + void ProxyRow::setupControls(View &&view) { updateFields(std::move(view)); _toggled.stop(); @@ -563,6 +570,9 @@ void ProxyRow::showMenu() { addAction(tr::lng_proxy_edit_share(tr::now), [=] { _shareClicks.fire({}); }, &st::menuIconShare); + addAction(tr::lng_group_invite_context_qr(tr::now), [=] { + _showQrClicks.fire({}); + }, &st::menuIconQrCode); } if (_view.deleted) { addAction(tr::lng_proxy_menu_restore(tr::now), [=] { @@ -898,9 +908,11 @@ void ProxiesBox::setupButtons(int id, not_null button) { getDelegate()->show(_controller->editItemBox(id)); }, button->lifetime()); - button->shareClicks( - ) | rpl::start_with_next([=] { - _controller->shareItem(id); + rpl::merge( + button->shareClicks() | rpl::map_to(false), + button->showQrClicks() | rpl::map_to(true) + ) | rpl::start_with_next([=](bool qr) { + _controller->shareItem(id, qr); }, button->lifetime()); button->clicks( @@ -1411,8 +1423,8 @@ void ProxiesBoxController::restoreItem(int id) { setDeleted(id, false); } -void ProxiesBoxController::shareItem(int id) { - share(findById(id)->data); +void ProxiesBoxController::shareItem(int id, bool qr) { + share(findById(id)->data, qr); } void ProxiesBoxController::applyItem(int id) { @@ -1653,10 +1665,11 @@ void ProxiesBoxController::updateView(const Item &item) { deleted, !deleted && supportsShare, supportsCalls, - state }); + state, + }); } -void ProxiesBoxController::share(const ProxyData &proxy) { +void ProxiesBoxController::share(const ProxyData &proxy, bool qr) { if (proxy.type == Type::Http) { return; } @@ -1669,6 +1682,13 @@ void ProxiesBoxController::share(const ProxyData &proxy) { ? "&pass=" + qthelp::url_encode(proxy.password) : "") + ((proxy.type == Type::Mtproto && !proxy.password.isEmpty()) ? "&secret=" + proxy.password : ""); + if (qr) { + _show->showBox(Box([=](not_null box) { + Ui::FillPeerQrBox(box, nullptr, link, rpl::single(QString())); + box->setTitle(tr::lng_proxy_edit_share_qr_box_title()); + })); + return; + } QGuiApplication::clipboard()->setText(link); _show->showToast(tr::lng_username_copied(tr::now)); } diff --git a/Telegram/SourceFiles/boxes/connection_box.h b/Telegram/SourceFiles/boxes/connection_box.h index 25da434586..5c92904b79 100644 --- a/Telegram/SourceFiles/boxes/connection_box.h +++ b/Telegram/SourceFiles/boxes/connection_box.h @@ -73,7 +73,7 @@ public: void deleteItem(int id); void restoreItem(int id); - void shareItem(int id); + void shareItem(int id, bool qr); void applyItem(int id); object_ptr editItemBox(int id); object_ptr addNewItemBox(); @@ -106,7 +106,7 @@ private: std::vector::iterator findByProxy(const ProxyData &proxy); void setDeleted(int id, bool deleted); void updateView(const Item &item); - void share(const ProxyData &proxy); + void share(const ProxyData &proxy, bool qr = false); void saveDelayed(); void refreshChecker(Item &item); void setupChecker(int id, const Checker &checker);