2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2016-03-24 12:57:10 +00:00
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2018-06-20 17:30:57 +00:00
|
|
|
#include "data/data_session.h"
|
2020-04-10 13:18:51 +00:00
|
|
|
#include "data/data_document_media.h"
|
2021-10-01 10:48:52 +00:00
|
|
|
#include "dialogs/ui/dialogs_layout.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/widgets/tooltip.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/layer_widget.h"
|
2018-12-10 13:26:53 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2017-05-30 13:54:05 +00:00
|
|
|
#include "lang/lang_cloud_manager.h"
|
|
|
|
#include "lang/lang_instance.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-11-16 12:15:14 +00:00
|
|
|
#include "core/shortcuts.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/sandbox.h"
|
|
|
|
#include "core/application.h"
|
2020-06-25 07:14:05 +00:00
|
|
|
#include "export/export_manager.h"
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_widget.h"
|
2020-06-25 07:14:05 +00:00
|
|
|
#include "main/main_session.h"
|
2019-06-06 09:37:12 +00:00
|
|
|
#include "main/main_account.h" // Account::sessionValue.
|
2020-06-28 17:13:11 +00:00
|
|
|
#include "main/main_domain.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2021-06-08 18:58:34 +00:00
|
|
|
#include "media/system_media_controls_manager.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2017-06-27 19:24:59 +00:00
|
|
|
#include "boxes/connection_box.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "storage/storage_account.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-06-01 13:07:03 +00:00
|
|
|
#include "apiwrap.h"
|
2020-06-11 09:41:03 +00:00
|
|
|
#include "api/api_updates.h"
|
2018-09-11 18:07:04 +00:00
|
|
|
#include "settings/settings_intro.h"
|
2016-10-17 10:55:17 +00:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2021-02-17 05:48:39 +00:00
|
|
|
#include "base/variant.h"
|
2016-11-02 14:44:33 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
|
|
|
#include "window/themes/window_theme_warning.h"
|
2018-06-03 13:30:40 +00:00
|
|
|
#include "window/window_lock_widgets.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "window/window_main_menu.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "window/window_controller.h" // App::wnd.
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "window/window_media_preview.h"
|
|
|
|
#include "facades.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_window.h"
|
2014-08-06 14:40:21 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QWindow>
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Code for testing languages is F7-F6-F7-F8
|
|
|
|
void FeedLangTestingKey(int key) {
|
|
|
|
static auto codeState = 0;
|
|
|
|
if ((codeState == 0 && key == Qt::Key_F7)
|
|
|
|
|| (codeState == 1 && key == Qt::Key_F6)
|
|
|
|
|| (codeState == 2 && key == Qt::Key_F7)
|
|
|
|
|| (codeState == 3 && key == Qt::Key_F8)) {
|
|
|
|
++codeState;
|
|
|
|
} else {
|
|
|
|
codeState = 0;
|
|
|
|
}
|
|
|
|
if (codeState == 4) {
|
|
|
|
codeState = 0;
|
2017-05-30 17:58:25 +00:00
|
|
|
Lang::CurrentCloudManager().switchToTestLanguage();
|
2017-05-30 13:54:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
2021-06-06 19:49:15 +00:00
|
|
|
: Platform::MainWindow(controller) {
|
2016-11-04 11:14:47 +00:00
|
|
|
resize(st::windowDefaultWidth, st::windowDefaultHeight);
|
2015-09-29 13:24:39 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
using Window::Theme::BackgroundUpdate;
|
|
|
|
Window::Theme::Background()->updates(
|
|
|
|
) | rpl::start_with_next([=](const BackgroundUpdate &data) {
|
2016-11-02 14:44:33 +00:00
|
|
|
themeUpdated(data);
|
2021-07-15 11:12:38 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-24 07:56:16 +00:00
|
|
|
Core::App().passcodeLockChanges(
|
2018-06-03 13:30:40 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateGlobalMenu();
|
|
|
|
}, lifetime());
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2018-12-10 13:26:53 +00:00
|
|
|
Ui::Emoji::Updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Ui::ForceFullRepaint(this);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-07-25 21:30:56 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 15:24:28 +00:00
|
|
|
void MainWindow::initHook() {
|
|
|
|
Platform::MainWindow::initHook();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
QCoreApplication::instance()->installEventFilter(this);
|
2019-04-05 10:13:54 +00:00
|
|
|
|
|
|
|
// Non-queued activeChanged handlers must use QtSignalProducer.
|
|
|
|
connect(
|
|
|
|
windowHandle(),
|
|
|
|
&QWindow::activeChanged,
|
|
|
|
this,
|
|
|
|
[=] { checkHistoryActivation(); },
|
|
|
|
Qt::QueuedConnection);
|
2021-06-06 19:49:15 +00:00
|
|
|
|
2021-06-08 18:58:34 +00:00
|
|
|
if (Media::SystemMediaControlsManager::Supported()) {
|
|
|
|
using MediaManager = Media::SystemMediaControlsManager;
|
2021-06-06 19:49:15 +00:00
|
|
|
_mediaControlsManager = std::make_unique<MediaManager>(&controller());
|
|
|
|
}
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
void MainWindow::createTrayIconMenu() {
|
2014-09-29 02:47:30 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2017-01-11 05:30:51 +00:00
|
|
|
trayIconMenu = new Ui::PopupMenu(nullptr);
|
2015-11-01 18:14:30 +00:00
|
|
|
trayIconMenu->deleteOnHide(false);
|
2016-10-19 12:24:39 +00:00
|
|
|
#else // Q_OS_WIN
|
2015-07-21 15:35:08 +00:00
|
|
|
trayIconMenu = new QMenu(this);
|
2021-02-23 00:55:14 +00:00
|
|
|
|
|
|
|
connect(trayIconMenu, &QMenu::aboutToShow, [=] {
|
|
|
|
updateIsActive();
|
|
|
|
updateTrayMenu();
|
|
|
|
});
|
2016-10-19 12:24:39 +00:00
|
|
|
#endif // else for Q_OS_WIN
|
2016-01-01 07:42:06 +00:00
|
|
|
|
2021-04-10 19:39:06 +00:00
|
|
|
const auto minimizeAction = trayIconMenu->addAction(QString(), [=] {
|
2021-01-22 12:16:18 +00:00
|
|
|
if (_activeForTrayIconAction) {
|
|
|
|
minimizeToTray();
|
|
|
|
} else {
|
|
|
|
showFromTrayMenu();
|
|
|
|
}
|
|
|
|
});
|
2021-04-10 19:39:06 +00:00
|
|
|
const auto notificationAction = trayIconMenu->addAction(QString(), [=] {
|
2021-01-22 12:16:18 +00:00
|
|
|
toggleDisplayNotifyFromTray();
|
|
|
|
});
|
|
|
|
trayIconMenu->addAction(tr::lng_quit_from_tray(tr::now), [=] {
|
|
|
|
quitFromTray();
|
|
|
|
});
|
2020-02-12 08:09:17 +00:00
|
|
|
|
2021-04-10 19:39:06 +00:00
|
|
|
_updateTrayMenuTextActions.events(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (!trayIconMenu) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_activeForTrayIconAction = isActiveForTrayMenu();
|
|
|
|
minimizeAction->setText(_activeForTrayIconAction
|
|
|
|
? tr::lng_minimize_to_tray(tr::now)
|
|
|
|
: tr::lng_open_from_tray(tr::now));
|
|
|
|
|
|
|
|
auto notificationActionText = Core::App().settings().desktopNotify()
|
|
|
|
? tr::lng_disable_notifications_from_tray(tr::now)
|
|
|
|
: tr::lng_enable_notifications_from_tray(tr::now);
|
|
|
|
notificationAction->setText(notificationActionText);
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_updateTrayMenuTextActions.fire({});
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
initTrayMenuHook();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::applyInitialWorkMode() {
|
2021-05-27 19:45:52 +00:00
|
|
|
const auto workMode = Core::App().settings().workMode();
|
|
|
|
workmodeUpdated(workMode);
|
2016-11-07 15:24:28 +00:00
|
|
|
|
2021-02-17 15:20:05 +00:00
|
|
|
if (Core::App().settings().windowPosition().maximized) {
|
2020-02-12 08:09:17 +00:00
|
|
|
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
|
|
|
setWindowState(Qt::WindowMaximized);
|
|
|
|
}
|
|
|
|
if (cStartInTray()
|
|
|
|
|| (cLaunchMode() == LaunchModeAutoStart
|
|
|
|
&& cStartMinimized()
|
|
|
|
&& !Core::App().passcodeLocked())) {
|
|
|
|
const auto minimizeAndHide = [=] {
|
|
|
|
DEBUG_LOG(("Window Pos: First show, setting minimized after."));
|
|
|
|
setWindowState(windowState() | Qt::WindowMinimized);
|
2021-05-27 22:11:16 +00:00
|
|
|
if (workMode == Core::Settings::WorkMode::TrayOnly
|
|
|
|
|| workMode == Core::Settings::WorkMode::WindowAndTray) {
|
2020-02-12 08:09:17 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Platform::IsLinux()) {
|
|
|
|
// If I call hide() synchronously here after show() then on Ubuntu 14.04
|
|
|
|
// it will show a window frame with transparent window body, without content.
|
|
|
|
// And to be able to "Show from tray" one more hide() will be required.
|
|
|
|
crl::on_main(this, minimizeAndHide);
|
|
|
|
} else {
|
|
|
|
minimizeAndHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setPositionInited();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::finishFirstShow() {
|
|
|
|
createTrayIconMenu();
|
|
|
|
applyInitialWorkMode();
|
|
|
|
createGlobalMenu();
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
windowDeactivateEvents(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}, lifetime());
|
2021-07-29 12:30:13 +00:00
|
|
|
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
void MainWindow::clearWidgetsHook() {
|
2020-06-15 16:25:02 +00:00
|
|
|
_mediaPreview.destroy();
|
2016-11-04 08:23:50 +00:00
|
|
|
_main.destroy();
|
2016-11-24 19:28:23 +00:00
|
|
|
_intro.destroy();
|
2020-06-16 14:19:23 +00:00
|
|
|
if (!Core::App().passcodeLocked()) {
|
|
|
|
_passcodeLock.destroy();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
QPixmap MainWindow::grabInner() {
|
2020-06-16 14:19:23 +00:00
|
|
|
if (_passcodeLock) {
|
2018-06-03 13:30:40 +00:00
|
|
|
return Ui::GrabWidget(_passcodeLock);
|
2020-06-16 14:19:23 +00:00
|
|
|
} else if (_intro) {
|
|
|
|
return Ui::GrabWidget(_intro);
|
2016-11-24 19:28:23 +00:00
|
|
|
} else if (_main) {
|
2018-06-03 13:30:40 +00:00
|
|
|
return Ui::GrabWidget(_main);
|
2015-10-17 14:52:26 +00:00
|
|
|
}
|
2018-06-03 13:30:40 +00:00
|
|
|
return {};
|
2015-10-17 14:52:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 13:08:16 +00:00
|
|
|
void MainWindow::preventOrInvoke(Fn<void()> callback) {
|
|
|
|
if (_main && _main->preventsCloseSection(callback)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
void MainWindow::setupPasscodeLock() {
|
2016-11-04 19:50:35 +00:00
|
|
|
auto animated = (_main || _intro);
|
|
|
|
auto bg = animated ? grabInner() : QPixmap();
|
2019-09-09 15:54:38 +00:00
|
|
|
_passcodeLock.create(bodyWidget(), &controller());
|
2016-11-04 08:23:50 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().hideMediaView();
|
2017-09-20 10:23:57 +00:00
|
|
|
Ui::hideSettingsAndLayer(anim::type::instant);
|
2018-06-03 13:30:40 +00:00
|
|
|
if (_main) {
|
|
|
|
_main->hide();
|
|
|
|
}
|
|
|
|
if (_intro) {
|
|
|
|
_intro->hide();
|
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
if (animated) {
|
2018-06-03 13:30:40 +00:00
|
|
|
_passcodeLock->showAnimated(bg);
|
2015-03-02 12:34:16 +00:00
|
|
|
} else {
|
2020-02-11 09:01:08 +00:00
|
|
|
_passcodeLock->showFinished();
|
2015-09-16 13:04:08 +00:00
|
|
|
setInnerFocus();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
void MainWindow::clearPasscodeLock() {
|
2020-06-15 16:25:02 +00:00
|
|
|
if (!_passcodeLock) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-03 13:30:40 +00:00
|
|
|
|
|
|
|
if (_intro) {
|
2020-06-15 16:25:02 +00:00
|
|
|
auto bg = grabInner();
|
|
|
|
_passcodeLock.destroy();
|
2020-06-16 14:19:23 +00:00
|
|
|
_intro->show();
|
|
|
|
updateControlsGeometry();
|
2018-06-03 13:30:40 +00:00
|
|
|
_intro->showAnimated(bg, true);
|
2018-06-07 07:44:38 +00:00
|
|
|
} else if (_main) {
|
2020-06-15 16:25:02 +00:00
|
|
|
auto bg = grabInner();
|
|
|
|
_passcodeLock.destroy();
|
2020-06-16 14:19:23 +00:00
|
|
|
_main->show();
|
|
|
|
updateControlsGeometry();
|
2018-06-03 13:30:40 +00:00
|
|
|
_main->showAnimated(bg, true);
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().checkStartUrl();
|
2018-06-03 13:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
void MainWindow::setupIntro(Intro::EnterPoint point) {
|
2018-06-03 13:30:40 +00:00
|
|
|
auto animated = (_main || _passcodeLock);
|
2016-11-04 19:50:35 +00:00
|
|
|
auto bg = animated ? grabInner() : QPixmap();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-06-25 14:17:37 +00:00
|
|
|
destroyLayer();
|
2021-02-21 03:51:30 +00:00
|
|
|
auto created = object_ptr<Intro::Widget>(
|
|
|
|
bodyWidget(),
|
|
|
|
&controller(),
|
|
|
|
&account(),
|
|
|
|
point);
|
2021-02-03 01:58:27 +00:00
|
|
|
created->showSettingsRequested(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
showSettings();
|
|
|
|
}, created->lifetime());
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
clearWidgets();
|
2020-06-25 14:17:37 +00:00
|
|
|
_intro = std::move(created);
|
2020-06-16 14:19:23 +00:00
|
|
|
if (_passcodeLock) {
|
|
|
|
_intro->hide();
|
2016-11-04 19:50:35 +00:00
|
|
|
} else {
|
2020-06-16 14:19:23 +00:00
|
|
|
_intro->show();
|
|
|
|
updateControlsGeometry();
|
|
|
|
if (animated) {
|
|
|
|
_intro->showAnimated(bg);
|
|
|
|
} else {
|
|
|
|
setInnerFocus();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
fixOrder();
|
2014-12-12 16:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
void MainWindow::setupMain() {
|
2019-06-06 11:59:00 +00:00
|
|
|
Expects(account().sessionExists());
|
2018-06-07 07:44:38 +00:00
|
|
|
|
2020-08-24 12:57:36 +00:00
|
|
|
const auto animated = _intro
|
|
|
|
|| (_passcodeLock && !Core::App().passcodeLocked());
|
2020-06-29 12:11:34 +00:00
|
|
|
const auto bg = animated ? grabInner() : QPixmap();
|
2020-08-24 12:57:36 +00:00
|
|
|
const auto weakAnimatedLayer = (_main && _layer && !_passcodeLock)
|
2020-06-29 12:11:34 +00:00
|
|
|
? Ui::MakeWeak(_layer.get())
|
|
|
|
: nullptr;
|
2020-08-24 12:57:36 +00:00
|
|
|
if (weakAnimatedLayer) {
|
2020-06-29 12:11:34 +00:00
|
|
|
Assert(!animated);
|
|
|
|
_layer->hideAllAnimatedPrepare();
|
|
|
|
} else {
|
|
|
|
destroyLayer();
|
|
|
|
}
|
2020-06-25 12:16:09 +00:00
|
|
|
auto created = object_ptr<MainWidget>(bodyWidget(), sessionController());
|
2014-05-30 08:53:19 +00:00
|
|
|
clearWidgets();
|
2020-06-25 12:16:09 +00:00
|
|
|
_main = std::move(created);
|
2020-06-16 14:19:23 +00:00
|
|
|
if (_passcodeLock) {
|
|
|
|
_main->hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2020-06-16 14:19:23 +00:00
|
|
|
_main->show();
|
|
|
|
updateControlsGeometry();
|
|
|
|
if (animated) {
|
|
|
|
_main->showAnimated(bg);
|
|
|
|
} else {
|
|
|
|
_main->activate();
|
|
|
|
}
|
|
|
|
Core::App().checkStartUrl();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
fixOrder();
|
2020-08-24 12:57:36 +00:00
|
|
|
if (const auto strong = weakAnimatedLayer.data()) {
|
2020-06-29 12:11:34 +00:00
|
|
|
strong->hideAllAnimatedRun();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::showSettings() {
|
2019-03-12 08:07:39 +00:00
|
|
|
if (_passcodeLock) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-18 12:40:43 +00:00
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
if (const auto session = sessionController()) {
|
|
|
|
session->showSettings();
|
2018-09-05 19:05:49 +00:00
|
|
|
} else {
|
2020-06-10 14:52:44 +00:00
|
|
|
showSpecialLayer(
|
|
|
|
Box<Settings::LayerWidget>(&controller()),
|
|
|
|
anim::type::normal);
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
void MainWindow::showSpecialLayer(
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::LayerWidget> layer,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated) {
|
2019-03-12 08:07:39 +00:00
|
|
|
if (_passcodeLock) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-03 20:07:26 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
if (layer) {
|
|
|
|
ensureLayerCreated();
|
2018-04-06 16:23:09 +00:00
|
|
|
_layer->showSpecialLayer(std::move(layer), animated);
|
|
|
|
} else if (_layer) {
|
|
|
|
_layer->hideSpecialLayer(animated);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
bool MainWindow::showSectionInExistingLayer(
|
|
|
|
not_null<Window::SectionMemento*> memento,
|
|
|
|
const Window::SectionShow ¶ms) {
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_layer) {
|
|
|
|
return _layer->showSectionInternal(memento, params);
|
2017-10-03 13:05:58 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
void MainWindow::showMainMenu() {
|
2018-06-03 13:30:40 +00:00
|
|
|
if (_passcodeLock) return;
|
2016-11-11 19:51:59 +00:00
|
|
|
|
|
|
|
if (isHidden()) showFromTray();
|
|
|
|
|
2017-04-06 19:14:12 +00:00
|
|
|
ensureLayerCreated();
|
2019-09-18 11:19:05 +00:00
|
|
|
_layer->showMainMenu(
|
2021-07-25 21:30:56 +00:00
|
|
|
object_ptr<Window::MainMenu>(body(), sessionController()),
|
2019-09-18 11:19:05 +00:00
|
|
|
anim::type::normal);
|
2017-04-06 19:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ensureLayerCreated() {
|
2018-11-23 11:05:06 +00:00
|
|
|
if (_layer) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-18 11:19:05 +00:00
|
|
|
_layer = base::make_unique_q<Ui::LayerStackWidget>(
|
2018-11-23 11:05:06 +00:00
|
|
|
bodyWidget());
|
|
|
|
|
|
|
|
_layer->hideFinishEvents(
|
2019-06-24 08:59:21 +00:00
|
|
|
) | rpl::filter([=] {
|
|
|
|
return _layer != nullptr; // Last hide finish is sent from destructor.
|
|
|
|
}) | rpl::start_with_next([=] {
|
2018-11-23 11:05:06 +00:00
|
|
|
destroyLayer();
|
|
|
|
}, _layer->lifetime());
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
|
|
|
controller->enableGifPauseReason(Window::GifPauseReason::Layer);
|
2017-04-06 19:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 11:05:06 +00:00
|
|
|
void MainWindow::destroyLayer() {
|
|
|
|
if (!_layer) {
|
|
|
|
return;
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2019-06-24 08:59:21 +00:00
|
|
|
|
2019-02-17 06:54:57 +00:00
|
|
|
auto layer = base::take(_layer);
|
|
|
|
const auto resetFocus = Ui::InFocusChain(layer);
|
|
|
|
if (resetFocus) {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
layer = nullptr;
|
2019-06-24 08:59:21 +00:00
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
|
|
|
controller->disableGifPauseReason(Window::GifPauseReason::Layer);
|
2018-11-23 11:05:06 +00:00
|
|
|
}
|
2019-02-17 06:54:57 +00:00
|
|
|
if (resetFocus) {
|
|
|
|
setInnerFocus();
|
|
|
|
}
|
2018-11-23 11:05:06 +00:00
|
|
|
InvokeQueued(this, [=] {
|
|
|
|
checkHistoryActivation();
|
|
|
|
});
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void MainWindow::ui_hideSettingsAndLayer(anim::type animated) {
|
2019-06-24 08:59:21 +00:00
|
|
|
if (animated == anim::type::instant) {
|
|
|
|
destroyLayer();
|
|
|
|
} else if (_layer) {
|
2018-04-06 16:23:09 +00:00
|
|
|
_layer->hideAll(animated);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:58:43 +00:00
|
|
|
void MainWindow::ui_removeLayerBlackout() {
|
|
|
|
if (_layer) {
|
|
|
|
_layer->removeBodyCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
MainWidget *MainWindow::sessionContent() const {
|
|
|
|
return _main.data();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 05:48:39 +00:00
|
|
|
void MainWindow::showBoxOrLayer(
|
|
|
|
std::variant<
|
|
|
|
v::null_t,
|
|
|
|
object_ptr<Ui::BoxContent>,
|
|
|
|
std::unique_ptr<Ui::LayerWidget>> &&layer,
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOptions options,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated) {
|
2021-02-17 05:48:39 +00:00
|
|
|
using UniqueLayer = std::unique_ptr<Ui::LayerWidget>;
|
|
|
|
using ObjectBox = object_ptr<Ui::BoxContent>;
|
|
|
|
if (auto layerWidget = std::get_if<UniqueLayer>(&layer)) {
|
2017-04-06 19:14:12 +00:00
|
|
|
ensureLayerCreated();
|
2021-02-17 05:48:39 +00:00
|
|
|
_layer->showLayer(std::move(*layerWidget), options, animated);
|
|
|
|
} else if (auto box = std::get_if<ObjectBox>(&layer); *box != nullptr) {
|
|
|
|
ensureLayerCreated();
|
|
|
|
_layer->showBox(std::move(*box), options, animated);
|
2015-09-16 13:04:08 +00:00
|
|
|
} else {
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_layer) {
|
|
|
|
_layer->hideTopLayer(animated);
|
2017-09-20 10:23:57 +00:00
|
|
|
if ((animated == anim::type::instant)
|
2018-04-06 16:23:09 +00:00
|
|
|
&& _layer
|
|
|
|
&& !_layer->layerShown()) {
|
2018-11-23 11:05:06 +00:00
|
|
|
destroyLayer();
|
2015-12-07 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().hideMediaView();
|
2015-09-16 13:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-17 05:48:39 +00:00
|
|
|
void MainWindow::ui_showBox(
|
|
|
|
object_ptr<Ui::BoxContent> box,
|
|
|
|
Ui::LayerOptions options,
|
|
|
|
anim::type animated) {
|
|
|
|
showBoxOrLayer(std::move(box), options, animated);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showLayer(
|
|
|
|
std::unique_ptr<Ui::LayerWidget> &&layer,
|
|
|
|
Ui::LayerOptions options,
|
|
|
|
anim::type animated) {
|
|
|
|
showBoxOrLayer(std::move(layer), options, animated);
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
bool MainWindow::ui_isLayerShown() {
|
2018-04-06 16:23:09 +00:00
|
|
|
return _layer != nullptr;
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 13:18:51 +00:00
|
|
|
bool MainWindow::showMediaPreview(
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<DocumentData*> document) {
|
2020-04-10 13:18:51 +00:00
|
|
|
const auto media = document->activeMediaView();
|
2020-05-22 13:29:19 +00:00
|
|
|
const auto preview = Data::VideoPreviewState(media.get());
|
2020-04-10 13:18:51 +00:00
|
|
|
if (!document->sticker()
|
2020-05-22 13:29:19 +00:00
|
|
|
&& (!document->isAnimation() || !preview.loaded())) {
|
2020-04-10 13:18:51 +00:00
|
|
|
return false;
|
2017-04-02 10:25:54 +00:00
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (!_mediaPreview) {
|
2019-06-06 10:21:40 +00:00
|
|
|
_mediaPreview.create(bodyWidget(), sessionController());
|
2016-10-24 15:36:17 +00:00
|
|
|
updateControlsGeometry();
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
if (_mediaPreview->isHidden()) {
|
|
|
|
fixOrder();
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_mediaPreview->showPreview(origin, document);
|
2020-04-10 13:18:51 +00:00
|
|
|
return true;
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 13:18:51 +00:00
|
|
|
bool MainWindow::showMediaPreview(
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<PhotoData*> photo) {
|
2016-04-10 18:18:26 +00:00
|
|
|
if (!_mediaPreview) {
|
2019-06-06 10:21:40 +00:00
|
|
|
_mediaPreview.create(bodyWidget(), sessionController());
|
2016-10-24 15:36:17 +00:00
|
|
|
updateControlsGeometry();
|
2016-02-17 16:37:21 +00:00
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_mediaPreview->isHidden()) {
|
2016-02-17 16:37:21 +00:00
|
|
|
fixOrder();
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_mediaPreview->showPreview(origin, photo);
|
2020-04-10 13:18:51 +00:00
|
|
|
return true;
|
2016-02-17 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
void MainWindow::hideMediaPreview() {
|
|
|
|
if (!_mediaPreview) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
_mediaPreview->hidePreview();
|
2016-02-17 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 14:44:33 +00:00
|
|
|
void MainWindow::themeUpdated(const Window::Theme::BackgroundUpdate &data) {
|
|
|
|
using Type = Window::Theme::BackgroundUpdate::Type;
|
2017-02-03 20:07:26 +00:00
|
|
|
|
|
|
|
// We delay animating theme warning because we want all other
|
2021-07-15 11:12:38 +00:00
|
|
|
// subscribers to receive palette changed notification before any
|
2017-02-03 20:07:26 +00:00
|
|
|
// animations (that include pixmap caches with old palette values).
|
2016-11-02 14:44:33 +00:00
|
|
|
if (data.type == Type::TestingTheme) {
|
|
|
|
if (!_testingThemeWarning) {
|
2016-11-04 11:14:47 +00:00
|
|
|
_testingThemeWarning.create(bodyWidget());
|
2017-02-03 20:07:26 +00:00
|
|
|
_testingThemeWarning->hide();
|
2016-11-02 14:44:33 +00:00
|
|
|
_testingThemeWarning->setGeometry(rect());
|
|
|
|
_testingThemeWarning->setHiddenCallback([this] { _testingThemeWarning.destroyDelayed(); });
|
|
|
|
}
|
2017-12-30 21:28:38 +00:00
|
|
|
crl::on_main(this, [=] {
|
2017-02-03 20:07:26 +00:00
|
|
|
if (_testingThemeWarning) {
|
|
|
|
_testingThemeWarning->showAnimated();
|
|
|
|
}
|
2017-12-30 21:28:38 +00:00
|
|
|
});
|
2016-11-02 14:44:33 +00:00
|
|
|
} else if (data.type == Type::RevertingTheme || data.type == Type::ApplyingTheme) {
|
2017-02-03 20:07:26 +00:00
|
|
|
if (_testingThemeWarning) {
|
|
|
|
if (_testingThemeWarning->isHidden()) {
|
|
|
|
_testingThemeWarning.destroy();
|
|
|
|
} else {
|
2017-12-30 21:28:38 +00:00
|
|
|
crl::on_main(this, [=] {
|
2017-02-03 20:07:26 +00:00
|
|
|
if (_testingThemeWarning) {
|
|
|
|
_testingThemeWarning->hideAnimated();
|
|
|
|
_testingThemeWarning = nullptr;
|
|
|
|
}
|
|
|
|
setInnerFocus();
|
2017-12-30 21:28:38 +00:00
|
|
|
});
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 14:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 11:23:51 +00:00
|
|
|
bool MainWindow::doWeMarkAsRead() {
|
|
|
|
if (!_main || Ui::isLayerShown()) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-28 06:36:15 +00:00
|
|
|
updateIsActive();
|
|
|
|
return isActive() && _main->doWeMarkAsRead();
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::checkHistoryActivation() {
|
2020-02-11 11:23:51 +00:00
|
|
|
if (_main) {
|
|
|
|
_main->checkHistoryActivation();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
bool MainWindow::contentOverlapped(const QRect &globalRect) {
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_main && _main->contentOverlapped(globalRect)) return true;
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_layer && _layer->contentOverlapped(globalRect)) return true;
|
2015-10-01 14:05:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::setInnerFocus() {
|
2016-11-02 14:44:33 +00:00
|
|
|
if (_testingThemeWarning) {
|
|
|
|
_testingThemeWarning->setFocus();
|
2018-04-06 16:23:09 +00:00
|
|
|
} else if (_layer && _layer->canSetFocus()) {
|
|
|
|
_layer->setInnerFocus();
|
2018-06-03 13:30:40 +00:00
|
|
|
} else if (_passcodeLock) {
|
|
|
|
_passcodeLock->setInnerFocus();
|
2016-11-04 08:23:50 +00:00
|
|
|
} else if (_main) {
|
|
|
|
_main->setInnerFocus();
|
2016-11-24 19:28:23 +00:00
|
|
|
} else if (_intro) {
|
|
|
|
_intro->setInnerFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 14:02:55 +00:00
|
|
|
bool MainWindow::eventFilter(QObject *object, QEvent *e) {
|
2016-02-28 09:48:09 +00:00
|
|
|
switch (e->type()) {
|
2017-08-08 09:31:48 +00:00
|
|
|
case QEvent::KeyPress: {
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()
|
|
|
|
&& (e->type() == QEvent::KeyPress)
|
|
|
|
&& object == windowHandle()) {
|
2017-05-30 13:54:05 +00:00
|
|
|
auto key = static_cast<QKeyEvent*>(e)->key();
|
|
|
|
FeedLangTestingKey(key);
|
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::MouseMove: {
|
2020-02-19 16:54:19 +00:00
|
|
|
const auto position = static_cast<QMouseEvent*>(e)->globalPos();
|
2020-06-11 09:41:03 +00:00
|
|
|
if (_lastMousePosition != position) {
|
|
|
|
if (const auto controller = sessionController()) {
|
|
|
|
if (controller->session().updates().isIdle()) {
|
|
|
|
Core::App().updateNonIdle();
|
|
|
|
}
|
|
|
|
}
|
2015-01-26 13:04:41 +00:00
|
|
|
}
|
2020-02-19 16:54:19 +00:00
|
|
|
_lastMousePosition = position;
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
2016-02-28 09:48:09 +00:00
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
case QEvent::MouseButtonRelease: {
|
2018-11-26 11:00:31 +00:00
|
|
|
hideMediaPreview();
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
2016-02-28 09:48:09 +00:00
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
case QEvent::ApplicationActivate: {
|
2017-05-19 14:02:55 +00:00
|
|
|
if (object == QCoreApplication::instance()) {
|
2018-11-26 11:00:31 +00:00
|
|
|
InvokeQueued(this, [=] {
|
2017-05-19 14:02:55 +00:00
|
|
|
handleActiveChanged();
|
|
|
|
});
|
2016-02-28 09:48:09 +00:00
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
2016-02-28 09:48:09 +00:00
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
case QEvent::WindowStateChange: {
|
2017-05-19 14:02:55 +00:00
|
|
|
if (object == this) {
|
|
|
|
auto state = (windowState() & Qt::WindowMinimized) ? Qt::WindowMinimized :
|
|
|
|
((windowState() & Qt::WindowMaximized) ? Qt::WindowMaximized :
|
|
|
|
((windowState() & Qt::WindowFullScreen) ? Qt::WindowFullScreen : Qt::WindowNoState));
|
|
|
|
handleStateChanged(state);
|
2016-02-28 09:48:09 +00:00
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
2016-02-28 09:48:09 +00:00
|
|
|
|
|
|
|
case QEvent::Move:
|
2017-08-08 09:31:48 +00:00
|
|
|
case QEvent::Resize: {
|
2017-05-19 14:02:55 +00:00
|
|
|
if (object == this) {
|
2016-11-04 11:14:47 +00:00
|
|
|
positionUpdated();
|
2014-06-20 07:06:21 +00:00
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
} break;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-02-28 09:48:09 +00:00
|
|
|
|
2017-05-19 14:02:55 +00:00
|
|
|
return Platform::MainWindow::eventFilter(object, e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 00:55:14 +00:00
|
|
|
void MainWindow::updateTrayMenu() {
|
2021-04-10 19:39:06 +00:00
|
|
|
if (!trayIconMenu) {
|
|
|
|
return;
|
2021-02-23 00:55:14 +00:00
|
|
|
}
|
2021-04-10 19:39:06 +00:00
|
|
|
_updateTrayMenuTextActions.fire({});
|
2016-10-19 12:24:39 +00:00
|
|
|
|
2020-01-02 11:25:52 +00:00
|
|
|
psTrayMenuUpdated();
|
2014-09-26 23:48:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 10:32:34 +00:00
|
|
|
bool MainWindow::takeThirdSectionFromLayer() {
|
2018-04-06 16:23:09 +00:00
|
|
|
return _layer ? _layer->takeToThirdSection() : false;
|
2017-09-19 10:32:34 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::fixOrder() {
|
2020-04-08 14:50:28 +00:00
|
|
|
if (_passcodeLock) _passcodeLock->raise();
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_layer) _layer->raise();
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_mediaPreview) _mediaPreview->raise();
|
2016-11-02 14:44:33 +00:00
|
|
|
if (_testingThemeWarning) _testingThemeWarning->raise();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 13:21:01 +00:00
|
|
|
void MainWindow::handleTrayIconActication(
|
|
|
|
QSystemTrayIcon::ActivationReason reason) {
|
2020-06-17 09:36:25 +00:00
|
|
|
updateIsActive();
|
2019-06-03 14:41:23 +00:00
|
|
|
if (Platform::IsMac() && isActive()) {
|
2019-10-13 11:30:52 +00:00
|
|
|
if (trayIcon && !trayIcon->contextMenu()) {
|
2021-01-22 12:16:18 +00:00
|
|
|
showFromTray();
|
2019-10-13 11:30:52 +00:00
|
|
|
}
|
2019-04-12 13:21:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-29 02:47:30 +00:00
|
|
|
if (reason == QSystemTrayIcon::Context) {
|
2021-02-23 00:55:14 +00:00
|
|
|
updateTrayMenu();
|
2021-09-03 13:04:31 +00:00
|
|
|
InvokeQueued(this, [=] {
|
2020-08-28 16:14:19 +00:00
|
|
|
psShowTrayMenu();
|
|
|
|
});
|
2018-03-09 12:53:44 +00:00
|
|
|
} else if (!skipTrayClick()) {
|
2021-01-22 12:16:18 +00:00
|
|
|
if (isActiveForTrayMenu()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
minimizeToTray();
|
|
|
|
} else {
|
2021-01-22 12:16:18 +00:00
|
|
|
showFromTray();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
_lastTrayClickTime = crl::now();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 12:53:44 +00:00
|
|
|
bool MainWindow::skipTrayClick() const {
|
|
|
|
return (_lastTrayClickTime > 0)
|
2019-02-19 06:57:53 +00:00
|
|
|
&& (crl::now() - _lastTrayClickTime
|
2018-03-09 12:53:44 +00:00
|
|
|
< QApplication::doubleClickInterval());
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::toggleDisplayNotifyFromTray() {
|
2020-06-24 07:56:16 +00:00
|
|
|
if (controller().locked()) {
|
2015-10-17 18:30:55 +00:00
|
|
|
if (!isActive()) showFromTray();
|
2021-10-18 22:28:08 +00:00
|
|
|
Ui::show(Box<Ui::InformBox>(tr::lng_passcode_need_unblock(tr::now)));
|
2015-10-17 18:30:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-28 17:13:11 +00:00
|
|
|
if (!sessionController()) {
|
2017-03-23 12:30:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2020-05-12 10:04:53 +00:00
|
|
|
auto soundNotifyChanged = false;
|
|
|
|
auto flashBounceNotifyChanged = false;
|
2020-06-18 18:04:16 +00:00
|
|
|
auto &settings = Core::App().settings();
|
|
|
|
settings.setDesktopNotify(!settings.desktopNotify());
|
|
|
|
if (settings.desktopNotify()) {
|
|
|
|
if (settings.rememberedSoundNotifyFromTray()
|
|
|
|
&& !settings.soundNotify()) {
|
|
|
|
settings.setSoundNotify(true);
|
|
|
|
settings.setRememberedSoundNotifyFromTray(false);
|
2016-08-27 04:49:18 +00:00
|
|
|
soundNotifyChanged = true;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (settings.rememberedFlashBounceNotifyFromTray()
|
|
|
|
&& !settings.flashBounceNotify()) {
|
|
|
|
settings.setFlashBounceNotify(true);
|
|
|
|
settings.setRememberedFlashBounceNotifyFromTray(false);
|
2020-05-12 10:04:53 +00:00
|
|
|
flashBounceNotifyChanged = true;
|
|
|
|
}
|
2015-10-12 21:48:14 +00:00
|
|
|
} else {
|
2020-06-18 18:04:16 +00:00
|
|
|
if (settings.soundNotify()) {
|
|
|
|
settings.setSoundNotify(false);
|
|
|
|
settings.setRememberedSoundNotifyFromTray(true);
|
2016-08-27 04:49:18 +00:00
|
|
|
soundNotifyChanged = true;
|
|
|
|
} else {
|
2020-06-18 18:04:16 +00:00
|
|
|
settings.setRememberedSoundNotifyFromTray(false);
|
2015-10-12 21:48:14 +00:00
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (settings.flashBounceNotify()) {
|
|
|
|
settings.setFlashBounceNotify(false);
|
|
|
|
settings.setRememberedFlashBounceNotifyFromTray(true);
|
2020-05-12 10:04:53 +00:00
|
|
|
flashBounceNotifyChanged = true;
|
|
|
|
} else {
|
2020-06-18 18:04:16 +00:00
|
|
|
settings.setRememberedFlashBounceNotifyFromTray(false);
|
2020-05-12 10:04:53 +00:00
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
}
|
2021-09-22 10:02:01 +00:00
|
|
|
Core::App().saveSettingsDelayed();
|
2020-05-12 10:04:53 +00:00
|
|
|
using Change = Window::Notifications::ChangeType;
|
2021-05-25 13:51:59 +00:00
|
|
|
auto ¬ifications = Core::App().notifications();
|
|
|
|
notifications.notifySettingsChanged(Change::DesktopEnabled);
|
2016-08-27 04:49:18 +00:00
|
|
|
if (soundNotifyChanged) {
|
2021-05-25 13:51:59 +00:00
|
|
|
notifications.notifySettingsChanged(Change::SoundEnabled);
|
2020-05-12 10:04:53 +00:00
|
|
|
}
|
|
|
|
if (flashBounceNotifyChanged) {
|
2021-05-25 13:51:59 +00:00
|
|
|
notifications.notifySettingsChanged(Change::FlashBounceEnabled);
|
2015-02-04 06:14:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::closeEvent(QCloseEvent *e) {
|
2019-01-21 13:42:21 +00:00
|
|
|
if (Core::Sandbox::Instance().isSavingSession()) {
|
2016-06-21 15:58:07 +00:00
|
|
|
e->accept();
|
2014-05-30 08:53:19 +00:00
|
|
|
App::quit();
|
2016-06-21 15:58:07 +00:00
|
|
|
} else {
|
|
|
|
e->ignore();
|
2020-06-28 17:13:11 +00:00
|
|
|
const auto hasAuth = [&] {
|
|
|
|
if (!Core::App().domain().started()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (const auto &[_, account] : Core::App().domain().accounts()) {
|
|
|
|
if (account->sessionExists()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}();
|
|
|
|
if (!hasAuth || !hideNoQuit()) {
|
2016-06-21 15:58:07 +00:00
|
|
|
App::quit();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:36:17 +00:00
|
|
|
void MainWindow::updateControlsGeometry() {
|
2017-02-03 20:07:26 +00:00
|
|
|
Platform::MainWindow::updateControlsGeometry();
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
auto body = bodyWidget()->rect();
|
2018-06-03 13:30:40 +00:00
|
|
|
if (_passcodeLock) _passcodeLock->setGeometry(body);
|
2020-03-06 11:37:48 +00:00
|
|
|
auto mainLeft = 0;
|
|
|
|
auto mainWidth = body.width();
|
|
|
|
if (const auto session = sessionController()) {
|
|
|
|
if (const auto skip = session->filtersWidth()) {
|
|
|
|
mainLeft += skip;
|
|
|
|
mainWidth -= skip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_main) {
|
|
|
|
_main->setGeometry({
|
|
|
|
body.x() + mainLeft,
|
|
|
|
body.y(),
|
|
|
|
mainWidth,
|
|
|
|
body.height() });
|
|
|
|
}
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_intro) _intro->setGeometry(body);
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_layer) _layer->setGeometry(body);
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_mediaPreview) _mediaPreview->setGeometry(body);
|
|
|
|
if (_testingThemeWarning) _testingThemeWarning->setGeometry(body);
|
2017-09-15 17:34:41 +00:00
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
if (_main) _main->checkMainSectionToLayer();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::sendPaths() {
|
2020-06-24 07:56:16 +00:00
|
|
|
if (controller().locked()) {
|
2018-06-03 13:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().hideMediaView();
|
2017-09-20 10:23:57 +00:00
|
|
|
Ui::hideSettingsAndLayer(anim::type::instant);
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_main) {
|
|
|
|
_main->activate();
|
2014-07-18 10:37:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 15:22:36 +00:00
|
|
|
void MainWindow::activeChangedHook() {
|
2020-06-11 09:41:03 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
|
|
|
controller->session().updates().updateOnline();
|
|
|
|
}
|
2015-01-26 13:04:41 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
MainWindow::~MainWindow() {
|
2014-05-30 08:53:19 +00:00
|
|
|
delete trayIcon;
|
|
|
|
delete trayIconMenu;
|
|
|
|
}
|
2019-09-13 06:06:02 +00:00
|
|
|
|
|
|
|
namespace App {
|
|
|
|
|
|
|
|
MainWindow *wnd() {
|
|
|
|
return (Core::IsAppLaunched() && Core::App().activeWindow())
|
|
|
|
? Core::App().activeWindow()->widget().get()
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace App
|