From f677b116f96d9cd93b65ea788456211b51b6967c Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Thu, 19 Sep 2019 12:28:36 +0300
Subject: [PATCH] Use install_base_filter for lib_base.

---
 .../SourceFiles/boxes/create_poll_box.cpp     | 10 ++---
 .../SourceFiles/boxes/edit_caption_box.cpp    |  6 +--
 Telegram/SourceFiles/boxes/send_files_box.cpp |  6 +--
 .../chat_helpers/emoji_suggestions_widget.cpp | 14 +++----
 .../chat_helpers/message_field.cpp            |  8 ++--
 Telegram/SourceFiles/core/event_filter.cpp    | 38 -----------------
 Telegram/SourceFiles/core/event_filter.h      | 41 -------------------
 .../SourceFiles/dialogs/dialogs_widget.cpp    | 10 ++---
 .../SourceFiles/history/history_widget.cpp    |  6 +--
 .../view/history_view_compose_controls.cpp    |  6 +--
 .../view/history_view_scheduled_section.cpp   | 10 ++---
 .../window/themes/window_theme_editor_box.cpp |  8 ++--
 Telegram/gyp/telegram/sources.txt             |  2 -
 Telegram/lib_base                             |  2 +-
 14 files changed, 43 insertions(+), 124 deletions(-)
 delete mode 100644 Telegram/SourceFiles/core/event_filter.cpp
 delete mode 100644 Telegram/SourceFiles/core/event_filter.h

diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp
index eb46cc606d..e93824ba29 100644
--- a/Telegram/SourceFiles/boxes/create_poll_box.cpp
+++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp
@@ -17,12 +17,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/widgets/labels.h"
 #include "ui/widgets/buttons.h"
 #include "main/main_session.h"
-#include "core/event_filter.h"
 #include "chat_helpers/emoji_suggestions_widget.h"
 #include "chat_helpers/message_field.h"
 #include "history/view/history_view_schedule_box.h"
 #include "settings/settings_common.h"
 #include "base/unique_qptr.h"
+#include "base/event_filter.h"
 #include "facades.h"
 #include "styles/style_layers.h"
 #include "styles/style_boxes.h"
@@ -522,14 +522,14 @@ void Options::addEmptyOption() {
 	QObject::connect(field, &Ui::InputField::focused, [=] {
 		_scrollToWidget.fire_copy(field);
 	});
-	Core::InstallEventFilter(field, [=](not_null<QEvent*> event) {
+	base::install_event_filter(field, [=](not_null<QEvent*> event) {
 		if (event->type() != QEvent::KeyPress
 			|| !field->getLastText().isEmpty()) {
-			return Core::EventFilter::Result::Continue;
+			return base::EventFilterResult::Continue;
 		}
 		const auto key = static_cast<QKeyEvent*>(event.get())->key();
 		if (key != Qt::Key_Backspace) {
-			return Core::EventFilter::Result::Continue;
+			return base::EventFilterResult::Continue;
 		}
 
 		const auto index = findField(field);
@@ -538,7 +538,7 @@ void Options::addEmptyOption() {
 		} else {
 			_backspaceInFront.fire({});
 		}
-		return Core::EventFilter::Result::Cancel;
+		return base::EventFilterResult::Cancel;
 	});
 
 	_list.back().removeClicks(
diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp
index 47f80eb78f..8870d947b9 100644
--- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp
+++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp
@@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "chat_helpers/message_field.h"
 #include "chat_helpers/tabbed_panel.h"
 #include "chat_helpers/tabbed_selector.h"
-#include "core/event_filter.h"
+#include "base/event_filter.h"
 #include "core/file_utilities.h"
 #include "core/mime_type.h"
 #include "data/data_document.h"
@@ -725,9 +725,9 @@ void EditCaptionBox::setupEmojiPanel() {
 
 	const auto filterCallback = [=](not_null<QEvent*> event) {
 		emojiFilterForGeometry(event);
-		return Core::EventFilter::Result::Continue;
+		return base::EventFilterResult::Continue;
 	};
-	_emojiFilter.reset(Core::InstallEventFilter(container, filterCallback));
+	_emojiFilter.reset(base::install_event_filter(container, filterCallback));
 
 	_emojiToggle.create(this, st::boxAttachEmoji);
 	_emojiToggle->installEventFilter(_emojiPanel);
diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp
index afc842773a..2a458900ec 100644
--- a/Telegram/SourceFiles/boxes/send_files_box.cpp
+++ b/Telegram/SourceFiles/boxes/send_files_box.cpp
@@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "history/view/history_view_schedule_box.h"
 #include "core/file_utilities.h"
 #include "core/mime_type.h"
-#include "core/event_filter.h"
+#include "base/event_filter.h"
 #include "ui/effects/animations.h"
 #include "ui/widgets/checkbox.h"
 #include "ui/widgets/buttons.h"
@@ -1706,9 +1706,9 @@ void SendFilesBox::setupEmojiPanel() {
 
 	const auto filterCallback = [=](not_null<QEvent*> event) {
 		emojiFilterForGeometry(event);
-		return Core::EventFilter::Result::Continue;
+		return base::EventFilterResult::Continue;
 	};
-	_emojiFilter.reset(Core::InstallEventFilter(container, filterCallback));
+	_emojiFilter.reset(base::install_event_filter(container, filterCallback));
 
 	_emojiToggle.create(this, st::boxAttachEmoji);
 	_emojiToggle->setVisible(!_caption->isHidden());
diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp
index 394691007c..f5bee20f85 100644
--- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp
+++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp
@@ -17,7 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/ui_utility.h"
 #include "platform/platform_specific.h"
 #include "core/application.h"
-#include "core/event_filter.h"
+#include "base/event_filter.h"
 #include "main/main_session.h"
 #include "app.h"
 #include "styles/style_chat_helpers.h"
@@ -525,17 +525,17 @@ SuggestionsController::SuggestionsController(
 
 	const auto fieldCallback = [=](not_null<QEvent*> event) {
 		return fieldFilter(event)
-			? Core::EventFilter::Result::Cancel
-			: Core::EventFilter::Result::Continue;
+			? base::EventFilterResult::Cancel
+			: base::EventFilterResult::Continue;
 	};
-	_fieldFilter.reset(Core::InstallEventFilter(_field, fieldCallback));
+	_fieldFilter.reset(base::install_event_filter(_field, fieldCallback));
 
 	const auto outerCallback = [=](not_null<QEvent*> event) {
 		return outerFilter(event)
-			? Core::EventFilter::Result::Cancel
-			: Core::EventFilter::Result::Continue;
+			? base::EventFilterResult::Cancel
+			: base::EventFilterResult::Continue;
 	};
-	_outerFilter.reset(Core::InstallEventFilter(outer, outerCallback));
+	_outerFilter.reset(base::install_event_filter(outer, outerCallback));
 
 	QObject::connect(
 		_field,
diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp
index a3b1f94b44..43fb295003 100644
--- a/Telegram/SourceFiles/chat_helpers/message_field.cpp
+++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp
@@ -12,13 +12,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "history/history_item.h" // HistoryItem::originalText
 #include "base/qthelp_regex.h"
 #include "base/qthelp_url.h"
+#include "base/event_filter.h"
 #include "boxes/abstract_box.h"
 #include "ui/wrap/vertical_layout.h"
 #include "ui/widgets/popup_menu.h"
 #include "ui/ui_utility.h"
 #include "data/data_session.h"
 #include "data/data_user.h"
-#include "core/event_filter.h"
 #include "chat_helpers/emoji_suggestions_widget.h"
 #include "window/window_session_controller.h"
 #include "lang/lang_keys.h"
@@ -676,10 +676,10 @@ void SetupSendMenu(
 		(*menu)->popup(QCursor::pos());
 		return true;
 	};
-	Core::InstallEventFilter(button, [=](not_null<QEvent*> e) {
+	base::install_event_filter(button, [=](not_null<QEvent*> e) {
 		if (e->type() == QEvent::ContextMenu && showMenu()) {
-			return Core::EventFilter::Result::Cancel;
+			return base::EventFilterResult::Cancel;
 		}
-		return Core::EventFilter::Result::Continue;
+		return base::EventFilterResult::Continue;
 	});
 }
diff --git a/Telegram/SourceFiles/core/event_filter.cpp b/Telegram/SourceFiles/core/event_filter.cpp
deleted file mode 100644
index 37e3e7cf33..0000000000
--- a/Telegram/SourceFiles/core/event_filter.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-This file is part of Telegram Desktop,
-the official desktop application for the Telegram messaging service.
-
-For license and copyright information please follow this link:
-https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
-*/
-#include "core/event_filter.h"
-
-namespace Core {
-
-EventFilter::EventFilter(
-	not_null<QObject*> parent,
-	not_null<QObject*> object,
-	Fn<EventFilter::Result(not_null<QEvent*>)> filter)
-: QObject(parent)
-, _filter(std::move(filter)) {
-	object->installEventFilter(this);
-}
-
-bool EventFilter::eventFilter(QObject *watched, QEvent *event) {
-	return (_filter(event) == Result::Cancel);
-}
-
-not_null<QObject*> InstallEventFilter(
-		not_null<QObject*> object,
-		Fn<EventFilter::Result(not_null<QEvent*>)> filter) {
-	return InstallEventFilter(object, object, std::move(filter));
-}
-
-not_null<QObject*> InstallEventFilter(
-		not_null<QObject*> context,
-		not_null<QObject*> object,
-		Fn<EventFilter::Result(not_null<QEvent*>)> filter) {
-	return new EventFilter(context, object, std::move(filter));
-}
-
-} // namespace Core
diff --git a/Telegram/SourceFiles/core/event_filter.h b/Telegram/SourceFiles/core/event_filter.h
deleted file mode 100644
index d6c847af2e..0000000000
--- a/Telegram/SourceFiles/core/event_filter.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
-This file is part of Telegram Desktop,
-the official desktop application for the Telegram messaging service.
-
-For license and copyright information please follow this link:
-https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
-*/
-#pragma once
-
-namespace Core {
-
-class EventFilter : public QObject {
-public:
-	enum Result {
-		Continue,
-		Cancel,
-	};
-
-	EventFilter(
-		not_null<QObject*> parent,
-		not_null<QObject*> object,
-		Fn<Result(not_null<QEvent*>)> filter);
-
-protected:
-	bool eventFilter(QObject *watched, QEvent *event);
-
-private:
-	Fn<Result(not_null<QEvent*>)> _filter;
-
-};
-
-not_null<QObject*> InstallEventFilter(
-	not_null<QObject*> object,
-	Fn<EventFilter::Result(not_null<QEvent*>)> filter);
-
-not_null<QObject*> InstallEventFilter(
-	not_null<QObject*> context,
-	not_null<QObject*> object,
-	Fn<EventFilter::Result(not_null<QEvent*>)> filter);
-
-} // namespace Core
diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp
index 020dfed4cc..86b305d83b 100644
--- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp
+++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp
@@ -23,8 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "mainwidget.h"
 #include "main/main_session.h"
 #include "apiwrap.h"
+#include "base/event_filter.h"
 #include "core/application.h"
-#include "core/event_filter.h"
 #include "core/update_checker.h"
 #include "boxes/peer_list_box.h"
 #include "boxes/peers/edit_participants_box.h"
@@ -314,13 +314,13 @@ void Widget::setupScrollUpButton() {
 		}
 		scrollToTop();
 	});
-	Core::InstallEventFilter(_scrollToTop, [=](not_null<QEvent*> event) {
+	base::install_event_filter(_scrollToTop, [=](not_null<QEvent*> event) {
 		if (event->type() != QEvent::Wheel) {
-			return Core::EventFilter::Result::Continue;
+			return base::EventFilterResult::Continue;
 		}
 		return _scroll->viewportEvent(event)
-			? Core::EventFilter::Result::Cancel
-			: Core::EventFilter::Result::Continue;
+			? base::EventFilterResult::Cancel
+			: base::EventFilterResult::Continue;
 	});
 	updateScrollUpVisibility();
 }
diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp
index c1bd89f430..20fbd79a01 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "boxes/share_box.h"
 #include "boxes/edit_caption_box.h"
 #include "core/file_utilities.h"
-#include "core/event_filter.h"
 #include "ui/toast/toast.h"
 #include "ui/special_buttons.h"
 #include "ui/emoji_config.h"
@@ -28,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/image/image.h"
 #include "ui/special_buttons.h"
 #include "inline_bots/inline_bot_result.h"
+#include "base/event_filter.h"
 #include "base/unixtime.h"
 #include "data/data_drafts.h"
 #include "data/data_session.h"
@@ -680,11 +680,11 @@ void HistoryWidget::initTabbedSelector() {
 
 	const auto selector = controller()->tabbedSelector();
 
-	Core::InstallEventFilter(this, selector, [=](not_null<QEvent*> e) {
+	base::install_event_filter(this, selector, [=](not_null<QEvent*> e) {
 		if (_tabbedPanel && e->type() == QEvent::ParentChange) {
 			setTabbedPanel(nullptr);
 		}
-		return Core::EventFilter::Result::Continue;
+		return base::EventFilterResult::Continue;
 	});
 
 	selector->emojiChosen(
diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp
index 41e8e143ec..7bb12d9664 100644
--- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp
@@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/special_buttons.h"
 #include "ui/ui_utility.h"
 #include "lang/lang_keys.h"
-#include "core/event_filter.h"
+#include "base/event_filter.h"
 #include "base/qt_signal_producer.h"
 #include "history/history.h"
 #include "chat_helpers/tabbed_panel.h"
@@ -228,11 +228,11 @@ void ComposeControls::initTabbedSelector() {
 	const auto selector = _window->tabbedSelector();
 	const auto wrap = _wrap.get();
 
-	Core::InstallEventFilter(wrap, selector, [=](not_null<QEvent*> e) {
+	base::install_event_filter(wrap, selector, [=](not_null<QEvent*> e) {
 		if (_tabbedPanel && e->type() == QEvent::ParentChange) {
 			setTabbedPanel(nullptr);
 		}
-		return Core::EventFilter::Result::Continue;
+		return base::EventFilterResult::Continue;
 	});
 
 	selector->emojiChosen(
diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp
index e1409ad36b..6b9d7fbd3a 100644
--- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp
@@ -27,7 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "boxes/send_files_box.h"
 #include "window/window_session_controller.h"
 #include "window/window_peer_menu.h"
-#include "core/event_filter.h"
+#include "base/event_filter.h"
 #include "core/file_utilities.h"
 #include "main/main_session.h"
 #include "data/data_session.h"
@@ -551,13 +551,13 @@ void ScheduledWidget::setupScrollDownButton() {
 	_scrollDown->setClickedCallback([=] {
 		scrollDownClicked();
 	});
-	Core::InstallEventFilter(_scrollDown, [=](not_null<QEvent*> event) {
+	base::install_event_filter(_scrollDown, [=](not_null<QEvent*> event) {
 		if (event->type() != QEvent::Wheel) {
-			return Core::EventFilter::Result::Continue;
+			return base::EventFilterResult::Continue;
 		}
 		return _scroll->viewportEvent(event)
-			? Core::EventFilter::Result::Cancel
-			: Core::EventFilter::Result::Continue;
+			? base::EventFilterResult::Cancel
+			: base::EventFilterResult::Continue;
 	});
 	updateScrollDownVisibility();
 }
diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp
index 60cf874412..31d5af17fb 100644
--- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp
+++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp
@@ -26,8 +26,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "storage/localstorage.h"
 #include "core/file_utilities.h"
 #include "core/application.h"
-#include "core/event_filter.h"
 #include "lang/lang_keys.h"
+#include "base/event_filter.h"
 #include "base/zlib_help.h"
 #include "base/unixtime.h"
 #include "data/data_session.h"
@@ -717,15 +717,15 @@ void CreateForExistingBox(
 		box->closeBox();
 		StartEditor(window, cloud);
 	};
-	Core::InstallEventFilter(box, box, [=](not_null<QEvent*> event) {
+	base::install_event_filter(box, box, [=](not_null<QEvent*> event) {
 		if (event->type() == QEvent::KeyPress) {
 			const auto key = static_cast<QKeyEvent*>(event.get())->key();
 			if (key == Qt::Key_Enter || key == Qt::Key_Return) {
 				done();
-				return Core::EventFilter::Result::Cancel;
+				return base::EventFilterResult::Cancel;
 			}
 		}
-		return Core::EventFilter::Result::Continue;
+		return base::EventFilterResult::Continue;
 	});
 	box->addButton(tr::lng_theme_editor_create(), done);
 	box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
diff --git a/Telegram/gyp/telegram/sources.txt b/Telegram/gyp/telegram/sources.txt
index 1a7fecd2ba..effb6c0ed0 100644
--- a/Telegram/gyp/telegram/sources.txt
+++ b/Telegram/gyp/telegram/sources.txt
@@ -150,8 +150,6 @@
 <(src_loc)/core/crash_report_window.h
 <(src_loc)/core/crash_reports.cpp
 <(src_loc)/core/crash_reports.h
-<(src_loc)/core/event_filter.cpp
-<(src_loc)/core/event_filter.h
 <(src_loc)/core/file_utilities.cpp
 <(src_loc)/core/file_utilities.h
 <(src_loc)/core/launcher.cpp
diff --git a/Telegram/lib_base b/Telegram/lib_base
index ec7852a1cc..be55609960 160000
--- a/Telegram/lib_base
+++ b/Telegram/lib_base
@@ -1 +1 @@
-Subproject commit ec7852a1cc36c45550074cd98f292f61f056ecf2
+Subproject commit be556099605f1ee83e3ca444b75dd90b950b6a36