2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Use Controller::account in MainWindow.

This commit is contained in:
John Preston
2019-06-06 14:59:00 +03:00
parent 1e861f79f0
commit 0868a9f7b9
14 changed files with 84 additions and 54 deletions

View File

@@ -93,16 +93,18 @@ void ConvertIconToBlack(QImage &image) {
}
}
QIcon CreateOfficialIcon() {
QIcon CreateOfficialIcon(Main::Account *account) {
auto image = Core::IsAppLaunched() ? Core::App().logo() : LoadLogo();
if (AuthSession::Exists() && Auth().supportMode()) {
if (account
&& account->sessionExists()
&& account->session().supportMode()) {
ConvertIconToBlack(image);
}
return QIcon(App::pixmapFromImageInPlace(std::move(image)));
}
QIcon CreateIcon() {
auto result = CreateOfficialIcon();
QIcon CreateIcon(Main::Account *account) {
auto result = CreateOfficialIcon(account);
if (Platform::IsLinux()) {
return QIcon::fromTheme("telegram", result);
}
@@ -114,7 +116,6 @@ MainWindow::MainWindow(not_null<Controller*> controller)
, _positionUpdatedTimer([=] { savePosition(); })
, _outdated(CreateOutdatedBar(this))
, _body(this)
, _icon(CreateIcon())
, _titleText(qsl("Telegram")) {
subscribe(Theme::Background(), [=](
const Theme::BackgroundUpdate &data) {
@@ -150,13 +151,17 @@ MainWindow::MainWindow(not_null<Controller*> controller)
_inactivePressTimer.setCallback([this] { setInactivePress(false); });
}
Main::Account &MainWindow::account() const {
return _controller->account();
}
Window::SessionController *MainWindow::sessionController() const {
return _controller->sessionController();
}
void MainWindow::checkLockByTerms() {
const auto data = Core::App().termsLocked();
if (!data || !AuthSession::Exists()) {
if (!data || !account().sessionExists()) {
if (_termsBox) {
_termsBox->closeBox();
}
@@ -175,8 +180,8 @@ void MainWindow::checkLockByTerms() {
box->agreeClicks(
) | rpl::start_with_next([=] {
const auto mention = box ? box->lastClickedMention() : QString();
if (AuthSession::Exists()) {
Auth().api().acceptTerms(id);
if (account().sessionExists()) {
account().session().api().acceptTerms(id);
if (!mention.isEmpty()) {
MentionClickHandler(mention).onClick({});
}
@@ -224,8 +229,8 @@ void MainWindow::showTermsDecline() {
void MainWindow::showTermsDelete() {
const auto box = std::make_shared<QPointer<BoxContent>>();
const auto deleteByTerms = [=] {
if (AuthSession::Exists()) {
Auth().termsDeleteNow();
if (account().sessionExists()) {
account().session().termsDeleteNow();
} else {
Ui::hideLayer();
}
@@ -278,9 +283,10 @@ bool MainWindow::computeIsActive() const {
}
void MainWindow::updateWindowIcon() {
const auto supportIcon = AuthSession::Exists() && Auth().supportMode();
if (supportIcon != _usingSupportIcon) {
_icon = CreateIcon();
const auto supportIcon = account().sessionExists()
&& account().session().supportMode();
if (supportIcon != _usingSupportIcon || _icon.isNull()) {
_icon = CreateIcon(&account());
_usingSupportIcon = supportIcon;
}
setWindowIcon(_icon);
@@ -485,8 +491,8 @@ void MainWindow::updateControlsGeometry() {
void MainWindow::updateUnreadCounter() {
if (!Global::started() || App::quitting()) return;
const auto counter = AuthSession::Exists()
? Auth().data().unreadBadge()
const auto counter = account().sessionExists()
? account().session().data().unreadBadge()
: 0;
_titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram");