[PATCH virt-viewer 02/10] iso-dialog: Use GtkHeaderBar

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

 



We now display the current ISO as subtitle on the HeaderBar. On the
glade UI file, we get rid of the GtkAlignment object that was used to
put some space between the tree view and dialog buttons. The "Select
ISO" label is gone too.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@xxxxxxxxxx>
---
 src/remote-viewer-iso-list-dialog.c        | 32 +++++++++--
 src/resources/ui/remote-viewer-iso-list.ui | 87 +++++++++++-------------------
 2 files changed, 59 insertions(+), 60 deletions(-)

diff --git a/src/remote-viewer-iso-list-dialog.c b/src/remote-viewer-iso-list-dialog.c
index ed51ffa..2110d70 100644
--- a/src/remote-viewer-iso-list-dialog.c
+++ b/src/remote-viewer-iso-list-dialog.c
@@ -36,6 +36,7 @@ G_DEFINE_TYPE(RemoteViewerISOListDialog, remote_viewer_iso_list_dialog, GTK_TYPE
 
 struct _RemoteViewerISOListDialogPrivate
 {
+    GtkHeaderBar *header_bar;
     GtkListStore *list_store;
     GtkWidget *status;
     GtkWidget *spinner;
@@ -121,6 +122,19 @@ remote_viewer_iso_list_dialog_show_files(RemoteViewerISOListDialog *self)
 }
 
 static void
+remote_viewer_iso_list_dialog_set_subtitle(RemoteViewerISOListDialog *self, const char *iso_name)
+{
+    RemoteViewerISOListDialogPrivate *priv = self->priv;
+    gchar *subtitle = NULL;
+
+    if (iso_name && strlen(iso_name) != 0)
+        subtitle = g_strdup_printf(_("Current: %s"), iso_name);
+
+    gtk_header_bar_set_subtitle(priv->header_bar, subtitle);
+    g_free(subtitle);
+}
+
+static void
 remote_viewer_iso_list_dialog_foreach(char *name, RemoteViewerISOListDialog *self)
 {
     RemoteViewerISOListDialogPrivate *priv = self->priv;
@@ -140,6 +154,7 @@ remote_viewer_iso_list_dialog_foreach(char *name, RemoteViewerISOListDialog *sel
         gtk_tree_view_set_cursor(GTK_TREE_VIEW(priv->tree_view), path, NULL, FALSE);
         gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(priv->tree_view), path, NULL, TRUE, 0.5, 0.5);
         gtk_tree_path_free(path);
+        remote_viewer_iso_list_dialog_set_subtitle(self, current_iso);
     }
 
     g_free(current_iso);
@@ -210,6 +225,7 @@ remote_viewer_iso_list_dialog_response(GtkDialog *dialog,
 
     gtk_spinner_start(GTK_SPINNER(priv->spinner));
     gtk_label_set_markup(GTK_LABEL(priv->status), _("<b>Loading...</b>"));
+    remote_viewer_iso_list_dialog_set_subtitle(self, NULL);
     gtk_stack_set_visible_child_full(GTK_STACK(priv->stack), "status",
                                      GTK_STACK_TRANSITION_TYPE_NONE);
     gtk_dialog_set_response_sensitive(GTK_DIALOG(self), GTK_RESPONSE_NONE, FALSE);
@@ -265,9 +281,13 @@ remote_viewer_iso_list_dialog_init(RemoteViewerISOListDialog *self)
     RemoteViewerISOListDialogPrivate *priv = self->priv = DIALOG_PRIVATE(self);
     GtkBuilder *builder = virt_viewer_util_load_ui("remote-viewer-iso-list.ui");
     GtkCellRendererToggle *cell_renderer;
+    GtkWidget *button, *image;
 
     gtk_builder_connect_signals(builder, self);
 
+    priv->header_bar = GTK_HEADER_BAR(gtk_dialog_get_header_bar(GTK_DIALOG(self)));
+    gtk_header_bar_set_has_subtitle(priv->header_bar, TRUE);
+
     priv->status = GTK_WIDGET(gtk_builder_get_object(builder, "status"));
     priv->spinner = GTK_WIDGET(gtk_builder_get_object(builder, "spinner"));
     priv->stack = GTK_WIDGET(gtk_builder_get_object(builder, "stack"));
@@ -281,12 +301,12 @@ remote_viewer_iso_list_dialog_init(RemoteViewerISOListDialog *self)
 
     g_object_unref(builder);
 
-    gtk_dialog_add_buttons(GTK_DIALOG(self),
-                           _("Refresh"), GTK_RESPONSE_NONE,
-                           _("Close"), GTK_RESPONSE_CLOSE,
-                           NULL);
+    button = gtk_dialog_add_button(GTK_DIALOG(self), "", GTK_RESPONSE_NONE);
+    image = gtk_image_new_from_icon_name("view-refresh-symbolic", GTK_ICON_SIZE_BUTTON);
+    gtk_button_set_image(GTK_BUTTON(button), image);
+    gtk_button_set_always_show_image(GTK_BUTTON(button), TRUE);
+    gtk_widget_set_tooltip_text(button, _("Refresh"));
 
-    gtk_dialog_set_default_response(GTK_DIALOG(self), GTK_RESPONSE_CLOSE);
     gtk_dialog_set_response_sensitive(GTK_DIALOG(self), GTK_RESPONSE_NONE, FALSE);
     g_signal_connect(self, "response", G_CALLBACK(remote_viewer_iso_list_dialog_response), NULL);
 }
@@ -360,6 +380,7 @@ ovirt_foreign_menu_iso_name_changed(OvirtForeignMenu *foreign_menu,
         g_free(name);
     } while (gtk_tree_model_iter_next(model, &iter));
 
+    remote_viewer_iso_list_dialog_set_subtitle(self, current_iso);
     gtk_dialog_set_response_sensitive(GTK_DIALOG(self), GTK_RESPONSE_NONE, TRUE);
     gtk_widget_set_sensitive(priv->tree_view, TRUE);
     g_free(current_iso);
@@ -382,6 +403,7 @@ remote_viewer_iso_list_dialog_new(GtkWindow *parent, GObject *foreign_menu)
                           "border-width", 18,
                           "default-width", 400,
                           "default-height", 300,
+                          "use-header-bar", TRUE,
                           "foreign-menu", foreign_menu,
                           NULL);
 
diff --git a/src/resources/ui/remote-viewer-iso-list.ui b/src/resources/ui/remote-viewer-iso-list.ui
index ab1bdc4..b385527 100644
--- a/src/resources/ui/remote-viewer-iso-list.ui
+++ b/src/resources/ui/remote-viewer-iso-list.ui
@@ -72,70 +72,47 @@
         <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkLabel">
+          <object class="GtkScrolledWindow">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">Select ISO</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkAlignment" id="alignment">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="bottom_padding">6</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkScrolledWindow">
+              <object class="GtkTreeView" id="view">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="shadow_type">in</property>
+                <property name="model">liststore</property>
+                <property name="headers_visible">False</property>
+                <property name="rules_hint">True</property>
+                <property name="search_column">1</property>
+                <property name="enable_grid_lines">horizontal</property>
+                <signal name="row-activated" handler="remote_viewer_iso_list_dialog_row_activated" swapped="no"/>
+                <child internal-child="selection">
+                  <object class="GtkTreeSelection" id="treeview-selection"/>
+                </child>
                 <child>
-                  <object class="GtkTreeView" id="view">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="model">liststore</property>
-                    <property name="headers_visible">False</property>
-                    <property name="rules_hint">True</property>
-                    <property name="search_column">1</property>
-                    <property name="enable_grid_lines">horizontal</property>
-                    <signal name="row-activated" handler="remote_viewer_iso_list_dialog_row_activated" swapped="no"/>
-                    <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="treeview-selection"/>
-                    </child>
+                  <object class="GtkTreeViewColumn" id="selected_column">
+                    <property name="sizing">autosize</property>
+                    <property name="title" translatable="yes">Selected</property>
                     <child>
-                      <object class="GtkTreeViewColumn" id="selected_column">
-                        <property name="sizing">autosize</property>
-                        <property name="title" translatable="yes">Selected</property>
-                        <child>
-                          <object class="GtkCellRendererToggle" id="cellrenderertoggle">
-                            <signal name="toggled" handler="remote_viewer_iso_list_dialog_toggled" swapped="no"/>
-                          </object>
-                          <attributes>
-                            <attribute name="active">0</attribute>
-                          </attributes>
-                        </child>
+                      <object class="GtkCellRendererToggle" id="cellrenderertoggle">
+                        <signal name="toggled" handler="remote_viewer_iso_list_dialog_toggled" swapped="no"/>
                       </object>
+                      <attributes>
+                        <attribute name="active">0</attribute>
+                      </attributes>
                     </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkTreeViewColumn" id="name_column">
+                    <property name="title" translatable="yes">Name</property>
+                    <property name="expand">True</property>
                     <child>
-                      <object class="GtkTreeViewColumn" id="name_column">
-                        <property name="title" translatable="yes">Name</property>
-                        <property name="expand">True</property>
-                        <child>
-                          <object class="GtkCellRendererText" id="cellrenderertext"/>
-                          <attributes>
-                            <attribute name="text">1</attribute>
-                            <attribute name="weight">2</attribute>
-                          </attributes>
-                        </child>
-                      </object>
+                      <object class="GtkCellRendererText" id="cellrenderertext"/>
+                      <attributes>
+                        <attribute name="text">1</attribute>
+                        <attribute name="weight">2</attribute>
+                      </attributes>
                     </child>
                   </object>
                 </child>
-- 
2.9.3

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux