[gnome-system-monitor] Port View menu to GAction



commit d43c6621dcaba308ca747230f810d739145ac805
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Jul 18 14:38:32 2013 +0200

    Port View menu to GAction
    
    gsettings keys "show-tree" and "view-as" are renamed to
    "show-dependencies" and "show-whose-processes", respectively.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704467

 data/interface.ui                                 |   27 +++++
 data/menus.ui                                     |    1 +
 data/popups.ui                                    |    7 --
 src/callbacks.cpp                                 |   10 --
 src/callbacks.h                                   |    4 -
 src/interface.cpp                                 |  114 +++++++++------------
 src/org.gnome.gnome-system-monitor.gschema.xml.in |   15 ++-
 src/procman-app.cpp                               |   20 +---
 src/procman-app.h                                 |    9 --
 src/proctable.cpp                                 |   34 +++----
 10 files changed, 105 insertions(+), 136 deletions(-)
---
diff --git a/data/interface.ui b/data/interface.ui
index abbce81..db76ef3 100644
--- a/data/interface.ui
+++ b/data/interface.ui
@@ -61,6 +61,7 @@
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="halign">end</property>
+                        <property name="menu_model">view-menu</property>
                         <child>
                           <object class="GtkBox" id="box1">
                             <property name="visible">True</property>
@@ -617,4 +618,30 @@
       </object>
     </child>
   </object>
+  <menu id="view-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Active Processes</attribute>
+        <attribute name="action">win.show-whose-processes</attribute>
+        <attribute name="target">active</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">A_ll Processes</attribute>
+        <attribute name="action">win.show-whose-processes</attribute>
+        <attribute name="target">all</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">M_y Processes</attribute>
+        <attribute name="action">win.show-whose-processes</attribute>
+        <attribute name="target">user</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Dependencies</attribute>
+        <attribute name="action">win.show-dependencies</attribute>
+        <attribute name="accel">&lt;Primary&gt;d</attribute>
+      </item>
+    </section>
+  </menu>
 </interface>
diff --git a/data/menus.ui b/data/menus.ui
index f582813..4b734e9 100644
--- a/data/menus.ui
+++ b/data/menus.ui
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <interface>
   <menu id="app-menu">
     <section>
diff --git a/data/popups.ui b/data/popups.ui
index 5f581b2..715dc92 100644
--- a/data/popups.ui
+++ b/data/popups.ui
@@ -21,11 +21,4 @@
     <separator />
     <menuitem action="ProcessProperties" />
   </popup>
-  <popup name="ViewMenu" action="View">
-    <menuitem name="ViewActiveProcesses" action="ShowActiveProcesses" />
-    <menuitem name="ViewAllProcesses" action="ShowAllProcesses" />
-    <menuitem name="ViewMyProcesses" action="ShowMyProcesses" />
-    <separator />
-    <menuitem name="ViewDependencies" action="ShowDependencies" />
-  </popup>
 </ui>
diff --git a/src/callbacks.cpp b/src/callbacks.cpp
index 6204790..7a13b3b 100644
--- a/src/callbacks.cpp
+++ b/src/callbacks.cpp
@@ -420,16 +420,6 @@ cb_refresh_icons (GtkIconTheme *theme, gpointer data)
     cb_timeout(app);
 }
 
-void
-cb_radio_processes(GtkAction *action, GtkRadioAction *current, gpointer data)
-{
-    ProcmanApp * const app = static_cast<ProcmanApp *>(data);
-
-    app->config.whose_process = gtk_radio_action_get_current_value(current);
-
-    g_settings_set_int (app->settings, "view-as",
-                        app->config.whose_process);
-}
 
 void
 cb_column_resized(GtkWidget *widget, GParamSpec* param, gpointer data)
diff --git a/src/callbacks.h b/src/callbacks.h
index 4ec4730..ff091b2 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -62,10 +62,6 @@ gint            cb_timeout (gpointer data);
 
 void            cb_refresh_icons (GtkIconTheme *theme, gpointer data);
 
-void            cb_radio_processes(GtkAction *action,
-                                   GtkRadioAction *current,
-                                   gpointer data);
-
 void            cb_column_resized (GtkWidget* column, GParamSpec* param, gpointer data);
 
 
diff --git a/src/interface.cpp b/src/interface.cpp
index 370257c..55170d4 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -39,12 +39,8 @@
 #include "disks.h"
 #include "gsm_color_button.h"
 
-static void     cb_toggle_tree (GtkAction *action, gpointer data);
-
 static const GtkActionEntry menu_entries[] =
 {
-    { "View", NULL, N_("_View") },
-
     { "StopProcess", NULL, N_("_Stop Process"), "<control>S",
       N_("Stop process"), G_CALLBACK(cb_kill_sigstop) },
     { "ContProcess", NULL, N_("_Continue Process"), "<control>C",
@@ -69,24 +65,6 @@ static const GtkActionEntry menu_entries[] =
       N_("View additional information about a process"), G_CALLBACK (cb_show_process_properties) },
 };
 
-static const GtkToggleActionEntry toggle_menu_entries[] =
-{
-    { "ShowDependencies", NULL, N_("_Dependencies"), "<control>D",
-      N_("Show parent/child relationship between processes"),
-      G_CALLBACK (cb_toggle_tree), TRUE },
-};
-
-
-static const GtkRadioActionEntry radio_menu_entries[] =
-{
-    { "ShowActiveProcesses", NULL, N_("_Active Processes"), NULL,
-      N_("Show active processes"), ACTIVE_PROCESSES },
-    { "ShowAllProcesses", NULL, N_("A_ll Processes"), NULL,
-      N_("Show all processes"), ALL_PROCESSES },
-    { "ShowMyProcesses", NULL, N_("M_y Processes"), NULL,
-      N_("Show only user-owned processes"), MY_PROCESSES }
-};
-
 static const GtkRadioActionEntry priority_menu_entries[] =
 {
     { "VeryHigh", NULL, N_("Very High"), NULL,
@@ -129,9 +107,6 @@ create_proc_view(ProcmanApp *app, GtkBuilder * builder)
                       G_CALLBACK (cb_end_process_button_pressed), app);
 
     button = GTK_WIDGET (gtk_builder_get_object (builder, "viewmenubutton"));
-    viewmenu = gtk_ui_manager_get_widget (app->uimanager, "/ViewMenu");
-    gtk_widget_set_halign (viewmenu, GTK_ALIGN_END);
-    gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), viewmenu);
 
     button = GTK_WIDGET (gtk_builder_get_object (builder, "refreshbutton"));
     action = gtk_action_group_get_action (app->action_group, "Refresh");
@@ -314,6 +289,14 @@ on_activate_radio (GSimpleAction *action, GVariant *parameter, gpointer data)
 }
 
 static void
+on_activate_toggle (GSimpleAction *action, GVariant *parameter, gpointer data)
+{
+    GVariant *state = g_action_get_state (G_ACTION (action));
+    g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
+    g_variant_unref (state);
+}
+
+static void
 change_show_page_state (GSimpleAction *action, GVariant *state, gpointer data)
 {
     ProcmanApp *app = (ProcmanApp *) data;
@@ -322,6 +305,24 @@ change_show_page_state (GSimpleAction *action, GVariant *state, gpointer data)
     g_settings_set_value (app->settings, "current-tab", state);
 }
 
+static void
+change_show_processes_state (GSimpleAction *action, GVariant *state, gpointer data)
+{
+    ProcmanApp *app = (ProcmanApp *) data;
+
+    g_simple_action_set_state (action, state);
+    g_settings_set_value (app->settings, "show-whose-processes", state);
+}
+
+static void
+change_show_dependencies_state (GSimpleAction *action, GVariant *state, gpointer data)
+{
+    ProcmanApp *app = (ProcmanApp *) data;
+
+    g_simple_action_set_state (action, state);
+    g_settings_set_value (app->settings, "show-dependencies", state);
+}
+
 void
 update_page_activities (ProcmanApp *app)
 {
@@ -385,7 +386,6 @@ create_main_window (ProcmanApp *app)
     gint i;
     gint width, height, xpos, ypos;
     GtkWidget *main_window;
-    GtkAction *action;
     GtkWidget *notebook;
 
     GtkBuilder *builder = gtk_builder_new();
@@ -394,10 +394,13 @@ create_main_window (ProcmanApp *app)
     main_window = GTK_WIDGET (gtk_builder_get_object (builder, "main_window"));
     gtk_window_set_application (GTK_WINDOW (main_window), app->gobj());
     gtk_widget_set_name (main_window, "gnome-system-monitor");
+    app->main_window = main_window;
 
     GActionEntry win_action_entries[] = {
         { "about", on_activate_about, NULL, NULL, NULL },
-        { "show-page", on_activate_radio, "i", "0", change_show_page_state }
+        { "show-page", on_activate_radio, "i", "0", change_show_page_state },
+        { "show-whose-processes", on_activate_radio, "s", "'all'", change_show_processes_state },
+        { "show-dependencies", on_activate_toggle, NULL, "false", change_show_dependencies_state }
     };
 
     g_action_map_add_action_entries (G_ACTION_MAP (main_window),
@@ -439,17 +442,6 @@ create_main_window (ProcmanApp *app)
                                   menu_entries,
                                   G_N_ELEMENTS (menu_entries),
                                   app);
-    gtk_action_group_add_toggle_actions (app->action_group,
-                                         toggle_menu_entries,
-                                         G_N_ELEMENTS (toggle_menu_entries),
-                                         app);
-
-    gtk_action_group_add_radio_actions (app->action_group,
-                                        radio_menu_entries,
-                                        G_N_ELEMENTS (radio_menu_entries),
-                                        app->config.whose_process,
-                                        G_CALLBACK(cb_radio_processes),
-                                        app);
 
     gtk_action_group_add_radio_actions (app->action_group,
                                         priority_menu_entries,
@@ -481,15 +473,21 @@ create_main_window (ProcmanApp *app)
                       G_CALLBACK (cb_main_window_delete),
                       app);
 
-    action = gtk_action_group_get_action (app->action_group, "ShowDependencies");
-    gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
-                                  app->config.show_tree);
+    GAction *action;
+    action = g_action_map_lookup_action (G_ACTION_MAP (main_window),
+                                         "show-dependencies");
+    g_action_change_state (action,
+                           g_settings_get_value (app->settings, "show-dependencies"));
+
+
+    action = g_action_map_lookup_action (G_ACTION_MAP (main_window),
+                                         "show-whose-processes");
+    g_action_change_state (action,
+                           g_settings_get_value (app->settings, "show-whose-processes"));
 
-    
     gtk_builder_connect_signals (builder, NULL);
 
     gtk_widget_show_all(main_window);
-    app->main_window = main_window;
 
     g_object_unref (G_OBJECT (builder));
 }
@@ -525,16 +523,14 @@ update_sensitivity(ProcmanApp *app)
                                               "OpenFiles",
                                               "ProcessProperties" };
 
-    const char * const processes_actions[] = { "ShowActiveProcesses",
-                                               "ShowAllProcesses",
-                                               "ShowMyProcesses",
-                                               "ShowDependencies",
-                                               "Refresh"
-    };
+    // FIXME: add Refresh when ported
+    const char * const processes_actions[] = { "show-whose-processes",
+                                               "show-dependencies" };
 
     size_t i;
     gboolean processes_sensitivity, selected_sensitivity;
     GtkAction *action;
+    GAction *gaction;
 
     processes_sensitivity = (g_settings_get_int (app->settings, "current-tab") == PROCMAN_TAB_PROCESSES);
     selected_sensitivity = (processes_sensitivity && app->selected_process != NULL);
@@ -546,9 +542,9 @@ update_sensitivity(ProcmanApp *app)
     }
 
     for (i = 0; i != G_N_ELEMENTS(processes_actions); ++i) {
-        action = gtk_action_group_get_action(app->action_group,
-                                             processes_actions[i]);
-        gtk_action_set_sensitive(action, processes_sensitivity);
+        gaction = g_action_map_lookup_action (G_ACTION_MAP (app->main_window),
+                                              processes_actions[i]);
+        g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction), processes_sensitivity);
     }
 
     for (i = 0; i != G_N_ELEMENTS(selected_actions); ++i) {
@@ -576,17 +572,3 @@ block_priority_changed_handlers(ProcmanApp *app, bool block)
         }
     }
 }
-
-static void
-cb_toggle_tree (GtkAction *action, gpointer data)
-{
-    ProcmanApp *app = static_cast<ProcmanApp *>(data);
-    GSettings *settings = app->settings;
-    gboolean show;
-
-    show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-    if (show == app->config.show_tree)
-        return;
-
-    g_settings_set_boolean (settings, "show-tree", show);
-}
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in 
b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index 314faa6..c72ce08 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -35,7 +35,7 @@
       </_summary>
     </key>
 
-    <key name="show-tree" type="b">
+    <key name="show-dependencies" type="b">
       <default>false
       </default>
       <_summary>Show process dependencies in tree form
@@ -103,11 +103,14 @@
       </_summary>
     </key>
 
-    <key name="view-as" type="i">
-      <default>1
-      </default>
-      <_summary>Determines which processes to show by default. 0 is All, 1 is user, and 2 is active
-      </_summary>
+    <key name="show-whose-processes" type="s">
+      <default>'user'</default>
+      <choices>
+        <choice value="all"/>
+        <choice value="user"/>
+        <choice value="active"/>
+      </choices>
+      <_summary>Determines which processes to show.</_summary>
     </key>
 
     <key name="current-tab" type="i">
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
index 671077b..5632341 100644
--- a/src/procman-app.cpp
+++ b/src/procman-app.cpp
@@ -35,15 +35,12 @@ init_volume_monitor(ProcmanApp *app)
 }
 
 static void
-tree_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+cb_show_dependencies_changed (GSettings *settings, const gchar *key, gpointer data)
 {
     ProcmanApp *app = static_cast<ProcmanApp *>(data);
 
-    app->config.show_tree = g_settings_get_boolean(settings, key);
-
-    g_object_set(G_OBJECT(app->tree),
-                 "show-expanders", app->config.show_tree,
-                 NULL);
+    gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (app->tree),
+                                      g_settings_get_boolean (settings, "show-dependencies"));
 
     proctable_clear_tree (app);
     proctable_update_all (app);
@@ -81,12 +78,10 @@ network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data)
 }
 
 static void
-view_as_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+cb_show_whose_processes_changed (GSettings *settings, const gchar *key, gpointer data)
 {
     ProcmanApp *app = static_cast<ProcmanApp *>(data);
 
-    app->config.whose_process = g_settings_get_int (settings, key);
-    app->config.whose_process = CLAMP (app->config.whose_process, 0, 2);
     proctable_clear_tree (app);
     proctable_update_all (app);
 }
@@ -257,8 +252,7 @@ ProcmanApp::load_settings()
     config.ypos = g_settings_get_int (settings, "y-position");
     config.maximized = g_settings_get_boolean (settings, "maximized");
 
-    config.show_tree = g_settings_get_boolean (settings, "show-tree");
-    g_signal_connect (G_OBJECT(settings), "changed::show-tree", G_CALLBACK(tree_changed_cb), this);
+    g_signal_connect (G_OBJECT(settings), "changed::show-dependencies", 
G_CALLBACK(cb_show_dependencies_changed), this);
 
     config.solaris_mode = g_settings_get_boolean(settings, procman::settings::solaris_mode.c_str());
     std::string detail_string("changed::" + procman::settings::solaris_mode);
@@ -289,8 +283,7 @@ ProcmanApp::load_settings()
     g_signal_connect (settings, "changed::show-all-fs", G_CALLBACK(show_all_fs_changed_cb), this);
 
 
-    config.whose_process = g_settings_get_int (settings, "view-as");
-    g_signal_connect (G_OBJECT(settings), "changed::view-as", G_CALLBACK(view_as_changed_cb), this);
+    g_signal_connect (G_OBJECT(settings), "changed::show-whose-processes", 
G_CALLBACK(cb_show_whose_processes_changed), this);
 
     /* Determine number of cpus since libgtop doesn't really tell you*/
     config.num_cpus = 0;
@@ -349,7 +342,6 @@ ProcmanApp::load_settings()
     config.update_interval = MAX (config.update_interval, 1000);
     config.graph_update_interval = MAX (config.graph_update_interval, 250);
     config.disks_update_interval = MAX (config.disks_update_interval, 1000);
-    config.whose_process = CLAMP (config.whose_process, 0, 2);
 }
 
 ProcmanApp::ProcmanApp() : Gtk::Application("org.gnome.SystemMonitor", Gio::APPLICATION_HANDLES_COMMAND_LINE)
diff --git a/src/procman-app.h b/src/procman-app.h
index 3fd2258..6aea147 100644
--- a/src/procman-app.h
+++ b/src/procman-app.h
@@ -14,13 +14,6 @@ struct LoadGraph;
 
 enum
 {
-    ALL_PROCESSES,
-    MY_PROCESSES,
-    ACTIVE_PROCESSES
-};
-
-enum
-{
     VERY_HIGH_PRIORITY,
     HIGH_PRIORITY,
     NORMAL_PRIORITY,
@@ -49,12 +42,10 @@ struct ProcConfig
     gint            ypos;
     gboolean        maximized;
     gboolean        show_kill_warning;
-    gboolean        show_tree;
     gboolean        show_all_fs;
     int             update_interval;
     int             graph_update_interval;
     int             disks_update_interval;
-    gint            whose_process;
     GdkRGBA         cpu_color[GLIBTOP_NCPU];
     GdkRGBA         mem_color;
     GdkRGBA         swap_color;
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 4409460..9587c53 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -261,9 +261,8 @@ proctable_new (ProcmanApp * const app)
 
     proctree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
     gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (proctree), COL_TOOLTIP);
-    g_object_set(G_OBJECT(proctree),
-                 "show-expanders", app->config.show_tree,
-                 NULL);
+    gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (proctree),
+                                      g_settings_get_boolean (app->settings, "show-dependencies"));
     gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (proctree),
                                          search_equal_func,
                                          NULL,
@@ -649,7 +648,7 @@ insert_info_to_tree (ProcInfo *info, ProcmanApp *app, bool forced = false)
 
     model = gtk_tree_view_get_model (GTK_TREE_VIEW (app->tree));
 
-    if (app->config.show_tree) {
+    if (g_settings_get_boolean (app->settings, "show-dependencies")) {
 
         ProcInfo *parent = 0;
 
@@ -899,7 +898,7 @@ refresh_list (ProcmanApp *app, const pid_t* pid_list, const guint n)
     // pid_list == ProcInfo::all + addition
 
 
-    if (app->config.show_tree) {
+    if (g_settings_get_boolean (app->settings, "show-dependencies")) {
 
         // insert process in the tree. walk through the addition list
         // (new process + process that have a new parent). This loop
@@ -976,21 +975,16 @@ proctable_update_list (ProcmanApp *app)
     glibtop_cpu cpu;
     gint which, arg;
 
-    switch (app->config.whose_process) {
-        case ALL_PROCESSES:
-            which = GLIBTOP_KERN_PROC_ALL;
-            arg = 0;
-            break;
-
-        case ACTIVE_PROCESSES:
-            which = GLIBTOP_KERN_PROC_ALL | GLIBTOP_EXCLUDE_IDLE;
-            arg = 0;
-            break;
-
-        default:
-            which = GLIBTOP_KERN_PROC_UID;
-            arg = getuid ();
-            break;
+    const char* whose_processes = g_settings_get_string (app->settings, "show-whose-processes");
+    if (strcmp (whose_processes, "all") == 0) {
+        which = GLIBTOP_KERN_PROC_ALL;
+        arg = 0;
+    } else if (strcmp (whose_processes, "active") == 0) {
+        which = GLIBTOP_KERN_PROC_ALL | GLIBTOP_EXCLUDE_IDLE;
+        arg = 0;
+    } else if (strcmp (whose_processes, "user") == 0) {
+      which = GLIBTOP_KERN_PROC_UID;
+      arg = getuid ();
     }
 
     pid_list = glibtop_get_proclist (&proclist, which, arg);


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