manager: Remove gcal_manager_enable/disable_source()

This is now managed by GcalCalendar itself.
This commit is contained in:
Georges Basile Stavracas Neto
2019-05-04 12:05:39 -03:00
parent 560419ed8a
commit e800bb2476
4 changed files with 24 additions and 112 deletions
+18
View File
@@ -68,6 +68,19 @@ static GParamSpec *properties [N_PROPS];
* Auxiliary methods * 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 static void
update_color (GcalCalendar *self) 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); selectable_extension = e_source_get_extension (self->source, E_SOURCE_EXTENSION_CALENDAR);
e_source_selectable_set_color (selectable_extension, color_string); e_source_selectable_set_color (selectable_extension, color_string);
save_calendar (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR]); 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)); g_return_if_fail (GCAL_IS_CALENDAR (self));
e_source_set_display_name (self->source, name); e_source_set_display_name (self->source, name);
save_calendar (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]); 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); selectable_extension = e_source_get_extension (self->source, E_SOURCE_EXTENSION_CALENDAR);
e_source_selectable_set_selected (selectable_extension, visible); e_source_selectable_set_selected (selectable_extension, visible);
save_calendar (self);
} }
-85
View File
@@ -1087,91 +1087,6 @@ gcal_manager_add_source (GcalManager *self,
GCAL_RETURN (e_source_dup_uid (source)); 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: * gcal_manager_save_source:
* @self: a #GcalManager * @self: a #GcalManager
-6
View File
@@ -87,12 +87,6 @@ gchar* gcal_manager_add_source (GcalManager
const gchar *backend, const gchar *backend,
const gchar *color); 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, void gcal_manager_save_source (GcalManager *self,
ESource *source); ESource *source);
+6 -21
View File
@@ -492,14 +492,13 @@ calendar_visible_check_toggled (GObject *object,
gpointer user_data) gpointer user_data)
{ {
GcalSourceDialog *self = GCAL_SOURCE_DIALOG (user_data); GcalSourceDialog *self = GCAL_SOURCE_DIALOG (user_data);
GcalCalendar *calendar;
GcalManager *manager; GcalManager *manager;
manager = gcal_context_get_manager (self->context); manager = gcal_context_get_manager (self->context);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object))) calendar = gcal_manager_get_calendar_from_source (manager, self->source);
gcal_manager_enable_source (manager, self->source); gcal_calendar_set_visible (calendar, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object)));
else
gcal_manager_disable_source (manager, self->source);
} }
static void static void
@@ -1666,20 +1665,13 @@ notification_child_revealed_changed (GtkWidget *notification,
return; return;
/* Enable the source again to remove it's name from disabled list */ /* 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); e_source_remove_sync (removed_source, NULL, &error);
/**
* If something goes wrong, throw
* an alert and add the source back.
*/
if (error != NULL) if (error != NULL)
{ {
g_warning ("[source-dialog] Error removing source: %s", error->message); g_warning ("[source-dialog] Error removing source: %s", error->message);
add_calendar (manager, self->removed_calendar, self); 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 there's any set source, unremove it */
if (self->removed_calendar != NULL) if (self->removed_calendar != NULL)
{ {
ESource *removed_source; gcal_calendar_set_visible (self->removed_calendar, TRUE);
removed_source = gcal_calendar_get_source (self->removed_calendar);
/* Enable the source before adding it again */
gcal_manager_enable_source (manager, removed_source);
add_calendar (manager, self->removed_calendar, self); 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); self->notification_timeout_id = g_timeout_add_seconds (5, hide_notification_scheduled, user_data);
/* Disable the source, so it gets hidden */ gcal_calendar_set_visible (self->removed_calendar, FALSE);
gcal_manager_disable_source (manager, removed_source);
g_list_free (children); g_list_free (children);
g_free (str); g_free (str);