[utilities/konsole] /: Add a menu option for monitors to only notify once.

Kurt Hindenburg null at kde.org
Sun May 14 19:59:49 BST 2023


Git commit b69a2b88ef0283cd1176b48590f24973ec1b053c by Kurt Hindenburg, on behalf of Matan Ziv-Av.
Committed on 14/05/2023 at 14:15.
Pushed by hindenburg into branch 'master'.

Add a menu option for monitors to only notify once.

When this option is enabled, the monitors (prompt, activity, silence,
process termination) are disabled automatically after one notification.

M  +2    -1    desktop/sessionui.rc
M  +7    -0    doc/manual/index.docbook
M  +8    -0    src/session/Session.cpp
M  +17   -1    src/session/SessionController.cpp
M  +7    -0    src/session/SessionController.h

https://invent.kde.org/utilities/konsole/commit/b69a2b88ef0283cd1176b48590f24973ec1b053c

diff --git a/desktop/sessionui.rc b/desktop/sessionui.rc
index 992517f11..614a8553b 100644
--- a/desktop/sessionui.rc
+++ b/desktop/sessionui.rc
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <!DOCTYPE gui SYSTEM "kpartgui.dtd">
 
-<gui name="session" version="34">
+<gui name="session" version="35">
     <MenuBar>
         <Menu name="file">
             <Action name="file_save_as" group="session-operations"/>
@@ -28,6 +28,7 @@
             <Action name="edit_find_prev" group="session-edit-operations"/>
         </Menu>
         <Menu name="view">
+            <Action name="monitor-once" group="session-view-operations"/>
             <Action name="monitor-prompt" group="session-view-operations"/>
             <Action name="monitor-silence" group="session-view-operations"/>
             <Action name="monitor-activity" group="session-view-operations"/>
diff --git a/doc/manual/index.docbook b/doc/manual/index.docbook
index 1a81bc382..e33fb7af3 100644
--- a/doc/manual/index.docbook
+++ b/doc/manual/index.docbook
@@ -899,6 +899,13 @@ menu item earlier.</action> The default layouts (2x2, 2x1, and 1x2) can be loade
 </para></listitem>
 </varlistentry>
 
+<varlistentry>
+<term><menuchoice>
+<guimenu>View</guimenu><guimenuitem>One-shot monitors</guimenuitem></menuchoice></term>
+<listitem><para><action>The following monitors only notify once, and are then disabled.  </action>
+</para></listitem>
+</varlistentry>
+
 <varlistentry>
 <term><menuchoice>
 <shortcut><keycombo action="simul">&Ctrl;&Shift;<keycap>R</keycap></keycombo></shortcut>
diff --git a/src/session/Session.cpp b/src/session/Session.cpp
index d4fc12e6f..e821e46e9 100644
--- a/src/session/Session.cpp
+++ b/src/session/Session.cpp
@@ -26,6 +26,7 @@
 #include <QKeyEvent>
 
 // KDE
+#include <KActionCollection>
 #include <KConfigGroup>
 #include <KIO/DesktopExecParser>
 #include <KLocalizedString>
@@ -44,6 +45,7 @@
 
 #include "Pty.h"
 #include "SSHProcessInfo.h"
+#include "SessionController.h"
 #include "SessionManager.h"
 #include "ShellCommand.h"
 #include "Vt102Emulation.h"
@@ -743,6 +745,9 @@ void Session::silenceTimerDone()
     connect(notification, &KNotification::defaultActivated, this, [view, notification]() {
         view->notificationClicked(notification->xdgActivationToken());
     });
+    if (view->sessionController()->isMonitorOnce()) {
+        view->sessionController()->actionCollection()->action(QStringLiteral("monitor-silence"))->setChecked(false);
+    }
     setPendingNotification(Notification::Silence);
 }
 
@@ -1936,6 +1941,9 @@ void Session::handleActivity()
         connect(notification, &KNotification::defaultActivated, this, [view, notification]() {
             view->notificationClicked(notification->xdgActivationToken());
         });
+        if (view->sessionController()->isMonitorOnce()) {
+            view->sessionController()->actionCollection()->action(QStringLiteral("monitor-activity"))->setChecked(false);
+        }
 
         // mask activity notification for a while to avoid flooding
         _notifiedActivity = true;
diff --git a/src/session/SessionController.cpp b/src/session/SessionController.cpp
index fa5a033b8..3395f4682 100644
--- a/src/session/SessionController.cpp
+++ b/src/session/SessionController.cpp
@@ -134,6 +134,7 @@ SessionController::SessionController(Session *sessionParam, TerminalDisplay *vie
     , _isSearchBarEnabled(false)
     , _searchBar(viewParam->searchBar())
     , _monitorProcessFinish(false)
+    , _monitorOnce(false)
     , _escapedUrlFilter(nullptr)
 {
     Q_ASSERT(sessionParam);
@@ -365,6 +366,9 @@ void SessionController::snapshot()
             connect(notification, &KNotification::defaultActivated, this, [this, notification]() {
                 view()->notificationClicked(notification->xdgActivationToken());
             });
+            if (_monitorOnce) {
+                actionCollection()->action(QStringLiteral("monitor-process-finish"))->setChecked(false);
+            }
         }
         _previousForegroundProcessName = isForegroundProcessActive ? session()->foregroundProcessName() : QString();
     }
@@ -884,7 +888,12 @@ void SessionController::setupExtraActions()
     collection->setDefaultShortcut(action, Qt::CTRL | Qt::ALT | Qt::Key_U);
 
     // Monitor
-    KToggleAction *toggleAction = new KToggleAction(i18n("Monitor for &Prompt"), this);
+    KToggleAction *toggleAction = new KToggleAction(i18n("One-shot monitors"), this);
+    action = collection->addAction(QStringLiteral("monitor-once"), toggleAction);
+    connect(action, &QAction::toggled, this, &Konsole::SessionController::monitorOnce);
+    action->setIcon(QIcon::fromTheme(QStringLiteral("tools-media-optical-burn")));
+
+    toggleAction = new KToggleAction(i18n("Monitor for &Prompt"), this);
     collection->setDefaultShortcut(toggleAction, Konsole::ACCEL | Qt::Key_R);
     action = collection->addAction(QStringLiteral("monitor-prompt"), toggleAction);
     connect(action, &QAction::toggled, this, &Konsole::SessionController::monitorPrompt);
@@ -1844,8 +1853,15 @@ void SessionController::notifyPrompt()
         connect(notification, &KNotification::defaultActivated, this, [this, notification]() {
             view()->notificationClicked(notification->xdgActivationToken());
         });
+        if (_monitorOnce) {
+            actionCollection()->action(QStringLiteral("monitor-prompt"))->setChecked(false);
+        }
     }
 }
+void SessionController::monitorOnce(bool once)
+{
+    _monitorOnce = once;
+}
 void SessionController::monitorPrompt(bool monitor)
 {
     session()->setMonitorPrompt(monitor);
diff --git a/src/session/SessionController.h b/src/session/SessionController.h
index b59ea199b..9924fdbd1 100644
--- a/src/session/SessionController.h
+++ b/src/session/SessionController.h
@@ -152,6 +152,11 @@ public:
 
     void setVisible(QString name, bool visible);
 
+    bool isMonitorOnce() const
+    {
+        return _monitorOnce;
+    };
+
 Q_SIGNALS:
     /**
      * Emitted when the view associated with the controller is focused.
@@ -265,6 +270,7 @@ private Q_SLOTS:
     void showHistoryOptions();
     void clearHistory();
     void clearHistoryAndReset();
+    void monitorOnce(bool once);
     void monitorPrompt(bool monitor);
     void monitorActivity(bool monitor);
     void monitorSilence(bool monitor);
@@ -390,6 +396,7 @@ private:
 
     QString _previousForegroundProcessName;
     bool _monitorProcessFinish;
+    bool _monitorOnce;
     EscapeSequenceUrlFilter *_escapedUrlFilter;
 
     std::unique_ptr<KXMLGUIBuilder> _clientBuilder;


More information about the kde-doc-english mailing list