tdesktop/Telegram/SourceFiles/window/window_controller.cpp

159 lines
3.6 KiB
C++
Raw Normal View History

/*
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"
#include "main/main_session.h"
2019-09-18 11:19:05 +00:00
#include "ui/layers/box_content.h"
#include "ui/layers/layer_widget.h"
#include "ui/toast/toast.h"
#include "ui/emoji_config.h"
#include "chat_helpers/emoji_sets_manager.h"
#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"
#include "mainwindow.h"
#include "facades.h"
#include "app.h"
2019-09-04 07:19:15 +00:00
#include <QtGui/QWindow>
#include <QtGui/QScreen>
namespace Window {
Controller::Controller(not_null<Main::Account*> account)
: _account(account)
, _widget(this) {
2019-06-06 11:59:00 +00:00
_account->sessionValue(
) | rpl::start_with_next([=](Main::Session *session) {
_sessionController = session
2019-09-03 15:24:51 +00:00
? std::make_unique<SessionController>(session, this)
: nullptr;
if (_sessionController) {
_sessionController->filtersMenuChanged(
) | rpl::start_with_next([=] {
sideBarChanged();
}, session->lifetime());
}
2020-03-03 12:07:22 +00:00
if (_sessionController && Global::DialogsFiltersEnabled()) {
_sessionController->toggleFiltersMenu(true);
} else {
sideBarChanged();
}
_widget.updateWindowIcon();
}, _lifetime);
_widget.init();
}
Controller::~Controller() {
// We want to delete all widgets before the _sessionController.
_widget.clearWidgets();
}
void Controller::finishFirstShow() {
_widget.finishFirstShow();
2019-09-02 16:10:18 +00:00
checkThemeEditor();
}
void Controller::checkThemeEditor() {
using namespace Window::Theme;
if (const auto editing = Background()->editingTheme()) {
showRightColumn(Box<Editor>(this, *editing));
2019-09-02 16:10:18 +00:00
}
}
void Controller::setupPasscodeLock() {
_widget.setupPasscodeLock();
}
void Controller::clearPasscodeLock() {
_widget.clearPasscodeLock();
}
void Controller::setupIntro() {
_widget.setupIntro();
}
void Controller::setupMain() {
2020-06-10 10:49:10 +00:00
Expects(_account->sessionExists());
_widget.setupMain();
if (const auto id = Ui::Emoji::NeedToSwitchBackToId()) {
2020-06-10 10:49:10 +00:00
Ui::Emoji::LoadAndSwitchTo(&_account->session(), id);
}
}
void Controller::showSettings() {
_widget.showSettings();
}
void Controller::showToast(const QString &text) {
Ui::Toast::Show(_widget.bodyWidget(), text);
}
void Controller::showBox(
2019-09-18 11:19:05 +00:00
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options,
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();
_widget.fixOrder();
2020-03-03 12:07:22 +00:00
}
void Controller::activate() {
_widget.activate();
}
void Controller::reActivate() {
_widget.reActivateWindow();
}
void Controller::updateIsActive(int timeout) {
_widget.updateIsActive(timeout);
}
void Controller::minimize() {
if (Global::WorkMode().value() == dbiwmTrayOnly) {
_widget.minimizeToTray();
} else {
_widget.setWindowState(_widget.windowState() | Qt::WindowMinimized);
}
}
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