diff --git a/Telegram/SourceFiles/api/api_attached_stickers.cpp b/Telegram/SourceFiles/api/api_attached_stickers.cpp index 65cf9efd9..480e9674b 100644 --- a/Telegram/SourceFiles/api/api_attached_stickers.cpp +++ b/Telegram/SourceFiles/api/api_attached_stickers.cpp @@ -36,10 +36,12 @@ void AttachedStickers::request( return; } if (result.v.isEmpty()) { - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + strongController->show( + Box(tr::lng_stickers_not_found(tr::now))); return; } else if (result.v.size() > 1) { - Ui::show(Box(strongController, result)); + strongController->show( + Box(strongController, result)); return; } // Single attached sticker pack. @@ -52,12 +54,15 @@ void AttachedStickers::request( const auto setId = (setData->vid().v && setData->vaccess_hash().v) ? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash()) : MTP_inputStickerSetShortName(setData->vshort_name()); - Ui::show( + strongController->show( Box(strongController, setId), Ui::LayerOption::KeepOther); }).fail([=](const MTP::Error &error) { _requestId = 0; - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + if (const auto strongController = weak.get()) { + strongController->show( + Box(tr::lng_stickers_not_found(tr::now))); + } }).send(); } diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 183864479..facc08489 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -34,7 +34,11 @@ void CheckChatInvite( session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) { Core::App().hideMediaView(); result.match([=](const MTPDchatInvite &data) { - const auto box = Ui::show(Box( + const auto strongController = weak.get(); + if (!strongController) { + return; + } + const auto box = strongController->show(Box( session, data, invitePeekChannel, @@ -80,7 +84,10 @@ void CheckChatInvite( return; } Core::App().hideMediaView(); - Ui::show(Box(tr::lng_group_invite_bad_link(tr::now))); + if (const auto strong = weak.get()) { + strong->show( + Box(tr::lng_group_invite_bad_link(tr::now))); + } }); } diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 3df6df80a..6c8c7946a 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -151,7 +151,7 @@ void BackgroundBox::prepare() { _inner->chooseEvents( ) | rpl::start_with_next([=](const Data::WallPaper &paper) { - Ui::show( + _controller->show( Box(_controller, paper), Ui::LayerOption::KeepOther); }, _inner->lifetime()); @@ -176,7 +176,7 @@ void BackgroundBox::removePaper(const Data::WallPaper &paper) { paper.mtpSettings() )).send(); }; - Ui::show( + _controller->show( Box( tr::lng_background_sure_delete(tr::now), tr::lng_selected_delete(tr::now), diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 3877a9057..a3d667bfb 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -769,23 +769,25 @@ bool BackgroundPreviewBox::Start( const QString &slug, const QMap ¶ms) { if (const auto paper = Data::WallPaper::FromColorSlug(slug)) { - Ui::show(Box( + controller->show(Box( controller, paper->withUrlParams(params))); return true; } if (!IsValidWallPaperSlug(slug)) { - Ui::show(Box(tr::lng_background_bad_link(tr::now))); + controller->show( + Box(tr::lng_background_bad_link(tr::now))); return false; } controller->session().api().requestWallPaper(slug, crl::guard(controller, [=]( const Data::WallPaper &result) { - Ui::show(Box( + controller->show(Box( controller, result.withUrlParams(params))); - }), [](const MTP::Error &error) { - Ui::show(Box(tr::lng_background_bad_link(tr::now))); - }); + }), crl::guard(controller, [=](const MTP::Error &error) { + controller->show( + Box(tr::lng_background_bad_link(tr::now))); + })); return true; } diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index c72618cea..82e37f248 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -1085,7 +1085,7 @@ object_ptr CreatePollBox::setupContent() { send({ .silent = true }); }; const auto sendScheduled = [=] { - Ui::show( + _controller->show( HistoryView::PrepareScheduleBox( this, SendMenu::Type::Scheduled, diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index d6e2a26c7..1102f5fa1 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -165,7 +165,7 @@ void EditPrivacyBox::editExceptions( })); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; - Ui::show( + _window->show( Box(std::move(controller), std::move(initBox)), Ui::LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 182ffcce2..b9a2bcd33 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -201,8 +201,10 @@ void SaveSlowmodeSeconds( void ShowEditPermissions( not_null navigation, not_null peer) { - const auto box = Ui::show( - Box(navigation, peer), + auto content = Box(navigation, peer); + const auto box = QPointer(content.data()); + navigation->parentController()->show( + std::move(content), Ui::LayerOption::KeepOther); const auto saving = box->lifetime().make_state(0); const auto save = [=]( @@ -244,8 +246,10 @@ void ShowEditPermissions( void ShowEditInviteLinks( not_null navigation, not_null peer) { - const auto box = Ui::show( - Box(navigation, peer), + auto content = Box(navigation, peer); + const auto box = QPointer(content.data()); + navigation->parentController()->show( + std::move(content), Ui::LayerOption::KeepOther); const auto saving = box->lifetime().make_state(0); const auto save = [=]( @@ -612,7 +616,7 @@ object_ptr Controller::createStickersEdit() { tr::lng_group_stickers_add(tr::now), st::editPeerInviteLinkButton) )->addClickHandler([=] { - Ui::show( + _navigation->parentController()->show( Box(_navigation->parentController(), channel), Ui::LayerOption::KeepOther); }); @@ -649,7 +653,7 @@ void Controller::showEditPeerTypeBox( _usernameSavedValue = publicLink; refreshHistoryVisibility(); }); - Ui::show( + _navigation->parentController()->show( Box( _peer, _channelHasLocationOriginalValue, @@ -681,7 +685,7 @@ void Controller::showEditLinkedChatBox() { || channel->canEditPreHistoryHidden())); if (const auto chat = *_linkedChatSavedValue) { - *box = Ui::show( + *box = _navigation->parentController()->show( EditLinkedChatBox( _navigation, channel, @@ -709,7 +713,7 @@ void Controller::showEditLinkedChatBox() { for (const auto &item : list) { chats.emplace_back(_peer->owner().processChat(item)); } - *box = Ui::show( + *box = _navigation->parentController()->show( EditLinkedChatBox( _navigation, channel, @@ -858,7 +862,7 @@ void Controller::fillHistoryVisibilityButton() { _historyVisibilitySavedValue = checked; }); const auto buttonCallback = [=] { - Ui::show( + _navigation->parentController()->show( Box( _peer, boxCallback, @@ -1023,9 +1027,15 @@ void Controller::fillManageSection() { wrap->entity(), tr::lng_manage_peer_invite_links(), rpl::duplicate(count) | ToPositiveNumberString(), - [=] { Ui::show( - Box(ManageInviteLinksBox, _peer, _peer->session().user(), 0, 0), - Ui::LayerOption::KeepOther); + [=] { + _navigation->parentController()->show( + Box( + ManageInviteLinksBox, + _peer, + _peer->session().user(), + 0, + 0), + Ui::LayerOption::KeepOther); }, st::infoIconInviteLinks); @@ -1520,7 +1530,7 @@ void Controller::deleteWithConfirmation() { const auto deleteCallback = crl::guard(this, [=] { deleteChannel(); }); - Ui::show( + _navigation->parentController()->show( Box( text, tr::lng_box_delete(tr::now), diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index cc4662345..f5fc45e5e 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1002,7 +1002,7 @@ void SendFilesBox::sendScheduled() { ? SendMenu::Type::ScheduledToUser : _sendMenuType; const auto callback = [=](Api::SendOptions options) { send(options); }; - Ui::show( + _controller->show( HistoryView::PrepareScheduleBox(this, type, callback), Ui::LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 343576326..b9f26c330 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -153,7 +153,7 @@ QPointer StickerSetBox::Show( not_null document) { if (const auto sticker = document->sticker()) { if (sticker->set.type() != mtpc_inputStickerSetEmpty) { - return Ui::show( + return controller->show( Box(controller, sticker->set), Ui::LayerOption::KeepOther).data(); } @@ -324,7 +324,7 @@ StickerSetBox::Inner::Inner( gotSet(result); }).fail([=](const MTP::Error &error) { _loaded = true; - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + controller->show(Box(tr::lng_stickers_not_found(tr::now))); }).send(); _controller->session().api().updateStickers(); @@ -419,7 +419,8 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { }); if (_pack.isEmpty()) { - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + _controller->show( + Box(tr::lng_stickers_not_found(tr::now))); return; } else { int32 rows = _pack.size() / kStickersPanelPerRow + ((_pack.size() % kStickersPanelPerRow) ? 1 : 0); @@ -795,7 +796,7 @@ QString StickerSetBox::Inner::shortName() const { void StickerSetBox::Inner::install() { if (isMasksSet()) { - Ui::show( + _controller->show( Box(tr::lng_stickers_masks_pack(tr::now)), Ui::LayerOption::KeepOther); return; @@ -808,7 +809,8 @@ void StickerSetBox::Inner::install() { )).done([=](const MTPmessages_StickerSetInstallResult &result) { installDone(result); }).fail([=](const MTP::Error &error) { - Ui::show(Box(tr::lng_stickers_not_found(tr::now))); + _controller->show( + Box(tr::lng_stickers_not_found(tr::now))); }).send(); } diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index ad6eccf91..27294ebc8 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -1592,7 +1592,7 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { }(); const auto showSetByRow = [&](const Row &row) { setSelected(SelectedRow()); - Ui::show( + _controller->show( Box(_controller, row.set->mtpInput()), Ui::LayerOption::KeepOther); }; diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index c4bd60eba..4b79a05da 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -357,7 +357,7 @@ base::unique_qptr BoxController::rowContextMenu( auto result = base::make_unique_q(parent); result->addAction(tr::lng_context_delete_selected(tr::now), [=] { - Ui::show( + _window->show( Box(session, base::duplicate(ids)), Ui::LayerOption::KeepOther); }); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index e4d70743f..b9f146da0 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -281,7 +281,7 @@ Fn(controller, text, link, [=]( + controller->show(Box(controller, text, link, [=]( const QString &text, const QString &link) { if (const auto strong = weak.data()) { @@ -321,7 +321,9 @@ void InitSpellchecker( Core::App().settings().spellcheckerEnabledValue(), Spellchecker::SpellingHighlighter::CustomContextMenuItem{ tr::lng_settings_manage_dictionaries(tr::now), - [=] { Ui::show(Box(controller)); } + [=] { + controller->show(Box(controller)); + } }); field->setExtendedContextMenu(s->contextMenuCreated()); #endif // TDESKTOP_DISABLE_SPELLCHECK diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index d7b478995..f40b7605d 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -534,7 +534,7 @@ void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) { updateSelected(); if (_iconOver == SpecialOver::Settings) { - Ui::show(Box( + _pan->controller()->show(Box( _pan->controller(), (hasOnlyFeaturedSets() ? StickersBox::Section::Featured @@ -909,7 +909,7 @@ StickersListWidget::StickersListWidget( setAttribute(Qt::WA_OpaquePaintEvent); _settings->addClickHandler([=] { - Ui::show( + controller->show( Box(controller, StickersBox::Section::Installed)); }); @@ -2185,7 +2185,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { removeSet(sets[button->section].id); } } else if (std::get_if(&pressed)) { - Ui::show(Box(controller(), _megagroupSet)); + controller()->show(Box(controller(), _megagroupSet)); } } } @@ -3005,7 +3005,7 @@ void StickersListWidget::displaySet(uint64 setId) { if (setId == Data::Stickers::MegagroupSetId) { if (_megagroupSet->canEditStickers()) { _displayingSet = true; - checkHideWithBox(Ui::show( + checkHideWithBox(controller()->show( Box(controller(), _megagroupSet), Ui::LayerOption::KeepOther).data()); return; @@ -3019,7 +3019,7 @@ void StickersListWidget::displaySet(uint64 setId) { auto it = sets.find(setId); if (it != sets.cend()) { _displayingSet = true; - checkHideWithBox(Ui::show( + checkHideWithBox(controller()->show( Box(controller(), it->second->mtpInput()), Ui::LayerOption::KeepOther).data()); } @@ -3083,7 +3083,7 @@ void StickersListWidget::removeMegagroupSet(bool locally) { return; } _removingSetId = Data::Stickers::MegagroupSetId; - Ui::show(Box(tr::lng_stickers_remove_group_set(tr::now), crl::guard(this, [this, group = _megagroupSet] { + controller()->show(Box(tr::lng_stickers_remove_group_set(tr::now), crl::guard(this, [this, group = _megagroupSet] { Expects(group->mgInfo != nullptr); if (group->mgInfo->stickerSet.type() != mtpc_inputStickerSetEmpty) { @@ -3105,7 +3105,7 @@ void StickersListWidget::removeSet(uint64 setId) { const auto set = it->second.get(); _removingSetId = set->id; auto text = tr::lng_stickers_remove_pack(tr::now, lt_sticker_pack, set->title); - Ui::show(Box(text, tr::lng_stickers_remove_pack_confirm(tr::now), crl::guard(this, [=] { + controller()->show(Box(text, tr::lng_stickers_remove_pack_confirm(tr::now), crl::guard(this, [=] { Ui::hideLayer(); const auto &sets = session().data().stickers().sets(); const auto it = sets.find(_removingSetId); diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 19094e42d..677ea8a8e 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -68,7 +68,7 @@ bool ShowStickerSet( return false; } Core::App().hideMediaView(); - Ui::show(Box( + controller->show(Box( controller, MTP_inputStickerSetShortName(MTP_string(match->captured(1))))); return true; @@ -368,7 +368,7 @@ bool ResolveSettings( } if (section == qstr("devices")) { controller->session().api().authorizations().reload(); - Ui::show(Box(&controller->session())); + controller->show(Box(&controller->session())); return true; } else if (section == qstr("language")) { ShowLanguagesBox(); @@ -401,12 +401,12 @@ bool HandleUnknown( Core::UpdateApplication(); close(); }; - Ui::show(Box( + controller->show(Box( text, tr::lng_menu_update(tr::now), callback)); } else { - Ui::show(Box(text)); + controller->show(Box(text)); } }); controller->session().api().requestDeepLinkInfo(request, callback); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index d45013a87..30fb4b0b2 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -3192,7 +3192,7 @@ void InnerWidget::setupShortcuts() { }); request->check(Command::ShowContacts) && request->handle([=] { - Ui::show(PrepareContactsBox(_controller)); + _controller->show(PrepareContactsBox(_controller)); return true; }); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 4a95caee1..22f855017 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -478,7 +478,8 @@ void InnerWidget::showFilter(Fn callback) { if (_admins.empty()) { _showFilterCallback = std::move(callback); } else { - Ui::show(Box(_channel, _admins, _filter, std::move(callback))); + _controller->show( + Box(_channel, _admins, _filter, std::move(callback))); } } @@ -1317,7 +1318,8 @@ void InnerWidget::suggestRestrictUser(not_null user) { (*weakBox)->closeBox(); } }); - *weakBox = Ui::show( + *weakBox = QPointer(box.data()); + _controller->show( std::move(box), Ui::LayerOption::KeepOther); }; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index 5206eae06..e86f4b2bb 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -326,7 +326,7 @@ Widget::Widget( connect(_scroll, &Ui::ScrollArea::scrolled, this, [this] { onScroll(); }); _whatIsThis->setClickedCallback([=] { - Ui::show(Box(channel->isMegagroup() + controller->show(Box(channel->isMegagroup() ? tr::lng_admin_log_about_text(tr::now) : tr::lng_admin_log_about_text_channel(tr::now))); }); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index f8b69a155..80a73756d 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -3226,7 +3226,7 @@ void HistoryInner::deleteItem(not_null item) { } } const auto suggestModerateActions = true; - Ui::show(Box(item, suggestModerateActions)); + _controller->show(Box(item, suggestModerateActions)); } bool HistoryInner::hasPendingResizedItems() const { @@ -3240,7 +3240,7 @@ void HistoryInner::deleteAsGroup(FullMsgId itemId) { if (!group) { return deleteItem(item); } - Ui::show(Box( + _controller->show(Box( &session(), session().data().itemsToIds(group->items))); } @@ -3263,7 +3263,7 @@ void HistoryInner::reportAsGroup(FullMsgId itemId) { void HistoryInner::blockSenderItem(FullMsgId itemId) { if (const auto item = session().data().message(itemId)) { - Ui::show(Box( + _controller->show(Box( Window::BlockSenderFromRepliesBox, _controller, itemId)); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ac80baef5..d65668e43 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -627,7 +627,7 @@ HistoryWidget::HistoryWidget( const auto unavailable = _peer->computeUnavailableReason(); if (!unavailable.isEmpty()) { controller->showBackFromStack(); - Ui::show(Box(unavailable)); + controller->show(Box(unavailable)); return; } } @@ -791,7 +791,7 @@ void HistoryWidget::initVoiceRecordBar() { ? Data::RestrictionError(_peer, ChatRestriction::f_send_media) : std::nullopt; if (error) { - Ui::show(Box(*error)); + controller()->show(Box(*error)); return true; } else if (showSlowmodeError()) { return true; @@ -948,7 +948,7 @@ void HistoryWidget::supportShareContact(Support::Contact contact) { contact.lastName, action); }; - const auto box = Ui::show(Box( + const auto box = controller()->show(Box( controller(), _history, contact, @@ -3089,10 +3089,11 @@ void HistoryWidget::saveEditMsg() { if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) { const auto suggestModerateActions = false; - Ui::show(Box(item, suggestModerateActions)); + controller()->show( + Box(item, suggestModerateActions)); return; } else if (!left.text.isEmpty()) { - Ui::show(Box(tr::lng_edit_too_long(tr::now))); + controller()->show(Box(tr::lng_edit_too_long(tr::now))); return; } @@ -3126,14 +3127,16 @@ void HistoryWidget::saveEditMsg() { } const auto &err = error.type(); if (ranges::contains(Api::kDefaultEditMessagesErrors, err)) { - Ui::show(Box(tr::lng_edit_error(tr::now))); + controller()->show( + Box(tr::lng_edit_error(tr::now))); } else if (err == u"MESSAGE_NOT_MODIFIED"_q) { cancelEdit(); } else if (err == u"MESSAGE_EMPTY"_q) { _field->selectAll(); _field->setFocus(); } else { - Ui::show(Box(tr::lng_edit_error(tr::now))); + controller()->show( + Box(tr::lng_edit_error(tr::now))); } update(); })(); @@ -3256,7 +3259,7 @@ void HistoryWidget::sendScheduled() { return; } const auto callback = [=](Api::SendOptions options) { send(options); }; - Ui::show( + controller()->show( HistoryView::PrepareScheduleBox(_list, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -3470,7 +3473,7 @@ void HistoryWidget::checkSuggestToGigagroup() { group->input, MTP_string("convert_to_gigagroup") )).send(); - Ui::show(Box([=](not_null box) { + controller()->show(Box([=](not_null box) { box->setTitle(tr::lng_gigagroup_suggest_title()); box->addRow( object_ptr( @@ -3508,7 +3511,8 @@ void HistoryWidget::unreadMentionsAnimationFinish() { void HistoryWidget::chooseAttach() { if (_editMsgId) { - Ui::show(Box(tr::lng_edit_caption_attach(tr::now))); + controller()->show( + Box(tr::lng_edit_caption_attach(tr::now))); return; } @@ -4335,7 +4339,8 @@ bool HistoryWidget::confirmSendingFiles( return false; } if (_editMsgId) { - Ui::show(Box(tr::lng_edit_caption_attach(tr::now))); + controller()->show( + Box(tr::lng_edit_caption_attach(tr::now))); return false; } @@ -4379,7 +4384,7 @@ bool HistoryWidget::confirmSendingFiles( })); Window::ActivateWindow(controller()); - const auto shown = Ui::show(std::move(box)); + const auto shown = controller()->show(std::move(box)); shown->setCloseByOutsideClick(false); return true; @@ -5330,7 +5335,7 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) { auto errorText = result.result->getErrorOnSend(_history); if (!errorText.isEmpty()) { - Ui::show(Box(errorText)); + controller()->show(Box(errorText)); return; } @@ -5664,7 +5669,9 @@ bool HistoryWidget::sendExistingDocument( ? Data::RestrictionError(_peer, ChatRestriction::f_send_stickers) : std::nullopt; if (error) { - Ui::show(Box(*error), Ui::LayerOption::KeepOther); + controller()->show( + Box(*error), + Ui::LayerOption::KeepOther); return false; } else if (!_peer || !_peer->canWrite()) { return false; @@ -5698,7 +5705,9 @@ bool HistoryWidget::sendExistingPhoto( ? Data::RestrictionError(_peer, ChatRestriction::f_send_media) : std::nullopt; if (error) { - Ui::show(Box(*error), Ui::LayerOption::KeepOther); + controller()->show( + Box(*error), + Ui::LayerOption::KeepOther); return false; } else if (!_peer || !_peer->canWrite()) { return false; @@ -5782,14 +5791,18 @@ void HistoryWidget::replyToMessage(not_null item) { } if (item->history() == _migrated) { if (item->serviceMsg()) { - Ui::show(Box(tr::lng_reply_cant(tr::now))); + controller()->show(Box(tr::lng_reply_cant(tr::now))); } else { const auto itemId = item->fullId(); - Ui::show(Box(tr::lng_reply_cant_forward(tr::now), tr::lng_selected_forward(tr::now), crl::guard(this, [=] { - controller()->content()->setForwardDraft( - _peer->id, - { 1, itemId }); - }))); + controller()->show( + Box( + tr::lng_reply_cant_forward(tr::now), + tr::lng_selected_forward(tr::now), + crl::guard(this, [=] { + controller()->content()->setForwardDraft( + _peer->id, + { 1, itemId }); + }))); } return; } @@ -5832,12 +5845,13 @@ void HistoryWidget::editMessage(FullMsgId itemId) { void HistoryWidget::editMessage(not_null item) { if (_voiceRecordBar->isActive()) { - Ui::show(Box(tr::lng_edit_caption_voice(tr::now))); + controller()->show( + Box(tr::lng_edit_caption_voice(tr::now))); return; } if (const auto media = item->media()) { if (media->allowsEditCaption()) { - Ui::show(Box(controller(), item)); + controller()->show(Box(controller(), item)); return; } } @@ -6283,14 +6297,13 @@ void HistoryWidget::confirmDeleteSelected() { return; } const auto weak = Ui::MakeWeak(this); - const auto box = Ui::show(Box( - &session(), - std::move(items))); + auto box = Box(&session(), std::move(items)); box->setDeleteConfirmedCallback([=] { if (const auto strong = weak.data()) { strong->clearSelected(); } }); + controller()->show(std::move(box)); } void HistoryWidget::escape() { @@ -6303,7 +6316,7 @@ void HistoryWidget::escape() { } else if (_editMsgId) { if (_replyEditMsg && PrepareEditText(_replyEditMsg) != _field->getTextWithTags()) { - Ui::show(Box( + controller()->show(Box( tr::lng_cancel_edit_post_sure(tr::now), tr::lng_cancel_edit_post_yes(tr::now), tr::lng_cancel_edit_post_no(tr::now), diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 96b3131c1..62554d451 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -795,7 +795,8 @@ rpl::producer<> ComposeControls::attachRequests() const { _attachRequests.events() ) | rpl::filter([=] { if (isEditingMessage()) { - Ui::show(Box(tr::lng_edit_caption_attach(tr::now))); + _window->show( + Box(tr::lng_edit_caption_attach(tr::now))); return false; } return true; @@ -1655,7 +1656,7 @@ void ComposeControls::initVoiceRecordBar() { ChatRestriction::f_send_media) : std::nullopt; if (error) { - Ui::show(Box(*error)); + _window->show(Box(*error)); return true; } else if (_showSlowmodeError && _showSlowmodeError()) { return true; @@ -1954,7 +1955,7 @@ void ComposeControls::editMessage(not_null item) { Expects(draftKeyCurrent() != Data::DraftKey::None()); if (_voiceRecordBar->isActive()) { - Ui::show(Box(tr::lng_edit_caption_voice(tr::now))); + _window->show(Box(tr::lng_edit_caption_voice(tr::now))); return; } diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index 3796889c6..1c21b9968 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -1638,7 +1638,7 @@ void VoiceRecordBar::showDiscardBox( callback(); } }; - Ui::show(Box( + _controller->show(Box( (isListenState() ? tr::lng_record_listen_cancel_sure : tr::lng_record_lock_cancel_sure)(tr::now), diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 436028e94..4129a9dad 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -508,7 +508,7 @@ bool AddRescheduleAction( ? HistoryView::DefaultScheduleTime() : itemDate + 600; - const auto box = Ui::show( + const auto box = request.navigation->parentController()->show( HistoryView::PrepareScheduleBox( &request.navigation->session(), sendMenuType, @@ -676,14 +676,15 @@ bool AddDeleteSelectedAction( menu->addAction(tr::lng_context_delete_selected(tr::now), [=] { const auto weak = Ui::MakeWeak(list); auto items = ExtractIdsList(request.selectedItems); - const auto box = Ui::show(Box( + auto box = Box( &request.navigation->session(), - std::move(items))); + std::move(items)); box->setDeleteConfirmedCallback([=] { if (const auto strong = weak.data()) { strong->cancelSelection(); } }); + request.navigation->parentController()->show(std::move(box)); }); return true; } @@ -716,7 +717,7 @@ bool AddDeleteMessageAction( if (const auto item = owner->message(itemId)) { if (asGroup) { if (const auto group = owner->groups().find(item)) { - Ui::show(Box( + controller->show(Box( &owner->session(), owner->itemsToIds(group->items))); return; @@ -729,7 +730,8 @@ bool AddDeleteMessageAction( } } const auto suggestModerateActions = true; - Ui::show(Box(item, suggestModerateActions)); + controller->show( + Box(item, suggestModerateActions)); } }); if (const auto message = item->toHistoryMessage()) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 1bca5aee5..a558c462f 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2826,14 +2826,15 @@ void ConfirmDeleteSelectedItems(not_null widget) { } } const auto weak = Ui::MakeWeak(widget); - const auto box = Ui::show(Box( + auto box = Box( &widget->controller()->session(), - widget->getSelectedIds())); + widget->getSelectedIds()); box->setDeleteConfirmedCallback([=] { if (const auto strong = weak.data()) { strong->cancelSelection(); } }); + widget->controller()->show(std::move(box)); } void ConfirmForwardSelectedItems(not_null widget) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index a925a57d0..6c1be95c1 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -215,7 +215,7 @@ RepliesWidget::RepliesWidget( const auto media = item->media(); if (media && !media->webpage()) { if (media->allowsEditCaption()) { - Ui::show(Box(controller, item)); + controller->show(Box(controller, item)); } } else { _composeControls->editMessage(fullId); @@ -655,7 +655,7 @@ bool RepliesWidget::confirmSendingFiles( insertTextOnCancel)); //ActivateWindow(controller()); - const auto shown = Ui::show(std::move(box)); + const auto shown = controller()->show(std::move(box)); shown->setCloseByOutsideClick(false); return true; @@ -945,13 +945,13 @@ void RepliesWidget::edit( if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) { if (item) { - Ui::show(Box(item, false)); + controller()->show(Box(item, false)); } else { doSetInnerFocus(); } return; } else if (!left.text.isEmpty()) { - Ui::show(Box(tr::lng_edit_too_long(tr::now))); + controller()->show(Box(tr::lng_edit_too_long(tr::now))); return; } @@ -976,13 +976,13 @@ void RepliesWidget::edit( const auto &err = error.type(); if (ranges::contains(Api::kDefaultEditMessagesErrors, err)) { - Ui::show(Box(tr::lng_edit_error(tr::now))); + controller()->show(Box(tr::lng_edit_error(tr::now))); } else if (err == u"MESSAGE_NOT_MODIFIED"_q) { _composeControls->cancelEditMessage(); } else if (err == u"MESSAGE_EMPTY"_q) { doSetInnerFocus(); } else { - Ui::show(Box(tr::lng_edit_error(tr::now))); + controller()->show(Box(tr::lng_edit_error(tr::now))); } update(); return true; @@ -1018,7 +1018,9 @@ bool RepliesWidget::sendExistingDocument( _history->peer, ChatRestriction::f_send_stickers); if (error) { - Ui::show(Box(*error), Ui::LayerOption::KeepOther); + controller()->show( + Box(*error), + Ui::LayerOption::KeepOther); return false; } else if (showSlowmodeError()) { return false; @@ -1052,7 +1054,9 @@ bool RepliesWidget::sendExistingPhoto( _history->peer, ChatRestriction::f_send_media); if (error) { - Ui::show(Box(*error), Ui::LayerOption::KeepOther); + controller()->show( + Box(*error), + Ui::LayerOption::KeepOther); return false; } else if (showSlowmodeError()) { return false; @@ -1073,7 +1077,7 @@ void RepliesWidget::sendInlineResult( not_null bot) { const auto errorText = result->getErrorOnSend(_history); if (!errorText.isEmpty()) { - Ui::show(Box(errorText)); + controller()->show(Box(errorText)); return; } sendInlineResult(result, bot, Api::SendOptions()); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index b9556fc20..ea8579d9b 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -148,7 +148,7 @@ ScheduledWidget::ScheduledWidget( const auto media = item->media(); if (media && !media->webpage()) { if (media->allowsEditCaption()) { - Ui::show(Box(controller, item)); + controller->show(Box(controller, item)); } } else { _composeControls->editMessage(fullId); @@ -384,7 +384,7 @@ bool ScheduledWidget::confirmSendingFiles( insertTextOnCancel)); //ActivateWindow(controller()); - const auto shown = Ui::show(std::move(box)); + const auto shown = controller()->show(std::move(box)); shown->setCloseByOutsideClick(false); return true; @@ -454,7 +454,7 @@ void ScheduledWidget::uploadFile( action.options = options; session().api().sendFile(fileContent, type, action); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -499,7 +499,7 @@ void ScheduledWidget::send() { return; } const auto callback = [=](Api::SendOptions options) { send(options); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -544,7 +544,7 @@ void ScheduledWidget::sendVoice( const auto callback = [=](Api::SendOptions options) { sendVoice(bytes, waveform, duration, options); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -579,13 +579,13 @@ void ScheduledWidget::edit( if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) { if (item) { - Ui::show(Box(item, false)); + controller()->show(Box(item, false)); } else { _composeControls->focus(); } return; } else if (!left.text.isEmpty()) { - Ui::show(Box(tr::lng_edit_too_long(tr::now))); + controller()->show(Box(tr::lng_edit_too_long(tr::now))); return; } @@ -610,13 +610,13 @@ void ScheduledWidget::edit( const auto &err = error.type(); if (ranges::contains(Api::kDefaultEditMessagesErrors, err)) { - Ui::show(Box(tr::lng_edit_error(tr::now))); + controller()->show(Box(tr::lng_edit_error(tr::now))); } else if (err == u"MESSAGE_NOT_MODIFIED"_q) { _composeControls->cancelEditMessage(); } else if (err == u"MESSAGE_EMPTY"_q) { _composeControls->focus(); } else { - Ui::show(Box(tr::lng_edit_error(tr::now))); + controller()->show(Box(tr::lng_edit_error(tr::now))); } update(); return true; @@ -638,7 +638,7 @@ void ScheduledWidget::sendExistingDocument( const auto callback = [=](Api::SendOptions options) { sendExistingDocument(document, options); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -650,7 +650,9 @@ bool ScheduledWidget::sendExistingDocument( _history->peer, ChatRestriction::f_send_stickers); if (error) { - Ui::show(Box(*error), Ui::LayerOption::KeepOther); + controller()->show( + Box(*error), + Ui::LayerOption::KeepOther); return false; } @@ -668,7 +670,7 @@ void ScheduledWidget::sendExistingPhoto(not_null photo) { const auto callback = [=](Api::SendOptions options) { sendExistingPhoto(photo, options); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -680,7 +682,9 @@ bool ScheduledWidget::sendExistingPhoto( _history->peer, ChatRestriction::f_send_media); if (error) { - Ui::show(Box(*error), Ui::LayerOption::KeepOther); + controller()->show( + Box(*error), + Ui::LayerOption::KeepOther); return false; } @@ -699,13 +703,13 @@ void ScheduledWidget::sendInlineResult( not_null bot) { const auto errorText = result->getErrorOnSend(_history); if (!errorText.isEmpty()) { - Ui::show(Box(errorText)); + controller()->show(Box(errorText)); return; } const auto callback = [=](Api::SendOptions options) { sendInlineResult(result, bot, options); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } @@ -1174,7 +1178,7 @@ void ScheduledWidget::listSendBotCommand( message.action.options = options; session().api().sendMessage(std::move(message)); }; - Ui::show( + controller()->show( PrepareScheduleBox(this, sendMenuType(), callback), Ui::LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index c57955372..0cf05d4ba 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -540,14 +540,15 @@ void TopBar::performDelete() { if (items.empty()) { _cancelSelectionClicks.fire({}); } else { - const auto box = Ui::show(Box( + auto box = Box( &_navigation->session(), - std::move(items))); + std::move(items)); box->setDeleteConfirmedCallback([weak = Ui::MakeWeak(this)] { if (weak) { weak->_cancelSelectionClicks.fire({}); } }); + _navigation->parentController()->show(std::move(box)); } } diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index e6d1e66a2..b9e2ca803 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -1154,7 +1154,8 @@ void MainWindow::createGlobalMenu() { return; } - Ui::show(PrepareContactsBox(sessionController())); + sessionController()->show( + PrepareContactsBox(sessionController())); })); psAddContact = tools->addAction( diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 950caed80..f89168bcc 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -723,7 +723,7 @@ void MainWindow::createGlobalMenu() { if (!sessionController()) { return; } - Ui::show(PrepareContactsBox(sessionController())); + sessionController()->show(PrepareContactsBox(sessionController())); })); { auto callback = [=] { diff --git a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm index aa4dcd2f9..483b513e2 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm @@ -464,7 +464,7 @@ void AppendEmojiPacks( auto callback = [=] { if (document) { if (const auto error = RestrictionToSendStickers(_controller)) { - Ui::show(Box(*error)); + _controller->show(Box(*error)); return true; } Api::SendExistingDocument( diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 3bf3d6363..a8434963f 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_window_title.h" #include "base/platform/base_platform_info.h" +#include "window/window_controller.h" #include "window/window_session_controller.h" #include "lang/lang_keys.h" #include "core/update_checker.h" @@ -45,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { void SetupConnectionType( + not_null controller, not_null account, not_null container) { const auto connectionType = [=] { @@ -69,7 +71,7 @@ void SetupConnectionType( ) | rpl::map(connectionType), st::settingsButton); button->addClickHandler([=] { - Ui::show(ProxiesBoxController::CreateOwningBox(account)); + controller->show(ProxiesBoxController::CreateOwningBox(account)); }); } @@ -304,7 +306,7 @@ void SetupSpellchecker( Spellchecker::ButtonManageDictsState(session), st::settingsButton )->addClickHandler([=] { - Ui::show(Box(controller)); + controller->show(Box(controller)); }); button->toggledValue( @@ -450,7 +452,7 @@ void SetupSystemIntegrationContent( }) | rpl::start_with_next([=](bool checked) { if (controller->session().domain().local().hasLocalPasscode()) { minimized->entity()->setChecked(false); - Ui::show(Box( + controller->show(Box( tr::lng_error_start_minimized_passcoded(tr::now))); } else { cSetStartMinimized(checked); @@ -510,7 +512,9 @@ void SetupAnimations(not_null container) { }, container->lifetime()); } -void SetupOpenGL(not_null container) { +void SetupOpenGL( + not_null controller, + not_null container) { const auto toggles = container->lifetime().make_state< rpl::event_stream >(); @@ -534,7 +538,7 @@ void SetupOpenGL(not_null container) { const auto cancelled = crl::guard(button, [=] { toggles->fire(!enabled); }); - Ui::show(Box( + controller->show(Box( tr::lng_settings_need_restart(tr::now), tr::lng_settings_restart_now(tr::now), confirmed, @@ -547,7 +551,7 @@ void SetupPerformance( not_null container) { SetupAnimations(container); if (!Platform::IsMac()) { - SetupOpenGL(container); + SetupOpenGL(controller, container); } } @@ -606,7 +610,10 @@ void Advanced::setupContent(not_null controller) { addDivider(); AddSkip(content); AddSubsectionTitle(content, tr::lng_settings_network_proxy()); - SetupConnectionType(&controller->session().account(), content); + SetupConnectionType( + &controller->window(), + &controller->session().account(), + content); AddSkip(content); SetupDataStorage(controller, content); SetupAutoDownload(controller, content); diff --git a/Telegram/SourceFiles/settings/settings_advanced.h b/Telegram/SourceFiles/settings/settings_advanced.h index a763263a4..60924f9d3 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.h +++ b/Telegram/SourceFiles/settings/settings_advanced.h @@ -13,9 +13,14 @@ namespace Main { class Account; } // namespace Main +namespace Window { +class Controller; +} // namespace Window + namespace Settings { void SetupConnectionType( + not_null controller, not_null account, not_null container); bool HasUpdate(); diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index fe7220728..f4c0d03a2 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -125,7 +125,7 @@ void Calls::setupContent() { call->setCurrentVideoDevice(deviceId); } }); - Ui::show(Box([=](not_null box) { + _controller->show(Box([=](not_null box) { SingleChoiceBox(box, { .title = tr::lng_settings_call_camera(), .options = options, @@ -200,7 +200,7 @@ void Calls::setupContent() { ), st::settingsButton )->addClickHandler([=] { - Ui::show(ChooseAudioOutputBox(crl::guard(this, [=]( + _controller->show(ChooseAudioOutputBox(crl::guard(this, [=]( const QString &id, const QString &name) { _outputNameStream.fire_copy(name); @@ -221,7 +221,7 @@ void Calls::setupContent() { ), st::settingsButton )->addClickHandler([=] { - Ui::show(ChooseAudioInputBox(crl::guard(this, [=]( + _controller->show(ChooseAudioInputBox(crl::guard(this, [=]( const QString &id, const QString &name) { _inputNameStream.fire_copy(name); @@ -268,11 +268,12 @@ void Calls::setupContent() { content, tr::lng_settings_call_open_system_prefs(), st::settingsButton - )->addClickHandler([] { + )->addClickHandler([=] { const auto opened = Platform::OpenSystemSettings( Platform::SystemSettingsType::Audio); if (!opened) { - Ui::show(Box(tr::lng_linux_no_audio_prefs(tr::now))); + _controller->show( + Box(tr::lng_linux_no_audio_prefs(tr::now))); } }); @@ -304,7 +305,7 @@ void Calls::requestPermissionAndStartTestingMicrophone() { Platform::PermissionType::Microphone); Ui::hideLayer(); }; - Ui::show(Box( + _controller->show(Box( tr::lng_no_mic_permission(tr::now), tr::lng_menu_settings(tr::now), showSystemSettings)); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 7cad61674..8550d3240 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -416,7 +416,7 @@ BackgroundRow::BackgroundRow( updateImage(); _chooseFromGallery->addClickHandler([=] { - Ui::show(Box(controller)); + controller->show(Box(controller)); }); _chooseFromFile->addClickHandler([=] { ChooseFromFile(controller, this); @@ -635,7 +635,7 @@ void ChooseFromFile( auto local = Data::CustomWallPaper(); local.setLocalImageAsThumbnail(std::make_shared( std::move(image))); - Ui::show(Box(controller, local)); + controller->show(Box(controller, local)); }); FileDialog::GetOpenPath( parent.get(), @@ -725,7 +725,7 @@ void SetupStickersEmoji( &st::settingsIconStickers, st::settingsChatIconLeft )->addClickHandler([=] { - Ui::show( + controller->show( Box(controller, StickersBox::Section::Installed)); }); @@ -736,7 +736,7 @@ void SetupStickersEmoji( &st::settingsIconEmoji, st::settingsChatIconLeft )->addClickHandler([=] { - Ui::show(Box(session)); + controller->show(Box(session)); }); AddSkip(container, st::settingsCheckboxesSkip); @@ -862,7 +862,7 @@ void SetupDataStorage( st::settingsButton, tr::lng_download_path()); path->entity()->addClickHandler([=] { - Ui::show(Box(controller)); + controller->show(Box(controller)); }); path->toggleOn(ask->toggledValue() | rpl::map(!_1)); #endif // OS_WIN_STORE @@ -901,7 +901,8 @@ void SetupAutoDownload( std::move(label), st::settingsButton )->addClickHandler([=] { - Ui::show(Box(&controller->session(), source)); + controller->show( + Box(&controller->session(), source)); }); }; add(tr::lng_media_auto_in_private(), Source::User); @@ -1142,7 +1143,7 @@ void SetupDefaultThemes( // in Window::Theme::Revert which is called by Editor. // // So we check here, before we change the saved accent color. - Ui::show(Box( + window->show(Box( tr::lng_theme_editor_cant_change_theme(tr::now))); return; } @@ -1269,7 +1270,9 @@ void SetupCloudThemes( wrap->setDuration(0)->toggleOn(list->empty() | rpl::map(!_1)); } -void SetupAutoNightMode(not_null container) { +void SetupAutoNightMode( + not_null controller, + not_null container) { if (!Platform::IsDarkModeSupported()) { return; } @@ -1294,7 +1297,7 @@ void SetupAutoNightMode(not_null container) { }) | rpl::start_with_next([=](bool checked) { if (checked && Window::Theme::Background()->editingTheme()) { autoNight->setChecked(false); - Ui::show(Box( + controller->show(Box( tr::lng_theme_editor_cant_change_theme(tr::now))); } else { Core::App().settings().setSystemDarkModeEnabled(checked); @@ -1451,7 +1454,7 @@ void Chat::setupContent(not_null controller) { const auto content = Ui::CreateChild(this); SetupThemeOptions(controller, content); - SetupAutoNightMode(content); + SetupAutoNightMode(controller, content); SetupCloudThemes(controller, content); SetupChatBackground(controller, content); SetupStickersEmoji(controller, content); diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index a35832df8..1822c6353 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -75,18 +75,20 @@ void SetupPhoto( if (image.isNull() || image.width() > 10 * image.height() || image.height() > 10 * image.width()) { - Ui::show(Box(tr::lng_bad_photo(tr::now))); + controller->show(Box(tr::lng_bad_photo(tr::now))); return; } - const auto box = Ui::show( - Box(image, tr::lng_settings_crop_profile(tr::now))); + auto box = Box( + image, + tr::lng_settings_crop_profile(tr::now)); box->ready( ) | rpl::start_with_next([=](QImage &&image) { self->session().api().uploadPeerPhoto( self, std::move(image)); }, box->lifetime()); + controller->show(std::move(box)); }; FileDialog::GetOpenPath( upload, @@ -219,6 +221,7 @@ void AddRow( void SetupRows( not_null container, + not_null controller, not_null self) { const auto session = &self->session(); @@ -229,7 +232,7 @@ void SetupRows( tr::lng_settings_name_label(), Info::Profile::NameValue(self), tr::lng_profile_copy_fullname(tr::now), - [=] { Ui::show(Box(self)); }, + [=] { controller->show(Box(self)); }, st::settingsInfoName); AddRow( @@ -237,7 +240,7 @@ void SetupRows( tr::lng_settings_phone_label(), Info::Profile::PhoneValue(self), tr::lng_profile_copy_phone(tr::now), - [=] { Ui::show(Box(session)); }, + [=] { controller->show(Box(session)); }, st::settingsInfoPhone); auto username = Info::Profile::UsernameValue(self); @@ -272,7 +275,7 @@ void SetupRows( std::move(label), std::move(value), tr::lng_context_copy_mention(tr::now), - [=] { Ui::show(Box(session)); }, + [=] { controller->show(Box(session)); }, st::settingsInfoUsername); AddSkip(container, st::settingsInfoAfterSkip); @@ -439,7 +442,7 @@ void Information::setupContent( const auto self = controller->session().user(); SetupPhoto(content, controller, self); - SetupRows(content, self); + SetupRows(content, controller, self); SetupBio(content, self); //auto manager = SetupBio(content, self); //_canSaveChanges = std::move(manager.canSave); diff --git a/Telegram/SourceFiles/settings/settings_intro.cpp b/Telegram/SourceFiles/settings/settings_intro.cpp index a3727937d..0dba3c777 100644 --- a/Telegram/SourceFiles/settings/settings_intro.cpp +++ b/Telegram/SourceFiles/settings/settings_intro.cpp @@ -65,7 +65,7 @@ object_ptr CreateIntroSettings( AddDivider(result); AddSkip(result); SetupLanguageButton(result, false); - SetupConnectionType(&window->account(), result); + SetupConnectionType(window, &window->account(), result); AddSkip(result); if (HasUpdate()) { AddDivider(result); @@ -89,7 +89,7 @@ object_ptr CreateIntroSettings( } AddDivider(result); AddSkip(result); - SetupInterfaceScale(result, false); + SetupInterfaceScale(window, result, false); SetupDefaultThemes(window, result); AddSkip(result); diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index f2e77d1f1..191e6c200 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "api/api_sensitive_content.h" #include "api/api_global_privacy.h" +#include "window/window_controller.h" #include "window/window_session_controller.h" #include "core/click_handler_types.h" #include "base/call_delayed.h" @@ -167,6 +168,7 @@ bool HasInterfaceScale() { } void SetupInterfaceScale( + not_null window, not_null container, bool icon) { if (!HasInterfaceScale()) { @@ -234,7 +236,7 @@ void SetupInterfaceScale( button, [=] { repeatSetScale(cConfigScale(), repeatSetScale); }); }); - Ui::show(Box( + window->show(Box( tr::lng_settings_need_restart(tr::now), tr::lng_settings_restart_now(tr::now), confirmed, @@ -332,7 +334,7 @@ void SetupHelp( sure, OpenFaq); box->setStrictCancel(true); - Ui::show(std::move(box)); + controller->show(std::move(box)); }); AddSkip(container); @@ -368,7 +370,7 @@ void Main::setupContent(not_null controller) { if (HasInterfaceScale()) { AddDivider(content); AddSkip(content); - SetupInterfaceScale(content); + SetupInterfaceScale(&controller->window(), content); AddSkip(content); } SetupHelp(controller, content); diff --git a/Telegram/SourceFiles/settings/settings_main.h b/Telegram/SourceFiles/settings/settings_main.h index 5a68bd197..c90f8bf8c 100644 --- a/Telegram/SourceFiles/settings/settings_main.h +++ b/Telegram/SourceFiles/settings/settings_main.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" namespace Window { +class Controller; class SessionController; } // namespace Window @@ -24,6 +25,7 @@ void SetupLanguageButton( bool icon = true); bool HasInterfaceScale(); void SetupInterfaceScale( + not_null window, not_null container, bool icon = true); void SetupFaq( diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 8bd864fe4..1b7a25efa 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -304,7 +304,7 @@ void BlockedBoxController::BlockNewPeer( }); box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); }; - Ui::show( + window->show( Box(std::move(controller), std::move(initBox)), Ui::LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index b5f0d5bb7..9339a7958 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -140,7 +140,7 @@ void SetupPrivacy( BlockedBoxController::BlockNewPeer(controller); }); }; - Ui::show(Box( + controller->show(Box( std::make_unique(controller), initBox)); }); @@ -271,7 +271,7 @@ void SetupLocalPasscode( std::move(text), st::settingsButton) )->addClickHandler([=] { - Ui::show(Box(&controller->session(), false)); + controller->show(Box(&controller->session(), false)); }); const auto wrap = container->add( @@ -285,7 +285,7 @@ void SetupLocalPasscode( tr::lng_settings_passcode_disable(), st::settingsButton) )->addClickHandler([=] { - Ui::show(Box(&controller->session(), true)); + controller->show(Box(&controller->session(), true)); }); const auto autoLockBoxClosing = @@ -314,7 +314,8 @@ void SetupLocalPasscode( std::move(value), st::settingsButton )->addClickHandler([=] { - const auto box = Ui::show(Box(&controller->session())); + const auto box = controller->show( + Box(&controller->session())); box->boxClosing( ) | rpl::start_to_stream(*autoLockBoxClosing, box->lifetime()); }); @@ -409,9 +410,9 @@ void SetupCloudPassword( ))->setDuration(0); change->entity()->addClickHandler([=] { if (CheckEditCloudPassword(session)) { - Ui::show(EditCloudPasswordBox(session)); + controller->show(EditCloudPasswordBox(session)); } else { - Ui::show(CloudPasswordAppOutdatedBox()); + controller->show(CloudPasswordAppOutdatedBox()); } }); @@ -448,14 +449,14 @@ void SetupCloudPassword( session->api().clearUnconfirmedPassword(); }, validation.box->lifetime()); - Ui::show(std::move(validation.box)); + controller->show(std::move(validation.box)); }); const auto remove = [=] { if (CheckEditCloudPassword(session)) { - RemoveCloudPassword(session); + RemoveCloudPassword(controller); } else { - Ui::show(CloudPasswordAppOutdatedBox()); + controller->show(CloudPasswordAppOutdatedBox()); } }; const auto disable = container->add( @@ -569,7 +570,7 @@ void SetupSelfDestruction( label(), st::settingsButton )->addClickHandler([=] { - Ui::show(Box( + controller->show(Box( session, session->api().selfDestruct().days())); }); @@ -648,7 +649,7 @@ void SetupBotsAndWebsites( tr::lng_settings_clear_payment_info(), st::settingsButton )->addClickHandler([=] { - Ui::show(ClearPaymentInfoBox(session)); + controller->show(ClearPaymentInfoBox(session)); }); AddSkip(container); @@ -678,7 +679,7 @@ void SetupSessionsList( std::move(count), st::settingsButton )->addClickHandler([=] { - Ui::show(Box(&controller->session())); + controller->show(Box(&controller->session())); }); AddSkip(container, st::settingsPrivacySecurityPadding); AddDividerText(container, tr::lng_settings_sessions_about()); @@ -734,7 +735,8 @@ object_ptr EditCloudPasswordBox(not_null session return result; } -void RemoveCloudPassword(not_null<::Main::Session*> session) { +void RemoveCloudPassword(not_null controller) { + const auto session = &controller->session(); const auto current = session->api().passwordStateCurrent(); Assert(current.has_value()); @@ -744,7 +746,7 @@ void RemoveCloudPassword(not_null<::Main::Session*> session) { } auto fields = PasscodeBox::CloudFields::From(*current); fields.turningOff = true; - const auto box = Ui::show(Box(session, fields)); + auto box = Box(session, fields); rpl::merge( box->newPasswordSet() | rpl::to_empty, @@ -757,6 +759,8 @@ void RemoveCloudPassword(not_null<::Main::Session*> session) { ) | rpl::start_with_next([=] { session->api().clearUnconfirmedPassword(); }, box->lifetime()); + + controller->show(std::move(box)); } object_ptr CloudPasswordAppOutdatedBox() { @@ -789,7 +793,7 @@ void AddPrivacyButton( ) | rpl::take( 1 ) | rpl::start_with_next([=](const Privacy &value) { - Ui::show( + controller->show( Box(controller, controllerFactory(), value), Ui::LayerOption::KeepOther); }); diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.h b/Telegram/SourceFiles/settings/settings_privacy_security.h index 09ea6361b..aef85d7c5 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.h +++ b/Telegram/SourceFiles/settings/settings_privacy_security.h @@ -23,7 +23,7 @@ int ExceptionUsersCount(const std::vector> &exceptions); bool CheckEditCloudPassword(not_null<::Main::Session*> session); object_ptr EditCloudPasswordBox( not_null<::Main::Session*> session); -void RemoveCloudPassword(not_null<::Main::Session*> session); +void RemoveCloudPassword(not_null session); object_ptr CloudPasswordAppOutdatedBox(); void AddPrivacyButton( diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index c20ee9ea7..b59288418 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -507,7 +507,7 @@ void Helper::showEditInfoBox( TextUtilities::ConvertTextTagsToEntities(result.tags) }, done); }; - Ui::show( + controller->show( Box(controller, editData, save), Ui::LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index 59a7a5ddf..fc3c2711e 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -665,8 +665,8 @@ Editor::Editor( this, [=] { save(); })); - _inner->setErrorCallback([this] { - Ui::show(Box(tr::lng_theme_editor_error(tr::now))); + _inner->setErrorCallback([=] { + window->show(Box(tr::lng_theme_editor_error(tr::now))); // This could be from inner->_context observable notification. // We should not destroy it while iterating in subscribers. @@ -748,12 +748,14 @@ void Editor::exportTheme() { QFile f(path); if (!f.open(QIODevice::WriteOnly)) { LOG(("Theme Error: could not open zip-ed theme file '%1' for writing").arg(path)); - Ui::show(Box(tr::lng_theme_editor_error(tr::now))); + _window->show( + Box(tr::lng_theme_editor_error(tr::now))); return; } if (f.write(result) != result.size()) { LOG(("Theme Error: could not write zip-ed theme to file '%1'").arg(path)); - Ui::show(Box(tr::lng_theme_editor_error(tr::now))); + _window->show( + Box(tr::lng_theme_editor_error(tr::now))); return; } Ui::Toast::Show(tr::lng_theme_editor_done(tr::now)); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index ffd15956d..81a21798b 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -126,7 +126,7 @@ void Controller::checkLockByTerms() { return; } Ui::hideSettingsAndLayer(anim::type::instant); - const auto box = Ui::show(Box( + const auto box = show(Box( *data, tr::lng_terms_agree(), tr::lng_terms_decline())); @@ -161,7 +161,7 @@ void Controller::checkLockByTerms() { } void Controller::showTermsDecline() { - const auto box = Ui::show( + const auto box = show( Box( TextWithEntities{ tr::lng_terms_update_sorry(tr::now) }, tr::lng_terms_decline_and_delete(), @@ -193,7 +193,7 @@ void Controller::showTermsDelete() { Ui::hideLayer(); } }; - Ui::show( + show( Box( tr::lng_terms_delete_warning(tr::now), tr::lng_terms_delete_now(tr::now), diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 9325c77aa..0720d1f56 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -131,7 +131,7 @@ void ShowCallsBox(not_null window) { return true; }); }; - Ui::show(Box(std::move(controller), initBox)); + window->show(Box(std::move(controller), initBox)); } } // namespace @@ -617,7 +617,11 @@ MainMenu::MainMenu( _telegram->setLinksTrusted(); _version->setRichText(textcmdLink(1, tr::lng_settings_current_version(tr::now, lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, tr::lng_menu_about(tr::now))); _version->setLink(1, std::make_shared(Core::App().changelogLink())); - _version->setLink(2, std::make_shared([] { Ui::show(Box()); })); + _version->setLink( + 2, + std::make_shared([=] { + controller->show(Box()); + })); _controller->session().downloaderTaskFinished( ) | rpl::start_with_next([=] { @@ -903,7 +907,7 @@ void MainMenu::refreshMenu() { controller->showNewChannel(); }, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver); _menu->addAction(tr::lng_menu_contacts(tr::now), [=] { - Ui::show(PrepareContactsBox(controller)); + controller->show(PrepareContactsBox(controller)); }, &st::mainMenuContacts, &st::mainMenuContactsOver); if (_controller->session().serverConfig().phoneCallsEnabled.current()) { _menu->addAction(tr::lng_menu_calls(tr::now), [=] { @@ -938,7 +942,7 @@ void MainMenu::refreshMenu() { auto nightCallback = [=] { if (Window::Theme::Background()->editingTheme()) { - Ui::show(Box( + controller->show(Box( tr::lng_theme_editor_cant_change_theme(tr::now))); return; } diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index aace39cad..239db221f 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -141,7 +141,7 @@ void SessionNavigation::resolveUsername( }).fail([=](const MTP::Error &error) { _resolveRequestId = 0; if (error.code() == 400) { - Ui::show(Box( + show(Box( tr::lng_username_not_found(tr::now, lt_user, username))); } }).send(); @@ -471,7 +471,7 @@ SessionController::SessionController( ) | rpl::start_with_next([=](PeerData *peer) { if (peer == _showEditPeer) { _showEditPeer = nullptr; - Ui::show(Box(this, peer)); + show(Box(this, peer)); } }, lifetime()); @@ -993,7 +993,7 @@ void SessionController::startOrJoinGroupCall( GroupCallJoinConfirm confirm) { auto &calls = Core::App().calls(); const auto askConfirmation = [&](QString text, QString button) { - Ui::show(Box(text, button, crl::guard(this, [=] { + show(Box(text, button, crl::guard(this, [=] { Ui::hideLayer(); startOrJoinGroupCall(peer, joinHash, GroupCallJoinConfirm::None); }))); @@ -1095,7 +1095,7 @@ void SessionController::showJumpToDate(Dialogs::Key chat, QDate requestedDate) { box->setMinDate(minPeerDate(chat)); box->setMaxDate(maxPeerDate(chat)); box->setBeginningButton(true); - Ui::show(std::move(box)); + show(std::move(box)); } void SessionController::showPassportForm(const Passport::FormRequest &request) { @@ -1210,6 +1210,13 @@ Window::Adaptive &SessionController::adaptive() const { return _window->adaptive(); } +QPointer SessionController::show( + object_ptr content, + Ui::LayerOptions options, + anim::type animated) { + return _window->show(std::move(content), options, animated); +} + SessionController::~SessionController() = default; } // namespace Window diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index f4f21ea97..7955e1cf0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "dialogs/dialogs_key.h" #include "ui/effects/animation_value.h" +#include "ui/layers/layer_widget.h" #include "window/window_adaptive.h" class PhotoData; @@ -250,6 +251,11 @@ public: return _selectingPeer; } + QPointer show( + object_ptr content, + Ui::LayerOptions options = Ui::LayerOption::KeepOther, + anim::type animated = anim::type::normal); + [[nodiscard]] auto tabbedSelector() const -> not_null; void takeTabbedSelectorOwnershipFrom(not_null parent);