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(); }
UpdateStateRow::UpdateStateRow(QWidget *parent) : RpWidget(parent) , _check(this, lang(lng_settings_check_now)) , _restart(this, lang(lng_settings_update_now)) { connect(_check, SIGNAL(clicked()), this, SLOT(onCheck())); connect(_restart, SIGNAL(clicked()), this, SIGNAL(restart())); _versionText = lng_settings_current_version_label(lt_version, currentVersionText()); Core::UpdateChecker checker; checker.checking() | rpl::start_with_next([=] { onChecking(); }, lifetime()); checker.isLatest() | rpl::start_with_next([=] { onLatest(); }, lifetime()); checker.progress( ) | rpl::start_with_next([=](Core::UpdateChecker::Progress progress) { onDownloading(progress.already, progress.size); }, lifetime()); checker.failed() | rpl::start_with_next([=] { onFailed(); }, lifetime()); checker.ready() | rpl::start_with_next([=] { onReady(); }, lifetime()); switch (checker.state()) { case Core::UpdateChecker::State::Download: setState(State::Download, true); setDownloadProgress(checker.already(), checker.size()); break; case Core::UpdateChecker::State::Ready: setState(State::Ready, true); break; default: setState(State::None, true); break; } }
UpdateStateRow::UpdateStateRow(QWidget *parent) : TWidget(parent) , _check(this, lang(lng_settings_check_now)) , _restart(this, lang(lng_settings_update_now)) { connect(_check, SIGNAL(clicked()), this, SLOT(onCheck())); connect(_restart, SIGNAL(clicked()), this, SIGNAL(restart())); Sandbox::connect(SIGNAL(updateChecking()), this, SLOT(onChecking())); Sandbox::connect(SIGNAL(updateLatest()), this, SLOT(onLatest())); Sandbox::connect(SIGNAL(updateProgress(qint64, qint64)), this, SLOT(onDownloading(qint64, qint64))); Sandbox::connect(SIGNAL(updateFailed()), this, SLOT(onFailed())); Sandbox::connect(SIGNAL(updateReady()), this, SLOT(onReady())); _versionText = lng_settings_current_version_label(lt_version, currentVersionText()); switch (Sandbox::updatingState()) { case Application::UpdatingDownload: setState(State::Download, true); setDownloadProgress(Sandbox::updatingReady(), Sandbox::updatingSize()); break; case Application::UpdatingReady: setState(State::Ready, true); break; default: setState(State::None, true); break; } }