From 4a8d297df3c90d0f4178389e7fc4ad3c9475b47e Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Jun 2020 21:26:29 +0400 Subject: [PATCH] Use username in notifications if available. --- .../platform/mac/window_title_mac.h | 2 +- .../platform/win/window_title_win.cpp | 19 ++++++++++--------- .../platform/win/window_title_win.h | 12 ++++-------- .../window/notifications_manager.cpp | 6 +++++- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/window_title_mac.h b/Telegram/SourceFiles/platform/mac/window_title_mac.h index 1a58f626d6..bf7370c084 100644 --- a/Telegram/SourceFiles/platform/mac/window_title_mac.h +++ b/Telegram/SourceFiles/platform/mac/window_title_mac.h @@ -17,7 +17,7 @@ namespace Platform { class MainWindow; -class TitleWidget : public Window::TitleWidget, private base::Subscriber { +class TitleWidget : public Window::TitleWidget { public: TitleWidget(MainWindow *parent, int height); diff --git a/Telegram/SourceFiles/platform/win/window_title_win.cpp b/Telegram/SourceFiles/platform/win/window_title_win.cpp index 6e098f46a9..80df1d90d5 100644 --- a/Telegram/SourceFiles/platform/win/window_title_win.cpp +++ b/Telegram/SourceFiles/platform/win/window_title_win.cpp @@ -47,7 +47,11 @@ TitleWidget::TitleWidget(QWidget *parent) } void TitleWidget::init() { - connect(window()->windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onWindowStateChanged(Qt::WindowState))); + connect( + window()->windowHandle(), + &QWindow::windowStateChanged, + this, + [=](Qt::WindowState state) { windowStateChanged(state); }); _maximizedState = (window()->windowState() & Qt::WindowMaximized); _activeState = isActiveWindow(); updateButtonsState(); @@ -74,15 +78,12 @@ void TitleWidget::resizeEvent(QResizeEvent *e) { _shadow->setGeometry(0, height() - st::lineWidth, width(), st::lineWidth); } -void TitleWidget::updateControlsVisibility() { - updateControlsPosition(); - update(); -} +void TitleWidget::windowStateChanged(Qt::WindowState state) { + if (state == Qt::WindowMinimized) { + return; + } -void TitleWidget::onWindowStateChanged(Qt::WindowState state) { - if (state == Qt::WindowMinimized) return; - - auto maximized = (state == Qt::WindowMaximized); + const auto maximized = (state == Qt::WindowMaximized); if (_maximizedState != maximized) { _maximizedState = maximized; updateButtonsState(); diff --git a/Telegram/SourceFiles/platform/win/window_title_win.h b/Telegram/SourceFiles/platform/win/window_title_win.h index ce7af371e7..3423857a79 100644 --- a/Telegram/SourceFiles/platform/win/window_title_win.h +++ b/Telegram/SourceFiles/platform/win/window_title_win.h @@ -30,25 +30,21 @@ void DefaultPreviewWindowFramePaint(QImage &preview, const style::palette &palet namespace Platform { -class TitleWidget : public Window::TitleWidget, private base::Subscriber { - Q_OBJECT - +class TitleWidget : public Window::TitleWidget { public: TitleWidget(QWidget *parent); void init() override; - Window::HitTestResult hitTest(const QPoint &p) const override; - -public slots: - void onWindowStateChanged(Qt::WindowState state = Qt::WindowNoState); - void updateControlsVisibility(); + [[nodiscard]] Window::HitTestResult hitTest( + const QPoint &p) const override; protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; private: + void windowStateChanged(Qt::WindowState state = Qt::WindowNoState); void updateButtonsState(); void updateControlsPosition(); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 77fafa6cbe..c84a55527d 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -552,7 +552,11 @@ QString Manager::addTargetAccountName( const QString &title, not_null session) { return (Core::App().domain().accounts().size() > 1) - ? (title + accountNameSeparator() + session->user()->name) + ? (title + + accountNameSeparator() + + (session->user()->username.isEmpty() + ? session->user()->name + : session->user()->username)) : title; }