aboutsummaryrefslogtreecommitdiffstats
path: root/libevolution-utils/evolution-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'libevolution-utils/evolution-util.c')
-rw-r--r--libevolution-utils/evolution-util.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/libevolution-utils/evolution-util.c b/libevolution-utils/evolution-util.c
index 23d3b51efa..e6c6e84290 100644
--- a/libevolution-utils/evolution-util.c
+++ b/libevolution-utils/evolution-util.c
@@ -258,3 +258,69 @@ e_ascii_dtostr (gchar *buffer,
return buffer;
}
+/**
+ * e_builder_get_widget:
+ * @builder: a #GtkBuilder
+ * @widget_name: name of a widget in @builder
+ *
+ * Gets the widget named @widget_name. Note that this function does not
+ * increment the reference count of the returned widget. If @widget_name
+ * could not be found in the @builder<!-- -->'s object tree, a run-time
+ * warning is emitted since this usually indicates a programming error.
+ *
+ * This is a convenience function to work around the awkwardness of
+ * #GtkBuilder returning #GObject pointers, when the vast majority of
+ * the time you want a #GtkWidget pointer.
+ *
+ * If you need something from @builder other than a #GtkWidget, or you
+ * want to test for the existence of some widget name without incurring
+ * a run-time warning, use gtk_builder_get_object().
+ *
+ * Returns: the widget named @widget_name, or %NULL
+ **/
+GtkWidget *
+e_builder_get_widget (GtkBuilder *builder,
+ const gchar *widget_name)
+{
+ GObject *object;
+
+ g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
+ g_return_val_if_fail (widget_name != NULL, NULL);
+
+ object = gtk_builder_get_object (builder, widget_name);
+ if (object == NULL) {
+ g_warning ("Could not find widget '%s'", widget_name);
+ return NULL;
+ }
+
+ return GTK_WIDGET (object);
+}
+
+/**
+ * e_load_ui_builder_definition:
+ * @builder: a #GtkBuilder
+ * @basename: basename of the UI definition file
+ *
+ * Loads a UI definition into @builder from Evolution's UI directory.
+ * Failure here is fatal, since the application can't function without
+ * its UI definitions.
+ **/
+void
+e_load_ui_builder_definition (GtkBuilder *builder,
+ const gchar *basename)
+{
+ gchar *filename;
+ GError *error = NULL;
+
+ g_return_if_fail (GTK_IS_BUILDER (builder));
+ g_return_if_fail (basename != NULL);
+
+ filename = g_build_filename (EVOLUTION_UIDIR, basename, NULL);
+ gtk_builder_add_from_file (builder, filename, &error);
+ g_free (filename);
+
+ if (error != NULL) {
+ g_error ("%s: %s", basename, error->message);
+ g_assert_not_reached ();
+ }
+}