2019-06-06 11:20:21 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "window/window_controller.h"
|
|
|
|
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "main/main_account.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "main/main_domain.h"
|
2020-03-18 12:14:45 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/box_content.h"
|
|
|
|
#include "ui/layers/layer_widget.h"
|
2020-03-13 06:56:03 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2020-05-07 15:06:44 +00:00
|
|
|
#include "ui/emoji_config.h"
|
|
|
|
#include "chat_helpers/emoji_sets_manager.h"
|
2019-06-06 11:20:21 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2019-09-02 16:10:18 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
|
|
|
#include "window/themes/window_theme_editor.h"
|
2019-06-06 11:20:21 +00:00
|
|
|
#include "mainwindow.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2019-06-06 11:20:21 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QWindow>
|
|
|
|
#include <QtGui/QScreen>
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
Controller::Controller()
|
2020-06-17 09:36:25 +00:00
|
|
|
: _widget(this)
|
|
|
|
, _isActiveTimer([=] { updateIsActive(); }) {
|
2020-06-15 16:25:02 +00:00
|
|
|
_widget.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller::~Controller() {
|
|
|
|
// We want to delete all widgets before the _sessionController.
|
|
|
|
_widget.clearWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::showAccount(not_null<Main::Account*> account) {
|
2020-06-16 06:48:21 +00:00
|
|
|
Window::Theme::Background()->start();
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
_accountLifetime.destroy();
|
|
|
|
_account = account;
|
|
|
|
|
2019-06-06 11:59:00 +00:00
|
|
|
_account->sessionValue(
|
2020-06-15 16:25:02 +00:00
|
|
|
) | rpl::start_with_next([=](Main::Session *session) {
|
2020-06-16 06:42:47 +00:00
|
|
|
const auto was = base::take(_sessionController);
|
2019-06-06 11:20:21 +00:00
|
|
|
_sessionController = session
|
2019-09-03 15:24:51 +00:00
|
|
|
? std::make_unique<SessionController>(session, this)
|
2019-06-06 11:20:21 +00:00
|
|
|
: nullptr;
|
2020-03-18 12:14:45 +00:00
|
|
|
if (_sessionController) {
|
|
|
|
_sessionController->filtersMenuChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
sideBarChanged();
|
|
|
|
}, session->lifetime());
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (session && session->settings().dialogsFiltersEnabled()) {
|
2020-03-03 12:07:22 +00:00
|
|
|
_sessionController->toggleFiltersMenu(true);
|
|
|
|
} else {
|
|
|
|
sideBarChanged();
|
|
|
|
}
|
2019-06-06 11:20:21 +00:00
|
|
|
_widget.updateWindowIcon();
|
2020-06-15 16:25:02 +00:00
|
|
|
_widget.updateGlobalMenu();
|
|
|
|
if (session) {
|
|
|
|
setupMain();
|
|
|
|
} else {
|
|
|
|
setupIntro();
|
|
|
|
}
|
2020-06-16 09:40:43 +00:00
|
|
|
}, _accountLifetime);
|
2019-08-16 12:44:20 +00:00
|
|
|
}
|
2019-06-06 11:20:21 +00:00
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
void Controller::finishFirstShow() {
|
|
|
|
_widget.finishFirstShow();
|
2019-09-02 16:10:18 +00:00
|
|
|
checkThemeEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::checkThemeEditor() {
|
2019-09-05 10:51:36 +00:00
|
|
|
using namespace Window::Theme;
|
2019-09-05 20:21:44 +00:00
|
|
|
|
|
|
|
if (const auto editing = Background()->editingTheme()) {
|
|
|
|
showRightColumn(Box<Editor>(this, *editing));
|
2019-09-02 16:10:18 +00:00
|
|
|
}
|
2019-06-06 11:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::setupPasscodeLock() {
|
|
|
|
_widget.setupPasscodeLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::clearPasscodeLock() {
|
2020-06-15 16:25:02 +00:00
|
|
|
if (!_account) {
|
|
|
|
showAccount(&Core::App().activeAccount());
|
|
|
|
} else {
|
|
|
|
_widget.clearPasscodeLock();
|
|
|
|
}
|
2019-06-06 11:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::setupIntro() {
|
|
|
|
_widget.setupIntro();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::setupMain() {
|
2020-06-15 16:25:02 +00:00
|
|
|
Expects(_sessionController != nullptr);
|
2020-06-10 10:49:10 +00:00
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
_widget.setupMain();
|
2020-05-07 15:06:44 +00:00
|
|
|
|
|
|
|
if (const auto id = Ui::Emoji::NeedToSwitchBackToId()) {
|
2020-06-15 16:25:02 +00:00
|
|
|
Ui::Emoji::LoadAndSwitchTo(&_sessionController->session(), id);
|
2020-05-07 15:06:44 +00:00
|
|
|
}
|
2019-06-06 11:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::showSettings() {
|
|
|
|
_widget.showSettings();
|
|
|
|
}
|
|
|
|
|
2020-03-13 06:56:03 +00:00
|
|
|
void Controller::showToast(const QString &text) {
|
|
|
|
Ui::Toast::Show(_widget.bodyWidget(), text);
|
|
|
|
}
|
|
|
|
|
2019-06-10 14:58:45 +00:00
|
|
|
void Controller::showBox(
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> content,
|
|
|
|
Ui::LayerOptions options,
|
2019-06-10 14:58:45 +00:00
|
|
|
anim::type animated) {
|
|
|
|
_widget.ui_showBox(std::move(content), options, animated);
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:25:19 +00:00
|
|
|
void Controller::showRightColumn(object_ptr<TWidget> widget) {
|
|
|
|
_widget.showRightColumn(std::move(widget));
|
|
|
|
}
|
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
void Controller::sideBarChanged() {
|
|
|
|
_widget.setMinimumWidth(_widget.computeMinWidth());
|
|
|
|
_widget.updateControlsGeometry();
|
2020-04-08 14:50:28 +00:00
|
|
|
_widget.fixOrder();
|
2020-03-03 12:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
void Controller::activate() {
|
|
|
|
_widget.activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::reActivate() {
|
|
|
|
_widget.reActivateWindow();
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
void Controller::updateIsActiveFocus() {
|
|
|
|
_isActiveTimer.callOnce(sessionController()
|
|
|
|
? sessionController()->session().serverConfig().onlineFocusTimeout
|
|
|
|
: crl::time(1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::updateIsActiveBlur() {
|
|
|
|
_isActiveTimer.callOnce(sessionController()
|
|
|
|
? sessionController()->session().serverConfig().offlineBlurTimeout
|
|
|
|
: crl::time(1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::updateIsActive() {
|
|
|
|
_widget.updateIsActive();
|
2019-06-06 11:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::minimize() {
|
|
|
|
if (Global::WorkMode().value() == dbiwmTrayOnly) {
|
|
|
|
_widget.minimizeToTray();
|
|
|
|
} else {
|
2020-01-02 11:57:36 +00:00
|
|
|
_widget.setWindowState(_widget.windowState() | Qt::WindowMinimized);
|
2019-06-06 11:20:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::close() {
|
|
|
|
if (!_widget.hideNoQuit()) {
|
|
|
|
_widget.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Controller::getPointForCallPanelCenter() const {
|
|
|
|
Expects(_widget.windowHandle() != nullptr);
|
|
|
|
|
|
|
|
return _widget.isActive()
|
|
|
|
? _widget.geometry().center()
|
|
|
|
: _widget.windowHandle()->screen()->geometry().center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::tempDirDelete(int task) {
|
|
|
|
_widget.tempDirDelete(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Window
|