Moved some session dependent methods to SessionController.

MainWindow::showAddContact(),
MainWindow::showNewGroup(),
MainWindow::showNewChannel().
This commit is contained in:
23rd 2021-02-03 04:17:03 +03:00 committed by John Preston
parent 683d78c64a
commit 019e691fbb
9 changed files with 95 additions and 64 deletions

View file

@ -113,7 +113,7 @@ object_ptr<Ui::BoxContent> PrepareContactsBox(
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
box->addLeftButton(
tr::lng_profile_add_contact(),
[=] { controller->widget()->showAddContact(); });
[=] { controller->showAddContact(); });
};
return Box<PeerListBox>(
std::make_unique<ContactsBoxController>(

View file

@ -2281,7 +2281,7 @@ void InnerWidget::refreshEmptyLabel() {
resizeEmptyLabel();
_empty->setClickHandlerFilter([=](const auto &...) {
if (_emptyState == EmptyState::NoContacts) {
App::wnd()->showAddContact();
_controller->showAddContact();
} else if (_emptyState == EmptyState::EmptyFolder) {
editOpenedFilter();
}

View file

@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_domain.h"
#include "mainwidget.h"
#include "boxes/confirm_box.h"
#include "boxes/add_contact_box.h"
#include "boxes/connection_box.h"
#include "storage/storage_account.h"
#include "storage/localstorage.h"
@ -669,42 +668,6 @@ void MainWindow::updateTrayMenu(bool force) {
psTrayMenuUpdated();
}
void MainWindow::showAddContact() {
if (isHidden()) {
showFromTray();
}
if (const auto controller = sessionController()) {
Ui::show(
Box<AddContactBox>(&controller->session()),
Ui::LayerOption::KeepOther);
}
}
void MainWindow::showNewGroup() {
if (isHidden()) {
showFromTray();
}
if (const auto controller = sessionController()) {
Ui::show(
Box<GroupInfoBox>(controller, GroupInfoBox::Type::Group),
Ui::LayerOption::KeepOther);
}
}
void MainWindow::showNewChannel() {
if (isHidden()) {
showFromTray();
}
if (const auto controller = sessionController()) {
Ui::show(
Box<GroupInfoBox>(controller, GroupInfoBox::Type::Channel),
Ui::LayerOption::KeepOther);
}
}
void MainWindow::showLogoutConfirmation() {
if (isHidden()) {
showFromTray();

View file

@ -53,9 +53,6 @@ public:
void setupMain();
void showSettings();
void showAddContact();
void showNewGroup();
void showNewChannel();
void setInnerFocus();

View file

@ -932,6 +932,12 @@ void MainWindow::updateGlobalMenuHook() {
#else // DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void MainWindow::createGlobalMenu() {
const auto ensureWindowShown = [=] {
if (isHidden()) {
showFromTray();
}
};
psMainMenu = new QMenu(this);
auto file = psMainMenu->addMenu(tr::lng_mac_menu_file(tr::now));
@ -1061,20 +1067,32 @@ void MainWindow::createGlobalMenu() {
psAddContact = tools->addAction(
tr::lng_mac_menu_add_contact(tr::now),
App::wnd(),
[=] { App::wnd()->showAddContact(); });
this,
[=] {
Expects(sessionController() != nullptr);
ensureWindowShown();
sessionController()->showAddContact();
});
tools->addSeparator();
psNewGroup = tools->addAction(
tr::lng_mac_menu_new_group(tr::now),
App::wnd(),
[=] { App::wnd()->showNewGroup(); });
this,
[=] {
Expects(sessionController() != nullptr);
ensureWindowShown();
sessionController()->showNewGroup();
});
psNewChannel = tools->addAction(
tr::lng_mac_menu_new_channel(tr::now),
App::wnd(),
[=] { App::wnd()->showNewChannel(); });
this,
[=] {
Expects(sessionController() != nullptr);
ensureWindowShown();
sessionController()->showNewChannel();
});
auto help = psMainMenu->addMenu(tr::lng_linux_menu_help(tr::now));

View file

@ -684,6 +684,12 @@ void MainWindow::initShadows() {
}
void MainWindow::createGlobalMenu() {
const auto ensureWindowShown = [=] {
if (isHidden()) {
showFromTray();
}
};
auto main = psMainMenu.addMenu(qsl("Telegram"));
auto about = main->addAction(tr::lng_mac_menu_about_telegram(tr::now, lt_telegram, qsl("Telegram")));
connect(about, &QAction::triggered, about, [] {
@ -738,16 +744,40 @@ void MainWindow::createGlobalMenu() {
}
Ui::show(PrepareContactsBox(sessionController()));
}));
psAddContact = window->addAction(tr::lng_mac_menu_add_contact(tr::now), App::wnd(), [=] {
App::wnd()->showAddContact();
});
{
auto callback = [=] {
Expects(sessionController() != nullptr);
ensureWindowShown();
sessionController()->showAddContact();
};
psAddContact = window->addAction(
tr::lng_mac_menu_add_contact(tr::now),
this,
std::move(callback));
}
window->addSeparator();
psNewGroup = window->addAction(tr::lng_mac_menu_new_group(tr::now), App::wnd(), [=] {
App::wnd()->showNewGroup();
});
psNewChannel = window->addAction(tr::lng_mac_menu_new_channel(tr::now), App::wnd(), [=] {
App::wnd()->showNewChannel();
});
{
auto callback = [=] {
Expects(sessionController() != nullptr);
ensureWindowShown();
sessionController()->showNewGroup();
};
psNewGroup = window->addAction(
tr::lng_mac_menu_new_group(tr::now),
this,
std::move(callback));
}
{
auto callback = [=] {
Expects(sessionController() != nullptr);
ensureWindowShown();
sessionController()->showNewChannel();
};
psNewChannel = window->addAction(
tr::lng_mac_menu_new_channel(tr::now),
this,
std::move(callback));
}
window->addSeparator();
psShowTelegram = window->addAction(tr::lng_mac_menu_show(tr::now), App::wnd(), [=] {
showFromTray();

View file

@ -894,13 +894,13 @@ void MainMenu::parentResized() {
void MainMenu::refreshMenu() {
_menu->clearActions();
const auto controller = _controller;
if (!_controller->session().supportMode()) {
const auto controller = _controller;
_menu->addAction(tr::lng_create_group_title(tr::now), [] {
App::wnd()->showNewGroup();
_menu->addAction(tr::lng_create_group_title(tr::now), [=] {
controller->showNewGroup();
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
_menu->addAction(tr::lng_create_channel_title(tr::now), [] {
App::wnd()->showNewChannel();
_menu->addAction(tr::lng_create_channel_title(tr::now), [=] {
controller->showNewChannel();
}, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver);
_menu->addAction(tr::lng_menu_contacts(tr::now), [=] {
Ui::show(PrepareContactsBox(controller));
@ -911,8 +911,8 @@ void MainMenu::refreshMenu() {
}, &st::mainMenuCalls, &st::mainMenuCallsOver);
}
} else {
_menu->addAction(tr::lng_profile_add_contact(tr::now), [] {
App::wnd()->showAddContact();
_menu->addAction(tr::lng_profile_add_contact(tr::now), [=] {
controller->showAddContact();
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
const auto fix = std::make_shared<QPointer<QAction>>();

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "window/window_session_controller.h"
#include "boxes/add_contact_box.h"
#include "boxes/peers/edit_peer_info_box.h"
#include "boxes/peer_list_controllers.h"
#include "window/window_controller.h"
@ -1140,6 +1141,24 @@ void SessionController::setActiveChatsFilter(FilterId id) {
}
}
void SessionController::showAddContact() {
_window->show(
Box<AddContactBox>(&session()),
Ui::LayerOption::KeepOther);
}
void SessionController::showNewGroup() {
_window->show(
Box<GroupInfoBox>(this, GroupInfoBox::Type::Group),
Ui::LayerOption::KeepOther);
}
void SessionController::showNewChannel() {
_window->show(
Box<GroupInfoBox>(this, GroupInfoBox::Type::Channel),
Ui::LayerOption::KeepOther);
}
SessionController::~SessionController() = default;
} // namespace Window

View file

@ -325,6 +325,10 @@ public:
Dialogs::Key chat,
QDate requestedDate);
void showAddContact();
void showNewGroup();
void showNewChannel();
void showPassportForm(const Passport::FormRequest &request);
void clearPassportForm();