[virt-tools-list] [PATCH virt-viewer 06/10] virt-viewer-preferences: Use GtkHeaderBar

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


This dialog changed very little when compared to the old version. I did
change the way widgets are organized within the dialog, as it now groups
the file selector together with the read-only checkbox.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
---
 src/resources/ui/virt-viewer-preferences.ui | 103 ++++++++++++++++------------
 src/virt-viewer-app.c                       |  38 ++++++----
 2 files changed, 82 insertions(+), 59 deletions(-)

diff --git a/src/resources/ui/virt-viewer-preferences.ui b/src/resources/ui/virt-viewer-preferences.ui
index f9738c5..c110335 100644
--- a/src/resources/ui/virt-viewer-preferences.ui
+++ b/src/resources/ui/virt-viewer-preferences.ui
@@ -1,28 +1,33 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
 <interface>
-  <!-- interface-requires gtk+ 2.6 -->
-  <!-- interface-naming-policy toplevel-contextual -->
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkHeaderBar" id="headerbar">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="title">Preferences</property>
+    <property name="show_close_button">True</property>
+    <property name="decoration_layout">:close</property>
+    <child>
+      <placeholder/>
+    </child>
+  </object>
   <object class="GtkDialog" id="preferences">
     <property name="can_focus">False</property>
-    <property name="border_width">5</property>
+    <property name="border_width">6</property>
     <property name="title" translatable="yes">Preferences</property>
     <property name="type_hint">normal</property>
     <signal name="delete-event" handler="gtk_widget_hide_on_delete" swapped="no"/>
     <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox1">
+      <object class="GtkBox" id="dialog-vbox1">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
         <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
+          <object class="GtkButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
-            <child>
-              <placeholder/>
-            </child>
-            <child>
-              <placeholder/>
-            </child>
           </object>
           <packing>
             <property name="expand">True</property>
@@ -31,88 +36,96 @@
           </packing>
         </child>
         <child>
-          <object class="GtkNotebook" id="notebook1">
+          <object class="GtkNotebook">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="border_width">0</property>
             <child>
-              <object class="GtkVBox" id="vbox1">
+              <object class="GtkBox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">18</property>
+                <property name="border_width">12</property>
+                <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkLabel" id="label2">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes">Folder sharing</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
+                    <property name="halign">start</property>
+                    <property name="label" translatable="yes"><b>Folder sharing</b></property>
+                    <property name="use_markup">True</property>
+                    <property name="wrap">True</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
-                    <property name="fill">False</property>
+                    <property name="fill">True</property>
                     <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkTable" id="table1">
+                  <object class="GtkGrid">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="border_width">6</property>
-                    <property name="n_rows">2</property>
-                    <property name="n_columns">2</property>
-                    <property name="column_spacing">12</property>
                     <property name="row_spacing">6</property>
-                    <child>
-                      <object class="GtkCheckButton" id="cbsharefolder">
-                        <property name="label" translatable="yes">Share folder</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="draw_indicator">True</property>
-                      </object>
-                      <packing>
-                        <property name="x_options"/>
-                      </packing>
-                    </child>
+                    <property name="column_spacing">6</property>
                     <child>
                       <object class="GtkCheckButton" id="cbsharefolderro">
                         <property name="label" translatable="yes">Read-only</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
+                        <property name="halign">start</property>
                         <property name="draw_indicator">True</property>
                       </object>
                       <packing>
-                        <property name="right_attach">2</property>
+                        <property name="left_attach">1</property>
                         <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
                       </packing>
                     </child>
                     <child>
                       <object class="GtkFileChooserButton" id="fcsharefolder">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="margin_left">4</property>
+                        <property name="hexpand">True</property>
                         <property name="action">select-folder</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
-                        <property name="right_attach">2</property>
+                        <property name="top_attach">0</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkCheckButton" id="cbsharefolder">
+                        <property name="label" translatable="yes">Share Folder:</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="halign">start</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">1</property>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
                   </packing>
                 </child>
               </object>
+              <packing>
+                <property name="tab_expand">True</property>
+              </packing>
             </child>
             <child type="tab">
-              <object class="GtkLabel" id="label1">
+              <object class="GtkLabel">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Spice</property>
@@ -125,7 +138,7 @@
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 2e7e193..0d2d33b 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -2475,43 +2475,53 @@ static GtkWidget *
 virt_viewer_app_get_preferences(VirtViewerApp *self)
 {
     VirtViewerSession *session = virt_viewer_app_get_session(self);
-    GtkBuilder *builder = virt_viewer_util_load_ui("virt-viewer-preferences.ui");
     gboolean can_share_folder = virt_viewer_session_can_share_folder(session);
-    GtkWidget *preferences = self->priv->preferences;
+    GtkWidget *headerbar, *check, *chooser, *readonly, *preferences = self->priv->preferences;
+    GtkBuilder *builder;
     gchar *path;
 
     if (preferences)
         goto end;
 
+    builder = virt_viewer_util_load_ui("virt-viewer-preferences.ui");
     gtk_builder_connect_signals(builder, self);
 
     preferences = GTK_WIDGET(gtk_builder_get_object(builder, "preferences"));
-    self->priv->preferences = preferences;
+    headerbar = GTK_WIDGET(gtk_builder_get_object(builder, "headerbar"));
+    gtk_window_set_titlebar(GTK_WINDOW(preferences), headerbar);
+
+    check = GTK_WIDGET(gtk_builder_get_object(builder, "cbsharefolder"));
+    chooser = GTK_WIDGET(gtk_builder_get_object(builder, "fcsharefolder"));
+    readonly = GTK_WIDGET(gtk_builder_get_object(builder, "cbsharefolderro"));
+
+    gtk_widget_set_sensitive(check, can_share_folder);
+
+    g_object_bind_property(G_OBJECT(check), "active",
+                           G_OBJECT(chooser), "sensitive",
+                           G_BINDING_SYNC_CREATE);
 
-    g_object_set (gtk_builder_get_object(builder, "cbsharefolder"),
-                  "sensitive", can_share_folder, NULL);
-    g_object_set (gtk_builder_get_object(builder, "cbsharefolderro"),
-                  "sensitive", can_share_folder, NULL);
-    g_object_set (gtk_builder_get_object(builder, "fcsharefolder"),
-                  "sensitive", can_share_folder, NULL);
+    g_object_bind_property(G_OBJECT(check), "active",
+                           G_OBJECT(readonly), "sensitive",
+                           G_BINDING_SYNC_CREATE);
+
+    self->priv->preferences = preferences;
 
     if (!can_share_folder)
         goto end;
 
     g_object_bind_property(virt_viewer_app_get_session(self),
                            "share-folder",
-                           gtk_builder_get_object(builder, "cbsharefolder"),
+                           G_OBJECT(check),
                            "active",
                            G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
 
     g_object_bind_property(virt_viewer_app_get_session(self),
                            "share-folder-ro",
-                           gtk_builder_get_object(builder, "cbsharefolderro"),
+                           G_OBJECT(readonly),
                            "active",
                            G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
 
-    self->priv->preferences_shared_folder =
-        GTK_FILE_CHOOSER(gtk_builder_get_object(builder, "fcsharefolder"));
+    self->priv->preferences_shared_folder = GTK_FILE_CHOOSER(chooser);
 
     g_object_get(virt_viewer_app_get_session(self),
                  "shared-folder", &path, NULL);
@@ -2524,8 +2534,8 @@ virt_viewer_app_get_preferences(VirtViewerApp *self)
                                       G_CALLBACK(share_folder_changed), self,
                                       G_CONNECT_SWAPPED);
 
-end:
     g_object_unref(builder);
+end:
 
     return preferences;
 }
-- 
2.9.3




More information about the virt-tools-list mailing list