[virt-tools-list] [PATCH virt-viewer 03/10] guest-details-dialog: Use GtkHeaderBar

Eduardo Lima (Etrunko) etrunko at redhat.com
Thu Feb 9 19:22:44 UTC 2017


This is the simplest dialog on the application, there was not much to
change here. In order to not leave a big amount of unused space on the
HeaderBar, we set the guest name as the subtitle.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
---
 src/resources/ui/virt-viewer-guest-details.ui | 64 +++++++++++----------------
 src/virt-viewer-window.c                      | 12 ++---
 2 files changed, 34 insertions(+), 42 deletions(-)

diff --git a/src/resources/ui/virt-viewer-guest-details.ui b/src/resources/ui/virt-viewer-guest-details.ui
index 209272f..7522049 100644
--- a/src/resources/ui/virt-viewer-guest-details.ui
+++ b/src/resources/ui/virt-viewer-guest-details.ui
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.0 on Thu Jan 16 16:13:38 2014 -->
+<!-- Generated with glade 3.20.0 -->
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <requires lib="gtk+" version="3.12"/>
   <object class="GtkDialog" id="guestdetailsdialog">
     <property name="can_focus">False</property>
+    <property name="border_width">12</property>
     <property name="title" translatable="yes">Guest Details</property>
-    <property name="resizable">True</property>
     <property name="default_width">400</property>
     <property name="type_hint">dialog</property>
     <signal name="response" handler="virt_viewer_window_guest_details_response" swapped="no"/>
@@ -13,24 +13,13 @@
       <object class="GtkBox" id="dialog-vbox2">
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
+        <property name="spacing">6</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox" id="dialog-action_area2">
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" id="button1">
-                <property name="label" translatable="yes">_Close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
+              <placeholder/>
             </child>
           </object>
           <packing>
@@ -41,80 +30,81 @@
           </packing>
         </child>
         <child>
-          <object class="GtkTable" id="grid1">
+          <object class="GtkGrid">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="border_width">6</property>
             <property name="row_spacing">6</property>
             <property name="column_spacing">6</property>
-            <property name="n_rows">2</property>
             <child>
               <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="label" translatable="yes"><b>Name:</b></property>
+                <property name="use_markup">True</property>
                 <property name="xalign">1</property>
-                <property name="label" translatable="yes">Name:</property>
               </object>
               <packing>
-                <property name="x_options">GTK_SHRINK | GTK_FILL</property>
-                <property name="y_options">GTK_FILL</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
               </packing>
             </child>
             <child>
               <object class="GtkLabel" id="label2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="label" translatable="yes"><b>GUID:</b></property>
+                <property name="use_markup">True</property>
                 <property name="xalign">1</property>
-                <property name="label" translatable="yes">GUID:</property>
               </object>
               <packing>
+                <property name="left_attach">0</property>
                 <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_SHRINK | GTK_FILL</property>
-                <property name="y_options">GTK_FILL</property>
               </packing>
             </child>
             <child>
               <object class="GtkLabel" id="namevaluelabel">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
                 <property name="label" translatable="yes">label</property>
                 <property name="selectable">True</property>
+                <property name="xalign">0</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="y_options">GTK_FILL</property>
+                <property name="top_attach">0</property>
               </packing>
             </child>
             <child>
               <object class="GtkLabel" id="guidvaluelabel">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
                 <property name="label" translatable="yes">label</property>
                 <property name="selectable">True</property>
+                <property name="xalign">0</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
                 <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="y_options">GTK_FILL</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
             <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
     </child>
-    <action-widgets>
-      <action-widget response="-7">button1</action-widget>
-    </action-widgets>
+  </object>
+  <object class="GtkHeaderBar" id="headerbar">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="title">Guest Details</property>
+    <property name="show_close_button">True</property>
+    <property name="decoration_layout">:close</property>
+    <child>
+      <placeholder/>
+    </child>
   </object>
 </interface>
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 8eda12e..c75e75b 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -986,16 +986,17 @@ virt_viewer_window_menu_help_guest_details(GtkWidget *menu G_GNUC_UNUSED,
                                            VirtViewerWindow *self)
 {
     GtkBuilder *ui = virt_viewer_util_load_ui("virt-viewer-guest-details.ui");
+    GtkWidget *dialog, *headerbar, *namelabel, *guidlabel;
     char *name = NULL;
     char *uuid = NULL;
 
     g_return_if_fail(ui != NULL);
 
-    GtkWidget *dialog = GTK_WIDGET(gtk_builder_get_object(ui, "guestdetailsdialog"));
-    GtkWidget *namelabel = GTK_WIDGET(gtk_builder_get_object(ui, "namevaluelabel"));
-    GtkWidget *guidlabel = GTK_WIDGET(gtk_builder_get_object(ui, "guidvaluelabel"));
-
-    g_return_if_fail(dialog && namelabel && guidlabel);
+    dialog = GTK_WIDGET(gtk_builder_get_object(ui, "guestdetailsdialog"));
+    headerbar = GTK_WIDGET(gtk_builder_get_object(ui, "headerbar"));
+    gtk_window_set_titlebar(GTK_WINDOW(dialog), headerbar);
+    namelabel = GTK_WIDGET(gtk_builder_get_object(ui, "namevaluelabel"));
+    guidlabel = GTK_WIDGET(gtk_builder_get_object(ui, "guidvaluelabel"));
 
     g_object_get(self->priv->app, "guest-name", &name, "uuid", &uuid, NULL);
 
@@ -1003,6 +1004,7 @@ virt_viewer_window_menu_help_guest_details(GtkWidget *menu G_GNUC_UNUSED,
         name = g_strdup(_("Unknown"));
     if (!uuid || *uuid == '\0')
         uuid = g_strdup(_("Unknown"));
+    gtk_header_bar_set_subtitle(GTK_HEADER_BAR(headerbar), name);
     gtk_label_set_text(GTK_LABEL(namelabel), name);
     gtk_label_set_text(GTK_LABEL(guidlabel), uuid);
     g_free(name);
-- 
2.9.3




More information about the virt-tools-list mailing list