[nautilus] nautilus-progress-info-widget: Use GtkBuilder for the UI



commit 2b09a6f2e396f6505ef5a3988994694dc9d25cf0
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Feb 5 15:25:51 2015 +0100

    nautilus-progress-info-widget: Use GtkBuilder for the UI
    
    As always, it's better to use GtkBuilder definition files for the UI.
    Also improve the looks using a round button and symbolic icons.

 src/Adwaita.css                       |    5 ++
 src/nautilus-progress-info-widget.c   |  105 ++++++++++-----------------------
 src/nautilus-progress-info-widget.h   |    4 +-
 src/nautilus-progress-info-widget.xml |   87 +++++++++++++++++++++++++++
 src/nautilus.gresource.xml            |    1 +
 5 files changed, 126 insertions(+), 76 deletions(-)
---
diff --git a/src/Adwaita.css b/src/Adwaita.css
index ba77196..e8020c7 100644
--- a/src/Adwaita.css
+++ b/src/Adwaita.css
@@ -33,6 +33,11 @@
     color: @theme_unfocused_selected_fg_color;
 }
 
+.nautilus-circular-button {
+  border-radius: 20px;
+  outline-radius: 20px;
+}
+
 /* Floating status bar */
 .floating-bar {
   padding: 2px;
diff --git a/src/nautilus-progress-info-widget.c b/src/nautilus-progress-info-widget.c
index 491ac8b..86b34fd 100644
--- a/src/nautilus-progress-info-widget.c
+++ b/src/nautilus-progress-info-widget.c
@@ -25,13 +25,13 @@
 #include <config.h>
 
 #include "nautilus-progress-info-widget.h"
-
-struct _NautilusProgressInfoWidgetPriv {
+struct _NautilusProgressInfoWidgetPrivate {
        NautilusProgressInfo *info;
 
        GtkWidget *status; /* GtkLabel */
        GtkWidget *details; /* GtkLabel */
        GtkWidget *progress_bar;
+       GtkWidget *cancel;
 };
 
 enum {
@@ -41,8 +41,8 @@ enum {
 
 static GParamSpec *properties[NUM_PROPERTIES] = { NULL };
 
-G_DEFINE_TYPE (NautilusProgressInfoWidget, nautilus_progress_info_widget,
-               GTK_TYPE_BOX);
+G_DEFINE_TYPE_WITH_PRIVATE (NautilusProgressInfoWidget, nautilus_progress_info_widget,
+                            GTK_TYPE_BOX);
 
 static void
 info_finished (NautilusProgressInfoWidget *self)
@@ -89,68 +89,21 @@ cancel_clicked (GtkWidget *button,
 }
 
 static void
-nautilus_progress_info_widget_constructed (GObject *obj)
+nautilus_progress_info_widget_dispose (GObject *obj)
 {
-       GtkWidget *label, *progress_bar, *hbox, *box, *button, *image;
        NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
 
-       G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->constructed (obj);
-
-       label = gtk_label_new ("status");
-       gtk_widget_set_size_request (label, 500, -1);
-       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-       gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR);
-       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-       gtk_box_pack_start (GTK_BOX (self),
-                           label,
-                           TRUE, FALSE,
-                           0);
-       self->priv->status = label;
-
-       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
-
-       progress_bar = gtk_progress_bar_new ();
-       self->priv->progress_bar = progress_bar;
-       gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (progress_bar), 0.05);
-       box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-       gtk_box_pack_start(GTK_BOX (box),
-                          progress_bar,
-                          TRUE, FALSE,
-                          0);
-       gtk_box_pack_start(GTK_BOX (hbox),
-                          box,
-                          TRUE, TRUE,
-                          0);
-
-       image = gtk_image_new_from_icon_name ("gtk-cancel",
-                                             GTK_ICON_SIZE_BUTTON);
-       button = gtk_button_new ();
-       gtk_container_add (GTK_CONTAINER (button), image);
-       gtk_box_pack_start (GTK_BOX (hbox),
-                           button,
-                           FALSE,FALSE,
-                           0);
-       g_signal_connect (button, "clicked",
-                         G_CALLBACK (cancel_clicked), self);
+       g_clear_object (&self->priv->info);
 
-       gtk_box_pack_start (GTK_BOX (self),
-                           hbox,
-                           FALSE,FALSE,
-                           0);
-
-       label = gtk_label_new ("details");
-       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-       gtk_box_pack_start (GTK_BOX (self),
-                           label,
-                           TRUE, FALSE,
-                           0);
-       self->priv->details = label;
-       
-       gtk_widget_show_all (GTK_WIDGET (self));
+       G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->dispose (obj);
+}
 
-       update_data (self);
-       update_progress (self);
+static void
+nautilus_progress_info_widget_constructed (GObject *obj)
+{
+       NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
+
+       G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->constructed (obj);
 
        g_signal_connect_swapped (self->priv->info,
                                  "changed",
@@ -161,16 +114,9 @@ nautilus_progress_info_widget_constructed (GObject *obj)
        g_signal_connect_swapped (self->priv->info,
                                  "finished",
                                  G_CALLBACK (info_finished), self);
-}
 
-static void
-nautilus_progress_info_widget_dispose (GObject *obj)
-{
-       NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
-
-       g_clear_object (&self->priv->info);
-
-       G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->dispose (obj);
+       update_data (self);
+       update_progress (self);
 }
 
 static void
@@ -194,17 +140,22 @@ nautilus_progress_info_widget_set_property (GObject *object,
 static void
 nautilus_progress_info_widget_init (NautilusProgressInfoWidget *self)
 {
-       self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_INFO_WIDGET,
-                                                 NautilusProgressInfoWidgetPriv);
+       self->priv = nautilus_progress_info_widget_get_instance_private (self);
+
+       gtk_widget_init_template (GTK_WIDGET (self));
+
+       g_signal_connect (self->priv->cancel, "clicked",
+                         G_CALLBACK (cancel_clicked), self);
 
-       
 }
 
 static void
 nautilus_progress_info_widget_class_init (NautilusProgressInfoWidgetClass *klass)
 {
        GObjectClass *oclass;
+       GtkWidgetClass *widget_class;
 
+       widget_class = GTK_WIDGET_CLASS (klass);
        oclass = G_OBJECT_CLASS (klass);
        oclass->set_property = nautilus_progress_info_widget_set_property;
        oclass->constructed = nautilus_progress_info_widget_constructed;
@@ -220,7 +171,13 @@ nautilus_progress_info_widget_class_init (NautilusProgressInfoWidgetClass *klass
 
        g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
 
-       g_type_class_add_private (klass, sizeof (NautilusProgressInfoWidgetPriv));
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/nautilus/nautilus-progress-info-widget.xml");
+
+       gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, status);
+       gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, details);
+       gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, progress_bar);
+       gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, cancel);
 }
 
 GtkWidget *
diff --git a/src/nautilus-progress-info-widget.h b/src/nautilus-progress-info-widget.h
index 38915d1..5bb40c9 100644
--- a/src/nautilus-progress-info-widget.h
+++ b/src/nautilus-progress-info-widget.h
@@ -41,13 +41,13 @@
 #define NAUTILUS_PROGRESS_INFO_WIDGET_GET_CLASS(obj) \
        (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_PROGRESS_INFO_WIDGET, 
NautilusProgressInfoWidgetClass))
 
-typedef struct _NautilusProgressInfoWidgetPriv NautilusProgressInfoWidgetPriv;
+typedef struct _NautilusProgressInfoWidgetPrivate NautilusProgressInfoWidgetPrivate;
 
 typedef struct {
        GtkBox parent;
 
        /* private */
-       NautilusProgressInfoWidgetPriv *priv;
+       NautilusProgressInfoWidgetPrivate *priv;
 } NautilusProgressInfoWidget;
 
 typedef struct {
diff --git a/src/nautilus-progress-info-widget.xml b/src/nautilus-progress-info-widget.xml
new file mode 100644
index 0000000..fa645ef
--- /dev/null
+++ b/src/nautilus-progress-info-widget.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="NautilusProgressInfoWidget" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="margin">5</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkLabel" id="status">
+        <property name="label">status</property>
+        <property name="visible">True</property>
+        <property name="xalign">0</property>
+        <property name="width-request">400</property>
+        <property name="wrap">True</property>
+        <property name="wrap-mode">word-char</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="box2">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkProgressBar" id="progress_bar">
+            <property name="visible">True</property>
+            <property name="valign">center</property>
+            <property name="pulse-step">0.05</property>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="cancel">
+            <property name="visible">True</property>
+            <property name="receives_default">True</property>
+            <property name="margin_start">20</property>
+            <style>
+              <class name="image-button"/>
+              <class name="nautilus-circular-button"/>
+            </style>
+            <child>
+              <object class="GtkImage" id="cancel_icon">
+                <property name="visible">True</property>
+                <property name="icon-name">window-close-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </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="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="details">
+        <property name="label">details</property>
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">label</property>
+        <property name="ellipsize">end</property>
+        <property name="xalign">0</property>
+        <property name="wrap">True</property>
+        <property name="wrap-mode">word-char</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml
index ff0a1ca..1bdb66c 100644
--- a/src/nautilus.gresource.xml
+++ b/src/nautilus.gresource.xml
@@ -8,6 +8,7 @@
     <file>nautilus-toolbar-view-menu.xml</file>
     <file>nautilus-toolbar-action-menu.xml</file>
     <file>nautilus-view-context-menus.xml</file>
+    <file>nautilus-progress-info-widget.xml</file>
     <file alias="icons/thumbnail_frame.png">../icons/thumbnail_frame.png</file>
     <file alias="icons/filmholes.png">../icons/filmholes.png</file>
     <file alias="icons/knob.png">../icons/knob.png</file>


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