From 3c8c05944761feea9e8777ebda12345d233e47c9 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 28 Aug 2020 20:14:19 +0400 Subject: [PATCH] Eliminate the need of Q_OBJECT in main_window_linux and main_window_win --- Telegram/SourceFiles/mainwindow.cpp | 4 +- .../platform/linux/main_window_linux.cpp | 58 ++++++++++------- .../platform/linux/main_window_linux.h | 63 +++++++++---------- .../platform/mac/main_window_mac.h | 4 +- .../platform/win/main_window_win.h | 7 +-- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 66272f6004..5e20476469 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -764,7 +764,9 @@ void MainWindow::handleTrayIconActication( } if (reason == QSystemTrayIcon::Context) { updateTrayMenu(true); - QTimer::singleShot(1, this, SLOT(psShowTrayMenu())); + base::call_delayed(1, this, [=] { + psShowTrayMenu(); + }); } else if (!skipTrayClick()) { if (Platform::IsWayland() ? isVisible() : isActive()) { minimizeToTray(); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index dc958a2d6f..900892f020 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -435,7 +435,12 @@ void MainWindow::initHook() { sniWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, - &MainWindow::onSNIOwnerChanged); + [=]( + const QString &service, + const QString &oldOwner, + const QString &newOwner) { + handleSNIOwnerChanged(service, oldOwner, newOwner); + }); AppMenuSupported = IsAppMenuSupported(); @@ -449,13 +454,18 @@ void MainWindow::initHook() { appMenuWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, - &MainWindow::onAppMenuOwnerChanged); + [=]( + const QString &service, + const QString &oldOwner, + const QString &newOwner) { + handleAppMenuOwnerChanged(service, oldOwner, newOwner); + }); connect( windowHandle(), &QWindow::visibleChanged, this, - &MainWindow::onVisibleChanged); + [=](bool visible) { handleVisibleChanged(visible); }); if (AppMenuSupported) { LOG(("Using D-Bus global menu.")); @@ -560,7 +570,7 @@ void MainWindow::attachToSNITrayIcon() { updateTrayMenu(); } -void MainWindow::onSNIOwnerChanged( +void MainWindow::handleSNIOwnerChanged( const QString &service, const QString &oldOwner, const QString &newOwner) { @@ -596,7 +606,7 @@ void MainWindow::onSNIOwnerChanged( } } -void MainWindow::onAppMenuOwnerChanged( +void MainWindow::handleAppMenuOwnerChanged( const QString &service, const QString &oldOwner, const QString &newOwner) { @@ -780,7 +790,7 @@ void MainWindow::createGlobalMenu() { auto quit = file->addAction( tr::lng_mac_menu_quit_telegram(tr::now, lt_telegram, qsl("Telegram")), App::wnd(), - SLOT(quitFromTray()), + [=] { App::wnd()->quitFromTray(); }, QKeySequence::Quit); quit->setMenuRole(QAction::QuitRole); @@ -790,13 +800,13 @@ void MainWindow::createGlobalMenu() { psUndo = edit->addAction( tr::lng_linux_menu_undo(tr::now), this, - SLOT(psLinuxUndo()), + [=] { psLinuxUndo(); }, QKeySequence::Undo); psRedo = edit->addAction( tr::lng_linux_menu_redo(tr::now), this, - SLOT(psLinuxRedo()), + [=] { psLinuxRedo(); }, QKeySequence::Redo); edit->addSeparator(); @@ -804,24 +814,24 @@ void MainWindow::createGlobalMenu() { psCut = edit->addAction( tr::lng_mac_menu_cut(tr::now), this, - SLOT(psLinuxCut()), + [=] { psLinuxCut(); }, QKeySequence::Cut); psCopy = edit->addAction( tr::lng_mac_menu_copy(tr::now), this, - SLOT(psLinuxCopy()), + [=] { psLinuxCopy(); }, QKeySequence::Copy); psPaste = edit->addAction( tr::lng_mac_menu_paste(tr::now), this, - SLOT(psLinuxPaste()), + [=] { psLinuxPaste(); }, QKeySequence::Paste); psDelete = edit->addAction( tr::lng_mac_menu_delete(tr::now), this, - SLOT(psLinuxDelete()), + [=] { psLinuxDelete(); }, QKeySequence(Qt::ControlModifier | Qt::Key_Backspace)); edit->addSeparator(); @@ -829,44 +839,44 @@ void MainWindow::createGlobalMenu() { psBold = edit->addAction( tr::lng_menu_formatting_bold(tr::now), this, - SLOT(psLinuxBold()), + [=] { psLinuxBold(); }, QKeySequence::Bold); psItalic = edit->addAction( tr::lng_menu_formatting_italic(tr::now), this, - SLOT(psLinuxItalic()), + [=] { psLinuxItalic(); }, QKeySequence::Italic); psUnderline = edit->addAction( tr::lng_menu_formatting_underline(tr::now), this, - SLOT(psLinuxUnderline()), + [=] { psLinuxUnderline(); }, QKeySequence::Underline); psStrikeOut = edit->addAction( tr::lng_menu_formatting_strike_out(tr::now), this, - SLOT(psLinuxStrikeOut()), + [=] { psLinuxStrikeOut(); }, Ui::kStrikeOutSequence); psMonospace = edit->addAction( tr::lng_menu_formatting_monospace(tr::now), this, - SLOT(psLinuxMonospace()), + [=] { psLinuxMonospace(); }, Ui::kMonospaceSequence); psClearFormat = edit->addAction( tr::lng_menu_formatting_clear(tr::now), this, - SLOT(psLinuxClearFormat()), + [=] { psLinuxClearFormat(); }, Ui::kClearFormatSequence); edit->addSeparator(); psSelectAll = edit->addAction( tr::lng_mac_menu_select_all(tr::now), - this, SLOT(psLinuxSelectAll()), + this, [=] { psLinuxSelectAll(); }, QKeySequence::SelectAll); edit->addSeparator(); @@ -874,7 +884,7 @@ void MainWindow::createGlobalMenu() { auto prefs = edit->addAction( tr::lng_mac_menu_preferences(tr::now), App::wnd(), - SLOT(showSettings()), + [=] { App::wnd()->showSettings(); }, QKeySequence(Qt::ControlModifier | Qt::Key_Comma)); prefs->setMenuRole(QAction::PreferencesRole); @@ -909,19 +919,19 @@ void MainWindow::createGlobalMenu() { psAddContact = tools->addAction( tr::lng_mac_menu_add_contact(tr::now), App::wnd(), - SLOT(onShowAddContact())); + [=] { App::wnd()->onShowAddContact(); }); tools->addSeparator(); psNewGroup = tools->addAction( tr::lng_mac_menu_new_group(tr::now), App::wnd(), - SLOT(onShowNewGroup())); + [=] { App::wnd()->onShowNewGroup(); }); psNewChannel = tools->addAction( tr::lng_mac_menu_new_channel(tr::now), App::wnd(), - SLOT(onShowNewChannel())); + [=] { App::wnd()->onShowNewChannel(); }); auto help = psMainMenu->addMenu(tr::lng_linux_menu_help(tr::now)); @@ -1066,7 +1076,7 @@ void MainWindow::updateGlobalMenuHook() { ForceDisabled(psClearFormat, !markdownEnabled); } -void MainWindow::onVisibleChanged(bool visible) { +void MainWindow::handleVisibleChanged(bool visible) { if (AppMenuSupported && !_mainMenuPath.path().isEmpty()) { if (visible) { RegisterAppMenu(winId(), _mainMenuPath); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index 5a911f7eaf..0190b42626 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -21,8 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { class MainWindow : public Window::MainWindow { - Q_OBJECT - public: explicit MainWindow(not_null controller); @@ -33,43 +31,12 @@ public: style::color fg, bool smallIcon) = 0; + void psShowTrayMenu(); + static void LibsLoaded(); ~MainWindow(); -public slots: - void psShowTrayMenu(); - -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - void onSNIOwnerChanged( - const QString &service, - const QString &oldOwner, - const QString &newOwner); - - void onAppMenuOwnerChanged( - const QString &service, - const QString &oldOwner, - const QString &newOwner); - - void psLinuxUndo(); - void psLinuxRedo(); - void psLinuxCut(); - void psLinuxCopy(); - void psLinuxPaste(); - void psLinuxDelete(); - void psLinuxSelectAll(); - - void psLinuxBold(); - void psLinuxItalic(); - void psLinuxUnderline(); - void psLinuxStrikeOut(); - void psLinuxMonospace(); - void psLinuxClearFormat(); - - void onVisibleChanged(bool visible); - -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - protected: void initHook() override; void unreadCounterChangedHook() override; @@ -100,6 +67,7 @@ private: void updateIconCounters(); void updateWaylandDecorationColors(); + void handleVisibleChanged(bool visible); #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION StatusNotifierItem *_sniTrayIcon = nullptr; @@ -131,6 +99,31 @@ private: void setSNITrayIcon(int counter, bool muted); void attachToSNITrayIcon(); + + void handleSNIOwnerChanged( + const QString &service, + const QString &oldOwner, + const QString &newOwner); + + void handleAppMenuOwnerChanged( + const QString &service, + const QString &oldOwner, + const QString &newOwner); + + void psLinuxUndo(); + void psLinuxRedo(); + void psLinuxCut(); + void psLinuxCopy(); + void psLinuxPaste(); + void psLinuxDelete(); + void psLinuxSelectAll(); + + void psLinuxBold(); + void psLinuxItalic(); + void psLinuxUnderline(); + void psLinuxStrikeOut(); + void psLinuxMonospace(); + void psLinuxClearFormat(); #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION }; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index b5fd21dee5..f9179a3e00 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -35,11 +35,11 @@ public: void updateWindowIcon() override; + void psShowTrayMenu(); + class Private; public slots: - void psShowTrayMenu(); - void psMacUndo(); void psMacRedo(); void psMacCut(); diff --git a/Telegram/SourceFiles/platform/win/main_window_win.h b/Telegram/SourceFiles/platform/win/main_window_win.h index b022251112..2ac8161e60 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.h +++ b/Telegram/SourceFiles/platform/win/main_window_win.h @@ -21,8 +21,6 @@ class PopupMenu; namespace Platform { class MainWindow : public Window::MainWindow { - Q_OBJECT - public: explicit MainWindow(not_null controller); @@ -58,11 +56,10 @@ public: return _deltaTop; } - ~MainWindow(); - -public slots: void psShowTrayMenu(); + ~MainWindow(); + protected: void initHook() override; int32 screenNameChecksum(const QString &name) const override;