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"
|
2016-09-30 12:52:03 +00:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2016-06-07 19:59:39 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2016-11-04 08:23:50 +00:00
|
|
|
#include "styles/style_window.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.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"
|
2018-12-10 13:26:53 +00:00
|
|
|
#include "ui/emoji_config.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"
|
2018-06-03 13:30:40 +00:00
|
|
|
#include "auth_session.h"
|
2016-03-14 16:59:18 +00:00
|
|
|
#include "intro/introwidget.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"
|
2016-06-02 13:02:55 +00:00
|
|
|
#include "observer_peer.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-06-01 13:07:03 +00:00
|
|
|
#include "apiwrap.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"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "window/layer_widget.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"
|
2017-03-27 12:24:38 +00:00
|
|
|
#include "window/window_controller.h"
|
2014-08-06 14:40:21 +00:00
|
|
|
|
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
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
MainWindow::MainWindow() {
|
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));
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
subscribe(Core::App().authSessionChanged(), [this] {
|
2018-09-11 12:50:40 +00:00
|
|
|
updateGlobalMenu();
|
2018-12-11 12:22:27 +00:00
|
|
|
if (!AuthSession::Exists()) {
|
|
|
|
_mediaPreview.destroy();
|
|
|
|
}
|
2018-09-11 12:50:40 +00:00
|
|
|
});
|
2016-11-02 14:44:33 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
|
|
|
themeUpdated(data);
|
|
|
|
});
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().lockChanges(
|
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);
|
|
|
|
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);
|
2017-05-19 14:02:55 +00:00
|
|
|
connect(windowHandle(), &QWindow::activeChanged, this, [this] { checkHistoryActivation(); }, Qt::QueuedConnection);
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::firstShow() {
|
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
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
auto isLinux = (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64);
|
|
|
|
auto notificationActionText = lang(Global::DesktopNotify()
|
|
|
|
? lng_disable_notifications_from_tray
|
|
|
|
: lng_enable_notifications_from_tray);
|
|
|
|
|
|
|
|
if (isLinux) {
|
2018-01-25 10:10:52 +00:00
|
|
|
trayIconMenu->addAction(lang(lng_open_from_tray), this, SLOT(showFromTray()));
|
|
|
|
trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()));
|
|
|
|
trayIconMenu->addAction(notificationActionText, this, SLOT(toggleDisplayNotifyFromTray()));
|
|
|
|
trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()));
|
2015-07-21 15:35:08 +00:00
|
|
|
} else {
|
2018-01-25 10:10:52 +00:00
|
|
|
trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()));
|
|
|
|
trayIconMenu->addAction(notificationActionText, this, SLOT(toggleDisplayNotifyFromTray()));
|
|
|
|
trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()));
|
2015-07-21 15:35:08 +00:00
|
|
|
}
|
2017-03-08 07:31:05 +00:00
|
|
|
Global::RefWorkMode().setForced(Global::WorkMode().value(), true);
|
2016-11-07 15:24:28 +00:00
|
|
|
|
2015-07-21 13:29:38 +00:00
|
|
|
psFirstShow();
|
2014-09-29 02:47:30 +00:00
|
|
|
updateTrayMenu();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
void MainWindow::clearWidgetsHook() {
|
2018-06-07 07:44:38 +00:00
|
|
|
Expects(_passcodeLock == nullptr || !Global::LocalPasscode());
|
|
|
|
|
2016-11-04 08:23:50 +00:00
|
|
|
_main.destroy();
|
2018-06-07 07:44:38 +00:00
|
|
|
_passcodeLock.destroy();
|
2016-11-24 19:28:23 +00:00
|
|
|
_intro.destroy();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
QPixmap MainWindow::grabInner() {
|
2016-11-04 11:14:47 +00:00
|
|
|
if (_intro) {
|
2018-06-03 13:30:40 +00:00
|
|
|
return Ui::GrabWidget(_intro);
|
|
|
|
} else if (_passcodeLock) {
|
|
|
|
return Ui::GrabWidget(_passcodeLock);
|
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();
|
2018-06-03 13:30:40 +00:00
|
|
|
_passcodeLock.create(bodyWidget());
|
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 {
|
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() {
|
|
|
|
if (!_passcodeLock) return;
|
|
|
|
|
|
|
|
auto bg = grabInner();
|
|
|
|
|
|
|
|
_passcodeLock.destroy();
|
|
|
|
if (_intro) {
|
|
|
|
_intro->showAnimated(bg, true);
|
2018-06-07 07:44:38 +00:00
|
|
|
} else if (_main) {
|
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-07 07:44:38 +00:00
|
|
|
} else {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().startMtp();
|
2018-06-07 07:44:38 +00:00
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
setupMain();
|
|
|
|
} else {
|
|
|
|
setupIntro();
|
|
|
|
}
|
2018-06-03 13:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
void MainWindow::setupIntro() {
|
2017-09-20 10:23:57 +00:00
|
|
|
Ui::hideSettingsAndLayer(anim::type::instant);
|
2016-06-26 15:37:47 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
clearWidgets();
|
2016-11-04 11:14:47 +00:00
|
|
|
_intro.create(bodyWidget());
|
2016-11-04 08:23:50 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
if (animated) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_intro->showAnimated(bg);
|
2016-11-04 19:50:35 +00:00
|
|
|
} 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() {
|
2018-06-07 07:44:38 +00:00
|
|
|
Expects(AuthSession::Exists());
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
auto animated = (_intro || _passcodeLock);
|
2016-11-04 19:50:35 +00:00
|
|
|
auto bg = animated ? grabInner() : QPixmap();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
clearWidgets();
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2017-04-07 18:10:49 +00:00
|
|
|
_main.create(bodyWidget(), controller());
|
2017-01-14 18:50:16 +00:00
|
|
|
_main->show();
|
2016-11-04 08:23:50 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
if (animated) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_main->showAnimated(bg);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2016-11-04 08:23:50 +00:00
|
|
|
_main->activate();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2018-09-11 12:50:40 +00:00
|
|
|
_main->start();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
fixOrder();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
if (const auto controller = this->controller()) {
|
|
|
|
controller->showSettings();
|
|
|
|
} else {
|
2018-09-11 18:07:04 +00:00
|
|
|
showSpecialLayer(Box<Settings::LayerWidget>(), 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(
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Window::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();
|
2018-04-06 16:23:09 +00:00
|
|
|
_layer->showMainMenu(controller(), 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;
|
|
|
|
}
|
|
|
|
_layer = base::make_unique_q<Window::LayerStackWidget>(
|
|
|
|
bodyWidget());
|
|
|
|
|
|
|
|
_layer->hideFinishEvents(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
destroyLayer();
|
|
|
|
}, _layer->lifetime());
|
|
|
|
|
|
|
|
if (controller()) {
|
|
|
|
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-02-17 06:54:57 +00:00
|
|
|
auto layer = base::take(_layer);
|
|
|
|
const auto resetFocus = Ui::InFocusChain(layer);
|
|
|
|
if (resetFocus) {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
layer = nullptr;
|
2018-11-23 11:05:06 +00:00
|
|
|
if (controller()) {
|
|
|
|
controller()->disableGifPauseReason(Window::GifPauseReason::Layer);
|
|
|
|
}
|
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) {
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_layer) {
|
|
|
|
_layer->hideAll(animated);
|
2017-09-20 10:23:57 +00:00
|
|
|
if (animated == anim::type::instant) {
|
2018-11-23 11:05:06 +00:00
|
|
|
destroyLayer();
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:58:43 +00:00
|
|
|
void MainWindow::ui_removeLayerBlackout() {
|
|
|
|
if (_layer) {
|
|
|
|
_layer->removeBodyCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
MainWidget *MainWindow::mainWidget() {
|
2016-11-04 08:23:50 +00:00
|
|
|
return _main;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
void MainWindow::ui_showBox(
|
|
|
|
object_ptr<BoxContent> box,
|
2017-09-20 10:23:57 +00:00
|
|
|
LayerOptions options,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void MainWindow::ui_showMediaPreview(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<DocumentData*> document) {
|
2017-04-02 10:25:54 +00:00
|
|
|
if (!document || ((!document->isAnimation() || !document->loaded()) && !document->sticker())) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (!_mediaPreview) {
|
2017-04-07 18:10:49 +00:00
|
|
|
_mediaPreview.create(bodyWidget(), controller());
|
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);
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void MainWindow::ui_showMediaPreview(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<PhotoData*> photo) {
|
|
|
|
if (!photo) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (!_mediaPreview) {
|
2017-04-07 18:10:49 +00:00
|
|
|
_mediaPreview.create(bodyWidget(), controller());
|
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);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool MainWindow::doWeReadServerHistory() {
|
|
|
|
updateIsActive(0);
|
2018-09-28 11:56:21 +00:00
|
|
|
return isActive()
|
|
|
|
&& !Ui::isLayerShown()
|
|
|
|
&& (_main ? _main->doWeReadServerHistory() : false);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 07:16:07 +00:00
|
|
|
bool MainWindow::doWeReadMentions() {
|
|
|
|
updateIsActive(0);
|
2018-09-28 11:56:21 +00:00
|
|
|
return isActive()
|
|
|
|
&& !Ui::isLayerShown()
|
|
|
|
&& (_main ? _main->doWeReadMentions() : false);
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::checkHistoryActivation() {
|
2018-09-28 11:56:21 +00:00
|
|
|
if (doWeReadServerHistory()) {
|
2016-11-04 08:23:50 +00:00
|
|
|
_main->markActiveHistoryAsRead();
|
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: {
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_main && _main->isIdle()) {
|
2019-03-10 13:40:44 +00:00
|
|
|
Core::App().updateNonIdle();
|
2016-11-04 08:23:50 +00:00
|
|
|
_main->checkIdleFinish();
|
2015-01-26 13:04:41 +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::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) {
|
2015-01-15 14:22:15 +00:00
|
|
|
if (!trayIconMenu || (cPlatform() == dbipWindows && !force)) return;
|
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
auto iconMenu = trayIconMenu;
|
|
|
|
auto actions = iconMenu->actions();
|
|
|
|
auto isLinux = (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64);
|
|
|
|
if (isLinux) {
|
|
|
|
auto minimizeAction = actions.at(1);
|
|
|
|
minimizeAction->setDisabled(!isVisible());
|
2015-10-23 16:45:23 +00:00
|
|
|
} else {
|
2017-01-01 16:45:20 +00:00
|
|
|
updateIsActive(0);
|
|
|
|
auto active = 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()));
|
|
|
|
toggleAction->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray));
|
|
|
|
|
|
|
|
// On macOS just remove trayIcon menu if the window is not active.
|
|
|
|
// So we will activate the window on click instead of showing the menu.
|
|
|
|
if (!active && (cPlatform() == dbipMac || cPlatform() == dbipMacOld)) {
|
|
|
|
iconMenu = nullptr;
|
|
|
|
}
|
2015-10-23 16:45:23 +00:00
|
|
|
}
|
2016-10-19 12:24:39 +00:00
|
|
|
auto notificationAction = actions.at(isLinux ? 2 : 1);
|
|
|
|
auto notificationActionText = lang(Global::DesktopNotify()
|
|
|
|
? lng_disable_notifications_from_tray
|
|
|
|
: lng_enable_notifications_from_tray);
|
|
|
|
notificationAction->setText(notificationActionText);
|
|
|
|
|
2015-02-16 14:51:50 +00:00
|
|
|
#ifndef Q_OS_WIN
|
2016-10-19 12:24:39 +00:00
|
|
|
if (trayIcon && trayIcon->contextMenu() != iconMenu) {
|
|
|
|
trayIcon->setContextMenu(iconMenu);
|
2015-02-16 14:51:50 +00:00
|
|
|
}
|
2016-10-19 12:24:39 +00:00
|
|
|
#endif // !Q_OS_WIN
|
2015-01-15 14:22:15 +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();
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
if (AuthSession::Exists()) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(Box<AddContactBox>(), 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();
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
if (AuthSession::Exists()) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<GroupInfoBox>(CreatingGroupGroup, false),
|
|
|
|
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();
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
if (_main) {
|
|
|
|
Ui::show(
|
|
|
|
Box<GroupInfoBox>(CreatingGroupChannel, false),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
}
|
2014-11-18 12:40:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::onLogout() {
|
2018-06-04 18:18:52 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
showFromTray();
|
|
|
|
}
|
2014-11-18 12:40:43 +00:00
|
|
|
|
2018-06-20 17:30:57 +00:00
|
|
|
const auto logout = [] {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().logOut();
|
2018-06-20 17:30:57 +00:00
|
|
|
};
|
|
|
|
const auto callback = [=] {
|
|
|
|
if (AuthSession::Exists() && Auth().data().exportInProgress()) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
Auth().data().stopExportWithConfirmation(logout);
|
|
|
|
} else {
|
|
|
|
logout();
|
|
|
|
}
|
|
|
|
};
|
2018-06-04 18:18:52 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
lang(lng_sure_logout),
|
|
|
|
lang(lng_settings_logout),
|
|
|
|
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();
|
2016-02-18 16:36:33 +00:00
|
|
|
updateIsActive(Global::OnlineFocusTimeout());
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void MainWindow::noIntro(Intro::Widget *was) {
|
2016-11-04 08:23:50 +00:00
|
|
|
if (was == _intro) {
|
|
|
|
_intro = nullptr;
|
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() {
|
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) {
|
2017-05-19 14:02:55 +00:00
|
|
|
App::CallDelayed(1, this, [this] {
|
2017-01-01 16:45:20 +00:00
|
|
|
updateTrayMenu();
|
|
|
|
updateGlobalMenu();
|
2017-05-19 14:02:55 +00:00
|
|
|
});
|
2014-06-14 19:32:11 +00:00
|
|
|
activate();
|
2016-04-14 19:24:42 +00:00
|
|
|
Notify::unreadCounterUpdated();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::toggleTray(QSystemTrayIcon::ActivationReason reason) {
|
2017-01-01 16:45:20 +00:00
|
|
|
updateIsActive(0);
|
|
|
|
if ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) && isActive()) return;
|
2014-09-29 02:47:30 +00:00
|
|
|
if (reason == QSystemTrayIcon::Context) {
|
|
|
|
updateTrayMenu(true);
|
|
|
|
QTimer::singleShot(1, this, SLOT(psShowTrayMenu()));
|
2018-03-09 12:53:44 +00:00
|
|
|
} else if (!skipTrayClick()) {
|
2017-01-01 16:45:20 +00:00
|
|
|
if (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() {
|
2019-01-21 13:42:21 +00:00
|
|
|
if (Core::App().locked()) {
|
2015-10-17 18:30:55 +00:00
|
|
|
if (!isActive()) showFromTray();
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_passcode_need_unblock)));
|
2015-10-17 18:30:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-23 12:30:16 +00:00
|
|
|
if (!AuthSession::Exists()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
|
|
|
|
bool soundNotifyChanged = false;
|
|
|
|
Global::SetDesktopNotify(!Global::DesktopNotify());
|
|
|
|
if (Global::DesktopNotify()) {
|
|
|
|
if (Global::RestoreSoundNotifyFromTray() && !Global::SoundNotify()) {
|
|
|
|
Global::SetSoundNotify(true);
|
|
|
|
Global::SetRestoreSoundNotifyFromTray(false);
|
|
|
|
soundNotifyChanged = true;
|
|
|
|
}
|
2015-10-12 21:48:14 +00:00
|
|
|
} else {
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::SoundNotify()) {
|
|
|
|
Global::SetSoundNotify(false);
|
|
|
|
Global::SetRestoreSoundNotifyFromTray(true);
|
|
|
|
soundNotifyChanged = true;
|
|
|
|
} else {
|
|
|
|
Global::SetRestoreSoundNotifyFromTray(false);
|
2015-10-12 21:48:14 +00:00
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
}
|
|
|
|
Local::writeUserSettings();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(Window::Notifications::ChangeType::DesktopEnabled);
|
2016-08-27 04:49:18 +00:00
|
|
|
if (soundNotifyChanged) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(Window::Notifications::ChangeType::SoundEnabled);
|
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();
|
2017-08-08 09:56:10 +00:00
|
|
|
if (!AuthSession::Exists() || !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);
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_main) _main->setGeometry(body);
|
|
|
|
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
|
|
|
MainWindow::TempDirState MainWindow::tempDirState() {
|
2014-11-22 09:45:04 +00:00
|
|
|
if (_clearManager && _clearManager->hasTask(Local::ClearManagerDownloads)) {
|
2014-05-30 08:53:19 +00:00
|
|
|
return TempDirRemoving;
|
|
|
|
}
|
|
|
|
return QDir(cTempDir()).exists() ? TempDirExists : TempDirEmpty;
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
MainWindow::TempDirState MainWindow::localStorageState() {
|
2015-01-02 14:55:24 +00:00
|
|
|
if (_clearManager && _clearManager->hasTask(Local::ClearManagerStorage)) {
|
2014-11-22 09:45:04 +00:00
|
|
|
return TempDirRemoving;
|
|
|
|
}
|
2018-08-27 11:35:58 +00:00
|
|
|
return TempDirEmpty;
|
2014-11-22 09:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::tempDirDelete(int task) {
|
2014-11-22 09:45:04 +00:00
|
|
|
if (_clearManager) {
|
|
|
|
if (_clearManager->addTask(task)) {
|
|
|
|
return;
|
|
|
|
} else {
|
2016-08-28 19:16:23 +00:00
|
|
|
_clearManager->stop();
|
|
|
|
_clearManager = nullptr;
|
2014-11-22 09:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_clearManager = new Local::ClearManager();
|
|
|
|
_clearManager->addTask(task);
|
|
|
|
connect(_clearManager, SIGNAL(succeed(int,void*)), this, SLOT(onClearFinished(int,void*)));
|
|
|
|
connect(_clearManager, SIGNAL(failed(int,void*)), this, SLOT(onClearFailed(int,void*)));
|
|
|
|
_clearManager->start();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::onClearFinished(int task, void *manager) {
|
2014-11-22 09:45:04 +00:00
|
|
|
if (manager && manager == _clearManager) {
|
2016-08-28 19:16:23 +00:00
|
|
|
_clearManager->stop();
|
|
|
|
_clearManager = nullptr;
|
2014-11-22 09:45:04 +00:00
|
|
|
}
|
|
|
|
emit tempDirCleared(task);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void MainWindow::onClearFailed(int task, void *manager) {
|
2014-11-22 09:45:04 +00:00
|
|
|
if (manager && manager == _clearManager) {
|
2016-08-28 19:16:23 +00:00
|
|
|
_clearManager->stop();
|
|
|
|
_clearManager = nullptr;
|
2014-11-22 09:45:04 +00:00
|
|
|
}
|
|
|
|
emit tempDirClearFailed(task);
|
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)));
|
2018-10-07 11:45:46 +00:00
|
|
|
if (AuthSession::Exists() && Auth().supportMode()) {
|
|
|
|
Window::ConvertIconToBlack(img);
|
|
|
|
}
|
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() {
|
2019-01-21 13:42:21 +00:00
|
|
|
if (Core::App().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() {
|
2016-11-04 08:23:50 +00:00
|
|
|
if (_main) _main->updateOnline();
|
2015-01-26 13:04:41 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
MainWindow::~MainWindow() {
|
2016-08-28 19:16:23 +00:00
|
|
|
if (_clearManager) {
|
|
|
|
_clearManager->stop();
|
|
|
|
_clearManager = nullptr;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
delete trayIcon;
|
|
|
|
delete trayIconMenu;
|
|
|
|
}
|