From f85c3c88f72f7835810ed20937495e278f6976cd Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 23 Feb 2024 13:29:17 +0400 Subject: [PATCH] Add rpl interface to RadiobuttonGroup. --- Telegram/SourceFiles/boxes/add_contact_box.cpp | 6 +++--- Telegram/SourceFiles/boxes/auto_lock_box.cpp | 8 +++++--- Telegram/SourceFiles/boxes/connection_box.cpp | 8 ++++---- Telegram/SourceFiles/boxes/download_path_box.cpp | 8 +++++--- Telegram/SourceFiles/boxes/edit_privacy_box.cpp | 2 +- Telegram/SourceFiles/boxes/gift_premium_box.cpp | 4 ++-- .../boxes/peers/edit_participant_box.cpp | 2 +- .../peers/edit_peer_history_visibility_box.cpp | 2 +- .../SourceFiles/boxes/peers/edit_peer_type_box.cpp | 14 +++++++------- Telegram/SourceFiles/boxes/premium_limits_box.cpp | 2 +- Telegram/SourceFiles/boxes/ringtones_box.cpp | 2 +- .../SourceFiles/boxes/self_destruction_box.cpp | 2 +- .../export/view/export_view_settings.cpp | 2 +- .../info/boosts/create_giveaway_box.cpp | 10 +++++----- .../passport/passport_panel_edit_document.cpp | 2 +- .../SourceFiles/settings/settings_business.cpp | 2 +- Telegram/SourceFiles/settings/settings_calls.cpp | 2 +- .../SourceFiles/settings/settings_global_ttl.cpp | 4 ++-- Telegram/SourceFiles/settings/settings_premium.cpp | 2 +- .../settings/settings_privacy_controllers.cpp | 2 +- .../SourceFiles/ui/effects/premium_graphics.cpp | 8 ++++---- .../window/themes/window_themes_cloud_list.cpp | 2 +- 22 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 9819c855cb..d3715e8843 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1018,7 +1018,7 @@ void SetupChannelBox::prepare() { cancel); connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); }); - _link->setVisible(_privacyGroup->value() == Privacy::Public); + _link->setVisible(_privacyGroup->current() == Privacy::Public); _privacyGroup->setChangedCallback([=](Privacy value) { privacyChanged(value); @@ -1063,7 +1063,7 @@ void SetupChannelBox::updateMaxHeight() { : 0) + st::newGroupPadding.bottom(); if (!_channel->isMegagroup() - || _privacyGroup->value() == Privacy::Public) { + || _privacyGroup->current() == Privacy::Public) { newHeight += st::newGroupLinkPadding.top() + _link->height() + st::newGroupLinkPadding.bottom(); @@ -1264,7 +1264,7 @@ void SetupChannelBox::save() { }; if (_saveRequestId) { return; - } else if (_privacyGroup->value() == Privacy::Private) { + } else if (_privacyGroup->current() == Privacy::Private) { closeBox(); } else { const auto link = _link->text().trimmed(); diff --git a/Telegram/SourceFiles/boxes/auto_lock_box.cpp b/Telegram/SourceFiles/boxes/auto_lock_box.cpp index 70c09ec9ef..cc7cdb4271 100644 --- a/Telegram/SourceFiles/boxes/auto_lock_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_lock_box.cpp @@ -81,9 +81,9 @@ void AutoLockBox::prepare() { const auto timeInput = Ui::CreateChild( this, - (group->value() == kCustom) + (group->current() == kCustom ? TimeString(currentTime) - : kDefaultCustom.utf8(), + : kDefaultCustom.utf8()), st::autolockTimeField, st::autolockDateField, st::scheduleTimeSeparator, @@ -115,7 +115,9 @@ void AutoLockBox::prepare() { }); rpl::merge( - boxClosing() | rpl::filter([=] { return group->value() == kCustom; }), + boxClosing() | rpl::filter( + [=] { return group->current() == kCustom; } + ), timeInput->submitRequests() ) | rpl::start_with_next([=] { if (const auto result = collect()) { diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 4403f56faa..cf9d91f8cb 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -717,7 +717,7 @@ void ProxiesBox::refreshProxyForCalls() { return; } _proxyForCalls->toggle( - (_proxySettings->value() == ProxyData::Settings::Enabled + (_proxySettings->current() == ProxyData::Settings::Enabled && _currentProxySupportsCallsId != 0), anim::type::normal); } @@ -864,7 +864,7 @@ void ProxyBox::refreshButtons() { addButton(tr::lng_settings_save(), [=] { save(); }); addButton(tr::lng_cancel(), [=] { closeBox(); }); - const auto type = _type->value(); + const auto type = _type->current(); if (type == Type::Socks5 || type == Type::Mtproto) { addLeftButton(tr::lng_proxy_share(), [=] { share(); }); } @@ -885,7 +885,7 @@ void ProxyBox::share() { ProxyData ProxyBox::collectData() { auto result = ProxyData(); - result.type = _type->value(); + result.type = _type->current(); result.host = _host->getLastText().trimmed(); result.port = _port->getLastText().trimmed().toInt(); result.user = (result.type == Type::Mtproto) @@ -1053,7 +1053,7 @@ void ProxyBox::setupControls(const ProxyData &data) { handleType(type); refreshButtons(); }); - handleType(_type->value()); + handleType(_type->current()); } void ProxyBox::addLabel( diff --git a/Telegram/SourceFiles/boxes/download_path_box.cpp b/Telegram/SourceFiles/boxes/download_path_box.cpp index 69179e9f45..f61c0e6e7d 100644 --- a/Telegram/SourceFiles/boxes/download_path_box.cpp +++ b/Telegram/SourceFiles/boxes/download_path_box.cpp @@ -44,7 +44,9 @@ void DownloadPathBox::prepare() { setTitle(tr::lng_download_path_header()); - _group->setChangedCallback([this](Directory value) { radioChanged(value); }); + _group->setChangedCallback([this](Directory value) { + radioChanged(value); + }); _pathLink->addClickHandler([=] { editPath(); }); if (!_path.isEmpty() && _path != FileDialog::Tmp()) { @@ -54,7 +56,7 @@ void DownloadPathBox::prepare() { } void DownloadPathBox::updateControlsVisibility() { - auto custom = (_group->value() == Directory::Custom); + auto custom = (_group->current() == Directory::Custom); _pathLink->setVisible(custom); auto newHeight = st::boxOptionListPadding.top() + (_default ? _default->getMargins().top() + _default->heightNoMargins() : 0) + st::boxOptionListSkip + _temp->heightNoMargins() + st::boxOptionListSkip + _dir->heightNoMargins(); @@ -122,7 +124,7 @@ void DownloadPathBox::editPath() { void DownloadPathBox::save() { #ifndef OS_WIN_STORE - auto value = _group->value(); + auto value = _group->current(); auto computePath = [this, value] { if (value == Directory::Custom) { return _path; diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 7ad5798ec4..367742971a 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -582,7 +582,7 @@ void EditMessagesPrivacyBox( box->addButton(tr::lng_settings_save(), [=] { if (controller->session().premium()) { privacy->updateNewRequirePremium( - group->value() == kOptionPremium); + group->current() == kOptionPremium); box->closeBox(); } else { showToast(); diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index 7e0e6b5dc5..f544b5647b 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -386,7 +386,7 @@ void GiftBox( state->buttonText.events(), Ui::Premium::GiftGradientStops(), [=] { - const auto value = group->value(); + const auto value = group->current(); return (value < options.size() && value >= 0) ? options[value].botUrl : QString(); @@ -665,7 +665,7 @@ void GiftsBox( } auto invoice = api->invoice( users.size(), - api->monthsFromPreset(group->value())); + api->monthsFromPreset(group->current())); invoice.purpose = Payments::InvoicePremiumGiftCodeUsers{ users }; state->confirmButtonBusy = true; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 51d969d0eb..ff9398bf00 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -840,7 +840,7 @@ void EditRestrictedBox::createUntilGroup() { void EditRestrictedBox::createUntilVariants() { auto addVariant = [&](int value, const QString &text) { - if (!canSave() && _untilGroup->value() != value) { + if (!canSave() && _untilGroup->current() != value) { return; } _untilVariants.emplace_back( diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp index 6970664166..9086dfce8f 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp @@ -25,7 +25,7 @@ void EditPeerHistoryVisibilityBox( box->setTitle(tr::lng_manage_history_visibility_title()); box->addButton(tr::lng_settings_save(), [=] { - savedCallback(historyVisibility->value()); + savedCallback(historyVisibility->current()); box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index 46fb2619c0..6cafe4d2c6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -76,7 +76,7 @@ public: } [[nodiscard]] Privacy getPrivacy() const { - return _controls.privacy->value(); + return _controls.privacy->current(); } [[nodiscard]] bool noForwards() const { @@ -238,7 +238,7 @@ void Controller::createContent() { }, wrap->lifetime()); } else { _controls.whoSendWrap->toggle( - (_controls.privacy->value() == Privacy::HasUsername), + (_controls.privacy->current() == Privacy::HasUsername), anim::type::instant); } auto joinToWrite = _controls.joinToWrite @@ -299,7 +299,7 @@ void Controller::createContent() { if (_linkOnly) { _controls.inviteLinkWrap->show(anim::type::instant); } else { - if (_controls.privacy->value() == Privacy::NoUsername) { + if (_controls.privacy->current() == Privacy::NoUsername) { checkUsernameAvailability(); } const auto forShowing = _dataSavedValue @@ -474,7 +474,7 @@ object_ptr Controller::createUsernameEdit() { &Ui::UsernameInput::changed, [this] { usernameChanged(); }); - const auto shown = (_controls.privacy->value() == Privacy::HasUsername); + const auto shown = (_controls.privacy->current() == Privacy::HasUsername); result->toggle(shown, anim::type::instant); return result; @@ -539,7 +539,7 @@ void Controller::checkUsernameAvailability() { if (!_controls.usernameInput) { return; } - const auto initial = (_controls.privacy->value() != Privacy::HasUsername); + const auto initial = (_controls.privacy->current() != Privacy::HasUsername); const auto checking = initial ? u".bad."_q : getUsernameInput(); @@ -573,11 +573,11 @@ void Controller::checkUsernameAvailability() { _controls.privacy->setValue(Privacy::NoUsername); } else if (type == u"CHANNELS_ADMIN_PUBLIC_TOO_MUCH"_q) { _usernameState = UsernameState::TooMany; - if (_controls.privacy->value() == Privacy::HasUsername) { + if (_controls.privacy->current() == Privacy::HasUsername) { askUsernameRevoke(); } } else if (initial) { - if (_controls.privacy->value() == Privacy::HasUsername) { + if (_controls.privacy->current() == Privacy::HasUsername) { showUsernameEmpty(); setFocusUsername(); } diff --git a/Telegram/SourceFiles/boxes/premium_limits_box.cpp b/Telegram/SourceFiles/boxes/premium_limits_box.cpp index ad8d313df0..2a9c0d4b10 100644 --- a/Telegram/SourceFiles/boxes/premium_limits_box.cpp +++ b/Telegram/SourceFiles/boxes/premium_limits_box.cpp @@ -1142,7 +1142,7 @@ void AccountsLimitBox( const auto ref = QString(); const auto wasAccount = &session->account(); - const auto nowAccount = accounts[group->value()]; + const auto nowAccount = accounts[group->current()]; if (wasAccount == nowAccount) { Settings::ShowPremium(session, ref); return; diff --git a/Telegram/SourceFiles/boxes/ringtones_box.cpp b/Telegram/SourceFiles/boxes/ringtones_box.cpp index 74e8f510b7..d8097222e9 100644 --- a/Telegram/SourceFiles/boxes/ringtones_box.cpp +++ b/Telegram/SourceFiles/boxes/ringtones_box.cpp @@ -327,7 +327,7 @@ void RingtonesBox( box->setWidth(st::boxWideWidth); box->addButton(tr::lng_settings_save(), [=] { - const auto value = state->group->value(); + const auto value = state->group->current(); auto sound = (value == kDefaultValue) ? Data::NotifySound() : (value == kNoSoundValue) diff --git a/Telegram/SourceFiles/boxes/self_destruction_box.cpp b/Telegram/SourceFiles/boxes/self_destruction_box.cpp index 03d8a6155a..0ab869ae5b 100644 --- a/Telegram/SourceFiles/boxes/self_destruction_box.cpp +++ b/Telegram/SourceFiles/boxes/self_destruction_box.cpp @@ -95,7 +95,7 @@ void SelfDestructionBox::showContent() { clearButtons(); addButton(tr::lng_settings_save(), [=] { - const auto value = _ttlGroup->value(); + const auto value = _ttlGroup->current(); switch (_type) { case Type::Account: _session->api().selfDestruct().updateAccountTTL(value); diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index bbc91c2dcd..8f546260a7 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -78,7 +78,7 @@ void ChooseFormatBox( addFormatOption( tr::lng_export_option_html_and_json(tr::now), Format::HtmlAndJson); - box->addButton(tr::lng_settings_save(), [=] { done(group->value()); }); + box->addButton(tr::lng_settings_save(), [=] { done(group->current()); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index 6c5583723b..01462aa3ba 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -630,9 +630,9 @@ void CreateGiveawayBox( const auto createCallback = [=](GiveawayType type) { return [=] { - const auto was = membersGroup->value(); + const auto was = membersGroup->current(); membersGroup->setValue(type); - const auto now = membersGroup->value(); + const auto now = membersGroup->current(); if (was == now) { base::call_delayed( st::defaultRippleAnimation.hideDuration, @@ -990,7 +990,7 @@ void CreateGiveawayBox( if (state->confirmButtonBusy.current()) { return; } - const auto type = typeGroup->value(); + const auto type = typeGroup->current(); const auto isSpecific = (type == GiveawayType::SpecificUsers); const auto isRandom = (type == GiveawayType::Random); if (!isSpecific && !isRandom) { @@ -1003,7 +1003,7 @@ void CreateGiveawayBox( prepaid ? prepaid->months : state->apiOptions.monthsFromPreset( - durationGroup->value())); + durationGroup->current())); if (isSpecific) { if (state->selectedToAward.empty()) { return; @@ -1029,7 +1029,7 @@ void CreateGiveawayBox( .countries = state->countriesValue.current(), .additionalPrize = state->additionalPrize.current(), .untilDate = state->dateValue.current(), - .onlyNewSubscribers = (membersGroup->value() + .onlyNewSubscribers = (membersGroup->current() == GiveawayType::OnlyNewMembers), .showWinners = state->showWinners.current(), }; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index c3715e9772..bac92c2c80 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -140,7 +140,7 @@ void RequestTypeBox::setupControls( _height = y; _submit = [=] { - const auto value = group->hasValue() ? group->value() : -1; + const auto value = group->hasValue() ? group->current() : -1; if (value >= 0) { submit(value); } diff --git a/Telegram/SourceFiles/settings/settings_business.cpp b/Telegram/SourceFiles/settings/settings_business.cpp index f936466068..aae5868df7 100644 --- a/Telegram/SourceFiles/settings/settings_business.cpp +++ b/Telegram/SourceFiles/settings/settings_business.cpp @@ -503,7 +503,7 @@ QPointer Business::createPinnedToBottom( std::move(buttonText), std::nullopt, [=, options = session->api().premium().subscriptionOptions()] { - const auto value = _radioGroup->value(); + const auto value = _radioGroup->current(); return (value < options.size() && value >= 0) ? options[value].botUrl : QString(); diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index 0b6a706746..de7c34e3eb 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -607,7 +607,7 @@ void ChooseMediaDeviceBox( button->finishAnimating(); button->clicks( ) | rpl::filter([=] { - return (group->value() == index); + return (group->current() == index); }) | rpl::start_with_next([=] { choose(id); }, button->lifetime()); diff --git a/Telegram/SourceFiles/settings/settings_global_ttl.cpp b/Telegram/SourceFiles/settings/settings_global_ttl.cpp index 8e2024622c..99dea5b2d1 100644 --- a/Telegram/SourceFiles/settings/settings_global_ttl.cpp +++ b/Telegram/SourceFiles/settings/settings_global_ttl.cpp @@ -294,7 +294,7 @@ void GlobalTTL::rebuildButtons(TimeId currentTTL) const { rpl::single(ttlText)), st::settingsButtonNoIcon)); button->setClickedCallback([=] { - if (_group->value() == ttl) { + if (_group->current() == ttl) { return; } if (!ttl) { @@ -357,7 +357,7 @@ void GlobalTTL::setupContent() { show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{ .show = show, - .startTtl = _group->value(), + .startTtl = _group->current(), .callback = [=](TimeId ttl, Fn) { showSure(ttl, true); }, .hideDisable = true, })); diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index f9d627d3bb..e56122c942 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -1190,7 +1190,7 @@ QPointer Premium::createPinnedToBottom( std::move(buttonText), std::nullopt, [=, options = session->api().premium().subscriptionOptions()] { - const auto value = _radioGroup->value(); + const auto value = _radioGroup->current(); return (value < options.size() && value >= 0) ? options[value].botUrl : QString(); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 5828b2e0ef..5f7cb56b10 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -598,7 +598,7 @@ object_ptr PhoneNumberPrivacyController::setupMiddleWidget( _saveAdditional = [=] { controller->session().api().userPrivacy().save( Api::UserPrivacy::Key::AddedByPhone, - Api::UserPrivacy::Rule{ .option = group->value() }); + Api::UserPrivacy::Rule{ .option = group->current() }); }; return widget; diff --git a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp index e46760ee1a..3d3cb00ef9 100644 --- a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp @@ -1063,7 +1063,7 @@ void AddAccountsRow( }); const auto index = int(state->accounts.size()) - 1; state->accounts[index].checkbox.setChecked( - index == group->value(), + index == group->current(), anim::type::instant); widget->paintRequest( @@ -1303,7 +1303,7 @@ void AddGiftOptions( int nowIndex = 0; Ui::Animations::Simple animation; }; - const auto wasGroupValue = group->value(); + const auto wasGroupValue = group->current(); const auto animation = parent->lifetime().make_state(); animation->nowIndex = wasGroupValue; @@ -1324,7 +1324,7 @@ void AddGiftOptions( const auto &stCheckbox = st::defaultBoxCheckbox; auto radioView = std::make_unique( st::defaultRadio, - (group->hasValue() && group->value() == index)); + (group->hasValue() && group->current() == index)); const auto radioViewRaw = radioView.get(); const auto radio = Ui::CreateChild( row, @@ -1468,7 +1468,7 @@ void AddGiftOptions( row->setClickedCallback([=, duration = st::defaultCheck.duration] { group->setValue(index); - animation->nowIndex = group->value(); + animation->nowIndex = group->current(); animation->animation.stop(); animation->animation.start( [=] { parent->update(); }, diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 1e71863af5..4001edae47 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -498,7 +498,7 @@ bool CloudList::insertTillLimit( void CloudList::insert(int index, const Data::CloudTheme &theme) { const auto id = theme.id; const auto value = groupValueForId(id); - const auto checked = _group->hasValue() && (_group->value() == value); + const auto checked = _group->hasValue() && (_group->current() == value); auto check = std::make_unique(checked); const auto raw = check.get(); auto button = std::make_unique(