MainMenu::MainMenu( QWidget *parent, not_null<Controller*> controller) : TWidget(parent) , _controller(controller) , _menu(this, st::mainMenu) , _telegram(this, st::mainMenuTelegramLabel) , _version(this, st::mainMenuVersionLabel) { setAttribute(Qt::WA_OpaquePaintEvent); subscribe(Global::RefSelfChanged(), [this] { checkSelf(); }); checkSelf(); _nightThemeSwitch.setCallback([this] { if (const auto action = *_nightThemeAction) { const auto nightMode = Window::Theme::IsNightMode(); if (action->isChecked() != nightMode) { Window::Theme::ToggleNightMode(); } } }); resize(st::mainMenuWidth, parentWidget()->height()); _menu->setTriggeredCallback([](QAction *action, int actionTop, Ui::Menu::TriggeredSource source) { emit action->triggered(); }); refreshMenu(); _telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop"))); _telegram->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org"))); _version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about))); _version->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog"))); _version->setLink(2, std::make_shared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); })); subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserPhoneChanged, [this](const Notify::PeerUpdate &update) { if (update.peer->isSelf()) { updatePhone(); } })); subscribe(Global::RefPhoneCallsEnabledChanged(), [this] { refreshMenu(); }); subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) { refreshMenu(); } }); updatePhone(); }
void MainMenu::refreshMenu() { _menu->clearActions(); _menu->addAction(lang(lng_create_group_title), [] { App::wnd()->onShowNewGroup(); }, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver); _menu->addAction(lang(lng_create_channel_title), [] { App::wnd()->onShowNewChannel(); }, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver); _menu->addAction(lang(lng_menu_contacts), [] { Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(), [](not_null<PeerListBox*> box) { box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); box->addLeftButton(langFactory(lng_profile_add_contact), [] { App::wnd()->onShowAddContact(); }); })); }, &st::mainMenuContacts, &st::mainMenuContactsOver); if (Global::PhoneCallsEnabled()) { _menu->addAction(lang(lng_menu_calls), [] { Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>(), [](not_null<PeerListBox*> box) { box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); })); }, &st::mainMenuCalls, &st::mainMenuCallsOver); } _menu->addAction(lang(lng_menu_settings), [] { App::wnd()->showSettings(); }, &st::mainMenuSettings, &st::mainMenuSettingsOver); _nightThemeAction = std::make_shared<QPointer<QAction>>(nullptr); auto action = _menu->addAction(lang(lng_menu_night_mode), [this] { if (auto action = *_nightThemeAction) { action->setChecked(!action->isChecked()); _nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration); } }, &st::mainMenuNightMode, &st::mainMenuNightModeOver); *_nightThemeAction = action; action->setCheckable(true); action->setChecked(Window::Theme::IsNightMode()); _menu->finishAnimating(); updatePhone(); }
void MainMenu::refreshMenu() { _menu->clearActions(); if (!Auth().supportMode()) { _menu->addAction(lang(lng_create_group_title), [] { App::wnd()->onShowNewGroup(); }, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver); _menu->addAction(lang(lng_create_channel_title), [] { App::wnd()->onShowNewChannel(); }, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver); _menu->addAction(lang(lng_menu_contacts), [] { Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(), [](not_null<PeerListBox*> box) { box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); box->addLeftButton(langFactory(lng_profile_add_contact), [] { App::wnd()->onShowAddContact(); }); })); }, &st::mainMenuContacts, &st::mainMenuContactsOver); if (Global::PhoneCallsEnabled()) { _menu->addAction(lang(lng_menu_calls), [] { Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>(), [](not_null<PeerListBox*> box) { box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); })); }, &st::mainMenuCalls, &st::mainMenuCallsOver); } } else { _menu->addAction(lang(lng_profile_add_contact), [] { App::wnd()->onShowAddContact(); }, &st::mainMenuContacts, &st::mainMenuContactsOver); const auto fix = std::make_shared<QPointer<QAction>>(); *fix = _menu->addAction(qsl("Fix chats order"), [=] { (*fix)->setChecked(!(*fix)->isChecked()); Auth().settings().setSupportFixChatsOrder((*fix)->isChecked()); Local::writeUserSettings(); }, &st::mainMenuFixOrder, &st::mainMenuFixOrderOver); (*fix)->setCheckable(true); (*fix)->setChecked(Auth().settings().supportFixChatsOrder()); const auto subscription = Ui::AttachAsChild(_menu, rpl::lifetime()); _menu->addAction(qsl("Reload templates"), [=] { *subscription = Auth().supportTemplates()->errors( ) | rpl::start_with_next([=](QStringList errors) { Ui::Toast::Show(errors.isEmpty() ? "Templates reloaded!" : ("Errors:\n\n" + errors.join("\n\n"))); }); Auth().supportTemplates()->reload(); }, &st::mainMenuReload, &st::mainMenuReloadOver); } _menu->addAction(lang(lng_menu_settings), [] { App::wnd()->showSettings(); }, &st::mainMenuSettings, &st::mainMenuSettingsOver); _nightThemeAction = std::make_shared<QPointer<QAction>>(); auto action = _menu->addAction(lang(lng_menu_night_mode), [=] { if (auto action = *_nightThemeAction) { action->setChecked(!action->isChecked()); _nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration); } }, &st::mainMenuNightMode, &st::mainMenuNightModeOver); *_nightThemeAction = action; action->setCheckable(true); action->setChecked(Window::Theme::IsNightMode()); _menu->finishAnimating(); updatePhone(); }