From b4af8055210edca5de2e352db2dca038ed6ea63d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 3 Feb 2021 05:49:26 +0300 Subject: [PATCH] Moved showLogoutConfirmation from MainWindow to Window::Controller. --- Telegram/SourceFiles/mainwindow.cpp | 33 ------------------- Telegram/SourceFiles/mainwindow.h | 2 -- .../platform/linux/main_window_linux.cpp | 11 ++++--- .../platform/mac/main_window_mac.mm | 14 +++++--- .../SourceFiles/settings/settings_common.cpp | 2 +- .../SourceFiles/window/window_controller.cpp | 30 +++++++++++++++++ .../SourceFiles/window/window_controller.h | 2 ++ .../window/window_lock_widgets.cpp | 2 +- 8 files changed, 51 insertions(+), 45 deletions(-) diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 743fa3fd0..318f43e95 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -670,39 +670,6 @@ void MainWindow::updateTrayMenu(bool force) { psTrayMenuUpdated(); } -void MainWindow::showLogoutConfirmation() { - if (isHidden()) { - showFromTray(); - } - - const auto account = Core::App().passcodeLocked() - ? nullptr - : sessionController() - ? &sessionController()->session().account() - : nullptr; - const auto weak = base::make_weak(account); - const auto callback = [=] { - if (account && !weak) { - return; - } - if (account - && account->sessionExists() - && Core::App().exportManager().inProgress(&account->session())) { - Ui::hideLayer(); - Core::App().exportManager().stopWithConfirmation([=] { - Core::App().logout(account); - }); - } else { - Core::App().logout(account); - } - }; - Ui::show(Box( - tr::lng_sure_logout(tr::now), - tr::lng_settings_logout(tr::now), - st::attentionBoxButton, - callback)); -} - bool MainWindow::takeThirdSectionFromLayer() { return _layer ? _layer->takeToThirdSection() : false; } diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index f2a952528..f47d01689 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -103,8 +103,6 @@ public: not_null photo); void hideMediaPreview(); - void showLogoutConfirmation(); - void updateControlsGeometry() override; protected: diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 8c022e7d7..3247ca4e1 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -942,10 +942,13 @@ void MainWindow::createGlobalMenu() { auto file = psMainMenu->addMenu(tr::lng_mac_menu_file(tr::now)); - psLogout = file->addAction(tr::lng_mac_menu_logout(tr::now)); - connect(psLogout, &QAction::triggered, psLogout, [] { - if (App::wnd()) App::wnd()->showLogoutConfirmation(); - }); + psLogout = file->addAction( + tr::lng_mac_menu_logout(tr::now), + this, + [=] { + ensureWindowShown(); + controller().showLogoutConfirmation(); + }); auto quit = file->addAction( tr::lng_mac_menu_quit_telegram(tr::now, lt_telegram, qsl("Telegram")), diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 37b2e7ef8..77fb8de4a 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -713,10 +713,16 @@ void MainWindow::createGlobalMenu() { } QMenu *file = psMainMenu.addMenu(tr::lng_mac_menu_file(tr::now)); - psLogout = file->addAction(tr::lng_mac_menu_logout(tr::now)); - connect(psLogout, &QAction::triggered, psLogout, [] { - if (App::wnd()) App::wnd()->showLogoutConfirmation(); - }); + { + auto callback = [=] { + ensureWindowShown(); + controller().showLogoutConfirmation(); + }; + psLogout = file->addAction( + tr::lng_mac_menu_logout(tr::now), + this, + std::move(callback)); + } QMenu *edit = psMainMenu.addMenu(tr::lng_mac_menu_edit(tr::now)); psUndo = edit->addAction(tr::lng_mac_menu_undo(tr::now), this, SLOT(psMacUndo()), QKeySequence::Undo); diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index 43951b443..f94456ee6 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -210,7 +210,7 @@ void FillMenu( } addAction( tr::lng_settings_logout(tr::now), - [=] { window->widget()->showLogoutConfirmation(); }); + [=] { window->showLogoutConfirmation(); }); } } diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index eb514d7e0..f76b5d697 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_updates.h" #include "core/application.h" #include "core/click_handler_types.h" +#include "export/export_manager.h" #include "platform/platform_window_title.h" #include "main/main_account.h" #include "main/main_domain.h" @@ -329,4 +330,33 @@ QPoint Controller::getPointForCallPanelCenter() const { : _widget.windowHandle()->screen()->geometry().center(); } +void Controller::showLogoutConfirmation() { + const auto account = Core::App().passcodeLocked() + ? nullptr + : sessionController() + ? &sessionController()->session().account() + : nullptr; + const auto weak = base::make_weak(account); + const auto callback = [=] { + if (account && !weak) { + return; + } + if (account + && account->sessionExists() + && Core::App().exportManager().inProgress(&account->session())) { + Ui::hideLayer(); + Core::App().exportManager().stopWithConfirmation([=] { + Core::App().logout(account); + }); + } else { + Core::App().logout(account); + } + }; + show(Box( + tr::lng_sure_logout(tr::now), + tr::lng_settings_logout(tr::now), + st::attentionBoxButton, + callback)); +} + } // namespace Window diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 975626974..b5cb6710e 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -46,6 +46,8 @@ public: void setupIntro(); void setupMain(); + void showLogoutConfirmation(); + void showSettings(); [[nodiscard]] int verticalShadowTop() const; diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index 0e471a702..d13581ec3 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -120,7 +120,7 @@ PasscodeLockWidget::PasscodeLockWidget( _submit->setClickedCallback([=] { submit(); }); _logout->setClickedCallback([=] { - window->widget()->showLogoutConfirmation(); + window->showLogoutConfirmation(); }); }