diff --git a/Telegram/SourceFiles/boxes/abstractbox.h b/Telegram/SourceFiles/boxes/abstractbox.h index 5e3861c17b..26520c20d3 100644 --- a/Telegram/SourceFiles/boxes/abstractbox.h +++ b/Telegram/SourceFiles/boxes/abstractbox.h @@ -47,7 +47,7 @@ private: }; -class AbstractBox : public LayerWidget { +class AbstractBox : public LayerWidget, protected base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 52377b0665..4dc8f29c88 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -1362,8 +1362,8 @@ RevokePublicLinkBox::RevokePublicLinkBox(base::lambda_unique &&revokeCal updateMaxHeight(); - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); prepare(); } diff --git a/Telegram/SourceFiles/boxes/backgroundbox.cpp b/Telegram/SourceFiles/boxes/backgroundbox.cpp index b5a56f8d02..9f2700dea4 100644 --- a/Telegram/SourceFiles/boxes/backgroundbox.cpp +++ b/Telegram/SourceFiles/boxes/backgroundbox.cpp @@ -29,13 +29,14 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org BackgroundInner::BackgroundInner() : _bgCount(0), _rows(0), _over(-1), _overDown(-1) { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); if (App::cServerBackgrounds().isEmpty()) { resize(BackgroundsInRow * (st::backgroundSize.width() + st::backgroundPadding) + st::backgroundPadding, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding); MTP::send(MTPaccount_GetWallPapers(), rpcDone(&BackgroundInner::gotWallpapers)); } else { updateWallpapers(); } + + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); setMouseTracking(true); } diff --git a/Telegram/SourceFiles/boxes/backgroundbox.h b/Telegram/SourceFiles/boxes/backgroundbox.h index 66866f1655..ebdcab053a 100644 --- a/Telegram/SourceFiles/boxes/backgroundbox.h +++ b/Telegram/SourceFiles/boxes/backgroundbox.h @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" #include "core/lambda_wrap.h" -class BackgroundInner : public QWidget, public RPCSender { +class BackgroundInner : public TWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/boxes/confirmbox.cpp b/Telegram/SourceFiles/boxes/confirmbox.cpp index 10d67a9cae..61107ba4a1 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.cpp +++ b/Telegram/SourceFiles/boxes/confirmbox.cpp @@ -546,7 +546,7 @@ ConfirmInviteBox::ConfirmInviteBox(const QString &title, const MTPChatPhoto &pho if (!location.isNull()) { _photo = ImagePtr(location); if (!_photo->loaded()) { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); _photo->load(); } } diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index f903768da1..16f02d661f 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -106,7 +106,7 @@ ContactsInner::ContactsInner(UserData *bot) : TWidget() } void ContactsInner::init() { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); connect(&_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact())); connect(&_allAdmins, SIGNAL(changed()), this, SLOT(onAllAdminsChanged())); @@ -1750,7 +1750,8 @@ MembersInner::MembersInner(ChannelData *channel, MembersFilter filter) : TWidget , _aboutWidth(st::boxWideWidth - st::contactsPadding.left() - st::contactsPadding.right()) , _about(_aboutWidth) , _aboutHeight(0) { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); + connect(App::main(), SIGNAL(peerNameChanged(PeerData*,const PeerData::Names&,const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&))); connect(App::main(), SIGNAL(peerPhotoChanged(PeerData*)), this, SLOT(peerUpdated(PeerData*))); diff --git a/Telegram/SourceFiles/boxes/contactsbox.h b/Telegram/SourceFiles/boxes/contactsbox.h index 59c41c09a0..27a13294a7 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.h +++ b/Telegram/SourceFiles/boxes/contactsbox.h @@ -36,7 +36,7 @@ using MembersAlreadyIn = OrderedSet; QString cantInviteError(); class ConfirmBox; -class ContactsInner : public TWidget, public RPCSender { +class ContactsInner : public TWidget, public RPCSender, private base::Subscriber { Q_OBJECT private: @@ -269,7 +269,7 @@ private: }; -class MembersInner : public TWidget, public RPCSender { +class MembersInner : public TWidget, public RPCSender, private base::Subscriber { Q_OBJECT private: diff --git a/Telegram/SourceFiles/boxes/localstoragebox.cpp b/Telegram/SourceFiles/boxes/localstoragebox.cpp index 29b3e62790..23057c10aa 100644 --- a/Telegram/SourceFiles/boxes/localstoragebox.cpp +++ b/Telegram/SourceFiles/boxes/localstoragebox.cpp @@ -33,10 +33,11 @@ LocalStorageBox::LocalStorageBox() : AbstractBox() connect(_clear, SIGNAL(clicked()), this, SLOT(onClear())); connect(_close, SIGNAL(clicked()), this, SLOT(onClose())); - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); connect(App::wnd(), SIGNAL(tempDirCleared(int)), this, SLOT(onTempDirCleared(int))); connect(App::wnd(), SIGNAL(tempDirClearFailed(int)), this, SLOT(onTempDirClearFailed(int))); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); + checkLocalStoredCounts(); prepare(); } diff --git a/Telegram/SourceFiles/boxes/sharebox.cpp b/Telegram/SourceFiles/boxes/sharebox.cpp index 19b249b365..b3fbec61b3 100644 --- a/Telegram/SourceFiles/boxes/sharebox.cpp +++ b/Telegram/SourceFiles/boxes/sharebox.cpp @@ -243,8 +243,6 @@ namespace internal { ShareInner::ShareInner(QWidget *parent) : ScrolledWidget(parent) , _chatsIndexed(std_::make_unique(Dialogs::SortMode::Add)) { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); - _rowsTop = st::shareRowsTop; _rowHeight = st::shareRowHeight; setAttribute(Qt::WA_OpaquePaintEvent); @@ -264,7 +262,12 @@ ShareInner::ShareInner(QWidget *parent) : ScrolledWidget(parent) using UpdateFlag = Notify::PeerUpdate::Flag; auto observeEvents = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged; - Notify::registerPeerObserver(observeEvents, this, &ShareInner::notifyPeerUpdated); + + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); + + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); } void ShareInner::setVisibleTopBottom(int visibleTop, int visibleBottom) { diff --git a/Telegram/SourceFiles/boxes/sharebox.h b/Telegram/SourceFiles/boxes/sharebox.h index 675fb92aab..d486e6e12e 100644 --- a/Telegram/SourceFiles/boxes/sharebox.h +++ b/Telegram/SourceFiles/boxes/sharebox.h @@ -108,7 +108,7 @@ private: namespace internal { -class ShareInner : public ScrolledWidget, public RPCSender, public Notify::Observer { +class ShareInner : public ScrolledWidget, public RPCSender, public Notify::Observer, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/boxes/stickersetbox.cpp b/Telegram/SourceFiles/boxes/stickersetbox.cpp index 728cee6907..6c20fbc79e 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.cpp +++ b/Telegram/SourceFiles/boxes/stickersetbox.cpp @@ -41,7 +41,6 @@ constexpr int kArchivedLimitPerPage = 30; StickerSetInner::StickerSetInner(const MTPInputStickerSet &set) : ScrolledWidget() , _input(set) { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); switch (set.type()) { case mtpc_inputStickerSetID: _setId = set.c_inputStickerSetID().vid.v; _setAccess = set.c_inputStickerSetID().vaccess_hash.v; break; case mtpc_inputStickerSetShortName: _setShortName = qs(set.c_inputStickerSetShortName().vshort_name); break; @@ -49,6 +48,8 @@ StickerSetInner::StickerSetInner(const MTPInputStickerSet &set) : ScrolledWidget MTP::send(MTPmessages_GetStickerSet(_input), rpcDone(&StickerSetInner::gotSet), rpcFail(&StickerSetInner::failedSet)); App::main()->updateStickers(); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); + setMouseTracking(true); _previewTimer.setSingleShot(true); @@ -515,7 +516,7 @@ StickersInner::StickersInner(const Stickers::Order &archivedIds) : ScrolledWidge } void StickersInner::setup() { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(onImageLoaded())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); setMouseTracking(true); } diff --git a/Telegram/SourceFiles/boxes/stickersetbox.h b/Telegram/SourceFiles/boxes/stickersetbox.h index 3c7a936a32..1626fd08a4 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.h +++ b/Telegram/SourceFiles/boxes/stickersetbox.h @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org class ConfirmBox; -class StickerSetInner : public ScrolledWidget, public RPCSender { +class StickerSetInner : public ScrolledWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: @@ -207,7 +207,7 @@ int32 stickerPacksCount(bool includeDisabledOfficial = false); namespace internal { -class StickersInner : public ScrolledWidget, public RPCSender { +class StickersInner : public ScrolledWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/core/basic_types.h index 778aff01b1..2b22bc4cda 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/core/basic_types.h @@ -1064,7 +1064,7 @@ extern QAtomicInt ComponentIndexLast; template struct BaseComponent { BaseComponent() { - static_assert(alignof(Type) <= sizeof(SmallestSizeType), "Components should align to a pointer!"); + static_assert(alignof(Type) <= alignof(SmallestSizeType), "Components should align to a pointer!"); } BaseComponent(const BaseComponent &other) = delete; BaseComponent &operator=(const BaseComponent &other) = delete; diff --git a/Telegram/SourceFiles/core/lambda_wrap.h b/Telegram/SourceFiles/core/lambda_wrap.h index 9bc1fe084a..9305c66945 100644 --- a/Telegram/SourceFiles/core/lambda_wrap.h +++ b/Telegram/SourceFiles/core/lambda_wrap.h @@ -20,6 +20,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once +#ifndef OS_MAC_OLD +#include +#endif // OS_MAC_OLD + namespace base { namespace internal { @@ -50,7 +54,7 @@ struct lambda_wrap_helper_base { const call_type call; const destruct_type destruct; - static constexpr size_t kFullStorageSize = 40U; + static constexpr size_t kFullStorageSize = sizeof(void*) + 24U; static constexpr size_t kStorageSize = kFullStorageSize - sizeof(void*); template @@ -90,43 +94,47 @@ const lambda_wrap_empty lambda_wrap_empty::ins template struct lambda_wrap_helper_move_impl; -template -struct lambda_wrap_helper_move_impl : public lambda_wrap_helper_base { - using JustLambda = std_::decay_simple_t; - using LambdaPtr = std_::unique_ptr; - using Parent = lambda_wrap_helper_base; - static void construct_move_other_method(void *lambda, void *source) { - auto source_lambda = static_cast(source); - new (lambda) LambdaPtr(std_::move(*source_lambda)); - } - static void construct_move_lambda_method(void *lambda, void *source) { - auto source_lambda = static_cast(source); - new (lambda) LambdaPtr(std_::make_unique(static_cast(*source_lambda))); - } - static Return call_method(const void *lambda, Args... args) { - return (**static_cast(lambda))(std_::forward(args)...); - } - static void destruct_method(const void *lambda) { - static_cast(lambda)->~LambdaPtr(); - } - lambda_wrap_helper_move_impl() : Parent( - &Parent::bad_construct_copy, - &lambda_wrap_helper_move_impl::construct_move_other_method, - &lambda_wrap_helper_move_impl::call_method, - &lambda_wrap_helper_move_impl::destruct_method) { - } - -protected: - lambda_wrap_helper_move_impl( - typename Parent::construct_copy_other_type construct_copy_other - ) : Parent( - construct_copy_other, - &lambda_wrap_helper_move_impl::construct_move_other_method, - &lambda_wrap_helper_move_impl::call_method, - &lambda_wrap_helper_move_impl::destruct_method) { - } - -}; +// +// Disable large lambda support. +// If you really need it, just store data in some std_::unique_ptr. +// +//template +//struct lambda_wrap_helper_move_impl : public lambda_wrap_helper_base { +// using JustLambda = std_::decay_simple_t; +// using LambdaPtr = std_::unique_ptr; +// using Parent = lambda_wrap_helper_base; +// static void construct_move_other_method(void *lambda, void *source) { +// auto source_lambda = static_cast(source); +// new (lambda) LambdaPtr(std_::move(*source_lambda)); +// } +// static void construct_move_lambda_method(void *lambda, void *source) { +// auto source_lambda = static_cast(source); +// new (lambda) LambdaPtr(std_::make_unique(static_cast(*source_lambda))); +// } +// static Return call_method(const void *lambda, Args... args) { +// return (**static_cast(lambda))(std_::forward(args)...); +// } +// static void destruct_method(const void *lambda) { +// static_cast(lambda)->~LambdaPtr(); +// } +// lambda_wrap_helper_move_impl() : Parent( +// &Parent::bad_construct_copy, +// &lambda_wrap_helper_move_impl::construct_move_other_method, +// &lambda_wrap_helper_move_impl::call_method, +// &lambda_wrap_helper_move_impl::destruct_method) { +// } +// +//protected: +// lambda_wrap_helper_move_impl( +// typename Parent::construct_copy_other_type construct_copy_other +// ) : Parent( +// construct_copy_other, +// &lambda_wrap_helper_move_impl::construct_move_other_method, +// &lambda_wrap_helper_move_impl::call_method, +// &lambda_wrap_helper_move_impl::destruct_method) { +// } +// +//}; template struct lambda_wrap_helper_move_impl : public lambda_wrap_helper_base { @@ -137,6 +145,12 @@ struct lambda_wrap_helper_move_impl : new (lambda) JustLambda(static_cast(*source_lambda)); } static void construct_move_lambda_method(void *lambda, void *source) { + static_assert(alignof(JustLambda) <= alignof(void*), "Bad lambda alignment."); +#ifndef OS_MAC_OLD + auto space = sizeof(JustLambda); + auto aligned = std::align(alignof(JustLambda), space, lambda, space); + t_assert(aligned == lambda); +#endif // OS_MAC_OLD auto source_lambda = static_cast(source); new (lambda) JustLambda(static_cast(*source_lambda)); } @@ -177,23 +191,27 @@ const lambda_wrap_helper_move lambda_wrap_helper_move struct lambda_wrap_helper_copy_impl; -template -struct lambda_wrap_helper_copy_impl : public lambda_wrap_helper_move_impl { - using JustLambda = std_::decay_simple_t; - using LambdaPtr = std_::unique_ptr; - using Parent = lambda_wrap_helper_move_impl; - static void construct_copy_other_method(void *lambda, const void *source) { - auto source_lambda = static_cast(source); - new (lambda) LambdaPtr(std_::make_unique(*source_lambda->get())); - } - static void construct_copy_lambda_method(void *lambda, const void *source) { - auto source_lambda = static_cast(source); - new (lambda) LambdaPtr(std_::make_unique(static_cast(*source_lambda))); - } - lambda_wrap_helper_copy_impl() : Parent(&lambda_wrap_helper_copy_impl::construct_copy_other_method) { - } - -}; +// +// Disable large lambda support. +// If you really need it, just store data in some QSharedPointer. +// +//template +//struct lambda_wrap_helper_copy_impl : public lambda_wrap_helper_move_impl { +// using JustLambda = std_::decay_simple_t; +// using LambdaPtr = std_::unique_ptr; +// using Parent = lambda_wrap_helper_move_impl; +// static void construct_copy_other_method(void *lambda, const void *source) { +// auto source_lambda = static_cast(source); +// new (lambda) LambdaPtr(std_::make_unique(*source_lambda->get())); +// } +// static void construct_copy_lambda_method(void *lambda, const void *source) { +// auto source_lambda = static_cast(source); +// new (lambda) LambdaPtr(std_::make_unique(static_cast(*source_lambda))); +// } +// lambda_wrap_helper_copy_impl() : Parent(&lambda_wrap_helper_copy_impl::construct_copy_other_method) { +// } +// +//}; template struct lambda_wrap_helper_copy_impl : public lambda_wrap_helper_move_impl { @@ -204,6 +222,12 @@ struct lambda_wrap_helper_copy_impl : new (lambda) JustLambda(static_cast(*source_lambda)); } static void construct_copy_lambda_method(void *lambda, const void *source) { + static_assert(alignof(JustLambda) <= alignof(void*), "Bad lambda alignment."); +#ifndef OS_MAC_OLD + auto space = sizeof(JustLambda); + auto aligned = std::align(alignof(JustLambda), space, lambda, space); + t_assert(aligned == lambda); +#endif // OS_MAC_OLD auto source_lambda = static_cast(source); new (lambda) JustLambda(static_cast(*source_lambda)); } @@ -356,7 +380,7 @@ public: auto temp = other; this->helper_->destruct(this->storage_); this->helper_ = &internal::lambda_wrap_helper_copy::instance; - internal::lambda_wrap_helper_copy::construct_move_lambda_method(this->storage_, &other); + internal::lambda_wrap_helper_copy::construct_copy_lambda_method(this->storage_, &other); return *this; } diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index eed96774f3..38e9caf2b3 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -46,13 +46,15 @@ DialogsInner::DialogsInner(QWidget *parent, MainWidget *main) : SplittedWidget(p if (Global::DialogsModeEnabled()) { importantDialogs = std_::make_unique(Dialogs::SortMode::Date); } - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); connect(main, SIGNAL(peerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&))); connect(main, SIGNAL(peerPhotoChanged(PeerData*)), this, SLOT(onPeerPhotoChanged(PeerData*))); connect(main, SIGNAL(dialogRowReplaced(Dialogs::Row*,Dialogs::Row*)), this, SLOT(onDialogRowReplaced(Dialogs::Row*,Dialogs::Row*))); connect(&_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact())); connect(&_cancelSearchInPeer, SIGNAL(clicked()), this, SIGNAL(cancelSearchInPeer())); _cancelSearchInPeer.hide(); + + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); + refresh(); } diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index 8891478f6c..743705025d 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -42,7 +42,7 @@ enum DialogsSearchRequestType { DialogsSearchMigratedFromOffset, }; -class DialogsInner : public SplittedWidget, public RPCSender { +class DialogsInner : public SplittedWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/history/field_autocomplete.cpp b/Telegram/SourceFiles/history/field_autocomplete.cpp index bf8687542c..5b710363fc 100644 --- a/Telegram/SourceFiles/history/field_autocomplete.cpp +++ b/Telegram/SourceFiles/history/field_autocomplete.cpp @@ -44,8 +44,6 @@ FieldAutocomplete::FieldAutocomplete(QWidget *parent) : TWidget(parent) connect(_inner, SIGNAL(stickerChosen(DocumentData*,FieldAutocomplete::ChooseMethod)), this, SIGNAL(stickerChosen(DocumentData*,FieldAutocomplete::ChooseMethod))); connect(_inner, SIGNAL(mustScrollTo(int, int)), _scroll, SLOT(scrollToY(int, int))); - connect(App::wnd(), SIGNAL(imageLoaded()), _inner, SLOT(update())); - setFocusPolicy(Qt::NoFocus); _scroll->setFocusPolicy(Qt::NoFocus); _scroll->viewport()->setFocusPolicy(Qt::NoFocus); @@ -539,6 +537,7 @@ FieldAutocompleteInner::FieldAutocompleteInner(FieldAutocomplete *parent, Mentio , _previewShown(false) { _previewTimer.setSingleShot(true); connect(&_previewTimer, SIGNAL(timeout()), this, SLOT(onPreview())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); } void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { @@ -933,7 +932,4 @@ void FieldAutocompleteInner::onPreview() { } } -FieldAutocompleteInner::~FieldAutocompleteInner() { -} - } // namespace internal diff --git a/Telegram/SourceFiles/history/field_autocomplete.h b/Telegram/SourceFiles/history/field_autocomplete.h index 71b4cba99d..9f824a8297 100644 --- a/Telegram/SourceFiles/history/field_autocomplete.h +++ b/Telegram/SourceFiles/history/field_autocomplete.h @@ -138,7 +138,7 @@ private: namespace internal { -class FieldAutocompleteInner final : public TWidget { +class FieldAutocompleteInner final : public TWidget, private base::Subscriber { Q_OBJECT public: @@ -150,8 +150,6 @@ public: void setRecentInlineBotsInRows(int32 bots); - ~FieldAutocompleteInner(); - signals: void mentionChosen(UserData *user, FieldAutocomplete::ChooseMethod method) const; void hashtagChosen(QString hashtag, FieldAutocomplete::ChooseMethod method) const; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 9b38e8eb5d..198a634b1a 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -3040,7 +3040,7 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent) setAcceptDrops(true); - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); connect(&_scroll, SIGNAL(scrolled()), this, SLOT(onScroll())); connect(&_reportSpamPanel, SIGNAL(reportClicked()), this, SLOT(onReportSpamClicked())); connect(&_reportSpamPanel, SIGNAL(hideClicked()), this, SLOT(onReportSpamHide())); diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index 9c38039f1d..fb5374dd31 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -437,7 +437,7 @@ MediaPreviewWidget::MediaPreviewWidget(QWidget *parent) : TWidget(parent) , _a_shown(animation(this, &MediaPreviewWidget::step_shown)) , _emojiSize(EmojiSizes[EIndex + 1] / cIntRetinaFactor()) { setAttribute(Qt::WA_TransparentForMouseEvents); - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); } void MediaPreviewWidget::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index 14d1fbc84e..3161e00435 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -129,7 +129,7 @@ private: }; -class MediaPreviewWidget : public TWidget { +class MediaPreviewWidget : public TWidget, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index cc3abdd4a4..f69dfd2fc6 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -406,8 +406,7 @@ MainWindow::MainWindow() { connect(&_autoLockTimer, SIGNAL(timeout()), this, SLOT(checkAutoLock())); - connect(this, SIGNAL(imageLoaded()), this, SLOT(notifyUpdateAllPhotos())); - + subscribe(FileDownload::ImageLoaded(), [this] { notifyUpdateAllPhotos(); }); subscribe(Global::RefSelfChanged(), [this]() { updateGlobalMenu(); }); setAttribute(Qt::WA_NoSystemBackground); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index edd20a7945..804a6b01ad 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -292,8 +292,6 @@ signals: void tempDirClearFailed(int task); void newAuthorization(); - void imageLoaded(); - private slots: void onStateChanged(Qt::WindowState state); void onSettingsDestroyed(QObject *was); diff --git a/Telegram/SourceFiles/mtproto/facade.cpp b/Telegram/SourceFiles/mtproto/facade.cpp index a5293f3535..6aa4064cb8 100644 --- a/Telegram/SourceFiles/mtproto/facade.cpp +++ b/Telegram/SourceFiles/mtproto/facade.cpp @@ -206,7 +206,7 @@ namespace { } req = i.value(); } - if (internal::Session *session = internal::getSession(newdcWithShift)) { + if (auto session = internal::getSession(newdcWithShift)) { internal::registerRequest(requestId, (dcWithShift < 0) ? -newdcWithShift : newdcWithShift); session->sendPrepared(req); } diff --git a/Telegram/SourceFiles/mtproto/file_download.cpp b/Telegram/SourceFiles/mtproto/file_download.cpp index e4623dbc97..513fbfd8e0 100644 --- a/Telegram/SourceFiles/mtproto/file_download.cpp +++ b/Telegram/SourceFiles/mtproto/file_download.cpp @@ -207,9 +207,8 @@ void FileLoader::localLoaded(const StorageImageSaved &result, const QByteArray & _fileIsOpen = false; psPostprocessFile(QFileInfo(_file).absoluteFilePath()); } - emit App::wnd()->imageLoaded(); emit progress(this); - FileDownload::internal::notifyImageLoaded(); + FileDownload::ImageLoaded().notify(); loadNext(); } @@ -516,8 +515,6 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe } removeFromQueue(); - emit App::wnd()->imageLoaded(); - if (!_queue->queries) { App::app()->killDownloadSessionsStart(_dc); } @@ -544,7 +541,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe } emit progress(this); if (_complete) { - FileDownload::internal::notifyImageLoaded(); + FileDownload::ImageLoaded().notify(); } loadNext(); } @@ -669,13 +666,11 @@ void webFileLoader::onFinished(const QByteArray &data) { } removeFromQueue(); - emit App::wnd()->imageLoaded(); - if (_localStatus == LocalNotFound || _localStatus == LocalFailed) { Local::writeWebFile(_url, _data); } emit progress(this); - FileDownload::internal::notifyImageLoaded(); + FileDownload::ImageLoaded().notify(); loadNext(); } @@ -1093,21 +1088,12 @@ namespace MTP { namespace FileDownload { namespace { -using internal::ImageLoadedHandler; - -Notify::SimpleObservedEventRegistrator creator(nullptr, nullptr); +base::Observable ImageLoadedObservable; } // namespace -namespace internal { - -Notify::ConnectionId plainRegisterImageLoadedObserver(ImageLoadedHandler &&handler) { - return creator.registerObserver(std_::forward(handler)); +base::Observable &ImageLoaded() { + return ImageLoadedObservable; } -void notifyImageLoaded() { - creator.notify(); -} - -} // namespace internal -} +} // namespace FileDownload diff --git a/Telegram/SourceFiles/mtproto/file_download.h b/Telegram/SourceFiles/mtproto/file_download.h index 0d883504bd..f4453ee7f3 100644 --- a/Telegram/SourceFiles/mtproto/file_download.h +++ b/Telegram/SourceFiles/mtproto/file_download.h @@ -397,21 +397,6 @@ void stopWebLoadManager(); namespace FileDownload { -namespace internal { - -using ImageLoadedHandler = base::lambda_unique; -Notify::ConnectionId plainRegisterImageLoadedObserver(ImageLoadedHandler &&handler); - -void notifyImageLoaded(); - -} // namespace internal - -template -void registerImageLoadedObserver(ObserverType *observer, void (ObserverType::*handler)()) { - auto connection = internal::plainRegisterImageLoadedObserver([observer, handler]() { - (observer->*handler)(); - }); - Notify::observerRegistered(observer, connection); -} +base::Observable &ImageLoaded(); } // namespace FileDownload diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index aee59e5c3d..53955b68c4 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -96,11 +96,9 @@ ConnectionId plainRegisterPeerObserver(PeerUpdate::Flags events, PeerUpdateHandl } // namespace internal -template -void registerPeerObserver(PeerUpdate::Flags events, ObserverType *observer, void (ObserverType::*handler)(const PeerUpdate &)) { - auto connection = internal::plainRegisterPeerObserver(events, [observer, handler](const PeerUpdate &update) { - (observer->*handler)(update); - }); +template +void registerPeerObserver(PeerUpdate::Flags events, ObserverType *observer, Lambda &&other) { + auto connection = internal::plainRegisterPeerObserver(events, std_::move(other)); observerRegistered(observer, connection); } diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index efbf98167c..db99a6a3df 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -89,7 +89,7 @@ OverviewInner::OverviewInner(OverviewWidget *overview, ScrollArea *scroll, PeerD , _touchAccelerationTime(0) , _touchTime(0) , _menu(0) { - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update())); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); resize(_width, st::wndMinHeight); diff --git a/Telegram/SourceFiles/overviewwidget.h b/Telegram/SourceFiles/overviewwidget.h index 016d14ad22..cd785b2b8a 100644 --- a/Telegram/SourceFiles/overviewwidget.h +++ b/Telegram/SourceFiles/overviewwidget.h @@ -33,7 +33,7 @@ class Date; } // namespace Overview class OverviewWidget; -class OverviewInner : public QWidget, public AbstractTooltipShower, public RPCSender { +class OverviewInner : public QWidget, public AbstractTooltipShower, public RPCSender, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/profile/profile_actions_widget.cpp b/Telegram/SourceFiles/profile/profile_actions_widget.cpp index df96da74bb..49f64ee4d4 100644 --- a/Telegram/SourceFiles/profile/profile_actions_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_actions_widget.cpp @@ -39,7 +39,9 @@ ActionsWidget::ActionsWidget(QWidget *parent, PeerData *peer) : BlockWidget(pare | UpdateFlag::UserIsBlocked | UpdateFlag::BotCommandsChanged | UpdateFlag::MembersChanged; - Notify::registerPeerObserver(observeEvents, this, &ActionsWidget::notifyPeerUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); validateBlockStatus(); refreshButtons(); diff --git a/Telegram/SourceFiles/profile/profile_block_widget.h b/Telegram/SourceFiles/profile/profile_block_widget.h index 7b77d27702..541c9dedec 100644 --- a/Telegram/SourceFiles/profile/profile_block_widget.h +++ b/Telegram/SourceFiles/profile/profile_block_widget.h @@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Profile { -class BlockWidget : public ScrolledWidget, public Notify::Observer { +class BlockWidget : public ScrolledWidget, public Notify::Observer, protected base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index 16e2cb6ccf..cdcc561511 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -68,8 +68,12 @@ CoverWidget::CoverWidget(QWidget *parent, PeerData *peer) : TWidget(parent) auto observeEvents = ButtonsUpdateFlags | UpdateFlag::NameChanged | UpdateFlag::UserOnlineChanged; - Notify::registerPeerObserver(observeEvents, this, &CoverWidget::notifyPeerUpdated); - FileDialog::registerObserver(this, &CoverWidget::notifyFileQueryUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); + subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) { + notifyFileQueryUpdated(update); + }); connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); diff --git a/Telegram/SourceFiles/profile/profile_cover.h b/Telegram/SourceFiles/profile/profile_cover.h index 5b3c8023b8..a735c10622 100644 --- a/Telegram/SourceFiles/profile/profile_cover.h +++ b/Telegram/SourceFiles/profile/profile_cover.h @@ -40,7 +40,7 @@ class BackButton; class UserpicButton; class CoverDropArea; -class CoverWidget final : public TWidget, public Notify::Observer { +class CoverWidget final : public TWidget, public Notify::Observer, private base::Subscriber { Q_OBJECT public: diff --git a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp index 8d2cde28b9..36d44ee865 100644 --- a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp +++ b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp @@ -83,7 +83,9 @@ FixedBar::FixedBar(QWidget *parent, PeerData *peer) : TWidget(parent) auto observeEvents = ButtonsUpdateFlags | UpdateFlag::MigrationChanged; - Notify::registerPeerObserver(observeEvents, this, &FixedBar::notifyPeerUpdate); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdate(update); + }); refreshRightActions(); } diff --git a/Telegram/SourceFiles/profile/profile_info_widget.cpp b/Telegram/SourceFiles/profile/profile_info_widget.cpp index 032f6cd6f4..c844fcb2f1 100644 --- a/Telegram/SourceFiles/profile/profile_info_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_info_widget.cpp @@ -36,7 +36,9 @@ InfoWidget::InfoWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, pe | UpdateFlag::UsernameChanged | UpdateFlag::UserPhoneChanged | UpdateFlag::UserCanShareContact; - Notify::registerPeerObserver(observeEvents, this, &InfoWidget::notifyPeerUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); refreshLabels(); } diff --git a/Telegram/SourceFiles/profile/profile_invite_link_widget.cpp b/Telegram/SourceFiles/profile/profile_invite_link_widget.cpp index 294d4626b3..e5c3f29a9b 100644 --- a/Telegram/SourceFiles/profile/profile_invite_link_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_invite_link_widget.cpp @@ -33,7 +33,9 @@ using UpdateFlag = Notify::PeerUpdate::Flag; InviteLinkWidget::InviteLinkWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_invite_link_section)) { auto observeEvents = UpdateFlag::InviteLinkChanged | UpdateFlag::UsernameChanged; - Notify::registerPeerObserver(observeEvents, this, &InviteLinkWidget::notifyPeerUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); refreshLink(); refreshVisibility(); diff --git a/Telegram/SourceFiles/profile/profile_members_widget.cpp b/Telegram/SourceFiles/profile/profile_members_widget.cpp index 78db1d3c9e..f6bcc2f50e 100644 --- a/Telegram/SourceFiles/profile/profile_members_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_members_widget.cpp @@ -49,16 +49,14 @@ MembersWidget::MembersWidget(QWidget *parent, PeerData *peer, TitleVisibility ti auto observeEvents = UpdateFlag::AdminsChanged | UpdateFlag::MembersChanged | UpdateFlag::UserOnlineChanged; - Notify::registerPeerObserver(observeEvents, this, &MembersWidget::notifyPeerUpdated); - FileDownload::registerImageLoadedObserver(this, &MembersWidget::repaintCallback); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); + subscribe(FileDownload::ImageLoaded(), [this] { update(); }); refreshMembers(); } -void MembersWidget::repaintCallback() { - update(); -} - void MembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) { if (update.peer != peer()) { if (update.flags & UpdateFlag::UserOnlineChanged) { @@ -83,7 +81,7 @@ void MembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) { } } } - repaintCallback(); + this->update(); } void MembersWidget::refreshUserOnline(UserData *user) { @@ -606,7 +604,9 @@ ChannelMembersWidget::ChannelMembersWidget(QWidget *parent, PeerData *peer) : Bl | UpdateFlag::ChannelCanViewMembers | UpdateFlag::AdminsChanged | UpdateFlag::MembersChanged; - Notify::registerPeerObserver(observeEvents, this, &ChannelMembersWidget::notifyPeerUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); refreshButtons(); } diff --git a/Telegram/SourceFiles/profile/profile_members_widget.h b/Telegram/SourceFiles/profile/profile_members_widget.h index 83ed921af1..6e7cb28b31 100644 --- a/Telegram/SourceFiles/profile/profile_members_widget.h +++ b/Telegram/SourceFiles/profile/profile_members_widget.h @@ -78,7 +78,6 @@ private slots: private: // Observed notifications. void notifyPeerUpdated(const Notify::PeerUpdate &update); - void repaintCallback(); void preloadUserPhotos(); diff --git a/Telegram/SourceFiles/profile/profile_settings_widget.cpp b/Telegram/SourceFiles/profile/profile_settings_widget.cpp index c79d9e180e..ed47209ded 100644 --- a/Telegram/SourceFiles/profile/profile_settings_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_settings_widget.cpp @@ -51,7 +51,9 @@ SettingsWidget::SettingsWidget(QWidget *parent, PeerData *peer) : BlockWidget(pa observeEvents |= UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged; } } - Notify::registerPeerObserver(observeEvents, this, &SettingsWidget::notifyPeerUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); refreshButtons(); _enableNotifications->finishAnimations(); diff --git a/Telegram/SourceFiles/profile/profile_shared_media_widget.cpp b/Telegram/SourceFiles/profile/profile_shared_media_widget.cpp index 23c4063956..1f6e4679e7 100644 --- a/Telegram/SourceFiles/profile/profile_shared_media_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_shared_media_widget.cpp @@ -51,7 +51,9 @@ QString getButtonText(MediaOverviewType type, int count) { SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_shared_media)) , _history(App::history(peer)) , _migrated(peer->migrateFrom() ? App::history(peer->migrateFrom()) : nullptr) { - Notify::registerPeerObserver(Notify::PeerUpdate::Flag::SharedMediaChanged, this, &SharedMediaWidget::notifyPeerUpdated); + Notify::registerPeerObserver(Notify::PeerUpdate::Flag::SharedMediaChanged, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); App::main()->preloadOverviews(peer); if (_migrated) { diff --git a/Telegram/SourceFiles/profile/profile_userpic_button.cpp b/Telegram/SourceFiles/profile/profile_userpic_button.cpp index e1b92dedba..6b7b1ed91c 100644 --- a/Telegram/SourceFiles/profile/profile_userpic_button.cpp +++ b/Telegram/SourceFiles/profile/profile_userpic_button.cpp @@ -36,8 +36,15 @@ UserpicButton::UserpicButton(QWidget *parent, PeerData *peer) : Button(parent), _userpic = prepareUserpicPixmap(); } - Notify::registerPeerObserver(Notify::PeerUpdate::Flag::PhotoChanged, this, &UserpicButton::notifyPeerUpdated); - FileDownload::registerImageLoadedObserver(this, &UserpicButton::notifyImageLoaded); + Notify::registerPeerObserver(Notify::PeerUpdate::Flag::PhotoChanged, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); + subscribe(FileDownload::ImageLoaded(), [this] { + if (_waiting && _peer->userpicLoaded()) { + _waiting = false; + startNewPhotoShowing(); + } + }); } void UserpicButton::showFinished() { @@ -68,13 +75,6 @@ void UserpicButton::notifyPeerUpdated(const Notify::PeerUpdate &update) { this->update(); } -void UserpicButton::notifyImageLoaded() { - if (_waiting && _peer->userpicLoaded()) { - _waiting = false; - startNewPhotoShowing(); - } -} - void UserpicButton::processPeerPhoto() { bool hasPhoto = (_peer->photoId && _peer->photoId != UnknownPeerPhotoId); setCursor(hasPhoto ? style::cur_pointer : style::cur_default); diff --git a/Telegram/SourceFiles/profile/profile_userpic_button.h b/Telegram/SourceFiles/profile/profile_userpic_button.h index cd75d80a44..cfac826e1f 100644 --- a/Telegram/SourceFiles/profile/profile_userpic_button.h +++ b/Telegram/SourceFiles/profile/profile_userpic_button.h @@ -28,7 +28,7 @@ struct PeerUpdate; namespace Profile { -class UserpicButton final : public Button, public Notify::Observer { +class UserpicButton final : public Button, public Notify::Observer, private base::Subscriber { public: UserpicButton(QWidget *parent, PeerData *peer); @@ -41,7 +41,6 @@ protected: private: void notifyPeerUpdated(const Notify::PeerUpdate &update); - void notifyImageLoaded(); void processPeerPhoto(); void processNewPeerPhoto(); diff --git a/Telegram/SourceFiles/settings/settings_background_widget.cpp b/Telegram/SourceFiles/settings/settings_background_widget.cpp index 61c7cf27f9..ac25cbd539 100644 --- a/Telegram/SourceFiles/settings/settings_background_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_background_widget.cpp @@ -163,9 +163,11 @@ void BackgroundRow::updateImage() { } BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_background)) { - FileDialog::registerObserver(this, &BackgroundWidget::notifyFileQueryUpdated); createControls(); + subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) { + notifyFileQueryUpdated(update); + }); subscribe(Window::chatBackground(), [this](const Window::ChatBackgroundUpdate &update) { using Update = Window::ChatBackgroundUpdate; if (update.type == Update::Type::New) { diff --git a/Telegram/SourceFiles/settings/settings_cover.cpp b/Telegram/SourceFiles/settings/settings_cover.cpp index 50d57b2997..a6f7f112d4 100644 --- a/Telegram/SourceFiles/settings/settings_cover.cpp +++ b/Telegram/SourceFiles/settings/settings_cover.cpp @@ -57,8 +57,13 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent, connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName())); auto observeEvents = Notify::PeerUpdate::Flag::NameChanged; - Notify::registerPeerObserver(observeEvents, this, &CoverWidget::notifyPeerUpdated); - FileDialog::registerObserver(this, &CoverWidget::notifyFileQueryUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); + + subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) { + notifyFileQueryUpdated(update); + }); connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); diff --git a/Telegram/SourceFiles/settings/settings_general_widget.cpp b/Telegram/SourceFiles/settings/settings_general_widget.cpp index 60b2a15e28..4945dd5c8c 100644 --- a/Telegram/SourceFiles/settings/settings_general_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_general_widget.cpp @@ -171,7 +171,9 @@ GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(pare , _changeLanguage(this, lang(lng_settings_change_lang), st::defaultBoxLinkButton) { connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage())); subscribe(Global::RefChooseCustomLang(), [this]() { chooseCustomLang(); }); - FileDialog::registerObserver(this, &GeneralWidget::notifyFileQueryUpdated); + subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) { + notifyFileQueryUpdated(update); + }); refreshControls(); } diff --git a/Telegram/SourceFiles/settings/settings_info_widget.cpp b/Telegram/SourceFiles/settings/settings_info_widget.cpp index 28219a8583..e6b83ca0ab 100644 --- a/Telegram/SourceFiles/settings/settings_info_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_info_widget.cpp @@ -34,7 +34,9 @@ using UpdateFlag = Notify::PeerUpdate::Flag; InfoWidget::InfoWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_info)) { auto observeEvents = UpdateFlag::UsernameChanged | UpdateFlag::UserPhoneChanged; - Notify::registerPeerObserver(observeEvents, this, &InfoWidget::notifyPeerUpdated); + Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) { + notifyPeerUpdated(update); + }); createControls(); } diff --git a/Telegram/SourceFiles/stickers/emoji_pan.cpp b/Telegram/SourceFiles/stickers/emoji_pan.cpp index a6060ffda4..d7a73e2217 100644 --- a/Telegram/SourceFiles/stickers/emoji_pan.cpp +++ b/Telegram/SourceFiles/stickers/emoji_pan.cpp @@ -801,7 +801,6 @@ StickerPanInner::StickerPanInner() : ScrolledWidget() setFocusPolicy(Qt::NoFocus); setAttribute(Qt::WA_OpaquePaintEvent); - connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(onImageLoaded())); connect(&_settings, SIGNAL(clicked()), this, SLOT(onSettings())); _previewTimer.setSingleShot(true); @@ -809,6 +808,11 @@ StickerPanInner::StickerPanInner() : ScrolledWidget() _updateInlineItems.setSingleShot(true); connect(&_updateInlineItems, SIGNAL(timeout()), this, SLOT(onUpdateInlineItems())); + + subscribe(FileDownload::ImageLoaded(), [this] { + update(); + readVisibleSets(); + }); } void StickerPanInner::setMaxHeight(int32 h) { @@ -855,11 +859,6 @@ void StickerPanInner::readVisibleSets() { } } -void StickerPanInner::onImageLoaded() { - update(); - readVisibleSets(); -} - int StickerPanInner::featuredRowHeight() const { return st::featuredStickersHeader + st::stickerPanSize.height() + st::featuredStickersSkip; } diff --git a/Telegram/SourceFiles/stickers/emoji_pan.h b/Telegram/SourceFiles/stickers/emoji_pan.h index 92da29b81f..71b542af7f 100644 --- a/Telegram/SourceFiles/stickers/emoji_pan.h +++ b/Telegram/SourceFiles/stickers/emoji_pan.h @@ -207,7 +207,7 @@ struct StickerIcon { int pixh = 0; }; -class StickerPanInner : public ScrolledWidget { +class StickerPanInner : public ScrolledWidget, private base::Subscriber { Q_OBJECT public: @@ -274,7 +274,6 @@ private slots: void onPreview(); void onUpdateInlineItems(); void onSwitchPm(); - void onImageLoaded(); signals: void selected(DocumentData *sticker); diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index f9627501ce..85c8bd0284 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -27,12 +27,11 @@ static const ChannelId NoChannel = 0; typedef int32 MsgId; struct FullMsgId { - FullMsgId() : channel(NoChannel), msg(0) { - } + FullMsgId() = default; FullMsgId(ChannelId channel, MsgId msg) : channel(channel), msg(msg) { } - ChannelId channel; - MsgId msg; + ChannelId channel = NoChannel; + MsgId msg = 0; }; typedef uint64 PeerId; diff --git a/Telegram/SourceFiles/ui/filedialog.cpp b/Telegram/SourceFiles/ui/filedialog.cpp index 45a947ceb8..4601b616e8 100644 --- a/Telegram/SourceFiles/ui/filedialog.cpp +++ b/Telegram/SourceFiles/ui/filedialog.cpp @@ -255,7 +255,7 @@ QString filedialogAllFilesFilter() { namespace FileDialog { namespace { -using internal::QueryUpdateHandler; +base::Observable QueryDoneObservable; struct Query { enum class Type { @@ -285,16 +285,10 @@ void StartCallback() { Queries.makeIfNull(); } -void FinishCallback() { - Queries.clear(); -} - -Notify::SimpleObservedEventRegistrator creator(StartCallback, FinishCallback); - } // namespace QueryId queryReadFile(const QString &caption, const QString &filter) { - t_assert(creator.started()); + Queries.makeIfNull(); Queries->push_back(Query(Query::Type::ReadFile, caption, filter)); Global::RefHandleFileDialogQueue().call(); @@ -302,7 +296,7 @@ QueryId queryReadFile(const QString &caption, const QString &filter) { } QueryId queryReadFiles(const QString &caption, const QString &filter) { - t_assert(creator.started()); + Queries.makeIfNull(); Queries->push_back(Query(Query::Type::ReadFiles, caption, filter)); Global::RefHandleFileDialogQueue().call(); @@ -310,7 +304,7 @@ QueryId queryReadFiles(const QString &caption, const QString &filter) { } QueryId queryWriteFile(const QString &caption, const QString &filter, const QString &filePath) { - t_assert(creator.started()); + Queries.makeIfNull(); Queries->push_back(Query(Query::Type::WriteFile, caption, filter, filePath)); Global::RefHandleFileDialogQueue().call(); @@ -318,7 +312,7 @@ QueryId queryWriteFile(const QString &caption, const QString &filter, const QStr } QueryId queryReadFolder(const QString &caption) { - t_assert(creator.started()); + Queries.makeIfNull(); Queries->push_back(Query(Query::Type::ReadFolder, caption)); Global::RefHandleFileDialogQueue().call(); @@ -326,7 +320,7 @@ QueryId queryReadFolder(const QString &caption) { } bool processQuery() { - if (!creator.started() || !Global::started() || Queries->isEmpty()) return false; + if (!Queries || !Global::started() || Queries->isEmpty()) return false; auto query = Queries->front(); Queries->pop_front(); @@ -374,17 +368,14 @@ bool processQuery() { } // No one knows what happened during filedialogGet*() call in the event loop. - if (!creator.started() || !Global::started()) return false; + if (!Queries || !Global::started()) return false; - creator.notify(update); + QueryDone().notify(std_::move(update)); return true; } -namespace internal { - -Notify::ConnectionId plainRegisterObserver(QueryUpdateHandler &&handler) { - return creator.registerObserver(std_::forward(handler)); +base::Observable &QueryDone() { + return QueryDoneObservable; } -} // namespace internal } // namespace FileDialog diff --git a/Telegram/SourceFiles/ui/filedialog.h b/Telegram/SourceFiles/ui/filedialog.h index a73b97603c..fac4b2a7de 100644 --- a/Telegram/SourceFiles/ui/filedialog.h +++ b/Telegram/SourceFiles/ui/filedialog.h @@ -63,19 +63,6 @@ QueryId queryReadFolder(const QString &caption); // NB! This function enters an event loop. bool processQuery(); -namespace internal { - -using QueryUpdateHandler = base::lambda_unique; -Notify::ConnectionId plainRegisterObserver(QueryUpdateHandler &&handler); - -} // namespace internal - -template -void registerObserver(ObserverType *observer, void (ObserverType::*handler)(const QueryUpdate &)) { - auto connection = internal::plainRegisterObserver([observer, handler](const QueryUpdate &update) { - (observer->*handler)(update); - }); - Notify::observerRegistered(observer, connection); -} +base::Observable &QueryDone(); } // namespace FileDialog