From 9a3e0e51ba3d13decad71fbf30956aeaf9f0dae6 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Mon, 9 Feb 2015 14:50:03 -0200 Subject: [PATCH] source-dialog: handle source name changes --- data/ui/source-dialog.ui | 1 + src/gcal-source-dialog.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/data/ui/source-dialog.ui b/data/ui/source-dialog.ui index 709708f3..ec07f125 100644 --- a/data/ui/source-dialog.ui +++ b/data/ui/source-dialog.ui @@ -81,6 +81,7 @@ True True True + 1 diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c index 8c0b8e80..2aa5c5bc 100644 --- a/src/gcal-source-dialog.c +++ b/src/gcal-source-dialog.c @@ -52,6 +52,10 @@ struct _GcalSourceDialog static void action_widget_activated (GtkWidget *widget, gpointer user_data); +static void name_entry_text_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data); + G_DEFINE_TYPE_WITH_PRIVATE (GcalSourceDialog, gcal_source_dialog, GTK_TYPE_DIALOG) enum { @@ -83,6 +87,27 @@ action_widget_activated (GtkWidget *widget, gtk_dialog_response (GTK_DIALOG (user_data), response); } +/** + * name_entry_text_changed: + * + * Callend when the name entry's text + * is edited. It changes the source's + * display name, but wait's for the + * calendar's ::response signal to + * commit these changes. + * + * Returns: + */ +static void +name_entry_text_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + GcalSourceDialogPrivate *priv = GCAL_SOURCE_DIALOG (user_data)->priv; + + e_source_set_display_name (priv->source, gtk_entry_get_text (GTK_ENTRY (priv->name_entry))); +} + GcalSourceDialog * gcal_source_dialog_new (void) { @@ -171,6 +196,7 @@ gcal_source_dialog_class_init (GcalSourceDialogClass *klass) gtk_widget_class_bind_template_child_private (widget_class, GcalSourceDialog, stack); gtk_widget_class_bind_template_callback (widget_class, action_widget_activated); + gtk_widget_class_bind_template_callback (widget_class, name_entry_text_changed); } static void @@ -269,6 +295,9 @@ gcal_source_dialog_set_source (GcalSourceDialog *dialog, priv->source = source; default_source = gcal_manager_get_default_source (priv->manager); + /* block signals */ + g_signal_handlers_block_by_func (priv->name_entry, name_entry_text_changed, dialog); + /* color button */ gdk_rgba_parse (&color, get_color_name_from_source (source)); gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->calendar_color_button), &color); @@ -286,5 +315,8 @@ gcal_source_dialog_set_source (GcalSourceDialog *dialog, /* FIXME: account information on subtitle */ gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->headerbar), ""); + /* unblock signals */ + g_signal_handlers_unblock_by_func (priv->name_entry, name_entry_text_changed, dialog); + g_object_unref (default_source); }