From 4276b6cce069f62877c3b37c0280352f03fa68c2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 15 Jul 2021 14:12:38 +0300 Subject: [PATCH] Use rpl for Window::Theme::Background updates. --- Telegram/SourceFiles/apiwrap.cpp | 2 +- Telegram/SourceFiles/apiwrap.h | 2 +- Telegram/SourceFiles/app.cpp | 13 +------ Telegram/SourceFiles/boxes/add_contact_box.h | 8 +--- Telegram/SourceFiles/boxes/background_box.cpp | 21 +++++++---- .../boxes/background_preview_box.cpp | 10 ++--- .../boxes/background_preview_box.h | 5 +-- Telegram/SourceFiles/boxes/confirm_box.h | 2 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 11 +++--- Telegram/SourceFiles/boxes/peer_list_box.h | 4 +- .../boxes/peers/add_participants_box.h | 5 +-- Telegram/SourceFiles/boxes/share_box.cpp | 12 +++--- .../SourceFiles/boxes/sticker_set_box.cpp | 2 +- Telegram/SourceFiles/boxes/stickers_box.h | 2 +- .../SourceFiles/calls/calls_box_controller.h | 2 +- Telegram/SourceFiles/calls/calls_instance.h | 2 +- .../chat_helpers/field_autocomplete.cpp | 5 +-- .../chat_helpers/stickers_list_widget.h | 4 +- .../chat_helpers/tabbed_selector.h | 2 +- Telegram/SourceFiles/core/changelogs.cpp | 2 +- Telegram/SourceFiles/core/changelogs.h | 2 +- Telegram/SourceFiles/core/core_settings.cpp | 1 - .../SourceFiles/data/data_cloud_themes.cpp | 3 +- Telegram/SourceFiles/data/data_session.cpp | 2 +- .../dialogs/dialogs_inner_widget.cpp | 1 - .../dialogs/dialogs_inner_widget.h | 2 +- .../admin_log/history_admin_log_section.h | 5 ++- .../SourceFiles/history/history_widget.cpp | 10 ++--- Telegram/SourceFiles/history/history_widget.h | 2 - .../view/history_view_service_message.cpp | 21 +++++++---- .../view/history_view_service_message.h | 2 - .../view/history_view_top_bar_widget.h | 2 +- .../media/history_view_theme_document.cpp | 2 +- .../info_common_groups_inner_widget.cpp | 2 +- .../info/media/info_media_list_widget.cpp | 10 ++--- Telegram/SourceFiles/intro/intro_step.cpp | 8 +--- Telegram/SourceFiles/main/main_session.cpp | 2 - Telegram/SourceFiles/main/main_session.h | 4 +- Telegram/SourceFiles/mainwidget.cpp | 16 +++----- Telegram/SourceFiles/mainwidget.h | 1 - Telegram/SourceFiles/mainwindow.cpp | 9 +++-- .../player/media_player_volume_controller.h | 2 +- .../mtproto/dedicated_file_loader.h | 2 +- .../platform/mac/main_window_mac.mm | 10 ++--- .../touchbar/items/mac_pinned_chats_item.mm | 8 +--- .../platform/win/main_window_win.cpp | 12 +++--- .../SourceFiles/profile/profile_back_button.h | 2 +- .../profile/profile_block_widget.h | 2 +- .../SourceFiles/settings/settings_chat.cpp | 15 +++----- .../settings/settings_privacy_controllers.cpp | 4 +- .../settings/settings_privacy_controllers.h | 4 +- .../SourceFiles/ui/effects/round_checkbox.cpp | 20 +++------- Telegram/SourceFiles/window/main_window.cpp | 11 ++---- Telegram/SourceFiles/window/main_window.h | 2 +- .../window/notifications_manager_default.cpp | 31 +++++++--------- .../window/notifications_manager_default.h | 2 +- .../window/themes/window_theme.cpp | 37 ++++++++++++------- .../SourceFiles/window/themes/window_theme.h | 14 +++++-- .../window/themes/window_theme_editor.cpp | 10 +++-- .../window/themes/window_theme_preview.cpp | 1 - .../window/themes/window_theme_warning.cpp | 4 +- .../themes/window_themes_cloud_list.cpp | 6 +-- .../window/window_connecting_widget.cpp | 15 +++----- .../SourceFiles/window/window_main_menu.cpp | 24 ++++++------ .../SourceFiles/window/window_main_menu.h | 2 +- .../SourceFiles/window/window_media_preview.h | 2 +- 66 files changed, 203 insertions(+), 262 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 549749af3..cea8377a2 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -37,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_cloud_themes.h" #include "data/data_chat_filters.h" #include "data/data_histories.h" +#include "data/data_wall_paper.h" #include "data/stickers/data_stickers.h" #include "dialogs/dialogs_key.h" #include "core/core_cloud_password.h" @@ -62,7 +63,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager.h" #include "window/window_lock_widgets.h" #include "window/window_session_controller.h" -#include "window/themes/window_theme.h" #include "inline_bots/inline_bot_result.h" #include "chat_helpers/message_field.h" #include "ui/item_text_options.h" diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 8b31f82f0..9c3a58287 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -108,7 +108,7 @@ QString RequestKey(Types &&...values) { } // namespace Api -class ApiWrap : public MTP::Sender, private base::Subscriber { +class ApiWrap final : public MTP::Sender { public: using SendAction = Api::SendAction; using MessageToSend = Api::MessageToSend; diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index f495c327b..70c0fc178 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_location_manager.h" #include "history/history_item_components.h" -#include "history/view/history_view_service_message.h" +#include "history/view/history_view_element.h" #include "media/audio/media_audio.h" #include "ui/image/image.h" #include "ui/cached_round_corners.h" @@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "core/sandbox.h" #include "core/application.h" -#include "window/themes/window_theme.h" #include "window/notifications_manager.h" #include "window/window_controller.h" #include "platform/platform_notifications_manager.h" @@ -99,16 +98,6 @@ namespace App { void initMedia() { Ui::StartCachedCorners(); - - using Update = Window::Theme::BackgroundUpdate; - static auto subscription = Window::Theme::Background()->add_subscription([](const Update &update) { - if (update.paletteChanged()) { - if (const auto m = App::main()) { // multi good - m->updateScrollColors(); - } - HistoryView::serviceColorsUpdated(); - } - }); } void deinitMedia() { diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index bda2c9d92..c58133504 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -145,9 +145,7 @@ private: }; -class SetupChannelBox final - : public Ui::BoxContent - , private base::Subscriber { +class SetupChannelBox final : public Ui::BoxContent { public: SetupChannelBox( QWidget*, @@ -244,9 +242,7 @@ private: }; -class RevokePublicLinkBox final - : public Ui::BoxContent - , private base::Subscriber { +class RevokePublicLinkBox final : public Ui::BoxContent { public: RevokePublicLinkBox( QWidget*, diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 965840acc..43d06d53a 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/background_preview_box.h" #include "boxes/confirm_box.h" #include "window/window_session_controller.h" +#include "window/themes/window_theme.h" #include "styles/style_overview.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -55,9 +56,7 @@ QImage TakeMiddleSample(QImage original, QSize size) { } // namespace -class BackgroundBox::Inner final - : public Ui::RpWidget - , private base::Subscriber { +class BackgroundBox::Inner final : public Ui::RpWidget { public: Inner( QWidget *parent, @@ -203,16 +202,22 @@ BackgroundBox::Inner::Inner( ) | rpl::start_with_next([=] { update(); }, lifetime()); + + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _check->invalidateCache(); + }, lifetime()); + using Update = Window::Theme::BackgroundUpdate; - subscribe(Window::Theme::Background(), [=](const Update &update) { - if (update.paletteChanged()) { - _check->invalidateCache(); - } else if (update.type == Update::Type::New) { + Window::Theme::Background()->updates( + ) | rpl::start_with_next([=](const Update &update) { + if (update.type == Update::Type::New) { sortPapers(); requestPapers(); this->update(); } - }); + }, lifetime()); + setMouseTracking(true); } diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 4f78d2ebb..a85eb58e8 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -99,12 +99,10 @@ private: }; ServiceCheck::Generator::Generator() { - *_lifetime.make_state() = Window::Theme::Background( - )->add_subscription([=](const Window::Theme::BackgroundUpdate &update) { - if (update.paletteChanged()) { - invalidate(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + invalidate(); + }, _lifetime); } auto ServiceCheck::Generator::framesForStyle( diff --git a/Telegram/SourceFiles/boxes/background_preview_box.h b/Telegram/SourceFiles/boxes/background_preview_box.h index 28d45b659..e530f99bb 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -9,11 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "base/binary_guard.h" -#include "window/themes/window_theme.h" #include "history/admin_log/history_admin_log_item.h" #include "history/view/history_view_element.h" #include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" +#include "data/data_wall_paper.h" namespace Data { class DocumentMedia; @@ -29,8 +29,7 @@ class Checkbox; class BackgroundPreviewBox : public Ui::BoxContent - , private HistoryView::SimpleElementDelegate - , private base::Subscriber { + , private HistoryView::SimpleElementDelegate { public: BackgroundPreviewBox( QWidget*, diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index 22ebb6b60..ca0a2cbe2 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -141,7 +141,7 @@ public: }; -class MaxInviteBox : public Ui::BoxContent, private base::Subscriber { +class MaxInviteBox final : public Ui::BoxContent { public: MaxInviteBox(QWidget*, not_null channel); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index f78f25a81..6b9bb077d 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_changes.h" #include "base/unixtime.h" -#include "window/themes/window_theme.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_dialogs.h" @@ -738,11 +737,11 @@ PeerListContent::PeerListContent( } }, lifetime()); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { - if (update.paletteChanged()) { - invalidatePixmapsCache(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + invalidatePixmapsCache(); + }, lifetime()); + _repaintByStatus.setCallback([this] { update(); }); } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 4991b11b0..ce2d6a62a 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -527,9 +527,7 @@ struct PeerListState { QString searchQuery; }; -class PeerListContent - : public Ui::RpWidget - , private base::Subscriber { +class PeerListContent : public Ui::RpWidget { public: PeerListContent( QWidget *parent, diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index b2f64dd3f..ba9a9da1c 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -73,7 +73,6 @@ private: // with search + contacts search + global search. class AddSpecialBoxController : public PeerListController - , private base::Subscriber , public base::has_weak_ptr { public: using Role = ParticipantsBoxController::Role; @@ -146,9 +145,7 @@ protected: }; // Finds chat/channel members, then contacts, then global search results. -class AddSpecialBoxSearchController - : public PeerListSearchController - , private base::Subscriber { +class AddSpecialBoxSearchController : public PeerListSearchController { public: using Role = ParticipantsBoxController::Role; diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 8c6cb34b8..337aca662 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_message.h" #include "history/view/history_view_schedule_box.h" -#include "window/themes/window_theme.h" #include "window/window_session_controller.h" #include "boxes/peer_list_box.h" #include "chat_helpers/emoji_suggestions_widget.h" @@ -42,7 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" #include "styles/style_chat.h" -class ShareBox::Inner final : public Ui::RpWidget, private base::Subscriber { +class ShareBox::Inner final : public Ui::RpWidget { public: Inner(QWidget *parent, const Descriptor &descriptor); @@ -598,11 +597,10 @@ ShareBox::Inner::Inner(QWidget *parent, const Descriptor &descriptor) update(); }, lifetime()); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { - if (update.paletteChanged()) { - invalidateCache(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + invalidateCache(); + }, lifetime()); } void ShareBox::Inner::invalidateCache() { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index fdf774d42..74c3a84dd 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -55,7 +55,7 @@ using SetFlag = Data::StickersSetFlag; } // namespace -class StickerSetBox::Inner : public Ui::RpWidget, private base::Subscriber { +class StickerSetBox::Inner final : public Ui::RpWidget { public: Inner( QWidget *parent, diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 75b549bc2..472b6b12d 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -49,7 +49,7 @@ namespace Stickers { class Set; } // namespace Stickers -class StickersBox final : public Ui::BoxContent, private base::Subscriber { +class StickersBox final : public Ui::BoxContent { public: enum class Section { Installed, diff --git a/Telegram/SourceFiles/calls/calls_box_controller.h b/Telegram/SourceFiles/calls/calls_box_controller.h index a4bd41804..d23cff5d5 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.h +++ b/Telegram/SourceFiles/calls/calls_box_controller.h @@ -16,7 +16,7 @@ class SessionController; namespace Calls { -class BoxController : public PeerListController, private base::Subscriber { +class BoxController : public PeerListController { public: explicit BoxController(not_null window); diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index ff1f51c9c..6ab7e937c 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -43,7 +43,7 @@ class GroupCall; class Panel; struct DhConfig; -class Instance : private base::Subscriber, public base::has_weak_ptr { +class Instance final : public base::has_weak_ptr { public: Instance(); ~Instance(); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 464a73298..0f83918ab 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -44,10 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include -class FieldAutocomplete::Inner final - : public Ui::RpWidget - , private base::Subscriber { - +class FieldAutocomplete::Inner final : public Ui::RpWidget { public: struct ScrollTo { int top; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index cfc0d853d..49a24b440 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -43,9 +43,7 @@ namespace ChatHelpers { struct StickerIcon; -class StickersListWidget - : public TabbedSelector::Inner - , private base::Subscriber { +class StickersListWidget final : public TabbedSelector::Inner { public: StickersListWidget( QWidget *parent, diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index ff5b7fad5..74bbcb4d2 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -51,7 +51,7 @@ class EmojiListWidget; class StickersListWidget; class GifsListWidget; -class TabbedSelector : public Ui::RpWidget, private base::Subscriber { +class TabbedSelector : public Ui::RpWidget { public: struct FileChosen { not_null document; diff --git a/Telegram/SourceFiles/core/changelogs.cpp b/Telegram/SourceFiles/core/changelogs.cpp index bc539b66f..0f0917017 100644 --- a/Telegram/SourceFiles/core/changelogs.cpp +++ b/Telegram/SourceFiles/core/changelogs.cpp @@ -143,7 +143,7 @@ std::map BetaLogs() { "- Use Direct3D 9 backend in ANGLE by default (Windows).\n" "- Fix \"Show in Finder\" not focusing the Finder window (macOS).\n" - + "- Use GTK from a child process (Linux).\n" }, }; diff --git a/Telegram/SourceFiles/core/changelogs.h b/Telegram/SourceFiles/core/changelogs.h index f888fa468..ba5e312ff 100644 --- a/Telegram/SourceFiles/core/changelogs.h +++ b/Telegram/SourceFiles/core/changelogs.h @@ -18,7 +18,7 @@ namespace Core { [[nodiscard]] QString FormatVersionDisplay(int version); [[nodiscard]] QString FormatVersionPrecise(int version); -class Changelogs : public base::has_weak_ptr, private base::Subscriber { +class Changelogs final : public base::has_weak_ptr { public: Changelogs(not_null session, int oldVersion); diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index b80f2a90f..83ceb0803 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/send_files_box.h" #include "ui/widgets/input_fields.h" #include "storage/serialize_common.h" -#include "window/themes/window_theme.h" #include "window/section_widget.h" #include "base/platform/base_platform_info.h" #include "webrtc/webrtc_create_adm.h" diff --git a/Telegram/SourceFiles/data/data_cloud_themes.cpp b/Telegram/SourceFiles/data/data_cloud_themes.cpp index 8d719c4e9..ee59cac2b 100644 --- a/Telegram/SourceFiles/data/data_cloud_themes.cpp +++ b/Telegram/SourceFiles/data/data_cloud_themes.cpp @@ -63,8 +63,7 @@ void CloudThemes::setupReload() { if (needReload()) { _reloadCurrentTimer.callOnce(kFirstReloadTimeout); } - base::ObservableViewer( - *Background() + Background()->updates( ) | rpl::filter([](const BackgroundUpdate &update) { return (update.type == BackgroundUpdate::Type::ApplyingTheme); }) | rpl::map([=] { diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 5b50e62de..4fcdb3e49 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -34,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/audio/media_audio.h" #include "boxes/abstract_box.h" #include "passport/passport_form_controller.h" -#include "window/themes/window_theme.h" #include "lang/lang_keys.h" // tr::lng_deleted(tr::now) in user name #include "data/stickers/data_stickers.h" #include "data/data_changes.h" @@ -48,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_web_page.h" +#include "data/data_wall_paper.h" #include "data/data_game.h" #include "data/data_poll.h" #include "data/data_chat_filters.h" diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index fad66090a..2e8128349 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -38,7 +38,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "storage/storage_account.h" #include "apiwrap.h" -#include "window/themes/window_theme.h" #include "main/main_session.h" #include "main/main_session_settings.h" #include "window/notifications_manager.h" diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index c9e0fd0a3..e830dbece 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -62,7 +62,7 @@ enum class WidgetState { Filtered, }; -class InnerWidget final : public Ui::RpWidget, private base::Subscriber { +class InnerWidget final : public Ui::RpWidget { Q_OBJECT public: diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h index 38c915bd4..791ffd150 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.h @@ -45,7 +45,10 @@ inline bool operator!=(const FilterValue &a, const FilterValue &b) { class Widget final : public Window::SectionWidget { public: - Widget(QWidget *parent, not_null controller, not_null channel); + Widget( + QWidget *parent, + not_null controller, + not_null channel); not_null channel() const; Dialogs::RowDescriptor activeChat() const override; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 700275756..29660f306 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -111,7 +111,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/unread_badge.h" #include "main/main_session.h" #include "main/main_session_settings.h" -#include "window/themes/window_theme.h" #include "window/notifications_manager.h" #include "window/window_adaptive.h" #include "window/window_controller.h" @@ -304,7 +303,10 @@ HistoryWidget::HistoryWidget( _scroll->hide(); _kbScroll->hide(); - updateScrollColors(); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _scroll->updateBars(); + }, lifetime()); _historyDown->installEventFilter(this); _unreadMentions->installEventFilter(this); @@ -4698,10 +4700,6 @@ void HistoryWidget::itemEdited(not_null item) { } } -void HistoryWidget::updateScrollColors() { - _scroll->updateBars(); -} - MsgId HistoryWidget::replyToId() const { return _replyToId ? _replyToId : (_kbReplyTo ? _kbReplyTo->id : 0); } diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index e42bae30b..99e24905e 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -188,8 +188,6 @@ public: MessageIdsList getSelectedItems() const; void itemEdited(not_null item); - void updateScrollColors(); - void replyToMessage(FullMsgId itemId); void replyToMessage(not_null item); void editMessage(FullMsgId itemId); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index d513e30bd..0090f59f4 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -43,6 +43,15 @@ enum CornerHorizontalSide { class ServiceMessageStyleData : public Data::AbstractStructure { public: + ServiceMessageStyleData() { + style::PaletteChanged( + ) | rpl::start_with_next([=] { + for (auto &corner : corners) { + corner = QPixmap(); + } + }, _lifetime); + } + // circle[CircleMask value] QImage circle[2]; @@ -50,6 +59,10 @@ public: QPixmap corners[8]; base::flat_map, QPixmap> overridenCorners; + +private: + rpl::lifetime _lifetime; + }; Data::GlobalStructurePointer serviceMessageStyle; @@ -420,14 +433,6 @@ QVector ServiceMessagePainter::countLineWidths(const Ui::Text::String &text return lineWidths; } -void serviceColorsUpdated() { - if (serviceMessageStyle) { - for (auto &corner : serviceMessageStyle->corners) { - corner = QPixmap(); - } - } -} - Service::Service( not_null delegate, not_null data, diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.h b/Telegram/SourceFiles/history/view/history_view_service_message.h index 1295ae4e5..321222225 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.h +++ b/Telegram/SourceFiles/history/view/history_view_service_message.h @@ -126,6 +126,4 @@ private: }; -void serviceColorsUpdated(); - } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index ae6d0453c..9bd045a99 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -35,7 +35,7 @@ namespace HistoryView { class SendActionPainter; -class TopBarWidget : public Ui::RpWidget, private base::Subscriber { +class TopBarWidget final : public Ui::RpWidget { public: struct SelectedState { bool textSelected = false; diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index a71751dbf..2f19bf157 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -16,11 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document_media.h" #include "data/data_file_click_handler.h" #include "data/data_file_origin.h" +#include "data/data_wall_paper.h" #include "base/qthelp_url.h" #include "ui/text/format_values.h" #include "ui/cached_round_corners.h" #include "ui/ui_utility.h" -#include "window/themes/window_theme.h" #include "layout.h" // FullSelection #include "styles/style_chat.h" diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index 60d189da0..df925b4d2 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -27,7 +27,7 @@ namespace { constexpr auto kCommonGroupsPerPage = 40; constexpr auto kCommonGroupsSearchAfter = 20; -class ListController : public PeerListController , private base::Subscriber { +class ListController final : public PeerListController { public: ListController( not_null controller, diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index dc924a319..04768355d 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/view/history_view_cursor_state.h" #include "history/view/history_view_service_message.h" -#include "window/themes/window_theme.h" #include "window/window_session_controller.h" #include "window/window_peer_menu.h" #include "ui/widgets/popup_menu.h" @@ -626,12 +625,9 @@ Main::Session &ListWidget::session() const { void ListWidget::start() { _controller->setSearchEnabledByContent(false); - ObservableViewer( - *Window::Theme::Background() - ) | rpl::start_with_next([this](const auto &update) { - if (update.paletteChanged()) { - invalidatePaletteCache(); - } + style::PaletteChanged( + ) | rpl::start_with_next([=] { + invalidatePaletteCache(); }, lifetime()); session().downloaderTaskFinished( diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index ff8997d6e..df2d7c35d 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_chat_filters.h" #include "window/window_controller.h" -#include "window/themes/window_theme.h" #include "styles/style_intro.h" #include "styles/style_window.h" @@ -75,11 +74,8 @@ Step::Step( ? st::introCoverDescription : st::introDescription)) { hide(); - base::ObservableViewer( - *Window::Theme::Background() - ) | rpl::filter([](const Window::Theme::BackgroundUpdate &update) { - return update.paletteChanged(); - }) | rpl::start_with_next([=] { + style::PaletteChanged( + ) | rpl::start_with_next([=] { if (!_coverMask.isNull()) { _coverMask = QPixmap(); prepareCoverMask(); diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 3a732c0ce..1ebeba575 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -28,8 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/stickers/data_stickers.h" #include "window/window_session_controller.h" #include "window/window_lock_widgets.h" -#include "window/themes/window_theme.h" -//#include "platform/platform_specific.h" #include "base/unixtime.h" #include "calls/calls_instance.h" #include "support/support_helper.h" diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index cd29bcb5b..60a641584 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -59,9 +59,7 @@ class Account; class Domain; class SessionSettings; -class Session final - : public base::has_weak_ptr - , private base::Subscriber { +class Session final : public base::has_weak_ptr { public: Session( not_null account, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index a0c15092b..cce67eb09 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -242,7 +242,6 @@ MainWidget::MainWidget( , _cacheBackgroundTimer([=] { cacheBackground(); }) , _viewsIncrementTimer([=] { viewsIncrement(); }) , _changelogs(Core::Changelogs::Create(&controller->session())) { - updateScrollColors(); setupConnectingWidget(); connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); @@ -347,11 +346,13 @@ MainWidget::MainWidget( QCoreApplication::instance()->installEventFilter(this); using Update = Window::Theme::BackgroundUpdate; - subscribe(Window::Theme::Background(), [this](const Update &update) { - if (update.type == Update::Type::New || update.type == Update::Type::Changed) { + Window::Theme::Background()->updates( + ) | rpl::start_with_next([=](const Update &update) { + if (update.type == Update::Type::New + || update.type == Update::Type::Changed) { clearCachedBackground(); } - }); + }, lifetime()); subscribe(Media::Player::instance()->playerWidgetOver(), [this](bool over) { if (over) { @@ -1173,10 +1174,6 @@ QPixmap MainWidget::cachedBackground(const QRect &forRect, int &x, int &y) { return QPixmap(); } -void MainWidget::updateScrollColors() { - _history->updateScrollColors(); -} - void MainWidget::setChatBackground( const Data::WallPaper &background, QImage &&image) { @@ -1197,8 +1194,7 @@ void MainWidget::setChatBackground( checkChatBackground(); const auto tile = Data::IsLegacy1DefaultWallPaper(background); - using Update = Window::Theme::BackgroundUpdate; - Window::Theme::Background()->notify(Update(Update::Type::Start, tile)); + Window::Theme::Background()->downloadingStarted(tile); } bool MainWidget::isReadyChatBackground( diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index af80f5fd2..7d289fa08 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -190,7 +190,6 @@ public: void searchMessages(const QString &query, Dialogs::Key inChat); QPixmap cachedBackground(const QRect &forRect, int &x, int &y); - void updateScrollColors(); void setChatBackground( const Data::WallPaper &background, diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index c12f73702..05fcef530 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -98,9 +98,12 @@ MainWindow::MainWindow(not_null controller) setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { + using Window::Theme::BackgroundUpdate; + Window::Theme::Background()->updates( + ) | rpl::start_with_next([=](const BackgroundUpdate &data) { themeUpdated(data); - }); + }, lifetime()); + Core::App().passcodeLockChanges( ) | rpl::start_with_next([=] { updateGlobalMenu(); @@ -571,7 +574,7 @@ void MainWindow::themeUpdated(const Window::Theme::BackgroundUpdate &data) { using Type = Window::Theme::BackgroundUpdate::Type; // We delay animating theme warning because we want all other - // subscribers to receive paltte changed notification before any + // subscribers to receive palette changed notification before any // animations (that include pixmap caches with old palette values). if (data.type == Type::TestingTheme) { if (!_testingThemeWarning) { diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.h b/Telegram/SourceFiles/media/player/media_player_volume_controller.h index 1c3a60202..c5d35a70a 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.h +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.h @@ -25,7 +25,7 @@ class SessionController; namespace Media { namespace Player { -class VolumeController : public Ui::RpWidget, private base::Subscriber { +class VolumeController final : public Ui::RpWidget { public: VolumeController( QWidget *parent, diff --git a/Telegram/SourceFiles/mtproto/dedicated_file_loader.h b/Telegram/SourceFiles/mtproto/dedicated_file_loader.h index 4c13841db..605a4cac0 100644 --- a/Telegram/SourceFiles/mtproto/dedicated_file_loader.h +++ b/Telegram/SourceFiles/mtproto/dedicated_file_loader.h @@ -15,7 +15,7 @@ class Session; namespace MTP { -class WeakInstance : private QObject, private base::Subscriber { +class WeakInstance final : private QObject { public: explicit WeakInstance(base::weak_ptr session); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index a99cdf98c..aebe04d29 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager_default.h" #include "window/window_session_controller.h" #include "window/window_controller.h" -#include "window/themes/window_theme.h" #include "platform/mac/touchbar/mac_touchbar_manager.h" #include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" @@ -451,11 +450,10 @@ MainWindow::MainWindow(not_null controller) _hideAfterFullScreenTimer.setCallback([this] { hideAndDeactivate(); }); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { - if (data.paletteChanged()) { - _private->updateNativeTitle(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _private->updateNativeTitle(); + }, lifetime()); } void MainWindow::closeWithoutDestroy() { diff --git a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm index e2ab74355..72902ae10 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm @@ -30,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_dialogs.h" #include "ui/effects/animations.h" #include "ui/empty_userpic.h" -#include "window/themes/window_theme.h" #include "window/window_controller.h" #include "window/window_session_controller.h" @@ -718,11 +717,8 @@ TimeId CalculateOnlineTill(not_null peer) { const auto localGuard = _lifetime.make_state(); - base::ObservableViewer( - *Window::Theme::Background() - ) | rpl::filter([](const Window::Theme::BackgroundUpdate &update) { - return update.paletteChanged(); - }) | rpl::start_with_next([=] { + style::PaletteChanged( + ) | rpl::start_with_next([=] { crl::on_main(&(*localGuard), [=] { updateOnlineColor(); if (const auto f = _session->data().folderLoaded(ArchiveId)) { diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index c3cac0b2e..fcae28803 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -122,11 +122,12 @@ MainWindow::MainWindow(not_null controller) if (!kTaskbarCreatedMsgId) { kTaskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); } - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { - if (_shadow && update.paletteChanged()) { + style::PaletteChanged( + ) | rpl::start_with_next([=] { + if (_shadow) { _shadow->setColor(st::windowShadowFg->c); } - }); + }, lifetime()); setupNativeWindowFrame(); using namespace rpl::mappers; @@ -145,8 +146,7 @@ void MainWindow::setupNativeWindowFrame() { ); using BackgroundUpdate = Window::Theme::BackgroundUpdate; - auto paletteChanges = base::ObservableViewer( - *Window::Theme::Background() + auto themeChanges = Window::Theme::Background()->updates( ) | rpl::filter([=](const BackgroundUpdate &update) { return update.type == BackgroundUpdate::Type::ApplyingTheme; }) | rpl::to_empty; @@ -154,7 +154,7 @@ void MainWindow::setupNativeWindowFrame() { auto nightMode = rpl::single( rpl::empty_value() ) | rpl::then( - std::move(paletteChanges) + std::move(themeChanges) ) | rpl::map([=] { return Window::Theme::IsNightMode(); }) | rpl::distinct_until_changed(); diff --git a/Telegram/SourceFiles/profile/profile_back_button.h b/Telegram/SourceFiles/profile/profile_back_button.h index 98056ce9e..4c3ca7cea 100644 --- a/Telegram/SourceFiles/profile/profile_back_button.h +++ b/Telegram/SourceFiles/profile/profile_back_button.h @@ -15,7 +15,7 @@ class Session; namespace Profile { -class BackButton final : public Ui::AbstractButton, private base::Subscriber { +class BackButton final : public Ui::AbstractButton { public: BackButton( QWidget *parent, diff --git a/Telegram/SourceFiles/profile/profile_block_widget.h b/Telegram/SourceFiles/profile/profile_block_widget.h index ec593cac0..7bf06269f 100644 --- a/Telegram/SourceFiles/profile/profile_block_widget.h +++ b/Telegram/SourceFiles/profile/profile_block_widget.h @@ -14,7 +14,7 @@ namespace Profile { class SectionMemento; -class BlockWidget : public Ui::RpWidget, protected base::Subscriber { +class BlockWidget : public Ui::RpWidget { public: BlockWidget(QWidget *parent, PeerData *peer, const QString &title); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 913b8af59..f2428b818 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -424,8 +424,7 @@ BackgroundRow::BackgroundRow( }); using Update = const Window::Theme::BackgroundUpdate; - base::ObservableViewer( - *Window::Theme::Background() + Window::Theme::Background()->updates( ) | rpl::filter([](const Update &update) { return (update.type == Update::Type::New || update.type == Update::Type::Start @@ -958,8 +957,7 @@ void SetupChatBackground( }, tile->lifetime()); using Update = const Window::Theme::BackgroundUpdate; - base::ObservableViewer( - *Window::Theme::Background() + Window::Theme::Background()->updates( ) | rpl::filter([](const Update &update) { return (update.type == Update::Type::Changed); }) | rpl::map([] { @@ -1089,8 +1087,7 @@ void SetupDefaultThemes( refreshColorizer(scheme.type); } - base::ObservableViewer( - *Background() + Background()->updates( ) | rpl::filter([](const BackgroundUpdate &update) { return (update.type == BackgroundUpdate::Type::ApplyingTheme); }) | rpl::map([=] { @@ -1254,9 +1251,9 @@ void SetupCloudThemes( editWrap->toggleOn(rpl::single(BackgroundUpdate( BackgroundUpdate::Type::ApplyingTheme, Background()->tile() - )) | rpl::then(base::ObservableViewer( - *Background() - )) | rpl::filter([](const BackgroundUpdate &update) { + )) | rpl::then( + Background()->updates() + ) | rpl::filter([](const BackgroundUpdate &update) { return (update.type == BackgroundUpdate::Type::ApplyingTheme); }) | rpl::map([=] { const auto userId = controller->session().userId(); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 3c4cdcef2..cfa37a7b3 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -47,9 +47,7 @@ namespace { constexpr auto kBlockedPerPage = 40; -class BlockPeerBoxController - : public ChatsListBoxController - , private base::Subscriber { +class BlockPeerBoxController final : public ChatsListBoxController { public: explicit BlockPeerBoxController(not_null session); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 0bcc31e8c..8173cc869 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -18,9 +18,7 @@ class SessionController; namespace Settings { -class BlockedBoxController - : public PeerListController - , private base::Subscriber { +class BlockedBoxController : public PeerListController { public: explicit BlockedBoxController( not_null window); diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index f07e81a5a..e0536010f 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/effects/round_checkbox.h" -#include "window/themes/window_theme.h" #include "ui/rp_widget.h" #include "ui/ui_utility.h" @@ -22,9 +21,12 @@ class CheckCaches : public QObject { public: CheckCaches(QObject *parent) : QObject(parent) { Expects(parent != nullptr); - } - void clear(); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _data.clear(); + }, _lifetime); + } QPixmap frame( const style::RoundCheckbox *st, @@ -54,6 +56,7 @@ private: float64 progress); std::map _data; + rpl::lifetime _lifetime; }; @@ -134,10 +137,6 @@ QRect WideDestRect( return QRect(iconLeft, iconTop, iconSize, iconSize); } -void CheckCaches::clear() { - _data.clear(); -} - int CheckCaches::countFramesCount(const style::RoundCheckbox *st) { return (st->duration / AnimationTimerDelta) + 1; } @@ -248,13 +247,6 @@ CheckCaches *FrameCaches() { } const auto result = new CheckCaches(QCoreApplication::instance()); Instance = result; - const auto subscription = Ui::CreateChild(result); - *subscription = Window::Theme::Background()->add_subscription([=]( - const Window::Theme::BackgroundUpdate &update) { - if (update.paletteChanged()) { - FrameCaches()->clear(); - } - }); return result; } diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index f22a5d6a0..4ac93f8f1 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "ui/platform/ui_platform_utility.h" #include "history/history.h" -#include "window/themes/window_theme.h" #include "window/window_session_controller.h" #include "window/window_lock_widgets.h" #include "window/window_outdated_bar.h" @@ -165,12 +164,10 @@ MainWindow::MainWindow(not_null controller) , _outdated(CreateOutdatedBar(this)) , _body(this) , _titleText(qsl("Telegram")) { - subscribe(Theme::Background(), [=]( - const Theme::BackgroundUpdate &data) { - if (data.paletteChanged()) { - updatePalette(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + updatePalette(); + }, lifetime()); Core::App().unreadBadgeChanges( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index cf545158b..afc365093 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -37,7 +37,7 @@ QImage LoadLogoNoMargin(); QIcon CreateIcon(Main::Session *session = nullptr); void ConvertIconToBlack(QImage &image); -class MainWindow : public Ui::RpWidget, protected base::Subscriber { +class MainWindow : public Ui::RpWidget { public: explicit MainWindow(not_null controller); virtual ~MainWindow(); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index cd7d6ac96..02bd82d75 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/empty_userpic.h" #include "ui/ui_utility.h" #include "dialogs/dialogs_layout.h" -#include "window/themes/window_theme.h" #include "window/window_controller.h" #include "storage/file_download.h" #include "main/main_session.h" @@ -641,18 +640,17 @@ Notification::Notification( prepareActionsCache(); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { - if (data.paletteChanged()) { - updateNotifyDisplay(); - if (!_buttonsCache.isNull()) { - prepareActionsCache(); - } - update(); - if (_background) { - _background->update(); - } + style::PaletteChanged( + ) | rpl::start_with_next([=] { + updateNotifyDisplay(); + if (!_buttonsCache.isNull()) { + prepareActionsCache(); } - }); + update(); + if (_background) { + _background->update(); + } + }, lifetime()); show(); } @@ -1077,11 +1075,10 @@ HideAllButton::HideAllButton( hide(); createWinId(); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { - if (data.paletteChanged()) { - update(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); show(); } diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index b92b4e393..1f45b18b8 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -132,7 +132,7 @@ private: namespace internal { -class Widget : public Ui::RpWidget, protected base::Subscriber { +class Widget : public Ui::RpWidget { public: enum class Direction { Up, diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index d9f6208ab..c47b90d4c 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -551,11 +551,12 @@ void ChatBackground::initialRead() { void ChatBackground::start() { saveAdjustableColors(); - subscribe(this, [=](const BackgroundUpdate &update) { + _updates.events( + ) | rpl::start_with_next([=](const BackgroundUpdate &update) { if (update.paletteChanged()) { style::NotifyPaletteChanged(); } - }); + }, _lifetime); initialRead(); @@ -620,7 +621,7 @@ void ChatBackground::checkUploadWallPaper() { if (const auto paper = Data::WallPaper::Create(_session, result)) { setPaper(*paper); writeNewBackgroundSettings(); - notify(BackgroundUpdate(BackgroundUpdate::Type::New, tile())); + _updates.fire({ BackgroundUpdate::Type::New, tile() }); } }).send(); }); @@ -705,10 +706,10 @@ void ChatBackground::set(const Data::WallPaper &paper, QImage image) { && !_pixmap.isNull() && !_pixmapForTiled.isNull())); - notify(BackgroundUpdate(BackgroundUpdate::Type::New, tile())); + _updates.fire({ BackgroundUpdate::Type::New, tile() }); // delayed? if (needResetAdjustable) { - notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); - notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); + _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() }); + _updates.fire({ BackgroundUpdate::Type::ApplyingTheme, tile() }); } checkUploadWallPaper(); } @@ -883,7 +884,7 @@ void ChatBackground::setTile(bool tile) { && !Data::details::IsTestingDefaultWallPaper(_paper)) { Local::writeSettings(); } - notify(BackgroundUpdate(BackgroundUpdate::Type::Changed, tile)); + _updates.fire({ BackgroundUpdate::Type::Changed, tile }); // delayed? } } @@ -927,8 +928,8 @@ void ChatBackground::reset() { } else { set(Data::ThemeWallPaper()); restoreAdjustableColors(); - notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); - notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); + _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() }); + _updates.fire({ BackgroundUpdate::Type::ApplyingTheme, tile() }); } writeNewBackgroundSettings(); } @@ -990,7 +991,7 @@ void ChatBackground::setTestingTheme(Instance &&theme) { // Apply current background image so that service bg colors are recounted. set(_paper, std::move(_original)); } - notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); + _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() }); } void ChatBackground::setTestingDefaultTheme() { @@ -1000,7 +1001,7 @@ void ChatBackground::setTestingDefaultTheme() { saveForRevert(); set(Data::details::TestingDefaultWallPaper()); setTile(false); - notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); + _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() }); } void ChatBackground::keepApplied(const Object &object, bool write) { @@ -1027,7 +1028,7 @@ void ChatBackground::keepApplied(const Object &object, bool write) { writeNewBackgroundSettings(); } } - notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); + _updates.fire({ BackgroundUpdate::Type::ApplyingTheme, tile() }); } bool ChatBackground::isNonDefaultThemeOrBackground() { @@ -1068,7 +1069,15 @@ void ChatBackground::revert() { // Apply current background image so that service bg colors are recounted. set(_paper, std::move(_original)); } - notify(BackgroundUpdate(BackgroundUpdate::Type::RevertingTheme, tile()), true); + _updates.fire({ BackgroundUpdate::Type::RevertingTheme, tile() }); +} + +void ChatBackground::appliedEditedPalette() { + _updates.fire({ BackgroundUpdate::Type::ApplyingEdit, tile() }); +} + +void ChatBackground::downloadingStarted(bool tile) { + _updates.fire({ BackgroundUpdate::Type::Start, tile }); } void ChatBackground::setNightModeValue(bool nightMode) { @@ -1225,7 +1234,7 @@ bool ApplyEditedPalette(const QByteArray &content) { return false; } style::main_palette::apply(out.palette); - Background()->notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingEdit, Background()->tile()), true); + Background()->appliedEditedPalette(); return true; } diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index 0d38ecf14..598b53f1e 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -131,12 +131,14 @@ enum class ClearEditing { KeepChanges, }; -class ChatBackground - : public base::Observable - , private base::Subscriber { +class ChatBackground final { public: ChatBackground(); + [[nodiscard]] rpl::producer updates() const { + return _updates.events(); + } + void start(); // This method is allowed to (and should) be called before start(). @@ -159,6 +161,9 @@ public: void setTestingDefaultTheme(); void revert(); + void appliedEditedPalette(); + void downloadingStarted(bool tile); + [[nodiscard]] Data::WallPaper paper() const { return _paper; } @@ -227,6 +232,7 @@ private: friend bool IsNonDefaultBackground(); Main::Session *_session = nullptr; + rpl::event_stream _updates; Data::WallPaper _paper = Data::details::UninitializedWallPaper(); std::optional _paperColor; QImage _original; @@ -259,7 +265,7 @@ private: }; -ChatBackground *Background(); +[[nodiscard]] ChatBackground *Background(); void ComputeBackgroundRects(QRect wholeFill, QSize imageSize, QRect &to, QRect &from); diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index 0403e7dc3..b556b2a03 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -197,7 +197,7 @@ QString bytesToUtf8(QLatin1String bytes) { } // namespace -class Editor::Inner : public TWidget, private base::Subscriber { +class Editor::Inner : public Ui::RpWidget, private base::Subscriber { public: Inner(QWidget *parent, const QString &path); @@ -387,7 +387,8 @@ QByteArray StripCloudTextFields(const QByteArray &text) { return (start > 0) ? text.mid(start) : text; } -Editor::Inner::Inner(QWidget *parent, const QString &path) : TWidget(parent) +Editor::Inner::Inner(QWidget *parent, const QString &path) +: RpWidget(parent) , _path(path) , _existingRows(this, EditorBlock::Type::Existing, &_context) , _newRows(this, EditorBlock::Type::New, &_context) { @@ -410,7 +411,8 @@ Editor::Inner::Inner(QWidget *parent, const QString &path) : TWidget(parent) _scrollCallback(top, top + data.height); } }); - subscribe(Background(), [this](const BackgroundUpdate &update) { + Background()->updates( + ) | rpl::start_with_next([=](const BackgroundUpdate &update) { if (_applyingUpdate || !Background()->editingTheme()) { return; } @@ -422,7 +424,7 @@ Editor::Inner::Inner(QWidget *parent, const QString &path) : TWidget(parent) tr::lng_theme_editor_cant_change_theme(tr::now))); }); } - }); + }, lifetime()); } void Editor::Inner::recreateRows() { diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index 294db4211..484dff0bf 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "window/themes/window_theme_preview.h" -#include "window/themes/window_theme.h" #include "lang/lang_keys.h" #include "platform/platform_window_title.h" #include "ui/text/text_options.h" diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp index 13d86a951..af9e1af69 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp @@ -30,8 +30,8 @@ WarningWidget::WarningWidget(QWidget *parent) , _secondsLeft(kWaitBeforeRevertMs / 1000) , _keepChanges(this, tr::lng_theme_keep_changes(), st::defaultBoxButton) , _revert(this, tr::lng_theme_revert(), st::defaultBoxButton) { - _keepChanges->setClickedCallback([] { Window::Theme::KeepApplied(); }); - _revert->setClickedCallback([] { Window::Theme::Revert(); }); + _keepChanges->setClickedCallback([] { KeepApplied(); }); + _revert->setClickedCallback([] { Revert(); }); updateText(); } diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 2d721bd54..896e82e9e 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -340,9 +340,9 @@ void CloudList::setup() { auto themeChanges = rpl::single(BackgroundUpdate( BackgroundUpdate::Type::ApplyingTheme, Background()->tile() - )) | rpl::then(base::ObservableViewer( - *Background() - )) | rpl::filter([](const BackgroundUpdate &update) { + )) | rpl::then( + Background()->updates() + ) | rpl::filter([](const BackgroundUpdate &update) { return (update.type == BackgroundUpdate::Type::ApplyingTheme); }); diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index 1693c4a3b..06da3c872 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -16,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/core_settings.h" #include "core/update_checker.h" -#include "window/themes/window_theme.h" #include "boxes/connection_box.h" #include "boxes/abstract_box.h" #include "lang/lang_keys.h" @@ -112,9 +111,7 @@ private: }; -class ConnectionState::Widget::ProxyIcon - : public Ui::RpWidget - , private base::Subscriber { +class ConnectionState::Widget::ProxyIcon final : public Ui::RpWidget { public: ProxyIcon(QWidget *parent); @@ -143,12 +140,10 @@ ConnectionState::Widget::ProxyIcon::ProxyIcon(QWidget *parent) : RpWidget(parent st::connectingRadial.size.height(), st::connectingProxyOn.height())); - using namespace Window::Theme; - subscribe(Background(), [=](const BackgroundUpdate &update) { - if (update.paletteChanged()) { - refreshCacheImages(); - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + refreshCacheImages(); + }, lifetime()); refreshCacheImages(); } diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 307331a0a..3379e6589 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -138,9 +138,7 @@ void ShowCallsBox(not_null window) { namespace Window { -class MainMenu::AccountButton final - : public Ui::RippleButton - , public base::Subscriber { +class MainMenu::AccountButton final : public Ui::RippleButton { public: AccountButton(QWidget *parent, not_null account); @@ -209,12 +207,10 @@ MainMenu::AccountButton::AccountButton( + _st.itemPadding.bottom(); resize(width(), height); - subscribe(Window::Theme::Background(), [=]( - const Window::Theme::BackgroundUpdate &update) { - if (update.paletteChanged()) { - _userpicKey = {}; - } - }); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _userpicKey = {}; + }, lifetime()); rpl::single( rpl::empty_value() @@ -639,8 +635,10 @@ MainMenu::MainMenu( refreshMenu(); }, lifetime()); - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { - if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) { + using Window::Theme::BackgroundUpdate; + Window::Theme::Background()->updates( + ) | rpl::start_with_next([=](const BackgroundUpdate &update) { + if (update.type == BackgroundUpdate::Type::ApplyingTheme) { if (const auto action = *_nightThemeAction) { const auto nightMode = Window::Theme::IsNightMode(); if (action->isChecked() != nightMode) { @@ -649,10 +647,10 @@ MainMenu::MainMenu( } } } - if (update.type == Window::Theme::BackgroundUpdate::Type::New) { + if (update.type == BackgroundUpdate::Type::New) { refreshBackground(); } - }); + }, lifetime()); updatePhone(); initResetScaleButton(); } diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index 4866d6192..1ea7c1f2b 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -37,7 +37,7 @@ namespace Window { class SessionController; -class MainMenu : public Ui::LayerWidget, private base::Subscriber { +class MainMenu final : public Ui::LayerWidget { public: MainMenu(QWidget *parent, not_null controller); diff --git a/Telegram/SourceFiles/window/window_media_preview.h b/Telegram/SourceFiles/window/window_media_preview.h index a7d1283fd..e1480865c 100644 --- a/Telegram/SourceFiles/window/window_media_preview.h +++ b/Telegram/SourceFiles/window/window_media_preview.h @@ -25,7 +25,7 @@ namespace Window { class SessionController; -class MediaPreviewWidget : public Ui::RpWidget, private base::Subscriber { +class MediaPreviewWidget final : public Ui::RpWidget { public: MediaPreviewWidget( QWidget *parent,