[gnome-calendar] source-dialog: use a builder .ui definition for interface
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] source-dialog: use a builder .ui definition for interface
- Date: Mon, 25 May 2015 17:04:26 +0000 (UTC)
commit ef9d1301d92410e01d741183549d244d30261084
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon May 18 17:21:32 2015 -0300
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(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index e8370d4..577c312 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 d209d35..7a150e2 100644
--- a/data/calendar.gresource.xml
+++ b/data/calendar.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/calendar">
+ <file alias="calendar-row.ui" compressed="true" preprocess="xml-stripblanks">ui/calendar-row.ui</file>
<file alias="date-selector.ui" compressed="true" preprocess="xml-stripblanks">ui/date-selector.ui</file>
<file alias="edit-dialog.ui" compressed="true" preprocess="xml-stripblanks">ui/edit-dialog.ui</file>
<file alias="menus.ui" compressed="true" preprocess="xml-stripblanks">ui/menus.ui</file>
diff --git a/data/ui/calendar-row.ui b/data/ui/calendar-row.ui
new file mode 100644
index 0000000..457ac3a
--- /dev/null
+++ b/data/ui/calendar-row.ui
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+ <requires lib="gtk+" version="3.16"/>
+ <object class="GtkListBoxRow" id="row">
+ <property name="width_request">100</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="column_spacing">12</property>
+ <child>
+ <object class="GtkImage" id="icon">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="pixel_size">24</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="height">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="subtitle">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="title">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index 610eb99..5df977e 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]