[gnome-system-monitor] Replaced duplicated code for sending signals with GAction parameters



commit 383007f2fa3a0ede8524fe83f402279c09a242b9
Author: Robert Roth <robert roth off gmail com>
Date:   Thu Jul 25 00:59:41 2013 +0300

    Replaced duplicated code for sending signals with GAction parameters

 data/menus.ui       |    4 ++++
 src/interface.cpp   |   47 ++++++++++++++++-------------------------------
 src/procman-app.cpp |    9 +++++----
 3 files changed, 25 insertions(+), 35 deletions(-)
---
diff --git a/data/menus.ui b/data/menus.ui
index f95c079..ce5bae0 100644
--- a/data/menus.ui
+++ b/data/menus.ui
@@ -62,11 +62,13 @@
         <attribute name="label" translatable="yes">_Stop Process</attribute>
         <attribute name="action">win.send-signal-stop</attribute>
         <attribute name="accel">&lt;Primary&gt;s</attribute>
+        <attribute name="target" type="i">19</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_Continue Process</attribute>
         <attribute name="action">win.send-signal-cont</attribute>
         <attribute name="accel">&lt;Primary&gt;c</attribute>
+        <attribute name="target" type="i">18</attribute>
       </item>
     </section>
     <section>
@@ -74,11 +76,13 @@
         <attribute name="label" translatable="yes">_End Process</attribute>
         <attribute name="action">win.send-signal-end</attribute>
         <attribute name="accel">&lt;Primary&gt;e</attribute>
+        <attribute name="target" type="i">15</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_Kill Process</attribute>
         <attribute name="action">win.send-signal-kill</attribute>
         <attribute name="accel">&lt;Primary&gt;k</attribute>
+        <attribute name="target" type="i">9</attribute>
       </item>
     </section>
     <section>
diff --git a/src/interface.cpp b/src/interface.cpp
index 363cea0..21944a7 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -366,37 +366,22 @@ kill_process_with_confirmation (ProcmanApp *app, int signal) {
 }
 
 static void
-on_activate_send_signal_stop (GSimpleAction *, GVariant *, gpointer data)
+on_activate_send_signal (GSimpleAction *, GVariant *parameter, gpointer data)
 {
     ProcmanApp *app = (ProcmanApp *) data;
 
     /* no confirmation */
-    kill_process (app, SIGSTOP);
-}
-
-static void
-on_activate_send_signal_cont (GSimpleAction *, GVariant *, gpointer data)
-{
-    ProcmanApp *app = (ProcmanApp *) data;
-
-    /* no confirmation */
-    kill_process (app, SIGCONT);
-}
-
-static void
-on_activate_send_signal_end (GSimpleAction *, GVariant *, gpointer data)
-{
-    ProcmanApp *app = (ProcmanApp *) data;
-
-    kill_process_with_confirmation (app, SIGTERM);
-}
-
-static void
-on_activate_send_signal_kill (GSimpleAction *, GVariant *, gpointer data)
-{
-    ProcmanApp *app = (ProcmanApp *) data;
-
-    kill_process_with_confirmation (app, SIGKILL);
+    gint32 signal = g_variant_get_int32(parameter);
+    switch (signal) {
+        case SIGSTOP:
+        case SIGCONT:
+            kill_process (app, signal);
+            break;
+        case SIGTERM:
+        case SIGKILL:
+            kill_process_with_confirmation (app, signal);
+            break;
+    }
 }
 
 static void
@@ -583,10 +568,10 @@ create_main_window (ProcmanApp *app)
 
     GActionEntry win_action_entries[] = {
         { "about", on_activate_about, NULL, NULL, NULL },
-        { "send-signal-stop", on_activate_send_signal_stop, NULL, NULL, NULL },
-        { "send-signal-cont", on_activate_send_signal_cont, NULL, NULL, NULL },
-        { "send-signal-end", on_activate_send_signal_end, NULL, NULL, NULL },
-        { "send-signal-kill", on_activate_send_signal_kill, NULL, NULL, NULL },
+        { "send-signal-stop", on_activate_send_signal, "i", NULL, NULL },
+        { "send-signal-cont", on_activate_send_signal, "i", NULL, NULL },
+        { "send-signal-end", on_activate_send_signal, "i", NULL, NULL },
+        { "send-signal-kill", on_activate_send_signal, "i", NULL, NULL },
         { "priority", on_activate_priority, "s", "'normal'", change_priority_state },
         { "memory-maps", on_activate_memory_maps, NULL, NULL, NULL },
         { "open-files", on_activate_open_files, NULL, NULL, NULL },
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
index 1846569..1116bdd 100644
--- a/src/procman-app.cpp
+++ b/src/procman-app.cpp
@@ -3,6 +3,7 @@
 #include <glib/gi18n.h>
 #include <glibtop.h>
 #include <glibtop/close.h>
+#include <signal.h>
 
 #include "procman-app.h"
 #include "procdialogs.h"
@@ -670,10 +671,10 @@ void ProcmanApp::on_startup()
     set_app_menu (menu);
 
     add_accelerator("<Primary>d", "win.show-dependencies", NULL);
-    add_accelerator("<Primary>s", "win.send-signal-stop", NULL);
-    add_accelerator("<Primary>c", "win.send-signal-cont", NULL);
-    add_accelerator("<Primary>e", "win.send-signal-end", NULL);
-    add_accelerator("<Primary>k", "win.send-signal-kill", NULL);
+    add_accelerator("<Primary>s", "win.send-signal-stop", g_variant_new_int32(SIGSTOP));
+    add_accelerator("<Primary>c", "win.send-signal-cont", g_variant_new_int32(SIGCONT));
+    add_accelerator("<Primary>e", "win.send-signal-end", g_variant_new_int32(SIGTERM));
+    add_accelerator("<Primary>k", "win.send-signal-kill", g_variant_new_int32 (SIGKILL));
     add_accelerator("<Primary>m", "win.memory-maps", NULL);
     add_accelerator("<Primary>f", "win.open-files", NULL);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]