mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Use Window::Controller to manage MainWindow.
This commit is contained in:
@@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/window_session_controller.h"
|
||||
#include "window/window_lock_widgets.h"
|
||||
#include "window/window_outdated_bar.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "main/main_account.h" // Account::authSessionValue.
|
||||
#include "core/click_handler_types.h"
|
||||
@@ -108,8 +109,9 @@ QIcon CreateIcon() {
|
||||
return result;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: _positionUpdatedTimer([=] { savePosition(); })
|
||||
MainWindow::MainWindow(not_null<Controller*> controller)
|
||||
: _controller(controller)
|
||||
, _positionUpdatedTimer([=] { savePosition(); })
|
||||
, _outdated(CreateOutdatedBar(this))
|
||||
, _body(this)
|
||||
, _icon(CreateIcon())
|
||||
@@ -127,14 +129,6 @@ MainWindow::MainWindow()
|
||||
workmodeUpdated(mode);
|
||||
});
|
||||
|
||||
Core::App().activeAccount().sessionValue(
|
||||
) | rpl::start_with_next([=](AuthSession *session) {
|
||||
_controller = session
|
||||
? std::make_unique<Window::SessionController>(session, this)
|
||||
: nullptr;
|
||||
updateWindowIcon();
|
||||
}, lifetime());
|
||||
|
||||
Core::App().termsLockValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
checkLockByTerms();
|
||||
@@ -156,6 +150,10 @@ MainWindow::MainWindow()
|
||||
_inactivePressTimer.setCallback([this] { setInactivePress(false); });
|
||||
}
|
||||
|
||||
Window::SessionController *MainWindow::sessionController() const {
|
||||
return _controller->sessionController();
|
||||
}
|
||||
|
||||
void MainWindow::checkLockByTerms() {
|
||||
const auto data = Core::App().termsLocked();
|
||||
if (!data || !AuthSession::Exists()) {
|
||||
|
@@ -15,6 +15,7 @@ class BoxContent;
|
||||
|
||||
namespace Window {
|
||||
|
||||
class Controller;
|
||||
class SessionController;
|
||||
class TitleWidget;
|
||||
struct TermsLock;
|
||||
@@ -28,11 +29,12 @@ class MainWindow : public Ui::RpWidget, protected base::Subscriber {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
explicit MainWindow(not_null<Controller*> controller);
|
||||
|
||||
Window::SessionController *sessionController() const {
|
||||
return _controller.get();
|
||||
not_null<Window::Controller*> controller() const {
|
||||
return _controller;
|
||||
}
|
||||
Window::SessionController *sessionController() const;
|
||||
void setInactivePress(bool inactive);
|
||||
bool wasInactivePress() const {
|
||||
return _wasInactivePress;
|
||||
@@ -83,6 +85,8 @@ public:
|
||||
|
||||
rpl::producer<> leaveEvents() const;
|
||||
|
||||
virtual void updateWindowIcon();
|
||||
|
||||
public slots:
|
||||
bool minimizeToTray();
|
||||
void updateGlobalMenu() {
|
||||
@@ -110,8 +114,6 @@ protected:
|
||||
virtual void clearWidgetsHook() {
|
||||
}
|
||||
|
||||
virtual void updateWindowIcon();
|
||||
|
||||
virtual void stateChangedHook(Qt::WindowState state) {
|
||||
}
|
||||
|
||||
@@ -159,10 +161,11 @@ private:
|
||||
|
||||
int computeMinHeight() const;
|
||||
|
||||
not_null<Window::Controller*> _controller;
|
||||
|
||||
base::Timer _positionUpdatedTimer;
|
||||
bool _positionInited = false;
|
||||
|
||||
std::unique_ptr<Window::SessionController> _controller;
|
||||
object_ptr<TitleWidget> _title = { nullptr };
|
||||
object_ptr<Ui::RpWidget> _outdated;
|
||||
object_ptr<TWidget> _body;
|
||||
|
95
Telegram/SourceFiles/window/window_controller.cpp
Normal file
95
Telegram/SourceFiles/window/window_controller.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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 "window/window_session_controller.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
namespace Window {
|
||||
|
||||
Controller::Controller(not_null<Main::Account*> account)
|
||||
: _account(account)
|
||||
, _widget(this) {
|
||||
Core::App().activeAccount().sessionValue(
|
||||
) | rpl::start_with_next([=](AuthSession *session) {
|
||||
_sessionController = session
|
||||
? std::make_unique<SessionController>(session, &_widget)
|
||||
: nullptr;
|
||||
_widget.updateWindowIcon();
|
||||
}, _lifetime);
|
||||
|
||||
_widget.init();
|
||||
}
|
||||
|
||||
Controller::~Controller() = default;
|
||||
|
||||
void Controller::firstShow() {
|
||||
_widget.firstShow();
|
||||
}
|
||||
|
||||
void Controller::setupPasscodeLock() {
|
||||
_widget.setupPasscodeLock();
|
||||
}
|
||||
|
||||
void Controller::clearPasscodeLock() {
|
||||
_widget.clearPasscodeLock();
|
||||
}
|
||||
|
||||
void Controller::setupIntro() {
|
||||
_widget.setupIntro();
|
||||
}
|
||||
|
||||
void Controller::setupMain() {
|
||||
_widget.setupMain();
|
||||
}
|
||||
|
||||
void Controller::showSettings() {
|
||||
_widget.showSettings();
|
||||
}
|
||||
|
||||
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(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
|
64
Telegram/SourceFiles/window/window_controller.h
Normal file
64
Telegram/SourceFiles/window/window_controller.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
namespace Main {
|
||||
class Account;
|
||||
} // namespace Main
|
||||
|
||||
namespace Window {
|
||||
|
||||
class Controller final {
|
||||
public:
|
||||
explicit Controller(not_null<Main::Account*> account);
|
||||
~Controller();
|
||||
|
||||
Controller(const Controller &other) = delete;
|
||||
Controller &operator=(const Controller &other) = delete;
|
||||
|
||||
not_null<Main::Account*> account() const {
|
||||
return _account;
|
||||
}
|
||||
not_null<::MainWindow*> widget() {
|
||||
return &_widget;
|
||||
}
|
||||
SessionController *sessionController() const {
|
||||
return _sessionController.get();
|
||||
}
|
||||
|
||||
void firstShow();
|
||||
|
||||
void setupPasscodeLock();
|
||||
void clearPasscodeLock();
|
||||
void setupIntro();
|
||||
void setupMain();
|
||||
|
||||
void showSettings();
|
||||
|
||||
void activate();
|
||||
void reActivate();
|
||||
void updateIsActive(int timeout);
|
||||
void minimize();
|
||||
void close();
|
||||
|
||||
QPoint getPointForCallPanelCenter() const;
|
||||
|
||||
void tempDirDelete(int task);
|
||||
|
||||
private:
|
||||
not_null<Main::Account*> _account;
|
||||
::MainWindow _widget;
|
||||
std::unique_ptr<SessionController> _sessionController;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Window
|
Reference in New Issue
Block a user