Show phone instead of "online" in the main menu.

This commit is contained in:
John Preston 2017-05-07 12:00:49 +03:00
parent 475f0e9544
commit 291a6b73ab
2 changed files with 14 additions and 10 deletions

View File

@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "boxes/about_box.h" #include "boxes/about_box.h"
#include "lang.h" #include "lang.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "observer_peer.h"
#include "auth_session.h" #include "auth_session.h"
#include "mainwidget.h" #include "mainwidget.h"
@ -74,8 +75,12 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent)
_version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); })); _version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); });
subscribe(Global::RefConnectionTypeChanged(), [this] { updateConnectionState(); }); subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserPhoneChanged, [this](const Notify::PeerUpdate &update) {
updateConnectionState(); if (update.peer->isSelf()) {
updatePhone();
}
}));
updatePhone();
} }
void MainMenu::checkSelf() { void MainMenu::checkSelf() {
@ -125,12 +130,11 @@ void MainMenu::updateControlsGeometry() {
_version->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuVersionBottom - _version->height()); _version->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuVersionBottom - _version->height());
} }
void MainMenu::updateConnectionState() { void MainMenu::updatePhone() {
auto state = MTP::dcstate(); if (auto self = App::self()) {
if (state == MTP::ConnectingState || state == MTP::DisconnectedState || state < 0) { _phoneText = App::formatPhone(self->phone());
_connectionText = lang(lng_status_connecting);
} else { } else {
_connectionText = lang(lng_status_online); _phoneText = QString();
} }
update(); update();
} }
@ -146,7 +150,7 @@ void MainMenu::paintEvent(QPaintEvent *e) {
if (auto self = App::self()) { if (auto self = App::self()) {
self->nameText.drawLeftElided(p, st::mainMenuCoverTextLeft, st::mainMenuCoverNameTop, width() - 2 * st::mainMenuCoverTextLeft, width()); self->nameText.drawLeftElided(p, st::mainMenuCoverTextLeft, st::mainMenuCoverNameTop, width() - 2 * st::mainMenuCoverTextLeft, width());
p.setFont(st::normalFont); p.setFont(st::normalFont);
p.drawTextLeft(st::mainMenuCoverTextLeft, st::mainMenuCoverStatusTop, width(), _connectionText); p.drawTextLeft(st::mainMenuCoverTextLeft, st::mainMenuCoverStatusTop, width(), _phoneText);
} }
if (_cloudButton) { if (_cloudButton) {
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);

View File

@ -48,7 +48,7 @@ protected:
private: private:
void checkSelf(); void checkSelf();
void updateControlsGeometry(); void updateControlsGeometry();
void updateConnectionState(); void updatePhone();
object_ptr<Profile::UserpicButton> _userpicButton = { nullptr }; object_ptr<Profile::UserpicButton> _userpicButton = { nullptr };
object_ptr<Ui::IconButton> _cloudButton = { nullptr }; object_ptr<Ui::IconButton> _cloudButton = { nullptr };
@ -57,7 +57,7 @@ private:
object_ptr<Ui::FlatLabel> _version; object_ptr<Ui::FlatLabel> _version;
bool _showFinished = false; bool _showFinished = false;
QString _connectionText; QString _phoneText;
}; };