[gnome-system-monitor] Refactored procaction execution to use one common struct



commit d796c47eb219dd7a4f8db87d1779bb4d5060e5df
Author: Robert Roth <robert roth off gmail com>
Date:   Sun Aug 11 16:55:08 2013 +0300

    Refactored procaction execution to use one common struct

 src/application.h   |   13 -------------
 src/procactions.cpp |   22 +++++++++++-----------
 src/procactions.h   |    6 ++++++
 src/procdialogs.cpp |   10 +++++-----
 4 files changed, 22 insertions(+), 29 deletions(-)
---
diff --git a/src/application.h b/src/application.h
index 8a32d14..abb3b85 100644
--- a/src/application.h
+++ b/src/application.h
@@ -198,17 +198,4 @@ protected:
     virtual void on_startup();
 };
 
-struct ReniceArgs
-{
-    GsmApplication *app;
-    int nice_value;
-};
-
-
-struct KillArgs
-{
-    GsmApplication *app;
-    int signal;
-};
-
 #endif /* _GSM_APPLICATION_H_ */
diff --git a/src/procactions.cpp b/src/procactions.cpp
index 0f192c2..65626d9 100644
--- a/src/procactions.cpp
+++ b/src/procactions.cpp
@@ -35,7 +35,7 @@
 static void
 renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
 {
-    const struct ReniceArgs * const args = static_cast<ReniceArgs*>(data);
+    const struct ProcActionArgs * const args = static_cast<ProcActionArgs*>(data);
 
     ProcInfo *info = NULL;
     gint error;
@@ -47,9 +47,9 @@ renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter
 
     if (!info)
         return;
-    if (info->nice == args->nice_value)
+    if (info->nice == args->arg_value)
         return;
-    error = setpriority (PRIO_PROCESS, info->pid, args->nice_value);
+    error = setpriority (PRIO_PROCESS, info->pid, args->arg_value);
 
     /* success */
     if(error != -1) return;
@@ -62,7 +62,7 @@ renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter
 
         success = procdialog_create_root_password_dialog (
             PROCMAN_ACTION_RENICE, args->app, info->pid,
-            args->nice_value);
+            args->arg_value);
 
         if(success) return;
 
@@ -75,7 +75,7 @@ renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter
     error_msg = g_strdup_printf (
         _("Cannot change the priority of process with PID %d to %d.\n"
           "%s"),
-        info->pid, args->nice_value, g_strerror(saved_errno));
+        info->pid, args->arg_value, g_strerror(saved_errno));
 
     dialog = gtk_message_dialog_new (
         NULL,
@@ -93,7 +93,7 @@ renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter
 void
 renice (GsmApplication *app, int nice)
 {
-    struct ReniceArgs args = { app, nice };
+    struct ProcActionArgs args = { app, nice };
 
     /* EEEK - ugly hack - make sure the table is not updated as a crash
     ** occurs if you first kill a process and the tree node is removed while
@@ -115,7 +115,7 @@ renice (GsmApplication *app, int nice)
 static void
 kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
 {
-    const struct KillArgs * const args = static_cast<KillArgs*>(data);
+    const struct ProcActionArgs * const args = static_cast<ProcActionArgs*>(data);
     char *error_msg;
     ProcInfo *info;
     int error;
@@ -127,7 +127,7 @@ kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
     if (!info)
         return;
 
-    error = kill (info->pid, args->signal);
+    error = kill (info->pid, args->arg_value);
 
     /* success */
     if(error != -1) return;
@@ -140,7 +140,7 @@ kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
 
         success = procdialog_create_root_password_dialog (
             PROCMAN_ACTION_KILL, args->app, info->pid,
-            args->signal);
+            args->arg_value);
 
         if(success) return;
 
@@ -153,7 +153,7 @@ kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
     error_msg = g_strdup_printf (
         _("Cannot kill process with PID %d with signal %d.\n"
           "%s"),
-        info->pid, args->signal, g_strerror(saved_errno));
+        info->pid, args->arg_value, g_strerror(saved_errno));
 
     dialog = gtk_message_dialog_new (
         NULL,
@@ -171,7 +171,7 @@ kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
 void
 kill_process (GsmApplication *app, int sig)
 {
-    struct KillArgs args = { app, sig };
+    struct ProcActionArgs args = { app, sig };
 
     /* EEEK - ugly hack - make sure the table is not updated as a crash
     ** occurs if you first kill a process and the tree node is removed while
diff --git a/src/procactions.h b/src/procactions.h
index 4b16fb2..2c064ce 100644
--- a/src/procactions.h
+++ b/src/procactions.h
@@ -25,4 +25,10 @@
 void            renice (GsmApplication *app, int nice);
 void            kill_process (GsmApplication *app, int sig);
 
+struct ProcActionArgs
+{
+    GsmApplication *app;
+    int arg_value;
+};
+
 #endif /* _GSM_PROCACTIONS_H_ */
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index f84ae00..6694828 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -44,12 +44,12 @@ static gint new_nice_value = 0;
 static void
 kill_dialog_button_pressed (GtkDialog *dialog, gint id, gpointer data)
 {
-    struct KillArgs *kargs = static_cast<KillArgs*>(data);
+    struct ProcActionArgs *kargs = static_cast<ProcActionArgs*>(data);
 
     gtk_widget_destroy (GTK_WIDGET (dialog));
 
     if (id == GTK_RESPONSE_OK)
-        kill_process (kargs->app, kargs->signal);
+        kill_process (kargs->app, kargs->arg_value);
 
     g_free (kargs);
 }
@@ -59,11 +59,11 @@ procdialog_create_kill_dialog (GsmApplication *app, int signal)
 {
     GtkWidget *kill_alert_dialog;
     gchar *primary, *secondary, *button_text;
-    struct KillArgs *kargs;
+    struct ProcActionArgs *kargs;
 
-    kargs = g_new(KillArgs, 1);
+    kargs = g_new(ProcActionArgs, 1);
     kargs->app = app;
-    kargs->signal = signal;
+    kargs->arg_value = signal;
     gint selected_count = gtk_tree_selection_count_selected_rows (app->selection);
 
     if ( selected_count == 1 ) {


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