From 1f18c9a273621fc1b9366a8c189b4bb56b9d6a17 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 28 Feb 2022 19:21:28 +0300 Subject: [PATCH] Added RTMP info to settings of group call. --- Telegram/SourceFiles/calls/calls.style | 12 + .../calls/group/calls_group_call.cpp | 8 + .../calls/group/calls_group_rtmp.cpp | 305 ++++++++++-------- .../calls/group/calls_group_rtmp.h | 18 ++ .../calls/group/calls_group_settings.cpp | 23 ++ 5 files changed, 238 insertions(+), 128 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls.style b/Telegram/SourceFiles/calls/calls.style index 2dacab597..7609eb9a6 100644 --- a/Telegram/SourceFiles/calls/calls.style +++ b/Telegram/SourceFiles/calls/calls.style @@ -12,6 +12,7 @@ using "ui/layers/layers.style"; using "ui/chat/chat.style"; // GroupCallUserpics using "info/info.style"; // ShortInfoCover using "window/window.style"; +using "settings/settings.style"; // settingsSubsectionTitle CallSignalBars { width: pixels; @@ -1380,6 +1381,17 @@ groupCallRtmpShowButton: IconButton(defaultIconButton) { color: windowBgOver; } } +groupCallSettingsRtmpShowButton: IconButton(groupCallRtmpShowButton) { + ripple: groupCallRipple; +} +groupCallSubsectionTitle: FlatLabel(settingsSubsectionTitle) { + textFg: groupCallActiveFg; +} +groupCallAttentionBoxButton: RoundButton(groupCallBoxButton) { + textFg: attentionButtonFg; + textFgOver: attentionButtonFgOver; +} + groupCallRtmpUrlSkip: 1px; groupCallRtmpKeySubsectionTitleSkip: 8px; groupCallRtmpSubsectionTitleAddPadding: margins(0px, -1px, 0px, -4px); diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index f01dfcba3..1570a5b41 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -1028,6 +1028,14 @@ rpl::producer GroupCall::emptyRtmpValue() const { return _emptyRtmp.value(); } +QString GroupCall::rtmpUrl() const { + return _rtmpUrl; +} + +QString GroupCall::rtmpKey() const { + return _rtmpKey; +} + Data::GroupCall *GroupCall::lookupReal() const { const auto real = _peer->groupCall(); return (real && real->id() == _id) ? real : nullptr; diff --git a/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp b/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp index 6b63dc8c0..9128cf1d9 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp @@ -19,11 +19,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" +#include "ui/wrap/vertical_layout.h" #include "styles/style_boxes.h" #include "styles/style_calls.h" #include "styles/style_info.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" +#include "styles/style_settings.h" #include #include @@ -41,141 +43,23 @@ void StartWithBox( Fn showToast, rpl::producer &&data) { struct State { - rpl::variable hidden = true; - rpl::variable key; - rpl::variable url; base::unique_qptr menu; - bool warned = false; }; - - const auto &rowPadding = st::boxRowPadding; - - const auto passChar = QChar(box->style()->styleHint( - QStyle::SH_LineEdit_PasswordCharacter)); const auto state = box->lifetime().make_state(); - state->key = rpl::duplicate( - data - ) | rpl::map([=](const auto &d) { return d.key; }); - state->url = std::move( - data - ) | rpl::map([=](const auto &d) { return d.url; }); - const auto addButton = [&]( - bool key, - rpl::producer &&text) { - const auto &padding = st::groupCallRtmpCopyButton.padding; - - auto wrap = object_ptr(box); - auto button = Ui::CreateChild( - wrap.data(), - rpl::duplicate(text), - st::groupCallRtmpCopyButton); - button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); - button->setClickedCallback(key - ? Fn([=] { - QGuiApplication::clipboard()->setText(state->key.current()); - showToast(tr::lng_group_call_rtmp_key_copied(tr::now)); - }) - : Fn([=] { - QGuiApplication::clipboard()->setText(state->url.current()); - showToast(tr::lng_group_call_rtmp_url_copied(tr::now)); - })); - const auto weak = box->addRow(std::move(wrap), rowPadding); - button->heightValue( - ) | rpl::start_with_next([=](int height) { - weak->resize(weak->width(), height); - }, box->lifetime()); - return weak; - }; - - const auto addLabel = [&]( - rpl::producer &&text, - const style::FlatLabel &st) { - const auto label = box->addRow( - object_ptr(box, std::move(text), st), - st::boxRowPadding); - label->setSelectable(true); - label->setBreakEverywhere(true); - return label; - }; + StartRtmpProcess::FillRtmpRows( + box->verticalLayout(), + true, + std::move(showBox), + std::move(showToast), + std::move(data), + &st::boxLabel, + &st::groupCallRtmpShowButton, + &st::settingsSubsectionTitle, + &st::attentionBoxButton); box->setTitle(tr::lng_group_call_rtmp_title()); - // Server URL. - Settings::AddSubsectionTitle( - box->verticalLayout(), - tr::lng_group_call_rtmp_url_subtitle(), - st::groupCallRtmpSubsectionTitleAddPadding); - auto urlLabelContent = state->url.value(); - addLabel(std::move(urlLabelContent), st::boxLabel); - box->addSkip(st::groupCallRtmpUrlSkip); - addButton(false, tr::lng_group_call_rtmp_url_copy()); - // - - Settings::AddDivider(box->verticalLayout()); - - // Stream Key. - box->addSkip(st::groupCallRtmpKeySubsectionTitleSkip); - Settings::AddSubsectionTitle( - box->verticalLayout(), - tr::lng_group_call_rtmp_key_subtitle(), - st::groupCallRtmpSubsectionTitleAddPadding); - - auto keyLabelContent = rpl::combine( - state->hidden.value(), - state->key.value() - ) | rpl::map([passChar](bool hidden, const QString &key) { - return key.isEmpty() - ? QString() - : hidden - ? QString().fill(passChar, kPasswordCharAmount) - : key; - }); - const auto streamKeyLabel = addLabel( - std::move(keyLabelContent), - st::boxLabel); - streamKeyLabel->setSelectable(false); - const auto streamKeyButton = Ui::CreateChild( - box.get(), - st::groupCallRtmpShowButton); - - streamKeyLabel->topValue( - ) | rpl::start_with_next([=, right = rowPadding.right()](int top) { - streamKeyButton->moveToRight( - st::groupCallRtmpShowButtonPosition.x(), - top + st::groupCallRtmpShowButtonPosition.y()); - streamKeyButton->raise(); - }, box->lifetime()); - streamKeyButton->addClickHandler([=] { - const auto toggle = [=] { - const auto newValue = !state->hidden.current(); - state->hidden = newValue; - streamKeyLabel->setSelectable(!newValue); - streamKeyLabel->setAttribute( - Qt::WA_TransparentForMouseEvents, - newValue); - }; - if (!state->warned && state->hidden.current()) { - showBox(Ui::MakeConfirmBox({ - .text = tr::lng_group_call_rtmp_key_warning( - Ui::Text::RichLangValue), - .confirmed = [=](Fn &&close) { - state->warned = true; - toggle(); - close(); - }, - .confirmText = tr::lng_from_request_understand(), - .cancelText = tr::lng_close(), - .confirmStyle = &st::attentionBoxButton, - })); - } else { - toggle(); - } - }); - - addButton(true, tr::lng_group_call_rtmp_key_copy()); - // - Settings::AddDividerText( box->verticalLayout(), tr::lng_group_call_rtmp_info()); @@ -312,4 +196,169 @@ void StartRtmpProcess::createBox() { _request->showBox(std::move(object)); } +void StartRtmpProcess::FillRtmpRows( + not_null container, + bool divider, + Fn)> showBox, + Fn showToast, + rpl::producer &&data, + const style::FlatLabel *labelStyle, + const style::IconButton *showButtonStyle, + const style::FlatLabel *subsectionTitleStyle, + const style::RoundButton *attentionButtonStyle) { + struct State { + rpl::variable hidden = true; + rpl::variable key; + rpl::variable url; + bool warned = false; + }; + + const auto &rowPadding = st::boxRowPadding; + + const auto passChar = QChar(container->style()->styleHint( + QStyle::SH_LineEdit_PasswordCharacter)); + const auto state = container->lifetime().make_state(); + state->key = rpl::duplicate( + data + ) | rpl::map([=](const auto &d) { return d.key; }); + state->url = std::move( + data + ) | rpl::map([=](const auto &d) { return d.url; }); + + const auto addButton = [&]( + bool key, + rpl::producer &&text) { + const auto &padding = st::groupCallRtmpCopyButton.padding; + + auto wrap = object_ptr(container); + auto button = Ui::CreateChild( + wrap.data(), + rpl::duplicate(text), + st::groupCallRtmpCopyButton); + button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); + button->setClickedCallback(key + ? Fn([=] { + QGuiApplication::clipboard()->setText(state->key.current()); + showToast(tr::lng_group_call_rtmp_key_copied(tr::now)); + }) + : Fn([=] { + QGuiApplication::clipboard()->setText(state->url.current()); + showToast(tr::lng_group_call_rtmp_url_copied(tr::now)); + })); + const auto weak = container->add(std::move(wrap), rowPadding); + button->heightValue( + ) | rpl::start_with_next([=](int height) { + weak->resize(weak->width(), height); + }, container->lifetime()); + return weak; + }; + + const auto addLabel = [&]( + rpl::producer &&text, + const style::FlatLabel &st) { + const auto label = container->add( + object_ptr(container, std::move(text), st), + st::boxRowPadding); + label->setSelectable(true); + label->setBreakEverywhere(true); + return label; + }; + + // Server URL. + { + // Settings::AddSubsectionTitle + container->add( + object_ptr( + container, + tr::lng_group_call_rtmp_url_subtitle(), + *subsectionTitleStyle), + st::settingsSubsectionTitlePadding + + st::groupCallRtmpSubsectionTitleAddPadding); + } + + auto urlLabelContent = state->url.value(); + addLabel(std::move(urlLabelContent), *labelStyle); + container->add(object_ptr( + container, + st::groupCallRtmpUrlSkip)); + addButton(false, tr::lng_group_call_rtmp_url_copy()); + // + + if (divider) { + Settings::AddDivider(container); + } + + // Stream Key. + container->add(object_ptr( + container, + st::groupCallRtmpKeySubsectionTitleSkip)); + + { + // Settings::AddSubsectionTitle + container->add( + object_ptr( + container, + tr::lng_group_call_rtmp_key_subtitle(), + *subsectionTitleStyle), + st::settingsSubsectionTitlePadding + + st::groupCallRtmpSubsectionTitleAddPadding); + } + + auto keyLabelContent = rpl::combine( + state->hidden.value(), + state->key.value() + ) | rpl::map([passChar](bool hidden, const QString &key) { + return key.isEmpty() + ? QString() + : hidden + ? QString().fill(passChar, kPasswordCharAmount) + : key; + }); + const auto streamKeyLabel = addLabel( + std::move(keyLabelContent), + *labelStyle); + streamKeyLabel->setSelectable(false); + const auto streamKeyButton = Ui::CreateChild( + container.get(), + *showButtonStyle); + + streamKeyLabel->topValue( + ) | rpl::start_with_next([=, right = rowPadding.right()](int top) { + streamKeyButton->moveToRight( + st::groupCallRtmpShowButtonPosition.x(), + top + st::groupCallRtmpShowButtonPosition.y()); + streamKeyButton->raise(); + }, container->lifetime()); + streamKeyButton->addClickHandler([=] { + const auto toggle = [=] { + const auto newValue = !state->hidden.current(); + state->hidden = newValue; + streamKeyLabel->setSelectable(!newValue); + streamKeyLabel->setAttribute( + Qt::WA_TransparentForMouseEvents, + newValue); + }; + if (!state->warned && state->hidden.current()) { + showBox(Ui::MakeConfirmBox({ + .text = tr::lng_group_call_rtmp_key_warning( + Ui::Text::RichLangValue), + .confirmed = [=](Fn &&close) { + state->warned = true; + toggle(); + close(); + }, + .confirmText = tr::lng_from_request_understand(), + .cancelText = tr::lng_close(), + .confirmStyle = attentionButtonStyle, + .labelStyle = labelStyle, + })); + } else { + toggle(); + } + }); + + addButton(true, tr::lng_group_call_rtmp_key_copy()); + // +} + } // namespace Calls::Group diff --git a/Telegram/SourceFiles/calls/group/calls_group_rtmp.h b/Telegram/SourceFiles/calls/group/calls_group_rtmp.h index fabc5136a..6142361f0 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_rtmp.h +++ b/Telegram/SourceFiles/calls/group/calls_group_rtmp.h @@ -14,8 +14,15 @@ class PeerData; namespace Ui { class BoxContent; +class VerticalLayout; } // namespace Ui +namespace style { +struct FlatLabel; +struct RoundButton; +struct IconButton; +} // namespace style + namespace Calls::Group { struct JoinInfo; @@ -36,6 +43,17 @@ public: Fn showToast, Fn done); + static void FillRtmpRows( + not_null container, + bool divider, + Fn)> showBox, + Fn showToast, + rpl::producer &&data, + const style::FlatLabel *labelStyle, + const style::IconButton *showButtonStyle, + const style::FlatLabel *subsectionTitleStyle, + const style::RoundButton *attentionButtonStyle); + private: void requestUrl(bool revoke); void processUrl(Data data); diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index 0d9241936..6d9adb393 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -33,6 +33,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_group_call.h" +#include "calls/group/calls_group_rtmp.h" +#include "ui/toast/toast.h" #include "data/data_changes.h" #include "core/application.h" #include "ui/boxes/single_choice_box.h" @@ -625,6 +627,27 @@ void SettingsBox( st::groupCallSettingsButton )->addClickHandler(std::move(shareLink)); } + if (rtmp) { + StartRtmpProcess::FillRtmpRows( + box->verticalLayout(), + false, + [=](object_ptr &&object) { + box->getDelegate()->show(std::move(object)); + }, + [=](QString text) { + Ui::Toast::Show( + box->getDelegate()->outerContainer(), + text); + }, + rpl::single({ + call->rtmpUrl(), + call->rtmpKey() + }), + &st::groupCallBoxLabel, + &st::groupCallSettingsRtmpShowButton, + &st::groupCallSubsectionTitle, + &st::groupCallAttentionBoxButton); + } if (peer->canManageGroupCall()) { AddButton(