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"
|
2016-09-30 12:52:03 +00:00
|
|
|
#include "dialogs/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"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/add_contact_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"
|
2020-08-28 12:07:29 +00:00
|
|
|
#include "platform/platform_specific.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"
|
2019-09-26 10:55:35 +00:00
|
|
|
#include "base/call_delayed.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"
|
|
|
|
#include "app.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)
|
|
|
|
: Platform::MainWindow(controller) {
|
2019-01-21 13:42:21 +00:00
|
|
|
auto logo = Core::App().logo();
|
2017-05-12 15:27:19 +00:00
|
|
|
icon16 = logo.scaledToWidth(16, Qt::SmoothTransformation);
|
|
|
|
icon32 = logo.scaledToWidth(32, Qt::SmoothTransformation);
|
|
|
|
icon64 = logo.scaledToWidth(64, Qt::SmoothTransformation);
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
auto logoNoMargin = Core::App().logoNoMargin();
|
2017-05-12 15:27:19 +00:00
|
|
|
iconbig16 = logoNoMargin.scaledToWidth(16, Qt::SmoothTransformation);
|
|
|
|
iconbig32 = logoNoMargin.scaledToWidth(32, Qt::SmoothTransformation);
|
|
|
|
iconbig64 = logoNoMargin.scaledToWidth(64, Qt::SmoothTransformation);
|
2014-09-20 21:31:03 +00:00
|
|
|
|
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));
|
|
|
|
|
2016-11-02 14:44:33 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
|
|
|
themeUpdated(data);
|
|
|
|
});
|
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());
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
2020-08-28 12:07:29 +00:00
|
|
|
|
|
|
|
if (Platform::WindowsNeedShadow()) {
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
} else {
|
|
|
|
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);
|
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);
|
2016-10-19 12:24:39 +00:00
|
|
|
#endif // else for Q_OS_WIN
|
2016-01-01 07:42:06 +00:00
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
auto notificationActionText = Core::App().settings().desktopNotify()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_disable_notifications_from_tray(tr::now)
|
|
|
|
: tr::lng_enable_notifications_from_tray(tr::now);
|
2016-10-19 12:24:39 +00:00
|
|
|
|
2020-06-21 08:42:08 +00:00
|
|
|
if (Platform::IsLinux() && !Platform::IsWayland()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
trayIconMenu->addAction(tr::lng_open_from_tray(tr::now), this, SLOT(showFromTray()));
|
2015-07-21 15:35:08 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
trayIconMenu->addAction(tr::lng_minimize_to_tray(tr::now), this, SLOT(minimizeToTray()));
|
|
|
|
trayIconMenu->addAction(notificationActionText, this, SLOT(toggleDisplayNotifyFromTray()));
|
|
|
|
trayIconMenu->addAction(tr::lng_quit_from_tray(tr::now), this, SLOT(quitFromTray()));
|
2020-02-12 08:09:17 +00:00
|
|
|
|
|
|
|
initTrayMenuHook();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::applyInitialWorkMode() {
|
2017-03-08 07:31:05 +00:00
|
|
|
Global::RefWorkMode().setForced(Global::WorkMode().value(), true);
|
2016-11-07 15:24:28 +00:00
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
if (cWindowPos().maximized) {
|
|
|
|
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);
|
|
|
|
if (Global::WorkMode().value() == dbiwmTrayOnly
|
|
|
|
|| Global::WorkMode().value() == dbiwmWindowAndTray) {
|
|
|
|
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();
|
|
|
|
initShadows();
|
|
|
|
applyInitialWorkMode();
|
|
|
|
createGlobalMenu();
|
|
|
|
firstShadowsUpdate();
|
2014-09-29 02:47:30 +00:00
|
|
|
updateTrayMenu();
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
windowDeactivateEvents(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}, lifetime());
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
auto created = object_ptr<Intro::Widget>(bodyWidget(), &account(), point);
|
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 (isHidden()) {
|
|
|
|
showFromTray();
|
|
|
|
}
|
|
|
|
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(
|
|
|
|
object_ptr<Window::MainMenu>(this, sessionController()),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
void MainWindow::ui_showBox(
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> box,
|
|
|
|
Ui::LayerOptions options,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated) {
|
2015-12-07 18:09:05 +00:00
|
|
|
if (box) {
|
2017-04-06 19:14:12 +00:00
|
|
|
ensureLayerCreated();
|
2018-04-06 16:23:09 +00:00
|
|
|
_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// subscribers to receive paltte changed notification before any
|
|
|
|
// 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;
|
|
|
|
}
|
2020-06-17 09:36:25 +00:00
|
|
|
updateIsActive();
|
2020-02-19 16:54:19 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::updateTrayMenu(bool force) {
|
2020-01-02 11:25:52 +00:00
|
|
|
if (!trayIconMenu || (Platform::IsWindows() && !force)) return;
|
2015-01-15 14:22:15 +00:00
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
auto actions = trayIconMenu->actions();
|
2020-06-21 08:42:08 +00:00
|
|
|
if (Platform::IsLinux() && !Platform::IsWayland()) {
|
2016-10-19 12:24:39 +00:00
|
|
|
auto minimizeAction = actions.at(1);
|
2020-01-31 06:34:37 +00:00
|
|
|
minimizeAction->setEnabled(isVisible());
|
2015-10-23 16:45:23 +00:00
|
|
|
} else {
|
2020-06-17 09:36:25 +00:00
|
|
|
updateIsActive();
|
2020-06-21 08:42:08 +00:00
|
|
|
auto active = Platform::IsWayland() ? isVisible() : isActive();
|
2016-10-19 12:24:39 +00:00
|
|
|
auto toggleAction = actions.at(0);
|
|
|
|
disconnect(toggleAction, SIGNAL(triggered(bool)), this, SLOT(minimizeToTray()));
|
|
|
|
disconnect(toggleAction, SIGNAL(triggered(bool)), this, SLOT(showFromTray()));
|
|
|
|
connect(toggleAction, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray()));
|
2019-06-19 15:09:03 +00:00
|
|
|
toggleAction->setText(active
|
|
|
|
? tr::lng_minimize_to_tray(tr::now)
|
|
|
|
: tr::lng_open_from_tray(tr::now));
|
2015-10-23 16:45:23 +00:00
|
|
|
}
|
2020-06-21 08:42:08 +00:00
|
|
|
auto notificationAction = actions.at(Platform::IsLinux() && !Platform::IsWayland() ? 2 : 1);
|
2020-06-18 18:04:16 +00:00
|
|
|
auto notificationActionText = Core::App().settings().desktopNotify()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_disable_notifications_from_tray(tr::now)
|
|
|
|
: tr::lng_enable_notifications_from_tray(tr::now);
|
2016-10-19 12:24:39 +00:00
|
|
|
notificationAction->setText(notificationActionText);
|
|
|
|
|
2020-01-02 11:25:52 +00:00
|
|
|
psTrayMenuUpdated();
|
2014-09-26 23:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::onShowAddContact() {
|
2014-11-25 12:15:29 +00:00
|
|
|
if (isHidden()) showFromTray();
|
|
|
|
|
2020-06-28 17:13:11 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
Ui::show(
|
2020-06-28 17:13:11 +00:00
|
|
|
Box<AddContactBox>(&controller->session()),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::onShowNewGroup() {
|
2014-11-18 12:40:43 +00:00
|
|
|
if (isHidden()) showFromTray();
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
2020-06-23 13:29:02 +00:00
|
|
|
Box<GroupInfoBox>(controller, GroupInfoBox::Type::Group),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::onShowNewChannel() {
|
2015-09-21 20:57:42 +00:00
|
|
|
if (isHidden()) showFromTray();
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
2020-06-23 13:29:02 +00:00
|
|
|
Box<GroupInfoBox>(controller, GroupInfoBox::Type::Channel),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
2014-11-18 12:40:43 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
void MainWindow::showLogoutConfirmation() {
|
2018-06-04 18:18:52 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
showFromTray();
|
|
|
|
}
|
2014-11-18 12:40:43 +00:00
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
const auto account = Core::App().passcodeLocked()
|
|
|
|
? nullptr
|
|
|
|
: sessionController()
|
|
|
|
? &sessionController()->session().account()
|
|
|
|
: nullptr;
|
|
|
|
const auto weak = base::make_weak(account);
|
2020-06-16 14:19:23 +00:00
|
|
|
const auto callback = [=] {
|
|
|
|
if (account && !weak) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-16 09:40:43 +00:00
|
|
|
if (account
|
|
|
|
&& account->sessionExists()
|
2020-06-25 07:14:05 +00:00
|
|
|
&& Core::App().exportManager().inProgress(&account->session())) {
|
2018-06-20 17:30:57 +00:00
|
|
|
Ui::hideLayer();
|
2020-06-25 07:14:05 +00:00
|
|
|
Core::App().exportManager().stopWithConfirmation([=] {
|
2020-06-16 09:40:43 +00:00
|
|
|
Core::App().logout(account);
|
2019-07-24 08:46:23 +00:00
|
|
|
});
|
2018-06-20 17:30:57 +00:00
|
|
|
} else {
|
2020-06-16 09:40:43 +00:00
|
|
|
Core::App().logout(account);
|
2018-06-20 17:30:57 +00:00
|
|
|
}
|
2020-06-16 14:19:23 +00:00
|
|
|
};
|
2018-06-04 18:18:52 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_sure_logout(tr::now),
|
|
|
|
tr::lng_settings_logout(tr::now),
|
2018-06-04 18:18:52 +00:00
|
|
|
st::attentionBoxButton,
|
2018-06-20 17:30:57 +00:00
|
|
|
callback));
|
2014-11-18 12:40:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::quitFromTray() {
|
2014-05-30 08:53:19 +00:00
|
|
|
App::quit();
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::activate() {
|
2014-05-30 08:53:19 +00:00
|
|
|
bool wasHidden = !isVisible();
|
|
|
|
setWindowState(windowState() & ~Qt::WindowMinimized);
|
|
|
|
setVisible(true);
|
2014-09-26 23:48:19 +00:00
|
|
|
psActivateProcess();
|
2014-05-30 08:53:19 +00:00
|
|
|
activateWindow();
|
2020-06-17 09:36:25 +00:00
|
|
|
controller().updateIsActiveFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (wasHidden) {
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_main) {
|
|
|
|
_main->windowShown();
|
2014-05-30 08:53: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
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::showFromTray(QSystemTrayIcon::ActivationReason reason) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (reason != QSystemTrayIcon::Context) {
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(1, this, [this] {
|
2017-01-01 16:45:20 +00:00
|
|
|
updateTrayMenu();
|
|
|
|
updateGlobalMenu();
|
2017-05-19 14:02:55 +00:00
|
|
|
});
|
2020-01-02 11:25:52 +00:00
|
|
|
activate();
|
2020-06-18 11:17:58 +00:00
|
|
|
updateUnreadCounter();
|
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()) {
|
|
|
|
showFromTray(reason);
|
|
|
|
}
|
2019-04-12 13:21:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-29 02:47:30 +00:00
|
|
|
if (reason == QSystemTrayIcon::Context) {
|
|
|
|
updateTrayMenu(true);
|
2020-08-28 16:14:19 +00:00
|
|
|
base::call_delayed(1, this, [=] {
|
|
|
|
psShowTrayMenu();
|
|
|
|
});
|
2018-03-09 12:53:44 +00:00
|
|
|
} else if (!skipTrayClick()) {
|
2020-06-21 08:42:08 +00:00
|
|
|
if (Platform::IsWayland() ? isVisible() : isActive()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
minimizeToTray();
|
|
|
|
} else {
|
|
|
|
showFromTray(reason);
|
|
|
|
}
|
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();
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::show(Box<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
|
|
|
}
|
2020-06-18 12:47:09 +00:00
|
|
|
account().session().saveSettings();
|
2020-05-12 10:04:53 +00:00
|
|
|
using Change = Window::Notifications::ChangeType;
|
2020-06-19 12:59:31 +00:00
|
|
|
auto &changes = Core::App().notifications().settingsChanged();
|
2020-05-12 10:04:53 +00:00
|
|
|
changes.notify(Change::DesktopEnabled);
|
2016-08-27 04:49:18 +00:00
|
|
|
if (soundNotifyChanged) {
|
2020-05-12 10:04:53 +00:00
|
|
|
changes.notify(Change::SoundEnabled);
|
|
|
|
}
|
|
|
|
if (flashBounceNotifyChanged) {
|
|
|
|
changes.notify(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-12-23 13:21:01 +00:00
|
|
|
void MainWindow::placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color) {
|
2014-09-26 23:48:19 +00:00
|
|
|
QPainter p(&img);
|
|
|
|
|
|
|
|
QString cnt = (count < 100) ? QString("%1").arg(count) : QString("..%1").arg(count % 10, 1, 10, QChar('0'));
|
|
|
|
int32 cntSize = cnt.size();
|
|
|
|
|
|
|
|
p.setBrush(bg->b);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
int32 fontSize;
|
|
|
|
if (size == 16) {
|
|
|
|
fontSize = 8;
|
|
|
|
} else if (size == 32) {
|
|
|
|
fontSize = (cntSize < 2) ? 12 : 12;
|
|
|
|
} else {
|
|
|
|
fontSize = (cntSize < 2) ? 22 : 22;
|
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
style::font f = { fontSize, 0, 0 };
|
2015-10-03 10:09:09 +00:00
|
|
|
int32 w = f->width(cnt), d, r;
|
2014-09-26 23:48:19 +00:00
|
|
|
if (size == 16) {
|
|
|
|
d = (cntSize < 2) ? 2 : 1;
|
|
|
|
r = (cntSize < 2) ? 4 : 3;
|
|
|
|
} else if (size == 32) {
|
|
|
|
d = (cntSize < 2) ? 5 : 2;
|
|
|
|
r = (cntSize < 2) ? 8 : 7;
|
|
|
|
} else {
|
|
|
|
d = (cntSize < 2) ? 9 : 4;
|
|
|
|
r = (cntSize < 2) ? 16 : 14;
|
|
|
|
}
|
|
|
|
p.drawRoundedRect(QRect(shift.x() + size - w - d * 2, shift.y() + size - f->height, w + d * 2, f->height), r, r);
|
|
|
|
p.setFont(f->f);
|
|
|
|
|
|
|
|
p.setPen(color->p);
|
|
|
|
|
|
|
|
p.drawText(shift.x() + size - w - d, shift.y() + size - f->height + f->ascent, cnt);
|
|
|
|
|
|
|
|
}
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
QImage MainWindow::iconWithCounter(int size, int count, style::color bg, style::color fg, bool smallIcon) {
|
2014-09-20 21:31:03 +00:00
|
|
|
bool layer = false;
|
|
|
|
if (size < 0) {
|
|
|
|
size = -size;
|
|
|
|
layer = true;
|
|
|
|
}
|
|
|
|
if (layer) {
|
2014-12-15 15:55:45 +00:00
|
|
|
if (size != 16 && size != 20 && size != 24) size = 32;
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2019-01-10 13:55:56 +00:00
|
|
|
// platform/linux/main_window_linux depends on count used the same
|
|
|
|
// way for all the same (count % 1000) values.
|
2014-09-20 21:31:03 +00:00
|
|
|
QString cnt = (count < 1000) ? QString("%1").arg(count) : QString("..%1").arg(count % 100, 2, 10, QChar('0'));
|
|
|
|
QImage result(size, size, QImage::Format_ARGB32);
|
|
|
|
int32 cntSize = cnt.size();
|
2016-10-31 12:29:26 +00:00
|
|
|
result.fill(Qt::transparent);
|
2014-09-20 21:31:03 +00:00
|
|
|
{
|
|
|
|
QPainter p(&result);
|
2016-10-28 12:44:28 +00:00
|
|
|
p.setBrush(bg);
|
2014-09-20 21:31:03 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
int32 fontSize;
|
2014-12-15 15:55:45 +00:00
|
|
|
if (size == 16) {
|
2014-09-20 21:31:03 +00:00
|
|
|
fontSize = (cntSize < 2) ? 11 : ((cntSize < 3) ? 11 : 8);
|
2014-12-15 15:55:45 +00:00
|
|
|
} else if (size == 20) {
|
|
|
|
fontSize = (cntSize < 2) ? 14 : ((cntSize < 3) ? 13 : 10);
|
|
|
|
} else if (size == 24) {
|
|
|
|
fontSize = (cntSize < 2) ? 17 : ((cntSize < 3) ? 16 : 12);
|
2014-09-20 21:31:03 +00:00
|
|
|
} else {
|
|
|
|
fontSize = (cntSize < 2) ? 22 : ((cntSize < 3) ? 20 : 16);
|
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
style::font f = { fontSize, 0, 0 };
|
2015-10-03 10:09:09 +00:00
|
|
|
int32 w = f->width(cnt), d, r;
|
2014-12-15 15:55:45 +00:00
|
|
|
if (size == 16) {
|
2014-09-20 21:31:03 +00:00
|
|
|
d = (cntSize < 2) ? 5 : ((cntSize < 3) ? 2 : 1);
|
|
|
|
r = (cntSize < 2) ? 8 : ((cntSize < 3) ? 7 : 3);
|
2014-12-15 15:55:45 +00:00
|
|
|
} else if (size == 20) {
|
|
|
|
d = (cntSize < 2) ? 6 : ((cntSize < 3) ? 2 : 1);
|
|
|
|
r = (cntSize < 2) ? 10 : ((cntSize < 3) ? 9 : 5);
|
|
|
|
} else if (size == 24) {
|
|
|
|
d = (cntSize < 2) ? 7 : ((cntSize < 3) ? 3 : 1);
|
|
|
|
r = (cntSize < 2) ? 12 : ((cntSize < 3) ? 11 : 6);
|
2014-09-20 21:31:03 +00:00
|
|
|
} else {
|
|
|
|
d = (cntSize < 2) ? 9 : ((cntSize < 3) ? 4 : 2);
|
|
|
|
r = (cntSize < 2) ? 16 : ((cntSize < 3) ? 14 : 8);
|
|
|
|
}
|
|
|
|
p.drawRoundedRect(QRect(size - w - d * 2, size - f->height, w + d * 2, f->height), r, r);
|
2016-10-28 12:44:28 +00:00
|
|
|
p.setFont(f);
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(fg);
|
2014-09-20 21:31:03 +00:00
|
|
|
|
|
|
|
p.drawText(size - w - d, size - f->height + f->ascent, cnt);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
if (size != 16 && size != 32) size = 64;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:33:11 +00:00
|
|
|
QImage img(smallIcon ? ((size == 16) ? iconbig16 : (size == 32 ? iconbig32 : iconbig64)) : ((size == 16) ? icon16 : (size == 32 ? icon32 : icon64)));
|
2020-06-15 16:25:02 +00:00
|
|
|
if (const auto controller = sessionController()) {
|
|
|
|
if (controller->session().supportMode()) {
|
|
|
|
Window::ConvertIconToBlack(img);
|
|
|
|
}
|
2018-10-07 11:45:46 +00:00
|
|
|
}
|
2014-09-20 21:31:03 +00:00
|
|
|
if (!count) return img;
|
|
|
|
|
|
|
|
if (smallIcon) {
|
2016-10-31 12:29:26 +00:00
|
|
|
placeSmallCounter(img, size, count, bg, QPoint(), fg);
|
2014-09-20 21:31:03 +00:00
|
|
|
} else {
|
|
|
|
QPainter p(&img);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.drawPixmap(size / 2, size / 2, App::pixmapFromImageInPlace(iconWithCounter(-size / 2, count, bg, fg, false)));
|
2014-09-20 21:31:03 +00:00
|
|
|
}
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
void MainWindow::updateIsActiveHook() {
|
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
|