[gnome-system-monitor] Port to GtkStack and GtkHeaderBar



commit 1d2e60ad778d82247fb93619f037e454a9f1d773
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Jul 25 14:52:52 2013 +0200

    Port to GtkStack and GtkHeaderBar
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674405

 data/interface.ui                                 |   54 +++++++--------------
 src/interface.cpp                                 |   24 +++++-----
 src/load-graph.cpp                                |    2 +-
 src/org.gnome.gnome-system-monitor.gschema.xml.in |   13 +++--
 src/procdialogs.cpp                               |   18 +++----
 src/procman-app.cpp                               |   28 +++++------
 src/procman-app.h                                 |    2 +-
 7 files changed, 59 insertions(+), 82 deletions(-)
---
diff --git a/data/interface.ui b/data/interface.ui
index b9109bd..f8c2ae3 100644
--- a/data/interface.ui
+++ b/data/interface.ui
@@ -13,7 +13,18 @@
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkNotebook" id="notebook">
+          <object class="GtkHeaderBar" id="header_bar">
+            <property name="visible">True</property>
+            <child type="title">
+              <object class="GtkStackSwitcher" id="stack_switcher">
+                <property name="visible">True</property>
+                <property name="stack">stack</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkStack" id="stack">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="hexpand">True</property>
@@ -141,15 +152,9 @@
                   </packing>
                 </child>
               </object>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="proc_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Processes</property>
-              </object>
               <packing>
-                <property name="tab_fill">False</property>
+                <property name="name">processes</property>
+                <property name="title" translatable="yes">Processes</property>
               </packing>
             </child>
             <child>
@@ -551,18 +556,8 @@
                 </child>
               </object>
               <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="res_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Resources</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-                <property name="tab_fill">False</property>
+                <property name="name">resources</property>
+                <property name="title" translatable="yes">Resources</property>
               </packing>
             </child>
             <child>
@@ -591,18 +586,8 @@
                 </child>
               </object>
               <packing>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="fs_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">File Systems</property>
-              </object>
-              <packing>
-                <property name="position">2</property>
-                <property name="tab_fill">False</property>
+                <property name="name">disks</property>
+                <property name="title" translatable="yes">File Systems</property>
               </packing>
             </child>
           </object>
@@ -613,9 +598,6 @@
             <property name="position">0</property>
           </packing>
         </child>
-        <child>
-          <placeholder/>
-        </child>
       </object>
     </child>
   </object>
diff --git a/src/interface.cpp b/src/interface.cpp
index 8c20370..0ba54bd 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -478,9 +478,9 @@ change_priority_state (GSimpleAction *action, GVariant *state, gpointer data)
 void
 update_page_activities (ProcmanApp *app)
 {
-    int current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (app->notebook));
+    const char *current_page = gtk_stack_get_visible_child_name (GTK_STACK (app->stack));
 
-    if (current_page == PROCMAN_TAB_PROCESSES) {
+    if (strcmp (current_page, "processes") == 0) {
         proctable_thaw (app);
 
         update_sensitivity (app);
@@ -492,7 +492,7 @@ update_page_activities (ProcmanApp *app)
         update_sensitivity (app);
     }
 
-    if (current_page == PROCMAN_TAB_RESOURCES) {
+    if (strcmp (current_page, "resources") == 0) {
         load_graph_start (app->cpu_graph);
         load_graph_start (app->mem_graph);
         load_graph_start (app->net_graph);
@@ -502,7 +502,7 @@ update_page_activities (ProcmanApp *app)
         load_graph_stop (app->net_graph);
     }
 
-    if (current_page == PROCMAN_TAB_DISKS) {
+    if (strcmp (current_page, "disks") == 0) {
                disks_update (app);
                disks_thaw (app);
     } else {
@@ -511,7 +511,7 @@ update_page_activities (ProcmanApp *app)
 }
 
 static void
-cb_change_current_page (GtkNotebook *notebook, GParamSpec *pspec, gpointer data)
+cb_change_current_page (GtkStack *stack, GParamSpec *pspec, gpointer data)
 {
     update_page_activities ((ProcmanApp *)data);
 }
@@ -531,7 +531,7 @@ create_main_window (ProcmanApp *app)
 {
     gint width, height, xpos, ypos;
     GtkWidget *main_window;
-    GtkWidget *notebook;
+    GtkWidget *stack;
     GtkWidget *view_menu_button;
     GMenuModel *view_menu_model;
 
@@ -559,7 +559,7 @@ create_main_window (ProcmanApp *app)
         { "open-files", on_activate_open_files, NULL, NULL, NULL },
         { "process-properties", on_activate_process_properties, NULL, NULL, NULL },
         { "refresh", on_activate_refresh, NULL, NULL, NULL },
-        { "show-page", on_activate_radio, "i", "0", change_show_page_state },
+        { "show-page", on_activate_radio, "s", "'resources'", 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 }
     };
@@ -586,8 +586,8 @@ create_main_window (ProcmanApp *app)
         gtk_window_maximize(GTK_WINDOW(main_window));
     }
 
-    /* create the main notebook */
-    app->notebook = notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook"));
+    /* create the main stack */
+    app->stack = stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack"));
 
     create_proc_view(app, builder);
 
@@ -595,9 +595,9 @@ create_main_window (ProcmanApp *app)
     
     create_disk_view (app, builder);
 
-    g_settings_bind (app->settings, "current-tab", notebook, "page", G_SETTINGS_BIND_DEFAULT);
+    g_settings_bind (app->settings, "current-tab", stack, "visible-child-name", G_SETTINGS_BIND_DEFAULT);
 
-    g_signal_connect (G_OBJECT (notebook), "notify::page",
+    g_signal_connect (G_OBJECT (stack), "notify::visible-child",
                       G_CALLBACK (cb_change_current_page), app);
     update_page_activities (app);
 
@@ -661,7 +661,7 @@ update_sensitivity(ProcmanApp *app)
     gboolean processes_sensitivity, selected_sensitivity;
     GAction *action;
 
-    processes_sensitivity = (g_settings_get_int (app->settings, "current-tab") == PROCMAN_TAB_PROCESSES);
+    processes_sensitivity = (strcmp (g_settings_get_string (app->settings, "current-tab"), "processes") == 
0);
     selected_sensitivity = (processes_sensitivity && app->selected_process != NULL);
 
     for (i = 0; i != G_N_ELEMENTS(processes_actions); ++i) {
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 76a905c..10b347b 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -91,7 +91,7 @@ void draw_background(LoadGraph *graph) {
                                                            allocation.height);
     cr = cairo_create (graph->background);
 
-    GtkStyleContext *context = gtk_widget_get_style_context (ProcmanApp::get()->notebook);
+    GtkStyleContext *context = gtk_widget_get_style_context (ProcmanApp::get()->stack);
     gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
     gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg);
 
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in 
b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index c72ce08..01b1250 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -113,14 +113,15 @@
       <_summary>Determines which processes to show.</_summary>
     </key>
 
-    <key name="current-tab" type="i">
-      <range min="0" max="2"/>
-      <default>1
-      </default>
+    <key name="current-tab" type="s">
+      <choices>
+        <choice value="processes"/>
+        <choice value="resources"/>
+        <choice value="disks"/>
+      </choices>
+      <default>'resources'</default>
       <_summary>Saves the currently viewed tab
       </_summary>
-      <_description>0 for the processes list, 1 for the resources and 2 for the disks list
-      </_description>
     </key>
 
     <key name="cpu-colors" type="a(us)">
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index ac397a0..6a8b661 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -468,18 +468,14 @@ procdialog_create_preferences_dialog (ProcmanApp *app)
     g_signal_connect (G_OBJECT (prefs_dialog), "response",
                       G_CALLBACK (prefs_dialog_button_pressed), app);
 
-    switch (g_settings_get_int (app->settings, "current-tab")) {
-        case PROCMAN_TAB_PROCESSES:
-            gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
-            break;
-        case PROCMAN_TAB_RESOURCES:
-            gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
-            break;
-        case PROCMAN_TAB_DISKS:
-            gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
-            break;
+    const char* current_tab = g_settings_get_string (app->settings, "current-tab");
+    if (strcmp (current_tab, "processes") == 0)
+        gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
+    else if (strcmp (current_tab, "resources") == 0)
+        gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
+    else if (strcmp (current_tab, "disks") == 0)
+        gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
 
-    }
     gtk_builder_connect_signals (builder, NULL);
     g_object_unref (G_OBJECT (builder));
 }
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
index 221604e..f841764 100644
--- a/src/procman-app.cpp
+++ b/src/procman-app.cpp
@@ -542,21 +542,19 @@ int ProcmanApp::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>&
 
     g_strfreev(argv);
 
-    if (option_group.show_processes_tab) {
-        procman_debug("Starting with PROCMAN_TAB_PROCESSES by commandline request");
-        g_settings_set_int (settings, "current-tab", PROCMAN_TAB_PROCESSES);
-    } else if (option_group.show_resources_tab) {
-        procman_debug("Starting with PROCMAN_TAB_RESOURCES by commandline request");
-        g_settings_set_int (settings, "current-tab", PROCMAN_TAB_RESOURCES);
-    } else if (option_group.show_file_systems_tab) {
-        procman_debug("Starting with PROCMAN_TAB_DISKS by commandline request");
-        g_settings_set_int (settings, "current-tab", PROCMAN_TAB_DISKS);
-    } else if (option_group.print_version) {
+    if (option_group.print_version) {
         g_print("%s %s\n", _("GNOME System Monitor"), VERSION);
-       exit (EXIT_SUCCESS);
-       return 0;
+        exit (EXIT_SUCCESS);
     }
 
+    if (option_group.show_processes_tab)
+        g_settings_set_string (settings, "current-tab", "processes");
+    else if (option_group.show_resources_tab)
+        g_settings_set_string (settings, "current-tab", "resources");
+    else if (option_group.show_file_systems_tab)
+        g_settings_set_string (settings, "current-tab", "disks");
+    else if (option_group.print_version)
+
     on_activate ();
 
     return 0;
@@ -655,9 +653,9 @@ void ProcmanApp::on_startup()
 
     create_main_window (this);
 
-    add_accelerator ("<Alt>1", "win.show-page", g_variant_new_int32 (PROCMAN_TAB_PROCESSES));
-    add_accelerator ("<Alt>2", "win.show-page", g_variant_new_int32 (PROCMAN_TAB_RESOURCES));
-    add_accelerator ("<Alt>3", "win.show-page", g_variant_new_int32 (PROCMAN_TAB_DISKS));
+    add_accelerator ("<Alt>1", "win.show-page", g_variant_new_string ("processes"));
+    add_accelerator ("<Alt>2", "win.show-page", g_variant_new_string ("resources"));
+    add_accelerator ("<Alt>3", "win.show-page", g_variant_new_string ("disks"));
     add_accelerator ("<Primary>r", "win.refresh", NULL);
 
     gtk_widget_show (main_window);
diff --git a/src/procman-app.h b/src/procman-app.h
index 8f374e7..956722e 100644
--- a/src/procman-app.h
+++ b/src/procman-app.h
@@ -168,7 +168,7 @@ public:
     GtkWidget        *loadavg;
     GtkWidget        *popup_menu;
     GtkWidget        *disk_list;
-    GtkWidget        *notebook;
+    GtkWidget        *stack;
     ProcConfig        config;
     LoadGraph        *cpu_graph;
     LoadGraph        *mem_graph;


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