From ef9d1301d92410e01d741183549d244d30261084 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Mon, 18 May 2015 17:21:32 -0300 Subject: [PATCH] source-dialog: use a builder .ui definition for interface We know that coding interfaces sucks, so use a .ui file instead. --- data/Makefile.am | 1 + data/calendar.gresource.xml | 1 + data/ui/calendar-row.ui | 56 +++++++++++++++++++++++++++++++++++++ src/gcal-source-dialog.c | 34 +++++++++++----------- 4 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 data/ui/calendar-row.ui diff --git a/data/Makefile.am b/data/Makefile.am index e8370d4a..577c312a 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -49,6 +49,7 @@ EXTRA_DIST= \ org.gnome.Calendar.desktop \ calendar.gresource.xml \ shell-search-provider-dbus-interfaces.xml \ + ui/calendar-row.ui \ ui/date-selector.ui \ ui/edit-dialog.ui \ ui/menus.ui \ diff --git a/data/calendar.gresource.xml b/data/calendar.gresource.xml index d209d359..7a150e21 100644 --- a/data/calendar.gresource.xml +++ b/data/calendar.gresource.xml @@ -1,6 +1,7 @@ + ui/calendar-row.ui ui/date-selector.ui ui/edit-dialog.ui ui/menus.ui diff --git a/data/ui/calendar-row.ui b/data/ui/calendar-row.ui new file mode 100644 index 00000000..457ac3a3 --- /dev/null +++ b/data/ui/calendar-row.ui @@ -0,0 +1,56 @@ + + + + + + 100 + True + True + + + True + False + 6 + 12 + + + True + False + 24 + + + 0 + 0 + 2 + + + + + True + False + True + 0 + + + + 1 + 1 + + + + + True + False + 0 + + + 1 + 0 + + + + + + diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c index 610eb99d..5df977e3 100644 --- a/src/gcal-source-dialog.c +++ b/src/gcal-source-dialog.c @@ -597,6 +597,7 @@ make_row_from_source (GcalSourceDialog *dialog, ESource *source) { GcalSourceDialogPrivate *priv; + GtkBuilder *builder; GtkWidget *bottom_label; GtkWidget *top_label; GdkPixbuf *pixbuf; @@ -608,37 +609,36 @@ make_row_from_source (GcalSourceDialog *dialog, priv = dialog->priv; get_source_parent_name_color (priv->manager, source, &parent_name, NULL); - row = gtk_list_box_row_new (); + builder = gtk_builder_new_from_resource ("/org/gnome/calendar/calendar-row.ui"); + + /* + * Since we're destroying the builder instance before adding + * the row to the listbox, it should be referenced here so + * it isn't destroyed with the GtkBuilder. + */ + row = g_object_ref (gtk_builder_get_object (builder, "row")); /* main box */ - grid = g_object_new (GTK_TYPE_GRID, "border-width", 6, "column-spacing", 12, NULL); + grid = GTK_WIDGET (gtk_builder_get_object (builder, "grid")); /* source color icon */ gdk_rgba_parse (&color, get_color_name_from_source (source)); pixbuf = get_circle_pixbuf_from_color (&color, 24); - icon = gtk_image_new_from_pixbuf (pixbuf); + icon = GTK_WIDGET (gtk_builder_get_object (builder, "icon")); + gtk_image_set_from_pixbuf (GTK_IMAGE (icon), pixbuf); /* source name label */ - top_label = g_object_new (GTK_TYPE_LABEL, - "label", e_source_get_display_name (source), - "xalign", 0.0, - "hexpand", TRUE, - NULL); + top_label = GTK_WIDGET (gtk_builder_get_object (builder, "title")); + gtk_label_set_label (GTK_LABEL (top_label), e_source_get_display_name (source)); g_object_bind_property (source, "display-name", top_label, "label", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); g_signal_connect (source, "notify::display-name", G_CALLBACK (invalidate_calendar_listbox_sort), priv->calendars_listbox); /* parent source name label */ - bottom_label = g_object_new (GTK_TYPE_LABEL, "label", parent_name, "xalign", 0.0, "hexpand", TRUE, NULL); - gtk_style_context_add_class (gtk_widget_get_style_context (bottom_label), "dim-label"); - - gtk_grid_attach (GTK_GRID (grid), icon, 0, 0, 1, 2); - gtk_grid_attach (GTK_GRID (grid), top_label, 1, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), bottom_label, 1, 1, 1, 1); - gtk_container_add (GTK_CONTAINER (row), grid); - - gtk_widget_show_all (row); + bottom_label = GTK_WIDGET (gtk_builder_get_object (builder, "subtitle")); + gtk_label_set_label (GTK_LABEL (bottom_label), parent_name); + g_object_unref (builder); g_object_unref (pixbuf); g_free (parent_name);