Use Window::Controller to manage MainWindow.
This commit is contained in:
parent
a547f80ae9
commit
dd68c7e90d
|
@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "core/application.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "platform/platform_notifications_manager.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "storage/localstorage.h"
|
||||
|
@ -102,8 +103,8 @@ namespace App {
|
|||
}
|
||||
|
||||
MainWindow *wnd() {
|
||||
return Core::IsAppLaunched()
|
||||
? Core::App().getActiveWindow()
|
||||
return (Core::IsAppLaunched() && Core::App().activeWindow())
|
||||
? Core::App().activeWindow()->widget().get()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/effects/animations.h"
|
||||
#include "storage/serialize_common.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "base/qthelp_regex.h"
|
||||
#include "base/qthelp_url.h"
|
||||
#include "boxes/connection_box.h"
|
||||
|
@ -171,12 +172,11 @@ void Application::run() {
|
|||
// Create mime database, so it won't be slow later.
|
||||
QMimeDatabase().mimeTypeForName(qsl("text/plain"));
|
||||
|
||||
_window = std::make_unique<MainWindow>();
|
||||
_window->init();
|
||||
_window = std::make_unique<Window::Controller>(&activeAccount());
|
||||
|
||||
auto currentGeometry = _window->geometry();
|
||||
const auto currentGeometry = _window->widget()->geometry();
|
||||
_mediaView = std::make_unique<Media::View::OverlayWidget>();
|
||||
_window->setGeometry(currentGeometry);
|
||||
_window->widget()->setGeometry(currentGeometry);
|
||||
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
connect(
|
||||
|
@ -223,8 +223,8 @@ void Application::run() {
|
|||
bool Application::hideMediaView() {
|
||||
if (_mediaView && !_mediaView->isHidden()) {
|
||||
_mediaView->hide();
|
||||
if (auto activeWindow = getActiveWindow()) {
|
||||
activeWindow->reActivateWindow();
|
||||
if (const auto window = activeWindow()) {
|
||||
window->reActivate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -966,7 +966,7 @@ rpl::producer<bool> Application::lockValue() const {
|
|||
_1 || _2);
|
||||
}
|
||||
|
||||
MainWindow *Application::getActiveWindow() const {
|
||||
Window::Controller *Application::activeWindow() const {
|
||||
return _window.get();
|
||||
}
|
||||
|
||||
|
@ -974,10 +974,8 @@ bool Application::closeActiveWindow() {
|
|||
if (hideMediaView()) {
|
||||
return true;
|
||||
}
|
||||
if (auto activeWindow = getActiveWindow()) {
|
||||
if (!activeWindow->hideNoQuit()) {
|
||||
activeWindow->close();
|
||||
}
|
||||
if (const auto window = activeWindow()) {
|
||||
window->close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -985,19 +983,19 @@ bool Application::closeActiveWindow() {
|
|||
|
||||
bool Application::minimizeActiveWindow() {
|
||||
hideMediaView();
|
||||
if (auto activeWindow = getActiveWindow()) {
|
||||
if (Global::WorkMode().value() == dbiwmTrayOnly) {
|
||||
activeWindow->minimizeToTray();
|
||||
} else {
|
||||
activeWindow->setWindowState(Qt::WindowMinimized);
|
||||
}
|
||||
if (const auto window = activeWindow()) {
|
||||
window->minimize();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QWidget *Application::getFileDialogParent() {
|
||||
return (_mediaView && _mediaView->isVisible()) ? (QWidget*)_mediaView.get() : (QWidget*)getActiveWindow();
|
||||
return (_mediaView && _mediaView->isVisible())
|
||||
? (QWidget*)_mediaView.get()
|
||||
: activeWindow()
|
||||
? (QWidget*)activeWindow()->widget()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
void Application::checkMediaViewActivation() {
|
||||
|
@ -1032,7 +1030,7 @@ void Application::loggedOut() {
|
|||
clearPasscodeLock();
|
||||
Media::Player::mixer()->stopAndClear();
|
||||
Global::SetVoiceMsgPlaybackDoubled(false);
|
||||
if (const auto window = getActiveWindow()) {
|
||||
if (const auto window = activeWindow()) {
|
||||
window->tempDirDelete(Local::ClearManagerAll);
|
||||
window->setupIntro();
|
||||
}
|
||||
|
@ -1051,12 +1049,8 @@ void Application::loggedOut() {
|
|||
}
|
||||
|
||||
QPoint Application::getPointForCallPanelCenter() const {
|
||||
if (auto activeWindow = getActiveWindow()) {
|
||||
Assert(activeWindow->windowHandle() != nullptr);
|
||||
if (activeWindow->isActive()) {
|
||||
return activeWindow->geometry().center();
|
||||
}
|
||||
return activeWindow->windowHandle()->screen()->geometry().center();
|
||||
if (const auto window = activeWindow()) {
|
||||
return window->getPointForCallPanelCenter();
|
||||
}
|
||||
return QApplication::desktop()->screenGeometry().center();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/timer.h"
|
||||
|
||||
class AuthSessionSettings;
|
||||
class MainWindow;
|
||||
class MainWidget;
|
||||
class FileUploader;
|
||||
class Translator;
|
||||
|
@ -23,6 +24,7 @@ class Databases;
|
|||
|
||||
namespace Window {
|
||||
struct TermsLock;
|
||||
class Controller;
|
||||
} // namespace Window
|
||||
|
||||
namespace ChatHelpers {
|
||||
|
@ -89,7 +91,7 @@ public:
|
|||
}
|
||||
|
||||
// Windows interface.
|
||||
MainWindow *getActiveWindow() const;
|
||||
Window::Controller *activeWindow() const;
|
||||
bool closeActiveWindow();
|
||||
bool minimizeActiveWindow();
|
||||
QWidget *getFileDialogParent();
|
||||
|
@ -272,7 +274,7 @@ private:
|
|||
const std::unique_ptr<Storage::Databases> _databases;
|
||||
const std::unique_ptr<Ui::Animations::Manager> _animationsManager;
|
||||
const std::unique_ptr<Main::Account> _account;
|
||||
std::unique_ptr<MainWindow> _window;
|
||||
std::unique_ptr<Window::Controller> _window;
|
||||
std::unique_ptr<Media::View::OverlayWidget> _mediaView;
|
||||
const std::unique_ptr<Lang::Instance> _langpack;
|
||||
std::unique_ptr<Lang::CloudManager> _langCloudManager;
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "core/application.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
#include "platform/platform_info.h"
|
||||
|
@ -375,7 +376,7 @@ void Manager::set(const QString &keys, Command command) {
|
|||
}
|
||||
auto shortcut = base::make_unique_q<QShortcut>(
|
||||
result,
|
||||
Core::App().getActiveWindow(),
|
||||
Core::App().activeWindow()->widget().get(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
Qt::ApplicationShortcut);
|
||||
|
|
|
@ -66,7 +66,8 @@ void FeedLangTestingKey(int key) {
|
|||
|
||||
} // namespace
|
||||
|
||||
MainWindow::MainWindow() {
|
||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||
: Platform::MainWindow(controller) {
|
||||
auto logo = Core::App().logo();
|
||||
icon16 = logo.scaledToWidth(16, Qt::SmoothTransformation);
|
||||
icon32 = logo.scaledToWidth(32, Qt::SmoothTransformation);
|
||||
|
|
|
@ -44,7 +44,7 @@ class MainWindow : public Platform::MainWindow {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
~MainWindow();
|
||||
|
||||
void firstShow();
|
||||
|
|
|
@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_user.h"
|
||||
#include "window/themes/window_theme_preview.h"
|
||||
#include "window/window_peer_menu.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "main/main_account.h" // Account::sessionValue.
|
||||
#include "observer_peer.h"
|
||||
#include "auth_session.h"
|
||||
|
@ -326,8 +327,10 @@ void OverlayWidget::moveToScreen(bool force) {
|
|||
}
|
||||
return nullptr;
|
||||
};
|
||||
const auto activeWindow = Core::App().getActiveWindow();
|
||||
const auto activeWindowScreen = widgetScreen(activeWindow);
|
||||
const auto window = Core::App().activeWindow()
|
||||
? Core::App().activeWindow()->widget().get()
|
||||
: nullptr;
|
||||
const auto activeWindowScreen = widgetScreen(window);
|
||||
const auto myScreen = widgetScreen(this);
|
||||
if (activeWindowScreen && myScreen && myScreen != activeWindowScreen) {
|
||||
windowHandle()->setScreen(activeWindowScreen);
|
||||
|
|
|
@ -193,7 +193,8 @@ quint32 djbStringHash(QString string) {
|
|||
|
||||
} // namespace
|
||||
|
||||
MainWindow::MainWindow() {
|
||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||
: Window::MainWindow(controller) {
|
||||
connect(&_psCheckStatusIconTimer, SIGNAL(timeout()), this, SLOT(psStatusIconCheck()));
|
||||
_psCheckStatusIconTimer.setSingleShot(false);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class MainWindow : public Window::MainWindow {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
|
||||
void psFirstShow();
|
||||
void psInitSysMenu();
|
||||
|
|
|
@ -18,7 +18,7 @@ class MainWindow : public Window::MainWindow {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
|
||||
void psFirstShow();
|
||||
void psInitSysMenu();
|
||||
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
~MainWindow();
|
||||
|
||||
class Private;
|
||||
void updateWindowIcon() override;
|
||||
|
||||
public slots:
|
||||
void psShowTrayMenu();
|
||||
|
@ -56,7 +56,6 @@ protected:
|
|||
void handleActiveChangedHook() override;
|
||||
void stateChangedHook(Qt::WindowState state) override;
|
||||
void initHook() override;
|
||||
void updateWindowIcon() override;
|
||||
void titleVisibilityChangedHook() override;
|
||||
void unreadCounterChangedHook() override;
|
||||
|
||||
|
@ -83,13 +82,15 @@ protected:
|
|||
void closeWithoutDestroy() override;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
friend class Private;
|
||||
|
||||
void initTouchBar();
|
||||
void hideAndDeactivate();
|
||||
void createGlobalMenu();
|
||||
void updateTitleCounter();
|
||||
void updateIconCounters();
|
||||
|
||||
friend class Private;
|
||||
std::unique_ptr<Private> _private;
|
||||
|
||||
mutable bool psIdle;
|
||||
|
|
|
@ -381,8 +381,9 @@ MainWindow::Private::~Private() {
|
|||
[_observer release];
|
||||
}
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: _private(std::make_unique<Private>(this)) {
|
||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||
: Window::MainWindow(controller)
|
||||
, _private(std::make_unique<Private>(this)) {
|
||||
#ifndef OS_MAC_OLD
|
||||
auto forceOpenGL = std::make_unique<QOpenGLWidget>(this);
|
||||
#endif // !OS_MAC_OLD
|
||||
|
|
|
@ -598,8 +598,9 @@ bool handleSessionNotification = false;
|
|||
|
||||
UINT MainWindow::_taskbarCreatedMsgId = 0;
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: ps_tbHider_hWnd(createTaskbarHider()) {
|
||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||
: Window::MainWindow(controller)
|
||||
, ps_tbHider_hWnd(createTaskbarHider()) {
|
||||
if (!_taskbarCreatedMsgId) {
|
||||
_taskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class MainWindow : public Window::MainWindow {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
|
||||
HWND psHwnd() const;
|
||||
HMENU psMenu() const;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -827,6 +827,8 @@
|
|||
<(src_loc)/window/section_widget.h
|
||||
<(src_loc)/window/window_connecting_widget.cpp
|
||||
<(src_loc)/window/window_connecting_widget.h
|
||||
<(src_loc)/window/window_controller.cpp
|
||||
<(src_loc)/window/window_controller.h
|
||||
<(src_loc)/window/window_history_hider.cpp
|
||||
<(src_loc)/window/window_history_hider.h
|
||||
<(src_loc)/window/window_lock_widgets.cpp
|
||||
|
|
Loading…
Reference in New Issue