[gnome-calendar] manager: Remove gcal_manager_enable/disable_source()



commit e800bb2476a220ceb66568346722eabf6083ecc6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat May 4 10:36:26 2019 -0300

    manager: Remove gcal_manager_enable/disable_source()
    
    This is now managed by GcalCalendar itself.

 src/core/gcal-calendar.c | 18 ++++++++++
 src/core/gcal-manager.c  | 85 ------------------------------------------------
 src/core/gcal-manager.h  |  6 ----
 src/gcal-source-dialog.c | 27 ++++-----------
 4 files changed, 24 insertions(+), 112 deletions(-)
---
diff --git a/src/core/gcal-calendar.c b/src/core/gcal-calendar.c
index b2937425..7b0d8e36 100644
--- a/src/core/gcal-calendar.c
+++ b/src/core/gcal-calendar.c
@@ -68,6 +68,19 @@ static GParamSpec *properties [N_PROPS];
  * Auxiliary methods
  */
 
+static void
+save_calendar (GcalCalendar *self)
+{
+  if (!e_source_get_writable (self->source))
+    {
+      g_warning ("Calendar %s is read-only and cannot be modified. Aborting.",
+                 e_source_get_uid (self->source));
+      return;
+    }
+
+  e_source_write (self->source, NULL, NULL, NULL);
+}
+
 static void
 update_color (GcalCalendar *self)
 {
@@ -464,6 +477,8 @@ gcal_calendar_set_color (GcalCalendar  *self,
   selectable_extension = e_source_get_extension (self->source, E_SOURCE_EXTENSION_CALENDAR);
   e_source_selectable_set_color (selectable_extension, color_string);
 
+  save_calendar (self);
+
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR]);
 }
 
@@ -513,6 +528,7 @@ gcal_calendar_set_name (GcalCalendar *self,
   g_return_if_fail (GCAL_IS_CALENDAR (self));
 
   e_source_set_display_name (self->source, name);
+  save_calendar (self);
 
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]);
 }
@@ -601,5 +617,7 @@ gcal_calendar_set_visible (GcalCalendar *self,
 
   selectable_extension = e_source_get_extension (self->source, E_SOURCE_EXTENSION_CALENDAR);
   e_source_selectable_set_selected (selectable_extension, visible);
+
+  save_calendar (self);
 }
 
diff --git a/src/core/gcal-manager.c b/src/core/gcal-manager.c
index 8ac27940..d40ac4e6 100644
--- a/src/core/gcal-manager.c
+++ b/src/core/gcal-manager.c
@@ -1087,91 +1087,6 @@ gcal_manager_add_source (GcalManager *self,
   GCAL_RETURN (e_source_dup_uid (source));
 }
 
-/**
- * gcal_manager_enable_source:
- * @self: a #GcalManager
- * @source: the target ESource
- *
- * Enable the given ESource.
- */
-void
-gcal_manager_enable_source (GcalManager *self,
-                            ESource     *source)
-{
-  ESourceSelectable *selectable;
-  GcalCalendar *calendar;
-  ECalClient *client;
-
-  GCAL_ENTRY;
-
-  g_return_if_fail (GCAL_IS_MANAGER (self));
-  g_return_if_fail (E_IS_SOURCE (source));
-
-  calendar = g_hash_table_lookup (self->clients, source);
-  selectable = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
-
-  if (is_source_enabled (source))
-    {
-      g_debug ("Source '%s' already enabled", e_source_get_uid (source));
-      GCAL_EXIT;
-      return;
-    }
-
-  client = gcal_calendar_get_client (calendar);
-  e_cal_data_model_add_client (self->e_data_model, client);
-
-  if (self->shell_search_data_model)
-    e_cal_data_model_add_client (self->shell_search_data_model, client);
-
-  /* Save the source */
-  e_source_selectable_set_selected (selectable, TRUE);
-  gcal_manager_save_source (self, source);
-
-  GCAL_EXIT;
-}
-
-/**
- * gcal_manager_disable_source:
- * @self: a #GcalManager
- * @source: the target ESource
- *
- * Disable the given ESource.
- */
-void
-gcal_manager_disable_source (GcalManager *self,
-                             ESource     *source)
-{
-  ESourceSelectable *selectable;
-  const gchar *source_uid;
-
-  GCAL_ENTRY;
-
-  g_return_if_fail (GCAL_IS_MANAGER (self));
-  g_return_if_fail (E_IS_SOURCE (source));
-
-  selectable = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
-
-  if (!is_source_enabled (source))
-    {
-      g_debug ("Source '%s' already disabled", e_source_get_uid (source));
-      GCAL_EXIT;
-      return;
-    }
-
-  source_uid = e_source_get_uid (source);
-
-  e_cal_data_model_remove_client (self->e_data_model, source_uid);
-
-  if (self->shell_search_data_model != NULL)
-    e_cal_data_model_remove_client (self->shell_search_data_model, source_uid);
-
-  /* Save the source */
-  e_source_selectable_set_selected (selectable, FALSE);
-  gcal_manager_save_source (self, source);
-
-  GCAL_EXIT;
-}
-
 /**
  * gcal_manager_save_source:
  * @self: a #GcalManager
diff --git a/src/core/gcal-manager.h b/src/core/gcal-manager.h
index cc9863b9..7e213ebf 100644
--- a/src/core/gcal-manager.h
+++ b/src/core/gcal-manager.h
@@ -87,12 +87,6 @@ gchar*               gcal_manager_add_source                     (GcalManager
                                                                   const gchar        *backend,
                                                                   const gchar        *color);
 
-void                 gcal_manager_enable_source                  (GcalManager        *self,
-                                                                  ESource            *source);
-
-void                 gcal_manager_disable_source                 (GcalManager        *self,
-                                                                  ESource            *source);
-
 void                 gcal_manager_save_source                    (GcalManager        *self,
                                                                   ESource            *source);
 
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index b36553c9..7c815bed 100644
--- a/src/gcal-source-dialog.c
+++ b/src/gcal-source-dialog.c
@@ -492,14 +492,13 @@ calendar_visible_check_toggled (GObject    *object,
                                 gpointer    user_data)
 {
   GcalSourceDialog *self = GCAL_SOURCE_DIALOG (user_data);
+  GcalCalendar *calendar;
   GcalManager *manager;
 
   manager = gcal_context_get_manager (self->context);
 
-  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object)))
-    gcal_manager_enable_source (manager, self->source);
-  else
-    gcal_manager_disable_source (manager, self->source);
+  calendar = gcal_manager_get_calendar_from_source (manager, self->source);
+  gcal_calendar_set_visible (calendar, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object)));
 }
 
 static void
@@ -1666,20 +1665,13 @@ notification_child_revealed_changed (GtkWidget  *notification,
         return;
 
       /* Enable the source again to remove it's name from disabled list */
-      gcal_manager_enable_source (manager, removed_source);
-
+      gcal_calendar_set_visible (self->removed_calendar, TRUE);
       e_source_remove_sync (removed_source, NULL, &error);
 
-      /**
-       * If something goes wrong, throw
-       * an alert and add the source back.
-       */
       if (error != NULL)
         {
           g_warning ("[source-dialog] Error removing source: %s", error->message);
-
           add_calendar (manager, self->removed_calendar, self);
-          gcal_manager_enable_source (manager, removed_source);
         }
     }
 }
@@ -1703,13 +1695,7 @@ undo_remove_action (GtkButton *button,
   /* if there's any set source, unremove it */
   if (self->removed_calendar != NULL)
     {
-      ESource *removed_source;
-
-      removed_source = gcal_calendar_get_source (self->removed_calendar);
-
-      /* Enable the source before adding it again */
-      gcal_manager_enable_source (manager, removed_source);
-
+      gcal_calendar_set_visible (self->removed_calendar, TRUE);
       add_calendar (manager, self->removed_calendar, self);
 
       /*
@@ -1805,8 +1791,7 @@ remove_button_clicked (GtkWidget *button,
 
       self->notification_timeout_id = g_timeout_add_seconds (5, hide_notification_scheduled, user_data);
 
-      /* Disable the source, so it gets hidden */
-      gcal_manager_disable_source (manager, removed_source);
+      gcal_calendar_set_visible (self->removed_calendar, FALSE);
 
       g_list_free (children);
       g_free (str);


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