[nautilus/wip/csoriano/progress_dialog: 13/16] nautilus-progress-info-widget: Use GtkBuilder for the UI
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/progress_dialog: 13/16] nautilus-progress-info-widget: Use GtkBuilder for the UI
- Date: Wed, 11 Feb 2015 11:42:53 +0000 (UTC)
commit 60c01770241481b35ebf9ae9fd01e514686b7c27
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 ui files for the UI.
Also it will make easier to tweak the UI in future.
src/nautilus-progress-info-widget.c | 104 ++++++++++-----------------------
src/nautilus-progress-info-widget.h | 4 +-
src/nautilus-progress-info-widget.xml | 92 +++++++++++++++++++++++++++++
src/nautilus.gresource.xml | 1 +
4 files changed, 126 insertions(+), 75 deletions(-)
---
diff --git a/src/nautilus-progress-info-widget.c b/src/nautilus-progress-info-widget.c
index 491ac8b..7a96842 100644
--- a/src/nautilus-progress-info-widget.c
+++ b/src/nautilus-progress-info-widget.c
@@ -26,12 +26,13 @@
#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 +42,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 +90,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 +115,12 @@ 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_signal_connect (self->priv->cancel, "clicked",
+ G_CALLBACK (cancel_clicked), self);
- G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->dispose (obj);
+ update_data (self);
+ update_progress (self);
}
static void
@@ -181,6 +131,7 @@ nautilus_progress_info_widget_set_property (GObject *object,
{
NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (object);
+ g_print ("set property \n");
switch (property_id) {
case PROP_INFO:
self->priv->info = g_value_dup_object (value);
@@ -194,21 +145,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));
}
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;
oclass->dispose = nautilus_progress_info_widget_dispose;
+ oclass->constructed = nautilus_progress_info_widget_constructed;
properties[PROP_INFO] =
g_param_spec_object ("info",
@@ -220,7 +172,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..c2ae770
--- /dev/null
+++ b/src/nautilus-progress-info-widget.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="NautilusProgressInfoWidget" parent="GtkBox">
+ <property name="visible">True</property>
+ <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>
+ <child>
+ <object class="GtkLabel" id="status">
+ <property name="label">status</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="width-request">500</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>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkProgressBar" id="progress_bar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</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="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="margin_start">10</property>
+ <style>
+ <class name="image-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="can_focus">False</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>
+ </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]