diff options
Diffstat (limited to 'src/webenginewidgets/api/qwebenginenotificationpresenter.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginenotificationpresenter.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/webenginewidgets/api/qwebenginenotificationpresenter.cpp b/src/webenginewidgets/api/qwebenginenotificationpresenter.cpp index da97c4662..667605c37 100644 --- a/src/webenginewidgets/api/qwebenginenotificationpresenter.cpp +++ b/src/webenginewidgets/api/qwebenginenotificationpresenter.cpp @@ -39,6 +39,7 @@ #include "qwebenginenotificationpresenter_p.h" +#include <QApplication> #include <QSystemTrayIcon> QT_BEGIN_NAMESPACE @@ -55,50 +56,53 @@ DefaultNotificationPresenter::~DefaultNotificationPresenter() { } -void DefaultNotificationPresenter::show(const QWebEngineNotification ¬ification) +void DefaultNotificationPresenter::show(std::unique_ptr<QWebEngineNotification> notification) { - if (m_activeNotification.isValid()) { - m_activeNotification.close(); - m_activeNotification.disconnect(this); + Q_ASSERT(notification); + if (m_activeNotification) { + m_activeNotification->close(); + m_activeNotification->disconnect(this); } - m_activeNotification = notification; + m_activeNotification = std::move(notification); #ifndef QT_NO_SYSTEMTRAYICON - if (m_activeNotification.isValid() && m_systemTrayIcon) { + if (m_activeNotification && m_systemTrayIcon) { + m_systemTrayIcon->setIcon(qApp->windowIcon()); m_systemTrayIcon->show(); - QIcon icon = notification.icon(); - if (!icon.isNull()) - m_systemTrayIcon->showMessage(notification.title(), notification.message(), icon); + QImage notificationIconImage = m_activeNotification->icon(); + m_notificationIcon = QIcon(QPixmap::fromImage(std::move(notificationIconImage), Qt::NoFormatConversion)); + if (!m_notificationIcon.isNull()) + m_systemTrayIcon->showMessage(m_activeNotification->title(), m_activeNotification->message(), m_notificationIcon); else - m_systemTrayIcon->showMessage(notification.title(), notification.message()); - notification.show(); - connect(&m_activeNotification, &QWebEngineNotification::closed, this, &DefaultNotificationPresenter::closeNotification); + m_systemTrayIcon->showMessage(m_activeNotification->title(), m_activeNotification->message()); + m_activeNotification->show(); + connect(m_activeNotification.get(), &QWebEngineNotification::closed, this, &DefaultNotificationPresenter::closeNotification); } #endif } void DefaultNotificationPresenter::messageClicked() { - if (m_activeNotification.isValid()) - m_activeNotification.click(); + if (m_activeNotification) + m_activeNotification->click(); } void DefaultNotificationPresenter::closeNotification() { #ifndef QT_NO_SYSTEMTRAYICON const QWebEngineNotification *canceled = static_cast<const QWebEngineNotification *>(QObject::sender()); - if (m_systemTrayIcon && canceled->matches(m_activeNotification)) + if (m_systemTrayIcon && canceled->matches(m_activeNotification.get())) m_systemTrayIcon->hide(); #endif } -void defaultNotificationPresenter(const QWebEngineNotification ¬ification) +void defaultNotificationPresenter(std::unique_ptr<QWebEngineNotification> notification) { static DefaultNotificationPresenter *presenter = nullptr; if (!presenter) presenter = new DefaultNotificationPresenter(); - presenter->show(notification); + presenter->show(std::move(notification)); } |