diff --git a/Telegram/SourceFiles/base/lambda.h b/Telegram/SourceFiles/base/lambda.h index 6bf720563..92955d0ca 100644 --- a/Telegram/SourceFiles/base/lambda.h +++ b/Telegram/SourceFiles/base/lambda.h @@ -576,49 +576,4 @@ inline lambda_internal::guard_t lambda_guarded(PointersAnd return lambda_internal::guard_t(std::forward(qobjectsAndLambda)...); } -// Pass lambda instead of a Qt void() slot. - -class lambda_slot_wrap : public QObject { - Q_OBJECT - -public: - lambda_slot_wrap(QObject *parent, lambda lambda) : QObject(parent), _lambda(std::move(lambda)) { - } - -public slots : - void action() { - _lambda(); - } - -private: - lambda _lambda; - -}; - -inline lambda_slot_wrap *lambda_slot(QObject *parent, lambda lambda) { - return new lambda_slot_wrap(parent, std::move(lambda)); -} - -class lambda_slot_once_wrap : public QObject { - Q_OBJECT - -public: - lambda_slot_once_wrap(QObject *parent, lambda_once lambda) : QObject(parent), _lambda(std::move(lambda)) { - } - -public slots : - void action() { - _lambda(); - delete this; - } - -private: - lambda_once _lambda; - -}; - -inline lambda_slot_once_wrap *lambda_slot_once(QObject *parent, lambda_once lambda) { - return new lambda_slot_once_wrap(parent, std::move(lambda)); -} - } // namespace base diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index b470bba1d..8cc4df07a 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -41,7 +41,7 @@ namespace App { namespace internal { void CallDelayed(int duration, base::lambda_once &&lambda) { - QTimer::singleShot(duration, base::lambda_slot_once(App::app(), std::move(lambda)), SLOT(action())); + Messenger::Instance().callDelayed(duration, std::move(lambda)); } } // namespace internal diff --git a/Telegram/SourceFiles/messenger.h b/Telegram/SourceFiles/messenger.h index 501c51231..de16d7e7a 100644 --- a/Telegram/SourceFiles/messenger.h +++ b/Telegram/SourceFiles/messenger.h @@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "base/observer.h" #include "mtproto/auth_key.h" +#include "base/timer.h" namespace App { void quit(); @@ -170,6 +171,10 @@ public: void call_handleDelayedPeerUpdates(); void call_handleObservables(); + void callDelayed(int duration, base::lambda_once &&lambda) { + _callDelayedTimer.call(duration, std::move(lambda)); + } + signals: void peerPhotoDone(PeerId peer); void peerPhotoFail(PeerId peer); @@ -220,4 +225,6 @@ private: QImage _logo; QImage _logoNoMargin; + base::DelayedCallTimer _callDelayedTimer; + }; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index fcf843b31..ea23b5557 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -407,10 +407,10 @@ void MainWindow::psFirstShow() { void MainWindow::createGlobalMenu() { auto main = psMainMenu.addMenu(qsl("Telegram")); auto about = main->addAction(lng_mac_menu_about_telegram(lt_telegram, qsl("Telegram"))); - connect(about, SIGNAL(triggered()), base::lambda_slot(about, [] { + connect(about, &QAction::triggered, about, [] { if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); Ui::show(Box()); - }), SLOT(action())); + }); about->setMenuRole(QAction::AboutQtRole); main->addSeparator(); @@ -433,12 +433,12 @@ void MainWindow::createGlobalMenu() { QMenu *window = psMainMenu.addMenu(lang(lng_mac_menu_window)); psContacts = window->addAction(lang(lng_mac_menu_contacts)); - connect(psContacts, SIGNAL(triggered()), base::lambda_slot(psContacts, [] { + connect(psContacts, &QAction::triggered, psContacts, [] { if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); if (!App::self()) return; Ui::show(Box()); - }), SLOT(action())); + }); psAddContact = window->addAction(lang(lng_mac_menu_add_contact), App::wnd(), SLOT(onShowAddContact())); window->addSeparator(); psNewGroup = window->addAction(lang(lng_mac_menu_new_group), App::wnd(), SLOT(onShowNewGroup())); diff --git a/Telegram/SourceFiles/ui/widgets/menu.cpp b/Telegram/SourceFiles/ui/widgets/menu.cpp index 84e10b766..bf56cfc44 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/menu.cpp @@ -61,7 +61,7 @@ QAction *Menu::addAction(const QString &text, const QObject *receiver, const cha QAction *Menu::addAction(const QString &text, base::lambda callback, const style::icon *icon, const style::icon *iconOver) { auto action = addAction(new QAction(text, this), icon, iconOver); - connect(action, SIGNAL(triggered(bool)), base::lambda_slot(action, std::move(callback)), SLOT(action()), Qt::QueuedConnection); + connect(action, &QAction::triggered, action, std::move(callback), Qt::QueuedConnection); return action; }