[gnome-calendar/calendar-editor] source-dialog: handle source name changes



commit 52c1615240aeed7952061b3d2b6d0af2c627b399
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Feb 9 14:50:03 2015 -0200

    source-dialog: handle source name changes

 data/ui/source-dialog.ui |    1 +
 src/gcal-source-dialog.c |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/source-dialog.ui b/data/ui/source-dialog.ui
index 709708f..ec07f12 100644
--- a/data/ui/source-dialog.ui
+++ b/data/ui/source-dialog.ui
@@ -81,6 +81,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hexpand">True</property>
+                    <signal name="notify::text" handler="name_entry_text_changed" object="GcalSourceDialog" 
swapped="no"/>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index 8c0b8e8..2aa5c5b 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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]