[gnome-calendar] edit-dialog: update sources when their readonly state changes



commit 31fa4e8e06e9a2b74d9e73f842dd9ca07a1aafbd
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Dec 16 11:19:56 2014 -0200

    edit-dialog: update sources when their readonly state changes
    
    This fixes the annoying all-insensitive-menu bug.

 src/gcal-edit-dialog.c |   68 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 54 insertions(+), 14 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 1902de9..5238fb4 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -71,6 +71,19 @@ typedef struct
 
 static void        fill_sources_menu                      (GcalEditDialog    *dialog);
 
+static void        on_source_activate                     (GcalManager       *manager,
+                                                           ESource           *source,
+                                                           gboolean           active,
+                                                           gpointer           user_data);
+
+static void        on_source_added                        (GcalManager       *manager,
+                                                           ESource           *source,
+                                                           gpointer           user_data);
+
+static void        on_source_removed                      (GcalManager       *manager,
+                                                           ESource           *source,
+                                                           gpointer           user_data);
+
 static void        on_calendar_selected                   (GtkWidget         *menu_item,
                                                            GVariant          *value,
                                                            gpointer           user_data);
@@ -117,12 +130,11 @@ fill_sources_menu (GcalEditDialog *dialog)
   GList *aux;
 
   priv = gcal_edit_dialog_get_instance_private (dialog);
-
-  if (priv->manager == NULL)
-    return;
-
   list = gcal_manager_get_sources (priv->manager);
-  priv->sources_menu = g_menu_new ();
+
+  /* clear menu */
+  if (priv->sources_menu)
+    g_menu_remove_all (priv->sources_menu);
 
   for (aux = list; aux != NULL; aux = aux->next)
     {
@@ -137,7 +149,7 @@ fill_sources_menu (GcalEditDialog *dialog)
       /* retrieve color */
       extension = E_SOURCE_SELECTABLE (e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR));
       gdk_rgba_parse (&color, e_source_selectable_get_color (E_SOURCE_SELECTABLE (extension)));
-      pix = gcal_get_pixbuf_from_color (&color, 16);;
+      pix = gcal_get_pixbuf_from_color (&color, 16);
 
       /* menu item */
       item = g_menu_item_new (e_source_get_display_name (source), "edit.select_calendar");
@@ -160,12 +172,35 @@ fill_sources_menu (GcalEditDialog *dialog)
       g_object_unref (item);
     }
 
-  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->sources_button), G_MENU_MODEL (priv->sources_menu));
-
   g_list_free (list);
 }
 
 static void
+on_source_activate (GcalManager *manager,
+                    ESource     *source,
+                    gboolean     active,
+                    gpointer     user_data)
+{
+  fill_sources_menu (GCAL_EDIT_DIALOG (user_data));
+}
+
+static void
+on_source_added (GcalManager *manager,
+                 ESource     *source,
+                 gpointer     user_data)
+{
+  fill_sources_menu (GCAL_EDIT_DIALOG (user_data));
+}
+
+static void
+on_source_removed (GcalManager *manager,
+                   ESource     *source,
+                   gpointer     user_data)
+{
+  fill_sources_menu (GCAL_EDIT_DIALOG (user_data));
+}
+
+static void
 on_calendar_selected (GtkWidget *menu_item,
                       GVariant  *value,
                       gpointer   user_data)
@@ -524,6 +559,10 @@ gcal_edit_dialog_constructed (GObject* object)
 
   g_action_map_add_action (G_ACTION_MAP (priv->action_group), G_ACTION (priv->action));
 
+  /* sources menu */
+  priv->sources_menu = g_menu_new ();
+  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->sources_button), G_MENU_MODEL (priv->sources_menu));
+
   /* bind title & symmary */
   g_object_bind_property (priv->summary_entry,
                           "text",
@@ -841,12 +880,6 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog,
   /* Clear event data */
   gcal_edit_dialog_clear_data (dialog);
 
-  /* update sources list */
-  if (priv->sources_menu != NULL)
-    g_menu_remove_all (priv->sources_menu);
-
-  fill_sources_menu (dialog);
-
   /* Load new event data */
   /* summary */
   e_cal_component_get_summary (priv->component, &e_summary);
@@ -943,6 +976,13 @@ gcal_edit_dialog_set_manager (GcalEditDialog *dialog,
   priv = gcal_edit_dialog_get_instance_private (dialog);
 
   priv->manager = manager;
+
+  g_signal_connect (manager, "source-activate",
+                    G_CALLBACK (on_source_activate), dialog);
+  g_signal_connect (manager, "source-added",
+                    G_CALLBACK (on_source_added), dialog);
+  g_signal_connect (manager, "source-removed",
+                    G_CALLBACK (on_source_removed), dialog);
 }
 
 ECalComponent*


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