[gnome-system-monitor] Moved renice dialog into UI file



commit a7c6043aea197fa47d4224d2d8a8ebd409eb31e6
Author: Robert Roth <robert roth off gmail com>
Date:   Sat Jan 28 07:33:13 2012 +0200

    Moved renice dialog into UI file

 data/preferences.ui |  171 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/procdialogs.cpp |   78 +++++++----------------
 2 files changed, 191 insertions(+), 58 deletions(-)
---
diff --git a/data/preferences.ui b/data/preferences.ui
index 3165076..375bfd8 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -1,6 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkImage" id="ok_image">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-ok</property>
+  </object>
   <object class="GtkDialog" id="preferences_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -13,10 +18,6 @@
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog_layout">
         <property name="can_focus">False</property>
-        <property name="margin_left">5</property>
-        <property name="margin_right">5</property>
-        <property name="margin_top">5</property>
-        <property name="margin_bottom">5</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
@@ -734,4 +735,166 @@
       <action-widget response="-7">close_button</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkAdjustment" id="renice_adj">
+    <property name="lower">-20</property>
+    <property name="upper">20</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkDialog" id="renice_dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="resizable">False</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_resize_grip">False</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="renice_layout">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="renice_action_area">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="change_priority_button">
+                <property name="label" translatable="yes">Change _Priority</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="image">ok_image</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="dialog_content_grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
+            <property name="orientation">vertical</property>
+            <property name="row_spacing">12</property>
+            <child>
+              <object class="GtkGrid" id="renice_grid">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="row_spacing">6</property>
+                <property name="column_spacing">12</property>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="nice_value_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="yalign">0.80000001192092896</property>
+                    <property name="label" translatable="yes">_Nice value:</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">nice_value_scale</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScale" id="nice_value_scale">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="adjustment">renice_adj</property>
+                    <property name="round_digits">1</property>
+                    <property name="digits">0</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="priority_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="note_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">&lt;small&gt;&lt;i&gt;&lt;b&gt;Note:&lt;/b&gt; The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority.&lt;/i&gt;&lt;/small&gt;</property>
+                <property name="use_markup">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="100">change_priority_button</action-widget>
+    </action-widgets>
+  </object>
 </interface>
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index 2618acd..03ac2b3 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -152,16 +152,10 @@ void
 procdialog_create_renice_dialog (ProcData *procdata)
 {
     ProcInfo *info = procdata->selected_process;
-    GtkWidget *dialog = NULL;
-    GtkWidget *dialog_vbox;
-    GtkWidget *vbox;
     GtkWidget *label;
     GtkWidget *priority_label;
-    GtkWidget *table;
     GtkAdjustment *renice_adj;
-    GtkWidget *hscale;
-    GtkWidget *button;
-    GtkWidget *icon;
+    GtkBuilder *builder;
     gchar     *text;
     gchar     *dialog_title;
 
@@ -171,75 +165,50 @@ procdialog_create_renice_dialog (ProcData *procdata)
     if (!info)
         return;
 
-    dialog_title = g_strdup_printf (_("Change Priority of Process Â%s (PID: %u)"),
-                                    info->name, info->pid);
-    dialog = gtk_dialog_new_with_buttons (dialog_title, NULL,
-                                          GTK_DIALOG_DESTROY_WITH_PARENT,
-                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                          NULL);
-    g_free (dialog_title);
+    gchar* filename = g_build_filename (GSM_DATA_DIR, "preferences.ui", NULL);
 
-    renice_dialog = dialog;
-    gtk_window_set_resizable (GTK_WINDOW (renice_dialog), FALSE);
-    gtk_container_set_border_width (GTK_CONTAINER (renice_dialog), 5);
+    builder = gtk_builder_new();
+    gtk_builder_add_from_file (builder, filename, NULL);
 
-    button = gtk_button_new_with_mnemonic (_("Change _Priority"));
-    gtk_widget_set_can_default (button, TRUE);
+    renice_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "renice_dialog"));
 
-    icon = gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON);
-    gtk_button_set_image (GTK_BUTTON (button), icon);
+    dialog_title = g_strdup_printf (_("Change Priority of Process Â%s (PID: %u)"),
+                                    info->name, info->pid);
+
+    gtk_window_set_title (GTK_WINDOW(renice_dialog), dialog_title);
+    
+    g_free (dialog_title);
 
-    gtk_dialog_add_action_widget (GTK_DIALOG (renice_dialog), button, 100);
     gtk_dialog_set_default_response (GTK_DIALOG (renice_dialog), 100);
     new_nice_value = -100;
 
-    dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-    gtk_box_set_spacing (GTK_BOX (dialog_vbox), 2);
-    gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
-
-    vbox = gtk_vbox_new (FALSE, 12);
-    gtk_box_pack_start (GTK_BOX (dialog_vbox), vbox, TRUE, TRUE, 0);
-    gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-
-    table = gtk_table_new (2, 2, FALSE);
-    gtk_table_set_col_spacings (GTK_TABLE(table), 12);
-    gtk_table_set_row_spacings (GTK_TABLE(table), 6);
-    gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
+    renice_adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "renice_adj"));
+    gtk_adjustment_configure( GTK_ADJUSTMENT(renice_adj), info->nice, RENICE_VAL_MIN, RENICE_VAL_MAX, 1, 1, 0);
 
-    label = gtk_label_new_with_mnemonic (_("_Nice value:"));
-    gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 2,
-                      GTK_FILL, GTK_FILL, 0, 0);
-
-    renice_adj = gtk_adjustment_new (info->nice, RENICE_VAL_MIN, RENICE_VAL_MAX, 1, 1, 0);
     new_nice_value = 0;
-    hscale = gtk_hscale_new (renice_adj);
-    gtk_label_set_mnemonic_widget (GTK_LABEL (label), hscale);
-    gtk_scale_set_digits (GTK_SCALE (hscale), 0);
-    gtk_table_attach (GTK_TABLE (table), hscale, 1, 2, 0, 1,
-                      static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
-    text = g_strdup_printf(_("(%s Priority)"), procman::get_nice_level (info->nice));
-    priority_label = gtk_label_new (text);
-    gtk_table_attach (GTK_TABLE (table), priority_label, 1, 2, 1, 2,
-                      GTK_FILL, GTK_FILL, 0, 0);
-    g_free(text);
+    
+    priority_label =  GTK_WIDGET (gtk_builder_get_object (builder, "priority_label"));
+    gtk_label_set_label (GTK_LABEL(priority_label), procman::get_nice_level (info->nice));
 
     text = g_strconcat("<small><i><b>", _("Note:"), "</b> ",
                        _("The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority."),
                        "</i></small>", NULL);
-    label = gtk_label_new (_(text));
+    label = GTK_WIDGET (gtk_builder_get_object (builder, "note_label"));
+    gtk_label_set_label (GTK_LABEL(label), _(text));
     gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-    gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
     g_free (text);
 
-    g_signal_connect (G_OBJECT (dialog), "response",
+    g_signal_connect (G_OBJECT (renice_dialog), "response",
                       G_CALLBACK (renice_dialog_button_pressed), procdata);
     g_signal_connect (G_OBJECT (renice_adj), "value_changed",
                       G_CALLBACK (renice_scale_changed), priority_label);
 
-    gtk_widget_show_all (dialog);
+    gtk_widget_show_all (renice_dialog);
 
+    gtk_builder_connect_signals (builder, NULL);
 
+    g_object_unref (G_OBJECT (builder));
+    //g_free (filename);
 }
 
 static void
@@ -591,6 +560,7 @@ procdialog_create_preferences_dialog (ProcData *procdata)
     }
     gtk_builder_connect_signals (builder, NULL);
     g_object_unref (G_OBJECT (builder));
+    g_free (filename);
 }
 
 



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