From f3a9066dd5c41dc1de4cdc03bf64ee51dd83b88f Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 15 Aug 2023 22:23:38 +0200 Subject: [PATCH] Port away from KNotification::CloseWhenWidgetActivated --- src/session/Session.cpp | 43 +++++++++++++++++++++------- src/session/SessionController.cpp | 34 +++++++++++++++------- src/terminalDisplay/TerminalBell.cpp | 2 +- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/session/Session.cpp b/src/session/Session.cpp index be5434ddc..7d8a4b1f9 100644 --- a/src/session/Session.cpp +++ b/src/session/Session.cpp @@ -736,11 +736,17 @@ void Session::silenceTimerDone() view = _views.first(); } - KNotification *notification = KNotification::event(hasFocus() ? QStringLiteral("Silence") : QStringLiteral("SilenceHidden"), - i18n("Silence in '%1' (Session '%2')", _displayTitle, _nameTitle), - QPixmap(), - view, - KNotification::CloseWhenWidgetActivated); +#if QT_VERSION_MAJOR == 5 + KNotification *notification = + new KNotification(hasFocus() ? QStringLiteral("Silence") : QStringLiteral("SilenceHidden"), KNotification::CloseWhenWidgetActivated); + notification->setWidget(view); +#else + KNotification *notification = + new KNotification(hasFocus() ? QStringLiteral("Silence") : QStringLiteral("SilenceHidden"), KNotification::CloseWhenWindowActivated); + notification->setWindow(view->windowHandle()); +#endif + + notification->setText(i18n("Silence in '%1' (Session '%2')", _displayTitle, _nameTitle)); notification->setDefaultAction(i18n("Show session")); connect(notification, &KNotification::defaultActivated, this, [view, notification]() { view->notificationClicked(notification->xdgActivationToken()); @@ -1085,7 +1091,15 @@ void Session::done(int exitCode, QProcess::ExitStatus exitStatus) } // FIXME: See comments in Session::silenceTimerDone() - KNotification::event(QStringLiteral("Finished"), message, QPixmap(), QApplication::activeWindow(), KNotification::CloseWhenWidgetActivated); +#if QT_VERSION_MAJOR == 5 + KNotification *notification = new KNotification(QStringLiteral("Finished"), KNotification::CloseWhenWidgetActivated); + notification->setWidget(QApplication::activeWindow()); +#else + KNotification *notification = new KNotification(QStringLiteral("Finished"), KNotification::CloseWhenWindowActivated); + notification->setWindow(QApplication::activeWindow()->windowHandle()); +#endif + notification->setText(message); + notification->sendEvent(); } if (exitStatus != QProcess::NormalExit) { @@ -1932,15 +1946,22 @@ void Session::handleActivity() } if (_monitorActivity && !_notifiedActivity) { - KNotification *notification = KNotification::event(hasFocus() ? QStringLiteral("Activity") : QStringLiteral("ActivityHidden"), - i18n("Activity in '%1' (Session '%2')", _displayTitle, _nameTitle), - QPixmap(), - view, - KNotification::CloseWhenWidgetActivated); +#if QT_VERSION_MAJOR == 5 + KNotification *notification = + new KNotification(hasFocus() ? QStringLiteral("Activity") : QStringLiteral("ActivityHidden"), KNotification::CloseWhenWidgetActivated); + notification->setWidget(view); +#else + KNotification *notification = + new KNotification(hasFocus() ? QStringLiteral("Activity") : QStringLiteral("ActivityHidden"), KNotification::CloseWhenWindowActivated); + notification->setWindow(view->windowHandle()); +#endif + notification->setText(i18n("Activity in '%1' (Session '%2')", _displayTitle, _nameTitle)); notification->setDefaultAction(i18n("Show session")); connect(notification, &KNotification::defaultActivated, this, [view, notification]() { view->notificationClicked(notification->xdgActivationToken()); }); + notification->sendEvent(); + if (view->sessionController()->isMonitorOnce()) { view->sessionController()->actionCollection()->action(QStringLiteral("monitor-activity"))->setChecked(false); } diff --git a/src/session/SessionController.cpp b/src/session/SessionController.cpp index 7f4d95c62..2f015f8b9 100644 --- a/src/session/SessionController.cpp +++ b/src/session/SessionController.cpp @@ -356,16 +356,21 @@ void SessionController::snapshot() if (_monitorProcessFinish) { bool isForegroundProcessActive = session()->isForegroundProcessActive(); if (!_previousForegroundProcessName.isNull() && !isForegroundProcessActive) { - KNotification *notification = - KNotification::event(session()->hasFocus() ? QStringLiteral("ProcessFinished") : QStringLiteral("ProcessFinishedHidden"), - i18n("The process '%1' has finished running in session '%2'", _previousForegroundProcessName, session()->nameTitle()), - QPixmap(), - view(), - KNotification::CloseWhenWidgetActivated); +#if QT_VERSION_MAJOR == 5 + KNotification *notification = new KNotification(session()->hasFocus() ? QStringLiteral("ProcessFinished") : QStringLiteral("ProcessFinishedHidden"), + KNotification::CloseWhenWidgetActivated); + notification->setWidget(view()); +#else + KNotification *notification = new KNotification(session()->hasFocus() ? QStringLiteral("ProcessFinished") : QStringLiteral("ProcessFinishedHidden"), + KNotification::CloseWhenWindowActivated); + notification->setWindow(view()->windowHandle()); +#endif + notification->setText(i18n("The process '%1' has finished running in session '%2'", _previousForegroundProcessName, session()->nameTitle())); notification->setDefaultAction(i18n("Show session")); connect(notification, &KNotification::defaultActivated, this, [this, notification]() { view()->notificationClicked(notification->xdgActivationToken()); }); + notification->sendEvent(); if (_monitorOnce) { actionCollection()->action(QStringLiteral("monitor-process-finish"))->setChecked(false); } @@ -1859,15 +1864,22 @@ void SessionController::resetFontSize() void SessionController::notifyPrompt() { if (session()->isMonitorPrompt()) { - KNotification *notification = KNotification::event(session()->hasFocus() ? QStringLiteral("Prompt") : QStringLiteral("PromptHidden"), - i18n("The shell prompt is displayed in session '%1'", session()->nameTitle()), - QPixmap(), - view(), - KNotification::CloseWhenWidgetActivated); +#if QT_VERSION_MAJOR == 5 + KNotification *notification = + new KNotification(session()->hasFocus() ? QStringLiteral("Prompt") : QStringLiteral("PromptHidden"), KNotification::CloseWhenWidgetActivated); + notification->setWidget(view()); +#else + KNotification *notification = + new KNotification(session()->hasFocus() ? QStringLiteral("Prompt") : QStringLiteral("PromptHidden"), KNotification::CloseWhenWindowActivated); + notification->setWindow(view()->windowHandle()); +#endif + + notification->setText(i18n("The shell prompt is displayed in session '%1'", session()->nameTitle())); notification->setDefaultAction(i18n("Show session")); connect(notification, &KNotification::defaultActivated, this, [this, notification]() { view()->notificationClicked(notification->xdgActivationToken()); }); + notification->sendEvent(); if (_monitorOnce) { actionCollection()->action(QStringLiteral("monitor-prompt"))->setChecked(false); } diff --git a/src/terminalDisplay/TerminalBell.cpp b/src/terminalDisplay/TerminalBell.cpp index dd13c4fbb..3960e3c9c 100644 --- a/src/terminalDisplay/TerminalBell.cpp +++ b/src/terminalDisplay/TerminalBell.cpp @@ -39,7 +39,7 @@ void TerminalBell::bell(TerminalDisplay *terminalDisplay, const QString &message // should not change and should be kept stable, because other applications // that use this code via KPart rely on these names for notifications. KNotification *notification = - KNotification::event(terminalHasFocus ? QStringLiteral("BellVisible") : QStringLiteral("BellInvisible"), message, QPixmap(), terminalDisplay); + KNotification::event(terminalHasFocus ? QStringLiteral("BellVisible") : QStringLiteral("BellInvisible"), message, QPixmap()); notification->setDefaultAction(i18n("Show session")); connect(notification, &KNotification::defaultActivated, this, [notification, terminalDisplay]() { terminalDisplay->notificationClicked(notification->xdgActivationToken());